#delaunay-triangulation #voronoi-diagram #delaunay #diagram #voronoi #graphics

voronator

Implements 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

4 releases

0.2.1 Feb 14, 2023
0.2.0 Oct 13, 2021
0.1.2 Oct 12, 2021
0.1.0 Jun 30, 2020

#405 in Algorithms

Download history 464/week @ 2024-01-03 769/week @ 2024-01-10 1153/week @ 2024-01-17 456/week @ 2024-01-24 1637/week @ 2024-01-31 1183/week @ 2024-02-07 973/week @ 2024-02-14 1163/week @ 2024-02-21 520/week @ 2024-02-28 955/week @ 2024-03-06 976/week @ 2024-03-13 486/week @ 2024-03-20 783/week @ 2024-03-27 576/week @ 2024-04-03 1178/week @ 2024-04-10 537/week @ 2024-04-17

3,120 downloads per month
Used in 3 crates

Custom license

155KB
843 lines

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

Dependencies