refactor(graph): Rename `GetPetgraphIndex` to `GetIndex`

This commit is contained in:
Mikolaj Wielgus 2025-09-13 20:44:33 +02:00
parent 7c4bc87301
commit 6a2102e0a2
28 changed files with 243 additions and 297 deletions

View File

@ -24,7 +24,7 @@ use crate::{
rules::AccessRules, rules::AccessRules,
}, },
geometry::shape::AccessShape, geometry::shape::AccessShape,
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
layout::{ layout::{
poly::{MakePolygon, PolyWeight}, poly::{MakePolygon, PolyWeight},
Layout, Layout,
@ -34,7 +34,7 @@ use crate::{
use super::ratline::{RatlineIndex, RatlineWeight}; use super::ratline::{RatlineIndex, RatlineWeight};
#[enum_dispatch(GetPetgraphIndex)] #[enum_dispatch(GetIndex)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum RatvertexIndex { pub enum RatvertexIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
@ -144,8 +144,8 @@ impl Ratsnest {
this.graph.retain_edges(|g, i| { this.graph.retain_edges(|g, i| {
if let Some((source, target)) = g.edge_endpoints(i) { if let Some((source, target)) = g.edge_endpoints(i) {
let source_index = g.node_weight(source).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().petgraph_index(); let target_index = g.node_weight(target).unwrap().node_index().index();
!unionfind.equiv(source_index, target_index) !unionfind.equiv(source_index, target_index)
} else { } else {
true true

View File

@ -14,7 +14,7 @@ use crate::{
shape::{AccessShape, Shape}, shape::{AccessShape, Shape},
GenericNode, GetLayer, GenericNode, GetLayer,
}, },
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
layout::{poly::PolyWeight, CompoundWeight, NodeIndex}, layout::{poly::PolyWeight, CompoundWeight, NodeIndex},
}; };
@ -36,7 +36,7 @@ impl PinSelector {
NodeIndex::Compound(compound) => { NodeIndex::Compound(compound) => {
if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound) if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound)
{ {
GenericIndex::<PolyWeight>::new(compound.petgraph_index()) GenericIndex::<PolyWeight>::new(compound.index())
.ref_(board.layout()) .ref_(board.layout())
.layer() .layer()
} else { } else {

View File

@ -40,7 +40,7 @@ pub enum ResolvedSelector<'a> {
impl<'a> ResolvedSelector<'a> { impl<'a> ResolvedSelector<'a> {
pub fn try_from_node(board: &'a Board<impl AccessMesadata>, node: NodeIndex) -> Option<Self> { pub fn try_from_node(board: &'a Board<impl AccessMesadata>, node: NodeIndex) -> Option<Self> {
use crate::{drawing::graph::MakePrimitiveRef, graph::GetPetgraphIndex}; use crate::{drawing::graph::MakePrimitiveRef, graph::GetIndex};
let (layer, loose) = match node { let (layer, loose) = match node {
NodeIndex::Primitive(primitive) => ( NodeIndex::Primitive(primitive) => (
@ -50,7 +50,7 @@ impl<'a> ResolvedSelector<'a> {
NodeIndex::Compound(compound) => { NodeIndex::Compound(compound) => {
match board.layout().drawing().compound_weight(compound) { match board.layout().drawing().compound_weight(compound) {
CompoundWeight::Poly(..) => ( CompoundWeight::Poly(..) => (
GenericIndex::<PolyWeight>::new(compound.petgraph_index()) GenericIndex::<PolyWeight>::new(compound.index())
.ref_(board.layout()) .ref_(board.layout())
.layer(), .layer(),
None, None,

View File

@ -12,12 +12,12 @@ use crate::{
Drawing, Drawing,
}, },
geometry::{GetLayer, GetOffset, GetWidth, SetOffset}, geometry::{GetLayer, GetOffset, GetWidth, SetOffset},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
}; };
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum BendIndex { pub enum BendIndex {
Fixed(FixedBendIndex), Fixed(FixedBendIndex),

View File

@ -15,11 +15,11 @@ use crate::{
Drawing, Drawing,
}, },
geometry::{GetLayer, GetSetPos, GetWidth}, geometry::{GetLayer, GetSetPos, GetWidth},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
math::Circle, math::Circle,
}; };
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum DotIndex { pub enum DotIndex {
Fixed(FixedDotIndex), Fixed(FixedDotIndex),

View File

@ -37,7 +37,7 @@ use crate::{
AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel,
GetLayer, GetOffset, GetSetPos, GetWidth, GetLayer, GetOffset, GetSetPos, GetWidth,
}, },
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
math::{NoBitangents, RotationSense}, math::{NoBitangents, RotationSense},
}; };
@ -570,7 +570,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
let core = *self let core = *self
.recording_geometry_with_rtree .recording_geometry_with_rtree
.graph() .graph()
.neighbors(inner.petgraph_index()) .neighbors(inner.index())
.filter(|ni| { .filter(|ni| {
matches!( matches!(
self.recording_geometry_with_rtree self.recording_geometry_with_rtree
@ -578,7 +578,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
.edge_weight( .edge_weight(
self.recording_geometry_with_rtree self.recording_geometry_with_rtree
.graph() .graph()
.find_edge(inner.petgraph_index(), *ni) .find_edge(inner.index(), *ni)
.unwrap() .unwrap()
) )
.unwrap(), .unwrap(),

View File

@ -16,10 +16,10 @@ use crate::{
rules::AccessRules, rules::AccessRules,
Drawing, Drawing,
}, },
graph::{GetPetgraphIndex, MakeRef}, graph::{GetIndex, MakeRef},
}; };
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum GearIndex { pub enum GearIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
@ -53,7 +53,7 @@ impl From<BendIndex> for GearIndex {
} }
} }
#[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetPetgraphIndex)] #[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetIndex)]
pub enum GearRef<'a, CW, Cel, R> { pub enum GearRef<'a, CW, Cel, R> {
FixedDot(FixedDotRef<'a, CW, Cel, R>), FixedDot(FixedDotRef<'a, CW, Cel, R>),
FixedBend(FixedBendRef<'a, CW, Cel, R>), FixedBend(FixedBendRef<'a, CW, Cel, R>),

View File

@ -7,7 +7,7 @@ use petgraph::stable_graph::NodeIndex;
use crate::{ use crate::{
geometry::GetLayer, geometry::GetLayer,
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
}; };
use super::{ 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 // 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. // 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)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum PrimitiveIndex { pub enum PrimitiveIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),

View File

@ -17,7 +17,7 @@ use crate::{
rules::AccessRules, rules::AccessRules,
seg::{LoneLooseSegIndex, SeqLooseSegIndex}, seg::{LoneLooseSegIndex, SeqLooseSegIndex},
}, },
graph::GetPetgraphIndex, graph::GetIndex,
}; };
#[enum_dispatch] #[enum_dispatch]
@ -38,7 +38,7 @@ pub trait GetPrevNextLoose {
} }
} }
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum LooseIndex { pub enum LooseIndex {
Dot(LooseDotIndex), Dot(LooseDotIndex),
@ -71,7 +71,7 @@ impl TryFrom<PrimitiveIndex> for LooseIndex {
} }
} }
#[enum_dispatch(GetPrevNextLoose, GetDrawing, GetPetgraphIndex)] #[enum_dispatch(GetPrevNextLoose, GetDrawing, GetIndex)]
pub enum Loose<'a, CW, Cel, R> { pub enum Loose<'a, CW, Cel, R> {
Dot(LooseDotRef<'a, CW, Cel, R>), Dot(LooseDotRef<'a, CW, Cel, R>),
LoneSeg(LoneLooseSegRef<'a, CW, Cel, R>), LoneSeg(LoneLooseSegRef<'a, CW, Cel, R>),
@ -95,7 +95,7 @@ impl<CW, Cel, R> GetPrevNextLoose for LooseDotRef<'_, CW, Cel, R> {
let bend = self.bend(); let bend = self.bend();
if let Some(prev) = maybe_prev { if let Some(prev) = maybe_prev {
if bend.petgraph_index() != prev.petgraph_index() { if bend.index() != prev.index() {
Some(bend.into()) Some(bend.into())
} else { } else {
self.seg().map(Into::into) self.seg().map(Into::into)
@ -119,7 +119,7 @@ impl<CW, Cel, R> GetPrevNextLoose for SeqLooseSegRef<'_, CW, Cel, R> {
return Some(joints.1.into()); return Some(joints.1.into());
}; };
if joints.0.petgraph_index() != prev.petgraph_index() { if joints.0.index() != prev.index() {
match joints.0 { match joints.0 {
DotIndex::Fixed(..) => None, DotIndex::Fixed(..) => None,
DotIndex::Loose(dot) => Some(dot.into()), DotIndex::Loose(dot) => Some(dot.into()),
@ -135,7 +135,7 @@ impl<CW, Cel, R> GetPrevNextLoose for LooseBendRef<'_, CW, Cel, R> {
let joints = self.joints(); let joints = self.joints();
if let Some(prev) = maybe_prev { if let Some(prev) = maybe_prev {
if joints.0.petgraph_index() != prev.petgraph_index() { if joints.0.index() != prev.index() {
Some(joints.0.into()) Some(joints.0.into())
} else { } else {
Some(joints.1.into()) Some(joints.1.into())

View File

@ -15,7 +15,7 @@ use crate::{
Drawing, Drawing,
}, },
geometry::{primitive::PrimitiveShape, GenericNode, GetLayer, GetOffset, GetWidth, Retag}, geometry::{primitive::PrimitiveShape, GenericNode, GetLayer, GetOffset, GetWidth, Retag},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
}; };
use super::gear::{DrawingOutwardWalker, GetOuterGears, WalkOutwards}; use super::gear::{DrawingOutwardWalker, GetOuterGears, WalkOutwards};
@ -67,14 +67,14 @@ pub trait GetOtherJoint: GetJoints {
impl<F, S> GetOtherJoint for S impl<F, S> GetOtherJoint for S
where where
F: GetPetgraphIndex, F: GetIndex,
S: GetJoints<F = F>, S: GetJoints<F = F>,
<S as GetJoints>::T: GetPetgraphIndex + Into<F>, <S as GetJoints>::T: GetIndex + Into<F>,
{ {
type J = F; type J = F;
fn other_joint(&self, end: F) -> F { fn other_joint(&self, end: F) -> F {
let joints = self.joints(); let joints = self.joints();
if joints.0.petgraph_index() != end.petgraph_index() { if joints.0.index() != end.index() {
joints.0 joints.0
} else { } else {
joints.1.into() joints.1.into()
@ -88,13 +88,13 @@ pub trait GetJoints {
fn joints(&self) -> (Self::F, Self::T); 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. // TODO: Make it return an iterator instead of a vec.
fn lowest_gears(&self) -> Vec<LooseBendIndex> { fn lowest_gears(&self) -> Vec<LooseBendIndex> {
self.drawing() self.drawing()
.geometry() .geometry()
.all_rails(self.petgraph_index()) .all_rails(self.index())
.map(|ni| LooseBendIndex::new(ni.petgraph_index())) .map(|ni| LooseBendIndex::new(ni.index()))
.collect() .collect()
} }
} }
@ -109,12 +109,7 @@ pub trait GetCore: GetBendIndex {
impl<S: GetDrawing + GetBendIndex> GetCore for S { impl<S: GetDrawing + GetBendIndex> GetCore for S {
fn core(&self) -> FixedDotIndex { fn core(&self) -> FixedDotIndex {
FixedDotIndex::new( FixedDotIndex::new(self.drawing().geometry().core(self.bend_index()).index())
self.drawing()
.geometry()
.core(self.bend_index())
.petgraph_index(),
)
} }
} }
@ -205,7 +200,7 @@ impl<'a, W, CW, Cel, R> GenericPrimitive<'a, W, CW, Cel, R> {
.drawing .drawing
.geometry() .geometry()
.graph() .graph()
.node_weight(self.index.petgraph_index()) .node_weight(self.index.index())
.unwrap() .unwrap()
{ {
*weight *weight
@ -217,7 +212,7 @@ impl<'a, W, CW, Cel, R> GenericPrimitive<'a, W, CW, Cel, R> {
impl<W, CW, Cel, R> GetInterior<PrimitiveIndex> for GenericPrimitive<'_, W, CW, Cel, R> { impl<W, CW, Cel, R> GetInterior<PrimitiveIndex> for GenericPrimitive<'_, W, CW, Cel, R> {
fn interior(&self) -> Vec<PrimitiveIndex> { fn interior(&self) -> Vec<PrimitiveIndex> {
vec![self.tagged_weight().retag(self.index.petgraph_index())] vec![self.tagged_weight().retag(self.index.index())]
} }
} }
@ -230,9 +225,9 @@ impl<W, CW, Cel, R> GetDrawing for GenericPrimitive<'_, W, CW, Cel, R> {
} }
} }
impl<W, CW, Cel, R> GetPetgraphIndex for GenericPrimitive<'_, W, CW, Cel, R> { impl<W, CW, Cel, R> GetIndex for GenericPrimitive<'_, W, CW, Cel, R> {
fn petgraph_index(&self) -> NodeIndex<usize> { fn index(&self) -> NodeIndex<usize> {
self.index.petgraph_index() self.index.index()
} }
} }
@ -305,7 +300,7 @@ impl<CW, Cel, R> LooseDotRef<'_, CW, Cel, R> {
self.drawing self.drawing
.geometry() .geometry()
.joined_segs(self.index.into()) .joined_segs(self.index.into())
.map(|ni| SeqLooseSegIndex::new(ni.petgraph_index())) .map(|ni| SeqLooseSegIndex::new(ni.index()))
.next() .next()
} }
@ -313,7 +308,7 @@ impl<CW, Cel, R> LooseDotRef<'_, CW, Cel, R> {
self.drawing self.drawing
.geometry() .geometry()
.joined_bends(self.index.into()) .joined_bends(self.index.into())
.map(|ni| LooseBendIndex::new(ni.petgraph_index())) .map(|ni| LooseBendIndex::new(ni.index()))
.next() .next()
.unwrap() .unwrap()
} }
@ -356,8 +351,8 @@ impl<CW, Cel, R> GetJoints for FixedSegRef<'_, CW, Cel, R> {
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
let (from, to) = self.drawing.geometry().seg_joints(self.index.into()); let (from, to) = self.drawing.geometry().seg_joints(self.index.into());
( (
FixedDotIndex::new(from.petgraph_index()), FixedDotIndex::new(from.index()),
FixedDotIndex::new(to.petgraph_index()), FixedDotIndex::new(to.index()),
) )
} }
} }
@ -379,8 +374,8 @@ impl<CW, Cel, R> GetJoints for LoneLooseSegRef<'_, CW, Cel, R> {
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
let (from, to) = self.drawing.geometry().seg_joints(self.index.into()); let (from, to) = self.drawing.geometry().seg_joints(self.index.into());
( (
FixedDotIndex::new(from.petgraph_index()), FixedDotIndex::new(from.index()),
FixedDotIndex::new(to.petgraph_index()), FixedDotIndex::new(to.index()),
) )
} }
} }
@ -403,18 +398,18 @@ impl<CW, Cel, R> GetJoints for SeqLooseSegRef<'_, CW, Cel, R> {
let joints = self.drawing.geometry().seg_joints(self.index.into()); let joints = self.drawing.geometry().seg_joints(self.index.into());
if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) { if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) {
( (
FixedDotIndex::new(joints.0.petgraph_index()).into(), FixedDotIndex::new(joints.0.index()).into(),
LooseDotIndex::new(joints.1.petgraph_index()), LooseDotIndex::new(joints.1.index()),
) )
} else if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.1) { } else if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.1) {
( (
FixedDotIndex::new(joints.1.petgraph_index()).into(), FixedDotIndex::new(joints.1.index()).into(),
LooseDotIndex::new(joints.0.petgraph_index()), LooseDotIndex::new(joints.0.index()),
) )
} else { } else {
( (
LooseDotIndex::new(joints.0.petgraph_index()).into(), LooseDotIndex::new(joints.0.index()).into(),
LooseDotIndex::new(joints.1.petgraph_index()), LooseDotIndex::new(joints.1.index()),
) )
} }
} }
@ -443,8 +438,8 @@ impl<CW, Cel, R> GetJoints for FixedBendRef<'_, CW, Cel, R> {
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); let (from, to) = self.drawing.geometry().bend_joints(self.index.into());
( (
FixedDotIndex::new(from.petgraph_index()), FixedDotIndex::new(from.index()),
FixedDotIndex::new(to.petgraph_index()), FixedDotIndex::new(to.index()),
) )
} }
} }
@ -498,8 +493,8 @@ impl<CW, Cel, R> GetJoints for LooseBendRef<'_, CW, Cel, R> {
fn joints(&self) -> (LooseDotIndex, LooseDotIndex) { fn joints(&self) -> (LooseDotIndex, LooseDotIndex) {
let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); let (from, to) = self.drawing.geometry().bend_joints(self.index.into());
( (
LooseDotIndex::new(from.petgraph_index()), LooseDotIndex::new(from.index()),
LooseDotIndex::new(to.petgraph_index()), LooseDotIndex::new(to.index()),
) )
} }
} }
@ -521,13 +516,13 @@ impl<CW, Cel, R> LooseBendRef<'_, CW, Cel, R> {
self.drawing() self.drawing()
.geometry() .geometry()
.inner(self.bend_index()) .inner(self.bend_index())
.map(|ni| LooseBendIndex::new(ni.petgraph_index())) .map(|ni| LooseBendIndex::new(ni.index()))
} }
pub fn outers(&self) -> impl Iterator<Item = LooseBendIndex> + '_ { pub fn outers(&self) -> impl Iterator<Item = LooseBendIndex> + '_ {
self.drawing() self.drawing()
.geometry() .geometry()
.outers(self.bend_index()) .outers(self.bend_index())
.map(|node| LooseBendIndex::new(node.petgraph_index())) .map(|node| LooseBendIndex::new(node.index()))
} }
} }

View File

@ -13,12 +13,12 @@ use crate::{
Drawing, Drawing,
}, },
geometry::{GetLayer, GetWidth}, geometry::{GetLayer, GetWidth},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
}; };
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub enum SegIndex { pub enum SegIndex {
Fixed(FixedSegIndex), Fixed(FixedSegIndex),
@ -26,7 +26,7 @@ pub enum SegIndex {
SeqLoose(SeqLooseSegIndex), SeqLoose(SeqLooseSegIndex),
} }
#[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)] #[enum_dispatch(GetIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub enum LooseSegIndex { pub enum LooseSegIndex {
Lone(LoneLooseSegIndex), Lone(LoneLooseSegIndex),

View File

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use crate::graph::{GenericIndex, GetPetgraphIndex}; use crate::graph::{GenericIndex, GetIndex};
pub trait ManageCompounds<CW: Clone> { pub trait ManageCompounds<CW: Clone> {
type GeneralIndex: Copy; type GeneralIndex: Copy;
@ -12,7 +12,7 @@ pub trait ManageCompounds<CW: Clone> {
fn remove_compound(&mut self, compound: GenericIndex<CW>); fn remove_compound(&mut self, compound: GenericIndex<CW>);
fn add_to_compound<I>(&mut self, node: I, label: Self::EntryLabel, compound: GenericIndex<CW>) fn add_to_compound<I>(&mut self, node: I, label: Self::EntryLabel, compound: GenericIndex<CW>)
where where
I: Copy + GetPetgraphIndex; I: Copy + GetIndex;
fn compound_weight(&self, node: GenericIndex<CW>) -> &CW; fn compound_weight(&self, node: GenericIndex<CW>) -> &CW;
@ -23,5 +23,5 @@ pub trait ManageCompounds<CW: Clone> {
fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Self::EntryLabel, GenericIndex<CW>)> fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Self::EntryLabel, GenericIndex<CW>)>
where where
I: Copy + GetPetgraphIndex; I: Copy + GetIndex;
} }

View File

@ -4,7 +4,7 @@
use std::collections::{btree_map::Entry, BTreeMap}; use std::collections::{btree_map::Entry, BTreeMap};
use crate::graph::{GenericIndex, GetPetgraphIndex}; use crate::graph::{GenericIndex, GetIndex};
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer}; use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer};
@ -39,10 +39,10 @@ pub trait ApplyGeometryEdit<
BW: AccessBendWeight + GetLayer, BW: AccessBendWeight + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, DI: GetIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, SI: GetIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, BI: GetIndex + Into<PI> + Eq + Ord + Copy,
> >
{ {
fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>); fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>);
@ -89,10 +89,10 @@ impl<
BW: AccessBendWeight + GetLayer, BW: AccessBendWeight + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, DI: GetIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, SI: GetIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, BI: GetIndex + Into<PI> + Eq + Ord + Copy,
> Edit for GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> > Edit for GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
fn reverse_inplace(&mut self) { fn reverse_inplace(&mut self) {

View File

@ -25,12 +25,12 @@ use crate::{
compound::ManageCompounds, compound::ManageCompounds,
primitive::{BendShape, DotShape, PrimitiveShape, SegShape}, primitive::{BendShape, DotShape, PrimitiveShape, SegShape},
}, },
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
math::Circle, math::Circle,
}; };
pub trait Retag { pub trait Retag {
type Index: Sized + GetPetgraphIndex + PartialEq + Copy; type Index: Sized + GetIndex + PartialEq + Copy;
fn retag(&self, index: NodeIndex<usize>) -> Self::Index; fn retag(&self, index: NodeIndex<usize>) -> Self::Index;
} }
@ -74,11 +74,11 @@ pub enum GenericNode<P, C> {
Compound(C), Compound(C),
} }
impl<P: GetPetgraphIndex, C: GetPetgraphIndex> GetPetgraphIndex for GenericNode<P, C> { impl<P: GetIndex, C: GetIndex> GetIndex for GenericNode<P, C> {
fn petgraph_index(&self) -> NodeIndex<usize> { fn index(&self) -> NodeIndex<usize> {
match self { match self {
Self::Primitive(x) => x.petgraph_index(), Self::Primitive(x) => x.index(),
Self::Compound(x) => x.petgraph_index(), Self::Compound(x) => x.index(),
} }
} }
} }
@ -168,10 +168,10 @@ impl<
BW: AccessBendWeight + Into<PW>, BW: AccessBendWeight + Into<PW>,
CW, CW,
Cel, Cel,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
DI: GetPetgraphIndex + Into<PI> + Copy, DI: GetIndex + Into<PI> + Copy,
SI: GetPetgraphIndex + Into<PI> + Copy, SI: GetIndex + Into<PI> + Copy,
BI: GetPetgraphIndex + Into<PI> + Copy, BI: GetIndex + Into<PI> + Copy,
> Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
pub fn add_dot<W: AccessDotWeight + Into<PW>>(&mut self, weight: W) -> GenericIndex<W> { pub fn add_dot<W: AccessDotWeight + Into<PW>>(&mut self, weight: W) -> GenericIndex<W> {
@ -184,7 +184,7 @@ impl<
weight: W, weight: W,
) { ) {
self.graph self.graph
.update_node(dot.petgraph_index(), GenericNode::Primitive(weight.into())); .update_node(dot.index(), GenericNode::Primitive(weight.into()));
} }
pub fn add_seg<W: AccessSegWeight + Into<PW>>( pub fn add_seg<W: AccessSegWeight + Into<PW>>(
@ -207,7 +207,7 @@ impl<
weight: W, weight: W,
) { ) {
self.graph 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); self.init_seg_joints(seg, from, to);
} }
@ -217,28 +217,22 @@ impl<
from: DI, from: DI,
to: DI, to: DI,
) { ) {
self.graph.update_edge( self.graph
from.petgraph_index(), .update_edge(from.index(), seg.index(), GeometryLabel::Joined);
seg.petgraph_index(), self.graph
GeometryLabel::Joined, .update_edge(seg.index(), to.index(), GeometryLabel::Joined);
);
self.graph.update_edge(
seg.petgraph_index(),
to.petgraph_index(),
GeometryLabel::Joined,
);
} }
pub fn is_joined_with<I>(&self, seg: I, node: GenericNode<PI, GenericIndex<CW>>) -> bool pub fn is_joined_with<I>(&self, seg: I, node: GenericNode<PI, GenericIndex<CW>>) -> bool
where where
I: Copy + GetPetgraphIndex, I: Copy + GetIndex,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
{ {
match node { match node {
GenericNode::Primitive(prim) => self GenericNode::Primitive(prim) => self
.graph .graph
.find_edge_undirected(seg.petgraph_index(), prim.petgraph_index()) .find_edge_undirected(seg.index(), prim.index())
.map_or(false, |(eidx, _direction)| { .map_or(false, |(eidx, _direction)| {
matches!(self.graph.edge_weight(eidx).unwrap(), GeometryLabel::Joined) matches!(self.graph.edge_weight(eidx).unwrap(), GeometryLabel::Joined)
}), }),
@ -270,13 +264,13 @@ impl<
weight: W, weight: W,
) { ) {
self.graph 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); self.init_bend_joints_and_core(bend, from, to, core);
} }
pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex<CW>, weight: CW) { pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex<CW>, weight: CW) {
self.graph self.graph
.update_node(compound.petgraph_index(), GenericNode::Compound(weight)); .update_node(compound.index(), GenericNode::Compound(weight));
} }
fn init_bend_joints_and_core<W: AccessBendWeight + Into<PW>>( fn init_bend_joints_and_core<W: AccessBendWeight + Into<PW>>(
@ -286,80 +280,58 @@ impl<
to: DI, to: DI,
core: DI, core: DI,
) { ) {
self.graph.update_edge( self.graph
from.petgraph_index(), .update_edge(from.index(), bend.index(), GeometryLabel::Joined);
bend.petgraph_index(), self.graph
GeometryLabel::Joined, .update_edge(bend.index(), to.index(), GeometryLabel::Joined);
); self.graph
self.graph.update_edge( .update_edge(bend.index(), core.index(), GeometryLabel::Core);
bend.petgraph_index(),
to.petgraph_index(),
GeometryLabel::Joined,
);
self.graph.update_edge(
bend.petgraph_index(),
core.petgraph_index(),
GeometryLabel::Core,
);
} }
pub fn remove_primitive(&mut self, primitive: PI) { 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) { pub fn move_dot(&mut self, dot: DI, to: Point) {
let mut weight = self.dot_weight(dot); let mut weight = self.dot_weight(dot);
weight.set_pos(to); weight.set_pos(to);
*self.graph.node_weight_mut(dot.petgraph_index()).unwrap() = *self.graph.node_weight_mut(dot.index()).unwrap() = GenericNode::Primitive(weight.into());
GenericNode::Primitive(weight.into());
} }
pub fn shift_bend(&mut self, bend: BI, offset: f64) { pub fn shift_bend(&mut self, bend: BI, offset: f64) {
let mut weight = self.bend_weight(bend); let mut weight = self.bend_weight(bend);
weight.set_offset(offset); weight.set_offset(offset);
*self.graph.node_weight_mut(bend.petgraph_index()).unwrap() = *self.graph.node_weight_mut(bend.index()).unwrap() = GenericNode::Primitive(weight.into());
GenericNode::Primitive(weight.into());
} }
pub fn flip_bend(&mut self, bend: BI) { pub fn flip_bend(&mut self, bend: BI) {
let (from, to) = self.bend_joints(bend); let (from, to) = self.bend_joints(bend);
let from_edge_weight = self let from_edge_weight = self
.graph .graph
.remove_edge( .remove_edge(self.graph.find_edge(from.index(), bend.index()).unwrap())
self.graph
.find_edge(from.petgraph_index(), bend.petgraph_index())
.unwrap(),
)
.unwrap(); .unwrap();
let to_edge_weight = self let to_edge_weight = self
.graph .graph
.remove_edge( .remove_edge(self.graph.find_edge(bend.index(), to.index()).unwrap())
self.graph
.find_edge(bend.petgraph_index(), to.petgraph_index())
.unwrap(),
)
.unwrap(); .unwrap();
self.graph self.graph
.update_edge(from.petgraph_index(), bend.petgraph_index(), to_edge_weight); .update_edge(from.index(), bend.index(), to_edge_weight);
self.graph 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<BI>) { pub fn reattach_bend(&mut self, bend: BI, maybe_new_inner: Option<BI>) {
if let Some(old_inner_edge) = self if let Some(old_inner_edge) = self
.graph .graph
.edges_directed(bend.petgraph_index(), Incoming) .edges_directed(bend.index(), Incoming)
.find(|edge| matches!(edge.weight(), GeometryLabel::Outer)) .find(|edge| matches!(edge.weight(), GeometryLabel::Outer))
{ {
debug_assert!(self.graph.remove_edge(old_inner_edge.id()).is_some()); debug_assert!(self.graph.remove_edge(old_inner_edge.id()).is_some());
} }
if let Some(new_inner) = maybe_new_inner { if let Some(new_inner) = maybe_new_inner {
self.graph.update_edge( self.graph
new_inner.petgraph_index(), .update_edge(new_inner.index(), bend.index(), GeometryLabel::Outer);
bend.petgraph_index(),
GeometryLabel::Outer,
);
} }
} }
@ -378,7 +350,7 @@ impl<
PrimitiveShape::Seg(SegShape { PrimitiveShape::Seg(SegShape {
from: self.dot_weight(from).pos(), from: self.dot_weight(from).pos(),
to: self.dot_weight(to).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(), pos: core_weight.pos(),
r: self.inner_radius(bend), 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 { pub fn dot_weight(&self, dot: DI) -> DW {
self.primitive_weight(dot.petgraph_index()) self.primitive_weight(dot.index())
.try_into() .try_into()
.unwrap_or_else(|_| unreachable!()) .unwrap_or_else(|_| unreachable!())
} }
pub fn seg_weight(&self, seg: SI) -> SW { pub fn seg_weight(&self, seg: SI) -> SW {
self.primitive_weight(seg.petgraph_index()) self.primitive_weight(seg.index())
.try_into() .try_into()
.unwrap_or_else(|_| unreachable!()) .unwrap_or_else(|_| unreachable!())
} }
pub fn bend_weight(&self, bend: BI) -> BW { pub fn bend_weight(&self, bend: BI) -> BW {
self.primitive_weight(bend.petgraph_index()) self.primitive_weight(bend.index())
.try_into() .try_into()
.unwrap_or_else(|_| unreachable!()) .unwrap_or_else(|_| unreachable!())
} }
pub fn compound_weight(&self, compound: GenericIndex<CW>) -> &CW { pub fn compound_weight(&self, compound: GenericIndex<CW>) -> &CW {
if let GenericNode::Compound(weight) = if let GenericNode::Compound(weight) = self.graph.node_weight(compound.index()).unwrap() {
self.graph.node_weight(compound.petgraph_index()).unwrap()
{
weight weight
} else { } else {
unreachable!() unreachable!()
@ -439,7 +409,7 @@ impl<
fn core_weight(&self, bend: BI) -> DW { fn core_weight(&self, bend: BI) -> DW {
self.graph self.graph
.edges_directed(bend.petgraph_index(), Outgoing) .edges_directed(bend.index(), Outgoing)
.find(|edge| matches!(edge.weight(), GeometryLabel::Core)) .find(|edge| matches!(edge.weight(), GeometryLabel::Core))
.map(|edge| { .map(|edge| {
self.primitive_weight(edge.target()) self.primitive_weight(edge.target())
@ -451,13 +421,13 @@ impl<
pub fn joineds(&self, node: PI) -> impl Iterator<Item = PI> + '_ { pub fn joineds(&self, node: PI) -> impl Iterator<Item = PI> + '_ {
self.graph self.graph
.neighbors_undirected(node.petgraph_index()) .neighbors_undirected(node.index())
.filter(move |ni| { .filter(move |ni| {
matches!( matches!(
self.graph self.graph
.edge_weight( .edge_weight(
self.graph self.graph
.find_edge_undirected(node.petgraph_index(), *ni) .find_edge_undirected(node.index(), *ni)
.unwrap() .unwrap()
.0, .0,
) )
@ -479,12 +449,12 @@ impl<
fn joints(&self, node: PI) -> (DI, DI) { fn joints(&self, node: PI) -> (DI, DI) {
let lhs = self let lhs = self
.graph .graph
.edges_directed(node.petgraph_index(), Incoming) .edges_directed(node.index(), Incoming)
.find(|edge| matches!(edge.weight(), GeometryLabel::Joined)) .find(|edge| matches!(edge.weight(), GeometryLabel::Joined))
.map(|edge| edge.source()); .map(|edge| edge.source());
let rhs = self let rhs = self
.graph .graph
.edges_directed(node.petgraph_index(), Outgoing) .edges_directed(node.index(), Outgoing)
.find(|edge| matches!(edge.weight(), GeometryLabel::Joined)) .find(|edge| matches!(edge.weight(), GeometryLabel::Joined))
.map(|edge| edge.target()); .map(|edge| edge.target());
@ -525,7 +495,7 @@ pub struct OutwardWalker<BI> {
frontier: VecDeque<BI>, frontier: VecDeque<BI>,
} }
impl<BI: GetPetgraphIndex> OutwardWalker<BI> { impl<BI: GetIndex> OutwardWalker<BI> {
pub fn new(initial_frontier: impl Iterator<Item = BI>) -> Self { pub fn new(initial_frontier: impl Iterator<Item = BI>) -> Self {
let mut frontier = VecDeque::new(); let mut frontier = VecDeque::new();
frontier.extend(initial_frontier); frontier.extend(initial_frontier);
@ -544,7 +514,7 @@ impl<
PI: TryInto<DI> + TryInto<SI> + TryInto<BI>, PI: TryInto<DI> + TryInto<SI> + TryInto<BI>,
DI, DI,
SI, SI,
BI: Copy + GetPetgraphIndex, BI: Copy + GetIndex,
> Walker<&Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>> for OutwardWalker<BI> > Walker<&Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>> for OutwardWalker<BI>
{ {
type Item = BI; type Item = BI;
@ -570,7 +540,7 @@ impl<
PI: TryInto<DI> + TryInto<SI> + TryInto<BI>, PI: TryInto<DI> + TryInto<SI> + TryInto<BI>,
DI, DI,
SI, SI,
BI: GetPetgraphIndex, BI: GetIndex,
> Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > Geometry<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
pub fn all_rails(&self, node: NodeIndex<usize>) -> impl Iterator<Item = BI> + '_ { pub fn all_rails(&self, node: NodeIndex<usize>) -> impl Iterator<Item = BI> + '_ {
@ -586,7 +556,7 @@ impl<
pub fn core(&self, bend: BI) -> DI { pub fn core(&self, bend: BI) -> DI {
self.graph self.graph
.edges_directed(bend.petgraph_index(), Outgoing) .edges_directed(bend.index(), Outgoing)
.find(|edge| matches!(edge.weight(), GeometryLabel::Core)) .find(|edge| matches!(edge.weight(), GeometryLabel::Core))
.map(|edge| { .map(|edge| {
self.primitive_index(edge.target()) self.primitive_index(edge.target())
@ -598,7 +568,7 @@ impl<
pub fn inner(&self, bend: BI) -> Option<BI> { pub fn inner(&self, bend: BI) -> Option<BI> {
self.graph self.graph
.edges_directed(bend.petgraph_index(), Incoming) .edges_directed(bend.index(), Incoming)
.find(|edge| matches!(edge.weight(), GeometryLabel::Outer)) .find(|edge| matches!(edge.weight(), GeometryLabel::Outer))
.map(|edge| { .map(|edge| {
self.primitive_index(edge.source()) self.primitive_index(edge.source())
@ -609,7 +579,7 @@ impl<
pub fn outers(&self, bend: BI) -> impl Iterator<Item = BI> + '_ { pub fn outers(&self, bend: BI) -> impl Iterator<Item = BI> + '_ {
self.graph self.graph
.edges_directed(bend.petgraph_index(), Outgoing) .edges_directed(bend.index(), Outgoing)
.filter(|edge| matches!(edge.weight(), GeometryLabel::Outer)) .filter(|edge| matches!(edge.weight(), GeometryLabel::Outer))
.map(|edge| { .map(|edge| {
self.primitive_index(edge.target()) self.primitive_index(edge.target())
@ -634,24 +604,22 @@ impl<PW: Copy + Retag<Index = PI>, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D
} }
fn remove_compound(&mut self, compound: GenericIndex<CW>) { fn remove_compound(&mut self, compound: GenericIndex<CW>) {
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<I>(&mut self, primitive: I, entry_label: Cel, compound: GenericIndex<CW>) fn add_to_compound<I>(&mut self, primitive: I, entry_label: Cel, compound: GenericIndex<CW>)
where where
I: Copy + GetPetgraphIndex, I: Copy + GetIndex,
{ {
self.graph.update_edge( self.graph.update_edge(
primitive.petgraph_index(), primitive.index(),
compound.petgraph_index(), compound.index(),
GeometryLabel::Compound(entry_label), GeometryLabel::Compound(entry_label),
); );
} }
fn compound_weight(&self, compound: GenericIndex<CW>) -> &CW { fn compound_weight(&self, compound: GenericIndex<CW>) -> &CW {
if let GenericNode::Compound(weight) = if let GenericNode::Compound(weight) = self.graph.node_weight(compound.index()).unwrap() {
self.graph.node_weight(compound.petgraph_index()).unwrap()
{
weight weight
} else { } else {
unreachable!() unreachable!()
@ -663,7 +631,7 @@ impl<PW: Copy + Retag<Index = PI>, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D
compound: GenericIndex<CW>, compound: GenericIndex<CW>,
) -> impl Iterator<Item = (Cel, Self::GeneralIndex)> + '_ { ) -> impl Iterator<Item = (Cel, Self::GeneralIndex)> + '_ {
self.graph self.graph
.edges_directed(compound.petgraph_index(), Incoming) .edges_directed(compound.index(), Incoming)
.filter_map(|edge| { .filter_map(|edge| {
if let GeometryLabel::Compound(entry_label) = *edge.weight() { if let GeometryLabel::Compound(entry_label) = *edge.weight() {
Some((entry_label, self.primitive_index(edge.source()))) Some((entry_label, self.primitive_index(edge.source())))
@ -675,10 +643,10 @@ impl<PW: Copy + Retag<Index = PI>, DW, SW, BW, CW: Clone, Cel: Copy, PI: Copy, D
fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Cel, GenericIndex<CW>)> fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Cel, GenericIndex<CW>)>
where where
I: Copy + GetPetgraphIndex, I: Copy + GetIndex,
{ {
self.graph self.graph
.edges_directed(node.petgraph_index(), Outgoing) .edges_directed(node.index(), Outgoing)
.filter_map(|edge| { .filter_map(|edge| {
if let GeometryLabel::Compound(entry_label) = *edge.weight() { if let GeometryLabel::Compound(entry_label) = *edge.weight() {
Some((entry_label, GenericIndex::new(edge.target()))) Some((entry_label, GenericIndex::new(edge.target())))

View File

@ -8,7 +8,7 @@ use geo::Point;
use petgraph::stable_graph::StableDiGraph; use petgraph::stable_graph::StableDiGraph;
use rstar::RTree; use rstar::RTree;
use crate::graph::{GenericIndex, GetPetgraphIndex}; use crate::graph::{GenericIndex, GetIndex};
use super::{ use super::{
compound::ManageCompounds, compound::ManageCompounds,
@ -60,10 +60,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, DI: GetIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, SI: GetIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, BI: GetIndex + Into<PI> + Eq + Ord + Copy,
> RecordingGeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > RecordingGeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
pub fn new(layer_count: usize) -> Self { pub fn new(layer_count: usize) -> Self {
@ -363,10 +363,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, DI: GetIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, SI: GetIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, BI: GetIndex + Into<PI> + Eq + Ord + Copy,
> ApplyGeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> > ApplyGeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>
for RecordingGeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> for RecordingGeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {

View File

@ -15,7 +15,7 @@ use crate::{
AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel,
GetLayer, GetWidth, Retag, GetLayer, GetWidth, Retag,
}, },
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
}; };
use super::edit::{ApplyGeometryEdit, GeometryEdit}; use super::edit::{ApplyGeometryEdit, GeometryEdit};
@ -76,10 +76,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
DI: GetPetgraphIndex + Into<PI> + Copy, DI: GetIndex + Into<PI> + Copy,
SI: GetPetgraphIndex + Into<PI> + Copy, SI: GetIndex + Into<PI> + Copy,
BI: GetPetgraphIndex + Into<PI> + Copy, BI: GetIndex + Into<PI> + Copy,
> GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
pub fn new(layer_count: usize) -> Self { pub fn new(layer_count: usize) -> Self {
@ -108,7 +108,7 @@ impl<
weight: W, weight: W,
) { ) {
self.geometry self.geometry
.add_dot_at_index(GenericIndex::<W>::new(dot.petgraph_index()), weight); .add_dot_at_index(GenericIndex::<W>::new(dot.index()), weight);
self.init_dot_bbox(dot); self.init_dot_bbox(dot);
} }
@ -133,12 +133,8 @@ impl<
to: DI, to: DI,
weight: W, weight: W,
) { ) {
self.geometry.add_seg_at_index( self.geometry
GenericIndex::<W>::new(seg.petgraph_index()), .add_seg_at_index(GenericIndex::<W>::new(seg.index()), from, to, weight);
from,
to,
weight,
);
self.init_seg_bbox(seg); self.init_seg_bbox(seg);
} }
@ -159,7 +155,7 @@ impl<
pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex<CW>, weight: CW) { pub(super) fn add_compound_at_index(&mut self, compound: GenericIndex<CW>, weight: CW) {
self.geometry self.geometry
.add_compound_at_index(GenericIndex::<CW>::new(compound.petgraph_index()), weight); .add_compound_at_index(GenericIndex::<CW>::new(compound.index()), weight);
} }
pub fn add_to_compound<W>( pub fn add_to_compound<W>(
@ -314,10 +310,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
DI: GetPetgraphIndex + Into<PI> + Copy, DI: GetIndex + Into<PI> + Copy,
SI: GetPetgraphIndex + Into<PI> + Copy, SI: GetIndex + Into<PI> + Copy,
BI: GetPetgraphIndex + Into<PI> + Copy, BI: GetIndex + Into<PI> + Copy,
> GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
fn init_dot_bbox(&mut self, dot: DI) { fn init_dot_bbox(&mut self, dot: DI) {
@ -443,10 +439,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
DI: GetPetgraphIndex + Into<PI> + Copy, DI: GetIndex + Into<PI> + Copy,
SI: GetPetgraphIndex + Into<PI> + Copy, SI: GetIndex + Into<PI> + Copy,
BI: GetPetgraphIndex + Into<PI> + Copy, BI: GetIndex + Into<PI> + Copy,
> ManageCompounds<CW> for GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> > ManageCompounds<CW> for GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
type GeneralIndex = PI; type GeneralIndex = PI;
@ -467,7 +463,7 @@ impl<
fn add_to_compound<I>(&mut self, primitive: I, label: Cel, compound: GenericIndex<CW>) fn add_to_compound<I>(&mut self, primitive: I, label: Cel, compound: GenericIndex<CW>)
where where
I: Copy + GetPetgraphIndex, I: Copy + GetIndex,
{ {
self.geometry.add_to_compound(primitive, label, compound); self.geometry.add_to_compound(primitive, label, compound);
} }
@ -485,7 +481,7 @@ impl<
fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Cel, GenericIndex<CW>)> fn compounds<I>(&self, node: I) -> impl Iterator<Item = (Cel, GenericIndex<CW>)>
where where
I: Copy + GetPetgraphIndex, I: Copy + GetIndex,
{ {
self.geometry.compounds(node) self.geometry.compounds(node)
} }
@ -498,10 +494,10 @@ impl<
BW: AccessBendWeight + Into<PW> + GetLayer, BW: AccessBendWeight + Into<PW> + GetLayer,
CW: Clone, CW: Clone,
Cel: Copy, Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy, PI: GetIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, DI: GetIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, SI: GetIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy, BI: GetIndex + Into<PI> + Eq + Ord + Copy,
> ApplyGeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> > ApplyGeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>
for GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI> for GeometryWithRtree<PW, DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
@ -563,8 +559,7 @@ impl<
// Despite this method's name, it actually does not add the // Despite this method's name, it actually does not add the
// dot, it updates it. // dot, it updates it.
geometry geometry.add_dot_at_index(GenericIndex::<DW>::new(dot.index()), *weight);
.add_dot_at_index(GenericIndex::<DW>::new(dot.petgraph_index()), *weight);
}) })
} }
} }
@ -592,7 +587,7 @@ impl<
for (bend, (.., maybe_new_data)) in &edit.bends { for (bend, (.., maybe_new_data)) in &edit.bends {
if let Some(((from, to, core, ..), weight)) = maybe_new_data { if let Some(((from, to, core, ..), weight)) = maybe_new_data {
self.geometry.add_bend_at_index( self.geometry.add_bend_at_index(
GenericIndex::<BW>::new(bend.petgraph_index()), GenericIndex::<BW>::new(bend.index()),
*from, *from,
*to, *to,
*core, *core,
@ -622,7 +617,7 @@ impl<
for (entry_label, member) in members { for (entry_label, member) in members {
self.geometry.add_to_compound( self.geometry.add_to_compound(
GenericIndex::<PW>::new(member.petgraph_index()), GenericIndex::<PW>::new(member.index()),
*entry_label, *entry_label,
*compound, *compound,
); );

View File

@ -14,13 +14,13 @@ pub trait MakeRef<'a, C> {
} }
#[enum_dispatch] #[enum_dispatch]
pub trait GetPetgraphIndex { pub trait GetIndex {
fn petgraph_index(&self) -> NodeIndex<usize>; fn index(&self) -> NodeIndex<usize>;
} }
impl GetPetgraphIndex for NodeIndex<usize> { impl GetIndex for NodeIndex<usize> {
#[inline(always)] #[inline(always)]
fn petgraph_index(&self) -> NodeIndex<usize> { fn index(&self) -> NodeIndex<usize> {
*self *self
} }
} }
@ -92,9 +92,9 @@ impl<W> core::hash::Hash for GenericIndex<W> {
} }
} }
impl<W> GetPetgraphIndex for GenericIndex<W> { impl<W> GetIndex for GenericIndex<W> {
#[inline] #[inline]
fn petgraph_index(&self) -> NodeIndex<usize> { fn index(&self) -> NodeIndex<usize> {
self.node_index self.node_index
} }
} }

View File

@ -23,7 +23,7 @@ use crate::{
shape::AccessShape, shape::AccessShape,
GenericNode, GenericNode,
}, },
graph::GetPetgraphIndex, graph::GetIndex,
layout::{Layout, NodeIndex}, layout::{Layout, NodeIndex},
math::{intersect_linestring_and_ray, LineInGeneralForm, LineIntersection}, math::{intersect_linestring_and_ray, LineInGeneralForm, LineIntersection},
}; };
@ -121,7 +121,7 @@ impl<R: AccessRules> Layout<R> {
.filter(|(_, band_uid, _)| { .filter(|(_, band_uid, _)| {
// filter entries which are connected to either lhs or rhs (and possibly both) // filter entries which are connected to either lhs or rhs (and possibly both)
let (bts1, bts2) = band_uid.into(); 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(); let geometry = self.drawing.geometry();
[(bts1, left), (bts1, right), (bts2, left), (bts2, right)] [(bts1, left), (bts1, right), (bts2, left), (bts2, right)]
.iter() .iter()
@ -162,7 +162,7 @@ impl<R: AccessRules> Layout<R> {
.filter(|(_, band_uid, _)| { .filter(|(_, band_uid, _)| {
// filter entries which are connected to rhs // filter entries which are connected to rhs
let (bts1, bts2) = band_uid.into(); 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(); let geometry = self.drawing.geometry();
[(bts1, right), (bts2, right)] [(bts1, right), (bts2, right)]
.iter() .iter()

View File

@ -32,7 +32,7 @@ use crate::{
shape::{AccessShape, Shape}, shape::{AccessShape, Shape},
GenericNode, GetLayer, GetSetPos, GenericNode, GetLayer, GetSetPos,
}, },
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
layout::{ layout::{
poly::{add_poly_with_nodes_intern, MakePolygon, PolyWeight}, poly::{add_poly_with_nodes_intern, MakePolygon, PolyWeight},
via::{Via, ViaWeight}, via::{Via, ViaWeight},
@ -179,7 +179,7 @@ impl<R: AccessRules> Layout<R> {
} }
} }
Ok(GenericIndex::<ViaWeight>::new(compound.petgraph_index())) Ok(GenericIndex::<ViaWeight>::new(compound.index()))
} }
pub fn add_fixed_dot( pub fn add_fixed_dot(
@ -256,7 +256,7 @@ impl<R: AccessRules> Layout<R> {
GenericIndex::<PolyWeight>::new( GenericIndex::<PolyWeight>::new(
self.drawing self.drawing
.add_compound(recorder, CompoundWeight::Poly(weight)) .add_compound(recorder, CompoundWeight::Poly(weight))
.petgraph_index(), .index(),
) )
} }
@ -290,7 +290,7 @@ impl<R: AccessRules> Layout<R> {
self.drawing.rtree().iter().filter_map(|wrapper| { self.drawing.rtree().iter().filter_map(|wrapper| {
if let NodeIndex::Compound(compound) = wrapper.data { if let NodeIndex::Compound(compound) = wrapper.data {
if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) { if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) {
return Some(GenericIndex::<PolyWeight>::new(compound.petgraph_index())); return Some(GenericIndex::<PolyWeight>::new(compound.index()));
} }
} }
@ -311,7 +311,7 @@ impl<R: AccessRules> Layout<R> {
.filter_map(|wrapper| { .filter_map(|wrapper| {
if let NodeIndex::Compound(compound) = wrapper.data { if let NodeIndex::Compound(compound) = wrapper.data {
if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) { if let CompoundWeight::Poly(..) = self.drawing.compound_weight(compound) {
return Some(GenericIndex::<PolyWeight>::new(compound.petgraph_index())); return Some(GenericIndex::<PolyWeight>::new(compound.index()));
} }
} }
@ -325,12 +325,12 @@ impl<R: AccessRules> Layout<R> {
) -> impl Iterator<Item = (CompoundEntryLabel, PrimitiveIndex)> + '_ { ) -> impl Iterator<Item = (CompoundEntryLabel, PrimitiveIndex)> + '_ {
self.drawing self.drawing
.geometry() .geometry()
.compound_members(GenericIndex::new(poly.petgraph_index())) .compound_members(GenericIndex::new(poly.index()))
} }
fn compound_shape(&self, compound: GenericIndex<CompoundWeight>) -> Shape { fn compound_shape(&self, compound: GenericIndex<CompoundWeight>) -> Shape {
match self.drawing.compound_weight(compound) { match self.drawing.compound_weight(compound) {
CompoundWeight::Poly(_) => GenericIndex::<PolyWeight>::new(compound.petgraph_index()) CompoundWeight::Poly(_) => GenericIndex::<PolyWeight>::new(compound.index())
.ref_(self) .ref_(self)
.shape() .shape()
.into(), .into(),
@ -360,11 +360,8 @@ impl<R: AccessRules> Layout<R> {
let PrimitiveIndex::FixedDot(dot) = index else { let PrimitiveIndex::FixedDot(dot) = index else {
return None; return None;
}; };
if let GenericNode::Primitive(PrimitiveWeight::FixedDot(weight)) = drawing if let GenericNode::Primitive(PrimitiveWeight::FixedDot(weight)) =
.geometry() drawing.geometry().graph().node_weight(dot.index()).unwrap()
.graph()
.node_weight(dot.petgraph_index())
.unwrap()
{ {
Some((dot, weight)) Some((dot, weight))
} else { } else {
@ -378,7 +375,7 @@ impl<R: AccessRules> Layout<R> {
.drawing() .drawing()
.geometry() .geometry()
// TODO: Add `.compounds()` method working on `PrimitiveIndex`. // TODO: Add `.compounds()` method working on `PrimitiveIndex`.
.compounds(GenericIndex::<()>::new(primitive.petgraph_index())) .compounds(GenericIndex::<()>::new(primitive.index()))
.next() .next()
.is_some() .is_some()
{ {
@ -388,8 +385,7 @@ impl<R: AccessRules> Layout<R> {
} }
NodeIndex::Compound(compound) => Some(match self.drawing.compound_weight(compound) { NodeIndex::Compound(compound) => Some(match self.drawing.compound_weight(compound) {
CompoundWeight::Poly(_) => { CompoundWeight::Poly(_) => {
let poly = let poly = GenericIndex::<PolyWeight>::new(compound.index()).ref_(self);
GenericIndex::<PolyWeight>::new(compound.petgraph_index()).ref_(self);
(poly.apex(), poly.shape().center()) (poly.apex(), poly.shape().center())
} }
CompoundWeight::Via(weight) => { CompoundWeight::Via(weight) => {

View File

@ -21,7 +21,7 @@ use crate::{
Drawing, Drawing,
}, },
geometry::{compound::ManageCompounds, GetLayer, GetSetPos}, geometry::{compound::ManageCompounds, GetLayer, GetSetPos},
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
layout::{CompoundEntryLabel, CompoundWeight, Layout, LayoutEdit}, layout::{CompoundEntryLabel, CompoundWeight, Layout, LayoutEdit},
math::Circle, math::Circle,
}; };
@ -81,7 +81,7 @@ pub(super) fn add_poly_with_nodes_intern<R: AccessRules>(
for &idx in nodes { for &idx in nodes {
layout.drawing.add_to_compound( layout.drawing.add_to_compound(
recorder, recorder,
GenericIndex::<()>::new(idx.petgraph_index()), GenericIndex::<()>::new(idx.index()),
CompoundEntryLabel::Normal, CompoundEntryLabel::Normal,
poly_compound, poly_compound,
); );
@ -123,7 +123,7 @@ pub(super) fn add_poly_with_nodes_intern<R: AccessRules>(
for Rto { idx, .. } in temp_rtree { for Rto { idx, .. } in temp_rtree {
layout.drawing.add_to_compound( layout.drawing.add_to_compound(
recorder, recorder,
GenericIndex::<()>::new(idx.petgraph_index()), GenericIndex::<()>::new(idx.index()),
CompoundEntryLabel::Apex, CompoundEntryLabel::Apex,
poly_compound, poly_compound,
); );
@ -234,7 +234,7 @@ pub enum PolyWeight {
impl From<GenericIndex<PolyWeight>> for GenericIndex<CompoundWeight> { impl From<GenericIndex<PolyWeight>> for GenericIndex<CompoundWeight> {
fn from(poly: GenericIndex<PolyWeight>) -> Self { fn from(poly: GenericIndex<PolyWeight>) -> Self {
GenericIndex::<CompoundWeight>::new(poly.petgraph_index()) GenericIndex::<CompoundWeight>::new(poly.index())
} }
} }
@ -258,7 +258,7 @@ impl GetMaybeNet for SolidPolyWeight {
impl From<GenericIndex<SolidPolyWeight>> for GenericIndex<CompoundWeight> { impl From<GenericIndex<SolidPolyWeight>> for GenericIndex<CompoundWeight> {
fn from(poly: GenericIndex<SolidPolyWeight>) -> Self { fn from(poly: GenericIndex<SolidPolyWeight>) -> Self {
GenericIndex::<CompoundWeight>::new(poly.petgraph_index()) GenericIndex::<CompoundWeight>::new(poly.index())
} }
} }
@ -282,6 +282,6 @@ impl GetMaybeNet for PourPolyWeight {
impl From<GenericIndex<PourPolyWeight>> for GenericIndex<CompoundWeight> { impl From<GenericIndex<PourPolyWeight>> for GenericIndex<CompoundWeight> {
fn from(poly: GenericIndex<PourPolyWeight>) -> Self { fn from(poly: GenericIndex<PourPolyWeight>) -> Self {
GenericIndex::<CompoundWeight>::new(poly.petgraph_index()) GenericIndex::<CompoundWeight>::new(poly.index())
} }
} }

View File

@ -14,7 +14,7 @@ use crate::{
Drawing, Drawing,
}, },
geometry::primitive::{DotShape, PrimitiveShape}, geometry::primitive::{DotShape, PrimitiveShape},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
layout::{CompoundEntryLabel, CompoundWeight}, layout::{CompoundEntryLabel, CompoundWeight},
math::Circle, math::Circle,
}; };
@ -60,7 +60,7 @@ pub struct ViaWeight {
impl From<GenericIndex<ViaWeight>> for GenericIndex<CompoundWeight> { impl From<GenericIndex<ViaWeight>> for GenericIndex<CompoundWeight> {
fn from(via: GenericIndex<ViaWeight>) -> Self { fn from(via: GenericIndex<ViaWeight>) -> Self {
GenericIndex::<CompoundWeight>::new(via.petgraph_index()) GenericIndex::<CompoundWeight>::new(via.index())
} }
} }

View File

@ -27,7 +27,7 @@ use crate::{
graph::PrimitiveIndex, graph::PrimitiveIndex,
rules::AccessRules, rules::AccessRules,
}, },
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetIndex, MakeRef},
layout::{CompoundEntryLabel, Layout}, layout::{CompoundEntryLabel, Layout},
math::RotationSense, math::RotationSense,
router::thetastar::MakeEdgeRef, router::thetastar::MakeEdgeRef,
@ -47,8 +47,8 @@ impl core::fmt::Debug for NavnodeIndex {
} }
} }
impl GetPetgraphIndex for NavnodeIndex { impl GetIndex for NavnodeIndex {
fn petgraph_index(&self) -> NodeIndex<usize> { fn index(&self) -> NodeIndex<usize> {
self.0 self.0
} }
} }
@ -56,7 +56,7 @@ impl GetPetgraphIndex for NavnodeIndex {
/// A binavnode is a pair of navnodes, one clockwise and the other /// A binavnode is a pair of navnodes, one clockwise and the other
/// counterclockwise. Unlike their constituents, binavnodes are themselves /// counterclockwise. Unlike their constituents, binavnodes are themselves
/// not considered navnodes. /// not considered navnodes.
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetIndex, MakePrimitive)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinavnodeNodeIndex { pub enum BinavnodeNodeIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
@ -271,7 +271,7 @@ impl Navmesh {
// for each union. // for each union.
for prenavnode in prenavmesh.triangulation().node_identifiers() { for prenavnode in prenavmesh.triangulation().node_identifiers() {
let repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new( let repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new(
overlapping_prenavnodes_unions.find(prenavnode.petgraph_index()), overlapping_prenavnodes_unions.find(prenavnode.index()),
)); ));
if repr == prenavnode { if repr == prenavnode {
@ -325,7 +325,7 @@ impl Navmesh {
// Ignore overlaps of a fillet. // Ignore overlaps of a fillet.
if layout if layout
.drawing() .drawing()
.compounds(GenericIndex::<()>::new(prenavnode.petgraph_index())) .compounds(GenericIndex::<()>::new(prenavnode.index()))
.find(|(label, _)| *label == CompoundEntryLabel::Fillet) .find(|(label, _)| *label == CompoundEntryLabel::Fillet)
.is_some() .is_some()
{ {
@ -336,7 +336,7 @@ impl Navmesh {
// Ignore overlaps with fillets. // Ignore overlaps with fillets.
if layout if layout
.drawing() .drawing()
.compounds(GenericIndex::<()>::new(overlapee.1.petgraph_index())) .compounds(GenericIndex::<()>::new(overlapee.1.index()))
.find(|(label, _)| *label == CompoundEntryLabel::Fillet) .find(|(label, _)| *label == CompoundEntryLabel::Fillet)
.is_some() .is_some()
{ {
@ -347,8 +347,7 @@ impl Navmesh {
continue; continue;
}; };
overlapping_prenavnodes_unions overlapping_prenavnodes_unions.union(prenavnode.index(), overlapee.index());
.union(prenavnode.petgraph_index(), overlapee.petgraph_index());
} }
} }
@ -390,10 +389,10 @@ impl Navmesh {
// We assume prenavmesh nodes are fixed dots. This is an ugly shortcut, // We assume prenavmesh nodes are fixed dots. This is an ugly shortcut,
// since fixed bends also can be prenavnodes, but it works for now. // since fixed bends also can be prenavnodes, but it works for now.
let from_prenavnode_repr = PrenavmeshNodeIndex::FixedDot(GenericIndex::new( 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( 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( Self::add_prenavedge_as_quadrinavedges(
@ -456,7 +455,7 @@ impl Data for Navmesh {
impl DataMap for Navmesh { impl DataMap for Navmesh {
fn node_weight(&self, vertex: Self::NodeId) -> Option<&Self::NodeWeight> { 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> { fn edge_weight(&self, _edge: Self::EdgeId) -> Option<&Self::EdgeWeight> {
@ -496,11 +495,7 @@ impl<'a> IntoNeighbors for &'a Navmesh {
type Neighbors = Box<dyn Iterator<Item = NavnodeIndex> + 'a>; type Neighbors = Box<dyn Iterator<Item = NavnodeIndex> + 'a>;
fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors { fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors {
Box::new( Box::new(self.graph.neighbors(vertex.index()).map(NavnodeIndex))
self.graph
.neighbors(vertex.petgraph_index())
.map(NavnodeIndex),
)
} }
} }
@ -526,7 +521,7 @@ impl<'a> IntoEdges for &'a Navmesh {
fn edges(self, vertex: Self::NodeId) -> Self::Edges { fn edges(self, vertex: Self::NodeId) -> Self::Edges {
Box::new( Box::new(
self.graph self.graph
.edges(vertex.petgraph_index()) .edges(vertex.index())
.map(|edge| NavmeshEdgeReference { .map(|edge| NavmeshEdgeReference {
from: NavnodeIndex(edge.source()), from: NavnodeIndex(edge.source()),
to: NavnodeIndex(edge.target()), to: NavnodeIndex(edge.target()),

View File

@ -16,7 +16,7 @@ use crate::{
rules::AccessRules, rules::AccessRules,
}, },
geometry::{primitive::PrimitiveShape, shape::AccessShape as _, shape::MeasureLength as _}, geometry::{primitive::PrimitiveShape, shape::AccessShape as _, shape::MeasureLength as _},
graph::{GenericIndex, GetPetgraphIndex as _}, graph::{GenericIndex, GetIndex as _},
layout::{poly::PolyWeight, CompoundWeight}, layout::{poly::PolyWeight, CompoundWeight},
math::{poly_ext_handover, RotationSense}, math::{poly_ext_handover, RotationSense},
router::{ router::{
@ -270,7 +270,7 @@ impl AstarContext {
let current_poly = layout let current_poly = layout
.drawing() .drawing()
.compounds(GenericIndex::<()>::new(wrap_core.petgraph_index())) .compounds(GenericIndex::<()>::new(wrap_core.index()))
.find_map(|(_, compound)| { .find_map(|(_, compound)| {
if let CompoundWeight::Poly(_) = layout.drawing().compound_weight(compound) if let CompoundWeight::Poly(_) = layout.drawing().compound_weight(compound)
{ {
@ -279,7 +279,7 @@ impl AstarContext {
None None
} }
}) })
.map(|compound| GenericIndex::<PolyWeight>::new(compound.petgraph_index())); .map(|compound| GenericIndex::<PolyWeight>::new(compound.index()));
let (active_head, length_delta) = match ( let (active_head, length_delta) = match (
sub.polygon.take(), sub.polygon.take(),

View File

@ -32,7 +32,7 @@ use crate::{
shape::{AccessShape as _, MeasureLength as _}, shape::{AccessShape as _, MeasureLength as _},
GenericNode, GenericNode,
}, },
graph::GetPetgraphIndex as _, graph::GetIndex as _,
layout::Layout, layout::Layout,
math::{CachedPolyExt, RotationSense}, math::{CachedPolyExt, RotationSense},
router::draw::{Draw, DrawException}, router::draw::{Draw, DrawException},
@ -580,7 +580,7 @@ fn cane_around<R: AccessRules>(
let inner_bend = layout let inner_bend = layout
.drawing() .drawing()
.geometry() .geometry()
.all_rails(core.petgraph_index()) .all_rails(core.index())
.filter_map(|bi| { .filter_map(|bi| {
if let BendIndex::Loose(lbi) = bi { if let BendIndex::Loose(lbi) = bi {
if layout.drawing().find_loose_band_uid(lbi.into()).ok() == Some(inner) { if layout.drawing().find_loose_band_uid(lbi.into()).ok() == Some(inner) {

View File

@ -15,7 +15,7 @@ use crate::{
primitive::MakePrimitiveShape as _, primitive::MakePrimitiveShape as _,
}, },
geometry::{compound::ManageCompounds, shape::AccessShape as _, GetSetPos as _}, geometry::{compound::ManageCompounds, shape::AccessShape as _, GetSetPos as _},
graph::{GenericIndex, GetPetgraphIndex as _}, graph::{GenericIndex, GetIndex as _},
layout::{poly::PolyWeight, CompoundEntryLabel, Layout}, layout::{poly::PolyWeight, CompoundEntryLabel, Layout},
math::{is_poly_convex_hull_cw, CachedPolyExt, RotationSense}, math::{is_poly_convex_hull_cw, CachedPolyExt, RotationSense},
router::ng::{ router::ng::{
@ -52,7 +52,7 @@ impl PolygonRouting {
let convex_hull = layout let convex_hull = layout
.drawing() .drawing()
.geometry() .geometry()
.compound_members(GenericIndex::new(polyidx.petgraph_index())) .compound_members(GenericIndex::new(polyidx.index()))
.filter_map(|(entry_label, primitive_node)| { .filter_map(|(entry_label, primitive_node)| {
let PrimitiveIndex::FixedDot(poly_dot) = primitive_node else { let PrimitiveIndex::FixedDot(poly_dot) = primitive_node else {
return None; return None;

View File

@ -18,7 +18,7 @@ use crate::{
seg::{FixedSegIndex, LoneLooseSegIndex, SeqLooseSegIndex}, seg::{FixedSegIndex, LoneLooseSegIndex, SeqLooseSegIndex},
}, },
geometry::{shape::AccessShape, GetLayer}, geometry::{shape::AccessShape, GetLayer},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetIndex},
layout::{CompoundEntryLabel, Layout}, layout::{CompoundEntryLabel, Layout},
triangulation::{GetTrianvertexNodeIndex, Triangulation}, triangulation::{GetTrianvertexNodeIndex, Triangulation},
}; };
@ -28,7 +28,7 @@ use super::{navmesh::NavmeshError, RouterOptions};
/// Prenavmesh nodes are the vertices of constrained Delaunay triangulation /// Prenavmesh nodes are the vertices of constrained Delaunay triangulation
/// before it is converted to the navmesh, which is done by multiplying each /// before it is converted to the navmesh, which is done by multiplying each
/// of the prenavmesh nodes into more nodes, called navnodes. /// 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)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum PrenavmeshNodeIndex { pub enum PrenavmeshNodeIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
@ -165,7 +165,7 @@ impl Prenavmesh {
layout layout
.drawing() .drawing()
// TODO: Add `.compounds()` method working on `PrimitiveIndex`. // TODO: Add `.compounds()` method working on `PrimitiveIndex`.
.compounds(GenericIndex::<()>::new(dot.petgraph_index())) .compounds(GenericIndex::<()>::new(dot.index()))
.find(|(label, _)| *label == CompoundEntryLabel::Fillet) .find(|(label, _)| *label == CompoundEntryLabel::Fillet)
.is_some(); .is_some();
@ -254,7 +254,7 @@ impl Prenavmesh {
fn is_fixed_dot_filleted(layout: &Layout<impl AccessRules>, dot: FixedDotIndex) -> bool { fn is_fixed_dot_filleted(layout: &Layout<impl AccessRules>, dot: FixedDotIndex) -> bool {
layout layout
.drawing() .drawing()
.compounds(GenericIndex::<()>::new(dot.petgraph_index())) .compounds(GenericIndex::<()>::new(dot.index()))
.find(|(label, _)| .find(|(label, _)|
// Fillets fail this test for some reason that I did not investigate, so // Fillets fail this test for some reason that I did not investigate, so
// I added this condition. // I added this condition.
@ -269,7 +269,7 @@ impl Prenavmesh {
layout layout
.drawing() .drawing()
// TODO: Add `.compounds()` method working on `PrimitiveIndex`. // 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) .find(|(label, _)| *label == CompoundEntryLabel::Fillet)
.is_some() .is_some()
}) })

View File

@ -11,7 +11,7 @@ use spade::{
handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, HasPosition, InsertionError, handles::FixedVertexHandle, ConstrainedDelaunayTriangulation, HasPosition, InsertionError,
}; };
use crate::graph::GetPetgraphIndex; use crate::graph::GetIndex;
pub trait GetTrianvertexNodeIndex<I> { pub trait GetTrianvertexNodeIndex<I> {
fn node_index(&self) -> I; fn node_index(&self) -> I;
@ -27,7 +27,7 @@ pub struct Triangulation<I, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: De
index_marker: PhantomData<I>, index_marker: PhantomData<I>,
} }
impl<I: GetPetgraphIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Default> impl<I: GetIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Default>
Triangulation<I, VW, EW> Triangulation<I, VW, EW>
{ {
pub fn new(node_bound: usize) -> Self { pub fn new(node_bound: usize) -> Self {
@ -39,15 +39,15 @@ impl<I: GetPetgraphIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Defa
} }
pub fn add_vertex(&mut self, weight: VW) -> Result<(), InsertionError> { 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] = self.trianvertex_to_handle[index] =
Some(spade::Triangulation::insert(&mut self.cdt, weight)?); Some(spade::Triangulation::insert(&mut self.cdt, weight)?);
Ok(()) Ok(())
} }
pub fn add_constraint_edge(&mut self, from: VW, to: VW) -> Result<bool, InsertionError> { pub fn add_constraint_edge(&mut self, from: VW, to: VW) -> Result<bool, InsertionError> {
let from_index = from.node_index().petgraph_index().index(); let from_index = from.node_index().index().index();
let to_index = to.node_index().petgraph_index().index(); let to_index = to.node_index().index().index();
// It is possible for one or both constraint edge endpoint vertices to // It is possible for one or both constraint edge endpoint vertices to
// not exist in the triangulation even after everything has been added. // not exist in the triangulation even after everything has been added.
@ -75,13 +75,13 @@ impl<I: GetPetgraphIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Defa
pub fn weight(&self, vertex: I) -> &VW { pub fn weight(&self, vertex: I) -> &VW {
spade::Triangulation::s(&self.cdt) 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 { pub fn weight_mut(&mut self, vertex: I) -> &mut VW {
spade::Triangulation::vertex_data_mut( spade::Triangulation::vertex_data_mut(
&mut self.cdt, &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<I: GetPetgraphIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Defa
} }
fn handle(&self, vertex: I) -> FixedVertexHandle { 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<<VW as HasPosition>::Scalar> pub fn position(&self, vertex: I) -> Point<<VW as HasPosition>::Scalar>
@ -104,11 +104,8 @@ impl<I: GetPetgraphIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Defa
} }
} }
impl< impl<I: Copy + PartialEq + GetIndex, VW: GetTrianvertexNodeIndex<I> + HasPosition, EW: Default>
I: Copy + PartialEq + GetPetgraphIndex, visit::GraphBase for Triangulation<I, VW, EW>
VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Default,
> visit::GraphBase for Triangulation<I, VW, EW>
{ {
type NodeId = I; type NodeId = I;
type EdgeId = (I, I); type EdgeId = (I, I);
@ -133,7 +130,7 @@ impl<EW> PartialOrd for TriangulationEdgeWeightWrapper<EW> {
} }
impl< impl<
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition, VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Copy + Default, EW: Copy + Default,
> visit::Data for Triangulation<I, VW, EW> > visit::Data for Triangulation<I, VW, EW>
@ -173,7 +170,7 @@ impl<I: Copy, EW: Copy> visit::EdgeRef for TriangulationEdgeReference<I, EW> {
impl< impl<
'a, 'a,
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition, VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Default, EW: Default,
> visit::IntoNeighbors for &'a Triangulation<I, VW, EW> > visit::IntoNeighbors for &'a Triangulation<I, VW, EW>
@ -191,7 +188,7 @@ impl<
impl< impl<
'a, 'a,
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition<Scalar = f64>, VW: GetTrianvertexNodeIndex<I> + HasPosition<Scalar = f64>,
EW: Copy + Default, EW: Copy + Default,
> visit::IntoEdgeReferences for &'a Triangulation<I, VW, EW> > visit::IntoEdgeReferences for &'a Triangulation<I, VW, EW>
@ -218,7 +215,7 @@ impl<
impl< impl<
'a, 'a,
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition<Scalar = f64>, VW: GetTrianvertexNodeIndex<I> + HasPosition<Scalar = f64>,
EW: Copy + Default, EW: Copy + Default,
> visit::IntoEdges for &'a Triangulation<I, VW, EW> > visit::IntoEdges for &'a Triangulation<I, VW, EW>
@ -248,7 +245,7 @@ impl<
impl< impl<
'a, 'a,
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition, VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Default, EW: Default,
> visit::IntoNodeIdentifiers for &'a Triangulation<I, VW, EW> > visit::IntoNodeIdentifiers for &'a Triangulation<I, VW, EW>
@ -298,7 +295,7 @@ impl<I: Copy, VW> visit::NodeRef for TriangulationVertexReference<'_, I, VW> {
impl< impl<
'a, 'a,
I: Copy + PartialEq + GetPetgraphIndex, I: Copy + PartialEq + GetIndex,
VW: GetTrianvertexNodeIndex<I> + HasPosition, VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Copy + Default, EW: Copy + Default,
> visit::IntoNodeReferences for &'a Triangulation<I, VW, EW> > visit::IntoNodeReferences for &'a Triangulation<I, VW, EW>
@ -320,7 +317,7 @@ impl<
} }
impl< impl<
I: Copy + PartialEq + GetPetgraphIndex + std::fmt::Debug, I: Copy + PartialEq + GetIndex + std::fmt::Debug,
VW: GetTrianvertexNodeIndex<I> + HasPosition, VW: GetTrianvertexNodeIndex<I> + HasPosition,
EW: Default, EW: Default,
> visit::NodeIndexable for &Triangulation<I, VW, EW> > visit::NodeIndexable for &Triangulation<I, VW, EW>
@ -331,7 +328,7 @@ impl<
} }
fn to_index(&self, node: I) -> usize { fn to_index(&self, node: I) -> usize {
node.petgraph_index().index() node.index().index()
} }
fn from_index(&self, index: usize) -> I { fn from_index(&self, index: usize) -> I {

View File

@ -14,7 +14,7 @@ use topola::{
board::{edit::BoardEdit, AccessMesadata, Board}, board::{edit::BoardEdit, AccessMesadata, Board},
drawing::graph::{GetMaybeNet, PrimitiveIndex}, drawing::graph::{GetMaybeNet, PrimitiveIndex},
geometry::{shape::MeasureLength, GenericNode, GetLayer}, geometry::{shape::MeasureLength, GenericNode, GetLayer},
graph::{GetPetgraphIndex, MakeRef}, graph::{GetIndex, MakeRef},
router::{navmesh::Navmesh, RouterOptions}, router::{navmesh::Navmesh, RouterOptions},
specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, 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) { if let Some(netname) = autorouter.board().layout().rules().net_netname(net) {
// We don't route ground. // We don't route ground.
let org = unionfind.find(origin_dot.petgraph_index()); let org = unionfind.find(origin_dot.index());
let desc = unionfind.find(destination_dot.petgraph_index()); let desc = unionfind.find(destination_dot.index());
if netname != "GND" { if netname != "GND" {
assert_eq!(org, desc); assert_eq!(org, desc);
@ -282,7 +282,7 @@ fn unionfind(autorouter: &mut Autorouter<impl AccessMesadata>) -> UnionFind<Node
.geometry() .geometry()
.joineds(primitive) .joineds(primitive)
{ {
unionfind.union(primitive.petgraph_index(), joined.petgraph_index()); unionfind.union(primitive.index(), joined.index());
} }
} }