]> git.localhorst.tv Git - space.git/blobdiff - src/graphics/Vector.h
Vector<int> : SDL_Point optimization
[space.git] / src / graphics / Vector.h
index b5c6d7d11dd9f9452c0a65b781a511b8fa9603ad..34d829713e5dea735d339b0ed56cafdb3a409d11 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <algorithm>
 #include <ostream>
+#include <SDL.h>
 
 
 namespace space {
@@ -29,12 +30,50 @@ public:
                return *this;
        }
 
+       SDL_Point ToPoint() const {
+               SDL_Point p;
+               p.x = x;
+               p.y = y;
+               return p;
+       }
+
 public:
        Scalar x;
        Scalar y;
 
 };
 
+/// specialization with same layout as SDL_Point
+template<>
+class Vector<int>
+: public SDL_Point {
+
+public:
+       constexpr Vector() : SDL_Point({0, 0}) { }
+       constexpr Vector(int x, int y) : SDL_Point({x, y}) { }
+
+       template<class Other>
+       constexpr Vector(Vector<Other> other)
+       : SDL_Point({int(other.x), int(other.y)}) { }
+
+public:
+       Vector<int> &operator +=(Vector<int> other) {
+               x += other.x;
+               y += other.y;
+               return *this;
+       }
+       Vector<int> &operator -=(Vector<int> other) {
+               x -= other.x;
+               y -= other.y;
+               return *this;
+       }
+
+       SDL_Point ToPoint() const {
+               return *this;
+       }
+
+};
+
 
 template<class Scalar>
 constexpr Vector<Scalar> operator -(Vector<Scalar> v) {