@woosh/meep-engine 2.117.21 → 2.117.22

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
@@ -52066,19 +52066,52 @@ class TerrainPreview {
52066
52066
  const UINT32_MAX = 4294967295;
52067
52067
 
52068
52068
  /**
52069
- * Assumes arrays have the same type
52070
- * @param {TypedArray|Float32Array|Uint8Array|Uint32Array} source
52071
- * @param {TypedArray|Float32Array|Uint8Array|Uint32Array} destination
52069
+ * This is essentially a {@link memcopy} implementation for ArrayBuffers
52070
+ * NOTE: allocates light-weight typed arrays under the hood, so beware of potential GC implications. Generally not an issue, unless you're copying very large number of very small arrays, consider alternatives such as {@link array_copy} instead
52071
+ * @param {ArrayBuffer} source
52072
+ * @param {number} source_offset
52073
+ * @param {ArrayBuffer} target
52074
+ * @param {number} target_offset
52075
+ * @param {number} byte_length
52072
52076
  */
52073
- function typed_array_copy(source, destination) {
52074
- const destination_size = destination.length;
52077
+ function array_buffer_copy(
52078
+ source, source_offset,
52079
+ target, target_offset,
52080
+ byte_length
52081
+ ) {
52082
+
52083
+ /**
52084
+ * @type {Uint8Array|Uint16Array|Uint32Array}
52085
+ */
52086
+ let source_array;
52087
+ /**
52088
+ * @type {Uint8Array|Uint16Array|Uint32Array}
52089
+ */
52090
+ let target_array;
52091
+
52092
+ const alignment = largest_common_alignment_uint32(source_offset,target_offset,byte_length);
52093
+
52094
+ if (
52095
+ alignment === 4
52096
+ ) {
52097
+ // aligned on 4-byte boundary
52098
+ source_array = new Uint32Array(source, source_offset, byte_length >>> 2);
52099
+ target_array = new Uint32Array(target, target_offset, byte_length >>> 2);
52100
+
52101
+ } else if (
52102
+ alignment === 2
52103
+ ) {
52104
+ // aligned on 2-byte boundary
52105
+ source_array = new Uint16Array(source, source_offset, byte_length >>> 1);
52106
+ target_array = new Uint16Array(target, target_offset, byte_length >>> 1);
52075
52107
 
52076
- if (destination_size >= source.length) {
52077
- destination.set(source, 0);
52078
52108
  } else {
52079
- // destination is smaller than source, crop source data
52080
- array_copy(source, 0, destination, 0, destination_size);
52109
+ // worst-case, assume 1-byte boundary
52110
+ source_array = new Uint8Array(source, source_offset, byte_length);
52111
+ target_array = new Uint8Array(target, target_offset, byte_length);
52081
52112
  }
52113
+
52114
+ target_array.set(source_array);
52082
52115
  }
52083
52116
 
52084
52117
  /**
@@ -52292,7 +52325,11 @@ class BVH {
52292
52325
  this.__data_uint32 = new Uint32Array(new_data_buffer);
52293
52326
 
52294
52327
  // copy old data into new buffer
52295
- typed_array_copy(old_data_uint32, this.__data_uint32);
52328
+ array_buffer_copy(
52329
+ old_data_uint32.buffer, old_data_uint32.byteOffset,
52330
+ new_data_buffer, 0,
52331
+ Math.min(old_data_uint32.byteLength, new_data_buffer.byteLength)
52332
+ );
52296
52333
 
52297
52334
  this.__capacity = new_capacity;
52298
52335
  }
@@ -61430,6 +61467,22 @@ Cache.prototype.delete = Cache.prototype.remove;
61430
61467
  */
61431
61468
  Cache.prototype.has = Cache.prototype.contains;
61432
61469
 
61470
+ /**
61471
+ * Assumes arrays have the same type
61472
+ * @param {TypedArray|Float32Array|Uint8Array|Uint32Array} source
61473
+ * @param {TypedArray|Float32Array|Uint8Array|Uint32Array} destination
61474
+ */
61475
+ function typed_array_copy(source, destination) {
61476
+ const destination_size = destination.length;
61477
+
61478
+ if (destination_size >= source.length) {
61479
+ destination.set(source, 0);
61480
+ } else {
61481
+ // destination is smaller than source, crop source data
61482
+ array_copy(source, 0, destination, 0, destination_size);
61483
+ }
61484
+ }
61485
+
61433
61486
  /**
61434
61487
  *
61435
61488
  * @param {Object} a