transform: Implement transform_bounds() for dihedrals

No longer using the default path and risking rounding issues.
This commit is contained in:
Benjamin Otte 2024-07-09 11:37:52 +02:00
parent 3bcfc5539c
commit 555f7d5404
2 changed files with 38 additions and 1 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#include "gdk/gdkdihedralprivate.h"
#include <graphene.h>
#include <math.h>
@ -251,3 +253,21 @@ gsk_rect_normalize (graphene_rect_t *r)
r->size.height = size;
}
}
static inline void
gsk_rect_dihedral (const graphene_rect_t *src,
GdkDihedral dihedral,
graphene_rect_t *res)
{
float xx, xy, yx, yy;
gdk_dihedral_get_mat2 (dihedral, &xx, &xy, &yx, &yy);
graphene_rect_init (res,
(xx * src->origin.x + xy * src->origin.y),
(yx * src->origin.x + yy * src->origin.y),
(xx * src->size.width + xy * src->size.height),
(yx * src->size.width + yy * src->size.height));
gsk_rect_normalize (res);
}

View File

@ -36,6 +36,8 @@
#include "gsktransformprivate.h"
#include "gskrectprivate.h"
/* {{{ Boilerplate */
struct _GskTransformClass
@ -2357,11 +2359,26 @@ gsk_transform_transform_bounds (GskTransform *self,
}
break;
case GSK_FINE_TRANSFORM_CATEGORY_2D_DIHEDRAL:
{
GdkDihedral dihedral;
float dx, dy, scale_x, scale_y;
gsk_transform_to_dihedral (self, &dihedral, &scale_x, &scale_y, &dx, &dy);
gsk_rect_dihedral (rect, dihedral, out_rect);
graphene_rect_init (out_rect,
(out_rect->origin.x * scale_x) + dx,
(out_rect->origin.y * scale_y) + dy,
out_rect->size.width * scale_x,
out_rect->size.height * scale_y);
}
break;
case GSK_FINE_TRANSFORM_CATEGORY_UNKNOWN:
case GSK_FINE_TRANSFORM_CATEGORY_ANY:
case GSK_FINE_TRANSFORM_CATEGORY_3D:
case GSK_FINE_TRANSFORM_CATEGORY_2D:
case GSK_FINE_TRANSFORM_CATEGORY_2D_DIHEDRAL:
default:
{
graphene_matrix_t mat;