[gtk/wip/baedert/gl-rework: 37/47] GskTransform: Compute sin/deg of 90deg rotations manually
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/gl-rework: 37/47] GskTransform: Compute sin/deg of 90deg rotations manually
- Date: Sun, 22 Dec 2019 05:45:02 +0000 (UTC)
commit 37ccf21a1325a760416e78fef122335839c09e14
Author: Timm Bäder <mail baedert org>
Date: Thu Dec 19 12:30:08 2019 +0100
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]