From 64807abc59e5aca7834f9183f4295f8de7502944 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 20 Dec 2020 11:19:43 -0500 Subject: [PATCH] Add a test for tangents of degenerate curves The stroker relies on these to work. --- testsuite/gsk/curve-special-cases.c | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/testsuite/gsk/curve-special-cases.c b/testsuite/gsk/curve-special-cases.c index 820cb73d59..d8dd0274ba 100644 --- a/testsuite/gsk/curve-special-cases.c +++ b/testsuite/gsk/curve-special-cases.c @@ -87,7 +87,6 @@ test_curve_tangents (void) gsk_curve_get_end_tangent (&c, &t); g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001)); - graphene_point_init (&p[0], 0, 0); graphene_point_init (&p[1], 0, 100); gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_LINE, p)); @@ -120,6 +119,36 @@ test_curve_tangents (void) g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001)); } +static void +test_curve_degenerate_tangents (void) +{ + GskCurve c; + graphene_point_t p[4]; + graphene_vec2_t t; + + graphene_point_init (&p[0], 0, 0); + graphene_point_init (&p[1], 0, 0); + graphene_point_init (&p[2], 100, 0); + graphene_point_init (&p[3], 100, 0); + gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CURVE, p)); + + gsk_curve_get_start_tangent (&c, &t); + g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001)); + gsk_curve_get_end_tangent (&c, &t); + g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001)); + + graphene_point_init (&p[0], 0, 0); + graphene_point_init (&p[1], 50, 0); + graphene_point_init (&p[2], 50, 0); + graphene_point_init (&p[3], 100, 0); + gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CURVE, p)); + + gsk_curve_get_start_tangent (&c, &t); + g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001)); + gsk_curve_get_end_tangent (&c, &t); + g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001)); +} + static void test_errant_intersection (void) { @@ -258,7 +287,6 @@ test_line_intersection_parallel (void) 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 @@ -269,6 +297,7 @@ 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/special/degenerate-tangents", test_curve_degenerate_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);