From eef69694fdd25ead67e018beff0c4a52d6b366a8 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 25 May 2026 22:42:04 +0200 Subject: [PATCH] Move location methods to new files --- topola-egui/src/viewport.rs | 2 +- topola/src/board/locate.rs | 52 +++++++++++++++++++++++++++++++++++++ topola/src/board/mod.rs | 1 + topola/src/board/select.rs | 22 ---------------- topola/src/layout/locate.rs | 49 ++++++++++++++++++++++++++++++++++ topola/src/layout/mod.rs | 40 +--------------------------- 6 files changed, 104 insertions(+), 62 deletions(-) create mode 100644 topola/src/board/locate.rs create mode 100644 topola/src/layout/locate.rs diff --git a/topola-egui/src/viewport.rs b/topola-egui/src/viewport.rs index 32da440..2ea7f37 100644 --- a/topola-egui/src/viewport.rs +++ b/topola-egui/src/viewport.rs @@ -58,7 +58,7 @@ impl Viewport { .router() .navmesher_board() .board() - .point_pin_selector( + .locate_pin_at_point( workspace.appearance_panel.active, Vector2::new( pointer_scene_pos.x as i64, diff --git a/topola/src/board/locate.rs b/topola/src/board/locate.rs new file mode 100644 index 0000000..b852b77 --- /dev/null +++ b/topola/src/board/locate.rs @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{ + Vector2, + board::Board, + layout::LayerId, + selections::{ComponentSelector, PinSelector}, +}; + +impl Board { + pub fn locate_component_at_point( + &self, + layer: LayerId, + point: Vector2, + ) -> Option { + if let Some(joint_id) = self.layout.locate_joints_at_point(layer, point).next() { + return self.joint_component_selector(joint_id); + } + + if let Some(segment_id) = self.layout.locate_segments_at_point(layer, point).next() { + return self.segment_component_selector(segment_id); + } + + // TODO: Vias. + + if let Some(polygon_id) = self.layout.locate_polygons_at_point(layer, point).next() { + return self.polygon_component_selector(polygon_id); + } + + None + } + + pub fn locate_pin_at_point(&self, layer: LayerId, point: Vector2) -> Option { + if let Some(joint_id) = self.layout.locate_joints_at_point(layer, point).next() { + return self.joint_pin_selector(joint_id); + } + + if let Some(segment_id) = self.layout.locate_segments_at_point(layer, point).next() { + return self.segment_pin_selector(segment_id); + } + + // TODO: Vias. + + if let Some(polygon_id) = self.layout.locate_polygons_at_point(layer, point).next() { + return self.polygon_pin_selector(polygon_id); + } + + None + } +} diff --git a/topola/src/board/mod.rs b/topola/src/board/mod.rs index 398c1b1..024b512 100644 --- a/topola/src/board/mod.rs +++ b/topola/src/board/mod.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 mod layer; +mod locate; mod resolve; mod select; pub mod selections; diff --git a/topola/src/board/select.rs b/topola/src/board/select.rs index a2b3e51..e25241c 100644 --- a/topola/src/board/select.rs +++ b/topola/src/board/select.rs @@ -108,28 +108,6 @@ impl Board { selection.0.contains(&selector) } - pub fn point_component_selector( - &self, - layer: LayerId, - point: Vector2, - ) -> Option { - if let Some(joint_id) = self.layout.locate_joints_at_point(layer, point).next() { - return self.joint_component_selector(joint_id); - } - - if let Some(segment_id) = self.layout.locate_segments_at_point(layer, point).next() { - return self.segment_component_selector(segment_id); - } - - // TODO: Vias. - - if let Some(polygon_id) = self.layout.locate_polygons_at_point(layer, point).next() { - return self.polygon_component_selector(polygon_id); - } - - None - } - pub fn joint_component_selector(&self, id: JointId) -> Option { let joint = self.layout.joint(id); diff --git a/topola/src/layout/locate.rs b/topola/src/layout/locate.rs new file mode 100644 index 0000000..b76ed86 --- /dev/null +++ b/topola/src/layout/locate.rs @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{ + Vector2, + layout::{LayerId, Layout}, + primitives::{JointId, PolygonId, SegmentId}, +}; + +impl Layout { + pub fn locate_joints_at_point( + &self, + layer: LayerId, + point: Vector2, + ) -> impl Iterator { + self.joints_rtree + .as_ref() + .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) + .map(|geom_with_data| geom_with_data.data) + .filter(move |&joint_id| self.joints[joint_id.index()].contains_point(point)) + } + + pub fn locate_segments_at_point( + &self, + layer: LayerId, + point: Vector2, + ) -> impl Iterator { + self.segments_rtree + .as_ref() + .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) + .map(|geom_with_data| geom_with_data.data) + .filter(move |&segment_id| self.segment(segment_id).contains_point(point)) + } + + // TODO: vias. + + pub fn locate_polygons_at_point( + &self, + layer: LayerId, + point: Vector2, + ) -> impl Iterator { + self.polygons_rtree + .as_ref() + .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) + .map(|geom_with_data| geom_with_data.data) + .filter(move |&polygon_id| self.polygons[polygon_id.index()].contains_point(point)) + } +} diff --git a/topola/src/layout/mod.rs b/topola/src/layout/mod.rs index b62d137..7d5b139 100644 --- a/topola/src/layout/mod.rs +++ b/topola/src/layout/mod.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 pub mod compounds; +mod locate; pub mod primitives; mod transforms; @@ -23,7 +24,6 @@ use crate::{ Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, ViaSpec, }, - math::Vector2, }; #[derive( @@ -370,44 +370,6 @@ impl Layout { .insert(GeomWithData::new(new_polygon.bbox(), id), ()); } - pub fn locate_joints_at_point( - &self, - layer: LayerId, - point: Vector2, - ) -> impl Iterator { - self.joints_rtree - .as_ref() - .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) - .map(|geom_with_data| geom_with_data.data) - .filter(move |&joint_id| self.joints[joint_id.index()].contains_point(point)) - } - - pub fn locate_segments_at_point( - &self, - layer: LayerId, - point: Vector2, - ) -> impl Iterator { - self.segments_rtree - .as_ref() - .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) - .map(|geom_with_data| geom_with_data.data) - .filter(move |&segment_id| self.segment(segment_id).contains_point(point)) - } - - // TODO: vias. - - pub fn locate_polygons_at_point( - &self, - layer: LayerId, - point: Vector2, - ) -> impl Iterator { - self.polygons_rtree - .as_ref() - .locate_all_at_point(&[point.x, point.y, layer.index() as i64]) - .map(|geom_with_data| geom_with_data.data) - .filter(move |&polygon_id| self.polygons[polygon_id.index()].contains_point(point)) - } - pub fn layer_joints(&self, layer: LayerId) -> impl Iterator + '_ { let envelope = Self::whole_layer_aabb(layer); self.joints_rtree