[gtk/wip/baedert/gl-rework: 66/71] GskTransform: Add gsk_transform_transform_point()



commit 0f43108e7745e08105ab7b11ade72eb6598b17af
Author: Timm Bäder <mail baedert org>
Date:   Tue Jan 21 09:41:54 2020 +0100

    GskTransform: Add gsk_transform_transform_point()
    
    Equivalent of gsk_transform_transform_bounds() and
    graphene_matrix_transform_point() respectively.

 gsk/gsktransform.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gsk/gsktransform.h |  5 +++++
 2 files changed, 61 insertions(+)
---
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
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]