asWeighted method

WeightedWalkable<Pos> asWeighted({
  1. required double weight(
    1. E,
    2. E,
    3. Pos
    ),
  2. Iterable<Pos> directions = Direction.cardinal,
})

Returns a view of this grid as a weighted walkable.

The view is a WeightedWalkable where nodes are positions in the grid, and edges are pairs of elements at each position. The directions are the relative positions of the neighbors to connect each node to, which by default are the four cardinal directions (north, east, south, west).

A weight is derived from the source and target nodes and the direction moved by calling the weight function. Any value that returns double.infinity is considered impassable and will not be connected to its neighbors.

Implementation

WeightedWalkable<Pos> asWeighted({
  required double Function(E, E, Pos) weight,
  Iterable<Pos> directions = Direction.cardinal,
}) {
  return GridWalkable.from(
    this,
    directions: directions,
    weight: weight,
  );
}