Fix rounding bug and improve arc discretization #49
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.
Fix #24. Also use the improved
circular_arc
method to renderTurn
s with circular arcs—since the curvature is constant and known, we can easily discretize to a tolerance using a simple formula without resorting to adaptive methods.Some notes:
adapted_grid
and tolerance in the sense ofatol
's "max distance between polygon and exact edge" is complicated. One might guess thatgrid_step = 1.0μm, max_change=5°
means that we start with a grid step of 1 micron (true) and refine until the max change in direction between steps of the underlying curve falls below 5 degrees (we get much smaller change depending on the radius but it's hard to follow why, and I'm not sure whether or not that's a bug). In any case, for tight curves, the distance from the true curve can be significantly more than 1nm, and for large radius of curvature, far more points are used than are necessary for 1nm tolerance (1μm steps give 1nm tolerance at 125μm radius, and tighter tolerance for larger radii).Turn
with the same angular step, such that the curve with the largest radius meetsatol
(and thus so do all curves with smaller radii). An alternative implementation could discretize the inside edge of a trace with fewer points than the outside edge. There's no official promise that the curves have the same number of points, but I think it's nice that the width of the discretized trace is constant. All other curves are discretized according to theTurn
without regard to the style, so they also have the same number of points on each curve. Eventually, we may want to simplify path rendering by first converting toCurvilinearPolygon
s usingOffsetSegment
s, then discretizing the offset segments. In that case, we could preserve this behavior by going back to choosing the discretization according to the underlyingTurn
curve, although then tolerance might not be met on outer offset curves.