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
-
A Grid
widthcells across andheightdown, each holdingfill. A negative size panics, and so does one with more cells than an Int counts. -
How many cells wide it is.
-
How many cells high it is.
-
How many cells it has, Width times Height.
-
Whether (
x,y) is one of the Grid's cells. -
The value at (
x,y). One outside the Grid panics. -
Sets the value at (
x,y) tovalue. One outside the Grid panics. -
The positions beside (
x,y) that are in the Grid: above, left, right, and below it. -
The positions around (
x,y) that are in the Grid, its corners too, row by row. -
Gives every cell the
value. -
The values, row by row, in a new array.
-
A new Grid with the same size and values.
-
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
-
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
-
A Grid3
widthcells across,heightdown, anddepthdeep, each holdingfill. A negative size panics, and so does one with more cells than an Int counts. -
How many cells wide it is.
-
How many cells high it is.
-
How many cells deep it is.
-
How many cells it has, Width times Height times Depth.
-
Whether (
x,y,z) is one of the Grid3's cells. -
The value at (
x,y,z). One outside the Grid3 panics. -
Sets the value at (
x,y,z) tovalue. One outside the Grid3 panics. -
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. -
The positions around (
x,y,z) that are in the Grid3, its edges and corners too, layer by layer and row by row. -
Gives every cell the
value. -
The values, layer by layer and row by row, in a new array.
-
A new Grid3 with the same size and values.
-
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
-
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
-
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
-
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
-
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.