Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@thi.ng/grid-iterators

0.4.10 • Public • Published

grid-iterators

npm version npm downloads Twitter Follow

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

anim

Source

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

Diagonal

anim

Source

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

Hilbert curve

anim

Source

Interleave columns

anim

Source

Supports custom strides... example uses step = 4

Interleave rows

anim

Source

Supports custom strides... example uses step = 4

Random

anim

Source

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

Rows

anim

Source

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

Outward spiral

anim

Source

Z-curve

anim

Source

Zigzag columns

anim

Source

Zigzag diagonal

anim

Source

Zigzag rows

anim

Source

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

Related packages

  • @thi.ng/morton - Z-order curve / Morton encoding, decoding & range extraction for arbitrary dimensions

Installation

yarn add @thi.ng/grid-iterators
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/grid-iterators?module" crossorigin></script>
 
// UMD
<script src="https://unpkg.com/@thi.ng/grid-iterators/lib/index.umd.js" crossorigin></script>

Package sizes (gzipped, pre-treeshake): ESM: 1.41 KB / CJS: 1.53 KB / UMD: 1.58 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

Generated API docs

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

License

© 2019 - 2020 Karsten Schmidt // Apache Software License 2.0

Install

npm i @thi.ng/grid-iterators

DownloadsWeekly Downloads

130

Version

0.4.10

License

Apache-2.0

Unpacked Size

84 kB

Total Files

46

Last publish

Collaborators

  • avatar