[gtk/path-work-rebased: 108/149] testsuite: Add special-case curve tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/path-work-rebased: 108/149] testsuite: Add special-case curve tests
- Date: Fri, 8 Apr 2022 02:53:27 +0000 (UTC)
commit d91e06398be896199308dcff0618379783111396
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Apr 7 14:48:19 2022 -0400
testsuite: Add special-case curve tests
testsuite/gsk/curve-special-cases.c | 144 ++++++++++++++++++++++++++++++++++++
testsuite/gsk/meson.build | 2 +-
2 files changed, 145 insertions(+), 1 deletion(-)
---
diff --git a/testsuite/gsk/curve-special-cases.c b/testsuite/gsk/curve-special-cases.c
index aac4976573..820cb73d59 100644
--- a/testsuite/gsk/curve-special-cases.c
+++ b/testsuite/gsk/curve-special-cases.c
@@ -120,6 +120,147 @@ test_curve_tangents (void)
g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
}
+static void
+test_errant_intersection (void)
+{
+ GskCurve c;
+ GskCurve l;
+ graphene_point_t p[4];
+ graphene_point_t q[2];
+ float t1[3], t2[3];
+ graphene_point_t s[3];
+ int n;
+
+ graphene_point_init (&p[0], 888, 482);
+ graphene_point_init (&p[1], 999.333313, 508.666687);
+ graphene_point_init (&p[2], 1080.83325, 544.333313);
+ graphene_point_init (&p[3], 1132.5, 589);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CURVE, p));
+
+ graphene_point_init (&q[0], 886, 680);
+ graphene_point_init (&q[1], 642, 618);
+ gsk_curve_init (&l, gsk_pathop_encode (GSK_PATH_LINE, q));
+
+ n = gsk_curve_intersect (&l, &c, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 0);
+}
+
+static void
+test_errant_intersection2 (void)
+{
+ GskCurve c;
+ GskCurve l;
+ graphene_point_t p[4];
+ graphene_point_t q[2];
+ float t1[3], t2[3];
+ graphene_point_t s[3];
+ int n;
+
+ graphene_point_init (&p[0], 1119.5, 772);
+ graphene_point_init (&p[1], 1039.16675, 850.666687);
+ graphene_point_init (&p[2], 925.333313, 890);
+ graphene_point_init (&p[3], 778, 890);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CURVE, p));
+
+ graphene_point_init (&q[0], 1052, 1430);
+ graphene_point_init (&q[1], 734, 762);
+ gsk_curve_init (&l, gsk_pathop_encode (GSK_PATH_LINE, q));
+
+ n = gsk_curve_intersect (&l, &c, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 1);
+
+ graphene_point_init (&q[0], 954, 762);
+ graphene_point_init (&q[1], 1292, 1430);
+ gsk_curve_init (&l, gsk_pathop_encode (GSK_PATH_LINE, q));
+
+ n = gsk_curve_intersect (&l, &c, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 1);
+
+ graphene_point_init (&p[0], 248, 142);
+ graphene_point_init (&p[1], 283, 103);
+ graphene_point_init (&p[2], 333, 80);
+ graphene_point_init (&p[3], 384, 80);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CURVE, p));
+
+ graphene_point_init (&q[0], 256, 719);
+ graphene_point_init (&q[1], 256, 76);
+ gsk_curve_init (&l, gsk_pathop_encode (GSK_PATH_LINE, q));
+
+ n = gsk_curve_intersect (&l, &c, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 1);
+}
+
+static void
+test_line_intersection_parallel (void)
+{
+ GskCurve l1;
+ GskCurve l2;
+ graphene_point_t p1[1];
+ graphene_point_t p2[2];
+ float t1[3], t2[3];
+ graphene_point_t s[3];
+ int n;
+
+ graphene_point_init (&p1[0], 0, 100);
+ graphene_point_init (&p1[1], 100, 100);
+ gsk_curve_init (&l1, gsk_pathop_encode (GSK_PATH_LINE, p1));
+
+ graphene_point_init (&p2[0], 0, 110);
+ graphene_point_init (&p2[1], 100, 110);
+ gsk_curve_init (&l2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&l1, &l2, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 0);
+
+ graphene_point_init (&p2[0], 110, 100);
+ graphene_point_init (&p2[1], 210, 100);
+ gsk_curve_init (&l2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&l1, &l2, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 0);
+
+ graphene_point_init (&p2[0], 0, 100);
+ graphene_point_init (&p2[1], -100, 100);
+ gsk_curve_init (&l2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&l1, &l2, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 1);
+ g_assert_cmpfloat_with_epsilon (t1[0], 0, 0.001);
+ g_assert_cmpfloat_with_epsilon (t2[0], 0, 0.001);
+
+ graphene_point_init (&p2[0], 20, 100);
+ graphene_point_init (&p2[1], 80, 100);
+ gsk_curve_init (&l2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&l1, &l2, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 2);
+ g_assert_cmpfloat_with_epsilon (t1[0], 0.2, 0.001);
+ g_assert_cmpfloat_with_epsilon (t1[1], 0.8, 0.001);
+ g_assert_cmpfloat_with_epsilon (t2[0], 0, 0.001);
+ g_assert_cmpfloat_with_epsilon (t2[1], 1, 0.001);
+
+ graphene_point_init (&p2[0], 150, 100);
+ graphene_point_init (&p2[1], 50, 100);
+ gsk_curve_init (&l2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&l1, &l2, t1, t2, s, G_N_ELEMENTS (s));
+
+ g_assert_true (n == 2);
+ g_assert_cmpfloat_with_epsilon (t1[0], 1, 0.001);
+ g_assert_cmpfloat_with_epsilon (t1[1], 0.5, 0.001);
+ g_assert_cmpfloat_with_epsilon (t2[0], 0.5, 0.001);
+ g_assert_cmpfloat_with_epsilon (t2[1], 1, 0.001);
+
+}
+
int
main (int argc,
char *argv[])
@@ -128,6 +269,9 @@ main (int argc,
g_test_add_func ("/curve/special/conic-segment", test_conic_segment);
g_test_add_func ("/curve/special/tangents", test_curve_tangents);
+ g_test_add_func ("/curve/errant-intersection", test_errant_intersection);
+ g_test_add_func ("/curve/errant-intersection2", test_errant_intersection2);
+ g_test_add_func ("/curve/line-intersection-parallel", test_line_intersection_parallel);
return g_test_run ();
}
diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build
index 5012a7d5aa..fb58541ff0 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -209,7 +209,7 @@ endforeach
tests = [
['curve', ['../../gsk/gskcurve.c', '../../gsk/gskcurveintersect.c'], ['-DGTK_COMPILATION']],
- ['curve-special-cases', ['../../gsk/gskcurve.c'], ['-DGTK_COMPILATION']],
+ ['curve-special-cases', ['../../gsk/gskcurve.c', '../../gsk/gskcurveintersect.c'], ['-DGTK_COMPILATION']],
['dash'],
['path'],
['path-special-cases'],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]