Fix point disappearing during curve merging #61
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.
Overview
This commit fixes an issue where a point suddenly disappears during merging.
The problem was caused by an off-by-one error in the clipping coordinates.
The problem was fixed by including t = 1 when looking for a t-value during curve fitting in
_tValueForPointOnCubicCurve
.Details
Test file: thin.ufo.zip
Here's the outline before merging.
And the output after merging.
Looking at the merge point in detail, there was an offset by 1 (an error of 1 / 2 ^ 17).
One of the points, the point on 47, was removed by
pyclipper
so the output contour was smooth.However this difference caused the curve to go into the condition on line 806 in
OutputContour.reCurveSubSegments
where it thinks the end offlatSegment
is different frominputSegment.flat[0]
.In that condition, we search for the tValue for a point 1 (in 2^17) off the end point. The solver from
inputSegment.tValueForPoint(searchPoint)
returns 1.0 which gets filtered out by line 968:The result of this is
tValues = []
and in turn this skips the condition on line 853 thus a point gets omitted/deleted.Allowing the t-value solver to include the end point fixes the issue.