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
45 explicit Bbox2(GeomTest* pGeomTest_=NULL):
46 minX(DBL_MAX),minY(DBL_MAX),
47 maxX(-DBL_MAX),maxY(-DBL_MAX),
49 bValid(false),pGeomTest(pGeomTest_)
111 bool add(std::vector<Point2*>::const_iterator start_it,std::vector<Point2*>::const_iterator end_it)
113 if(start_it==end_it)
return false;
116 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
117 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
119 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
124 treatPointForInvalidBox(**start_it);
126 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
138 bool add(std::vector<Point2>::const_iterator start_it,std::vector<Point2>::const_iterator end_it)
140 if(start_it==end_it)
return false;
143 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
144 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
146 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
151 treatPointForInvalidBox(*start_it);
153 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
165 bool add(
size_t numPoints,
double * coordinates)
167 #if GEOM_PSEUDO3D==GEOM_TRUE
168 const int NUMCOMPONENTS(3);
170 const int NUMCOMPONENTS(2);
173 if(numPoints==0)
return false;
174 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
175 double firstX(coordinates[0]);
176 double firstY(coordinates[1]);
177 if(firstX<minX) minX=firstX;
178 if(firstX>maxX) maxX=firstX;
179 if(firstY<minY) minY=firstY;
180 if(firstY>maxY) maxY=firstY;
182 for(
size_t i=0;i<numPoints;++i)
184 double x(coordinates[NUMCOMPONENTS*i]);
185 double y(coordinates[NUMCOMPONENTS*i+1]);
187 else if(x>maxX) maxX=x;
189 else if(y>maxY) maxY=y;
193 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
208 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
209 treatPointForValidBox(p);
211 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
216 treatPointForInvalidBox(p);
229 if(other.minX<minX) {minX=other.minX;bRet=
true;}
230 if(other.minY<minY) {minY=other.minY;bRet=
true;}
231 if(other.maxX>maxX) {maxX=other.maxX;bRet=
true;}
232 if(other.maxY>maxY) {maxY=other.maxY;bRet=
true;}
256 #if GEOM_PSEUDO3D==GEOM_TRUE
270 #if GEOM_PSEUDO3D==GEOM_TRUE
271 return Point2(minX,minY,0);
278 #if GEOM_PSEUDO3D==GEOM_TRUE
292 #if GEOM_PSEUDO3D==GEOM_TRUE
293 return Point2(maxX,maxY,0);
306 return (std::min)(minX,minY);
315 return (std::max)(maxX,maxY);
342 double range0=getRangeX();
343 double range1=getRangeY();
344 if(range0>range1)
return range0;
372 void getBounds(
double& minX_,
double& maxX_,
double& minY_,
double& maxY_)
const;
388 if(minX<=maxX && minY<=maxY) bValid=
true;
396 if(minX<=maxX && minY<=maxY) bValid=
true;
404 if(minX<=maxX && minY<=maxY) bValid=
true;
412 if(minX<=maxX && minY<=maxY) bValid=
true;
441 if(minX==maxX) maxX+=val;
442 if(minY==maxY) maxY+=val;
447 inline void treatPointForValidBox(
const Point2& p)
452 else if(x>maxX) maxX=x;
454 else if(y>maxY) maxY=y;
457 inline void treatPointForInvalidBox(
const Point2& p)
460 if(minX==DBL_MAX) minX=p.x();
461 if(minY==DBL_MAX) minY=p.y();
462 if(maxX==-DBL_MAX) maxX=p.x();
463 if(maxY==-DBL_MAX) maxY=p.y();
467 friend std::ostream &
operator<<(std::ostream &stream,
const Bbox2& pC);
494 stream<<
"Bbox2: xy("<<pC.minX<<
","<<pC.minY<<
") -> xy("<<pC.maxX<<
","<<pC.maxY<<
"), rangeX="<<pC.
getRangeX()<<
", rangeY="<<pC.
getRangeY();
Bbox2 getBox(std::vector< Point2 > &vP)
Compute the bounding box.
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Print the box.
Definition: Bbox2.h:492
Bbox2 is an axis aligned 2D bounding box.
Definition: Bbox2.h:37
double getMaxCoord() const
Get maximum coordinate.
Definition: Bbox2.h:313
void doubleTheBox()
Double the box.
bool add(std::vector< Point2 * >::const_iterator start_it, std::vector< Point2 * >::const_iterator end_it)
Add points.
Definition: Bbox2.h:111
void setMaxX(double val)
Set maxX.
Definition: Bbox2.h:392
void getOffsetCorners(double offset, std::vector< Point2 > &vBoxCorners) const
Get offset corners.
void getBoundary(std::vector< Segment2 > &vBoundary) const
Get boundary.
bool add(const Point2 &p)
Add a point.
Definition: Bbox2.h:203
bool add(const Bbox2 &other)
Add another bounding box.
Definition: Bbox2.h:226
void getCorners(std::vector< Point2 > &vBoxCorners) const
Get corners.
bool isInBox(const Point2 &p) const
Point-in-Box Test.
bool add(std::vector< Point2 >::const_iterator start_it, std::vector< Point2 >::const_iterator end_it)
Add points.
Definition: Bbox2.h:138
void reset()
Reset the bounds.
Definition: Bbox2.h:59
double getRangeX() const
Get x-range.
Definition: Bbox2.h:323
Bbox2 operator+(const Bbox2 &b)
Add a bounding box.
double getMaxRange() const
Get max range.
Definition: Bbox2.h:340
double get_minX() const
Get minX.
Definition: Bbox2.h:352
Point2 computeCenter() const
Compute the 2D midpoint.
void setMaxY(double val)
Set maxY.
Definition: Bbox2.h:408
double get_maxX() const
Get maxX.
Definition: Bbox2.h:362
double get_maxY() const
Get maxY.
Definition: Bbox2.h:367
void setMinY(double val)
Set minY.
Definition: Bbox2.h:400
Point2 getMaxPoint() const
Get the max point.
Definition: Bbox2.h:290
void setMinX(double val)
Set minX.
Definition: Bbox2.h:384
void inflateIfDegenerate(double val)
Inflate if Degenerate.
Definition: Bbox2.h:437
bool isValid() const
Check if the bounds are valid.
Definition: Bbox2.h:75
bool doIntersect(const Bbox2 &other) const
Check intersection.
double getRangeY() const
Get y-range.
Definition: Bbox2.h:331
Bbox2(GeomTest *pGeomTest_=NULL)
Constructor.
Definition: Bbox2.h:45
bool add(size_t numPoints, double *coordinates)
Add points.
Definition: Bbox2.h:165
Point2 getMinPoint() const
Get the min point.
Definition: Bbox2.h:268
double getMinCoord() const
Get minimum coordinate.
Definition: Bbox2.h:304
void enlargeRanges(double factor, bool bUseMaxRange, double minRange)
Enlarge the x|y-ranges of a bounding box.
double get_minY() const
Get minY.
Definition: Bbox2.h:357
void getBounds(double &minX_, double &maxX_, double &minY_, double &maxY_) const
Get bounds.
Point.
Definition: Point2.h:43
void xy(double &x_, double &y_) const
Get the x- and y-coordinate.
Definition: Point2.h:245