@cult-frog/noise 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +205 -2
- package/dist/fractal/_types/fractalOptions.d.ts +36 -0
- package/dist/fractal/_types/fractalOptions.d.ts.map +1 -0
- package/dist/fractal/_types/fractalOptions.js +2 -0
- package/dist/fractal/_types/fractalOptions.js.map +1 -0
- package/dist/fractal/_types/index.d.ts +2 -0
- package/dist/fractal/_types/index.d.ts.map +1 -0
- package/dist/fractal/_types/index.js +2 -0
- package/dist/fractal/_types/index.js.map +1 -0
- package/dist/fractal/fractal.d.ts +17 -0
- package/dist/fractal/fractal.d.ts.map +1 -0
- package/dist/fractal/fractal.js +31 -0
- package/dist/fractal/fractal.js.map +1 -0
- package/dist/fractal/index.d.ts +4 -0
- package/dist/fractal/index.d.ts.map +1 -0
- package/dist/fractal/index.js +3 -0
- package/dist/fractal/index.js.map +1 -0
- package/dist/fractal/options.d.ts +14 -0
- package/dist/fractal/options.d.ts.map +1 -0
- package/dist/fractal/options.js +57 -0
- package/dist/fractal/options.js.map +1 -0
- package/dist/gradient/cubeEdge3.d.ts +11 -0
- package/dist/gradient/cubeEdge3.d.ts.map +1 -0
- package/dist/gradient/cubeEdge3.js +39 -0
- package/dist/gradient/cubeEdge3.js.map +1 -0
- package/dist/gradient/index.d.ts +2 -0
- package/dist/gradient/index.d.ts.map +1 -0
- package/dist/gradient/index.js +2 -0
- package/dist/gradient/index.js.map +1 -0
- package/dist/hashes/hash.d.ts +16 -0
- package/dist/hashes/hash.d.ts.map +1 -0
- package/dist/hashes/hash.js +37 -0
- package/dist/hashes/hash.js.map +1 -0
- package/dist/hashes/hashes.d.ts +3 -0
- package/dist/hashes/hashes.d.ts.map +1 -0
- package/dist/hashes/hashes.js +3 -0
- package/dist/hashes/hashes.js.map +1 -0
- package/dist/hashes/index.d.ts +2 -0
- package/dist/hashes/index.d.ts.map +1 -0
- package/dist/hashes/index.js +2 -0
- package/dist/hashes/index.js.map +1 -0
- package/dist/hashes/lowbias.d.ts +12 -0
- package/dist/hashes/lowbias.d.ts.map +1 -0
- package/dist/hashes/lowbias.js +19 -0
- package/dist/hashes/lowbias.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/noiseMap/_types/index.d.ts +3 -0
- package/dist/noiseMap/_types/index.d.ts.map +1 -0
- package/dist/noiseMap/_types/index.js +2 -0
- package/dist/noiseMap/_types/index.js.map +1 -0
- package/dist/noiseMap/_types/noise2d.d.ts +21 -0
- package/dist/noiseMap/_types/noise2d.d.ts.map +1 -0
- package/dist/noiseMap/_types/noise2d.js +2 -0
- package/dist/noiseMap/_types/noise2d.js.map +1 -0
- package/dist/noiseMap/_types/noise3d.d.ts +24 -0
- package/dist/noiseMap/_types/noise3d.d.ts.map +1 -0
- package/dist/noiseMap/_types/noise3d.js +2 -0
- package/dist/noiseMap/_types/noise3d.js.map +1 -0
- package/dist/noiseMap/index.d.ts +6 -0
- package/dist/noiseMap/index.d.ts.map +1 -0
- package/dist/noiseMap/index.js +3 -0
- package/dist/noiseMap/index.js.map +1 -0
- package/dist/noiseMap/noise2d.d.ts +52 -0
- package/dist/noiseMap/noise2d.d.ts.map +1 -0
- package/dist/noiseMap/noise2d.js +105 -0
- package/dist/noiseMap/noise2d.js.map +1 -0
- package/dist/noiseMap/noise3d.d.ts +62 -0
- package/dist/noiseMap/noise3d.d.ts.map +1 -0
- package/dist/noiseMap/noise3d.js +129 -0
- package/dist/noiseMap/noise3d.js.map +1 -0
- package/dist/noiseTypes/cellular/2d.d.ts +36 -0
- package/dist/noiseTypes/cellular/2d.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/2d.js +123 -0
- package/dist/noiseTypes/cellular/2d.js.map +1 -0
- package/dist/noiseTypes/cellular/3d.d.ts +32 -0
- package/dist/noiseTypes/cellular/3d.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/3d.js +143 -0
- package/dist/noiseTypes/cellular/3d.js.map +1 -0
- package/dist/noiseTypes/cellular/_types/index.d.ts +2 -0
- package/dist/noiseTypes/cellular/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/_types/index.js +2 -0
- package/dist/noiseTypes/cellular/_types/index.js.map +1 -0
- package/dist/noiseTypes/cellular/_types/options.d.ts +37 -0
- package/dist/noiseTypes/cellular/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/_types/options.js +2 -0
- package/dist/noiseTypes/cellular/_types/options.js.map +1 -0
- package/dist/noiseTypes/cellular/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/cellular/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/defaultOptions.js +13 -0
- package/dist/noiseTypes/cellular/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/cellular/floorDiv.d.ts +18 -0
- package/dist/noiseTypes/cellular/floorDiv.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/floorDiv.js +28 -0
- package/dist/noiseTypes/cellular/floorDiv.js.map +1 -0
- package/dist/noiseTypes/cellular/index.d.ts +4 -0
- package/dist/noiseTypes/cellular/index.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/index.js +3 -0
- package/dist/noiseTypes/cellular/index.js.map +1 -0
- package/dist/noiseTypes/cellular/options.d.ts +6 -0
- package/dist/noiseTypes/cellular/options.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/options.js +20 -0
- package/dist/noiseTypes/cellular/options.js.map +1 -0
- package/dist/noiseTypes/index.d.ts +5 -0
- package/dist/noiseTypes/index.d.ts.map +1 -0
- package/dist/noiseTypes/index.js +5 -0
- package/dist/noiseTypes/index.js.map +1 -0
- package/dist/noiseTypes/perlin/2d.d.ts +23 -0
- package/dist/noiseTypes/perlin/2d.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/2d.js +64 -0
- package/dist/noiseTypes/perlin/2d.js.map +1 -0
- package/dist/noiseTypes/perlin/3d.d.ts +24 -0
- package/dist/noiseTypes/perlin/3d.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/3d.js +69 -0
- package/dist/noiseTypes/perlin/3d.js.map +1 -0
- package/dist/noiseTypes/perlin/_types/index.d.ts +2 -0
- package/dist/noiseTypes/perlin/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/_types/index.js +2 -0
- package/dist/noiseTypes/perlin/_types/index.js.map +1 -0
- package/dist/noiseTypes/perlin/_types/options.d.ts +22 -0
- package/dist/noiseTypes/perlin/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/_types/options.js +2 -0
- package/dist/noiseTypes/perlin/_types/options.js.map +1 -0
- package/dist/noiseTypes/perlin/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/perlin/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/defaultOptions.js +14 -0
- package/dist/noiseTypes/perlin/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/perlin/index.d.ts +4 -0
- package/dist/noiseTypes/perlin/index.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/index.js +3 -0
- package/dist/noiseTypes/perlin/index.js.map +1 -0
- package/dist/noiseTypes/perlin/options.d.ts +9 -0
- package/dist/noiseTypes/perlin/options.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/options.js +17 -0
- package/dist/noiseTypes/perlin/options.js.map +1 -0
- package/dist/noiseTypes/perlin/sample2.d.ts +25 -0
- package/dist/noiseTypes/perlin/sample2.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/sample2.js +58 -0
- package/dist/noiseTypes/perlin/sample2.js.map +1 -0
- package/dist/noiseTypes/perlin/sample3.d.ts +9 -0
- package/dist/noiseTypes/perlin/sample3.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/sample3.js +38 -0
- package/dist/noiseTypes/perlin/sample3.js.map +1 -0
- package/dist/noiseTypes/simplex/2d.d.ts +23 -0
- package/dist/noiseTypes/simplex/2d.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/2d.js +64 -0
- package/dist/noiseTypes/simplex/2d.js.map +1 -0
- package/dist/noiseTypes/simplex/3d.d.ts +25 -0
- package/dist/noiseTypes/simplex/3d.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/3d.js +70 -0
- package/dist/noiseTypes/simplex/3d.js.map +1 -0
- package/dist/noiseTypes/simplex/_types/index.d.ts +2 -0
- package/dist/noiseTypes/simplex/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/_types/index.js +2 -0
- package/dist/noiseTypes/simplex/_types/index.js.map +1 -0
- package/dist/noiseTypes/simplex/_types/options.d.ts +33 -0
- package/dist/noiseTypes/simplex/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/_types/options.js +2 -0
- package/dist/noiseTypes/simplex/_types/options.js.map +1 -0
- package/dist/noiseTypes/simplex/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/simplex/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/defaultOptions.js +14 -0
- package/dist/noiseTypes/simplex/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/simplex/index.d.ts +4 -0
- package/dist/noiseTypes/simplex/index.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/index.js +3 -0
- package/dist/noiseTypes/simplex/index.js.map +1 -0
- package/dist/noiseTypes/simplex/options.d.ts +9 -0
- package/dist/noiseTypes/simplex/options.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/options.js +17 -0
- package/dist/noiseTypes/simplex/options.js.map +1 -0
- package/dist/noiseTypes/simplex/sample2.d.ts +32 -0
- package/dist/noiseTypes/simplex/sample2.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/sample2.js +94 -0
- package/dist/noiseTypes/simplex/sample2.js.map +1 -0
- package/dist/noiseTypes/simplex/sample3.d.ts +19 -0
- package/dist/noiseTypes/simplex/sample3.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/sample3.js +110 -0
- package/dist/noiseTypes/simplex/sample3.js.map +1 -0
- package/dist/noiseTypes/white/2d.d.ts +18 -0
- package/dist/noiseTypes/white/2d.d.ts.map +1 -0
- package/dist/noiseTypes/white/2d.js +33 -0
- package/dist/noiseTypes/white/2d.js.map +1 -0
- package/dist/noiseTypes/white/3d.d.ts +17 -0
- package/dist/noiseTypes/white/3d.d.ts.map +1 -0
- package/dist/noiseTypes/white/3d.js +34 -0
- package/dist/noiseTypes/white/3d.js.map +1 -0
- package/dist/noiseTypes/white/_types/index.d.ts +2 -0
- package/dist/noiseTypes/white/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/white/_types/index.js +2 -0
- package/dist/noiseTypes/white/_types/index.js.map +1 -0
- package/dist/noiseTypes/white/_types/options.d.ts +28 -0
- package/dist/noiseTypes/white/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/white/_types/options.js +2 -0
- package/dist/noiseTypes/white/_types/options.js.map +1 -0
- package/dist/noiseTypes/white/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/white/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/white/defaultOptions.js +10 -0
- package/dist/noiseTypes/white/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/white/index.d.ts +4 -0
- package/dist/noiseTypes/white/index.d.ts.map +1 -0
- package/dist/noiseTypes/white/index.js +3 -0
- package/dist/noiseTypes/white/index.js.map +1 -0
- package/dist/noiseTypes/white/options.d.ts +6 -0
- package/dist/noiseTypes/white/options.d.ts.map +1 -0
- package/dist/noiseTypes/white/options.js +14 -0
- package/dist/noiseTypes/white/options.js.map +1 -0
- package/package.json +78 -4
- package/src/fractal/_types/fractalOptions.ts +35 -0
- package/src/fractal/_types/index.ts +1 -0
- package/src/fractal/fractal.ts +41 -0
- package/src/fractal/index.ts +4 -0
- package/src/fractal/options.ts +62 -0
- package/src/gradient/cubeEdge3.ts +47 -0
- package/src/gradient/index.ts +1 -0
- package/src/hashes/hash.ts +41 -0
- package/src/hashes/hashes.ts +2 -0
- package/src/hashes/index.ts +1 -0
- package/src/hashes/lowbias.ts +18 -0
- package/src/index.ts +4 -0
- package/src/noiseMap/_types/index.ts +2 -0
- package/src/noiseMap/_types/noise2d.ts +21 -0
- package/src/noiseMap/_types/noise3d.ts +24 -0
- package/src/noiseMap/index.ts +7 -0
- package/src/noiseMap/noise2d.ts +117 -0
- package/src/noiseMap/noise3d.ts +146 -0
- package/src/noiseTypes/cellular/2d.ts +142 -0
- package/src/noiseTypes/cellular/3d.ts +171 -0
- package/src/noiseTypes/cellular/_types/index.ts +1 -0
- package/src/noiseTypes/cellular/_types/options.ts +37 -0
- package/src/noiseTypes/cellular/defaultOptions.ts +15 -0
- package/src/noiseTypes/cellular/floorDiv.ts +27 -0
- package/src/noiseTypes/cellular/index.ts +4 -0
- package/src/noiseTypes/cellular/options.ts +20 -0
- package/src/noiseTypes/index.ts +4 -0
- package/src/noiseTypes/perlin/2d.ts +86 -0
- package/src/noiseTypes/perlin/3d.ts +93 -0
- package/src/noiseTypes/perlin/_types/index.ts +1 -0
- package/src/noiseTypes/perlin/_types/options.ts +23 -0
- package/src/noiseTypes/perlin/defaultOptions.ts +16 -0
- package/src/noiseTypes/perlin/index.ts +4 -0
- package/src/noiseTypes/perlin/options.ts +19 -0
- package/src/noiseTypes/perlin/sample2.ts +62 -0
- package/src/noiseTypes/perlin/sample3.ts +43 -0
- package/src/noiseTypes/simplex/2d.ts +86 -0
- package/src/noiseTypes/simplex/3d.ts +94 -0
- package/src/noiseTypes/simplex/_types/index.ts +1 -0
- package/src/noiseTypes/simplex/_types/options.ts +34 -0
- package/src/noiseTypes/simplex/defaultOptions.ts +16 -0
- package/src/noiseTypes/simplex/index.ts +4 -0
- package/src/noiseTypes/simplex/options.ts +19 -0
- package/src/noiseTypes/simplex/sample2.ts +103 -0
- package/src/noiseTypes/simplex/sample3.ts +128 -0
- package/src/noiseTypes/white/2d.ts +44 -0
- package/src/noiseTypes/white/3d.ts +46 -0
- package/src/noiseTypes/white/_types/index.ts +1 -0
- package/src/noiseTypes/white/_types/options.ts +28 -0
- package/src/noiseTypes/white/defaultOptions.ts +12 -0
- package/src/noiseTypes/white/index.ts +4 -0
- package/src/noiseTypes/white/options.ts +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src/hashes/hashes.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hashes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hashes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrambles a 32-bit integer so that flipping any input bit flips about half
|
|
3
|
+
* the output bits, returned unsigned. This is Chris Wellons' `lowbias32`
|
|
4
|
+
* (hash-prospector), found by search for low bias. It is a bijection, so
|
|
5
|
+
* distinct inputs never collide, and 0 maps to 0.
|
|
6
|
+
*
|
|
7
|
+
* Used both inside {@link hash2}/{@link hash3} and on its own to draw further
|
|
8
|
+
* independent values from one hash, as cellular noise does for each point's
|
|
9
|
+
* x, y and z.
|
|
10
|
+
*/
|
|
11
|
+
export declare function lowbias32(h: number): number;
|
|
12
|
+
//# sourceMappingURL=lowbias.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowbias.d.ts","sourceRoot":"","sources":["../../src/hashes/lowbias.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAO3C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrambles a 32-bit integer so that flipping any input bit flips about half
|
|
3
|
+
* the output bits, returned unsigned. This is Chris Wellons' `lowbias32`
|
|
4
|
+
* (hash-prospector), found by search for low bias. It is a bijection, so
|
|
5
|
+
* distinct inputs never collide, and 0 maps to 0.
|
|
6
|
+
*
|
|
7
|
+
* Used both inside {@link hash2}/{@link hash3} and on its own to draw further
|
|
8
|
+
* independent values from one hash, as cellular noise does for each point's
|
|
9
|
+
* x, y and z.
|
|
10
|
+
*/
|
|
11
|
+
export function lowbias32(h) {
|
|
12
|
+
h ^= h >>> 16;
|
|
13
|
+
h = Math.imul(h, 0x7feb352d);
|
|
14
|
+
h ^= h >>> 15;
|
|
15
|
+
h = Math.imul(h, 0x846ca68b);
|
|
16
|
+
h ^= h >>> 16;
|
|
17
|
+
return h >>> 0;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=lowbias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowbias.js","sourceRoot":"","sources":["../../src/hashes/lowbias.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC7B,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC7B,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/noiseMap/_types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/noiseMap/_types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Brand } from '@cult-frog/types';
|
|
2
|
+
/**
|
|
3
|
+
* A 2D noise map: one `Float32Array` holding a two-number header, then every
|
|
4
|
+
* cell's value in row-major order (x fastest).
|
|
5
|
+
*
|
|
6
|
+
* @example [width, height, value, value, value, value, ...]
|
|
7
|
+
*
|
|
8
|
+
* It is a plain typed array, so it can be posted to a worker, transferred, or
|
|
9
|
+
* uploaded without copying. The brand stops an arbitrary `Float32Array` being
|
|
10
|
+
* passed where a map is expected; make maps with `Noise2D.create` or a
|
|
11
|
+
* generator. Never write to the header: every helper reads the size from it, so
|
|
12
|
+
* changing it makes `get`, `set` and `forEach` index the wrong cells. Use
|
|
13
|
+
* `Noise2D.getValues` for a view of the cells alone.
|
|
14
|
+
*/
|
|
15
|
+
export type Noise2D = Brand<Float32Array, 'Noise2D'> & {
|
|
16
|
+
/** Width in cells. Part of the header: read-only by contract. */
|
|
17
|
+
0: number;
|
|
18
|
+
/** Height in cells. Part of the header: read-only by contract. */
|
|
19
|
+
1: number;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=noise2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise2d.d.ts","sourceRoot":"","sources":["../../../src/noiseMap/_types/noise2d.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG;IACrD,iEAAiE;IACjE,CAAC,EAAE,MAAM,CAAC;IACV,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise2d.js","sourceRoot":"","sources":["../../../src/noiseMap/_types/noise2d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Brand } from '@cult-frog/types';
|
|
2
|
+
/**
|
|
3
|
+
* A 3D noise map: one `Float32Array` holding a three-number header, then every
|
|
4
|
+
* cell's value with x varying fastest, then y, then z, so each z layer is one
|
|
5
|
+
* contiguous 2D slice.
|
|
6
|
+
*
|
|
7
|
+
* @example [width, height, depth, value, value, value, value, value, value, ...]
|
|
8
|
+
*
|
|
9
|
+
* It is a plain typed array, so it can be posted to a worker, transferred, or
|
|
10
|
+
* uploaded without copying. The brand stops an arbitrary `Float32Array` being
|
|
11
|
+
* passed where a map is expected; make maps with `Noise3D.create` or a
|
|
12
|
+
* generator. Never write to the header: every helper reads the size from it, so
|
|
13
|
+
* changing it makes `get`, `set` and `forEach` index the wrong cells. Use
|
|
14
|
+
* `Noise3D.getValues` for a view of the cells alone.
|
|
15
|
+
*/
|
|
16
|
+
export type Noise3D = Brand<Float32Array, 'Noise3D'> & {
|
|
17
|
+
/** Width in cells. Part of the header: read-only by contract. */
|
|
18
|
+
0: number;
|
|
19
|
+
/** Height in cells. Part of the header: read-only by contract. */
|
|
20
|
+
1: number;
|
|
21
|
+
/** Depth in cells. Part of the header: read-only by contract. */
|
|
22
|
+
2: number;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=noise3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise3d.d.ts","sourceRoot":"","sources":["../../../src/noiseMap/_types/noise3d.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG;IACrD,iEAAiE;IACjE,CAAC,EAAE,MAAM,CAAC;IACV,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;IACV,iEAAiE;IACjE,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise3d.js","sourceRoot":"","sources":["../../../src/noiseMap/_types/noise3d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as Noise2D from './noise2d.js';
|
|
2
|
+
export * as Noise3D from './noise3d.js';
|
|
3
|
+
import type { Noise2D as Noise2DType, Noise3D as Noise3DType } from './_types/index.js';
|
|
4
|
+
export type Noise2D = Noise2DType;
|
|
5
|
+
export type Noise3D = Noise3DType;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/noiseMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAExF,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC;AAClC,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/noiseMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Noise2D } from './_types/noise2d.js';
|
|
2
|
+
/**
|
|
3
|
+
* Allocates a zero-filled `width` × `height` map. The caller owns it; every
|
|
4
|
+
* generator returns a map made here and keeps no reference to it.
|
|
5
|
+
*
|
|
6
|
+
* Throws a `RangeError` unless both sizes are positive integers. The sizes are
|
|
7
|
+
* stored in the map's Float32 header, which holds integers exactly only up to
|
|
8
|
+
* 2^24, so larger sizes are not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare function create(width: number, height: number): Noise2D;
|
|
11
|
+
/** Number of columns, read from the map's header. */
|
|
12
|
+
export declare function width(noise: Noise2D): number;
|
|
13
|
+
/** Number of rows, read from the map's header. */
|
|
14
|
+
export declare function height(noise: Noise2D): number;
|
|
15
|
+
/**
|
|
16
|
+
* The map's cells as a row-major view over the same buffer, without the header:
|
|
17
|
+
* cell (x, y) is at `y * width + x`. Writes through it change the map, and it
|
|
18
|
+
* stays valid as long as the map does. There are no bounds checks, unlike
|
|
19
|
+
* `get`/`set`, so it suits whole-map passes whose loops already stay in range.
|
|
20
|
+
* Each call allocates a small view object, so take it once per pass, not per cell.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getValues(noise: Noise2D): Float32Array;
|
|
23
|
+
/**
|
|
24
|
+
* Writes `value` to cell (`x`, `y`), rounded to Float32 like every map value.
|
|
25
|
+
* Throws a `RangeError` unless both coordinates are integers inside the map.
|
|
26
|
+
* The check runs on every call; for whole-map passes use {@link getValues}.
|
|
27
|
+
*/
|
|
28
|
+
export declare function set(noise: Noise2D, x: number, y: number, value: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Reads cell (`x`, `y`). Throws a `RangeError` unless both coordinates are
|
|
31
|
+
* integers inside the map. The check runs on every call; for whole-map passes
|
|
32
|
+
* use {@link getValues}.
|
|
33
|
+
*/
|
|
34
|
+
export declare function get(noise: Noise2D, x: number, y: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Calls `callback` once per cell in row-major order (x fastest), with the
|
|
37
|
+
* cell's value and coordinates. Writing to the map from the callback is safe:
|
|
38
|
+
* each value is read just before its call. Each read is bounds-checked like
|
|
39
|
+
* {@link get}, so hot loops should use {@link getValues} instead.
|
|
40
|
+
*/
|
|
41
|
+
export declare function forEach(noise: Noise2D, callback: (value: number, x: number, y: number) => void): void;
|
|
42
|
+
/**
|
|
43
|
+
* A new greyscale RGBA image of the map: 4 bytes per cell in row-major order,
|
|
44
|
+
* with each channel set to `value * 255` truncated and alpha 255.
|
|
45
|
+
*
|
|
46
|
+
* Expects values in [0, 1], which every generator produces. Values outside it
|
|
47
|
+
* wrap around rather than clamp (1.5 becomes 126, not 255), because `Uint8Array`
|
|
48
|
+
* stores numbers modulo 256. For `ImageData`, wrap the result's bytes in a
|
|
49
|
+
* `Uint8ClampedArray`; no copy is needed.
|
|
50
|
+
*/
|
|
51
|
+
export declare function toPixelBuffer(noise: Noise2D): Uint8Array;
|
|
52
|
+
//# sourceMappingURL=noise2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise2d.d.ts","sourceRoot":"","sources":["../../src/noiseMap/noise2d.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAiBnD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAS7D;AAED,qDAAqD;AACrD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE5C;AAED,kDAAkD;AAClD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE7C;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,GACtD,IAAI,CAON;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAcxD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const HEADER_LENGTH = 2;
|
|
2
|
+
function validateBounds(noise, x, y) {
|
|
3
|
+
const [width, height] = noise;
|
|
4
|
+
if (!(Number.isInteger(x) && Number.isInteger(y)))
|
|
5
|
+
throw new RangeError('Invalid x or y');
|
|
6
|
+
if (x < 0 || x >= width || y < 0 || y >= height)
|
|
7
|
+
throw new RangeError('Invalid bounds');
|
|
8
|
+
}
|
|
9
|
+
function getIndex(noise, x, y) {
|
|
10
|
+
/** @todo - should validation have an opt out? */
|
|
11
|
+
validateBounds(noise, x, y);
|
|
12
|
+
const [width] = noise;
|
|
13
|
+
return y * width + x + HEADER_LENGTH;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Allocates a zero-filled `width` × `height` map. The caller owns it; every
|
|
17
|
+
* generator returns a map made here and keeps no reference to it.
|
|
18
|
+
*
|
|
19
|
+
* Throws a `RangeError` unless both sizes are positive integers. The sizes are
|
|
20
|
+
* stored in the map's Float32 header, which holds integers exactly only up to
|
|
21
|
+
* 2^24, so larger sizes are not supported.
|
|
22
|
+
*/
|
|
23
|
+
export function create(width, height) {
|
|
24
|
+
if (!(Number.isInteger(width) && Number.isInteger(height)))
|
|
25
|
+
throw new RangeError('Invalid width or height');
|
|
26
|
+
if (width <= 0 || height <= 0)
|
|
27
|
+
throw new RangeError('Invalid width or height');
|
|
28
|
+
const noise = new Float32Array(width * height + HEADER_LENGTH);
|
|
29
|
+
noise[0] = width;
|
|
30
|
+
noise[1] = height;
|
|
31
|
+
return noise;
|
|
32
|
+
}
|
|
33
|
+
/** Number of columns, read from the map's header. */
|
|
34
|
+
export function width(noise) {
|
|
35
|
+
return noise[0];
|
|
36
|
+
}
|
|
37
|
+
/** Number of rows, read from the map's header. */
|
|
38
|
+
export function height(noise) {
|
|
39
|
+
return noise[1];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The map's cells as a row-major view over the same buffer, without the header:
|
|
43
|
+
* cell (x, y) is at `y * width + x`. Writes through it change the map, and it
|
|
44
|
+
* stays valid as long as the map does. There are no bounds checks, unlike
|
|
45
|
+
* `get`/`set`, so it suits whole-map passes whose loops already stay in range.
|
|
46
|
+
* Each call allocates a small view object, so take it once per pass, not per cell.
|
|
47
|
+
*/
|
|
48
|
+
export function getValues(noise) {
|
|
49
|
+
return noise.subarray(HEADER_LENGTH);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Writes `value` to cell (`x`, `y`), rounded to Float32 like every map value.
|
|
53
|
+
* Throws a `RangeError` unless both coordinates are integers inside the map.
|
|
54
|
+
* The check runs on every call; for whole-map passes use {@link getValues}.
|
|
55
|
+
*/
|
|
56
|
+
export function set(noise, x, y, value) {
|
|
57
|
+
noise[getIndex(noise, x, y)] = value;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reads cell (`x`, `y`). Throws a `RangeError` unless both coordinates are
|
|
61
|
+
* integers inside the map. The check runs on every call; for whole-map passes
|
|
62
|
+
* use {@link getValues}.
|
|
63
|
+
*/
|
|
64
|
+
export function get(noise, x, y) {
|
|
65
|
+
return noise[getIndex(noise, x, y)];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Calls `callback` once per cell in row-major order (x fastest), with the
|
|
69
|
+
* cell's value and coordinates. Writing to the map from the callback is safe:
|
|
70
|
+
* each value is read just before its call. Each read is bounds-checked like
|
|
71
|
+
* {@link get}, so hot loops should use {@link getValues} instead.
|
|
72
|
+
*/
|
|
73
|
+
export function forEach(noise, callback) {
|
|
74
|
+
const [width, height] = noise;
|
|
75
|
+
for (let y = 0; y < height; y++) {
|
|
76
|
+
for (let x = 0; x < width; x++) {
|
|
77
|
+
callback(get(noise, x, y), x, y);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A new greyscale RGBA image of the map: 4 bytes per cell in row-major order,
|
|
83
|
+
* with each channel set to `value * 255` truncated and alpha 255.
|
|
84
|
+
*
|
|
85
|
+
* Expects values in [0, 1], which every generator produces. Values outside it
|
|
86
|
+
* wrap around rather than clamp (1.5 becomes 126, not 255), because `Uint8Array`
|
|
87
|
+
* stores numbers modulo 256. For `ImageData`, wrap the result's bytes in a
|
|
88
|
+
* `Uint8ClampedArray`; no copy is needed.
|
|
89
|
+
*/
|
|
90
|
+
export function toPixelBuffer(noise) {
|
|
91
|
+
const [width, height] = noise;
|
|
92
|
+
const pixelBuffer = new Uint8Array(width * height * 4);
|
|
93
|
+
for (let y = 0; y < height; y++) {
|
|
94
|
+
for (let x = 0; x < width; x++) {
|
|
95
|
+
const index = (y * width + x) * 4;
|
|
96
|
+
const value = get(noise, x, y);
|
|
97
|
+
pixelBuffer[index] = value * 255;
|
|
98
|
+
pixelBuffer[index + 1] = value * 255;
|
|
99
|
+
pixelBuffer[index + 2] = value * 255;
|
|
100
|
+
pixelBuffer[index + 3] = 255;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return pixelBuffer;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=noise2d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise2d.js","sourceRoot":"","sources":["../../src/noiseMap/noise2d.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,SAAS,cAAc,CAAC,KAAc,EAAE,CAAS,EAAE,CAAS;IAC1D,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAC9B,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC1F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM;QAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,CAAS,EAAE,CAAS;IACpD,iDAAiD;IACjD,cAAc,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACtB,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,aAAa,CAAC;AACvC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa,EAAE,MAAc;IAClD,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,CAAC;IAClD,IAAI,KAAK,IAAI,CAAC,IAAI,MAAM,IAA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KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAC9B,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/B,WAAW,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;YACjC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;YACrC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;YACrC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Noise3D } from './_types/noise3d.js';
|
|
2
|
+
/**
|
|
3
|
+
* Allocates a zero-filled `width` × `height` × `depth` map. The caller owns it;
|
|
4
|
+
* every generator returns a map made here and keeps no reference to it.
|
|
5
|
+
*
|
|
6
|
+
* Throws a `RangeError` unless all three sizes are positive integers. The sizes
|
|
7
|
+
* are stored in the map's Float32 header, which holds integers exactly only up
|
|
8
|
+
* to 2^24, so larger sizes are not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare function create(width: number, height: number, depth: number): Noise3D;
|
|
11
|
+
/** Number of columns, read from the map's header. */
|
|
12
|
+
export declare function width(noise: Noise3D): number;
|
|
13
|
+
/** Number of rows per layer, read from the map's header. */
|
|
14
|
+
export declare function height(noise: Noise3D): number;
|
|
15
|
+
/** Number of layers, read from the map's header. */
|
|
16
|
+
export declare function depth(noise: Noise3D): number;
|
|
17
|
+
/**
|
|
18
|
+
* The map's cells as a view over the same buffer, without the header. x varies
|
|
19
|
+
* fastest, then y, then z: cell (x, y, z) is at `(z * height + y) * width + x`.
|
|
20
|
+
* Writes through it change the map, and it stays valid as long as the map does.
|
|
21
|
+
* There are no bounds checks, unlike `get`/`set`, so it suits whole-map passes
|
|
22
|
+
* whose loops already stay in range. Each call allocates a small view object, so
|
|
23
|
+
* take it once per pass, not per cell.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getValues(noise: Noise3D): Float32Array;
|
|
26
|
+
/**
|
|
27
|
+
* Writes `value` to cell (`x`, `y`, `z`), rounded to Float32 like every map
|
|
28
|
+
* value. Throws a `RangeError` unless all three coordinates are integers inside
|
|
29
|
+
* the map. The check runs on every call; for whole-map passes use
|
|
30
|
+
* {@link getValues}.
|
|
31
|
+
*/
|
|
32
|
+
export declare function set(noise: Noise3D, x: number, y: number, z: number, value: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Reads cell (`x`, `y`, `z`). Throws a `RangeError` unless all three
|
|
35
|
+
* coordinates are integers inside the map. The check runs on every call; for
|
|
36
|
+
* whole-map passes use {@link getValues}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function get(noise: Noise3D, x: number, y: number, z: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Calls `callback` once per cell in storage order (x fastest, then y, then z),
|
|
41
|
+
* with the cell's value and coordinates. Writing to the map from the callback
|
|
42
|
+
* is safe: each value is read just before its call. Each read is bounds-checked
|
|
43
|
+
* like {@link get}, so hot loops should use {@link getValues} instead.
|
|
44
|
+
*/
|
|
45
|
+
export declare function forEach(noise: Noise3D, callback: (value: number, x: number, y: number, z: number) => void): void;
|
|
46
|
+
/**
|
|
47
|
+
* A new greyscale RGBA image of layer `layer` (a z index): 4 bytes per cell in
|
|
48
|
+
* row-major order, with each channel set to `value * 255` truncated and alpha
|
|
49
|
+
* 255. Throws a `RangeError` unless `layer` is an integer inside the map.
|
|
50
|
+
*
|
|
51
|
+
* Expects values in [0, 1], which every generator produces. Values outside it
|
|
52
|
+
* wrap around rather than clamp (1.5 becomes 126, not 255), because `Uint8Array`
|
|
53
|
+
* stores numbers modulo 256. For `ImageData`, wrap the result's bytes in a
|
|
54
|
+
* `Uint8ClampedArray`; no copy is needed.
|
|
55
|
+
*/
|
|
56
|
+
export declare function toPixelBuffer(noise: Noise3D, layer: number): Uint8Array;
|
|
57
|
+
/**
|
|
58
|
+
* {@link toPixelBuffer} for every layer, in z order: `depth` separate buffers of
|
|
59
|
+
* `width * height * 4` bytes each.
|
|
60
|
+
*/
|
|
61
|
+
export declare function toPixelBuffers(noise: Noise3D): Uint8Array[];
|
|
62
|
+
//# sourceMappingURL=noise3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise3d.d.ts","sourceRoot":"","sources":["../../src/noiseMap/noise3d.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAoBnD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAW5E;AAED,qDAAqD;AACrD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE5C;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE7C;AAED,oDAAoD;AACpD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE5C;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAExF;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,GACjE,IAAI,CASN;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAcvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,EAAE,CAQ3D"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const HEADER_LENGTH = 3;
|
|
2
|
+
function validateBounds(noise, x, y, z) {
|
|
3
|
+
const [width, height, depth] = noise;
|
|
4
|
+
if (!(Number.isInteger(x) && Number.isInteger(y) && Number.isInteger(z)))
|
|
5
|
+
throw new RangeError('Invalid x, y, or z');
|
|
6
|
+
if (x < 0 || x >= width || y < 0 || y >= height || z < 0 || z >= depth)
|
|
7
|
+
throw new RangeError('Invalid bounds');
|
|
8
|
+
}
|
|
9
|
+
function getIndex(noise, x, y, z) {
|
|
10
|
+
/** @todo - should validation have an opt out? */
|
|
11
|
+
validateBounds(noise, x, y, z);
|
|
12
|
+
const [width, height] = noise;
|
|
13
|
+
// +3 skips the [width, height, depth] header
|
|
14
|
+
return (z * height + y) * width + x + HEADER_LENGTH;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Allocates a zero-filled `width` × `height` × `depth` map. The caller owns it;
|
|
18
|
+
* every generator returns a map made here and keeps no reference to it.
|
|
19
|
+
*
|
|
20
|
+
* Throws a `RangeError` unless all three sizes are positive integers. The sizes
|
|
21
|
+
* are stored in the map's Float32 header, which holds integers exactly only up
|
|
22
|
+
* to 2^24, so larger sizes are not supported.
|
|
23
|
+
*/
|
|
24
|
+
export function create(width, height, depth) {
|
|
25
|
+
if (!(Number.isInteger(width) && Number.isInteger(height) && Number.isInteger(depth)))
|
|
26
|
+
throw new RangeError('Invalid width, height, or depth');
|
|
27
|
+
if (width <= 0 || height <= 0 || depth <= 0)
|
|
28
|
+
throw new RangeError('Invalid width, height, or depth');
|
|
29
|
+
const noise = new Float32Array(width * height * depth + 3);
|
|
30
|
+
noise[0] = width;
|
|
31
|
+
noise[1] = height;
|
|
32
|
+
noise[2] = depth;
|
|
33
|
+
return noise;
|
|
34
|
+
}
|
|
35
|
+
/** Number of columns, read from the map's header. */
|
|
36
|
+
export function width(noise) {
|
|
37
|
+
return noise[0];
|
|
38
|
+
}
|
|
39
|
+
/** Number of rows per layer, read from the map's header. */
|
|
40
|
+
export function height(noise) {
|
|
41
|
+
return noise[1];
|
|
42
|
+
}
|
|
43
|
+
/** Number of layers, read from the map's header. */
|
|
44
|
+
export function depth(noise) {
|
|
45
|
+
return noise[2];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The map's cells as a view over the same buffer, without the header. x varies
|
|
49
|
+
* fastest, then y, then z: cell (x, y, z) is at `(z * height + y) * width + x`.
|
|
50
|
+
* Writes through it change the map, and it stays valid as long as the map does.
|
|
51
|
+
* There are no bounds checks, unlike `get`/`set`, so it suits whole-map passes
|
|
52
|
+
* whose loops already stay in range. Each call allocates a small view object, so
|
|
53
|
+
* take it once per pass, not per cell.
|
|
54
|
+
*/
|
|
55
|
+
export function getValues(noise) {
|
|
56
|
+
return noise.subarray(HEADER_LENGTH);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Writes `value` to cell (`x`, `y`, `z`), rounded to Float32 like every map
|
|
60
|
+
* value. Throws a `RangeError` unless all three coordinates are integers inside
|
|
61
|
+
* the map. The check runs on every call; for whole-map passes use
|
|
62
|
+
* {@link getValues}.
|
|
63
|
+
*/
|
|
64
|
+
export function set(noise, x, y, z, value) {
|
|
65
|
+
noise[getIndex(noise, x, y, z)] = value;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reads cell (`x`, `y`, `z`). Throws a `RangeError` unless all three
|
|
69
|
+
* coordinates are integers inside the map. The check runs on every call; for
|
|
70
|
+
* whole-map passes use {@link getValues}.
|
|
71
|
+
*/
|
|
72
|
+
export function get(noise, x, y, z) {
|
|
73
|
+
return noise[getIndex(noise, x, y, z)];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Calls `callback` once per cell in storage order (x fastest, then y, then z),
|
|
77
|
+
* with the cell's value and coordinates. Writing to the map from the callback
|
|
78
|
+
* is safe: each value is read just before its call. Each read is bounds-checked
|
|
79
|
+
* like {@link get}, so hot loops should use {@link getValues} instead.
|
|
80
|
+
*/
|
|
81
|
+
export function forEach(noise, callback) {
|
|
82
|
+
const [width, height, depth] = noise;
|
|
83
|
+
for (let z = 0; z < depth; z++) {
|
|
84
|
+
for (let y = 0; y < height; y++) {
|
|
85
|
+
for (let x = 0; x < width; x++) {
|
|
86
|
+
callback(get(noise, x, y, z), x, y, z);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A new greyscale RGBA image of layer `layer` (a z index): 4 bytes per cell in
|
|
93
|
+
* row-major order, with each channel set to `value * 255` truncated and alpha
|
|
94
|
+
* 255. Throws a `RangeError` unless `layer` is an integer inside the map.
|
|
95
|
+
*
|
|
96
|
+
* Expects values in [0, 1], which every generator produces. Values outside it
|
|
97
|
+
* wrap around rather than clamp (1.5 becomes 126, not 255), because `Uint8Array`
|
|
98
|
+
* stores numbers modulo 256. For `ImageData`, wrap the result's bytes in a
|
|
99
|
+
* `Uint8ClampedArray`; no copy is needed.
|
|
100
|
+
*/
|
|
101
|
+
export function toPixelBuffer(noise, layer) {
|
|
102
|
+
const [width, height] = noise;
|
|
103
|
+
const pixelBuffer = new Uint8Array(width * height * 4);
|
|
104
|
+
for (let y = 0; y < height; y++) {
|
|
105
|
+
for (let x = 0; x < width; x++) {
|
|
106
|
+
const index = (y * width + x) * 4;
|
|
107
|
+
const value = get(noise, x, y, layer);
|
|
108
|
+
pixelBuffer[index] = value * 255;
|
|
109
|
+
pixelBuffer[index + 1] = value * 255;
|
|
110
|
+
pixelBuffer[index + 2] = value * 255;
|
|
111
|
+
pixelBuffer[index + 3] = 255;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return pixelBuffer;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* {@link toPixelBuffer} for every layer, in z order: `depth` separate buffers of
|
|
118
|
+
* `width * height * 4` bytes each.
|
|
119
|
+
*/
|
|
120
|
+
export function toPixelBuffers(noise) {
|
|
121
|
+
const [, , depth] = noise;
|
|
122
|
+
const pixelBuffers = [];
|
|
123
|
+
for (let z = 0; z < depth; z++) {
|
|
124
|
+
const pixelBuffer = toPixelBuffer(noise, z);
|
|
125
|
+
pixelBuffers.push(pixelBuffer);
|
|
126
|
+
}
|
|
127
|
+
return pixelBuffers;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=noise3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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C,GAAG,KAAK,GAAG,GAAG,CAAC;YACjC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;YACrC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;YACrC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,CAAC,EAAE,AAAD,EAAG,KAAK,CAAC,GAAG,KAAK,CAAC;IAC1B,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5C,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Noise2D } from '../../noiseMap/index.js';
|
|
2
|
+
import type { Cellular2dOptions } from './_types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a `width` × `height` map of cellular (Worley) noise in [0, 1]. Each
|
|
5
|
+
* value is the distance from its cell to the nearest feature point (F1),
|
|
6
|
+
* divided by the diagonal of one grid cell. The caller owns the returned map.
|
|
7
|
+
*
|
|
8
|
+
* The world is divided into `cellWidth` × `cellHeight` grid cells anchored at
|
|
9
|
+
* world (0, 0), and each grid cell holds one point whose position depends only
|
|
10
|
+
* on the cell's coordinates and the seed. Each value therefore depends only on
|
|
11
|
+
* its world cell (`x + offsetX`, `y + offsetY`) and the other options, never on
|
|
12
|
+
* the map's size, so chunks of any size created with the same options and their
|
|
13
|
+
* world origin as the offset agree bit for bit wherever they overlap.
|
|
14
|
+
*
|
|
15
|
+
* The mapping to [0, 1] is fixed by the cell size rather than stretched per
|
|
16
|
+
* map. The diagonal is the true upper bound but is almost never reached: 256²
|
|
17
|
+
* maps span roughly 0–0.8 and average about 0.3, so the result reads darker
|
|
18
|
+
* than gradient noise centred on 0.5.
|
|
19
|
+
*
|
|
20
|
+
* Distances are measured from the sample's position inside its own grid cell,
|
|
21
|
+
* not from absolute world coordinates, so precision does not fall off far from
|
|
22
|
+
* the origin. The point hash takes 32-bit cell coordinates, so the pattern
|
|
23
|
+
* repeats every 2^32 grid cells along each axis.
|
|
24
|
+
*
|
|
25
|
+
* Known limitation: only the 3×3 block of grid cells around each sample is
|
|
26
|
+
* searched, so the true nearest point is missed when it lies two cells over.
|
|
27
|
+
* For square cells that is rare (about one value in a 256² map), but it grows
|
|
28
|
+
* with the cell's aspect ratio and shows as visible seams: roughly 0.15% of
|
|
29
|
+
* values at 10 × 20, 3% at 5 × 20 and 8% at 3 × 17. Searching
|
|
30
|
+
* `ceil(diagonal / cellSize)` cells along each axis would make it exact.
|
|
31
|
+
*
|
|
32
|
+
* Throws if the size is not a positive integer or an option breaks its contract
|
|
33
|
+
* in {@link Cellular2dOptions}.
|
|
34
|
+
*/
|
|
35
|
+
export declare function create(width: number, height: number, options?: Partial<Cellular2dOptions>): Noise2D;
|
|
36
|
+
//# sourceMappingURL=2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2d.d.ts","sourceRoot":"","sources":["../../../src/noiseTypes/cellular/2d.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKlD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAc3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM,GACvC,OAAO,CAqFT"}
|