X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fgraphics%2FVector.h;fp=src%2Fgraphics%2FVector.h;h=34d829713e5dea735d339b0ed56cafdb3a409d11;hp=b5c6d7d11dd9f9452c0a65b781a511b8fa9603ad;hb=1129b8ac89f1e614f69793227ccec90157708aea;hpb=61c2d30a60d586cbe63885885c6a373c7713af1e diff --git a/src/graphics/Vector.h b/src/graphics/Vector.h index b5c6d7d..34d8297 100644 --- a/src/graphics/Vector.h +++ b/src/graphics/Vector.h @@ -3,6 +3,7 @@ #include #include +#include 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 +: public SDL_Point { + +public: + constexpr Vector() : SDL_Point({0, 0}) { } + constexpr Vector(int x, int y) : SDL_Point({x, y}) { } + + template + constexpr Vector(Vector other) + : SDL_Point({int(other.x), int(other.y)}) { } + +public: + Vector &operator +=(Vector other) { + x += other.x; + y += other.y; + return *this; + } + Vector &operator -=(Vector other) { + x -= other.x; + y -= other.y; + return *this; + } + + SDL_Point ToPoint() const { + return *this; + } + +}; + template constexpr Vector operator -(Vector v) {