0022885: Bugfix: else clause applies to the wrong if statement because of missing...
[occt.git] / src / Bnd / Bnd_B2x.lxx
1 // File:      Bnd_B2x.lxx
2 // Created:   08.09.05 20:13:23
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
5
6 #include <gp_Pnt2d.hxx>
7
8 #ifndef Bnd_B2x_RealLast
9 #define Bnd_B2x_RealLast RealType(1e30);
10 #endif
11
12 /**
13  * Empty constructor
14  */
15 inline Bnd_B2x::Bnd_B2x ()
16 {
17   Clear();
18 }
19
20 /**
21  * Constructor.
22  * @param theCenter
23  *   Center of the created box
24  * @param theHSize
25  *   Half-diagonal of the box, both X and Y should be non-negative
26  */
27 inline Bnd_B2x::Bnd_B2x (const gp_XY& theCenter,
28                          const gp_XY& theHSize)
29 {
30   myCenter[0] = RealType(theCenter.X());
31   myCenter[1] = RealType(theCenter.Y());
32   myHSize[0]  = RealType(theHSize.X());
33   myHSize[1]  = RealType(theHSize.Y());
34 }
35
36 /**
37  * Reset the box data.
38  */
39 inline void Bnd_B2x::Clear ()
40 {
41   myCenter[0] = Bnd_B2x_RealLast;
42   myCenter[1] = Bnd_B2x_RealLast;
43   myHSize[0] = -Bnd_B2x_RealLast;
44   myHSize[1] = -Bnd_B2x_RealLast;
45 }
46
47 /**
48  * Check if the box is empty.
49  */
50 inline Standard_Boolean Bnd_B2x::IsVoid () const
51 {
52   return (myHSize[0] < -1e-5);
53 }
54
55 /**
56  * Update the box by point.
57  */
58 inline void Bnd_B2x::Add (const gp_Pnt2d& thePnt)
59 {
60   Add (thePnt.XY());
61 }
62
63 /**
64  * Update the box by another box.
65  */
66 inline void Bnd_B2x::Add (const Bnd_B2x& theBox)
67 {
68   if (theBox.IsVoid() == Standard_False) {
69     Add (theBox.CornerMin());
70     Add (theBox.CornerMax());
71   }
72 }
73
74 /**
75  * Query a box corner.
76  */
77 inline gp_XY Bnd_B2x::CornerMin () const
78 {
79   return gp_XY (myCenter[0] - myHSize[0], myCenter[1] - myHSize[1]);
80 }
81
82 /**
83  * Query a box corner.
84  */
85 inline gp_XY Bnd_B2x::CornerMax () const
86 {
87   return gp_XY (myCenter[0] + myHSize[0], myCenter[1] + myHSize[1]);
88 }
89
90 /**
91  * Query the square diagonal.
92  */
93 inline Standard_Real Bnd_B2x::SquareExtent () const
94 {
95   return 4 * (myHSize[0] * myHSize[0] + myHSize[1] * myHSize[1]);
96 }
97
98 /**
99  * Set the Center coordinates.
100  */
101 inline void Bnd_B2x::SetCenter (const gp_XY& theCenter)
102 {
103   myCenter[0] = RealType(theCenter.X());
104   myCenter[1] = RealType(theCenter.Y());
105 }
106
107 /**
108  * Set the HSize coordinates.
109  */
110 inline void Bnd_B2x::SetHSize (const gp_XY& theHSize)
111 {
112   myHSize[0] = RealType(theHSize.X());
113   myHSize[1] = RealType(theHSize.Y());
114 }
115
116 /**
117  * Increase the box.
118  * @param aDiff
119  *   absolute value of this parameter is added to the box size in all dimensions.
120  */
121 inline void Bnd_B2x::Enlarge (const Standard_Real aDiff)
122 {
123   const RealType aD = RealType(Abs(aDiff));
124   myHSize[0] += aD;
125   myHSize[1] += aD;
126 }
127
128 /**
129  * Intersection Box - Point
130  */
131 inline Standard_Boolean Bnd_B2x::IsOut (const gp_XY& thePnt) const
132 {
133   return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
134           Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1]);
135 }
136
137 /**
138  * Intersection Box-Box.
139  */
140 inline Standard_Boolean Bnd_B2x::IsOut (const Bnd_B2x& theBox) const
141 {
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]);
144 }
145
146 /**
147  * Test the complete inclusion of this box in theBox.
148  */
149 inline Standard_Boolean Bnd_B2x::IsIn (const Bnd_B2x& theBox) const
150 {
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]);
153 }
154