src/proto2/Vector.hh
branchno-netsession
changeset 41 ca80cd67785d
parent 35 e21cfda0edde
equal deleted inserted replaced
40:4b2867fb5c12 41:ca80cd67785d
     1 #ifndef COOR_H
     1 #ifndef COOR_H
     2 #define COOR_H
     2 #define COOR_H
     3 
     3 
     4 #include <iostream>
     4 #include <iostream>
       
     5 #include <cmath>
     5 
     6 
     6 /**
     7 /**
     7  * 2D Vector class. Implements standard vector operations.
     8  * 2D Vector class. Implements standard vector operations.
     8  */
     9  */
     9 template <typename T>
    10 template <typename T>
    53     }
    54     }
    54     void operator/=(const T &d) {
    55     void operator/=(const T &d) {
    55         this->x /= d;
    56         this->x /= d;
    56         this->y /= d;
    57         this->y /= d;
    57     }
    58     }
       
    59     T length() const {
       
    60         return sqrt(x*x+y*y);
       
    61     }
    58 };
    62 };
    59 
    63 
    60 template<typename T>
    64 template<typename T>
    61 bool operator==(const _Vector<T> &v1, const _Vector<T> &v2) {
    65 bool operator==(const _Vector<T> &v1, const _Vector<T> &v2) {
    62     return ((v1.x == v2.x) && (v1.y == v2.y));
    66     return ((v1.x == v2.x) && (v1.y == v2.y));