Skip to content

Overview

Module Geometry.Grids contains a bunch of functions for working with grid representations. These grids are uniform, meaning all rows have the same number of columns. Much like a spreadsheet.

ixfx’s grids aren’t associated with data or visual representation. It’s a way of working with a logical grid.

The type of a Grid is:

type Grid = Readonly<{
cols: number // Number of columns
rows: number // Number of rows
}>

And continuing the similarity with spreadsheets, each position in the grid is a GridCell, made up of an integer x and y value.

type GridCell = Readonly<{
x: number // Column (starting at 0)
y: number // Row (starting at 0)
}>

Below is a demo to play with some of the grid features.

  • Visit: Traverse through each cell according to some logic
  • Offset: Calculate an offset from a cell position. Includes logic for how to wrap at the grid boundary. In the demo, checking ‘Cardinals’ produces cell position for all cardinal directions.
  • Line: Using a start and end cell, calculate all the cells connecting them in a straight line

Practical uses

Grids are useful for:

In the demo below a grid is used to lay things out on a canvas