Browse Source

Add Min/Max/Clamp for Vector2i

Michael Ragazzon 3 years ago
parent
commit
ee3655f1b0
2 changed files with 24 additions and 0 deletions
  1. 8 0
      Include/RmlUi/Core/Math.h
  2. 16 0
      Source/Core/Math.cpp

+ 8 - 0
Include/RmlUi/Core/Math.h

@@ -39,6 +39,7 @@ template <typename ColourType, int AlphaDefault> class Colour;
 using Colourb = Colour< byte, 255 >;
 using Colourb = Colour< byte, 255 >;
 template <typename Type> class Vector2;
 template <typename Type> class Vector2;
 using Vector2f = Vector2< float >;
 using Vector2f = Vector2< float >;
+using Vector2i = Vector2< int >;
 
 
 namespace Math {
 namespace Math {
 
 
@@ -85,12 +86,19 @@ Type Lerp(float t, Type v0, Type v1)
 /// Element-wise maximum.
 /// Element-wise maximum.
 template <>
 template <>
 RMLUICORE_API Vector2f Max<Vector2f>(Vector2f a, Vector2f b);
 RMLUICORE_API Vector2f Max<Vector2f>(Vector2f a, Vector2f b);
+template <>
+RMLUICORE_API Vector2i Max<Vector2i>(Vector2i a, Vector2i b);
 /// Element-wise minimum.
 /// Element-wise minimum.
 template <>
 template <>
 RMLUICORE_API Vector2f Min<Vector2f>(Vector2f a, Vector2f b);
 RMLUICORE_API Vector2f Min<Vector2f>(Vector2f a, Vector2f b);
+template <>
+RMLUICORE_API Vector2i Min<Vector2i>(Vector2i a, Vector2i b);
 /// Element-wise clamp.
 /// Element-wise clamp.
 template <>
 template <>
 RMLUICORE_API Vector2f Clamp<Vector2f>(Vector2f value, Vector2f min, Vector2f max);
 RMLUICORE_API Vector2f Clamp<Vector2f>(Vector2f value, Vector2f min, Vector2f max);
+template <>
+RMLUICORE_API Vector2i Clamp<Vector2i>(Vector2i value, Vector2i min, Vector2i max);
+
 
 
 /// Color interpolation.
 /// Color interpolation.
 RMLUICORE_API Colourb RoundedLerp(float t, Colourb c0, Colourb c1);
 RMLUICORE_API Colourb RoundedLerp(float t, Colourb c0, Colourb c1);

+ 16 - 0
Source/Core/Math.cpp

@@ -268,18 +268,34 @@ Vector2f Max<Vector2f>(Vector2f a, Vector2f b)
 {
 {
 	return Vector2f(Max(a.x, b.x), Max(a.y, b.y));
 	return Vector2f(Max(a.x, b.x), Max(a.y, b.y));
 }
 }
+template <>
+Vector2i Max<Vector2i>(Vector2i a, Vector2i b)
+{
+	return Vector2i(Max(a.x, b.x), Max(a.y, b.y));
+}
 
 
 template <>
 template <>
 Vector2f Min<Vector2f>(Vector2f a, Vector2f b)
 Vector2f Min<Vector2f>(Vector2f a, Vector2f b)
 {
 {
 	return Vector2f(Min(a.x, b.x), Min(a.y, b.y));
 	return Vector2f(Min(a.x, b.x), Min(a.y, b.y));
 }
 }
+template <>
+Vector2i Min<Vector2i>(Vector2i a, Vector2i b)
+{
+	return Vector2i(Min(a.x, b.x), Min(a.y, b.y));
+}
 
 
 template <>
 template <>
 Vector2f Clamp(Vector2f value, Vector2f min, Vector2f max)
 Vector2f Clamp(Vector2f value, Vector2f min, Vector2f max)
 {
 {
 	return Vector2f(Clamp(value.x, min.x, max.x), Clamp(value.y, min.y, max.y));
 	return Vector2f(Clamp(value.x, min.x, max.x), Clamp(value.y, min.y, max.y));
 }
 }
+template <>
+Vector2i Clamp(Vector2i value, Vector2i min, Vector2i max)
+{
+	return Vector2i(Clamp(value.x, min.x, max.x), Clamp(value.y, min.y, max.y));
+}
+
 
 
 Colourb RoundedLerp(float t, Colourb v0, Colourb v1)
 Colourb RoundedLerp(float t, Colourb v0, Colourb v1)
 {
 {