diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index df072ff..af43d7f 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -138,33 +138,15 @@ impl eframe::App for App { let transform = egui::emath::RectTransform::from_to(self.from_rect, viewport_rect); let mut painter = Painter::new(ui, transform); - let dot_shape = Shape::Dot(DotShape { - c: Circle { - pos: [50.0, 100.0].into(), - r: 10.0, - }, - }); - - let seg_shape = Shape::Seg(SegShape { - from: [200.0, 25.0].into(), - to: [300.0, 300.0].into(), - width: 5.0, - }); - - let bend_shape = Shape::Bend(BendShape { - from: [100.0, 100.0].into(), - to: [160.0, 160.0].into(), - c: Circle { - pos: [130.0, 130.0].into(), - r: 30.0, - }, - width: 12.0, - }); - if let Some(layout) = &self.layout { - for node in layout.nodes() { + for node in layout.layer_nodes(1) { let shape = node.primitive(layout).shape(); - painter.paint_shape(&shape, egui::Color32::from_rgb(255, 0, 0)); + painter.paint_shape(&shape, egui::Color32::from_rgb(52, 52, 200)); + } + + for node in layout.layer_nodes(0) { + let shape = node.primitive(layout).shape(); + painter.paint_shape(&shape, egui::Color32::from_rgb(200, 52, 52)); } } }) diff --git a/src/bin/topola-sdl2-demo/main.rs b/src/bin/topola-sdl2-demo/main.rs index 61907f5..62050be 100644 --- a/src/bin/topola-sdl2-demo/main.rs +++ b/src/bin/topola-sdl2-demo/main.rs @@ -394,7 +394,18 @@ fn render_times( }; //let result = panic::catch_unwind(|| { - for node in layout.nodes() { + for node in layout.layer_nodes(1) { + let color = if highlighteds.contains(&node) { + ColorU::new(100, 100, 255, 255) + } else { + ColorU::new(52, 52, 200, 255) + }; + + let shape = node.primitive(layout).shape(); + painter.paint_shape(&shape, color, view.zoom); + } + + for node in layout.layer_nodes(0) { let color = if highlighteds.contains(&node) { ColorU::new(255, 100, 100, 255) } else { diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 289adde..7e400b4 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -2,7 +2,7 @@ use contracts::debug_ensures; use enum_dispatch::enum_dispatch; use geo::Point; -use rstar::RTreeObject; +use rstar::{RTreeObject, AABB}; use thiserror::Error; use super::graph::GetLayer; @@ -630,20 +630,19 @@ impl Layout { .map(|wrapper| wrapper.data) } - pub fn shapes(&self) -> impl Iterator + '_ { - self.nodes().map(|node| node.primitive(self).shape()) + pub fn layer_nodes(&self, layer: u64) -> impl Iterator + '_ { + self.geometry_with_rtree + .rtree() + .locate_in_envelope_intersecting(&AABB::from_corners( + [-f64::INFINITY, -f64::INFINITY, layer as f64], + [f64::INFINITY, f64::INFINITY, layer as f64], + )) + .map(|wrapper| wrapper.data) } pub fn node_count(&self) -> usize { self.geometry_with_rtree.graph().node_count() } - - fn node_indices(&self) -> impl Iterator + '_ { - self.geometry_with_rtree - .rtree() - .iter() - .map(|wrapper| wrapper.data) - } } impl Layout {