2.0.0-beta.1 • Published 6 years ago

hilbert-curve v2.0.0-beta.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Hilbert curve mapping

Installation

npm install hilbert-curve

Usage

Node:

const hilbertCurve = require("hilbert-curve");

// or

import * as hilbertCurve from "hilbert-curve";

Browser:

<!-- unpkg -->
<script src="https://unpkg.com/hilbert-curve"></script>

<!-- jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/hilbert-curve"></script>

Hilbert Curve Numbering

hilbertCurve.indexToPoint(i, o)

Given an index i, return the point on the Hilbert curve of order o (the length of the entire curve being 2^o * 2^o), e.g.

// order is 3, i.e. curve is defined on a 2^3 * 2^3 = 8 * 8 square
hilbertCurve.indexToPoint(17, 3);
// { x: 1, y: 4 }

hilbertCurve.pointToIndex({x, y}, o)

Inverse: given a point {x,y} on the Hilbert curve of order o, return the index, e.g.

hilbertCurve.pointToIndex({ x: 5, y: 2 }, 3);
// 55

hilbertCurve.construct(data, o)

Construct the Hilbert curve of order o from data, e.g.

// data is `[1, 2, 3, ..., 14, 15, 16]`
const data = Array.from({ length: 4 * 4 }, (_, i) => i + 1);
hilbertCurve.construct(data, 2);
// [1, 2, 15, 16, 4, 3, 14, 13, 5, 8, 9, 12, 6, 7, 10, 11]

Try hilbert-curve in your browser.

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago