From ddcaca8432c2caf57d1defade0c32e90c649554c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 21 Mar 2012 12:00:36 +0100 Subject: utils: templatized point, point_3d and rectangle added template parameter for the geometry helper classes, moved function definitions to hpp file to support templates --- src/utils/point.hpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'src/utils/point.hpp') diff --git a/src/utils/point.hpp b/src/utils/point.hpp index 7c1ec727..6618e285 100644 --- a/src/utils/point.hpp +++ b/src/utils/point.hpp @@ -29,18 +29,70 @@ namespace usdx { + template class Point { private: - float x; - float y; + T x; + T y; + public: - Point(float x, float y); - Point(const Point& point); - Point& operator=(const Point& point); + Point(T x, T y): + x(x), y(y) + { + } + + Point(const Point& point): + x(point.x), y(point.y) + { + } + + Point& operator=(const Point& point) + { + x = point.x; + y = point.y; + return *this; + } + + + T get_x(void) const + { + return x; + } + + T get_y(void) const + { + return y; + } + + + Point& operator+=(const Point &other) + { + x += other.x; + y += other.y; + return *this; + } + + Point& operator-=(const Point &other) + { + x -= other.x; + y -= other.y; + return *this; + } + + const Point operator+(const Point &other) const + { + Point result(*this); + result += other; + return result; + } - float get_x(void) const; - float get_y(void) const; + const Point operator-(const Point &other) const + { + Point result(*this); + result -= other; + return result; + } }; }; -- cgit v1.2.3