@woosh/meep-engine 2.94.1 → 2.94.4

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.
@@ -355,6 +355,24 @@ export class Transform {
355
355
  toString() {
356
356
  return `{ position: ${this.position}, rotation: ${this.rotation}, scale: ${this.scale} }`;
357
357
  }
358
+
359
+ /**
360
+ * @deprecated use {@link Quaternion.rotateTowards} instead
361
+ * @param {Quaternion} sourceQuaternion
362
+ * @param {Vector3} targetVector
363
+ * @param {Number} limit
364
+ */
365
+ static adjustRotation(
366
+ sourceQuaternion,
367
+ targetVector,
368
+ limit = Infinity
369
+ ) {
370
+ const q = new Quaternion();
371
+
372
+ q.lookRotation(targetVector);
373
+
374
+ sourceQuaternion.rotateTowards(q, limit);
375
+ }
358
376
  }
359
377
 
360
378
  /**
@@ -370,17 +388,4 @@ Transform.typeName = "Transform";
370
388
  Transform.prototype.isTransform = true;
371
389
 
372
390
 
373
- /**
374
- * @deprecated use {@link Quaternion.rotateTowards} instead
375
- * @param {Quaternion} sourceQuaternion
376
- * @param {Vector3} targetVector
377
- * @param {Number} limit
378
- */
379
- Transform.adjustRotation = function (sourceQuaternion, targetVector, limit = Infinity) {
380
- const q = new Quaternion();
381
-
382
- q.lookRotation(targetVector);
383
-
384
- sourceQuaternion.rotateTowards(q, limit);
385
- };
386
391
 
@@ -1,9 +1,24 @@
1
+ import { jest } from "@jest/globals";
1
2
  import { MATRIX_4_IDENTITY } from "../../../core/geom/3d/mat4/MATRIX_4_IDENTITY.js";
2
3
  import Quaternion from "../../../core/geom/Quaternion.js";
3
4
  import Vector3 from "../../../core/geom/Vector3.js";
4
5
  import { Transform } from "./Transform.js";
5
6
  import { TransformFlags } from "./TransformFlags.js";
6
7
 
8
+ /**
9
+ *
10
+ * @return {Transform}
11
+ */
12
+ function sample_a() {
13
+ const a = new Transform();
14
+
15
+ a.position.set(1, 2, 3);
16
+ a.rotation.set(5, -7, 11, -13);
17
+ a.scale.set(17, -23, 29);
18
+
19
+ return a;
20
+ }
21
+
7
22
  test("constructor does not throw", () => {
8
23
 
9
24
  expect(() => new Transform()).not.toThrow();
@@ -46,19 +61,43 @@ test("position changes propagate to matrix", () => {
46
61
  expect(t.matrix[14]).toBe(-7);
47
62
  });
48
63
 
49
- /**
50
- *
51
- * @return {Transform}
52
- */
53
- function sample_a() {
54
- const a = new Transform();
64
+ test("subscribe/unsubscribe", () => {
65
+ const mock = jest.fn();
55
66
 
56
- a.position.set(1, 2, 3);
57
- a.rotation.set(5, -7, 11, -13);
58
- a.scale.set(17, -23, 29);
67
+ const t = sample_a();
59
68
 
60
- return a;
61
- }
69
+ t.subscribe(mock);
70
+
71
+ expect(mock).not.toHaveBeenCalled();
72
+
73
+ t.position._add(1, 0, 0);
74
+
75
+ expect(mock).toHaveBeenCalledTimes(1);
76
+
77
+ t.scale._add(0, 1, 0);
78
+
79
+ expect(mock).toHaveBeenCalledTimes(2);
80
+
81
+ t.rotation.set(-1, 3, -5, -t.rotation.w);
82
+
83
+ expect(mock).toHaveBeenCalledTimes(3);
84
+
85
+ t.unsubscribe(mock);
86
+
87
+ expect(mock).toHaveBeenCalledTimes(3);
88
+
89
+ t.position._add(1, 0, 0);
90
+
91
+ expect(mock).toHaveBeenCalledTimes(3);
92
+
93
+ t.scale._add(0, 1, 0);
94
+
95
+ expect(mock).toHaveBeenCalledTimes(3);
96
+
97
+ t.rotation.set(-1, 3, -5, -t.rotation.w);
98
+
99
+ expect(mock).toHaveBeenCalledTimes(3);
100
+ });
62
101
 
63
102
  test("to/fromJSON consistency", () => {
64
103
  const a = sample_a();
@@ -5,9 +5,8 @@
5
5
  * @param {number} height
6
6
  * @param {number} start
7
7
  * @param {number} goal
8
- * @param {number} crossing_penalty
9
8
  * @param {number} block_value value in the field that signifies impassible obstacle
10
9
  * @returns {Array.<number>} array of indices representing path from start to end
11
10
  */
12
- export function find_path_on_grid_astar(field: number[] | Uint8Array | Uint16Array | Float32Array, width: number, height: number, start: number, goal: number, crossing_penalty: number, block_value: number): Array<number>;
11
+ export function find_path_on_grid_astar(field: number[] | Uint8Array | Uint16Array | Float32Array, width: number, height: number, start: number, goal: number, block_value: number): Array<number>;
13
12
  //# sourceMappingURL=find_path_on_grid_astar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find_path_on_grid_astar.d.ts","sourceRoot":"","sources":["../../../../../src/engine/navigation/grid/find_path_on_grid_astar.js"],"names":[],"mappings":"AAkMA;;;;;;;;;;GAUG;AACH,+CATW,MAAM,EAAE,GAAC,UAAU,GAAC,WAAW,GAAC,YAAY,SAC5C,MAAM,UACN,MAAM,SACN,MAAM,QACN,MAAM,oBACN,MAAM,eACN,MAAM,GACJ,MAAO,MAAM,CAAC,CA6F1B"}
1
+ {"version":3,"file":"find_path_on_grid_astar.d.ts","sourceRoot":"","sources":["../../../../../src/engine/navigation/grid/find_path_on_grid_astar.js"],"names":[],"mappings":"AAoMA;;;;;;;;;GASG;AACH,+CARW,MAAM,EAAE,GAAC,UAAU,GAAC,WAAW,GAAC,YAAY,SAC5C,MAAM,UACN,MAAM,SACN,MAAM,QACN,MAAM,eACN,MAAM,GACJ,MAAO,MAAM,CAAC,CA2F1B"}
@@ -2,6 +2,7 @@ import { assert } from "../../../core/assert.js";
2
2
  import { BitSet } from "../../../core/binary/BitSet.js";
3
3
  import { Uint32Heap } from "../../../core/collection/heap/Uint32Heap.js";
4
4
  import Vector2 from '../../../core/geom/Vector2.js';
5
+ import { sign } from "../../../core/math/sign.js";
5
6
 
6
7
  const neighbors = new Uint32Array(4);
7
8
 
@@ -58,7 +59,7 @@ function compute_neighbors(result, index, width, height) {
58
59
  /**
59
60
  *
60
61
  * @param {number} node
61
- * @param {number[]} g_score
62
+ * @param {number[]|Float32Array} g_score
62
63
  * @param {number} width
63
64
  * @param {number} height
64
65
  * @returns {number[]}
@@ -87,11 +88,11 @@ function compute_path(node, g_score, width, height) {
87
88
 
88
89
  // normalize
89
90
  if (_dx !== 0) {
90
- _dx /= Math.abs(_dx);
91
+ _dx = sign(_dx);
91
92
  }
92
93
 
93
94
  if (_dy !== 0) {
94
- _dy /= Math.abs(_dy);
95
+ _dy = sign(_dy);
95
96
  }
96
97
 
97
98
  const direction_change = dx !== _dx || dy !== _dy;
@@ -152,6 +153,7 @@ function compute_path(node, g_score, width, height) {
152
153
 
153
154
  }
154
155
 
156
+ // so far the path is from goal to start, we need to reverse it
155
157
  result.reverse();
156
158
 
157
159
  return result;
@@ -199,7 +201,6 @@ let g_score = new Float32Array(1024);
199
201
  * @param {number} height
200
202
  * @param {number} start
201
203
  * @param {number} goal
202
- * @param {number} crossing_penalty
203
204
  * @param {number} block_value value in the field that signifies impassible obstacle
204
205
  * @returns {Array.<number>} array of indices representing path from start to end
205
206
  */
@@ -207,7 +208,6 @@ export function find_path_on_grid_astar(
207
208
  field,
208
209
  width, height,
209
210
  start, goal,
210
- crossing_penalty,
211
211
  block_value
212
212
  ) {
213
213
 
@@ -217,7 +217,6 @@ export function find_path_on_grid_astar(
217
217
  assert.isNonNegativeInteger(start, "start");
218
218
  assert.isNonNegativeInteger(goal, "goal");
219
219
 
220
- assert.isNumber(crossing_penalty, 'crossingPenalty');
221
220
  assert.isNumber(block_value, 'blockValue');
222
221
 
223
222
  // prepare sets
@@ -271,7 +270,7 @@ export function find_path_on_grid_astar(
271
270
  }
272
271
 
273
272
  // Cost of traversing to this neighbour
274
- const transition_cost = neighbor_value * crossing_penalty + 1;
273
+ const transition_cost = neighbor_value + 1;
275
274
 
276
275
  // updated path cost
277
276
  const cost_so_far = g_score[currentNode] + transition_cost;
@@ -4,13 +4,13 @@ import { number_pretty_print } from "../../../core/primitives/numbers/number_pre
4
4
  import { find_path_on_grid_astar } from "./find_path_on_grid_astar.js";
5
5
 
6
6
  test("sanity check on 1x1 grid", () => {
7
- const path = find_path_on_grid_astar([0], 1, 1, 0, 0, 0, 1);
7
+ const path = find_path_on_grid_astar([0], 1, 1, 0, 0, 1);
8
8
 
9
9
  expect(path).toEqual([0]);
10
10
  });
11
11
 
12
12
  test("sanity check on 2x1 grid", () => {
13
- const path = find_path_on_grid_astar([0, 0], 2, 1, 0, 1, 0, 1);
13
+ const path = find_path_on_grid_astar([0, 0], 2, 1, 0, 1, 1);
14
14
 
15
15
  expect(path).toEqual([0, 1]);
16
16
  });
@@ -20,7 +20,7 @@ test("sanity check on 2x2 grid", () => {
20
20
  const path = find_path_on_grid_astar([
21
21
  0, 0,
22
22
  1, 0
23
- ], 2, 2, 0, 3, 0, 1);
23
+ ], 2, 2, 0, 3, 1);
24
24
 
25
25
  expect(path).toEqual([0, 1, 3]);
26
26
  });
@@ -31,7 +31,7 @@ test("path on open 3x3 grid", () => {
31
31
  0, 0, 0,
32
32
  0, 0, 0,
33
33
  0, 0, 0
34
- ], 3, 3, 0, 8, 0, 1);
34
+ ], 3, 3, 0, 8, 1);
35
35
 
36
36
  expect(path).toEqual([0, 3, 5, 8]);
37
37
  });
@@ -76,12 +76,7 @@ test.skip("performance, 256x256 random", () => {
76
76
  const start = coordinates[i2];
77
77
  const goal = coordinates[i2 + 1];
78
78
 
79
- find_path_on_grid_astar(
80
- field,
81
- FIELD_SIZE, FIELD_SIZE,
82
- start,
83
- goal, 1, 255
84
- );
79
+ find_path_on_grid_astar(field, FIELD_SIZE, FIELD_SIZE, start, goal, 255);
85
80
  }
86
81
 
87
82
  const t1 = performance.now();