@woosh/meep-engine 2.105.0 → 2.106.1

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 (79) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/build/meep.cjs +358 -188
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +358 -188
  6. package/package.json +1 -1
  7. package/src/core/assert.d.ts.map +1 -1
  8. package/src/core/assert.js +3 -1
  9. package/src/core/cache/Cache.d.ts.map +1 -1
  10. package/src/core/cache/Cache.js +23 -19
  11. package/src/core/collection/array/array_copy.spec.d.ts +2 -0
  12. package/src/core/collection/array/array_copy.spec.d.ts.map +1 -0
  13. package/src/core/collection/array/array_copy.spec.js +19 -0
  14. package/src/core/collection/list/List.d.ts.map +1 -1
  15. package/src/core/collection/list/List.js +55 -30
  16. package/src/core/collection/list/List.spec.js +101 -0
  17. package/src/core/collection/list/ListForwarder.d.ts.map +1 -1
  18. package/src/core/collection/list/ListForwarder.js +49 -53
  19. package/src/core/collection/list/ListForwarder.spec.js +2 -0
  20. package/src/core/collection/list/SortedListProjection.d.ts +4 -1
  21. package/src/core/collection/list/SortedListProjection.d.ts.map +1 -1
  22. package/src/core/collection/list/SortedListProjection.js +4 -1
  23. package/src/core/collection/map/AbstractAsyncMap.d.ts.map +1 -1
  24. package/src/core/collection/map/AbstractAsyncMap.js +0 -3
  25. package/src/core/collection/map/AsyncMapWrapper.d.ts +6 -10
  26. package/src/core/collection/map/AsyncMapWrapper.d.ts.map +1 -1
  27. package/src/core/collection/map/AsyncMapWrapper.js +14 -9
  28. package/src/core/collection/map/HashMap.d.ts.map +1 -1
  29. package/src/core/collection/map/HashMap.js +30 -3
  30. package/src/core/collection/map/ObservedMap.d.ts +12 -3
  31. package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
  32. package/src/core/collection/map/ObservedMap.js +14 -4
  33. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  34. package/src/core/collection/queue/Deque.js +100 -95
  35. package/src/core/collection/set/ArraySet.d.ts.map +1 -0
  36. package/src/core/collection/set/{Set.js → ArraySet.js} +2 -2
  37. package/src/core/collection/set/set_remove.d.ts +3 -3
  38. package/src/core/collection/set/set_remove.d.ts.map +1 -1
  39. package/src/core/collection/set/set_remove.js +5 -5
  40. package/src/core/color/oklab/find_gamut_intersection.js +1 -1
  41. package/src/core/geom/2d/Rectangle.d.ts +54 -5
  42. package/src/core/geom/2d/Rectangle.d.ts.map +1 -1
  43. package/src/core/geom/2d/Rectangle.js +70 -3
  44. package/src/core/geom/2d/circle/Circle.d.ts +1 -1
  45. package/src/core/geom/2d/circle/Circle.js +1 -1
  46. package/src/core/geom/2d/compute_triangle_area_2d.d.ts.map +1 -1
  47. package/src/core/geom/2d/compute_triangle_area_2d.js +7 -1
  48. package/src/core/geom/2d/shape/AbstractShape.d.ts +2 -0
  49. package/src/core/geom/2d/shape/AbstractShape.d.ts.map +1 -1
  50. package/src/core/geom/2d/shape/AbstractShape.js +8 -2
  51. package/src/core/geom/2d/shape/CircleShape.d.ts +14 -0
  52. package/src/core/geom/2d/shape/CircleShape.d.ts.map +1 -1
  53. package/src/core/geom/2d/shape/CircleShape.js +64 -22
  54. package/src/core/geom/2d/uv_map_circle_to_square.d.ts +8 -0
  55. package/src/core/geom/2d/uv_map_circle_to_square.d.ts.map +1 -0
  56. package/src/core/geom/2d/{UvUtils.js → uv_map_circle_to_square.js} +2 -17
  57. package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts +2 -0
  58. package/src/core/geom/2d/uv_map_circle_to_square.spec.d.ts.map +1 -0
  59. package/src/core/geom/2d/uv_map_circle_to_square.spec.js +28 -0
  60. package/src/core/geom/2d/uv_map_square_to_circle.d.ts +8 -0
  61. package/src/core/geom/2d/uv_map_square_to_circle.d.ts.map +1 -0
  62. package/src/core/geom/2d/uv_map_square_to_circle.js +14 -0
  63. package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts +2 -0
  64. package/src/core/geom/2d/uv_map_square_to_circle.spec.d.ts.map +1 -0
  65. package/src/core/geom/2d/uv_map_square_to_circle.spec.js +30 -0
  66. package/src/core/geom/Vector3.d.ts +13 -4
  67. package/src/core/geom/Vector3.d.ts.map +1 -1
  68. package/src/core/geom/Vector3.js +83 -36
  69. package/src/core/geom/Vector3.spec.js +113 -12
  70. package/src/core/collection/set/Set.d.ts.map +0 -1
  71. package/src/core/geom/2d/Geometry2D.d.ts +0 -31
  72. package/src/core/geom/2d/Geometry2D.d.ts.map +0 -1
  73. package/src/core/geom/2d/Geometry2D.js +0 -59
  74. package/src/core/geom/2d/UvUtils.d.ts +0 -15
  75. package/src/core/geom/2d/UvUtils.d.ts.map +0 -1
  76. package/src/core/geom/2d/UvUtils.spec.d.ts +0 -2
  77. package/src/core/geom/2d/UvUtils.spec.d.ts.map +0 -1
  78. package/src/core/geom/2d/UvUtils.spec.js +0 -55
  79. /package/src/core/collection/set/{Set.d.ts → ArraySet.d.ts} +0 -0
package/build/meep.cjs CHANGED
@@ -251,7 +251,9 @@ class InMemoryDescriptor extends BaseDescription {
251
251
 
252
252
  function equal(a, b, m) {
253
253
  if (a !== b) {
254
- const message = m !== undefined ? m : `${a} !== ${b}`;
254
+ const details = `${a} !== ${b}`;
255
+
256
+ const message = (m !== undefined && m !== "") ? `${m}. ${details}` : details;
255
257
  throw new Error(message);
256
258
  }
257
259
  }
@@ -2106,10 +2108,23 @@ let Vector3$1 = class Vector3 {
2106
2108
  * @constructor
2107
2109
  */
2108
2110
  constructor(x = 0, y = 0, z = 0) {
2111
+ /**
2112
+ * @type {number}
2113
+ */
2109
2114
  this.x = x;
2115
+ /**
2116
+ * @type {number}
2117
+ */
2110
2118
  this.y = y;
2119
+ /**
2120
+ * @type {number}
2121
+ */
2111
2122
  this.z = z;
2112
2123
 
2124
+ /**
2125
+ * @readonly
2126
+ * @type {Signal<number,number,number,number,number,number>}
2127
+ */
2113
2128
  this.onChanged = new Signal();
2114
2129
  }
2115
2130
 
@@ -2407,7 +2422,11 @@ let Vector3$1 = class Vector3 {
2407
2422
  const ax = first.x, ay = first.y, az = first.z;
2408
2423
  const bx = second.x, by = second.y, bz = second.z;
2409
2424
 
2410
- this._crossVectors(ax, ay, az, bx, by, bz);
2425
+ this._crossVectors(
2426
+ ax, ay, az,
2427
+ bx, by, bz
2428
+ );
2429
+
2411
2430
  }
2412
2431
 
2413
2432
  /**
@@ -2619,6 +2638,7 @@ let Vector3$1 = class Vector3 {
2619
2638
  /**
2620
2639
  *
2621
2640
  * @param {THREE.Matrix4} matrix4
2641
+ * @deprecated use {@link @applyMatrix4} directly instead, pass `mat.elements`
2622
2642
  */
2623
2643
  applyMatrix4_three(matrix4) {
2624
2644
  this.applyMatrix4(matrix4.elements);
@@ -2647,7 +2667,9 @@ let Vector3$1 = class Vector3 {
2647
2667
  * @param {ArrayLike<number>|number[]|Float32Array} m4
2648
2668
  */
2649
2669
  applyDirectionMatrix4(m4) {
2650
- const x = this.x, y = this.y, z = this.z;
2670
+ const x = this.x;
2671
+ const y = this.y;
2672
+ const z = this.z;
2651
2673
 
2652
2674
  const _x = m4[0] * x + m4[4] * y + m4[8] * z;
2653
2675
  const _y = m4[1] * x + m4[5] * y + m4[9] * z;
@@ -2678,25 +2700,34 @@ let Vector3$1 = class Vector3 {
2678
2700
  }
2679
2701
 
2680
2702
  /**
2681
- *
2703
+ * @deprecated use non-three.js version instead
2682
2704
  * @param {THREE.Matrix3} m
2683
2705
  * @returns {Vector3}
2684
2706
  */
2685
2707
  applyMatrix3_three(m) {
2708
+ this.applyMatrix3(m.elements);
2686
2709
 
2687
- const x = this.x, y = this.y, z = this.z;
2688
- const e = m.elements;
2710
+ return this;
2711
+ }
2689
2712
 
2690
- const _x = e[0] * x + e[3] * y + e[6] * z;
2691
- const _y = e[1] * x + e[4] * y + e[7] * z;
2692
- const _z = e[2] * x + e[5] * y + e[8] * z;
2713
+ /**
2714
+ *
2715
+ * @param {number[]|Float32Array} mat
2716
+ */
2717
+ applyMatrix3(mat) {
2718
+ const x = this.x;
2719
+ const y = this.y;
2720
+ const z = this.z;
2693
2721
 
2694
- return this.set(_x, _y, _z);
2722
+ const _x = mat[0] * x + mat[3] * y + mat[6] * z;
2723
+ const _y = mat[1] * x + mat[4] * y + mat[7] * z;
2724
+ const _z = mat[2] * x + mat[5] * y + mat[8] * z;
2695
2725
 
2726
+ this.set(_x, _y, _z);
2696
2727
  }
2697
2728
 
2698
2729
  /**
2699
- *
2730
+ * @deprecated use non-three.js version instead
2700
2731
  * @param {THREE.Matrix4} matrix4
2701
2732
  */
2702
2733
  threejs_setFromMatrixPosition(matrix4) {
@@ -2781,17 +2812,7 @@ let Vector3$1 = class Vector3 {
2781
2812
  const y1 = other.y;
2782
2813
  const z1 = other.z;
2783
2814
 
2784
- const d = v3_dot(x0, y0, z0, x1, y1, z1);
2785
-
2786
- const mag2 = (x1 * x1 + y1 * y1 + z1 * z1);
2787
-
2788
- const m = d / mag2;
2789
-
2790
- const x = x1 * m;
2791
- const y = y1 * m;
2792
- const z = z1 * m;
2793
-
2794
- this.set(x, y, z);
2815
+ this._projectVectors(x0, y0, z0, x1, y1, z1);
2795
2816
  }
2796
2817
 
2797
2818
  /**
@@ -2828,7 +2849,10 @@ let Vector3$1 = class Vector3 {
2828
2849
  * @param {number} y1
2829
2850
  * @param {number} z1
2830
2851
  */
2831
- _projectVectors(x0, y0, z0, x1, y1, z1) {
2852
+ _projectVectors(
2853
+ x0, y0, z0,
2854
+ x1, y1, z1
2855
+ ) {
2832
2856
 
2833
2857
  const d = v3_dot(x0, y0, z0, x1, y1, z1);
2834
2858
 
@@ -2851,11 +2875,15 @@ let Vector3$1 = class Vector3 {
2851
2875
  */
2852
2876
  setFromSphericalCoords(radius, phi, theta) {
2853
2877
 
2854
- const sinPhiRadius = Math.sin(phi) * radius;
2878
+ const sin_phi = Math.sin(phi);
2879
+ const cos_phi = Math.cos(phi);
2880
+
2881
+ const sin_theta = Math.sin(theta);
2882
+ const cos_theta = Math.cos(theta);
2855
2883
 
2856
- const _x = sinPhiRadius * Math.sin(theta);
2857
- const _y = Math.cos(phi) * radius;
2858
- const _z = sinPhiRadius * Math.cos(theta);
2884
+ const _x = radius * sin_phi * sin_theta;
2885
+ const _y = radius * cos_phi;
2886
+ const _z = radius * sin_phi * cos_theta;
2859
2887
 
2860
2888
  this.set(_x, _y, _z);
2861
2889
  }
@@ -2863,11 +2891,15 @@ let Vector3$1 = class Vector3 {
2863
2891
  /**
2864
2892
  *
2865
2893
  * @param {function} processor
2894
+ * @param {*} [thisArg]
2866
2895
  * @returns {Vector3}
2867
2896
  */
2868
- process(processor) {
2869
- processor(this.x, this.y, this.z);
2870
- this.onChanged.add(processor);
2897
+ process(processor, thisArg) {
2898
+
2899
+ processor.call(thisArg, this.x, this.y, this.z);
2900
+
2901
+ this.onChanged.add(processor, thisArg);
2902
+
2871
2903
  return this;
2872
2904
  }
2873
2905
 
@@ -2881,6 +2913,7 @@ let Vector3$1 = class Vector3 {
2881
2913
  */
2882
2914
  fromJSON(json) {
2883
2915
  if (typeof json === 'number') {
2916
+ // special case where input is a number
2884
2917
  this.setScalar(json);
2885
2918
  } else {
2886
2919
  this.copy(json);
@@ -2894,6 +2927,7 @@ let Vector3$1 = class Vector3 {
2894
2927
  /**
2895
2928
  *
2896
2929
  * @param {BinaryBuffer} buffer
2930
+ * @deprecated
2897
2931
  */
2898
2932
  toBinaryBuffer(buffer) {
2899
2933
  buffer.writeFloat64(this.x);
@@ -2904,6 +2938,7 @@ let Vector3$1 = class Vector3 {
2904
2938
  /**
2905
2939
  *
2906
2940
  * @param {BinaryBuffer} buffer
2941
+ * @deprecated
2907
2942
  */
2908
2943
  fromBinaryBuffer(buffer) {
2909
2944
  const x = buffer.readFloat64();
@@ -2916,6 +2951,7 @@ let Vector3$1 = class Vector3 {
2916
2951
  /**
2917
2952
  *
2918
2953
  * @param {BinaryBuffer} buffer
2954
+ * @deprecated
2919
2955
  */
2920
2956
  toBinaryBufferFloat32(buffer) {
2921
2957
  buffer.writeFloat32(this.x);
@@ -2926,6 +2962,7 @@ let Vector3$1 = class Vector3 {
2926
2962
  /**
2927
2963
  *
2928
2964
  * @param {BinaryBuffer} buffer
2965
+ * @deprecated
2929
2966
  */
2930
2967
  fromBinaryBufferFloat32(buffer) {
2931
2968
  const x = buffer.readFloat32();
@@ -3045,12 +3082,6 @@ Vector3$1.prototype.fromArray = Vector3$1.prototype.readFromArray;
3045
3082
  Vector3$1.prototype.toArray = Vector3$1.prototype.writeToArray;
3046
3083
 
3047
3084
 
3048
- /**
3049
- * @readonly
3050
- * @type {boolean}
3051
- */
3052
- Vector3$1.prototype.isVector3 = true;
3053
-
3054
3085
  /**
3055
3086
  * @readonly
3056
3087
  * @type {Vector3}
@@ -3107,10 +3138,20 @@ Vector3$1.forward = Object.freeze(new Vector3$1(0, 0, 1));
3107
3138
  */
3108
3139
  Vector3$1.back = Object.freeze(new Vector3$1(0, 0, -1));
3109
3140
 
3141
+ /**
3142
+ * @readonly
3143
+ * @type {boolean}
3144
+ */
3145
+ Vector3$1.prototype.isVector3 = true;
3146
+
3147
+ /**
3148
+ * @readonly
3149
+ * @type {string}
3150
+ */
3110
3151
  Vector3$1.typeName = "Vector3";
3111
3152
 
3112
3153
  /**
3113
- *
3154
+ * @deprecated use {@link v3_dot} directly instead
3114
3155
  * @param {number} x0
3115
3156
  * @param {number} y0
3116
3157
  * @param {number} z0
@@ -60141,6 +60182,8 @@ class HashMap {
60141
60182
  this.#bin_count = 2 ** this.#bin_count_power_of_two;
60142
60183
  this.#bin_count_mask = this.#bin_count - 1;
60143
60184
 
60185
+ const old_entry_allocation_count = this.#entries_allocated_count;
60186
+
60144
60187
  this.#entries_allocated_count = 2 ** this.#entries_count_power_of_two;
60145
60188
 
60146
60189
  const BinsArray = UintArrayForCount(this.#entries_allocated_count + ENTRY_BASE);
@@ -60152,7 +60195,7 @@ class HashMap {
60152
60195
 
60153
60196
  this.#entries = new_entries;
60154
60197
 
60155
- array_copy(old_entries, 0, new_entries, 0, min2(old_entries.length, this.#entries_allocated_count));
60198
+ array_copy(old_entries, 0, new_entries, 0, min2(old_entry_allocation_count, this.#entries_allocated_count));
60156
60199
 
60157
60200
  if (this.#size > 0) {
60158
60201
  // re-hash
@@ -60221,12 +60264,21 @@ class HashMap {
60221
60264
  this.#entries_bound++;
60222
60265
 
60223
60266
  if (this.#entries[i] !== undefined) {
60267
+
60268
+ // entry exists, let's reuse it
60269
+
60224
60270
  const entry = this.#entries[i];
60271
+
60225
60272
  entry.hash = hash;
60226
60273
  entry.key = k;
60227
60274
  entry.value = v;
60275
+
60228
60276
  } else {
60277
+
60278
+ // entry slot is empty
60279
+
60229
60280
  this.#entries[i] = new HashMapEntry(k, v, hash);
60281
+
60230
60282
  }
60231
60283
 
60232
60284
  return i;
@@ -60298,7 +60350,9 @@ class HashMap {
60298
60350
 
60299
60351
  const entry_index = this.#allocate_entry(key, value, raw_hash);
60300
60352
 
60301
- this.#bins[bin_index] = entry_index + ENTRY_BASE;
60353
+ const bin_value = entry_index + ENTRY_BASE;
60354
+
60355
+ this.#bins[bin_index] = bin_value;
60302
60356
 
60303
60357
  break;
60304
60358
 
@@ -60373,6 +60427,7 @@ class HashMap {
60373
60427
  * @return {V}
60374
60428
  */
60375
60429
  getOrCompute(key, compute, compute_context) {
60430
+
60376
60431
  const existing = this.get(key);
60377
60432
 
60378
60433
  if (existing !== undefined) {
@@ -60528,7 +60583,11 @@ class HashMap {
60528
60583
 
60529
60584
  let written_entries = 0;
60530
60585
 
60531
- for (let existing_entry_index = this.#entries_start; existing_entry_index < entries_bound; existing_entry_index++) {
60586
+ for (
60587
+ let existing_entry_index = this.#entries_start;
60588
+ existing_entry_index < entries_bound;
60589
+ existing_entry_index++
60590
+ ) {
60532
60591
  const entry = entries[existing_entry_index];
60533
60592
 
60534
60593
  const hash = entry.hash;
@@ -60582,6 +60641,7 @@ class HashMap {
60582
60641
  }
60583
60642
 
60584
60643
  forEach(callback, thisArg) {
60644
+
60585
60645
  const count = this.#bin_count;
60586
60646
  const entries = this.#entries;
60587
60647
  const bins = this.#bins;
@@ -61082,6 +61142,22 @@ class Cache {
61082
61142
  let element = this.data.get(key);
61083
61143
 
61084
61144
  if (element === undefined) {
61145
+ //compute weight
61146
+ const elementWeight = this.computeElementWeight(key, value);
61147
+
61148
+ /**
61149
+ * It's possible that element being added is larger than cache's capacity,
61150
+ * in which case entire cache will be evicted, but there still won't be enough space
61151
+ * @type {number}
61152
+ */
61153
+ const weightTarget = this.#maxWeight - elementWeight;
61154
+
61155
+ if (weightTarget < 0) {
61156
+ // Special case
61157
+ // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61158
+ return;
61159
+ }
61160
+
61085
61161
  element = new CacheElement();
61086
61162
 
61087
61163
  element.key = key;
@@ -61099,25 +61175,8 @@ class Cache {
61099
61175
  this.__last = element;
61100
61176
  }
61101
61177
 
61102
- //compute weight
61103
- const elementWeight = this.computeElementWeight(key, value);
61104
-
61105
61178
  element.weight = elementWeight;
61106
61179
 
61107
-
61108
- /**
61109
- * It's possible that element being added is larger than cache's capacity,
61110
- * in which case entire cache will be evicted, but there still won't be enough space
61111
- * @type {number}
61112
- */
61113
- const weightTarget = this.#maxWeight - elementWeight;
61114
-
61115
- if (weightTarget < 0) {
61116
- // Special case
61117
- // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61118
- return;
61119
- }
61120
-
61121
61180
  //evict elements until there is enough space for the element
61122
61181
  this.evictUntilWeight(weightTarget);
61123
61182
 
@@ -61130,9 +61189,14 @@ class Cache {
61130
61189
  // check if value is the same
61131
61190
  if (value === element.value) ; else {
61132
61191
  // replace value, adjust weight
61133
- this.#weight -= this.valueWeigher(element.value);
61134
- this.#weight += this.valueWeigher(value);
61192
+ this.#weight -= element.weight;
61135
61193
 
61194
+ const elementWeight = this.computeElementWeight(key, value);
61195
+
61196
+ this.#weight += elementWeight;
61197
+
61198
+ // assign new values
61199
+ element.weight = elementWeight;
61136
61200
  element.value = value;
61137
61201
  }
61138
61202
 
@@ -61432,18 +61496,27 @@ class List {
61432
61496
  removed: new Signal()
61433
61497
  };
61434
61498
 
61499
+ /**
61500
+ *
61501
+ * @type {T[]}
61502
+ */
61503
+ data = []
61504
+
61435
61505
  /**
61436
61506
  * @param {[]} [array]
61437
61507
  * @constructor
61438
61508
  */
61439
61509
  constructor(array) {
61440
61510
 
61441
- /**
61442
- * @private
61443
- * @readonly
61444
- * @type {T[]}
61445
- */
61446
- this.data = array !== undefined ? array.slice() : [];
61511
+ if (array !== undefined) {
61512
+
61513
+ /**
61514
+ * @private
61515
+ * @readonly
61516
+ * @type {T[]}
61517
+ */
61518
+ this.data = array.slice();
61519
+ }
61447
61520
 
61448
61521
  /**
61449
61522
  * Number of elements in the list
@@ -61532,9 +61605,11 @@ class List {
61532
61605
 
61533
61606
  if (index > this.length) {
61534
61607
  this.length = index;
61535
- }
61536
61608
 
61537
- this.data.splice(index, 0, el);
61609
+ this.data[index] = el;
61610
+ } else {
61611
+ this.data.splice(index, 0, el);
61612
+ }
61538
61613
 
61539
61614
  this.length++;
61540
61615
 
@@ -61672,11 +61747,11 @@ class List {
61672
61747
  addAllUnique(elements) {
61673
61748
  const data = this.data;
61674
61749
 
61675
- const unique = elements.filter(function (e, i) {
61676
- return data.indexOf(e) === -1 && elements.indexOf(e, i + 1) === -1;
61677
- });
61750
+ const length = data.length;
61678
61751
 
61679
- this.addAll(unique);
61752
+ for (let i = 0; i < length; i++) {
61753
+ this.addUnique(data[i]);
61754
+ }
61680
61755
  }
61681
61756
 
61682
61757
  /**
@@ -61687,21 +61762,23 @@ class List {
61687
61762
  */
61688
61763
  removeMany(index, removeCount) {
61689
61764
 
61690
- const els = this.data.splice(index, removeCount);
61765
+ const removed_elements = this.data.splice(index, removeCount);
61691
61766
 
61692
- const removedCount = els.length;
61767
+ const removedCount = removed_elements.length;
61693
61768
 
61694
61769
  this.length -= removedCount;
61695
61770
 
61696
- if (this.on.removed.hasHandlers()) {
61771
+ const onRemoved = this.on.removed;
61772
+
61773
+ if (onRemoved.hasHandlers()) {
61697
61774
  for (let i = 0; i < removedCount; i++) {
61698
- const element = els[i];
61775
+ const element = removed_elements[i];
61699
61776
 
61700
- this.on.removed.send2(element, index + i);
61777
+ onRemoved.send2(element, index + i);
61701
61778
  }
61702
61779
  }
61703
61780
 
61704
- return els;
61781
+ return removed_elements;
61705
61782
  }
61706
61783
 
61707
61784
  /**
@@ -61780,8 +61857,13 @@ class List {
61780
61857
  }
61781
61858
  }
61782
61859
 
61783
- sort() {
61784
- Array.prototype.sort.apply(this.data, arguments);
61860
+ /**
61861
+ *
61862
+ * @param {function(a:T, b:T):number} [compare_function]
61863
+ * @returns {List}
61864
+ */
61865
+ sort(compare_function) {
61866
+ Array.prototype.sort.call(this.data, compare_function);
61785
61867
  return this;
61786
61868
  }
61787
61869
 
@@ -61945,18 +62027,24 @@ class List {
61945
62027
  *
61946
62028
  * @param {function(el:T):boolean} matcher
61947
62029
  * @param {function(el:T, index:number):*} callback
62030
+ * @returns {boolean}
61948
62031
  */
61949
62032
  visitFirstMatch(matcher, callback) {
61950
- const data = this.data;
61951
- let i = 0;
61952
- const l = this.length;
61953
- for (; i < l; i++) {
61954
- const el = data[i];
61955
- if (matcher(el)) {
61956
- callback(el, i);
61957
- return;
61958
- }
62033
+ const index = this.findIndex(matcher);
62034
+
62035
+ if (index === -1) {
62036
+ return false;
61959
62037
  }
62038
+
62039
+ const el = this.data[index];
62040
+
62041
+ if (matcher(el)) {
62042
+ callback(el, index);
62043
+ return true;
62044
+ } else {
62045
+ return false;
62046
+ }
62047
+
61960
62048
  }
61961
62049
 
61962
62050
  /**
@@ -84558,15 +84646,25 @@ class BinaryHeap {
84558
84646
  * @template K,V
84559
84647
  */
84560
84648
  class ObservedMap {
84649
+ /**
84650
+ * @readonly
84651
+ */
84652
+ on = {
84653
+ /**
84654
+ * @type {Signal}
84655
+ */
84656
+ set: new Signal(),
84657
+ /**
84658
+ * @type {Signal}
84659
+ */
84660
+ deleted: new Signal()
84661
+ };
84662
+
84561
84663
  /**
84562
84664
  * @template K,V
84563
84665
  * @constructor
84564
84666
  */
84565
84667
  constructor(source = new Map()) {
84566
- this.on = {
84567
- set: new Signal(),
84568
- deleted: new Signal()
84569
- };
84570
84668
 
84571
84669
  /**
84572
84670
  *
@@ -84636,11 +84734,42 @@ const STATUS_FULL = 0;
84636
84734
  const STATUS_EMPTY = 1;
84637
84735
  const STATUS_NORMAL = 2;
84638
84736
 
84737
+ const EMPTY_ARRAY = new Array(0);
84738
+
84639
84739
  /**
84640
84740
  * Double-ended queue backed by an array
84641
84741
  * @template T
84642
84742
  */
84643
84743
  class Deque {
84744
+
84745
+ /**
84746
+ * Using static array allocator to preserve data locality.
84747
+ * Initialization via "[]" would give us a dynamically sized array,
84748
+ * but it would have unpredictable locality as array may or may not have it's elements stored next to each other in memory
84749
+ * @type {T[]}
84750
+ * @private
84751
+ */
84752
+ #data=EMPTY_ARRAY;
84753
+ /**
84754
+ *
84755
+ * @type {number}
84756
+ * @private
84757
+ */
84758
+ #head = 0;
84759
+ /**
84760
+ *
84761
+ * @type {number}
84762
+ * @private
84763
+ */
84764
+ #tail = 0;
84765
+
84766
+ /**
84767
+ *
84768
+ * @type {number}
84769
+ * @private
84770
+ */
84771
+ #status = STATUS_EMPTY;
84772
+
84644
84773
  /**
84645
84774
  * @template T
84646
84775
  * @param {number} [min_size]
@@ -84649,34 +84778,8 @@ class Deque {
84649
84778
 
84650
84779
  const size = ceilPowerOfTwo(max2(1, min_size));
84651
84780
 
84652
- /**
84653
- * Using static array allocator to preserve data locality.
84654
- * Initialization via "[]" would give us a dynamically sized array,
84655
- * but it would have unpredictable locality as array may or may not have it's elements stored next to each other in memory
84656
- * @type {T[]}
84657
- * @private
84658
- */
84659
- this.__data = new Array(size);
84660
-
84661
- /**
84662
- *
84663
- * @type {number}
84664
- * @private
84665
- */
84666
- this.__head = 0;
84667
- /**
84668
- *
84669
- * @type {number}
84670
- * @private
84671
- */
84672
- this.__tail = 0;
84781
+ this.#data = new Array(size);
84673
84782
 
84674
- /**
84675
- *
84676
- * @type {number}
84677
- * @private
84678
- */
84679
- this.__status = STATUS_EMPTY;
84680
84783
  }
84681
84784
 
84682
84785
  /**
@@ -84684,14 +84787,14 @@ class Deque {
84684
84787
  * @param {boolean} adding
84685
84788
  * @private
84686
84789
  */
84687
- resetStatus(adding) {
84688
- const head = this.__head;
84689
- const tail = this.__tail;
84790
+ #reset_status(adding) {
84791
+ const head = this.#head;
84792
+ const tail = this.#tail;
84690
84793
 
84691
84794
  if (head === tail) {
84692
- this.__status = adding ? STATUS_FULL : STATUS_EMPTY;
84795
+ this.#status = adding ? STATUS_FULL : STATUS_EMPTY;
84693
84796
  } else {
84694
- this.__status = STATUS_NORMAL;
84797
+ this.#status = STATUS_NORMAL;
84695
84798
  }
84696
84799
  }
84697
84800
 
@@ -84701,10 +84804,10 @@ class Deque {
84701
84804
  * @returns {number}
84702
84805
  * @private
84703
84806
  */
84704
- __circular_next_position(current) {
84807
+ #circular_next_position(current) {
84705
84808
  const next = current + 1;
84706
84809
 
84707
- const length = this.__data.length;
84810
+ const length = this.#data.length;
84708
84811
 
84709
84812
  return (next >= length) ? 0 : next;
84710
84813
  }
@@ -84715,20 +84818,20 @@ class Deque {
84715
84818
  * @returns {number}
84716
84819
  * @private
84717
84820
  */
84718
- __circular_previous_position(current) {
84821
+ #circular_previous_position(current) {
84719
84822
  const prev = current - 1;
84720
- return (prev < 0) ? (this.__data.length - 1) : prev;
84823
+ return (prev < 0) ? (this.#data.length - 1) : prev;
84721
84824
  }
84722
84825
 
84723
- __check_and_expand() {
84724
- const status = this.__status;
84826
+ #check_and_expand() {
84827
+ const status = this.#status;
84725
84828
 
84726
84829
  if (status !== STATUS_FULL) {
84727
84830
  // queue still has space, we're done
84728
84831
  return;
84729
84832
  }
84730
84833
 
84731
- const length = this.__data.length;
84834
+ const length = this.#data.length;
84732
84835
 
84733
84836
  if (UINT32_MAX === length) {
84734
84837
  throw new Error('Maximum array size exceeded');
@@ -84747,19 +84850,19 @@ class Deque {
84747
84850
  */
84748
84851
  const new_data = new Array(new_length);
84749
84852
 
84750
- const head = this.__head;
84853
+ const head = this.#head;
84751
84854
 
84752
84855
  // copy the front portion
84753
- array_copy(this.__data, head, new_data, 0, length - head);
84856
+ array_copy(this.#data, head, new_data, 0, length - head);
84754
84857
  // copy the remainder
84755
- array_copy(this.__data, 0, new_data, length - head, head);
84858
+ array_copy(this.#data, 0, new_data, length - head, head);
84756
84859
 
84757
- this.__head = 0;
84758
- this.__tail = length;
84860
+ this.#head = 0;
84861
+ this.#tail = length;
84759
84862
 
84760
- this.__status = STATUS_NORMAL;
84863
+ this.#status = STATUS_NORMAL;
84761
84864
 
84762
- this.__data = new_data;
84865
+ this.#data = new_data;
84763
84866
  }
84764
84867
 
84765
84868
  /**
@@ -84771,34 +84874,34 @@ class Deque {
84771
84874
  }
84772
84875
 
84773
84876
  clear() {
84774
- if (this.__status !== STATUS_EMPTY) {
84775
- let cursor = this.__head;
84776
- const tail = this.__tail;
84877
+ if (this.#status !== STATUS_EMPTY) {
84878
+ let cursor = this.#head;
84879
+ const tail = this.#tail;
84777
84880
 
84778
84881
  do {
84779
- this.__data[cursor] = undefined;
84780
- cursor = this.__circular_next_position(cursor);
84882
+ this.#data[cursor] = undefined;
84883
+ cursor = this.#circular_next_position(cursor);
84781
84884
  } while (cursor !== tail);
84782
84885
 
84783
- this.__status = STATUS_EMPTY;
84886
+ this.#status = STATUS_EMPTY;
84784
84887
  }
84785
84888
 
84786
- this.__head = 0;
84787
- this.__tail = 0;
84889
+ this.#head = 0;
84890
+ this.#tail = 0;
84788
84891
  }
84789
84892
 
84790
84893
  /**
84791
84894
  * @returns {number}
84792
84895
  */
84793
84896
  size() {
84794
- const data = this.__data;
84897
+ const data = this.#data;
84795
84898
 
84796
- if (this.__status === STATUS_FULL) {
84899
+ if (this.#status === STATUS_FULL) {
84797
84900
  return data.length;
84798
84901
  }
84799
84902
 
84800
- const head = this.__head;
84801
- const tail = this.__tail;
84903
+ const head = this.#head;
84904
+ const tail = this.#tail;
84802
84905
 
84803
84906
  return (head <= tail) ? (tail - head) : (tail + data.length - head);
84804
84907
  }
@@ -84809,43 +84912,43 @@ class Deque {
84809
84912
  * @param {boolean} shift_front should we shift elements before the removed element or after?
84810
84913
  * @private
84811
84914
  */
84812
- __remove_internal(current, shift_front) {
84915
+ #remove_internal(current, shift_front) {
84813
84916
  let cursor = current;
84814
84917
 
84815
84918
  if (shift_front) {
84816
84919
 
84817
84920
  // shift towards tail
84818
84921
 
84819
- const head = this.__head;
84922
+ const head = this.#head;
84820
84923
 
84821
84924
  while (cursor !== head) {
84822
- const next = this.__circular_previous_position(cursor);
84823
- this.__data[cursor] = this.__data[next];
84925
+ const next = this.#circular_previous_position(cursor);
84926
+ this.#data[cursor] = this.#data[next];
84824
84927
  cursor = next;
84825
84928
  }
84826
84929
 
84827
- this.__head = this.__circular_next_position(head);
84930
+ this.#head = this.#circular_next_position(head);
84828
84931
 
84829
84932
  } else {
84830
84933
 
84831
84934
  // shift towards head
84832
84935
 
84833
- const tail = this.__tail;
84936
+ const tail = this.#tail;
84834
84937
 
84835
84938
  while (cursor !== tail) {
84836
- const next = this.__circular_next_position(cursor);
84837
- this.__data[cursor] = this.__data[next];
84939
+ const next = this.#circular_next_position(cursor);
84940
+ this.#data[cursor] = this.#data[next];
84838
84941
  cursor = next;
84839
84942
  }
84840
84943
 
84841
- this.__tail = this.__circular_previous_position(tail);
84944
+ this.#tail = this.#circular_previous_position(tail);
84842
84945
 
84843
84946
  }
84844
84947
 
84845
84948
  // fill in slot of last moved element
84846
- this.__data[cursor] = undefined;
84949
+ this.#data[cursor] = undefined;
84847
84950
 
84848
- this.resetStatus(false);
84951
+ this.#reset_status(false);
84849
84952
  }
84850
84953
 
84851
84954
  /**
@@ -84854,13 +84957,13 @@ class Deque {
84854
84957
  * @returns {boolean}
84855
84958
  */
84856
84959
  remove(e) {
84857
- const i = this.__index_of(e);
84960
+ const i = this.#index_of(e);
84858
84961
 
84859
84962
  if (i === -1) {
84860
84963
  return false;
84861
84964
  }
84862
84965
 
84863
- this.__remove_internal(i, true);
84966
+ this.#remove_internal(i, true);
84864
84967
 
84865
84968
  return true;
84866
84969
  }
@@ -84871,14 +84974,14 @@ class Deque {
84871
84974
  * @returns {number}
84872
84975
  * @private
84873
84976
  */
84874
- __index_of(e) {
84977
+ #index_of(e) {
84875
84978
  const size = this.size();
84876
84979
 
84877
- const data = this.__data;
84980
+ const data = this.#data;
84878
84981
  const capacity = data.length;
84879
84982
 
84880
84983
  for (let i = 0; i < size; i++) {
84881
- const index = (this.__head + i) % capacity;
84984
+ const index = (this.#head + i) % capacity;
84882
84985
 
84883
84986
  const el = data[index];
84884
84987
 
@@ -84896,7 +84999,7 @@ class Deque {
84896
84999
  * @returns {boolean}
84897
85000
  */
84898
85001
  has(e) {
84899
- return this.__index_of(e) !== -1;
85002
+ return this.#index_of(e) !== -1;
84900
85003
  }
84901
85004
 
84902
85005
  /**
@@ -84904,10 +85007,10 @@ class Deque {
84904
85007
  * @param {T} e
84905
85008
  */
84906
85009
  addFirst(e) {
84907
- this.__check_and_expand();
84908
- this.__head = this.__circular_previous_position(this.__head);
84909
- this.__data[this.__head] = e;
84910
- this.resetStatus(true);
85010
+ this.#check_and_expand();
85011
+ this.#head = this.#circular_previous_position(this.#head);
85012
+ this.#data[this.#head] = e;
85013
+ this.#reset_status(true);
84911
85014
  }
84912
85015
 
84913
85016
  /**
@@ -84915,10 +85018,10 @@ class Deque {
84915
85018
  * @returns {T|undefined}
84916
85019
  */
84917
85020
  removeFirst() {
84918
- const element = this.__data[this.__head];
84919
- this.__data[this.__head] = undefined;
84920
- this.__head = this.__circular_next_position(this.__head);
84921
- this.resetStatus(false);
85021
+ const element = this.#data[this.#head];
85022
+ this.#data[this.#head] = undefined;
85023
+ this.#head = this.#circular_next_position(this.#head);
85024
+ this.#reset_status(false);
84922
85025
  return element;
84923
85026
  }
84924
85027
 
@@ -84927,7 +85030,7 @@ class Deque {
84927
85030
  * @returns {T|undefined}
84928
85031
  */
84929
85032
  getFirst() {
84930
- return this.__data[this.__head];
85033
+ return this.#data[this.#head];
84931
85034
  }
84932
85035
 
84933
85036
  /**
@@ -84935,10 +85038,10 @@ class Deque {
84935
85038
  * @param {T} e
84936
85039
  */
84937
85040
  addLast(e) {
84938
- this.__check_and_expand();
84939
- this.__data[this.__tail] = e;
84940
- this.__tail = this.__circular_next_position(this.__tail);
84941
- this.resetStatus(true);
85041
+ this.#check_and_expand();
85042
+ this.#data[this.#tail] = e;
85043
+ this.#tail = this.#circular_next_position(this.#tail);
85044
+ this.#reset_status(true);
84942
85045
  }
84943
85046
 
84944
85047
  /**
@@ -84946,11 +85049,11 @@ class Deque {
84946
85049
  * @returns {T}
84947
85050
  */
84948
85051
  removeLast() {
84949
- const last = this.__circular_previous_position(this.__tail);
84950
- const element = this.__data[last];
84951
- this.__data[last] = undefined;
84952
- this.__tail = last;
84953
- this.resetStatus(false);
85052
+ const last = this.#circular_previous_position(this.#tail);
85053
+ const element = this.#data[last];
85054
+ this.#data[last] = undefined;
85055
+ this.#tail = last;
85056
+ this.#reset_status(false);
84954
85057
  return element;
84955
85058
  }
84956
85059
 
@@ -84960,8 +85063,8 @@ class Deque {
84960
85063
  * @returns {T|undefined}
84961
85064
  */
84962
85065
  getLast() {
84963
- const last = this.__circular_previous_position(this.__tail);
84964
- return this.__data[last];
85066
+ const last = this.#circular_previous_position(this.#tail);
85067
+ return this.#data[last];
84965
85068
  }
84966
85069
  }
84967
85070
 
@@ -98774,6 +98877,38 @@ class Rectangle {
98774
98877
  this.size = new Vector2(width, height);
98775
98878
  }
98776
98879
 
98880
+ /**
98881
+ *
98882
+ * @return {number}
98883
+ */
98884
+ get x0() {
98885
+ return this.position.x;
98886
+ }
98887
+
98888
+ /**
98889
+ *
98890
+ * @return {number}
98891
+ */
98892
+ get x1() {
98893
+ return this.position.x + this.size.x;
98894
+ }
98895
+
98896
+ /**
98897
+ *
98898
+ * @return {number}
98899
+ */
98900
+ get y0() {
98901
+ return this.position.y;
98902
+ }
98903
+
98904
+ /**
98905
+ *
98906
+ * @return {number}
98907
+ */
98908
+ get y1() {
98909
+ return this.position.y + this.size.y;
98910
+ }
98911
+
98777
98912
  /**
98778
98913
  *
98779
98914
  * @param {number} x
@@ -98791,7 +98926,13 @@ class Rectangle {
98791
98926
  * @returns {Rectangle}
98792
98927
  */
98793
98928
  clone() {
98794
- return new Rectangle(this.position.x, this.position.y, this.size.x, this.size.y);
98929
+ const position = this.position;
98930
+ const size = this.size;
98931
+
98932
+ return new Rectangle(
98933
+ position.x, position.y,
98934
+ size.x, size.y
98935
+ );
98795
98936
  }
98796
98937
 
98797
98938
  /**
@@ -98852,6 +98993,11 @@ class Rectangle {
98852
98993
  return overlap1D(x0, x1, _x0, s.x + _x0) && overlap1D(y0, y1, _y0, _y0 + s.y);
98853
98994
  }
98854
98995
 
98996
+ /**
98997
+ *
98998
+ * @param {Rectangle} other
98999
+ * @returns {boolean}
99000
+ */
98855
99001
  overlaps(other) {
98856
99002
  const x0 = other.position.x;
98857
99003
  const y0 = other.position.y;
@@ -98860,6 +99006,13 @@ class Rectangle {
98860
99006
  return this._overlaps(x0, y0, x1, y1);
98861
99007
  }
98862
99008
 
99009
+ /**
99010
+ *
99011
+ * @param {number} x0
99012
+ * @param {number} y0
99013
+ * @param {number} x1
99014
+ * @param {number} y1
99015
+ */
98863
99016
  _resizeToFit(x0, y0, x1, y1) {
98864
99017
  const size = this.size;
98865
99018
 
@@ -98885,6 +99038,10 @@ class Rectangle {
98885
99038
  size.set(nX1 - nX0, nY1 - nY0);
98886
99039
  }
98887
99040
 
99041
+ /**
99042
+ *
99043
+ * @param {Rectangle} other
99044
+ */
98888
99045
  resizeToFit(other) {
98889
99046
  const x0 = other.position.x;
98890
99047
  const y0 = other.position.y;
@@ -98894,6 +99051,14 @@ class Rectangle {
98894
99051
  return this._resizeToFit(x0, y0, x1, y1);
98895
99052
  }
98896
99053
 
99054
+ /**
99055
+ *
99056
+ * @param {number} x0
99057
+ * @param {number} y0
99058
+ * @param {number} x1
99059
+ * @param {number} y1
99060
+ * @returns {boolean}
99061
+ */
98897
99062
  _contains(x0, y0, x1, y1) {
98898
99063
  const size = this.size;
98899
99064
 
@@ -98906,6 +99071,11 @@ class Rectangle {
98906
99071
  return x0 >= _x0 && x1 <= _x1 && y0 >= _y0 && y1 <= _y1;
98907
99072
  }
98908
99073
 
99074
+ /**
99075
+ *
99076
+ * @param {Rectangle} other
99077
+ * @returns {boolean}
99078
+ */
98909
99079
  contains(other) {
98910
99080
  const x0 = other.position.x;
98911
99081
  const y0 = other.position.y;