Browse Source

Math: Normalize angle to positive values only

Michael Ragazzon 2 years ago
parent
commit
17f1d9583c
2 changed files with 7 additions and 4 deletions
  1. 3 3
      Include/RmlUi/Core/Math.h
  2. 4 1
      Source/Core/Math.cpp

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

@@ -154,9 +154,9 @@ namespace Math {
 	/// @param[in] The angle, in degrees.
 	/// @return The angle converted to radians.
 	RMLUICORE_API float DegreesToRadians(float angle);
-	/// Normalises and angle in radians
-	/// @param[in] The angle, in randians
-	/// @return The normalised angle
+	/// Normalises an angle in radians to [0, 2pi).
+	/// @param[in] The angle, in radians.
+	/// @return The normalised angle.
 	RMLUICORE_API float NormaliseAngle(float angle);
 
 	/// Calculates the square root of a value.

+ 4 - 1
Source/Core/Math.cpp

@@ -116,7 +116,10 @@ namespace Math {
 
 	RMLUICORE_API float NormaliseAngle(float angle)
 	{
-		return fmodf(angle, RMLUI_PI * 2.0f);
+		float result = fmodf(angle, RMLUI_PI * 2.0f);
+		if (result < 0.f)
+			result += RMLUI_PI * 2.0f;
+		return result;
 	}
 
 	RMLUICORE_API float SquareRoot(float value)