From d849a53b984b63fa8a0a69821d0d96d28bdd24dc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 20 Sep 2023 22:08:52 -0400 Subject: [PATCH 1/2] contour: Fix get_closest_point for circles --- gsk/gskcontour.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gsk/gskcontour.c b/gsk/gskcontour.c index 4071a387bc..7d36852ca1 100644 --- a/gsk/gskcontour.c +++ b/gsk/gskcontour.c @@ -104,6 +104,19 @@ struct _GskContourClass #define DEG_TO_RAD(x) ((x) * (G_PI / 180.f)) #define RAD_TO_DEG(x) ((x) / (G_PI / 180.f)) +static inline void +_sincosf (float angle, + float *out_s, + float *out_c) +{ +#ifdef HAVE_SINCOSF + sincosf (angle, out_s, out_c); +#else + *out_s = sinf (angle); + *out_c = cosf (angle); +#endif +} + static void _g_string_append_float (GString *string, const char *prefix, @@ -1498,7 +1511,7 @@ gsk_circle_contour_get_closest_point (const GskContour *contour, angle = atan2f (point->y - self->center.y, point->x - self->center.x); if (angle < 0) - angle = M_PI - angle; + angle = 2 * M_PI + angle; t = CLAMP (angle / (2 * M_PI), 0, 1); @@ -1554,9 +1567,11 @@ gsk_circle_contour_get_position (const GskContour *contour, } else { - float angle = M_PI_2 * ((idx - 1) + t); - *position = GRAPHENE_POINT_INIT (self->center.x + cosf (angle) * self->radius, - self->center.y + sinf (angle) * self->radius); + float s, c; + + _sincosf (M_PI_2 * ((idx - 1) + t), &s, &c); + *position = GRAPHENE_POINT_INIT (self->center.x + c * self->radius, + self->center.y + s * self->radius); } } From 76df3ade186e33cadc1578c8862c0e17920f515c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 20 Sep 2023 22:12:09 -0400 Subject: [PATCH 2/2] gtk-demo: Update some ifdefed code This was from a time when we had arcs. --- demos/gtk-demo/path_spinner.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demos/gtk-demo/path_spinner.c b/demos/gtk-demo/path_spinner.c index 914a608198..3c4945a3f9 100644 --- a/demos/gtk-demo/path_spinner.c +++ b/demos/gtk-demo/path_spinner.c @@ -9,6 +9,8 @@ #include "paintable.h" +#undef SHOW_CONTROLS + #define GTK_TYPE_SPINNER_PAINTABLE (gtk_spinner_paintable_get_type ()) G_DECLARE_FINAL_TYPE (GtkSpinnerPaintable, gtk_spinner_paintable, GTK, SPINNER_PAINTABLE, GObject) @@ -150,6 +152,7 @@ static gboolean add_controls (GskPathOperation op, const graphene_point_t *pts, gsize n_pts, + float weight, gpointer data) { GskPathBuilder *builder = data; @@ -166,7 +169,7 @@ add_controls (GskPathOperation op, break; case GSK_PATH_QUAD: - case GSK_PATH_ARC: + case GSK_PATH_CONIC: gsk_path_builder_line_to (builder, pts[1].x, pts[1].y); gsk_path_builder_line_to (builder, pts[2].x, pts[2].y); break;