From cff83041330c18ff7c71bc5b1c53f36d09f9dc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 21 Jan 2020 09:41:54 +0100 Subject: [PATCH] GskTransform: Add gsk_transform_transform_point() Equivalent of gsk_transform_transform_bounds() and graphene_matrix_transform_point() respectively. --- docs/reference/gsk/gsk4-sections.txt | 1 + gsk/gsktransform.c | 56 ++++++++++++++++++++++++++++ gsk/gsktransform.h | 5 +++ 3 files changed, 62 insertions(+) diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt index 0f464bd195..201840b5c2 100644 --- a/docs/reference/gsk/gsk4-sections.txt +++ b/docs/reference/gsk/gsk4-sections.txt @@ -183,6 +183,7 @@ gsk_transform_perspective gsk_transform_equal gsk_transform_transform_bounds +gsk_transform_transform_point GSK_TYPE_TRANSFORM gsk_transform_get_type diff --git a/gsk/gsktransform.c b/gsk/gsktransform.c index 388dad5b45..5d9d538d4c 100644 --- a/gsk/gsktransform.c +++ b/gsk/gsktransform.c @@ -1773,6 +1773,62 @@ gsk_transform_transform_bounds (GskTransform *self, } } +/** + * gsk_transform_transform_point: + * @self: a #GskTransform + * @point: a #graphene_point_t + * @out_point: (out caller-allocates): return location for + * the transformed point + * + * Transforms a #graphene_point_t using the given transform @self. + */ +void +gsk_transform_transform_point (GskTransform *self, + const graphene_point_t *point, + graphene_point_t *out_point) +{ + switch (gsk_transform_get_category (self)) + { + case GSK_TRANSFORM_CATEGORY_IDENTITY: + *out_point = *point; + break; + + case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE: + { + float dx, dy; + + gsk_transform_to_translate (self, &dx, &dy); + out_point->x = point->x + dx; + out_point->y = point->y + dy; + } + break; + + case GSK_TRANSFORM_CATEGORY_2D_AFFINE: + { + float dx, dy, scale_x, scale_y; + + gsk_transform_to_affine (self, &scale_x, &scale_y, &dx, &dy); + + out_point->x = (point->x * scale_x) + dx; + out_point->y = (point->y * scale_y) + dy; + } + break; + + case GSK_TRANSFORM_CATEGORY_UNKNOWN: + case GSK_TRANSFORM_CATEGORY_ANY: + case GSK_TRANSFORM_CATEGORY_3D: + case GSK_TRANSFORM_CATEGORY_2D: + default: + { + graphene_matrix_t mat; + + gsk_transform_to_matrix (self, &mat); + graphene_matrix_transform_point (&mat, point, out_point); + } + break; + } +} + static guint gsk_transform_parse_float (GtkCssParser *parser, guint n, diff --git a/gsk/gsktransform.h b/gsk/gsktransform.h index 56cafcc430..f3676bca63 100644 --- a/gsk/gsktransform.h +++ b/gsk/gsktransform.h @@ -116,6 +116,11 @@ GDK_AVAILABLE_IN_ALL void gsk_transform_transform_bounds (GskTransform *self, const graphene_rect_t *rect, graphene_rect_t *out_rect); +GDK_AVAILABLE_IN_ALL +void gsk_transform_transform_point (GskTransform *self, + const graphene_point_t *point, + graphene_point_t *out_point); + G_END_DECLS