linelike intersections (#3353)
* Replace linelike intersections with line-curve/line-line tests, fixes #3352 * Tests for #3352
This commit is contained in:
parent
5ce71286ac
commit
b5ddc99fb9
@ -1370,6 +1370,11 @@ def _curve_curve_intersections_t(
|
||||
return unique_values
|
||||
|
||||
|
||||
def _is_linelike(segment):
|
||||
maybeline = _alignment_transformation(segment).transformPoints(segment)
|
||||
return all(math.isclose(p[1], 0.0) for p in maybeline)
|
||||
|
||||
|
||||
def curveCurveIntersections(curve1, curve2):
|
||||
"""Finds intersections between a curve and a curve.
|
||||
|
||||
@ -1391,6 +1396,17 @@ def curveCurveIntersections(curve1, curve2):
|
||||
>>> intersections[0].pt
|
||||
(81.7831487395506, 109.88904552375288)
|
||||
"""
|
||||
if _is_linelike(curve1):
|
||||
line1 = curve1[0], curve1[-1]
|
||||
if _is_linelike(curve2):
|
||||
line2 = curve2[0], curve2[-1]
|
||||
return lineLineIntersections(*line1, *line2)
|
||||
else:
|
||||
return curveLineIntersections(curve2, line1)
|
||||
elif _is_linelike(curve2):
|
||||
line2 = curve2[0], curve2[-1]
|
||||
return curveLineIntersections(curve1, line2)
|
||||
|
||||
intersection_ts = _curve_curve_intersections_t(curve1, curve2)
|
||||
return [
|
||||
Intersection(pt=segmentPointAtT(curve1, ts[0]), t1=ts[0], t2=ts[1])
|
||||
|
@ -4,6 +4,7 @@ from fontTools.misc.bezierTools import (
|
||||
calcQuadraticArcLength,
|
||||
calcCubicBounds,
|
||||
curveLineIntersections,
|
||||
curveCurveIntersections,
|
||||
segmentPointAtT,
|
||||
splitLine,
|
||||
splitQuadratic,
|
||||
@ -189,3 +190,10 @@ def test_calcQuadraticArcLength():
|
||||
assert calcQuadraticArcLength(
|
||||
(210, 333), (289, 333), (326.5, 290.5)
|
||||
) == pytest.approx(127.9225)
|
||||
|
||||
|
||||
def test_intersections_linelike():
|
||||
seg1 = [(0.0, 0.0), (0.0, 0.25), (0.0, 0.75), (0.0, 1.0)]
|
||||
seg2 = [(0.0, 0.5), (0.25, 0.5), (0.75, 0.5), (1.0, 0.5)]
|
||||
pt = curveCurveIntersections(seg1, seg2)[0][0]
|
||||
assert pt == (0.0, 0.5)
|
||||
|
Loading…
x
Reference in New Issue
Block a user