Function iter_num_tools::grid_space

source ·
pub fn grid_space<R, S, const N: usize>(
    range: R,
    steps: S
) -> GridSpace<R::Item, N>where
    R: ToGridSpace<S, N>,
Expand description

Creates a linear grid space over range with a fixed number of width and height steps

use iter_num_tools::grid_space;

let it = grid_space([0.0, 0.0]..[1.0, 2.0], [2, 4]);
assert!(it.eq(vec![
    [0.0, 0.0], [0.5, 0.0],
    [0.0, 0.5], [0.5, 0.5],
    [0.0, 1.0], [0.5, 1.0],
    [0.0, 1.5], [0.5, 1.5],
]));

// inclusive and with a single step count
let it = grid_space([0.0, 0.0]..=[1.0, 2.0], 3);
assert!(it.eq(vec![
    [0.0, 0.0], [0.5, 0.0], [1.0, 0.0],
    [0.0, 1.0], [0.5, 1.0], [1.0, 1.0],
    [0.0, 2.0], [0.5, 2.0], [1.0, 2.0],
]));

// even nd spaces
let it = grid_space([0, 0, 0]..=[1, 1, 1], 2);
assert!(it.eq(vec![
    [0, 0, 0], [1, 0, 0],
    [0, 1, 0], [1, 1, 0],

    [0, 0, 1], [1, 0, 1],
    [0, 1, 1], [1, 1, 1],
]));