X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgeometry%2FVector.h;h=7c698ff4af0a11d9b707cd0b51503142e016f475;hb=64c0880d31cddc599b30331f9485d65eeaf705ee;hp=d7d0f3d69139ecb84249d258535f7bd75972fa60;hpb=a2cf146565731e09f2e4d3159c19229abc33b143;p=l2e.git diff --git a/src/geometry/Vector.h b/src/geometry/Vector.h index d7d0f3d..7c698ff 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,78 @@ 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 +(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 +=(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 -(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 -=(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 bool operator ==(const Vector &lhs, const Vector &rhs) { + return lhs.X() == rhs.X() && lhs.Y() == rhs.Y(); +} + +template +inline bool operator !=(const Vector &lhs, const Vector &rhs) { + return lhs.X() != rhs.X() || lhs.Y() != rhs.Y(); +} + +template +inline std::ostream &operator <<(std::ostream &out, const Vector &v) { + out << '<' << v.X() << ", " << v.Y() << '>'; + return out; +} + } #endif /* GEOMETRY_VECTOR_H_ */