From a4d13a3435530f97a70eea05837729a563717fb0 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 19 Mar 2026 14:27:32 +0100 Subject: [PATCH] Do some renamings, some changes in `Cargo.toml` --- Cargo.toml | 2 +- topola/src/layout.rs | 22 +++++++++++----------- topola/src/lib.rs | 1 + topola/src/navmesher.rs | 6 +++--- topola/src/primitives.rs | 15 +++++++++++---- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 314395e..ec24376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ resolver = "2" [workspace.dependencies] derive-getters = "0.5" -derive_more = { version = "2.1", features = ["add", "constructor", "from", "into"] } +derive_more = { version = "2.1", features = ["full"] } serde = { version = "1", features = ["derive", "rc"] } thiserror = "2.0" undoredo = { version = "0.8", features = ["stable-vec"] } diff --git a/topola/src/layout.rs b/topola/src/layout.rs index 03868fe..ee44e31 100644 --- a/topola/src/layout.rs +++ b/topola/src/layout.rs @@ -165,16 +165,16 @@ impl Layout { } pub fn segment_endpoints(&self, segment_id: SegmentId) -> [Vector2; 2] { - let endjoints = self.segments.get(&segment_id.id()).unwrap().endjoints; + let endjoints = self.segments.get(&segment_id.index()).unwrap().endjoints; [ - self.joints.get(&endjoints[0].id()).unwrap().position, - self.joints.get(&endjoints[1].id()).unwrap().position, + self.joints.get(&endjoints[0].index()).unwrap().position, + self.joints.get(&endjoints[1].index()).unwrap().position, ] } pub fn segment_contains_point(&self, segment_id: SegmentId, point: Vector2) -> bool { let endpoints = self.segment_endpoints(segment_id); - let segment = self.segments.get(&segment_id.id()).unwrap(); + let segment = self.segments.get(&segment_id.index()).unwrap(); let vertices = crate::math::inflated_segment( endpoints[0].x, endpoints[0].y, @@ -187,8 +187,8 @@ impl Layout { pub fn segment_bbox(&self, segment_id: SegmentId) -> Rectangle<[i64; 3]> { let endpoints = self.segment_endpoints(segment_id); - let layer = self.segments.get(&segment_id.id()).unwrap().layer as i64; - let half_width = self.segments.get(&segment_id.id()).unwrap().half_width as i64; + let layer = self.segments.get(&segment_id.index()).unwrap().layer as i64; + let half_width = self.segments.get(&segment_id.index()).unwrap().half_width as i64; let min_x = std::cmp::min(endpoints[0].x, endpoints[1].x) - half_width; let min_y = std::cmp::min(endpoints[0].y, endpoints[1].y) - half_width; @@ -209,7 +209,7 @@ impl Layout { .map(|geom_with_data| geom_with_data.data) .filter(move |joint_id| { self.joints - .get(&joint_id.id()) + .get(&joint_id.index()) .unwrap() .contains_point(point) }) @@ -240,22 +240,22 @@ impl Layout { .map(|geom_with_data| geom_with_data.data) .filter(move |polygon_id| { self.polygons - .get(&polygon_id.id()) + .get(&polygon_id.index()) .unwrap() .contains_point(point) }) } pub fn joint(&self, joint_id: JointId) -> &Joint { - self.joints.get(&joint_id.id()).unwrap() + self.joints.get(&joint_id.index()).unwrap() } pub fn segment(&self, segment_id: SegmentId) -> &Segment { - self.segments.get(&segment_id.id()).unwrap() + self.segments.get(&segment_id.index()).unwrap() } pub fn polygon(&self, polygon_id: PolygonId) -> &Polygon { - self.polygons.get(&polygon_id.id()).unwrap() + self.polygons.get(&polygon_id.index()).unwrap() } pub fn pin(&self, pin_id: PinId) -> &Pin { diff --git a/topola/src/lib.rs b/topola/src/lib.rs index 0a61fc9..059f491 100644 --- a/topola/src/lib.rs +++ b/topola/src/lib.rs @@ -7,6 +7,7 @@ mod layout; mod math; mod navmesher; mod primitives; +//mod ratsnests; mod selection; mod specctra; diff --git a/topola/src/navmesher.rs b/topola/src/navmesher.rs index af56580..26c6f08 100644 --- a/topola/src/navmesher.rs +++ b/topola/src/navmesher.rs @@ -234,7 +234,7 @@ impl NavmesherBoard { pub fn insert_joint(&mut self, joint: Joint) -> JointId { let joint_id = self.board.add_joint(joint); self.joint_multiobstacles.insert( - joint_id.id(), + joint_id.index(), self.navmesher .insert_multiobstacle(joint.layer, Self::joint_bounding_octagon(joint)), ); @@ -262,7 +262,7 @@ impl NavmesherBoard { pub fn insert_segment(&mut self, segment: Segment) -> SegmentId { let segment_id = self.board.add_segment(segment); self.segment_multiobstacles.insert( - segment_id.id(), + segment_id.index(), self.navmesher.insert_multiobstacle( segment.layer, self.segment_bounding_rectangle(segment_id, segment), @@ -295,7 +295,7 @@ impl NavmesherBoard { pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId { let polygon_id = self.board.add_polygon(polygon.clone()); self.polygon_multiobstacles.insert( - polygon_id.id(), + polygon_id.index(), self.navmesher .insert_multiobstacle(polygon.layer, polygon.vertices), ); diff --git a/topola/src/primitives.rs b/topola/src/primitives.rs index 93b7125..7c89133 100644 --- a/topola/src/primitives.rs +++ b/topola/src/primitives.rs @@ -11,6 +11,13 @@ use crate::{ layout::{NetId, PinId}, }; +#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub enum PrimitiveId { + Joint(JointId), + Segment(SegmentId), + Polygon(PolygonId), +} + #[derive( Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, )] @@ -19,7 +26,7 @@ pub struct JointId(usize); impl JointId { /// Returns the underlying index. #[inline] - pub fn id(self) -> usize { + pub fn index(self) -> usize { self.0 } } @@ -63,7 +70,7 @@ pub struct SegmentId(usize); impl SegmentId { /// Returns the underlying index. #[inline] - pub fn id(self) -> usize { + pub fn index(self) -> usize { self.0 } } @@ -85,7 +92,7 @@ pub struct ViaId(usize); impl ViaId { /// Returns the underlying index. #[inline] - pub fn id(self) -> usize { + pub fn index(self) -> usize { self.0 } } @@ -113,7 +120,7 @@ pub struct PolygonId(usize); impl PolygonId { /// Returns the underlying index. #[inline] - pub fn id(self) -> usize { + pub fn index(self) -> usize { self.0 } }