4 * Created on: Aug 6, 2012
8 #ifndef GEOMETRY_VECTOR_H_
9 #define GEOMETRY_VECTOR_H_
15 template<class Scalar>
19 Vector() : x(0), y(0) { }
20 Vector(Scalar x, Scalar y) : x(x), y(y) { }
22 Vector(const Vector<T> &other) : x(other.X()), y(other.Y()) { };
24 Vector(T x, T y) : x(x), y(y) { }
27 Scalar X() const { return x; }
28 Scalar Y() const { return y; }
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());
42 inline Vector<T> &operator +=(Vector<T> &lhs, const Vector<T> &rhs) {
43 return lhs = lhs + rhs;
47 inline Vector<T> operator -(const Vector<T> &lhs, const Vector<T> &rhs) {
48 return Vector<T>(lhs.X() - rhs.X(), lhs.Y() - rhs.Y());
52 inline Vector<T> &operator -=(Vector<T> &lhs, const Vector<T> &rhs) {
53 return lhs = lhs - rhs;
57 inline Vector<T> operator -(const Vector<T> &v) {
58 return Vector<T>(-v.X(), -v.Y());
62 inline Vector<T> operator *(const Vector<T> &v, T s) {
63 return Vector<T>(v.X() * s, v.Y() * s);
66 inline Vector<T> operator *(T s, const Vector<T> &v) {
67 return Vector<T>(s * v.X(), s * v.Y());
71 inline Vector<T> operator /(const Vector<T> &v, T s) {
72 return Vector<T>(v.X() / s, v.Y() / s);
76 inline std::ostream &operator <<(std::ostream &out, const Vector<T> &v) {
77 out << '<' << v.X() << ", " << v.Y() << '>';
83 #endif /* GEOMETRY_VECTOR_H_ */