typemytype / booleanOperations

Boolean operations on paths
MIT License
39 stars 18 forks source link

Fix point disappearing during curve merging #61

Open mental-design opened 3 years ago

mental-design commented 3 years ago

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.

Screen Shot 2021-02-05 at 3 35 32 PM

And the output after merging.

Screen Shot 2021-02-05 at 3 37 19 PM

Looking at the merge point in detail, there was an offset by 1 (an error of 1 / 2 ^ 17). download

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 of flatSegment is different from inputSegment.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:

solutions = [t for t in solutions if 0 <= t < 1]

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.

Screen Shot 2021-02-05 at 3 54 37 PM