mirror of https://codeberg.org/topola/topola.git
refactor(Retag): only implement trait once, Index should be associated type
This commit is contained in:
parent
1e690ace11
commit
61c7b5450f
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<PrimitiveIndex> {
|
||||
fn retag(&self, index: NodeIndex<usize>) -> PrimitiveIndex;
|
||||
pub trait Retag {
|
||||
type Index: Sized + GetPetgraphIndex + PartialEq + Copy;
|
||||
fn retag(&self, index: NodeIndex<usize>) -> 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<PrimitiveIndex> for $weight_struct {
|
||||
fn retag(&self, index: NodeIndex<usize>) -> 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<PrimitiveIndex>)]
|
||||
#[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<usize>) -> 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth};
|
||||
|
||||
pub trait ApplyGeometryEdit<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
@ -37,7 +37,7 @@ pub struct GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ impl<PW, DW, SW, BW, CW, PI, DI, SI, BI> Geometry<PW, DW, SW, BW, CW, PI, DI, SI
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW>,
|
||||
SW: AccessSegWeight + Into<PW>,
|
||||
BW: AccessBendWeight + Into<PW>,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub struct RecordingGeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
@ -338,7 +338,7 @@ fn edit_remove_from_map<I: Ord, T>(
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ pub struct GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
|||
#[debug_invariant(self.test_envelopes())]
|
||||
#[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())]
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
@ -262,7 +262,7 @@ impl<
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
@ -392,7 +392,7 @@ impl<
|
|||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
||||
|
|
|
|||
Loading…
Reference in New Issue