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