Skip to content
FutureBlitz

    Install

    Import std.collections.grid

    std.collections.grid

    Fixed-size 2D and 3D grids of values, read and set by position.

    Grid<T> and Grid3<T>: a fixed number of values in columns and rows, and in layers too, read and set by position, like a map's tiles or a volume's voxels. A position is (x, y), or (x, y, z), each from 0, and one outside the Grid panics where it's used. The cells are in one array, row by row, and layer by layer.

    std/collections/grid.fb

    Types

    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.

    GridIterator struct

    Public Struct GridIterator<T> Implements Iterator<T>

    Goes over a Grid's or a Grid3's cells, which never change in number.

    std/collections/grid.fb, line 125

    • Public ByRef Method Next(): T? method #

      The next cell's value, row by row from (0, 0), or Null after the last.

    Grid3 class

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

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

    Examples

    Local voxels = Grid3<Bool>(4, 4, 4, False)
    voxels[1, 2, 3] = True
    Expect(voxels[1, 2, 3] && !voxels[0, 0, 0])
    Expect(voxels.Neighbors6(0, 0, 0).Count == 3)

    std/collections/grid.fb, line 173

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

      A Grid3 width cells across, height down, and depth deep, 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 Depth: Int property #

      How many cells deep it is.

    • Public Property Count: Int property #

      How many cells it has, Width times Height times Depth.

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

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

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

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

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

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

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

      The positions that share a face with (x, y, z) and are in the Grid3: the layer before, then above, left, right, and below, then the layer after.

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

      The positions around (x, y, z) that are in the Grid3, its edges and corners too, layer by layer and row by row.

    • Public Method Fill(value: T) method #

      Gives every cell the value.

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

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

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

      A new Grid3 with the same size and values.

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

      The values, layer by layer and row by row.

    Extends

    Grid extend

    Extend Grid<T> Implements Equatable

    Compares Grids with == and !=, where their cells can be compared.

    std/collections/grid.fb, line 139

    • Operator ==(a: Grid<T>, b: Grid<T>): Bool operator #

      Whether the two are the same size, with equal values in each cell.

    Grid extend

    Extend Grid<T> Implements Printable

    Shows a Grid in a string, as its ToString writes it.

    std/collections/grid.fb, line 150

    • Public Method ToString(): String method #

      Its rows, from the top, each as an array: "[[1, 2, 3], [4, 5, 6]]".

    Grid3 extend

    Extend Grid3<T> Implements Equatable

    Compares Grid3s with == and !=, where their cells can be compared.

    std/collections/grid.fb, line 309

    • Operator ==(a: Grid3<T>, b: Grid3<T>): Bool operator #

      Whether the two are the same size, with equal values in each cell.

    Grid3 extend

    Extend Grid3<T> Implements Printable

    Shows a Grid3 in a string, as its ToString writes it.

    std/collections/grid.fb, line 322

    • Public Method ToString(): String method #

      Its layers, each its rows as arrays: "[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]".

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