Crate voronoice

Source
Expand description

§voronoice

This crate provides a nice and fast way to construct 2D Voronoi diagrams from a set of sites. It builds Voronoi diagrams by first obtaining its Delaunay triangulation, through the really fast delaunator crate, and then extracting its dual Voronoi diagram.

Both the Voronoi graph and its dual Delaunay graph are exposed through the Voronoi type.

§Example

 use voronoice::*;

 // voronoi sites
 let sites = vec![
     Point { x: 0.0, y: 0.0 }, Point { x: 1.0, y: 0.0 }, Point { x: 0.0, y: 1.0 }
 ];

 // builds a voronoi diagram from the set of sites above, bounded by a square of size 4
 let my_voronoi = VoronoiBuilder::default()
     .set_sites(sites)
     .set_bounding_box(BoundingBox::new_centered_square(4.0))
     .set_lloyd_relaxation_iterations(5)
     .build()
     .unwrap();

 // inspect cells through iterators
 my_voronoi.iter_cells().for_each(|cell| {
     println!("Vertices of cell: {:?}", cell.iter_vertices().collect::<Vec<&Point>>())
 });

 // or probe cells individually
 let my_cell = my_voronoi.cell(1);
 println!("Second cell has site {:?}, voronoi vertices {:?} and delaunay triangles {:?}",
     my_cell.site_position(),
     my_cell.iter_vertices().collect::<Vec<&Point>>(),
     my_cell.triangles().iter().collect::<Vec<&usize>>());

 // or, for graphical applications, that benefit from index buffers
 // you can access the raw, indexed data
 let all_voronoi_cell_vertices = my_voronoi.vertices();
 let indexed_voronoi_cells = my_voronoi.cells();
 println!("The first vertex position for the first voronoi cell is at {:?}",
     all_voronoi_cell_vertices[indexed_voronoi_cells[0][0]]);

Structs§

BoundingBox
Defines a rectangular bounding box.
CellPathIterator
Iterator that produces a path between two points in the Voronoi diagram that uses a greed approach to minimizes a cost function.
NeighborSiteIterator
Iterates over sites that are adjacent in the voronoi diagram.
Point
Represents a 2D point in the input vector.
TopologicalNeighborSiteIterator
Iterates over sites that are topologically adjacent.
Voronoi
The dual Delaunay-Voronoi graph.
VoronoiBuilder
Provides a convenient way to construct a Voronoi diagram.
VoronoiCell
Represents a Voronoi cell. This is an ergonomic way to access cell details.

Enums§

ClipBehavior
Defines how Voronoi generation will handle clipping of Voronoi cell edges within the bounding box.