Jelajahi Sumber

Math: Add component-wise absolute value for Vector2f

Michael Ragazzon 2 tahun lalu
induk
melakukan
4545e406e5
2 mengubah file dengan 9 tambahan dan 0 penghapusan
  1. 4 0
      Include/RmlUi/Core/Math.h
  2. 5 0
      Source/Core/Math.cpp

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

@@ -111,6 +111,10 @@ RMLUICORE_API float AbsoluteValue(float value);
 /// @param[in] value The number of get the absolute value of.
 /// @return The absolute value of the number.
 RMLUICORE_API int AbsoluteValue(int value);
+/// Calculates the component-wise absolute value of a vector.
+/// @param[in] value The vector of get the absolute value of.
+/// @return The absolute value of the vector.
+RMLUICORE_API Vector2f AbsoluteValue(Vector2f value);
 
 /// Calculates the cosine of an angle.
 /// @param[in] angle The angle to calculate the cosine of, in radians.

+ 5 - 0
Source/Core/Math.cpp

@@ -64,6 +64,11 @@ RMLUICORE_API int AbsoluteValue(int value)
 	return abs(value);
 }
 
+RMLUICORE_API Vector2f AbsoluteValue(Vector2f value)
+{
+	return {fabsf(value.x), fabsf(value.y)};
+}
+
 // Calculates the cosine of an angle.
 RMLUICORE_API float Cos(float angle)
 {