Skip to content

Commit

Permalink
Merge pull request #1057 from cmyr/erase-corners-extra-segment
Browse files Browse the repository at this point in the history
Fix extra segment in eraseOpenCorners
  • Loading branch information
anthrotype authored Jan 21, 2025
2 parents ed39aa3 + 7edf757 commit b0fc3bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Lib/glyphsLib/filters/eraseOpenCorners.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def _operate(self, *points):
_qCurveTo = _curveTo = _lineTo = _qCurveToOne = _curveToOne = _operate

def closePath(self):
self.segments.append((self._getCurrentPoint(), self.segments[0][0]))
# only add a line segment here if the current first and last point aren't equal
if self._getCurrentPoint() != self.segments[0][0]:
self.segments.append((self._getCurrentPoint(), self.segments[0][0]))
self.is_closed = True
self.endPath()

Expand Down
21 changes: 21 additions & 0 deletions tests/eraseOpenCorners_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@
("closePath", ()),
],
},
{
"name": "curveAsLastSegment",
"width": 600,
"outline": [
("moveTo", ((100, 100),)),
("lineTo", ((10, 110),)),
("lineTo", ((15, 120),)),
("lineTo", ((60, 30),)),
("curveTo", ((80, 30), (100, 80), (100, 100))),
("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'.
Expand Down Expand Up @@ -334,6 +346,15 @@ def test_large_crossing(font):
assert len(newcontour) == 3


# there was an issue where we would generate an extra lineto if we erased
# corners on an outline where the last segment was a curve
def test_curve_as_last_segment(font):
philter = EraseOpenCornersFilter(include={"curveAsLastSegment"})
assert philter(font)
newcontour = font["curveAsLastSegment"][0]
assert structure(newcontour) == ["curve", "line", "line", None, None]


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

0 comments on commit b0fc3bc

Please sign in to comment.