Warning, /include/opencascade/Bnd_B2x.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_Pnt2d.hxx>
0017
0018 #ifndef Bnd_B2x_RealLast
0019 #define Bnd_B2x_RealLast RealType(1e30);
0020 #endif
0021
0022 /**
0023 * Empty constructor
0024 */
0025 inline Bnd_B2x::Bnd_B2x ()
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_B2x::Bnd_B2x (const gp_XY& theCenter,
0038 const gp_XY& theHSize)
0039 {
0040 myCenter[0] = RealType(theCenter.X());
0041 myCenter[1] = RealType(theCenter.Y());
0042 myHSize[0] = RealType(theHSize.X());
0043 myHSize[1] = RealType(theHSize.Y());
0044 }
0045
0046 /**
0047 * Reset the box data.
0048 */
0049 inline void Bnd_B2x::Clear ()
0050 {
0051 myCenter[0] = Bnd_B2x_RealLast;
0052 myCenter[1] = Bnd_B2x_RealLast;
0053 myHSize[0] = -Bnd_B2x_RealLast;
0054 myHSize[1] = -Bnd_B2x_RealLast;
0055 }
0056
0057 /**
0058 * Check if the box is empty.
0059 */
0060 inline Standard_Boolean Bnd_B2x::IsVoid () const
0061 {
0062 return (myHSize[0] < -1e-5);
0063 }
0064
0065 /**
0066 * Update the box by point.
0067 */
0068 inline void Bnd_B2x::Add (const gp_Pnt2d& thePnt)
0069 {
0070 Add (thePnt.XY());
0071 }
0072
0073 /**
0074 * Update the box by another box.
0075 */
0076 inline void Bnd_B2x::Add (const Bnd_B2x& theBox)
0077 {
0078 if (theBox.IsVoid() == Standard_False) {
0079 Add (theBox.CornerMin());
0080 Add (theBox.CornerMax());
0081 }
0082 }
0083
0084 /**
0085 * Query a box corner.
0086 */
0087 inline gp_XY Bnd_B2x::CornerMin () const
0088 {
0089 return gp_XY (myCenter[0] - myHSize[0], myCenter[1] - myHSize[1]);
0090 }
0091
0092 /**
0093 * Query a box corner.
0094 */
0095 inline gp_XY Bnd_B2x::CornerMax () const
0096 {
0097 return gp_XY (myCenter[0] + myHSize[0], myCenter[1] + myHSize[1]);
0098 }
0099
0100 /**
0101 * Query the square diagonal.
0102 */
0103 inline Standard_Real Bnd_B2x::SquareExtent () const
0104 {
0105 return 4 * (myHSize[0] * myHSize[0] + myHSize[1] * myHSize[1]);
0106 }
0107
0108 /**
0109 * Set the Center coordinates.
0110 */
0111 inline void Bnd_B2x::SetCenter (const gp_XY& theCenter)
0112 {
0113 myCenter[0] = RealType(theCenter.X());
0114 myCenter[1] = RealType(theCenter.Y());
0115 }
0116
0117 /**
0118 * Set the HSize coordinates.
0119 */
0120 inline void Bnd_B2x::SetHSize (const gp_XY& theHSize)
0121 {
0122 myHSize[0] = RealType(theHSize.X());
0123 myHSize[1] = RealType(theHSize.Y());
0124 }
0125
0126 /**
0127 * Increase the box.
0128 * @param aDiff
0129 * absolute value of this parameter is added to the box size in all dimensions.
0130 */
0131 inline void Bnd_B2x::Enlarge (const Standard_Real aDiff)
0132 {
0133 const RealType aD = RealType(Abs(aDiff));
0134 myHSize[0] += aD;
0135 myHSize[1] += aD;
0136 }
0137
0138 /**
0139 * Intersection Box - Point
0140 */
0141 inline Standard_Boolean Bnd_B2x::IsOut (const gp_XY& thePnt) const
0142 {
0143 return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
0144 Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1]);
0145 }
0146
0147 /**
0148 * Intersection Box-Box.
0149 */
0150 inline Standard_Boolean Bnd_B2x::IsOut (const Bnd_B2x& theBox) const
0151 {
0152 return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
0153 Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1]);
0154 }
0155
0156 /**
0157 * Test the complete inclusion of this box in theBox.
0158 */
0159 inline Standard_Boolean Bnd_B2x::IsIn (const Bnd_B2x& theBox) const
0160 {
0161 return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
0162 Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1]);
0163 }
0164