@woosh/meep-engine 2.43.13 → 2.43.14

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 (85) hide show
  1. package/core/bvh2/aabb3/aabb3_detailed_volume_intersection.js +1 -1
  2. package/core/bvh2/traversal/__process_point_if_within_planes.js +1 -1
  3. package/core/geom/3d/plane/is_point_within_planes.js +1 -1
  4. package/core/geom/3d/plane/plane3_slerp.js +1 -1
  5. package/core/geom/3d/topology/computeTopoMeshVertexDuplicates.js +2 -1
  6. package/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +1 -1
  7. package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
  8. package/core/geom/3d/topology/weld_duplicate_vertices.js +1 -1
  9. package/core/geom/ConicRay.js +2 -1
  10. package/core/geom/Quaternion.js +2 -1
  11. package/core/geom/Vector3.js +5 -2
  12. package/core/geom/normalize_angle_rad.js +1 -1
  13. package/core/geom/random/randomPointInCircle.js +1 -1
  14. package/core/geom/random/randomPointInSphere.js +1 -1
  15. package/core/math/EPSILON.js +5 -0
  16. package/core/math/PI2.js +5 -0
  17. package/core/math/PI_HALF.js +5 -0
  18. package/core/math/bezierCurve.js +22 -0
  19. package/core/math/clamp.spec.js +15 -0
  20. package/core/math/computeGreatestCommonDivisor.js +28 -0
  21. package/core/math/computeIsoscelesTriangleApexAngle.js +17 -0
  22. package/core/math/computeWholeDivisorLow.js +30 -0
  23. package/core/math/computeWholeDivisorLow.spec.js +9 -0
  24. package/core/math/copysign.spec.js +13 -0
  25. package/core/math/cubicCurve.js +34 -0
  26. package/core/math/cubicCurve.spec.js +13 -0
  27. package/core/math/{MathUtils.d.ts → epsilonEquals.d.ts} +0 -0
  28. package/core/math/epsilonEquals.js +16 -0
  29. package/core/math/hash/computeHashFloat.spec.js +7 -0
  30. package/core/math/inverseLerp.spec.js +13 -0
  31. package/core/math/isValueBetween.spec.js +11 -0
  32. package/core/math/isValueBetweenInclusive.spec.js +16 -0
  33. package/core/math/lerp.spec.js +15 -0
  34. package/core/math/makeCubicCurve.js +15 -0
  35. package/core/math/makeCubicCurve.spec.js +9 -0
  36. package/core/math/makeSequenceLoop.js +20 -0
  37. package/core/math/max2.spec.js +13 -0
  38. package/core/math/max3.spec.js +27 -0
  39. package/core/math/min2.spec.js +12 -0
  40. package/core/math/min3.spec.js +27 -0
  41. package/core/math/normalizeArrayVector.js +25 -0
  42. package/core/math/overlap1D.spec.js +10 -0
  43. package/core/math/quadraticCurve.js +11 -0
  44. package/core/math/quadraticCurve.spec.js +13 -0
  45. package/core/math/sign.spec.js +13 -0
  46. package/core/model/stat/Stat.js +2 -1
  47. package/engine/EngineHarness.js +5 -23
  48. package/engine/achievements/AchievementManager.js +1 -1
  49. package/engine/animation/TransitionFunctions.js +1 -1
  50. package/engine/ecs/gui/position/ViewportPositionSystem.js +1 -1
  51. package/engine/ecs/systems/SteeringSystem.js +1 -1
  52. package/engine/ecs/terrain/ecs/Terrain.d.ts +7 -0
  53. package/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +68 -0
  54. package/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationAdapter.js +31 -0
  55. package/engine/ecs/terrain/ecs/{ClingToTerrainSystem.js → cling/ClingToTerrainSystem.js} +52 -34
  56. package/engine/ecs/terrain/ecs/{ClingToTerrainSystem.spec.js → cling/ClingToTerrainSystem.spec.js} +1 -1
  57. package/engine/graphics/camera/CameraShake.js +1 -1
  58. package/engine/graphics/camera/testClippingPlaneComputation.js +1 -1
  59. package/engine/graphics/ecs/path/entity/EntityPath.js +1 -1
  60. package/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -1
  61. package/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +4 -2
  62. package/engine/graphics/geometry/MikkT/NotZero.js +1 -1
  63. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +14 -288
  64. package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +1 -1
  65. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  66. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +1 -1
  67. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  68. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
  69. package/engine/graphics/shadows/testShadowMapRendering.js +1 -1
  70. package/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
  71. package/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +1 -1
  72. package/generation/example/themes/SampleTheme0.js +2 -2
  73. package/generation/grid/generation/GridTaskExecuteRuleTimes.js +1 -1
  74. package/generation/grid/generation/grid/select/CellSupplierBestN.js +1 -1
  75. package/generation/markers/GridActionRuleSet.js +1 -1
  76. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  77. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.js +2 -1
  78. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.js +2 -1
  79. package/package.json +1 -1
  80. package/view/elements/radial/RadialMenuElement.js +1 -1
  81. package/view/elements/radial/RadialText.js +1 -1
  82. package/view/tooltip/TooltipView.js +1 -1
  83. package/core/math/MathUtils.js +0 -247
  84. package/core/math/MathUtils.spec.js +0 -232
  85. package/engine/ecs/terrain/ecs/ClingToTerrain.js +0 -100
@@ -4,9 +4,9 @@ import { plane3_computeLineSegmentIntersection } from "../../geom/Plane.js";
4
4
  import { aabb3_corner_edge_mapping } from "./aabb3_corner_edge_mapping.js";
5
5
  import { aabb3_edge_corner_mapping } from "./aabb3_edge_corner_mapping.js";
6
6
  import { plane_computeConvex3PlaneIntersection } from "../../geom/3d/plane/plane_computeConvex3PlaneIntersection.js";
7
- import { EPSILON } from "../../math/MathUtils.js";
8
7
  import { is_point_within_planes } from "../../geom/3d/plane/is_point_within_planes.js";
9
8
  import { v3_distance_above_plane } from "../../geom/v3_distance_above_plane.js";
9
+ import { EPSILON } from "../../math/EPSILON.js";
10
10
 
11
11
  /**
12
12
  * Common piece of continuous memory for better cache coherence
@@ -1,5 +1,5 @@
1
- import { EPSILON } from "../../math/MathUtils.js";
2
1
  import { v3_distance_above_plane } from "../../geom/v3_distance_above_plane.js";
2
+ import { EPSILON } from "../../math/EPSILON.js";
3
3
 
4
4
  /**
5
5
  *
@@ -1,5 +1,5 @@
1
- import { EPSILON } from "../../../math/MathUtils.js";
2
1
  import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
2
+ import { EPSILON } from "../../../math/EPSILON.js";
3
3
 
4
4
  /**
5
5
  *
@@ -1,9 +1,9 @@
1
1
  import { lerp } from "../../../math/lerp.js";
2
- import { EPSILON } from "../../../math/MathUtils.js";
3
2
  import Vector3 from "../../Vector3.js";
4
3
  import { v3_dot } from "../../v3_dot.js";
5
4
  import { v3_length_sqr } from "../../v3_length_sqr.js";
6
5
  import { v3_slerp } from "../../v3_slerp.js";
6
+ import { EPSILON } from "../../../math/EPSILON.js";
7
7
 
8
8
  const e = new Vector3();
9
9
 
@@ -1,5 +1,6 @@
1
- import { EPSILON, epsilonEquals } from "../../../math/MathUtils.js";
2
1
  import { mortonEncode_magicbits } from "../morton/mortonEncode_magicbits.js";
2
+ import { epsilonEquals } from "../../../math/epsilonEquals.js";
3
+ import { EPSILON } from "../../../math/EPSILON.js";
3
4
 
4
5
  /**
5
6
  *
@@ -5,11 +5,11 @@ import { compute_edge_collapse_cost_quadratic } from "./quadratic/compute_edge_c
5
5
  import { tm_vertex_compute_normal } from "../tm_vertex_compute_normal.js";
6
6
  import { min2 } from "../../../../math/min2.js";
7
7
  import { vec3 } from "gl-matrix";
8
- import { EPSILON } from "../../../../math/MathUtils.js";
9
8
  import { tm_edge_collapse_is_degenerate_flip } from "./tm_edge_collapse_is_degenerate_flip.js";
10
9
  import { query_edge_is_boundary } from "../query/query_edge_is_boundary.js";
11
10
  import { tm_edge_kill } from "../tm_edge_kill.js";
12
11
  import { squirrel3 } from "../../../../math/hash/squirrel3.js";
12
+ import { EPSILON } from "../../../../math/EPSILON.js";
13
13
 
14
14
  /**
15
15
  *
@@ -1,8 +1,8 @@
1
1
  import { v3_dot } from "../../../../v3_dot.js";
2
2
  import { fabsf } from "../../../../../math/fabsf.js";
3
- import { EPSILON } from "../../../../../math/MathUtils.js";
4
3
  import { vec3 } from "gl-matrix";
5
4
  import { compute_triangle_normal } from "../../struct/TopoTriangle.js";
5
+ import { EPSILON } from "../../../../../math/EPSILON.js";
6
6
 
7
7
  const scratch_v3 = new Float32Array(3);
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { computeTopoMeshVertexDuplicates } from "./computeTopoMeshVertexDuplicates.js";
2
- import { EPSILON } from "../../../math/MathUtils.js";
3
2
  import { tm_vert_splice } from "./tm_vert_splice.js";
4
3
  import { debugValidateMesh } from "./debugValidateMesh.js";
4
+ import { EPSILON } from "../../../math/EPSILON.js";
5
5
 
6
6
  /**
7
7
  *
@@ -1,8 +1,9 @@
1
1
  import { assert } from "../assert.js";
2
- import { EPSILON, epsilonEquals } from "../math/MathUtils.js";
3
2
  import Vector3 from "./Vector3.js";
4
3
  import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
5
4
  import { computeHashFloat } from "../math/hash/computeHashFloat.js";
5
+ import { epsilonEquals } from "../math/epsilonEquals.js";
6
+ import { EPSILON } from "../math/EPSILON.js";
6
7
 
7
8
 
8
9
  /**
@@ -8,11 +8,12 @@ import { assert } from "../assert.js";
8
8
  import Signal from "../events/signal/Signal.js";
9
9
  import { clamp } from "../math/clamp.js";
10
10
  import { lerp } from "../math/lerp.js";
11
- import { EPSILON, epsilonEquals } from "../math/MathUtils.js";
12
11
  import Vector3 from "./Vector3.js";
13
12
  import { v3_dot } from "./v3_dot.js";
14
13
  import { min2 } from "../math/min2.js";
15
14
  import { computeHashFloat } from "../math/hash/computeHashFloat.js";
15
+ import { epsilonEquals } from "../math/epsilonEquals.js";
16
+ import { EPSILON } from "../math/EPSILON.js";
16
17
 
17
18
  const matrix = new ThreeMatrix4();
18
19
 
@@ -6,7 +6,6 @@
6
6
  import { assert } from "../assert.js";
7
7
  import Signal from "../events/signal/Signal.js";
8
8
  import { lerp } from "../math/lerp.js";
9
- import { EPSILON, epsilonEquals } from "../math/MathUtils.js";
10
9
  import { sign } from "../math/sign.js";
11
10
  import { v3_dot } from "./v3_dot.js";
12
11
  import { v3_length_sqr } from "./v3_length_sqr.js";
@@ -15,6 +14,8 @@ import { v3_angle_between } from "./v3_angle_between.js";
15
14
  import { v3_lerp } from "./v3_lerp.js";
16
15
  import { v3_slerp } from "./v3_slerp.js";
17
16
  import { computeHashFloat } from "../math/hash/computeHashFloat.js";
17
+ import { epsilonEquals } from "../math/epsilonEquals.js";
18
+ import { EPSILON } from "../math/EPSILON.js";
18
19
 
19
20
  class Vector3 {
20
21
  /**
@@ -650,7 +651,9 @@ class Vector3 {
650
651
  * @return {boolean}
651
652
  */
652
653
  _roughlyEquals(x, y, z, tolerance = EPSILON) {
653
- return epsilonEquals(this.x, x, tolerance) && epsilonEquals(this.y, y, tolerance) && epsilonEquals(this.z, z, tolerance);
654
+ return epsilonEquals(this.x, x, tolerance)
655
+ && epsilonEquals(this.y, y, tolerance)
656
+ && epsilonEquals(this.z, z, tolerance);
654
657
  }
655
658
 
656
659
  floor() {
@@ -1,4 +1,4 @@
1
- import { PI2 } from "../math/MathUtils.js";
1
+ import { PI2 } from "../math/PI2.js";
2
2
 
3
3
  /**
4
4
  * Force angle to [-PI, +PI] range
@@ -1,4 +1,4 @@
1
- import { PI2 } from "../../math/MathUtils.js";
1
+ import { PI2 } from "../../math/PI2.js";
2
2
 
3
3
  /**
4
4
  * Pick a random point within a unit circle
@@ -1,4 +1,4 @@
1
- import { PI2 } from "../../math/MathUtils.js";
1
+ import { PI2 } from "../../math/PI2.js";
2
2
 
3
3
  /**
4
4
  *
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Very small value, used for comparison when compensation for rounding error is required
3
+ * @type {number}
4
+ */
5
+ export const EPSILON = 0.000001;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Pi*2
3
+ * @type {number}
4
+ */
5
+ export const PI2 = Math.PI * 2;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Pi/2
3
+ * @type {number}
4
+ */
5
+ export const PI_HALF = Math.PI / 2;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 3-rd degree bezier curve
3
+ * @param {number} t
4
+ * @param {number} p0 start point
5
+ * @param {number} p1 control point
6
+ * @param {number} p2 control point
7
+ * @param {number} p3 end point
8
+ * @returns {number}
9
+ */
10
+ function bezierCurve(t, p0, p1, p2, p3) {
11
+ const nt = 1 - t;
12
+
13
+ const nt_2 = nt * nt;
14
+
15
+ const nt_3 = nt_2 * nt;
16
+
17
+ const t_2 = t * t;
18
+
19
+ const t_3 = t_2 * t;
20
+
21
+ return nt_3 * p0 + 3 * nt_2 * t * p1 + 3 * nt * t_2 * p2 + t_3 * p3;
22
+ }
@@ -0,0 +1,15 @@
1
+ import { clamp } from "./clamp.js";
2
+
3
+ test('clamp', () => {
4
+ expect(clamp(0, 0, 0)).toBe(0);
5
+
6
+ expect(clamp(0, 1, 1)).toBe(1);
7
+
8
+ expect(clamp(0, -1, -1)).toBe(-1);
9
+
10
+ expect(clamp(3, 1, 2)).toBe(2);
11
+
12
+ expect(clamp(0, 1, 2)).toBe(1);
13
+
14
+ expect(clamp(2, 1, 3)).toBe(2);
15
+ });
@@ -0,0 +1,28 @@
1
+ import { assert } from "../assert.js";
2
+ import { min2 } from "./min2.js";
3
+
4
+ /**
5
+ * Find the greatest common divisor (denominator/factor)
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @returns {number}
9
+ */
10
+ export function computeGreatestCommonDivisor(a, b) {
11
+ assert.typeOf(a, 'number', 'a');
12
+ assert.typeOf(b, 'number', 'b');
13
+
14
+ // start with the lowest of the two as a guess
15
+ let result = min2(a, b);
16
+
17
+ while (result > 1) {
18
+ if (a % result === 0 && b % result === 0) {
19
+ // found a common divisor
20
+ break;
21
+ }
22
+
23
+ // keep going down
24
+ result--;
25
+ }
26
+
27
+ return result;
28
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ *
3
+ * @param {number} side length of the side
4
+ * @param {number} base length of the base
5
+ * @returns {number}
6
+ */
7
+ export function computeIsoscelesTriangleApexAngle(side, base) {
8
+ const b2 = base * base;
9
+ const s2 = side * side;
10
+
11
+ const upper = (2 * s2 - b2);
12
+ const lower = (2 * s2);
13
+
14
+ const cosAlpha = upper / lower;
15
+
16
+ return Math.acos(cosAlpha);
17
+ }
@@ -0,0 +1,30 @@
1
+ import { assert } from "../assert.js";
2
+
3
+ /**
4
+ * Compute lowest positive integer divisor of a given "product" value
5
+ * @param {number} product
6
+ * @param {number} limit
7
+ * @returns {number}
8
+ */
9
+ export function computeWholeDivisorLow(product, limit) {
10
+ assert.typeOf(product, 'number', 'product');
11
+ assert.typeOf(limit, 'number', 'limit');
12
+
13
+
14
+ assert.ok(Number.isInteger(product), `expected product to be an integer, instead got '${product}'`);
15
+ assert.ok(Number.isInteger(limit), `expected limit to be an integer, instead got '${limit}'`);
16
+
17
+ let i = limit;
18
+
19
+ while (i > 1) {
20
+
21
+ if (product % i === 0) {
22
+ break;
23
+ }
24
+
25
+ i--;
26
+
27
+ }
28
+
29
+ return i;
30
+ }
@@ -0,0 +1,9 @@
1
+ import { computeWholeDivisorLow } from "./computeWholeDivisorLow.js";
2
+
3
+ test('computeWholeDivisorLow 1/1', () => {
4
+ expect(computeWholeDivisorLow(1, 1)).toEqual(1);
5
+ });
6
+
7
+ test('computeWholeDivisorLow 16/5', () => {
8
+ expect(computeWholeDivisorLow(16, 5)).toEqual(4);
9
+ });
@@ -0,0 +1,13 @@
1
+ import { copysign } from "./copysign.js";
2
+
3
+ test('copysign', () => {
4
+ expect(copysign(1, 2)).toBe(1);
5
+ expect(copysign(2, 1)).toBe(2);
6
+
7
+ expect(copysign(2, -1)).toBe(-2);
8
+ expect(copysign(-2, 1)).toBe(2);
9
+ expect(copysign(-2, -1)).toBe(-2);
10
+
11
+ expect(copysign(3, 7)).toBe(3);
12
+ expect(copysign(3, -7)).toBe(-3);
13
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ *
3
+ * @param {Number} t
4
+ * @param {Number} p0
5
+ * @param {Number} p1
6
+ * @param {Number} p2
7
+ * @param {Number} p3
8
+ * @return {Number}
9
+ */
10
+ export function cubicCurve(t, p0, p1, p2, p3) {
11
+ /**
12
+ *
13
+ * @type {number}
14
+ */
15
+ const cX = 3 * (p1 - p0);
16
+
17
+ /**
18
+ *
19
+ * @type {number}
20
+ */
21
+ const bX = 3 * (p2 - p1) - cX;
22
+
23
+ /**
24
+ *
25
+ * @type {number}
26
+ */
27
+ const aX = p3 - p0 - cX - bX;
28
+
29
+ const t_2 = t * t;
30
+
31
+ const t_3 = t_2 * t;
32
+
33
+ return (aX * t_3) + (bX * t_2) + (cX * t) + p0;
34
+ }
@@ -0,0 +1,13 @@
1
+ import { cubicCurve } from "./cubicCurve.js";
2
+
3
+ test("cubicCurve", () => {
4
+ expect(cubicCurve(0, 1, 2, 3, 4)).toBe(1);
5
+
6
+ expect(cubicCurve(0, 2, 3, 4, 5)).toBe(2);
7
+
8
+ expect(cubicCurve(1, 2, 3, 4, 5)).toBe(5);
9
+
10
+ expect(cubicCurve(1, 3, 4, 5, 6)).toBe(6);
11
+
12
+ expect(cubicCurve(2, 2, 2, 2, 3)).toBe(10);
13
+ });
File without changes
@@ -0,0 +1,16 @@
1
+ import { assert } from "../assert.js";
2
+
3
+ /**
4
+ * Comparison of two numbers with a given tolerance
5
+ * @param {number} a
6
+ * @param {number} b
7
+ * @param {number} tolerance
8
+ * @returns {boolean}
9
+ */
10
+ export function epsilonEquals(a, b, tolerance) {
11
+ assert.isNumber(a, 'a');
12
+ assert.isNumber(b, 'b');
13
+ assert.isNumber(tolerance, 'tolerance');
14
+
15
+ return Math.abs(a - b) <= tolerance;
16
+ }
@@ -0,0 +1,7 @@
1
+ import { computeHashFloat } from "./computeHashFloat.js";
2
+
3
+ test("computeHashFloat", () => {
4
+ expect(computeHashFloat(500)).toEqual(computeHashFloat(500));
5
+
6
+ expect(computeHashFloat(500)).not.toEqual(computeHashFloat(400))
7
+ });
@@ -0,0 +1,13 @@
1
+ import { inverseLerp } from "./inverseLerp.js";
2
+
3
+ test('inverseLerp', () => {
4
+ expect(inverseLerp(0, 5, 0.5)).toBe(0.1);
5
+
6
+ expect(inverseLerp(-5, 5, 0)).toBe(0.5);
7
+
8
+ expect(inverseLerp(0, 0, 0)).toBe(0);
9
+
10
+ expect(inverseLerp(1, 2, 1)).toBe(0);
11
+
12
+ expect(inverseLerp(1, 2, 2)).toBe(1);
13
+ });
@@ -0,0 +1,11 @@
1
+ import { isValueBetween } from "./isValueBetween.js";
2
+
3
+ test("isValueBetween", () => {
4
+ expect(isValueBetween(0, 1, 2)).toBe(false);
5
+ });
6
+
7
+ test("isValueBetween negative limits", () => {
8
+ expect(isValueBetween(1, -1, 2)).toBe(true);
9
+
10
+ expect(isValueBetween(1, 2, -1)).toBe(true);
11
+ });
@@ -0,0 +1,16 @@
1
+ import { isValueBetweenInclusive } from "./isValueBetweenInclusive.js";
2
+
3
+
4
+ test("isValueBetweenInclusive", () => {
5
+ expect(isValueBetweenInclusive(1, 1, 2)).toBe(true);
6
+
7
+ expect(isValueBetweenInclusive(2, 1, 2)).toBe(true);
8
+
9
+ expect(isValueBetweenInclusive(1.5, 1, 2)).toBe(true);
10
+
11
+ expect(isValueBetweenInclusive(0.5, 1, 2)).toBe(false);
12
+
13
+ expect(isValueBetweenInclusive(3, 1, 2)).toBe(false);
14
+ });
15
+
16
+
@@ -0,0 +1,15 @@
1
+ import { lerp } from "./lerp.js";
2
+
3
+ test('lerp', () => {
4
+ expect(lerp(0, 5, 0.1)).toBe(0.5);
5
+
6
+ expect(lerp(-5, 5, 0.5)).toBe(0);
7
+
8
+ expect(lerp(0, 0, 0)).toBe(0);
9
+
10
+ expect(lerp(0, 0, 1)).toBe(0);
11
+
12
+ expect(lerp(1, 2, 0)).toBe(1);
13
+
14
+ expect(lerp(1, 2, 1)).toBe(2);
15
+ });
@@ -0,0 +1,15 @@
1
+ import { cubicCurve } from "./cubicCurve.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Number} p0
6
+ * @param {Number} p1
7
+ * @param {Number} p2
8
+ * @param {Number} p3
9
+ * @return {function(number): Number}
10
+ */
11
+ export function makeCubicCurve(p0, p1, p2, p3) {
12
+ return function (v) {
13
+ return cubicCurve(v, p0, p1, p2, p3);
14
+ }
15
+ }
@@ -0,0 +1,9 @@
1
+ import { makeCubicCurve } from "./makeCubicCurve.js";
2
+
3
+ test("makeCubicCurve", () => {
4
+ const f = makeCubicCurve(1, 2, 3, 4);
5
+ expect(f(0)).toBe(1);
6
+
7
+ expect(f(1)).toBe(4);
8
+ });
9
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @template T
3
+ * @param {T[]} sequence
4
+ * @returns {function(): T}
5
+ */
6
+ export function makeSequenceLoop(sequence) {
7
+ let i = 0;
8
+
9
+ const data = sequence.slice();
10
+ const n = data.length;
11
+
12
+
13
+ return function sequenceLoop() {
14
+ const datum = data[i % n];
15
+
16
+ i++;
17
+
18
+ return datum;
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import { max2 } from "./max2.js";
2
+
3
+ test('max2', () => {
4
+ expect(max2(0, 0)).toBe(0);
5
+
6
+ expect(max2(2, 1)).toBe(2);
7
+
8
+ expect(max2(1, 2)).toBe(2);
9
+
10
+ expect(max2(-1, 1)).toBe(1);
11
+
12
+ expect(max2(1, -1)).toBe(1);
13
+ });
@@ -0,0 +1,27 @@
1
+ import { max3 } from "./max3.js";
2
+
3
+ test("max3", () => {
4
+ expect(max3(-1, -3, 1)).toBe(1);
5
+
6
+ expect(max3(-3, -1, 1)).toBe(1);
7
+
8
+ expect(max3(-3, 1, -1)).toBe(1);
9
+
10
+ expect(max3(-1, 1, -3)).toBe(1);
11
+
12
+ expect(max3(1, -1, -3)).toBe(1);
13
+
14
+ expect(max3(1, -3, -1)).toBe(1);
15
+
16
+ expect(max3(-3, 1, 1)).toBe(1);
17
+
18
+ expect(max3(3, 1, 1)).toBe(3);
19
+
20
+ expect(max3(3, 3, -1)).toBe(3);
21
+
22
+ expect(max3(3, 3, 4)).toBe(4);
23
+
24
+ expect(max3(3, 0, 3)).toBe(3);
25
+
26
+ expect(max3(3, 4, 3)).toBe(4);
27
+ });
@@ -23,3 +23,15 @@ test("0,-1", () => {
23
23
  test("Infinity,-Infinity", () => {
24
24
  expect(min2(Infinity, -Infinity)).toBe(-Infinity);
25
25
  });
26
+
27
+ test('min2', () => {
28
+ expect(min2(0, 0)).toBe(0);
29
+
30
+ expect(min2(2, 1)).toBe(1);
31
+
32
+ expect(min2(1, 2)).toBe(1);
33
+
34
+ expect(min2(-1, 1)).toBe(-1);
35
+
36
+ expect(min2(1, -1)).toBe(-1);
37
+ });
@@ -0,0 +1,27 @@
1
+ import { min3 } from "./min3.js";
2
+
3
+ test("min3", () => {
4
+ expect(min3(-1, -3, 1)).toBe(-3);
5
+
6
+ expect(min3(-3, -1, 1)).toBe(-3);
7
+
8
+ expect(min3(-1, 1, -3)).toBe(-3);
9
+
10
+ expect(min3(1, -3, -1)).toBe(-3);
11
+
12
+ expect(min3(-3, 1, -1)).toBe(-3);
13
+
14
+ expect(min3(1, -1, -3)).toBe(-3);
15
+
16
+ expect(min3(-3, 1, 1)).toBe(-3);
17
+
18
+ expect(min3(2, 1, 1)).toBe(1);
19
+
20
+ expect(min3(3, 3, -1)).toBe(-1);
21
+
22
+ expect(min3(3, 3, 4)).toBe(3);
23
+
24
+ expect(min3(3, 0, 3)).toBe(0);
25
+
26
+ expect(min3(3, 4, 3)).toBe(3);
27
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Assuming the input is an N-dimension vector, normalizes the vector to magnitude of 1
3
+ * @param {number[]|Float32Array} result
4
+ * @param {number[]|Float32Array} data
5
+ * @param {number} [length] number of dimensions
6
+ */
7
+ export function normalizeArrayVector(result, data, length = data.length) {
8
+
9
+ let magnitude2 = 0;
10
+
11
+ for (let i = 0; i < length; i++) {
12
+ const value = data[i];
13
+
14
+ const value2 = value * value;
15
+
16
+ magnitude2 += value2;
17
+ }
18
+
19
+ const magnitude_inv = 1 / Math.sqrt(magnitude2);
20
+
21
+ for (let i = 0; i < length; i++) {
22
+ result[i] = data[i] * magnitude_inv;
23
+ }
24
+
25
+ }
@@ -0,0 +1,10 @@
1
+ import { overlap1D } from "./overlap1D.js";
2
+
3
+ test('overlap1D', () => {
4
+ expect(overlap1D(0, 0, 0, 0)).toBe(false);
5
+ expect(overlap1D(-3, -1, -2, -0.5)).toBe(true);
6
+ expect(overlap1D(-1, 2, 1, 1)).toBe(true);
7
+ expect(overlap1D(1, 1, -1, 2)).toBe(true);
8
+
9
+ expect(overlap1D(1, 2, 2, 3)).toBe(false);
10
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {Number} t
4
+ * @param {Number} p0
5
+ * @param {Number} p1
6
+ * @param {Number} p2
7
+ * @return {number}
8
+ */
9
+ export function quadraticCurve(t, p0, p1, p2) {
10
+ return (1 - t) * (1 - t) * p0 + 2 * (1 - t) * t * p1 + t * t * p2;
11
+ }