Skip to content

Commit

Permalink
Merge pull request #1058 from cmyr/erase-corners-two-segments
Browse files Browse the repository at this point in the history
Fix edge case in open corner erasure logic
  • Loading branch information
anthrotype authored Jan 21, 2025
2 parents 74c6324 + e03ad3d commit ed39aa3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/glyphsLib/filters/eraseOpenCorners.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def endPath(self):
)
logger.debug("Segments: %s", segs)

while ix < len(segs):
# we need at least two segments to find a corner
while len(segs) > 2 and ix < len(segs):
next_ix = (ix + 1) % len(segs)

# Am I a line segment?
Expand Down
18 changes: 18 additions & 0 deletions tests/eraseOpenCorners_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@
("closePath", ()),
],
},
# a pathological case, where a curve has two segments.
# the naive logic treats this as an open corner, treating the
# same curve segment as the 'prev' and 'next'.
{
"name": "justTwoSegments",
"width": 600,
"outline": [
("moveTo", ((10, 10),)),
("lineTo", ((13, 10),)),
("curveTo", ((11, 8), (11, 8), (10, 10))),
("closePath", ()),
],
},
]
}
]
Expand Down Expand Up @@ -321,6 +334,11 @@ def test_large_crossing(font):
assert len(newcontour) == 3


def test_only_two_segments(font):
philter = EraseOpenCornersFilter(include={"justTwoSegments"})
assert not philter(font)


def structure(contour):
return [x.segmentType for x in contour]

Expand Down

0 comments on commit ed39aa3

Please sign in to comment.