Skip to content
FutureBlitz

    Install

    Import std.collections.grid

    Grid

    std.collections.grid

    class

    Public Class Grid<T> Implements Iterable<T>, Cloneable

    A rectangle of cells, Width by Height, each a T, indexed as grid[x, y].

    Examples

    Local grid = Grid<Int>(3, 2, 0)
    grid[2, 1] = 5
    Expect(grid[2, 1] == 5 && grid[0, 0] == 0)
    Expect(grid.Count == 6)
    Expect(grid.InBounds(2, 1) && !grid.InBounds(3, 0))
    Expect(grid.Neighbors4(0, 0) == [(1, 0), (0, 1)])

    std/collections/grid.fb, line 23

    • @PanicsAtCaller Public New(width: Int, height: Int, fill: T) constructor #

      A Grid width cells across and height down, each holding fill. A negative size panics, and so does one with more cells than an Int counts.

    • Public Property Width: Int property #

      How many cells wide it is.

    • Public Property Height: Int property #

      How many cells high it is.

    • Public Property Count: Int property #

      How many cells it has, Width times Height.

    • Public Method InBounds(x: Int, y: Int): Bool method #

      Whether (x, y) is one of the Grid's cells.

    • @PanicsAtCaller Operator [](x: Int, y: Int): T operator #

      The value at (x, y). One outside the Grid panics.

    • @PanicsAtCaller Operator []=(x: Int, y: Int, value: T) operator #

      Sets the value at (x, y) to value. One outside the Grid panics.

    • @PanicsAtCaller Public Method Neighbors4(x: Int, y: Int): (Int, Int)[] method #

      The positions beside (x, y) that are in the Grid: above, left, right, and below it.

    • @PanicsAtCaller Public Method Neighbors8(x: Int, y: Int): (Int, Int)[] method #

      The positions around (x, y) that are in the Grid, its corners too, row by row.

    • Public Method Fill(value: T) method #

      Gives every cell the value.

    • Public Method ToArray(): T[] method #

      The values, row by row, in a new array.

    • Public Method Clone(): Grid<T> method #

      A new Grid with the same size and values.

    • Public Method Iterate(): GridIterator<T> method #

      The values, row by row.

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