1 // Created on: 2005-09-08
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <gp_Pnt2d.hxx>
18 #ifndef Bnd_B2x_RealLast
19 #define Bnd_B2x_RealLast RealType(1e30);
25 inline Bnd_B2x::Bnd_B2x ()
33 * Center of the created box
35 * Half-diagonal of the box, both X and Y should be non-negative
37 inline Bnd_B2x::Bnd_B2x (const gp_XY& theCenter,
38 const gp_XY& theHSize)
40 myCenter[0] = RealType(theCenter.X());
41 myCenter[1] = RealType(theCenter.Y());
42 myHSize[0] = RealType(theHSize.X());
43 myHSize[1] = RealType(theHSize.Y());
49 inline void Bnd_B2x::Clear ()
51 myCenter[0] = Bnd_B2x_RealLast;
52 myCenter[1] = Bnd_B2x_RealLast;
53 myHSize[0] = -Bnd_B2x_RealLast;
54 myHSize[1] = -Bnd_B2x_RealLast;
58 * Check if the box is empty.
60 inline Standard_Boolean Bnd_B2x::IsVoid () const
62 return (myHSize[0] < -1e-5);
66 * Update the box by point.
68 inline void Bnd_B2x::Add (const gp_Pnt2d& thePnt)
74 * Update the box by another box.
76 inline void Bnd_B2x::Add (const Bnd_B2x& theBox)
78 if (theBox.IsVoid() == Standard_False) {
79 Add (theBox.CornerMin());
80 Add (theBox.CornerMax());
87 inline gp_XY Bnd_B2x::CornerMin () const
89 return gp_XY (myCenter[0] - myHSize[0], myCenter[1] - myHSize[1]);
95 inline gp_XY Bnd_B2x::CornerMax () const
97 return gp_XY (myCenter[0] + myHSize[0], myCenter[1] + myHSize[1]);
101 * Query the square diagonal.
103 inline Standard_Real Bnd_B2x::SquareExtent () const
105 return 4 * (myHSize[0] * myHSize[0] + myHSize[1] * myHSize[1]);
109 * Set the Center coordinates.
111 inline void Bnd_B2x::SetCenter (const gp_XY& theCenter)
113 myCenter[0] = RealType(theCenter.X());
114 myCenter[1] = RealType(theCenter.Y());
118 * Set the HSize coordinates.
120 inline void Bnd_B2x::SetHSize (const gp_XY& theHSize)
122 myHSize[0] = RealType(theHSize.X());
123 myHSize[1] = RealType(theHSize.Y());
129 * absolute value of this parameter is added to the box size in all dimensions.
131 inline void Bnd_B2x::Enlarge (const Standard_Real aDiff)
133 const RealType aD = RealType(Abs(aDiff));
139 * Intersection Box - Point
141 inline Standard_Boolean Bnd_B2x::IsOut (const gp_XY& thePnt) const
143 return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
144 Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1]);
148 * Intersection Box-Box.
150 inline Standard_Boolean Bnd_B2x::IsOut (const Bnd_B2x& theBox) const
152 return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
153 Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1]);
157 * Test the complete inclusion of this box in theBox.
159 inline Standard_Boolean Bnd_B2x::IsIn (const Bnd_B2x& theBox) const
161 return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
162 Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1]);