[gtk/wip/otte/lottie: 29/31] testsuite: Add a test for get_point()




commit 6f2050ac3d166a914c07bd97431fa3f6a9d25ac2
Author: Benjamin Otte <otte redhat com>
Date:   Fri Nov 27 07:12:03 2020 +0100

    testsuite: Add a test for get_point()

 testsuite/gsk/path.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
---
diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c
index 1c98db2640..9aab55612d 100644
--- a/testsuite/gsk/path.c
+++ b/testsuite/gsk/path.c
@@ -430,6 +430,55 @@ test_segment (void)
     }
 }
 
+static void
+test_get_point (void)
+{
+  static const guint max_contours = 5;
+  static const float tolerance = 0.5;
+  GskPath *path;
+  GskPathMeasure *measure;
+  guint n_discontinuities;
+  float length, offset, last_offset;
+  graphene_point_t point, last_point;
+  guint i, j;
+
+  for (i = 0; i < 10; i++)
+    {
+      path = create_random_path (max_contours);
+      measure = gsk_path_measure_new_with_tolerance (path, tolerance);
+      length = gsk_path_measure_get_length (measure);
+      n_discontinuities = 0;
+
+      gsk_path_measure_get_point (measure,
+                                  0,
+                                  &last_point,
+                                  NULL);
+      /* FIXME: anything we can test with tangents here? */
+      last_offset = 0;
+
+      for (j = 1; j <= 1024; j++)
+        {
+          offset = length * j / 1024;
+          gsk_path_measure_get_point (measure,
+                                      offset,
+                                      &point,
+                                      NULL);
+
+          if (graphene_point_distance (&last_point, &point, NULL, NULL) > offset - last_offset + tolerance)
+            {
+              n_discontinuities++;
+              g_assert_cmpint (n_discontinuities, <, max_contours);
+            }
+
+          last_offset = offset;
+          last_point = point;
+        }
+
+      gsk_path_measure_unref (measure);
+      gsk_path_unref (path);
+    }
+}
+
 static void
 test_closest_point (void)
 {
@@ -526,6 +575,7 @@ main (int   argc,
   g_test_add_func ("/path/segment_end", test_segment_end);
   g_test_add_func ("/path/segment_chunk", test_segment_chunk);
   g_test_add_func ("/path/segment", test_segment);
+  g_test_add_func ("/path/get_point", test_get_point);
   g_test_add_func ("/path/closest_point", test_closest_point);
 
   return g_test_run ();


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