Improved and fixed dim2.h.
authorPeter Kovacs <kpeter@inf.elte.hu>
Thu, 03 Jan 2008 01:08:23 +0100
changeset 15062f361aa520
parent 14 8685efdef52f
child 16 22696f89d183
Improved and fixed dim2.h.
Improved and fixed documentation.
Bug fix in BoundingBox<>::operator&.
Removed \author tags.
lemon/dim2.h
     1.1 --- a/lemon/dim2.h	Wed Jan 02 03:55:00 2008 +0100
     1.2 +++ b/lemon/dim2.h	Thu Jan 03 01:08:23 2008 +0100
     1.3 @@ -34,9 +34,6 @@
     1.4  /// can be used to determine
     1.5  /// the rectangular bounding box of a set of
     1.6  /// \ref lemon::dim2::Point "dim2::Point"'s.
     1.7 -///
     1.8 -///\author Attila Bernath
     1.9 -
    1.10  
    1.11  namespace lemon {
    1.12  
    1.13 @@ -62,9 +59,9 @@
    1.14  
    1.15        typedef T Value;
    1.16  
    1.17 -      ///First co-ordinate
    1.18 +      ///First coordinate
    1.19        T x;
    1.20 -      ///Second co-ordinate
    1.21 +      ///Second coordinate
    1.22        T y;     
    1.23        
    1.24        ///Default constructor
    1.25 @@ -75,8 +72,8 @@
    1.26  
    1.27        ///The dimension of the vector.
    1.28  
    1.29 -      ///This class give back always 2.
    1.30 -      ///
    1.31 +      ///The dimension of the vector.
    1.32 +      ///This function always returns 2. 
    1.33        int size() const { return 2; }
    1.34  
    1.35        ///Subscripting operator
    1.36 @@ -138,7 +135,7 @@
    1.37          return b+=u;
    1.38        }
    1.39  
    1.40 -      ///Return the neg of the vectors
    1.41 +      ///Return the negative of the vector
    1.42        Point<T> operator-() const {
    1.43          Point<T> b=*this;
    1.44          b.x=-b.x; b.y=-b.y;
    1.45 @@ -175,9 +172,9 @@
    1.46  
    1.47      };
    1.48  
    1.49 -  ///Return an Point 
    1.50 +  ///Return a Point 
    1.51  
    1.52 -  ///Return an Point
    1.53 +  ///Return a Point.
    1.54    ///\relates Point
    1.55    template <typename T>
    1.56    inline Point<T> makePoint(const T& x, const T& y) {
    1.57 @@ -186,7 +183,7 @@
    1.58  
    1.59    ///Return a vector multiplied by a scalar
    1.60  
    1.61 -  ///Return a vector multiplied by a scalar
    1.62 +  ///Return a vector multiplied by a scalar.
    1.63    ///\relates Point
    1.64    template<typename T> Point<T> operator*(const T &u,const Point<T> &x) {
    1.65      return x*u;
    1.66 @@ -194,7 +191,7 @@
    1.67  
    1.68    ///Read a plainvector from a stream
    1.69  
    1.70 -  ///Read a plainvector from a stream
    1.71 +  ///Read a plainvector from a stream.
    1.72    ///\relates Point
    1.73    ///
    1.74    template<typename T>
    1.75 @@ -222,7 +219,7 @@
    1.76  
    1.77    ///Write a plainvector to a stream
    1.78  
    1.79 -  ///Write a plainvector to a stream
    1.80 +  ///Write a plainvector to a stream.
    1.81    ///\relates Point
    1.82    ///
    1.83    template<typename T>
    1.84 @@ -234,7 +231,7 @@
    1.85  
    1.86    ///Rotate by 90 degrees
    1.87  
    1.88 -  ///Returns its parameter rotated by 90 degrees in positive direction.
    1.89 +  ///Returns the parameter rotated by 90 degrees in positive direction.
    1.90    ///\relates Point
    1.91    ///
    1.92    template<typename T>
    1.93 @@ -245,7 +242,7 @@
    1.94  
    1.95    ///Rotate by 180 degrees
    1.96  
    1.97 -  ///Returns its parameter rotated by 180 degrees.
    1.98 +  ///Returns the parameter rotated by 180 degrees.
    1.99    ///\relates Point
   1.100    ///
   1.101    template<typename T>
   1.102 @@ -256,7 +253,7 @@
   1.103  
   1.104    ///Rotate by 270 degrees
   1.105  
   1.106 -  ///Returns its parameter rotated by 90 degrees in negative direction.
   1.107 +  ///Returns the parameter rotated by 90 degrees in negative direction.
   1.108    ///\relates Point
   1.109    ///
   1.110    template<typename T>
   1.111 @@ -271,7 +268,6 @@
   1.112  
   1.113    /// A class to calculate or store the bounding box of plainvectors.
   1.114    ///
   1.115 -  ///\author Attila Bernath
   1.116      template<typename T>
   1.117      class BoundingBox {
   1.118        Point<T> bottom_left, top_right;
   1.119 @@ -286,9 +282,11 @@
   1.120        
   1.121        ///Construct an instance from two points
   1.122        
   1.123 -      ///Construct an instance from two points
   1.124 -      ///\warning The coordinates of the bottom-left corner must be no more
   1.125 -      ///than those of the top-right one
   1.126 +      ///Construct an instance from two points.
   1.127 +      ///\param a The bottom left corner.
   1.128 +      ///\param b The top right corner.
   1.129 +      ///\warning The coordinates of the bottom left corner must be no more
   1.130 +      ///than those of the top right one.
   1.131        BoundingBox(Point<T> a,Point<T> b)
   1.132        {
   1.133  	bottom_left=a;
   1.134 @@ -298,9 +296,13 @@
   1.135        
   1.136        ///Construct an instance from four numbers
   1.137  
   1.138 -      ///Construct an instance from four numbers
   1.139 -      ///\warning The coordinates of the bottom-left corner must be no more
   1.140 -      ///than those of the top-right one
   1.141 +      ///Construct an instance from four numbers.
   1.142 +      ///\param l The left side of the box.
   1.143 +      ///\param b The bottom of the box.
   1.144 +      ///\param r The right side of the box.
   1.145 +      ///\param t The top of the box.
   1.146 +      ///\warning The left side must be no more than the right side and
   1.147 +      ///bottom must be no more than the top. 
   1.148        BoundingBox(T l,T b,T r,T t)
   1.149        {
   1.150  	bottom_left=Point<T>(l,b);
   1.151 @@ -308,7 +310,12 @@
   1.152  	_empty = false;
   1.153        }
   1.154        
   1.155 -      ///Were any points added?
   1.156 +      ///Return \c true if the bounding box is empty.
   1.157 +      
   1.158 +      ///Return \c true if the bounding box is empty (i.e. return \c false
   1.159 +      ///if at least one point was added to the box or the coordinates of
   1.160 +      ///the box were set).
   1.161 +      ///The coordinates of an empty bounding box are not defined. 
   1.162        bool empty() const {
   1.163          return _empty;
   1.164        }
   1.165 @@ -329,7 +336,7 @@
   1.166        ///Set the bottom left corner
   1.167  
   1.168        ///Set the bottom left corner.
   1.169 -      ///It should only bee used for non-empty box.
   1.170 +      ///It should only be used for non-empty box.
   1.171        void bottomLeft(Point<T> p) {
   1.172  	bottom_left = p;
   1.173        }
   1.174 @@ -345,7 +352,7 @@
   1.175        ///Set the top right corner
   1.176  
   1.177        ///Set the top right corner.
   1.178 -      ///It should only bee used for non-empty box.
   1.179 +      ///It should only be used for non-empty box.
   1.180        void topRight(Point<T> p) {
   1.181  	top_right = p;
   1.182        }
   1.183 @@ -361,7 +368,7 @@
   1.184        ///Set the bottom right corner
   1.185  
   1.186        ///Set the bottom right corner.
   1.187 -      ///It should only bee used for non-empty box.
   1.188 +      ///It should only be used for non-empty box.
   1.189        void bottomRight(Point<T> p) {
   1.190  	top_right.x = p.x;
   1.191  	bottom_left.y = p.y;
   1.192 @@ -378,7 +385,7 @@
   1.193        ///Set the top left corner
   1.194  
   1.195        ///Set the top left corner.
   1.196 -      ///It should only bee used for non-empty box.
   1.197 +      ///It should only be used for non-empty box.
   1.198        void topLeft(Point<T> p) {
   1.199  	top_right.y = p.y;
   1.200  	bottom_left.x = p.x;
   1.201 @@ -395,7 +402,7 @@
   1.202        ///Set the bottom of the box
   1.203  
   1.204        ///Set the bottom of the box.
   1.205 -      ///It should only bee used for non-empty box.
   1.206 +      ///It should only be used for non-empty box.
   1.207        void bottom(T t) {
   1.208  	bottom_left.y = t;
   1.209        }
   1.210 @@ -411,7 +418,7 @@
   1.211        ///Set the top of the box
   1.212  
   1.213        ///Set the top of the box.
   1.214 -      ///It should only bee used for non-empty box.
   1.215 +      ///It should only be used for non-empty box.
   1.216        void top(T t) {
   1.217  	top_right.y = t;
   1.218        }
   1.219 @@ -427,7 +434,7 @@
   1.220        ///Set the left side of the box
   1.221  
   1.222        ///Set the left side of the box.
   1.223 -      ///It should only bee used for non-empty box
   1.224 +      ///It should only be used for non-empty box.
   1.225        void left(T t) {
   1.226  	bottom_left.x = t;
   1.227        }
   1.228 @@ -443,7 +450,7 @@
   1.229        ///Set the right side of the box
   1.230  
   1.231        ///Set the right side of the box.
   1.232 -      ///It should only bee used for non-empty box
   1.233 +      ///It should only be used for non-empty box.
   1.234        void right(T t) {
   1.235  	top_right.x = t;
   1.236        }
   1.237 @@ -465,7 +472,7 @@
   1.238        }
   1.239  
   1.240        ///Checks whether a point is inside a bounding box
   1.241 -      bool inside(const Point<T>& u){
   1.242 +      bool inside(const Point<T>& u) const {
   1.243          if (_empty)
   1.244            return false;
   1.245          else{
   1.246 @@ -475,6 +482,9 @@
   1.247        }
   1.248    
   1.249        ///Increments a bounding box with a point
   1.250 +
   1.251 +      ///Increments a bounding box with a point.
   1.252 +      ///
   1.253        BoundingBox& add(const Point<T>& u){
   1.254          if (_empty){
   1.255            bottom_left=top_right=u;
   1.256 @@ -489,7 +499,10 @@
   1.257          return *this;
   1.258        }
   1.259      
   1.260 -      ///Increments a bounding to contain another bounding box
   1.261 +      ///Increments a bounding box to contain another bounding box
   1.262 +      
   1.263 +      ///Increments a bounding box to contain another bounding box.
   1.264 +      ///
   1.265        BoundingBox& add(const BoundingBox &u){
   1.266          if ( !u.empty() ){
   1.267            this->add(u.bottomLeft());
   1.268 @@ -499,24 +512,31 @@
   1.269        }
   1.270    
   1.271        ///Intersection of two bounding boxes
   1.272 -      BoundingBox operator &(const BoundingBox& u){
   1.273 +
   1.274 +      ///Intersection of two bounding boxes.
   1.275 +      ///
   1.276 +      BoundingBox operator&(const BoundingBox& u) const {
   1.277          BoundingBox b;
   1.278 -	b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
   1.279 -	b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
   1.280 -	b.top_right.x=std::min(this->top_right.x,u.top_right.x);
   1.281 -	b.top_right.y=std::min(this->top_right.y,u.top_right.y);
   1.282 -	b._empty = this->_empty || u._empty ||
   1.283 -	  b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y;
   1.284 +        if (this->_empty || u._empty) {
   1.285 +	  b._empty = true;
   1.286 +	} else {
   1.287 +	  b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
   1.288 +	  b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
   1.289 +	  b.top_right.x = std::min(this->top_right.x,u.top_right.x);
   1.290 +	  b.top_right.y = std::min(this->top_right.y,u.top_right.y);
   1.291 +	  b._empty = b.bottom_left.x > b.top_right.x ||
   1.292 +	             b.bottom_left.y > b.top_right.y;
   1.293 +	} 
   1.294          return b;
   1.295        }
   1.296  
   1.297      };//class Boundingbox
   1.298  
   1.299  
   1.300 -  ///Map of x-coordinates of a dim2::Point<>-map
   1.301 +  ///Map of x-coordinates of a \ref Point "Point"-map
   1.302  
   1.303    ///\ingroup maps
   1.304 -  ///Map of x-coordinates of a dim2::Point<>-map
   1.305 +  ///Map of x-coordinates of a \ref Point "Point"-map.
   1.306    ///
   1.307    template<class M>
   1.308    class XMap 
   1.309 @@ -570,7 +590,7 @@
   1.310      
   1.311    ///Returns a \ref ConstXMap class
   1.312  
   1.313 -  ///This function just returns an \ref ConstXMap class.
   1.314 +  ///This function just returns a \ref ConstXMap class.
   1.315    ///
   1.316    ///\ingroup maps
   1.317    ///\relates ConstXMap
   1.318 @@ -580,10 +600,10 @@
   1.319      return ConstXMap<M>(m);
   1.320    }
   1.321  
   1.322 -  ///Map of y-coordinates of a dim2::Point<>-map
   1.323 +  ///Map of y-coordinates of a \ref Point "Point"-map
   1.324      
   1.325    ///\ingroup maps
   1.326 -  ///Map of y-coordinates of a dim2::Point<>-map
   1.327 +  ///Map of y-coordinates of a \ref Point "Point"-map.
   1.328    ///
   1.329    template<class M>
   1.330    class YMap 
   1.331 @@ -599,9 +619,9 @@
   1.332      void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
   1.333    };
   1.334  
   1.335 -  ///Returns an \ref YMap class
   1.336 +  ///Returns a \ref YMap class
   1.337  
   1.338 -  ///This function just returns an \ref YMap class.
   1.339 +  ///This function just returns a \ref YMap class.
   1.340    ///
   1.341    ///\ingroup maps
   1.342    ///\relates YMap
   1.343 @@ -637,7 +657,7 @@
   1.344      
   1.345    ///Returns a \ref ConstYMap class
   1.346  
   1.347 -  ///This function just returns an \ref ConstYMap class.
   1.348 +  ///This function just returns a \ref ConstYMap class.
   1.349    ///
   1.350    ///\ingroup maps
   1.351    ///\relates ConstYMap
   1.352 @@ -649,10 +669,10 @@
   1.353  
   1.354  
   1.355      ///\brief Map of the \ref Point::normSquare() "normSquare()"
   1.356 -    ///of an \ref Point "Point"-map
   1.357 +    ///of a \ref Point "Point"-map
   1.358      ///
   1.359      ///Map of the \ref Point::normSquare() "normSquare()"
   1.360 -    ///of an \ref Point "Point"-map
   1.361 +    ///of a \ref Point "Point"-map.
   1.362      ///\ingroup maps
   1.363      ///
   1.364    template<class M>
   1.365 @@ -670,7 +690,7 @@
   1.366      
   1.367    ///Returns a \ref NormSquareMap class
   1.368  
   1.369 -  ///This function just returns an \ref NormSquareMap class.
   1.370 +  ///This function just returns a \ref NormSquareMap class.
   1.371    ///
   1.372    ///\ingroup maps
   1.373    ///\relates NormSquareMap