tur/grid
stdlib/grid.tur
typed Grid[A]: 2D row-major grid parameterized over element type A.
Since: Phase TC2-A
defstruct
Grid
(defstruct Grid [A])
parameterized 2D grid with element type A.
Since: Phase TC2
defn
grid-new
(grid-new [width :int height :int])
create a new zero-filled Grid[A].
Parameters
| width | number of columns | |
| height | number of rows |
Returns
A new Grid[A] with all elements initialized to 0.
Example
(grid-new 8 8) ; => 8x8 grid
Since: Phase TC2
defn
grid-get
(grid-get [g :int x :int y :int])
return the element at (x, y).
Parameters
| g | Grid[A] | |
| x | column index | |
| y | row index |
Returns
The element of type A at (x, y).
Example
(grid-get g 0 0) ; => element at (0,0)
Since: Phase TC2
defn
grid-set!
(grid-set! [g :int x :int y :int v :int])
set the element at (x, y).
Parameters
| g | Grid[A] | |
| x | column index | |
| y | row index | |
| v | new element value of type A |
Example
(grid-set! g 0 0 1)
Since: Phase TC2
defn
grid-width
(grid-width [g :int])
return the width of a Grid[A].
Parameters
| g | Grid[A] |
Returns
Width (number of columns).
Example
(grid-width g) ; => 8
Since: Phase TC2
defn
grid-height
(grid-height [g :int])
return the height of a Grid[A].
Parameters
| g | Grid[A] |
Returns
Height (number of rows).
Example
(grid-height g) ; => 8
Since: Phase TC2
defn
grid-free
(grid-free [g :int])
free a Grid[A] and its data buffer.
Parameters
| g | Grid[A] to free |
Example
(grid-free g)
Since: Phase TC2