mirror of https://codeberg.org/topola/topola.git
refactor(drawing/gear): Remove `GetPrevNextInChain` trait
It wasn't helpful after all.
This commit is contained in:
parent
9f7e10bc03
commit
c2cd565a9b
|
|
@ -83,29 +83,6 @@ pub trait WalkOutwards {
|
||||||
fn outwards(&self) -> DrawingOutwardWalker;
|
fn outwards(&self) -> DrawingOutwardWalker;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[enum_dispatch]
|
|
||||||
pub trait GetPrevNextInChain {
|
|
||||||
fn next_in_chain(&self, maybe_prev: Option<GearIndex>) -> Option<GearIndex>;
|
|
||||||
|
|
||||||
fn prev_in_chain(&self, maybe_next: Option<GearIndex>) -> Option<GearIndex> {
|
|
||||||
// Just as in the `GetPrevNextLoose` trait.
|
|
||||||
let maybe_prev = maybe_next.or_else(|| self.next_in_chain(None));
|
|
||||||
self.next_in_chain(maybe_prev)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Because types have trait bounds, we cannot use enum_dispatch and instead we
|
|
||||||
// implement `GetPrevNextInChain` explicitly.
|
|
||||||
impl<'a, CW: Clone, Cel: Copy, R: AccessRules> GetPrevNextInChain for GearRef<'a, CW, Cel, R> {
|
|
||||||
fn next_in_chain(&self, maybe_prev: Option<GearIndex>) -> Option<GearIndex> {
|
|
||||||
match self {
|
|
||||||
GearRef::FixedDot(dot) => dot.next_in_chain(maybe_prev),
|
|
||||||
GearRef::FixedBend(bend) => bend.next_in_chain(maybe_prev),
|
|
||||||
GearRef::LooseBend(bend) => bend.next_in_chain(maybe_prev),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// I found it easier to just duplicate `OutwardWalker<BI>` for `Drawing<...>`.
|
/// I found it easier to just duplicate `OutwardWalker<BI>` for `Drawing<...>`.
|
||||||
pub struct DrawingOutwardWalker {
|
pub struct DrawingOutwardWalker {
|
||||||
frontier: VecDeque<LooseBendIndex>,
|
frontier: VecDeque<LooseBendIndex>,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
||||||
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
||||||
gear::{GearIndex, GetPrevNextInChain},
|
|
||||||
graph::{GetMaybeNet, PrimitiveIndex, PrimitiveWeight},
|
graph::{GetMaybeNet, PrimitiveIndex, PrimitiveWeight},
|
||||||
rules::{AccessRules, Conditions, GetConditions},
|
rules::{AccessRules, Conditions, GetConditions},
|
||||||
seg::{FixedSegWeight, LoneLooseSegWeight, SegIndex, SeqLooseSegIndex, SeqLooseSegWeight},
|
seg::{FixedSegWeight, LoneLooseSegWeight, SegIndex, SeqLooseSegIndex, SeqLooseSegWeight},
|
||||||
|
|
@ -292,24 +291,6 @@ impl<CW, Cel, R> GetOuterGears for FixedDot<'_, CW, Cel, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CW: Clone, Cel: Copy, R: AccessRules> GetPrevNextInChain for FixedDot<'_, CW, Cel, R> {
|
|
||||||
fn next_in_chain(&self, maybe_prev: Option<GearIndex>) -> Option<GearIndex> {
|
|
||||||
self.drawing
|
|
||||||
.overlapees(self.index.into())
|
|
||||||
.find_map(|infringement| {
|
|
||||||
let PrimitiveIndex::FixedDot(intersectee) = infringement.1 else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(prev) = maybe_prev {
|
|
||||||
(infringement.1 == prev.into()).then_some(intersectee.into())
|
|
||||||
} else {
|
|
||||||
Some(intersectee.into())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CW, Cel, R> WalkOutwards for FixedDot<'_, CW, Cel, R> {
|
impl<CW, Cel, R> WalkOutwards for FixedDot<'_, CW, Cel, R> {
|
||||||
fn outwards(&self) -> DrawingOutwardWalker {
|
fn outwards(&self) -> DrawingOutwardWalker {
|
||||||
DrawingOutwardWalker::new(self.lowest_gears().into_iter())
|
DrawingOutwardWalker::new(self.lowest_gears().into_iter())
|
||||||
|
|
@ -476,12 +457,6 @@ impl<CW, Cel, R> GetOuterGears for FixedBend<'_, CW, Cel, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CW, Cel, R> GetPrevNextInChain for FixedBend<'_, CW, Cel, R> {
|
|
||||||
fn next_in_chain(&self, _maybe_prev: Option<GearIndex>) -> Option<GearIndex> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CW, Cel, R> WalkOutwards for FixedBend<'_, CW, Cel, R> {
|
impl<CW, Cel, R> WalkOutwards for FixedBend<'_, CW, Cel, R> {
|
||||||
fn outwards(&self) -> DrawingOutwardWalker {
|
fn outwards(&self) -> DrawingOutwardWalker {
|
||||||
DrawingOutwardWalker::new(self.lowest_gears().into_iter())
|
DrawingOutwardWalker::new(self.lowest_gears().into_iter())
|
||||||
|
|
@ -535,12 +510,6 @@ impl<CW, Cel, R> GetOuterGears for LooseBend<'_, CW, Cel, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CW, Cel, R> GetPrevNextInChain for LooseBend<'_, CW, Cel, R> {
|
|
||||||
fn next_in_chain(&self, _maybe_prev: Option<GearIndex>) -> Option<GearIndex> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CW, Cel, R> WalkOutwards for LooseBend<'_, CW, Cel, R> {
|
impl<CW, Cel, R> WalkOutwards for LooseBend<'_, CW, Cel, R> {
|
||||||
fn outwards(&self) -> DrawingOutwardWalker {
|
fn outwards(&self) -> DrawingOutwardWalker {
|
||||||
DrawingOutwardWalker::new(self.outers())
|
DrawingOutwardWalker::new(self.outers())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue