[gtk/curve-ops: 3/3] Add curve split tests




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

    Add curve split tests

 testsuite/gsk/curve.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index bea1cfe143..8bea03db8e 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -227,6 +227,54 @@ test_curve_curve_intersection (void)
   g_assert_cmpfloat (t2[1], >, 0.5);
 }
 
+/* Some sanity checks for splitting curves.
+ */
+static void
+test_curve_split (void)
+{
+  GskCurve c;
+
+  for (int i = 0; i < 100; i++)
+    {
+      init_random_curve (&c);
+
+      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_eval (&c, j / 20.0, &p, &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));
+
+        }
+    }
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -238,6 +286,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]