Skip to content

Commit

Permalink
Handle more degenerate cases
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Dec 15, 2023
1 parent 8695d19 commit 42d8e2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Lib/fontTools/misc/bezierTools.py
Expand Up @@ -1184,8 +1184,11 @@ def lineLineIntersections(s1, e1, s2, e2):
if math.isclose(s1x, e1x) and math.isclose(s1y, e1y): # Line segment is tiny
return []
if math.isclose(e1x, s1x):
if math.isclose(e2x, s2x) and math.isclose(s1y, s2y):
return [Intersection(pt=(s1x, s1y), t1=0, t2=0)]
if math.isclose(e2x, s2x): # Same start
if math.isclose(s1y, s2y):
return [Intersection(pt=(s1x, s1y), t1=0, t2=0)]
# Degenerate coincident case
return []
x = s1x
slope34 = (e2y - s2y) / (e2x - s2x)
y = slope34 * (x - s2x) + s2y
Expand All @@ -1196,8 +1199,11 @@ def lineLineIntersections(s1, e1, s2, e2):
)
]
if math.isclose(s2x, e2x):
if math.isclose(s1x, e1x) and math.isclose(e1y, e2y):
return [Intersection(pt=(e1x, e1y), t1=1, t2=1)]
if math.isclose(s1x, e1x):
if math.isclose(e1y, e2y): # Same end
return [Intersection(pt=(e1x, e1y), t1=1, t2=1)]

Check warning on line 1204 in Lib/fontTools/misc/bezierTools.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/misc/bezierTools.py#L1204

Added line #L1204 was not covered by tests
# Degenerate coincident case
return []

Check warning on line 1206 in Lib/fontTools/misc/bezierTools.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/misc/bezierTools.py#L1206

Added line #L1206 was not covered by tests
x = s2x
slope12 = (e1y - s1y) / (e1x - s1x)
y = slope12 * (x - s1x) + s1y
Expand Down
3 changes: 3 additions & 0 deletions Tests/misc/bezierTools_test.py
Expand Up @@ -205,3 +205,6 @@ def test_intersections_samestart():
seg2 = [(250, 1000), (250, 400)]
pt = lineLineIntersections(*seg1, *seg2)[0][0]
assert pt == (250.0, 1000.0)
seg3 = [(250, 810), (250, 500)]
assert lineLineIntersections(*seg1, *seg3) == []

0 comments on commit 42d8e2f

Please sign in to comment.