b311480e |
1 | // Created on: 2005-09-08 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2005-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <gp_Pnt.hxx> |
17 | |
18 | #ifndef Bnd_B3x_RealLast |
19 | #define Bnd_B3x_RealLast RealType(1e30); |
20 | #endif |
21 | |
22 | /** |
23 | * Empty constructor |
24 | */ |
25 | inline Bnd_B3x::Bnd_B3x () |
26 | { |
27 | Clear(); |
28 | } |
29 | |
30 | /** |
31 | * Constructor. |
32 | * @param theCenter |
33 | * Center of the created box |
34 | * @param theHSize |
35 | * Half-diagonal of the box, both X and Y should be non-negative |
36 | */ |
37 | inline Bnd_B3x::Bnd_B3x (const gp_XYZ& theCenter, |
38 | const gp_XYZ& theHSize) |
39 | { |
40 | myCenter[0] = RealType(theCenter.X()); |
41 | myCenter[1] = RealType(theCenter.Y()); |
42 | myCenter[2] = RealType(theCenter.Z()); |
43 | myHSize[0] = RealType(theHSize.X()); |
44 | myHSize[1] = RealType(theHSize.Y()); |
45 | myHSize[2] = RealType(theHSize.Z()); |
46 | } |
47 | |
48 | /** |
49 | * Reset the box data. |
50 | */ |
51 | inline void Bnd_B3x::Clear () |
52 | { |
53 | myCenter[0] = Bnd_B3x_RealLast; |
54 | myCenter[1] = Bnd_B3x_RealLast; |
55 | myCenter[2] = Bnd_B3x_RealLast; |
56 | myHSize[0] = -Bnd_B3x_RealLast; |
57 | myHSize[1] = -Bnd_B3x_RealLast; |
58 | myHSize[2] = -Bnd_B3x_RealLast; |
59 | } |
60 | |
61 | /** |
62 | * Check if the box is empty. |
63 | */ |
64 | inline Standard_Boolean Bnd_B3x::IsVoid () const |
65 | { |
66 | return (myHSize[0] < -1e-5); |
67 | } |
68 | |
69 | /** |
70 | * Update the box by point. |
71 | */ |
72 | inline void Bnd_B3x::Add (const gp_Pnt& thePnt) |
73 | { |
74 | Add (thePnt.XYZ()); |
75 | } |
76 | |
77 | /** |
78 | * Update the box by another box. |
79 | */ |
80 | inline void Bnd_B3x::Add (const Bnd_B3x& theBox) |
81 | { |
82 | if (theBox.IsVoid() == Standard_False) { |
83 | Add (theBox.CornerMin()); |
84 | Add (theBox.CornerMax()); |
85 | } |
86 | } |
87 | |
88 | /** |
89 | * Query a box corner. |
90 | */ |
91 | inline gp_XYZ Bnd_B3x::CornerMin () 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 a box corner. |
100 | */ |
101 | inline gp_XYZ Bnd_B3x::CornerMax () const |
102 | { |
103 | return gp_XYZ (myCenter[0] + myHSize[0], |
104 | myCenter[1] + myHSize[1], |
105 | myCenter[2] + myHSize[2]); |
106 | } |
107 | |
108 | /** |
109 | * Query the square diagonal. |
110 | */ |
111 | inline Standard_Real Bnd_B3x::SquareExtent () const |
112 | { |
113 | return 4 * (myHSize[0] * myHSize[0] + |
114 | myHSize[1] * myHSize[1] + |
115 | myHSize[2] * myHSize[2]); |
116 | } |
117 | |
118 | /** |
119 | * Set the Center coordinates. |
120 | */ |
121 | inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter) |
122 | { |
123 | myCenter[0] = RealType(theCenter.X()); |
124 | myCenter[1] = RealType(theCenter.Y()); |
125 | myCenter[2] = RealType(theCenter.Z()); |
126 | } |
127 | |
128 | /** |
129 | * Set the Center coordinates. |
130 | */ |
131 | inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize) |
132 | { |
133 | myHSize[0] = RealType(theHSize.X()); |
134 | myHSize[1] = RealType(theHSize.Y()); |
135 | myHSize[2] = RealType(theHSize.Z()); |
136 | } |
137 | |
138 | /** |
139 | * Increase the box. |
140 | * @param aDiff |
141 | * absolute value of this parameter is added to the box size in all dimensions. |
142 | */ |
143 | inline void Bnd_B3x::Enlarge (const Standard_Real aDiff) |
144 | { |
145 | const Standard_Real aD = Abs(aDiff); |
146 | myHSize[0] += RealType(aD); |
147 | myHSize[1] += RealType(aD); |
148 | myHSize[2] += RealType(aD); |
149 | } |
150 | |
151 | /** |
152 | * Intersection Box - Point |
153 | */ |
154 | inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const |
155 | { |
156 | return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] || |
157 | Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1] || |
158 | Abs(RealType(thePnt.Z()) - myCenter[2]) > myHSize[2]); |
159 | } |
160 | |
161 | /** |
162 | * Intersection Box-Box. |
163 | */ |
164 | inline Standard_Boolean Bnd_B3x::IsOut (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 | |
171 | /** |
172 | * Test the complete inclusion of this box in theBox. |
173 | */ |
174 | inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const |
175 | { |
176 | return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] && |
177 | Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1] && |
178 | Abs(theBox.myCenter[2]-myCenter[2]) < theBox.myHSize[2]-myHSize[2]); |
179 | } |
180 | |