lemon/xy.h
author deba
Tue, 31 Jan 2006 20:04:36 +0000
changeset 1933 a876a3d6a4c7
parent 1875 98698b69a902
child 1956 a055123339d5
permissions -rw-r--r--
Revising the bpugraph concept

We need a public but very limited ANode and BNode class
It can be used with ItemSetTraits and with some special maps

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