From 2efa2ecd04a9c38d31e91950eac098faa3e5ca08 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 8 Aug 2012 16:19:38 +0200 Subject: [PATCH] added more operators in geometry lib --- src/geometry/operators.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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_ */ -- 2.39.2