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
Section titled “Practical uses”Grids are useful for:
- Image processing & generation (see Module Visual.ImageDataGrid )
- Wayfinding for agents in games
- Flow-field simulations
- …and much else.
Note that many practical uses of grids don’t actually show or work with a grid visually. Rather, it’s the logical, spatial arrangement of data that is helpful in some situations.
In the demo below a grid is used to lay things out on a canvas
Importing
Section titled “Importing”// Sub moduleimport { Grids } from "@ixfx/geometry.js"// Eg: Grids.offset();
// Whole moduleimport * as Geometry from "@ixfx/geometry.js"// Eg: Geometry.Grids.offset();
// From bundleimport { Geometry } from "@ixfx"// Eg: Geometry.Grids.offset();
// And within your HTML's <HEAD> </HEAD> block:<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>
// Sub module from parentimport { Grids } from "@ixfx/geometry.js"// Eg: Grids.offset();
// Whole parent moduleimport * as Geometry from "@ixfx/geometry.js"// Eg: Geometry.Grids.offset();
// From the bundleimport { Geometry } from "@ixfx/bundle.js"// Eg: Geometry.Grids.offset();
// Sub module from parentimport { Grids } from "https://unpkg.com/@ixfx/geometry/bundle"// Eg: Grids.offset();
// Whole parent moduleimport * as Geometry from "https://unpkg.com/@ixfx/geometry/bundle"// Eg: Geometry.Grids.offset();
// Single module from the bundleimport { Geometry } from "https://unpkg.com/@ixfx/bundle"// Eg: Geometry.Grids.offset();