1use voronator::{VoronoiDiagram, delaunator::Point};
2use rand::{prelude::*, distributions::Uniform};
3use plotpy::{Curve, Plot};
4use std::time::Instant;
5
6fn main() {
7
8 let mut rng = thread_rng();
9 let range1 = Uniform::new(0.0, 100.0);
10 let range2 = Uniform::new(0.0, 100.0);
11 let points: Vec<(f64, f64)> = (0..10000)
12 .map(|_| (rng.sample(&range1), rng.sample(&range2)))
13 .collect();
14
15 let now = Instant::now();
16
17 let diagram = VoronoiDiagram::<Point>::from_tuple(&(0.0, 0.0), &(100.0, 100.0), &points).unwrap();
18
19 let elapsed = now.elapsed();
20
21 println!("{:.2?} elapsed time", elapsed);
22
23 let mut plot = Plot::new();
24
25 for cell in diagram.cells() {
26 let mut p_x: Vec<f32> = cell.points().into_iter().map(|x| x.x as f32).collect();
27 let mut p_y: Vec<f32> = cell.points().into_iter().map(|x| x.y as f32).collect();
28
29 p_x.push(p_x[0]);
30 p_y.push(p_y[0]);
31
32 let mut curve = Curve::new();
33 curve.set_line_width(0.5);
34 curve.draw(&p_x, &p_y);
35 plot.add(&curve);
36 }
37
38 plot.save("plot.svg").unwrap();
39}