Browse Source

Math: Add element-wise clamp for Vector2f

Michael Ragazzon 2 years ago
parent
commit
83e3c5a374
2 changed files with 9 additions and 0 deletions
  1. 3 0
      Include/RmlUi/Core/Math.h
  2. 6 0
      Source/Core/Math.cpp

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

@@ -88,6 +88,9 @@ RMLUICORE_API Vector2f Max<Vector2f>(Vector2f a, Vector2f 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);
+/// Element-wise clamp.
+template <>
+RMLUICORE_API Vector2f Clamp<Vector2f>(Vector2f value, Vector2f min, Vector2f 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);

+ 6 - 0
Source/Core/Math.cpp

@@ -275,6 +275,12 @@ 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 <>
+Vector2f Clamp(Vector2f value, Vector2f min, Vector2f max)
+{
+	return Vector2f(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)
 {
 {
 	return Colourb{
 	return Colourb{