[gtk/path-work-rebased: 12/36] curve2: Show osculating circles




commit 98aca9e2cd2dc5c6331298a894d59f2779a1e064
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 23 18:52:56 2020 -0500

    curve2: Show osculating circles

 tests/curve2.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
---
diff --git a/tests/curve2.c b/tests/curve2.c
index b79b3b96f9..5a9f99cc52 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -13,6 +13,8 @@ struct _DemoWidget
   graphene_point_t point2;
   graphene_vec2_t tangent;
   double start, end;
+  float curvature;
+  graphene_point_t center;
 
   gboolean track;
   gboolean show_bounding_box;
@@ -63,6 +65,7 @@ motion (GtkEventControllerMotion *controller,
                                                &self->tangent);
 
       gsk_path_measure_get_point (self->measure, t, &self->point2, NULL);
+      self->curvature = gsk_path_measure_get_curvature (self->measure, t, &self->center);
 
       text = g_strdup_printf ("%.1f", distance);
       gtk_label_set_label (GTK_LABEL (self->label), text);
@@ -273,6 +276,25 @@ demo_widget_snapshot (GtkWidget   *widget,
 
       gsk_path_unref (path);
 
+      if (self->curvature != 0)
+        {
+          builder = gsk_path_builder_new ();
+          gsk_path_builder_add_circle (builder, &self->center, fabs (1/self->curvature));
+          gsk_path_builder_add_circle (builder, &self->center, 3);
+
+          path = gsk_path_builder_free_to_path (builder);
+
+          stroke = gsk_stroke_new (1.0);
+          gtk_snapshot_push_stroke (snapshot, path, stroke);
+          gsk_stroke_free (stroke);
+
+          gtk_snapshot_append_color (snapshot,
+                                     &(GdkRGBA){ 1, 0, 1, 1},
+                                     &GRAPHENE_RECT_INIT (0, 0, width, height ));
+
+          gtk_snapshot_pop (snapshot);
+        }
+
       gtk_widget_snapshot_child (widget, self->label, snapshot);
     }
 


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