@woosh/meep-engine 2.94.1 → 2.94.2

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.
@@ -116584,7 +116584,7 @@ function compute_neighbors(result, index, width, height) {
116584
116584
  /**
116585
116585
  *
116586
116586
  * @param {number} node
116587
- * @param {number[]} g_score
116587
+ * @param {number[]|Float32Array} g_score
116588
116588
  * @param {number} width
116589
116589
  * @param {number} height
116590
116590
  * @returns {number[]}
@@ -116613,11 +116613,11 @@ function compute_path(node, g_score, width, height) {
116613
116613
 
116614
116614
  // normalize
116615
116615
  if (_dx !== 0) {
116616
- _dx /= Math.abs(_dx);
116616
+ _dx = sign$1(_dx);
116617
116617
  }
116618
116618
 
116619
116619
  if (_dy !== 0) {
116620
- _dy /= Math.abs(_dy);
116620
+ _dy = sign$1(_dy);
116621
116621
  }
116622
116622
 
116623
116623
  const direction_change = dx !== _dx || dy !== _dy;
@@ -116678,6 +116678,7 @@ function compute_path(node, g_score, width, height) {
116678
116678
 
116679
116679
  }
116680
116680
 
116681
+ // so far the path is from goal to start, we need to reverse it
116681
116682
  result.reverse();
116682
116683
 
116683
116684
  return result;
@@ -116725,7 +116726,6 @@ let g_score = new Float32Array(1024);
116725
116726
  * @param {number} height
116726
116727
  * @param {number} start
116727
116728
  * @param {number} goal
116728
- * @param {number} crossing_penalty
116729
116729
  * @param {number} block_value value in the field that signifies impassible obstacle
116730
116730
  * @returns {Array.<number>} array of indices representing path from start to end
116731
116731
  */
@@ -116733,7 +116733,6 @@ function find_path_on_grid_astar(
116733
116733
  field,
116734
116734
  width, height,
116735
116735
  start, goal,
116736
- crossing_penalty,
116737
116736
  block_value
116738
116737
  ) {
116739
116738
 
@@ -116788,7 +116787,7 @@ function find_path_on_grid_astar(
116788
116787
  }
116789
116788
 
116790
116789
  // Cost of traversing to this neighbour
116791
- const transition_cost = neighbor_value * crossing_penalty + 1;
116790
+ const transition_cost = neighbor_value + 1;
116792
116791
 
116793
116792
  // updated path cost
116794
116793
  const cost_so_far = g_score[currentNode] + transition_cost;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.94.1",
8
+ "version": "2.94.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -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();