.
2 2 dimensional vector (plainvector) implementation
17 ///Default constructor: both coordinates become 0
20 ///Constructing from coordinates
21 xy(T a, T b) { _x=a; _y=b; }
23 ///Gives back the x coordinate
28 ///Gives back the y coordinate
33 ///Gives back the square of the norm of the vector
38 ///Increments the left hand side by u
39 xy<T>& operator +=(const xy<T>& u){
45 ///Decrements the left hand side by u
46 xy<T>& operator -=(const xy<T>& u){
52 ///Multiplying the left hand side with a scalar
53 xy<T>& operator *=(const T &u){
59 ///Returns the scalar product of two vectors
60 T operator *(const xy<T>& u){
61 return _x*u._x+_y*u._y;
64 ///Returns the sum of two vectors
65 xy<T> operator+(const xy<T> &u) const {
70 ///Returns the difference of two vectors
71 xy<T> operator-(const xy<T> &u) const {
76 ///Returns a vector multiplied by a scalar
77 xy<T> operator*(const T &u) const {
83 bool operator==(const xy<T> &u){
84 return (_x==u._x) && (_y==u._y);
88 bool operator!=(xy u){
89 return (_x!=u._x) || (_y!=u._y);
93 ///Reading a plainvector from a stream
96 istream& operator>>(istream &is, xy<T> &z)
98 ///This is not the best solution here: I didn't know how to solve this with friend functions
106 ///Outputting a plainvector to a stream
109 ostream& operator<<(ostream &os, xy<T> z)
111 os << "(" << z.x() << ", " << z.y() << ")";