Package Exports
- @thi.ng/grid-iterators
- @thi.ng/grid-iterators/circle
- @thi.ng/grid-iterators/column-ends
- @thi.ng/grid-iterators/columns
- @thi.ng/grid-iterators/diagonal
- @thi.ng/grid-iterators/diagonal-ends
- @thi.ng/grid-iterators/hilbert
- @thi.ng/grid-iterators/hvline
- @thi.ng/grid-iterators/interleave
- @thi.ng/grid-iterators/line
- @thi.ng/grid-iterators/random
- @thi.ng/grid-iterators/row-ends
- @thi.ng/grid-iterators/rows
- @thi.ng/grid-iterators/spiral
- @thi.ng/grid-iterators/zcurve
- @thi.ng/grid-iterators/zigzag-columns
- @thi.ng/grid-iterators/zigzag-diagonal
- @thi.ng/grid-iterators/zigzag-rows
Readme
This project is part of the @thi.ng/umbrella monorepo.
About
2D grid iterators w/ multiple orderings.
Provides the 15 following orderings to generate grid coordinates and additional iterators for shape rasterization:
Columns

Also see the filtered version
columnEnds2d(),
which only includes the end points of each column.
Diagonal

Also see the filtered version
diagonalEnds2d(),
which only includes the end points of the diagonals.
Hilbert curve

Interleave columns

Supports custom strides... example uses step = 4
Interleave rows

Supports custom strides... example uses step = 4
Random

Supports custom PRNG implementations via IRandom interface defined in
@thi.ng/random
Rows

Also see the filtered version
rowEnds2d(),
which only includes the end points of each row.
Outward spiral

Z-curve

Zigzag columns

Zigzag diagonal

Zigzag rows

Some functions have been ported from Christopher Kulla's Java-based Sunflow renderer.
For more basic 2D/3D grid iteration, also see range2d() & range3d()
in
@thi.ng/transducers.
Miscellaneous
Additionally, the following shape iterators are available:
Status
STABLE - used in production
Search or submit any issues for this package
Related packages
- @thi.ng/morton - Z-order curve / Morton encoding, decoding & range extraction for arbitrary dimensions
- @thi.ng/transducers - Lightweight transducer implementations for ES6 / TypeScript
Installation
yarn add @thi.ng/grid-iteratorsES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/grid-iterators"></script>For Node.js REPL:
# with flag only for < v16
node --experimental-repl-await
> const gridIterators = await import("@thi.ng/grid-iterators");Package sizes (gzipped, pre-treeshake): ESM: 1.50 KB
Dependencies
Usage examples
Several demos in this repo's /examples directory are using this package.
A selection:
| Screenshot | Description | Live demo | Source |
|---|---|---|---|
![]() |
Visualization of different grid iterator strategies | Demo | Source |
API
import * as gi from "@thi.ng/grid-iterators";
[...gi.zigzagRows2d(4, 4)]
// [
// [ 0, 0 ], [ 1, 0 ], [ 2, 0 ], [ 3, 0 ],
// [ 3, 1 ], [ 2, 1 ], [ 1, 1 ], [ 0, 1 ],
// [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ],
// [ 3, 3 ], [ 2, 3 ], [ 1, 3 ], [ 0, 3 ]
// ]Authors
Karsten Schmidt
If this project contributes to an academic publication, please cite it as:
@misc{thing-grid-iterators,
title = "@thi.ng/grid-iterators",
author = "Karsten Schmidt",
note = "https://thi.ng/grid-iterators",
year = 2019
}License
© 2019 - 2021 Karsten Schmidt // Apache Software License 2.0
