[gtk/wip/matthiasc/lottie-stroke: 217/217] Add a testcase
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/lottie-stroke: 217/217] Add a testcase
- Date: Sat, 5 Dec 2020 08:00:24 +0000 (UTC)
commit e76c11e96f39c6048d39f71cd28cc332117c970c
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 5 02:56:55 2020 -0500
Add a testcase
Test that we compute the correct distance when finding
the closest point to a rectangle. Currently, we don't.
testsuite/gsk/path-special-cases.c | 51 ++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
---
diff --git a/testsuite/gsk/path-special-cases.c b/testsuite/gsk/path-special-cases.c
index 8f97eaa17c..d76f752b35 100644
--- a/testsuite/gsk/path-special-cases.c
+++ b/testsuite/gsk/path-special-cases.c
@@ -306,6 +306,56 @@ test_serialize_custom_contours (void)
gsk_path_unref (path1);
}
+/* Test that get_closest_point works for rectangles and circles */
+static void
+test_closest_point_custom_contours (void)
+{
+ static const float tolerance = 0.5;
+ GskPathBuilder *builder;
+ GskPath *path;
+ GskPathMeasure *measure;
+ float length, offset, closest_offset, distance;
+ graphene_point_t point, closest_point;
+ guint i, j;
+
+ for (i = 0; i < 2; i++)
+ {
+ builder = gsk_path_builder_new ();
+ if (i == 0)
+ gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (100, 100, 200, 200));
+ else
+ gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (100, 100), 200);
+
+ path = gsk_path_builder_free_to_path (builder);
+
+ measure = gsk_path_measure_new_with_tolerance (path, tolerance);
+ length = gsk_path_measure_get_length (measure);
+
+ for (j = 0; j < 100; j++)
+ {
+ offset = g_test_rand_double_range (0, length);
+
+ gsk_path_measure_get_point (measure,
+ offset,
+ &point,
+ NULL);
+ g_assert_true (gsk_path_measure_get_closest_point_full (measure,
+ &point,
+ tolerance,
+ &distance,
+ &closest_point,
+ &closest_offset,
+ NULL));
+ g_assert_cmpfloat (distance, <=, tolerance);
+ g_assert_cmpfloat (graphene_point_distance (&point, &closest_point, NULL, NULL), <=, tolerance);
+ g_assert_cmpfloat_with_epsilon (closest_offset, offset, tolerance);
+ }
+
+ gsk_path_measure_unref (measure);
+ gsk_path_unref (path);
+ }
+}
+
/* Test that single-point contours don't crash the stroker */
static void
test_point_to_stroke (void)
@@ -353,6 +403,7 @@ main (int argc,
g_test_add_func ("/path/rsvg-parse", test_rsvg_parse);
g_test_add_func ("/path/serialize-custom-contours", test_serialize_custom_contours);
+ g_test_add_func ("/path/closest-point-custom-contours", test_closest_point_custom_contours);
g_test_add_func ("/path/point_to_stroke", test_point_to_stroke);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]