2 // Created: 08.09.05 20:13:23
3 // Author: Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
6 #include <gp_Pnt2d.hxx>
8 #ifndef Bnd_B2x_RealLast
9 #define Bnd_B2x_RealLast RealType(1e30);
15 inline Bnd_B2x::Bnd_B2x ()
23 * Center of the created box
25 * Half-diagonal of the box, both X and Y should be non-negative
27 inline Bnd_B2x::Bnd_B2x (const gp_XY& theCenter,
28 const gp_XY& theHSize)
30 myCenter[0] = RealType(theCenter.X());
31 myCenter[1] = RealType(theCenter.Y());
32 myHSize[0] = RealType(theHSize.X());
33 myHSize[1] = RealType(theHSize.Y());
39 inline void Bnd_B2x::Clear ()
41 myCenter[0] = Bnd_B2x_RealLast;
42 myCenter[1] = Bnd_B2x_RealLast;
43 myHSize[0] = -Bnd_B2x_RealLast;
44 myHSize[1] = -Bnd_B2x_RealLast;
48 * Check if the box is empty.
50 inline Standard_Boolean Bnd_B2x::IsVoid () const
52 return (myHSize[0] < -1e-5);
56 * Update the box by point.
58 inline void Bnd_B2x::Add (const gp_Pnt2d& thePnt)
64 * Update the box by another box.
66 inline void Bnd_B2x::Add (const Bnd_B2x& theBox)
68 if (theBox.IsVoid() == Standard_False) {
69 Add (theBox.CornerMin());
70 Add (theBox.CornerMax());
77 inline gp_XY Bnd_B2x::CornerMin () const
79 return gp_XY (myCenter[0] - myHSize[0], myCenter[1] - myHSize[1]);
85 inline gp_XY Bnd_B2x::CornerMax () const
87 return gp_XY (myCenter[0] + myHSize[0], myCenter[1] + myHSize[1]);
91 * Query the square diagonal.
93 inline Standard_Real Bnd_B2x::SquareExtent () const
95 return 4 * (myHSize[0] * myHSize[0] + myHSize[1] * myHSize[1]);
99 * Set the Center coordinates.
101 inline void Bnd_B2x::SetCenter (const gp_XY& theCenter)
103 myCenter[0] = RealType(theCenter.X());
104 myCenter[1] = RealType(theCenter.Y());
108 * Set the HSize coordinates.
110 inline void Bnd_B2x::SetHSize (const gp_XY& theHSize)
112 myHSize[0] = RealType(theHSize.X());
113 myHSize[1] = RealType(theHSize.Y());
119 * absolute value of this parameter is added to the box size in all dimensions.
121 inline void Bnd_B2x::Enlarge (const Standard_Real aDiff)
123 const RealType aD = RealType(Abs(aDiff));
129 * Intersection Box - Point
131 inline Standard_Boolean Bnd_B2x::IsOut (const gp_XY& thePnt) const
133 return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
134 Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1]);
138 * Intersection Box-Box.
140 inline Standard_Boolean Bnd_B2x::IsOut (const Bnd_B2x& theBox) const
142 return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
143 Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1]);
147 * Test the complete inclusion of this box in theBox.
149 inline Standard_Boolean Bnd_B2x::IsIn (const Bnd_B2x& theBox) const
151 return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
152 Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1]);