use voronator::{VoronoiDiagram, delaunator::Point};
use rand::{prelude::*, distributions::Uniform};
use plotpy::{Curve, Plot};
use std::time::Instant;
fn main() {
let mut rng = thread_rng();
let range1 = Uniform::new(0.0, 100.0);
let range2 = Uniform::new(0.0, 100.0);
let points: Vec<(f64, f64)> = (0..10000)
.map(|_| (rng.sample(&range1), rng.sample(&range2)))
.collect();
let now = Instant::now();
let diagram = VoronoiDiagram::<Point>::from_tuple(&(0.0, 0.0), &(100.0, 100.0), &points).unwrap();
let elapsed = now.elapsed();
println!("{:.2?} elapsed time", elapsed);
let mut plot = Plot::new();
for cell in diagram.cells() {
let mut p_x: Vec<f32> = cell.points().into_iter().map(|x| x.x as f32).collect();
let mut p_y: Vec<f32> = cell.points().into_iter().map(|x| x.y as f32).collect();
p_x.push(p_x[0]);
p_y.push(p_y[0]);
let mut curve = Curve::new();
curve.set_line_width(0.5);
curve.draw(&p_x, &p_y);
plot.add(&curve);
}
plot.save("plot.svg").unwrap();
}