From: Daniel Karbach Date: Wed, 8 Aug 2012 14:19:38 +0000 (+0200) Subject: added more operators in geometry lib X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=2efa2ecd04a9c38d31e91950eac098faa3e5ca08;p=l2e.git added more operators in geometry lib --- diff --git a/src/geometry/operators.h b/src/geometry/operators.h index 7a8e7ea..2dfa54e 100644 --- a/src/geometry/operators.h +++ b/src/geometry/operators.h @@ -11,6 +11,8 @@ #include "Point.h" #include "Vector.h" +#include + namespace geometry { template @@ -22,6 +24,17 @@ inline Point operator +(const Point &lhs, const Vector &rhs) { return Point(lhs.X() + rhs.X(), lhs.Y() + rhs.Y()); } +template +inline Vector &operator +=(Vector &lhs, const Vector &rhs) { + lhs = lhs + rhs; + return lhs; +} +template +inline Point &operator +=(Point &lhs, const Vector &rhs) { + lhs = lhs + rhs; + return lhs; +} + template inline Vector operator -(const Vector &lhs, const Vector &rhs) { return Vector(lhs.X() - rhs.X(), lhs.Y() - rhs.Y()); @@ -36,6 +49,17 @@ inline Vector operator -(const Vector &v) { return Vector(-v.X(), -v.Y()); } +template +inline std::ostream &operator <<(std::ostream &out, const Point &p) { + out << '(' << p.X() << ", " << p.Y() << ')'; + return out; +} +template +inline std::ostream &operator <<(std::ostream &out, const Vector &v) { + out << '<' << v.X() << ", " << v.Y() << '>'; + return out; +} + } #endif /* GEOMETRY_OPERATORS_H_ */