diff options
Diffstat (limited to 'include/mglpp/system/vec.hpp')
-rw-r--r-- | include/mglpp/system/vec.hpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/include/mglpp/system/vec.hpp b/include/mglpp/system/vec.hpp index ac06a52..a9de662 100644 --- a/include/mglpp/system/vec.hpp +++ b/include/mglpp/system/vec.hpp @@ -2,23 +2,38 @@ #define MGLPP_VEC_HPP namespace mgl { - struct vec2f { - vec2f(float x = 0.0f, float y = 0.0f) : x(x), y(y) {} + template <typename T> + struct vec2 { + vec2(T x = 0, T y = 0) : x(x), y(y) {} - float x; - float y; - }; + vec2<T> operator + (vec2<T> other) const { + return { x + other.x, y + other.y }; + } + + vec2<T> operator - (vec2<T> other) const { + return { x - other.x, y - other.y }; + } - struct vec2i { - vec2i(int x = 0, int y = 0) : x(x), y(y) {} + vec2<T> operator * (vec2<T> other) const { + return { x * other.x, y * other.y }; + } + + vec2<T> operator * (T v) const { + return { x * v, y * v }; + } - vec2f to_vec2f() const { + vec2<float> to_vec2f() const { return { (float)x, (float)y }; } - int x; - int y; + T x; + T y; }; + + using vec2f = vec2<float>; + using vec2d = vec2<double>; + using vec2i = vec2<int>; + using vec2u = vec2<unsigned int>; } #endif /* MGLPP_VEC_HPP */ |