[gtk/path-ops: 4/19] curve: Fix line-curve intersections
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/path-ops: 4/19] curve: Fix line-curve intersections
- Date: Fri, 25 Mar 2022 13:56:52 +0000 (UTC)
commit f8602487482b42892d4ce534fc7190125a21f92b
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 20 21:27:44 2022 -0400
curve: Fix line-curve intersections
We were not rejecting intersections outside the
[0, 1] range of the line. Test included.
gsk/gskcurveintersect.c | 14 +++++++++-----
testsuite/gsk/curve.c | 26 ++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/gsk/gskcurveintersect.c b/gsk/gskcurveintersect.c
index 327827c718..1b0d820dfa 100644
--- a/gsk/gskcurveintersect.c
+++ b/gsk/gskcurveintersect.c
@@ -231,7 +231,7 @@ line_curve_intersect (const GskCurve *curve1,
const graphene_point_t *b = &curve1->line.points[1];
graphene_point_t pts[4];
float t[3];
- int m, i;
+ int m, i, j;
/* Rotate things to place curve1 on the x axis,
* then solve curve2 for y == 0.
@@ -241,14 +241,18 @@ line_curve_intersect (const GskCurve *curve1,
m = get_cubic_roots (pts[0].y, pts[1].y, pts[2].y, pts[3].y, t);
m = MIN (m, n);
+
+ j = 0;
for (i = 0; i < m; i++)
{
- t2[i] = t[i];
- gsk_curve_get_point (curve2, t[i], &p[i]);
- find_point_on_line (a, b, &p[i], &t1[i]);
+ t2[j] = t[i];
+ gsk_curve_get_point (curve2, t2[j], &p[j]);
+ find_point_on_line (a, b, &p[i], &t1[j]);
+ if (acceptable (t1[j]))
+ j++;
}
- return m;
+ return j;
}
static void
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
index 1d6cb73f40..7bae660ac5 100644
--- a/testsuite/gsk/curve.c
+++ b/testsuite/gsk/curve.c
@@ -327,6 +327,31 @@ test_line_curve_intersection (void)
graphene_rect_contains_point (&b, &p[0]);
}
+static void
+test_line_curve_none_intersection (void)
+{
+ GskCurve c1, c2;
+ graphene_point_t p1[4], p2[2];
+ float t1[9], t2[9];
+ graphene_point_t p[9];
+ int n;
+
+ graphene_point_init (&p1[0], 333, 78);
+ graphene_point_init (&p1[1], 415, 78);
+ graphene_point_init (&p1[2], 463, 131);
+ graphene_point_init (&p1[3], 463, 223);
+
+ graphene_point_init (&p2[0], 520, 476);
+ graphene_point_init (&p2[1], 502, 418);
+
+ gsk_curve_init (&c1, gsk_pathop_encode (GSK_PATH_CURVE, p1));
+ gsk_curve_init (&c2, gsk_pathop_encode (GSK_PATH_LINE, p2));
+
+ n = gsk_curve_intersect (&c1, &c2, t1, t2, p, 1);
+
+ g_assert_cmpint (n, ==, 0);
+}
+
static void
test_curve_curve_intersection (void)
{
@@ -662,6 +687,7 @@ main (int argc, char *argv[])
g_test_add_func ("/curve/decompose-curve", test_curve_decompose_curve);
g_test_add_func ("/curve/intersection/line-line", test_line_line_intersection);
g_test_add_func ("/curve/intersection/line-curve", test_line_curve_intersection);
+ g_test_add_func ("/curve/intersection/line-curve-none", test_line_curve_none_intersection);
g_test_add_func ("/curve/intersection/curve-curve", test_curve_curve_intersection);
g_test_add_func ("/curve/intersection/curve-curve-max", test_curve_curve_max_intersection);
g_test_add_func ("/curve/intersection/horizontal-line", test_curve_intersection_horizontal_line);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]