1 // Created on: 2005-09-08
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #ifndef Bnd_B3x_RealLast
19 #define Bnd_B3x_RealLast RealType(1e30);
25 inline Bnd_B3x::Bnd_B3x ()
33 * Center of the created box
35 * Half-diagonal of the box, both X and Y should be non-negative
37 inline Bnd_B3x::Bnd_B3x (const gp_XYZ& theCenter,
38 const gp_XYZ& theHSize)
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());
51 inline void Bnd_B3x::Clear ()
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;
62 * Check if the box is empty.
64 inline Standard_Boolean Bnd_B3x::IsVoid () const
66 return (myHSize[0] < -1e-5);
70 * Update the box by point.
72 inline void Bnd_B3x::Add (const gp_Pnt& thePnt)
78 * Update the box by another box.
80 inline void Bnd_B3x::Add (const Bnd_B3x& theBox)
82 if (theBox.IsVoid() == Standard_False) {
83 Add (theBox.CornerMin());
84 Add (theBox.CornerMax());
91 inline gp_XYZ Bnd_B3x::CornerMin () const
93 return gp_XYZ (myCenter[0] - myHSize[0],
94 myCenter[1] - myHSize[1],
95 myCenter[2] - myHSize[2]);
101 inline gp_XYZ Bnd_B3x::CornerMax () const
103 return gp_XYZ (myCenter[0] + myHSize[0],
104 myCenter[1] + myHSize[1],
105 myCenter[2] + myHSize[2]);
109 * Query the square diagonal.
111 inline Standard_Real Bnd_B3x::SquareExtent () const
113 return 4 * (myHSize[0] * myHSize[0] +
114 myHSize[1] * myHSize[1] +
115 myHSize[2] * myHSize[2]);
119 * Set the Center coordinates.
121 inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter)
123 myCenter[0] = RealType(theCenter.X());
124 myCenter[1] = RealType(theCenter.Y());
125 myCenter[2] = RealType(theCenter.Z());
129 * Set the Center coordinates.
131 inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize)
133 myHSize[0] = RealType(theHSize.X());
134 myHSize[1] = RealType(theHSize.Y());
135 myHSize[2] = RealType(theHSize.Z());
141 * absolute value of this parameter is added to the box size in all dimensions.
143 inline void Bnd_B3x::Enlarge (const Standard_Real aDiff)
145 const Standard_Real aD = Abs(aDiff);
146 myHSize[0] += RealType(aD);
147 myHSize[1] += RealType(aD);
148 myHSize[2] += RealType(aD);
152 * Intersection Box - Point
154 inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const
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]);
162 * Intersection Box-Box.
164 inline Standard_Boolean Bnd_B3x::IsOut (const Bnd_B3x& theBox) const
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]);
172 * Test the complete inclusion of this box in theBox.
174 inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const
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]);