COIN-OR::LEMON - Graph Library

Changeset 2562:27c54b7f4f1d in lemon-0.x


Ignore:
Timestamp:
02/05/08 12:23:23 (12 years ago)
Author:
Peter Kovacs
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3443
Message:

Improvements and fixes in dim2.h.

  • Several doc improvements.
  • Fix BoundingBox::operator& implementation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/dim2.h

    r2553 r2562  
    5353
    5454  /// A simple two dimensional vector (plainvector) implementation
    55   ///with the usual vector
    56   /// operators.
    57   ///
     55  /// with the usual vector operations.
    5856  template<typename T>
    5957    class Point {
     
    6361      typedef T Value;
    6462
    65       ///First co-ordinate
     63      ///First coordinate
    6664      T x;
    67       ///Second co-ordinate
     65      ///Second coordinate
    6866      T y;     
    6967     
     
    7674      ///The dimension of the vector.
    7775
    78       ///This class give back always 2.
     76      ///This function always returns 2.
    7977      ///
    8078      int size() const { return 2; }
     
    10098      }
    10199 
    102       ///Increment the left hand side by u
     100      ///Increment the left hand side by \c u
    103101      Point<T>& operator +=(const Point<T>& u) {
    104102        x += u.x;
     
    107105      }
    108106 
    109       ///Decrement the left hand side by u
     107      ///Decrement the left hand side by \c u
    110108      Point<T>& operator -=(const Point<T>& u) {
    111109        x -= u.x;
     
    139137      }
    140138
    141       ///Return the neg of the vectors
     139      ///Return the negative of the vector
    142140      Point<T> operator-() const {
    143141        Point<T> b=*this;
     
    176174    };
    177175
    178   ///Return an Point
    179 
    180   ///Return an Point
     176  ///Return a Point
     177
     178  ///Return a Point.
    181179  ///\relates Point
    182180  template <typename T>
     
    287285      ///Construct an instance from two points
    288286     
    289       ///Construct an instance from two points
    290       ///\warning The coordinates of the bottom-left corner must be no more
    291       ///than those of the top-right one
     287      ///Construct an instance from two points.
     288      ///\param a The bottom left corner.
     289      ///\param b The top right corner.
     290      ///\warning The coordinates of the bottom left corner must be no more
     291      ///than those of the top right one.
    292292      BoundingBox(Point<T> a,Point<T> b)
    293293      {
     
    299299      ///Construct an instance from four numbers
    300300
    301       ///Construct an instance from four numbers
    302       ///\warning The coordinates of the bottom-left corner must be no more
    303       ///than those of the top-right one
     301      ///Construct an instance from four numbers.
     302      ///\param l The left side of the box.
     303      ///\param b The bottom of the box.
     304      ///\param r The right side of the box.
     305      ///\param t The top of the box.
     306      ///\warning The left side must be no more than the right side and
     307      ///bottom must be no more than the top.
    304308      BoundingBox(T l,T b,T r,T t)
    305309      {
     
    309313      }
    310314     
    311       ///Were any points added?
     315      ///Return \c true if the bounding box is empty.
     316     
     317      ///Return \c true if the bounding box is empty (i.e. return \c false
     318      ///if at least one point was added to the box or the coordinates of
     319      ///the box were set).
     320      ///
     321      ///The coordinates of an empty bounding box are not defined.
    312322      bool empty() const {
    313323        return _empty;
     
    319329      }
    320330
    321       ///Give back the bottom left corner
    322 
    323       ///Give back the bottom left corner.
     331      ///Give back the bottom left corner of the box
     332
     333      ///Give back the bottom left corner of the box.
    324334      ///If the bounding box is empty, then the return value is not defined.
    325335      Point<T> bottomLeft() const {
     
    327337      }
    328338
    329       ///Set the bottom left corner
    330 
    331       ///Set the bottom left corner.
    332       ///It should only bee used for non-empty box.
     339      ///Set the bottom left corner of the box
     340
     341      ///Set the bottom left corner of the box.
     342      ///It should only be used for non-empty box.
    333343      void bottomLeft(Point<T> p) {
    334344        bottom_left = p;
    335345      }
    336346
    337       ///Give back the top right corner
    338 
    339       ///Give back the top right corner.
     347      ///Give back the top right corner of the box
     348
     349      ///Give back the top right corner of the box.
    340350      ///If the bounding box is empty, then the return value is not defined.
    341351      Point<T> topRight() const {
     
    343353      }
    344354
    345       ///Set the top right corner
    346 
    347       ///Set the top right corner.
    348       ///It should only bee used for non-empty box.
     355      ///Set the top right corner of the box
     356
     357      ///Set the top right corner of the box.
     358      ///It should only be used for non-empty box.
    349359      void topRight(Point<T> p) {
    350360        top_right = p;
    351361      }
    352362
    353       ///Give back the bottom right corner
    354 
    355       ///Give back the bottom right corner.
     363      ///Give back the bottom right corner of the box
     364
     365      ///Give back the bottom right corner of the box.
    356366      ///If the bounding box is empty, then the return value is not defined.
    357367      Point<T> bottomRight() const {
     
    359369      }
    360370
    361       ///Set the bottom right corner
    362 
    363       ///Set the bottom right corner.
    364       ///It should only bee used for non-empty box.
     371      ///Set the bottom right corner of the box
     372
     373      ///Set the bottom right corner of the box.
     374      ///It should only be used for non-empty box.
    365375      void bottomRight(Point<T> p) {
    366376        top_right.x = p.x;
     
    368378      }
    369379 
    370       ///Give back the top left corner
    371 
    372       ///Give back the top left corner.
     380      ///Give back the top left corner of the box
     381
     382      ///Give back the top left corner of the box.
    373383      ///If the bounding box is empty, then the return value is not defined.
    374384      Point<T> topLeft() const {
     
    376386      }
    377387
    378       ///Set the top left corner
    379 
    380       ///Set the top left corner.
    381       ///It should only bee used for non-empty box.
     388      ///Set the top left corner of the box
     389
     390      ///Set the top left corner of the box.
     391      ///It should only be used for non-empty box.
    382392      void topLeft(Point<T> p) {
    383393        top_right.y = p.y;
     
    396406
    397407      ///Set the bottom of the box.
    398       ///It should only bee used for non-empty box.
     408      ///It should only be used for non-empty box.
    399409      void bottom(T t) {
    400410        bottom_left.y = t;
     
    412422
    413423      ///Set the top of the box.
    414       ///It should only bee used for non-empty box.
     424      ///It should only be used for non-empty box.
    415425      void top(T t) {
    416426        top_right.y = t;
     
    428438
    429439      ///Set the left side of the box.
    430       ///It should only bee used for non-empty box
     440      ///It should only be used for non-empty box.
    431441      void left(T t) {
    432442        bottom_left.x = t;
     
    444454
    445455      ///Set the right side of the box.
    446       ///It should only bee used for non-empty box
     456      ///It should only be used for non-empty box.
    447457      void right(T t) {
    448458        top_right.x = t;
     
    466476
    467477      ///Checks whether a point is inside a bounding box
    468       bool inside(const Point<T>& u){
     478      bool inside(const Point<T>& u) const {
    469479        if (_empty)
    470480          return false;
     
    476486 
    477487      ///Increments a bounding box with a point
     488
     489      ///Increments a bounding box with a point.
     490      ///
    478491      BoundingBox& add(const Point<T>& u){
    479492        if (_empty){
     
    490503      }
    491504   
    492       ///Increments a bounding to contain another bounding box
     505      ///Increments a bounding box to contain another bounding box
     506     
     507      ///Increments a bounding box to contain another bounding box.
     508      ///
    493509      BoundingBox& add(const BoundingBox &u){
    494510        if ( !u.empty() ){
     
    500516 
    501517      ///Intersection of two bounding boxes
    502       BoundingBox operator &(const BoundingBox& u){
     518
     519      ///Intersection of two bounding boxes.
     520      ///
     521      BoundingBox operator&(const BoundingBox& u) const {
    503522        BoundingBox b;
    504         b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
    505         b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
    506         b.top_right.x=std::min(this->top_right.x,u.top_right.x);
    507         b.top_right.y=std::min(this->top_right.y,u.top_right.y);
    508         b._empty = this->_empty || u._empty ||
    509           b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y;
     523        if (this->_empty || u._empty) {
     524          b._empty = true;
     525        } else {
     526          b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
     527          b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
     528          b.top_right.x=std::min(this->top_right.x,u.top_right.x);
     529          b.top_right.y=std::min(this->top_right.y,u.top_right.y);
     530          b._empty = b.bottom_left.x > b.top_right.x ||
     531                     b.bottom_left.y > b.top_right.y;
     532        }
    510533        return b;
    511534      }
     
    514537
    515538
    516   ///Map of x-coordinates of a dim2::Point<>-map
    517 
    518   ///\ingroup maps
    519   ///Map of x-coordinates of a dim2::Point<>-map
     539  ///Map of x-coordinates of a \ref Point "Point"-map
     540
     541  ///\ingroup maps
     542  ///Map of x-coordinates of a \ref Point "Point"-map.
    520543  ///
    521544  template<class M>
     
    571594  ///Returns a \ref ConstXMap class
    572595
    573   ///This function just returns an \ref ConstXMap class.
     596  ///This function just returns a \ref ConstXMap class.
    574597  ///
    575598  ///\ingroup maps
     
    581604  }
    582605
    583   ///Map of y-coordinates of a dim2::Point<>-map
     606  ///Map of y-coordinates of a \ref Point "Point"-map
    584607   
    585608  ///\ingroup maps
    586   ///Map of y-coordinates of a dim2::Point<>-map
     609  ///Map of y-coordinates of a \ref Point "Point"-map.
    587610  ///
    588611  template<class M>
     
    600623  };
    601624
    602   ///Returns an \ref YMap class
    603 
    604   ///This function just returns an \ref YMap class.
     625  ///Returns a \ref YMap class
     626
     627  ///This function just returns a \ref YMap class.
    605628  ///
    606629  ///\ingroup maps
     
    638661  ///Returns a \ref ConstYMap class
    639662
    640   ///This function just returns an \ref ConstYMap class.
     663  ///This function just returns a \ref ConstYMap class.
    641664  ///
    642665  ///\ingroup maps
     
    649672
    650673
    651     ///\brief Map of the \ref Point::normSquare() "normSquare()"
    652     ///of an \ref Point "Point"-map
    653     ///
    654     ///Map of the \ref Point::normSquare() "normSquare()"
    655     ///of an \ref Point "Point"-map
    656     ///\ingroup maps
     674  ///\brief Map of the \ref Point::normSquare() "normSquare()"
     675  ///of a \ref Point "Point"-map
     676  ///
     677  ///Map of the \ref Point::normSquare() "normSquare()"
     678  ///of a \ref Point "Point"-map.
     679  ///\ingroup maps
    657680    ///
    658681  template<class M>
     
    671694  ///Returns a \ref NormSquareMap class
    672695
    673   ///This function just returns an \ref NormSquareMap class.
     696  ///This function just returns a \ref NormSquareMap class.
    674697  ///
    675698  ///\ingroup maps
Note: See TracChangeset for help on using the changeset viewer.