Merge branch 'fix-angle-normalization' into 'master'

gsk: Fix angle normalization

See merge request GNOME/gtk!1409
This commit is contained in:
Matthias Clasen
2020-02-11 16:17:14 +00:00

View File

@@ -821,20 +821,28 @@ static const GskTransformClass GSK_ROTATE_TRANSFORM_CLASS =
static inline float
normalize_angle (float angle)
{
float f;
if (angle >= 0 && angle < 360)
return angle;
f = angle - (360 * ((int)(angle / 360.0)));
while (angle >= 360)
angle -= 360;
while (angle < 0)
angle += 360;
if (f < 0)
f = 360 + f;
/* Due to precision issues we may end up with a result that is just
* past the allowed range when rounded. For example, something like
* -epsilon + 360 when rounded to a float may end up with 360.
* So, we handle these cases by returning the exact value 0.
*/
g_assert (f < 360.0);
g_assert (f >= 0.0);
if (angle >= 360)
angle = 0;
return f;
g_assert (angle < 360.0);
g_assert (angle >= 0.0);
return angle;
}
/**