pipeline builders for sequence to grid with simple horizontal / vertical layout

This commit is contained in:
Michael Sippel 2021-07-05 13:27:42 +02:00
parent e7d1763369
commit f2fdaa687b
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 30 additions and 2 deletions

View file

@ -14,7 +14,8 @@ pub use {
InnerViewPort,
OuterViewPort
},
index::{IndexView}
index::{IndexView},
grid::{GridView}
}
};
@ -40,6 +41,24 @@ where SrcKey: Clone + Send + Sync + 'static,
}
}
impl<Item> OuterViewPort<dyn IndexView<usize, Item = Item>>
where Item: 'static
{
pub fn to_grid_horizontal(&self) -> OuterViewPort<dyn GridView<Item = Item>> {
self.map_key(
|idx| cgmath::Point2::new(*idx as i16, 0),
|pt| if pt.y == 0 { Some(pt.x as usize) } else { None }
)
}
pub fn to_grid_vertical(&self) -> OuterViewPort<dyn GridView<Item = Item>> {
self.map_key(
|idx| cgmath::Point2::new(0, *idx as i16),
|pt| if pt.x == 0 { Some(pt.y as usize) } else { None }
)
}
}
pub struct MapIndexKey<DstKey, SrcKey, SrcView, F1, F2>
where DstKey: Clone + Send + Sync,
SrcKey: Clone + Send + Sync,

View file

@ -9,7 +9,8 @@ use {
ViewPort, InnerViewPort, OuterViewPort
},
sequence::SequenceView,
index::IndexView
index::IndexView,
grid::GridView
}
};
@ -43,6 +44,14 @@ impl<Item: 'static> OuterViewPort<dyn SequenceView<Item = Item>> {
self.add_observer(Sequence2Index::new(port.inner()));
port.into_outer()
}
pub fn to_grid_horizontal(&self) -> OuterViewPort<dyn GridView<Item = Item>> {
self.to_index().to_grid_horizontal()
}
pub fn to_grid_vertical(&self) -> OuterViewPort<dyn GridView<Item = Item>> {
self.to_index().to_grid_vertical()
}
}
impl<SrcView> View for Sequence2Index<SrcView>