1 // Created on: 2005-09-08
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2005-2012 OPEN CASCADE SAS
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.
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.
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.
23 #ifndef Bnd_B3x_RealLast
24 #define Bnd_B3x_RealLast RealType(1e30);
30 inline Bnd_B3x::Bnd_B3x ()
38 * Center of the created box
40 * Half-diagonal of the box, both X and Y should be non-negative
42 inline Bnd_B3x::Bnd_B3x (const gp_XYZ& theCenter,
43 const gp_XYZ& theHSize)
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());
56 inline void Bnd_B3x::Clear ()
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;
67 * Check if the box is empty.
69 inline Standard_Boolean Bnd_B3x::IsVoid () const
71 return (myHSize[0] < -1e-5);
75 * Update the box by point.
77 inline void Bnd_B3x::Add (const gp_Pnt& thePnt)
83 * Update the box by another box.
85 inline void Bnd_B3x::Add (const Bnd_B3x& theBox)
87 if (theBox.IsVoid() == Standard_False) {
88 Add (theBox.CornerMin());
89 Add (theBox.CornerMax());
96 inline gp_XYZ Bnd_B3x::CornerMin () const
98 return gp_XYZ (myCenter[0] - myHSize[0],
99 myCenter[1] - myHSize[1],
100 myCenter[2] - myHSize[2]);
104 * Query a box corner.
106 inline gp_XYZ Bnd_B3x::CornerMax () const
108 return gp_XYZ (myCenter[0] + myHSize[0],
109 myCenter[1] + myHSize[1],
110 myCenter[2] + myHSize[2]);
114 * Query the square diagonal.
116 inline Standard_Real Bnd_B3x::SquareExtent () const
118 return 4 * (myHSize[0] * myHSize[0] +
119 myHSize[1] * myHSize[1] +
120 myHSize[2] * myHSize[2]);
124 * Set the Center coordinates.
126 inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter)
128 myCenter[0] = RealType(theCenter.X());
129 myCenter[1] = RealType(theCenter.Y());
130 myCenter[2] = RealType(theCenter.Z());
134 * Set the Center coordinates.
136 inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize)
138 myHSize[0] = RealType(theHSize.X());
139 myHSize[1] = RealType(theHSize.Y());
140 myHSize[2] = RealType(theHSize.Z());
146 * absolute value of this parameter is added to the box size in all dimensions.
148 inline void Bnd_B3x::Enlarge (const Standard_Real aDiff)
150 const Standard_Real aD = Abs(aDiff);
151 myHSize[0] += RealType(aD);
152 myHSize[1] += RealType(aD);
153 myHSize[2] += RealType(aD);
157 * Intersection Box - Point
159 inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const
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]);
167 * Intersection Box-Box.
169 inline Standard_Boolean Bnd_B3x::IsOut (const Bnd_B3x& theBox) const
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]);
177 * Test the complete inclusion of this box in theBox.
179 inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const
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]);