Kaynağa Gözat

Add Max and Min math functions for Vector2f

Michael Ragazzon 4 yıl önce
ebeveyn
işleme
221b43b8d6
2 değiştirilmiş dosya ile 20 ekleme ve 0 silme
  1. 8 0
      Include/RmlUi/Core/Math.h
  2. 12 0
      Source/Core/Math.cpp

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

@@ -82,6 +82,14 @@ Type Lerp(float t, Type v0, Type v1)
 	return v0 * (1.0f - t) + v1 * t;
 	return v0 * (1.0f - t) + v1 * t;
 }
 }
 
 
+/// Element-wise maximum.
+template <>
+RMLUICORE_API Vector2f Max<Vector2f>(Vector2f a, Vector2f b);
+/// Element-wise minimum.
+template <>
+RMLUICORE_API Vector2f Min<Vector2f>(Vector2f a, Vector2f b);
+
+/// Color interpolation.
 RMLUICORE_API Colourb RoundedLerp(float t, Colourb c0, Colourb c1);
 RMLUICORE_API Colourb RoundedLerp(float t, Colourb c0, Colourb c1);
 
 
 /// Evaluates if a number is, or close to, zero.
 /// Evaluates if a number is, or close to, zero.

+ 12 - 0
Source/Core/Math.cpp

@@ -248,6 +248,18 @@ RMLUICORE_API bool RandomBool()
 	return RandomInteger(2) == 1;
 	return RandomInteger(2) == 1;
 }
 }
 
 
+template <>
+Vector2f Max<Vector2f>(Vector2f a, Vector2f b)
+{
+	return Vector2f(Max(a.x, b.x), Max(a.y, b.y));
+}
+
+template <>
+Vector2f Min<Vector2f>(Vector2f a, Vector2f b)
+{
+	return Vector2f(Min(a.x, b.x), Min(a.y, b.y));
+}
+
 Colourb RoundedLerp(float t, Colourb v0, Colourb v1)
 Colourb RoundedLerp(float t, Colourb v0, Colourb v1)
 {
 {
 	return Colourb{
 	return Colourb{