Skip to content
FutureBlitz

    Install

    Import std.algo.grid

    FlowField

    std.algo.grid

    class

    Public Class FlowField

    A flow field over a grid: each cell's cheapest way to the nearest of its goals, worked out once from the goals outward, so any number of agents follow it with no search of their own. Entering a cell costs what cost gives for it, and a cell it gives Null for is a wall that no path goes through; a step along an axis costs that, and a diagonal one the square root of 2 times it.

    Examples

    // Every cell costs 1 to enter, and the goal is the top left corner.
    Local field = FlowField(4, 4, [Vec2i(0, 0)], Function(cell: Vec2i): Double? => 1.0)
    Expect(field.Distance(Vec2i(3, 0)) == 3.0)
    Expect(field.Next(Vec2i(3, 0)) == Vec2i(2, 0))
    Expect(field.Next(Vec2i(0, 0)) == Null)

    std/algo/grid.fb, line 139

    • @PanicsAtCaller Public New(width: Int, height: Int, goals: Vec2i[], cost: Func(Vec2i): Double?, diagonal: Bool = False) constructor #

      A flow field over a grid of width by height to the goals, through the cells cost gives a cost for, along the axes, or diagonally too. A goal that cost gives Null for isn't one. A negative size, a goal off the grid, or a cost that's negative or NaN panics.

    • Public Property Width: Int property #

      How many cells wide its grid is.

    • Public Property Height: Int property #

      How many cells high its grid is.

    • @PanicsAtCaller Public Method Reaches(cell: Vec2i): Bool method #

      Whether the cell has a way to a goal, the goals included. A cell off the grid panics.

    • @PanicsAtCaller Public Method Distance(cell: Vec2i): Double? method #

      The cost from the cell to its nearest goal, 0 at a goal, or Null where it has no way to one. A cell off the grid panics.

    • @PanicsAtCaller Public Method Next(cell: Vec2i): Vec2i? method #

      The cell to step to from this one on its cheapest way to a goal, or Null at a goal or where there's no way to one. A cell off the grid panics.

    • @PanicsAtCaller Public Method Direction(cell: Vec2i): Vec2 method #

      Which way to go from the cell, of length 1, toward its next cell: the zero vector at a goal or where there's no way to one. A cell off the grid panics.

    Report an issue with this page or with FutureBlitz on GitHub.