@flighthq/math 0.5.1-next.3302.76ece6b → 0.5.1-next.4304.322dc96
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 +21 -6
- 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 +17 -10
- 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 +25 -14
- 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 +22 -20
- package/dist/constants.js.map +1 -1
- package/dist/contract.d.ts +16 -15
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +17 -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 +31 -29
- package/dist/hash.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- 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 +27 -18
- 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 +41 -41
- 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 +38 -37
- 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 +40 -30
- 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 +143 -137
- 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 +20 -13
- 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 +32 -26
- 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 +153 -105
- package/dist/statistics.js.map +1 -1
- package/package.json +3 -4
- package/src/angle.test.ts +57 -41
- package/src/clamp.test.ts +26 -21
- package/src/comparison.test.ts +23 -18
- package/src/constants.test.ts +63 -58
- package/src/hash.test.ts +41 -33
- package/src/interpolation.test.ts +43 -32
- package/src/interpolationAdvanced.test.ts +74 -68
- 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 +361 -280
- package/src/randomRange.test.ts +78 -62
- package/src/rounding.test.ts +45 -29
- package/src/scalar.test.ts +32 -21
- package/src/statistics.test.ts +83 -67
package/dist/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,mEAAmE;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,CAAS,EAAE,CAAS;IAC7D,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IACpD,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3G,OAAO,UAAU,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,GAAG,EACH,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,MAAM,EACN,KAAK,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,OAAO,EACP,KAAK,EACL,GAAG,EACH,MAAM,EACN,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,OAAO,EACP,WAAW,EACX,MAAM,EACN,KAAK,EACL,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,MAAM,EACN,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,UAAU,EACV,cAAc,EACd,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,cAAc,EACd,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
// Generated from crates/flight-math/src/lib.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
1
3
|
export { CIRCLE_KAPPA, DEG_TO_RAD, EPSILON, HALF_PI, RAD_TO_DEG, TAU, approxEqual, approxEqualRelative, approxZero, ceilPowerOfTwo, ceilTo, clamp, createRandomSource, createRandomSourceFromHash, damp, degToRad, deltaAngle, euclideanMod, factorial, floorPowerOfTwo, floorTo, fract, gcd, hash2D, hash3D, hashCombine, hashUint32, hypot2, inRange, inverseLerp, isEven, isOdd, isPowerOfTwo, lcm, lerp, lerpAngle, mean, median, moveTowards, nextMultipleOf, nextPowerOfTwo, normalizeAngle, pick, pingPong, previousPowerOfTwo, quantize, radToDeg, randomBool, randomExponential, randomGaussian, randomGaussianPair, randomInsideUnitDisc, randomInsideUnitSphere, randomInt, randomOnUnitCircle, randomOnUnitSphere, randomPoisson, randomRange, randomSign, randomWeighted, remap, repeat, roundTo, saturate, shuffle, shuffleInPlace, sign, smoothStep, smootherStep, standardDeviation, step, variance, weightedAverage, } from "./contract.js";
|
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,GAAG,EACH,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,MAAM,EACN,KAAK,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,OAAO,EACP,KAAK,EACL,GAAG,EACH,MAAM,EACN,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,OAAO,EACP,WAAW,EACX,MAAM,EACN,KAAK,EACL,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,MAAM,EACN,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,UAAU,EACV,cAAc,EACd,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,cAAc,EACd,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,eAAe,GAChB,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,mEAAmE;AAEnE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,GAAG,EACH,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,MAAM,EACN,KAAK,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,OAAO,EACP,KAAK,EACL,GAAG,EACH,MAAM,EACN,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,OAAO,EACP,WAAW,EACX,MAAM,EACN,KAAK,EACL,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,MAAM,EACN,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,UAAU,EACV,cAAc,EACd,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,cAAc,EACd,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,eAAe,GAChB,MAAM,eAAe,CAAC"}
|
package/dist/interpolation.d.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return the `t` value that maps to `value` in the range `[a, b]`.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* The inverse of `lerp`: `inverseLerp(a, b, lerp(a, b, t)) == t` when
|
|
5
|
+
* `a != b`. Returns `0` when `a == b` to avoid division by zero.
|
|
5
6
|
*/
|
|
6
7
|
export declare function inverseLerp(a: number, b: number, value: number): number;
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Linearly interpolate between `a` and `b` by factor `t`.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
+
* `t = 0` returns `a`; `t = 1` returns `b`. `t` is not clamped — pass a
|
|
12
|
+
* saturated `t` for clamped behaviour. Safe in hot loops, no allocation.
|
|
11
13
|
*/
|
|
12
14
|
export declare function lerp(a: number, b: number, t: number): number;
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Linearly interpolate `value` from `[inMin, inMax]` into `[outMin, outMax]`.
|
|
14
17
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
18
|
+
* Equivalent to `lerp(outMin, outMax, inverseLerp(inMin, inMax, value))`.
|
|
19
|
+
* Input range is not clamped. Returns `outMin` when `inMin == inMax`.
|
|
17
20
|
*/
|
|
18
21
|
export declare function remap(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
|
|
19
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Hermite interpolation between `edge0` and `edge1` with a smooth ease curve.
|
|
20
24
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* Returns 0 for `x <= edge0`, 1 for `x >= edge1`, and smoothly interpolates
|
|
26
|
+
* in between using `3t^2 - 2t^3`. This is the same `smoothstep` found in GLSL.
|
|
23
27
|
*/
|
|
24
28
|
export declare function smoothStep(edge0: number, edge1: number, x: number): number;
|
|
25
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Returns 0 if `x < edge`, otherwise 1. The scalar step function from GLSL.
|
|
31
|
+
*/
|
|
26
32
|
export declare function step(edge: number, x: number): number;
|
|
27
33
|
//# sourceMappingURL=interpolation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../src/interpolation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../src/interpolation.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMzG;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
package/dist/interpolation.js
CHANGED
|
@@ -1,43 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/interpolation.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
/**
|
|
4
|
+
* Return the `t` value that maps to `value` in the range `[a, b]`.
|
|
2
5
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
6
|
+
* The inverse of `lerp`: `inverseLerp(a, b, lerp(a, b, t)) == t` when
|
|
7
|
+
* `a != b`. Returns `0` when `a == b` to avoid division by zero.
|
|
5
8
|
*/
|
|
6
9
|
export function inverseLerp(a, b, value) {
|
|
7
10
|
const range = b - a;
|
|
8
|
-
return range === 0 ? 0 : (value - a) / range;
|
|
11
|
+
return range === 0.0 ? 0.0 : (value - a) / range;
|
|
9
12
|
}
|
|
10
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Linearly interpolate between `a` and `b` by factor `t`.
|
|
11
15
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
16
|
+
* `t = 0` returns `a`; `t = 1` returns `b`. `t` is not clamped — pass a
|
|
17
|
+
* saturated `t` for clamped behaviour. Safe in hot loops, no allocation.
|
|
14
18
|
*/
|
|
15
19
|
export function lerp(a, b, t) {
|
|
16
20
|
return a + (b - a) * t;
|
|
17
21
|
}
|
|
18
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Linearly interpolate `value` from `[inMin, inMax]` into `[outMin, outMax]`.
|
|
19
24
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
25
|
+
* Equivalent to `lerp(outMin, outMax, inverseLerp(inMin, inMax, value))`.
|
|
26
|
+
* Input range is not clamped. Returns `outMin` when `inMin == inMax`.
|
|
22
27
|
*/
|
|
23
28
|
export function remap(value, inMin, inMax, outMin, outMax) {
|
|
24
29
|
const inRange = inMax - inMin;
|
|
25
|
-
if (inRange === 0)
|
|
30
|
+
if (inRange === 0.0) {
|
|
26
31
|
return outMin;
|
|
32
|
+
}
|
|
27
33
|
return outMin + ((value - inMin) / inRange) * (outMax - outMin);
|
|
28
34
|
}
|
|
29
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Hermite interpolation between `edge0` and `edge1` with a smooth ease curve.
|
|
30
37
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
38
|
+
* Returns 0 for `x <= edge0`, 1 for `x >= edge1`, and smoothly interpolates
|
|
39
|
+
* in between using `3t^2 - 2t^3`. This is the same `smoothstep` found in GLSL.
|
|
33
40
|
*/
|
|
34
41
|
export function smoothStep(edge0, edge1, x) {
|
|
35
42
|
const t = (x - edge0) / (edge1 - edge0);
|
|
36
|
-
const s = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
37
|
-
return s * s * (3 - 2 * s);
|
|
43
|
+
const s = t < 0.0 ? 0.0 : t > 1.0 ? 1.0 : t;
|
|
44
|
+
return s * s * (3.0 - 2.0 * s);
|
|
38
45
|
}
|
|
39
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Returns 0 if `x < edge`, otherwise 1. The scalar step function from GLSL.
|
|
48
|
+
*/
|
|
40
49
|
export function step(edge, x) {
|
|
41
|
-
return x < edge ? 0 : 1;
|
|
50
|
+
return x < edge ? 0.0 : 1.0;
|
|
42
51
|
}
|
|
43
52
|
//# sourceMappingURL=interpolation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolation.js","sourceRoot":"","sources":["../src/interpolation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"interpolation.js","sourceRoot":"","sources":["../src/interpolation.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,mEAAmE;AAEnE;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,KAAa;IAC7D,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IAClD,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,KAAa,EAAE,KAAa,EAAE,MAAc,EAAE,MAAc;IAC/F,MAAM,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;IAC9B,IAAI,OAAO,KAAK,GAAG,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,KAAa,EAAE,CAAS;IAChE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,CAAS;IAC1C,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9B,CAAC"}
|
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Frame-rate-independent exponential decay toward `target`.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* from Freya Holmér / Game Math — it does not overshoot and is independent of
|
|
6
|
-
* frame rate. `deltaTime` should be in seconds.
|
|
4
|
+
* Equivalent to `lerp(current, target, 1 - exp(-lambda * deltaTime))`.
|
|
5
|
+
* Higher `lambda` = faster convergence. `deltaTime` should be in seconds.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
7
|
+
* Returns `current` when `deltaTime <= 0` or `lambda <= 0`.
|
|
9
8
|
*/
|
|
10
9
|
export declare function damp(current: number, target: number, lambda: number, deltaTime: number): number;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
10
|
+
/**
|
|
11
|
+
* Linearly interpolate between two angles `a` and `b` (radians) by factor `t`,
|
|
12
|
+
* taking the shortest arc.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* specific range should normalize it themselves.
|
|
14
|
+
* `t` is not clamped. The result wraps naturally; there is no explicit
|
|
15
|
+
* normalize call on the output.
|
|
17
16
|
*/
|
|
18
17
|
export declare function lerpAngle(a: number, b: number, t: number): number;
|
|
19
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Move `current` toward `target` by at most `maxDelta`, without overshooting.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* `maxDelta` should be positive; passing a negative `maxDelta` moves away
|
|
22
|
+
* from `target` instead.
|
|
23
23
|
*/
|
|
24
24
|
export declare function moveTowards(current: number, target: number, maxDelta: number): number;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Bounce `t` back and forth over `[0, length]` like a ping-pong ball.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
+
* `pingPong(t, 1)` cycles: 0 -> 1 -> 0 -> 1 -> ...
|
|
28
29
|
*/
|
|
29
30
|
export declare function pingPong(t: number, length: number): number;
|
|
30
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Wrap `t` over `[0, length)`.
|
|
31
33
|
*
|
|
32
|
-
*
|
|
34
|
+
* `repeat(1.6, 1)` -> `0.6`. Analogous to Unity's `Mathf.Repeat`.
|
|
33
35
|
*/
|
|
34
36
|
export declare function repeat(t: number, length: number): number;
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Hermite interpolation with a smoother quintic ease curve (Ken Perlin).
|
|
36
39
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* Uses `6t^5 - 15t^4 + 10t^3` — has zero first- and second-derivative at the
|
|
41
|
+
* edges, making it smoother than the cubic `smoothStep`. Returns 0 for
|
|
42
|
+
* `x <= edge0`, 1 for `x >= edge1`.
|
|
40
43
|
*/
|
|
41
44
|
export declare function smootherStep(edge0: number, edge1: number, x: number): number;
|
|
42
45
|
//# sourceMappingURL=interpolationAdvanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolationAdvanced.d.ts","sourceRoot":"","sources":["../src/interpolationAdvanced.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interpolationAdvanced.d.ts","sourceRoot":"","sources":["../src/interpolationAdvanced.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK/F;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMrF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAI5E"}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/interpolation_advanced.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
/**
|
|
4
|
+
* Frame-rate-independent exponential decay toward `target`.
|
|
2
5
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* from Freya Holmér / Game Math — it does not overshoot and is independent of
|
|
6
|
-
* frame rate. `deltaTime` should be in seconds.
|
|
6
|
+
* Equivalent to `lerp(current, target, 1 - exp(-lambda * deltaTime))`.
|
|
7
|
+
* Higher `lambda` = faster convergence. `deltaTime` should be in seconds.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* Returns `current` when `deltaTime <= 0` or `lambda <= 0`.
|
|
9
10
|
*/
|
|
10
11
|
export function damp(current, target, lambda, deltaTime) {
|
|
11
|
-
if (deltaTime <= 0 || lambda <= 0)
|
|
12
|
+
if (deltaTime <= 0.0 || lambda <= 0.0) {
|
|
12
13
|
return current;
|
|
14
|
+
}
|
|
13
15
|
return target + (current - target) * Math.exp(-lambda * deltaTime);
|
|
14
16
|
}
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* Linearly interpolate between two angles `a` and `b` (radians) by factor `t`,
|
|
19
|
+
* taking the shortest arc.
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* specific range should normalize it themselves.
|
|
21
|
+
* `t` is not clamped. The result wraps naturally; there is no explicit
|
|
22
|
+
* normalize call on the output.
|
|
21
23
|
*/
|
|
22
24
|
export function lerpAngle(a, b, t) {
|
|
23
|
-
const
|
|
24
|
-
let diff = (((b - a) %
|
|
25
|
-
if (diff > Math.PI)
|
|
26
|
-
diff -=
|
|
25
|
+
const tau = Math.PI * 2.0;
|
|
26
|
+
let diff = (((b - a) % tau) + tau) % tau;
|
|
27
|
+
if (diff > Math.PI) {
|
|
28
|
+
diff -= tau;
|
|
29
|
+
}
|
|
27
30
|
return a + diff * t;
|
|
28
31
|
}
|
|
29
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Move `current` toward `target` by at most `maxDelta`, without overshooting.
|
|
30
34
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
35
|
+
* `maxDelta` should be positive; passing a negative `maxDelta` moves away
|
|
36
|
+
* from `target` instead.
|
|
33
37
|
*/
|
|
34
38
|
export function moveTowards(current, target, maxDelta) {
|
|
35
39
|
const delta = target - current;
|
|
36
|
-
if (Math.abs(delta) <= maxDelta)
|
|
40
|
+
if (Math.abs(delta) <= maxDelta) {
|
|
37
41
|
return target;
|
|
42
|
+
}
|
|
38
43
|
return current + Math.sign(delta) * maxDelta;
|
|
39
44
|
}
|
|
40
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Bounce `t` back and forth over `[0, length]` like a ping-pong ball.
|
|
41
47
|
*
|
|
42
|
-
*
|
|
48
|
+
* `pingPong(t, 1)` cycles: 0 -> 1 -> 0 -> 1 -> ...
|
|
43
49
|
*/
|
|
44
50
|
export function pingPong(t, length) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// layer, not from silent coercion here.
|
|
49
|
-
const cycle = 2 * length;
|
|
50
|
-
const mod = ((t % cycle) + cycle) % cycle;
|
|
51
|
-
return mod <= length ? mod : cycle - mod;
|
|
51
|
+
const cycle = 2.0 * length;
|
|
52
|
+
const modulo = ((t % cycle) + cycle) % cycle;
|
|
53
|
+
return modulo <= length ? modulo : cycle - modulo;
|
|
52
54
|
}
|
|
53
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Wrap `t` over `[0, length)`.
|
|
54
57
|
*
|
|
55
|
-
*
|
|
58
|
+
* `repeat(1.6, 1)` -> `0.6`. Analogous to Unity's `Mathf.Repeat`.
|
|
56
59
|
*/
|
|
57
60
|
export function repeat(t, length) {
|
|
58
|
-
// No guard on a non-positive length: the arithmetic yields NaN and NaN PROPAGATES. These functions do not
|
|
59
|
-
// invent values — a silent 0 turns a loud upstream failure into a plausible number, and IEEE propagation
|
|
60
|
-
// lowers for free where an explicit branch does not. Callers who want a warning get one from a guard
|
|
61
|
-
// layer, not from silent coercion here.
|
|
62
61
|
return ((t % length) + length) % length;
|
|
63
62
|
}
|
|
64
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Hermite interpolation with a smoother quintic ease curve (Ken Perlin).
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
66
|
+
* Uses `6t^5 - 15t^4 + 10t^3` — has zero first- and second-derivative at the
|
|
67
|
+
* edges, making it smoother than the cubic `smoothStep`. Returns 0 for
|
|
68
|
+
* `x <= edge0`, 1 for `x >= edge1`.
|
|
69
69
|
*/
|
|
70
70
|
export function smootherStep(edge0, edge1, x) {
|
|
71
71
|
const t = (x - edge0) / (edge1 - edge0);
|
|
72
|
-
const s = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
73
|
-
return s * s * s * (s * (s * 6 - 15) + 10);
|
|
72
|
+
const s = t < 0.0 ? 0.0 : t > 1.0 ? 1.0 : t;
|
|
73
|
+
return s * s * s * (s * (s * 6.0 - 15.0) + 10.0);
|
|
74
74
|
}
|
|
75
75
|
//# sourceMappingURL=interpolationAdvanced.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolationAdvanced.js","sourceRoot":"","sources":["../src/interpolationAdvanced.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"interpolationAdvanced.js","sourceRoot":"","sources":["../src/interpolationAdvanced.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,mEAAmE;AAEnE;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe,EAAE,MAAc,EAAE,MAAc,EAAE,SAAiB;IACrF,IAAI,SAAS,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IACvD,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;IAC1B,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACzC,IAAI,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACnB,IAAI,IAAI,GAAG,CAAC;IACd,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,QAAgB;IAC3E,MAAM,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,MAAc;IAChD,MAAM,KAAK,GAAG,GAAG,GAAG,MAAM,CAAC;IAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;IAC7C,OAAO,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,MAAc;IAC9C,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa,EAAE,CAAS;IAClE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/nextPowerOfTwo.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return `true` if `n` is an integer power of two (i.e. 1, 2, 4, 8, ...).
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
+
* Returns `false` for `n <= 0`.
|
|
4
5
|
*/
|
|
5
6
|
export declare function isPowerOfTwo(n: number): boolean;
|
|
6
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Round `value` up to the nearest multiple of `multiple`.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* `nextMultipleOf(7.0, 4.0)` -> `8.0`. When `multiple <= 0` the result is `value`.
|
|
9
11
|
*/
|
|
10
12
|
export declare function nextMultipleOf(value: number, multiple: number): number;
|
|
11
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Round `n` up to the next power of two.
|
|
12
15
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
16
|
+
* Uses integer bit-twiddling for stability on large values. Returns `1` for
|
|
17
|
+
* `n <= 1`.
|
|
15
18
|
*/
|
|
16
19
|
export declare function nextPowerOfTwo(n: number): number;
|
|
17
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Round `n` down to the largest power of two that is `<= n`.
|
|
18
22
|
*
|
|
19
|
-
*
|
|
23
|
+
* `previousPowerOfTwo(6)` -> `4`. Returns `1` for `n <= 1`.
|
|
20
24
|
*/
|
|
21
25
|
export declare function previousPowerOfTwo(n: number): number;
|
|
22
26
|
//# sourceMappingURL=nextPowerOfTwo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextPowerOfTwo.d.ts","sourceRoot":"","sources":["../src/nextPowerOfTwo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nextPowerOfTwo.d.ts","sourceRoot":"","sources":["../src/nextPowerOfTwo.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMtE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWhD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWpD"}
|
package/dist/nextPowerOfTwo.js
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
// Generated from crates/flight-math/src/next_power_of_two.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
/**
|
|
4
|
+
* Return `true` if `n` is an integer power of two (i.e. 1, 2, 4, 8, ...).
|
|
2
5
|
*
|
|
3
|
-
*
|
|
6
|
+
* Returns `false` for `n <= 0`.
|
|
4
7
|
*/
|
|
5
8
|
export function isPowerOfTwo(n) {
|
|
6
9
|
return n > 0 && (n & (n - 1)) === 0;
|
|
7
10
|
}
|
|
8
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Round `value` up to the nearest multiple of `multiple`.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
14
|
+
* `nextMultipleOf(7.0, 4.0)` -> `8.0`. When `multiple <= 0` the result is `value`.
|
|
11
15
|
*/
|
|
12
16
|
export function nextMultipleOf(value, multiple) {
|
|
13
|
-
if (multiple <= 0)
|
|
17
|
+
if (multiple <= 0.0) {
|
|
14
18
|
return value;
|
|
19
|
+
}
|
|
15
20
|
const remainder = value % multiple;
|
|
16
|
-
return remainder === 0 ? value : value + multiple - remainder;
|
|
21
|
+
return remainder === 0.0 ? value : value + multiple - remainder;
|
|
17
22
|
}
|
|
18
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Round `n` up to the next power of two.
|
|
19
25
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
26
|
+
* Uses integer bit-twiddling for stability on large values. Returns `1` for
|
|
27
|
+
* `n <= 1`.
|
|
22
28
|
*/
|
|
23
29
|
export function nextPowerOfTwo(n) {
|
|
24
|
-
if (n <= 1)
|
|
25
|
-
return 1;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return (n + 1) >>> 0;
|
|
30
|
+
if (n <= 1) {
|
|
31
|
+
return 1 >>> 0;
|
|
32
|
+
}
|
|
33
|
+
let v = (n - 1) >>> 0;
|
|
34
|
+
v |= v >>> 1;
|
|
35
|
+
v |= v >>> 2;
|
|
36
|
+
v |= v >>> 4;
|
|
37
|
+
v |= v >>> 8;
|
|
38
|
+
v |= v >>> 16;
|
|
39
|
+
return ((v + 1) >>> 0) >>> 0;
|
|
35
40
|
}
|
|
36
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Round `n` down to the largest power of two that is `<= n`.
|
|
37
43
|
*
|
|
38
|
-
*
|
|
44
|
+
* `previousPowerOfTwo(6)` -> `4`. Returns `1` for `n <= 1`.
|
|
39
45
|
*/
|
|
40
46
|
export function previousPowerOfTwo(n) {
|
|
41
|
-
if (n <= 1)
|
|
42
|
-
return 1;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
n |= n >> 2;
|
|
52
|
-
n |= n >> 4;
|
|
53
|
-
n |= n >> 8;
|
|
54
|
-
n |= n >> 16;
|
|
55
|
-
return (n + 1) >>> 1;
|
|
47
|
+
if (n <= 1) {
|
|
48
|
+
return 1 >>> 0;
|
|
49
|
+
}
|
|
50
|
+
let v = n;
|
|
51
|
+
v |= v >> 1;
|
|
52
|
+
v |= v >> 2;
|
|
53
|
+
v |= v >> 4;
|
|
54
|
+
v |= v >> 8;
|
|
55
|
+
v |= v >> 16;
|
|
56
|
+
return ((((v >>> 0) + 1) >>> 0) >>> 1) >>> 0;
|
|
56
57
|
}
|
|
57
58
|
//# sourceMappingURL=nextPowerOfTwo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextPowerOfTwo.js","sourceRoot":"","sources":["../src/nextPowerOfTwo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nextPowerOfTwo.js","sourceRoot":"","sources":["../src/nextPowerOfTwo.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,mEAAmE;AAEnE;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,QAAgB;IAC5D,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;IACnC,OAAO,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,CAAS;IACtC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACb,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACb,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACb,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACb,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAS;IAC1C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACZ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
package/dist/numberTheory.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return the factorial of non-negative integer `n`.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* (above IEEE 754 double precision range).
|
|
4
|
+
* `factorial(0)` -> `1` by convention. Throws for negative inputs.
|
|
5
|
+
* Returns positive infinity for `n > 170` (above the IEEE 754 double-precision range).
|
|
6
6
|
*/
|
|
7
7
|
export declare function factorial(n: number): number;
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Return the greatest common divisor of `a` and `b` (Euclidean algorithm).
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Operates on the absolute values of the inputs, so negative arguments are
|
|
12
|
+
* accepted. Throws when both `a` and `b` are `0` (the GCD of zero and zero
|
|
13
|
+
* is undefined).
|
|
13
14
|
*/
|
|
14
15
|
export declare function gcd(a: number, b: number): number;
|
|
15
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Return the squared distance `x^2 + y^2`.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* the actual distance value is not needed.
|
|
19
|
+
* Allocation-free substitute for squaring `hypot(x, y)` when you only need
|
|
20
|
+
* to compare distances.
|
|
20
21
|
*/
|
|
21
22
|
export declare function hypot2(x: number, y: number): number;
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Return `true` if `n` is even.
|
|
25
|
+
*/
|
|
23
26
|
export declare function isEven(n: number): boolean;
|
|
24
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Return `true` if `n` is odd.
|
|
29
|
+
*/
|
|
25
30
|
export declare function isOdd(n: number): boolean;
|
|
26
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Return the least common multiple of `a` and `b`.
|
|
27
33
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* `Number.MAX_SAFE_INTEGER` and lose precision.
|
|
34
|
+
* Operates on the absolute values of the inputs. Throws when both `a` and
|
|
35
|
+
* `b` are `0` (see `gcd`).
|
|
31
36
|
*/
|
|
32
37
|
export declare function lcm(a: number, b: number): number;
|
|
33
38
|
//# sourceMappingURL=numberTheory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberTheory.d.ts","sourceRoot":"","sources":["../src/numberTheory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"numberTheory.d.ts","sourceRoot":"","sources":["../src/numberTheory.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAc3C;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYhD;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,GAAG,OAAO,CAEzC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAExC;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|