[gtk/matthiasc/lottie2: 23/24] Add another test




commit 61f3949bbe565c95c43e9f6d0f44f212c71f46f2
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Nov 26 02:02:55 2020 -0500

    Add another test
    
    Check that the returned offset actually matches the point
    that is returned by gsk_path_measure_get_closest_point_full.

 testsuite/gsk/path.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
---
diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c
index a5a7986660..c3025b0a95 100644
--- a/testsuite/gsk/path.c
+++ b/testsuite/gsk/path.c
@@ -782,6 +782,49 @@ test_bounds (void)
     }
 }
 
+static void
+test_closest_point_offset (void)
+{
+  GskPath *path;
+  GskPathMeasure *measure;
+  guint i, j;
+
+  for (i = 0; i < 10; i++)
+    {
+      path = create_random_path ();
+      measure = gsk_path_measure_new (path);
+
+      for (j = 0; j < 100; j++)
+        {
+          graphene_point_t test = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
+                                                       g_test_rand_double_range (-1000, 1000));
+          graphene_point_t p;
+          graphene_vec2_t t;
+          float offset;
+          float distance;
+          gboolean found;
+
+          found = gsk_path_measure_get_closest_point_full (measure,
+                                                           &test,
+                                                           INFINITY,
+                                                           &distance,
+                                                           &p,
+                                                           &offset,
+                                                           &t);
+
+          if (found)
+            {
+              graphene_point_t p2;
+              gsk_path_measure_get_point (measure, offset, &p2, NULL);
+              g_assert_true (graphene_point_near (&p, &p2, 0.0001));
+            }
+        }
+
+      gsk_path_measure_unref (measure);
+      gsk_path_unref (path);
+    }
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -798,6 +841,7 @@ main (int   argc,
   g_test_add_func ("/path/from-random-string", test_from_random_string);
   g_test_add_func ("/path/serialize", test_serialize);
   g_test_add_func ("/path/bounds", test_bounds);
+  g_test_add_func ("/path/closest_point_offset", test_closest_point_offset);
 
   return g_test_run ();
 }


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