@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 CHANGED
@@ -102844,7 +102844,7 @@ class GUIEngine {
102844
102844
 
102845
102845
  constructor() {
102846
102846
 
102847
- this.ticker.subscribe(d => {
102847
+ this.ticker.onTick.add(d => {
102848
102848
 
102849
102849
 
102850
102850
  let ctx = null;
@@ -116253,17 +116253,17 @@ class Uint32Heap {
116253
116253
  const size = this.__size;
116254
116254
 
116255
116255
  while (true) {
116256
- const l = (i << 1) + 1;
116257
- const r = l + 1;
116256
+ const left = (i << 1) + 1;
116257
+ const right = left + 1;
116258
116258
 
116259
116259
  let smallest = i;
116260
116260
 
116261
- if (l < size && this.compare(l, smallest)) {
116262
- smallest = l;
116261
+ if (left < size && this.compare(left, smallest)) {
116262
+ smallest = left;
116263
116263
  }
116264
116264
 
116265
- if (r < size && this.compare(r, smallest)) {
116266
- smallest = r;
116265
+ if (right < size && this.compare(right, smallest)) {
116266
+ smallest = right;
116267
116267
  }
116268
116268
 
116269
116269
  if (smallest === i) {
@@ -116337,19 +116337,23 @@ class Uint32Heap {
116337
116337
 
116338
116338
  pop_min() {
116339
116339
 
116340
- const result = this.top_id;
116340
+ const new_size = this.__size - 1;
116341
+ this.__size = new_size;
116341
116342
 
116342
- this.__size--;
116343
+ const uint32 = this.__data_uint32;
116344
+ const top_id = uint32[1];
116343
116345
 
116344
- if (this.__size > 0) {
116345
- // move top element to the bottom
116346
- this.swap(0, this.__size);
116346
+ // move bottom element to the top.
116347
+ // the top doesn't need to be moved down as we have discarded it already
116348
+ const i2 = new_size << 1; // same as *2
116347
116349
 
116348
- // rebalance
116349
- this.heap_down(0);
116350
- }
116350
+ uint32[0] = uint32[i2];
116351
+ uint32[1] = uint32[i2 + 1];
116351
116352
 
116352
- return result;
116353
+ // re-balance
116354
+ this.heap_down(0);
116355
+
116356
+ return top_id;
116353
116357
  }
116354
116358
 
116355
116359
  /**
@@ -116367,6 +116371,7 @@ class Uint32Heap {
116367
116371
  const _id = uint32[address];
116368
116372
 
116369
116373
  if (_id === id) {
116374
+ // reverse address to index
116370
116375
  return (address >>> 1);
116371
116376
  }
116372
116377
  }
@@ -116380,7 +116385,7 @@ class Uint32Heap {
116380
116385
  * @param {number} id
116381
116386
  * @returns {boolean}
116382
116387
  */
116383
- contains(id){
116388
+ contains(id) {
116384
116389
  return this.find_index_by_id(id) !== -1;
116385
116390
  }
116386
116391
 
@@ -116511,7 +116516,7 @@ class Uint32Heap {
116511
116516
 
116512
116517
  // insert at the end
116513
116518
  const index = current_size;
116514
- const address = index << 1;
116519
+ const address = index << 1; // same as *2
116515
116520
 
116516
116521
  // write data
116517
116522
  this.__data_float32[address] = score;
@@ -116581,7 +116586,7 @@ function compute_neighbors(result, index, width, height) {
116581
116586
  /**
116582
116587
  *
116583
116588
  * @param {number} node
116584
- * @param {number[]} g_score
116589
+ * @param {number[]|Float32Array} g_score
116585
116590
  * @param {number} width
116586
116591
  * @param {number} height
116587
116592
  * @returns {number[]}
@@ -116610,11 +116615,11 @@ function compute_path(node, g_score, width, height) {
116610
116615
 
116611
116616
  // normalize
116612
116617
  if (_dx !== 0) {
116613
- _dx /= Math.abs(_dx);
116618
+ _dx = sign$1(_dx);
116614
116619
  }
116615
116620
 
116616
116621
  if (_dy !== 0) {
116617
- _dy /= Math.abs(_dy);
116622
+ _dy = sign$1(_dy);
116618
116623
  }
116619
116624
 
116620
116625
  const direction_change = dx !== _dx || dy !== _dy;
@@ -116675,6 +116680,7 @@ function compute_path(node, g_score, width, height) {
116675
116680
 
116676
116681
  }
116677
116682
 
116683
+ // so far the path is from goal to start, we need to reverse it
116678
116684
  result.reverse();
116679
116685
 
116680
116686
  return result;
@@ -116709,6 +116715,12 @@ const open = new Uint32Heap();
116709
116715
  const closed = new BitSet();
116710
116716
  closed.preventShrink();
116711
116717
 
116718
+ /**
116719
+ * Contains refined heuristic value
116720
+ * @type {Float32Array}
116721
+ */
116722
+ let g_score = new Float32Array(1024);
116723
+
116712
116724
  /**
116713
116725
  *
116714
116726
  * @param {number[]|Uint8Array|Uint16Array|Float32Array} field
@@ -116716,7 +116728,6 @@ closed.preventShrink();
116716
116728
  * @param {number} height
116717
116729
  * @param {number} start
116718
116730
  * @param {number} goal
116719
- * @param {number} crossing_penalty
116720
116731
  * @param {number} block_value value in the field that signifies impassible obstacle
116721
116732
  * @returns {Array.<number>} array of indices representing path from start to end
116722
116733
  */
@@ -116724,7 +116735,6 @@ function find_path_on_grid_astar(
116724
116735
  field,
116725
116736
  width, height,
116726
116737
  start, goal,
116727
- crossing_penalty,
116728
116738
  block_value
116729
116739
  ) {
116730
116740
 
@@ -116732,14 +116742,15 @@ function find_path_on_grid_astar(
116732
116742
  open.clear();
116733
116743
  closed.reset();
116734
116744
 
116735
- /**
116736
- * Contains refined heuristic value
116737
- * @type {number[]}
116738
- */
116739
- const g_score = [];
116745
+ const cell_count = width * height;
116740
116746
 
116741
- g_score[start] = 0;
116747
+ if (g_score.length < cell_count) {
116748
+ g_score = new Float32Array(cell_count);
116749
+ }
116742
116750
 
116751
+ g_score.fill(Infinity, 0, cell_count);
116752
+
116753
+ g_score[start] = 0;
116743
116754
 
116744
116755
  open.insert(start, heuristic(start, goal, width));
116745
116756
 
@@ -116778,32 +116789,24 @@ function find_path_on_grid_astar(
116778
116789
  }
116779
116790
 
116780
116791
  // Cost of traversing to this neighbour
116781
- const transition_cost = neighbor_value * crossing_penalty + 1;
116792
+ const transition_cost = neighbor_value + 1;
116782
116793
 
116783
116794
  // updated path cost
116784
116795
  const cost_so_far = g_score[currentNode] + transition_cost;
116785
116796
 
116786
- const index_in_open_set = open.find_index_by_id(neighbor);
116797
+ if (cost_so_far < g_score[neighbor]) {
116787
116798
 
116788
- const not_in_open_set = index_in_open_set === -1;
116789
-
116790
- if (not_in_open_set || cost_so_far < g_score[neighbor]) {
116791
-
116792
- // update refined score
116799
+ // update actual cost
116793
116800
  g_score[neighbor] = cost_so_far;
116794
116801
 
116795
116802
  const remaining_heuristic = heuristic(neighbor, goal, width);
116796
116803
 
116797
116804
  const refined_heuristic = cost_so_far + remaining_heuristic;
116798
116805
 
116799
- if (not_in_open_set) {
116800
- // Pushing to heap will put it in proper place based on the 'f' value.
116801
- open.insert(neighbor, refined_heuristic);
116802
- } else {
116803
- // Already seen the node, but since it has been re-scored we need to reorder it in the heap
116804
- open.__update_score_by_index(index_in_open_set, refined_heuristic);
116805
- }
116806
+ // Pushing to heap will put it in proper place based on the 'f' value.
116807
+ open.insert_or_update(neighbor, refined_heuristic);
116806
116808
  }
116809
+
116807
116810
  }
116808
116811
  }
116809
116812