GridWalkable<E>.from constructor

GridWalkable<E>.from(
  1. Grid<E> grid, {
  2. double weight(
    1. E,
    2. E,
    3. Pos
    ) = _defaultWeight,
  3. Iterable<Pos> directions = Direction.cardinal,
})

Creates a new lazily built weighted graph from a grid.

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.

The directions are the relative positions of the neighbors to connect each node to. By default, the Direction.cardinal directions are used, which is the four cardinal directions (north, east, south, west).

Implementation

factory GridWalkable.from(
  Grid<E> grid, {
  double Function(E, E, Pos) weight = _defaultWeight,
  Iterable<Pos> directions = Direction.cardinal,
}) {
  final list = identical(directions, Direction.cardinal)
      ? Direction.cardinal
      : List.of(directions);
  return GridWalkable._(
    grid,
    list,
    weight,
  );
}