From bc5e205b90a3fcc8ba6c350693db677a51412b9e Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 18 May 2026 22:41:57 +0200 Subject: [PATCH] Move nets and pins to separate directory, `compounds` --- topola/src/board.rs | 3 +- topola/src/compounds/mod.rs | 9 ++++ topola/src/compounds/net.rs | 18 ++++++++ topola/src/compounds/pin.rs | 39 +++++++++++++++++ topola/src/layout.rs | 72 +++++++------------------------- topola/src/lib.rs | 2 + topola/src/navmesher.rs | 4 +- topola/src/primitives/joint.rs | 2 +- topola/src/primitives/polygon.rs | 2 +- topola/src/primitives/segment.rs | 2 +- topola/src/primitives/via.rs | 5 +-- topola/src/ratsnest.rs | 5 ++- topola/src/specctra.rs | 7 ++-- 13 files changed, 102 insertions(+), 68 deletions(-) create mode 100644 topola/src/compounds/mod.rs create mode 100644 topola/src/compounds/net.rs create mode 100644 topola/src/compounds/pin.rs diff --git a/topola/src/board.rs b/topola/src/board.rs index d5bbfd8..f5bba03 100644 --- a/topola/src/board.rs +++ b/topola/src/board.rs @@ -7,7 +7,8 @@ use derive_getters::{Dissolve, Getters}; use undoredo::{ApplyDelta, Delta, FlushDelta}; use crate::{ - layout::{Layout, LayoutHalfDelta, NetId, PinId}, + compounds::{NetId, PinId}, + layout::{Layout, LayoutHalfDelta}, math::Vector2, primitives::{ JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, diff --git a/topola/src/compounds/mod.rs b/topola/src/compounds/mod.rs new file mode 100644 index 0000000..3be1f75 --- /dev/null +++ b/topola/src/compounds/mod.rs @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +mod net; +mod pin; + +pub use net::NetId; +pub use pin::{Pin, PinId}; diff --git a/topola/src/compounds/net.rs b/topola/src/compounds/net.rs new file mode 100644 index 0000000..3c88d0f --- /dev/null +++ b/topola/src/compounds/net.rs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use derive_more::Constructor; +use serde::{Deserialize, Serialize}; + +#[derive( + Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, +)] +pub struct NetId(usize); + +impl NetId { + #[inline] + pub fn index(self) -> usize { + self.0 + } +} diff --git a/topola/src/compounds/pin.rs b/topola/src/compounds/pin.rs new file mode 100644 index 0000000..18a15f6 --- /dev/null +++ b/topola/src/compounds/pin.rs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use derive_more::Constructor; +use serde::{Deserialize, Serialize}; + +use crate::primitives::{JointId, PolygonId, SegmentId, ViaId}; + +#[derive( + Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, +)] +pub struct PinId(usize); + +impl PinId { + #[inline] + pub fn index(self) -> usize { + self.0 + } +} + +#[derive(Clone, Debug)] +pub struct Pin { + pub(crate) joints: Vec, + pub(crate) segments: Vec, + pub(crate) vias: Vec, + pub(crate) polygons: Vec, +} + +impl Pin { + pub fn new() -> Self { + Self { + joints: Vec::new(), + segments: Vec::new(), + vias: Vec::new(), + polygons: Vec::new(), + } + } +} diff --git a/topola/src/layout.rs b/topola/src/layout.rs index d457756..be152ec 100644 --- a/topola/src/layout.rs +++ b/topola/src/layout.rs @@ -3,66 +3,23 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use derive_getters::Getters; -use derive_more::Constructor; use rstar::{ AABB, RTree, primitives::{GeomWithData, Rectangle}, }; -use serde::{Deserialize, Serialize}; use stable_vec::StableVec; use undoredo::aliases::RTreeHalfDelta; use undoredo::{Delta, Recorder}; use crate::{ - Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Vector2, Via, ViaId, - primitives::{JointSpec, SegmentSpec, ViaSpec}, + compounds::{Pin, PinId}, + math::Vector2, + primitives::{ + Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, + ViaSpec, + }, }; -#[derive( - Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, -)] -pub struct PinId(usize); - -impl PinId { - /// Returns the underlying index. - #[inline] - pub fn index(self) -> usize { - self.0 - } -} - -#[derive(Clone, Debug)] -pub struct Pin { - joints: Vec, - segments: Vec, - vias: Vec, - polygons: Vec, -} - -impl Pin { - pub fn new() -> Self { - Self { - joints: Vec::new(), - segments: Vec::new(), - vias: Vec::new(), - polygons: Vec::new(), - } - } -} - -#[derive( - Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, -)] -pub struct NetId(usize); - -impl NetId { - /// Returns the underlying index. - #[inline] - pub fn index(self) -> usize { - self.0 - } -} - #[derive(Delta, Clone, Debug, Getters)] pub struct Layout { #[undoredo(skip)] @@ -72,8 +29,7 @@ pub struct Layout { #[undoredo(skip)] layer_count: usize, - #[undoredo(skip)] - pins: StableVec, + pins: Recorder>, joints: Recorder>, segments: Recorder>, @@ -105,7 +61,7 @@ impl Layout { place_boundary: boundary, layer_count, - pins: StableVec::new(), + pins: Recorder::new(StableVec::new()), joints: Recorder::new(StableVec::new()), segments: Recorder::new(StableVec::new()), @@ -137,7 +93,8 @@ impl Layout { .insert(GeomWithData::new(bbox, joint_id), ()); if let Some(pin_id) = pin_id { - self.pins[pin_id.index()].joints.push(joint_id); + self.pins + .modify(pin_id.index(), |pin| pin.joints.push(joint_id)); } joint_id @@ -204,7 +161,8 @@ impl Layout { .insert(GeomWithData::new(bbox, segment_id), ()); if let Some(pin_id) = pin_id { - self.pins[pin_id.index()].segments.push(segment_id); + self.pins + .modify(pin_id.index(), |pin| pin.segments.push(segment_id)); } segment_id @@ -274,7 +232,8 @@ impl Layout { self.vias_rtree.insert(GeomWithData::new(bbox, via_id), ()); if let Some(pin_id) = pin_id { - self.pins[pin_id.index()].vias.push(via_id); + self.pins + .modify(pin_id.index(), |pin| pin.vias.push(via_id)); } via_id @@ -326,7 +285,8 @@ impl Layout { .insert(GeomWithData::new(bbox, polygon_id), ()); if let Some(pin_id) = pin_id { - self.pins[pin_id.index()].polygons.push(polygon_id); + self.pins + .modify(pin_id.index(), |pin| pin.polygons.push(polygon_id)); } polygon_id diff --git a/topola/src/lib.rs b/topola/src/lib.rs index 4376b1a..46b9178 100644 --- a/topola/src/lib.rs +++ b/topola/src/lib.rs @@ -4,6 +4,7 @@ mod autorouter; mod board; +mod compounds; mod drawer; mod layout; mod math; @@ -17,6 +18,7 @@ mod specctra; pub use crate::autorouter::Autorouter; pub use crate::board::Board; +pub use crate::compounds::{Pin, PinId}; pub use crate::layout::Layout; pub use crate::math::Vector2; pub use crate::primitives::{ diff --git a/topola/src/navmesher.rs b/topola/src/navmesher.rs index ee8598d..823bdab 100644 --- a/topola/src/navmesher.rs +++ b/topola/src/navmesher.rs @@ -10,7 +10,9 @@ use stable_vec::StableVec; use undoredo::Recorder; use crate::{ - Board, Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Vector2, primitives::JointSpec, + Board, + math::Vector2, + primitives::{Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId}, }; #[derive( diff --git a/topola/src/primitives/joint.rs b/topola/src/primitives/joint.rs index 0965dbe..1eb6a57 100644 --- a/topola/src/primitives/joint.rs +++ b/topola/src/primitives/joint.rs @@ -6,7 +6,7 @@ use derive_more::Constructor; use rstar::{AABB, primitives::Rectangle}; use serde::{Deserialize, Serialize}; -use crate::layout::{NetId, PinId}; +use crate::compounds::{NetId, PinId}; use crate::math::Vector2; use crate::primitives::{SegmentId, ViaId}; diff --git a/topola/src/primitives/polygon.rs b/topola/src/primitives/polygon.rs index 905180b..3ebdf8d 100644 --- a/topola/src/primitives/polygon.rs +++ b/topola/src/primitives/polygon.rs @@ -6,7 +6,7 @@ use derive_more::Constructor; use rstar::{AABB, Envelope, primitives::Rectangle}; use serde::{Deserialize, Serialize}; -use crate::layout::{NetId, PinId}; +use crate::compounds::{NetId, PinId}; use crate::math::Vector2; #[derive( diff --git a/topola/src/primitives/segment.rs b/topola/src/primitives/segment.rs index 64e80b1..6f62f22 100644 --- a/topola/src/primitives/segment.rs +++ b/topola/src/primitives/segment.rs @@ -6,7 +6,7 @@ use derive_more::Constructor; use rstar::primitives::Rectangle; use serde::{Deserialize, Serialize}; -use crate::layout::{NetId, PinId}; +use crate::compounds::{NetId, PinId}; use crate::math::Vector2; use crate::primitives::JointId; diff --git a/topola/src/primitives/via.rs b/topola/src/primitives/via.rs index 70236ec..bd78493 100644 --- a/topola/src/primitives/via.rs +++ b/topola/src/primitives/via.rs @@ -6,10 +6,9 @@ use derive_more::Constructor; use rstar::{AABB, primitives::Rectangle}; use serde::{Deserialize, Serialize}; -use crate::layout::{NetId, PinId}; +use crate::compounds::{NetId, PinId}; use crate::math::Vector2; - -use super::joint::JointId; +use crate::primitives::JointId; #[derive( Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, diff --git a/topola/src/ratsnest.rs b/topola/src/ratsnest.rs index 91ee7af..161d98d 100644 --- a/topola/src/ratsnest.rs +++ b/topola/src/ratsnest.rs @@ -9,7 +9,10 @@ use serde::{Deserialize, Serialize}; use spade::{DelaunayTriangulation, HasPosition, Triangulation, handles::FixedVertexHandle}; use crate::{ - Board, JointId, PolygonId, SegmentId, Vector2, layout::NetId, primitives::PrimitiveId, + Board, + compounds::NetId, + math::Vector2, + primitives::{JointId, PolygonId, PrimitiveId, SegmentId}, }; #[derive(Clone, Copy, Debug, Deserialize, Eq, Getters, Ord, PartialEq, PartialOrd, Serialize)] diff --git a/topola/src/specctra.rs b/topola/src/specctra.rs index 59ebc86..f419738 100644 --- a/topola/src/specctra.rs +++ b/topola/src/specctra.rs @@ -11,10 +11,11 @@ use specctra::{ }; use crate::{ - Segment, Vector2, board::Board, - layout::{NetId, PinId}, - primitives::{JointSpec, Polygon, SegmentSpec}, + compounds::NetId, + compounds::PinId, + math::Vector2, + primitives::{JointSpec, Polygon, Segment, SegmentSpec}, }; impl Board {