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