|
|
|||
File indexing completed on 2026-06-07 08:30:25
0001 // Created on: 1991-01-28 0002 // Created by: Remi Lequette 0003 // Copyright (c) 1991-1999 Matra Datavision 0004 // Copyright (c) 1999-2012 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Bnd_Box2d_HeaderFile 0018 #define _Bnd_Box2d_HeaderFile 0019 0020 #include <gp_Lin2d.hxx> 0021 #include <gp_Pnt2d.hxx> 0022 #include <Standard.hxx> 0023 #include <Standard_DefineAlloc.hxx> 0024 #include <Standard_Handle.hxx> 0025 0026 #include <Standard_Real.hxx> 0027 #include <Standard_Integer.hxx> 0028 #include <Standard_Boolean.hxx> 0029 class gp_Dir2d; 0030 class gp_Trsf2d; 0031 0032 //! Describes a bounding box in 2D space. 0033 //! A bounding box is parallel to the axes of the coordinates 0034 //! system. If it is finite, it is defined by the two intervals: 0035 //! - [ Xmin,Xmax ], and 0036 //! - [ Ymin,Ymax ]. 0037 //! A bounding box may be infinite (i.e. open) in one or more 0038 //! directions. It is said to be: 0039 //! - OpenXmin if it is infinite on the negative side of the "X Direction"; 0040 //! - OpenXmax if it is infinite on the positive side of the "X Direction"; 0041 //! - OpenYmin if it is infinite on the negative side of the "Y Direction"; 0042 //! - OpenYmax if it is infinite on the positive side of the "Y Direction"; 0043 //! - WholeSpace if it is infinite in all four directions. In 0044 //! this case, any point of the space is inside the box; 0045 //! - Void if it is empty. In this case, there is no point included in the box. 0046 //! A bounding box is defined by four bounds (Xmin, Xmax, Ymin and Ymax) which 0047 //! limit the bounding box if it is finite, six flags (OpenXmin, OpenXmax, OpenYmin, 0048 //! OpenYmax, WholeSpace and Void) which describe the bounding box if it is infinite or empty, and 0049 //! - a gap, which is included on both sides in any direction when consulting the finite bounds of 0050 //! the box. 0051 class Bnd_Box2d 0052 { 0053 public: 0054 DEFINE_STANDARD_ALLOC 0055 0056 //! Creates an empty 2D bounding box. 0057 //! The constructed box is qualified Void. Its gap is null. 0058 Bnd_Box2d() 0059 : Xmin(0.), 0060 Xmax(0.), 0061 Ymin(0.), 0062 Ymax(0.), 0063 Gap(0.), 0064 Flags(VoidMask) 0065 { 0066 } 0067 0068 //! Sets this bounding box so that it covers the whole 2D 0069 //! space, i.e. it is infinite in all directions. 0070 void SetWhole() { Flags = WholeMask; } 0071 0072 //! Sets this 2D bounding box so that it is empty. All points are outside a void box. 0073 void SetVoid() 0074 { 0075 Flags = VoidMask; 0076 Gap = 0.0; 0077 } 0078 0079 //! Sets this 2D bounding box so that it bounds 0080 //! the point P. This involves first setting this bounding box 0081 //! to be void and then adding the point PThe rectangle bounds the point <P>. 0082 void Set(const gp_Pnt2d& thePnt) 0083 { 0084 Flags = VoidMask; 0085 Gap = 0.0; 0086 Add(thePnt); 0087 } 0088 0089 //! Sets this 2D bounding box so that it bounds 0090 //! the half-line defined by point P and direction D, i.e. all 0091 //! points M defined by M=P+u*D, where u is greater than 0092 //! or equal to 0, are inside the bounding area. This involves 0093 //! first setting this 2D box to be void and then adding the half-line. 0094 void Set(const gp_Pnt2d& thePnt, const gp_Dir2d& theDir) 0095 { 0096 Flags = VoidMask; 0097 Gap = 0.0; 0098 Add(thePnt, theDir); 0099 } 0100 0101 //! Enlarges this 2D bounding box, if required, so that it 0102 //! contains at least: 0103 //! - interval [ aXmin,aXmax ] in the "X Direction", 0104 //! - interval [ aYmin,aYmax ] in the "Y Direction" 0105 Standard_EXPORT void Update(const Standard_Real aXmin, 0106 const Standard_Real aYmin, 0107 const Standard_Real aXmax, 0108 const Standard_Real aYmax); 0109 0110 //! Adds a point of coordinates (X,Y) to this bounding box. 0111 Standard_EXPORT void Update(const Standard_Real X, const Standard_Real Y); 0112 0113 //! Returns the gap of this 2D bounding box. 0114 Standard_Real GetGap() const { return Gap; } 0115 0116 //! Set the gap of this 2D bounding box to abs(Tol). 0117 void SetGap(const Standard_Real Tol) { Gap = Tol; } 0118 0119 //! Enlarges the box with a tolerance value. 0120 //! This means that the minimum values of its X and Y 0121 //! intervals of definition, when they are finite, are reduced by 0122 //! the absolute value of Tol, while the maximum values are 0123 //! increased by the same amount. 0124 void Enlarge(const Standard_Real theTol) 0125 { 0126 Standard_Real aTol = theTol < 0.0 ? -theTol : theTol; 0127 if (Gap < aTol) 0128 Gap = aTol; 0129 } 0130 0131 //! Returns the bounds of this 2D bounding box. 0132 //! The gap is included. If this bounding box is infinite (i.e. "open"), returned values 0133 //! may be equal to +/- Precision::Infinite(). 0134 //! if IsVoid() 0135 Standard_EXPORT void Get(Standard_Real& aXmin, 0136 Standard_Real& aYmin, 0137 Standard_Real& aXmax, 0138 Standard_Real& aYmax) const; 0139 0140 //! The Box will be infinitely long in the Xmin direction. 0141 void OpenXmin() { Flags |= XminMask; } 0142 0143 //! The Box will be infinitely long in the Xmax direction. 0144 void OpenXmax() { Flags |= XmaxMask; } 0145 0146 //! The Box will be infinitely long in the Ymin direction. 0147 void OpenYmin() { Flags |= YminMask; } 0148 0149 //! The Box will be infinitely long in the Ymax direction. 0150 void OpenYmax() { Flags |= YmaxMask; } 0151 0152 //! Returns true if this bounding box is open in the Xmin direction. 0153 Standard_Boolean IsOpenXmin() const { return (Flags & XminMask) != 0; } 0154 0155 //! Returns true if this bounding box is open in the Xmax direction. 0156 Standard_Boolean IsOpenXmax() const { return (Flags & XmaxMask) != 0; } 0157 0158 //! Returns true if this bounding box is open in the Ymin direction. 0159 Standard_Boolean IsOpenYmin() const { return (Flags & YminMask) != 0; } 0160 0161 //! Returns true if this bounding box is open in the Ymax direction. 0162 Standard_Boolean IsOpenYmax() const { return (Flags & YmaxMask) != 0; } 0163 0164 //! Returns true if this bounding box is infinite in all 4 0165 //! directions (Whole Space flag). 0166 Standard_Boolean IsWhole() const { return (Flags & WholeMask) == WholeMask; } 0167 0168 //! Returns true if this 2D bounding box is empty (Void flag). 0169 Standard_Boolean IsVoid() const { return (Flags & VoidMask) != 0; } 0170 0171 //! Returns a bounding box which is the result of applying the 0172 //! transformation T to this bounding box. 0173 //! Warning 0174 //! Applying a geometric transformation (for example, a 0175 //! rotation) to a bounding box generally increases its 0176 //! dimensions. This is not optimal for algorithms which use it. 0177 Standard_NODISCARD Standard_EXPORT Bnd_Box2d Transformed(const gp_Trsf2d& T) const; 0178 0179 //! Adds the 2d box <Other> to <me>. 0180 Standard_EXPORT void Add(const Bnd_Box2d& Other); 0181 0182 //! Adds the 2d point. 0183 void Add(const gp_Pnt2d& thePnt) { Update(thePnt.X(), thePnt.Y()); } 0184 0185 //! Extends bounding box from thePnt in the direction theDir. 0186 void Add(const gp_Pnt2d& thePnt, const gp_Dir2d& theDir) 0187 { 0188 Add(thePnt); 0189 Add(theDir); 0190 } 0191 0192 //! Extends the Box in the given Direction, i.e. adds 0193 //! a half-line. The box may become infinite in 1 or 2 0194 //! directions. 0195 Standard_EXPORT void Add(const gp_Dir2d& D); 0196 0197 //! Returns True if the 2d pnt <P> is out <me>. 0198 Standard_EXPORT Standard_Boolean IsOut(const gp_Pnt2d& P) const; 0199 0200 //! Returns True if the line doesn't intersect the box. 0201 Standard_EXPORT Standard_Boolean IsOut(const gp_Lin2d& theL) const; 0202 0203 //! Returns True if the segment doesn't intersect the box. 0204 Standard_EXPORT Standard_Boolean IsOut(const gp_Pnt2d& theP0, const gp_Pnt2d& theP1) const; 0205 0206 //! Returns True if <Box2d> is out <me>. 0207 Standard_EXPORT Standard_Boolean IsOut(const Bnd_Box2d& Other) const; 0208 0209 //! Returns True if transformed <Box2d> is out <me>. 0210 Standard_Boolean IsOut(const Bnd_Box2d& theOther, const gp_Trsf2d& theTrsf) const 0211 { 0212 return IsOut(theOther.Transformed(theTrsf)); 0213 } 0214 0215 //! Compares a transformed bounding with a transformed 0216 //! bounding. The default implementation is to make a copy 0217 //! of <me> and <Other>, to transform them and to test. 0218 Standard_Boolean IsOut(const gp_Trsf2d& T1, const Bnd_Box2d& Other, const gp_Trsf2d& T2) const 0219 { 0220 return Transformed(T1).IsOut(Other.Transformed(T2)); 0221 } 0222 0223 Standard_EXPORT void Dump() const; 0224 0225 //! Computes the squared diagonal of me. 0226 Standard_Real SquareExtent() const 0227 { 0228 if (IsVoid()) 0229 return 0.0; 0230 const Standard_Real aDx = Xmax - Xmin + Gap + Gap; 0231 const Standard_Real aDy = Ymax - Ymin + Gap + Gap; 0232 return aDx * aDx + aDy * aDy; 0233 } 0234 0235 protected: 0236 //! Bit flags. 0237 enum MaskFlags 0238 { 0239 VoidMask = 0x01, 0240 XminMask = 0x02, 0241 XmaxMask = 0x04, 0242 YminMask = 0x08, 0243 YmaxMask = 0x10, 0244 WholeMask = 0x1e 0245 }; 0246 0247 private: 0248 Standard_Real Xmin; 0249 Standard_Real Xmax; 0250 Standard_Real Ymin; 0251 Standard_Real Ymax; 0252 Standard_Real Gap; 0253 Standard_Integer Flags; 0254 }; 0255 0256 #endif // _Bnd_Box2d_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|