From f2fdaa687b98f56048891082aa6ba41beedcc65b Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 5 Jul 2021 13:27:42 +0200 Subject: [PATCH] pipeline builders for sequence to grid with simple horizontal / vertical layout --- nested/src/index/map_key.rs | 21 ++++++++++++++++++++- nested/src/sequence/seq2idx.rs | 11 ++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/nested/src/index/map_key.rs b/nested/src/index/map_key.rs index 19e6916..4635f4c 100644 --- a/nested/src/index/map_key.rs +++ b/nested/src/index/map_key.rs @@ -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 OuterViewPort> +where Item: 'static +{ + pub fn to_grid_horizontal(&self) -> OuterViewPort> { + 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> { + 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 where DstKey: Clone + Send + Sync, SrcKey: Clone + Send + Sync, diff --git a/nested/src/sequence/seq2idx.rs b/nested/src/sequence/seq2idx.rs index 79cf003..17df9e7 100644 --- a/nested/src/sequence/seq2idx.rs +++ b/nested/src/sequence/seq2idx.rs @@ -9,7 +9,8 @@ use { ViewPort, InnerViewPort, OuterViewPort }, sequence::SequenceView, - index::IndexView + index::IndexView, + grid::GridView } }; @@ -43,6 +44,14 @@ impl OuterViewPort> { self.add_observer(Sequence2Index::new(port.inner())); port.into_outer() } + + pub fn to_grid_horizontal(&self) -> OuterViewPort> { + self.to_index().to_grid_horizontal() + } + + pub fn to_grid_vertical(&self) -> OuterViewPort> { + self.to_index().to_grid_vertical() + } } impl View for Sequence2Index