src/lemon/xy.h
changeset 1295 02a403c305b9
parent 1202 da44ee225dad
child 1317 83f80464f111
equal deleted inserted replaced
10:f50102feddb2 11:e4bc855ba8d4
    36 namespace lemon {
    36 namespace lemon {
    37 
    37 
    38   /// \addtogroup misc
    38   /// \addtogroup misc
    39   /// @{
    39   /// @{
    40 
    40 
    41   /// A two dimensional vector (plainvector) implementation
    41   /// A simple two dimensional vector (plainvector) implementation
    42 
    42 
    43   /// A two dimensional vector (plainvector) implementation
    43   /// A simple two dimensional vector (plainvector) implementation
    44   ///with the usual vector
    44   ///with the usual vector
    45   /// operators.
    45   /// operators.
    46   ///
    46   ///
    47   ///\author Attila Bernath
    47   ///\author Attila Bernath
    48   template<typename T>
    48   template<typename T>
    52 
    52 
    53       typedef T Value;
    53       typedef T Value;
    54 
    54 
    55       T x,y;     
    55       T x,y;     
    56       
    56       
    57       ///Default constructor: both coordinates become 0
    57       ///Default constructor
    58       xy() : x(0), y(0) {}
    58       xy() {}
    59 
    59 
    60       ///Constructing the instance from coordinates
    60       ///Constructing the instance from coordinates
    61       xy(T a, T b) : x(a), y(b) { }
    61       xy(T a, T b) : x(a), y(b) { }
    62 
    62 
    63 
    63 
    64       ///Conversion constructor
    64       ///Conversion constructor
    65       template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {}
    65       template<class TT> xy(const xy<TT> &p) : x(p.x), y(p.y) {}
    66 
    66 
    67       ///Gives back the square of the norm of the vector
    67       ///Gives back the square of the norm of the vector
    68       T normSquare(){
    68       T normSquare() const {
    69 	return x*x+y*y;
    69 	return x*x+y*y;
    70       };
    70       };
    71   
    71   
    72       ///Increments the left hand side by u
    72       ///Increments the left hand side by u
    73       xy<T>& operator +=(const xy<T>& u){
    73       xy<T>& operator +=(const xy<T>& u) {
    74 	x += u.x;
    74 	x += u.x;
    75 	y += u.y;
    75 	y += u.y;
    76 	return *this;
    76 	return *this;
    77       };
    77       };
    78   
    78   
    79       ///Decrements the left hand side by u
    79       ///Decrements the left hand side by u
    80       xy<T>& operator -=(const xy<T>& u){
    80       xy<T>& operator -=(const xy<T>& u) {
    81 	x -= u.x;
    81 	x -= u.x;
    82 	y -= u.y;
    82 	y -= u.y;
    83 	return *this;
    83 	return *this;
    84       };
    84       };
    85 
    85 
    86       ///Multiplying the left hand side with a scalar
    86       ///Multiplying the left hand side with a scalar
    87       xy<T>& operator *=(const T &u){
    87       xy<T>& operator *=(const T &u) {
    88 	x *= u;
    88 	x *= u;
    89 	y *= u;
    89 	y *= u;
    90 	return *this;
    90 	return *this;
    91       };
    91       };
    92 
    92 
    93       ///Dividing the left hand side by a scalar
    93       ///Dividing the left hand side by a scalar
    94       xy<T>& operator /=(const T &u){
    94       xy<T>& operator /=(const T &u) {
    95 	x /= u;
    95 	x /= u;
    96 	y /= u;
    96 	y /= u;
    97 	return *this;
    97 	return *this;
    98       };
    98       };
    99   
    99   
   100       ///Returns the scalar product of two vectors
   100       ///Returns the scalar product of two vectors
   101       T operator *(const xy<T>& u){
   101       T operator *(const xy<T>& u) const {
   102 	return x*u.x+y*u.y;
   102 	return x*u.x+y*u.y;
   103       };
   103       };
   104   
   104   
   105       ///Returns the sum of two vectors
   105       ///Returns the sum of two vectors
   106       xy<T> operator+(const xy<T> &u) const {
   106       xy<T> operator+(const xy<T> &u) const {
   132 	xy<T> b=*this;
   132 	xy<T> b=*this;
   133 	return b/=u;
   133 	return b/=u;
   134       };
   134       };
   135 
   135 
   136       ///Testing equality
   136       ///Testing equality
   137       bool operator==(const xy<T> &u){
   137       bool operator==(const xy<T> &u) const {
   138 	return (x==u.x) && (y==u.y);
   138 	return (x==u.x) && (y==u.y);
   139       };
   139       };
   140 
   140 
   141       ///Testing inequality
   141       ///Testing inequality
   142       bool operator!=(xy u){
   142       bool operator!=(xy u) const {
   143 	return  (x!=u.x) || (y!=u.y);
   143 	return  (x!=u.x) || (y!=u.y);
   144       };
   144       };
   145 
   145 
   146     };
   146     };
   147 
   147