Warning, /include/opencascade/Bnd_B3x.lxx is written in an unsupported language. File is not indexed.
0001 // Created on: 2005-09-08
0002 // Created by: Alexander GRIGORIEV
0003 // Copyright (c) 2005-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015
0016 #include <gp_Pnt.hxx>
0017
0018 #ifndef Bnd_B3x_RealLast
0019 #define Bnd_B3x_RealLast RealType(1e30);
0020 #endif
0021
0022 /**
0023 * Empty constructor
0024 */
0025 inline Bnd_B3x::Bnd_B3x ()
0026 {
0027 Clear();
0028 }
0029
0030 /**
0031 * Constructor.
0032 * @param theCenter
0033 * Center of the created box
0034 * @param theHSize
0035 * Half-diagonal of the box, both X and Y should be non-negative
0036 */
0037 inline Bnd_B3x::Bnd_B3x (const gp_XYZ& theCenter,
0038 const gp_XYZ& theHSize)
0039 {
0040 myCenter[0] = RealType(theCenter.X());
0041 myCenter[1] = RealType(theCenter.Y());
0042 myCenter[2] = RealType(theCenter.Z());
0043 myHSize[0] = RealType(theHSize.X());
0044 myHSize[1] = RealType(theHSize.Y());
0045 myHSize[2] = RealType(theHSize.Z());
0046 }
0047
0048 /**
0049 * Reset the box data.
0050 */
0051 inline void Bnd_B3x::Clear ()
0052 {
0053 myCenter[0] = Bnd_B3x_RealLast;
0054 myCenter[1] = Bnd_B3x_RealLast;
0055 myCenter[2] = Bnd_B3x_RealLast;
0056 myHSize[0] = -Bnd_B3x_RealLast;
0057 myHSize[1] = -Bnd_B3x_RealLast;
0058 myHSize[2] = -Bnd_B3x_RealLast;
0059 }
0060
0061 /**
0062 * Check if the box is empty.
0063 */
0064 inline Standard_Boolean Bnd_B3x::IsVoid () const
0065 {
0066 return (myHSize[0] < -1e-5);
0067 }
0068
0069 /**
0070 * Update the box by point.
0071 */
0072 inline void Bnd_B3x::Add (const gp_Pnt& thePnt)
0073 {
0074 Add (thePnt.XYZ());
0075 }
0076
0077 /**
0078 * Update the box by another box.
0079 */
0080 inline void Bnd_B3x::Add (const Bnd_B3x& theBox)
0081 {
0082 if (theBox.IsVoid() == Standard_False) {
0083 Add (theBox.CornerMin());
0084 Add (theBox.CornerMax());
0085 }
0086 }
0087
0088 /**
0089 * Query a box corner.
0090 */
0091 inline gp_XYZ Bnd_B3x::CornerMin () const
0092 {
0093 return gp_XYZ (myCenter[0] - myHSize[0],
0094 myCenter[1] - myHSize[1],
0095 myCenter[2] - myHSize[2]);
0096 }
0097
0098 /**
0099 * Query a box corner.
0100 */
0101 inline gp_XYZ Bnd_B3x::CornerMax () const
0102 {
0103 return gp_XYZ (myCenter[0] + myHSize[0],
0104 myCenter[1] + myHSize[1],
0105 myCenter[2] + myHSize[2]);
0106 }
0107
0108 /**
0109 * Query the square diagonal.
0110 */
0111 inline Standard_Real Bnd_B3x::SquareExtent () const
0112 {
0113 return 4 * (myHSize[0] * myHSize[0] +
0114 myHSize[1] * myHSize[1] +
0115 myHSize[2] * myHSize[2]);
0116 }
0117
0118 /**
0119 * Set the Center coordinates.
0120 */
0121 inline void Bnd_B3x::SetCenter (const gp_XYZ& theCenter)
0122 {
0123 myCenter[0] = RealType(theCenter.X());
0124 myCenter[1] = RealType(theCenter.Y());
0125 myCenter[2] = RealType(theCenter.Z());
0126 }
0127
0128 /**
0129 * Set the Center coordinates.
0130 */
0131 inline void Bnd_B3x::SetHSize (const gp_XYZ& theHSize)
0132 {
0133 myHSize[0] = RealType(theHSize.X());
0134 myHSize[1] = RealType(theHSize.Y());
0135 myHSize[2] = RealType(theHSize.Z());
0136 }
0137
0138 /**
0139 * Increase the box.
0140 * @param aDiff
0141 * absolute value of this parameter is added to the box size in all dimensions.
0142 */
0143 inline void Bnd_B3x::Enlarge (const Standard_Real aDiff)
0144 {
0145 const Standard_Real aD = Abs(aDiff);
0146 myHSize[0] += RealType(aD);
0147 myHSize[1] += RealType(aD);
0148 myHSize[2] += RealType(aD);
0149 }
0150
0151 /**
0152 * Intersection Box - Point
0153 */
0154 inline Standard_Boolean Bnd_B3x::IsOut (const gp_XYZ& thePnt) const
0155 {
0156 return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
0157 Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1] ||
0158 Abs(RealType(thePnt.Z()) - myCenter[2]) > myHSize[2]);
0159 }
0160
0161 /**
0162 * Intersection Box-Box.
0163 */
0164 inline Standard_Boolean Bnd_B3x::IsOut (const Bnd_B3x& theBox) const
0165 {
0166 return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
0167 Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1] ||
0168 Abs(theBox.myCenter[2]-myCenter[2]) > theBox.myHSize[2]+myHSize[2]);
0169 }
0170
0171 /**
0172 * Test the complete inclusion of this box in theBox.
0173 */
0174 inline Standard_Boolean Bnd_B3x::IsIn (const Bnd_B3x& theBox) const
0175 {
0176 return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
0177 Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1] &&
0178 Abs(theBox.myCenter[2]-myCenter[2]) < theBox.myHSize[2]-myHSize[2]);
0179 }
0180