lemon/xy.h
changeset 1634 910b1bcb7d05
parent 1435 8e85e6bbefdf
child 1706 163746ec3094
equal deleted inserted replaced
0:779c31ffc30b 1:4413804cc849
   304               (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
   304               (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
   305         }
   305         }
   306       }
   306       }
   307   
   307   
   308       ///Increments a bounding box with a point
   308       ///Increments a bounding box with a point
   309       BoundingBox& operator +=(const xy<T>& u){
   309       BoundingBox& add(const xy<T>& u){
   310         if (_empty){
   310         if (_empty){
   311           bottom_left=top_right=u;
   311           bottom_left=top_right=u;
   312           _empty = false;
   312           _empty = false;
   313         }
   313         }
   314         else{
   314         else{
   318           if (top_right.y < u.y) top_right.y = u.y;
   318           if (top_right.y < u.y) top_right.y = u.y;
   319         }
   319         }
   320         return *this;
   320         return *this;
   321       }
   321       }
   322   
   322   
   323       ///Sums a bounding box and a point
   323 //       ///Sums a bounding box and a point
   324       BoundingBox operator +(const xy<T>& u){
   324 //       BoundingBox operator +(const xy<T>& u){
   325         BoundingBox b = *this;
   325 //         BoundingBox b = *this;
   326         return b += u;
   326 //         return b += u;
   327       }
   327 //       }
   328 
   328 
   329       ///Increments a bounding box with an other bounding box
   329       ///Increments a bounding box with an other bounding box
   330       BoundingBox& operator +=(const BoundingBox &u){
   330       BoundingBox& add(const BoundingBox &u){
   331         if ( !u.empty() ){
   331         if ( !u.empty() ){
   332           *this += u.bottomLeft();
   332           this->add(u.bottomLeft());
   333           *this += u.topRight();
   333 	  this->add(u.topRight());
   334         }
   334         }
   335         return *this;
   335         return *this;
   336       }
   336       }
   337   
   337   
   338       ///Sums two bounding boxes
   338       ///Sums two bounding boxes
   339       BoundingBox operator +(const BoundingBox& u){
   339       BoundingBox operator +(const BoundingBox& u){
   340         BoundingBox b = *this;
   340         BoundingBox b = *this;
   341         return b += u;
   341         return b.add(u);
       
   342       }
       
   343 
       
   344 
       
   345       ///Intersection of two bounding boxes
       
   346       BoundingBox operator &(const BoundingBox& u){
       
   347         BoundingBox b;
       
   348 	b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
       
   349 	b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
       
   350 	b.top_right.x=std::min(this->top_right.x,u.top_right.x);
       
   351 	b.top_right.y=std::min(this->top_right.y,u.top_right.y);
       
   352 	b._empty = this->_empty || u._empty ||
       
   353 	  b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y;
       
   354         return b;
   342       }
   355       }
   343 
   356 
   344     };//class Boundingbox
   357     };//class Boundingbox
   345 
   358 
   346 
   359