1.1 --- a/lemon/dim2.h Sun Jul 13 16:46:56 2008 +0100
1.2 +++ b/lemon/dim2.h Sun Jul 13 19:51:02 2008 +0100
1.3 @@ -1,6 +1,6 @@
1.4 -/* -*- C++ -*-
1.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
1.6 *
1.7 - * This file is a part of LEMON, a generic C++ optimization library
1.8 + * This file is a part of LEMON, a generic C++ optimization library.
1.9 *
1.10 * Copyright (C) 2003-2008
1.11 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.12 @@ -24,7 +24,7 @@
1.13
1.14 ///\ingroup misc
1.15 ///\file
1.16 -///\brief A simple two dimensional vector and a bounding box implementation
1.17 +///\brief A simple two dimensional vector and a bounding box implementation
1.18 ///
1.19 /// The class \ref lemon::dim2::Point "dim2::Point" implements
1.20 /// a two dimensional vector with the usual operations.
1.21 @@ -59,8 +59,8 @@
1.22 ///First coordinate
1.23 T x;
1.24 ///Second coordinate
1.25 - T y;
1.26 -
1.27 + T y;
1.28 +
1.29 ///Default constructor
1.30 Point() {}
1.31
1.32 @@ -70,7 +70,7 @@
1.33 ///Returns the dimension of the vector (i.e. returns 2).
1.34
1.35 ///The dimension of the vector.
1.36 - ///This function always returns 2.
1.37 + ///This function always returns 2.
1.38 int size() const { return 2; }
1.39
1.40 ///Subscripting operator
1.41 @@ -92,14 +92,14 @@
1.42 T normSquare() const {
1.43 return x*x+y*y;
1.44 }
1.45 -
1.46 +
1.47 ///Increment the left hand side by \c u
1.48 Point<T>& operator +=(const Point<T>& u) {
1.49 x += u.x;
1.50 y += u.y;
1.51 return *this;
1.52 }
1.53 -
1.54 +
1.55 ///Decrement the left hand side by \c u
1.56 Point<T>& operator -=(const Point<T>& u) {
1.57 x -= u.x;
1.58 @@ -120,12 +120,12 @@
1.59 y /= u;
1.60 return *this;
1.61 }
1.62 -
1.63 +
1.64 ///Return the scalar product of two vectors
1.65 T operator *(const Point<T>& u) const {
1.66 return x*u.x+y*u.y;
1.67 }
1.68 -
1.69 +
1.70 ///Return the sum of two vectors
1.71 Point<T> operator+(const Point<T> &u) const {
1.72 Point<T> b=*this;
1.73 @@ -169,7 +169,7 @@
1.74
1.75 };
1.76
1.77 - ///Return a Point
1.78 + ///Return a Point
1.79
1.80 ///Return a Point.
1.81 ///\relates Point
1.82 @@ -259,7 +259,7 @@
1.83 return Point<T>(z.y,-z.x);
1.84 }
1.85
1.86 -
1.87 +
1.88
1.89 /// A class to calculate or store the bounding box of plainvectors.
1.90
1.91 @@ -270,15 +270,15 @@
1.92 Point<T> bottom_left, top_right;
1.93 bool _empty;
1.94 public:
1.95 -
1.96 +
1.97 ///Default constructor: creates an empty bounding box
1.98 BoundingBox() { _empty = true; }
1.99
1.100 ///Construct an instance from one point
1.101 BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
1.102 -
1.103 +
1.104 ///Construct an instance from two points
1.105 -
1.106 +
1.107 ///Construct an instance from two points.
1.108 ///\param a The bottom left corner.
1.109 ///\param b The top right corner.
1.110 @@ -286,11 +286,11 @@
1.111 ///than those of the top right one.
1.112 BoundingBox(Point<T> a,Point<T> b)
1.113 {
1.114 - bottom_left=a;
1.115 - top_right=b;
1.116 - _empty = false;
1.117 + bottom_left=a;
1.118 + top_right=b;
1.119 + _empty = false;
1.120 }
1.121 -
1.122 +
1.123 ///Construct an instance from four numbers
1.124
1.125 ///Construct an instance from four numbers.
1.126 @@ -299,25 +299,25 @@
1.127 ///\param r The right side of the box.
1.128 ///\param t The top of the box.
1.129 ///\warning The left side must be no more than the right side and
1.130 - ///bottom must be no more than the top.
1.131 + ///bottom must be no more than the top.
1.132 BoundingBox(T l,T b,T r,T t)
1.133 {
1.134 - bottom_left=Point<T>(l,b);
1.135 - top_right=Point<T>(r,t);
1.136 - _empty = false;
1.137 + bottom_left=Point<T>(l,b);
1.138 + top_right=Point<T>(r,t);
1.139 + _empty = false;
1.140 }
1.141 -
1.142 +
1.143 ///Return \c true if the bounding box is empty.
1.144 -
1.145 +
1.146 ///Return \c true if the bounding box is empty (i.e. return \c false
1.147 ///if at least one point was added to the box or the coordinates of
1.148 ///the box were set).
1.149 ///
1.150 - ///The coordinates of an empty bounding box are not defined.
1.151 + ///The coordinates of an empty bounding box are not defined.
1.152 bool empty() const {
1.153 return _empty;
1.154 }
1.155 -
1.156 +
1.157 ///Make the BoundingBox empty
1.158 void clear() {
1.159 _empty=1;
1.160 @@ -336,7 +336,7 @@
1.161 ///Set the bottom left corner of the box.
1.162 ///It should only be used for non-empty box.
1.163 void bottomLeft(Point<T> p) {
1.164 - bottom_left = p;
1.165 + bottom_left = p;
1.166 }
1.167
1.168 ///Give back the top right corner of the box
1.169 @@ -352,7 +352,7 @@
1.170 ///Set the top right corner of the box.
1.171 ///It should only be used for non-empty box.
1.172 void topRight(Point<T> p) {
1.173 - top_right = p;
1.174 + top_right = p;
1.175 }
1.176
1.177 ///Give back the bottom right corner of the box
1.178 @@ -368,10 +368,10 @@
1.179 ///Set the bottom right corner of the box.
1.180 ///It should only be used for non-empty box.
1.181 void bottomRight(Point<T> p) {
1.182 - top_right.x = p.x;
1.183 - bottom_left.y = p.y;
1.184 + top_right.x = p.x;
1.185 + bottom_left.y = p.y;
1.186 }
1.187 -
1.188 +
1.189 ///Give back the top left corner of the box
1.190
1.191 ///Give back the top left corner of the box.
1.192 @@ -385,8 +385,8 @@
1.193 ///Set the top left corner of the box.
1.194 ///It should only be used for non-empty box.
1.195 void topLeft(Point<T> p) {
1.196 - top_right.y = p.y;
1.197 - bottom_left.x = p.x;
1.198 + top_right.y = p.y;
1.199 + bottom_left.x = p.x;
1.200 }
1.201
1.202 ///Give back the bottom of the box
1.203 @@ -402,7 +402,7 @@
1.204 ///Set the bottom of the box.
1.205 ///It should only be used for non-empty box.
1.206 void bottom(T t) {
1.207 - bottom_left.y = t;
1.208 + bottom_left.y = t;
1.209 }
1.210
1.211 ///Give back the top of the box
1.212 @@ -418,7 +418,7 @@
1.213 ///Set the top of the box.
1.214 ///It should only be used for non-empty box.
1.215 void top(T t) {
1.216 - top_right.y = t;
1.217 + top_right.y = t;
1.218 }
1.219
1.220 ///Give back the left side of the box
1.221 @@ -428,13 +428,13 @@
1.222 T left() const {
1.223 return bottom_left.x;
1.224 }
1.225 -
1.226 +
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 be used for non-empty box.
1.231 void left(T t) {
1.232 - bottom_left.x = t;
1.233 + bottom_left.x = t;
1.234 }
1.235
1.236 /// Give back the right side of the box
1.237 @@ -450,7 +450,7 @@
1.238 ///Set the right side of the box.
1.239 ///It should only be used for non-empty box.
1.240 void right(T t) {
1.241 - top_right.x = t;
1.242 + top_right.x = t;
1.243 }
1.244
1.245 ///Give back the height of the box
1.246 @@ -478,7 +478,7 @@
1.247 (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
1.248 }
1.249 }
1.250 -
1.251 +
1.252 ///Increments a bounding box with a point
1.253
1.254 ///Increments a bounding box with a point.
1.255 @@ -496,19 +496,19 @@
1.256 }
1.257 return *this;
1.258 }
1.259 -
1.260 +
1.261 ///Increments a bounding box to contain another bounding box
1.262 -
1.263 +
1.264 ///Increments a bounding box to contain another bounding box.
1.265 ///
1.266 BoundingBox& add(const BoundingBox &u){
1.267 if ( !u.empty() ){
1.268 this->add(u.bottomLeft());
1.269 - this->add(u.topRight());
1.270 + this->add(u.topRight());
1.271 }
1.272 return *this;
1.273 }
1.274 -
1.275 +
1.276 ///Intersection of two bounding boxes
1.277
1.278 ///Intersection of two bounding boxes.
1.279 @@ -516,15 +516,15 @@
1.280 BoundingBox operator&(const BoundingBox& u) const {
1.281 BoundingBox b;
1.282 if (this->_empty || u._empty) {
1.283 - b._empty = true;
1.284 - } else {
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 = b.bottom_left.x > b.top_right.x ||
1.290 - b.bottom_left.y > b.top_right.y;
1.291 - }
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 @@ -537,7 +537,7 @@
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 + class XMap
1.310 {
1.311 M& _map;
1.312 public:
1.313 @@ -549,21 +549,21 @@
1.314 Value operator[](Key k) const {return _map[k].x;}
1.315 void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
1.316 };
1.317 -
1.318 +
1.319 ///Returns an \ref XMap class
1.320
1.321 ///This function just returns an \ref XMap class.
1.322 ///
1.323 ///\ingroup maps
1.324 ///\relates XMap
1.325 - template<class M>
1.326 - inline XMap<M> xMap(M &m)
1.327 + template<class M>
1.328 + inline XMap<M> xMap(M &m)
1.329 {
1.330 return XMap<M>(m);
1.331 }
1.332
1.333 - template<class M>
1.334 - inline XMap<M> xMap(const M &m)
1.335 + template<class M>
1.336 + inline XMap<M> xMap(const M &m)
1.337 {
1.338 return XMap<M>(m);
1.339 }
1.340 @@ -574,7 +574,7 @@
1.341 ///Constant (read only) version of \ref XMap
1.342 ///
1.343 template<class M>
1.344 - class ConstXMap
1.345 + class ConstXMap
1.346 {
1.347 const M& _map;
1.348 public:
1.349 @@ -585,26 +585,26 @@
1.350 ConstXMap(const M &map) : _map(map) {}
1.351 Value operator[](Key k) const {return _map[k].x;}
1.352 };
1.353 -
1.354 +
1.355 ///Returns a \ref ConstXMap class
1.356
1.357 ///This function just returns a \ref ConstXMap class.
1.358 ///
1.359 ///\ingroup maps
1.360 ///\relates ConstXMap
1.361 - template<class M>
1.362 - inline ConstXMap<M> xMap(const M &m)
1.363 + template<class M>
1.364 + inline ConstXMap<M> xMap(const M &m)
1.365 {
1.366 return ConstXMap<M>(m);
1.367 }
1.368
1.369 ///Map of y-coordinates of a \ref Point "Point"-map
1.370 -
1.371 +
1.372 ///\ingroup maps
1.373 ///Map of y-coordinates of a \ref Point "Point"-map.
1.374 ///
1.375 template<class M>
1.376 - class YMap
1.377 + class YMap
1.378 {
1.379 M& _map;
1.380 public:
1.381 @@ -623,14 +623,14 @@
1.382 ///
1.383 ///\ingroup maps
1.384 ///\relates YMap
1.385 - template<class M>
1.386 - inline YMap<M> yMap(M &m)
1.387 + template<class M>
1.388 + inline YMap<M> yMap(M &m)
1.389 {
1.390 return YMap<M>(m);
1.391 }
1.392
1.393 - template<class M>
1.394 - inline YMap<M> yMap(const M &m)
1.395 + template<class M>
1.396 + inline YMap<M> yMap(const M &m)
1.397 {
1.398 return YMap<M>(m);
1.399 }
1.400 @@ -641,7 +641,7 @@
1.401 ///Constant (read only) version of \ref YMap
1.402 ///
1.403 template<class M>
1.404 - class ConstYMap
1.405 + class ConstYMap
1.406 {
1.407 const M& _map;
1.408 public:
1.409 @@ -652,15 +652,15 @@
1.410 ConstYMap(const M &map) : _map(map) {}
1.411 Value operator[](Key k) const {return _map[k].y;}
1.412 };
1.413 -
1.414 +
1.415 ///Returns a \ref ConstYMap class
1.416
1.417 ///This function just returns a \ref ConstYMap class.
1.418 ///
1.419 ///\ingroup maps
1.420 ///\relates ConstYMap
1.421 - template<class M>
1.422 - inline ConstYMap<M> yMap(const M &m)
1.423 + template<class M>
1.424 + inline ConstYMap<M> yMap(const M &m)
1.425 {
1.426 return ConstYMap<M>(m);
1.427 }
1.428 @@ -673,7 +673,7 @@
1.429 ///of a \ref Point "Point"-map.
1.430 ///\ingroup maps
1.431 template<class M>
1.432 - class NormSquareMap
1.433 + class NormSquareMap
1.434 {
1.435 const M& _map;
1.436 public:
1.437 @@ -684,15 +684,15 @@
1.438 NormSquareMap(const M &map) : _map(map) {}
1.439 Value operator[](Key k) const {return _map[k].normSquare();}
1.440 };
1.441 -
1.442 +
1.443 ///Returns a \ref NormSquareMap class
1.444
1.445 ///This function just returns a \ref NormSquareMap class.
1.446 ///
1.447 ///\ingroup maps
1.448 ///\relates NormSquareMap
1.449 - template<class M>
1.450 - inline NormSquareMap<M> normSquareMap(const M &m)
1.451 + template<class M>
1.452 + inline NormSquareMap<M> normSquareMap(const M &m)
1.453 {
1.454 return NormSquareMap<M>(m);
1.455 }
1.456 @@ -700,7 +700,7 @@
1.457 /// @}
1.458
1.459 } //namespce dim2
1.460 -
1.461 +
1.462 } //namespace lemon
1.463
1.464 #endif //LEMON_DIM2_H