# 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 Delauney triangulation, through the really fast delaunator crate, and then extracting its dual Voronoi diagram.

Both the Voronoi graph and its dual Delauney 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.vertices().collect::<Vec<&Point>>())
});

// or proble cells individually
let my_cell = my_voronoi.cell(1);
println!("Second cell has site {:?}, voronoi vertices {:?} and delauney triangles {:?}",
my_cell.site_position(),
my_cell.vertices().collect::<Vec<&Point>>(),
my_cell.triangles().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]);```

## Structs

 BoundingBox Defines a rectangular bounding box. Point Represents a 2D point in the input vector. Voronoi The dual Delauney-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.