Skip to main content

flow_field

Function flow_field 

Source
pub fn flow_field(
    width: u16,
    height: u16,
    goals: impl IntoIterator<Item = Pos>,
    cost: impl Fn(Pos) -> Option<u32>,
) -> Grid<Option<u32>>
Expand description

How far every tile of a width × height grid is from the nearest of goals: the cost of the cheapest walk from the tile onto a goal, where entering a tile costs cost(tile), as in reachable, and there is no budget. A goal is 0 from itself. A tile that can’t be entered has no distance (unless it is a goal), and neither has a tile with no walk to a goal: a goal that can’t be entered is never walked onto. Goals outside the grid are left out.