Browse Source

Fixed a rounding error in the border radius color lerp (#203)

* Fixed a rounding error in the border radius color lerp

* Added a missing header

* Switched to using Math::RoundToInteger

Co-authored-by: Jacqueline <[email protected]>
jac8888 4 years ago
parent
commit
747d73c0b6
1 changed files with 22 additions and 2 deletions
  1. 22 2
      Source/Core/GeometryBackgroundBorder.cpp

+ 22 - 2
Source/Core/GeometryBackgroundBorder.cpp

@@ -258,7 +258,17 @@ void GeometryBackgroundBorder::DrawArc(Vector2f pos_center, Vector2f r, float a0
 		const float t = float(i) / float(num_points - 1);
 
 		const float a = Math::Lerp(t, a0, a1);
-		const Colourb color = Math::Lerp(t, color0, color1);
+		const Colourb color
+		{
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[0]), static_cast<float>(color1[0])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[1]), static_cast<float>(color1[1])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[2]), static_cast<float>(color1[2])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[3]), static_cast<float>(color1[3]))))
+		};
 
 		const Vector2f unit_vector(Math::Cos(a), Math::Sin(a));
 
@@ -336,7 +346,17 @@ void GeometryBackgroundBorder::DrawArcArc(Vector2f pos_center, float R, Vector2f
 		const float t = float(i) / float(num_points - 1);
 
 		const float a = Math::Lerp(t, a0, a1);
-		const Colourb color = Math::Lerp(t, color0, color1);
+		const Colourb color
+		{
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[0]), static_cast<float>(color1[0])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[1]), static_cast<float>(color1[1])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[2]), static_cast<float>(color1[2])))),
+			static_cast<unsigned char>(Math::RoundToInteger(Math::Lerp(t, 
+				static_cast<float>(color0[3]), static_cast<float>(color1[3]))))
+		};
 
 		const Vector2f unit_vector(Math::Cos(a), Math::Sin(a));