@flighthq/math 0.3.1-next.407.d03a0bb → 0.3.1-next.425.a3192ab

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.
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Control-point distance, as a fraction of the radius, for approximating a quarter circle with one
3
+ * cubic Bezier: `4 * (sqrt(2) - 1) / 3`.
4
+ *
5
+ * Named for the circle that defines it rather than the arcs that use it. It is computed rather than
6
+ * written out because a transcribed decimal is a second copy of a number nothing recomputes — the
7
+ * digits are long enough that a wrong one reads as correct and draws a circle that still looks round.
8
+ */
9
+ export declare const CIRCLE_KAPPA: number;
1
10
  /** Smallest positive number distinguishable from zero in floating-point comparisons. */
2
11
  export declare const EPSILON = 0.000001;
3
12
  /** Full circle in radians (2π). Prefer `TAU` over `2 * Math.PI` for clarity. */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,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":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAEvD,wFAAwF;AACxF,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"}
package/dist/constants.js CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Control-point distance, as a fraction of the radius, for approximating a quarter circle with one
3
+ * cubic Bezier: `4 * (sqrt(2) - 1) / 3`.
4
+ *
5
+ * Named for the circle that defines it rather than the arcs that use it. It is computed rather than
6
+ * written out because a transcribed decimal is a second copy of a number nothing recomputes — the
7
+ * digits are long enough that a wrong one reads as correct and draws a circle that still looks round.
8
+ */
9
+ export const CIRCLE_KAPPA = (4 * (Math.SQRT2 - 1)) / 3;
1
10
  /** Smallest positive number distinguishable from zero in floating-point comparisons. */
2
11
  export const EPSILON = 1e-6;
3
12
  /** Full circle in radians (2π). Prefer `TAU` over `2 * Math.PI` for clarity. */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,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;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEvD,wFAAwF;AACxF,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"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { 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';
1
+ 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';
2
2
  export type { RandomSource } from './contract';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,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,YAAY,CAAC;AAKpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","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,YAAY,CAAC;AAKpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { 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';
1
+ 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';
2
2
  //# 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,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,YAAY,CAAC"}
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,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/math",
3
- "version": "0.3.1-next.407.d03a0bb",
3
+ "version": "0.3.1-next.425.a3192ab",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/types": "0.3.1-next.407.d03a0bb"
41
+ "@flighthq/types": "0.3.1-next.425.a3192ab"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "^5.3.0"
@@ -1,6 +1,31 @@
1
- import { DEG_TO_RAD, EPSILON, HALF_PI, RAD_TO_DEG, TAU } from './constants';
1
+ import { CIRCLE_KAPPA, DEG_TO_RAD, EPSILON, HALF_PI, RAD_TO_DEG, TAU } from './constants';
2
2
 
3
3
  describe('constants', () => {
4
+ describe('CIRCLE_KAPPA', () => {
5
+ // Asserted against the COMPUTED expression, never a transcribed decimal. A test that restates the
6
+ // digits agrees with a typo in them, which is how a wrong digit at the 13th decimal survived a
7
+ // full suite. Exact equality, not toBeCloseTo: the error this guards against is far smaller than
8
+ // any tolerance worth writing.
9
+ it('equals four thirds of the square root of two less one', () => {
10
+ expect(CIRCLE_KAPPA).toBe((4 * (Math.sqrt(2) - 1)) / 3);
11
+ });
12
+
13
+ it('sweeps a unit quarter circle when used as the cubic control distance', () => {
14
+ // Catches a wrong FORMULA, not a wrong digit — and only that. A mistyped decimal moves the
15
+ // swept radius far less than the cubic's own approximation error, so this cannot stand in for
16
+ // the exact equality above. What it does add is independence from it: if the constant and that
17
+ // assertion were ever edited to agree on a wrong expression, the geometry would still object.
18
+ const radiusAt = (t: number): number => {
19
+ const u = 1 - t;
20
+ const x = u * u * u + 3 * u * u * t + 3 * u * t * t * CIRCLE_KAPPA;
21
+ const y = 3 * u * u * t * CIRCLE_KAPPA + 3 * u * t * t + t * t * t;
22
+ return Math.hypot(x, y);
23
+ };
24
+
25
+ for (const t of [0, 0.25, 0.5, 0.75, 1]) expect(radiusAt(t)).toBeCloseTo(1, 3);
26
+ });
27
+ });
28
+
4
29
  describe('DEG_TO_RAD', () => {
5
30
  it('converts 180 degrees to π', () => {
6
31
  expect(180 * DEG_TO_RAD).toBeCloseTo(Math.PI, 10);