Move location methods to new files

This commit is contained in:
Mikolaj Wielgus 2026-05-25 22:42:04 +02:00
parent 31107559c8
commit eef69694fd
6 changed files with 104 additions and 62 deletions

View File

@ -58,7 +58,7 @@ impl Viewport {
.router() .router()
.navmesher_board() .navmesher_board()
.board() .board()
.point_pin_selector( .locate_pin_at_point(
workspace.appearance_panel.active, workspace.appearance_panel.active,
Vector2::new( Vector2::new(
pointer_scene_pos.x as i64, pointer_scene_pos.x as i64,

View File

@ -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<i64>,
) -> Option<ComponentSelector> {
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<i64>) -> Option<PinSelector> {
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
}
}

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
mod layer; mod layer;
mod locate;
mod resolve; mod resolve;
mod select; mod select;
pub mod selections; pub mod selections;

View File

@ -108,28 +108,6 @@ impl Board {
selection.0.contains(&selector) selection.0.contains(&selector)
} }
pub fn point_component_selector(
&self,
layer: LayerId,
point: Vector2<i64>,
) -> Option<ComponentSelector> {
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<ComponentSelector> { pub fn joint_component_selector(&self, id: JointId) -> Option<ComponentSelector> {
let joint = self.layout.joint(id); let joint = self.layout.joint(id);

View File

@ -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<i64>,
) -> impl Iterator<Item = JointId> {
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<i64>,
) -> impl Iterator<Item = SegmentId> {
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<i64>,
) -> impl Iterator<Item = PolygonId> {
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))
}
}

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
pub mod compounds; pub mod compounds;
mod locate;
pub mod primitives; pub mod primitives;
mod transforms; mod transforms;
@ -23,7 +24,6 @@ use crate::{
Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId,
ViaSpec, ViaSpec,
}, },
math::Vector2,
}; };
#[derive( #[derive(
@ -370,44 +370,6 @@ impl Layout {
.insert(GeomWithData::new(new_polygon.bbox(), id), ()); .insert(GeomWithData::new(new_polygon.bbox(), id), ());
} }
pub fn locate_joints_at_point(
&self,
layer: LayerId,
point: Vector2<i64>,
) -> impl Iterator<Item = JointId> {
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<i64>,
) -> impl Iterator<Item = SegmentId> {
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<i64>,
) -> impl Iterator<Item = PolygonId> {
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<Item = JointId> + '_ { pub fn layer_joints(&self, layer: LayerId) -> impl Iterator<Item = JointId> + '_ {
let envelope = Self::whole_layer_aabb(layer); let envelope = Self::whole_layer_aabb(layer);
self.joints_rtree self.joints_rtree