From 6a2102e0a22305bf818915da7681a6d9032bb14c Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sat, 13 Sep 2025 20:44:33 +0200 Subject: [PATCH] refactor(graph): Rename `GetPetgraphIndex` to `GetIndex` --- src/autorouter/ratsnest.rs | 8 +- src/autorouter/selection.rs | 4 +- src/board/mod.rs | 4 +- src/drawing/bend.rs | 4 +- src/drawing/dot.rs | 4 +- src/drawing/drawing.rs | 6 +- src/drawing/gear.rs | 6 +- src/drawing/graph.rs | 4 +- src/drawing/loose.rs | 12 +-- src/drawing/primitive.rs | 67 ++++++------ src/drawing/seg.rs | 6 +- src/geometry/compound.rs | 6 +- src/geometry/edit.rs | 18 ++-- src/geometry/geometry.rs | 154 +++++++++++---------------- src/geometry/recording_with_rtree.rs | 18 ++-- src/geometry/with_rtree.rs | 57 +++++----- src/graph.rs | 12 +-- src/layout/collect_bands.rs | 6 +- src/layout/layout.rs | 26 ++--- src/layout/poly.rs | 12 +-- src/layout/via.rs | 4 +- src/router/navmesh.rs | 31 +++--- src/router/ng/eval.rs | 6 +- src/router/ng/mod.rs | 4 +- src/router/ng/poly.rs | 4 +- src/router/prenavmesh.rs | 10 +- src/triangulation.rs | 39 ++++--- tests/common/mod.rs | 8 +- 28 files changed, 243 insertions(+), 297 deletions(-) diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index 3886510..628baaf 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -24,7 +24,7 @@ use crate::{ rules::AccessRules, }, geometry::shape::AccessShape, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, layout::{ poly::{MakePolygon, PolyWeight}, Layout, @@ -34,7 +34,7 @@ use crate::{ use super::ratline::{RatlineIndex, RatlineWeight}; -#[enum_dispatch(GetPetgraphIndex)] +#[enum_dispatch(GetIndex)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum RatvertexIndex { FixedDot(FixedDotIndex), @@ -144,8 +144,8 @@ impl Ratsnest { this.graph.retain_edges(|g, i| { if let Some((source, target)) = g.edge_endpoints(i) { - let source_index = g.node_weight(source).unwrap().node_index().petgraph_index(); - let target_index = g.node_weight(target).unwrap().node_index().petgraph_index(); + let source_index = g.node_weight(source).unwrap().node_index().index(); + let target_index = g.node_weight(target).unwrap().node_index().index(); !unionfind.equiv(source_index, target_index) } else { true diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index 62b52eb..7e0eb59 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -14,7 +14,7 @@ use crate::{ shape::{AccessShape, Shape}, GenericNode, GetLayer, }, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, layout::{poly::PolyWeight, CompoundWeight, NodeIndex}, }; @@ -36,7 +36,7 @@ impl PinSelector { NodeIndex::Compound(compound) => { if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound) { - GenericIndex::::new(compound.petgraph_index()) + GenericIndex::::new(compound.index()) .ref_(board.layout()) .layer() } else { diff --git a/src/board/mod.rs b/src/board/mod.rs index 44cc3c5..e89540a 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -40,7 +40,7 @@ pub enum ResolvedSelector<'a> { impl<'a> ResolvedSelector<'a> { pub fn try_from_node(board: &'a Board, node: NodeIndex) -> Option { - use crate::{drawing::graph::MakePrimitiveRef, graph::GetPetgraphIndex}; + use crate::{drawing::graph::MakePrimitiveRef, graph::GetIndex}; let (layer, loose) = match node { NodeIndex::Primitive(primitive) => ( @@ -50,7 +50,7 @@ impl<'a> ResolvedSelector<'a> { NodeIndex::Compound(compound) => { match board.layout().drawing().compound_weight(compound) { CompoundWeight::Poly(..) => ( - GenericIndex::::new(compound.petgraph_index()) + GenericIndex::::new(compound.index()) .ref_(board.layout()) .layer(), None, diff --git a/src/drawing/bend.rs b/src/drawing/bend.rs index c494b9d..564e022 100644 --- a/src/drawing/bend.rs +++ b/src/drawing/bend.rs @@ -12,12 +12,12 @@ use crate::{ Drawing, }, geometry::{GetLayer, GetOffset, GetWidth, SetOffset}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, }; use petgraph::stable_graph::NodeIndex; -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum BendIndex { Fixed(FixedBendIndex), diff --git a/src/drawing/dot.rs b/src/drawing/dot.rs index 3d289ff..5d9cb68 100644 --- a/src/drawing/dot.rs +++ b/src/drawing/dot.rs @@ -15,11 +15,11 @@ use crate::{ Drawing, }, geometry::{GetLayer, GetSetPos, GetWidth}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, math::Circle, }; -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum DotIndex { Fixed(FixedDotIndex), diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index f6cef61..8b69572 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -37,7 +37,7 @@ use crate::{ AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, GetLayer, GetOffset, GetSetPos, GetWidth, }, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, math::{NoBitangents, RotationSense}, }; @@ -570,7 +570,7 @@ impl Drawing { let core = *self .recording_geometry_with_rtree .graph() - .neighbors(inner.petgraph_index()) + .neighbors(inner.index()) .filter(|ni| { matches!( self.recording_geometry_with_rtree @@ -578,7 +578,7 @@ impl Drawing { .edge_weight( self.recording_geometry_with_rtree .graph() - .find_edge(inner.petgraph_index(), *ni) + .find_edge(inner.index(), *ni) .unwrap() ) .unwrap(), diff --git a/src/drawing/gear.rs b/src/drawing/gear.rs index 76715c0..242dc41 100644 --- a/src/drawing/gear.rs +++ b/src/drawing/gear.rs @@ -16,10 +16,10 @@ use crate::{ rules::AccessRules, Drawing, }, - graph::{GetPetgraphIndex, MakeRef}, + graph::{GetIndex, MakeRef}, }; -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum GearIndex { FixedDot(FixedDotIndex), @@ -53,7 +53,7 @@ impl From for GearIndex { } } -#[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetPetgraphIndex)] +#[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetIndex)] pub enum GearRef<'a, CW, Cel, R> { FixedDot(FixedDotRef<'a, CW, Cel, R>), FixedBend(FixedBendRef<'a, CW, Cel, R>), diff --git a/src/drawing/graph.rs b/src/drawing/graph.rs index 4ff5b1e..86ef5ff 100644 --- a/src/drawing/graph.rs +++ b/src/drawing/graph.rs @@ -7,7 +7,7 @@ use petgraph::stable_graph::NodeIndex; use crate::{ geometry::GetLayer, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, }; use super::{ @@ -88,7 +88,7 @@ macro_rules! impl_weight_forward { // TODO: This enum shouldn't exist: we shouldn't be carrying the tag around like this. Instead we // should be getting it from the graph when it's needed. -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum PrimitiveIndex { FixedDot(FixedDotIndex), diff --git a/src/drawing/loose.rs b/src/drawing/loose.rs index f025131..0d53b20 100644 --- a/src/drawing/loose.rs +++ b/src/drawing/loose.rs @@ -17,7 +17,7 @@ use crate::{ rules::AccessRules, seg::{LoneLooseSegIndex, SeqLooseSegIndex}, }, - graph::GetPetgraphIndex, + graph::GetIndex, }; #[enum_dispatch] @@ -38,7 +38,7 @@ pub trait GetPrevNextLoose { } } -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum LooseIndex { Dot(LooseDotIndex), @@ -71,7 +71,7 @@ impl TryFrom for LooseIndex { } } -#[enum_dispatch(GetPrevNextLoose, GetDrawing, GetPetgraphIndex)] +#[enum_dispatch(GetPrevNextLoose, GetDrawing, GetIndex)] pub enum Loose<'a, CW, Cel, R> { Dot(LooseDotRef<'a, CW, Cel, R>), LoneSeg(LoneLooseSegRef<'a, CW, Cel, R>), @@ -95,7 +95,7 @@ impl GetPrevNextLoose for LooseDotRef<'_, CW, Cel, R> { let bend = self.bend(); if let Some(prev) = maybe_prev { - if bend.petgraph_index() != prev.petgraph_index() { + if bend.index() != prev.index() { Some(bend.into()) } else { self.seg().map(Into::into) @@ -119,7 +119,7 @@ impl GetPrevNextLoose for SeqLooseSegRef<'_, CW, Cel, R> { return Some(joints.1.into()); }; - if joints.0.petgraph_index() != prev.petgraph_index() { + if joints.0.index() != prev.index() { match joints.0 { DotIndex::Fixed(..) => None, DotIndex::Loose(dot) => Some(dot.into()), @@ -135,7 +135,7 @@ impl GetPrevNextLoose for LooseBendRef<'_, CW, Cel, R> { let joints = self.joints(); if let Some(prev) = maybe_prev { - if joints.0.petgraph_index() != prev.petgraph_index() { + if joints.0.index() != prev.index() { Some(joints.0.into()) } else { Some(joints.1.into()) diff --git a/src/drawing/primitive.rs b/src/drawing/primitive.rs index 2b4a59c..a80c867 100644 --- a/src/drawing/primitive.rs +++ b/src/drawing/primitive.rs @@ -15,7 +15,7 @@ use crate::{ Drawing, }, geometry::{primitive::PrimitiveShape, GenericNode, GetLayer, GetOffset, GetWidth, Retag}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, }; use super::gear::{DrawingOutwardWalker, GetOuterGears, WalkOutwards}; @@ -67,14 +67,14 @@ pub trait GetOtherJoint: GetJoints { impl GetOtherJoint for S where - F: GetPetgraphIndex, + F: GetIndex, S: GetJoints, - ::T: GetPetgraphIndex + Into, + ::T: GetIndex + Into, { type J = F; fn other_joint(&self, end: F) -> F { let joints = self.joints(); - if joints.0.petgraph_index() != end.petgraph_index() { + if joints.0.index() != end.index() { joints.0 } else { joints.1.into() @@ -88,13 +88,13 @@ pub trait GetJoints { fn joints(&self) -> (Self::F, Self::T); } -pub trait GetLowestGears: GetDrawing + GetPetgraphIndex { +pub trait GetLowestGears: GetDrawing + GetIndex { // TODO: Make it return an iterator instead of a vec. fn lowest_gears(&self) -> Vec { self.drawing() .geometry() - .all_rails(self.petgraph_index()) - .map(|ni| LooseBendIndex::new(ni.petgraph_index())) + .all_rails(self.index()) + .map(|ni| LooseBendIndex::new(ni.index())) .collect() } } @@ -109,12 +109,7 @@ pub trait GetCore: GetBendIndex { impl GetCore for S { fn core(&self) -> FixedDotIndex { - FixedDotIndex::new( - self.drawing() - .geometry() - .core(self.bend_index()) - .petgraph_index(), - ) + FixedDotIndex::new(self.drawing().geometry().core(self.bend_index()).index()) } } @@ -205,7 +200,7 @@ impl<'a, W, CW, Cel, R> GenericPrimitive<'a, W, CW, Cel, R> { .drawing .geometry() .graph() - .node_weight(self.index.petgraph_index()) + .node_weight(self.index.index()) .unwrap() { *weight @@ -217,7 +212,7 @@ impl<'a, W, CW, Cel, R> GenericPrimitive<'a, W, CW, Cel, R> { impl GetInterior for GenericPrimitive<'_, W, CW, Cel, R> { fn interior(&self) -> Vec { - vec![self.tagged_weight().retag(self.index.petgraph_index())] + vec![self.tagged_weight().retag(self.index.index())] } } @@ -230,9 +225,9 @@ impl GetDrawing for GenericPrimitive<'_, W, CW, Cel, R> { } } -impl GetPetgraphIndex for GenericPrimitive<'_, W, CW, Cel, R> { - fn petgraph_index(&self) -> NodeIndex { - self.index.petgraph_index() +impl GetIndex for GenericPrimitive<'_, W, CW, Cel, R> { + fn index(&self) -> NodeIndex { + self.index.index() } } @@ -305,7 +300,7 @@ impl LooseDotRef<'_, CW, Cel, R> { self.drawing .geometry() .joined_segs(self.index.into()) - .map(|ni| SeqLooseSegIndex::new(ni.petgraph_index())) + .map(|ni| SeqLooseSegIndex::new(ni.index())) .next() } @@ -313,7 +308,7 @@ impl LooseDotRef<'_, CW, Cel, R> { self.drawing .geometry() .joined_bends(self.index.into()) - .map(|ni| LooseBendIndex::new(ni.petgraph_index())) + .map(|ni| LooseBendIndex::new(ni.index())) .next() .unwrap() } @@ -356,8 +351,8 @@ impl GetJoints for FixedSegRef<'_, CW, Cel, R> { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { let (from, to) = self.drawing.geometry().seg_joints(self.index.into()); ( - FixedDotIndex::new(from.petgraph_index()), - FixedDotIndex::new(to.petgraph_index()), + FixedDotIndex::new(from.index()), + FixedDotIndex::new(to.index()), ) } } @@ -379,8 +374,8 @@ impl GetJoints for LoneLooseSegRef<'_, CW, Cel, R> { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { let (from, to) = self.drawing.geometry().seg_joints(self.index.into()); ( - FixedDotIndex::new(from.petgraph_index()), - FixedDotIndex::new(to.petgraph_index()), + FixedDotIndex::new(from.index()), + FixedDotIndex::new(to.index()), ) } } @@ -403,18 +398,18 @@ impl GetJoints for SeqLooseSegRef<'_, CW, Cel, R> { let joints = self.drawing.geometry().seg_joints(self.index.into()); if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) { ( - FixedDotIndex::new(joints.0.petgraph_index()).into(), - LooseDotIndex::new(joints.1.petgraph_index()), + FixedDotIndex::new(joints.0.index()).into(), + LooseDotIndex::new(joints.1.index()), ) } else if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.1) { ( - FixedDotIndex::new(joints.1.petgraph_index()).into(), - LooseDotIndex::new(joints.0.petgraph_index()), + FixedDotIndex::new(joints.1.index()).into(), + LooseDotIndex::new(joints.0.index()), ) } else { ( - LooseDotIndex::new(joints.0.petgraph_index()).into(), - LooseDotIndex::new(joints.1.petgraph_index()), + LooseDotIndex::new(joints.0.index()).into(), + LooseDotIndex::new(joints.1.index()), ) } } @@ -443,8 +438,8 @@ impl GetJoints for FixedBendRef<'_, CW, Cel, R> { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); ( - FixedDotIndex::new(from.petgraph_index()), - FixedDotIndex::new(to.petgraph_index()), + FixedDotIndex::new(from.index()), + FixedDotIndex::new(to.index()), ) } } @@ -498,8 +493,8 @@ impl GetJoints for LooseBendRef<'_, CW, Cel, R> { fn joints(&self) -> (LooseDotIndex, LooseDotIndex) { let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); ( - LooseDotIndex::new(from.petgraph_index()), - LooseDotIndex::new(to.petgraph_index()), + LooseDotIndex::new(from.index()), + LooseDotIndex::new(to.index()), ) } } @@ -521,13 +516,13 @@ impl LooseBendRef<'_, CW, Cel, R> { self.drawing() .geometry() .inner(self.bend_index()) - .map(|ni| LooseBendIndex::new(ni.petgraph_index())) + .map(|ni| LooseBendIndex::new(ni.index())) } pub fn outers(&self) -> impl Iterator + '_ { self.drawing() .geometry() .outers(self.bend_index()) - .map(|node| LooseBendIndex::new(node.petgraph_index())) + .map(|node| LooseBendIndex::new(node.index())) } } diff --git a/src/drawing/seg.rs b/src/drawing/seg.rs index d172f9f..ab4047c 100644 --- a/src/drawing/seg.rs +++ b/src/drawing/seg.rs @@ -13,12 +13,12 @@ use crate::{ Drawing, }, geometry::{GetLayer, GetWidth}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, }; use petgraph::stable_graph::NodeIndex; -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] pub enum SegIndex { Fixed(FixedSegIndex), @@ -26,7 +26,7 @@ pub enum SegIndex { SeqLoose(SeqLooseSegIndex), } -#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] +#[enum_dispatch(GetIndex, MakePrimitiveRef)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] pub enum LooseSegIndex { Lone(LoneLooseSegIndex), diff --git a/src/geometry/compound.rs b/src/geometry/compound.rs index d8cbf1b..8de4045 100644 --- a/src/geometry/compound.rs +++ b/src/geometry/compound.rs @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -use crate::graph::{GenericIndex, GetPetgraphIndex}; +use crate::graph::{GenericIndex, GetIndex}; pub trait ManageCompounds { type GeneralIndex: Copy; @@ -12,7 +12,7 @@ pub trait ManageCompounds { fn remove_compound(&mut self, compound: GenericIndex); fn add_to_compound(&mut self, node: I, label: Self::EntryLabel, compound: GenericIndex) where - I: Copy + GetPetgraphIndex; + I: Copy + GetIndex; fn compound_weight(&self, node: GenericIndex) -> &CW; @@ -23,5 +23,5 @@ pub trait ManageCompounds { fn compounds(&self, node: I) -> impl Iterator)> where - I: Copy + GetPetgraphIndex; + I: Copy + GetIndex; } diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index 7197ebe..b3f3c14 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -4,7 +4,7 @@ use std::collections::{btree_map::Entry, BTreeMap}; -use crate::graph::{GenericIndex, GetPetgraphIndex}; +use crate::graph::{GenericIndex, GetIndex}; use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer}; @@ -39,10 +39,10 @@ pub trait ApplyGeometryEdit< BW: AccessBendWeight + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, - DI: GetPetgraphIndex + Into + Eq + Ord + Copy, - SI: GetPetgraphIndex + Into + Eq + Ord + Copy, - BI: GetPetgraphIndex + Into + Eq + Ord + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, + DI: GetIndex + Into + Eq + Ord + Copy, + SI: GetIndex + Into + Eq + Ord + Copy, + BI: GetIndex + Into + Eq + Ord + Copy, > { fn apply(&mut self, edit: &GeometryEdit); @@ -89,10 +89,10 @@ impl< BW: AccessBendWeight + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, - DI: GetPetgraphIndex + Into + Eq + Ord + Copy, - SI: GetPetgraphIndex + Into + Eq + Ord + Copy, - BI: GetPetgraphIndex + Into + Eq + Ord + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, + DI: GetIndex + Into + Eq + Ord + Copy, + SI: GetIndex + Into + Eq + Ord + Copy, + BI: GetIndex + Into + Eq + Ord + Copy, > Edit for GeometryEdit { fn reverse_inplace(&mut self) { diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index b025103..885b702 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -25,12 +25,12 @@ use crate::{ compound::ManageCompounds, primitive::{BendShape, DotShape, PrimitiveShape, SegShape}, }, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, math::Circle, }; pub trait Retag { - type Index: Sized + GetPetgraphIndex + PartialEq + Copy; + type Index: Sized + GetIndex + PartialEq + Copy; fn retag(&self, index: NodeIndex) -> Self::Index; } @@ -74,11 +74,11 @@ pub enum GenericNode { Compound(C), } -impl GetPetgraphIndex for GenericNode { - fn petgraph_index(&self) -> NodeIndex { +impl GetIndex for GenericNode { + fn index(&self) -> NodeIndex { match self { - Self::Primitive(x) => x.petgraph_index(), - Self::Compound(x) => x.petgraph_index(), + Self::Primitive(x) => x.index(), + Self::Compound(x) => x.index(), } } } @@ -168,10 +168,10 @@ impl< BW: AccessBendWeight + Into, CW, Cel, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Copy, + DI: GetIndex + Into + Copy, + SI: GetIndex + Into + Copy, + BI: GetIndex + Into + Copy, > Geometry { pub fn add_dot>(&mut self, weight: W) -> GenericIndex { @@ -184,7 +184,7 @@ impl< weight: W, ) { self.graph - .update_node(dot.petgraph_index(), GenericNode::Primitive(weight.into())); + .update_node(dot.index(), GenericNode::Primitive(weight.into())); } pub fn add_seg>( @@ -207,7 +207,7 @@ impl< weight: W, ) { self.graph - .update_node(seg.petgraph_index(), GenericNode::Primitive(weight.into())); + .update_node(seg.index(), GenericNode::Primitive(weight.into())); self.init_seg_joints(seg, from, to); } @@ -217,28 +217,22 @@ impl< from: DI, to: DI, ) { - self.graph.update_edge( - from.petgraph_index(), - seg.petgraph_index(), - GeometryLabel::Joined, - ); - self.graph.update_edge( - seg.petgraph_index(), - to.petgraph_index(), - GeometryLabel::Joined, - ); + self.graph + .update_edge(from.index(), seg.index(), GeometryLabel::Joined); + self.graph + .update_edge(seg.index(), to.index(), GeometryLabel::Joined); } pub fn is_joined_with(&self, seg: I, node: GenericNode>) -> bool where - I: Copy + GetPetgraphIndex, + I: Copy + GetIndex, CW: Clone, Cel: Copy, { match node { GenericNode::Primitive(prim) => self .graph - .find_edge_undirected(seg.petgraph_index(), prim.petgraph_index()) + .find_edge_undirected(seg.index(), prim.index()) .map_or(false, |(eidx, _direction)| { matches!(self.graph.edge_weight(eidx).unwrap(), GeometryLabel::Joined) }), @@ -270,13 +264,13 @@ impl< weight: W, ) { self.graph - .update_node(bend.petgraph_index(), GenericNode::Primitive(weight.into())); + .update_node(bend.index(), GenericNode::Primitive(weight.into())); self.init_bend_joints_and_core(bend, from, to, core); } pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex, weight: CW) { self.graph - .update_node(compound.petgraph_index(), GenericNode::Compound(weight)); + .update_node(compound.index(), GenericNode::Compound(weight)); } fn init_bend_joints_and_core>( @@ -286,80 +280,58 @@ impl< to: DI, core: DI, ) { - self.graph.update_edge( - from.petgraph_index(), - bend.petgraph_index(), - GeometryLabel::Joined, - ); - self.graph.update_edge( - bend.petgraph_index(), - to.petgraph_index(), - GeometryLabel::Joined, - ); - self.graph.update_edge( - bend.petgraph_index(), - core.petgraph_index(), - GeometryLabel::Core, - ); + self.graph + .update_edge(from.index(), bend.index(), GeometryLabel::Joined); + self.graph + .update_edge(bend.index(), to.index(), GeometryLabel::Joined); + self.graph + .update_edge(bend.index(), core.index(), GeometryLabel::Core); } pub fn remove_primitive(&mut self, primitive: PI) { - debug_assert!(self.graph.remove_node(primitive.petgraph_index()).is_some()); + debug_assert!(self.graph.remove_node(primitive.index()).is_some()); } pub fn move_dot(&mut self, dot: DI, to: Point) { let mut weight = self.dot_weight(dot); weight.set_pos(to); - *self.graph.node_weight_mut(dot.petgraph_index()).unwrap() = - GenericNode::Primitive(weight.into()); + *self.graph.node_weight_mut(dot.index()).unwrap() = GenericNode::Primitive(weight.into()); } pub fn shift_bend(&mut self, bend: BI, offset: f64) { let mut weight = self.bend_weight(bend); weight.set_offset(offset); - *self.graph.node_weight_mut(bend.petgraph_index()).unwrap() = - GenericNode::Primitive(weight.into()); + *self.graph.node_weight_mut(bend.index()).unwrap() = GenericNode::Primitive(weight.into()); } pub fn flip_bend(&mut self, bend: BI) { let (from, to) = self.bend_joints(bend); let from_edge_weight = self .graph - .remove_edge( - self.graph - .find_edge(from.petgraph_index(), bend.petgraph_index()) - .unwrap(), - ) + .remove_edge(self.graph.find_edge(from.index(), bend.index()).unwrap()) .unwrap(); let to_edge_weight = self .graph - .remove_edge( - self.graph - .find_edge(bend.petgraph_index(), to.petgraph_index()) - .unwrap(), - ) + .remove_edge(self.graph.find_edge(bend.index(), to.index()).unwrap()) .unwrap(); self.graph - .update_edge(from.petgraph_index(), bend.petgraph_index(), to_edge_weight); + .update_edge(from.index(), bend.index(), to_edge_weight); self.graph - .update_edge(bend.petgraph_index(), to.petgraph_index(), from_edge_weight); + .update_edge(bend.index(), to.index(), from_edge_weight); } pub fn reattach_bend(&mut self, bend: BI, maybe_new_inner: Option) { if let Some(old_inner_edge) = self .graph - .edges_directed(bend.petgraph_index(), Incoming) + .edges_directed(bend.index(), Incoming) .find(|edge| matches!(edge.weight(), GeometryLabel::Outer)) { debug_assert!(self.graph.remove_edge(old_inner_edge.id()).is_some()); } if let Some(new_inner) = maybe_new_inner { - self.graph.update_edge( - new_inner.petgraph_index(), - bend.petgraph_index(), - GeometryLabel::Outer, - ); + self.graph + .update_edge(new_inner.index(), bend.index(), GeometryLabel::Outer); } } @@ -378,7 +350,7 @@ impl< PrimitiveShape::Seg(SegShape { from: self.dot_weight(from).pos(), to: self.dot_weight(to).pos(), - width: self.primitive_weight(seg.petgraph_index()).width(), + width: self.primitive_weight(seg.index()).width(), }) } @@ -392,7 +364,7 @@ impl< pos: core_weight.pos(), r: self.inner_radius(bend), }, - width: self.primitive_weight(bend.petgraph_index()).width(), + width: self.primitive_weight(bend.index()).width(), }) } @@ -410,27 +382,25 @@ impl< } pub fn dot_weight(&self, dot: DI) -> DW { - self.primitive_weight(dot.petgraph_index()) + self.primitive_weight(dot.index()) .try_into() .unwrap_or_else(|_| unreachable!()) } pub fn seg_weight(&self, seg: SI) -> SW { - self.primitive_weight(seg.petgraph_index()) + self.primitive_weight(seg.index()) .try_into() .unwrap_or_else(|_| unreachable!()) } pub fn bend_weight(&self, bend: BI) -> BW { - self.primitive_weight(bend.petgraph_index()) + self.primitive_weight(bend.index()) .try_into() .unwrap_or_else(|_| unreachable!()) } pub fn compound_weight(&self, compound: GenericIndex) -> &CW { - if let GenericNode::Compound(weight) = - self.graph.node_weight(compound.petgraph_index()).unwrap() - { + if let GenericNode::Compound(weight) = self.graph.node_weight(compound.index()).unwrap() { weight } else { unreachable!() @@ -439,7 +409,7 @@ impl< fn core_weight(&self, bend: BI) -> DW { self.graph - .edges_directed(bend.petgraph_index(), Outgoing) + .edges_directed(bend.index(), Outgoing) .find(|edge| matches!(edge.weight(), GeometryLabel::Core)) .map(|edge| { self.primitive_weight(edge.target()) @@ -451,13 +421,13 @@ impl< pub fn joineds(&self, node: PI) -> impl Iterator + '_ { self.graph - .neighbors_undirected(node.petgraph_index()) + .neighbors_undirected(node.index()) .filter(move |ni| { matches!( self.graph .edge_weight( self.graph - .find_edge_undirected(node.petgraph_index(), *ni) + .find_edge_undirected(node.index(), *ni) .unwrap() .0, ) @@ -479,12 +449,12 @@ impl< fn joints(&self, node: PI) -> (DI, DI) { let lhs = self .graph - .edges_directed(node.petgraph_index(), Incoming) + .edges_directed(node.index(), Incoming) .find(|edge| matches!(edge.weight(), GeometryLabel::Joined)) .map(|edge| edge.source()); let rhs = self .graph - .edges_directed(node.petgraph_index(), Outgoing) + .edges_directed(node.index(), Outgoing) .find(|edge| matches!(edge.weight(), GeometryLabel::Joined)) .map(|edge| edge.target()); @@ -525,7 +495,7 @@ pub struct OutwardWalker { frontier: VecDeque, } -impl OutwardWalker { +impl OutwardWalker { pub fn new(initial_frontier: impl Iterator) -> Self { let mut frontier = VecDeque::new(); frontier.extend(initial_frontier); @@ -544,7 +514,7 @@ impl< PI: TryInto + TryInto + TryInto, DI, SI, - BI: Copy + GetPetgraphIndex, + BI: Copy + GetIndex, > Walker<&Geometry> for OutwardWalker { type Item = BI; @@ -570,7 +540,7 @@ impl< PI: TryInto + TryInto + TryInto, DI, SI, - BI: GetPetgraphIndex, + BI: GetIndex, > Geometry { pub fn all_rails(&self, node: NodeIndex) -> impl Iterator + '_ { @@ -586,7 +556,7 @@ impl< pub fn core(&self, bend: BI) -> DI { self.graph - .edges_directed(bend.petgraph_index(), Outgoing) + .edges_directed(bend.index(), Outgoing) .find(|edge| matches!(edge.weight(), GeometryLabel::Core)) .map(|edge| { self.primitive_index(edge.target()) @@ -598,7 +568,7 @@ impl< pub fn inner(&self, bend: BI) -> Option { self.graph - .edges_directed(bend.petgraph_index(), Incoming) + .edges_directed(bend.index(), Incoming) .find(|edge| matches!(edge.weight(), GeometryLabel::Outer)) .map(|edge| { self.primitive_index(edge.source()) @@ -609,7 +579,7 @@ impl< pub fn outers(&self, bend: BI) -> impl Iterator + '_ { self.graph - .edges_directed(bend.petgraph_index(), Outgoing) + .edges_directed(bend.index(), Outgoing) .filter(|edge| matches!(edge.weight(), GeometryLabel::Outer)) .map(|edge| { self.primitive_index(edge.target()) @@ -634,24 +604,22 @@ impl, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D } fn remove_compound(&mut self, compound: GenericIndex) { - debug_assert!(self.graph.remove_node(compound.petgraph_index()).is_some()); + debug_assert!(self.graph.remove_node(compound.index()).is_some()); } fn add_to_compound(&mut self, primitive: I, entry_label: Cel, compound: GenericIndex) where - I: Copy + GetPetgraphIndex, + I: Copy + GetIndex, { self.graph.update_edge( - primitive.petgraph_index(), - compound.petgraph_index(), + primitive.index(), + compound.index(), GeometryLabel::Compound(entry_label), ); } fn compound_weight(&self, compound: GenericIndex) -> &CW { - if let GenericNode::Compound(weight) = - self.graph.node_weight(compound.petgraph_index()).unwrap() - { + if let GenericNode::Compound(weight) = self.graph.node_weight(compound.index()).unwrap() { weight } else { unreachable!() @@ -663,7 +631,7 @@ impl, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D compound: GenericIndex, ) -> impl Iterator + '_ { self.graph - .edges_directed(compound.petgraph_index(), Incoming) + .edges_directed(compound.index(), Incoming) .filter_map(|edge| { if let GeometryLabel::Compound(entry_label) = *edge.weight() { Some((entry_label, self.primitive_index(edge.source()))) @@ -675,10 +643,10 @@ impl, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D fn compounds(&self, node: I) -> impl Iterator)> where - I: Copy + GetPetgraphIndex, + I: Copy + GetIndex, { self.graph - .edges_directed(node.petgraph_index(), Outgoing) + .edges_directed(node.index(), Outgoing) .filter_map(|edge| { if let GeometryLabel::Compound(entry_label) = *edge.weight() { Some((entry_label, GenericIndex::new(edge.target()))) diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index 8b82258..eb19d55 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -8,7 +8,7 @@ use geo::Point; use petgraph::stable_graph::StableDiGraph; use rstar::RTree; -use crate::graph::{GenericIndex, GetPetgraphIndex}; +use crate::graph::{GenericIndex, GetIndex}; use super::{ compound::ManageCompounds, @@ -60,10 +60,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, - DI: GetPetgraphIndex + Into + Eq + Ord + Copy, - SI: GetPetgraphIndex + Into + Eq + Ord + Copy, - BI: GetPetgraphIndex + Into + Eq + Ord + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, + DI: GetIndex + Into + Eq + Ord + Copy, + SI: GetIndex + Into + Eq + Ord + Copy, + BI: GetIndex + Into + Eq + Ord + Copy, > RecordingGeometryWithRtree { pub fn new(layer_count: usize) -> Self { @@ -363,10 +363,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, - DI: GetPetgraphIndex + Into + Eq + Ord + Copy, - SI: GetPetgraphIndex + Into + Eq + Ord + Copy, - BI: GetPetgraphIndex + Into + Eq + Ord + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, + DI: GetIndex + Into + Eq + Ord + Copy, + SI: GetIndex + Into + Eq + Ord + Copy, + BI: GetIndex + Into + Eq + Ord + Copy, > ApplyGeometryEdit for RecordingGeometryWithRtree { diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index b6f6d1d..e57a2dc 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -15,7 +15,7 @@ use crate::{ AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, GetLayer, GetWidth, Retag, }, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, }; use super::edit::{ApplyGeometryEdit, GeometryEdit}; @@ -76,10 +76,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + PartialEq + Copy, + DI: GetIndex + Into + Copy, + SI: GetIndex + Into + Copy, + BI: GetIndex + Into + Copy, > GeometryWithRtree { pub fn new(layer_count: usize) -> Self { @@ -108,7 +108,7 @@ impl< weight: W, ) { self.geometry - .add_dot_at_index(GenericIndex::::new(dot.petgraph_index()), weight); + .add_dot_at_index(GenericIndex::::new(dot.index()), weight); self.init_dot_bbox(dot); } @@ -133,12 +133,8 @@ impl< to: DI, weight: W, ) { - self.geometry.add_seg_at_index( - GenericIndex::::new(seg.petgraph_index()), - from, - to, - weight, - ); + self.geometry + .add_seg_at_index(GenericIndex::::new(seg.index()), from, to, weight); self.init_seg_bbox(seg); } @@ -159,7 +155,7 @@ impl< pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex, weight: CW) { self.geometry - .add_compound_at_index(GenericIndex::::new(compound.petgraph_index()), weight); + .add_compound_at_index(GenericIndex::::new(compound.index()), weight); } pub fn add_to_compound( @@ -314,10 +310,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + PartialEq + Copy, + DI: GetIndex + Into + Copy, + SI: GetIndex + Into + Copy, + BI: GetIndex + Into + Copy, > GeometryWithRtree { fn init_dot_bbox(&mut self, dot: DI) { @@ -443,10 +439,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, - DI: GetPetgraphIndex + Into + Copy, - SI: GetPetgraphIndex + Into + Copy, - BI: GetPetgraphIndex + Into + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + PartialEq + Copy, + DI: GetIndex + Into + Copy, + SI: GetIndex + Into + Copy, + BI: GetIndex + Into + Copy, > ManageCompounds for GeometryWithRtree { type GeneralIndex = PI; @@ -467,7 +463,7 @@ impl< fn add_to_compound(&mut self, primitive: I, label: Cel, compound: GenericIndex) where - I: Copy + GetPetgraphIndex, + I: Copy + GetIndex, { self.geometry.add_to_compound(primitive, label, compound); } @@ -485,7 +481,7 @@ impl< fn compounds(&self, node: I) -> impl Iterator)> where - I: Copy + GetPetgraphIndex, + I: Copy + GetIndex, { self.geometry.compounds(node) } @@ -498,10 +494,10 @@ impl< BW: AccessBendWeight + Into + GetLayer, CW: Clone, Cel: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, - DI: GetPetgraphIndex + Into + Eq + Ord + Copy, - SI: GetPetgraphIndex + Into + Eq + Ord + Copy, - BI: GetPetgraphIndex + Into + Eq + Ord + Copy, + PI: GetIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, + DI: GetIndex + Into + Eq + Ord + Copy, + SI: GetIndex + Into + Eq + Ord + Copy, + BI: GetIndex + Into + Eq + Ord + Copy, > ApplyGeometryEdit for GeometryWithRtree { @@ -563,8 +559,7 @@ impl< // Despite this method's name, it actually does not add the // dot, it updates it. - geometry - .add_dot_at_index(GenericIndex::::new(dot.petgraph_index()), *weight); + geometry.add_dot_at_index(GenericIndex::::new(dot.index()), *weight); }) } } @@ -592,7 +587,7 @@ impl< for (bend, (.., maybe_new_data)) in &edit.bends { if let Some(((from, to, core, ..), weight)) = maybe_new_data { self.geometry.add_bend_at_index( - GenericIndex::::new(bend.petgraph_index()), + GenericIndex::::new(bend.index()), *from, *to, *core, @@ -622,7 +617,7 @@ impl< for (entry_label, member) in members { self.geometry.add_to_compound( - GenericIndex::::new(member.petgraph_index()), + GenericIndex::::new(member.index()), *entry_label, *compound, ); diff --git a/src/graph.rs b/src/graph.rs index 99b41c2..fba5f53 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -14,13 +14,13 @@ pub trait MakeRef<'a, C> { } #[enum_dispatch] -pub trait GetPetgraphIndex { - fn petgraph_index(&self) -> NodeIndex; +pub trait GetIndex { + fn index(&self) -> NodeIndex; } -impl GetPetgraphIndex for NodeIndex { +impl GetIndex for NodeIndex { #[inline(always)] - fn petgraph_index(&self) -> NodeIndex { + fn index(&self) -> NodeIndex { *self } } @@ -92,9 +92,9 @@ impl core::hash::Hash for GenericIndex { } } -impl GetPetgraphIndex for GenericIndex { +impl GetIndex for GenericIndex { #[inline] - fn petgraph_index(&self) -> NodeIndex { + fn index(&self) -> NodeIndex { self.node_index } } diff --git a/src/layout/collect_bands.rs b/src/layout/collect_bands.rs index 70300fb..783b2d8 100644 --- a/src/layout/collect_bands.rs +++ b/src/layout/collect_bands.rs @@ -23,7 +23,7 @@ use crate::{ shape::AccessShape, GenericNode, }, - graph::GetPetgraphIndex, + graph::GetIndex, layout::{Layout, NodeIndex}, math::{intersect_linestring_and_ray, LineInGeneralForm, LineIntersection}, }; @@ -121,7 +121,7 @@ impl Layout { .filter(|(_, band_uid, _)| { // filter entries which are connected to either lhs or rhs (and possibly both) let (bts1, bts2) = band_uid.into(); - let (bts1, bts2) = (bts1.petgraph_index(), bts2.petgraph_index()); + let (bts1, bts2) = (bts1.index(), bts2.index()); let geometry = self.drawing.geometry(); [(bts1, left), (bts1, right), (bts2, left), (bts2, right)] .iter() @@ -162,7 +162,7 @@ impl Layout { .filter(|(_, band_uid, _)| { // filter entries which are connected to rhs let (bts1, bts2) = band_uid.into(); - let (bts1, bts2) = (bts1.petgraph_index(), bts2.petgraph_index()); + let (bts1, bts2) = (bts1.index(), bts2.index()); let geometry = self.drawing.geometry(); [(bts1, right), (bts2, right)] .iter() diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 350d021..fffe39c 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -32,7 +32,7 @@ use crate::{ shape::{AccessShape, Shape}, GenericNode, GetLayer, GetSetPos, }, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, layout::{ poly::{add_poly_with_nodes_intern, MakePolygon, PolyWeight}, via::{Via, ViaWeight}, @@ -179,7 +179,7 @@ impl Layout { } } - Ok(GenericIndex::::new(compound.petgraph_index())) + Ok(GenericIndex::::new(compound.index())) } pub fn add_fixed_dot( @@ -256,7 +256,7 @@ impl Layout { GenericIndex::::new( self.drawing .add_compound(recorder, CompoundWeight::Poly(weight)) - .petgraph_index(), + .index(), ) } @@ -290,7 +290,7 @@ impl Layout { self.drawing.rtree().iter().filter_map(|wrapper| { if let NodeIndex::Compound(compound) = wrapper.data { if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) { - return Some(GenericIndex::::new(compound.petgraph_index())); + return Some(GenericIndex::::new(compound.index())); } } @@ -311,7 +311,7 @@ impl Layout { .filter_map(|wrapper| { if let NodeIndex::Compound(compound) = wrapper.data { if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) { - return Some(GenericIndex::::new(compound.petgraph_index())); + return Some(GenericIndex::::new(compound.index())); } } @@ -325,12 +325,12 @@ impl Layout { ) -> impl Iterator + '_ { self.drawing .geometry() - .compound_members(GenericIndex::new(poly.petgraph_index())) + .compound_members(GenericIndex::new(poly.index())) } fn compound_shape(&self, compound: GenericIndex) -> Shape { match self.drawing.compound_weight(compound) { - CompoundWeight::Poly(_) => GenericIndex::::new(compound.petgraph_index()) + CompoundWeight::Poly(_) => GenericIndex::::new(compound.index()) .ref_(self) .shape() .into(), @@ -360,11 +360,8 @@ impl Layout { let PrimitiveIndex::FixedDot(dot) = index else { return None; }; - if let GenericNode::Primitive(PrimitiveWeight::FixedDot(weight)) = drawing - .geometry() - .graph() - .node_weight(dot.petgraph_index()) - .unwrap() + if let GenericNode::Primitive(PrimitiveWeight::FixedDot(weight)) = + drawing.geometry().graph().node_weight(dot.index()).unwrap() { Some((dot, weight)) } else { @@ -378,7 +375,7 @@ impl Layout { .drawing() .geometry() // TODO: Add `.compounds()` method working on `PrimitiveIndex`. - .compounds(GenericIndex::<()>::new(primitive.petgraph_index())) + .compounds(GenericIndex::<()>::new(primitive.index())) .next() .is_some() { @@ -388,8 +385,7 @@ impl Layout { } NodeIndex::Compound(compound) => Some(match self.drawing.compound_weight(compound) { CompoundWeight::Poly(_) => { - let poly = - GenericIndex::::new(compound.petgraph_index()).ref_(self); + let poly = GenericIndex::::new(compound.index()).ref_(self); (poly.apex(), poly.shape().center()) } CompoundWeight::Via(weight) => { diff --git a/src/layout/poly.rs b/src/layout/poly.rs index ac16fdc..0a1c615 100644 --- a/src/layout/poly.rs +++ b/src/layout/poly.rs @@ -21,7 +21,7 @@ use crate::{ Drawing, }, geometry::{compound::ManageCompounds, GetLayer, GetSetPos}, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, layout::{CompoundEntryLabel, CompoundWeight, Layout, LayoutEdit}, math::Circle, }; @@ -81,7 +81,7 @@ pub(super) fn add_poly_with_nodes_intern( for &idx in nodes { layout.drawing.add_to_compound( recorder, - GenericIndex::<()>::new(idx.petgraph_index()), + GenericIndex::<()>::new(idx.index()), CompoundEntryLabel::Normal, poly_compound, ); @@ -123,7 +123,7 @@ pub(super) fn add_poly_with_nodes_intern( for Rto { idx, .. } in temp_rtree { layout.drawing.add_to_compound( recorder, - GenericIndex::<()>::new(idx.petgraph_index()), + GenericIndex::<()>::new(idx.index()), CompoundEntryLabel::Apex, poly_compound, ); @@ -234,7 +234,7 @@ pub enum PolyWeight { impl From> for GenericIndex { fn from(poly: GenericIndex) -> Self { - GenericIndex::::new(poly.petgraph_index()) + GenericIndex::::new(poly.index()) } } @@ -258,7 +258,7 @@ impl GetMaybeNet for SolidPolyWeight { impl From> for GenericIndex { fn from(poly: GenericIndex) -> Self { - GenericIndex::::new(poly.petgraph_index()) + GenericIndex::::new(poly.index()) } } @@ -282,6 +282,6 @@ impl GetMaybeNet for PourPolyWeight { impl From> for GenericIndex { fn from(poly: GenericIndex) -> Self { - GenericIndex::::new(poly.petgraph_index()) + GenericIndex::::new(poly.index()) } } diff --git a/src/layout/via.rs b/src/layout/via.rs index c590aab..c4d7c00 100644 --- a/src/layout/via.rs +++ b/src/layout/via.rs @@ -14,7 +14,7 @@ use crate::{ Drawing, }, geometry::primitive::{DotShape, PrimitiveShape}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, layout::{CompoundEntryLabel, CompoundWeight}, math::Circle, }; @@ -60,7 +60,7 @@ pub struct ViaWeight { impl From> for GenericIndex { fn from(via: GenericIndex) -> Self { - GenericIndex::::new(via.petgraph_index()) + GenericIndex::::new(via.index()) } } diff --git a/src/router/navmesh.rs b/src/router/navmesh.rs index 1a23f20..3e92b7a 100644 --- a/src/router/navmesh.rs +++ b/src/router/navmesh.rs @@ -27,7 +27,7 @@ use crate::{ graph::PrimitiveIndex, rules::AccessRules, }, - graph::{GenericIndex, GetPetgraphIndex, MakeRef}, + graph::{GenericIndex, GetIndex, MakeRef}, layout::{CompoundEntryLabel, Layout}, math::RotationSense, router::thetastar::MakeEdgeRef, @@ -47,8 +47,8 @@ impl core::fmt::Debug for NavnodeIndex { } } -impl GetPetgraphIndex for NavnodeIndex { - fn petgraph_index(&self) -> NodeIndex { +impl GetIndex for NavnodeIndex { + fn index(&self) -> NodeIndex { self.0 } } @@ -56,7 +56,7 @@ impl GetPetgraphIndex for NavnodeIndex { /// A binavnode is a pair of navnodes, one clockwise and the other /// counterclockwise. Unlike their constituents, binavnodes are themselves /// not considered navnodes. -#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] +#[enum_dispatch(GetIndex, MakePrimitive)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BinavnodeNodeIndex { FixedDot(FixedDotIndex), @@ -271,7 +271,7 @@ impl Navmesh { // for each union. for prenavnode in prenavmesh.triangulation().node_identifiers() { let repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new( - overlapping_prenavnodes_unions.find(prenavnode.petgraph_index()), + overlapping_prenavnodes_unions.find(prenavnode.index()), )); if repr == prenavnode { @@ -325,7 +325,7 @@ impl Navmesh { // Ignore overlaps of a fillet. if layout .drawing() - .compounds(GenericIndex::<()>::new(prenavnode.petgraph_index())) + .compounds(GenericIndex::<()>::new(prenavnode.index())) .find(|(label, _)| *label == CompoundEntryLabel::Fillet) .is_some() { @@ -336,7 +336,7 @@ impl Navmesh { // Ignore overlaps with fillets. if layout .drawing() - .compounds(GenericIndex::<()>::new(overlapee.1.petgraph_index())) + .compounds(GenericIndex::<()>::new(overlapee.1.index())) .find(|(label, _)| *label == CompoundEntryLabel::Fillet) .is_some() { @@ -347,8 +347,7 @@ impl Navmesh { continue; }; - overlapping_prenavnodes_unions - .union(prenavnode.petgraph_index(), overlapee.petgraph_index()); + overlapping_prenavnodes_unions.union(prenavnode.index(), overlapee.index()); } } @@ -390,10 +389,10 @@ impl Navmesh { // We assume prenavmesh nodes are fixed dots. This is an ugly shortcut, // since fixed bends also can be prenavnodes, but it works for now. let from_prenavnode_repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new( - overlapping_prenavnodes_unions.find(from_prenavnode.petgraph_index()), + overlapping_prenavnodes_unions.find(from_prenavnode.index()), )); let to_prenavnode_repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new( - overlapping_prenavnodes_unions.find(to_prenavnode.petgraph_index()), + overlapping_prenavnodes_unions.find(to_prenavnode.index()), )); Self::add_prenavedge_as_quadrinavedges( @@ -456,7 +455,7 @@ impl Data for Navmesh { impl DataMap for Navmesh { fn node_weight(&self, vertex: Self::NodeId) -> Option<&Self::NodeWeight> { - self.graph.node_weight(vertex.petgraph_index()) + self.graph.node_weight(vertex.index()) } fn edge_weight(&self, _edge: Self::EdgeId) -> Option<&Self::EdgeWeight> { @@ -496,11 +495,7 @@ impl<'a> IntoNeighbors for &'a Navmesh { type Neighbors = Box + 'a>; fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors { - Box::new( - self.graph - .neighbors(vertex.petgraph_index()) - .map(NavnodeIndex), - ) + Box::new(self.graph.neighbors(vertex.index()).map(NavnodeIndex)) } } @@ -526,7 +521,7 @@ impl<'a> IntoEdges for &'a Navmesh { fn edges(self, vertex: Self::NodeId) -> Self::Edges { Box::new( self.graph - .edges(vertex.petgraph_index()) + .edges(vertex.index()) .map(|edge| NavmeshEdgeReference { from: NavnodeIndex(edge.source()), to: NavnodeIndex(edge.target()), diff --git a/src/router/ng/eval.rs b/src/router/ng/eval.rs index 6b62bbc..e94e5e8 100644 --- a/src/router/ng/eval.rs +++ b/src/router/ng/eval.rs @@ -16,7 +16,7 @@ use crate::{ rules::AccessRules, }, geometry::{primitive::PrimitiveShape, shape::AccessShape as _, shape::MeasureLength as _}, - graph::{GenericIndex, GetPetgraphIndex as _}, + graph::{GenericIndex, GetIndex as _}, layout::{poly::PolyWeight, CompoundWeight}, math::{poly_ext_handover, RotationSense}, router::{ @@ -270,7 +270,7 @@ impl AstarContext { let current_poly = layout .drawing() - .compounds(GenericIndex::<()>::new(wrap_core.petgraph_index())) + .compounds(GenericIndex::<()>::new(wrap_core.index())) .find_map(|(_, compound)| { if let CompoundWeight::Poly(_) = layout.drawing().compound_weight(compound) { @@ -279,7 +279,7 @@ impl AstarContext { None } }) - .map(|compound| GenericIndex::::new(compound.petgraph_index())); + .map(|compound| GenericIndex::::new(compound.index())); let (active_head, length_delta) = match ( sub.polygon.take(), diff --git a/src/router/ng/mod.rs b/src/router/ng/mod.rs index 7b0f273..846063f 100644 --- a/src/router/ng/mod.rs +++ b/src/router/ng/mod.rs @@ -32,7 +32,7 @@ use crate::{ shape::{AccessShape as _, MeasureLength as _}, GenericNode, }, - graph::GetPetgraphIndex as _, + graph::GetIndex as _, layout::Layout, math::{CachedPolyExt, RotationSense}, router::draw::{Draw, DrawException}, @@ -580,7 +580,7 @@ fn cane_around( let inner_bend = layout .drawing() .geometry() - .all_rails(core.petgraph_index()) + .all_rails(core.index()) .filter_map(|bi| { if let BendIndex::Loose(lbi) = bi { if layout.drawing().find_loose_band_uid(lbi.into()).ok() == Some(inner) { diff --git a/src/router/ng/poly.rs b/src/router/ng/poly.rs index 32ad5b8..88850c3 100644 --- a/src/router/ng/poly.rs +++ b/src/router/ng/poly.rs @@ -15,7 +15,7 @@ use crate::{ primitive::MakePrimitiveShape as _, }, geometry::{compound::ManageCompounds, shape::AccessShape as _, GetSetPos as _}, - graph::{GenericIndex, GetPetgraphIndex as _}, + graph::{GenericIndex, GetIndex as _}, layout::{poly::PolyWeight, CompoundEntryLabel, Layout}, math::{is_poly_convex_hull_cw, CachedPolyExt, RotationSense}, router::ng::{ @@ -52,7 +52,7 @@ impl PolygonRouting { let convex_hull = layout .drawing() .geometry() - .compound_members(GenericIndex::new(polyidx.petgraph_index())) + .compound_members(GenericIndex::new(polyidx.index())) .filter_map(|(entry_label, primitive_node)| { let PrimitiveIndex::FixedDot(poly_dot) = primitive_node else { return None; diff --git a/src/router/prenavmesh.rs b/src/router/prenavmesh.rs index 4309075..5e099b1 100644 --- a/src/router/prenavmesh.rs +++ b/src/router/prenavmesh.rs @@ -18,7 +18,7 @@ use crate::{ seg::{FixedSegIndex, LoneLooseSegIndex, SeqLooseSegIndex}, }, geometry::{shape::AccessShape, GetLayer}, - graph::{GenericIndex, GetPetgraphIndex}, + graph::{GenericIndex, GetIndex}, layout::{CompoundEntryLabel, Layout}, triangulation::{GetTrianvertexNodeIndex, Triangulation}, }; @@ -28,7 +28,7 @@ use super::{navmesh::NavmeshError, RouterOptions}; /// Prenavmesh nodes are the vertices of constrained Delaunay triangulation /// before it is converted to the navmesh, which is done by multiplying each /// of the prenavmesh nodes into more nodes, called navnodes. -#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] +#[enum_dispatch(GetIndex, MakePrimitive)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum PrenavmeshNodeIndex { FixedDot(FixedDotIndex), @@ -165,7 +165,7 @@ impl Prenavmesh { layout .drawing() // TODO: Add `.compounds()` method working on `PrimitiveIndex`. - .compounds(GenericIndex::<()>::new(dot.petgraph_index())) + .compounds(GenericIndex::<()>::new(dot.index())) .find(|(label, _)| *label == CompoundEntryLabel::Fillet) .is_some(); @@ -254,7 +254,7 @@ impl Prenavmesh { fn is_fixed_dot_filleted(layout: &Layout, dot: FixedDotIndex) -> bool { layout .drawing() - .compounds(GenericIndex::<()>::new(dot.petgraph_index())) + .compounds(GenericIndex::<()>::new(dot.index())) .find(|(label, _)| // Fillets fail this test for some reason that I did not investigate, so // I added this condition. @@ -269,7 +269,7 @@ impl Prenavmesh { layout .drawing() // TODO: Add `.compounds()` method working on `PrimitiveIndex`. - .compounds(GenericIndex::<()>::new(overlapee.1.petgraph_index())) + .compounds(GenericIndex::<()>::new(overlapee.1.index())) .find(|(label, _)| *label == CompoundEntryLabel::Fillet) .is_some() }) diff --git a/src/triangulation.rs b/src/triangulation.rs index ed5a805..753f7ad 100644 --- a/src/triangulation.rs +++ b/src/triangulation.rs @@ -11,7 +11,7 @@ use spade::{ handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, HasPosition, InsertionError, }; -use crate::graph::GetPetgraphIndex; +use crate::graph::GetIndex; pub trait GetTrianvertexNodeIndex { fn node_index(&self) -> I; @@ -27,7 +27,7 @@ pub struct Triangulation + HasPosition, EW: De index_marker: PhantomData, } -impl + HasPosition, EW: Default> +impl + HasPosition, EW: Default> Triangulation { pub fn new(node_bound: usize) -> Self { @@ -39,15 +39,15 @@ impl + HasPosition, EW: Defa } pub fn add_vertex(&mut self, weight: VW) -> Result<(), InsertionError> { - let index = weight.node_index().petgraph_index().index(); + let index = weight.node_index().index().index(); self.trianvertex_to_handle[index] = Some(spade::Triangulation::insert(&mut self.cdt, weight)?); Ok(()) } pub fn add_constraint_edge(&mut self, from: VW, to: VW) -> Result { - let from_index = from.node_index().petgraph_index().index(); - let to_index = to.node_index().petgraph_index().index(); + let from_index = from.node_index().index().index(); + let to_index = to.node_index().index().index(); // It is possible for one or both constraint edge endpoint vertices to // not exist in the triangulation even after everything has been added. @@ -75,13 +75,13 @@ impl + HasPosition, EW: Defa pub fn weight(&self, vertex: I) -> &VW { spade::Triangulation::s(&self.cdt) - .vertex_data(self.trianvertex_to_handle[vertex.petgraph_index().index()].unwrap()) + .vertex_data(self.trianvertex_to_handle[vertex.index().index()].unwrap()) } pub fn weight_mut(&mut self, vertex: I) -> &mut VW { spade::Triangulation::vertex_data_mut( &mut self.cdt, - self.trianvertex_to_handle[vertex.petgraph_index().index()].unwrap(), + self.trianvertex_to_handle[vertex.index().index()].unwrap(), ) } @@ -92,7 +92,7 @@ impl + HasPosition, EW: Defa } fn handle(&self, vertex: I) -> FixedVertexHandle { - self.trianvertex_to_handle[vertex.petgraph_index().index()].unwrap() + self.trianvertex_to_handle[vertex.index().index()].unwrap() } pub fn position(&self, vertex: I) -> Point<::Scalar> @@ -104,11 +104,8 @@ impl + HasPosition, EW: Defa } } -impl< - I: Copy + PartialEq + GetPetgraphIndex, - VW: GetTrianvertexNodeIndex + HasPosition, - EW: Default, - > visit::GraphBase for Triangulation +impl + HasPosition, EW: Default> + visit::GraphBase for Triangulation { type NodeId = I; type EdgeId = (I, I); @@ -133,7 +130,7 @@ impl PartialOrd for TriangulationEdgeWeightWrapper { } impl< - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::Data for Triangulation @@ -173,7 +170,7 @@ impl visit::EdgeRef for TriangulationEdgeReference { impl< 'a, - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Default, > visit::IntoNeighbors for &'a Triangulation @@ -191,7 +188,7 @@ impl< impl< 'a, - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::IntoEdgeReferences for &'a Triangulation @@ -218,7 +215,7 @@ impl< impl< 'a, - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::IntoEdges for &'a Triangulation @@ -248,7 +245,7 @@ impl< impl< 'a, - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Default, > visit::IntoNodeIdentifiers for &'a Triangulation @@ -298,7 +295,7 @@ impl visit::NodeRef for TriangulationVertexReference<'_, I, VW> { impl< 'a, - I: Copy + PartialEq + GetPetgraphIndex, + I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex + HasPosition, EW: Copy + Default, > visit::IntoNodeReferences for &'a Triangulation @@ -320,7 +317,7 @@ impl< } impl< - I: Copy + PartialEq + GetPetgraphIndex + std::fmt::Debug, + I: Copy + PartialEq + GetIndex + std::fmt::Debug, VW: GetTrianvertexNodeIndex + HasPosition, EW: Default, > visit::NodeIndexable for &Triangulation @@ -331,7 +328,7 @@ impl< } fn to_index(&self, node: I) -> usize { - node.petgraph_index().index() + node.index().index() } fn from_index(&self, index: usize) -> I { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 588081a..08b4aa3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -14,7 +14,7 @@ use topola::{ board::{edit::BoardEdit, AccessMesadata, Board}, drawing::graph::{GetMaybeNet, PrimitiveIndex}, geometry::{shape::MeasureLength, GenericNode, GetLayer}, - graph::{GetPetgraphIndex, MakeRef}, + graph::{GetIndex, MakeRef}, router::{navmesh::Navmesh, RouterOptions}, specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, }; @@ -217,8 +217,8 @@ pub fn assert_single_layer_groundless_autoroute( if let Some(netname) = autorouter.board().layout().rules().net_netname(net) { // We don't route ground. - let org = unionfind.find(origin_dot.petgraph_index()); - let desc = unionfind.find(destination_dot.petgraph_index()); + let org = unionfind.find(origin_dot.index()); + let desc = unionfind.find(destination_dot.index()); if netname != "GND" { assert_eq!(org, desc); @@ -282,7 +282,7 @@ fn unionfind(autorouter: &mut Autorouter) -> UnionFind