mirror of https://codeberg.org/topola/topola.git
Move location methods to new files
This commit is contained in:
parent
31107559c8
commit
eef69694fd
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
mod layer;
|
||||
mod locate;
|
||||
mod resolve;
|
||||
mod select;
|
||||
pub mod selections;
|
||||
|
|
|
|||
|
|
@ -108,28 +108,6 @@ impl Board {
|
|||
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> {
|
||||
let joint = self.layout.joint(id);
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
@ -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<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> + '_ {
|
||||
let envelope = Self::whole_layer_aabb(layer);
|
||||
self.joints_rtree
|
||||
|
|
|
|||
Loading…
Reference in New Issue