[gtk/curve-ops: 17/17] Test splitting harder
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/curve-ops: 17/17] Test splitting harder
- Date: Tue, 8 Dec 2020 19:18:17 +0000 (UTC)
commit 93c63a1ef2c1520e9d14ed2d3b1eef225e89d298
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 8 14:17:25 2020 -0500
Test splitting harder
Check that the points on the split curves are close
to the original curve, as they should.
testsuite/gsk/curve.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index 8bea03db8e..a04fa60634 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -227,6 +227,40 @@ test_curve_curve_intersection (void)
g_assert_cmpfloat (t2[1], >, 0.5);
}
+static void
+gsk_path_builder_pathop_to (GskPathBuilder *builder,
+ gskpathop op)
+{
+ const graphene_point_t *pts = gsk_pathop_points (op);
+
+ switch (gsk_pathop_op (op))
+ {
+ case GSK_PATH_MOVE:
+ gsk_path_builder_move_to (builder, pts[0].x, pts[0].y);
+ break;
+
+ case GSK_PATH_CLOSE:
+ gsk_path_builder_close (builder);
+ break;
+
+ case GSK_PATH_LINE:
+ gsk_path_builder_line_to (builder, pts[1].x, pts[1].y);
+ break;
+
+ case GSK_PATH_CURVE:
+ gsk_path_builder_curve_to (builder, pts[1].x, pts[1].y, pts[2].x, pts[2].y, pts[3].x, pts[3].y);
+ break;
+
+ case GSK_PATH_CONIC:
+ gsk_path_builder_conic_to (builder, pts[1].x, pts[1].y, pts[3].x, pts[3].y, pts[2].x);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+}
+
/* Some sanity checks for splitting curves.
*/
static void
@@ -236,8 +270,21 @@ test_curve_split (void)
for (int i = 0; i < 100; i++)
{
+ GskPathBuilder *builder;
+ GskPath *path;
+ GskPathMeasure *measure;
+ const graphene_point_t *s;
+
init_random_curve (&c);
+ builder = gsk_path_builder_new ();
+
+ s = gsk_curve_get_start_point (&c);
+ gsk_path_builder_move_to (builder, s->x, s->y);
+ gsk_curve_builder_to (&c, builder);
+ path = gsk_path_builder_free_to_path (builder);
+ measure = gsk_path_measure_new (path);
+
for (int j = 1; j < 20; j++)
{
GskCurve c1, c2;
@@ -271,6 +318,19 @@ test_curve_split (void)
gsk_curve_get_end_tangent (&c2, &t2);
g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
+ for (int k = 0; k < 20; k++)
+ {
+ graphene_point_t q;
+ float dist;
+
+ gsk_curve_eval (&c1, k/19, &q, NULL);
+ dist = gsk_path_measure_get_closest_point (measure, &q, NULL);
+ g_assert_cmpint (dist, <=, 0.001);
+
+ gsk_curve_eval (&c2, k/19, &q, NULL);
+ dist = gsk_path_measure_get_closest_point (measure, &q, NULL);
+ g_assert_cmpint (dist, <=, 0.001);
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]