From 73736fef50428dff8e5b67cc7bd0843dfa0a8d37 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sat, 16 Dec 2023 20:33:15 +0000 Subject: [PATCH] primitive: create `GetWraparound` trait to get the wraparound Wraparound is either the outer bend or the first rail bend. We need this trait because some routines can wrap around both fixed and loose primitives. --- src/primitive.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/primitive.rs b/src/primitive.rs index 58e1827..c662497 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -50,6 +50,10 @@ pub trait GetOtherEnd>: GetEnds } } +pub trait GetWraparound: GetLayout + GetNodeIndex { + fn wraparound(&self) -> Option; +} + pub trait GetFirstRail: GetLayout + GetNodeIndex { fn first_rail(&self) -> Option { self.layout() @@ -287,6 +291,12 @@ impl<'a> MakeShape for FixedDot<'a> { impl<'a> GetFirstRail for FixedDot<'a> {} +impl<'a> GetWraparound for FixedDot<'a> { + fn wraparound(&self) -> Option { + self.first_rail() + } +} + pub type LooseDot<'a> = GenericPrimitive<'a, LooseDotWeight>; impl_loose_primitive!(LooseDot, LooseDotWeight); @@ -467,6 +477,11 @@ impl<'a> GetEnds for FixedBend<'a> { impl<'a> GetOtherEnd for FixedBend<'a> {} impl<'a> GetFirstRail for FixedBend<'a> {} +impl<'a> GetWraparound for FixedBend<'a> { + fn wraparound(&self) -> Option { + self.first_rail() + } +} impl<'a> GetCore for FixedBend<'a> {} // TODO: Fixed bends don't have cores actually. //impl<'a> GetInnerOuter for FixedBend<'a> {} @@ -537,5 +552,10 @@ impl<'a> GetEnds for LooseBend<'a> { } impl<'a> GetOtherEnd for LooseBend<'a> {} +impl<'a> GetWraparound for LooseBend<'a> { + fn wraparound(&self) -> Option { + self.outer() + } +} impl<'a> GetCore for LooseBend<'a> {} impl<'a> GetInnerOuter for LooseBend<'a> {}