Improvements and fixes in dim2.h.
- Several doc improvements.
- Fix BoundingBox::operator& implementation.
1.1 --- a/lemon/dim2.h Tue Feb 05 11:10:08 2008 +0000
1.2 +++ b/lemon/dim2.h Tue Feb 05 11:23:23 2008 +0000
1.3 @@ -52,9 +52,7 @@
1.4 /// A simple two dimensional vector (plainvector) implementation
1.5
1.6 /// A simple two dimensional vector (plainvector) implementation
1.7 - ///with the usual vector
1.8 - /// operators.
1.9 - ///
1.10 + /// with the usual vector operations.
1.11 template<typename T>
1.12 class Point {
1.13
1.14 @@ -62,9 +60,9 @@
1.15
1.16 typedef T Value;
1.17
1.18 - ///First co-ordinate
1.19 + ///First coordinate
1.20 T x;
1.21 - ///Second co-ordinate
1.22 + ///Second coordinate
1.23 T y;
1.24
1.25 ///Default constructor
1.26 @@ -75,7 +73,7 @@
1.27
1.28 ///The dimension of the vector.
1.29
1.30 - ///This class give back always 2.
1.31 + ///This function always returns 2.
1.32 ///
1.33 int size() const { return 2; }
1.34
1.35 @@ -99,14 +97,14 @@
1.36 return x*x+y*y;
1.37 }
1.38
1.39 - ///Increment the left hand side by u
1.40 + ///Increment the left hand side by \c u
1.41 Point<T>& operator +=(const Point<T>& u) {
1.42 x += u.x;
1.43 y += u.y;
1.44 return *this;
1.45 }
1.46
1.47 - ///Decrement the left hand side by u
1.48 + ///Decrement the left hand side by \c u
1.49 Point<T>& operator -=(const Point<T>& u) {
1.50 x -= u.x;
1.51 y -= u.y;
1.52 @@ -138,7 +136,7 @@
1.53 return b+=u;
1.54 }
1.55
1.56 - ///Return the neg of the vectors
1.57 + ///Return the negative of the vector
1.58 Point<T> operator-() const {
1.59 Point<T> b=*this;
1.60 b.x=-b.x; b.y=-b.y;
1.61 @@ -175,9 +173,9 @@
1.62
1.63 };
1.64
1.65 - ///Return an Point
1.66 + ///Return a Point
1.67
1.68 - ///Return an Point
1.69 + ///Return a Point.
1.70 ///\relates Point
1.71 template <typename T>
1.72 inline Point<T> makePoint(const T& x, const T& y) {
1.73 @@ -286,9 +284,11 @@
1.74
1.75 ///Construct an instance from two points
1.76
1.77 - ///Construct an instance from two points
1.78 - ///\warning The coordinates of the bottom-left corner must be no more
1.79 - ///than those of the top-right one
1.80 + ///Construct an instance from two points.
1.81 + ///\param a The bottom left corner.
1.82 + ///\param b The top right corner.
1.83 + ///\warning The coordinates of the bottom left corner must be no more
1.84 + ///than those of the top right one.
1.85 BoundingBox(Point<T> a,Point<T> b)
1.86 {
1.87 bottom_left=a;
1.88 @@ -298,9 +298,13 @@
1.89
1.90 ///Construct an instance from four numbers
1.91
1.92 - ///Construct an instance from four numbers
1.93 - ///\warning The coordinates of the bottom-left corner must be no more
1.94 - ///than those of the top-right one
1.95 + ///Construct an instance from four numbers.
1.96 + ///\param l The left side of the box.
1.97 + ///\param b The bottom of the box.
1.98 + ///\param r The right side of the box.
1.99 + ///\param t The top of the box.
1.100 + ///\warning The left side must be no more than the right side and
1.101 + ///bottom must be no more than the top.
1.102 BoundingBox(T l,T b,T r,T t)
1.103 {
1.104 bottom_left=Point<T>(l,b);
1.105 @@ -308,7 +312,13 @@
1.106 _empty = false;
1.107 }
1.108
1.109 - ///Were any points added?
1.110 + ///Return \c true if the bounding box is empty.
1.111 +
1.112 + ///Return \c true if the bounding box is empty (i.e. return \c false
1.113 + ///if at least one point was added to the box or the coordinates of
1.114 + ///the box were set).
1.115 + ///
1.116 + ///The coordinates of an empty bounding box are not defined.
1.117 bool empty() const {
1.118 return _empty;
1.119 }
1.120 @@ -318,67 +328,67 @@
1.121 _empty=1;
1.122 }
1.123
1.124 - ///Give back the bottom left corner
1.125 + ///Give back the bottom left corner of the box
1.126
1.127 - ///Give back the bottom left corner.
1.128 + ///Give back the bottom left corner of the box.
1.129 ///If the bounding box is empty, then the return value is not defined.
1.130 Point<T> bottomLeft() const {
1.131 return bottom_left;
1.132 }
1.133
1.134 - ///Set the bottom left corner
1.135 + ///Set the bottom left corner of the box
1.136
1.137 - ///Set the bottom left corner.
1.138 - ///It should only bee used for non-empty box.
1.139 + ///Set the bottom left corner of the box.
1.140 + ///It should only be used for non-empty box.
1.141 void bottomLeft(Point<T> p) {
1.142 bottom_left = p;
1.143 }
1.144
1.145 - ///Give back the top right corner
1.146 + ///Give back the top right corner of the box
1.147
1.148 - ///Give back the top right corner.
1.149 + ///Give back the top right corner of the box.
1.150 ///If the bounding box is empty, then the return value is not defined.
1.151 Point<T> topRight() const {
1.152 return top_right;
1.153 }
1.154
1.155 - ///Set the top right corner
1.156 + ///Set the top right corner of the box
1.157
1.158 - ///Set the top right corner.
1.159 - ///It should only bee used for non-empty box.
1.160 + ///Set the top right corner of the box.
1.161 + ///It should only be used for non-empty box.
1.162 void topRight(Point<T> p) {
1.163 top_right = p;
1.164 }
1.165
1.166 - ///Give back the bottom right corner
1.167 + ///Give back the bottom right corner of the box
1.168
1.169 - ///Give back the bottom right corner.
1.170 + ///Give back the bottom right corner of the box.
1.171 ///If the bounding box is empty, then the return value is not defined.
1.172 Point<T> bottomRight() const {
1.173 return Point<T>(top_right.x,bottom_left.y);
1.174 }
1.175
1.176 - ///Set the bottom right corner
1.177 + ///Set the bottom right corner of the box
1.178
1.179 - ///Set the bottom right corner.
1.180 - ///It should only bee used for non-empty box.
1.181 + ///Set the bottom right corner of the box.
1.182 + ///It should only be used for non-empty box.
1.183 void bottomRight(Point<T> p) {
1.184 top_right.x = p.x;
1.185 bottom_left.y = p.y;
1.186 }
1.187
1.188 - ///Give back the top left corner
1.189 + ///Give back the top left corner of the box
1.190
1.191 - ///Give back the top left corner.
1.192 + ///Give back the top left corner of the box.
1.193 ///If the bounding box is empty, then the return value is not defined.
1.194 Point<T> topLeft() const {
1.195 return Point<T>(bottom_left.x,top_right.y);
1.196 }
1.197
1.198 - ///Set the top left corner
1.199 + ///Set the top left corner of the box
1.200
1.201 - ///Set the top left corner.
1.202 - ///It should only bee used for non-empty box.
1.203 + ///Set the top left corner of the box.
1.204 + ///It should only be used for non-empty box.
1.205 void topLeft(Point<T> p) {
1.206 top_right.y = p.y;
1.207 bottom_left.x = p.x;
1.208 @@ -395,7 +405,7 @@
1.209 ///Set the bottom of the box
1.210
1.211 ///Set the bottom of the box.
1.212 - ///It should only bee used for non-empty box.
1.213 + ///It should only be used for non-empty box.
1.214 void bottom(T t) {
1.215 bottom_left.y = t;
1.216 }
1.217 @@ -411,7 +421,7 @@
1.218 ///Set the top of the box
1.219
1.220 ///Set the top of the box.
1.221 - ///It should only bee used for non-empty box.
1.222 + ///It should only be used for non-empty box.
1.223 void top(T t) {
1.224 top_right.y = t;
1.225 }
1.226 @@ -427,7 +437,7 @@
1.227 ///Set the left side of the box
1.228
1.229 ///Set the left side of the box.
1.230 - ///It should only bee used for non-empty box
1.231 + ///It should only be used for non-empty box.
1.232 void left(T t) {
1.233 bottom_left.x = t;
1.234 }
1.235 @@ -443,7 +453,7 @@
1.236 ///Set the right side of the box
1.237
1.238 ///Set the right side of the box.
1.239 - ///It should only bee used for non-empty box
1.240 + ///It should only be used for non-empty box.
1.241 void right(T t) {
1.242 top_right.x = t;
1.243 }
1.244 @@ -465,7 +475,7 @@
1.245 }
1.246
1.247 ///Checks whether a point is inside a bounding box
1.248 - bool inside(const Point<T>& u){
1.249 + bool inside(const Point<T>& u) const {
1.250 if (_empty)
1.251 return false;
1.252 else{
1.253 @@ -475,6 +485,9 @@
1.254 }
1.255
1.256 ///Increments a bounding box with a point
1.257 +
1.258 + ///Increments a bounding box with a point.
1.259 + ///
1.260 BoundingBox& add(const Point<T>& u){
1.261 if (_empty){
1.262 bottom_left=top_right=u;
1.263 @@ -489,7 +502,10 @@
1.264 return *this;
1.265 }
1.266
1.267 - ///Increments a bounding to contain another bounding box
1.268 + ///Increments a bounding box to contain another bounding box
1.269 +
1.270 + ///Increments a bounding box to contain another bounding box.
1.271 + ///
1.272 BoundingBox& add(const BoundingBox &u){
1.273 if ( !u.empty() ){
1.274 this->add(u.bottomLeft());
1.275 @@ -499,24 +515,31 @@
1.276 }
1.277
1.278 ///Intersection of two bounding boxes
1.279 - BoundingBox operator &(const BoundingBox& u){
1.280 +
1.281 + ///Intersection of two bounding boxes.
1.282 + ///
1.283 + BoundingBox operator&(const BoundingBox& u) const {
1.284 BoundingBox b;
1.285 - b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
1.286 - b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
1.287 - b.top_right.x=std::min(this->top_right.x,u.top_right.x);
1.288 - b.top_right.y=std::min(this->top_right.y,u.top_right.y);
1.289 - b._empty = this->_empty || u._empty ||
1.290 - b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y;
1.291 + if (this->_empty || u._empty) {
1.292 + b._empty = true;
1.293 + } else {
1.294 + b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x);
1.295 + b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y);
1.296 + b.top_right.x=std::min(this->top_right.x,u.top_right.x);
1.297 + b.top_right.y=std::min(this->top_right.y,u.top_right.y);
1.298 + b._empty = b.bottom_left.x > b.top_right.x ||
1.299 + b.bottom_left.y > b.top_right.y;
1.300 + }
1.301 return b;
1.302 }
1.303
1.304 };//class Boundingbox
1.305
1.306
1.307 - ///Map of x-coordinates of a dim2::Point<>-map
1.308 + ///Map of x-coordinates of a \ref Point "Point"-map
1.309
1.310 ///\ingroup maps
1.311 - ///Map of x-coordinates of a dim2::Point<>-map
1.312 + ///Map of x-coordinates of a \ref Point "Point"-map.
1.313 ///
1.314 template<class M>
1.315 class XMap
1.316 @@ -570,7 +593,7 @@
1.317
1.318 ///Returns a \ref ConstXMap class
1.319
1.320 - ///This function just returns an \ref ConstXMap class.
1.321 + ///This function just returns a \ref ConstXMap class.
1.322 ///
1.323 ///\ingroup maps
1.324 ///\relates ConstXMap
1.325 @@ -580,10 +603,10 @@
1.326 return ConstXMap<M>(m);
1.327 }
1.328
1.329 - ///Map of y-coordinates of a dim2::Point<>-map
1.330 + ///Map of y-coordinates of a \ref Point "Point"-map
1.331
1.332 ///\ingroup maps
1.333 - ///Map of y-coordinates of a dim2::Point<>-map
1.334 + ///Map of y-coordinates of a \ref Point "Point"-map.
1.335 ///
1.336 template<class M>
1.337 class YMap
1.338 @@ -599,9 +622,9 @@
1.339 void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
1.340 };
1.341
1.342 - ///Returns an \ref YMap class
1.343 + ///Returns a \ref YMap class
1.344
1.345 - ///This function just returns an \ref YMap class.
1.346 + ///This function just returns a \ref YMap class.
1.347 ///
1.348 ///\ingroup maps
1.349 ///\relates YMap
1.350 @@ -637,7 +660,7 @@
1.351
1.352 ///Returns a \ref ConstYMap class
1.353
1.354 - ///This function just returns an \ref ConstYMap class.
1.355 + ///This function just returns a \ref ConstYMap class.
1.356 ///
1.357 ///\ingroup maps
1.358 ///\relates ConstYMap
1.359 @@ -648,12 +671,12 @@
1.360 }
1.361
1.362
1.363 - ///\brief Map of the \ref Point::normSquare() "normSquare()"
1.364 - ///of an \ref Point "Point"-map
1.365 - ///
1.366 - ///Map of the \ref Point::normSquare() "normSquare()"
1.367 - ///of an \ref Point "Point"-map
1.368 - ///\ingroup maps
1.369 + ///\brief Map of the \ref Point::normSquare() "normSquare()"
1.370 + ///of a \ref Point "Point"-map
1.371 + ///
1.372 + ///Map of the \ref Point::normSquare() "normSquare()"
1.373 + ///of a \ref Point "Point"-map.
1.374 + ///\ingroup maps
1.375 ///
1.376 template<class M>
1.377 class NormSquareMap
1.378 @@ -670,7 +693,7 @@
1.379
1.380 ///Returns a \ref NormSquareMap class
1.381
1.382 - ///This function just returns an \ref NormSquareMap class.
1.383 + ///This function just returns a \ref NormSquareMap class.
1.384 ///
1.385 ///\ingroup maps
1.386 ///\relates NormSquareMap