diff -r 8f1c317ebeb4 -r b79bcba43661 lemon/xy.h --- a/lemon/xy.h Tue Jul 26 13:15:13 2005 +0000 +++ b/lemon/xy.h Tue Jul 26 14:31:29 2005 +0000 @@ -306,7 +306,7 @@ } ///Increments a bounding box with a point - BoundingBox& operator +=(const xy& u){ + BoundingBox& add(const xy& u){ if (_empty){ bottom_left=top_right=u; _empty = false; @@ -320,17 +320,17 @@ return *this; } - ///Sums a bounding box and a point - BoundingBox operator +(const xy& u){ - BoundingBox b = *this; - return b += u; - } +// ///Sums a bounding box and a point +// BoundingBox operator +(const xy& u){ +// BoundingBox b = *this; +// return b += u; +// } ///Increments a bounding box with an other bounding box - BoundingBox& operator +=(const BoundingBox &u){ + BoundingBox& add(const BoundingBox &u){ if ( !u.empty() ){ - *this += u.bottomLeft(); - *this += u.topRight(); + this->add(u.bottomLeft()); + this->add(u.topRight()); } return *this; } @@ -338,7 +338,20 @@ ///Sums two bounding boxes BoundingBox operator +(const BoundingBox& u){ BoundingBox b = *this; - return b += u; + return b.add(u); + } + + + ///Intersection of two bounding boxes + BoundingBox operator &(const BoundingBox& u){ + BoundingBox b; + b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x); + b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y); + b.top_right.x=std::min(this->top_right.x,u.top_right.x); + b.top_right.y=std::min(this->top_right.y,u.top_right.y); + b._empty = this->_empty || u._empty || + b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y; + return b; } };//class Boundingbox