From 95694ac931706a8191d7552f054e2b41092e9da6 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sat, 14 Mar 2026 12:37:55 +0100 Subject: [PATCH] Display bboxes of primitives --- topola-egui/src/{displayer.rs => display.rs} | 89 +++++++++++++++++++- topola-egui/src/main.rs | 2 +- topola-egui/src/viewport.rs | 4 +- topola/src/layout.rs | 4 + 4 files changed, 94 insertions(+), 5 deletions(-) rename topola-egui/src/{displayer.rs => display.rs} (71%) diff --git a/topola-egui/src/displayer.rs b/topola-egui/src/display.rs similarity index 71% rename from topola-egui/src/displayer.rs rename to topola-egui/src/display.rs index de8d437..138ec85 100644 --- a/topola-egui/src/displayer.rs +++ b/topola-egui/src/display.rs @@ -5,9 +5,9 @@ use crate::{viewport::Viewport, workspace::Workspace}; use topola::{Joint, Polygon, Segment, SegmentId}; -pub struct Displayer {} +pub struct Display {} -impl Displayer { +impl Display { pub fn new() -> Self { Self {} } @@ -21,6 +21,7 @@ impl Displayer { workspace: &Workspace, ) { self.display_layout(ctx, ui, /*menu_bar,*/ viewport, workspace); + self.display_bboxes(ctx, ui, viewport, workspace); self.display_navmeshes(ctx, ui, viewport, workspace); } @@ -176,6 +177,90 @@ impl Displayer { )); } + fn display_bboxes( + &mut self, + ctx: &egui::Context, + ui: &egui::Ui, + viewport: &Viewport, + workspace: &Workspace, + ) { + for (_, joint) in workspace + .navmesher_board + .board() + .layout() + .joints() + .collection() + { + if workspace.appearance_panel.visible[joint.layer] { + ui.painter().rect_stroke( + egui::Rect { + min: egui::pos2( + joint.bbox().lower()[0] as f32, + joint.bbox().lower()[1] as f32, + ), + max: egui::pos2( + joint.bbox().upper()[0] as f32, + joint.bbox().upper()[1] as f32, + ), + }, + egui::CornerRadius::ZERO, + egui::Stroke::new(5.0, egui::Color32::GRAY), + egui::StrokeKind::Middle, + ); + } + } + + for (i, segment) in workspace + .navmesher_board + .board() + .layout() + .segments() + .collection() + { + if workspace.appearance_panel.visible[segment.layer] { + let endpoints = workspace + .navmesher_board + .board() + .layout() + .segment_endpoints(SegmentId::new(i)); + + ui.painter().rect_stroke( + egui::Rect::from_two_pos( + egui::pos2(endpoints[0][0] as f32, endpoints[0][1] as f32), + egui::pos2(endpoints[1][0] as f32, endpoints[1][1] as f32), + ), + egui::CornerRadius::ZERO, + egui::Stroke::new(5.0, egui::Color32::GRAY), + egui::StrokeKind::Middle, + ); + } + } + + // TODO: vias. + + for (i, polygon) in workspace + .navmesher_board + .board() + .layout() + .polygons() + .collection() + { + if workspace.appearance_panel.visible[polygon.layer] { + let bbox = polygon.bbox(); + + ui.painter().rect_stroke( + egui::Rect { + min: egui::pos2(bbox.lower()[0] as f32, bbox.lower()[1] as f32), + max: egui::pos2(bbox.upper()[0] as f32, bbox.upper()[1] as f32), + }, + egui::CornerRadius::ZERO, + egui::Stroke::new(5.0, egui::Color32::GRAY), + egui::StrokeKind::Middle, + ); + } + } + } + fn display_navmeshes( &mut self, ctx: &egui::Context, diff --git a/topola-egui/src/main.rs b/topola-egui/src/main.rs index 96eba3e..ecfd1b8 100644 --- a/topola-egui/src/main.rs +++ b/topola-egui/src/main.rs @@ -8,7 +8,7 @@ mod action; mod actions; mod app; mod appearance_panel; -mod displayer; +mod display; mod menu_bar; mod translator; mod viewport; diff --git a/topola-egui/src/viewport.rs b/topola-egui/src/viewport.rs index 37f1aab..fe0d2a1 100644 --- a/topola-egui/src/viewport.rs +++ b/topola-egui/src/viewport.rs @@ -4,7 +4,7 @@ use egui::Pos2; -use crate::{displayer::Displayer, workspace::Workspace}; +use crate::{display::Display, workspace::Workspace}; pub struct Viewport { pub scene_rect: egui::Rect, @@ -29,7 +29,7 @@ impl Viewport { .zoom_range(0.00001..=10000.0) .show(ui, &mut scene_rect, |ui| { if let Some(ref workspace) = workspace { - let mut displayer = Displayer::new(); + let mut displayer = Display::new(); displayer.update(ctx, ui, &self, workspace); } }); diff --git a/topola/src/layout.rs b/topola/src/layout.rs index f6af321..6ba7cb5 100644 --- a/topola/src/layout.rs +++ b/topola/src/layout.rs @@ -213,6 +213,8 @@ impl ApplyDelta for Layout { let polygons_delta = Delta::with_removed_inserted(removed.polygons, inserted.polygons); self.polygons.apply_delta(&polygons_delta); + + // TODO R-trees. } } @@ -223,6 +225,8 @@ impl FlushDelta for Layout { let (removed_vias, inserted_vias) = self.vias.flush_delta().dissolve(); let (removed_polygons, inserted_polygons) = self.polygons.flush_delta().dissolve(); + // TODO R-trees. + Delta::with_removed_inserted( LayoutHalfDelta { joints: removed_joints,