voronator

Crates.iovoronator
lib.rsvoronator
version0.2.1
sourcesrc
created_at2020-06-30 04:13:35.031492
updated_at2023-02-14 18:41:41.962103
descriptionImplements the Voronoi diagram construction as a dual of the Delaunay triangulation for a set of points and the construction of a centroidal tesselation of a Delaunay triangulation.
homepage
repositoryhttps://github.com/fesoliveira014/voronator-rs
max_upload_size
id259626
size331,568
Felipe Santos (fesoliveira014)

documentation

README

voronator

Port of the d3-delaunay and delaunator libraries in Rust.

This package implements the Voronoi diagram construction as a dual of the Delaunay triangulation for a set of points. It also implements the construction of a centroidal tesselation of a Delaunay triangulation, inspired by Red Blob Games.

Examples

extern crate voronator;
extern crate rand;

use voronator::VoronoiDiagram;
use voronator::delaunator::Point;
use rand::prelude::*;
use rand::distributions::Uniform;

fn main() {
    let mut rng = rand::thread_rng();
    let range1 = Uniform::new(0., 100.);
    let range2 = Uniform::new(0., 100.);
    let mut points: Vec<(f64, f64)> = (0..10)
        .map(|_| (rng.sample(&range1), rng.sample(&range2)))
        .collect();

    let diagram = VoronoiDiagram::<Point>::from_tuple(&(0., 0.), &(100., 100.), &points).unwrap();
    
    for cell in diagram.cells() {
        let p: Vec<(f32, f32)> = cell.points().into_iter()
            .map(|x| (x.x as f32, x.y as f32))
            .collect();
        
        println!("{:?}", p);
    }
}

Possible output:

Possible output

Commit count: 38

cargo fmt