Fix extra segment in eraseOpenCorners #1057
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the process of porting this functionality to Rust, I've run into a funny issue: in some cases, after erasing corners, the outline generated here contained an extra duplicate point at the beginning.
This error seems to be introduced only for contours where the last segment is a curve, and it is introduced early; even before we start processing, there is an extra segment in the segments list for these contours.
This patch addresses this by changing the logic of closePath to not emit a final line segment if it would be a duplicate, but I'm not totally confident that this is the right approach.
More detail: I believe that what is going on is an interaction between the logic for
closePath
ineraseOpenContours
and the logic in thePointToSegmentPen
that is writing into it. That pen is skipping the last LineTo segment in a closed path, trustingclosePath
to handle it; but by always adding a lineTo inclosePath
we're inserting extra segments when the last segment wasn't a lineTo.Another note: this patch is causing a new fontmake failure on one crater font, based on a rounding issue; there's a case where the start/end points are off by an epsilon in one master and not the other, which leads us to add the extra segment in one case. I'm not sure how best I should check this case.. should I strictly be looking for epsilon difference, or would it be okay to check if the points are equal after otround?