@woosh/meep-engine 2.94.0 → 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.
- package/build/meep.cjs +46 -43
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +46 -43
- package/package.json +1 -1
- package/src/core/collection/heap/Uint32Heap.d.ts.map +1 -1
- package/src/core/collection/heap/Uint32Heap.js +22 -17
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts +1 -2
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +24 -26
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +7 -12
- package/src/engine/ui/GUIEngine.js +1 -1
package/build/meep.module.js
CHANGED
|
@@ -102842,7 +102842,7 @@ class GUIEngine {
|
|
|
102842
102842
|
|
|
102843
102843
|
constructor() {
|
|
102844
102844
|
|
|
102845
|
-
this.ticker.
|
|
102845
|
+
this.ticker.onTick.add(d => {
|
|
102846
102846
|
|
|
102847
102847
|
|
|
102848
102848
|
let ctx = null;
|
|
@@ -116251,17 +116251,17 @@ class Uint32Heap {
|
|
|
116251
116251
|
const size = this.__size;
|
|
116252
116252
|
|
|
116253
116253
|
while (true) {
|
|
116254
|
-
const
|
|
116255
|
-
const
|
|
116254
|
+
const left = (i << 1) + 1;
|
|
116255
|
+
const right = left + 1;
|
|
116256
116256
|
|
|
116257
116257
|
let smallest = i;
|
|
116258
116258
|
|
|
116259
|
-
if (
|
|
116260
|
-
smallest =
|
|
116259
|
+
if (left < size && this.compare(left, smallest)) {
|
|
116260
|
+
smallest = left;
|
|
116261
116261
|
}
|
|
116262
116262
|
|
|
116263
|
-
if (
|
|
116264
|
-
smallest =
|
|
116263
|
+
if (right < size && this.compare(right, smallest)) {
|
|
116264
|
+
smallest = right;
|
|
116265
116265
|
}
|
|
116266
116266
|
|
|
116267
116267
|
if (smallest === i) {
|
|
@@ -116335,19 +116335,23 @@ class Uint32Heap {
|
|
|
116335
116335
|
|
|
116336
116336
|
pop_min() {
|
|
116337
116337
|
|
|
116338
|
-
const
|
|
116338
|
+
const new_size = this.__size - 1;
|
|
116339
|
+
this.__size = new_size;
|
|
116339
116340
|
|
|
116340
|
-
this.
|
|
116341
|
+
const uint32 = this.__data_uint32;
|
|
116342
|
+
const top_id = uint32[1];
|
|
116341
116343
|
|
|
116342
|
-
|
|
116343
|
-
|
|
116344
|
-
|
|
116344
|
+
// move bottom element to the top.
|
|
116345
|
+
// the top doesn't need to be moved down as we have discarded it already
|
|
116346
|
+
const i2 = new_size << 1; // same as *2
|
|
116345
116347
|
|
|
116346
|
-
|
|
116347
|
-
|
|
116348
|
-
}
|
|
116348
|
+
uint32[0] = uint32[i2];
|
|
116349
|
+
uint32[1] = uint32[i2 + 1];
|
|
116349
116350
|
|
|
116350
|
-
|
|
116351
|
+
// re-balance
|
|
116352
|
+
this.heap_down(0);
|
|
116353
|
+
|
|
116354
|
+
return top_id;
|
|
116351
116355
|
}
|
|
116352
116356
|
|
|
116353
116357
|
/**
|
|
@@ -116365,6 +116369,7 @@ class Uint32Heap {
|
|
|
116365
116369
|
const _id = uint32[address];
|
|
116366
116370
|
|
|
116367
116371
|
if (_id === id) {
|
|
116372
|
+
// reverse address to index
|
|
116368
116373
|
return (address >>> 1);
|
|
116369
116374
|
}
|
|
116370
116375
|
}
|
|
@@ -116378,7 +116383,7 @@ class Uint32Heap {
|
|
|
116378
116383
|
* @param {number} id
|
|
116379
116384
|
* @returns {boolean}
|
|
116380
116385
|
*/
|
|
116381
|
-
contains(id){
|
|
116386
|
+
contains(id) {
|
|
116382
116387
|
return this.find_index_by_id(id) !== -1;
|
|
116383
116388
|
}
|
|
116384
116389
|
|
|
@@ -116509,7 +116514,7 @@ class Uint32Heap {
|
|
|
116509
116514
|
|
|
116510
116515
|
// insert at the end
|
|
116511
116516
|
const index = current_size;
|
|
116512
|
-
const address = index << 1;
|
|
116517
|
+
const address = index << 1; // same as *2
|
|
116513
116518
|
|
|
116514
116519
|
// write data
|
|
116515
116520
|
this.__data_float32[address] = score;
|
|
@@ -116579,7 +116584,7 @@ function compute_neighbors(result, index, width, height) {
|
|
|
116579
116584
|
/**
|
|
116580
116585
|
*
|
|
116581
116586
|
* @param {number} node
|
|
116582
|
-
* @param {number[]} g_score
|
|
116587
|
+
* @param {number[]|Float32Array} g_score
|
|
116583
116588
|
* @param {number} width
|
|
116584
116589
|
* @param {number} height
|
|
116585
116590
|
* @returns {number[]}
|
|
@@ -116608,11 +116613,11 @@ function compute_path(node, g_score, width, height) {
|
|
|
116608
116613
|
|
|
116609
116614
|
// normalize
|
|
116610
116615
|
if (_dx !== 0) {
|
|
116611
|
-
_dx
|
|
116616
|
+
_dx = sign$1(_dx);
|
|
116612
116617
|
}
|
|
116613
116618
|
|
|
116614
116619
|
if (_dy !== 0) {
|
|
116615
|
-
_dy
|
|
116620
|
+
_dy = sign$1(_dy);
|
|
116616
116621
|
}
|
|
116617
116622
|
|
|
116618
116623
|
const direction_change = dx !== _dx || dy !== _dy;
|
|
@@ -116673,6 +116678,7 @@ function compute_path(node, g_score, width, height) {
|
|
|
116673
116678
|
|
|
116674
116679
|
}
|
|
116675
116680
|
|
|
116681
|
+
// so far the path is from goal to start, we need to reverse it
|
|
116676
116682
|
result.reverse();
|
|
116677
116683
|
|
|
116678
116684
|
return result;
|
|
@@ -116707,6 +116713,12 @@ const open = new Uint32Heap();
|
|
|
116707
116713
|
const closed = new BitSet();
|
|
116708
116714
|
closed.preventShrink();
|
|
116709
116715
|
|
|
116716
|
+
/**
|
|
116717
|
+
* Contains refined heuristic value
|
|
116718
|
+
* @type {Float32Array}
|
|
116719
|
+
*/
|
|
116720
|
+
let g_score = new Float32Array(1024);
|
|
116721
|
+
|
|
116710
116722
|
/**
|
|
116711
116723
|
*
|
|
116712
116724
|
* @param {number[]|Uint8Array|Uint16Array|Float32Array} field
|
|
@@ -116714,7 +116726,6 @@ closed.preventShrink();
|
|
|
116714
116726
|
* @param {number} height
|
|
116715
116727
|
* @param {number} start
|
|
116716
116728
|
* @param {number} goal
|
|
116717
|
-
* @param {number} crossing_penalty
|
|
116718
116729
|
* @param {number} block_value value in the field that signifies impassible obstacle
|
|
116719
116730
|
* @returns {Array.<number>} array of indices representing path from start to end
|
|
116720
116731
|
*/
|
|
@@ -116722,7 +116733,6 @@ function find_path_on_grid_astar(
|
|
|
116722
116733
|
field,
|
|
116723
116734
|
width, height,
|
|
116724
116735
|
start, goal,
|
|
116725
|
-
crossing_penalty,
|
|
116726
116736
|
block_value
|
|
116727
116737
|
) {
|
|
116728
116738
|
|
|
@@ -116730,14 +116740,15 @@ function find_path_on_grid_astar(
|
|
|
116730
116740
|
open.clear();
|
|
116731
116741
|
closed.reset();
|
|
116732
116742
|
|
|
116733
|
-
|
|
116734
|
-
* Contains refined heuristic value
|
|
116735
|
-
* @type {number[]}
|
|
116736
|
-
*/
|
|
116737
|
-
const g_score = [];
|
|
116743
|
+
const cell_count = width * height;
|
|
116738
116744
|
|
|
116739
|
-
g_score
|
|
116745
|
+
if (g_score.length < cell_count) {
|
|
116746
|
+
g_score = new Float32Array(cell_count);
|
|
116747
|
+
}
|
|
116740
116748
|
|
|
116749
|
+
g_score.fill(Infinity, 0, cell_count);
|
|
116750
|
+
|
|
116751
|
+
g_score[start] = 0;
|
|
116741
116752
|
|
|
116742
116753
|
open.insert(start, heuristic(start, goal, width));
|
|
116743
116754
|
|
|
@@ -116776,32 +116787,24 @@ function find_path_on_grid_astar(
|
|
|
116776
116787
|
}
|
|
116777
116788
|
|
|
116778
116789
|
// Cost of traversing to this neighbour
|
|
116779
|
-
const transition_cost = neighbor_value
|
|
116790
|
+
const transition_cost = neighbor_value + 1;
|
|
116780
116791
|
|
|
116781
116792
|
// updated path cost
|
|
116782
116793
|
const cost_so_far = g_score[currentNode] + transition_cost;
|
|
116783
116794
|
|
|
116784
|
-
|
|
116795
|
+
if (cost_so_far < g_score[neighbor]) {
|
|
116785
116796
|
|
|
116786
|
-
|
|
116787
|
-
|
|
116788
|
-
if (not_in_open_set || cost_so_far < g_score[neighbor]) {
|
|
116789
|
-
|
|
116790
|
-
// update refined score
|
|
116797
|
+
// update actual cost
|
|
116791
116798
|
g_score[neighbor] = cost_so_far;
|
|
116792
116799
|
|
|
116793
116800
|
const remaining_heuristic = heuristic(neighbor, goal, width);
|
|
116794
116801
|
|
|
116795
116802
|
const refined_heuristic = cost_so_far + remaining_heuristic;
|
|
116796
116803
|
|
|
116797
|
-
|
|
116798
|
-
|
|
116799
|
-
open.insert(neighbor, refined_heuristic);
|
|
116800
|
-
} else {
|
|
116801
|
-
// Already seen the node, but since it has been re-scored we need to reorder it in the heap
|
|
116802
|
-
open.__update_score_by_index(index_in_open_set, refined_heuristic);
|
|
116803
|
-
}
|
|
116804
|
+
// Pushing to heap will put it in proper place based on the 'f' value.
|
|
116805
|
+
open.insert_or_update(neighbor, refined_heuristic);
|
|
116804
116806
|
}
|
|
116807
|
+
|
|
116805
116808
|
}
|
|
116806
116809
|
}
|
|
116807
116810
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Uint32Heap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/heap/Uint32Heap.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IACI;;;OAGG;IACH,+BAFW,MAAM,EAuBhB;IAlBG,2BAA0E;IAE1E;;;;OAIG;IACH,sBAAwD;IAExD;;;;OAIG;IACH,uBAA0D;IAE1D,mBAAkC;IAClC,eAAe;IAGnB;;;OAGG;IACH,wBAsBC;IAED;;;;;OAKG;IACH,gBAOC;IAED;;;;;OAKG;IACH,aAiBC;IAED;;;OAGG;IACH,kBA6BC;IAED;;;;OAIG;IACH,gBAeC;IAED;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,YAFa,OAAO,CAInB;IAED,mBAEC;IAED,
|
|
1
|
+
{"version":3,"file":"Uint32Heap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/heap/Uint32Heap.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IACI;;;OAGG;IACH,+BAFW,MAAM,EAuBhB;IAlBG,2BAA0E;IAE1E;;;;OAIG;IACH,sBAAwD;IAExD;;;;OAIG;IACH,uBAA0D;IAE1D,mBAAkC;IAClC,eAAe;IAGnB;;;OAGG;IACH,wBAsBC;IAED;;;;;OAKG;IACH,gBAOC;IAED;;;;;OAKG;IACH,aAiBC;IAED;;;OAGG;IACH,kBA6BC;IAED;;;;OAIG;IACH,gBAeC;IAED;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,YAFa,OAAO,CAInB;IAED,mBAEC;IAED,kBAoBC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACJ,MAAM,CAmBlB;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,OAAO,CAInB;IAED;;OAEG;IACH,cAEC;IAED;;;;OAIG;IACH,WAHW,MAAM,GACJ,OAAO,CAWnB;IAED;;;OAGG;IACH,yBAFW,MAAM,QAehB;IAED;;;;OAIG;IACH,iBAHW,MAAM,SACN,MAAM,QAUhB;IAED;;;;OAIG;IACH,+BAHW,MAAM,SACN,MAAM,QAiBhB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,MAAM,CAYlB;IAGD;;;;OAIG;IACH,qBAHW,MAAM,SACN,MAAM,QAUhB;IAED;;;;OAIG;IACH,WAHW,MAAM,SACN,MAAM,QA0BhB;CAGJ"}
|
|
@@ -159,17 +159,17 @@ export class Uint32Heap {
|
|
|
159
159
|
const size = this.__size;
|
|
160
160
|
|
|
161
161
|
while (true) {
|
|
162
|
-
const
|
|
163
|
-
const
|
|
162
|
+
const left = (i << 1) + 1;
|
|
163
|
+
const right = left + 1;
|
|
164
164
|
|
|
165
165
|
let smallest = i;
|
|
166
166
|
|
|
167
|
-
if (
|
|
168
|
-
smallest =
|
|
167
|
+
if (left < size && this.compare(left, smallest)) {
|
|
168
|
+
smallest = left;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
if (
|
|
172
|
-
smallest =
|
|
171
|
+
if (right < size && this.compare(right, smallest)) {
|
|
172
|
+
smallest = right;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
if (smallest === i) {
|
|
@@ -244,19 +244,23 @@ export class Uint32Heap {
|
|
|
244
244
|
pop_min() {
|
|
245
245
|
assert.greaterThan(this.__size, 0, 'heap is empty');
|
|
246
246
|
|
|
247
|
-
const
|
|
247
|
+
const new_size = this.__size - 1;
|
|
248
|
+
this.__size = new_size;
|
|
248
249
|
|
|
249
|
-
this.
|
|
250
|
+
const uint32 = this.__data_uint32;
|
|
251
|
+
const top_id = uint32[1];
|
|
250
252
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
// move bottom element to the top.
|
|
254
|
+
// the top doesn't need to be moved down as we have discarded it already
|
|
255
|
+
const i2 = new_size << 1; // same as *2
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
uint32[0] = uint32[i2];
|
|
258
|
+
uint32[1] = uint32[i2 + 1];
|
|
259
|
+
|
|
260
|
+
// re-balance
|
|
261
|
+
this.heap_down(0);
|
|
258
262
|
|
|
259
|
-
return
|
|
263
|
+
return top_id;
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
/**
|
|
@@ -274,6 +278,7 @@ export class Uint32Heap {
|
|
|
274
278
|
const _id = uint32[address];
|
|
275
279
|
|
|
276
280
|
if (_id === id) {
|
|
281
|
+
// reverse address to index
|
|
277
282
|
return (address >>> 1);
|
|
278
283
|
}
|
|
279
284
|
}
|
|
@@ -287,7 +292,7 @@ export class Uint32Heap {
|
|
|
287
292
|
* @param {number} id
|
|
288
293
|
* @returns {boolean}
|
|
289
294
|
*/
|
|
290
|
-
contains(id){
|
|
295
|
+
contains(id) {
|
|
291
296
|
return this.find_index_by_id(id) !== -1;
|
|
292
297
|
}
|
|
293
298
|
|
|
@@ -422,7 +427,7 @@ export class Uint32Heap {
|
|
|
422
427
|
|
|
423
428
|
// insert at the end
|
|
424
429
|
const index = current_size;
|
|
425
|
-
const address = index << 1;
|
|
430
|
+
const address = index << 1; // same as *2
|
|
426
431
|
|
|
427
432
|
// write data
|
|
428
433
|
this.__data_float32[address] = score;
|
|
@@ -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,
|
|
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":"
|
|
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
|
|
91
|
+
_dx = sign(_dx);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
if (_dy !== 0) {
|
|
94
|
-
_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;
|
|
@@ -186,6 +188,12 @@ const open = new Uint32Heap();
|
|
|
186
188
|
const closed = new BitSet();
|
|
187
189
|
closed.preventShrink();
|
|
188
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Contains refined heuristic value
|
|
193
|
+
* @type {Float32Array}
|
|
194
|
+
*/
|
|
195
|
+
let g_score = new Float32Array(1024);
|
|
196
|
+
|
|
189
197
|
/**
|
|
190
198
|
*
|
|
191
199
|
* @param {number[]|Uint8Array|Uint16Array|Float32Array} field
|
|
@@ -193,7 +201,6 @@ closed.preventShrink();
|
|
|
193
201
|
* @param {number} height
|
|
194
202
|
* @param {number} start
|
|
195
203
|
* @param {number} goal
|
|
196
|
-
* @param {number} crossing_penalty
|
|
197
204
|
* @param {number} block_value value in the field that signifies impassible obstacle
|
|
198
205
|
* @returns {Array.<number>} array of indices representing path from start to end
|
|
199
206
|
*/
|
|
@@ -201,7 +208,6 @@ export function find_path_on_grid_astar(
|
|
|
201
208
|
field,
|
|
202
209
|
width, height,
|
|
203
210
|
start, goal,
|
|
204
|
-
crossing_penalty,
|
|
205
211
|
block_value
|
|
206
212
|
) {
|
|
207
213
|
|
|
@@ -211,21 +217,21 @@ export function find_path_on_grid_astar(
|
|
|
211
217
|
assert.isNonNegativeInteger(start, "start");
|
|
212
218
|
assert.isNonNegativeInteger(goal, "goal");
|
|
213
219
|
|
|
214
|
-
assert.isNumber(crossing_penalty, 'crossingPenalty');
|
|
215
220
|
assert.isNumber(block_value, 'blockValue');
|
|
216
221
|
|
|
217
222
|
// prepare sets
|
|
218
223
|
open.clear();
|
|
219
224
|
closed.reset();
|
|
220
225
|
|
|
221
|
-
|
|
222
|
-
* Contains refined heuristic value
|
|
223
|
-
* @type {number[]}
|
|
224
|
-
*/
|
|
225
|
-
const g_score = [];
|
|
226
|
+
const cell_count = width * height;
|
|
226
227
|
|
|
227
|
-
g_score
|
|
228
|
+
if (g_score.length < cell_count) {
|
|
229
|
+
g_score = new Float32Array(cell_count);
|
|
230
|
+
}
|
|
228
231
|
|
|
232
|
+
g_score.fill(Infinity, 0, cell_count);
|
|
233
|
+
|
|
234
|
+
g_score[start] = 0;
|
|
229
235
|
|
|
230
236
|
open.insert(start, heuristic(start, goal, width));
|
|
231
237
|
|
|
@@ -264,32 +270,24 @@ export function find_path_on_grid_astar(
|
|
|
264
270
|
}
|
|
265
271
|
|
|
266
272
|
// Cost of traversing to this neighbour
|
|
267
|
-
const transition_cost = neighbor_value
|
|
273
|
+
const transition_cost = neighbor_value + 1;
|
|
268
274
|
|
|
269
275
|
// updated path cost
|
|
270
276
|
const cost_so_far = g_score[currentNode] + transition_cost;
|
|
271
277
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const not_in_open_set = index_in_open_set === -1;
|
|
275
|
-
|
|
276
|
-
if (not_in_open_set || cost_so_far < g_score[neighbor]) {
|
|
278
|
+
if (cost_so_far < g_score[neighbor]) {
|
|
277
279
|
|
|
278
|
-
// update
|
|
280
|
+
// update actual cost
|
|
279
281
|
g_score[neighbor] = cost_so_far;
|
|
280
282
|
|
|
281
283
|
const remaining_heuristic = heuristic(neighbor, goal, width);
|
|
282
284
|
|
|
283
285
|
const refined_heuristic = cost_so_far + remaining_heuristic;
|
|
284
286
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
open.insert(neighbor, refined_heuristic);
|
|
288
|
-
} else {
|
|
289
|
-
// Already seen the node, but since it has been re-scored we need to reorder it in the heap
|
|
290
|
-
open.__update_score_by_index(index_in_open_set, refined_heuristic);
|
|
291
|
-
}
|
|
287
|
+
// Pushing to heap will put it in proper place based on the 'f' value.
|
|
288
|
+
open.insert_or_update(neighbor, refined_heuristic)
|
|
292
289
|
}
|
|
290
|
+
|
|
293
291
|
}
|
|
294
292
|
}
|
|
295
293
|
|
|
@@ -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,
|
|
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,
|
|
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,
|
|
23
|
+
], 2, 2, 0, 3, 1);
|
|
24
24
|
|
|
25
25
|
expect(path).toEqual([0, 1, 3]);
|
|
26
26
|
});
|
|
@@ -31,12 +31,12 @@ 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,
|
|
34
|
+
], 3, 3, 0, 8, 1);
|
|
35
35
|
|
|
36
36
|
expect(path).toEqual([0, 3, 5, 8]);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
test("performance, 256x256 random", () => {
|
|
39
|
+
test.skip("performance, 256x256 random", () => {
|
|
40
40
|
const FIELD_SIZE = 256;
|
|
41
41
|
|
|
42
42
|
const field = new Uint8Array(FIELD_SIZE * FIELD_SIZE);
|
|
@@ -52,7 +52,7 @@ test("performance, 256x256 random", () => {
|
|
|
52
52
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const SAMPLE_COUNT =
|
|
55
|
+
const SAMPLE_COUNT = 100000;
|
|
56
56
|
|
|
57
57
|
const coordinates = new Uint32Array(SAMPLE_COUNT * 2);
|
|
58
58
|
|
|
@@ -76,12 +76,7 @@ test("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();
|