@woosh/meep-engine 2.47.1 → 2.47.3

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
@@ -48200,11 +48200,6 @@ class Sampler2D {
48200
48200
  * @type {number}
48201
48201
  */
48202
48202
  this.version = 0;
48203
- /**
48204
- * @readonly
48205
- * @type {boolean}
48206
- */
48207
- this.isSampler2D = true;
48208
48203
  }
48209
48204
 
48210
48205
  /**
@@ -48235,7 +48230,7 @@ class Sampler2D {
48235
48230
 
48236
48231
  if (l === 0) {
48237
48232
  //no data
48238
- return undefined;
48233
+ return;
48239
48234
  }
48240
48235
 
48241
48236
  let bestValue = data[channel];
@@ -48261,8 +48256,6 @@ class Sampler2D {
48261
48256
  if (resultCount < result.length) {
48262
48257
  result.splice(resultCount, result.length - resultCount);
48263
48258
  }
48264
-
48265
- return;
48266
48259
  }
48267
48260
 
48268
48261
  /**
@@ -48761,73 +48754,6 @@ class Sampler2D {
48761
48754
  result.set(x, y);
48762
48755
  }
48763
48756
 
48764
- /**
48765
- *
48766
- * @param {number} scale
48767
- * @param {number} offset
48768
- * @return {function(index:int, array:ArrayLike, x:int, y:int)}
48769
- */
48770
- makeArrayFiller(scale, offset) {
48771
- scale = scale || 255;
48772
- offset = offset || 0;
48773
-
48774
- const sampler = this;
48775
- const v4 = [1 / scale, 1 / scale, 1 / scale, 1 / scale];
48776
-
48777
- //
48778
- function fillDD1(index, array, x, y) {
48779
- const val = (sampler.sampleChannelBilinear(x, y, 0) + offset) * scale | 0;
48780
- array[index] = val;
48781
- array[index + 1] = val;
48782
- array[index + 2] = val;
48783
- array[index + 3] = 255;
48784
- }
48785
-
48786
- function fillDD2(index, array, x, y) {
48787
- sampler.sampleBilinear(x, y, v4, 0);
48788
- const val = (v4[0] + offset) * scale | 0;
48789
- array.fill(val, index, index + 3);
48790
- array[index + 3] = (v4[1] + offset) * scale | 0;
48791
- }
48792
-
48793
- function fillDD3(index, array, x, y) {
48794
-
48795
- sampler.sampleBilinear(x, y, v4, 0);
48796
-
48797
- array[index] = (v4[0] + offset) * scale | 0;
48798
- array[index + 1] = (v4[1] + offset) * scale | 0;
48799
- array[index + 2] = (v4[2] + offset) * scale | 0;
48800
- array[index + 3] = 255;
48801
- }
48802
-
48803
- function fillDD4(index, array, x, y) {
48804
- sampler.sampleBilinear(x, y, v4, 0);
48805
- array[index] = (v4[0] + offset) * scale | 0;
48806
- array[index + 1] = (v4[1] + offset) * scale | 0;
48807
- array[index + 2] = (v4[2] + offset) * scale | 0;
48808
- array[index + 3] = (v4[3] + offset) * scale | 0;
48809
- }
48810
-
48811
- let fillDD;
48812
- switch (sampler.itemSize) {
48813
- case 1:
48814
- fillDD = fillDD1;
48815
- break;
48816
- case 2:
48817
- fillDD = fillDD2;
48818
- break;
48819
- case 3:
48820
- fillDD = fillDD3;
48821
- break;
48822
- case 4:
48823
- fillDD = fillDD4;
48824
- break;
48825
- default :
48826
- throw new Error("unsupported item size");
48827
- }
48828
- return fillDD;
48829
- }
48830
-
48831
48757
  /**
48832
48758
  * Copy a patch from another sampler with a margin.
48833
48759
  * This is useful for texture rendering where filtering can cause bleeding along the edges of the patch.
@@ -49404,28 +49330,7 @@ class Sampler2D {
49404
49330
  * @param {BinaryBuffer} buffer
49405
49331
  */
49406
49332
  toBinaryBuffer(buffer) {
49407
- const width = this.width;
49408
- const height = this.height;
49409
-
49410
- const itemSize = this.itemSize;
49411
-
49412
- buffer.writeUint16(width);
49413
- buffer.writeUint16(height);
49414
-
49415
- buffer.writeUint8(itemSize);
49416
-
49417
- if (this.data instanceof Uint8Array) {
49418
- //data type
49419
- buffer.writeUint8(0);
49420
-
49421
-
49422
- const byteSize = width * height * itemSize;
49423
-
49424
- buffer.writeBytes(this.data, 0, byteSize);
49425
-
49426
- } else {
49427
- throw new TypeError(`Unsupported data type`);
49428
- }
49333
+ throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
49429
49334
  }
49430
49335
 
49431
49336
  /**
@@ -49433,24 +49338,7 @@ class Sampler2D {
49433
49338
  * @param {BinaryBuffer} buffer
49434
49339
  */
49435
49340
  fromBinaryBuffer(buffer) {
49436
- this.width = buffer.readUint16();
49437
- this.height = buffer.readUint16();
49438
-
49439
- this.itemSize = buffer.readUint8();
49440
-
49441
- const dataType = buffer.readUint8();
49442
-
49443
- if (dataType === 0) {
49444
-
49445
- const numBytes = this.height * this.width * this.itemSize;
49446
- this.data = new Uint8Array(numBytes);
49447
-
49448
- buffer.readBytes(this.data, 0, numBytes);
49449
-
49450
- this.version++;
49451
- } else {
49452
- throw new TypeError(`Unsupported data type (${dataType})`);
49453
- }
49341
+ throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
49454
49342
  }
49455
49343
 
49456
49344
  /**
@@ -49695,6 +49583,11 @@ class Sampler2D {
49695
49583
 
49696
49584
  }
49697
49585
 
49586
+ /**
49587
+ * @readonly
49588
+ * @type {boolean}
49589
+ */
49590
+ Sampler2D.prototype.isSampler2D = true;
49698
49591
 
49699
49592
  /**
49700
49593
  * Based on code from reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
@@ -62653,6 +62546,10 @@ List.prototype.toBinaryBuffer = function (buffer) {
62653
62546
  for (let i = 0; i < n; i++) {
62654
62547
  const item = this.data[i];
62655
62548
 
62549
+ if(typeof item.toBinaryBuffer !== "function"){
62550
+ throw new Error('item.toBinaryBuffer is not a function');
62551
+ }
62552
+
62656
62553
  item.toBinaryBuffer(buffer);
62657
62554
  }
62658
62555
  };
@@ -62667,6 +62564,10 @@ List.prototype.fromBinaryBuffer = function (buffer, constructor) {
62667
62564
 
62668
62565
  const el = new constructor();
62669
62566
 
62567
+ if(typeof el.fromBinaryBuffer !== "function"){
62568
+ throw new Error('item.fromBinaryBuffer is not a function');
62569
+ }
62570
+
62670
62571
  el.fromBinaryBuffer(buffer);
62671
62572
 
62672
62573
  return el;
@@ -105706,213 +105607,223 @@ class TooltipManager {
105706
105607
  */
105707
105608
 
105708
105609
 
105709
- /**
105710
- *
105711
- * @param {number} x
105712
- * @param {number} y
105713
- * @param {number} width
105714
- * @param {number} height
105715
- * @constructor
105716
- */
105717
- function Rectangle(x = 0, y = 0, width = 0, height = 0) {
105610
+ class Rectangle {
105611
+ /**
105612
+ *
105613
+ * @param {number} x
105614
+ * @param {number} y
105615
+ * @param {number} width
105616
+ * @param {number} height
105617
+ * @constructor
105618
+ */
105619
+ constructor(x = 0, y = 0, width = 0, height = 0) {
105620
+
105621
+ /**
105622
+ * @readonly
105623
+ * @type {Vector2}
105624
+ */
105625
+ this.position = new Vector2(x, y);
105626
+
105627
+ /**
105628
+ * @readonly
105629
+ * @type {Vector2}
105630
+ */
105631
+ this.size = new Vector2(width, height);
105632
+ }
105718
105633
 
105719
105634
  /**
105720
- * @type {Vector2}
105635
+ *
105636
+ * @param {number} x
105637
+ * @param {number} y
105638
+ * @param {number} width
105639
+ * @param {number} height
105721
105640
  */
105722
- this.position = new Vector2(x, y);
105641
+ set(x, y, width, height) {
105642
+ this.size.set(width, height);
105643
+ this.position.set(x, y);
105644
+ }
105723
105645
 
105724
105646
  /**
105725
- * @type {Vector2}
105647
+ *
105648
+ * @returns {Rectangle}
105726
105649
  */
105727
- this.size = new Vector2(width, height);
105728
- }
105650
+ clone() {
105651
+ return new Rectangle(this.position.x, this.position.y, this.size.x, this.size.y);
105652
+ }
105729
105653
 
105730
- /**
105731
- *
105732
- * @param {number} x
105733
- * @param {number} y
105734
- * @param {number} width
105735
- * @param {number} height
105736
- */
105737
- Rectangle.prototype.set = function set(x, y, width, height) {
105738
- this.size.set(width, height);
105739
- this.position.set(x, y);
105740
- };
105654
+ /**
105655
+ *
105656
+ * @param {Rectangle} other
105657
+ */
105658
+ copy(other) {
105659
+ this.position.copy(other.position);
105660
+ this.size.copy(other.size);
105661
+ }
105741
105662
 
105742
- /**
105743
- *
105744
- * @returns {Rectangle}
105745
- */
105746
- Rectangle.prototype.clone = function () {
105747
- return new Rectangle(this.position.x, this.position.y, this.size.x, this.size.y);
105748
- };
105663
+ /**
105664
+ *
105665
+ * @param {number} x0
105666
+ * @param {number} y0
105667
+ * @param {number} x1
105668
+ * @param {number} y1
105669
+ * @returns {boolean}
105670
+ */
105671
+ _intersects(x0, y0, x1, y1) {
105672
+ const p = this.position;
105673
+ const s = this.size;
105749
105674
 
105750
- /**
105751
- *
105752
- * @param {Rectangle} other
105753
- */
105754
- Rectangle.prototype.copy = function (other) {
105755
- this.position.copy(other.position);
105756
- this.size.copy(other.size);
105757
- };
105675
+ const _x0 = p.x;
105676
+ const _y0 = p.y;
105758
105677
 
105759
- /**
105760
- *
105761
- * @param {number} x0
105762
- * @param {number} y0
105763
- * @param {number} x1
105764
- * @param {number} y1
105765
- * @returns {boolean}
105766
- */
105767
- Rectangle.prototype._intersects = function (x0, y0, x1, y1) {
105768
- const p = this.position;
105769
- const s = this.size;
105678
+ return intersects1D(x0, x1, _x0, s.x + _x0) && intersects1D(y0, y1, _y0, _y0 + s.y);
105679
+ }
105770
105680
 
105771
- const _x0 = p.x;
105772
- const _y0 = p.y;
105681
+ /**
105682
+ *
105683
+ * @param {Rectangle} other
105684
+ * @returns {boolean}
105685
+ */
105686
+ intersects(other) {
105687
+ const x0 = other.position.x;
105688
+ const y0 = other.position.y;
105689
+ const y1 = other.size.y + y0;
105690
+ const x1 = other.size.x + x0;
105691
+ return this._intersects(x0, y0, x1, y1);
105692
+ }
105773
105693
 
105774
- return intersects1D(x0, x1, _x0, s.x + _x0) && intersects1D(y0, y1, _y0, _y0 + s.y);
105775
- };
105694
+ /**
105695
+ *
105696
+ * @param {number} x0
105697
+ * @param {number} y0
105698
+ * @param {number} x1
105699
+ * @param {number} y1
105700
+ * @returns {boolean}
105701
+ */
105702
+ _overlaps(x0, y0, x1, y1) {
105703
+ const p = this.position;
105704
+ const s = this.size;
105776
105705
 
105777
- /**
105778
- *
105779
- * @param {Rectangle} other
105780
- * @returns {boolean}
105781
- */
105782
- Rectangle.prototype.intersects = function (other) {
105783
- const x0 = other.position.x;
105784
- const y0 = other.position.y;
105785
- const y1 = other.size.y + y0;
105786
- const x1 = other.size.x + x0;
105787
- return this._intersects(x0, y0, x1, y1);
105788
- };
105706
+ const _x0 = p.x;
105707
+ const _y0 = p.y;
105789
105708
 
105790
- /**
105791
- *
105792
- * @param {number} x0
105793
- * @param {number} y0
105794
- * @param {number} x1
105795
- * @param {number} y1
105796
- * @returns {boolean}
105797
- */
105798
- Rectangle.prototype._overlaps = function (x0, y0, x1, y1) {
105799
- const p = this.position;
105800
- const s = this.size;
105709
+ return overlap1D(x0, x1, _x0, s.x + _x0) && overlap1D(y0, y1, _y0, _y0 + s.y);
105710
+ }
105801
105711
 
105802
- const _x0 = p.x;
105803
- const _y0 = p.y;
105712
+ overlaps(other) {
105713
+ const x0 = other.position.x;
105714
+ const y0 = other.position.y;
105715
+ const y1 = other.size.y + y0;
105716
+ const x1 = other.size.x + x0;
105717
+ return this._overlaps(x0, y0, x1, y1);
105718
+ }
105804
105719
 
105805
- return overlap1D(x0, x1, _x0, s.x + _x0) && overlap1D(y0, y1, _y0, _y0 + s.y);
105806
- };
105720
+ _resizeToFit(x0, y0, x1, y1) {
105721
+ const size = this.size;
105807
105722
 
105808
- Rectangle.prototype.overlaps = function (other) {
105809
- const x0 = other.position.x;
105810
- const y0 = other.position.y;
105811
- const y1 = other.size.y + y0;
105812
- const x1 = other.size.x + x0;
105813
- return this._overlaps(x0, y0, x1, y1);
105814
- };
105723
+ const _x0 = this.position.x;
105724
+ const _y0 = this.position.y;
105815
105725
 
105816
- Rectangle.prototype._resizeToFit = function (x0, y0, x1, y1) {
105817
- const size = this.size;
105726
+ let _y1 = size.y + _y0;
105727
+ let _x1 = size.x + _x0;
105818
105728
 
105819
- const _x0 = this.position.x;
105820
- const _y0 = this.position.y;
105729
+ if (Number.isNaN(_x1)) {
105730
+ _x1 = -Infinity;
105731
+ }
105732
+ if (Number.isNaN(_y1)) {
105733
+ _y1 = -Infinity;
105734
+ }
105821
105735
 
105822
- let _y1 = size.y + _y0;
105823
- let _x1 = size.x + _x0;
105736
+ const nX0 = min2(x0, _x0);
105737
+ const nY0 = min2(y0, _y0);
105738
+ const nX1 = max2(x1, _x1);
105739
+ const nY1 = max2(y1, _y1);
105824
105740
 
105825
- if (Number.isNaN(_x1)) {
105826
- _x1 = -Infinity;
105827
- }
105828
- if (Number.isNaN(_y1)) {
105829
- _y1 = -Infinity;
105741
+ this.position.set(nX0, nY0);
105742
+ size.set(nX1 - nX0, nY1 - nY0);
105830
105743
  }
105831
105744
 
105832
- const nX0 = min2(x0, _x0);
105833
- const nY0 = min2(y0, _y0);
105834
- const nX1 = max2(x1, _x1);
105835
- const nY1 = max2(y1, _y1);
105745
+ resizeToFit(other) {
105746
+ const x0 = other.position.x;
105747
+ const y0 = other.position.y;
105748
+ const y1 = other.size.y + y0;
105749
+ const x1 = other.size.x + x0;
105836
105750
 
105837
- this.position.set(nX0, nY0);
105838
- size.set(nX1 - nX0, nY1 - nY0);
105839
- };
105751
+ return this._resizeToFit(x0, y0, x1, y1);
105752
+ }
105840
105753
 
105841
- Rectangle.prototype.resizeToFit = function (other) {
105842
- const x0 = other.position.x;
105843
- const y0 = other.position.y;
105844
- const y1 = other.size.y + y0;
105845
- const x1 = other.size.x + x0;
105754
+ _contains(x0, y0, x1, y1) {
105755
+ const size = this.size;
105846
105756
 
105847
- return this._resizeToFit(x0, y0, x1, y1);
105848
- };
105757
+ const _x0 = this.position.x;
105758
+ const _y0 = this.position.y;
105849
105759
 
105850
- Rectangle.prototype._contains = function (x0, y0, x1, y1) {
105851
- const size = this.size;
105760
+ const _y1 = size.y + _y0;
105761
+ const _x1 = size.x + _x0;
105852
105762
 
105853
- const _x0 = this.position.x;
105854
- const _y0 = this.position.y;
105763
+ return x0 >= _x0 && x1 <= _x1 && y0 >= _y0 && y1 <= _y1;
105764
+ }
105855
105765
 
105856
- const _y1 = size.y + _y0;
105857
- const _x1 = size.x + _x0;
105766
+ contains(other) {
105767
+ const x0 = other.position.x;
105768
+ const y0 = other.position.y;
105769
+ const y1 = other.size.y + y0;
105770
+ const x1 = other.size.x + x0;
105858
105771
 
105859
- return x0 >= _x0 && x1 <= _x1 && y0 >= _y0 && y1 <= _y1;
105860
- };
105772
+ return this._contains(x0, y0, x1, y1);
105773
+ }
105861
105774
 
105862
- Rectangle.prototype.contains = function (other) {
105863
- const x0 = other.position.x;
105864
- const y0 = other.position.y;
105865
- const y1 = other.size.y + y0;
105866
- const x1 = other.size.x + x0;
105775
+ /**
105776
+ *
105777
+ * @param {Vector2} result
105778
+ */
105779
+ computeCenter(result) {
105780
+ const p = this.position;
105781
+ const s = this.size;
105867
105782
 
105868
- return this._contains(x0, y0, x1, y1);
105869
- };
105783
+ const x = p.x + s.x / 2;
105784
+ const y = p.y + s.y / 2;
105870
105785
 
105871
- /**
105872
- *
105873
- * @param {Vector2} result
105874
- */
105875
- Rectangle.prototype.computeCenter = function (result) {
105876
- const p = this.position;
105877
- const s = this.size;
105786
+ result.set(x, y);
105787
+ }
105878
105788
 
105879
- const x = p.x + s.x / 2;
105880
- const y = p.y + s.y / 2;
105789
+ /**
105790
+ *
105791
+ * @return {number}
105792
+ */
105793
+ computeArea() {
105794
+ return this.size.x * this.size.y;
105795
+ }
105881
105796
 
105882
- result.set(x, y);
105883
- };
105797
+ /**
105798
+ *
105799
+ * @param {Array.<number>|Float32Array|Float64Array|Uint8Array} target
105800
+ * @param {number} [targetOffset=0]
105801
+ */
105802
+ toArray(target, targetOffset = 0) {
105803
+ target[targetOffset] = this.position.x;
105804
+ target[targetOffset + 1] = this.position.y;
105805
+ target[targetOffset + 2] = this.size.x;
105806
+ target[targetOffset + 3] = this.size.y;
105807
+ }
105884
105808
 
105885
- /**
105886
- *
105887
- * @return {number}
105888
- */
105889
- Rectangle.prototype.computeArea = function () {
105890
- return this.size.x * this.size.y;
105891
- };
105809
+ toJSON() {
105810
+ return {
105811
+ position: this.position.toJSON(),
105812
+ size: this.size.toJSON()
105813
+ };
105814
+ }
105815
+
105816
+ fromJSON(json) {
105817
+ this.position.fromJSON(json.position);
105818
+ this.size.fromJSON(json.size);
105819
+ }
105820
+ }
105892
105821
 
105893
105822
  /**
105894
- *
105895
- * @param {Array.<number>|Float32Array|Float64Array|Uint8Array} target
105896
- * @param {number} [targetOffset=0]
105823
+ * @readonly
105824
+ * @type {boolean}
105897
105825
  */
105898
- Rectangle.prototype.toArray = function (target, targetOffset = 0) {
105899
- target[targetOffset] = this.position.x;
105900
- target[targetOffset + 1] = this.position.y;
105901
- target[targetOffset + 2] = this.size.x;
105902
- target[targetOffset + 3] = this.size.y;
105903
- };
105904
-
105905
- Rectangle.prototype.toJSON = function () {
105906
- return {
105907
- position: this.position.toJSON(),
105908
- size: this.size.toJSON()
105909
- };
105910
- };
105911
-
105912
- Rectangle.prototype.fromJSON = function (json) {
105913
- this.position.fromJSON(json.position);
105914
- this.size.fromJSON(json.size);
105915
- };
105826
+ Rectangle.prototype.isRectangle = true;
105916
105827
 
105917
105828
  class VisualTip {
105918
105829
  /**