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.
This commit is contained in:
Mikolaj Wielgus 2023-12-16 20:33:15 +00:00
parent ef593aca78
commit 73736fef50
1 changed files with 20 additions and 0 deletions

View File

@ -50,6 +50,10 @@ pub trait GetOtherEnd<F: GetNodeIndex, T: GetNodeIndex + Into<F>>: GetEnds<F, T>
}
}
pub trait GetWraparound: GetLayout + GetNodeIndex {
fn wraparound(&self) -> Option<LooseBendIndex>;
}
pub trait GetFirstRail: GetLayout + GetNodeIndex {
fn first_rail(&self) -> Option<LooseBendIndex> {
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<LooseBendIndex> {
self.first_rail()
}
}
pub type LooseDot<'a> = GenericPrimitive<'a, LooseDotWeight>;
impl_loose_primitive!(LooseDot, LooseDotWeight);
@ -467,6 +477,11 @@ impl<'a> GetEnds<FixedDotIndex, FixedDotIndex> for FixedBend<'a> {
impl<'a> GetOtherEnd<FixedDotIndex, FixedDotIndex> for FixedBend<'a> {}
impl<'a> GetFirstRail for FixedBend<'a> {}
impl<'a> GetWraparound for FixedBend<'a> {
fn wraparound(&self) -> Option<LooseBendIndex> {
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<LooseDotIndex, LooseDotIndex> for LooseBend<'a> {
}
impl<'a> GetOtherEnd<LooseDotIndex, LooseDotIndex> for LooseBend<'a> {}
impl<'a> GetWraparound for LooseBend<'a> {
fn wraparound(&self) -> Option<LooseBendIndex> {
self.outer()
}
}
impl<'a> GetCore for LooseBend<'a> {}
impl<'a> GetInnerOuter for LooseBend<'a> {}