pub struct GoalDistance<K> { /* private fields */ }Expand description
How far a piece would walk from a tile to the nearest of some goals,
with one flow_field per movement kind K, built on first use and
kept. Stepping onto a goal’s own tile is free and always allowed: a
goal is often a tile another piece stands on.
Implementations§
Source§impl<K: Ord + Copy> GoalDistance<K>
impl<K: Ord + Copy> GoalDistance<K>
Sourcepub fn new(width: u16, height: u16, goals: Vec<Pos>) -> Self
pub fn new(width: u16, height: u16, goals: Vec<Pos>) -> Self
The goals goals on a width × height grid. Goals outside it are
left out of every walk.
Sourcepub fn distance(
&mut self,
kind: K,
from: Pos,
cost: impl Fn(Pos) -> Option<u32>,
) -> Option<u32>
pub fn distance( &mut self, kind: K, from: Pos, cost: impl Fn(Pos) -> Option<u32>, ) -> Option<u32>
How far a piece of movement kind kind would walk from from to
the nearest goal, where entering a tile costs cost(tile) (None:
it can’t be entered) and entering a goal costs 0. None with no
goals, or no walk. 0 on a goal.
The first call for a kind builds its field with cost; later
calls read it and never call cost, so cost must answer the same
for every call with one kind. Make a new GoalDistance when the
costs change.
Trait Implementations§
Source§impl<K: Clone> Clone for GoalDistance<K>
impl<K: Clone> Clone for GoalDistance<K>
Source§fn clone(&self) -> GoalDistance<K>
fn clone(&self) -> GoalDistance<K>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more