[gtk/wip/otte/lottie: 6/7] testuite: Add tests for gsk_curve_get_tangent()




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

    testuite: Add tests for gsk_curve_get_tangent()

 gsk/gskcurve.c        |  4 ++--
 testsuite/gsk/curve.c | 39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/gsk/gskcurve.c b/gsk/gskcurve.c
index 8127c74da5..4abcf0afb7 100644
--- a/gsk/gskcurve.c
+++ b/gsk/gskcurve.c
@@ -687,7 +687,7 @@ static void
 gsk_conic_curve_get_start_tangent (const GskCurve  *curve,
                                    graphene_vec2_t *tangent)
 {
-  const GskCurveCurve *self = &curve->curve;
+  const GskConicCurve *self = &curve->curve;
 
   get_tangent (&self->points[0], &self->points[1], tangent);
 }
@@ -696,7 +696,7 @@ static void
 gsk_conic_curve_get_end_tangent (const GskCurve  *curve,
                                  graphene_vec2_t *tangent)
 {
-  const GskCurveCurve *self = &curve->curve;
+  const GskConicCurve *self = &curve->curve;
 
   get_tangent (&self->points[1], &self->points[3], tangent);
 }
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]