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