diff --git a/crates/topola-egui/src/viewport.rs b/crates/topola-egui/src/viewport.rs index 09b94fe..9062715 100644 --- a/crates/topola-egui/src/viewport.rs +++ b/crates/topola-egui/src/viewport.rs @@ -19,6 +19,7 @@ use topola::{ primitive::MakePrimitiveShape, }, geometry::{shape::AccessShape, GenericNode}, + graph::MakeRef, layout::{poly::MakePolygon, via::ViaWeight}, math::Circle, }; @@ -176,7 +177,7 @@ impl Viewport { .normal }; - painter.paint_polygon(&board.layout().poly(poly).shape(), color) + painter.paint_polygon(&poly.ref_(board.layout()).shape(), color) } } } diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 70eaf41..a62dc1e 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -12,6 +12,7 @@ use thiserror::Error; use crate::{ board::{AccessMesadata, Board}, drawing::{band::BandTermsegIndex, dot::FixedDotIndex, Infringement}, + graph::MakeRef, layout::{via::ViaWeight, LayoutEdit}, router::{astar::AstarError, navmesh::NavmeshError, RouterOptions}, triangulation::GetTrianvertexNodeIndex, @@ -77,7 +78,7 @@ impl Autorouter { .node_index() { RatvertexIndex::FixedDot(dot) => dot, - RatvertexIndex::Poly(poly) => self.board.layout().poly(poly).apex(), + RatvertexIndex::Poly(poly) => poly.ref_(self.board.layout()).apex(), }; PointrouteExecutionStepper::new(self, origin_dot, point, options) @@ -195,7 +196,7 @@ impl Autorouter { .node_index() { RatvertexIndex::FixedDot(dot) => dot, - RatvertexIndex::Poly(poly) => self.board.layout().poly(poly).apex(), + RatvertexIndex::Poly(poly) => poly.ref_(self.board.layout()).apex(), }; let target_dot = match self @@ -206,7 +207,7 @@ impl Autorouter { .node_index() { RatvertexIndex::FixedDot(dot) => dot, - RatvertexIndex::Poly(poly) => self.board.layout().poly(poly).apex(), + RatvertexIndex::Poly(poly) => poly.ref_(self.board.layout()).apex(), }; (source_dot, target_dot) diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index f500124..8187d96 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -28,7 +28,7 @@ use crate::{ rules::AccessRules, }, geometry::shape::AccessShape, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetPetgraphIndex, MakeRef}, layout::{ poly::{MakePolygon, PolyWeight}, Layout, @@ -122,7 +122,7 @@ impl Ratsnest { handle_rvw( layout.drawing().compound_weight(poly.into()).maybe_net(), RatvertexIndex::Poly(poly), - layout.poly(poly).shape().center(), + poly.ref_(layout).shape().center(), )?; } } diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index de6d646..924df04 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -17,7 +17,7 @@ use crate::{ shape::{AccessShape, Shape}, GenericNode, GetLayer, }, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetPetgraphIndex, MakeRef}, layout::{poly::PolyWeight, CompoundWeight, NodeIndex}, }; @@ -39,9 +39,8 @@ impl PinSelector { NodeIndex::Compound(compound) => { if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound) { - board - .layout() - .poly(GenericIndex::::new(compound.petgraph_index())) + GenericIndex::::new(compound.petgraph_index()) + .ref_(board.layout()) .layer() } else { unreachable!() diff --git a/src/board/mod.rs b/src/board/mod.rs index 90b3199..b8a1c41 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -22,7 +22,7 @@ use crate::{ Collect, }, geometry::{edit::ApplyGeometryEdit, GenericNode, GetLayer}, - graph::GenericIndex, + graph::{GenericIndex, MakeRef}, layout::{poly::PolyWeight, CompoundWeight, Layout, LayoutEdit, NodeIndex}, }; @@ -47,9 +47,8 @@ impl<'a> ResolvedSelector<'a> { NodeIndex::Compound(compound) => { match board.layout().drawing().compound_weight(compound) { CompoundWeight::Poly(..) => ( - board - .layout() - .poly(GenericIndex::::new(compound.petgraph_index())) + GenericIndex::::new(compound.petgraph_index()) + .ref_(board.layout()) .layer(), None, ), diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 2718aeb..0a2f47c 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -34,9 +34,9 @@ use crate::{ shape::{AccessShape, Shape}, GenericNode, GetLayer, GetSetPos, }, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetPetgraphIndex, MakeRef}, layout::{ - poly::{is_apex, MakePolygon, Poly, PolyWeight}, + poly::{is_apex, MakePolygon, PolyWeight}, via::{Via, ViaWeight}, }, math::{Circle, LineIntersection, NormalLine}, @@ -292,7 +292,7 @@ impl Layout { ); } - let shape = self.poly(poly).shape(); + let shape = poly.ref_(self).shape(); let apex = self.add_fixed_dot_infringably( recorder, FixedDotWeight(GeneralDotWeight { @@ -374,10 +374,12 @@ impl Layout { match index { NodeIndex::Primitive(primitive) => primitive.primitive(&self.drawing).shape().into(), NodeIndex::Compound(compound) => match self.drawing.compound_weight(compound) { - CompoundWeight::Poly(_) => self - .poly(GenericIndex::::new(compound.petgraph_index())) - .shape() - .into(), + CompoundWeight::Poly(_) => { + GenericIndex::::new(compound.petgraph_index()) + .ref_(self) + .shape() + .into() + } CompoundWeight::Via(_) => self .via(GenericIndex::::new(compound.petgraph_index())) .shape() @@ -507,10 +509,6 @@ impl Layout { self.drawing.rules_mut() } - pub fn poly(&self, index: GenericIndex) -> Poly { - Poly::new(index, self.drawing()) - } - pub fn via(&self, index: GenericIndex) -> Via { Via::new(index, self.drawing()) } diff --git a/src/layout/poly.rs b/src/layout/poly.rs index 2e5c4e1..e0805d0 100644 --- a/src/layout/poly.rs +++ b/src/layout/poly.rs @@ -18,21 +18,29 @@ use crate::{ Drawing, }, geometry::{GetLayer, GetSetPos}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetPetgraphIndex, MakeRef}, layout::CompoundWeight, }; +use super::Layout; + #[enum_dispatch] pub trait MakePolygon { fn shape(&self) -> Polygon; } #[derive(Debug)] -pub struct Poly<'a, R> { +pub struct PolyRef<'a, R> { pub index: GenericIndex, drawing: &'a Drawing, } +impl<'a, R: AccessRules> MakeRef<'a, PolyRef<'a, R>, Layout> for GenericIndex { + fn ref_(&self, layout: &'a Layout) -> PolyRef<'a, R> { + PolyRef::new(*self, layout.drawing()) + } +} + pub(super) fn is_apex<'a, R: AccessRules>( drawing: &'a Drawing, dot: FixedDotIndex, @@ -45,7 +53,7 @@ pub(super) fn is_apex<'a, R: AccessRules>( && drawing.primitive(dot).bends().is_empty() } -impl<'a, R: AccessRules> Poly<'a, R> { +impl<'a, R: AccessRules> PolyRef<'a, R> { pub fn new(index: GenericIndex, drawing: &'a Drawing) -> Self { Self { index, drawing } } @@ -71,7 +79,7 @@ impl<'a, R: AccessRules> Poly<'a, R> { } } -impl GetLayer for Poly<'_, R> { +impl GetLayer for PolyRef<'_, R> { fn layer(&self) -> usize { if let CompoundWeight::Poly(weight) = self.drawing.compound_weight(self.index.into()) { weight.layer() @@ -81,13 +89,13 @@ impl GetLayer for Poly<'_, R> { } } -impl GetMaybeNet for Poly<'_, R> { +impl GetMaybeNet for PolyRef<'_, R> { fn maybe_net(&self) -> Option { self.drawing.compound_weight(self.index.into()).maybe_net() } } -impl MakePolygon for Poly<'_, R> { +impl MakePolygon for PolyRef<'_, R> { fn shape(&self) -> Polygon { Polygon::new( LineString::from(