Rename "polygon" to "poly", "segment" to "seg"

This follows the established pattern of narrowing the meaning of a word
by its apocopation, like in the following examples:

difference -> diff (visual representation of a difference)
rectangle -> rect (axis-aligned rectangle)
configuration -> config (a top-level configuration)
application -> app
specification -> spec
This commit is contained in:
Mikolaj Wielgus 2026-06-07 22:37:07 +02:00
parent ec8b72823c
commit b134f7eef2
34 changed files with 826 additions and 811 deletions

View File

@ -164,7 +164,7 @@ impl Boundary {
} }
} }
pub fn to_polygon(&self) -> GeoPolygon { pub fn to_poly(&self) -> GeoPolygon {
GeoPolygon::new( GeoPolygon::new(
LineString( LineString(
self.coords() self.coords()
@ -619,7 +619,7 @@ pub struct Polygon {
} }
impl Polygon { impl Polygon {
pub fn to_polygon(&self) -> GeoPolygon { pub fn to_poly(&self) -> GeoPolygon {
GeoPolygon::new( GeoPolygon::new(
LineString( LineString(
self.coords self.coords

View File

@ -219,8 +219,8 @@ impl DebugOverlay {
); );
} }
for segment_id in layout.layer_segments(layer) { for seg_id in layout.layer_segs(layer) {
let endpoints = layout.segment(segment_id).endpoints; let endpoints = layout.seg(seg_id).endpoints;
ui.painter().rect_stroke( ui.painter().rect_stroke(
egui::Rect::from_two_pos( egui::Rect::from_two_pos(
@ -248,9 +248,9 @@ impl DebugOverlay {
); );
} }
for polygon_id in layout.layer_polygons(layer) { for poly_id in layout.layer_polys(layer) {
let polygon = layout.polygon(polygon_id); let poly = layout.poly(poly_id);
let bbox = polygon.bbox(); let bbox = poly.bbox();
ui.painter().rect_stroke( ui.painter().rect_stroke(
egui::Rect { egui::Rect {

View File

@ -3,12 +3,14 @@
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{ use crate::{
controller::Controller, debug_overlay::{DebugOverlay, DebugOverlayOptions}, menu_bar::MenuBar, controller::Controller,
debug_overlay::{DebugOverlay, DebugOverlayOptions},
menu_bar::MenuBar,
viewport::Viewport, viewport::Viewport,
}; };
use topola::{ use topola::{
Workspace, Workspace,
layout::primitives::{Joint, Polygon, Segment, Via}, layout::primitives::{Joint, Poly, Seg, Via},
}; };
pub struct Display {} pub struct Display {}
@ -93,26 +95,24 @@ impl Display {
); );
} }
for segment_id in layout.layer_segments(layer) { for seg_id in layout.layer_segs(layer) {
let segment = layout.segment(segment_id); let seg = layout.seg(seg_id);
let pin_selected = let pin_selected =
board.pins_contain_segment(&workspace.workspace.selection().pins, segment_id); board.pins_contain_seg(&workspace.workspace.selection().pins, seg_id);
let net_selected = let net_selected =
board.nets_contain_segment(&workspace.workspace.selection().nets, segment_id); board.nets_contain_seg(&workspace.workspace.selection().nets, seg_id);
let component_selected = board.components_contain_segment( let component_selected = board
&workspace.workspace.selection().components, .components_contain_seg(&workspace.workspace.selection().components, seg_id);
segment_id, self.paint_seg(
);
self.paint_segment(
ctx, ctx,
ui, ui,
viewport, viewport,
segment, seg,
workspace.appearance_panel.layer_color( workspace.appearance_panel.layer_color(
ctx, ctx,
board.layer_desc(segment.layer), board.layer_desc(seg.layer),
pin_selected, pin_selected,
(segment.spec.pin.is_none() && net_selected) || component_selected, (seg.spec.pin.is_none() && net_selected) || component_selected,
), ),
); );
} }
@ -139,26 +139,24 @@ impl Display {
); );
} }
for polygon_id in layout.layer_polygons(layer) { for poly_id in layout.layer_polys(layer) {
let polygon = layout.polygon(polygon_id); let poly = layout.poly(poly_id);
let pin_selected = let pin_selected =
board.pins_contain_polygon(&workspace.workspace.selection().pins, polygon_id); board.pins_contain_poly(&workspace.workspace.selection().pins, poly_id);
let net_selected = let net_selected =
board.nets_contain_polygon(&workspace.workspace.selection().nets, polygon_id); board.nets_contain_poly(&workspace.workspace.selection().nets, poly_id);
let component_selected = board.components_contain_polygon( let component_selected = board
&workspace.workspace.selection().components, .components_contain_poly(&workspace.workspace.selection().components, poly_id);
polygon_id, self.paint_poly(
);
self.paint_polygon(
ctx, ctx,
ui, ui,
viewport, viewport,
polygon, poly,
workspace.appearance_panel.layer_color( workspace.appearance_panel.layer_color(
ctx, ctx,
board.layer_desc(polygon.spec.layer), board.layer_desc(poly.spec.layer),
pin_selected, pin_selected,
(polygon.spec.pin.is_none() && net_selected) || component_selected, (poly.spec.pin.is_none() && net_selected) || component_selected,
), ),
); );
} }
@ -192,20 +190,20 @@ impl Display {
); );
} }
fn paint_segment( fn paint_seg(
&mut self, &mut self,
ctx: &egui::Context, ctx: &egui::Context,
ui: &egui::Ui, ui: &egui::Ui,
viewport: &Viewport, viewport: &Viewport,
segment: &Segment, seg: &Seg,
color: egui::Color32, color: egui::Color32,
) { ) {
ui.painter().line_segment( ui.painter().line_segment(
[ [
egui::pos2(segment.endpoints[0].x as f32, segment.endpoints[0].y as f32), egui::pos2(seg.endpoints[0].x as f32, seg.endpoints[0].y as f32),
egui::pos2(segment.endpoints[1].x as f32, segment.endpoints[1].y as f32), egui::pos2(seg.endpoints[1].x as f32, seg.endpoints[1].y as f32),
], ],
egui::Stroke::new(segment.spec.half_width as f32 * 2.0, color), egui::Stroke::new(seg.spec.half_width as f32 * 2.0, color),
); );
} }
@ -224,16 +222,17 @@ impl Display {
); );
} }
fn paint_polygon( fn paint_poly(
&mut self, &mut self,
ctx: &egui::Context, ctx: &egui::Context,
ui: &egui::Ui, ui: &egui::Ui,
viewport: &Viewport, viewport: &Viewport,
polygon: &Polygon, poly: &Poly,
color: egui::Color32, color: egui::Color32,
) { ) {
let points: Vec<egui::Pos2> = polygon let points: Vec<egui::Pos2> = poly
.spec.vertices .spec
.vertices
.iter() .iter()
.map(|v| egui::pos2(v.x as f32, v.y as f32)) .map(|v| egui::pos2(v.x as f32, v.y as f32))
.collect(); .collect();

View File

@ -4,7 +4,7 @@
use crate::{ use crate::{
board::Board, board::Board,
layout::primitives::{JointId, PolygonId, SegmentId, ViaId}, layout::primitives::{JointId, PolyId, SegId, ViaId},
selections::{ComponentSelection, NetSelection, NetSelector, PinSelection}, selections::{ComponentSelection, NetSelection, NetSelector, PinSelection},
vector::Vector2, vector::Vector2,
}; };
@ -30,12 +30,12 @@ impl Board {
selection.0.contains(&selector) selection.0.contains(&selector)
} }
pub fn components_contain_segment( pub fn components_contain_seg(
&self, &self,
selection: &ComponentSelection, selection: &ComponentSelection,
id: SegmentId, id: SegId,
) -> bool { ) -> bool {
let Some(selector) = self.segment_component_selector(id) else { let Some(selector) = self.seg_component_selector(id) else {
return false; return false;
}; };
@ -50,12 +50,12 @@ impl Board {
selection.0.contains(&selector) selection.0.contains(&selector)
} }
pub fn components_contain_polygon( pub fn components_contain_poly(
&self, &self,
selection: &ComponentSelection, selection: &ComponentSelection,
id: PolygonId, id: PolyId,
) -> bool { ) -> bool {
let Some(selector) = self.polygon_component_selector(id) else { let Some(selector) = self.poly_component_selector(id) else {
return false; return false;
}; };
@ -73,9 +73,9 @@ impl Board {
.contains(&NetSelector::new(net_name.to_string())) .contains(&NetSelector::new(net_name.to_string()))
} }
pub fn nets_contain_segment(&self, selection: &NetSelection, id: SegmentId) -> bool { pub fn nets_contain_seg(&self, selection: &NetSelection, id: SegId) -> bool {
let segment = self.layout.segment(id); let seg = self.layout.seg(id);
let Some(net_name) = segment.net.and_then(|net| self.net_name(net)) else { let Some(net_name) = seg.net.and_then(|net| self.net_name(net)) else {
return false; return false;
}; };
@ -95,9 +95,9 @@ impl Board {
.contains(&NetSelector::new(net_name.to_string())) .contains(&NetSelector::new(net_name.to_string()))
} }
pub fn nets_contain_polygon(&self, selection: &NetSelection, id: PolygonId) -> bool { pub fn nets_contain_poly(&self, selection: &NetSelection, id: PolyId) -> bool {
let polygon = self.layout.polygon(id); let poly = self.layout.poly(id);
let Some(net_name) = polygon.spec.net.and_then(|net| self.net_name(net)) else { let Some(net_name) = poly.spec.net.and_then(|net| self.net_name(net)) else {
return false; return false;
}; };
@ -114,8 +114,8 @@ impl Board {
selection.0.contains(&selector) selection.0.contains(&selector)
} }
pub fn pins_contain_segment(&self, selection: &PinSelection, id: SegmentId) -> bool { pub fn pins_contain_seg(&self, selection: &PinSelection, id: SegId) -> bool {
let Some(selector) = self.segment_pin_selector(id) else { let Some(selector) = self.seg_pin_selector(id) else {
return false; return false;
}; };
@ -130,8 +130,8 @@ impl Board {
selection.0.contains(&selector) selection.0.contains(&selector)
} }
pub fn pins_contain_polygon(&self, selection: &PinSelection, id: PolygonId) -> bool { pub fn pins_contain_poly(&self, selection: &PinSelection, id: PolyId) -> bool {
let Some(selector) = self.polygon_pin_selector(id) else { let Some(selector) = self.poly_pin_selector(id) else {
return false; return false;
}; };

View File

@ -7,7 +7,7 @@ use crate::{
layout::{ layout::{
compounds::ComponentId, compounds::ComponentId,
primitives::{ primitives::{
JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, JointId, JointSpec, Poly, PolyId, Seg, SegId, SegSpec, Via, ViaId,
ViaSpec, ViaSpec,
}, },
}, },
@ -22,12 +22,12 @@ impl Board {
self.layout.insert_joint(spec) self.layout.insert_joint(spec)
} }
pub fn insert_segment(&mut self, spec: SegmentSpec) -> SegmentId { pub fn insert_seg(&mut self, spec: SegSpec) -> SegId {
self.layout.insert_segment(spec) self.layout.insert_seg(spec)
} }
pub fn insert_segment_raw(&mut self, segment: Segment) -> SegmentId { pub fn insert_seg_raw(&mut self, seg: Seg) -> SegId {
self.layout.insert_segment_raw(segment) self.layout.insert_seg_raw(seg)
} }
pub fn insert_via(&mut self, spec: ViaSpec) -> ViaId { pub fn insert_via(&mut self, spec: ViaSpec) -> ViaId {
@ -38,7 +38,7 @@ impl Board {
self.layout.insert_via_raw(via) self.layout.insert_via_raw(via)
} }
pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId { pub fn insert_poly(&mut self, poly: Poly) -> PolyId {
self.layout.insert_polygon(polygon) self.layout.insert_poly(poly)
} }
} }

View File

@ -67,16 +67,16 @@ impl Interactor for DragSelectInteractor {
.all(|joint_id| board.layout().joint(joint_id).spec.pin.is_some()) .all(|joint_id| board.layout().joint(joint_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_segments_prefer_layer_intersecting_rect(rect) .locate_segs_prefer_layer_intersecting_rect(rect)
.all(|segment_id| board.layout().segment(segment_id).spec.pin.is_some()) .all(|seg_id| board.layout().seg(seg_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_vias_prefer_layer_intersecting_rect(rect) .locate_vias_prefer_layer_intersecting_rect(rect)
.all(|via_id| board.layout().via(via_id).spec.pin.is_some()) .all(|via_id| board.layout().via(via_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_polygons_prefer_layer_intersecting_rect(rect) .locate_polys_prefer_layer_intersecting_rect(rect)
.all(|polygon_id| board.layout().polygon(polygon_id).spec.pin.is_some()) .all(|poly_id| board.layout().poly(poly_id).spec.pin.is_some())
} }
SelectionContainMode::Window => { SelectionContainMode::Window => {
board board
@ -85,16 +85,16 @@ impl Interactor for DragSelectInteractor {
.all(|joint_id| board.layout().joint(joint_id).spec.pin.is_some()) .all(|joint_id| board.layout().joint(joint_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_segments_prefer_layer_inside_rect(rect) .locate_segs_prefer_layer_inside_rect(rect)
.all(|segment_id| board.layout().segment(segment_id).spec.pin.is_some()) .all(|seg_id| board.layout().seg(seg_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_vias_prefer_layer_inside_rect(rect) .locate_vias_prefer_layer_inside_rect(rect)
.all(|via_id| board.layout().via(via_id).spec.pin.is_some()) .all(|via_id| board.layout().via(via_id).spec.pin.is_some())
&& board && board
.layout() .layout()
.locate_polygons_prefer_layer_inside_rect(rect) .locate_polys_prefer_layer_inside_rect(rect)
.all(|polygon_id| board.layout().polygon(polygon_id).spec.pin.is_some()) .all(|poly_id| board.layout().poly(poly_id).spec.pin.is_some())
} }
}; };

View File

@ -20,8 +20,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_at_point(point) .locate_segs_prefer_layer_at_point(point)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -30,8 +30,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_prefer_layer_at_point(point) .locate_polys_prefer_layer_at_point(point)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -44,8 +44,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_at_point(point) .locate_segs_at_point(point)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -54,8 +54,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_at_point(point) .locate_polys_at_point(point)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -68,8 +68,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_intersecting_rect(rect) .locate_segs_prefer_layer_intersecting_rect(rect)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -78,8 +78,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_prefer_layer_intersecting_rect(rect) .locate_polys_prefer_layer_intersecting_rect(rect)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -92,8 +92,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_intersecting_rect(rect) .locate_segs_intersecting_rect(rect)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -102,8 +102,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_intersecting_rect(rect) .locate_polys_intersecting_rect(rect)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -116,8 +116,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_inside_rect(rect) .locate_segs_prefer_layer_inside_rect(rect)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -126,8 +126,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_prefer_layer_inside_rect(rect) .locate_polys_prefer_layer_inside_rect(rect)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -140,8 +140,8 @@ impl Board {
.filter_map(|joint_id| self.joint_component_selector(joint_id)) .filter_map(|joint_id| self.joint_component_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_inside_rect(rect) .locate_segs_prefer_layer_inside_rect(rect)
.filter_map(|segment_id| self.segment_component_selector(segment_id)), .filter_map(|seg_id| self.seg_component_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -150,8 +150,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_prefer_layer_inside_rect(rect) .locate_polys_prefer_layer_inside_rect(rect)
.filter_map(|polygon_id| self.polygon_component_selector(polygon_id)), .filter_map(|poly_id| self.poly_component_selector(poly_id)),
) )
} }
@ -164,8 +164,8 @@ impl Board {
.filter_map(|joint_id| self.joint_net_selector(joint_id)) .filter_map(|joint_id| self.joint_net_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_at_point(point) .locate_segs_prefer_layer_at_point(point)
.filter_map(|segment_id| self.segment_net_selector(segment_id)), .filter_map(|seg_id| self.seg_net_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -174,8 +174,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_prefer_layer_at_point(point) .locate_polys_prefer_layer_at_point(point)
.filter_map(|polygon_id| self.polygon_net_selector(polygon_id)), .filter_map(|poly_id| self.poly_net_selector(poly_id)),
) )
} }
@ -188,8 +188,8 @@ impl Board {
.filter_map(|joint_id| self.joint_net_selector(joint_id)) .filter_map(|joint_id| self.joint_net_selector(joint_id))
.chain( .chain(
self.layout self.layout
.locate_segments_at_point(point) .locate_segs_at_point(point)
.filter_map(|segment_id| self.segment_net_selector(segment_id)), .filter_map(|seg_id| self.seg_net_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -198,8 +198,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_polygons_at_point(point) .locate_polys_at_point(point)
.filter_map(|polygon_id| self.polygon_net_selector(polygon_id)), .filter_map(|poly_id| self.poly_net_selector(poly_id)),
) )
} }
@ -276,8 +276,8 @@ impl Board {
point: Vector3<i64>, point: Vector3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_prefer_layer_at_point(point) .locate_polys_prefer_layer_at_point(point)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_prefer_layer_at_point(point) .locate_joints_prefer_layer_at_point(point)
@ -285,8 +285,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_at_point(point) .locate_segs_prefer_layer_at_point(point)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -300,8 +300,8 @@ impl Board {
point: Vector3<i64>, point: Vector3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_at_point(point) .locate_polys_at_point(point)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_at_point(point) .locate_joints_at_point(point)
@ -309,8 +309,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_at_point(point) .locate_segs_at_point(point)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -324,8 +324,8 @@ impl Board {
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_prefer_layer_intersecting_rect(rect) .locate_polys_prefer_layer_intersecting_rect(rect)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_prefer_layer_intersecting_rect(rect) .locate_joints_prefer_layer_intersecting_rect(rect)
@ -333,8 +333,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_intersecting_rect(rect) .locate_segs_prefer_layer_intersecting_rect(rect)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -348,8 +348,8 @@ impl Board {
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_intersecting_rect(rect) .locate_polys_intersecting_rect(rect)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_intersecting_rect(rect) .locate_joints_intersecting_rect(rect)
@ -357,8 +357,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_intersecting_rect(rect) .locate_segs_intersecting_rect(rect)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -372,8 +372,8 @@ impl Board {
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_prefer_layer_inside_rect(rect) .locate_polys_prefer_layer_inside_rect(rect)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_prefer_layer_inside_rect(rect) .locate_joints_prefer_layer_inside_rect(rect)
@ -381,8 +381,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_prefer_layer_inside_rect(rect) .locate_segs_prefer_layer_inside_rect(rect)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout
@ -396,8 +396,8 @@ impl Board {
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PinSelector> + '_ { ) -> impl Iterator<Item = PinSelector> + '_ {
self.layout self.layout
.locate_polygons_inside_rect(rect) .locate_polys_inside_rect(rect)
.filter_map(|polygon_id| self.polygon_pin_selector(polygon_id)) .filter_map(|poly_id| self.poly_pin_selector(poly_id))
.chain( .chain(
self.layout self.layout
.locate_joints_inside_rect(rect) .locate_joints_inside_rect(rect)
@ -405,8 +405,8 @@ impl Board {
) )
.chain( .chain(
self.layout self.layout
.locate_segments_inside_rect(rect) .locate_segs_inside_rect(rect)
.filter_map(|segment_id| self.segment_pin_selector(segment_id)), .filter_map(|seg_id| self.seg_pin_selector(seg_id)),
) )
.chain( .chain(
self.layout self.layout

View File

@ -6,7 +6,7 @@ use crate::{
board::{Board, selections::ComponentSelection}, board::{Board, selections::ComponentSelection},
layout::{ layout::{
compounds::ComponentId, compounds::ComponentId,
primitives::{JointId, PolygonId, SegmentId, ViaId}, primitives::{JointId, PolyId, SegId, ViaId},
}, },
selections::NetSelection, selections::NetSelection,
}; };
@ -41,22 +41,22 @@ impl Board {
resolved_joints.into_iter() resolved_joints.into_iter()
} }
pub fn resolve_net_segments(&self, selection: NetSelection) -> impl Iterator<Item = SegmentId> { pub fn resolve_net_segs(&self, selection: NetSelection) -> impl Iterator<Item = SegId> {
let mut resolved_segments = Vec::new(); let mut resolved_segs = Vec::new();
for (index, _) in self.layout.segments().container() { for (index, _) in self.layout.segs().container() {
let segment_id = SegmentId::new(index); let seg_id = SegId::new(index);
let Some(selector) = self.segment_net_selector(segment_id) else { let Some(selector) = self.seg_net_selector(seg_id) else {
continue; continue;
}; };
if selection.0.contains(&selector) { if selection.0.contains(&selector) {
resolved_segments.push(segment_id); resolved_segs.push(seg_id);
} }
} }
resolved_segments.into_iter() resolved_segs.into_iter()
} }
pub fn resolve_net_vias(&self, selection: NetSelection) -> impl Iterator<Item = ViaId> { pub fn resolve_net_vias(&self, selection: NetSelection) -> impl Iterator<Item = ViaId> {
@ -77,21 +77,21 @@ impl Board {
resolved_vias.into_iter() resolved_vias.into_iter()
} }
pub fn resolve_net_polygons(&self, selection: NetSelection) -> impl Iterator<Item = PolygonId> { pub fn resolve_net_polys(&self, selection: NetSelection) -> impl Iterator<Item = PolyId> {
let mut resolved_polygons = Vec::new(); let mut resolved_polys = Vec::new();
for (index, _) in self.layout.polygons().container() { for (index, _) in self.layout.polys().container() {
let polygon_id = PolygonId::new(index); let poly_id = PolyId::new(index);
let Some(selector) = self.polygon_net_selector(polygon_id) else { let Some(selector) = self.poly_net_selector(poly_id) else {
continue; continue;
}; };
if selection.0.contains(&selector) { if selection.0.contains(&selector) {
resolved_polygons.push(polygon_id); resolved_polys.push(poly_id);
} }
} }
resolved_polygons.into_iter() resolved_polys.into_iter()
} }
} }

View File

@ -9,7 +9,7 @@ use crate::{
ComponentSelection, ComponentSelector, NetSelector, PinSelection, PinSelector, ComponentSelection, ComponentSelector, NetSelector, PinSelection, PinSelector,
}, },
}, },
layout::primitives::{JointId, PolygonId, SegmentId, ViaId}, layout::primitives::{JointId, PolyId, SegId, ViaId},
}; };
impl Board { impl Board {
@ -49,24 +49,24 @@ impl Board {
component_selection.0.insert(component_selector); component_selection.0.insert(component_selector);
} }
for segment_id in self.layout.layer_segments(layer_id) { for seg_id in self.layout.layer_segs(layer_id) {
if self.layout.segment(segment_id).spec.pin != Some(pin_id) { if self.layout.seg(seg_id).spec.pin != Some(pin_id) {
continue; continue;
} }
let Some(component_selector) = self.segment_component_selector(segment_id) else { let Some(component_selector) = self.seg_component_selector(seg_id) else {
continue; continue;
}; };
component_selection.0.insert(component_selector); component_selection.0.insert(component_selector);
} }
for polygon_id in self.layout.layer_polygons(layer_id) { for poly_id in self.layout.layer_polys(layer_id) {
if self.layout.polygon(polygon_id).spec.pin != Some(pin_id) { if self.layout.poly(poly_id).spec.pin != Some(pin_id) {
continue; continue;
} }
let Some(component_selector) = self.polygon_component_selector(polygon_id) else { let Some(component_selector) = self.poly_component_selector(poly_id) else {
continue; continue;
}; };
@ -85,11 +85,11 @@ impl Board {
}) })
} }
pub fn segment_component_selector(&self, id: SegmentId) -> Option<ComponentSelector> { pub fn seg_component_selector(&self, id: SegId) -> Option<ComponentSelector> {
let segment = self.layout.segment(id); let seg = self.layout.seg(id);
Some(ComponentSelector { Some(ComponentSelector {
component: self.component_name(segment.spec.component?)?.to_string(), component: self.component_name(seg.spec.component?)?.to_string(),
}) })
} }
@ -101,11 +101,11 @@ impl Board {
}) })
} }
pub fn polygon_component_selector(&self, id: PolygonId) -> Option<ComponentSelector> { pub fn poly_component_selector(&self, id: PolyId) -> Option<ComponentSelector> {
let polygon = self.layout.polygon(id); let poly = self.layout.poly(id);
Some(ComponentSelector { Some(ComponentSelector {
component: self.component_name(polygon.spec.component?)?.to_string(), component: self.component_name(poly.spec.component?)?.to_string(),
}) })
} }
@ -117,11 +117,11 @@ impl Board {
}) })
} }
pub fn segment_net_selector(&self, id: SegmentId) -> Option<NetSelector> { pub fn seg_net_selector(&self, id: SegId) -> Option<NetSelector> {
let segment = self.layout.segment(id); let seg = self.layout.seg(id);
Some(NetSelector { Some(NetSelector {
net: self.net_name(segment.net?)?.to_string(), net: self.net_name(seg.net?)?.to_string(),
}) })
} }
@ -133,11 +133,11 @@ impl Board {
}) })
} }
pub fn polygon_net_selector(&self, id: PolygonId) -> Option<NetSelector> { pub fn poly_net_selector(&self, id: PolyId) -> Option<NetSelector> {
let polygon = self.layout.polygon(id); let poly = self.layout.poly(id);
Some(NetSelector { Some(NetSelector {
net: self.net_name(polygon.spec.net?)?.to_string(), net: self.net_name(poly.spec.net?)?.to_string(),
}) })
} }
@ -150,12 +150,12 @@ impl Board {
}) })
} }
pub fn segment_pin_selector(&self, id: SegmentId) -> Option<PinSelector> { pub fn seg_pin_selector(&self, id: SegId) -> Option<PinSelector> {
let segment = self.layout.segment(id); let seg = self.layout.seg(id);
Some(PinSelector { Some(PinSelector {
pin: self.pin_name(segment.spec.pin?)?.to_string(), pin: self.pin_name(seg.spec.pin?)?.to_string(),
layer: self.layer_name(segment.layer)?, layer: self.layer_name(seg.layer)?,
}) })
} }
@ -168,12 +168,12 @@ impl Board {
}) })
} }
pub fn polygon_pin_selector(&self, id: PolygonId) -> Option<PinSelector> { pub fn poly_pin_selector(&self, id: PolyId) -> Option<PinSelector> {
let polygon = self.layout.polygon(id); let poly = self.layout.poly(id);
Some(PinSelector { Some(PinSelector {
pin: self.pin_name(polygon.spec.pin?)?.to_string(), pin: self.pin_name(poly.spec.pin?)?.to_string(),
layer: self.layer_name(polygon.spec.layer)?, layer: self.layer_name(poly.spec.layer)?,
}) })
} }
} }

View File

@ -15,13 +15,13 @@ impl Board {
self.layout.delete_joint(joint_id); self.layout.delete_joint(joint_id);
} }
for segment_id in self for seg_id in self
.resolve_net_segments(selection.clone()) .resolve_net_segs(selection.clone())
.filter(|&segment_id| self.layout.segment(segment_id).spec.pin.is_none()) .filter(|&seg_id| self.layout.seg(seg_id).spec.pin.is_none())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.clone() .clone()
{ {
self.layout.delete_segment(segment_id); self.layout.delete_seg(seg_id);
} }
for via_id in self for via_id in self
@ -33,13 +33,13 @@ impl Board {
self.layout.delete_via(via_id); self.layout.delete_via(via_id);
} }
for polygon_id in self for poly_id in self
.resolve_net_polygons(selection.clone()) .resolve_net_polys(selection.clone())
.filter(|&polygon_id| self.layout.polygon(polygon_id).spec.pin.is_none()) .filter(|&poly_id| self.layout.poly(poly_id).spec.pin.is_none())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.clone() .clone()
{ {
self.layout.delete_polygon(polygon_id); self.layout.delete_poly(poly_id);
} }
} }
} }

View File

@ -2,14 +2,14 @@
// //
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
use polygon_unionfind::UnionFind; use poly_unionfind::UnionFind;
use crate::board::Board; use crate::board::Board;
pub struct Connectivity { pub struct Connectivity {
joints_unionfind: UnionFind, joints_unionfind: UnionFind,
segments_unionfind: UnionFind, segs_unionfind: UnionFind,
polygons_unionfind: UnionFind, polys_unionfind: UnionFind,
} }
impl Connectivity { impl Connectivity {
@ -18,11 +18,11 @@ impl Connectivity {
joints_unionfind: UnionFind::with_len( joints_unionfind: UnionFind::with_len(
board.layout().joints().container().num_elements(), board.layout().joints().container().num_elements(),
), ),
segments_unionfind: UnionFind::with_len( segs_unionfind: UnionFind::with_len(
board.layout().segments().container().num_elements(), board.layout().segs().container().num_elements(),
), ),
polygons_unionfind: UnionFind::with_len( polys_unionfind: UnionFind::with_len(
board.layout().polygons().container().num_elements(), board.layout().polys().container().num_elements(),
), ),
}; };

View File

@ -16,16 +16,16 @@ impl Layout {
unionize(&mut maybe_accum_bbox2, self.joint(joint_id).bbox().xy()); unionize(&mut maybe_accum_bbox2, self.joint(joint_id).bbox().xy());
} }
for &segment_id in &component.segments { for &seg_id in &component.segs {
unionize(&mut maybe_accum_bbox2, self.segment(segment_id).bbox().xy()); unionize(&mut maybe_accum_bbox2, self.seg(seg_id).bbox().xy());
} }
for &via_id in &component.vias { for &via_id in &component.vias {
unionize(&mut maybe_accum_bbox2, self.via(via_id).bbox().xy()); unionize(&mut maybe_accum_bbox2, self.via(via_id).bbox().xy());
} }
for &polygon_id in &component.polygons { for &poly_id in &component.polys {
unionize(&mut maybe_accum_bbox2, self.polygon(polygon_id).bbox().xy()); unionize(&mut maybe_accum_bbox2, self.poly(poly_id).bbox().xy());
} }
maybe_accum_bbox2 maybe_accum_bbox2

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use crate::layout::{ use crate::layout::{
compounds::PinId, compounds::PinId,
primitives::{JointId, PolygonId, PrimitiveId, SegmentId, ViaId}, primitives::{JointId, PolyId, PrimitiveId, SegId, ViaId},
}; };
#[derive( #[derive(
@ -37,9 +37,9 @@ impl ComponentId {
pub struct Component { pub struct Component {
pub pins: Vec<PinId>, pub pins: Vec<PinId>,
pub joints: Vec<JointId>, pub joints: Vec<JointId>,
pub segments: Vec<SegmentId>, pub segs: Vec<SegId>,
pub vias: Vec<ViaId>, pub vias: Vec<ViaId>,
pub polygons: Vec<PolygonId>, pub polys: Vec<PolyId>,
} }
impl Component { impl Component {
@ -52,15 +52,15 @@ impl Component {
.iter() .iter()
.map(|&joint_id| PrimitiveId::Joint(joint_id)) .map(|&joint_id| PrimitiveId::Joint(joint_id))
.chain( .chain(
self.segments self.segs
.iter() .iter()
.map(|&segment_id| PrimitiveId::Segment(segment_id)), .map(|&seg_id| PrimitiveId::Seg(seg_id)),
) )
.chain(self.vias.iter().map(|&via_id| PrimitiveId::Via(via_id))) .chain(self.vias.iter().map(|&via_id| PrimitiveId::Via(via_id)))
.chain( .chain(
self.polygons self.polys
.iter() .iter()
.map(|&polygon_id| PrimitiveId::Polygon(polygon_id)), .map(|&poly_id| PrimitiveId::Poly(poly_id)),
) )
} }
} }

View File

@ -9,7 +9,7 @@ use crate::{
layout::{ layout::{
Layout, Layout,
compounds::{ComponentId, NetId}, compounds::{ComponentId, NetId},
primitives::{JointId, PolygonId, PrimitiveId, SegmentId, ViaId}, primitives::{JointId, PolyId, PrimitiveId, SegId, ViaId},
}, },
vector::Vector2, vector::Vector2,
}; };
@ -47,9 +47,9 @@ pub struct PinSpec {
pub struct Pin { pub struct Pin {
pub spec: PinSpec, pub spec: PinSpec,
pub joints: Vec<JointId>, pub joints: Vec<JointId>,
pub segments: Vec<SegmentId>, pub segs: Vec<SegId>,
pub vias: Vec<ViaId>, pub vias: Vec<ViaId>,
pub polygons: Vec<PolygonId>, pub polys: Vec<PolyId>,
} }
impl Pin { impl Pin {
@ -57,9 +57,9 @@ impl Pin {
Pin { Pin {
spec, spec,
joints: Vec::new(), joints: Vec::new(),
segments: Vec::new(), segs: Vec::new(),
vias: Vec::new(), vias: Vec::new(),
polygons: Vec::new(), polys: Vec::new(),
} }
} }
@ -68,15 +68,15 @@ impl Pin {
.iter() .iter()
.map(|&joint_id| PrimitiveId::Joint(joint_id)) .map(|&joint_id| PrimitiveId::Joint(joint_id))
.chain( .chain(
self.segments self.segs
.iter() .iter()
.map(|&segment_id| PrimitiveId::Segment(segment_id)), .map(|&seg_id| PrimitiveId::Seg(seg_id)),
) )
.chain(self.vias.iter().map(|&via_id| PrimitiveId::Via(via_id))) .chain(self.vias.iter().map(|&via_id| PrimitiveId::Via(via_id)))
.chain( .chain(
self.polygons self.polys
.iter() .iter()
.map(|&polygon_id| PrimitiveId::Polygon(polygon_id)), .map(|&poly_id| PrimitiveId::Poly(poly_id)),
) )
} }
} }
@ -92,16 +92,16 @@ impl Layout {
sum = sum + self.joint(joint_id).center(); sum = sum + self.joint(joint_id).center();
count += 1; count += 1;
} }
for &segment_id in &pin.segments { for &seg_id in &pin.segs {
sum = sum + self.segment(segment_id).center(); sum = sum + self.seg(seg_id).center();
count += 1; count += 1;
} }
for &via_id in &pin.vias { for &via_id in &pin.vias {
sum = sum + self.via(via_id).position; sum = sum + self.via(via_id).position;
count += 1; count += 1;
} }
for &polygon_id in &pin.polygons { for &poly_id in &pin.polys {
sum = sum + self.polygon(polygon_id).centroid; sum = sum + self.poly(poly_id).centroid;
count += 1; count += 1;
} }

View File

@ -6,7 +6,7 @@ use rstar::primitives::GeomWithData;
use crate::layout::{ use crate::layout::{
Layout, Layout,
primitives::{JointId, PolygonId, SegmentId, ViaId}, primitives::{JointId, PolyId, SegId, ViaId},
}; };
impl Layout { impl Layout {
@ -37,35 +37,35 @@ impl Layout {
self.joints.remove(&joint_id.index()); self.joints.remove(&joint_id.index());
} }
pub fn delete_segment(&mut self, segment_id: SegmentId) { pub fn delete_seg(&mut self, seg_id: SegId) {
let segment = self.segment(segment_id); let seg = self.seg(seg_id);
let bbox = segment.bbox(); let bbox = seg.bbox();
let component = segment.spec.component; let component = seg.spec.component;
let pin = segment.spec.pin; let pin = seg.spec.pin;
if let Some(component_id) = component { if let Some(component_id) = component {
self.components.modify(component_id.index(), |component| { self.components.modify(component_id.index(), |component| {
if let Some(index) = component if let Some(index) = component
.segments .segs
.iter() .iter()
.position(|&curr| curr == segment_id) .position(|&curr| curr == seg_id)
{ {
component.segments.remove(index); component.segs.remove(index);
} }
}); });
} }
if let Some(pin_id) = pin { if let Some(pin_id) = pin {
self.pins.modify(pin_id.index(), |pin| { self.pins.modify(pin_id.index(), |pin| {
if let Some(index) = pin.segments.iter().position(|&curr| curr == segment_id) { if let Some(index) = pin.segs.iter().position(|&curr| curr == seg_id) {
pin.segments.remove(index); pin.segs.remove(index);
} }
}); });
} }
self.segments_rtree self.segs_rtree
.remove(&GeomWithData::new(bbox.rtree_rectangle(), segment_id)); .remove(&GeomWithData::new(bbox.rtree_rectangle(), seg_id));
self.segments.remove(&segment_id.index()); self.segs.remove(&seg_id.index());
} }
pub fn delete_via(&mut self, via_id: ViaId) { pub fn delete_via(&mut self, via_id: ViaId) {
@ -95,34 +95,34 @@ impl Layout {
self.vias.remove(&via_id.index()); self.vias.remove(&via_id.index());
} }
pub fn delete_polygon(&mut self, polygon_id: PolygonId) { pub fn delete_poly(&mut self, poly_id: PolyId) {
let polygon = self.polygon(polygon_id); let poly = self.poly(poly_id);
let bbox = polygon.bbox(); let bbox = poly.bbox();
let component = polygon.spec.component; let component = poly.spec.component;
let pin = polygon.spec.pin; let pin = poly.spec.pin;
if let Some(component_id) = component { if let Some(component_id) = component {
self.components.modify(component_id.index(), |component| { self.components.modify(component_id.index(), |component| {
if let Some(index) = component if let Some(index) = component
.polygons .polys
.iter() .iter()
.position(|&curr| curr == polygon_id) .position(|&curr| curr == poly_id)
{ {
component.polygons.remove(index); component.polys.remove(index);
} }
}); });
} }
if let Some(pin_id) = pin { if let Some(pin_id) = pin {
self.pins.modify(pin_id.index(), |pin| { self.pins.modify(pin_id.index(), |pin| {
if let Some(index) = pin.polygons.iter().position(|&curr| curr == polygon_id) { if let Some(index) = pin.polys.iter().position(|&curr| curr == poly_id) {
pin.polygons.remove(index); pin.polys.remove(index);
} }
}); });
} }
self.polygons_rtree self.polys_rtree
.remove(&GeomWithData::new(bbox.rtree_rectangle(), polygon_id)); .remove(&GeomWithData::new(bbox.rtree_rectangle(), poly_id));
self.polygons.remove(&polygon_id.index()); self.polys.remove(&poly_id.index());
} }
} }

View File

@ -15,7 +15,7 @@ use crate::layout::primitives::PrimitiveId;
use super::Layout; use super::Layout;
use super::compounds::{ComponentId, NetId, PinId}; use super::compounds::{ComponentId, NetId, PinId};
use super::primitives::{JointId, PolygonId, SegmentId, ViaId}; use super::primitives::{JointId, PolyId, SegId, ViaId};
#[derive( #[derive(
Clone, Copy, Constructor, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, Clone, Copy, Constructor, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
@ -43,9 +43,9 @@ mod sealed {
pub trait IntoPrimitiveId: Into<PrimitiveId> {} pub trait IntoPrimitiveId: Into<PrimitiveId> {}
impl IntoPrimitiveId for JointId {} impl IntoPrimitiveId for JointId {}
impl IntoPrimitiveId for SegmentId {} impl IntoPrimitiveId for SegId {}
impl IntoPrimitiveId for ViaId {} impl IntoPrimitiveId for ViaId {}
impl IntoPrimitiveId for PolygonId {} impl IntoPrimitiveId for PolyId {}
} }
impl<T: sealed::IntoPrimitiveId, U: sealed::IntoPrimitiveId> From<Infringement<T, U>> impl<T: sealed::IntoPrimitiveId, U: sealed::IntoPrimitiveId> From<Infringement<T, U>>
@ -120,8 +120,8 @@ impl Layout {
.iter() .iter()
.copied() .copied()
.flat_map(|joint_id| self.locate_joint_infringements(joint_id).map(Into::into)); .flat_map(|joint_id| self.locate_joint_infringements(joint_id).map(Into::into));
let segment_infringements = component.segments.iter().copied().flat_map(|segment_id| { let seg_infringements = component.segs.iter().copied().flat_map(|seg_id| {
self.locate_segment_infringements(segment_id) self.locate_seg_infringements(seg_id)
.map(Into::into) .map(Into::into)
}); });
let via_infringements = component let via_infringements = component
@ -129,15 +129,15 @@ impl Layout {
.iter() .iter()
.copied() .copied()
.flat_map(|via_id| self.locate_via_infringements(via_id).map(Into::into)); .flat_map(|via_id| self.locate_via_infringements(via_id).map(Into::into));
let polygon_infringements = component.polygons.iter().copied().flat_map(|polygon_id| { let poly_infringements = component.polys.iter().copied().flat_map(|poly_id| {
self.locate_polygon_infringements(polygon_id) self.locate_poly_infringements(poly_id)
.map(Into::into) .map(Into::into)
}); });
joint_infringements joint_infringements
.chain(segment_infringements) .chain(seg_infringements)
.chain(via_infringements) .chain(via_infringements)
.chain(polygon_infringements) .chain(poly_infringements)
} }
pub fn locate_pin_infringements( pub fn locate_pin_infringements(
@ -176,8 +176,8 @@ impl Layout {
.iter() .iter()
.copied() .copied()
.flat_map(|joint_id| self.locate_joint_infringements(joint_id).map(Into::into)) .flat_map(|joint_id| self.locate_joint_infringements(joint_id).map(Into::into))
.chain(pin.segments.iter().copied().flat_map(|segment_id| { .chain(pin.segs.iter().copied().flat_map(|seg_id| {
self.locate_segment_infringements(segment_id) self.locate_seg_infringements(seg_id)
.map(Into::into) .map(Into::into)
})) }))
.chain( .chain(
@ -186,8 +186,8 @@ impl Layout {
.copied() .copied()
.flat_map(|via_id| self.locate_via_infringements(via_id).map(Into::into)), .flat_map(|via_id| self.locate_via_infringements(via_id).map(Into::into)),
) )
.chain(pin.polygons.iter().copied().flat_map(|polygon_id| { .chain(pin.polys.iter().copied().flat_map(|poly_id| {
self.locate_polygon_infringements(polygon_id) self.locate_poly_infringements(poly_id)
.map(Into::into) .map(Into::into)
})) }))
} }
@ -199,7 +199,7 @@ impl Layout {
self.locate_joint_joint_infringements(infringer) self.locate_joint_joint_infringements(infringer)
.map(Into::into) .map(Into::into)
.chain( .chain(
self.locate_joint_segment_infringements(infringer) self.locate_joint_seg_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
@ -207,7 +207,7 @@ impl Layout {
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
self.locate_joint_polygon_infringements(infringer) self.locate_joint_poly_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
} }
@ -219,11 +219,11 @@ impl Layout {
self.locate_same_infringements(infringer, self.joints_rtree().as_ref()) self.locate_same_infringements(infringer, self.joints_rtree().as_ref())
} }
pub fn locate_joint_segment_infringements( pub fn locate_joint_seg_infringements(
&self, &self,
infringer: JointId, infringer: JointId,
) -> impl Iterator<Item = Infringement<JointId, SegmentId>> + '_ { ) -> impl Iterator<Item = Infringement<JointId, SegId>> + '_ {
self.locate_cross_infringements(infringer, self.segments_rtree().as_ref()) self.locate_cross_infringements(infringer, self.segs_rtree().as_ref())
} }
pub fn locate_joint_via_infringements( pub fn locate_joint_via_infringements(
@ -233,59 +233,59 @@ impl Layout {
self.locate_cross_infringements(infringer, self.vias_rtree().as_ref()) self.locate_cross_infringements(infringer, self.vias_rtree().as_ref())
} }
pub fn locate_joint_polygon_infringements( pub fn locate_joint_poly_infringements(
&self, &self,
infringer: JointId, infringer: JointId,
) -> impl Iterator<Item = Infringement<JointId, PolygonId>> + '_ { ) -> impl Iterator<Item = Infringement<JointId, PolyId>> + '_ {
self.locate_cross_infringements(infringer, self.polygons_rtree().as_ref()) self.locate_cross_infringements(infringer, self.polys_rtree().as_ref())
} }
pub fn locate_segment_infringements( pub fn locate_seg_infringements(
&self, &self,
infringer: SegmentId, infringer: SegId,
) -> impl Iterator<Item = Infringement<SegmentId>> + '_ { ) -> impl Iterator<Item = Infringement<SegId>> + '_ {
self.locate_segment_joint_infringements(infringer) self.locate_seg_joint_infringements(infringer)
.map(Into::into) .map(Into::into)
.chain( .chain(
self.locate_segment_segment_infringements(infringer) self.locate_seg_seg_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
self.locate_segment_via_infringements(infringer) self.locate_seg_via_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
self.locate_segment_polygon_infringements(infringer) self.locate_seg_poly_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
} }
pub fn locate_segment_joint_infringements( pub fn locate_seg_joint_infringements(
&self, &self,
infringer: SegmentId, infringer: SegId,
) -> impl Iterator<Item = Infringement<SegmentId, JointId>> + '_ { ) -> impl Iterator<Item = Infringement<SegId, JointId>> + '_ {
self.locate_cross_infringements(infringer, self.joints_rtree().as_ref()) self.locate_cross_infringements(infringer, self.joints_rtree().as_ref())
} }
pub fn locate_segment_segment_infringements( pub fn locate_seg_seg_infringements(
&self, &self,
infringer: SegmentId, infringer: SegId,
) -> impl Iterator<Item = Infringement<SegmentId, SegmentId>> + '_ { ) -> impl Iterator<Item = Infringement<SegId, SegId>> + '_ {
self.locate_same_infringements(infringer, self.segments_rtree().as_ref()) self.locate_same_infringements(infringer, self.segs_rtree().as_ref())
} }
pub fn locate_segment_via_infringements( pub fn locate_seg_via_infringements(
&self, &self,
infringer: SegmentId, infringer: SegId,
) -> impl Iterator<Item = Infringement<SegmentId, ViaId>> + '_ { ) -> impl Iterator<Item = Infringement<SegId, ViaId>> + '_ {
self.locate_cross_infringements(infringer, self.vias_rtree().as_ref()) self.locate_cross_infringements(infringer, self.vias_rtree().as_ref())
} }
pub fn locate_segment_polygon_infringements( pub fn locate_seg_poly_infringements(
&self, &self,
infringer: SegmentId, infringer: SegId,
) -> impl Iterator<Item = Infringement<SegmentId, PolygonId>> + '_ { ) -> impl Iterator<Item = Infringement<SegId, PolyId>> + '_ {
self.locate_cross_infringements(infringer, self.polygons_rtree().as_ref()) self.locate_cross_infringements(infringer, self.polys_rtree().as_ref())
} }
pub fn locate_via_infringements( pub fn locate_via_infringements(
@ -295,12 +295,12 @@ impl Layout {
self.locate_via_joint_infringements(infringer) self.locate_via_joint_infringements(infringer)
.map(Into::into) .map(Into::into)
.chain( .chain(
self.locate_via_segment_infringements(infringer) self.locate_via_seg_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain(self.locate_via_via_infringements(infringer).map(Into::into)) .chain(self.locate_via_via_infringements(infringer).map(Into::into))
.chain( .chain(
self.locate_via_polygon_infringements(infringer) self.locate_via_poly_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
} }
@ -312,11 +312,11 @@ impl Layout {
self.locate_cross_infringements(infringer, self.joints_rtree().as_ref()) self.locate_cross_infringements(infringer, self.joints_rtree().as_ref())
} }
pub fn locate_via_segment_infringements( pub fn locate_via_seg_infringements(
&self, &self,
infringer: ViaId, infringer: ViaId,
) -> impl Iterator<Item = Infringement<ViaId, SegmentId>> + '_ { ) -> impl Iterator<Item = Infringement<ViaId, SegId>> + '_ {
self.locate_cross_infringements(infringer, self.segments_rtree().as_ref()) self.locate_cross_infringements(infringer, self.segs_rtree().as_ref())
} }
pub fn locate_via_via_infringements( pub fn locate_via_via_infringements(
@ -326,59 +326,59 @@ impl Layout {
self.locate_same_infringements(infringer, self.vias_rtree().as_ref()) self.locate_same_infringements(infringer, self.vias_rtree().as_ref())
} }
pub fn locate_via_polygon_infringements( pub fn locate_via_poly_infringements(
&self, &self,
infringer: ViaId, infringer: ViaId,
) -> impl Iterator<Item = Infringement<ViaId, PolygonId>> + '_ { ) -> impl Iterator<Item = Infringement<ViaId, PolyId>> + '_ {
self.locate_cross_infringements(infringer, self.polygons_rtree().as_ref()) self.locate_cross_infringements(infringer, self.polys_rtree().as_ref())
} }
pub fn locate_polygon_infringements( pub fn locate_poly_infringements(
&self, &self,
infringer: PolygonId, infringer: PolyId,
) -> impl Iterator<Item = Infringement<PolygonId>> + '_ { ) -> impl Iterator<Item = Infringement<PolyId>> + '_ {
self.locate_polygon_joint_infringements(infringer) self.locate_poly_joint_infringements(infringer)
.map(Into::into) .map(Into::into)
.chain( .chain(
self.locate_polygon_segment_infringements(infringer) self.locate_poly_seg_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
self.locate_polygon_via_infringements(infringer) self.locate_poly_via_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
.chain( .chain(
self.locate_polygon_polygon_infringements(infringer) self.locate_poly_poly_infringements(infringer)
.map(Into::into), .map(Into::into),
) )
} }
pub fn locate_polygon_joint_infringements( pub fn locate_poly_joint_infringements(
&self, &self,
infringer: PolygonId, infringer: PolyId,
) -> impl Iterator<Item = Infringement<PolygonId, JointId>> + '_ { ) -> impl Iterator<Item = Infringement<PolyId, JointId>> + '_ {
self.locate_cross_infringements(infringer, self.joints_rtree().as_ref()) self.locate_cross_infringements(infringer, self.joints_rtree().as_ref())
} }
pub fn locate_polygon_segment_infringements( pub fn locate_poly_seg_infringements(
&self, &self,
infringer: PolygonId, infringer: PolyId,
) -> impl Iterator<Item = Infringement<PolygonId, SegmentId>> + '_ { ) -> impl Iterator<Item = Infringement<PolyId, SegId>> + '_ {
self.locate_cross_infringements(infringer, self.segments_rtree().as_ref()) self.locate_cross_infringements(infringer, self.segs_rtree().as_ref())
} }
pub fn locate_polygon_via_infringements( pub fn locate_poly_via_infringements(
&self, &self,
infringer: PolygonId, infringer: PolyId,
) -> impl Iterator<Item = Infringement<PolygonId, ViaId>> + '_ { ) -> impl Iterator<Item = Infringement<PolyId, ViaId>> + '_ {
self.locate_cross_infringements(infringer, self.vias_rtree().as_ref()) self.locate_cross_infringements(infringer, self.vias_rtree().as_ref())
} }
pub fn locate_polygon_polygon_infringements( pub fn locate_poly_poly_infringements(
&self, &self,
infringer: PolygonId, infringer: PolyId,
) -> impl Iterator<Item = Infringement<PolygonId, PolygonId>> + '_ { ) -> impl Iterator<Item = Infringement<PolyId, PolyId>> + '_ {
self.locate_same_infringements(infringer, self.polygons_rtree().as_ref()) self.locate_same_infringements(infringer, self.polys_rtree().as_ref())
} }
fn locate_cross_infringements< fn locate_cross_infringements<
@ -429,27 +429,27 @@ impl Layout {
fn primitive_component(&self, primitive: PrimitiveId) -> Option<ComponentId> { fn primitive_component(&self, primitive: PrimitiveId) -> Option<ComponentId> {
match primitive { match primitive {
PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.component, PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.component,
PrimitiveId::Segment(segment_id) => self.segment(segment_id).spec.component, PrimitiveId::Seg(seg_id) => self.seg(seg_id).spec.component,
PrimitiveId::Via(via_id) => self.via(via_id).spec.component, PrimitiveId::Via(via_id) => self.via(via_id).spec.component,
PrimitiveId::Polygon(polygon_id) => self.polygon(polygon_id).spec.component, PrimitiveId::Poly(poly_id) => self.poly(poly_id).spec.component,
} }
} }
fn primitive_bbox_envelope(&self, primitive: PrimitiveId) -> AABB<[i64; 3]> { fn primitive_bbox_envelope(&self, primitive: PrimitiveId) -> AABB<[i64; 3]> {
match primitive { match primitive {
PrimitiveId::Joint(joint_id) => self.joint(joint_id).bbox().aabb(), PrimitiveId::Joint(joint_id) => self.joint(joint_id).bbox().aabb(),
PrimitiveId::Segment(segment_id) => self.segment(segment_id).bbox().aabb(), PrimitiveId::Seg(seg_id) => self.seg(seg_id).bbox().aabb(),
PrimitiveId::Via(via_id) => self.via(via_id).bbox().aabb(), PrimitiveId::Via(via_id) => self.via(via_id).bbox().aabb(),
PrimitiveId::Polygon(polygon_id) => self.polygon(polygon_id).bbox().aabb(), PrimitiveId::Poly(poly_id) => self.poly(poly_id).bbox().aabb(),
} }
} }
pub fn primitive_net(&self, primitive: PrimitiveId) -> Option<NetId> { pub fn primitive_net(&self, primitive: PrimitiveId) -> Option<NetId> {
match primitive { match primitive {
PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.net, PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.net,
PrimitiveId::Segment(segment_id) => self.segment(segment_id).net, PrimitiveId::Seg(seg_id) => self.seg(seg_id).net,
PrimitiveId::Via(via_id) => self.via(via_id).net, PrimitiveId::Via(via_id) => self.via(via_id).net,
PrimitiveId::Polygon(polygon_id) => self.polygon(polygon_id).spec.net, PrimitiveId::Poly(poly_id) => self.poly(poly_id).spec.net,
} }
} }

View File

@ -8,7 +8,7 @@ use crate::layout::{
Layout, Layout,
compounds::{Component, ComponentId, Pin, PinId, PinSpec}, compounds::{Component, ComponentId, Pin, PinId, PinSpec},
primitives::{ primitives::{
Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, Joint, JointId, JointSpec, Poly, PolyId, Seg, SegId, SegSpec, Via, ViaId,
ViaSpec, ViaSpec,
}, },
}; };
@ -59,8 +59,8 @@ impl Layout {
joint_id joint_id
} }
pub fn insert_segment(&mut self, spec: SegmentSpec) -> SegmentId { pub fn insert_seg(&mut self, spec: SegSpec) -> SegId {
self.insert_segment_raw(Segment { self.insert_seg_raw(Seg {
spec, spec,
endpoints: [ endpoints: [
self.joint(spec.endjoints[0]).spec.position, self.joint(spec.endjoints[0]).spec.position,
@ -71,36 +71,36 @@ impl Layout {
}) })
} }
pub fn insert_segment_raw(&mut self, segment: Segment) -> SegmentId { pub fn insert_seg_raw(&mut self, seg: Seg) -> SegId {
let component_id = segment.spec.component; let component_id = seg.spec.component;
let pin_id = segment.spec.pin; let pin_id = seg.spec.pin;
let bbox = segment.bbox(); let bbox = seg.bbox();
let segment_id = SegmentId::new(self.segments.push(segment)); let seg_id = SegId::new(self.segs.push(seg));
self.joints self.joints
.modify(segment.spec.endjoints[0].index(), |joint| { .modify(seg.spec.endjoints[0].index(), |joint| {
joint.segments.push(segment_id) joint.segs.push(seg_id)
}); });
self.joints self.joints
.modify(segment.spec.endjoints[1].index(), |joint| { .modify(seg.spec.endjoints[1].index(), |joint| {
joint.segments.push(segment_id) joint.segs.push(seg_id)
}); });
self.segments_rtree self.segs_rtree
.insert(GeomWithData::new(bbox.rtree_rectangle(), segment_id), ()); .insert(GeomWithData::new(bbox.rtree_rectangle(), seg_id), ());
if let Some(component_id) = component_id { if let Some(component_id) = component_id {
self.components.modify(component_id.index(), |component| { self.components.modify(component_id.index(), |component| {
component.segments.push(segment_id) component.segs.push(seg_id)
}); });
} }
if let Some(pin_id) = pin_id { if let Some(pin_id) = pin_id {
self.pins self.pins
.modify(pin_id.index(), |pin| pin.segments.push(segment_id)); .modify(pin_id.index(), |pin| pin.segs.push(seg_id));
} }
segment_id seg_id
} }
pub fn insert_via(&mut self, spec: ViaSpec) -> ViaId { pub fn insert_via(&mut self, spec: ViaSpec) -> ViaId {
@ -145,26 +145,26 @@ impl Layout {
via_id via_id
} }
pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId { pub fn insert_poly(&mut self, poly: Poly) -> PolyId {
let bbox = polygon.bbox(); let bbox = poly.bbox();
let component_id = polygon.spec.component; let component_id = poly.spec.component;
let pin_id = polygon.spec.pin; let pin_id = poly.spec.pin;
let polygon_id = PolygonId::new(self.polygons.push(polygon)); let poly_id = PolyId::new(self.polys.push(poly));
self.polygons_rtree self.polys_rtree
.insert(GeomWithData::new(bbox.rtree_rectangle(), polygon_id), ()); .insert(GeomWithData::new(bbox.rtree_rectangle(), poly_id), ());
if let Some(component_id) = component_id { if let Some(component_id) = component_id {
self.components.modify(component_id.index(), |component| { self.components.modify(component_id.index(), |component| {
component.polygons.push(polygon_id) component.polys.push(poly_id)
}); });
} }
if let Some(pin_id) = pin_id { if let Some(pin_id) = pin_id {
self.pins self.pins
.modify(pin_id.index(), |pin| pin.polygons.push(polygon_id)); .modify(pin_id.index(), |pin| pin.polys.push(poly_id));
} }
polygon_id poly_id
} }
} }

View File

@ -8,7 +8,7 @@ use crate::{
layout::{ layout::{
Layout, Layout,
compounds::NetId, compounds::NetId,
primitives::{JointId, PolygonId, SegmentId, ViaId}, primitives::{JointId, PolyId, SegId, ViaId},
}, },
rect::{Rect2, Rect3}, rect::{Rect2, Rect3},
vector::{Vector2, Vector3}, vector::{Vector2, Vector3},
@ -144,53 +144,53 @@ impl Layout {
}) })
} }
pub fn locate_segments_prefer_layer_at_point( pub fn locate_segs_prefer_layer_at_point(
&self, &self,
point: Vector3<i64>, point: Vector3<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let at_point = self.locate_segments_at_point(point).collect::<Vec<_>>(); let at_point = self.locate_segs_at_point(point).collect::<Vec<_>>();
let segments = if at_point.is_empty() { let segs = if at_point.is_empty() {
self.locate_segments_any_layer_at_point(point.xy()) self.locate_segs_any_layer_at_point(point.xy())
.collect() .collect()
} else { } else {
at_point at_point
}; };
segments.into_iter() segs.into_iter()
} }
pub fn locate_segments_at_point(&self, point: Vector3<i64>) -> impl Iterator<Item = SegmentId> { pub fn locate_segs_at_point(&self, point: Vector3<i64>) -> impl Iterator<Item = SegId> {
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_all_at_point(&[point.x, point.y, point.z]) .locate_all_at_point(&[point.x, point.y, point.z])
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| self.segment(segment_id).contains_point2(point.xy())) .filter(move |&seg_id| self.seg(seg_id).contains_point2(point.xy()))
} }
pub fn locate_segments_any_layer_at_point( pub fn locate_segs_any_layer_at_point(
&self, &self,
point: Vector2<i64>, point: Vector2<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let envelope = point.z_extruded_infinitely().aabb(); let envelope = point.z_extruded_infinitely().aabb();
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| self.segments[segment_id.index()].contains_point2(point)) .filter(move |&seg_id| self.segs[seg_id.index()].contains_point2(point))
} }
pub fn locate_segments_prefer_layer_intersecting_rect( pub fn locate_segs_prefer_layer_intersecting_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let at_point = self let at_point = self
.locate_segments_intersecting_rect(rect) .locate_segs_intersecting_rect(rect)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let joints = if at_point.is_empty() { let joints = if at_point.is_empty() {
self.locate_segments_any_layer_intersecting_rect(rect.xy()) self.locate_segs_any_layer_intersecting_rect(rect.xy())
.collect() .collect()
} else { } else {
at_point at_point
@ -199,44 +199,44 @@ impl Layout {
joints.into_iter() joints.into_iter()
} }
pub fn locate_segments_intersecting_rect( pub fn locate_segs_intersecting_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&rect.aabb()) .locate_in_envelope_intersecting(&rect.aabb())
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| { .filter(move |&seg_id| {
let segment = self.segment(segment_id); let seg = self.seg(seg_id);
rect.xy().intersects_polygon(&segment.bounding_rectangle()) rect.xy().intersects_poly(&seg.bounding_rectangle())
}) })
} }
pub fn locate_segments_any_layer_intersecting_rect( pub fn locate_segs_any_layer_intersecting_rect(
&self, &self,
rect: Rect2<i64>, rect: Rect2<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let envelope = rect.z_extruded_infinitely().aabb(); let envelope = rect.z_extruded_infinitely().aabb();
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| { .filter(move |&seg_id| {
let segment = self.segment(segment_id); let seg = self.seg(seg_id);
rect.intersects_polygon(&segment.bounding_rectangle()) rect.intersects_poly(&seg.bounding_rectangle())
}) })
} }
pub fn locate_segments_prefer_layer_inside_rect( pub fn locate_segs_prefer_layer_inside_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let at_point = self.locate_segments_inside_rect(rect).collect::<Vec<_>>(); let at_point = self.locate_segs_inside_rect(rect).collect::<Vec<_>>();
let joints = if at_point.is_empty() { let joints = if at_point.is_empty() {
self.locate_segments_any_layer_inside_rect(rect.xy()) self.locate_segs_any_layer_inside_rect(rect.xy())
.collect() .collect()
} else { } else {
at_point at_point
@ -245,30 +245,30 @@ impl Layout {
joints.into_iter() joints.into_iter()
} }
pub fn locate_segments_inside_rect(&self, rect: Rect3<i64>) -> impl Iterator<Item = SegmentId> { pub fn locate_segs_inside_rect(&self, rect: Rect3<i64>) -> impl Iterator<Item = SegId> {
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope(&rect.aabb()) .locate_in_envelope(&rect.aabb())
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| { .filter(move |&seg_id| {
let segment = self.segment(segment_id); let seg = self.seg(seg_id);
rect.xy().contains_polygon(&segment.bounding_rectangle()) rect.xy().contains_poly(&seg.bounding_rectangle())
}) })
} }
pub fn locate_segments_any_layer_inside_rect( pub fn locate_segs_any_layer_inside_rect(
&self, &self,
rect: Rect2<i64>, rect: Rect2<i64>,
) -> impl Iterator<Item = SegmentId> { ) -> impl Iterator<Item = SegId> {
let envelope = rect.z_extruded_infinitely().aabb(); let envelope = rect.z_extruded_infinitely().aabb();
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope(&envelope) .locate_in_envelope(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&segment_id| { .filter(move |&seg_id| {
let segment = self.segment(segment_id); let seg = self.seg(seg_id);
rect.contains_polygon(&segment.bounding_rectangle()) rect.contains_poly(&seg.bounding_rectangle())
}) })
} }
@ -395,133 +395,133 @@ impl Layout {
}) })
} }
pub fn locate_polygons_prefer_layer_at_point( pub fn locate_polys_prefer_layer_at_point(
&self, &self,
point: Vector3<i64>, point: Vector3<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let at_point = self.locate_polygons_at_point(point).collect::<Vec<_>>(); let at_point = self.locate_polys_at_point(point).collect::<Vec<_>>();
let polygons = if at_point.is_empty() { let polys = if at_point.is_empty() {
self.locate_polygons_any_layer_at_point(point.xy()) self.locate_polys_any_layer_at_point(point.xy())
.collect() .collect()
} else { } else {
at_point at_point
}; };
polygons.into_iter() polys.into_iter()
} }
pub fn locate_polygons_at_point(&self, point: Vector3<i64>) -> impl Iterator<Item = PolygonId> { pub fn locate_polys_at_point(&self, point: Vector3<i64>) -> impl Iterator<Item = PolyId> {
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_all_at_point(&[point.x, point.y, point.z]) .locate_all_at_point(&[point.x, point.y, point.z])
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| { .filter(move |&poly_id| {
self.polygons[polygon_id.index()].contains_point2(point.xy()) self.polys[poly_id.index()].contains_point2(point.xy())
}) })
} }
pub fn locate_polygons_any_layer_at_point( pub fn locate_polys_any_layer_at_point(
&self, &self,
point: Vector2<i64>, point: Vector2<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let envelope = point.z_extruded_infinitely().aabb(); let envelope = point.z_extruded_infinitely().aabb();
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| self.polygons[polygon_id.index()].contains_point2(point)) .filter(move |&poly_id| self.polys[poly_id.index()].contains_point2(point))
} }
pub fn locate_polygons_prefer_layer_intersecting_rect( pub fn locate_polys_prefer_layer_intersecting_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let at_rect = self let at_rect = self
.locate_polygons_intersecting_rect(rect) .locate_polys_intersecting_rect(rect)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let polygons = if at_rect.is_empty() { let polys = if at_rect.is_empty() {
self.locate_polygons_any_layer_intersecting_rect(rect.xy()) self.locate_polys_any_layer_intersecting_rect(rect.xy())
.collect() .collect()
} else { } else {
at_rect at_rect
}; };
polygons.into_iter() polys.into_iter()
} }
pub fn locate_polygons_intersecting_rect( pub fn locate_polys_intersecting_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&rect.aabb()) .locate_in_envelope_intersecting(&rect.aabb())
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| { .filter(move |&poly_id| {
let polygon = self.polygon(polygon_id); let poly = self.poly(poly_id);
rect.xy().intersects_polygon(&polygon.spec.vertices) rect.xy().intersects_poly(&poly.spec.vertices)
}) })
} }
pub fn locate_polygons_any_layer_intersecting_rect( pub fn locate_polys_any_layer_intersecting_rect(
&self, &self,
rect: Rect2<i64>, rect: Rect2<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let envelope = rect.z_extruded_infinitely().aabb(); let envelope = rect.z_extruded_infinitely().aabb();
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| { .filter(move |&poly_id| {
let polygon = self.polygon(polygon_id); let poly = self.poly(poly_id);
rect.intersects_polygon(&polygon.spec.vertices) rect.intersects_poly(&poly.spec.vertices)
}) })
} }
pub fn locate_polygons_prefer_layer_inside_rect( pub fn locate_polys_prefer_layer_inside_rect(
&self, &self,
rect: Rect3<i64>, rect: Rect3<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let at_rect = self.locate_polygons_inside_rect(rect).collect::<Vec<_>>(); let at_rect = self.locate_polys_inside_rect(rect).collect::<Vec<_>>();
let polygons = if at_rect.is_empty() { let polys = if at_rect.is_empty() {
self.locate_polygons_any_layer_inside_rect(rect.xy()) self.locate_polys_any_layer_inside_rect(rect.xy())
.collect() .collect()
} else { } else {
at_rect at_rect
}; };
polygons.into_iter() polys.into_iter()
} }
pub fn locate_polygons_inside_rect(&self, rect: Rect3<i64>) -> impl Iterator<Item = PolygonId> { pub fn locate_polys_inside_rect(&self, rect: Rect3<i64>) -> impl Iterator<Item = PolyId> {
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope(&rect.aabb()) .locate_in_envelope(&rect.aabb())
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| { .filter(move |&poly_id| {
let polygon = self.polygon(polygon_id); let poly = self.poly(poly_id);
rect.xy().contains_polygon(&polygon.spec.vertices) rect.xy().contains_poly(&poly.spec.vertices)
}) })
} }
pub fn locate_polygons_any_layer_inside_rect( pub fn locate_polys_any_layer_inside_rect(
&self, &self,
rect: Rect2<i64>, rect: Rect2<i64>,
) -> impl Iterator<Item = PolygonId> { ) -> impl Iterator<Item = PolyId> {
let envelope = rect.z_extruded_infinitely().aabb(); let envelope = rect.z_extruded_infinitely().aabb();
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope(&envelope) .locate_in_envelope(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&polygon_id| { .filter(move |&poly_id| {
let polygon = self.polygon(polygon_id); let poly = self.poly(poly_id);
rect.contains_polygon(&polygon.spec.vertices) rect.contains_poly(&poly.spec.vertices)
}) })
} }
@ -537,8 +537,8 @@ impl Layout {
} }
} }
for segment_id in self.locate_segments_prefer_layer_intersecting_rect(rect) { for seg_id in self.locate_segs_prefer_layer_intersecting_rect(rect) {
if let Some(net) = self.segment(segment_id).net { if let Some(net) = self.seg(seg_id).net {
nets.insert(net); nets.insert(net);
} }
} }
@ -549,8 +549,8 @@ impl Layout {
} }
} }
for polygon_id in self.locate_polygons_prefer_layer_intersecting_rect(rect) { for poly_id in self.locate_polys_prefer_layer_intersecting_rect(rect) {
if let Some(net) = self.polygon(polygon_id).spec.net { if let Some(net) = self.poly(poly_id).spec.net {
nets.insert(net); nets.insert(net);
} }
} }
@ -567,8 +567,8 @@ impl Layout {
} }
} }
for segment_id in self.locate_segments_intersecting_rect(rect) { for seg_id in self.locate_segs_intersecting_rect(rect) {
if let Some(net) = self.segment(segment_id).net { if let Some(net) = self.seg(seg_id).net {
nets.insert(net); nets.insert(net);
} }
} }
@ -579,8 +579,8 @@ impl Layout {
} }
} }
for polygon_id in self.locate_polygons_intersecting_rect(rect) { for poly_id in self.locate_polys_intersecting_rect(rect) {
if let Some(net) = self.polygon(polygon_id).spec.net { if let Some(net) = self.poly(poly_id).spec.net {
nets.insert(net); nets.insert(net);
} }
} }
@ -600,8 +600,8 @@ impl Layout {
} }
} }
for segment_id in self.locate_segments_prefer_layer_inside_rect(rect) { for seg_id in self.locate_segs_prefer_layer_inside_rect(rect) {
if let Some(net) = self.segment(segment_id).net { if let Some(net) = self.seg(seg_id).net {
nets.insert(net); nets.insert(net);
} }
} }
@ -612,8 +612,8 @@ impl Layout {
} }
} }
for polygon_id in self.locate_polygons_prefer_layer_inside_rect(rect) { for poly_id in self.locate_polys_prefer_layer_inside_rect(rect) {
if let Some(net) = self.polygon(polygon_id).spec.net { if let Some(net) = self.poly(poly_id).spec.net {
nets.insert(net); nets.insert(net);
} }
} }
@ -630,8 +630,8 @@ impl Layout {
} }
} }
for segment_id in self.locate_segments_inside_rect(rect) { for seg_id in self.locate_segs_inside_rect(rect) {
if let Some(net) = self.segment(segment_id).net { if let Some(net) = self.seg(seg_id).net {
nets.insert(net); nets.insert(net);
} }
} }
@ -642,8 +642,8 @@ impl Layout {
} }
} }
for polygon_id in self.locate_polygons_inside_rect(rect) { for poly_id in self.locate_polys_inside_rect(rect) {
if let Some(net) = self.polygon(polygon_id).spec.net { if let Some(net) = self.poly(poly_id).spec.net {
nets.insert(net); nets.insert(net);
} }
} }

View File

@ -30,7 +30,7 @@ use undoredo::{Delta, Recorder};
use crate::{ use crate::{
layout::{ layout::{
compounds::{Component, ComponentId, Net, Pin, PinId}, compounds::{Component, ComponentId, Net, Pin, PinId},
primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId}, primitives::{Joint, JointId, Poly, PolyId, Seg, SegId, Via, ViaId},
}, },
vector::Vector2, vector::Vector2,
}; };
@ -72,25 +72,25 @@ pub struct Layout {
pins: Recorder<StableVec<Pin>>, pins: Recorder<StableVec<Pin>>,
joints: Recorder<StableVec<Joint>>, joints: Recorder<StableVec<Joint>>,
segments: Recorder<StableVec<Segment>>, segs: Recorder<StableVec<Seg>>,
vias: Recorder<StableVec<Via>>, vias: Recorder<StableVec<Via>>,
polygons: Recorder<StableVec<Polygon>>, polys: Recorder<StableVec<Poly>>,
joints_rtree: Recorder< joints_rtree: Recorder<
RTree<GeomWithData<Rectangle<[i64; 3]>, JointId>>, RTree<GeomWithData<Rectangle<[i64; 3]>, JointId>>,
RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, JointId>>, RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, JointId>>,
>, >,
segments_rtree: Recorder< segs_rtree: Recorder<
RTree<GeomWithData<Rectangle<[i64; 3]>, SegmentId>>, RTree<GeomWithData<Rectangle<[i64; 3]>, SegId>>,
RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, SegmentId>>, RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, SegId>>,
>, >,
vias_rtree: Recorder< vias_rtree: Recorder<
RTree<GeomWithData<Rectangle<[i64; 3]>, ViaId>>, RTree<GeomWithData<Rectangle<[i64; 3]>, ViaId>>,
RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, ViaId>>, RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, ViaId>>,
>, >,
polygons_rtree: Recorder< polys_rtree: Recorder<
RTree<GeomWithData<Rectangle<[i64; 3]>, PolygonId>>, RTree<GeomWithData<Rectangle<[i64; 3]>, PolyId>>,
RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, PolygonId>>, RTreeHalfDelta<GeomWithData<Rectangle<[i64; 3]>, PolyId>>,
>, >,
} }
@ -111,14 +111,14 @@ impl Layout {
pins: Recorder::new(StableVec::new()), pins: Recorder::new(StableVec::new()),
joints: Recorder::new(StableVec::new()), joints: Recorder::new(StableVec::new()),
segments: Recorder::new(StableVec::new()), segs: Recorder::new(StableVec::new()),
vias: Recorder::new(StableVec::new()), vias: Recorder::new(StableVec::new()),
polygons: Recorder::new(StableVec::new()), polys: Recorder::new(StableVec::new()),
joints_rtree: Recorder::new(RTree::new()), joints_rtree: Recorder::new(RTree::new()),
segments_rtree: Recorder::new(RTree::new()), segs_rtree: Recorder::new(RTree::new()),
vias_rtree: Recorder::new(RTree::new()), vias_rtree: Recorder::new(RTree::new()),
polygons_rtree: Recorder::new(RTree::new()), polys_rtree: Recorder::new(RTree::new()),
} }
} }
@ -131,13 +131,13 @@ impl Layout {
.filter(move |&id| self.joint(id).spec.layer == layer) .filter(move |&id| self.joint(id).spec.layer == layer)
} }
pub fn layer_segments(&self, layer: LayerId) -> impl Iterator<Item = SegmentId> + '_ { pub fn layer_segs(&self, layer: LayerId) -> impl Iterator<Item = SegId> + '_ {
let envelope = Self::whole_layer_aabb(layer); let envelope = Self::whole_layer_aabb(layer);
self.segments_rtree self.segs_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&id| self.segment(id).layer == layer) .filter(move |&id| self.seg(id).layer == layer)
} }
pub fn layer_vias(&self, layer: LayerId) -> impl Iterator<Item = ViaId> + '_ { pub fn layer_vias(&self, layer: LayerId) -> impl Iterator<Item = ViaId> + '_ {
@ -152,13 +152,13 @@ impl Layout {
}) })
} }
pub fn layer_polygons(&self, layer: LayerId) -> impl Iterator<Item = PolygonId> + '_ { pub fn layer_polys(&self, layer: LayerId) -> impl Iterator<Item = PolyId> + '_ {
let envelope = Self::whole_layer_aabb(layer); let envelope = Self::whole_layer_aabb(layer);
self.polygons_rtree self.polys_rtree
.as_ref() .as_ref()
.locate_in_envelope_intersecting(&envelope) .locate_in_envelope_intersecting(&envelope)
.map(|geom_with_data| geom_with_data.data) .map(|geom_with_data| geom_with_data.data)
.filter(move |&id| self.polygon(id).spec.layer == layer) .filter(move |&id| self.poly(id).spec.layer == layer)
} }
fn whole_layer_aabb(layer: LayerId) -> AABB<[i64; 3]> { fn whole_layer_aabb(layer: LayerId) -> AABB<[i64; 3]> {
@ -180,15 +180,15 @@ impl Layout {
&self.joints[joint_id.index()] &self.joints[joint_id.index()]
} }
pub fn segment(&self, segment_id: SegmentId) -> &Segment { pub fn seg(&self, seg_id: SegId) -> &Seg {
&self.segments[segment_id.index()] &self.segs[seg_id.index()]
} }
pub fn via(&self, via_id: ViaId) -> &Via { pub fn via(&self, via_id: ViaId) -> &Via {
&self.vias[via_id.index()] &self.vias[via_id.index()]
} }
pub fn polygon(&self, polygon_id: PolygonId) -> &Polygon { pub fn poly(&self, poly_id: PolyId) -> &Poly {
&self.polygons[polygon_id.index()] &self.polys[poly_id.index()]
} }
} }

View File

@ -7,7 +7,7 @@ use rstar::primitives::GeomWithData;
use crate::layout::{ use crate::layout::{
Layout, Layout,
primitives::{ primitives::{
Joint, JointId, JointSpec, Polygon, PolygonId, SegmentId, SegmentSpec, ViaId, ViaSpec, Joint, JointId, JointSpec, Poly, PolyId, SegId, SegSpec, ViaId, ViaSpec,
}, },
}; };
@ -19,8 +19,8 @@ impl Layout {
self.modify_joint_raw(id, |joint| f(&mut joint.spec)); self.modify_joint_raw(id, |joint| f(&mut joint.spec));
let new_joint = self.joints[id.index()].clone(); let new_joint = self.joints[id.index()].clone();
for &segment_id in &new_joint.segments { for &seg_id in &new_joint.segs {
self.update_segment(segment_id); self.update_seg(seg_id);
} }
for &via_id in &new_joint.vias { for &via_id in &new_joint.vias {
@ -45,43 +45,43 @@ impl Layout {
); );
} }
pub fn modify_segment<F>(&mut self, id: SegmentId, f: F) pub fn modify_seg<F>(&mut self, id: SegId, f: F)
where where
F: FnOnce(&mut SegmentSpec), F: FnOnce(&mut SegSpec),
{ {
let old_segment = &self.segments[id.index()]; let old_seg = &self.segs[id.index()];
self.segments_rtree self.segs_rtree
.remove(&GeomWithData::new(old_segment.bbox().rtree_rectangle(), id)); .remove(&GeomWithData::new(old_seg.bbox().rtree_rectangle(), id));
self.segments self.segs
.modify(id.index(), |segment| f(&mut segment.spec)); .modify(id.index(), |seg| f(&mut seg.spec));
let new_segment = &self.segments[id.index()]; let new_seg = &self.segs[id.index()];
self.segments_rtree.insert( self.segs_rtree.insert(
GeomWithData::new(new_segment.bbox().rtree_rectangle(), id), GeomWithData::new(new_seg.bbox().rtree_rectangle(), id),
(), (),
); );
} }
pub(super) fn update_segment(&mut self, id: SegmentId) { pub(super) fn update_seg(&mut self, id: SegId) {
let old_segment = &self.segments[id.index()]; let old_seg = &self.segs[id.index()];
self.segments_rtree self.segs_rtree
.remove(&GeomWithData::new(old_segment.bbox().rtree_rectangle(), id)); .remove(&GeomWithData::new(old_seg.bbox().rtree_rectangle(), id));
let endjoint_ids = old_segment.spec.endjoints; let endjoint_ids = old_seg.spec.endjoints;
let endjoint_specs = [ let endjoint_specs = [
self.joints[endjoint_ids[0].index()].spec, self.joints[endjoint_ids[0].index()].spec,
self.joints[endjoint_ids[1].index()].spec, self.joints[endjoint_ids[1].index()].spec,
]; ];
self.segments.modify(id.index(), |segment| { self.segs.modify(id.index(), |seg| {
segment.endpoints = [endjoint_specs[0].position, endjoint_specs[1].position]; seg.endpoints = [endjoint_specs[0].position, endjoint_specs[1].position];
segment.layer = endjoint_specs[0].layer; seg.layer = endjoint_specs[0].layer;
segment.net = endjoint_specs[0].net; seg.net = endjoint_specs[0].net;
}); });
let new_segment = &self.segments[id.index()]; let new_seg = &self.segs[id.index()];
self.segments_rtree.insert( self.segs_rtree.insert(
GeomWithData::new(new_segment.bbox().rtree_rectangle(), id), GeomWithData::new(new_seg.bbox().rtree_rectangle(), id),
(), (),
); );
} }
@ -123,19 +123,19 @@ impl Layout {
.insert(GeomWithData::new(new_via.bbox().rtree_rectangle(), id), ()); .insert(GeomWithData::new(new_via.bbox().rtree_rectangle(), id), ());
} }
pub fn modify_polygon<F>(&mut self, id: PolygonId, f: F) pub fn modify_poly<F>(&mut self, id: PolyId, f: F)
where where
F: FnOnce(&mut Polygon), F: FnOnce(&mut Poly),
{ {
let old_polygon = &self.polygons[id.index()]; let old_poly = &self.polys[id.index()];
self.polygons_rtree self.polys_rtree
.remove(&GeomWithData::new(old_polygon.bbox().rtree_rectangle(), id)); .remove(&GeomWithData::new(old_poly.bbox().rtree_rectangle(), id));
self.polygons.modify(id.index(), |polygon| f(polygon)); self.polys.modify(id.index(), |poly| f(poly));
let new_polygon = &self.polygons[id.index()]; let new_poly = &self.polys[id.index()];
self.polygons_rtree.insert( self.polys_rtree.insert(
GeomWithData::new(new_polygon.bbox().rtree_rectangle(), id), GeomWithData::new(new_poly.bbox().rtree_rectangle(), id),
(), (),
); );
} }

View File

@ -6,7 +6,7 @@ use crate::{
Rect2, Rect2,
layout::{ layout::{
Layout, Layout,
primitives::{JointId, PolygonId, SegmentId, ViaId}, primitives::{JointId, PolyId, SegId, ViaId},
}, },
}; };
@ -22,13 +22,13 @@ impl Layout {
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn joint_segment_rect_overlap( pub fn joint_seg_rect_overlap(
&self, &self,
infringer: JointId, infringer: JointId,
infringee: SegmentId, infringee: SegId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.joint(infringer).bbox().xy(); let infringer_bbox = self.joint(infringer).bbox().xy();
let infringee_bbox = self.segment(infringee).bbox().xy(); let infringee_bbox = self.seg(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
@ -44,57 +44,57 @@ impl Layout {
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn joint_polygon_rect_overlap( pub fn joint_poly_rect_overlap(
&self, &self,
infringer: JointId, infringer: JointId,
infringee: PolygonId, infringee: PolyId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.joint(infringer).bbox().xy(); let infringer_bbox = self.joint(infringer).bbox().xy();
let infringee_bbox = self.polygon(infringee).bbox().xy(); let infringee_bbox = self.poly(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn segment_joint_rect_overlap( pub fn seg_joint_rect_overlap(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: JointId, infringee: JointId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.segment(infringer).bbox().xy(); let infringer_bbox = self.seg(infringer).bbox().xy();
let infringee_bbox = self.joint(infringee).bbox().xy(); let infringee_bbox = self.joint(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn segment_segment_rect_overlap( pub fn seg_seg_rect_overlap(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: SegmentId, infringee: SegId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.segment(infringer).bbox().xy(); let infringer_bbox = self.seg(infringer).bbox().xy();
let infringee_bbox = self.segment(infringee).bbox().xy(); let infringee_bbox = self.seg(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn segment_via_rect_overlap( pub fn seg_via_rect_overlap(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: ViaId, infringee: ViaId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.segment(infringer).bbox().xy(); let infringer_bbox = self.seg(infringer).bbox().xy();
let infringee_bbox = self.via(infringee).bbox().xy(); let infringee_bbox = self.via(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn segment_polygon_rect_overlap( pub fn seg_poly_rect_overlap(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: PolygonId, infringee: PolyId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.segment(infringer).bbox().xy(); let infringer_bbox = self.seg(infringer).bbox().xy();
let infringee_bbox = self.polygon(infringee).bbox().xy(); let infringee_bbox = self.poly(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
@ -110,13 +110,13 @@ impl Layout {
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn via_segment_rect_overlap( pub fn via_seg_rect_overlap(
&self, &self,
infringer: ViaId, infringer: ViaId,
infringee: SegmentId, infringee: SegId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.via(infringer).bbox().xy(); let infringer_bbox = self.via(infringer).bbox().xy();
let infringee_bbox = self.segment(infringee).bbox().xy(); let infringee_bbox = self.seg(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
@ -128,57 +128,57 @@ impl Layout {
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn via_polygon_rect_overlap( pub fn via_poly_rect_overlap(
&self, &self,
infringer: ViaId, infringer: ViaId,
infringee: PolygonId, infringee: PolyId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.via(infringer).bbox().xy(); let infringer_bbox = self.via(infringer).bbox().xy();
let infringee_bbox = self.polygon(infringee).bbox().xy(); let infringee_bbox = self.poly(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn polygon_joint_rect_overlap( pub fn poly_joint_rect_overlap(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: JointId, infringee: JointId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.polygon(infringer).bbox().xy(); let infringer_bbox = self.poly(infringer).bbox().xy();
let infringee_bbox = self.joint(infringee).bbox().xy(); let infringee_bbox = self.joint(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn polygon_segment_rect_overlap( pub fn poly_seg_rect_overlap(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: SegmentId, infringee: SegId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.polygon(infringer).bbox().xy(); let infringer_bbox = self.poly(infringer).bbox().xy();
let infringee_bbox = self.segment(infringee).bbox().xy(); let infringee_bbox = self.seg(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn polygon_via_rect_overlap( pub fn poly_via_rect_overlap(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: ViaId, infringee: ViaId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.polygon(infringer).bbox().xy(); let infringer_bbox = self.poly(infringer).bbox().xy();
let infringee_bbox = self.via(infringee).bbox().xy(); let infringee_bbox = self.via(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }
pub fn polygon_polygon_rect_overlap( pub fn poly_poly_rect_overlap(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: PolygonId, infringee: PolyId,
) -> Option<Rect2<i64>> { ) -> Option<Rect2<i64>> {
let infringer_bbox = self.polygon(infringer).bbox().xy(); let infringer_bbox = self.poly(infringer).bbox().xy();
let infringee_bbox = self.polygon(infringee).bbox().xy(); let infringee_bbox = self.poly(infringee).bbox().xy();
infringer_bbox.intersection(infringee_bbox) infringer_bbox.intersection(infringee_bbox)
} }

View File

@ -6,7 +6,7 @@ use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::layout::compounds::{ComponentId, NetId, PinId}; use crate::layout::compounds::{ComponentId, NetId, PinId};
use crate::layout::primitives::{SegmentId, ViaId}; use crate::layout::primitives::{SegId, ViaId};
use crate::vector::Vector2; use crate::vector::Vector2;
use crate::{Rect3, Vector3, layout::LayerId}; use crate::{Rect3, Vector3, layout::LayerId};
@ -47,7 +47,7 @@ pub struct JointSpec {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Joint { pub struct Joint {
pub spec: JointSpec, pub spec: JointSpec,
pub segments: Vec<SegmentId>, pub segs: Vec<SegId>,
pub vias: Vec<ViaId>, pub vias: Vec<ViaId>,
} }
@ -55,7 +55,7 @@ impl Joint {
pub fn new(spec: JointSpec) -> Self { pub fn new(spec: JointSpec) -> Self {
Joint { Joint {
spec, spec,
segments: Vec::new(), segs: Vec::new(),
vias: Vec::new(), vias: Vec::new(),
} }
} }

View File

@ -6,13 +6,13 @@ use derive_more::From;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
mod joint; mod joint;
mod polygon; mod poly;
mod segment; mod seg;
mod via; mod via;
pub use joint::*; pub use joint::*;
pub use polygon::*; pub use poly::*;
pub use segment::*; pub use seg::*;
pub use via::*; pub use via::*;
use crate::{ use crate::{
@ -23,27 +23,27 @@ use crate::{
#[derive(Clone, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize)]
pub enum PrimitiveId { pub enum PrimitiveId {
Joint(JointId), Joint(JointId),
Segment(SegmentId), Seg(SegId),
Via(ViaId), Via(ViaId),
Polygon(PolygonId), Poly(PolyId),
} }
impl Layout { impl Layout {
pub fn primitive_pin(&self, primitive: PrimitiveId) -> Option<PinId> { pub fn primitive_pin(&self, primitive: PrimitiveId) -> Option<PinId> {
match primitive { match primitive {
PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.pin, PrimitiveId::Joint(joint_id) => self.joint(joint_id).spec.pin,
PrimitiveId::Segment(segment_id) => self.segment(segment_id).spec.pin, PrimitiveId::Seg(seg_id) => self.seg(seg_id).spec.pin,
PrimitiveId::Via(via_id) => self.via(via_id).spec.pin, PrimitiveId::Via(via_id) => self.via(via_id).spec.pin,
PrimitiveId::Polygon(polygon_id) => self.polygon(polygon_id).spec.pin, PrimitiveId::Poly(poly_id) => self.poly(poly_id).spec.pin,
} }
} }
pub fn primitive_bbox2(&self, primitive: PrimitiveId) -> Rect2<i64> { pub fn primitive_bbox2(&self, primitive: PrimitiveId) -> Rect2<i64> {
match primitive { match primitive {
PrimitiveId::Joint(joint_id) => self.joint(joint_id).bbox().xy(), PrimitiveId::Joint(joint_id) => self.joint(joint_id).bbox().xy(),
PrimitiveId::Segment(segment_id) => self.segment(segment_id).bbox().xy(), PrimitiveId::Seg(seg_id) => self.seg(seg_id).bbox().xy(),
PrimitiveId::Via(via_id) => self.via(via_id).bbox().xy(), PrimitiveId::Via(via_id) => self.via(via_id).bbox().xy(),
PrimitiveId::Polygon(polygon_id) => self.polygon(polygon_id).bbox().xy(), PrimitiveId::Poly(poly_id) => self.poly(poly_id).bbox().xy(),
} }
} }
} }

View File

@ -23,9 +23,9 @@ use crate::{Rect3, Vector3, layout::LayerId};
PartialOrd, PartialOrd,
Serialize, Serialize,
)] )]
pub struct PolygonId(usize); pub struct PolyId(usize);
impl PolygonId { impl PolyId {
/// Returns the underlying index. /// Returns the underlying index.
#[inline] #[inline]
pub fn index(self) -> usize { pub fn index(self) -> usize {
@ -34,7 +34,7 @@ impl PolygonId {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PolygonSpec { pub struct PolySpec {
pub vertices: Vec<Vector2<i64>>, pub vertices: Vec<Vector2<i64>>,
pub layer: LayerId, pub layer: LayerId,
pub net: Option<NetId>, pub net: Option<NetId>,
@ -43,12 +43,19 @@ pub struct PolygonSpec {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Polygon { pub struct Poly {
pub spec: PolygonSpec, pub spec: PolySpec,
pub centroid: Vector2<i64>, pub centroid: Vector2<i64>,
} }
impl Polygon { impl Poly {
pub fn new(spec: PolySpec) -> Self {
Self {
centroid: Vector2::<i64>::poly_centroid(&spec.vertices),
spec,
}
}
pub fn bbox(&self) -> Rect3<i64> { pub fn bbox(&self) -> Rect3<i64> {
let layer = self.spec.layer.index() as i64; let layer = self.spec.layer.index() as i64;
let mut min = Vector2::new(i64::MAX, i64::MAX); let mut min = Vector2::new(i64::MAX, i64::MAX);

View File

@ -9,7 +9,7 @@ use crate::layout::compounds::{ComponentId, NetId, PinId};
use crate::vector::Vector2; use crate::vector::Vector2;
use crate::{Rect3, Vector3, layout::LayerId}; use crate::{Rect3, Vector3, layout::LayerId};
use super::JointId; use super::{Joint, JointId};
#[derive( #[derive(
Clone, Clone,
@ -25,9 +25,9 @@ use super::JointId;
PartialOrd, PartialOrd,
Serialize, Serialize,
)] )]
pub struct SegmentId(usize); pub struct SegId(usize);
impl SegmentId { impl SegId {
/// Returns the underlying index. /// Returns the underlying index.
#[inline] #[inline]
pub fn index(self) -> usize { pub fn index(self) -> usize {
@ -36,7 +36,7 @@ impl SegmentId {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct SegmentSpec { pub struct SegSpec {
pub endjoints: [JointId; 2], pub endjoints: [JointId; 2],
pub half_width: u64, pub half_width: u64,
pub component: Option<ComponentId>, pub component: Option<ComponentId>,
@ -44,20 +44,29 @@ pub struct SegmentSpec {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Segment { pub struct Seg {
pub spec: SegmentSpec, pub spec: SegSpec,
pub endpoints: [Vector2<i64>; 2], pub endpoints: [Vector2<i64>; 2],
pub layer: LayerId, pub layer: LayerId,
pub net: Option<NetId>, pub net: Option<NetId>,
} }
impl Segment { impl Seg {
pub fn new(spec: SegSpec, endjoints: [&Joint; 2]) -> Self {
Self {
spec,
endpoints: [endjoints[0].spec.position, endjoints[1].spec.position],
layer: endjoints[0].spec.layer,
net: endjoints[0].spec.net,
}
}
pub fn center(&self) -> Vector2<i64> { pub fn center(&self) -> Vector2<i64> {
(self.endpoints[0] + self.endpoints[1]) / 2 (self.endpoints[0] + self.endpoints[1]) / 2
} }
pub fn contains_point2(&self, point: Vector2<i64>) -> bool { pub fn contains_point2(&self, point: Vector2<i64>) -> bool {
let vertices = crate::math::inflated_segment( let vertices = crate::math::inflated_seg(
self.endpoints[0].x, self.endpoints[0].x,
self.endpoints[0].y, self.endpoints[0].y,
self.endpoints[1].x, self.endpoints[1].x,
@ -70,7 +79,7 @@ impl Segment {
/// NOTE: This is not the bounding box. The output rectangle is in general /// NOTE: This is not the bounding box. The output rectangle is in general
/// not axis-aligned. /// not axis-aligned.
pub fn bounding_rectangle(&self) -> [Vector2<i64>; 4] { pub fn bounding_rectangle(&self) -> [Vector2<i64>; 4] {
crate::math::inflated_segment( crate::math::inflated_seg(
self.endpoints[0].x, self.endpoints[0].x,
self.endpoints[0].y, self.endpoints[0].y,
self.endpoints[1].x, self.endpoints[1].x,

View File

@ -7,7 +7,7 @@ use crate::{
layout::{ layout::{
Layout, Layout,
compounds::{ComponentId, PinId}, compounds::{ComponentId, PinId},
primitives::{JointId, PolygonId, PrimitiveId, SegmentId, ViaId}, primitives::{JointId, PolyId, PrimitiveId, SegId, ViaId},
}, },
orientation::Orientation, orientation::Orientation,
rect::Rect2, rect::Rect2,
@ -97,14 +97,14 @@ impl Layout {
PrimitiveId::Joint(infringer) => { PrimitiveId::Joint(infringer) => {
self.joint_primitive_repulsion(infringer, infringee, orientation) self.joint_primitive_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Segment(infringer) => { PrimitiveId::Seg(infringer) => {
self.segment_primitive_repulsion(infringer, infringee, orientation) self.seg_primitive_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Via(infringer) => { PrimitiveId::Via(infringer) => {
self.via_primitive_repulsion(infringer, infringee, orientation) self.via_primitive_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Polygon(infringer) => { PrimitiveId::Poly(infringer) => {
self.polygon_primitive_repulsion(infringer, infringee, orientation) self.poly_primitive_repulsion(infringer, infringee, orientation)
} }
} }
} }
@ -123,16 +123,16 @@ impl Layout {
) )
} }
pub fn joint_segment_repulsion( pub fn joint_seg_repulsion(
&self, &self,
infringer: JointId, infringer: JointId,
infringee: SegmentId, infringee: SegId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.joint_segment_rect_overlap(infringer, infringee), self.joint_seg_rect_overlap(infringer, infringee),
self.joint(infringer).center(), self.joint(infringer).center(),
self.segment(infringee).center(), self.seg(infringee).center(),
orientation, orientation,
) )
} }
@ -151,16 +151,16 @@ impl Layout {
) )
} }
pub fn joint_polygon_repulsion( pub fn joint_poly_repulsion(
&self, &self,
infringer: JointId, infringer: JointId,
infringee: PolygonId, infringee: PolyId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.joint_polygon_rect_overlap(infringer, infringee), self.joint_poly_rect_overlap(infringer, infringee),
self.joint(infringer).center(), self.joint(infringer).center(),
self.polygon(infringee).centroid, self.poly(infringee).centroid,
orientation, orientation,
) )
} }
@ -175,92 +175,92 @@ impl Layout {
PrimitiveId::Joint(infringee) => { PrimitiveId::Joint(infringee) => {
self.joint_joint_repulsion(infringer, infringee, orientation) self.joint_joint_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Segment(infringee) => { PrimitiveId::Seg(infringee) => {
self.joint_segment_repulsion(infringer, infringee, orientation) self.joint_seg_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Via(infringee) => { PrimitiveId::Via(infringee) => {
self.joint_via_repulsion(infringer, infringee, orientation) self.joint_via_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Polygon(infringee) => { PrimitiveId::Poly(infringee) => {
self.joint_polygon_repulsion(infringer, infringee, orientation) self.joint_poly_repulsion(infringer, infringee, orientation)
} }
} }
} }
pub fn segment_joint_repulsion( pub fn seg_joint_repulsion(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: JointId, infringee: JointId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.segment_joint_rect_overlap(infringer, infringee), self.seg_joint_rect_overlap(infringer, infringee),
self.segment(infringer).center(), self.seg(infringer).center(),
self.joint(infringee).center(), self.joint(infringee).center(),
orientation, orientation,
) )
} }
pub fn segment_segment_repulsion( pub fn seg_seg_repulsion(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: SegmentId, infringee: SegId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.segment_segment_rect_overlap(infringer, infringee), self.seg_seg_rect_overlap(infringer, infringee),
self.segment(infringer).center(), self.seg(infringer).center(),
self.segment(infringee).center(), self.seg(infringee).center(),
orientation, orientation,
) )
} }
pub fn segment_via_repulsion( pub fn seg_via_repulsion(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: ViaId, infringee: ViaId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.segment_via_rect_overlap(infringer, infringee), self.seg_via_rect_overlap(infringer, infringee),
self.segment(infringer).center(), self.seg(infringer).center(),
self.via(infringee).position, self.via(infringee).position,
orientation, orientation,
) )
} }
pub fn segment_polygon_repulsion( pub fn seg_poly_repulsion(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: PolygonId, infringee: PolyId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.segment_polygon_rect_overlap(infringer, infringee), self.seg_poly_rect_overlap(infringer, infringee),
self.segment(infringer).center(), self.seg(infringer).center(),
self.polygon(infringee).centroid, self.poly(infringee).centroid,
orientation, orientation,
) )
} }
pub fn segment_primitive_repulsion( pub fn seg_primitive_repulsion(
&self, &self,
infringer: SegmentId, infringer: SegId,
infringee: PrimitiveId, infringee: PrimitiveId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
match infringee { match infringee {
PrimitiveId::Joint(infringee) => { PrimitiveId::Joint(infringee) => {
self.segment_joint_repulsion(infringer, infringee, orientation) self.seg_joint_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Segment(infringee) => { PrimitiveId::Seg(infringee) => {
self.segment_segment_repulsion(infringer, infringee, orientation) self.seg_seg_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Via(infringee) => { PrimitiveId::Via(infringee) => {
self.segment_via_repulsion(infringer, infringee, orientation) self.seg_via_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Polygon(infringee) => { PrimitiveId::Poly(infringee) => {
self.segment_polygon_repulsion(infringer, infringee, orientation) self.seg_poly_repulsion(infringer, infringee, orientation)
} }
} }
} }
@ -279,16 +279,16 @@ impl Layout {
) )
} }
pub fn via_segment_repulsion( pub fn via_seg_repulsion(
&self, &self,
infringer: ViaId, infringer: ViaId,
infringee: SegmentId, infringee: SegId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.via_segment_rect_overlap(infringer, infringee), self.via_seg_rect_overlap(infringer, infringee),
self.via(infringer).position, self.via(infringer).position,
self.segment(infringee).center(), self.seg(infringee).center(),
orientation, orientation,
) )
} }
@ -307,16 +307,16 @@ impl Layout {
) )
} }
pub fn via_polygon_repulsion( pub fn via_poly_repulsion(
&self, &self,
infringer: ViaId, infringer: ViaId,
infringee: PolygonId, infringee: PolyId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.via_polygon_rect_overlap(infringer, infringee), self.via_poly_rect_overlap(infringer, infringee),
self.via(infringer).position, self.via(infringer).position,
self.polygon(infringee).centroid, self.poly(infringee).centroid,
orientation, orientation,
) )
} }
@ -331,92 +331,92 @@ impl Layout {
PrimitiveId::Joint(infringee) => { PrimitiveId::Joint(infringee) => {
self.via_joint_repulsion(infringer, infringee, orientation) self.via_joint_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Segment(infringee) => { PrimitiveId::Seg(infringee) => {
self.via_segment_repulsion(infringer, infringee, orientation) self.via_seg_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Via(infringee) => { PrimitiveId::Via(infringee) => {
self.via_via_repulsion(infringer, infringee, orientation) self.via_via_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Polygon(infringee) => { PrimitiveId::Poly(infringee) => {
self.via_polygon_repulsion(infringer, infringee, orientation) self.via_poly_repulsion(infringer, infringee, orientation)
} }
} }
} }
pub fn polygon_joint_repulsion( pub fn poly_joint_repulsion(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: JointId, infringee: JointId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.polygon_joint_rect_overlap(infringer, infringee), self.poly_joint_rect_overlap(infringer, infringee),
self.polygon(infringer).centroid, self.poly(infringer).centroid,
self.joint(infringee).center(), self.joint(infringee).center(),
orientation, orientation,
) )
} }
pub fn polygon_segment_repulsion( pub fn poly_seg_repulsion(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: SegmentId, infringee: SegId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.polygon_segment_rect_overlap(infringer, infringee), self.poly_seg_rect_overlap(infringer, infringee),
self.polygon(infringer).centroid, self.poly(infringer).centroid,
self.segment(infringee).center(), self.seg(infringee).center(),
orientation, orientation,
) )
} }
pub fn polygon_via_repulsion( pub fn poly_via_repulsion(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: ViaId, infringee: ViaId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.polygon_via_rect_overlap(infringer, infringee), self.poly_via_rect_overlap(infringer, infringee),
self.polygon(infringer).centroid, self.poly(infringer).centroid,
self.via(infringee).position, self.via(infringee).position,
orientation, orientation,
) )
} }
pub fn polygon_polygon_repulsion( pub fn poly_poly_repulsion(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: PolygonId, infringee: PolyId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
Self::repulsion_from_rect_overlap( Self::repulsion_from_rect_overlap(
self.polygon_polygon_rect_overlap(infringer, infringee), self.poly_poly_rect_overlap(infringer, infringee),
self.polygon(infringer).centroid, self.poly(infringer).centroid,
self.polygon(infringee).centroid, self.poly(infringee).centroid,
orientation, orientation,
) )
} }
pub fn polygon_primitive_repulsion( pub fn poly_primitive_repulsion(
&self, &self,
infringer: PolygonId, infringer: PolyId,
infringee: PrimitiveId, infringee: PrimitiveId,
orientation: Orientation, orientation: Orientation,
) -> Vector2<i64> { ) -> Vector2<i64> {
match infringee { match infringee {
PrimitiveId::Joint(infringee) => { PrimitiveId::Joint(infringee) => {
self.polygon_joint_repulsion(infringer, infringee, orientation) self.poly_joint_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Segment(infringee) => { PrimitiveId::Seg(infringee) => {
self.polygon_segment_repulsion(infringer, infringee, orientation) self.poly_seg_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Via(infringee) => { PrimitiveId::Via(infringee) => {
self.polygon_via_repulsion(infringer, infringee, orientation) self.poly_via_repulsion(infringer, infringee, orientation)
} }
PrimitiveId::Polygon(infringee) => { PrimitiveId::Poly(infringee) => {
self.polygon_polygon_repulsion(infringer, infringee, orientation) self.poly_poly_repulsion(infringer, infringee, orientation)
} }
} }
} }

View File

@ -44,6 +44,6 @@ impl Layout {
return Vector2::new(0, 0); return Vector2::new(0, 0);
} }
violator.closest_point_on_polygon_boundary(boundary) - violator violator.closest_point_on_poly_boundary(boundary) - violator
} }
} }

View File

@ -21,21 +21,21 @@ impl Layout {
self.modify_joint_raw(joint_id, |joint| joint.spec.position += translation); self.modify_joint_raw(joint_id, |joint| joint.spec.position += translation);
} }
for &segment_id in &component.segments { for &seg_id in &component.segs {
self.update_segment(segment_id); self.update_seg(seg_id);
} }
for &via_id in &component.vias { for &via_id in &component.vias {
self.update_via(via_id); self.update_via(via_id);
} }
for &polygon_id in &component.polygons { for &poly_id in &component.polys {
self.modify_polygon(polygon_id, |polygon| { self.modify_poly(poly_id, |poly| {
polygon poly
.spec.vertices .spec.vertices
.iter_mut() .iter_mut()
.for_each(|vertex| *vertex += translation); .for_each(|vertex| *vertex += translation);
polygon.centroid += translation; poly.centroid += translation;
}); });
} }
} }

View File

@ -6,9 +6,9 @@ use polygon_unionfind::UnionFind;
use crate::Vector2; use crate::Vector2;
/// Returns the four vertices of a segment inflated by `half_width`, forming a /// Returns the four vertices of a seg inflated by `half_width`, forming a
/// convex quadrilateral. The segment goes from (x1, y1) to (x2, y2). /// convex quadrilateral. The seg goes from (x1, y1) to (x2, y2).
pub fn inflated_segment(x1: i64, y1: i64, x2: i64, y2: i64, half_width: u64) -> [Vector2<i64>; 4] { pub fn inflated_seg(x1: i64, y1: i64, x2: i64, y2: i64, half_width: u64) -> [Vector2<i64>; 4] {
let dx = x2 - x1; let dx = x2 - x1;
let dy = y2 - y1; let dy = y2 - y1;

View File

@ -13,7 +13,7 @@ use crate::{
board::Board, board::Board,
layout::{ layout::{
LayerId, LayerId,
primitives::{Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId}, primitives::{Joint, JointId, JointSpec, Poly, PolyId, Seg, SegId},
}, },
vector::Vector2, vector::Vector2,
}; };
@ -85,14 +85,14 @@ impl LayerNavmesher {
pub fn insert_multiobstacle( pub fn insert_multiobstacle(
&mut self, &mut self,
polygon: impl IntoIterator<Item = Vector2<i64>>, poly: impl IntoIterator<Item = Vector2<i64>>,
) -> usize { ) -> usize {
let polygon: Vec<Vector2<i64>> = polygon.into_iter().collect(); let poly: Vec<Vector2<i64>> = poly.into_iter().collect();
let mut index = 0; let mut index = 0;
for i in 0..self.navmeshes.len() { for i in 0..self.navmeshes.len() {
index = self.navmeshes[i].insert_obstacle_and_rebuild( index = self.navmeshes[i].insert_obstacle_and_rebuild(
Self::inflate_polygon(polygon.clone(), self.inflation_factors[i]) Self::inflate_poly(poly.clone(), self.inflation_factors[i])
.into_iter() .into_iter()
.map(Into::into), .map(Into::into),
self.boundary.iter().cloned().map(Into::into), self.boundary.iter().cloned().map(Into::into),
@ -102,15 +102,15 @@ impl LayerNavmesher {
index index
} }
fn inflate_polygon( fn inflate_poly(
polygon: Vec<Vector2<i64>>, poly: Vec<Vector2<i64>>,
inflation_factor: f64, inflation_factor: f64,
) -> impl IntoIterator<Item = Vector2<i64>> { ) -> impl IntoIterator<Item = Vector2<i64>> {
// Centroid. // Centroid.
let cx = polygon.iter().map(|p| p.x as f64).sum::<f64>() / polygon.len() as f64; let cx = poly.iter().map(|p| p.x as f64).sum::<f64>() / poly.len() as f64;
let cy = polygon.iter().map(|p| p.y as f64).sum::<f64>() / polygon.len() as f64; let cy = poly.iter().map(|p| p.y as f64).sum::<f64>() / poly.len() as f64;
polygon.into_iter().map(move |p| { poly.into_iter().map(move |p| {
let px = p.x as f64; let px = p.x as f64;
let py = p.y as f64; let py = p.y as f64;
// Delta. // Delta.
@ -198,8 +198,8 @@ pub struct NavmesherBoard {
board: Board, board: Board,
joint_multiobstacles: Recorder<StableVec<MultiObstacleId>>, joint_multiobstacles: Recorder<StableVec<MultiObstacleId>>,
segment_multiobstacles: Recorder<StableVec<MultiObstacleId>>, seg_multiobstacles: Recorder<StableVec<MultiObstacleId>>,
polygon_multiobstacles: Recorder<StableVec<MultiObstacleId>>, poly_multiobstacles: Recorder<StableVec<MultiObstacleId>>,
} }
impl NavmesherBoard { impl NavmesherBoard {
@ -212,8 +212,8 @@ impl NavmesherBoard {
board, board,
joint_multiobstacles: Recorder::new(StableVec::new()), joint_multiobstacles: Recorder::new(StableVec::new()),
segment_multiobstacles: Recorder::new(StableVec::new()), seg_multiobstacles: Recorder::new(StableVec::new()),
polygon_multiobstacles: Recorder::new(StableVec::new()), poly_multiobstacles: Recorder::new(StableVec::new()),
}; };
/*for (i, joint) in this.board.layout().joints().container().iter() { /*for (i, joint) in this.board.layout().joints().container().iter() {
@ -224,19 +224,19 @@ impl NavmesherBoard {
); );
} }
for (i, segment) in this.board.layout().segments().container().iter() { for (i, seg) in this.board.layout().segs().container().iter() {
this.segment_multiobstacles.insert( this.seg_multiobstacles.insert(
i, i,
this.navmesher this.navmesher
.insert_multiobstacle(segment.layer, segment.bounding_rectangle()), .insert_multiobstacle(seg.layer, seg.bounding_rectangle()),
); );
} }
for (i, polygon) in this.board.layout().polygons().container().iter() { for (i, poly) in this.board.layout().polys().container().iter() {
this.polygon_multiobstacles.insert( this.poly_multiobstacles.insert(
i, i,
this.navmesher this.navmesher
.insert_multiobstacle(polygon.spec.layer, polygon.spec.vertices.clone()), .insert_multiobstacle(poly.spec.layer, poly.spec.vertices.clone()),
); );
}*/ }*/
@ -247,7 +247,7 @@ impl NavmesherBoard {
let layer = spec.layer; let layer = spec.layer;
let obstacle = Self::joint_bounding_octagon(&Joint { let obstacle = Self::joint_bounding_octagon(&Joint {
spec, spec,
segments: Vec::new(), segs: Vec::new(),
vias: Vec::new(), vias: Vec::new(),
}); });
let joint_id = self.board.insert_joint(spec); let joint_id = self.board.insert_joint(spec);
@ -276,26 +276,26 @@ impl NavmesherBoard {
] ]
} }
pub fn insert_segment_with_cache(&mut self, segment: Segment) -> SegmentId { pub fn insert_seg_with_cache(&mut self, seg: Seg) -> SegId {
let layer = segment.layer; let layer = seg.layer;
let obstacle = segment.bounding_rectangle(); let obstacle = seg.bounding_rectangle();
let segment_id = self.board.insert_segment_raw(segment); let seg_id = self.board.insert_seg_raw(seg);
self.segment_multiobstacles.insert( self.seg_multiobstacles.insert(
segment_id.index(), seg_id.index(),
self.navmesher.insert_multiobstacle(layer, obstacle), self.navmesher.insert_multiobstacle(layer, obstacle),
); );
segment_id seg_id
} }
pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId { pub fn insert_poly(&mut self, poly: Poly) -> PolyId {
let polygon_id = self.board.insert_polygon(polygon.clone()); let poly_id = self.board.insert_poly(poly.clone());
self.polygon_multiobstacles.insert( self.poly_multiobstacles.insert(
polygon_id.index(), poly_id.index(),
self.navmesher self.navmesher
.insert_multiobstacle(polygon.spec.layer, polygon.spec.vertices), .insert_multiobstacle(poly.spec.layer, poly.spec.vertices),
); );
polygon_id poly_id
} }
} }

View File

@ -13,7 +13,7 @@ use crate::{
layout::{ layout::{
LayerId, LayerId,
compounds::NetId, compounds::NetId,
primitives::{JointId, PolygonId, PrimitiveId, SegmentId}, primitives::{JointId, PolyId, PrimitiveId, SegId},
}, },
vector::Vector2, vector::Vector2,
}; };
@ -68,39 +68,39 @@ impl Ratsnest {
}); });
} }
for (i, segment) in board.layout().segments().container().iter() { for (i, seg) in board.layout().segs().container().iter() {
let Some(net) = segment.net else { let Some(net) = seg.net else {
continue; continue;
}; };
let segment_center = segment.center(); let seg_center = seg.center();
let _ = triangulations let _ = triangulations
.entry((net, segment.layer)) .entry((net, seg.layer))
.or_insert_with(DelaunayTriangulation::new) .or_insert_with(DelaunayTriangulation::new)
.insert(DelaunayVertex { .insert(DelaunayVertex {
layer: segment.layer, layer: seg.layer,
center: segment_center, center: seg_center,
position: spade::Point2::new(segment_center.x as f64, segment_center.y as f64), position: spade::Point2::new(seg_center.x as f64, seg_center.y as f64),
primitive_id: PrimitiveId::Segment(SegmentId::new(i)), primitive_id: PrimitiveId::Seg(SegId::new(i)),
}); });
} }
for (i, polygon) in board.layout().polygons().container().iter() { for (i, poly) in board.layout().polys().container().iter() {
let Some(net) = polygon.spec.net else { let Some(net) = poly.spec.net else {
continue; continue;
}; };
let _ = triangulations let _ = triangulations
.entry((net, polygon.spec.layer)) .entry((net, poly.spec.layer))
.or_insert_with(DelaunayTriangulation::new) .or_insert_with(DelaunayTriangulation::new)
.insert(DelaunayVertex { .insert(DelaunayVertex {
layer: polygon.spec.layer, layer: poly.spec.layer,
center: polygon.centroid, center: poly.centroid,
position: spade::Point2::new( position: spade::Point2::new(
polygon.centroid.x as f64, poly.centroid.x as f64,
polygon.centroid.y as f64, poly.centroid.y as f64,
), ),
primitive_id: PrimitiveId::Polygon(PolygonId::new(i)), primitive_id: PrimitiveId::Poly(PolyId::new(i)),
}); });
} }

View File

@ -184,46 +184,46 @@ impl_rect2_intersects_circle!(u128);
impl_rect2_intersects_circle!(f32); impl_rect2_intersects_circle!(f32);
impl_rect2_intersects_circle!(f64); impl_rect2_intersects_circle!(f64);
macro_rules! impl_rect2_contains_polygon { macro_rules! impl_rect2_contains_poly {
($type:ty) => { ($type:ty) => {
impl Rect2<$type> { impl Rect2<$type> {
pub fn contains_polygon(&self, polygon: &[Vector2<$type>]) -> bool { pub fn contains_poly(&self, poly: &[Vector2<$type>]) -> bool {
let corners = self.corners(); let corners = self.corners();
polygon.iter().all(|point| point.inside_polygon(&corners)) poly.iter().all(|point| point.inside_polygon(&corners))
} }
} }
}; };
} }
impl_rect2_contains_polygon!(i8); impl_rect2_contains_poly!(i8);
impl_rect2_contains_polygon!(i16); impl_rect2_contains_poly!(i16);
impl_rect2_contains_polygon!(i32); impl_rect2_contains_poly!(i32);
impl_rect2_contains_polygon!(i64); impl_rect2_contains_poly!(i64);
impl_rect2_contains_polygon!(i128); impl_rect2_contains_poly!(i128);
impl_rect2_contains_polygon!(u8); impl_rect2_contains_poly!(u8);
impl_rect2_contains_polygon!(u16); impl_rect2_contains_poly!(u16);
impl_rect2_contains_polygon!(u32); impl_rect2_contains_poly!(u32);
impl_rect2_contains_polygon!(u64); impl_rect2_contains_poly!(u64);
impl_rect2_contains_polygon!(u128); impl_rect2_contains_poly!(u128);
impl_rect2_contains_polygon!(f32); impl_rect2_contains_poly!(f32);
impl_rect2_contains_polygon!(f64); impl_rect2_contains_poly!(f64);
macro_rules! impl_rect2_intersects_polygon { macro_rules! impl_rect2_intersects_poly {
($type:ty) => { ($type:ty) => {
impl Rect2<$type> { impl Rect2<$type> {
pub fn intersects_polygon(&self, polygon: &[Vector2<$type>]) -> bool { pub fn intersects_poly(&self, poly: &[Vector2<$type>]) -> bool {
if polygon.is_empty() { if poly.is_empty() {
return false; return false;
} }
if polygon.iter().any(|&vertex| self.contains_point(vertex)) { if poly.iter().any(|&vertex| self.contains_point(vertex)) {
return true; return true;
} }
if self if self
.corners() .corners()
.iter() .iter()
.any(|corner| corner.inside_polygon(polygon)) .any(|corner| corner.inside_polygon(poly))
{ {
return true; return true;
} }
@ -237,18 +237,18 @@ macro_rules! impl_rect2_intersects_polygon {
}; };
} }
impl_rect2_intersects_polygon!(i8); impl_rect2_intersects_poly!(i8);
impl_rect2_intersects_polygon!(i16); impl_rect2_intersects_poly!(i16);
impl_rect2_intersects_polygon!(i32); impl_rect2_intersects_poly!(i32);
impl_rect2_intersects_polygon!(i64); impl_rect2_intersects_poly!(i64);
impl_rect2_intersects_polygon!(i128); impl_rect2_intersects_poly!(i128);
impl_rect2_intersects_polygon!(u8); impl_rect2_intersects_poly!(u8);
impl_rect2_intersects_polygon!(u16); impl_rect2_intersects_poly!(u16);
impl_rect2_intersects_polygon!(u32); impl_rect2_intersects_poly!(u32);
impl_rect2_intersects_polygon!(u64); impl_rect2_intersects_poly!(u64);
impl_rect2_intersects_polygon!(u128); impl_rect2_intersects_poly!(u128);
impl_rect2_intersects_polygon!(f32); impl_rect2_intersects_poly!(f32);
impl_rect2_intersects_polygon!(f64); impl_rect2_intersects_poly!(f64);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Getters, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Getters, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Rect3<T> { pub struct Rect3<T> {

View File

@ -12,7 +12,7 @@ use specctra::{
use crate::{ use crate::{
board::{Board, LayerDesc, LayerSide, LayerType}, board::{Board, LayerDesc, LayerSide, LayerType},
layout::primitives::{JointSpec, Polygon, PolygonSpec, Segment, SegmentSpec}, layout::primitives::{JointSpec, Poly, PolySpec, Seg, SegSpec},
layout::{ layout::{
LayerId, LayerId,
compounds::{ComponentId, NetId, PinId, PinSpec}, compounds::{ComponentId, NetId, PinId, PinSpec},
@ -225,7 +225,7 @@ impl Board {
} }
Shape::Polygon(polygon) => { Shape::Polygon(polygon) => {
let layer = get_layer(&board, &polygon.layer); let layer = get_layer(&board, &polygon.layer);
Self::place_polygon( Self::place_poly(
&mut board, &mut board,
place.point_with_rotation(), place.point_with_rotation(),
pin.point_with_rotation(), pin.point_with_rotation(),
@ -306,7 +306,7 @@ impl Board {
} }
Shape::Polygon(polygon) => { Shape::Polygon(polygon) => {
let layer = get_layer(&board, &polygon.layer); let layer = get_layer(&board, &polygon.layer);
Self::place_polygon( Self::place_poly(
&mut board, &mut board,
PointWithRotation::from_xy(via.x, via.y), PointWithRotation::from_xy(via.x, via.y),
PointWithRotation::default(), PointWithRotation::default(),
@ -383,8 +383,8 @@ impl Board {
flip: bool, flip: bool,
coordinate_scale: f64, coordinate_scale: f64,
) { ) {
board.insert_polygon({ board.insert_poly({
let spec = PolygonSpec { let spec = PolySpec {
vertices: vec![ vertices: vec![
Self::pos(place, pin_pos, x1, y1, flip, coordinate_scale), Self::pos(place, pin_pos, x1, y1, flip, coordinate_scale),
Self::pos(place, pin_pos, x2, y1, flip, coordinate_scale), Self::pos(place, pin_pos, x2, y1, flip, coordinate_scale),
@ -396,9 +396,9 @@ impl Board {
component, component,
pin, pin,
}; };
let centroid = Vector2::<i64>::polygon_centroid(&spec.vertices); let centroid = Vector2::<i64>::poly_centroid(&spec.vertices);
Polygon { spec, centroid } Poly { spec, centroid }
}); });
} }
@ -448,8 +448,8 @@ impl Board {
pin, pin,
}); });
let _ = board.insert_segment_raw(Segment { let _ = board.insert_seg_raw(Seg {
spec: SegmentSpec { spec: SegSpec {
endjoints: [prev_joint, joint], endjoints: [prev_joint, joint],
half_width: Self::scale_size(width / 2.0, coordinate_scale), half_width: Self::scale_size(width / 2.0, coordinate_scale),
component, component,
@ -465,7 +465,7 @@ impl Board {
} }
} }
fn place_polygon( fn place_poly(
board: &mut Board, board: &mut Board,
place: PointWithRotation, place: PointWithRotation,
pin_pos: PointWithRotation, pin_pos: PointWithRotation,
@ -482,17 +482,17 @@ impl Board {
.iter() .iter()
.map(|coord| Self::pos(place, pin_pos, coord.x, coord.y, flip, coordinate_scale)) .map(|coord| Self::pos(place, pin_pos, coord.x, coord.y, flip, coordinate_scale))
.collect(); .collect();
board.insert_polygon({ board.insert_poly({
let spec = PolygonSpec { let spec = PolySpec {
vertices, vertices,
layer, layer,
net, net,
component, component,
pin, pin,
}; };
let centroid = Vector2::<i64>::polygon_centroid(&spec.vertices); let centroid = Vector2::<i64>::poly_centroid(&spec.vertices);
Polygon { spec, centroid } Poly { spec, centroid }
}); });
} }

View File

@ -73,19 +73,19 @@ impl<T: Bounded + Copy> Vector2<T> {
macro_rules! impl_vector2_inside_polygon { macro_rules! impl_vector2_inside_polygon {
($type:ty) => { ($type:ty) => {
impl Vector2<$type> { impl Vector2<$type> {
// Checks if the point is inside a polygon by casting a ray to the // Checks if the point is inside a poly by casting a ray to the
// right. Division is not used to avoid integer truncation errors. // right. Division is not used to avoid integer truncation errors.
pub fn inside_polygon(&self, polygon: &[Vector2<$type>]) -> bool { pub fn inside_polygon(&self, poly: &[Vector2<$type>]) -> bool {
let mut inside = false; let mut inside = false;
let n = polygon.len(); let n = poly.len();
// `self` is `v0`. // `self` is `v0`.
// `v1` is the previous vertex. // `v1` is the previous vertex.
let mut v1 = &polygon[n - 1]; let mut v1 = &poly[n - 1];
// `v2` is the current vertex. // `v2` is the current vertex.
for v2 in polygon.iter() { for v2 in poly.iter() {
let dx12 = v2.x - v1.x; let dx12 = v2.x - v1.x;
let dy12 = v2.y - v1.y; let dy12 = v2.y - v1.y;
@ -147,40 +147,40 @@ impl_vector2_inside_polygon!(f64);
macro_rules! impl_vector2_closest_point_on_boundary { macro_rules! impl_vector2_closest_point_on_boundary {
($type:ty) => { ($type:ty) => {
impl Vector2<$type> { impl Vector2<$type> {
pub fn closest_point_on_segment( pub fn closest_point_on_seg(
self, self,
segment_start: Vector2<$type>, seg_start: Vector2<$type>,
segment_end: Vector2<$type>, seg_end: Vector2<$type>,
) -> Vector2<$type> { ) -> Vector2<$type> {
let abx = segment_end.x - segment_start.x; let abx = seg_end.x - seg_start.x;
let aby = segment_end.y - segment_start.y; let aby = seg_end.y - seg_start.y;
let apx = self.x - segment_start.x; let apx = self.x - seg_start.x;
let apy = self.y - segment_start.y; let apy = self.y - seg_start.y;
let ab_len_sq = abx * abx + aby * aby; let ab_len_sq = abx * abx + aby * aby;
if ab_len_sq == 0 as $type { if ab_len_sq == 0 as $type {
return segment_start; return seg_start;
} }
let t = (apx * abx + apy * aby).clamp(0 as $type, ab_len_sq); let t = (apx * abx + apy * aby).clamp(0 as $type, ab_len_sq);
Vector2::new( Vector2::new(
segment_start.x + abx * t / ab_len_sq, seg_start.x + abx * t / ab_len_sq,
segment_start.y + aby * t / ab_len_sq, seg_start.y + aby * t / ab_len_sq,
) )
} }
pub fn closest_point_on_polygon_boundary( pub fn closest_point_on_poly_boundary(
self, self,
polygon: &[Vector2<$type>], poly: &[Vector2<$type>],
) -> Vector2<$type> { ) -> Vector2<$type> {
let mut closest_point = polygon[0]; let mut closest_point = poly[0];
let mut best_distance_sq = <$type as Bounded>::max_value(); let mut best_distance_sq = <$type as Bounded>::max_value();
for i in 0..polygon.len() { for i in 0..poly.len() {
let segment_start = polygon[i]; let seg_start = poly[i];
let segment_end = polygon[(i + 1) % polygon.len()]; let seg_end = poly[(i + 1) % poly.len()];
let candidate = self.closest_point_on_segment(segment_start, segment_end); let candidate = self.closest_point_on_seg(seg_start, seg_end);
let dx = self.x - candidate.x; let dx = self.x - candidate.x;
let dy = self.y - candidate.y; let dy = self.y - candidate.y;
let distance_sq = dx * dx + dy * dy; let distance_sq = dx * dx + dy * dy;
@ -243,35 +243,35 @@ macro_rules! impl_vector2_rotate_around_point {
impl_vector2_rotate_around_point!(f32); impl_vector2_rotate_around_point!(f32);
impl_vector2_rotate_around_point!(f64); impl_vector2_rotate_around_point!(f64);
macro_rules! impl_polygon_centroid { macro_rules! impl_poly_centroid {
($type:ty) => { ($type:ty) => {
impl Vector2<$type> { impl Vector2<$type> {
pub fn polygon_centroid(polygon: &[Vector2<$type>]) -> Self { pub fn poly_centroid(poly: &[Vector2<$type>]) -> Self {
crate::profile_function!(); crate::profile_function!();
let mut sum = Vector2::new(0 as $type, 0 as $type); let mut sum = Vector2::new(0 as $type, 0 as $type);
for vertex in polygon.iter() { for vertex in poly.iter() {
sum += *vertex; sum += *vertex;
} }
sum / polygon.len() as $type sum / poly.len() as $type
} }
} }
}; };
} }
impl_polygon_centroid!(i8); impl_poly_centroid!(i8);
impl_polygon_centroid!(i16); impl_poly_centroid!(i16);
impl_polygon_centroid!(i32); impl_poly_centroid!(i32);
impl_polygon_centroid!(i64); impl_poly_centroid!(i64);
impl_polygon_centroid!(i128); impl_poly_centroid!(i128);
impl_polygon_centroid!(u8); impl_poly_centroid!(u8);
impl_polygon_centroid!(u16); impl_poly_centroid!(u16);
impl_polygon_centroid!(u32); impl_poly_centroid!(u32);
impl_polygon_centroid!(u64); impl_poly_centroid!(u64);
impl_polygon_centroid!(u128); impl_poly_centroid!(u128);
impl_polygon_centroid!(f32); impl_poly_centroid!(f32);
impl_polygon_centroid!(f64); impl_poly_centroid!(f64);
#[derive( #[derive(
Add, Add,