]> git.localhorst.tv Git - l2e.git/blob - src/geometry/operators.h
2dfa54e604cd883eece0f7b1543d4e2bc54677f7
[l2e.git] / src / geometry / operators.h
1 /*
2  * operators.h
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #ifndef GEOMETRY_OPERATORS_H_
9 #define GEOMETRY_OPERATORS_H_
10
11 #include "Point.h"
12 #include "Vector.h"
13
14 #include <ostream>
15
16 namespace geometry {
17
18 template<class T>
19 inline Vector<T> operator +(const Vector<T> &lhs, const Vector<T> &rhs) {
20         return Vector<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
21 }
22 template<class T>
23 inline Point<T> operator +(const Point<T> &lhs, const Vector<T> &rhs) {
24         return Point<T>(lhs.X() + rhs.X(), lhs.Y() + rhs.Y());
25 }
26
27 template<class T>
28 inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<T> &rhs) {
29         lhs = lhs + rhs;
30         return lhs;
31 }
32 template<class T>
33 inline Point<T> &operator +=(Point<T> &lhs, const Vector<T> &rhs) {
34         lhs = lhs + rhs;
35         return lhs;
36 }
37
38 template<class T>
39 inline Vector<T> operator -(const Vector<T> &lhs, const Vector<T> &rhs) {
40         return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
41 }
42 template<class T>
43 inline Point<T> operator -(const Point<T> &lhs, const Vector<T> &rhs) {
44         return Point<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
45 }
46
47 template<class T>
48 inline Vector<T> operator -(const Vector<T> &v) {
49         return Vector<T>(-v.X(), -v.Y());
50 }
51
52 template<class T>
53 inline std::ostream &operator <<(std::ostream &out, const Point<T> &p) {
54         out << '(' << p.X() << ", " << p.Y() << ')';
55         return out;
56 }
57 template<class T>
58 inline std::ostream &operator <<(std::ostream &out, const Vector<T> &v) {
59         out << '<' << v.X() << ", " << v.Y() << '>';
60         return out;
61 }
62
63 }
64
65 #endif /* GEOMETRY_OPERATORS_H_ */