Skip to content
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

Merged
merged 18 commits into from
Aug 10, 2023

Conversation

DanielVandH
Copy link
Member

@DanielVandH DanielVandH commented Aug 10, 2023

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:

  • Adds Tuples to the point interface.
  • Adds the option to give default polygon bounds that don't include all the polygon vertices.
  • Better documentation for using 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 kwarg clip_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.

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 95.08% and project coverage change: +0.60% 🎉

Comparison is base (dc18f8b) 93.48% compared to head (847863a) 94.08%.

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     
Files Changed Coverage Δ
src/DelaunayTriangulation.jl 100.00% <ø> (ø)
src/geometry_utils/polygons.jl 100.00% <ø> (ø)
src/voronoi/main.jl 100.00% <ø> (ø)
src/voronoi/coordinates.jl 91.58% <91.58%> (ø)
src/geometry_utils/sutherland_hodgman.jl 94.87% <94.87%> (ø)
src/data_structures/voronoi/voronoi.jl 91.89% <100.00%> (+11.57%) ⬆️
src/geometry_utils/intersections.jl 98.06% <100.00%> (+0.97%) ⬆️
src/interfaces/points.jl 94.38% <100.00%> (ø)
src/predicates/general.jl 98.17% <100.00%> (+0.08%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanielVandH
Copy link
Member Author

Returns nothing for points = [(0.0, 1.0), (-1.0, 2.0), (-2.0, -1.0)] and bb = (-1.0, 0.0, -1.0, 2.0)

@DanielVandH
Copy link
Member Author

Returns nothing for points = [(0.0, 1.0), (-1.0, 2.0), (-2.0, -1.0)] and bb = (-1.0, 0.0, -1.0, 2.0)

The issue was with my incorrect polygon-in-polygon predicate.

@DanielVandH DanielVandH merged commit 7ddb44a into main Aug 10, 2023
8 checks passed
@DanielVandH DanielVandH deleted the rect-clipping branch August 11, 2023 11:25
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.

1 participant