summaryrefslogtreecommitdiff
path: root/Client/Source/Math/Vector2.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Source/Math/Vector2.hpp')
-rw-r--r--Client/Source/Math/Vector2.hpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/Client/Source/Math/Vector2.hpp b/Client/Source/Math/Vector2.hpp
new file mode 100644
index 0000000..65f2c10
--- /dev/null
+++ b/Client/Source/Math/Vector2.hpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "../Utilities/Assert.h"
+#include "../Math/Functions.h"
+
+template <typename T>
+class Vector2Template
+{
+public:
+ Vector2Template(T x = 0, T y = 0)
+ {
+ this->x = x;
+ this->y = y;
+ }
+ inline void Set(T x, T y)
+ {
+ this->x = x;
+ this->y = y;
+ }
+
+ Vector2Template Clamp(T xmin, T xmax, T ymin, T ymax)
+ {
+ Vector2Template v;
+ v.x = clamp(x, xmin, xmax);
+ v.y = clamp(y, ymin, ymax);
+ return v;
+ }
+
+ T operator[](int i)
+ {
+ if (i == 0) return x;
+ else if (i == 1) return y;
+ Assert(false);
+ }
+
+ bool operator == (const Vector2Template& v) const
+ {
+ return v.x == x && v.y == y;
+ }
+
+ bool operator != (const Vector2Template& v) const
+ {
+ return v.x != x || v.y != y;
+ }
+
+ Vector2Template<T> operator - (const Vector2Template& v) const
+ {
+ Vector2Template<T> res = Vector2Template<T>(x - v.x, y - v.y);
+ return res;
+ }
+
+
+ float x, y;
+
+ static Vector2Template<T> zero;
+ static Vector2Template<T> one ;
+
+};
+
+using Vector2f = Vector2Template<float>;
+using Vector2i = Vector2Template<int>;
+
+
+template<typename T>
+Vector2Template<T> Vector2Template<T>::zero = Vector2Template(0, 0);
+template<typename T>
+Vector2Template<T> Vector2Template<T>::one = Vector2Template(1, 1);