From 766d4dff762e34ea56e7dbe433dd6c5bd2795ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 19 Dec 2019 12:30:08 +0100 Subject: [PATCH] GskTransform: Compute sin/deg of 90deg rotations manually Otherwise we might end up with inaccuracies, e.g. when gsk_transform_transform_bounds()'ing bounds. --- gsk/gsktransform.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/gsk/gsktransform.c b/gsk/gsktransform.c index 2f3003f6fe..1e6f87f8fa 100644 --- a/gsk/gsktransform.c +++ b/gsk/gsktransform.c @@ -685,16 +685,46 @@ gsk_rotate_transform_finalize (GskTransform *self) { } +static inline void +_sincos (float deg, + float *out_s, + float *out_c) +{ + if (deg == 90.0) + { + *out_c = 0.0; + *out_s = 1.0; + } + else if (deg == 180.0) + { + *out_c = -1.0; + *out_s = 0.0; + } + else if (deg == 270.0) + { + *out_c = 0.0; + *out_s = -1.0; + } + else if (deg == 0.0) + { + *out_c = 1.0; + *out_s = 0.0; + } + else + { + sincosf (deg * M_PI / 180.0, out_s, out_c); + } +} + static void gsk_rotate_transform_to_matrix (GskTransform *transform, graphene_matrix_t *out_matrix) { GskRotateTransform *self = (GskRotateTransform *) transform; - float rad, c, s; + float c, s; + + _sincos (self->angle, &s, &c); - rad = self->angle * M_PI / 180.f; - c = cosf (rad); - s = sinf (rad); graphene_matrix_init_from_2d (out_matrix, c, s, -s, c, @@ -711,14 +741,12 @@ gsk_rotate_transform_apply_2d (GskTransform *transform, float *out_dy) { GskRotateTransform *self = (GskRotateTransform *) transform; - float s, c, rad, xx, xy, yx, yy; + float s, c, xx, xy, yx, yy; if (fmodf (self->angle, 360.0f) == 0.0) return; - rad = self->angle * G_PI / 180.0f; - s = sinf (rad); - c = cosf (rad); + _sincos (self->angle, &s, &c); xx = c * *out_xx + s * *out_xy; yx = c * *out_yx + s * *out_yy;