aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/point.hpp
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-21 12:00:36 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:51 +0100
commitddcaca8432c2caf57d1defade0c32e90c649554c (patch)
tree3fb4f8edfb3aac494bce9d858d32b1cbec09d82e /src/utils/point.hpp
parent2aba7ea7a02f967efc40edb332ab42c56ed92ce6 (diff)
downloadusdx-ddcaca8432c2caf57d1defade0c32e90c649554c.tar.gz
usdx-ddcaca8432c2caf57d1defade0c32e90c649554c.tar.xz
usdx-ddcaca8432c2caf57d1defade0c32e90c649554c.zip
utils: templatized point, point_3d and rectangle
added template parameter for the geometry helper classes, moved function definitions to hpp file to support templates
Diffstat (limited to 'src/utils/point.hpp')
-rw-r--r--src/utils/point.hpp66
1 files changed, 59 insertions, 7 deletions
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 T>
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<T> result(*this);
+ result += other;
+ return result;
+ }
- float get_x(void) const;
- float get_y(void) const;
+ const Point operator-(const Point &other) const
+ {
+ Point<T> result(*this);
+ result -= other;
+ return result;
+ }
};
};