diff --git a/crates/specctra-core/src/read.rs b/crates/specctra-core/src/read.rs index 0caebff..1dee215 100644 --- a/crates/specctra-core/src/read.rs +++ b/crates/specctra-core/src/read.rs @@ -117,7 +117,7 @@ pub struct ListTokenizer { column: usize, } -impl ListTokenizer { +impl ListTokenizer { pub fn new(reader: R) -> Self { Self { reader, @@ -140,7 +140,9 @@ impl ListTokenizer { context: (self.line, self.column), } } +} +impl ListTokenizer { fn next_char(&mut self) -> Result { let return_chr = self.peek_char()?; self.reset_char(); diff --git a/crates/specctra-core/src/write.rs b/crates/specctra-core/src/write.rs index c77c12f..3937cc8 100644 --- a/crates/specctra-core/src/write.rs +++ b/crates/specctra-core/src/write.rs @@ -66,14 +66,14 @@ impl WriteSes for f64 { } } -pub struct ListWriter { +pub struct ListWriter { writable: W, indent_level: usize, multiline_level: usize, pub line_len: usize, } -impl ListWriter { +impl ListWriter { pub fn new(writable: W) -> Self { Self { writable, @@ -82,7 +82,9 @@ impl ListWriter { line_len: 0, } } +} +impl ListWriter { pub fn write_token(&mut self, token: ListToken) -> Result<(), io::Error> { let len = token.len(); diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index d8e476a..15f6b70 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -47,7 +47,7 @@ pub enum AutorouterError { } #[derive(Getters)] -pub struct Autorouter { +pub struct Autorouter { pub(super) board: Board, pub(super) ratsnest: Ratsnest, } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 1a218a5..f4e42dc 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -80,7 +80,7 @@ pub enum InvokerError { #[derive(Getters, Dissolve)] /// Structure that manages the execution and history of commands within the autorouting system -pub struct Invoker { +pub struct Invoker { /// Instance for executing desired autorouting commands pub(super) autorouter: Autorouter, /// History of executed commands diff --git a/src/board/mod.rs b/src/board/mod.rs index 665b837..ab56114 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -52,7 +52,7 @@ impl BandName { /// The struct manages the relationships between board's layout, /// and its compounds, as well as provides methods to manipulate them. #[derive(Debug, Getters)] -pub struct Board { +pub struct Board { layout: Layout, // TODO: Simplify access logic to these members so that `#[getter(skip)]`s can be removed. #[getter(skip)] @@ -61,7 +61,7 @@ pub struct Board { band_bandname: BiHashMap, } -impl Board { +impl Board { /// Initializes the board with given [`Layout`] pub fn new(layout: Layout) -> Self { Self { @@ -71,6 +71,13 @@ impl Board { } } + /// Returns a mutable reference to the layout, allowing modifications. + pub fn layout_mut(&mut self) -> &mut Layout { + &mut self.layout + } +} + +impl Board { /// Adds a new fixed dot with an optional pin name. /// /// Inserts the dot into the layout and, if a pin name is provided, maps it to the created dot's node. @@ -249,11 +256,6 @@ impl Board { pub fn mesadata(&self) -> &M { self.layout.drawing().rules() } - - /// Returns a mutable reference to the layout, allowing modifications. - pub fn layout_mut(&mut self) -> &mut Layout { - &mut self.layout - } } impl diff --git a/src/drawing/band.rs b/src/drawing/band.rs index 1dc0d81..009e977 100644 --- a/src/drawing/band.rs +++ b/src/drawing/band.rs @@ -56,20 +56,18 @@ impl From for LooseIndex { } } -impl<'a, CW: Copy, R: AccessRules> MakeRef<'a, BandRef<'a, CW, R>, Drawing> - for BandTermsegIndex -{ +impl<'a, CW, R> MakeRef<'a, BandRef<'a, CW, R>, Drawing> for BandTermsegIndex { fn ref_(&self, drawing: &'a Drawing) -> BandRef<'a, CW, R> { BandRef::new(*self, drawing) } } -pub struct BandRef<'a, CW: Copy, R: AccessRules> { +pub struct BandRef<'a, CW, R> { first_seg: BandTermsegIndex, drawing: &'a Drawing, } -impl<'a, CW: Copy, R: AccessRules> BandRef<'a, CW, R> { +impl<'a, CW, R> BandRef<'a, CW, R> { pub fn new(first_seg: BandTermsegIndex, drawing: &'a Drawing) -> BandRef<'a, CW, R> { Self { first_seg, drawing } } diff --git a/src/drawing/collect.rs b/src/drawing/collect.rs index cd7d765..68284ac 100644 --- a/src/drawing/collect.rs +++ b/src/drawing/collect.rs @@ -12,15 +12,17 @@ use super::{ }; #[derive(Debug)] -pub struct Collect<'a, CW: Copy, R: AccessRules> { +pub struct Collect<'a, CW, R> { drawing: &'a Drawing, } -impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> { +impl<'a, CW, R> Collect<'a, CW, R> { pub fn new(drawing: &'a Drawing) -> Self { Self { drawing } } +} +impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> { pub fn loose_band_uid(&self, start_loose: LooseIndex) -> BandUid { BandUid::new( self.loose_band_first_seg(start_loose), diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 97b5ff0..fccd178 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -66,7 +66,7 @@ pub struct Collision(pub PrimitiveShape, pub PrimitiveIndex); #[error("{1:?} is already connected to net {0}")] pub struct AlreadyConnected(pub usize, pub PrimitiveIndex); -pub type DrawingEdit = GeometryEdit< +pub type DrawingEdit = GeometryEdit< PrimitiveWeight, DotWeight, SegWeight, @@ -79,7 +79,7 @@ pub type DrawingEdit = GeometryEdit< >; #[derive(Debug, Getters)] -pub struct Drawing { +pub struct Drawing { recording_geometry_with_rtree: RecordingGeometryWithRtree< PrimitiveWeight, DotWeight, diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index ed8506b..b7c0f36 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -18,15 +18,17 @@ use super::{ Drawing, }; -pub struct Guide<'a, CW: Copy, R: AccessRules> { +pub struct Guide<'a, CW, R> { drawing: &'a Drawing, } -impl<'a, CW: Copy, R: AccessRules> Guide<'a, CW, R> { +impl<'a, CW, R> Guide<'a, CW, R> { pub fn new(drawing: &'a Drawing) -> Self { Self { drawing } } +} +impl<'a, CW: Copy, R: AccessRules> Guide<'a, CW, R> { pub fn head_into_dot_segment( &self, head: &Head, diff --git a/src/drawing/head.rs b/src/drawing/head.rs index 2cf009a..ae5e0be 100644 --- a/src/drawing/head.rs +++ b/src/drawing/head.rs @@ -25,7 +25,7 @@ pub enum Head { Cane(CaneHead), } -impl<'a, CW: Copy, R: AccessRules> MakeRef<'a, HeadRef<'a, CW, R>, Drawing> for Head { +impl<'a, CW, R> MakeRef<'a, HeadRef<'a, CW, R>, Drawing> for Head { fn ref_(&self, drawing: &'a Drawing) -> HeadRef<'a, CW, R> { HeadRef::new(*self, drawing) } @@ -67,18 +67,18 @@ impl GetFace for CaneHead { } } -pub struct HeadRef<'a, CW: Copy, R: AccessRules> { +pub struct HeadRef<'a, CW, R> { head: Head, drawing: &'a Drawing, } -impl<'a, CW: Copy, R: AccessRules> HeadRef<'a, CW, R> { +impl<'a, CW, R> HeadRef<'a, CW, R> { pub fn new(head: Head, drawing: &'a Drawing) -> Self { Self { drawing, head } } } -impl<'a, CW: Copy, R: AccessRules> GetFace for HeadRef<'a, CW, R> { +impl<'a, CW, R> GetFace for HeadRef<'a, CW, R> { fn face(&self) -> DotIndex { self.head.face() } diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index f497cf8..c5434e7 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -23,17 +23,7 @@ pub trait ApplyGeometryEdit< } #[derive(Debug, Clone)] -pub struct GeometryEdit< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, - DI: GetPetgraphIndex + Into + Eq + Hash + Copy, - SI: GetPetgraphIndex + Into + Eq + Hash + Copy, - BI: GetPetgraphIndex + Into + Eq + Hash + Copy, -> { +pub struct GeometryEdit { pub(super) dots: HashMap, Option)>, pub(super) segs: HashMap, Option<((DI, DI), SW)>)>, pub(super) bends: HashMap, Option<((DI, DI, DI), BW)>)>, diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index 1876fc3..5f5288f 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -70,17 +70,7 @@ pub trait AccessSegWeight: GetWidth + Into + Copy {} pub trait AccessBendWeight: GetOffset + SetOffset + GetWidth + Into + Copy {} #[derive(Debug, Getters)] -pub struct Geometry< - PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight, - SW: AccessSegWeight, - BW: AccessBendWeight, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, -> { +pub struct Geometry { graph: StableDiGraph, GeometryLabel, usize>, primitive_weight_marker: PhantomData, dot_weight_marker: PhantomData, diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index 7768fd0..abbee1f 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -19,17 +19,7 @@ use super::{ }; #[derive(Debug)] -pub struct RecordingGeometryWithRtree< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, - DI: GetPetgraphIndex + Into + Eq + Hash + Copy, - SI: GetPetgraphIndex + Into + Eq + Hash + Copy, - BI: GetPetgraphIndex + Into + Eq + Hash + Copy, -> { +pub struct RecordingGeometryWithRtree { geometry_with_rtree: GeometryWithRtree, } diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index 4783bdc..fb43d8a 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -36,17 +36,7 @@ impl RTreeObject for Bbox { pub type BboxedIndex = GeomWithData; #[derive(Debug, Getters)] -pub struct GeometryWithRtree< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, -> { +pub struct GeometryWithRtree { geometry: Geometry, rtree: RTree>>>, layer_count: usize, diff --git a/src/interactor/activity.rs b/src/interactor/activity.rs index 63b5176..2baa527 100644 --- a/src/interactor/activity.rs +++ b/src/interactor/activity.rs @@ -25,7 +25,7 @@ pub struct InteractiveInput { } /// This is the execution context passed to the stepper on each step -pub struct ActivityContext<'a, M: AccessMesadata> { +pub struct ActivityContext<'a, M> { pub interactive_input: &'a InteractiveInput, pub invoker: &'a mut Invoker, } diff --git a/src/interactor/interactor.rs b/src/interactor/interactor.rs index 6f1f624..25bc25a 100644 --- a/src/interactor/interactor.rs +++ b/src/interactor/interactor.rs @@ -17,7 +17,7 @@ use crate::{ }; /// Structure that manages the invoker and activities -pub struct Interactor { +pub struct Interactor { invoker: Invoker, activity: Option, } diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 9b89ad4..4d752a2 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -43,15 +43,17 @@ pub type LayoutEdit = DrawingEdit; #[derive(Debug, Getters)] /// Structure for managing the Layout design -pub struct Layout { +pub struct Layout { drawing: Drawing, } -impl Layout { +impl Layout { pub fn new(drawing: Drawing) -> Self { Self { drawing } } +} +impl Layout { /// Insert [`Cane`] object into the [`Layout`] pub fn insert_cane( &mut self, diff --git a/src/layout/poly.rs b/src/layout/poly.rs index d6e7818..4f908a3 100644 --- a/src/layout/poly.rs +++ b/src/layout/poly.rs @@ -28,7 +28,7 @@ pub trait GetMaybeApex { } #[derive(Debug)] -pub struct Poly<'a, R: AccessRules> { +pub struct Poly<'a, R> { pub index: GenericIndex, layout: &'a Layout, } diff --git a/src/layout/via.rs b/src/layout/via.rs index db7b177..c1c5ef1 100644 --- a/src/layout/via.rs +++ b/src/layout/via.rs @@ -11,12 +11,12 @@ use crate::{ }; #[derive(Debug)] -pub struct Via<'a, R: AccessRules> { +pub struct Via<'a, R> { pub index: GenericIndex, layout: &'a Layout, } -impl<'a, R: AccessRules> Via<'a, R> { +impl<'a, R> Via<'a, R> { pub fn new(index: GenericIndex, layout: &'a Layout) -> Self { Self { index, layout } } diff --git a/src/router/draw.rs b/src/router/draw.rs index d9f5b7e..3ae8b42 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -34,7 +34,7 @@ pub enum DrawException { /// This struct is a simple wrapper whose sole purpose is to have a separate /// file for the router module's routines for drawing and erasing the primitives /// to pull out or contract the currently routed band. -pub struct Draw<'a, R: AccessRules> { +pub struct Draw<'a, R> { layout: &'a mut Layout, } diff --git a/src/router/navcord.rs b/src/router/navcord.rs index 9d98acc..02632f6 100644 --- a/src/router/navcord.rs +++ b/src/router/navcord.rs @@ -120,7 +120,7 @@ impl NavcordStepper { } } -pub struct NavcordStepContext<'a: 'b, 'b, R: AccessRules> { +pub struct NavcordStepContext<'a: 'b, 'b, R> { pub navcorder: &'b mut Navcorder<'a, R>, pub navmesh: &'b Navmesh, pub to: NavvertexIndex, diff --git a/src/router/navcorder.rs b/src/router/navcorder.rs index ba6f529..3d01edc 100644 --- a/src/router/navcorder.rs +++ b/src/router/navcorder.rs @@ -21,15 +21,17 @@ pub enum NavcorderException { } #[derive(Debug)] -pub struct Navcorder<'a, R: AccessRules> { +pub struct Navcorder<'a, R> { pub layout: &'a mut Layout, } -impl<'a, R: AccessRules> Navcorder<'a, R> { +impl<'a, R> Navcorder<'a, R> { pub fn new(layout: &mut Layout) -> Navcorder { Navcorder { layout } } +} +impl<'a, R: AccessRules> Navcorder<'a, R> { pub fn start( &mut self, recorder: LayoutEdit, diff --git a/src/router/router.rs b/src/router/router.rs index 45b6ce9..2526f43 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -38,7 +38,7 @@ pub struct RouterOptions { } #[derive(Debug)] -pub struct RouterAstarStrategy<'a, R: AccessRules> { +pub struct RouterAstarStrategy<'a, R> { pub navcorder: Navcorder<'a, R>, pub navcord: &'a mut NavcordStepper, pub target: FixedDotIndex, @@ -46,7 +46,7 @@ pub struct RouterAstarStrategy<'a, R: AccessRules> { pub probe_obstacles: Vec, } -impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { +impl<'a, R> RouterAstarStrategy<'a, R> { pub fn new( navcorder: Navcorder<'a, R>, navcord: &'a mut NavcordStepper, @@ -60,7 +60,9 @@ impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { probe_obstacles: vec![], } } +} +impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { fn bihead_length(&self) -> f64 { self.navcord .head diff --git a/src/triangulation.rs b/src/triangulation.rs index 14c31f4..8e7c7a4 100644 --- a/src/triangulation.rs +++ b/src/triangulation.rs @@ -12,21 +12,14 @@ pub trait GetTrianvertexNodeIndex { } #[derive(Debug, Clone)] -pub struct Triangulation< - I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, -> { +pub struct Triangulation + HasPosition, EW: Default> { triangulation: DelaunayTriangulation, trianvertex_to_handle: Box<[Option]>, index_marker: PhantomData, } -impl< - I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, - > Triangulation +impl + HasPosition, EW: Default> + Triangulation { pub fn new(node_bound: usize) -> Self { Self { @@ -57,12 +50,6 @@ impl< ) } - pub fn position(&self, vertex: I) -> Point { - let position = - spade::Triangulation::vertex(&self.triangulation, self.handle(vertex)).position(); - point! {x: position.x, y: position.y} - } - fn vertex(&self, handle: FixedVertexHandle) -> I { spade::Triangulation::vertex(&self.triangulation, handle) .as_ref() @@ -72,12 +59,21 @@ impl< fn handle(&self, vertex: I) -> FixedVertexHandle { self.trianvertex_to_handle[vertex.petgraph_index().index()].unwrap() } + + pub fn position(&self, vertex: I) -> Point<::Scalar> + where + ::Scalar: geo::CoordNum, + { + let position = + spade::Triangulation::vertex(&self.triangulation, self.handle(vertex)).position(); + point! {x: position.x, y: position.y} + } } impl< I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, + VW: GetTrianvertexNodeIndex + HasPosition, + EW: Default, > visit::GraphBase for Triangulation { type NodeId = I; @@ -85,18 +81,18 @@ impl< } #[derive(Debug, Clone, Copy)] -pub struct TriangulationEdgeWeightWrapper { +pub struct TriangulationEdgeWeightWrapper { length: f64, pub weight: EW, } -impl PartialEq for TriangulationEdgeWeightWrapper { +impl PartialEq for TriangulationEdgeWeightWrapper { fn eq(&self, other: &Self) -> bool { self.length.eq(&other.length) } } -impl PartialOrd for TriangulationEdgeWeightWrapper { +impl PartialOrd for TriangulationEdgeWeightWrapper { fn partial_cmp(&self, other: &Self) -> Option { self.length.partial_cmp(&other.length) } @@ -104,7 +100,7 @@ impl PartialOrd for TriangulationEdgeWeightWrapper { impl< I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, + VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::Data for Triangulation { @@ -113,13 +109,13 @@ impl< } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct TriangulationEdgeReference { +pub struct TriangulationEdgeReference { from: I, to: I, weight: TriangulationEdgeWeightWrapper, } -impl visit::EdgeRef for TriangulationEdgeReference { +impl visit::EdgeRef for TriangulationEdgeReference { type NodeId = I; type EdgeId = (I, I); type Weight = TriangulationEdgeWeightWrapper; @@ -144,8 +140,8 @@ impl visit::EdgeRef for TriangulationEdgeReference< impl< 'a, I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, + VW: GetTrianvertexNodeIndex + HasPosition, + EW: Default, > visit::IntoNeighbors for &'a Triangulation { type Neighbors = Box + 'a>; @@ -221,8 +217,8 @@ impl< impl< 'a, I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, + VW: GetTrianvertexNodeIndex + HasPosition, + EW: Default, > visit::IntoNodeIdentifiers for &'a Triangulation { type NodeIdentifiers = Box + 'a>; @@ -238,13 +234,24 @@ impl< } } -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct TriangulationVertexReference<'a, I: Copy, VW> { +#[derive(Debug, PartialEq)] +pub struct TriangulationVertexReference<'a, I, VW> { index: I, weight: &'a VW, } -impl<'a, I: Copy, VW: Copy> visit::NodeRef for TriangulationVertexReference<'a, I, VW> { +impl Clone for TriangulationVertexReference<'_, I, VW> { + fn clone(&self) -> Self { + Self { + index: self.index.clone(), + weight: self.weight, + } + } +} + +impl Copy for TriangulationVertexReference<'_, I, VW> {} + +impl visit::NodeRef for TriangulationVertexReference<'_, I, VW> { type NodeId = I; type Weight = VW; @@ -260,7 +267,7 @@ impl<'a, I: Copy, VW: Copy> visit::NodeRef for TriangulationVertexReference<'a, impl< 'a, I: Copy + PartialEq + GetPetgraphIndex, - VW: Copy + GetTrianvertexNodeIndex + HasPosition, + VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::IntoNodeReferences for &'a Triangulation { @@ -283,8 +290,8 @@ impl< impl< 'a, I: Copy + PartialEq + GetPetgraphIndex + std::fmt::Debug, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Copy + Default, + VW: GetTrianvertexNodeIndex + HasPosition, + EW: Default, > visit::NodeIndexable for &'a Triangulation { fn node_bound(&self) -> usize {