Add voronoi rendering

This commit is contained in:
Emi Simpson 2021-11-16 19:24:50 -05:00
parent 88986e026c
commit f7be06caa4
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -60,7 +60,8 @@ async fn main() {
}
}
dd.update();
dd.draw();
//dd.draw_delaunay();
dd.draw_voronoi();
next_frame().await;
}
}
@ -442,7 +443,7 @@ impl fmt::Debug for Triangle {
}
impl DelaunayDemo {
fn draw(&self) {
fn draw_delaunay(&self) {
clear_background(BG);
let mut highlight_segments = Vec::new();
for triangle in &self.triangles {
@ -487,6 +488,23 @@ impl DelaunayDemo {
}
}
fn draw_voronoi(&self) {
clear_background(BG);
for neighbors in self.adjacency.values() {
if let (Occupant(tri1), Friend(tri2)) = neighbors {
let (center1, _) = tri1.circumcenter();
let (center2, _) = tri2.circumcenter();
draw_line(
center1.x as f32,
center1.y as f32,
center2.x as f32,
center2.y as f32,
3.0, FG
);
}
}
}
fn update(&mut self) {
if self.poisoned {
return