COIN-OR::LEMON - Graph Library

Ticket #126: dbe309b5e855.patch

File dbe309b5e855.patch, 12.8 KB (added by Peter Kovacs, 16 years ago)
  • lemon/dim2.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1220127583 -7200
    # Node ID dbe309b5e8558542297b2415f7b8ea5e4eced62f
    # Parent  d0aae16df1bb28a8cce519d53b1004399b71d9a7
    Rename BoundingBox to Box (ticket #126)
    
    diff -r d0aae16df1bb -r dbe309b5e855 lemon/dim2.h
    a b  
    2828/// The class \ref lemon::dim2::Point "dim2::Point" implements
    2929/// a two dimensional vector with the usual operations.
    3030///
    31 /// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox"
    32 /// can be used to determine
     31/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine
    3332/// the rectangular bounding box of a set of
    3433/// \ref lemon::dim2::Point "dim2::Point"'s.
    3534
     
    4443  /// \addtogroup misc
    4544  /// @{
    4645
    47   /// A simple two dimensional vector (plain vector) implementation
     46  /// Two dimensional vector (plain vector)
    4847
    4948  /// A simple two dimensional vector (plain vector) implementation
    5049  /// with the usual vector operations.
     
    260259
    261260
    262261
    263     /// A class to calculate or store the bounding box of plain vectors.
     262  /// Bounding box of plain vectors (\ref Point points).
    264263
    265     /// A class to calculate or store the bounding box of plain vectors.
    266     ///
    267     template<typename T>
    268     class BoundingBox {
     264  /// A class to calculate or store the bounding box of plain vectors
     265  /// (\ref Point points).
     266  template<typename T>
     267  class Box {
    269268      Point<T> _bottom_left, _top_right;
    270269      bool _empty;
    271270    public:
    272271
    273       ///Default constructor: creates an empty bounding box
    274       BoundingBox() { _empty = true; }
     272      ///Default constructor: creates an empty box
     273      Box() { _empty = true; }
    275274
    276       ///Construct an instance from one point
    277       BoundingBox(Point<T> a) {
     275      ///Construct a box from one point
     276      Box(Point<T> a) {
    278277        _bottom_left = _top_right = a;
    279278        _empty = false;
    280279      }
    281280
    282       ///Construct an instance from two points
     281      ///Construct a box from two points
    283282
    284       ///Construct an instance from two points.
     283      ///Construct a box from two points.
    285284      ///\param a The bottom left corner.
    286285      ///\param b The top right corner.
    287286      ///\warning The coordinates of the bottom left corner must be no more
    288287      ///than those of the top right one.
    289       BoundingBox(Point<T> a,Point<T> b)
     288      Box(Point<T> a,Point<T> b)
    290289      {
    291290        _bottom_left = a;
    292291        _top_right = b;
    293292        _empty = false;
    294293      }
    295294
    296       ///Construct an instance from four numbers
     295      ///Construct a box from four numbers
    297296
    298       ///Construct an instance from four numbers.
     297      ///Construct a box from four numbers.
    299298      ///\param l The left side of the box.
    300299      ///\param b The bottom of the box.
    301300      ///\param r The right side of the box.
    302301      ///\param t The top of the box.
    303302      ///\warning The left side must be no more than the right side and
    304303      ///bottom must be no more than the top.
    305       BoundingBox(T l,T b,T r,T t)
     304      Box(T l,T b,T r,T t)
    306305      {
    307306        _bottom_left=Point<T>(l,b);
    308307        _top_right=Point<T>(r,t);
    309308        _empty = false;
    310309      }
    311310
    312       ///Return \c true if the bounding box is empty.
     311      ///Return \c true if the box is empty.
    313312
    314       ///Return \c true if the bounding box is empty (i.e. return \c false
     313      ///Return \c true if the box is empty (i.e. return \c false
    315314      ///if at least one point was added to the box or the coordinates of
    316315      ///the box were set).
    317316      ///
    318       ///The coordinates of an empty bounding box are not defined.
     317      ///The coordinates of an empty box are not defined.
    319318      bool empty() const {
    320319        return _empty;
    321320      }
    322321
    323       ///Make the BoundingBox empty
     322      ///Make the box empty
    324323      void clear() {
    325324        _empty = true;
    326325      }
     
    328327      ///Give back the bottom left corner of the box
    329328
    330329      ///Give back the bottom left corner of the box.
    331       ///If the bounding box is empty, then the return value is not defined.
     330      ///If the box is empty, then the return value is not defined.
    332331      Point<T> bottomLeft() const {
    333332        return _bottom_left;
    334333      }
     
    344343      ///Give back the top right corner of the box
    345344
    346345      ///Give back the top right corner of the box.
    347       ///If the bounding box is empty, then the return value is not defined.
     346      ///If the box is empty, then the return value is not defined.
    348347      Point<T> topRight() const {
    349348        return _top_right;
    350349      }
     
    360359      ///Give back the bottom right corner of the box
    361360
    362361      ///Give back the bottom right corner of the box.
    363       ///If the bounding box is empty, then the return value is not defined.
     362      ///If the box is empty, then the return value is not defined.
    364363      Point<T> bottomRight() const {
    365364        return Point<T>(_top_right.x,_bottom_left.y);
    366365      }
     
    377376      ///Give back the top left corner of the box
    378377
    379378      ///Give back the top left corner of the box.
    380       ///If the bounding box is empty, then the return value is not defined.
     379      ///If the box is empty, then the return value is not defined.
    381380      Point<T> topLeft() const {
    382381        return Point<T>(_bottom_left.x,_top_right.y);
    383382      }
     
    394393      ///Give back the bottom of the box
    395394
    396395      ///Give back the bottom of the box.
    397       ///If the bounding box is empty, then the return value is not defined.
     396      ///If the box is empty, then the return value is not defined.
    398397      T bottom() const {
    399398        return _bottom_left.y;
    400399      }
     
    410409      ///Give back the top of the box
    411410
    412411      ///Give back the top of the box.
    413       ///If the bounding box is empty, then the return value is not defined.
     412      ///If the box is empty, then the return value is not defined.
    414413      T top() const {
    415414        return _top_right.y;
    416415      }
     
    426425      ///Give back the left side of the box
    427426
    428427      ///Give back the left side of the box.
    429       ///If the bounding box is empty, then the return value is not defined.
     428      ///If the box is empty, then the return value is not defined.
    430429      T left() const {
    431430        return _bottom_left.x;
    432431      }
     
    442441      /// Give back the right side of the box
    443442
    444443      /// Give back the right side of the box.
    445       ///If the bounding box is empty, then the return value is not defined.
     444      ///If the box is empty, then the return value is not defined.
    446445      T right() const {
    447446        return _top_right.x;
    448447      }
     
    458457      ///Give back the height of the box
    459458
    460459      ///Give back the height of the box.
    461       ///If the bounding box is empty, then the return value is not defined.
     460      ///If the box is empty, then the return value is not defined.
    462461      T height() const {
    463462        return _top_right.y-_bottom_left.y;
    464463      }
     
    466465      ///Give back the width of the box
    467466
    468467      ///Give back the width of the box.
    469       ///If the bounding box is empty, then the return value is not defined.
     468      ///If the box is empty, then the return value is not defined.
    470469      T width() const {
    471470        return _top_right.x-_bottom_left.x;
    472471      }
    473472
    474       ///Checks whether a point is inside a bounding box
     473      ///Checks whether a point is inside the box
    475474      bool inside(const Point<T>& u) const {
    476475        if (_empty)
    477476          return false;
     
    481480        }
    482481      }
    483482
    484       ///Increments a bounding box with a point
     483      ///Increments the box with a point
    485484
    486       ///Increments a bounding box with a point.
     485      ///Increments the box with a point.
    487486      ///
    488       BoundingBox& add(const Point<T>& u){
     487      Box& add(const Point<T>& u){
    489488        if (_empty) {
    490489          _bottom_left = _top_right = u;
    491490          _empty = false;
     
    499498        return *this;
    500499      }
    501500
    502       ///Increments a bounding box to contain another bounding box
     501      ///Increments the box to contain another box
    503502
    504       ///Increments a bounding box to contain another bounding box.
     503      ///Increments the box to contain another box.
    505504      ///
    506       BoundingBox& add(const BoundingBox &u){
     505      Box& add(const Box &u){
    507506        if ( !u.empty() ){
    508507          add(u._bottom_left);
    509508          add(u._top_right);
     
    511510        return *this;
    512511      }
    513512
    514       ///Intersection of two bounding boxes
     513      ///Intersection of two boxes
    515514
    516       ///Intersection of two bounding boxes.
     515      ///Intersection of two boxes.
    517516      ///
    518       BoundingBox operator&(const BoundingBox& u) const {
    519         BoundingBox b;
     517      Box operator&(const Box& u) const {
     518        Box b;
    520519        if (_empty || u._empty) {
    521520          b._empty = true;
    522521        } else {
     
    530529        return b;
    531530      }
    532531
    533     };//class Boundingbox
     532  };//class Box
    534533
    535534
    536   ///Read a bounding box from a stream
     535  ///Read a box from a stream
    537536
    538   ///Read a bounding box from a stream.
    539   ///\relates BoundingBox
     537  ///Read a box from a stream.
     538  ///\relates Box
    540539  template<typename T>
    541   inline std::istream& operator>>(std::istream &is, BoundingBox<T>& b) {
     540  inline std::istream& operator>>(std::istream &is, Box<T>& b) {
    542541    char c;
    543542    Point<T> p;
    544543    if (is >> c) {
     
    563562    return is;
    564563  }
    565564
    566   ///Write a bounding box to a stream
     565  ///Write a box to a stream
    567566
    568   ///Write a bounding box to a stream.
    569   ///\relates BoundingBox
     567  ///Write a box to a stream.
     568  ///\relates Box
    570569  template<typename T>
    571   inline std::ostream& operator<<(std::ostream &os, const BoundingBox<T>& b)
     570  inline std::ostream& operator<<(std::ostream &os, const Box<T>& b)
    572571  {
    573572    os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
    574573    return os;
  • lemon/graph_to_eps.h

    diff -r d0aae16df1bb -r dbe309b5e855 lemon/graph_to_eps.h
    a b  
    725725
    726726    double diag_len = 1;
    727727    if(!(_absoluteNodeSizes&&_absoluteArcWidths)) {
    728       dim2::BoundingBox<double> bb;
     728      dim2::Box<double> bb;
    729729      for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]);
    730730      if (bb.empty()) {
    731         bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0));
     731        bb = dim2::Box<double>(dim2::Point<double>(0,0));
    732732      }
    733733      diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare());
    734734      if(diag_len<EPSILON) diag_len = 1;
     
    736736      if(!_absoluteArcWidths) _arcWidthScale*=diag_len;
    737737    }
    738738
    739     dim2::BoundingBox<double> bb;
     739    dim2::Box<double> bb;
    740740    for(NodeIt n(g);n!=INVALID;++n) {
    741741      double ns=_nodeSizes[n]*_nodeScale;
    742742      dim2::Point<double> p(ns,ns);
     
    758758      }
    759759    }
    760760    if (bb.empty()) {
    761       bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0));
     761      bb = dim2::Box<double>(dim2::Point<double>(0,0));
    762762    }
    763763
    764764    if(_scaleToA4)
  • test/dim_test.cc

    diff -r d0aae16df1bb -r dbe309b5e855 test/dim_test.cc
    a b  
    5050  p = b/l;
    5151  check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar.");
    5252
    53   typedef dim2::BoundingBox<int> BB;
    54   BB box1;
    55   check(box1.empty(), "Wrong empty() in dim2::BoundingBox.");
     53  typedef dim2::Box<int> Box;
     54  Box box1;
     55  check(box1.empty(), "Wrong empty() in dim2::Box.");
    5656
    5757  box1.add(a);
    58   check(!box1.empty(), "Wrong empty() in dim2::BoundingBox.");
     58  check(!box1.empty(), "Wrong empty() in dim2::Box.");
    5959  box1.add(b);
    6060
    6161  check(box1.left()==1 && box1.bottom()==2 &&
    6262        box1.right()==3 && box1.top()==4,
    63         "Wrong addition of points to dim2::BoundingBox.");
     63        "Wrong addition of points to dim2::Box.");
    6464
    65   check(box1.inside(Point(2,3)), "Wrong inside() in dim2::BoundingBox.");
    66   check(box1.inside(Point(1,3)), "Wrong inside() in dim2::BoundingBox.");
    67   check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::BoundingBox.");
     65  check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box.");
     66  check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box.");
     67  check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box.");
    6868
    69   BB box2(Point(2,2));
    70   check(!box2.empty(), "Wrong empty() in dim2::BoundingBox.");
    71  
     69  Box box2(Point(2,2));
     70  check(!box2.empty(), "Wrong empty() in dim2::Box.");
     71
    7272  box2.bottomLeft(Point(2,0));
    7373  box2.topRight(Point(5,3));
    74   BB box3 = box1 & box2;
     74  Box box3 = box1 & box2;
    7575  check(!box3.empty() &&
    76         box3.left()==2 && box3.bottom()==2 && 
     76        box3.left()==2 && box3.bottom()==2 &&
    7777        box3.right()==3 && box3.top()==3,
    78         "Wrong intersection of two dim2::BoundingBox objects.");
    79  
     78        "Wrong intersection of two dim2::Box objects.");
     79
    8080  box1.add(box2);
    8181  check(!box1.empty() &&
    8282        box1.left()==1 && box1.bottom()==0 &&
    8383        box1.right()==5 && box1.top()==4,
    84         "Wrong addition of two dim2::BoundingBox objects.");
     84        "Wrong addition of two dim2::Box objects.");
    8585
    8686  return 0;
    8787}