[gtk/path-work-rebased: 60/118] testuite: Add tests for gsk_curve_get_tangent()




commit fa094b5678bbc7319fcbbe8bd727bc210b37f65e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Dec 8 21:23:58 2020 +0100

    testuite: Add tests for gsk_curve_get_tangent()

 testsuite/gsk/curve.c | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index 5e83a1b806..2fd899aa0b 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -61,6 +61,30 @@ init_random_curve (GskCurve *curve)
     }
 }
 
+static void
+test_curve_tangents (void)
+{
+  for (int i = 0; i < 100; i++)
+    {
+      GskCurve c;
+      graphene_vec2_t vec, exact;
+
+      init_random_curve (&c);
+
+      gsk_curve_get_tangent (&c, 0, &vec);
+      g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&vec), 1.0f, 0.00001);
+      gsk_curve_get_start_tangent (&c, &exact);
+      g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&exact), 1.0f, 0.00001);
+      g_assert_true (graphene_vec2_near (&vec, &exact, 0.05));
+
+      gsk_curve_get_tangent (&c, 1, &vec);
+      g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&vec), 1.0f, 0.00001);
+      gsk_curve_get_end_tangent (&c, &exact);
+      g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&exact), 1.0f, 0.00001);
+      g_assert_true (graphene_vec2_near (&vec, &exact, 0.05));
+    }
+}
+
 static void
 test_curve_points (void)
 {
@@ -71,10 +95,16 @@ test_curve_points (void)
 
       init_random_curve (&c);
 
-      gsk_curve_eval (&c, 0, &p, NULL);
-      g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c), &p, 0.01));
-      gsk_curve_eval (&c, 1, &p, NULL);
-      g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c), &p, 0.01));
+      /* We can assert equality here because evaluating the polynomials with 0
+       * has no effect on accuracy.
+       */
+      gsk_curve_get_point (&c, 0, &p);
+      g_assert_true (graphene_point_equal (gsk_curve_get_start_point (&c), &p));
+      /* But here we evaluate the polynomials with 1 which gives the highest possible
+       * accuracy error. So we'll just be generous here.
+       */
+      gsk_curve_get_point (&c, 1, &p);
+      g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c), &p, 0.05));
     }
 }
 
@@ -84,6 +114,7 @@ main (int argc, char *argv[])
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/curve/points", test_curve_points);
+  g_test_add_func ("/curve/tangents", test_curve_tangents);
 
   return g_test_run ();
 }


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