3 2 dimensional vector (plainvector) implementation
19 ///Default constructor: both coordinates become 0
22 ///Constructing from coordinates
23 xy(T a, T b) { _x=a; _y=b; }
25 ///Gives back the x coordinate
30 ///Gives back the y coordinate
35 ///Gives back the square of the norm of the vector
40 ///Increments the left hand side by u
41 xy<T>& operator +=(const xy<T>& u){
47 ///Decrements the left hand side by u
48 xy<T>& operator -=(const xy<T>& u){
54 ///Multiplying the left hand side with a scalar
55 xy<T>& operator *=(const T &u){
61 ///Dividing the left hand side by a scalar
62 xy<T>& operator /=(const T &u){
68 ///Returns the scalar product of two vectors
69 T operator *(const xy<T>& u){
70 return _x*u._x+_y*u._y;
73 ///Returns the sum of two vectors
74 xy<T> operator+(const xy<T> &u) const {
79 ///Returns the difference of two vectors
80 xy<T> operator-(const xy<T> &u) const {
85 ///Returns a vector multiplied by a scalar
86 xy<T> operator*(const T &u) const {
91 ///Returns a vector divided by a scalar
92 xy<T> operator/(const T &u) const {
98 bool operator==(const xy<T> &u){
99 return (_x==u._x) && (_y==u._y);
102 ///Testing inequality
103 bool operator!=(xy u){
104 return (_x!=u._x) || (_y!=u._y);
109 ///Reading a plainvector from a stream
112 std::istream& operator>>(std::istream &is, xy<T> &z)
114 ///This is not the best solution here: I didn't know how to solve this with friend functions
122 ///Outputting a plainvector to a stream
125 std::ostream& operator<<(std::ostream &os, xy<T> z)
127 os << "(" << z.x() << ", " << z.y() << ")";