COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon for lemon/dim2.h


Ignore:
Timestamp:
07/13/08 20:51:02 (11 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/dim2.h

    r49 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2525///\ingroup misc
    2626///\file
    27 ///\brief A simple two dimensional vector and a bounding box implementation 
     27///\brief A simple two dimensional vector and a bounding box implementation
    2828///
    2929/// The class \ref lemon::dim2::Point "dim2::Point" implements
     
    6060      T x;
    6161      ///Second coordinate
    62       T y;     
    63      
     62      T y;
     63
    6464      ///Default constructor
    6565      Point() {}
     
    7171
    7272      ///The dimension of the vector.
    73       ///This function always returns 2. 
     73      ///This function always returns 2.
    7474      int size() const { return 2; }
    7575
     
    9393        return x*x+y*y;
    9494      }
    95  
     95
    9696      ///Increment the left hand side by \c u
    9797      Point<T>& operator +=(const Point<T>& u) {
     
    100100        return *this;
    101101      }
    102  
     102
    103103      ///Decrement the left hand side by \c u
    104104      Point<T>& operator -=(const Point<T>& u) {
     
    121121        return *this;
    122122      }
    123  
     123
    124124      ///Return the scalar product of two vectors
    125125      T operator *(const Point<T>& u) const {
    126126        return x*u.x+y*u.y;
    127127      }
    128  
     128
    129129      ///Return the sum of two vectors
    130130      Point<T> operator+(const Point<T> &u) const {
     
    170170    };
    171171
    172   ///Return a Point 
     172  ///Return a Point
    173173
    174174  ///Return a Point.
     
    260260  }
    261261
    262  
     262
    263263
    264264  /// A class to calculate or store the bounding box of plainvectors.
     
    271271      bool _empty;
    272272    public:
    273      
     273
    274274      ///Default constructor: creates an empty bounding box
    275275      BoundingBox() { _empty = true; }
     
    277277      ///Construct an instance from one point
    278278      BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
    279      
     279
    280280      ///Construct an instance from two points
    281      
     281
    282282      ///Construct an instance from two points.
    283283      ///\param a The bottom left corner.
     
    287287      BoundingBox(Point<T> a,Point<T> b)
    288288      {
    289         bottom_left=a;
    290         top_right=b;
    291         _empty = false;
    292       }
    293      
     289        bottom_left=a;
     290        top_right=b;
     291        _empty = false;
     292      }
     293
    294294      ///Construct an instance from four numbers
    295295
     
    300300      ///\param t The top of the box.
    301301      ///\warning The left side must be no more than the right side and
    302       ///bottom must be no more than the top. 
     302      ///bottom must be no more than the top.
    303303      BoundingBox(T l,T b,T r,T t)
    304304      {
    305         bottom_left=Point<T>(l,b);
    306         top_right=Point<T>(r,t);
    307         _empty = false;
    308       }
    309      
     305        bottom_left=Point<T>(l,b);
     306        top_right=Point<T>(r,t);
     307        _empty = false;
     308      }
     309
    310310      ///Return \c true if the bounding box is empty.
    311      
     311
    312312      ///Return \c true if the bounding box is empty (i.e. return \c false
    313313      ///if at least one point was added to the box or the coordinates of
    314314      ///the box were set).
    315315      ///
    316       ///The coordinates of an empty bounding box are not defined. 
     316      ///The coordinates of an empty bounding box are not defined.
    317317      bool empty() const {
    318318        return _empty;
    319319      }
    320      
     320
    321321      ///Make the BoundingBox empty
    322322      void clear() {
     
    337337      ///It should only be used for non-empty box.
    338338      void bottomLeft(Point<T> p) {
    339         bottom_left = p;
     339        bottom_left = p;
    340340      }
    341341
     
    353353      ///It should only be used for non-empty box.
    354354      void topRight(Point<T> p) {
    355         top_right = p;
     355        top_right = p;
    356356      }
    357357
     
    369369      ///It should only be used for non-empty box.
    370370      void bottomRight(Point<T> p) {
    371         top_right.x = p.x;
    372         bottom_left.y = p.y;
    373       }
    374  
     371        top_right.x = p.x;
     372        bottom_left.y = p.y;
     373      }
     374
    375375      ///Give back the top left corner of the box
    376376
     
    386386      ///It should only be used for non-empty box.
    387387      void topLeft(Point<T> p) {
    388         top_right.y = p.y;
    389         bottom_left.x = p.x;
     388        top_right.y = p.y;
     389        bottom_left.x = p.x;
    390390      }
    391391
     
    403403      ///It should only be used for non-empty box.
    404404      void bottom(T t) {
    405         bottom_left.y = t;
     405        bottom_left.y = t;
    406406      }
    407407
     
    419419      ///It should only be used for non-empty box.
    420420      void top(T t) {
    421         top_right.y = t;
     421        top_right.y = t;
    422422      }
    423423
     
    429429        return bottom_left.x;
    430430      }
    431  
     431
    432432      ///Set the left side of the box
    433433
     
    435435      ///It should only be used for non-empty box.
    436436      void left(T t) {
    437         bottom_left.x = t;
     437        bottom_left.x = t;
    438438      }
    439439
     
    451451      ///It should only be used for non-empty box.
    452452      void right(T t) {
    453         top_right.x = t;
     453        top_right.x = t;
    454454      }
    455455
     
    479479        }
    480480      }
    481  
     481
    482482      ///Increments a bounding box with a point
    483483
     
    497497        return *this;
    498498      }
    499    
     499
    500500      ///Increments a bounding box to contain another bounding box
    501      
     501
    502502      ///Increments a bounding box to contain another bounding box.
    503503      ///
     
    505505        if ( !u.empty() ){
    506506          this->add(u.bottomLeft());
    507           this->add(u.topRight());
     507          this->add(u.topRight());
    508508        }
    509509        return *this;
    510510      }
    511  
     511
    512512      ///Intersection of two bounding boxes
    513513
     
    517517        BoundingBox b;
    518518        if (this->_empty || u._empty) {
    519           b._empty = true;
    520         } else {
    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;
    527         }
     519          b._empty = true;
     520        } else {
     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;
     527        }
    528528        return b;
    529529      }
     
    538538  ///
    539539  template<class M>
    540   class XMap 
     540  class XMap
    541541  {
    542542    M& _map;
     
    550550    void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
    551551  };
    552    
     552
    553553  ///Returns an \ref XMap class
    554554
     
    557557  ///\ingroup maps
    558558  ///\relates XMap
    559   template<class M> 
    560   inline XMap<M> xMap(M &m) 
     559  template<class M>
     560  inline XMap<M> xMap(M &m)
    561561  {
    562562    return XMap<M>(m);
    563563  }
    564564
    565   template<class M> 
    566   inline XMap<M> xMap(const M &m) 
     565  template<class M>
     566  inline XMap<M> xMap(const M &m)
    567567  {
    568568    return XMap<M>(m);
     
    575575  ///
    576576  template<class M>
    577   class ConstXMap 
     577  class ConstXMap
    578578  {
    579579    const M& _map;
     
    586586    Value operator[](Key k) const {return _map[k].x;}
    587587  };
    588    
     588
    589589  ///Returns a \ref ConstXMap class
    590590
     
    593593  ///\ingroup maps
    594594  ///\relates ConstXMap
    595   template<class M> 
    596   inline ConstXMap<M> xMap(const M &m) 
     595  template<class M>
     596  inline ConstXMap<M> xMap(const M &m)
    597597  {
    598598    return ConstXMap<M>(m);
     
    600600
    601601  ///Map of y-coordinates of a \ref Point "Point"-map
    602    
     602
    603603  ///\ingroup maps
    604604  ///Map of y-coordinates of a \ref Point "Point"-map.
    605605  ///
    606606  template<class M>
    607   class YMap 
     607  class YMap
    608608  {
    609609    M& _map;
     
    624624  ///\ingroup maps
    625625  ///\relates YMap
    626   template<class M> 
    627   inline YMap<M> yMap(M &m) 
     626  template<class M>
     627  inline YMap<M> yMap(M &m)
    628628  {
    629629    return YMap<M>(m);
    630630  }
    631631
    632   template<class M> 
    633   inline YMap<M> yMap(const M &m) 
     632  template<class M>
     633  inline YMap<M> yMap(const M &m)
    634634  {
    635635    return YMap<M>(m);
     
    642642  ///
    643643  template<class M>
    644   class ConstYMap 
     644  class ConstYMap
    645645  {
    646646    const M& _map;
     
    653653    Value operator[](Key k) const {return _map[k].y;}
    654654  };
    655    
     655
    656656  ///Returns a \ref ConstYMap class
    657657
     
    660660  ///\ingroup maps
    661661  ///\relates ConstYMap
    662   template<class M> 
    663   inline ConstYMap<M> yMap(const M &m) 
     662  template<class M>
     663  inline ConstYMap<M> yMap(const M &m)
    664664  {
    665665    return ConstYMap<M>(m);
     
    674674  ///\ingroup maps
    675675  template<class M>
    676   class NormSquareMap 
     676  class NormSquareMap
    677677  {
    678678    const M& _map;
     
    685685    Value operator[](Key k) const {return _map[k].normSquare();}
    686686  };
    687    
     687
    688688  ///Returns a \ref NormSquareMap class
    689689
     
    692692  ///\ingroup maps
    693693  ///\relates NormSquareMap
    694   template<class M> 
    695   inline NormSquareMap<M> normSquareMap(const M &m) 
     694  template<class M>
     695  inline NormSquareMap<M> normSquareMap(const M &m)
    696696  {
    697697    return NormSquareMap<M>(m);
     
    701701
    702702  } //namespce dim2
    703  
     703
    704704} //namespace lemon
    705705
Note: See TracChangeset for help on using the changeset viewer.