]> git.localhorst.tv Git - l2e.git/blob - src/geometry/operators.h
added -= operators for Point/Vector
[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         return lhs = lhs + rhs;
30 }
31 template<class T>
32 inline Point<T> &operator +=(Point<T> &lhs, const Vector<T> &rhs) {
33         return lhs = lhs + rhs;
34 }
35
36 template<class T>
37 inline Vector<T> operator -(const Vector<T> &lhs, const Vector<T> &rhs) {
38         return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
39 }
40 template<class T>
41 inline Point<T> operator -(const Point<T> &lhs, const Vector<T> &rhs) {
42         return Point<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
43 }
44
45 template<class T>
46 inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<T> &rhs) {
47         return lhs = lhs - rhs;
48 }
49 template<class T>
50 inline Point<T> &operator -=(Point<T> &lhs, const Vector<T> &rhs) {
51         return lhs = lhs - rhs;
52 }
53
54 template<class T>
55 inline Vector<T> operator -(const Vector<T> &v) {
56         return Vector<T>(-v.X(), -v.Y());
57 }
58
59 template<class T>
60 inline std::ostream &operator <<(std::ostream &out, const Point<T> &p) {
61         out << '(' << p.X() << ", " << p.Y() << ')';
62         return out;
63 }
64 template<class T>
65 inline std::ostream &operator <<(std::ostream &out, const Vector<T> &v) {
66         out << '<' << v.X() << ", " << v.Y() << '>';
67         return out;
68 }
69
70 }
71
72 #endif /* GEOMETRY_OPERATORS_H_ */