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/Math.h | 5 ++++- Runtime/Math/MathHelper.h | 2 +- Runtime/Math/Vector2.h | 34 +++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'Runtime/Math') diff --git a/Runtime/Math/Math.h b/Runtime/Math/Math.h index 5e08613..80f23f7 100644 --- a/Runtime/Math/Math.h +++ b/Runtime/Math/Math.h @@ -8,8 +8,11 @@ #include "Rect.h" #include "MathHelper.h" -typedef Internal::Vector2 Vector2; typedef Internal::Vector3 Vector3; typedef Internal::Vector4 Vector4; typedef Internal::Matrix44 Matrix44; typedef Internal::Rect Rect; + +typedef Internal::Vector2T Vector2i; +typedef Internal::Vector2T Vector2f; + diff --git a/Runtime/Math/MathHelper.h b/Runtime/Math/MathHelper.h index c41eec9..ad64dcf 100644 --- a/Runtime/Math/MathHelper.h +++ b/Runtime/Math/MathHelper.h @@ -1,7 +1,7 @@ #pragma once #define max(a, b)\ -(a)>(b)?(a):(b) +((a)>(b)?(a):(b)) #define min(a, b)\ (a)<(b)?(a):(b) 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