diff --git a/maze/src/lib.rs b/maze/src/lib.rs index 69d90d7..fe02044 100644 --- a/maze/src/lib.rs +++ b/maze/src/lib.rs @@ -502,8 +502,8 @@ impl BinaryMap { } } - pub fn lines(&self) -> impl Iterator { - self.0.windows(X) + pub fn rows(&self) -> impl Iterator { + self.0.windows(X).step_by(X) } /// 0 1 2 @@ -539,7 +539,22 @@ mod column_iter_tests { use super::*; #[test] - fn check() { + fn rows() { + let grid = [ + 1, 2, 3, // + 4, 5, 6, // + 7, 8, 9, // + 10, 11, 12, // + ]; + let mut it = grid.windows(3).step_by(3); + assert_eq!(it.next().map(Vec::from), Some(vec![1, 2, 3])); + assert_eq!(it.next().map(Vec::from), Some(vec![4, 5, 6])); + assert_eq!(it.next().map(Vec::from), Some(vec![7, 8, 9])); + assert_eq!(it.next().map(Vec::from), Some(vec![10, 11, 12])); + assert_eq!(it.next(), None); + } + #[test] + fn cols() { let grid = [ 1, 2, 3, // 4, 5, 6, //