Move nets and pins to separate directory, `compounds`

This commit is contained in:
Mikolaj Wielgus 2026-05-18 22:41:57 +02:00
parent b05c31f767
commit bc5e205b90
13 changed files with 102 additions and 68 deletions

View File

@ -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,

View File

@ -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};

View File

@ -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
}
}

View File

@ -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<JointId>,
pub(crate) segments: Vec<SegmentId>,
pub(crate) vias: Vec<ViaId>,
pub(crate) polygons: Vec<PolygonId>,
}
impl Pin {
pub fn new() -> Self {
Self {
joints: Vec::new(),
segments: Vec::new(),
vias: Vec::new(),
polygons: Vec::new(),
}
}
}

View File

@ -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<JointId>,
segments: Vec<SegmentId>,
vias: Vec<ViaId>,
polygons: Vec<PolygonId>,
}
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<Pin>,
pins: Recorder<StableVec<Pin>>,
joints: Recorder<StableVec<Joint>>,
segments: Recorder<StableVec<Segment>>,
@ -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

View File

@ -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::{

View File

@ -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(

View File

@ -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};

View File

@ -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(

View File

@ -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;

View File

@ -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,

View File

@ -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)]

View File

@ -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 {