@woosh/meep-engine 2.104.0 → 2.106.0

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 (30) 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 +131 -85
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +131 -85
  6. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +1 -1
  7. package/package.json +1 -1
  8. package/src/core/assert.d.ts.map +1 -1
  9. package/src/core/assert.js +3 -1
  10. package/src/core/bvh2/bvh3/build_triangle_morton_codes.d.ts +1 -1
  11. package/src/core/bvh2/bvh3/build_triangle_morton_codes.d.ts.map +1 -1
  12. package/src/core/bvh2/bvh3/build_triangle_morton_codes.js +3 -1
  13. package/src/core/bvh2/bvh3/ebvh_build_hierarchy.d.ts +1 -0
  14. package/src/core/bvh2/bvh3/ebvh_build_hierarchy.d.ts.map +1 -1
  15. package/src/core/bvh2/bvh3/ebvh_build_hierarchy.js +3 -2
  16. package/src/core/cache/Cache.d.ts +2 -1
  17. package/src/core/cache/Cache.d.ts.map +1 -1
  18. package/src/core/cache/Cache.js +68 -41
  19. package/src/core/cache/Cache.spec.js +42 -0
  20. package/src/core/cache/CacheElement.d.ts +1 -0
  21. package/src/core/cache/CacheElement.d.ts.map +1 -1
  22. package/src/core/cache/CacheElement.js +4 -0
  23. package/src/core/codegen/LineBuilder.d.ts +1 -24
  24. package/src/core/codegen/LineBuilder.d.ts.map +1 -1
  25. package/src/core/codegen/LineBuilder.js +19 -15
  26. package/src/core/collection/map/HashMap.d.ts.map +1 -1
  27. package/src/core/collection/map/HashMap.js +48 -30
  28. package/src/core/model/node-graph/NodeGraph.js +2 -2
  29. package/src/engine/graphics/ecs/mesh/Mesh.js +1 -1
  30. package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +1 -1
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
  }
@@ -60005,28 +60007,6 @@ const RESERVED_HASH_SUBSTITUTE = 0;
60005
60007
  const UNDEFINED_BIN_INDEX = ~0;
60006
60008
 
60007
60009
 
60008
- /**
60009
- * @template K,V
60010
- * @param {HashMapEntry<K,V>} record
60011
- * @param {number} hash
60012
- * @param {K} key
60013
- * @param {function(a:K,b:K):boolean} equality_op
60014
- */
60015
- function entry_equality_check(record, hash, key, equality_op) {
60016
- if (record.hash !== hash) {
60017
- return false;
60018
- }
60019
-
60020
- if (record.key === key) {
60021
- return true;
60022
- }
60023
-
60024
- const result = equality_op(record.key, key);
60025
-
60026
- return result;
60027
- }
60028
-
60029
-
60030
60010
  const EMPTY_BINS = new Uint32Array(0);
60031
60011
 
60032
60012
  /**
@@ -60094,6 +60074,10 @@ class HashMap {
60094
60074
  */
60095
60075
  #load_factor = DEFAULT_LOAD_FACTOR;
60096
60076
 
60077
+ /**
60078
+ * Used to track modifications to prevent concurrent changes during iteration
60079
+ * @type {number}
60080
+ */
60097
60081
  #version = 0;
60098
60082
 
60099
60083
  /**
@@ -60159,6 +60143,8 @@ class HashMap {
60159
60143
  this.#bin_count = 2 ** this.#bin_count_power_of_two;
60160
60144
  this.#bin_count_mask = this.#bin_count - 1;
60161
60145
 
60146
+ const old_entry_allocation_count = this.#entries_allocated_count;
60147
+
60162
60148
  this.#entries_allocated_count = 2 ** this.#entries_count_power_of_two;
60163
60149
 
60164
60150
  const BinsArray = UintArrayForCount(this.#entries_allocated_count + ENTRY_BASE);
@@ -60170,7 +60156,7 @@ class HashMap {
60170
60156
 
60171
60157
  this.#entries = new_entries;
60172
60158
 
60173
- array_copy(old_entries, 0, new_entries, 0, min2(old_entries.length, this.#entries_allocated_count));
60159
+ array_copy(old_entries, 0, new_entries, 0, min2(old_entry_allocation_count, this.#entries_allocated_count));
60174
60160
 
60175
60161
  if (this.#size > 0) {
60176
60162
  // re-hash
@@ -60206,6 +60192,25 @@ class HashMap {
60206
60192
  return original === RESERVED_HASH ? RESERVED_HASH_SUBSTITUTE : original;
60207
60193
  }
60208
60194
 
60195
+ /**
60196
+ * @param {HashMapEntry<K,V>} record
60197
+ * @param {number} hash
60198
+ * @param {K} key
60199
+ */
60200
+ #entry_equality_check(record, hash, key) {
60201
+ if (record.hash !== hash) {
60202
+ return false;
60203
+ }
60204
+
60205
+ if (record.key === key) {
60206
+ return true;
60207
+ }
60208
+
60209
+ const result = this.keyEqualityFunction(record.key, key);
60210
+
60211
+ return result;
60212
+ }
60213
+
60209
60214
  /**
60210
60215
  *
60211
60216
  * @param {K} k
@@ -60221,6 +60226,7 @@ class HashMap {
60221
60226
 
60222
60227
  if (this.#entries[i] !== undefined) {
60223
60228
  const entry = this.#entries[i];
60229
+
60224
60230
  entry.hash = hash;
60225
60231
  entry.key = k;
60226
60232
  entry.value = v;
@@ -60281,11 +60287,12 @@ class HashMap {
60281
60287
  // check if it's the entry that we're looking for
60282
60288
  const entry = this.#entries[bin - ENTRY_BASE];
60283
60289
 
60284
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
60290
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
60285
60291
  // found the right entry
60286
60292
  entry.value = value;
60287
60293
  return;
60288
60294
  }
60295
+
60289
60296
  } else if (bin === BIN_RESERVED_VALUE_EMPTY) {
60290
60297
  // bin is empty
60291
60298
 
@@ -60296,7 +60303,9 @@ class HashMap {
60296
60303
 
60297
60304
  const entry_index = this.#allocate_entry(key, value, raw_hash);
60298
60305
 
60299
- this.#bins[bin_index] = entry_index + ENTRY_BASE;
60306
+ const bin_value = entry_index + ENTRY_BASE;
60307
+
60308
+ this.#bins[bin_index] = bin_value;
60300
60309
 
60301
60310
  break;
60302
60311
 
@@ -60344,7 +60353,7 @@ class HashMap {
60344
60353
  // check if the entry is what we're looking for
60345
60354
  const entry = this.#entries[bin - ENTRY_BASE];
60346
60355
 
60347
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
60356
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
60348
60357
  // found the right entry
60349
60358
  return entry.value;
60350
60359
  }
@@ -60444,7 +60453,7 @@ class HashMap {
60444
60453
  const entry_index = bin - ENTRY_BASE;
60445
60454
  const entry = entries[entry_index];
60446
60455
 
60447
- if (entry_equality_check(entry, raw_hash, key, this.keyEqualityFunction)) {
60456
+ if (this.#entry_equality_check(entry, raw_hash, key)) {
60448
60457
  // found the right entry
60449
60458
 
60450
60459
  // record entry as dead
@@ -60526,7 +60535,11 @@ class HashMap {
60526
60535
 
60527
60536
  let written_entries = 0;
60528
60537
 
60529
- for (let existing_entry_index = this.#entries_start; existing_entry_index < entries_bound; existing_entry_index++) {
60538
+ for (
60539
+ let existing_entry_index = this.#entries_start;
60540
+ existing_entry_index < entries_bound;
60541
+ existing_entry_index++
60542
+ ) {
60530
60543
  const entry = entries[existing_entry_index];
60531
60544
 
60532
60545
  const hash = entry.hash;
@@ -60778,16 +60791,27 @@ class CacheElement {
60778
60791
  next.previous = previous;
60779
60792
  }
60780
60793
  }
60794
+
60795
+ toString() {
60796
+ return `CacheElement{ hasNext:${this.next !== null}, hasPrevious:${this.previous !== null}, weight:${this.weight}, key:${this.key}, value:${this.value} }`;
60797
+ }
60781
60798
  }
60782
60799
 
60783
- // TODO validate hashes of held elements to keep them up to date. Keys are assumed to be immutable, but this assumption may be broken by users
60784
-
60785
60800
  /**
60786
60801
  * Hash-based cache, uses LRU (least-recently-used) eviction policy
60802
+ * Make sure that keys being used are truly immutable when it comes to hash and equality calculation, otherwise cache corruption is inevitable
60787
60803
  * @template Key, Value
60788
60804
  * @extends Map<Key,Value>
60789
60805
  */
60790
60806
  class Cache {
60807
+ #maxWeight = Number.POSITIVE_INFINITY;
60808
+ /**
60809
+ *
60810
+ * @type {number}
60811
+ * @private
60812
+ */
60813
+ #weight = 0;
60814
+
60791
60815
  /**
60792
60816
  * @param {number} [maxWeight=Number.POSITIVE_INFINITY]
60793
60817
  * @param {function(key:Key):number} [keyWeigher= key=>0]
@@ -60811,14 +60835,8 @@ class Cache {
60811
60835
  * @type {number}
60812
60836
  * @private
60813
60837
  */
60814
- this.maxWeight = maxWeight;
60838
+ this.#maxWeight = maxWeight;
60815
60839
 
60816
- /**
60817
- *
60818
- * @type {number}
60819
- * @private
60820
- */
60821
- this.weight = 0;
60822
60840
 
60823
60841
  /**
60824
60842
  *
@@ -60919,18 +60937,37 @@ class Cache {
60919
60937
  return this.data.size;
60920
60938
  }
60921
60939
 
60940
+ /**
60941
+ * @deprecated use {@link maxWeight} directly instead
60942
+ */
60943
+ setMaxWeight(value) {
60944
+ this.maxWeight = value;
60945
+ }
60946
+
60947
+ /**
60948
+ * Total weight of all elements currently in the cache
60949
+ * @returns {number}
60950
+ */
60951
+ get weight() {
60952
+ return this.#weight;
60953
+ }
60954
+
60922
60955
  /**
60923
60956
  * Will cause evictions if current weight is smaller than what we're setting
60924
60957
  * @param {number} value
60925
60958
  */
60926
- setMaxWeight(value) {
60959
+ set maxWeight(value) {
60927
60960
  if (typeof value !== "number" || value < 0) {
60928
60961
  throw new Error(`Weight must be a non-negative number, instead was '${value}'`);
60929
60962
  }
60930
60963
 
60931
- this.maxWeight = value;
60964
+ this.#maxWeight = value;
60932
60965
 
60933
- this.evictUntilWeight(this.maxWeight);
60966
+ this.evictUntilWeight(this.#maxWeight);
60967
+ }
60968
+
60969
+ get maxWeight() {
60970
+ return this.#maxWeight;
60934
60971
  }
60935
60972
 
60936
60973
  /**
@@ -60949,7 +60986,8 @@ class Cache {
60949
60986
  result += weight;
60950
60987
  }
60951
60988
 
60952
- this.weight = result;
60989
+ this.#weight = result;
60990
+ this.evictUntilWeight(this.#maxWeight);
60953
60991
  }
60954
60992
 
60955
60993
  /**
@@ -60979,13 +61017,13 @@ class Cache {
60979
61017
 
60980
61018
  const delta_weight = new_weight - old_weight;
60981
61019
 
60982
- this.weight += delta_weight;
61020
+ this.#weight += delta_weight;
60983
61021
 
60984
61022
  if (
60985
- this.weight > this.maxWeight
60986
- && new_weight <= this.maxWeight //make it less likely to drop entire cache
61023
+ this.#weight > this.#maxWeight
61024
+ && new_weight <= this.#maxWeight //make it less likely to drop entire cache
60987
61025
  ) {
60988
- this.evictUntilWeight(this.maxWeight);
61026
+ this.evictUntilWeight(this.#maxWeight);
60989
61027
  }
60990
61028
 
60991
61029
  return true;
@@ -61041,7 +61079,7 @@ class Cache {
61041
61079
 
61042
61080
  const target = Math.max(targetWeight, 0);
61043
61081
 
61044
- while (this.weight > target) {
61082
+ while (this.#weight > target) {
61045
61083
  this.evictOne();
61046
61084
  }
61047
61085
  }
@@ -61055,6 +61093,22 @@ class Cache {
61055
61093
  let element = this.data.get(key);
61056
61094
 
61057
61095
  if (element === undefined) {
61096
+ //compute weight
61097
+ const elementWeight = this.computeElementWeight(key, value);
61098
+
61099
+ /**
61100
+ * It's possible that element being added is larger than cache's capacity,
61101
+ * in which case entire cache will be evicted, but there still won't be enough space
61102
+ * @type {number}
61103
+ */
61104
+ const weightTarget = this.#maxWeight - elementWeight;
61105
+
61106
+ if (weightTarget < 0) {
61107
+ // Special case
61108
+ // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61109
+ return;
61110
+ }
61111
+
61058
61112
  element = new CacheElement();
61059
61113
 
61060
61114
  element.key = key;
@@ -61072,25 +61126,8 @@ class Cache {
61072
61126
  this.__last = element;
61073
61127
  }
61074
61128
 
61075
- //compute weight
61076
- const elementWeight = this.computeElementWeight(key, value);
61077
-
61078
61129
  element.weight = elementWeight;
61079
61130
 
61080
-
61081
- /**
61082
- * It's possible that element being added is larger than cache's capacity,
61083
- * in which case entire cache will be evicted, but there still won't be enough space
61084
- * @type {number}
61085
- */
61086
- const weightTarget = this.maxWeight - elementWeight;
61087
-
61088
- if (weightTarget < 0) {
61089
- // Special case
61090
- // element does not fit into cache, attempting to insert it forcibly would result in a full flush and overflow
61091
- return;
61092
- }
61093
-
61094
61131
  //evict elements until there is enough space for the element
61095
61132
  this.evictUntilWeight(weightTarget);
61096
61133
 
@@ -61098,14 +61135,19 @@ class Cache {
61098
61135
  this.data.set(key, element);
61099
61136
 
61100
61137
  //update weight
61101
- this.weight += elementWeight;
61138
+ this.#weight += elementWeight;
61102
61139
  } else {
61103
61140
  // check if value is the same
61104
61141
  if (value === element.value) ; else {
61105
61142
  // replace value, adjust weight
61106
- this.weight -= this.valueWeigher(element.value);
61107
- this.weight += this.valueWeigher(value);
61143
+ this.#weight -= element.weight;
61108
61144
 
61145
+ const elementWeight = this.computeElementWeight(key, value);
61146
+
61147
+ this.#weight += elementWeight;
61148
+
61149
+ // assign new values
61150
+ element.weight = elementWeight;
61109
61151
  element.value = value;
61110
61152
  }
61111
61153
 
@@ -61190,7 +61232,7 @@ class Cache {
61190
61232
  this.data.delete(key);
61191
61233
 
61192
61234
  //update weight
61193
- this.weight -= element.weight;
61235
+ this.#weight -= element.weight;
61194
61236
  }
61195
61237
 
61196
61238
  /**
@@ -61262,7 +61304,7 @@ class Cache {
61262
61304
  this.__first = null;
61263
61305
  this.__last = null;
61264
61306
 
61265
- this.weight = 0;
61307
+ this.#weight = 0;
61266
61308
  }
61267
61309
 
61268
61310
  /**
@@ -63123,12 +63165,14 @@ class LineBuilder {
63123
63165
  *
63124
63166
  * @type {Line[]}
63125
63167
  */
63126
- lines = [];
63168
+ #lines = [];
63169
+
63127
63170
  /**
63128
63171
  *
63129
63172
  * @type {number}
63130
63173
  */
63131
- indentation = 0;
63174
+ #indentation = 0;
63175
+
63132
63176
  /**
63133
63177
  *
63134
63178
  * @type {number}
@@ -63140,7 +63184,7 @@ class LineBuilder {
63140
63184
  * @return {number}
63141
63185
  */
63142
63186
  get count() {
63143
- return this.lines.length;
63187
+ return this.#lines.length;
63144
63188
  }
63145
63189
 
63146
63190
  /**
@@ -63149,7 +63193,7 @@ class LineBuilder {
63149
63193
  * @param {string} term
63150
63194
  */
63151
63195
  containsSubstring(term) {
63152
- const lines = this.lines;
63196
+ const lines = this.#lines;
63153
63197
  const n = lines.length;
63154
63198
  for (let i = 0; i < n; i++) {
63155
63199
  const line = lines[i];
@@ -63169,7 +63213,7 @@ class LineBuilder {
63169
63213
  * @returns {LineBuilder}
63170
63214
  */
63171
63215
  indent() {
63172
- this.indentation++;
63216
+ this.#indentation++;
63173
63217
  return this;
63174
63218
  }
63175
63219
 
@@ -63178,7 +63222,7 @@ class LineBuilder {
63178
63222
  * @returns {LineBuilder}
63179
63223
  */
63180
63224
  dedent() {
63181
- this.indentation--;
63225
+ this.#indentation--;
63182
63226
  return this;
63183
63227
  }
63184
63228
 
@@ -63189,9 +63233,9 @@ class LineBuilder {
63189
63233
  */
63190
63234
  add(line_text) {
63191
63235
 
63192
- const line = new Line(line_text, this.indentation);
63236
+ const line = new Line(line_text, this.#indentation);
63193
63237
 
63194
- this.lines.push(line);
63238
+ this.#lines.push(line);
63195
63239
 
63196
63240
  return this;
63197
63241
  }
@@ -63202,23 +63246,23 @@ class LineBuilder {
63202
63246
  */
63203
63247
  addLines(lines) {
63204
63248
 
63205
- const other_lines = lines.lines;
63249
+ const other_lines = lines.#lines;
63206
63250
 
63207
63251
  const other_line_count = other_lines.length;
63208
63252
 
63209
63253
  for (let i = 0; i < other_line_count; i++) {
63210
63254
  const otherLine = other_lines[i];
63211
63255
 
63212
- const line = new Line(otherLine.text, otherLine.indentation + this.indentation);
63256
+ const line = new Line(otherLine.text, otherLine.indentation + this.#indentation);
63213
63257
 
63214
- this.lines.push(line);
63258
+ this.#lines.push(line);
63215
63259
  }
63216
63260
 
63217
63261
  }
63218
63262
 
63219
63263
  clear() {
63220
- this.lines = [];
63221
- this.indentation = 0;
63264
+ this.#lines = [];
63265
+ this.#indentation = 0;
63222
63266
  }
63223
63267
 
63224
63268
  /**
@@ -63230,7 +63274,7 @@ class LineBuilder {
63230
63274
 
63231
63275
  let i, j, l;
63232
63276
 
63233
- const lines = this.lines;
63277
+ const lines = this.#lines;
63234
63278
 
63235
63279
  for (i = 0, l = lines.length; i < l; i++) {
63236
63280
  const line = lines[i];
@@ -63263,7 +63307,9 @@ class LineBuilder {
63263
63307
 
63264
63308
  for (let i = 0; i < n; i++) {
63265
63309
 
63266
- r.add(lines[i]);
63310
+ const line_text = lines[i];
63311
+
63312
+ r.add(line_text);
63267
63313
 
63268
63314
  }
63269
63315
 
@@ -66277,7 +66323,7 @@ class GeometrySpatialQueryAccelerator {
66277
66323
  * @param {number} value in bytes
66278
66324
  */
66279
66325
  set cache_size(value) {
66280
- this.cache.setMaxWeight(value);
66326
+ this.cache.maxWeight = value;
66281
66327
  }
66282
66328
 
66283
66329
  /**