0024177: Eliminate CLang compiler warning -Wlogical-op-parentheses (&& within ||)
[occt.git] / src / Bnd / Bnd_B3x.lxx
1 // Created on: 2005-09-08
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2005-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <gp_Pnt.hxx>
22
23 #ifndef Bnd_B3x_RealLast
24 #define Bnd_B3x_RealLast RealType(1e30);
25 #endif
26
27 /**
28  * Empty constructor
29  */
30 inline Bnd_B3x::Bnd_B3x ()
31 {
32   Clear();
33 }
34
35 /**
36  * Constructor.
37  * @param theCenter
38  *   Center of the created box
39  * @param theHSize
40  *   Half-diagonal of the box, both X and Y should be non-negative
41  */
42 inline Bnd_B3x::Bnd_B3x (const gp_XYZ& theCenter,
43                          const gp_XYZ& theHSize)
44 {
45   myCenter[0] = RealType(theCenter.X());
46   myCenter[1] = RealType(theCenter.Y());
47   myCenter[2] = RealType(theCenter.Z());
48   myHSize[0]  = RealType(theHSize.X());
49   myHSize[1]  = RealType(theHSize.Y());
50   myHSize[2]  = RealType(theHSize.Z());
51 }
52
53 /**
54  * Reset the box data.
55  */
56 inline void Bnd_B3x::Clear ()
57 {
58   myCenter[0] = Bnd_B3x_RealLast;
59   myCenter[1] = Bnd_B3x_RealLast;
60   myCenter[2] = Bnd_B3x_RealLast;
61   myHSize[0] = -Bnd_B3x_RealLast;
62   myHSize[1] = -Bnd_B3x_RealLast;
63   myHSize[2] = -Bnd_B3x_RealLast;
64 }
65
66 /**
67  * Check if the box is empty.
68  */
69 inline Standard_Boolean Bnd_B3x::IsVoid () const
70 {
71   return (myHSize[0] < -1e-5);
72 }
73
74 /**
75  * Update the box by point.
76  */
77 inline void Bnd_B3x::Add (const gp_Pnt& thePnt)
78 {
79   Add (thePnt.XYZ());
80 }
81
82 /**
83  * Update the box by another box.
84  */
85 inline void Bnd_B3x::Add (const Bnd_B3x& theBox)
86 {
87   if (theBox.IsVoid() == Standard_False) {
88     Add (theBox.CornerMin());
89     Add (theBox.CornerMax());
90   }
91 }
92
93 /**
94  * Query a box corner.
95  */
96 inline gp_XYZ Bnd_B3x::CornerMin () const
97 {
98   return gp_XYZ (myCenter[0] - myHSize[0],
99                  myCenter[1] - myHSize[1],
100                  myCenter[2] - myHSize[2]);
101 }
102
103 /**
104  * Query a box corner.
105  */
106 inline gp_XYZ Bnd_B3x::CornerMax () const
107 {
108   return gp_XYZ (myCenter[0] + myHSize[0],
109                  myCenter[1] + myHSize[1],
110                  myCenter[2] + myHSize[2]);
111 }
112
113 /**
114  * Query the square diagonal.
115  */
116 inline Standard_Real Bnd_B3x::SquareExtent () const
117 {
118   return 4 * (myHSize[0] * myHSize[0] +
119               myHSize[1] * myHSize[1] +
120               myHSize[2] * myHSize[2]);
121 }
122
123 /**
124  * Set the Center coordinates.
125  */
126 inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter)
127 {
128   myCenter[0] = RealType(theCenter.X());
129   myCenter[1] = RealType(theCenter.Y());
130   myCenter[2] = RealType(theCenter.Z());
131 }
132
133 /**
134  * Set the Center coordinates.
135  */
136 inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize)
137 {
138   myHSize[0] = RealType(theHSize.X());
139   myHSize[1] = RealType(theHSize.Y());
140   myHSize[2] = RealType(theHSize.Z());
141 }
142
143 /**
144  * Increase the box.
145  * @param aDiff
146  *   absolute value of this parameter is added to the box size in all dimensions.
147  */
148 inline void Bnd_B3x::Enlarge (const Standard_Real aDiff)
149 {
150   const Standard_Real aD = Abs(aDiff);
151   myHSize[0] += RealType(aD);
152   myHSize[1] += RealType(aD);
153   myHSize[2] += RealType(aD);
154 }
155
156 /**
157  * Intersection Box - Point
158  */
159 inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const
160 {
161   return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
162           Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1] ||
163           Abs(RealType(thePnt.Z()) - myCenter[2]) > myHSize[2]);
164 }
165
166 /**
167  * Intersection Box-Box.
168  */
169 inline Standard_Boolean Bnd_B3x::IsOut (const Bnd_B3x& theBox) const
170 {
171   return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
172           Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1] ||
173           Abs(theBox.myCenter[2]-myCenter[2]) > theBox.myHSize[2]+myHSize[2]);
174 }
175
176 /**
177  * Test the complete inclusion of this box in theBox.
178  */
179 inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const
180 {
181   return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
182           Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1] &&
183           Abs(theBox.myCenter[2]-myCenter[2]) < theBox.myHSize[2]-myHSize[2]);
184 }
185