mirror of https://codeberg.org/topola/topola.git
Move primitives to new file and add enum to group them together
This commit is contained in:
parent
5113f30fd5
commit
4afd0d7e3d
|
|
@ -6,9 +6,9 @@ use bimap::BiBTreeMap;
|
||||||
use derive_getters::{Dissolve, Getters};
|
use derive_getters::{Dissolve, Getters};
|
||||||
use undoredo::{ApplyDelta, Delta, FlushDelta};
|
use undoredo::{ApplyDelta, Delta, FlushDelta};
|
||||||
|
|
||||||
use crate::layout::{
|
use crate::{
|
||||||
Joint, JointId, Layout, LayoutHalfDelta, NetId, PinId, Polygon, PolygonId, Segment, SegmentId,
|
layout::{Layout, LayoutHalfDelta, NetId, PinId},
|
||||||
Via, ViaId,
|
primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Getters)]
|
#[derive(Clone, Debug, Getters)]
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use stable_vec::StableVec;
|
use stable_vec::StableVec;
|
||||||
use undoredo::{ApplyDelta, Delta, FlushDelta, Recorder};
|
use undoredo::{ApplyDelta, Delta, FlushDelta, Recorder};
|
||||||
|
|
||||||
use crate::selection::PinSelector;
|
use crate::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId};
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
|
@ -57,129 +57,6 @@ impl NetId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
|
||||||
)]
|
|
||||||
pub struct JointId(usize);
|
|
||||||
|
|
||||||
impl JointId {
|
|
||||||
/// Returns the underlying index.
|
|
||||||
#[inline]
|
|
||||||
pub fn id(self) -> usize {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Joint {
|
|
||||||
pub position: [i64; 2],
|
|
||||||
pub layer: usize,
|
|
||||||
pub radius: u64,
|
|
||||||
pub net: NetId,
|
|
||||||
pub pin: Option<PinId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Joint {
|
|
||||||
pub fn pin_selector(&self) -> Option<PinSelector> {
|
|
||||||
Some(PinSelector {
|
|
||||||
pin: self.pin?,
|
|
||||||
layer: self.layer,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
|
||||||
)]
|
|
||||||
pub struct SegmentId(usize);
|
|
||||||
|
|
||||||
impl SegmentId {
|
|
||||||
/// Returns the underlying index.
|
|
||||||
#[inline]
|
|
||||||
pub fn id(self) -> usize {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Segment {
|
|
||||||
pub endjoints: [JointId; 2],
|
|
||||||
pub layer: usize,
|
|
||||||
pub half_width: u64,
|
|
||||||
pub net: NetId,
|
|
||||||
pub pin: Option<PinId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Segment {
|
|
||||||
pub fn pin_selector(&self) -> Option<PinSelector> {
|
|
||||||
Some(PinSelector {
|
|
||||||
pin: self.pin?,
|
|
||||||
layer: self.layer,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
|
||||||
)]
|
|
||||||
pub struct ViaId(usize);
|
|
||||||
|
|
||||||
impl ViaId {
|
|
||||||
/// Returns the underlying index.
|
|
||||||
#[inline]
|
|
||||||
pub fn id(self) -> usize {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Via {
|
|
||||||
pub endpoints: [JointId; 2],
|
|
||||||
pub layer: usize, // ??? This should be a range.
|
|
||||||
pub radius: u64,
|
|
||||||
pub net: NetId,
|
|
||||||
pub pin: Option<PinId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Via {
|
|
||||||
pub fn pin_selector(&self) -> Option<PinSelector> {
|
|
||||||
Some(PinSelector {
|
|
||||||
pin: self.pin?,
|
|
||||||
layer: self.layer,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
|
||||||
)]
|
|
||||||
pub struct PolygonId(usize);
|
|
||||||
|
|
||||||
impl PolygonId {
|
|
||||||
/// Returns the underlying index.
|
|
||||||
#[inline]
|
|
||||||
pub fn id(self) -> usize {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Polygon {
|
|
||||||
pub vertices: Vec<[i64; 2]>,
|
|
||||||
pub layer: usize,
|
|
||||||
pub net: NetId,
|
|
||||||
pub pin: Option<PinId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Polygon {
|
|
||||||
pub fn pin_selector(&self) -> Option<PinSelector> {
|
|
||||||
Some(PinSelector {
|
|
||||||
pin: self.pin?,
|
|
||||||
layer: self.layer,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Getters)]
|
#[derive(Clone, Debug, Getters)]
|
||||||
pub struct Layout {
|
pub struct Layout {
|
||||||
boundary: Vec<[i64; 2]>,
|
boundary: Vec<[i64; 2]>,
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ mod board;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod math;
|
mod math;
|
||||||
mod navmesher;
|
mod navmesher;
|
||||||
|
mod primitives;
|
||||||
mod selection;
|
mod selection;
|
||||||
mod specctra;
|
mod specctra;
|
||||||
|
|
||||||
pub use crate::board::Board;
|
pub use crate::board::Board;
|
||||||
pub use crate::layout::{
|
pub use crate::layout::Layout;
|
||||||
Joint, JointId, Layout, Polygon, PolygonId, Segment, SegmentId, Via, ViaId,
|
|
||||||
};
|
|
||||||
pub use crate::navmesher::NavmesherBoard;
|
pub use crate::navmesher::NavmesherBoard;
|
||||||
|
pub use crate::primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use derive_getters::Getters;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Board,
|
Board,
|
||||||
layout::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId},
|
primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Getters)]
|
#[derive(Clone, Debug, Getters)]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Topola contributors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
use derive_more::{Constructor, From};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
layout::{NetId, PinId},
|
||||||
|
selection::PinSelector,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, From, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
|
pub enum PrimitiveId {
|
||||||
|
Joint(JointId),
|
||||||
|
Segment(SegmentId),
|
||||||
|
Via(ViaId),
|
||||||
|
Polygon(PolygonId),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
)]
|
||||||
|
pub struct JointId(usize);
|
||||||
|
|
||||||
|
impl JointId {
|
||||||
|
/// Returns the underlying index.
|
||||||
|
#[inline]
|
||||||
|
pub fn id(self) -> usize {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct Joint {
|
||||||
|
pub position: [i64; 2],
|
||||||
|
pub layer: usize,
|
||||||
|
pub radius: u64,
|
||||||
|
pub net: NetId,
|
||||||
|
pub pin: Option<PinId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Joint {
|
||||||
|
pub fn pin_selector(&self) -> Option<PinSelector> {
|
||||||
|
Some(PinSelector {
|
||||||
|
pin: self.pin?,
|
||||||
|
layer: self.layer,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
)]
|
||||||
|
pub struct SegmentId(usize);
|
||||||
|
|
||||||
|
impl SegmentId {
|
||||||
|
/// Returns the underlying index.
|
||||||
|
#[inline]
|
||||||
|
pub fn id(self) -> usize {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct Segment {
|
||||||
|
pub endjoints: [JointId; 2],
|
||||||
|
pub layer: usize,
|
||||||
|
pub half_width: u64,
|
||||||
|
pub net: NetId,
|
||||||
|
pub pin: Option<PinId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Segment {
|
||||||
|
pub fn pin_selector(&self) -> Option<PinSelector> {
|
||||||
|
Some(PinSelector {
|
||||||
|
pin: self.pin?,
|
||||||
|
layer: self.layer,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
)]
|
||||||
|
pub struct ViaId(usize);
|
||||||
|
|
||||||
|
impl ViaId {
|
||||||
|
/// Returns the underlying index.
|
||||||
|
#[inline]
|
||||||
|
pub fn id(self) -> usize {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct Via {
|
||||||
|
pub endpoints: [JointId; 2],
|
||||||
|
pub layer: usize, // ??? This should be a range.
|
||||||
|
pub radius: u64,
|
||||||
|
pub net: NetId,
|
||||||
|
pub pin: Option<PinId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Via {
|
||||||
|
pub fn pin_selector(&self) -> Option<PinSelector> {
|
||||||
|
Some(PinSelector {
|
||||||
|
pin: self.pin?,
|
||||||
|
layer: self.layer,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
)]
|
||||||
|
pub struct PolygonId(usize);
|
||||||
|
|
||||||
|
impl PolygonId {
|
||||||
|
/// Returns the underlying index.
|
||||||
|
#[inline]
|
||||||
|
pub fn id(self) -> usize {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Polygon {
|
||||||
|
pub vertices: Vec<[i64; 2]>,
|
||||||
|
pub layer: usize,
|
||||||
|
pub net: NetId,
|
||||||
|
pub pin: Option<PinId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Polygon {
|
||||||
|
pub fn pin_selector(&self) -> Option<PinSelector> {
|
||||||
|
Some(PinSelector {
|
||||||
|
pin: self.pin?,
|
||||||
|
layer: self.layer,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,8 +13,9 @@ use specctra::{
|
||||||
use crate::{
|
use crate::{
|
||||||
Segment,
|
Segment,
|
||||||
board::Board,
|
board::Board,
|
||||||
layout::{Joint, NetId, PinId, Polygon},
|
layout::{NetId, PinId},
|
||||||
math::Vector2,
|
math::Vector2,
|
||||||
|
primitives::{Joint, Polygon},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue