Calculates a legal position for a cell based on
grid
size and bounds
wrapping logic.
Generator that returns rectangles for each cell in a grid
Returns the cell at a specified visual coordinate or undefined if the position is outside of the grid.
Returns true if two cells equal. Returns false if either cell are undefined
Returns x,y from an array index.
Returns a key string for a cell instance A key string allows comparison of instances by value rather than reference
Returns the visual midpoint of a cell (eg. pixel coordinate)
Returns the cells on the line of start
and end
, inclusive
Returns an { x, y }
signed vector corresponding to the provided cardinal direction.
Throws an exception if any of the grid's parameters are invalid
Returns the index for a given cell. This is useful if a grid is stored in an array.
Returns true if cell coordinates are above zero and within bounds of grid
Returns true if cell
parameter is a cell with x,y fields.
Does not check validity of fields.
Returns true if grids a
and b
are equal in value.
Returns false if either parameter is undefined.
Gets a list of neighbours for cell
(using neighbours), filtering
results to only those that are valid neighbours (using isNeighbour)
Returns neighbours for a cell. If no directions
are provided, it defaults to allDirections.
Returns a coordinate offset from start
by vector
amount.
Returns cells that correspond to the cardinal directions at a specified distance
i.e. it projects a line from start
cell in all cardinal directions and returns the cells at steps
distance.
Returns a visual rectangle of the cell, positioned from the top-left corner
Returns a list of cells from start
to end
.
Converts an 1D or 2D array of cell coordinates into values
Bounds logic
A function that returns a value (or undefined) based on a cell
A function that sets the value of a cell.
Identify neighbours logic. For a given grid
and origin
, return a list of neighbours
Logic to select the next cell based on a list of neighbours
Neighbour selector logic. For a given set of neighbours
pick one to visit next.
Shape of a grid and a function to read values from it, based on cell location.
Returns a list of all cardinal directions: n, ne, nw, e, s, se, sw, w
Returns a list of + shaped directions: n, e, s, w
Iterates over slices of the grid (eg a whole row, a whole column)