7fd59977 |
1 | // File: Bnd_B3x.lxx |
2 | // Created: 08.09.05 20:55:36 |
3 | // Author: Alexander GRIGORIEV |
4 | // Copyright: Open Cascade 2005 |
5 | |
6 | #include <gp_Pnt.hxx> |
7 | |
8 | #ifndef Bnd_B3x_RealLast |
9 | #define Bnd_B3x_RealLast RealType(1e30); |
10 | #endif |
11 | |
12 | /** |
13 | * Empty constructor |
14 | */ |
15 | inline Bnd_B3x::Bnd_B3x () |
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_B3x::Bnd_B3x (const gp_XYZ& theCenter, |
28 | const gp_XYZ& theHSize) |
29 | { |
30 | myCenter[0] = RealType(theCenter.X()); |
31 | myCenter[1] = RealType(theCenter.Y()); |
32 | myCenter[2] = RealType(theCenter.Z()); |
33 | myHSize[0] = RealType(theHSize.X()); |
34 | myHSize[1] = RealType(theHSize.Y()); |
35 | myHSize[2] = RealType(theHSize.Z()); |
36 | } |
37 | |
38 | /** |
39 | * Reset the box data. |
40 | */ |
41 | inline void Bnd_B3x::Clear () |
42 | { |
43 | myCenter[0] = Bnd_B3x_RealLast; |
44 | myCenter[1] = Bnd_B3x_RealLast; |
45 | myCenter[2] = Bnd_B3x_RealLast; |
46 | myHSize[0] = -Bnd_B3x_RealLast; |
47 | myHSize[1] = -Bnd_B3x_RealLast; |
48 | myHSize[2] = -Bnd_B3x_RealLast; |
49 | } |
50 | |
51 | /** |
52 | * Check if the box is empty. |
53 | */ |
54 | inline Standard_Boolean Bnd_B3x::IsVoid () const |
55 | { |
56 | return (myHSize[0] < -1e-5); |
57 | } |
58 | |
59 | /** |
60 | * Update the box by point. |
61 | */ |
62 | inline void Bnd_B3x::Add (const gp_Pnt& thePnt) |
63 | { |
64 | Add (thePnt.XYZ()); |
65 | } |
66 | |
67 | /** |
68 | * Update the box by another box. |
69 | */ |
70 | inline void Bnd_B3x::Add (const Bnd_B3x& theBox) |
71 | { |
72 | if (theBox.IsVoid() == Standard_False) { |
73 | Add (theBox.CornerMin()); |
74 | Add (theBox.CornerMax()); |
75 | } |
76 | } |
77 | |
78 | /** |
79 | * Query a box corner. |
80 | */ |
81 | inline gp_XYZ Bnd_B3x::CornerMin () const |
82 | { |
83 | return gp_XYZ (myCenter[0] - myHSize[0], |
84 | myCenter[1] - myHSize[1], |
85 | myCenter[2] - myHSize[2]); |
86 | } |
87 | |
88 | /** |
89 | * Query a box corner. |
90 | */ |
91 | inline gp_XYZ Bnd_B3x::CornerMax () const |
92 | { |
93 | return gp_XYZ (myCenter[0] + myHSize[0], |
94 | myCenter[1] + myHSize[1], |
95 | myCenter[2] + myHSize[2]); |
96 | } |
97 | |
98 | /** |
99 | * Query the square diagonal. |
100 | */ |
101 | inline Standard_Real Bnd_B3x::SquareExtent () const |
102 | { |
103 | return 4 * (myHSize[0] * myHSize[0] + |
104 | myHSize[1] * myHSize[1] + |
105 | myHSize[2] * myHSize[2]); |
106 | } |
107 | |
108 | /** |
109 | * Set the Center coordinates. |
110 | */ |
111 | inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter) |
112 | { |
113 | myCenter[0] = RealType(theCenter.X()); |
114 | myCenter[1] = RealType(theCenter.Y()); |
115 | myCenter[2] = RealType(theCenter.Z()); |
116 | } |
117 | |
118 | /** |
119 | * Set the Center coordinates. |
120 | */ |
121 | inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize) |
122 | { |
123 | myHSize[0] = RealType(theHSize.X()); |
124 | myHSize[1] = RealType(theHSize.Y()); |
125 | myHSize[2] = RealType(theHSize.Z()); |
126 | } |
127 | |
128 | /** |
129 | * Increase the box. |
130 | * @param aDiff |
131 | * absolute value of this parameter is added to the box size in all dimensions. |
132 | */ |
133 | inline void Bnd_B3x::Enlarge (const Standard_Real aDiff) |
134 | { |
135 | const Standard_Real aD = Abs(aDiff); |
136 | myHSize[0] += RealType(aD); |
137 | myHSize[1] += RealType(aD); |
138 | myHSize[2] += RealType(aD); |
139 | } |
140 | |
141 | /** |
142 | * Intersection Box - Point |
143 | */ |
144 | inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const |
145 | { |
146 | return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] || |
147 | Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1] || |
148 | Abs(RealType(thePnt.Z()) - myCenter[2]) > myHSize[2]); |
149 | } |
150 | |
151 | /** |
152 | * Intersection Box-Box. |
153 | */ |
154 | inline Standard_Boolean Bnd_B3x::IsOut (const Bnd_B3x& theBox) const |
155 | { |
156 | return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] || |
157 | Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1] || |
158 | Abs(theBox.myCenter[2]-myCenter[2]) > theBox.myHSize[2]+myHSize[2]); |
159 | } |
160 | |
161 | /** |
162 | * Test the complete inclusion of this box in theBox. |
163 | */ |
164 | inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const |
165 | { |
166 | return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] && |
167 | Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1] && |
168 | Abs(theBox.myCenter[2]-myCenter[2]) < theBox.myHSize[2]-myHSize[2]); |
169 | } |
170 | |