From f7be06caa4525cbdfd6f39e3ac84a84a28a2d84a Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Tue, 16 Nov 2021 19:24:50 -0500 Subject: [PATCH] Add voronoi rendering --- src/main.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 01e23e6..288c055 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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