X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgeometry%2FVector.h;h=bf647136ddfaa101ee8406b0f8fa36cdccf2a4b4;hb=0542849dfccfec1ce1477265fa0fee2401a8fb23;hp=d7d0f3d69139ecb84249d258535f7bd75972fa60;hpb=c20927cf8ab9bb7526f641850c3997f14c66f06e;p=l2e.git diff --git a/src/geometry/Vector.h b/src/geometry/Vector.h index d7d0f3d..bf64713 100644 --- a/src/geometry/Vector.h +++ b/src/geometry/Vector.h @@ -8,6 +8,8 @@ #ifndef GEOMETRY_VECTOR_H_ #define GEOMETRY_VECTOR_H_ +#include + namespace geometry { template @@ -30,6 +32,52 @@ private: }; + +template +inline Vector operator +(const Vector &lhs, const Vector &rhs) { + return Vector(lhs.X() + rhs.X(), lhs.Y() + rhs.Y()); +} + +template +inline Vector &operator +=(Vector &lhs, const Vector &rhs) { + return lhs = lhs + rhs; +} + +template +inline Vector operator -(const Vector &lhs, const Vector &rhs) { + return Vector(lhs.X() - rhs.X(), lhs.Y() - rhs.Y()); +} + +template +inline Vector &operator -=(Vector &lhs, const Vector &rhs) { + return lhs = lhs - rhs; +} + +template +inline Vector operator -(const Vector &v) { + return Vector(-v.X(), -v.Y()); +} + +template +inline Vector operator *(const Vector &v, T s) { + return Vector(v.X() * s, v.Y() * s); +} +template +inline Vector operator *(T s, const Vector &v) { + return Vector(s * v.X(), s * v.Y()); +} + +template +inline Vector operator /(const Vector &v, T s) { + return Vector(v.X() / s, v.Y() / s); +} + +template +inline std::ostream &operator <<(std::ostream &out, const Vector &v) { + out << '<' << v.X() << ", " << v.Y() << '>'; + return out; +} + } #endif /* GEOMETRY_VECTOR_H_ */