COIN-OR::LEMON - Graph Library

Changeset 2207:75a29ac69c19 in lemon-0.x for lemon/dim2.h


Ignore:
Timestamp:
09/07/06 15:27:16 (13 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2933
Message:

xy -> dim2::Point

File:
1 moved

Legend:

Unmodified
Added
Removed
  • lemon/dim2.h

    r2157 r2207  
    1717 */
    1818
    19 #ifndef LEMON_XY_H
    20 #define LEMON_XY_H
     19#ifndef LEMON_DIM2_H
     20#define LEMON_DIM2_H
    2121
    2222#include <iostream>
     
    2727///\brief A simple two dimensional vector and a bounding box implementation
    2828///
    29 /// The class \ref lemon::xy "xy" implements
     29/// The class \ref lemon::dim2::Point "dim2::Point" implements
    3030///a two dimensional vector with the usual
    3131/// operations.
    3232///
    33 /// The class \ref lemon::BoundingBox "BoundingBox" can be used to determine
    34 /// the rectangular bounding box of a set of \ref lemon::xy "xy"'s.
     33/// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox"
     34/// can be used to determine
     35/// the rectangular bounding box of a set of
     36/// \ref lemon::dim2::Point "dim2::Point"'s.
    3537///
    3638///\author Attila Bernath
     
    3840
    3941namespace lemon {
     42
     43  ///Tools for handling two dimensional coordinates
     44
     45  ///This namespace is a storage of several
     46  ///tools for handling two dimensional coordinates
     47  namespace dim2 {
    4048
    4149  /// \addtogroup misc
     
    4856  /// operators.
    4957  ///
    50   ///\note As you might have noticed, this class does not follow the
    51   ///\ref naming_conv "LEMON Coding Style" (it should be called \c Xy
    52   ///according to it). There is a stupid Hungarian proverb, "A kiv&eacute;tel
    53   ///er&otilde;s&iacute;ti a szab&aacute;lyt" ("An exception
    54   ///reinforces a rule", which is
    55   ///actually a mistranslation of the Latin proverb "Exceptio probat regulam").
    56   ///This class is an example for that.
    57   ///\author Attila Bernath
    5858  template<typename T>
    59     class xy {
     59    class Point {
    6060
    6161    public:
     
    6969     
    7070      ///Default constructor
    71       xy() {}
     71      Point() {}
    7272
    7373      ///Construct an instance from coordinates
    74       xy(T a, T b) : x(a), y(b) { }
     74      Point(T a, T b) : x(a), y(b) { }
    7575
    7676
    7777      ///Conversion constructor
    78       template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {}
     78      template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {}
    7979
    8080      ///Give back the square of the norm of the vector
     
    8484 
    8585      ///Increment the left hand side by u
    86       xy<T>& operator +=(const xy<T>& u) {
     86      Point<T>& operator +=(const Point<T>& u) {
    8787        x += u.x;
    8888        y += u.y;
     
    9191 
    9292      ///Decrement the left hand side by u
    93       xy<T>& operator -=(const xy<T>& u) {
     93      Point<T>& operator -=(const Point<T>& u) {
    9494        x -= u.x;
    9595        y -= u.y;
     
    9898
    9999      ///Multiply the left hand side with a scalar
    100       xy<T>& operator *=(const T &u) {
     100      Point<T>& operator *=(const T &u) {
    101101        x *= u;
    102102        y *= u;
     
    105105
    106106      ///Divide the left hand side by a scalar
    107       xy<T>& operator /=(const T &u) {
     107      Point<T>& operator /=(const T &u) {
    108108        x /= u;
    109109        y /= u;
     
    112112 
    113113      ///Return the scalar product of two vectors
    114       T operator *(const xy<T>& u) const {
     114      T operator *(const Point<T>& u) const {
    115115        return x*u.x+y*u.y;
    116116      }
    117117 
    118118      ///Return the sum of two vectors
    119       xy<T> operator+(const xy<T> &u) const {
    120         xy<T> b=*this;
     119      Point<T> operator+(const Point<T> &u) const {
     120        Point<T> b=*this;
    121121        return b+=u;
    122122      }
    123123
    124124      ///Return the neg of the vectors
    125       xy<T> operator-() const {
    126         xy<T> b=*this;
     125      Point<T> operator-() const {
     126        Point<T> b=*this;
    127127        b.x=-b.x; b.y=-b.y;
    128128        return b;
     
    130130
    131131      ///Return the difference of two vectors
    132       xy<T> operator-(const xy<T> &u) const {
    133         xy<T> b=*this;
     132      Point<T> operator-(const Point<T> &u) const {
     133        Point<T> b=*this;
    134134        return b-=u;
    135135      }
    136136
    137137      ///Return a vector multiplied by a scalar
    138       xy<T> operator*(const T &u) const {
    139         xy<T> b=*this;
     138      Point<T> operator*(const T &u) const {
     139        Point<T> b=*this;
    140140        return b*=u;
    141141      }
    142142
    143143      ///Return a vector divided by a scalar
    144       xy<T> operator/(const T &u) const {
    145         xy<T> b=*this;
     144      Point<T> operator/(const T &u) const {
     145        Point<T> b=*this;
    146146        return b/=u;
    147147      }
    148148
    149149      ///Test equality
    150       bool operator==(const xy<T> &u) const {
     150      bool operator==(const Point<T> &u) const {
    151151        return (x==u.x) && (y==u.y);
    152152      }
    153153
    154154      ///Test inequality
    155       bool operator!=(xy u) const {
     155      bool operator!=(Point u) const {
    156156        return  (x!=u.x) || (y!=u.y);
    157157      }
     
    159159    };
    160160
    161   ///Return an xy
    162 
    163   ///Return an xy
    164   ///\relates xy
     161  ///Return an Point
     162
     163  ///Return an Point
     164  ///\relates Point
    165165  template <typename T>
    166   inline xy<T> make_xy(const T& x, const T& y) {
    167     return xy<T>(x, y);
     166  inline Point<T> make_Point(const T& x, const T& y) {
     167    return Point<T>(x, y);
    168168  }
    169169
     
    171171
    172172  ///Return a vector multiplied by a scalar
    173   ///\relates xy
    174   template<typename T> xy<T> operator*(const T &u,const xy<T> &x) {
     173  ///\relates Point
     174  template<typename T> Point<T> operator*(const T &u,const Point<T> &x) {
    175175    return x*u;
    176176  }
     
    179179
    180180  ///Read a plainvector from a stream
    181   ///\relates xy
     181  ///\relates Point
    182182  ///
    183183  template<typename T>
    184   inline std::istream& operator>>(std::istream &is, xy<T> &z) {
     184  inline std::istream& operator>>(std::istream &is, Point<T> &z) {
    185185    char c;
    186186    if (is >> c) {
     
    207207
    208208  ///Write a plainvector to a stream
    209   ///\relates xy
     209  ///\relates Point
    210210  ///
    211211  template<typename T>
    212   inline std::ostream& operator<<(std::ostream &os, const xy<T>& z)
     212  inline std::ostream& operator<<(std::ostream &os, const Point<T>& z)
    213213  {
    214214    os << "(" << z.x << ", " << z.y << ")";
     
    219219
    220220  ///Returns its parameter rotated by 90 degrees in positive direction.
    221   ///\relates xy
     221  ///\relates Point
    222222  ///
    223223  template<typename T>
    224   inline xy<T> rot90(const xy<T> &z)
    225   {
    226     return xy<T>(-z.y,z.x);
     224  inline Point<T> rot90(const Point<T> &z)
     225  {
     226    return Point<T>(-z.y,z.x);
    227227  }
    228228
     
    230230
    231231  ///Returns its parameter rotated by 180 degrees.
    232   ///\relates xy
     232  ///\relates Point
    233233  ///
    234234  template<typename T>
    235   inline xy<T> rot180(const xy<T> &z)
    236   {
    237     return xy<T>(-z.x,-z.y);
     235  inline Point<T> rot180(const Point<T> &z)
     236  {
     237    return Point<T>(-z.x,-z.y);
    238238  }
    239239
     
    241241
    242242  ///Returns its parameter rotated by 90 degrees in negative direction.
    243   ///\relates xy
     243  ///\relates Point
    244244  ///
    245245  template<typename T>
    246   inline xy<T> rot270(const xy<T> &z)
    247   {
    248     return xy<T>(z.y,-z.x);
     246  inline Point<T> rot270(const Point<T> &z)
     247  {
     248    return Point<T>(z.y,-z.x);
    249249  }
    250250
     
    258258  template<typename T>
    259259    class BoundingBox {
    260       xy<T> bottom_left, top_right;
     260      Point<T> bottom_left, top_right;
    261261      bool _empty;
    262262    public:
     
    266266
    267267      ///Construct an instance from one point
    268       BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
     268      BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
    269269
    270270      ///Were any points added?
     
    282282      ///Give back the bottom left corner.
    283283      ///If the bounding box is empty, then the return value is not defined.
    284       xy<T> bottomLeft() const {
     284      Point<T> bottomLeft() const {
    285285        return bottom_left;
    286286      }
     
    290290      ///Set the bottom left corner.
    291291      ///It should only bee used for non-empty box.
    292       void bottomLeft(xy<T> p) {
     292      void bottomLeft(Point<T> p) {
    293293        bottom_left = p;
    294294      }
     
    298298      ///Give back the top right corner.
    299299      ///If the bounding box is empty, then the return value is not defined.
    300       xy<T> topRight() const {
     300      Point<T> topRight() const {
    301301        return top_right;
    302302      }
     
    306306      ///Set the top right corner.
    307307      ///It should only bee used for non-empty box.
    308       void topRight(xy<T> p) {
     308      void topRight(Point<T> p) {
    309309        top_right = p;
    310310      }
     
    314314      ///Give back the bottom right corner.
    315315      ///If the bounding box is empty, then the return value is not defined.
    316       xy<T> bottomRight() const {
    317         return xy<T>(top_right.x,bottom_left.y);
     316      Point<T> bottomRight() const {
     317        return Point<T>(top_right.x,bottom_left.y);
    318318      }
    319319
     
    322322      ///Set the bottom right corner.
    323323      ///It should only bee used for non-empty box.
    324       void bottomRight(xy<T> p) {
     324      void bottomRight(Point<T> p) {
    325325        top_right.x = p.x;
    326326        bottom_left.y = p.y;
     
    331331      ///Give back the top left corner.
    332332      ///If the bounding box is empty, then the return value is not defined.
    333       xy<T> topLeft() const {
    334         return xy<T>(bottom_left.x,top_right.y);
     333      Point<T> topLeft() const {
     334        return Point<T>(bottom_left.x,top_right.y);
    335335      }
    336336
     
    339339      ///Set the top left corner.
    340340      ///It should only bee used for non-empty box.
    341       void topLeft(xy<T> p) {
     341      void topLeft(Point<T> p) {
    342342        top_right.y = p.y;
    343343        bottom_left.x = p.x;
     
    425425
    426426      ///Checks whether a point is inside a bounding box
    427       bool inside(const xy<T>& u){
     427      bool inside(const Point<T>& u){
    428428        if (_empty)
    429429          return false;
     
    435435 
    436436      ///Increments a bounding box with a point
    437       BoundingBox& add(const xy<T>& u){
     437      BoundingBox& add(const Point<T>& u){
    438438        if (_empty){
    439439          bottom_left=top_right=u;
     
    450450 
    451451//       ///Sums a bounding box and a point
    452 //       BoundingBox operator +(const xy<T>& u){
     452//       BoundingBox operator +(const Point<T>& u){
    453453//         BoundingBox b = *this;
    454454//         return b += u;
     
    486486
    487487
    488   ///Map of x-coordinates of an xy<>-map
     488  ///Map of x-coordinates of a dim2::Point<>-map
    489489
    490490  ///\ingroup maps
     
    551551  }
    552552
    553   ///Map of y-coordinates of an xy<>-map
     553  ///Map of y-coordinates of a dim2::Point<>-map
    554554   
    555555  ///\ingroup maps
     
    617617
    618618
    619   ///Map of the \ref xy::normSquare() "normSquare()" of an \ref xy "xy"-map
    620 
    621   ///Map of the \ref xy::normSquare() "normSquare()" of an \ref xy "xy"-map
     619  ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"-map
     620
     621  ///Map of the \ref Point::normSquare() "normSquare()" of an \ref Point "Point"-map
    622622  ///\ingroup maps
    623623  ///
     
    649649  /// @}
    650650
    651 
     651  } //namespce dim2
     652 
    652653} //namespace lemon
    653654
    654 #endif //LEMON_XY_H
     655#endif //LEMON_DIM2_H
Note: See TracChangeset for help on using the changeset viewer.