#![allow(private_bounds)] use crate::lib::*; pub fn iter2d(args: impl IterArgs2d) -> impl Iterator> { let (wr, h) = args.get(); let (mut x, w, mut y, h) = (wr.start, wr.end, h.start, h.end); let ident = T::to(1); iter::from_fn(move || { if y >= h { None? } let ret = Some((x, y)); x += ident; if x >= w { x = wr.start; y += ident; } ret }) } pub fn iter3d(args: impl IterArgs3d) -> impl Iterator> { let (wr, hr, d) = args.get(); let (mut x, w, mut y, h, mut z, d) = (wr.start, wr.end, hr.start, hr.end, d.start, d.end); let ident = T::to(1); iter::from_fn(move || { if z >= d { None? } let ret = Some((x, y, z)); x += ident; if x >= w { x = wr.start; y += ident; } if y >= h { y = hr.start; z += ident; } ret }) } type Args2d = (R, R); trait IterArgs2d { fn get(self) -> Args2d; } impl IterArgs2d for Args2d { fn get(self) -> Self { self } } impl IterArgs2d for R { fn get(self) -> Args2d { (self.clone(), self) } } impl IterArgs2d for T { fn get(self) -> Args2d { (Def()..self, Def()..self) } } impl IterArgs2d for (T, T) { fn get(self) -> Args2d { (Def()..self.0, Def()..self.1) } } type Args3d = (R, R, R); trait IterArgs3d { fn get(self) -> Args3d; } impl IterArgs3d for Args3d { fn get(self) -> Self { self } } impl IterArgs3d for R { fn get(self) -> Args3d { (self.clone(), self.clone(), self) } } impl IterArgs3d for T { fn get(self) -> Args3d { (Def()..self, Def()..self, Def()..self) } } impl IterArgs3d for (T, T, T) { fn get(self) -> Args3d { (Def()..self.0, Def()..self.1, Def()..self.2) } } type R = ops::Range; trait_alias!(Rangeable, Default + ops::AddAssign + Copy + PartialOrd + Cast);