Function grid_search::around
source · pub fn around<'a>(y: usize, x: usize) -> Around<'a> ⓘ
Expand description
(y, x)
を基点とした周辺座標を yield するイテレータを作ります。
Examples
隣接 4 方向を走査する例です。
use grid_search::around;
const NSEW: [(isize, isize); 4] = [(-1, 0), (1, 0), (0, 1), (0, -1)];
let mut a = around(0, 1).y_range(0..3).x_range(0..4).directions(&NSEW);
assert_eq!(a.next(), Some((1, 1)));
assert_eq!(a.next(), Some((0, 2)));
assert_eq!(a.next(), Some((0, 0)));
assert_eq!(a.next(), None);
// .x..
// ....
// ....
//
// |
// v
//
// x.x.
// .x..
// ....