From ded30049dbcbc2c479fd6cc7595c2de142b7bb12 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 8 Aug 2023 08:36:27 -0400 Subject: [PATCH] path: Add gsk_path_get_start/end_point These are useful to have, now that we are relying more on GskPathPoint in our api. --- gsk/gskcontour.c | 16 ++++++++++ gsk/gskcontourprivate.h | 1 + gsk/gskpath.c | 66 +++++++++++++++++++++++++++++++++++++++++ gsk/gskpath.h | 7 +++++ 4 files changed, 90 insertions(+) diff --git a/gsk/gskcontour.c b/gsk/gskcontour.c index 19c00718b1..62a6389f04 100644 --- a/gsk/gskcontour.c +++ b/gsk/gskcontour.c @@ -61,6 +61,7 @@ struct _GskContourClass GskContour * (* reverse) (const GskContour *contour); int (* get_winding) (const GskContour *contour, const graphene_point_t *point); + gsize (* get_n_points) (const GskContour *contour); gboolean (* get_closest_point) (const GskContour *contour, const graphene_point_t *point, float threshold, @@ -399,6 +400,14 @@ gsk_standard_contour_get_winding (const GskContour *contour, return winding; } +static gsize +gsk_standard_contour_get_n_points (const GskContour *contour) +{ + GskStandardContour *self = (GskStandardContour *) contour; + + return self->n_ops; +} + static gboolean gsk_standard_contour_get_closest_point (const GskContour *contour, const graphene_point_t *point, @@ -556,6 +565,7 @@ static const GskContourClass GSK_STANDARD_CONTOUR_CLASS = gsk_standard_contour_foreach, gsk_standard_contour_reverse, gsk_standard_contour_get_winding, + gsk_standard_contour_get_n_points, gsk_standard_contour_get_closest_point, gsk_standard_contour_get_position, gsk_standard_contour_get_tangent, @@ -706,6 +716,12 @@ gsk_contour_get_closest_point (const GskContour *self, return self->klass->get_closest_point (self, point, threshold, result, out_dist); } +gsize +gsk_contour_get_n_points (const GskContour *self) +{ + return self->klass->get_n_points (self); +} + void gsk_contour_get_position (const GskContour *self, GskRealPathPoint *point, diff --git a/gsk/gskcontourprivate.h b/gsk/gskcontourprivate.h index 3b6365de9a..93f4ad9584 100644 --- a/gsk/gskcontourprivate.h +++ b/gsk/gskcontourprivate.h @@ -57,6 +57,7 @@ void gsk_contour_get_start_end (const GskContou graphene_point_t *end); int gsk_contour_get_winding (const GskContour *self, const graphene_point_t *point); +gsize gsk_contour_get_n_points (const GskContour *self); gboolean gsk_contour_get_closest_point (const GskContour *self, const graphene_point_t *point, float threshold, diff --git a/gsk/gskpath.c b/gsk/gskpath.c index 8a9764f505..e305ada47b 100644 --- a/gsk/gskpath.c +++ b/gsk/gskpath.c @@ -490,6 +490,72 @@ gsk_path_in_fill (GskPath *self, } } +/** + * gsk_path_get_start_point: + * @self: a `GskPath` + * @result: (out caller-allocates): return location for point + * + * Gets the start point of the path. + * + * An empty path has no points, so `FALSE` + * is returned in this case. + * + * Returns: `TRUE` if @result was filled + * + * Since: 4.14 + */ +gboolean +gsk_path_get_start_point (GskPath *self, + GskPathPoint *result) +{ + GskRealPathPoint *res = (GskRealPathPoint *) result; + + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (result != NULL, FALSE); + + if (self->n_contours == 0) + return FALSE; + + res->contour = 0; + res->idx = 1; + res->t = 0; + + return TRUE; +} + +/** + * gsk_path_get_end_point: + * @self: a `GskPath` + * @result: (out caller-allocates): return location for point + * + * Gets the end point of the path. + * + * An empty path has no points, so `FALSE` + * is returned in this case. + * + * Returns: `TRUE` if @result was filled + * + * Since: 4.14 + */ +gboolean +gsk_path_get_end_point (GskPath *self, + GskPathPoint *result) +{ + GskRealPathPoint *res = (GskRealPathPoint *) result; + + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (result != NULL, FALSE); + + if (self->n_contours == 0) + return FALSE; + + res->contour = self->n_contours - 1; + res->idx = gsk_contour_get_n_points (self->contours[self->n_contours - 1]) - 1; + res->t = 1; + + return TRUE; +} + /** * gsk_path_get_closest_point: * @self: a `GskPath` diff --git a/gsk/gskpath.h b/gsk/gskpath.h index 375e56d7e0..5cf43d5af7 100644 --- a/gsk/gskpath.h +++ b/gsk/gskpath.h @@ -110,6 +110,13 @@ gboolean gsk_path_in_fill (GskPath const graphene_point_t *point, GskFillRule fill_rule); +GDK_AVAILABLE_IN_4_14 +gboolean gsk_path_get_start_point (GskPath *self, + GskPathPoint *result); +GDK_AVAILABLE_IN_4_14 +gboolean gsk_path_get_end_point (GskPath *self, + GskPathPoint *result); + GDK_AVAILABLE_IN_4_14 gboolean gsk_path_get_closest_point (GskPath *self, const graphene_point_t *point,