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