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),
48 bValid(false),pGeomTest(pGeomTest_)
98 bool add(std::vector<Point2*>::const_iterator start_it,std::vector<Point2*>::const_iterator end_it)
100 if(start_it==end_it)
return false;
103 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
104 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
105 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
110 treatPointForInvalidBox(**start_it);
112 for(;start_it!=end_it;++start_it) treatPointForValidBox(**start_it);
122 bool add(std::vector<Point2>::const_iterator start_it,std::vector<Point2>::const_iterator end_it)
124 if(start_it==end_it)
return false;
127 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
128 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
129 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
134 treatPointForInvalidBox(*start_it);
136 for(;start_it!=end_it;++start_it) treatPointForValidBox(*start_it);
147 bool add(
size_t numPoints,
double * coordinates)
149 #if GEOM_PSEUDO3D==GEOM_TRUE
150 const int NUMCOMPONENTS(3);
152 const int NUMCOMPONENTS(2);
155 if(numPoints==0)
return false;
156 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
157 double firstX(coordinates[0]);
158 double firstY(coordinates[1]);
159 if(firstX<minX) minX=firstX;
160 if(firstX>maxX) maxX=firstX;
161 if(firstY<minY) minY=firstY;
162 if(firstY>maxY) maxY=firstY;
164 for(
size_t i=0;i<numPoints;++i)
166 double x(coordinates[NUMCOMPONENTS*i]);
167 double y(coordinates[NUMCOMPONENTS*i+1]);
169 else if(x>maxX) maxX=x;
171 else if(y>maxY) maxY=y;
174 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
189 double oldMinX(minX),oldMinY(minY),oldMaxX(maxX),oldMaxY(maxY);
190 treatPointForValidBox(p);
191 if(oldMinX!=minX || oldMinY!=minY || oldMaxX!=maxX || oldMaxY!=maxY )
return true;
196 treatPointForInvalidBox(p);
220 #if GEOM_PSEUDO3D==GEOM_TRUE
234 #if GEOM_PSEUDO3D==GEOM_TRUE
235 return Point2(minX,minY,0);
242 #if GEOM_PSEUDO3D==GEOM_TRUE
256 #if GEOM_PSEUDO3D==GEOM_TRUE
257 return Point2(maxX,maxY,0);
270 return (std::min)(minX,minY);
279 return (std::max)(maxX,maxY);
307 double range0=getRangeX();
308 double range1=getRangeY();
309 if(range0>range1)
return range0;
337 void getBounds(
double& minX_,
double& maxX_,
double& minY_,
double& maxY_)
const;
352 if(minX<=maxX && minY<=maxY) bValid=
true;
359 if(minX<=maxX && minY<=maxY) bValid=
true;
366 if(minX<=maxX && minY<=maxY) bValid=
true;
373 if(minX<=maxX && minY<=maxY) bValid=
true;
402 if(minX==maxX) maxX+=val;
403 if(minY==maxY) maxY+=val;
407 inline void treatPointForValidBox(
const Point2& p)
412 else if(x>maxX) maxX=x;
414 else if(y>maxY) maxY=y;
416 inline void treatPointForInvalidBox(
const Point2& p)
419 if(minX==DBL_MAX) minX=p.x();
420 if(minY==DBL_MAX) minY=p.y();
421 if(maxX==-DBL_MAX) maxX=p.x();
422 if(maxY==-DBL_MAX) maxY=p.y();
425 friend std::ostream &
operator<<(std::ostream &stream,
const Bbox2& pC);
452 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:450
Bbox2 is an axis aligned 2D bounding box.
Definition: Bbox2.h:37
double getMaxCoord() const
Get maximum coordinate.
Definition: Bbox2.h:277
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:98
void setMaxX(double val)
Set maxX.
Definition: Bbox2.h:356
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:184
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:122
double getRangeX() const
Get x-range.
Definition: Bbox2.h:287
Bbox2 operator+(const Bbox2 &b)
Add a bounding box.
double getMaxRange() const
Get max range.
Definition: Bbox2.h:305
double get_minX() const
Get minX.
Definition: Bbox2.h:317
Point2 computeCenter() const
Compute the 2D midpoint.
void setMaxY(double val)
Set maxY.
Definition: Bbox2.h:370
double get_maxX() const
Get maxX.
Definition: Bbox2.h:327
double get_maxY() const
Get maxY.
Definition: Bbox2.h:332
void setMinY(double val)
Set minY.
Definition: Bbox2.h:363
Point2 getMaxPoint() const
Get the max point.
Definition: Bbox2.h:254
void setMinX(double val)
Set minX.
Definition: Bbox2.h:349
void inflateIfDegenerate(double val)
Inflate if Degenerate.
Definition: Bbox2.h:398
bool isValid() const
Check if the bounds are valid.
Definition: Bbox2.h:61
bool doIntersect(const Bbox2 &other) const
Check intersection.
double getRangeY() const
Get y-range.
Definition: Bbox2.h:295
Bbox2(GeomTest *pGeomTest_=NULL)
Constructor.
Definition: Bbox2.h:45
bool add(size_t numPoints, double *coordinates)
Add points.
Definition: Bbox2.h:147
Point2 getMinPoint() const
Get the min point.
Definition: Bbox2.h:232
double getMinCoord() const
Get minimum coordinate.
Definition: Bbox2.h:268
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:322
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