| 95 |
95 |
| 96 impl<U: Num, const N: usize> Cube<N, U> { |
96 impl<U: Num, const N: usize> Cube<N, U> { |
| 97 /// Maps `f` over the triples $\\{(i, a\_i, b\_i)\\}\_{i=1}^N$ |
97 /// Maps `f` over the triples $\\{(i, a\_i, b\_i)\\}\_{i=1}^N$ |
| 98 /// of the cube $∏_{i=1}^N [a_i, b_i)$. |
98 /// of the cube $∏_{i=1}^N [a_i, b_i)$. |
| 99 #[inline] |
99 #[inline] |
| 100 pub fn map_indexed<T>(&self, f: impl Fn(usize, U, U) -> T) -> [T; N] { |
100 pub fn map_indexed<T>(&self, mut f: impl FnMut(usize, U, U) -> T) -> [T; N] { |
| 101 map1_indexed(self, |i, &[a, b]| f(i, a, b)) |
101 map1_indexed(self, |i, &[a, b]| f(i, a, b)) |
| 102 } |
102 } |
| 103 |
103 |
| 104 /// Maps `f` over the tuples $\\{(a\_i, b\_i)\\}\_{i=1}^N$ |
104 /// Maps `f` over the tuples $\\{(a\_i, b\_i)\\}\_{i=1}^N$ |
| 105 /// of the cube $∏_{i=1}^N [a_i, b_i)$. |
105 /// of the cube $∏_{i=1}^N [a_i, b_i)$. |
| 106 #[inline] |
106 #[inline] |
| 107 pub fn map<T>(&self, f: impl Fn(U, U) -> T) -> [T; N] { |
107 pub fn map<T>(&self, mut f: impl FnMut(U, U) -> T) -> [T; N] { |
| 108 map1(self, |&[a, b]| f(a, b)) |
108 map1(self, |&[a, b]| f(a, b)) |
| 109 } |
109 } |
| 110 |
110 |
| 111 /// Iterates over the start and end coordinates $\{(a_i, b_i)\}_{i=1}^N$ of the cube along |
111 /// Iterates over the start and end coordinates $\{(a_i, b_i)\}_{i=1}^N$ of the cube along |
| 112 /// each dimension. |
112 /// each dimension. |
| 143 |
143 |
| 144 /// Iterates over the corners $\{(c_1, … ,c_N) | c_i ∈ \{a_i, b_i\}\}$ of the cube |
144 /// Iterates over the corners $\{(c_1, … ,c_N) | c_i ∈ \{a_i, b_i\}\}$ of the cube |
| 145 /// $∏_{i=1}^N [a_i, b_i)$. |
145 /// $∏_{i=1}^N [a_i, b_i)$. |
| 146 #[inline] |
146 #[inline] |
| 147 pub fn iter_corners(&self) -> CubeCornersIter<'_, U, N> { |
147 pub fn iter_corners(&self) -> CubeCornersIter<'_, U, N> { |
| 148 CubeCornersIter { |
148 CubeCornersIter { index: 0, cube: self } |
| 149 index: 0, |
|
| 150 cube: self, |
|
| 151 } |
|
| 152 } |
149 } |
| 153 |
150 |
| 154 /// Returns the width-`N`-tuple $(b_1-a_1, … ,b_N-a_N)$ of the cube $∏_{i=1}^N [a_i, b_i)$. |
151 /// Returns the width-`N`-tuple $(b_1-a_1, … ,b_N-a_N)$ of the cube $∏_{i=1}^N [a_i, b_i)$. |
| 155 #[inline] |
152 #[inline] |
| 156 pub fn width(&self) -> Loc<N, U> { |
153 pub fn width(&self) -> Loc<N, U> { |