[gtk/curve-ops: 5/5] Add a test for curve bounds
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/curve-ops: 5/5] Add a test for curve bounds
- Date: Mon, 7 Dec 2020 07:33:54 +0000 (UTC)
commit 2bcff178488b43de9b3aa476fb1abd41518ddb4a
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 7 01:23:52 2020 -0500
Add a test for curve bounds
testsuite/gsk/curve.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index a58a1fb061..fb2ddc4bbb 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -83,6 +83,101 @@ test_curve_curve_intersection (void)
g_assert_cmpfloat (t2[1], >, 0.5);
}
+static void
+init_random_point (graphene_point_t *p)
+{
+ p->x = g_test_rand_double_range (0, 1000);
+ p->y = g_test_rand_double_range (0, 1000);
+}
+
+static void
+init_random_curve (GskCurve *curve)
+{
+ switch (g_test_rand_int_range (GSK_PATH_LINE, GSK_PATH_CONIC + 1))
+ {
+ case GSK_PATH_LINE:
+ {
+ graphene_point_t p[2];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_LINE, p));
+ }
+ break;
+
+ case GSK_PATH_CURVE:
+ {
+ graphene_point_t p[4];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ init_random_point (&p[2]);
+ init_random_point (&p[3]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CURVE, p));
+ }
+ break;
+
+ case GSK_PATH_CONIC:
+ {
+ graphene_point_t p[4];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ p[2] = GRAPHENE_POINT_INIT (g_test_rand_double_range (0, 20), 0);
+ init_random_point (&p[3]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CONIC, p));
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+test_curve_points (void)
+{
+ for (int i = 0; i < 100; i++)
+ {
+ GskCurve c;
+ graphene_point_t p;
+
+ 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));
+ }
+}
+
+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_hull (&c, &hull);
+ gsk_curve_get_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[])
{
@@ -91,6 +186,8 @@ 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/points", test_curve_points);
+ 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]