summaryrefslogtreecommitdiff
path: root/Runtime/Math
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-03 09:52:26 +0800
committerchai <chaifix@163.com>2021-11-03 09:52:26 +0800
commitc10e0d92f46e5eaf25a69e1fafe5f4dbd8eaab9d (patch)
tree2eb1a91339b35fea68f48b2774355f496519db83 /Runtime/Math
parent3898f2c648b1a731dead8337aad8912d2b8b80d7 (diff)
*misc
Diffstat (limited to 'Runtime/Math')
-rw-r--r--Runtime/Math/Math.h4
-rw-r--r--Runtime/Math/MathHelper.h11
-rw-r--r--Runtime/Math/Vector2.h17
3 files changed, 29 insertions, 3 deletions
diff --git a/Runtime/Math/Math.h b/Runtime/Math/Math.h
index aaeb264..5e08613 100644
--- a/Runtime/Math/Math.h
+++ b/Runtime/Math/Math.h
@@ -6,9 +6,7 @@
#include "Matrix44.h"
#include "FloatConversion.h"
#include "Rect.h"
-
-#define max(a, b)\
-(a)>(b)?(a):(b)
+#include "MathHelper.h"
typedef Internal::Vector2 Vector2;
typedef Internal::Vector3 Vector3;
diff --git a/Runtime/Math/MathHelper.h b/Runtime/Math/MathHelper.h
new file mode 100644
index 0000000..3f8754a
--- /dev/null
+++ b/Runtime/Math/MathHelper.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#define max(a, b)\
+(a)>(b)?(a):(b)
+
+#define min(a, b)\
+(a)<(b)?(a):(b)
+
+#define clamp(v, lo, hi)\
+max((lo), min((v), (hi)))
+
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
index 27cf312..9d7e4e9 100644
--- a/Runtime/Math/Vector2.h
+++ b/Runtime/Math/Vector2.h
@@ -1,4 +1,6 @@
#pragma once
+#include "MathHelper.h"
+#include "Runtime/Utilities/Assert.h"
namespace Internal
{
@@ -15,6 +17,21 @@ namespace Internal
this->y = y;
}
+ Vector2 Clamp(float xmin, float xmax, float ymin, float ymax)
+ {
+ Vector2 v;
+ v.x = clamp(x, xmin, xmax);
+ v.y = clamp(y, ymin, ymax);
+ return v;
+ }
+
+ float operator[](int i)
+ {
+ if (i == 0) return x;
+ else if (i == 1) return y;
+ Assert(false);
+ }
+
bool operator == (const Vector2& v) const
{
return v.x == x && v.y == y;