@flighthq/math 0.5.1-next.973.788d3d7 → 0.7.0-edge.5213.ead804b
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/README.md +2 -2
- package/dist/angle.d.ts +13 -6
- package/dist/angle.d.ts.map +1 -1
- package/dist/angle.js +22 -7
- package/dist/angle.js.map +1 -1
- package/dist/clamp.d.ts +11 -7
- package/dist/clamp.d.ts.map +1 -1
- package/dist/clamp.js +15 -8
- package/dist/clamp.js.map +1 -1
- package/dist/comparison.d.ts +13 -9
- package/dist/comparison.d.ts.map +1 -1
- package/dist/comparison.js +26 -15
- package/dist/comparison.js.map +1 -1
- package/dist/constants.d.ts +17 -17
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +18 -16
- package/dist/constants.js.map +1 -1
- package/dist/contract.d.ts +17 -15
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +15 -15
- package/dist/contract.js.map +1 -1
- package/dist/hash.d.ts +19 -21
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +32 -30
- package/dist/hash.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interpolation.d.ts +19 -13
- package/dist/interpolation.d.ts.map +1 -1
- package/dist/interpolation.js +23 -14
- package/dist/interpolation.js.map +1 -1
- package/dist/interpolationAdvanced.d.ts +25 -22
- package/dist/interpolationAdvanced.d.ts.map +1 -1
- package/dist/interpolationAdvanced.js +38 -38
- package/dist/interpolationAdvanced.js.map +1 -1
- package/dist/nextPowerOfTwo.d.ts +13 -9
- package/dist/nextPowerOfTwo.d.ts.map +1 -1
- package/dist/nextPowerOfTwo.js +35 -34
- package/dist/nextPowerOfTwo.js.map +1 -1
- package/dist/numberTheory.d.ts +23 -18
- package/dist/numberTheory.d.ts.map +1 -1
- package/dist/numberTheory.js +38 -28
- package/dist/numberTheory.js.map +1 -1
- package/dist/random.d.ts +9 -16
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +14 -21
- package/dist/random.js.map +1 -1
- package/dist/randomDistributions.d.ts +54 -75
- package/dist/randomDistributions.d.ts.map +1 -1
- package/dist/randomDistributions.js +134 -128
- package/dist/randomDistributions.js.map +1 -1
- package/dist/randomRange.d.ts +13 -8
- package/dist/randomRange.d.ts.map +1 -1
- package/dist/randomRange.js +19 -12
- package/dist/randomRange.js.map +1 -1
- package/dist/rounding.d.ts +18 -19
- package/dist/rounding.d.ts.map +1 -1
- package/dist/rounding.js +31 -25
- package/dist/rounding.js.map +1 -1
- package/dist/rustTestSupport.d.ts +5 -0
- package/dist/rustTestSupport.d.ts.map +1 -0
- package/dist/rustTestSupport.js +14 -0
- package/dist/rustTestSupport.js.map +1 -0
- package/dist/scalar.d.ts +15 -18
- package/dist/scalar.d.ts.map +1 -1
- package/dist/scalar.js +24 -23
- package/dist/scalar.js.map +1 -1
- package/dist/statistics.d.ts +18 -13
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +142 -94
- package/dist/statistics.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +4 -5
- package/src/angle.test.ts +55 -41
- package/src/clamp.test.ts +23 -18
- package/src/comparison.test.ts +22 -17
- package/src/constants.test.ts +61 -58
- package/src/hash.test.ts +41 -33
- package/src/interpolation.test.ts +41 -30
- package/src/interpolationAdvanced.test.ts +61 -57
- package/src/nextPowerOfTwo.test.ts +45 -46
- package/src/numberTheory.test.ts +44 -41
- package/src/random.test.ts +51 -21
- package/src/randomDistributions.test.ts +355 -271
- package/src/randomRange.test.ts +76 -60
- package/src/rounding.test.ts +45 -29
- package/src/scalar.test.ts +32 -21
- package/src/statistics.test.ts +80 -66
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/math`. The `@flighth
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/math@0.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/math@0.7.0-edge.5213.ead804b](https://github.com/flighthq/flight/tree/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/packages/math)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/ead804bfaef3e691a2e6e43e9711ddd3fd8a84a2/LICENSE.md)
|
package/dist/angle.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Convert `degrees` to radians.
|
|
3
|
+
*/
|
|
2
4
|
export declare function degToRad(degrees: number): number;
|
|
3
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Return the shortest signed difference between angles `from` and `to` (radians).
|
|
4
7
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
8
|
+
* The result is in `(-pi, pi]`. Useful for rotating a value toward a target by
|
|
9
|
+
* the minimum arc.
|
|
7
10
|
*/
|
|
8
11
|
export declare function deltaAngle(from: number, to: number): number;
|
|
9
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Wrap `radians` to the range `[-pi, pi)`.
|
|
14
|
+
*/
|
|
10
15
|
export declare function normalizeAngle(radians: number): number;
|
|
11
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Convert `radians` to degrees.
|
|
18
|
+
*/
|
|
12
19
|
export declare function radToDeg(radians: number): number;
|
|
13
20
|
//# sourceMappingURL=angle.d.ts.map
|
package/dist/angle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angle.d.ts","sourceRoot":"","sources":["../src/angle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"angle.d.ts","sourceRoot":"","sources":["../src/angle.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
package/dist/angle.js
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/angle.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { DEG_TO_RAD, RAD_TO_DEG, TAU } from './constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Convert `degrees` to radians.
|
|
6
|
+
*/
|
|
3
7
|
export function degToRad(degrees) {
|
|
4
8
|
return degrees * DEG_TO_RAD;
|
|
5
9
|
}
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Return the shortest signed difference between angles `from` and `to` (radians).
|
|
7
12
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
13
|
+
* The result is in `(-pi, pi]`. Useful for rotating a value toward a target by
|
|
14
|
+
* the minimum arc.
|
|
10
15
|
*/
|
|
11
16
|
export function deltaAngle(from, to) {
|
|
17
|
+
if (to - from === Math.PI) {
|
|
18
|
+
return Math.PI;
|
|
19
|
+
}
|
|
12
20
|
const diff = (((to - from) % TAU) + TAU) % TAU;
|
|
13
21
|
return diff > Math.PI ? diff - TAU : diff;
|
|
14
22
|
}
|
|
15
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Wrap `radians` to the range `[-pi, pi)`.
|
|
25
|
+
*/
|
|
16
26
|
export function normalizeAngle(radians) {
|
|
27
|
+
if (radians === Math.PI) {
|
|
28
|
+
return -Math.PI;
|
|
29
|
+
}
|
|
17
30
|
const wrapped = ((radians % TAU) + TAU) % TAU;
|
|
18
31
|
return wrapped >= Math.PI ? wrapped - TAU : wrapped;
|
|
19
32
|
}
|
|
20
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Convert `radians` to degrees.
|
|
35
|
+
*/
|
|
21
36
|
export function radToDeg(radians) {
|
|
22
37
|
return radians * RAD_TO_DEG;
|
|
23
38
|
}
|
package/dist/angle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angle.js","sourceRoot":"","sources":["../src/angle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"angle.js","sourceRoot":"","sources":["../src/angle.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,mEAAmE;AAEnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,OAAO,GAAG,UAAU,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,EAAU;IACjD,IAAI,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC/C,OAAO,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,IAAI,OAAO,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC9C,OAAO,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,OAAO,GAAG,UAAU,CAAC;AAC9B,CAAC"}
|
package/dist/clamp.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Clamp `value` to the inclusive range `[min, max]`.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
+
* When `min > max` the result is `min`. NaN propagates unchanged.
|
|
4
5
|
*/
|
|
5
6
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
6
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Return `true` if `value` is within the inclusive range `[min, max]`.
|
|
9
|
+
*/
|
|
7
10
|
export declare function inRange(value: number, min: number, max: number): boolean;
|
|
8
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* Named `saturate` after the GPU HLSL/GLSL convention. Follows GPU semantics:
|
|
15
|
+
* NaN returns 0 (unlike `clamp`, which propagates NaN). Safe in hot loops,
|
|
16
|
+
* no allocation.
|
|
13
17
|
*/
|
|
14
18
|
export declare function saturate(value: number): number;
|
|
15
19
|
//# sourceMappingURL=clamp.d.ts.map
|
package/dist/clamp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAExE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9C"}
|
package/dist/clamp.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/clamp.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
/**
|
|
4
|
+
* Clamp `value` to the inclusive range `[min, max]`.
|
|
2
5
|
*
|
|
3
|
-
*
|
|
6
|
+
* When `min > max` the result is `min`. NaN propagates unchanged.
|
|
4
7
|
*/
|
|
5
8
|
export function clamp(value, min, max) {
|
|
6
9
|
return value < min ? min : value > max ? max : value;
|
|
7
10
|
}
|
|
8
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Return `true` if `value` is within the inclusive range `[min, max]`.
|
|
13
|
+
*/
|
|
9
14
|
export function inRange(value, min, max) {
|
|
10
15
|
return value >= min && value <= max;
|
|
11
16
|
}
|
|
12
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
|
|
13
19
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
20
|
+
* Named `saturate` after the GPU HLSL/GLSL convention. Follows GPU semantics:
|
|
21
|
+
* NaN returns 0 (unlike `clamp`, which propagates NaN). Safe in hot loops,
|
|
22
|
+
* no allocation.
|
|
17
23
|
*/
|
|
18
24
|
export function saturate(value) {
|
|
19
|
-
if (value
|
|
25
|
+
if (Number.isNaN(value)) {
|
|
20
26
|
return 0;
|
|
27
|
+
}
|
|
21
28
|
return value < 0 ? 0 : value > 1 ? 1 : value;
|
|
22
29
|
}
|
|
23
30
|
//# sourceMappingURL=clamp.js.map
|
package/dist/clamp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,mEAAmE;AAEnE;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC3D,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC7D,OAAO,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/C,CAAC"}
|
package/dist/comparison.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return `true` if `|a - b| <= epsilon`.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* Uses an absolute epsilon, appropriate for values near zero. For magnitudes
|
|
5
|
+
* much larger than 1, use `approxEqualRelative`.
|
|
5
6
|
*/
|
|
6
7
|
export declare function approxEqual(a: number, b: number, epsilon?: number): boolean;
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Return `true` if `a` and `b` agree to within a relative tolerance.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Uses `|a - b| <= relativeEpsilon * max(|a|, |b|)`, which scales with
|
|
12
|
+
* magnitude and is appropriate for large numbers where absolute epsilon
|
|
13
|
+
* comparisons fail. For values near zero, falls back to `EPSILON`
|
|
14
|
+
* (absolute).
|
|
13
15
|
*/
|
|
14
16
|
export declare function approxEqualRelative(a: number, b: number, relativeEpsilon?: number): boolean;
|
|
15
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Return `true` if `|value| <= epsilon`.
|
|
19
|
+
*/
|
|
16
20
|
export declare function approxZero(value: number, epsilon?: number): boolean;
|
|
17
21
|
//# sourceMappingURL=comparison.d.ts.map
|
package/dist/comparison.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAG3E;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAO3F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAGnE"}
|
package/dist/comparison.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/comparison.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { EPSILON } from './constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Return `true` if `|a - b| <= epsilon`.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
7
|
+
* Uses an absolute epsilon, appropriate for values near zero. For magnitudes
|
|
8
|
+
* much larger than 1, use `approxEqualRelative`.
|
|
6
9
|
*/
|
|
7
|
-
export function approxEqual(a, b, epsilon
|
|
10
|
+
export function approxEqual(a, b, epsilon) {
|
|
11
|
+
epsilon = epsilon ?? EPSILON;
|
|
8
12
|
return Math.abs(a - b) <= epsilon;
|
|
9
13
|
}
|
|
10
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Return `true` if `a` and `b` agree to within a relative tolerance.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
17
|
+
* Uses `|a - b| <= relativeEpsilon * max(|a|, |b|)`, which scales with
|
|
18
|
+
* magnitude and is appropriate for large numbers where absolute epsilon
|
|
19
|
+
* comparisons fail. For values near zero, falls back to `EPSILON`
|
|
20
|
+
* (absolute).
|
|
16
21
|
*/
|
|
17
|
-
export function approxEqualRelative(a, b, relativeEpsilon
|
|
22
|
+
export function approxEqualRelative(a, b, relativeEpsilon) {
|
|
23
|
+
relativeEpsilon = relativeEpsilon ?? EPSILON;
|
|
18
24
|
const diff = Math.abs(a - b);
|
|
19
|
-
const largest = Math.
|
|
20
|
-
|
|
25
|
+
const largest = Math.abs(a) > Math.abs(b) ? Math.abs(a) : Math.abs(b);
|
|
26
|
+
let threshold = relativeEpsilon * largest;
|
|
27
|
+
threshold = threshold > EPSILON ? threshold : EPSILON;
|
|
28
|
+
return diff <= threshold;
|
|
21
29
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Return `true` if `|value| <= epsilon`.
|
|
32
|
+
*/
|
|
33
|
+
export function approxZero(value, epsilon) {
|
|
34
|
+
epsilon = epsilon ?? EPSILON;
|
|
24
35
|
return Math.abs(value) <= epsilon;
|
|
25
36
|
}
|
|
26
37
|
//# sourceMappingURL=comparison.js.map
|
package/dist/comparison.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparison.js","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"comparison.js","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mEAAmE;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,OAAgB;IAChE,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC;IAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAS,EAAE,CAAS,EAAE,eAAwB;IAChF,eAAe,GAAG,eAAe,IAAI,OAAO,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACtE,IAAI,SAAS,GAAG,eAAe,GAAG,OAAO,CAAC;IAC1C,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACtD,OAAO,IAAI,IAAI,SAAS,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,OAAgB;IACxD,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC;IAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC;AACpC,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Control-point distance, as a fraction of the radius, for approximating a quarter circle with one
|
|
3
3
|
* cubic Bezier: `4 * (sqrt(2) - 1) / 3`.
|
|
4
|
-
*
|
|
5
|
-
* Named for the circle that defines it rather than the arcs that use it. Written as a literal and
|
|
6
|
-
* pinned to that formula by the colocated test, which IS the recomputation a transcribed decimal
|
|
7
|
-
* would otherwise lack — the digits are long enough that a wrong one reads as correct and still
|
|
8
|
-
* draws a circle that looks round.
|
|
9
|
-
*
|
|
10
|
-
* A literal rather than the expression because `Math.SQRT2` is a property of a mutable global: no
|
|
11
|
-
* correct minifier may evaluate `4 * (Math.SQRT2 - 1) / 3` at build time, so that form reaches the
|
|
12
|
-
* bundle as a runtime computation of a compile-time-known number. Neither form is inlined at its
|
|
13
|
-
* use sites and both measure the same gzipped size, so this buys evaluation, not bytes.
|
|
14
4
|
*/
|
|
15
|
-
export declare const CIRCLE_KAPPA
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
export declare const CIRCLE_KAPPA: number;
|
|
6
|
+
/**
|
|
7
|
+
* Default absolute tolerance for approximate floating-point comparisons.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EPSILON: number;
|
|
10
|
+
/**
|
|
11
|
+
* Full circle in radians (2pi).
|
|
12
|
+
*/
|
|
19
13
|
export declare const TAU: number;
|
|
20
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Half of pi (pi / 2).
|
|
16
|
+
*/
|
|
21
17
|
export declare const HALF_PI: number;
|
|
22
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Multiply degrees by this constant to get radians.
|
|
20
|
+
*/
|
|
23
21
|
export declare const DEG_TO_RAD: number;
|
|
24
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Multiply radians by this constant to get degrees.
|
|
24
|
+
*/
|
|
25
25
|
export declare const RAD_TO_DEG: number;
|
|
26
26
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,MAAkB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAa,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,MAAoB,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAAsB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAAsB,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
+
// Generated from crates/flight-math/src/constants.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
1
3
|
/**
|
|
2
4
|
* Control-point distance, as a fraction of the radius, for approximating a quarter circle with one
|
|
3
5
|
* cubic Bezier: `4 * (sqrt(2) - 1) / 3`.
|
|
4
|
-
*
|
|
5
|
-
* Named for the circle that defines it rather than the arcs that use it. Written as a literal and
|
|
6
|
-
* pinned to that formula by the colocated test, which IS the recomputation a transcribed decimal
|
|
7
|
-
* would otherwise lack — the digits are long enough that a wrong one reads as correct and still
|
|
8
|
-
* draws a circle that looks round.
|
|
9
|
-
*
|
|
10
|
-
* A literal rather than the expression because `Math.SQRT2` is a property of a mutable global: no
|
|
11
|
-
* correct minifier may evaluate `4 * (Math.SQRT2 - 1) / 3` at build time, so that form reaches the
|
|
12
|
-
* bundle as a runtime computation of a compile-time-known number. Neither form is inlined at its
|
|
13
|
-
* use sites and both measure the same gzipped size, so this buys evaluation, not bytes.
|
|
14
6
|
*/
|
|
15
|
-
export const CIRCLE_KAPPA = 0.
|
|
16
|
-
/**
|
|
7
|
+
export const CIRCLE_KAPPA = 0.5522848;
|
|
8
|
+
/**
|
|
9
|
+
* Default absolute tolerance for approximate floating-point comparisons.
|
|
10
|
+
*/
|
|
17
11
|
export const EPSILON = 1e-6;
|
|
18
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Full circle in radians (2pi).
|
|
14
|
+
*/
|
|
19
15
|
export const TAU = Math.PI * 2;
|
|
20
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Half of pi (pi / 2).
|
|
18
|
+
*/
|
|
21
19
|
export const HALF_PI = Math.PI / 2;
|
|
22
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Multiply degrees by this constant to get radians.
|
|
22
|
+
*/
|
|
23
23
|
export const DEG_TO_RAD = Math.PI / 180;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Multiply radians by this constant to get degrees.
|
|
26
|
+
*/
|
|
25
27
|
export const RAD_TO_DEG = 180 / Math.PI;
|
|
26
28
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,mEAAmE;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAW,SAAS,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAW,IAAI,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAW,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAW,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAW,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAW,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC"}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
1
|
+
export { degToRad, deltaAngle, normalizeAngle, radToDeg } from './angle.ts';
|
|
2
|
+
export { clamp, inRange, saturate } from './clamp.ts';
|
|
3
|
+
export { approxEqual, approxEqualRelative, approxZero } from './comparison.ts';
|
|
4
|
+
export { CIRCLE_KAPPA, DEG_TO_RAD, EPSILON, HALF_PI, RAD_TO_DEG, TAU } from './constants.ts';
|
|
5
|
+
export { createRandomSourceFromHash, hash2D, hash3D, hashCombine, hashUint32 } from './hash.ts';
|
|
6
|
+
export { inverseLerp, lerp, remap, smoothStep, step } from './interpolation.ts';
|
|
7
|
+
export { damp, lerpAngle, moveTowards, pingPong, repeat, smootherStep } from './interpolationAdvanced.ts';
|
|
8
|
+
export { isPowerOfTwo, nextMultipleOf, nextPowerOfTwo, previousPowerOfTwo } from './nextPowerOfTwo.ts';
|
|
9
|
+
export { factorial, gcd, hypot2, isEven, isOdd, lcm } from './numberTheory.ts';
|
|
10
|
+
export { createRandomSource } from './random.ts';
|
|
11
|
+
export type { RandomSource } from './random.ts';
|
|
12
|
+
export { pick, randomExponential, randomGaussian, randomGaussianPair, randomInsideUnitDisc, randomInsideUnitSphere, randomOnUnitCircle, randomOnUnitSphere, randomPoisson, randomWeighted, shuffle, shuffleInPlace, } from './randomDistributions.ts';
|
|
13
|
+
export { randomBool, randomInt, randomRange, randomSign } from './randomRange.ts';
|
|
14
|
+
export { ceilTo, euclideanMod, floorTo, fract, roundTo } from './rounding.ts';
|
|
15
|
+
export { ceilPowerOfTwo, floorPowerOfTwo, quantize, sign } from './scalar.ts';
|
|
16
|
+
export { mean, median, standardDeviation, variance, weightedAverage } from './statistics.ts';
|
|
17
|
+
export type { MutableNumberArray } from './types.ts';
|
|
16
18
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,OAAO,EACP,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC7F,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
1
|
+
export { degToRad, deltaAngle, normalizeAngle, radToDeg } from './angle.js';
|
|
2
|
+
export { clamp, inRange, saturate } from './clamp.js';
|
|
3
|
+
export { approxEqual, approxEqualRelative, approxZero } from './comparison.js';
|
|
4
|
+
export { CIRCLE_KAPPA, DEG_TO_RAD, EPSILON, HALF_PI, RAD_TO_DEG, TAU } from './constants.js';
|
|
5
|
+
export { createRandomSourceFromHash, hash2D, hash3D, hashCombine, hashUint32 } from './hash.js';
|
|
6
|
+
export { inverseLerp, lerp, remap, smoothStep, step } from './interpolation.js';
|
|
7
|
+
export { damp, lerpAngle, moveTowards, pingPong, repeat, smootherStep } from './interpolationAdvanced.js';
|
|
8
|
+
export { isPowerOfTwo, nextMultipleOf, nextPowerOfTwo, previousPowerOfTwo } from './nextPowerOfTwo.js';
|
|
9
|
+
export { factorial, gcd, hypot2, isEven, isOdd, lcm } from './numberTheory.js';
|
|
10
|
+
export { createRandomSource } from './random.js';
|
|
11
|
+
export { pick, randomExponential, randomGaussian, randomGaussianPair, randomInsideUnitDisc, randomInsideUnitSphere, randomOnUnitCircle, randomOnUnitSphere, randomPoisson, randomWeighted, shuffle, shuffleInPlace, } from './randomDistributions.js';
|
|
12
|
+
export { randomBool, randomInt, randomRange, randomSign } from './randomRange.js';
|
|
13
|
+
export { ceilTo, euclideanMod, floorTo, fract, roundTo } from './rounding.js';
|
|
14
|
+
export { ceilPowerOfTwo, floorPowerOfTwo, quantize, sign } from './scalar.js';
|
|
15
|
+
export { mean, median, standardDeviation, variance, weightedAverage } from './statistics.js';
|
|
16
16
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EACL,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,OAAO,EACP,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/hash.d.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import type { RandomSource } from '
|
|
2
|
-
/**
|
|
1
|
+
import type { RandomSource } from './random.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Create a `RandomSource` seeded from a deterministic hash of `x` and `y`.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* const rng = createRandomSourceFromHash(tileX, tileY);
|
|
9
|
-
* const treasure = rng() < 0.05; // 5% chance, reproducible per tile
|
|
10
|
-
* ```
|
|
5
|
+
* Connects the stateless hash layer to the seeded-PRNG layer — each grid
|
|
6
|
+
* cell gets an independent reproducible random stream.
|
|
11
7
|
*/
|
|
12
8
|
export declare function createRandomSourceFromHash(x: number, y: number): RandomSource;
|
|
13
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Stateless position-seeded hash over a 2D integer grid.
|
|
14
11
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* Returns a deterministic value in `[0, 2^32)`. Suitable for procedural
|
|
13
|
+
* tile/cell content and gradient noise seed generation.
|
|
17
14
|
*/
|
|
18
15
|
export declare function hash2D(x: number, y: number): number;
|
|
19
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Stateless position-seeded hash over a 3D integer grid.
|
|
18
|
+
*/
|
|
20
19
|
export declare function hash3D(x: number, y: number, z: number): number;
|
|
21
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* const h = hashCombine(hashUint32(x), y);
|
|
26
|
-
* ```
|
|
23
|
+
* Used to build multi-dimensional hashes from `hashUint32`.
|
|
27
24
|
*/
|
|
28
25
|
export declare function hashCombine(seed: number, value: number): number;
|
|
29
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
|
|
30
28
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* Produces a deterministic, well-distributed 32-bit unsigned integer from any
|
|
30
|
+
* input. Useful as a stateless hash function for individual values.
|
|
33
31
|
*/
|
|
34
32
|
export declare function hashUint32(value: number): number;
|
|
35
33
|
//# sourceMappingURL=hash.d.ts.map
|
package/dist/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD"}
|
package/dist/hash.js
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/hash.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { createRandomSource } from './random.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a `RandomSource` seeded from a deterministic hash of `x` and `y`.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* const rng = createRandomSourceFromHash(tileX, tileY);
|
|
9
|
-
* const treasure = rng() < 0.05; // 5% chance, reproducible per tile
|
|
10
|
-
* ```
|
|
7
|
+
* Connects the stateless hash layer to the seeded-PRNG layer — each grid
|
|
8
|
+
* cell gets an independent reproducible random stream.
|
|
11
9
|
*/
|
|
12
10
|
export function createRandomSourceFromHash(x, y) {
|
|
13
11
|
return createRandomSource(hash2D(x, y));
|
|
14
12
|
}
|
|
15
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Stateless position-seeded hash over a 2D integer grid.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Returns a deterministic value in `[0, 2^32)`. Suitable for procedural
|
|
17
|
+
* tile/cell content and gradient noise seed generation.
|
|
19
18
|
*/
|
|
20
19
|
export function hash2D(x, y) {
|
|
21
|
-
return hashCombine(hashUint32(x
|
|
20
|
+
return hashCombine(hashUint32(x >>> 0), y >>> 0);
|
|
22
21
|
}
|
|
23
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Stateless position-seeded hash over a 3D integer grid.
|
|
24
|
+
*/
|
|
24
25
|
export function hash3D(x, y, z) {
|
|
25
|
-
return hashCombine(hash2D(x, y), z
|
|
26
|
+
return hashCombine(hash2D(x, y), z >>> 0);
|
|
26
27
|
}
|
|
27
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
|
|
28
30
|
*
|
|
29
|
-
*
|
|
30
|
-
* ```ts
|
|
31
|
-
* const h = hashCombine(hashUint32(x), y);
|
|
32
|
-
* ```
|
|
31
|
+
* Used to build multi-dimensional hashes from `hashUint32`.
|
|
33
32
|
*/
|
|
34
33
|
export function hashCombine(seed, value) {
|
|
35
|
-
|
|
34
|
+
const seedI = seed | 0;
|
|
35
|
+
const inner = (((((value + 0x9e3779b9) >>> 0) + ((seedI << 6) >>> 0)) >>> 0) + ((seedI >> 2) >>> 0)) >>> 0;
|
|
36
|
+
return hashUint32((seed ^ inner) >>> 0);
|
|
36
37
|
}
|
|
37
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
|
|
38
40
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
+
* Produces a deterministic, well-distributed 32-bit unsigned integer from any
|
|
42
|
+
* input. Useful as a stateless hash function for individual values.
|
|
41
43
|
*/
|
|
42
44
|
export function hashUint32(value) {
|
|
43
|
-
let h = value
|
|
44
|
-
h
|
|
45
|
-
h = Math.imul(h, 0x85ebca6b)
|
|
46
|
-
h
|
|
47
|
-
h = Math.imul(h, 0xc2b2ae35)
|
|
48
|
-
h
|
|
45
|
+
let h = value;
|
|
46
|
+
h = (h ^ (h >>> 16)) >>> 0;
|
|
47
|
+
h = Math.imul(h, 0x85ebca6b) >>> 0;
|
|
48
|
+
h = (h ^ (h >>> 13)) >>> 0;
|
|
49
|
+
h = Math.imul(h, 0xc2b2ae35) >>> 0;
|
|
50
|
+
h = (h ^ (h >>> 16)) >>> 0;
|
|
49
51
|
return h >>> 0;
|
|
50
52
|
}
|
|
51
53
|
//# sourceMappingURL=hash.js.map
|