22 #if GEOM_PSEUDO3D==GEOM_TRUE
23 namespace GEOM_FADE25D {
24 #elif GEOM_PSEUDO3D==GEOM_FALSE
25 namespace GEOM_FADE2D {
27 #error GEOM_PSEUDO3D is not defined
47 explicit Bbox2(GeomTest* pGeomTest_=NULL):
48 minX(DBL_MAX),minY(DBL_MAX),
49 maxX(-DBL_MAX),maxY(-DBL_MAX),
51 bValid(false),pGeomTest(pGeomTest_)
130 bool add(std::vector<Point2*>::const_iterator start_it,std::vector<Point2*>::const_iterator end_it)
132 if(start_it==end_it)
return false;
135 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
136 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
138 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
143 treatPointForInvalidBox(**start_it);
145 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
161 bool add(std::vector<Point2>::const_iterator start_it,std::vector<Point2>::const_iterator end_it)
163 if(start_it==end_it)
return false;
166 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
167 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
169 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
174 treatPointForInvalidBox(*start_it);
176 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
191 bool add(
size_t numPoints,
double * coordinates)
193 #if GEOM_PSEUDO3D==GEOM_TRUE
194 const int NUMCOMPONENTS(3);
196 const int NUMCOMPONENTS(2);
199 if(numPoints==0)
return false;
200 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
201 double firstX(coordinates[0]);
202 double firstY(coordinates[1]);
203 if(firstX<minX) minX=firstX;
204 if(firstX>maxX) maxX=firstX;
205 if(firstY<minY) minY=firstY;
206 if(firstY>maxY) maxY=firstY;
208 for(
size_t i=0;i<numPoints;++i)
210 double x(coordinates[NUMCOMPONENTS*i]);
211 double y(coordinates[NUMCOMPONENTS*i+1]);
213 else if(x>maxX) maxX=x;
215 else if(y>maxY) maxY=y;
219 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
236 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
237 treatPointForValidBox(p);
239 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
244 treatPointForInvalidBox(p);
249 bool add(
const Bbox2& other)
260 if(other.minX<minX) {minX=other.minX;bRet=
true;}
261 if(other.minY<minY) {minY=other.minY;bRet=
true;}
262 if(other.maxX>maxX) {maxX=other.maxX;bRet=
true;}
263 if(other.maxY>maxY) {maxY=other.maxY;bRet=
true;}
308 #if GEOM_PSEUDO3D==GEOM_TRUE
309 return Point2(minX,minY,0);
324 #if GEOM_PSEUDO3D==GEOM_TRUE
325 return Point2(maxX,maxY,0);
339 return (std::min)(minX,minY);
349 return (std::max)(maxX,maxY);
380 double range0=getRangeX();
381 double range1=getRangeY();
382 if(range0>range1)
return range0;
423 void getBounds(
double& minX_,
double& maxX_,
double& minY_,
double& maxY_)
const;
444 if(minX<=maxX && minY<=maxY) bValid=
true;
456 if(minX<=maxX && minY<=maxY) bValid=
true;
468 if(minX<=maxX && minY<=maxY) bValid=
true;
480 if(minX<=maxX && minY<=maxY) bValid=
true;
510 if(minX==maxX) maxX+=val;
511 if(minY==maxY) maxY+=val;
516 inline void treatPointForValidBox(
const Point2& p)
521 else if(x>maxX) maxX=x;
523 else if(y>maxY) maxY=y;
526 inline void treatPointForInvalidBox(
const Point2& p)
529 if(minX==DBL_MAX) minX=p.x();
530 if(minY==DBL_MAX) minY=p.y();
531 if(maxX==-DBL_MAX) maxX=p.x();
532 if(maxY==-DBL_MAX) maxY=p.y();
536 friend std::ostream &
operator<<(std::ostream &stream,
const Bbox2& pC);
544 friend Bbox2
intersection(
const Bbox2& a,
const Bbox2& b);
578 if(b.minX > ret.minX) ret.minX=b.minX;
579 if(b.maxX < ret.maxX) ret.maxX=b.maxX;
580 if(b.minY > ret.minY) ret.minY=b.minY;
581 if(b.maxY < ret.maxY) ret.maxY=b.maxY;
582 if( (ret.minX>ret.maxX) || (ret.minY>ret.maxY) )
607 stream<<
"Bbox2: xy("<<pC.minX<<
","<<pC.minY<<
") -> xy("<<pC.maxX<<
","<<pC.maxY<<
"), rangeX="<<pC.
getRangeX()<<
", rangeY="<<pC.
getRangeY();
Bbox2 getBox(std::vector< Point2 > &vP)
Computes the bounding box of a set of points.
Bbox2 intersection(const Bbox2 &a, const Bbox2 &b)
Computes the intersection of two bounding boxes.
Definition: Bbox2.h:575
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Prints the bounding box to a stream.
Definition: Bbox2.h:605
A 2D axis-aligned bounding box.
Definition: Bbox2.h:39
double getMaxCoord() const
Retrieves the largest coordinate value.
Definition: Bbox2.h:347
void doubleTheBox()
Doubles the size of the bounding box.
bool add(std::vector< Point2 * >::const_iterator start_it, std::vector< Point2 * >::const_iterator end_it)
Adds points to the bounding box.
Definition: Bbox2.h:130
void setMaxX(double val)
Sets the maxX value.
Definition: Bbox2.h:452
void getOffsetCorners(double offset, std::vector< Point2 > &vBoxCorners) const
Retrieves the offset corners of the bounding box.
void getBoundary(std::vector< Segment2 > &vBoundary) const
Retrieves the boundary of the bounding box.
bool add(const Point2 &p)
Adds a single point to the bounding box.
Definition: Bbox2.h:231
void getCorners(std::vector< Point2 > &vBoxCorners) const
Retrieves the corners of the bounding box.
bool isInBox(const Point2 &p) const
Checks if a point is inside the bounding box.
bool add(std::vector< Point2 >::const_iterator start_it, std::vector< Point2 >::const_iterator end_it)
Adds points to the bounding box.
Definition: Bbox2.h:161
void reset()
Resets the bounds.
Definition: Bbox2.h:62
double getRangeX() const
Retrieves the X-range of the bounding box.
Definition: Bbox2.h:358
Bbox2 operator+(const Bbox2 &b)
Adds another bounding box to this one.
double getMaxRange() const
Retrieves the largest range of the bounding box.
Definition: Bbox2.h:378
double get_minX() const
Retrieves the minX value.
Definition: Bbox2.h:391
Point2 computeCenter() const
Computes the 2D midpoint of the bounding box.
void setMaxY(double val)
Sets the maxY value.
Definition: Bbox2.h:476
double get_maxX() const
Retrieves the maxX value.
Definition: Bbox2.h:404
double get_maxY() const
Retrieves the maxY value.
Definition: Bbox2.h:411
void setMinY(double val)
Sets the minY value.
Definition: Bbox2.h:464
Point2 getMaxPoint() const
Retrieves the maximum corner point of the bounding box.
Definition: Bbox2.h:322
void setMinX(double val)
Sets the minX value.
Definition: Bbox2.h:440
void inflateIfDegenerate(double val)
Inflates the bounding box if degenerate.
Definition: Bbox2.h:506
bool isValid() const
Checks if the bounds are valid.
Definition: Bbox2.h:77
bool doIntersect(const Bbox2 &other) const
Checks if this bounding box intersects with another.
double getRangeY() const
Retrieves the Y-range of the bounding box.
Definition: Bbox2.h:368
Bbox2(GeomTest *pGeomTest_=NULL)
Default constructor.
Definition: Bbox2.h:47
bool add(size_t numPoints, double *coordinates)
Adds points to the bounding box.
Definition: Bbox2.h:191
Point2 getMinPoint() const
Retrieves the minimum corner point of the bounding box.
Definition: Bbox2.h:306
double getMinCoord() const
Retrieves the smallest coordinate value.
Definition: Bbox2.h:337
void enlargeRanges(double factor, bool bUseMaxRange, double minRange)
Enlarges the bounding box's ranges symmetrically.
double get_minY() const
Retrieves the minY value.
Definition: Bbox2.h:397
void getBounds(double &minX_, double &maxX_, double &minY_, double &maxY_) const
Retrieves the bounding box coordinates.
Represents a 2D point.
Definition: Point2.h:76
void xy(double &x_, double &y_) const
Get the x- and y- coordinates of the Point2.
Definition: Point2.h:291