COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/dim2.h

    r241 r220  
    2121
    2222#include <iostream>
     23#include <lemon/core.h>
    2324
    2425///\ingroup misc
     
    4546  /// @{
    4647
    47   /// A simple two dimensional vector (plain vector) implementation
    48 
    49   /// A simple two dimensional vector (plain vector) implementation
     48  /// A simple two dimensional vector (plainvector) implementation
     49
     50  /// A simple two dimensional vector (plainvector) implementation
    5051  /// with the usual vector operations.
    5152  template<typename T>
     
    186187  }
    187188
    188   ///Read a plain vector from a stream
    189 
    190   ///Read a plain vector from a stream.
     189  ///Read a plainvector from a stream
     190
     191  ///Read a plainvector from a stream.
    191192  ///\relates Point
    192193  ///
     
    214215  }
    215216
    216   ///Write a plain vector to a stream
    217 
    218   ///Write a plain vector to a stream.
     217  ///Write a plainvector to a stream
     218
     219  ///Write a plainvector to a stream.
    219220  ///\relates Point
    220221  ///
     
    261262
    262263
    263     /// A class to calculate or store the bounding box of plain vectors.
    264 
    265     /// A class to calculate or store the bounding box of plain vectors.
    266     ///
     264  /// A class to calculate or store the bounding box of plainvectors.
     265
     266  /// A class to calculate or store the bounding box of plainvectors.
     267  ///
    267268    template<typename T>
    268269    class BoundingBox {
    269       Point<T> _bottom_left, _top_right;
     270      Point<T> bottom_left, top_right;
    270271      bool _empty;
    271272    public:
     
    275276
    276277      ///Construct an instance from one point
    277       BoundingBox(Point<T> a) {
    278         _bottom_left = _top_right = a;
    279         _empty = false;
    280       }
     278      BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
    281279
    282280      ///Construct an instance from two points
     
    289287      BoundingBox(Point<T> a,Point<T> b)
    290288      {
    291         _bottom_left = a;
    292         _top_right = b;
     289        bottom_left=a;
     290        top_right=b;
    293291        _empty = false;
    294292      }
     
    305303      BoundingBox(T l,T b,T r,T t)
    306304      {
    307         _bottom_left=Point<T>(l,b);
    308         _top_right=Point<T>(r,t);
     305        bottom_left=Point<T>(l,b);
     306        top_right=Point<T>(r,t);
    309307        _empty = false;
    310308      }
     
    323321      ///Make the BoundingBox empty
    324322      void clear() {
    325         _empty = true;
     323        _empty=1;
    326324      }
    327325
     
    331329      ///If the bounding box is empty, then the return value is not defined.
    332330      Point<T> bottomLeft() const {
    333         return _bottom_left;
     331        return bottom_left;
    334332      }
    335333
     
    337335
    338336      ///Set the bottom left corner of the box.
    339       ///\pre The box must not be empty.
     337      ///It should only be used for non-empty box.
    340338      void bottomLeft(Point<T> p) {
    341         _bottom_left = p;
     339        bottom_left = p;
    342340      }
    343341
     
    347345      ///If the bounding box is empty, then the return value is not defined.
    348346      Point<T> topRight() const {
    349         return _top_right;
     347        return top_right;
    350348      }
    351349
     
    353351
    354352      ///Set the top right corner of the box.
    355       ///\pre The box must not be empty.
     353      ///It should only be used for non-empty box.
    356354      void topRight(Point<T> p) {
    357         _top_right = p;
     355        top_right = p;
    358356      }
    359357
     
    363361      ///If the bounding box is empty, then the return value is not defined.
    364362      Point<T> bottomRight() const {
    365         return Point<T>(_top_right.x,_bottom_left.y);
     363        return Point<T>(top_right.x,bottom_left.y);
    366364      }
    367365
     
    369367
    370368      ///Set the bottom right corner of the box.
    371       ///\pre The box must not be empty.
     369      ///It should only be used for non-empty box.
    372370      void bottomRight(Point<T> p) {
    373         _top_right.x = p.x;
    374         _bottom_left.y = p.y;
     371        top_right.x = p.x;
     372        bottom_left.y = p.y;
    375373      }
    376374
     
    380378      ///If the bounding box is empty, then the return value is not defined.
    381379      Point<T> topLeft() const {
    382         return Point<T>(_bottom_left.x,_top_right.y);
     380        return Point<T>(bottom_left.x,top_right.y);
    383381      }
    384382
     
    386384
    387385      ///Set the top left corner of the box.
    388       ///\pre The box must not be empty.
     386      ///It should only be used for non-empty box.
    389387      void topLeft(Point<T> p) {
    390         _top_right.y = p.y;
    391         _bottom_left.x = p.x;
     388        top_right.y = p.y;
     389        bottom_left.x = p.x;
    392390      }
    393391
     
    397395      ///If the bounding box is empty, then the return value is not defined.
    398396      T bottom() const {
    399         return _bottom_left.y;
     397        return bottom_left.y;
    400398      }
    401399
     
    403401
    404402      ///Set the bottom of the box.
    405       ///\pre The box must not be empty.
     403      ///It should only be used for non-empty box.
    406404      void bottom(T t) {
    407         _bottom_left.y = t;
     405        bottom_left.y = t;
    408406      }
    409407
     
    413411      ///If the bounding box is empty, then the return value is not defined.
    414412      T top() const {
    415         return _top_right.y;
     413        return top_right.y;
    416414      }
    417415
     
    419417
    420418      ///Set the top of the box.
    421       ///\pre The box must not be empty.
     419      ///It should only be used for non-empty box.
    422420      void top(T t) {
    423         _top_right.y = t;
     421        top_right.y = t;
    424422      }
    425423
     
    429427      ///If the bounding box is empty, then the return value is not defined.
    430428      T left() const {
    431         return _bottom_left.x;
     429        return bottom_left.x;
    432430      }
    433431
     
    435433
    436434      ///Set the left side of the box.
    437       ///\pre The box must not be empty.
     435      ///It should only be used for non-empty box.
    438436      void left(T t) {
    439         _bottom_left.x = t;
     437        bottom_left.x = t;
    440438      }
    441439
     
    445443      ///If the bounding box is empty, then the return value is not defined.
    446444      T right() const {
    447         return _top_right.x;
     445        return top_right.x;
    448446      }
    449447
     
    451449
    452450      ///Set the right side of the box.
    453       ///\pre The box must not be empty.
     451      ///It should only be used for non-empty box.
    454452      void right(T t) {
    455         _top_right.x = t;
     453        top_right.x = t;
    456454      }
    457455
     
    461459      ///If the bounding box is empty, then the return value is not defined.
    462460      T height() const {
    463         return _top_right.y-_bottom_left.y;
     461        return top_right.y-bottom_left.y;
    464462      }
    465463
     
    469467      ///If the bounding box is empty, then the return value is not defined.
    470468      T width() const {
    471         return _top_right.x-_bottom_left.x;
     469        return top_right.x-bottom_left.x;
    472470      }
    473471
     
    476474        if (_empty)
    477475          return false;
    478         else {
    479           return ( (u.x-_bottom_left.x)*(_top_right.x-u.x) >= 0 &&
    480                    (u.y-_bottom_left.y)*(_top_right.y-u.y) >= 0 );
     476        else{
     477          return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
     478              (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
    481479        }
    482480      }
     
    487485      ///
    488486      BoundingBox& add(const Point<T>& u){
    489         if (_empty) {
    490           _bottom_left = _top_right = u;
     487        if (_empty){
     488          bottom_left=top_right=u;
    491489          _empty = false;
    492490        }
    493         else {
    494           if (_bottom_left.x > u.x) _bottom_left.x = u.x;
    495           if (_bottom_left.y > u.y) _bottom_left.y = u.y;
    496           if (_top_right.x < u.x) _top_right.x = u.x;
    497           if (_top_right.y < u.y) _top_right.y = u.y;
     491        else{
     492          if (bottom_left.x > u.x) bottom_left.x = u.x;
     493          if (bottom_left.y > u.y) bottom_left.y = u.y;
     494          if (top_right.x < u.x) top_right.x = u.x;
     495          if (top_right.y < u.y) top_right.y = u.y;
    498496        }
    499497        return *this;
     
    506504      BoundingBox& add(const BoundingBox &u){
    507505        if ( !u.empty() ){
    508           add(u._bottom_left);
    509           add(u._top_right);
     506          this->add(u.bottomLeft());
     507          this->add(u.topRight());
    510508        }
    511509        return *this;
     
    518516      BoundingBox operator&(const BoundingBox& u) const {
    519517        BoundingBox b;
    520         if (_empty || u._empty) {
     518        if (this->_empty || u._empty) {
    521519          b._empty = true;
    522520        } else {
    523           b._bottom_left.x = std::max(_bottom_left.x, u._bottom_left.x);
    524           b._bottom_left.y = std::max(_bottom_left.y, u._bottom_left.y);
    525           b._top_right.x = std::min(_top_right.x, u._top_right.x);
    526           b._top_right.y = std::min(_top_right.y, u._top_right.y);
    527           b._empty = b._bottom_left.x > b._top_right.x ||
    528                      b._bottom_left.y > b._top_right.y;
     521          b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
     522          b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
     523          b.top_right.x = std::min(this->top_right.x,u.top_right.x);
     524          b.top_right.y = std::min(this->top_right.y,u.top_right.y);
     525          b._empty = b.bottom_left.x > b.top_right.x ||
     526                     b.bottom_left.y > b.top_right.y;
    529527        }
    530528        return b;
Note: See TracChangeset for help on using the changeset viewer.