[906] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
[1956] | 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[906] | 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[2207] | 19 | #ifndef LEMON_DIM2_H |
---|
| 20 | #define LEMON_DIM2_H |
---|
[201] | 21 | |
---|
| 22 | #include <iostream> |
---|
[1993] | 23 | #include <lemon/bits/utility.h> |
---|
[201] | 24 | |
---|
[491] | 25 | ///\ingroup misc |
---|
[249] | 26 | ///\file |
---|
| 27 | ///\brief A simple two dimensional vector and a bounding box implementation |
---|
| 28 | /// |
---|
[2207] | 29 | /// The class \ref lemon::dim2::Point "dim2::Point" implements |
---|
[249] | 30 | ///a two dimensional vector with the usual |
---|
| 31 | /// operations. |
---|
| 32 | /// |
---|
[2207] | 33 | /// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" |
---|
| 34 | /// can be used to determine |
---|
| 35 | /// the rectangular bounding box of a set of |
---|
| 36 | /// \ref lemon::dim2::Point "dim2::Point"'s. |
---|
[458] | 37 | /// |
---|
| 38 | ///\author Attila Bernath |
---|
[249] | 39 | |
---|
| 40 | |
---|
[921] | 41 | namespace lemon { |
---|
[431] | 42 | |
---|
[2207] | 43 | ///Tools for handling two dimensional coordinates |
---|
| 44 | |
---|
| 45 | ///This namespace is a storage of several |
---|
| 46 | ///tools for handling two dimensional coordinates |
---|
| 47 | namespace dim2 { |
---|
| 48 | |
---|
[431] | 49 | /// \addtogroup misc |
---|
| 50 | /// @{ |
---|
| 51 | |
---|
[1257] | 52 | /// A simple two dimensional vector (plainvector) implementation |
---|
[242] | 53 | |
---|
[1257] | 54 | /// A simple two dimensional vector (plainvector) implementation |
---|
[458] | 55 | ///with the usual vector |
---|
| 56 | /// operators. |
---|
| 57 | /// |
---|
[207] | 58 | template<typename T> |
---|
[2207] | 59 | class Point { |
---|
[201] | 60 | |
---|
[207] | 61 | public: |
---|
[240] | 62 | |
---|
[987] | 63 | typedef T Value; |
---|
[964] | 64 | |
---|
[1974] | 65 | ///First co-ordinate |
---|
| 66 | T x; |
---|
| 67 | ///Second co-ordinate |
---|
| 68 | T y; |
---|
[207] | 69 | |
---|
[1257] | 70 | ///Default constructor |
---|
[2207] | 71 | Point() {} |
---|
[201] | 72 | |
---|
[2157] | 73 | ///Construct an instance from coordinates |
---|
[2207] | 74 | Point(T a, T b) : x(a), y(b) { } |
---|
[201] | 75 | |
---|
| 76 | |
---|
[1049] | 77 | ///Conversion constructor |
---|
[2207] | 78 | template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {} |
---|
[1049] | 79 | |
---|
[2157] | 80 | ///Give back the square of the norm of the vector |
---|
[1257] | 81 | T normSquare() const { |
---|
[1426] | 82 | return x*x+y*y; |
---|
[1391] | 83 | } |
---|
[201] | 84 | |
---|
[2157] | 85 | ///Increment the left hand side by u |
---|
[2207] | 86 | Point<T>& operator +=(const Point<T>& u) { |
---|
[1426] | 87 | x += u.x; |
---|
| 88 | y += u.y; |
---|
| 89 | return *this; |
---|
[1391] | 90 | } |
---|
[201] | 91 | |
---|
[2157] | 92 | ///Decrement the left hand side by u |
---|
[2207] | 93 | Point<T>& operator -=(const Point<T>& u) { |
---|
[1426] | 94 | x -= u.x; |
---|
| 95 | y -= u.y; |
---|
| 96 | return *this; |
---|
[1391] | 97 | } |
---|
[201] | 98 | |
---|
[2157] | 99 | ///Multiply the left hand side with a scalar |
---|
[2207] | 100 | Point<T>& operator *=(const T &u) { |
---|
[1426] | 101 | x *= u; |
---|
| 102 | y *= u; |
---|
| 103 | return *this; |
---|
[1391] | 104 | } |
---|
[207] | 105 | |
---|
[2157] | 106 | ///Divide the left hand side by a scalar |
---|
[2207] | 107 | Point<T>& operator /=(const T &u) { |
---|
[1426] | 108 | x /= u; |
---|
| 109 | y /= u; |
---|
| 110 | return *this; |
---|
[1391] | 111 | } |
---|
[201] | 112 | |
---|
[2157] | 113 | ///Return the scalar product of two vectors |
---|
[2207] | 114 | T operator *(const Point<T>& u) const { |
---|
[1426] | 115 | return x*u.x+y*u.y; |
---|
[1391] | 116 | } |
---|
[201] | 117 | |
---|
[2157] | 118 | ///Return the sum of two vectors |
---|
[2207] | 119 | Point<T> operator+(const Point<T> &u) const { |
---|
| 120 | Point<T> b=*this; |
---|
[1426] | 121 | return b+=u; |
---|
[1391] | 122 | } |
---|
[201] | 123 | |
---|
[2157] | 124 | ///Return the neg of the vectors |
---|
[2207] | 125 | Point<T> operator-() const { |
---|
| 126 | Point<T> b=*this; |
---|
[1426] | 127 | b.x=-b.x; b.y=-b.y; |
---|
| 128 | return b; |
---|
[1391] | 129 | } |
---|
[1049] | 130 | |
---|
[2157] | 131 | ///Return the difference of two vectors |
---|
[2207] | 132 | Point<T> operator-(const Point<T> &u) const { |
---|
| 133 | Point<T> b=*this; |
---|
[1426] | 134 | return b-=u; |
---|
[1391] | 135 | } |
---|
[201] | 136 | |
---|
[2157] | 137 | ///Return a vector multiplied by a scalar |
---|
[2207] | 138 | Point<T> operator*(const T &u) const { |
---|
| 139 | Point<T> b=*this; |
---|
[1426] | 140 | return b*=u; |
---|
[1391] | 141 | } |
---|
[201] | 142 | |
---|
[2157] | 143 | ///Return a vector divided by a scalar |
---|
[2207] | 144 | Point<T> operator/(const T &u) const { |
---|
| 145 | Point<T> b=*this; |
---|
[1426] | 146 | return b/=u; |
---|
[1391] | 147 | } |
---|
[201] | 148 | |
---|
[2157] | 149 | ///Test equality |
---|
[2207] | 150 | bool operator==(const Point<T> &u) const { |
---|
[1426] | 151 | return (x==u.x) && (y==u.y); |
---|
[1391] | 152 | } |
---|
[201] | 153 | |
---|
[2157] | 154 | ///Test inequality |
---|
[2207] | 155 | bool operator!=(Point u) const { |
---|
[1426] | 156 | return (x!=u.x) || (y!=u.y); |
---|
[1391] | 157 | } |
---|
[201] | 158 | |
---|
[207] | 159 | }; |
---|
[201] | 160 | |
---|
[2207] | 161 | ///Return an Point |
---|
[1999] | 162 | |
---|
[2207] | 163 | ///Return an Point |
---|
| 164 | ///\relates Point |
---|
[1999] | 165 | template <typename T> |
---|
[2207] | 166 | inline Point<T> make_Point(const T& x, const T& y) { |
---|
| 167 | return Point<T>(x, y); |
---|
[1999] | 168 | } |
---|
| 169 | |
---|
[2157] | 170 | ///Return a vector multiplied by a scalar |
---|
[1083] | 171 | |
---|
[2157] | 172 | ///Return a vector multiplied by a scalar |
---|
[2207] | 173 | ///\relates Point |
---|
| 174 | template<typename T> Point<T> operator*(const T &u,const Point<T> &x) { |
---|
[1071] | 175 | return x*u; |
---|
[1391] | 176 | } |
---|
[1071] | 177 | |
---|
[814] | 178 | ///Read a plainvector from a stream |
---|
| 179 | |
---|
[967] | 180 | ///Read a plainvector from a stream |
---|
[2207] | 181 | ///\relates Point |
---|
[814] | 182 | /// |
---|
[207] | 183 | template<typename T> |
---|
[2207] | 184 | inline std::istream& operator>>(std::istream &is, Point<T> &z) { |
---|
[1392] | 185 | char c; |
---|
| 186 | if (is >> c) { |
---|
| 187 | if (c != '(') is.putback(c); |
---|
| 188 | } else { |
---|
| 189 | is.clear(); |
---|
| 190 | } |
---|
| 191 | if (!(is >> z.x)) return is; |
---|
| 192 | if (is >> c) { |
---|
| 193 | if (c != ',') is.putback(c); |
---|
| 194 | } else { |
---|
| 195 | is.clear(); |
---|
| 196 | } |
---|
| 197 | if (!(is >> z.y)) return is; |
---|
| 198 | if (is >> c) { |
---|
| 199 | if (c != ')') is.putback(c); |
---|
| 200 | } else { |
---|
| 201 | is.clear(); |
---|
| 202 | } |
---|
[207] | 203 | return is; |
---|
| 204 | } |
---|
[201] | 205 | |
---|
[814] | 206 | ///Write a plainvector to a stream |
---|
| 207 | |
---|
[967] | 208 | ///Write a plainvector to a stream |
---|
[2207] | 209 | ///\relates Point |
---|
[814] | 210 | /// |
---|
[207] | 211 | template<typename T> |
---|
[2207] | 212 | inline std::ostream& operator<<(std::ostream &os, const Point<T>& z) |
---|
[207] | 213 | { |
---|
[240] | 214 | os << "(" << z.x << ", " << z.y << ")"; |
---|
[207] | 215 | return os; |
---|
| 216 | } |
---|
| 217 | |
---|
[1202] | 218 | ///Rotate by 90 degrees |
---|
| 219 | |
---|
| 220 | ///Returns its parameter rotated by 90 degrees in positive direction. |
---|
[2207] | 221 | ///\relates Point |
---|
[1202] | 222 | /// |
---|
| 223 | template<typename T> |
---|
[2207] | 224 | inline Point<T> rot90(const Point<T> &z) |
---|
[1202] | 225 | { |
---|
[2207] | 226 | return Point<T>(-z.y,z.x); |
---|
[1202] | 227 | } |
---|
| 228 | |
---|
[2157] | 229 | ///Rotate by 180 degrees |
---|
| 230 | |
---|
| 231 | ///Returns its parameter rotated by 180 degrees. |
---|
[2207] | 232 | ///\relates Point |
---|
[2157] | 233 | /// |
---|
| 234 | template<typename T> |
---|
[2207] | 235 | inline Point<T> rot180(const Point<T> &z) |
---|
[2157] | 236 | { |
---|
[2207] | 237 | return Point<T>(-z.x,-z.y); |
---|
[2157] | 238 | } |
---|
| 239 | |
---|
[1202] | 240 | ///Rotate by 270 degrees |
---|
| 241 | |
---|
| 242 | ///Returns its parameter rotated by 90 degrees in negative direction. |
---|
[2207] | 243 | ///\relates Point |
---|
[1202] | 244 | /// |
---|
| 245 | template<typename T> |
---|
[2207] | 246 | inline Point<T> rot270(const Point<T> &z) |
---|
[1202] | 247 | { |
---|
[2207] | 248 | return Point<T>(z.y,-z.x); |
---|
[1202] | 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
[244] | 252 | |
---|
[458] | 253 | /// A class to calculate or store the bounding box of plainvectors. |
---|
| 254 | |
---|
| 255 | /// A class to calculate or store the bounding box of plainvectors. |
---|
| 256 | /// |
---|
| 257 | ///\author Attila Bernath |
---|
[244] | 258 | template<typename T> |
---|
| 259 | class BoundingBox { |
---|
[2207] | 260 | Point<T> bottom_left, top_right; |
---|
[244] | 261 | bool _empty; |
---|
| 262 | public: |
---|
| 263 | |
---|
[1426] | 264 | ///Default constructor: creates an empty bounding box |
---|
[244] | 265 | BoundingBox() { _empty = true; } |
---|
| 266 | |
---|
[2157] | 267 | ///Construct an instance from one point |
---|
[2207] | 268 | BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; } |
---|
[244] | 269 | |
---|
[1426] | 270 | ///Were any points added? |
---|
[244] | 271 | bool empty() const { |
---|
[1426] | 272 | return _empty; |
---|
[244] | 273 | } |
---|
| 274 | |
---|
[2157] | 275 | ///Make the BoundingBox empty |
---|
[1391] | 276 | void clear() { |
---|
[1426] | 277 | _empty=1; |
---|
[1391] | 278 | } |
---|
| 279 | |
---|
[2157] | 280 | ///Give back the bottom left corner |
---|
| 281 | |
---|
| 282 | ///Give back the bottom left corner. |
---|
| 283 | ///If the bounding box is empty, then the return value is not defined. |
---|
[2207] | 284 | Point<T> bottomLeft() const { |
---|
[1426] | 285 | return bottom_left; |
---|
[1391] | 286 | } |
---|
[244] | 287 | |
---|
[2157] | 288 | ///Set the bottom left corner |
---|
| 289 | |
---|
| 290 | ///Set the bottom left corner. |
---|
| 291 | ///It should only bee used for non-empty box. |
---|
[2207] | 292 | void bottomLeft(Point<T> p) { |
---|
[1927] | 293 | bottom_left = p; |
---|
| 294 | } |
---|
| 295 | |
---|
[2157] | 296 | ///Give back the top right corner |
---|
| 297 | |
---|
| 298 | ///Give back the top right corner. |
---|
| 299 | ///If the bounding box is empty, then the return value is not defined. |
---|
[2207] | 300 | Point<T> topRight() const { |
---|
[1426] | 301 | return top_right; |
---|
[1391] | 302 | } |
---|
[244] | 303 | |
---|
[2157] | 304 | ///Set the top right corner |
---|
| 305 | |
---|
| 306 | ///Set the top right corner. |
---|
| 307 | ///It should only bee used for non-empty box. |
---|
[2207] | 308 | void topRight(Point<T> p) { |
---|
[1927] | 309 | top_right = p; |
---|
| 310 | } |
---|
| 311 | |
---|
[2157] | 312 | ///Give back the bottom right corner |
---|
| 313 | |
---|
| 314 | ///Give back the bottom right corner. |
---|
| 315 | ///If the bounding box is empty, then the return value is not defined. |
---|
[2207] | 316 | Point<T> bottomRight() const { |
---|
| 317 | return Point<T>(top_right.x,bottom_left.y); |
---|
[1391] | 318 | } |
---|
[1045] | 319 | |
---|
[2157] | 320 | ///Set the bottom right corner |
---|
| 321 | |
---|
| 322 | ///Set the bottom right corner. |
---|
| 323 | ///It should only bee used for non-empty box. |
---|
[2207] | 324 | void bottomRight(Point<T> p) { |
---|
[1927] | 325 | top_right.x = p.x; |
---|
| 326 | bottom_left.y = p.y; |
---|
| 327 | } |
---|
[2157] | 328 | |
---|
| 329 | ///Give back the top left corner |
---|
[1927] | 330 | |
---|
[2157] | 331 | ///Give back the top left corner. |
---|
| 332 | ///If the bounding box is empty, then the return value is not defined. |
---|
[2207] | 333 | Point<T> topLeft() const { |
---|
| 334 | return Point<T>(bottom_left.x,top_right.y); |
---|
[1391] | 335 | } |
---|
[1045] | 336 | |
---|
[2157] | 337 | ///Set the top left corner |
---|
| 338 | |
---|
| 339 | ///Set the top left corner. |
---|
| 340 | ///It should only bee used for non-empty box. |
---|
[2207] | 341 | void topLeft(Point<T> p) { |
---|
[1927] | 342 | top_right.y = p.y; |
---|
| 343 | bottom_left.x = p.x; |
---|
| 344 | } |
---|
| 345 | |
---|
[2157] | 346 | ///Give back the bottom of the box |
---|
| 347 | |
---|
| 348 | ///Give back the bottom of the box. |
---|
| 349 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1045] | 350 | T bottom() const { |
---|
[1426] | 351 | return bottom_left.y; |
---|
[1391] | 352 | } |
---|
[1045] | 353 | |
---|
[2157] | 354 | ///Set the bottom of the box |
---|
| 355 | |
---|
| 356 | ///Set the bottom of the box. |
---|
| 357 | ///It should only bee used for non-empty box. |
---|
[1927] | 358 | void bottom(T t) { |
---|
| 359 | bottom_left.y = t; |
---|
| 360 | } |
---|
| 361 | |
---|
[2157] | 362 | ///Give back the top of the box |
---|
| 363 | |
---|
| 364 | ///Give back the top of the box. |
---|
| 365 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1045] | 366 | T top() const { |
---|
[1426] | 367 | return top_right.y; |
---|
[1391] | 368 | } |
---|
[1045] | 369 | |
---|
[2157] | 370 | ///Set the top of the box |
---|
| 371 | |
---|
| 372 | ///Set the top of the box. |
---|
| 373 | ///It should only bee used for non-empty box. |
---|
[1927] | 374 | void top(T t) { |
---|
| 375 | top_right.y = t; |
---|
| 376 | } |
---|
| 377 | |
---|
[2157] | 378 | ///Give back the left side of the box |
---|
| 379 | |
---|
| 380 | ///Give back the left side of the box. |
---|
| 381 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1045] | 382 | T left() const { |
---|
[1426] | 383 | return bottom_left.x; |
---|
[1391] | 384 | } |
---|
[2157] | 385 | |
---|
| 386 | ///Set the left side of the box |
---|
[1045] | 387 | |
---|
[2157] | 388 | ///Set the left side of the box. |
---|
| 389 | ///It should only bee used for non-empty box |
---|
[1927] | 390 | void left(T t) { |
---|
| 391 | bottom_left.x = t; |
---|
| 392 | } |
---|
| 393 | |
---|
[2157] | 394 | /// Give back the right side of the box |
---|
| 395 | |
---|
| 396 | /// Give back the right side of the box. |
---|
| 397 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1045] | 398 | T right() const { |
---|
[1426] | 399 | return top_right.x; |
---|
[1391] | 400 | } |
---|
[1045] | 401 | |
---|
[2157] | 402 | ///Set the right side of the box |
---|
| 403 | |
---|
| 404 | ///Set the right side of the box. |
---|
| 405 | ///It should only bee used for non-empty box |
---|
[1927] | 406 | void right(T t) { |
---|
| 407 | top_right.x = t; |
---|
| 408 | } |
---|
| 409 | |
---|
[2157] | 410 | ///Give back the height of the box |
---|
| 411 | |
---|
| 412 | ///Give back the height of the box. |
---|
| 413 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1102] | 414 | T height() const { |
---|
[1426] | 415 | return top_right.y-bottom_left.y; |
---|
[1391] | 416 | } |
---|
[1102] | 417 | |
---|
[2157] | 418 | ///Give back the width of the box |
---|
| 419 | |
---|
| 420 | ///Give back the width of the box. |
---|
| 421 | ///If the bounding box is empty, then the return value is not defined. |
---|
[1102] | 422 | T width() const { |
---|
[1426] | 423 | return top_right.x-bottom_left.x; |
---|
[1391] | 424 | } |
---|
[1102] | 425 | |
---|
[244] | 426 | ///Checks whether a point is inside a bounding box |
---|
[2207] | 427 | bool inside(const Point<T>& u){ |
---|
[1426] | 428 | if (_empty) |
---|
| 429 | return false; |
---|
| 430 | else{ |
---|
| 431 | return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 && |
---|
| 432 | (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 ); |
---|
| 433 | } |
---|
[244] | 434 | } |
---|
| 435 | |
---|
| 436 | ///Increments a bounding box with a point |
---|
[2207] | 437 | BoundingBox& add(const Point<T>& u){ |
---|
[1426] | 438 | if (_empty){ |
---|
| 439 | bottom_left=top_right=u; |
---|
| 440 | _empty = false; |
---|
| 441 | } |
---|
| 442 | else{ |
---|
| 443 | if (bottom_left.x > u.x) bottom_left.x = u.x; |
---|
| 444 | if (bottom_left.y > u.y) bottom_left.y = u.y; |
---|
| 445 | if (top_right.x < u.x) top_right.x = u.x; |
---|
| 446 | if (top_right.y < u.y) top_right.y = u.y; |
---|
| 447 | } |
---|
| 448 | return *this; |
---|
[1391] | 449 | } |
---|
[244] | 450 | |
---|
[1588] | 451 | // ///Sums a bounding box and a point |
---|
[2207] | 452 | // BoundingBox operator +(const Point<T>& u){ |
---|
[1588] | 453 | // BoundingBox b = *this; |
---|
| 454 | // return b += u; |
---|
| 455 | // } |
---|
[244] | 456 | |
---|
[2006] | 457 | ///Increments a bounding box with another bounding box |
---|
[1588] | 458 | BoundingBox& add(const BoundingBox &u){ |
---|
[1426] | 459 | if ( !u.empty() ){ |
---|
[1588] | 460 | this->add(u.bottomLeft()); |
---|
| 461 | this->add(u.topRight()); |
---|
[1426] | 462 | } |
---|
| 463 | return *this; |
---|
[1391] | 464 | } |
---|
[244] | 465 | |
---|
| 466 | ///Sums two bounding boxes |
---|
| 467 | BoundingBox operator +(const BoundingBox& u){ |
---|
[1426] | 468 | BoundingBox b = *this; |
---|
[1588] | 469 | return b.add(u); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | |
---|
| 473 | ///Intersection of two bounding boxes |
---|
| 474 | BoundingBox operator &(const BoundingBox& u){ |
---|
| 475 | BoundingBox b; |
---|
| 476 | b.bottom_left.x=std::max(this->bottom_left.x,u.bottom_left.x); |
---|
| 477 | b.bottom_left.y=std::max(this->bottom_left.y,u.bottom_left.y); |
---|
| 478 | b.top_right.x=std::min(this->top_right.x,u.top_right.x); |
---|
| 479 | b.top_right.y=std::min(this->top_right.y,u.top_right.y); |
---|
| 480 | b._empty = this->_empty || u._empty || |
---|
| 481 | b.bottom_left.x>top_right.x && b.bottom_left.y>top_right.y; |
---|
| 482 | return b; |
---|
[1391] | 483 | } |
---|
[244] | 484 | |
---|
| 485 | };//class Boundingbox |
---|
| 486 | |
---|
| 487 | |
---|
[2207] | 488 | ///Map of x-coordinates of a dim2::Point<>-map |
---|
[1317] | 489 | |
---|
| 490 | ///\ingroup maps |
---|
| 491 | /// |
---|
| 492 | template<class M> |
---|
| 493 | class XMap |
---|
| 494 | { |
---|
[1706] | 495 | M& _map; |
---|
[1317] | 496 | public: |
---|
[1420] | 497 | |
---|
[1317] | 498 | typedef typename M::Value::Value Value; |
---|
| 499 | typedef typename M::Key Key; |
---|
| 500 | ///\e |
---|
[1706] | 501 | XMap(M& map) : _map(map) {} |
---|
[1317] | 502 | Value operator[](Key k) const {return _map[k].x;} |
---|
[1352] | 503 | void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));} |
---|
[1317] | 504 | }; |
---|
| 505 | |
---|
| 506 | ///Returns an \ref XMap class |
---|
| 507 | |
---|
| 508 | ///This function just returns an \ref XMap class. |
---|
| 509 | /// |
---|
| 510 | ///\ingroup maps |
---|
| 511 | ///\relates XMap |
---|
| 512 | template<class M> |
---|
| 513 | inline XMap<M> xMap(M &m) |
---|
| 514 | { |
---|
| 515 | return XMap<M>(m); |
---|
| 516 | } |
---|
| 517 | |
---|
[1420] | 518 | template<class M> |
---|
| 519 | inline XMap<M> xMap(const M &m) |
---|
| 520 | { |
---|
| 521 | return XMap<M>(m); |
---|
| 522 | } |
---|
| 523 | |
---|
[1317] | 524 | ///Constant (read only) version of \ref XMap |
---|
| 525 | |
---|
| 526 | ///\ingroup maps |
---|
| 527 | /// |
---|
| 528 | template<class M> |
---|
| 529 | class ConstXMap |
---|
| 530 | { |
---|
[1706] | 531 | const M& _map; |
---|
[1317] | 532 | public: |
---|
[1420] | 533 | |
---|
[1317] | 534 | typedef typename M::Value::Value Value; |
---|
| 535 | typedef typename M::Key Key; |
---|
| 536 | ///\e |
---|
| 537 | ConstXMap(const M &map) : _map(map) {} |
---|
| 538 | Value operator[](Key k) const {return _map[k].x;} |
---|
| 539 | }; |
---|
| 540 | |
---|
| 541 | ///Returns a \ref ConstXMap class |
---|
| 542 | |
---|
| 543 | ///This function just returns an \ref ConstXMap class. |
---|
| 544 | /// |
---|
| 545 | ///\ingroup maps |
---|
| 546 | ///\relates ConstXMap |
---|
| 547 | template<class M> |
---|
| 548 | inline ConstXMap<M> xMap(const M &m) |
---|
| 549 | { |
---|
| 550 | return ConstXMap<M>(m); |
---|
| 551 | } |
---|
| 552 | |
---|
[2207] | 553 | ///Map of y-coordinates of a dim2::Point<>-map |
---|
[1317] | 554 | |
---|
| 555 | ///\ingroup maps |
---|
| 556 | /// |
---|
| 557 | template<class M> |
---|
| 558 | class YMap |
---|
| 559 | { |
---|
[1706] | 560 | M& _map; |
---|
[1317] | 561 | public: |
---|
[1420] | 562 | |
---|
[1317] | 563 | typedef typename M::Value::Value Value; |
---|
| 564 | typedef typename M::Key Key; |
---|
| 565 | ///\e |
---|
[1706] | 566 | YMap(M& map) : _map(map) {} |
---|
[1317] | 567 | Value operator[](Key k) const {return _map[k].y;} |
---|
[1352] | 568 | void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));} |
---|
[1317] | 569 | }; |
---|
| 570 | |
---|
| 571 | ///Returns an \ref YMap class |
---|
| 572 | |
---|
| 573 | ///This function just returns an \ref YMap class. |
---|
| 574 | /// |
---|
| 575 | ///\ingroup maps |
---|
| 576 | ///\relates YMap |
---|
| 577 | template<class M> |
---|
| 578 | inline YMap<M> yMap(M &m) |
---|
| 579 | { |
---|
| 580 | return YMap<M>(m); |
---|
| 581 | } |
---|
| 582 | |
---|
[1420] | 583 | template<class M> |
---|
| 584 | inline YMap<M> yMap(const M &m) |
---|
| 585 | { |
---|
| 586 | return YMap<M>(m); |
---|
| 587 | } |
---|
| 588 | |
---|
[1317] | 589 | ///Constant (read only) version of \ref YMap |
---|
| 590 | |
---|
| 591 | ///\ingroup maps |
---|
| 592 | /// |
---|
| 593 | template<class M> |
---|
| 594 | class ConstYMap |
---|
| 595 | { |
---|
[1706] | 596 | const M& _map; |
---|
[1317] | 597 | public: |
---|
[1420] | 598 | |
---|
[1317] | 599 | typedef typename M::Value::Value Value; |
---|
| 600 | typedef typename M::Key Key; |
---|
| 601 | ///\e |
---|
| 602 | ConstYMap(const M &map) : _map(map) {} |
---|
| 603 | Value operator[](Key k) const {return _map[k].y;} |
---|
| 604 | }; |
---|
| 605 | |
---|
| 606 | ///Returns a \ref ConstYMap class |
---|
| 607 | |
---|
| 608 | ///This function just returns an \ref ConstYMap class. |
---|
| 609 | /// |
---|
| 610 | ///\ingroup maps |
---|
| 611 | ///\relates ConstYMap |
---|
| 612 | template<class M> |
---|
| 613 | inline ConstYMap<M> yMap(const M &m) |
---|
| 614 | { |
---|
| 615 | return ConstYMap<M>(m); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | |
---|
[2207] | 619 | ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"-map |
---|
[1352] | 620 | |
---|
[2207] | 621 | ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"-map |
---|
[1352] | 622 | ///\ingroup maps |
---|
| 623 | /// |
---|
| 624 | template<class M> |
---|
| 625 | class NormSquareMap |
---|
| 626 | { |
---|
[1706] | 627 | const M& _map; |
---|
[1352] | 628 | public: |
---|
[1420] | 629 | |
---|
[1352] | 630 | typedef typename M::Value::Value Value; |
---|
| 631 | typedef typename M::Key Key; |
---|
| 632 | ///\e |
---|
| 633 | NormSquareMap(const M &map) : _map(map) {} |
---|
| 634 | Value operator[](Key k) const {return _map[k].normSquare();} |
---|
| 635 | }; |
---|
| 636 | |
---|
| 637 | ///Returns a \ref NormSquareMap class |
---|
| 638 | |
---|
| 639 | ///This function just returns an \ref NormSquareMap class. |
---|
| 640 | /// |
---|
| 641 | ///\ingroup maps |
---|
| 642 | ///\relates NormSquareMap |
---|
| 643 | template<class M> |
---|
| 644 | inline NormSquareMap<M> normSquareMap(const M &m) |
---|
| 645 | { |
---|
| 646 | return NormSquareMap<M>(m); |
---|
| 647 | } |
---|
| 648 | |
---|
[431] | 649 | /// @} |
---|
[244] | 650 | |
---|
[2207] | 651 | } //namespce dim2 |
---|
| 652 | |
---|
[921] | 653 | } //namespace lemon |
---|
[201] | 654 | |
---|
[2207] | 655 | #endif //LEMON_DIM2_H |
---|