@flighthq/math 0.5.1-next.920.da8f530 → 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.
Files changed (93) hide show
  1. package/README.md +2 -2
  2. package/dist/angle.d.ts +13 -6
  3. package/dist/angle.d.ts.map +1 -1
  4. package/dist/angle.js +22 -7
  5. package/dist/angle.js.map +1 -1
  6. package/dist/clamp.d.ts +11 -7
  7. package/dist/clamp.d.ts.map +1 -1
  8. package/dist/clamp.js +15 -8
  9. package/dist/clamp.js.map +1 -1
  10. package/dist/comparison.d.ts +13 -9
  11. package/dist/comparison.d.ts.map +1 -1
  12. package/dist/comparison.js +26 -15
  13. package/dist/comparison.js.map +1 -1
  14. package/dist/constants.d.ts +17 -17
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js +18 -16
  17. package/dist/constants.js.map +1 -1
  18. package/dist/contract.d.ts +17 -15
  19. package/dist/contract.d.ts.map +1 -1
  20. package/dist/contract.js +15 -15
  21. package/dist/contract.js.map +1 -1
  22. package/dist/hash.d.ts +19 -21
  23. package/dist/hash.d.ts.map +1 -1
  24. package/dist/hash.js +32 -30
  25. package/dist/hash.js.map +1 -1
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/interpolation.d.ts +19 -13
  31. package/dist/interpolation.d.ts.map +1 -1
  32. package/dist/interpolation.js +23 -14
  33. package/dist/interpolation.js.map +1 -1
  34. package/dist/interpolationAdvanced.d.ts +25 -22
  35. package/dist/interpolationAdvanced.d.ts.map +1 -1
  36. package/dist/interpolationAdvanced.js +38 -38
  37. package/dist/interpolationAdvanced.js.map +1 -1
  38. package/dist/nextPowerOfTwo.d.ts +13 -9
  39. package/dist/nextPowerOfTwo.d.ts.map +1 -1
  40. package/dist/nextPowerOfTwo.js +35 -34
  41. package/dist/nextPowerOfTwo.js.map +1 -1
  42. package/dist/numberTheory.d.ts +23 -18
  43. package/dist/numberTheory.d.ts.map +1 -1
  44. package/dist/numberTheory.js +38 -28
  45. package/dist/numberTheory.js.map +1 -1
  46. package/dist/random.d.ts +9 -16
  47. package/dist/random.d.ts.map +1 -1
  48. package/dist/random.js +14 -21
  49. package/dist/random.js.map +1 -1
  50. package/dist/randomDistributions.d.ts +54 -75
  51. package/dist/randomDistributions.d.ts.map +1 -1
  52. package/dist/randomDistributions.js +134 -128
  53. package/dist/randomDistributions.js.map +1 -1
  54. package/dist/randomRange.d.ts +13 -8
  55. package/dist/randomRange.d.ts.map +1 -1
  56. package/dist/randomRange.js +19 -12
  57. package/dist/randomRange.js.map +1 -1
  58. package/dist/rounding.d.ts +18 -19
  59. package/dist/rounding.d.ts.map +1 -1
  60. package/dist/rounding.js +31 -25
  61. package/dist/rounding.js.map +1 -1
  62. package/dist/rustTestSupport.d.ts +5 -0
  63. package/dist/rustTestSupport.d.ts.map +1 -0
  64. package/dist/rustTestSupport.js +14 -0
  65. package/dist/rustTestSupport.js.map +1 -0
  66. package/dist/scalar.d.ts +15 -18
  67. package/dist/scalar.d.ts.map +1 -1
  68. package/dist/scalar.js +24 -23
  69. package/dist/scalar.js.map +1 -1
  70. package/dist/statistics.d.ts +18 -13
  71. package/dist/statistics.d.ts.map +1 -1
  72. package/dist/statistics.js +142 -94
  73. package/dist/statistics.js.map +1 -1
  74. package/dist/types.d.ts +2 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +4 -5
  79. package/src/angle.test.ts +55 -41
  80. package/src/clamp.test.ts +23 -18
  81. package/src/comparison.test.ts +22 -17
  82. package/src/constants.test.ts +61 -58
  83. package/src/hash.test.ts +41 -33
  84. package/src/interpolation.test.ts +41 -30
  85. package/src/interpolationAdvanced.test.ts +61 -57
  86. package/src/nextPowerOfTwo.test.ts +45 -46
  87. package/src/numberTheory.test.ts +44 -41
  88. package/src/random.test.ts +51 -21
  89. package/src/randomDistributions.test.ts +355 -271
  90. package/src/randomRange.test.ts +76 -60
  91. package/src/rounding.test.ts +45 -29
  92. package/src/scalar.test.ts +32 -21
  93. 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.5.1-next.920.da8f530](https://github.com/flighthq/flight/tree/da8f530894916f9baa6a9f6822b4f393b9e70a85/packages/math)
17
- - [License](https://github.com/flighthq/flight/blob/da8f530894916f9baa6a9f6822b4f393b9e70a85/LICENSE.md)
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
- /** Convert `degrees` to radians. */
1
+ /**
2
+ * Convert `degrees` to radians.
3
+ */
2
4
  export declare function degToRad(degrees: number): number;
3
- /** Return the shortest signed difference between angles `from` and `to` (radians).
5
+ /**
6
+ * Return the shortest signed difference between angles `from` and `to` (radians).
4
7
  *
5
- * The result is in `(-π, π]`. Useful for rotating a value toward a target by
6
- * the minimum arc.
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
- /** Wrap `radians` to the range `[-π, π)`. */
12
+ /**
13
+ * Wrap `radians` to the range `[-pi, pi)`.
14
+ */
10
15
  export declare function normalizeAngle(radians: number): number;
11
- /** Convert `radians` to degrees. */
16
+ /**
17
+ * Convert `radians` to degrees.
18
+ */
12
19
  export declare function radToDeg(radians: number): number;
13
20
  //# sourceMappingURL=angle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"angle.d.ts","sourceRoot":"","sources":["../src/angle.ts"],"names":[],"mappings":"AAEA,oCAAoC;AACpC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,oCAAoC;AACpC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD"}
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
- import { DEG_TO_RAD, RAD_TO_DEG, TAU } from './constants';
2
- /** Convert `degrees` to radians. */
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
- /** Return the shortest signed difference between angles `from` and `to` (radians).
10
+ /**
11
+ * Return the shortest signed difference between angles `from` and `to` (radians).
7
12
  *
8
- * The result is in `(-π, π]`. Useful for rotating a value toward a target by
9
- * the minimum arc.
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
- /** Wrap `radians` to the range `[-π, π)`. */
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
- /** Convert `radians` to degrees. */
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,aAAa,CAAC;AAE1D,oCAAoC;AACpC,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,OAAO,GAAG,UAAU,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,EAAU;IACjD,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,CA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AAO,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
- /** Clamp `value` to the inclusive range `[min, max]`.
1
+ /**
2
+ * Clamp `value` to the inclusive range `[min, max]`.
2
3
  *
3
- * When `min > max` the result is `min`. NaN propagates unchanged.
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
- /** Return `true` if `value` is within the inclusive range `[min, max]`. */
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
- /** Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
11
+ /**
12
+ * Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
9
13
  *
10
- * Named `saturate` after the GPU HLSL/GLSL convention. Follows GPU semantics:
11
- * NaN returns 0 (unlike `clamp`, which propagates NaN). Safe in hot loops,
12
- * no allocation.
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
@@ -1 +1 @@
1
- {"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,2EAA2E;AAC3E,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAExE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG9C"}
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
- /** Clamp `value` to the inclusive range `[min, max]`.
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
- * When `min > max` the result is `min`. NaN propagates unchanged.
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
- /** Return `true` if `value` is within the inclusive range `[min, max]`. */
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
- /** Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
17
+ /**
18
+ * Clamp `value` to `[0, 1]`. Equivalent to `clamp(value, 0, 1)`.
13
19
  *
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.
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 !== 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;;;GAGG;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,2EAA2E;AAC3E,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC7D,OAAO,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,CAAC;IAC9B,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"}
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"}
@@ -1,17 +1,21 @@
1
- /** Return `true` if `|a - b| <= epsilon`.
1
+ /**
2
+ * Return `true` if `|a - b| <= epsilon`.
2
3
  *
3
- * Uses an absolute epsilon, appropriate for values near zero. For magnitudes
4
- * much larger than 1, use `approxEqualRelative`. Defaults to the SDK `EPSILON`.
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
- /** Return `true` if `a` and `b` agree to within a relative tolerance.
8
+ /**
9
+ * Return `true` if `a` and `b` agree to within a relative tolerance.
8
10
  *
9
- * Uses `|a - b| <= relativeEpsilon * max(|a|, |b|)`, which scales with
10
- * magnitude and is appropriate for large numbers where absolute epsilon
11
- * comparisons fail. For values near zero, falls back to `EPSILON`
12
- * (absolute). Defaults to `EPSILON` for `relativeEpsilon`.
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
- /** Return `true` if `|value| <= epsilon`. */
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
@@ -1 +1 @@
1
- {"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAgB,GAAG,OAAO,CAEpF;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,GAAE,MAAgB,GAAG,OAAO,CAIpG;AAED,6CAA6C;AAC7C,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAAgB,GAAG,OAAO,CAE5E"}
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"}
@@ -1,26 +1,37 @@
1
- import { EPSILON } from './constants';
2
- /** Return `true` if `|a - b| <= epsilon`.
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
- * Uses an absolute epsilon, appropriate for values near zero. For magnitudes
5
- * much larger than 1, use `approxEqualRelative`. Defaults to the SDK `EPSILON`.
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 = EPSILON) {
10
+ export function approxEqual(a, b, epsilon) {
11
+ epsilon = epsilon ?? EPSILON;
8
12
  return Math.abs(a - b) <= epsilon;
9
13
  }
10
- /** Return `true` if `a` and `b` agree to within a relative tolerance.
14
+ /**
15
+ * Return `true` if `a` and `b` agree to within a relative tolerance.
11
16
  *
12
- * Uses `|a - b| <= relativeEpsilon * max(|a|, |b|)`, which scales with
13
- * magnitude and is appropriate for large numbers where absolute epsilon
14
- * comparisons fail. For values near zero, falls back to `EPSILON`
15
- * (absolute). Defaults to `EPSILON` for `relativeEpsilon`.
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 = EPSILON) {
22
+ export function approxEqualRelative(a, b, relativeEpsilon) {
23
+ relativeEpsilon = relativeEpsilon ?? EPSILON;
18
24
  const diff = Math.abs(a - b);
19
- const largest = Math.max(Math.abs(a), Math.abs(b));
20
- return diff <= Math.max(relativeEpsilon * largest, EPSILON);
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
- /** Return `true` if `|value| <= epsilon`. */
23
- export function approxZero(value, epsilon = EPSILON) {
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
@@ -1 +1 @@
1
- {"version":3,"file":"comparison.js","sourceRoot":"","sources":["../src/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,UAAkB,OAAO;IACzE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAS,EAAE,CAAS,EAAE,kBAA0B,OAAO;IACzF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,UAAkB,OAAO;IACjE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC;AACpC,CAAC"}
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"}
@@ -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 = 0.5522847498307936;
16
- /** Default absolute tolerance for approximate floating-point comparisons. */
17
- export declare const EPSILON = 0.000001;
18
- /** Full circle in radians (2π). Prefer `TAU` over `2 * Math.PI` for clarity. */
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
- /** Half of π (π / 2). */
14
+ /**
15
+ * Half of pi (pi / 2).
16
+ */
21
17
  export declare const HALF_PI: number;
22
- /** Multiply degrees by this constant to get radians. */
18
+ /**
19
+ * Multiply degrees by this constant to get radians.
20
+ */
23
21
  export declare const DEG_TO_RAD: number;
24
- /** Multiply radians by this constant to get degrees. */
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
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAE/C,6EAA6E;AAC7E,eAAO,MAAM,OAAO,WAAO,CAAC;AAE5B,gFAAgF;AAChF,eAAO,MAAM,GAAG,QAAc,CAAC;AAE/B,yBAAyB;AACzB,eAAO,MAAM,OAAO,QAAc,CAAC;AAEnC,wDAAwD;AACxD,eAAO,MAAM,UAAU,QAAgB,CAAC;AAExC,wDAAwD;AACxD,eAAO,MAAM,UAAU,QAAgB,CAAC"}
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.5522847498307936;
16
- /** Default absolute tolerance for approximate floating-point comparisons. */
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
- /** Full circle in radians (2π). Prefer `TAU` over `2 * Math.PI` for clarity. */
12
+ /**
13
+ * Full circle in radians (2pi).
14
+ */
19
15
  export const TAU = Math.PI * 2;
20
- /** Half of π (π / 2). */
16
+ /**
17
+ * Half of pi (pi / 2).
18
+ */
21
19
  export const HALF_PI = Math.PI / 2;
22
- /** Multiply degrees by this constant to get radians. */
20
+ /**
21
+ * Multiply degrees by this constant to get radians.
22
+ */
23
23
  export const DEG_TO_RAD = Math.PI / 180;
24
- /** Multiply radians by this constant to get degrees. */
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
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAE/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAE5B,gFAAgF;AAChF,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAE/B,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAEnC,wDAAwD;AACxD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;AAExC,wDAAwD;AACxD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC"}
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"}
@@ -1,16 +1,18 @@
1
- export * from './angle';
2
- export * from './clamp';
3
- export * from './comparison';
4
- export * from './constants';
5
- export * from './hash';
6
- export * from './interpolation';
7
- export * from './interpolationAdvanced';
8
- export * from './nextPowerOfTwo';
9
- export * from './numberTheory';
10
- export * from './random';
11
- export * from './randomDistributions';
12
- export * from './randomRange';
13
- export * from './rounding';
14
- export * from './scalar';
15
- export * from './statistics';
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
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,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,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- export * from './comparison';
4
- export * from './constants';
5
- export * from './hash';
6
- export * from './interpolation';
7
- export * from './interpolationAdvanced';
8
- export * from './nextPowerOfTwo';
9
- export * from './numberTheory';
10
- export * from './random';
11
- export * from './randomDistributions';
12
- export * from './randomRange';
13
- export * from './rounding';
14
- export * from './scalar';
15
- export * from './statistics';
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
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CA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,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 '@flighthq/types/contract';
2
- /** Create a `RandomSource` seeded from a deterministic hash of `x` and `y`.
1
+ import type { RandomSource } from './random.ts';
2
+ /**
3
+ * Create a `RandomSource` seeded from a deterministic hash of `x` and `y`.
3
4
  *
4
- * Connects the stateless hash layer to the seeded-PRNG layer — each grid
5
- * cell gets an independent reproducible random stream.
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
- /** Stateless position-seeded hash over a 2D integer grid.
9
+ /**
10
+ * Stateless position-seeded hash over a 2D integer grid.
14
11
  *
15
- * Returns a deterministic `number` in `[0, 2³²)`. Suitable for procedural
16
- * tile/cell content and gradient noise seed generation.
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
- /** Stateless position-seeded hash over a 3D integer grid. */
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
- /** Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
20
+ /**
21
+ * Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
22
22
  *
23
- * Used to build multi-dimensional hashes from `hashUint32`:
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
- /** Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
26
+ /**
27
+ * Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
30
28
  *
31
- * Produces a deterministic, well-distributed 32-bit unsigned integer from any
32
- * input. Useful as a stateless hash function for individual values.
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
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,6DAA6D;AAC7D,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD"}
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
- import { createRandomSource } from './random';
2
- /** Create a `RandomSource` seeded from a deterministic hash of `x` and `y`.
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
- * Connects the stateless hash layer to the seeded-PRNG layer — each grid
5
- * cell gets an independent reproducible random stream.
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
- /** Stateless position-seeded hash over a 2D integer grid.
13
+ /**
14
+ * Stateless position-seeded hash over a 2D integer grid.
16
15
  *
17
- * Returns a deterministic `number` in `[0, 2³²)`. Suitable for procedural
18
- * tile/cell content and gradient noise seed generation.
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 | 0), y | 0);
20
+ return hashCombine(hashUint32(x >>> 0), y >>> 0);
22
21
  }
23
- /** Stateless position-seeded hash over a 3D integer grid. */
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 | 0);
26
+ return hashCombine(hash2D(x, y), z >>> 0);
26
27
  }
27
- /** Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
28
+ /**
29
+ * Combine a running hash `seed` with a new `value` using a Murmur3-inspired mix.
28
30
  *
29
- * Used to build multi-dimensional hashes from `hashUint32`:
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
- return hashUint32(seed ^ (value + 0x9e3779b9 + (seed << 6) + (seed >> 2)));
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
- /** Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
38
+ /**
39
+ * Finalise an arbitrary 32-bit integer through the fmix32 finalizer (Murmur3).
38
40
  *
39
- * Produces a deterministic, well-distributed 32-bit unsigned integer from any
40
- * input. Useful as a stateless hash function for individual values.
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 | 0;
44
- h ^= h >>> 16;
45
- h = Math.imul(h, 0x85ebca6b) | 0;
46
- h ^= h >>> 13;
47
- h = Math.imul(h, 0xc2b2ae35) | 0;
48
- h ^= h >>> 16;
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