Skip to content

Fix rounding bug and improve arc discretization #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged

Conversation

gpeairs
Copy link
Member

@gpeairs gpeairs commented Apr 23, 2025

Fix #24. Also use the improved circular_arc method to render Turns 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:

  • The relationship between adapted_grid and tolerance in the sense of atol's "max distance between polygon and exact edge" is complicated. One might guess that grid_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).
  • This discretizes the circular arcs along a styled Turn with the same angular step, such that the curve with the largest radius meets atol (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 the Turn 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 to CurvilinearPolygons using OffsetSegments, then discretizing the offset segments. In that case, we could preserve this behavior by going back to choosing the discretization according to the underlying Turn curve, although then tolerance might not be met on outer offset curves.

Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@gpeairs
Copy link
Member Author

gpeairs commented Apr 23, 2025

Even without rigorous benchmarking, we can see that this is a significant speedup over using adapted_grid for Turns. On DemoQPU17, we previously had (first execution, subsequent execution):

Rendering to polygons: 5.758117 seconds (10.51 M allocations: 615.602 MiB, 8.76% gc time, 88.12% compilation time)
Rendering to polygons: 0.654979 seconds (5.79 M allocations: 299.579 MiB, 4.17% gc time)

This PR takes off ~90% of the rendering time after compilation:

Rendering to polygons: 3.857135 seconds (4.37 M allocations: 317.261 MiB, 1.42% gc time, 97.37% compilation time)
Rendering to polygons: 0.077314 seconds (502.31 k allocations: 57.515 MiB, 5.17% gc time)

@gpeairs gpeairs changed the title Fix rounding bug Fix rounding bug and improve arc discretization Apr 23, 2025
@gpeairs gpeairs merged commit fa45ede into main Apr 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rounding occasionally fails when radius equals min_side_len
1 participant