diff --git a/src/drawing/bend.rs b/src/drawing/bend.rs index 3d75fbe..067086f 100644 --- a/src/drawing/bend.rs +++ b/src/drawing/bend.rs @@ -6,7 +6,7 @@ use enum_dispatch::enum_dispatch; use crate::{ drawing::{ - graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, + graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, primitive::{GenericPrimitive, Primitive}, rules::AccessRules, Drawing, diff --git a/src/drawing/dot.rs b/src/drawing/dot.rs index f337dbe..71195f1 100644 --- a/src/drawing/dot.rs +++ b/src/drawing/dot.rs @@ -9,7 +9,7 @@ use petgraph::stable_graph::NodeIndex; use crate::{ drawing::{ - graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, + graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, primitive::{GenericPrimitive, Primitive}, rules::AccessRules, Drawing, diff --git a/src/drawing/graph.rs b/src/drawing/graph.rs index 990e80a..1cce166 100644 --- a/src/drawing/graph.rs +++ b/src/drawing/graph.rs @@ -5,7 +5,7 @@ use enum_dispatch::enum_dispatch; use petgraph::stable_graph::NodeIndex; -use crate::{drawing::Drawing, graph::GetPetgraphIndex}; +use crate::graph::{GenericIndex, GetPetgraphIndex}; use super::{ bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, @@ -16,11 +16,12 @@ use super::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex, SeqLooseSegWeight, }, + Drawing, }; -#[enum_dispatch] -pub trait Retag { - fn retag(&self, index: NodeIndex) -> PrimitiveIndex; +pub trait Retag { + type Index: Sized + GetPetgraphIndex + PartialEq + Copy; + fn retag(&self, index: NodeIndex) -> Self::Index; } #[enum_dispatch] @@ -61,12 +62,6 @@ pub trait MakePrimitive { macro_rules! impl_weight_forward { ($weight_struct:ty, $weight_variant:ident, $index_struct:ident) => { - impl Retag for $weight_struct { - fn retag(&self, index: NodeIndex) -> PrimitiveIndex { - PrimitiveIndex::$weight_variant($index_struct::new(index)) - } - } - impl GetLayer for $weight_struct { fn layer(&self) -> usize { self.0.layer() @@ -112,7 +107,7 @@ pub enum PrimitiveIndex { LooseBend(LooseBendIndex), } -#[enum_dispatch(GetWidth, GetLayer, Retag)] +#[enum_dispatch(GetWidth, GetLayer)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum PrimitiveWeight { FixedDot(FixedDotWeight), @@ -123,3 +118,27 @@ pub enum PrimitiveWeight { FixedBend(FixedBendWeight), LooseBend(LooseBendWeight), } + +impl Retag for PrimitiveWeight { + type Index = PrimitiveIndex; + + fn retag(&self, index: NodeIndex) -> PrimitiveIndex { + macro_rules! match_self { + ($self:expr, $($kind:ident),*,) => {{ + match $self { + $(PrimitiveWeight::$kind(_) => PrimitiveIndex::$kind(GenericIndex::new(index))),* + } + }} + } + match_self!( + self, + FixedDot, + LooseDot, + FixedSeg, + LoneLooseSeg, + SeqLooseSeg, + FixedBend, + LooseBend, + ) + } +} diff --git a/src/drawing/seg.rs b/src/drawing/seg.rs index 216155a..bb0844b 100644 --- a/src/drawing/seg.rs +++ b/src/drawing/seg.rs @@ -6,7 +6,7 @@ use enum_dispatch::enum_dispatch; use crate::{ drawing::{ - graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, + graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, primitive::{GenericPrimitive, Primitive}, rules::AccessRules, Drawing, diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index a52e0ce..cb5496f 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -12,7 +12,7 @@ use crate::{ use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth}; pub trait ApplyGeometryEdit< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, @@ -37,7 +37,7 @@ pub struct GeometryEdit { } impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index 4eb2192..51a7348 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -113,7 +113,7 @@ impl Geometry + TryInto + TryInto + Retag + Copy, + PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into, SW: AccessSegWeight + Into, BW: AccessBendWeight + Into, diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index 35134b6..f8ee146 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -27,7 +27,7 @@ pub struct RecordingGeometryWithRtree { } impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, @@ -338,7 +338,7 @@ fn edit_remove_from_map( } impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index b0aad4a..08fb47d 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -49,7 +49,7 @@ pub struct GeometryWithRtree { #[debug_invariant(self.test_envelopes())] #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, @@ -262,7 +262,7 @@ impl< } impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, @@ -392,7 +392,7 @@ impl< } impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer,