[gtk/curve-ops: 9/17] Add a curve bounds test




commit 5a785c3fab2e4c7e816e8cd7681a25e4f39dc8b7
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 7 01:23:52 2020 -0500

    Add a curve bounds test

 testsuite/gsk/curve.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index b48e4fbbd9..3108cb4ce3 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -118,6 +118,33 @@ test_curve_tangents (void)
   g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
 }
 
+static void
+test_curve_bounds (void)
+{
+  for (int i = 0; i < 100; i++)
+    {
+      GskCurve c;
+      graphene_rect_t bounds;
+      graphene_rect_t hull;
+
+      init_random_curve (&c);
+      gsk_curve_get_bounds (&c, &hull);
+      gsk_curve_get_tight_bounds (&c, &bounds);
+
+      graphene_rect_inset (&hull, - 0.5, - 0.5); // FIXME: this seems big
+      g_assert_true (graphene_rect_contains_rect (&hull, &bounds));
+      graphene_rect_inset (&bounds, - 0.5, - 0.5);
+
+      for (int j = 0; j < 100; j++)
+        {
+          graphene_point_t p;
+
+          gsk_curve_eval (&c, j / 99.0, &p, NULL);
+          g_assert_true (graphene_rect_contains_point (&bounds, &p));
+        }
+    }
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -125,6 +152,7 @@ main (int argc, char *argv[])
 
   g_test_add_func ("/curve/points", test_curve_points);
   g_test_add_func ("/curve/tangents", test_curve_tangents);
+  g_test_add_func ("/curve/bounds", test_curve_bounds);
 
   return g_test_run ();
 }


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