[gtk/curve-ops: 20/22] Add curve split tests




commit 3ae22c214ef6522134a596a8f564634351fee9fe
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 7 20:51:23 2020 -0500

    Add curve split tests

 testsuite/gsk/curve.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index 480943a402..5e0025cc7c 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -314,6 +314,81 @@ test_curve_curve_intersection (void)
   graphene_rect_contains_point (&b, &p[0]);
 }
 
+/* Some sanity checks for splitting curves.
+ */
+static void
+test_curve_split (void)
+{
+  GskCurve c;
+
+  for (int i = 0; i < 100; i++)
+    {
+      GskPathBuilder *builder;
+      GskPath *path;
+      GskPathMeasure *measure;
+      const graphene_point_t *s;
+
+      init_random_curve (&c);
+
+      builder = gsk_path_builder_new ();
+
+      s = gsk_curve_get_start_point (&c);
+      gsk_path_builder_move_to (builder, s->x, s->y);
+      gsk_curve_builder_to (&c, builder);
+      path = gsk_path_builder_free_to_path (builder);
+      measure = gsk_path_measure_new_with_tolerance (path, 0.1);
+
+      for (int j = 1; j < 20; j++)
+        {
+          GskCurve c1, c2;
+          graphene_point_t p;
+          graphene_vec2_t t, t1, t2;
+
+          gsk_curve_split (&c, j / 20.0, &c1, &c2);
+
+          g_assert_true (c1.op == c.op);
+          g_assert_true (c2.op == c.op);
+
+          g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c),
+                                              gsk_curve_get_start_point (&c1), 0.005));
+          g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c1),
+                                              gsk_curve_get_start_point (&c2), 0.005));
+          g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c),
+                                              gsk_curve_get_end_point (&c2), 0.005));
+          gsk_curve_get_point (&c, j / 20.0, &p);
+          gsk_curve_get_tangent (&c, j / 20.0, &t);
+          g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c1), &p, 0.005));
+          g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c2), &p, 0.005));
+
+          gsk_curve_get_start_tangent (&c, &t1);
+          gsk_curve_get_start_tangent (&c1, &t2);
+          g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
+          gsk_curve_get_end_tangent (&c1, &t1);
+          gsk_curve_get_start_tangent (&c2, &t2);
+          g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
+          g_assert_true (graphene_vec2_near (&t, &t1, 0.005));
+          g_assert_true (graphene_vec2_near (&t, &t2, 0.005));
+          gsk_curve_get_end_tangent (&c, &t1);
+          gsk_curve_get_end_tangent (&c2, &t2);
+          g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
+
+          for (int k = 0; k < 20; k++)
+            {
+              graphene_point_t q;
+              float dist;
+
+              gsk_curve_get_point (&c1, k/19.0, &q);
+              dist = gsk_path_measure_get_closest_point (measure, &q, NULL);
+              g_assert_cmpfloat (dist, <=, 0.1);
+
+              gsk_curve_get_point (&c2, k/19.0, &q);
+              dist = gsk_path_measure_get_closest_point (measure, &q, NULL);
+              g_assert_cmpfloat (dist, <=, 0.1);
+            }
+        }
+    }
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -326,6 +401,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/curve/intersection/line-line", test_line_line_intersection);
   g_test_add_func ("/curve/intersection/line-curve", test_line_curve_intersection);
   g_test_add_func ("/curve/intersection/curve-curve", test_curve_curve_intersection);
+  g_test_add_func ("/curve/split", test_curve_split);
 
   return g_test_run ();
 }


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