From 94a9a28de16badb75e66a60efca3b01d31cc0fc6 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 4 Nov 2021 12:48:01 +0800 Subject: * text anchor --- Runtime/Math/Vector2.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'Runtime/Math/Vector2.h') 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 + 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 zero; + static Vector2T one; }; + + template + Vector2T Vector2T::zero = Vector2T(0, 0); + template + Vector2T Vector2T::one = Vector2T(1, 1); + + typedef Internal::Vector2T Vector2; + } + +typedef Internal::Vector2T Vector2; + -- cgit v1.1-26-g67d0