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_)
132 return p.
x()>=minX && p.
x()<=maxX && p.
y()>=minY && p.
y()<=maxY;
144 bool add(std::vector<Point2*>::const_iterator start_it,std::vector<Point2*>::const_iterator end_it)
146 if(start_it==end_it)
return false;
149 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
150 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
152 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
157 treatPointForInvalidBox(**start_it);
159 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
175 bool add(std::vector<Point2>::const_iterator start_it,std::vector<Point2>::const_iterator end_it)
177 if(start_it==end_it)
return false;
180 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
181 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
183 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
188 treatPointForInvalidBox(*start_it);
190 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
205 bool add(
size_t numPoints,
double * coordinates)
207 #if GEOM_PSEUDO3D==GEOM_TRUE
208 const int NUMCOMPONENTS(3);
210 const int NUMCOMPONENTS(2);
213 if(numPoints==0)
return false;
214 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
215 double firstX(coordinates[0]);
216 double firstY(coordinates[1]);
217 if(firstX<minX) minX=firstX;
218 if(firstX>maxX) maxX=firstX;
219 if(firstY<minY) minY=firstY;
220 if(firstY>maxY) maxY=firstY;
222 for(
size_t i=0;i<numPoints;++i)
224 double x(coordinates[NUMCOMPONENTS*i]);
225 double y(coordinates[NUMCOMPONENTS*i+1]);
227 else if(x>maxX) maxX=x;
229 else if(y>maxY) maxY=y;
233 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
250 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
251 treatPointForValidBox(p);
253 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
258 treatPointForInvalidBox(p);
275 if(other.minX<minX) {minX=other.minX;bRet=
true;}
276 if(other.minY<minY) {minY=other.minY;bRet=
true;}
277 if(other.maxX>maxX) {maxX=other.maxX;bRet=
true;}
278 if(other.maxY>maxY) {maxY=other.maxY;bRet=
true;}
323 #if GEOM_PSEUDO3D==GEOM_TRUE
324 return Point2(minX,minY,0);
339 #if GEOM_PSEUDO3D==GEOM_TRUE
340 return Point2(maxX,maxY,0);
354 return (std::min)(minX,minY);
364 return (std::max)(maxX,maxY);
395 double range0=getRangeX();
396 double range1=getRangeY();
397 if(range0>range1)
return range0;
438 void getBounds(
double& minX_,
double& maxX_,
double& minY_,
double& maxY_)
const;
459 if(minX<=maxX && minY<=maxY) bValid=
true;
471 if(minX<=maxX && minY<=maxY) bValid=
true;
483 if(minX<=maxX && minY<=maxY) bValid=
true;
495 if(minX<=maxX && minY<=maxY) bValid=
true;
525 if(minX==maxX) maxX+=val;
526 if(minY==maxY) maxY+=val;
531 inline void treatPointForValidBox(
const Point2& p)
536 else if(x>maxX) maxX=x;
538 else if(y>maxY) maxY=y;
541 inline void treatPointForInvalidBox(
const Point2& p)
544 if(minX==DBL_MAX) minX=p.x();
545 if(minY==DBL_MAX) minY=p.y();
546 if(maxX==-DBL_MAX) maxX=p.x();
547 if(maxY==-DBL_MAX) maxY=p.y();
551 friend std::ostream &
operator<<(std::ostream &stream,
const Bbox2& pC);
559 friend Bbox2
intersection(
const Bbox2& a,
const Bbox2& b);
593 if(b.minX > ret.minX) ret.minX=b.minX;
594 if(b.maxX < ret.maxX) ret.maxX=b.maxX;
595 if(b.minY > ret.minY) ret.minY=b.minY;
596 if(b.maxY < ret.maxY) ret.maxY=b.maxY;
597 if( (ret.minX>ret.maxX) || (ret.minY>ret.maxY) )
622 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:590
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Prints the bounding box to a stream.
Definition: Bbox2.h:620
A 2D axis-aligned bounding box.
Definition: Bbox2.h:39
Point2 getMaxPoint() const
Retrieves the maximum corner point of the bounding box.
Definition: Bbox2.h:337
double getMaxCoord() const
Retrieves the largest coordinate value.
Definition: Bbox2.h:362
bool add(size_t numPoints, double *coordinates)
Adds points to the bounding box.
Definition: Bbox2.h:205
void reset()
Resets the bounds.
Definition: Bbox2.h:62
bool add(const Bbox2 &other)
Adds another bounding box to this one.
Definition: Bbox2.h:272
Bbox2 operator+(const Bbox2 &b)
Adds another bounding box to this one.
Bbox2(GeomTest *pGeomTest_=NULL)
Default constructor.
Definition: Bbox2.h:47
void setMaxX(double val)
Sets the maxX value.
Definition: Bbox2.h:467
void setMaxY(double val)
Sets the maxY value.
Definition: Bbox2.h:491
void getCorners(std::vector< Point2 > &vBoxCorners) const
Retrieves the corners of the bounding box.
bool add(const Point2 &p)
Adds a single point to the bounding box.
Definition: Bbox2.h:245
double getRangeX() const
Retrieves the X-range of the bounding box.
Definition: Bbox2.h:373
Point2 computeCenter() const
Computes the 2D midpoint 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:144
double getMaxRange() const
Retrieves the largest range of the bounding box.
Definition: Bbox2.h:393
void getOffsetCorners(double offset, std::vector< Point2 > &vBoxCorners) const
Retrieves the offset corners of the bounding box.
bool doIntersect(const Bbox2 &other) const
Checks if this bounding box intersects with another.
void doubleTheBox()
Doubles the size of the bounding box.
void getBounds(double &minX_, double &maxX_, double &minY_, double &maxY_) const
Retrieves the bounding box coordinates.
double getRangeY() const
Retrieves the Y-range of the bounding box.
Definition: Bbox2.h:383
double get_minX() const
Retrieves the minX value.
Definition: Bbox2.h:406
void inflateIfDegenerate(double val)
Inflates the bounding box if degenerate.
Definition: Bbox2.h:521
void setMinX(double val)
Sets the minX value.
Definition: Bbox2.h:455
double getMinCoord() const
Retrieves the smallest coordinate value.
Definition: Bbox2.h:352
bool hasOn(const Point2 &p) const
Checks if a query point is included.
Definition: Bbox2.h:130
double get_maxY() const
Retrieves the maxY value.
Definition: Bbox2.h:426
bool isValid() const
Checks if the bounds are valid.
Definition: Bbox2.h:77
void setMinY(double val)
Sets the minY value.
Definition: Bbox2.h:479
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:175
Point2 getMinPoint() const
Retrieves the minimum corner point of the bounding box.
Definition: Bbox2.h:321
bool isInBox(const Point2 &p) const
Checks if a point is inside the bounding box.
double get_maxX() const
Retrieves the maxX value.
Definition: Bbox2.h:419
void getBoundary(std::vector< Segment2 > &vBoundary) const
Retrieves the boundary of the bounding box.
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:412
Represents a 2.5D 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
double y() const
Get the y-coordinate of the Point2.
Definition: Point2.h:250
double x() const
Get the x-coordinate of the Point2.
Definition: Point2.h:239