pub fn apply_stencil<'a, const N: usize>(
coords: &'a [usize; N],
sizes: &'a [usize; N],
offsets: &'a [[isize; N]],
) -> impl Iterator<Item = [usize; N]> + 'a
Expand description
Applies a stencil pattern to coordinates, returning valid resulting coordinates.
Given base coordinates and a set of offset vectors (the stencil), computes the coordinates that result from applying each offset. Only returns coordinates that fall within the specified bounds.
§Arguments
coords
- Base coordinates in N-dimensional spacesizes
- Size bounds for each dimension (coordinates must be < size)offsets
- Collection of offset vectors to apply to the base coordinates
§Returns
An iterator yielding valid coordinates (as Vec<usize>
) for each
offset that produces in-bounds results. Out-of-bounds results are
filtered out.
§Panics
Panics if coords
and sizes
have different lengths, or if any
offset vector has a different length than coords
.
§Examples
let coords = &[1, 1];
let sizes = &[3, 3];
let offsets: [[isize; 2]; 4] = [[-1, 0], [1, 0], [0, -1], [0, 1]];
let results: Vec<_> = ndslice::utils::apply_stencil(coords, sizes, &offsets).collect();
// Results in: [[0, 1], [2, 1], [1, 0], [1, 2]]