@woosh/meep-engine 2.126.28 → 2.126.30

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 (59) hide show
  1. package/package.json +1 -1
  2. package/src/core/events/signal/Signal.d.ts.map +1 -1
  3. package/src/core/events/signal/Signal.js +4 -2
  4. package/src/core/events/signal/SignalHandler.d.ts +9 -1
  5. package/src/core/events/signal/SignalHandler.d.ts.map +1 -1
  6. package/src/core/events/signal/SignalHandler.js +10 -2
  7. package/src/core/fsm/simple/SimpleStateMachine.js +1 -1
  8. package/src/core/geom/2d/spline_bezier2_2d.js +3 -3
  9. package/src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.d.ts +2 -2
  10. package/src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.d.ts.map +1 -1
  11. package/src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.js +7 -3
  12. package/src/core/geom/vec3/serialization/v3_binary_equality_decode.d.ts.map +1 -1
  13. package/src/core/geom/vec3/serialization/v3_binary_equality_decode.js +16 -1
  14. package/src/core/geom/vec3/serialization/v3_binary_equality_encode.d.ts.map +1 -1
  15. package/src/core/geom/vec3/serialization/v3_binary_equality_encode.js +15 -0
  16. package/src/core/math/spline/cubicCurve.d.ts +3 -3
  17. package/src/core/math/spline/cubicCurve.js +3 -3
  18. package/src/core/math/spline/makeCubicCurve.js +2 -2
  19. package/src/core/math/spline/spline2_bezier.d.ts +10 -0
  20. package/src/core/math/spline/spline2_bezier.d.ts.map +1 -0
  21. package/src/core/math/spline/spline2_bezier.js +13 -0
  22. package/src/core/math/spline/spline3_bezier.d.ts +13 -0
  23. package/src/core/math/spline/spline3_bezier.d.ts.map +1 -0
  24. package/src/core/math/spline/spline3_bezier.js +26 -0
  25. package/src/core/math/spline/spline3_bezier_bounds.d.ts +15 -0
  26. package/src/core/math/spline/spline3_bezier_bounds.d.ts.map +1 -0
  27. package/src/core/math/spline/spline3_bezier_bounds.js +89 -0
  28. package/src/core/math/spline/spline3_bezier_to_hermite.d.ts +15 -0
  29. package/src/core/math/spline/spline3_bezier_to_hermite.d.ts.map +1 -0
  30. package/src/core/math/spline/spline3_bezier_to_hermite.js +33 -0
  31. package/src/core/math/spline/spline3_hermite.d.ts +15 -0
  32. package/src/core/math/spline/spline3_hermite.d.ts.map +1 -0
  33. package/src/core/math/spline/spline3_hermite.js +26 -0
  34. package/src/core/math/spline/spline3_hermite_bounds.d.ts +17 -0
  35. package/src/core/math/spline/spline3_hermite_bounds.d.ts.map +1 -0
  36. package/src/core/math/spline/spline3_hermite_bounds.js +102 -0
  37. package/src/core/math/spline/spline3_hermite_to_bezier.d.ts +13 -0
  38. package/src/core/math/spline/spline3_hermite_to_bezier.d.ts.map +1 -0
  39. package/src/core/math/spline/spline3_hermite_to_bezier.js +32 -0
  40. package/src/core/math/spline/spline_bezier2.d.ts +3 -7
  41. package/src/core/math/spline/spline_bezier2.d.ts.map +1 -1
  42. package/src/core/math/spline/spline_bezier2.js +4 -11
  43. package/src/core/math/spline/spline_bezier3.d.ts +3 -10
  44. package/src/core/math/spline/spline_bezier3.d.ts.map +1 -1
  45. package/src/core/math/spline/spline_bezier3.js +4 -24
  46. package/src/core/math/spline/spline_bezier3_bounds.d.ts +3 -12
  47. package/src/core/math/spline/spline_bezier3_bounds.d.ts.map +1 -1
  48. package/src/core/math/spline/spline_bezier3_bounds.js +3 -85
  49. package/src/core/math/spline/spline_hermite3.d.ts +3 -12
  50. package/src/core/math/spline/spline_hermite3.d.ts.map +1 -1
  51. package/src/core/math/spline/spline_hermite3.js +4 -24
  52. package/src/core/math/spline/spline_hermite3_bounds.d.ts +3 -14
  53. package/src/core/math/spline/spline_hermite3_bounds.d.ts.map +1 -1
  54. package/src/core/math/spline/spline_hermite3_bounds.js +3 -98
  55. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts +1 -12
  56. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts.map +1 -1
  57. package/src/core/math/spline/spline_hermite3_to_bezier.js +4 -26
  58. package/src/engine/animation/curve/animation_curve_compute_aabb.js +2 -2
  59. package/src/engine/animation/curve/evaluate_two_key_curve.js +2 -2
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.126.28",
8
+ "version": "2.126.30",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../../../../src/core/events/signal/Signal.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH;IACI;;;;OAIG;IACH,iBAAqB;IAErB;;;;OAIG;IACH,cAAU;IAEV;;;OAGG;IACH,YAFU,MAAM,CAED;IAWf;;;OAGG;IACH,cAFW,OAAO,EAIjB;IAfD;;;OAGG;IACH,cAFa,OAAO,CAInB;IAYD;;;;OAIG;IACH,cAHW,MAAM;;KAAY,GAChB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM;;KAAY,GAChB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM;;KAAY,SAClB,OAAO,QAQjB;IAED;;;;OAIG;IACH,cAHW,MAAM;;KAAY,GAChB,OAAO,CAInB;IAGD;;;;;OAKG;IACH,sCAHW,GAAC,GACC,OAAO,CAcnB;IAED,aAEC;IAED,eAEC;IAED;;;OAGG;IACH,eAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,8BAFW,GAAC,QAUX;IAED;;;;OAIG;IACH,2BAFW,GAAC,QASX;IA8BD;;;;;OAKG;IACH,8BAHW,GAAC,GACC,OAAO,CA2CnB;IAED;;;;;;OAMG;IACH,kBAEC;IAqDD;;;OAGG;IACH,kBAFc,GAAC,EAAA,QA6Cd;IAGD;;;OAGG;IACH,cA0CC;IAED;;;;OAIG;IACH,WAFW,GAAC,QA2CX;IAED;;;;OAIG;IACH,SAHW,GAAC,KACD,GAAC,QA0CX;IAED;;;;;OAKG;IACH,SAJW,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;OAMG;IACH,SALW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;;;OAQG;IACH,SAPW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;;;;;OAUG;IACH,SATW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,MAAM,CAalB;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;;CAPxB"}
1
+ {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../../../../src/core/events/signal/Signal.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH;IACI;;;;OAIG;IACH,iBAAqB;IAErB;;;;OAIG;IACH,cAAU;IAEV;;;OAGG;IACH,YAFU,MAAM,CAED;IAWf;;;OAGG;IACH,cAFW,OAAO,EAIjB;IAfD;;;OAGG;IACH,cAFa,OAAO,CAInB;IAYD;;;;OAIG;IACH,cAHW,MAAM;;KAAY,GAChB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM;;KAAY,GAChB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM;;KAAY,SAClB,OAAO,QAQjB;IAED;;;;OAIG;IACH,cAHW,MAAM;;KAAY,GAChB,OAAO,CAInB;IAGD;;;;;OAKG;IACH,sCAHW,GAAC,GACC,OAAO,CAcnB;IAED,aAEC;IAED,eAEC;IAED;;;OAGG;IACH,eAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,8BAFW,GAAC,QAUX;IAED;;;;OAIG;IACH,2BAFW,GAAC,QASX;IA8BD;;;;;OAKG;IACH,8BAHW,GAAC,GACC,OAAO,CA2CnB;IAED;;;;;;OAMG;IACH,kBAEC;IAqDD;;;OAGG;IACH,kBAFc,GAAC,EAAA,QA6Cd;IAGD;;;OAGG;IACH,cA0CC;IAED;;;;OAIG;IACH,WAFW,GAAC,QA2CX;IAED;;;;OAIG;IACH,SAHW,GAAC,KACD,GAAC,QA0CX;IAED;;;;;OAKG;IACH,SAJW,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;OAMG;IACH,SALW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;;;OAQG;IACH,SAPW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;;;;;;;OAUG;IACH,SATW,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,KACD,GAAC,QA0CX;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,MAAM,CAalB;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;;CAPxB"}
@@ -5,10 +5,12 @@ import { SignalHandler, SignalHandlerFlags } from "./SignalHandler.js";
5
5
 
6
6
 
7
7
  /**
8
- * Signal is a type of event bus. You can subscribe to events using {@link add} method and dispatch using sendN method where N is the number of arguments you wish to pass
8
+ * Signal is a type of event bus. You can subscribe to events using {@link add} method and dispatch using sendN method where N is the number of arguments you wish to pass.
9
9
  * Signal is different from a normal event bus in that 1 signal corresponds to 1 event type. For example, in HTML you have `addEventListener` which lets you subscribe to any kind of event, let's use "mousedown" as a reference.
10
10
  * Using a Signal you would instead have a signal corresponding to "mousedown" and dispatch this signal only for this event.
11
- * @example `const mouseDown = new Signal<MouseEvent>(); mouseDown.send1(myMouseEvent);`
11
+ * @example
12
+ * const mouseDown = new Signal<MouseEvent>();
13
+ * mouseDown.send1(myMouseEvent);
12
14
  */
13
15
  export class Signal {
14
16
  /**
@@ -2,6 +2,14 @@ export type SignalHandlerFlags = number;
2
2
  export namespace SignalHandlerFlags {
3
3
  let RemoveAfterExecution: number;
4
4
  }
5
+ /**
6
+ * Represents a handler for signals in the event system.
7
+ *
8
+ * Used to encapsulate callback functions along with their execution context and provide flag-based behavior control.
9
+ * They can be organized into linked lists using the `next` property to form a chain of handlers.
10
+ *
11
+ * @see Signal
12
+ */
5
13
  export class SignalHandler {
6
14
  /**
7
15
  *
@@ -20,7 +28,7 @@ export class SignalHandler {
20
28
  */
21
29
  private flags;
22
30
  /**
23
- * Used to determine if handler was added mid-dispatch
31
+ * Used to determine if the handler was added mid-dispatch
24
32
  * @type {number}
25
33
  */
26
34
  generation: number;
@@ -1 +1 @@
1
- {"version":3,"file":"SignalHandler.d.ts","sourceRoot":"","sources":["../../../../../src/core/events/signal/SignalHandler.js"],"names":[],"mappings":"iCAIU,MAAM;;;;AAShB;IAmBI;;;;OAIG;IACH,wCAFW,GAAC,EASX;IA9BD;;;OAGG;IACH,MAFU,aAAa,GAAC,IAAI,CAEhB;IAEZ;;;OAGG;IACH,cAAU;IAEV;;;OAGG;IACH,YAFU,MAAM,CAEA;IAWZ,iBAAoB;IACpB,aAAsB;IAI1B;;;;OAIG;IACH,cAHW,MAAM,GAAC,kBAAkB,GACvB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GAAC,kBAAkB,GACvB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GAAC,kBAAkB,SACzB,OAAO,QAQjB;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,kBAAkB,GACvB,OAAO,CAInB;IAIL;;;OAGG;IACH,0BAFU,OAAO,CAEsB;CANtC"}
1
+ {"version":3,"file":"SignalHandler.d.ts","sourceRoot":"","sources":["../../../../../src/core/events/signal/SignalHandler.js"],"names":[],"mappings":"iCAIU,MAAM;;;;AAShB;;;;;;;GAOG;AACH;IAmBI;;;;OAIG;IACH,wCAFW,GAAC,EASX;IA9BD;;;OAGG;IACH,MAFU,aAAa,GAAC,IAAI,CAEhB;IAEZ;;;OAGG;IACH,cAAU;IAEV;;;OAGG;IACH,YAFU,MAAM,CAEA;IAWZ,iBAAoB;IACpB,aAAsB;IAI1B;;;;OAIG;IACH,cAHW,MAAM,GAAC,kBAAkB,GACvB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GAAC,kBAAkB,GACvB,IAAI,CAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GAAC,kBAAkB,SACzB,OAAO,QAQjB;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,kBAAkB,GACvB,OAAO,CAInB;IAIL;;;OAGG;IACH,0BAFU,OAAO,CAEsB;CANtC"}
@@ -11,6 +11,14 @@ export const SignalHandlerFlags = {
11
11
  RemoveAfterExecution: 1
12
12
  };
13
13
 
14
+ /**
15
+ * Represents a handler for signals in the event system.
16
+ *
17
+ * Used to encapsulate callback functions along with their execution context and provide flag-based behavior control.
18
+ * They can be organized into linked lists using the `next` property to form a chain of handlers.
19
+ *
20
+ * @see Signal
21
+ */
14
22
  export class SignalHandler {
15
23
  /**
16
24
  * Optional field. Used for forming linked lists of handlers
@@ -25,7 +33,7 @@ export class SignalHandler {
25
33
  flags = 0;
26
34
 
27
35
  /**
28
- * Used to determine if handler was added mid-dispatch
36
+ * Used to determine if the handler was added mid-dispatch
29
37
  * @type {number}
30
38
  */
31
39
  generation = -1;
@@ -36,7 +44,7 @@ export class SignalHandler {
36
44
  * @param {*} [context]
37
45
  */
38
46
  constructor(handle, context) {
39
- assert.notEqual(handle, undefined, 'handle must be defined');
47
+ assert.defined(handle, 'handle');
40
48
  assert.isFunction(handle, 'handle');
41
49
 
42
50
  this.handle = handle;
@@ -9,7 +9,7 @@ import { SimpleStateMachineDescription } from "./SimpleStateMachineDescription.j
9
9
  export class SimpleStateMachine {
10
10
 
11
11
  /**
12
- *
12
+ * Current state, -1 indicated "unset"
13
13
  * @type {number}
14
14
  * @private
15
15
  */
@@ -1,4 +1,4 @@
1
- import { spline_bezier2 } from "../../math/spline/spline_bezier2.js";
1
+ import { spline2_bezier } from "../../math/spline/spline2_bezier.js";
2
2
 
3
3
  /**
4
4
  *
@@ -19,8 +19,8 @@ export function spline_bezier2_2d(
19
19
  t
20
20
  ) {
21
21
 
22
- const x0 = spline_bezier2(t, p0x, p1x, p2x);
23
- const y0 = spline_bezier2(t, p0y, p1y, p2y);
22
+ const x0 = spline2_bezier(t, p0x, p1x, p2x);
23
+ const y0 = spline2_bezier(t, p0y, p1y, p2y);
24
24
 
25
25
  result.set(x0, y0);
26
26
  }
@@ -2,8 +2,8 @@
2
2
  *
3
3
  * @param {TetrahedralMesh} mesh
4
4
  * @param {number[]} positions
5
- * @param {string|number} color CSS color definition
6
- * @param {number} opacity
5
+ * @param {string|number} [color] CSS color definition
6
+ * @param {number} [opacity]
7
7
  * @returns {Entity}
8
8
  */
9
9
  export function visualize_tetrahedral_mesh({ mesh, positions, color, opacity }: TetrahedralMesh): Entity;
@@ -1 +1 @@
1
- {"version":3,"file":"visualize_tetrahedral_mesh.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.js"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,gFANW,eAAe,GAIb,MAAM,CA2BlB;mBAxCkB,kCAAkC"}
1
+ {"version":3,"file":"visualize_tetrahedral_mesh.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.js"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,gFANW,eAAe,GAIb,MAAM,CA8BlB;mBA5CkB,kCAAkC"}
@@ -4,21 +4,25 @@ import { Transform } from "../../../../engine/ecs/transform/Transform.js";
4
4
  import { DrawMode } from "../../../../engine/graphics/ecs/mesh-v2/DrawMode.js";
5
5
  import { ShadedGeometry } from "../../../../engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
6
6
  import { ShadedGeometryFlags } from "../../../../engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js";
7
+ import { assert } from "../../../assert.js";
7
8
  import { build_tetrahedral_mesh_buffer_geometry } from "./graphics/build_tetrahedral_mesh_buffer_geometry.js";
8
9
 
9
10
  /**
10
11
  *
11
12
  * @param {TetrahedralMesh} mesh
12
13
  * @param {number[]} positions
13
- * @param {string|number} color CSS color definition
14
- * @param {number} opacity
14
+ * @param {string|number} [color] CSS color definition
15
+ * @param {number} [opacity]
15
16
  * @returns {Entity}
16
17
  */
17
18
  export function visualize_tetrahedral_mesh({
18
- mesh, positions,
19
+ mesh,
20
+ positions,
19
21
  color = '#FF00FF',
20
22
  opacity = 0.35
21
23
  }) {
24
+ assert.defined(mesh, 'mesh');
25
+ assert.defined(positions, 'positions');
22
26
 
23
27
  const geometry = build_tetrahedral_mesh_buffer_geometry(mesh, positions);
24
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"v3_binary_equality_decode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/vec3/serialization/v3_binary_equality_decode.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,kDAPW,YAAY,UACZ,MAAM,EAAE,iBACR,MAAM,QA0ChB"}
1
+ {"version":3,"file":"v3_binary_equality_decode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/vec3/serialization/v3_binary_equality_decode.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,kDAPW,YAAY,UACZ,MAAM,EAAE,iBACR,MAAM,QAyDhB"}
@@ -14,7 +14,22 @@ export function v3_binary_equality_decode(buffer, result, result_offset) {
14
14
  let y = 0;
15
15
  let z = 0;
16
16
 
17
- if ((header & 7) === 7) {
17
+ if ((header & 0b01111) === 0b01111) {
18
+ // special encoded value, all 0
19
+
20
+ x = 0;
21
+ y = 0;
22
+ z = 0;
23
+
24
+ } else if ((header & 0b10111) === 0b10111) {
25
+
26
+ // special encoded value, all 1
27
+
28
+ x = 1;
29
+ y = 1;
30
+ z = 1;
31
+
32
+ } else if ((header & 7) === 7) {
18
33
  //all scale components are the same
19
34
  x = buffer.readFloat32();
20
35
  y = x;
@@ -1 +1 @@
1
- {"version":3,"file":"v3_binary_equality_encode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/vec3/serialization/v3_binary_equality_encode.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,kDARW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,QA4ChB"}
1
+ {"version":3,"file":"v3_binary_equality_encode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/vec3/serialization/v3_binary_equality_encode.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,kDARW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,QA2DhB"}
@@ -24,8 +24,23 @@ export function v3_binary_equality_encode(buffer, x, y, z){
24
24
  header |= 4;
25
25
  }
26
26
 
27
+ if (header === 7) {
28
+ if(x === 0){
29
+ // all axes 0
30
+ header |= 8;
31
+ }else if(x === 1){
32
+ // all axes 1
33
+ header |= 16;
34
+ }
35
+ }
36
+
27
37
  buffer.writeUint8(header);
28
38
 
39
+ if(header > 7){
40
+ // special value encoded in the header
41
+ return;
42
+ }
43
+
29
44
  if ((header & 7) === 7) {
30
45
  //all components are the same
31
46
  buffer.writeFloat32(x);
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @deprecated use {@link spline_bezier3} directly
2
+ * @deprecated use {@link spline3_bezier} directly
3
3
  */
4
- export const cubicCurve: typeof spline_bezier3;
5
- import { spline_bezier3 } from "./spline_bezier3.js";
4
+ export const cubicCurve: typeof spline3_bezier;
5
+ import { spline3_bezier } from "./spline3_bezier.js";
6
6
  //# sourceMappingURL=cubicCurve.d.ts.map
@@ -1,6 +1,6 @@
1
- import { spline_bezier3 } from "./spline_bezier3.js";
1
+ import { spline3_bezier } from "./spline3_bezier.js";
2
2
 
3
3
  /**
4
- * @deprecated use {@link spline_bezier3} directly
4
+ * @deprecated use {@link spline3_bezier} directly
5
5
  */
6
- export const cubicCurve = spline_bezier3;
6
+ export const cubicCurve = spline3_bezier;
@@ -1,4 +1,4 @@
1
- import { cubicCurve } from "./cubicCurve.js";
1
+ import { spline3_bezier } from "./spline3_bezier.js";
2
2
 
3
3
  /**
4
4
  *
@@ -10,6 +10,6 @@ import { cubicCurve } from "./cubicCurve.js";
10
10
  */
11
11
  export function makeCubicCurve(p0, p1, p2, p3) {
12
12
  return function (v) {
13
- return cubicCurve(v, p0, p1, p2, p3);
13
+ return spline3_bezier(v, p0, p1, p2, p3);
14
14
  }
15
15
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 2-nd (quadratic) degree bezier curve
3
+ * @param {number} t
4
+ * @param {number} p0
5
+ * @param {number} p1
6
+ * @param {number} p2
7
+ * @return {number}
8
+ */
9
+ export function spline2_bezier(t: number, p0: number, p1: number, p2: number): number;
10
+ //# sourceMappingURL=spline2_bezier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline2_bezier.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline2_bezier.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,kCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAMjB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 2-nd (quadratic) degree bezier curve
3
+ * @param {number} t
4
+ * @param {number} p0
5
+ * @param {number} p1
6
+ * @param {number} p2
7
+ * @return {number}
8
+ */
9
+ export function spline2_bezier(t, p0, p1, p2) {
10
+ const inv_t = 1 - t;
11
+
12
+ return inv_t * inv_t * p0 + 2 * inv_t * t * p1 + t * t * p2;
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 3-rd (cubic) degree bezier curve
3
+ * @see https://www.youtube.com/watch?v=jvPPXbo87ds&t=234s
4
+ * @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve
5
+ * @param {number} t factor value between 0..1
6
+ * @param {number} p0 start point
7
+ * @param {number} p1 control point
8
+ * @param {number} p2 control point
9
+ * @param {number} p3 end point
10
+ * @returns {number}
11
+ */
12
+ export function spline3_bezier(t: number, p0: number, p1: number, p2: number, p3: number): number;
13
+ //# sourceMappingURL=spline3_bezier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline3_bezier.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline3_bezier.js"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,kCAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAgBlB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 3-rd (cubic) degree bezier curve
3
+ * @see https://www.youtube.com/watch?v=jvPPXbo87ds&t=234s
4
+ * @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve
5
+ * @param {number} t factor value between 0..1
6
+ * @param {number} p0 start point
7
+ * @param {number} p1 control point
8
+ * @param {number} p2 control point
9
+ * @param {number} p3 end point
10
+ * @returns {number}
11
+ */
12
+ export function spline3_bezier(t, p0, p1, p2, p3) {
13
+ // first we compute necessary factors for each point
14
+ const nt = 1 - t;
15
+
16
+ const nt_2 = nt * nt;
17
+
18
+ const nt_3 = nt_2 * nt;
19
+
20
+ const t_2 = t * t;
21
+
22
+ const t_3 = t_2 * t;
23
+
24
+ // combine factors with point values to produce final result
25
+ return nt_3 * p0 + 3 * nt_2 * t * p1 + 3 * nt * t_2 * p2 + t_3 * p3;
26
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Compute bounds of a 3-rd degree bezier curve
3
+ * Note that this is a 1d case solver
4
+ * Lower bound will be written into result[offset], upper bounds will be written into result[offset+result_stride]
5
+ * @see https://github.com/adobe-webplatform/Snap.svg/blob/c8e483c9694517e24b282f8f59f985629f4994ce/src/path.js#L856
6
+ * @param {number[]|Float32Array} result
7
+ * @param {number} result_offset offset into the result array
8
+ * @param {number} result_stride
9
+ * @param {number} p0
10
+ * @param {number} p1
11
+ * @param {number} p2
12
+ * @param {number} p3
13
+ */
14
+ export function spline3_bezier_bounds(result: number[] | Float32Array, result_offset: number, result_stride: number, p0: number, p1: number, p2: number, p3: number): void;
15
+ //# sourceMappingURL=spline3_bezier_bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline3_bezier_bounds.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline3_bezier_bounds.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,8CARW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,iBACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAuEhB"}
@@ -0,0 +1,89 @@
1
+ import { assert } from "../../assert.js";
2
+ import { max2 } from "../max2.js";
3
+ import { min2 } from "../min2.js";
4
+ import { spline3_bezier } from "./spline3_bezier.js";
5
+
6
+ /**
7
+ * Compute bounds of a 3-rd degree bezier curve
8
+ * Note that this is a 1d case solver
9
+ * Lower bound will be written into result[offset], upper bounds will be written into result[offset+result_stride]
10
+ * @see https://github.com/adobe-webplatform/Snap.svg/blob/c8e483c9694517e24b282f8f59f985629f4994ce/src/path.js#L856
11
+ * @param {number[]|Float32Array} result
12
+ * @param {number} result_offset offset into the result array
13
+ * @param {number} result_stride
14
+ * @param {number} p0
15
+ * @param {number} p1
16
+ * @param {number} p2
17
+ * @param {number} p3
18
+ */
19
+ export function spline3_bezier_bounds(result, result_offset, result_stride, p0, p1, p2, p3) {
20
+ assert.greaterThan(result_stride, 0, 'result_stride must be greater than 0');
21
+ assert.isInteger(result_stride, 'result_stride');
22
+
23
+ const b = 6 * p0 - 12 * p1 + 6 * p2;
24
+ const a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
25
+ const c = 3 * p1 - 3 * p0;
26
+
27
+ let min = min2(p0, p3);
28
+ let max = max2(p0, p3);
29
+
30
+ if (Math.abs(a) < 1e-12) {
31
+
32
+ if (Math.abs(b) >= 1e-12) {
33
+ const t = -c / b;
34
+
35
+ if (0 < t && t < 1) {
36
+ const value = spline3_bezier(t, p0, p1, p2, p3);
37
+
38
+ if (value < min) {
39
+ min = value;
40
+ }
41
+ if (value > max) {
42
+ max = value;
43
+ }
44
+
45
+ }
46
+
47
+ }
48
+
49
+ } else {
50
+
51
+ const b2ac = b * b - 4 * c * a;
52
+ const sqrtb2ac = Math.sqrt(b2ac);
53
+
54
+ if (b2ac >= 0) {
55
+
56
+ const t1 = (-b + sqrtb2ac) / (2 * a);
57
+
58
+ if (0 < t1 && t1 < 1) {
59
+ const value = spline3_bezier(t1, p0, p1, p2, p3);
60
+
61
+ if (value < min) {
62
+ min = value;
63
+ }
64
+ if (value > max) {
65
+ max = value;
66
+ }
67
+ }
68
+
69
+ const t2 = (-b - sqrtb2ac) / (2 * a);
70
+
71
+ if (0 < t2 && t2 < 1) {
72
+ const value = spline3_bezier(t2, p0, p1, p2, p3);
73
+
74
+ if (value < min) {
75
+ min = value;
76
+ }
77
+ if (value > max) {
78
+ max = value;
79
+ }
80
+ }
81
+
82
+ }
83
+
84
+ }
85
+
86
+ result[result_offset] = min;
87
+ result[result_offset + result_stride] = max;
88
+ }
89
+
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 1D
3
+ * Cubic spline.
4
+ * The result is [v0, m0, v1, m1] where X are values are M are tangents.
5
+ * @param {Float32Array|number[]} result where to put results
6
+ * @param {number} result_offset offset to start writing at in result array
7
+ * @param {number} result_stride how far to step between each written value. Necessary for N-dimensional curves where we want to interleave multiple curves together, such as for color or quaternions
8
+ * @param {number} p0
9
+ * @param {number} p1
10
+ * @param {number} p2
11
+ * @param {number} p3
12
+ * @see spline3_hermite_to_bezier
13
+ */
14
+ export function spline3_bezier_to_hermite(result: Float32Array | number[], result_offset: number, result_stride: number, p0: number, p1: number, p2: number, p3: number): void;
15
+ //# sourceMappingURL=spline3_bezier_to_hermite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline3_bezier_to_hermite.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline3_bezier_to_hermite.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,kDATW,YAAY,GAAC,MAAM,EAAE,iBACrB,MAAM,iBACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAsBhB"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 1D
3
+ * Cubic spline.
4
+ * The result is [v0, m0, v1, m1] where X are values are M are tangents.
5
+ * @param {Float32Array|number[]} result where to put results
6
+ * @param {number} result_offset offset to start writing at in result array
7
+ * @param {number} result_stride how far to step between each written value. Necessary for N-dimensional curves where we want to interleave multiple curves together, such as for color or quaternions
8
+ * @param {number} p0
9
+ * @param {number} p1
10
+ * @param {number} p2
11
+ * @param {number} p3
12
+ * @see spline3_hermite_to_bezier
13
+ */
14
+ export function spline3_bezier_to_hermite(
15
+ result,
16
+ result_offset,
17
+ result_stride,
18
+ p0, p1, p2, p3,
19
+ ) {
20
+
21
+ // see https://github.com/krishauser/Klampt/blob/0ed16608a3eceee59d04383a17c207ebc33a399f/Python/klampt/math/spline.py#L133
22
+
23
+ const TENSION_FACTOR = 3;
24
+
25
+ const v0 = (p1 - p0) * TENSION_FACTOR;
26
+ const v1 = (p3 - p2) * TENSION_FACTOR;
27
+
28
+ result[result_offset + 0 * result_stride] = p0;
29
+ result[result_offset + 1 * result_stride] = v0;
30
+ result[result_offset + 2 * result_stride] = p3;
31
+ result[result_offset + 3 * result_stride] = v1;
32
+
33
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Perform cubic hermite interpolation
3
+ * @see https://en.wikipedia.org/wiki/Cubic_Hermite_spline
4
+ * @param {number} t normalized interpolation position in interval [0,1]
5
+ * @param {number} p0 first value
6
+ * @param {number} p1 second value
7
+ * @param {number} m0 first tangent (tangent exiting from first value)
8
+ * @param {number} m1 second tangent (tangent entering into second value)
9
+ * @return {number}
10
+ *
11
+ * @author Alex Goldring
12
+ * @copyright Company Named Limited (c) 2025
13
+ */
14
+ export function spline3_hermite(t: number, p0: number, p1: number, m0: number, m1: number): number;
15
+ //# sourceMappingURL=spline3_hermite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline3_hermite.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline3_hermite.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,mCAVW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAgBjB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Perform cubic hermite interpolation
3
+ * @see https://en.wikipedia.org/wiki/Cubic_Hermite_spline
4
+ * @param {number} t normalized interpolation position in interval [0,1]
5
+ * @param {number} p0 first value
6
+ * @param {number} p1 second value
7
+ * @param {number} m0 first tangent (tangent exiting from first value)
8
+ * @param {number} m1 second tangent (tangent entering into second value)
9
+ * @return {number}
10
+ *
11
+ * @author Alex Goldring
12
+ * @copyright Company Named Limited (c) 2025
13
+ */
14
+ export function spline3_hermite(t, p0, p1, m0, m1) {
15
+
16
+ const t2 = t * t;
17
+ const t3 = t2 * t;
18
+
19
+ const a = 2 * t3 - 3 * t2 + 1;
20
+ const b = t3 - 2 * t2 + t;
21
+ const c = t3 - t2;
22
+ const d = -2 * t3 + 3 * t2;
23
+
24
+ return a * p0 + b * m0 + c * m1 + d * p1;
25
+ }
26
+
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Compute `y0,y1` bounds of a cubic hermite spline.
3
+ * Lower bound will be written into result[offset], upper bounds will be written into result[offset+result_stride]
4
+ *
5
+ * @param {number[]|Float32Array} result output will be written here, only y0 and y1
6
+ * @param {number} result_offset offset into the result array
7
+ * @param {number} result_stride useful for mixing multidimensional results
8
+ * @param {number} p0
9
+ * @param {number} p1
10
+ * @param {number} m0
11
+ * @param {number} m1
12
+ *
13
+ * @author Alex Goldring
14
+ * @copyright Company Named Limited (c) 2025
15
+ */
16
+ export function spline3_hermite_bounds(result: number[] | Float32Array, result_offset: number, result_stride: number, p0: number, p1: number, m0: number, m1: number): void;
17
+ //# sourceMappingURL=spline3_hermite_bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline3_hermite_bounds.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline3_hermite_bounds.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,+CAXW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,iBACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAqFhB"}