egui: show root bbox

Helpful for debugging geometrical transformations.
This commit is contained in:
Mikolaj Wielgus 2024-09-11 13:34:47 +02:00
parent 8c671e5a2c
commit 89717f2b6e
2 changed files with 22 additions and 10 deletions

View File

@ -1,4 +1,5 @@
use geo::{CoordsIter, Point, Polygon}; use geo::{CoordsIter, Point, Polygon};
use rstar::AABB;
use topola::{ use topola::{
geometry::primitive::{AccessPrimitiveShape, PrimitiveShape}, geometry::primitive::{AccessPrimitiveShape, PrimitiveShape},
math::{self, Circle}, math::{self, Circle},
@ -59,19 +60,22 @@ impl<'a> Painter<'a> {
self.ui.painter().add(epaint_shape); self.ui.painter().add(epaint_shape);
if self.paint_bboxes { if self.paint_bboxes {
let bbox = AccessPrimitiveShape::bbox(shape, 0.0); self.paint_bbox(AccessPrimitiveShape::bbox(shape, 0.0));
let rect = egui::epaint::Rect {
min: [bbox.lower()[0] as f32, -bbox.upper()[1] as f32].into(),
max: [bbox.upper()[0] as f32, -bbox.lower()[1] as f32].into(),
};
self.ui.painter().add(egui::Shape::rect_stroke(
self.transform.mul_rect(rect),
egui::Rounding::ZERO,
egui::Stroke::new(1.0, egui::Color32::GRAY),
));
} }
} }
pub fn paint_bbox(&mut self, bbox: AABB<[f64; 2]>) {
let rect = egui::epaint::Rect {
min: [bbox.lower()[0] as f32, -bbox.upper()[1] as f32].into(),
max: [bbox.upper()[0] as f32, -bbox.lower()[1] as f32].into(),
};
self.ui.painter().add(egui::Shape::rect_stroke(
self.transform * rect,
egui::Rounding::ZERO,
egui::Stroke::new(1.0, egui::Color32::GRAY),
));
}
pub fn paint_dot(&mut self, circle: Circle, color: egui::epaint::Color32) { pub fn paint_dot(&mut self, circle: Circle, color: egui::epaint::Color32) {
let shape = self.dot_shape(circle, color); let shape = self.dot_shape(circle, color);
self.ui.painter().add(shape); self.ui.painter().add(shape);

View File

@ -3,6 +3,7 @@ use petgraph::{
data::DataMap, data::DataMap,
visit::{EdgeRef, IntoEdgeReferences}, visit::{EdgeRef, IntoEdgeReferences},
}; };
use rstar::AABB;
use topola::{ use topola::{
autorouter::invoker::{ autorouter::invoker::{
Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles,
@ -209,6 +210,13 @@ impl Viewport {
} }
} }
if top.show_bboxes {
let root_bbox3d = board.layout().drawing().rtree().root().envelope();
let root_bbox = AABB::<[f64; 2]>::from_corners([root_bbox3d.lower()[0], root_bbox3d.lower()[1]].into(), [root_bbox3d.upper()[0], root_bbox3d.upper()[1]].into());
painter.paint_bbox(root_bbox);
}
if let Some(execute) = maybe_execute { if let Some(execute) = maybe_execute {
for ghost in execute.ghosts().iter() { for ghost in execute.ghosts().iter() {
painter.paint_primitive(&ghost, egui::Color32::from_rgb(75, 75, 150)); painter.paint_primitive(&ghost, egui::Color32::from_rgb(75, 75, 150));