-
Notifications
You must be signed in to change notification settings - Fork 234
Add Voronoi methods #1487
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
base: split_delaunay_trait
Are you sure you want to change the base?
Add Voronoi methods #1487
Conversation
|
Some example output. I haven't written a benchmark, but single-core perf on my M2 is around 5.5 seconds to produce a clipped Voronoi diagram from 2693630 input vertices. That drops to around 1.3 seconds (including the snapping step) if you use a tolerance of |
85e0879 to
328155c
Compare
66eb15a to
5604e7b
Compare
| // - `CoordsIter` trait for vertex iteration | ||
| // The `line_intersection` and `Euclidean::distance` functions from geo are already used here. | ||
| // | ||
| // TODO: Cell clipping currently uses BooleanOps intersection. Alternative approaches that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are possible TODOs for follow-up work; I'm fairly happy with the existing clipping mechanisms, which took a long time to get into their current state. I suspect they could be further simplified if we could clip LineString geometries using BooleanOps, but I don't want to hold this up while we think through that.
| Ok(raw_cells | ||
| .into_iter() | ||
| .flat_map(|cell| { | ||
| // Skip intersection if cell is entirely within clip bounds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets us a 40-45 % speedup (inspired by JTS: https://github.com/locationtech/jts/blob/7b79342eb04dc572a02b6520c7c2d2e58b54ae86/modules/core/src/main/java/org/locationtech/jts/triangulate/VoronoiDiagramBuilder.java#L184)
Adds the Voronoi trait with methods to compute Voronoi diagrams: - voronoi_edges(): Returns line segments from unconstrained Delaunay triangulation - voronoi_edges_with_params(): Same with configurable tolerance and clipping - voronoi_cells(): Returns Vec<Polygon<T>> with cells clipped to padded bounding box - voronoi_cells_with_params(): Same with configurable tolerance and clipping Configuration is via VoronoiParams builder: - .tolerance(T): Snap nearby points before triangulation - .clip(VoronoiClip): Control clipping behaviour - Padded: 50% padding around input bbox (default, matches PostGIS) - Envelope: Clip to exact input bounding box - Polygon(&Polygon<T>): Clip to custom boundary Cells are constructed by iterating over Spade's voronoi_faces() and converting vertices (circumcenters for inner, bounding box intersections for outer) into polygon rings. Signed-off-by: Stephan Hügel <[email protected]>

Adds the Voronoi trait with methods to compute Voronoi diagrams:
Configuration is via VoronoiParams builder:
Cells are constructed by iterating over Spade's voronoi_faces() and converting vertices (circumcenters for inner, bounding box intersections for outer) into polygon rings.
CHANGES.mdif knowledge of this change could be valuable to users.Depends on #1486, please review / merge that first.