summaryrefslogtreecommitdiff
path: root/Runtime/Math/Vector2.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-04 12:48:01 +0800
committerchai <chaifix@163.com>2021-11-04 12:48:01 +0800
commit94a9a28de16badb75e66a60efca3b01d31cc0fc6 (patch)
treea37e09236da2b7cda11a451d6fed4fe37afb065c /Runtime/Math/Vector2.h
parentb215d811a1981e20f35bb31df4e6cd2a74146193 (diff)
* text anchor
Diffstat (limited to 'Runtime/Math/Vector2.h')
-rw-r--r--Runtime/Math/Vector2.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
index 9d7e4e9..f13e522 100644
--- a/Runtime/Math/Vector2.h
+++ b/Runtime/Math/Vector2.h
@@ -4,47 +4,59 @@
namespace Internal
{
- struct Vector2
+ template<typename T>
+ struct Vector2T
{
- Vector2(float x = 0, float y = 0)
+ Vector2T(T x = 0, T y = 0)
{
this->x = x;
this->y = y;
}
- inline void Set(float x, float y)
+ inline void Set(T x, T y)
{
this->x = x;
this->y = y;
}
- Vector2 Clamp(float xmin, float xmax, float ymin, float ymax)
+ Vector2T Clamp(T xmin, T xmax, T ymin, T ymax)
{
- Vector2 v;
+ Vector2T v;
v.x = clamp(x, xmin, xmax);
v.y = clamp(y, ymin, ymax);
return v;
}
- float operator[](int i)
+ T operator[](int i)
{
if (i == 0) return x;
else if (i == 1) return y;
Assert(false);
}
- bool operator == (const Vector2& v) const
+ bool operator == (const Vector2T& v) const
{
return v.x == x && v.y == y;
}
- bool operator != (const Vector2& v) const
+ bool operator != (const Vector2T& v) const
{
return v.x != x || v.y != y;
}
- float x, y;
+ T x, y;
- static Vector2 zero;
- static Vector2 one;
+ static Vector2T<T> zero;
+ static Vector2T<T> one;
};
+
+ template<typename T>
+ Vector2T<T> Vector2T<T>::zero = Vector2T(0, 0);
+ template<typename T>
+ Vector2T<T> Vector2T<T>::one = Vector2T(1, 1);
+
+ typedef Internal::Vector2T<float> Vector2;
+
}
+
+typedef Internal::Vector2T<float> Vector2;
+