summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2020-11-25 00:16:47 +0100
committerBenjamin Otte <otte@redhat.com>2020-11-26 03:16:23 +0100
commit0fd04ca3c6e487f7786c6aa2323cff12ad09b0f2 (patch)
treef6943939c5f9a27dbcc9315318567829cbeac528
parentb55558dfa5ef5cd627adb493318c2ce1157c8570 (diff)
downloadgtk+-0fd04ca3c6e487f7786c6aa2323cff12ad09b0f2.tar.gz
testsuite: Add tests for gsk_path_measure_get_closest_point()
-rw-r--r--testsuite/gsk/path.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c
index 793457fcae..e50212f24b 100644
--- a/testsuite/gsk/path.c
+++ b/testsuite/gsk/path.c
@@ -264,6 +264,90 @@ test_segment (void)
}
}
+static void
+test_closest_point (void)
+{
+ GskPath *path, *path1, *path2;
+ GskPathMeasure *measure, *measure1, *measure2;
+ GskPathBuilder *builder;
+ guint i, j;
+
+ for (i = 0; i < 10; i++)
+ {
+ path1 = create_random_path ();
+ measure1 = gsk_path_measure_new (path1);
+ path2 = create_random_path ();
+ measure2 = gsk_path_measure_new (path2);
+
+ builder = gsk_path_builder_new ();
+ gsk_path_builder_add_path (builder, path1);
+ gsk_path_builder_add_path (builder, path2);
+ path = gsk_path_builder_free_to_path (builder);
+ measure = gsk_path_measure_new (path);
+
+ for (j = 0; j < 100; j++)
+ {
+ graphene_point_t test = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
+ g_test_rand_double_range (-1000, 1000));
+ graphene_point_t p1, p2, p;
+ graphene_vec2_t t1, t2, t;
+ float offset1, offset2, offset;
+ float distance1, distance2, distance;
+ gboolean found1, found2, found;
+
+ found1 = gsk_path_measure_get_closest_point_full (measure1,
+ &test,
+ INFINITY,
+ &distance1,
+ &p1,
+ &offset1,
+ &t1);
+ found2 = gsk_path_measure_get_closest_point_full (measure2,
+ &test,
+ INFINITY,
+ &distance2,
+ &p2,
+ &offset2,
+ &t2);
+ found = gsk_path_measure_get_closest_point_full (measure,
+ &test,
+ INFINITY,
+ &distance,
+ &p,
+ &offset,
+ &t);
+
+ if (found1 && (!found2 || distance1 < distance2))
+ {
+ g_assert_cmpfloat (distance1, ==, distance);
+ g_assert_cmpfloat (p1.x, ==, p.x);
+ g_assert_cmpfloat (p1.y, ==, p.y);
+ g_assert_cmpfloat (offset1, ==, offset);
+ g_assert_true (graphene_vec2_equal (&t1, &t));
+ }
+ else if (found2)
+ {
+ g_assert_cmpfloat (distance2, ==, distance);
+ g_assert_cmpfloat (p2.x, ==, p.x);
+ g_assert_cmpfloat (p2.y, ==, p.y);
+ g_assert_cmpfloat_with_epsilon (offset2 + gsk_path_measure_get_length (measure1), offset, MAX (G_MINFLOAT, offset / 1024));
+ g_assert_true (graphene_vec2_equal (&t2, &t));
+ }
+ else
+ {
+ g_assert (!found);
+ }
+ }
+
+ gsk_path_measure_unref (measure2);
+ gsk_path_measure_unref (measure1);
+ gsk_path_measure_unref (measure);
+ gsk_path_unref (path2);
+ gsk_path_unref (path1);
+ gsk_path_unref (path);
+ }
+}
+
int
main (int argc,
char *argv[])
@@ -275,6 +359,7 @@ main (int argc,
g_test_add_func ("/path/segment_end", test_segment_end);
g_test_add_func ("/path/segment_chunk", test_segment_chunk);
g_test_add_func ("/path/segment", test_segment);
+ g_test_add_func ("/path/closest_point", test_closest_point);
return g_test_run ();
}