-
Notifications
You must be signed in to change notification settings - Fork 6
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
Clipping Voronoi tessellations to arbitrary bounding boxes #76
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 93.48% 94.08% +0.60%
==========================================
Files 73 75 +2
Lines 5446 5545 +99
==========================================
+ Hits 5091 5217 +126
+ Misses 355 328 -27
☔ View full report in Codecov by Sentry. |
Returns nothing for |
The issue was with my incorrect polygon-in-polygon predicate. |
After countless failed attempts at a generalised Sutherland-Hodgman algorithm, this PR introduces clipping Voronoi tessellations to arbitrary bounding boxes. In particular,
get_polygon_coordinates
now allows for a bounding box that doesn't necessarily contain all circumcenters/generators. This is especially needed for MakieOrg/Makie.jl#3102.For finite polygons: The Sutherland-Hodgman algorithm is used.
For unbounded polygons: The polygon is truncated so that the unbounded edges can be connected such that the line connecting them is entirely outside of the provided bounding box, using the Liang-Barsky algorithm to detect box-line segment intersections, and then the resulting finite polygon is clipped using the Sutherland-Hodgman algorithm.
This PR also:
get_polygon_coordinates
inside Voronoi docstrings.Note that clipping, i.e.
voronoi(tri, true)
, will still only clip to the convex hull. It would be possible to add that, e.g. add a kwargclip_to_hull
or something, together with a bounding box kwarg if!clip_to_hull
, but I do not see the need for that since only the rectangular case is simple to do for each polygon in isolation. PRs are welcome if you do want this.