summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-12-07 11:51:47 -0500
committerBenjamin Otte <otte@redhat.com>2020-12-27 00:31:18 +0100
commit61214221b30331ef9b5f19f091e7413ba8e1f3fd (patch)
tree595e6015734d6ba548701b04c9d0b97d4c55ca31
parent7eb4ed8f86495bc5d1642c9d0cdd45ee7c574107 (diff)
downloadgtk+-61214221b30331ef9b5f19f091e7413ba8e1f3fd.tar.gz
testsuite Add curve tangent tests
-rw-r--r--testsuite/gsk/curve-special-cases.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/testsuite/gsk/curve-special-cases.c b/testsuite/gsk/curve-special-cases.c
index 6caf8f2c92..aac4976573 100644
--- a/testsuite/gsk/curve-special-cases.c
+++ b/testsuite/gsk/curve-special-cases.c
@@ -71,6 +71,55 @@ test_conic_segment (void)
g_assert_cmpfloat_with_epsilon (measure_length (&c), measure_length (&s) + measure_length (&m) + measure_length (&e), 0.03125);
}
+static void
+test_curve_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], 100, 0);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_LINE, 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], 0, 100);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_LINE, p));
+
+ gsk_curve_get_start_tangent (&c, &t);
+ g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
+ gsk_curve_get_end_tangent (&c, &t);
+ g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
+
+ graphene_point_init (&p[0], 0, 0);
+ graphene_point_init (&p[1], 100, 0);
+ p[2] = GRAPHENE_POINT_INIT (g_test_rand_double_range (0, 20), 0);
+ graphene_point_init (&p[3], 100, 100);
+ gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CONIC, 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_y_axis (), 0.0001));
+
+ graphene_point_init (&p[0], 0, 0);
+ graphene_point_init (&p[1], 50, 0);
+ graphene_point_init (&p[2], 100, 50);
+ graphene_point_init (&p[3], 100, 100);
+ 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_y_axis (), 0.0001));
+}
+
int
main (int argc,
char *argv[])
@@ -78,6 +127,7 @@ main (int argc,
gtk_test_init (&argc, &argv, NULL);
g_test_add_func ("/curve/special/conic-segment", test_conic_segment);
+ g_test_add_func ("/curve/special/tangents", test_curve_tangents);
return g_test_run ();
}