[gtk/wip/matthiasc/lottie-stroke] Add a test for gsk_path_get_stroke_bounds



commit 016eabc28e1bb333f7d5880f58accffa153ac076
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 6 18:07:50 2020 -0500

    Add a test for gsk_path_get_stroke_bounds
    
    Test that the stroke path is actually contained
    in the stroke bounds. This works for paths that
    the stroker can handle, ie without too close
    neighbouring points.

 testsuite/gsk/path.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
---
diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c
index f04cd84d7c..92e66c1a2c 100644
--- a/testsuite/gsk/path.c
+++ b/testsuite/gsk/path.c
@@ -1165,6 +1165,71 @@ test_path_stroke_distance (void)
   gsk_stroke_free (stroke);
 }
 
+static void
+check_path_contained (GskPath         *path,
+                      graphene_rect_t *bounds)
+{
+  GskPathMeasure *measure;
+  float length;
+  float t;
+  int i;
+  graphene_point_t p;
+
+  measure = gsk_path_measure_new_with_tolerance (path, 0.1);
+  length = gsk_path_measure_get_length (measure);
+
+  for (i = 0; i < 1000; i++)
+    {
+      t = g_test_rand_double_range (0, length);
+      gsk_path_measure_get_point (measure,t, &p, NULL);
+
+      g_assert_true (graphene_rect_contains_point (bounds, &p));
+    }
+
+  gsk_path_measure_unref (measure);
+}
+
+static void
+test_path_stroke_bounds (void)
+{
+  GskPath *path;
+  GskPathMeasure *measure;
+  GskPath *stroke_path;
+  GskStroke *stroke;
+  int i;
+  float width = 10;
+  graphene_rect_t bounds;
+
+  stroke = gsk_stroke_new (width);
+  gsk_stroke_set_line_cap (stroke, GSK_LINE_CAP_ROUND);
+
+  i = 0;
+  while (i < 1000)
+    {
+      path = create_random_path (1);
+      /* We know the stroker can't robustly handle paths with
+       * too close neighbouring points
+       */
+      if (!path_is_spaced_out (path, width / 2))
+        continue;
+
+      measure = gsk_path_measure_new (path);
+      stroke_path = gsk_path_measure_stroke (measure, stroke);
+
+      gsk_path_get_stroke_bounds (path, stroke, &bounds);
+
+      check_path_contained (stroke_path, &bounds);
+
+      gsk_path_unref (stroke_path);
+      gsk_path_measure_unref (measure);
+      gsk_path_unref (path);
+
+      i++;
+    }
+
+  gsk_stroke_free (stroke);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -1183,6 +1248,7 @@ main (int   argc,
   g_test_add_func ("/path/in-fill-union", test_in_fill_union);
   g_test_add_func ("/path/in-fill-rotated", test_in_fill_rotated);
   g_test_add_func ("/path/stroke/distance", test_path_stroke_distance);
+  g_test_add_func ("/path/stroke/bounds", test_path_stroke_bounds);
 
   return g_test_run ();
 }


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