Skip to content

Commit

Permalink
Replace linelike intersections with line-curve/line-line tests, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Nov 27, 2023
1 parent 37abe74 commit 25e60d5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Lib/fontTools/misc/bezierTools.py
Expand Up @@ -1370,6 +1370,11 @@ def midpoint(r):
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.
Expand All @@ -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])
Expand Down

0 comments on commit 25e60d5

Please sign in to comment.