@woosh/meep-engine 2.46.36 → 2.47.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.
Files changed (26) hide show
  1. package/build/meep.cjs +302 -369
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +302 -369
  4. package/package.json +3 -2
  5. package/src/core/collection/list/List.js +8 -0
  6. package/src/core/geom/Rectangle.js +178 -168
  7. package/src/core/model/node-graph/NodeGraph.js +10 -1
  8. package/src/core/model/node-graph/node/NodeInstance.js +83 -15
  9. package/src/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +7 -2
  10. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +4 -2
  11. package/src/engine/graphics/micron/prototypeVirtualGeometry.js +2 -2
  12. package/src/engine/graphics/texture/sampler/Sampler2D.js +12 -198
  13. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -37
  14. package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +3 -3
  15. package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +2 -2
  16. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +51 -0
  17. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.spec.js +40 -0
  18. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +51 -0
  19. package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +4 -2
  20. package/src/engine/graphics/texture/sampler/sampler2d_make_array_filler_function.js +65 -0
  21. package/src/engine/graphics/texture/sampler/{sampler2D_scale_down_linear.js → sampler2d_scale_down_linear.js} +1 -1
  22. package/src/engine/graphics/texture/sampler/{downsampleSample2D.spec.js → sampler2d_scale_down_linear.spec.js} +2 -2
  23. package/src/engine/graphics/texture/sampler/{sample2d_write_to_canvas_raw.js → sampler2d_write_to_canvas_raw.js} +5 -1
  24. package/src/engine/graphics/texture/sampler/scaleSampler2D.js +2 -2
  25. package/src/engine/input/ecs/util/TerrainCameraTargetSampler.js +2 -2
  26. package/src/engine/ui/tiles2d/computeTileGridMove.js +2 -2
package/build/meep.cjs CHANGED
@@ -48200,59 +48200,15 @@ 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
  /**
48206
+ * @deprecated
48211
48207
  * @param {number} [channel=0]
48212
48208
  * @returns {{x: number, index: number, y: number, value: number}}
48213
48209
  */
48214
48210
  computeMax(channel = 0) {
48215
- const itemSize = this.itemSize;
48216
-
48217
- assert.isNumber(channel, "channel");
48218
- assert.isNonNegativeInteger(channel , 'channel');
48219
- assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
48220
-
48221
- const data = this.data;
48222
-
48223
- const l = data.length;
48224
-
48225
- if (l === 0) {
48226
- //no data
48227
- return undefined;
48228
- }
48229
-
48230
- let bestValue = data[channel];
48231
- let bestIndex = channel;
48232
-
48233
- for (let i = channel + itemSize; i < l; i += itemSize) {
48234
- const value = data[i];
48235
-
48236
- if (bestValue < value) {
48237
- bestValue = value;
48238
- bestIndex = i;
48239
- }
48240
-
48241
- }
48242
-
48243
- const width = this.width;
48244
-
48245
- const itemIndex = (bestIndex / this.itemSize) | 0;
48246
-
48247
- const x = itemIndex % width;
48248
- const y = (itemIndex / width) | 0;
48249
-
48250
- return {
48251
- index: bestIndex,
48252
- value: bestValue,
48253
- x,
48254
- y
48255
- };
48211
+ throw new Error("deprecated, use sampler2d_channel_compute_max");
48256
48212
  }
48257
48213
 
48258
48214
  /**
@@ -48274,7 +48230,7 @@ class Sampler2D {
48274
48230
 
48275
48231
  if (l === 0) {
48276
48232
  //no data
48277
- return undefined;
48233
+ return;
48278
48234
  }
48279
48235
 
48280
48236
  let bestValue = data[channel];
@@ -48300,56 +48256,15 @@ class Sampler2D {
48300
48256
  if (resultCount < result.length) {
48301
48257
  result.splice(resultCount, result.length - resultCount);
48302
48258
  }
48303
-
48304
- return;
48305
48259
  }
48306
48260
 
48307
48261
  /**
48262
+ * @deprecated
48308
48263
  * @param {number} [channel=0]
48309
48264
  * @returns {{x: number, index: number, y: number, value: number}}
48310
48265
  */
48311
48266
  computeMin(channel = 0) {
48312
- const itemSize = this.itemSize;
48313
-
48314
- assert.typeOf(channel, "number", "channel");
48315
- assert.ok(channel >= 0, `channel must be >= 0, was ${channel}`);
48316
- assert.ok(channel < itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
48317
-
48318
- const data = this.data;
48319
-
48320
- const l = data.length;
48321
-
48322
- if (l === 0) {
48323
- //no data
48324
- return undefined;
48325
- }
48326
-
48327
- let bestValue = data[channel];
48328
- let bestIndex = channel;
48329
-
48330
- for (let i = channel + itemSize; i < l; i += itemSize) {
48331
- const value = data[i];
48332
-
48333
- if (bestValue > value) {
48334
- bestValue = value;
48335
- bestIndex = i;
48336
- }
48337
-
48338
- }
48339
-
48340
- const width = this.width;
48341
-
48342
- const itemIndex = (bestIndex / this.itemSize) | 0;
48343
-
48344
- const x = itemIndex % width;
48345
- const y = (itemIndex / width) | 0;
48346
-
48347
- return {
48348
- index: bestIndex,
48349
- value: bestValue,
48350
- x,
48351
- y
48352
- };
48267
+ throw new Error("deprecated, use sampler2d_channel_compute_min");
48353
48268
  }
48354
48269
 
48355
48270
  /**
@@ -48839,73 +48754,6 @@ class Sampler2D {
48839
48754
  result.set(x, y);
48840
48755
  }
48841
48756
 
48842
- /**
48843
- *
48844
- * @param {number} scale
48845
- * @param {number} offset
48846
- * @return {function(index:int, array:ArrayLike, x:int, y:int)}
48847
- */
48848
- makeArrayFiller(scale, offset) {
48849
- scale = scale || 255;
48850
- offset = offset || 0;
48851
-
48852
- const sampler = this;
48853
- const v4 = [1 / scale, 1 / scale, 1 / scale, 1 / scale];
48854
-
48855
- //
48856
- function fillDD1(index, array, x, y) {
48857
- const val = (sampler.sampleChannelBilinear(x, y, 0) + offset) * scale | 0;
48858
- array[index] = val;
48859
- array[index + 1] = val;
48860
- array[index + 2] = val;
48861
- array[index + 3] = 255;
48862
- }
48863
-
48864
- function fillDD2(index, array, x, y) {
48865
- sampler.sampleBilinear(x, y, v4, 0);
48866
- const val = (v4[0] + offset) * scale | 0;
48867
- array.fill(val, index, index + 3);
48868
- array[index + 3] = (v4[1] + offset) * scale | 0;
48869
- }
48870
-
48871
- function fillDD3(index, array, x, y) {
48872
-
48873
- sampler.sampleBilinear(x, y, v4, 0);
48874
-
48875
- array[index] = (v4[0] + offset) * scale | 0;
48876
- array[index + 1] = (v4[1] + offset) * scale | 0;
48877
- array[index + 2] = (v4[2] + offset) * scale | 0;
48878
- array[index + 3] = 255;
48879
- }
48880
-
48881
- function fillDD4(index, array, x, y) {
48882
- sampler.sampleBilinear(x, y, v4, 0);
48883
- array[index] = (v4[0] + offset) * scale | 0;
48884
- array[index + 1] = (v4[1] + offset) * scale | 0;
48885
- array[index + 2] = (v4[2] + offset) * scale | 0;
48886
- array[index + 3] = (v4[3] + offset) * scale | 0;
48887
- }
48888
-
48889
- let fillDD;
48890
- switch (sampler.itemSize) {
48891
- case 1:
48892
- fillDD = fillDD1;
48893
- break;
48894
- case 2:
48895
- fillDD = fillDD2;
48896
- break;
48897
- case 3:
48898
- fillDD = fillDD3;
48899
- break;
48900
- case 4:
48901
- fillDD = fillDD4;
48902
- break;
48903
- default :
48904
- throw new Error("unsupported item size");
48905
- }
48906
- return fillDD;
48907
- }
48908
-
48909
48757
  /**
48910
48758
  * Copy a patch from another sampler with a margin.
48911
48759
  * This is useful for texture rendering where filtering can cause bleeding along the edges of the patch.
@@ -49482,28 +49330,7 @@ class Sampler2D {
49482
49330
  * @param {BinaryBuffer} buffer
49483
49331
  */
49484
49332
  toBinaryBuffer(buffer) {
49485
- const width = this.width;
49486
- const height = this.height;
49487
-
49488
- const itemSize = this.itemSize;
49489
-
49490
- buffer.writeUint16(width);
49491
- buffer.writeUint16(height);
49492
-
49493
- buffer.writeUint8(itemSize);
49494
-
49495
- if (this.data instanceof Uint8Array) {
49496
- //data type
49497
- buffer.writeUint8(0);
49498
-
49499
-
49500
- const byteSize = width * height * itemSize;
49501
-
49502
- buffer.writeBytes(this.data, 0, byteSize);
49503
-
49504
- } else {
49505
- throw new TypeError(`Unsupported data type`);
49506
- }
49333
+ throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
49507
49334
  }
49508
49335
 
49509
49336
  /**
@@ -49511,24 +49338,7 @@ class Sampler2D {
49511
49338
  * @param {BinaryBuffer} buffer
49512
49339
  */
49513
49340
  fromBinaryBuffer(buffer) {
49514
- this.width = buffer.readUint16();
49515
- this.height = buffer.readUint16();
49516
-
49517
- this.itemSize = buffer.readUint8();
49518
-
49519
- const dataType = buffer.readUint8();
49520
-
49521
- if (dataType === 0) {
49522
-
49523
- const numBytes = this.height * this.width * this.itemSize;
49524
- this.data = new Uint8Array(numBytes);
49525
-
49526
- buffer.readBytes(this.data, 0, numBytes);
49527
-
49528
- this.version++;
49529
- } else {
49530
- throw new TypeError(`Unsupported data type (${dataType})`);
49531
- }
49341
+ throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
49532
49342
  }
49533
49343
 
49534
49344
  /**
@@ -49773,6 +49583,11 @@ class Sampler2D {
49773
49583
 
49774
49584
  }
49775
49585
 
49586
+ /**
49587
+ * @readonly
49588
+ * @type {boolean}
49589
+ */
49590
+ Sampler2D.prototype.isSampler2D = true;
49776
49591
 
49777
49592
  /**
49778
49593
  * Based on code from reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
@@ -54840,7 +54655,7 @@ class ObservedString extends String {
54840
54655
  * @param {Sampler2D} input
54841
54656
  * @param {Sampler2D} output
54842
54657
  */
54843
- function sampler2D_scale_down_linear(input, output) {
54658
+ function sampler2d_scale_down_linear(input, output) {
54844
54659
  assert.notEqual(input, undefined, 'input is undefined');
54845
54660
  assert.notEqual(output, undefined, 'output is undefined');
54846
54661
 
@@ -55053,7 +54868,7 @@ function scaleSampler2D(input, output) {
55053
54868
  // downscaling
55054
54869
  if (Number.isInteger(sourceWidth / targetWidth) && Number.isInteger(sourceHeight / targetHeight)) {
55055
54870
  // dimensions are multiples of source/target
55056
- sampler2D_scale_down_linear(input, output);
54871
+ sampler2d_scale_down_linear(input, output);
55057
54872
  } else {
55058
54873
  // generic downsample
55059
54874
  genericResampleSampler2D(input, output);
@@ -62731,6 +62546,10 @@ List.prototype.toBinaryBuffer = function (buffer) {
62731
62546
  for (let i = 0; i < n; i++) {
62732
62547
  const item = this.data[i];
62733
62548
 
62549
+ if(typeof item.toBinaryBuffer !== "function"){
62550
+ throw new Error('item.toBinaryBuffer is not a function');
62551
+ }
62552
+
62734
62553
  item.toBinaryBuffer(buffer);
62735
62554
  }
62736
62555
  };
@@ -62745,6 +62564,10 @@ List.prototype.fromBinaryBuffer = function (buffer, constructor) {
62745
62564
 
62746
62565
  const el = new constructor();
62747
62566
 
62567
+ if(typeof el.fromBinaryBuffer !== "function"){
62568
+ throw new Error('item.fromBinaryBuffer is not a function');
62569
+ }
62570
+
62748
62571
  el.fromBinaryBuffer(buffer);
62749
62572
 
62750
62573
  return el;
@@ -65569,6 +65392,106 @@ WorkerBuilder.prototype.build = function () {
65569
65392
  return proxy;
65570
65393
  };
65571
65394
 
65395
+ /**
65396
+ *
65397
+ * @param {Sampler2D} sampler
65398
+ * @param {number} [channel=0]
65399
+ * @returns {undefined|{x: number, index:number, y: number, value: number}}
65400
+ */
65401
+ function sampler2d_channel_compute_max(sampler, channel=0){
65402
+ const itemSize = sampler.itemSize;
65403
+
65404
+ assert.isNumber(channel, "channel");
65405
+ assert.isNonNegativeInteger(channel , 'channel');
65406
+ assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
65407
+
65408
+ const data = sampler.data;
65409
+
65410
+ const l = data.length;
65411
+
65412
+ if (l === 0) {
65413
+ //no data
65414
+ return undefined;
65415
+ }
65416
+
65417
+ let bestValue = data[channel];
65418
+ let bestIndex = channel;
65419
+
65420
+ for (let i = channel + itemSize; i < l; i += itemSize) {
65421
+ const value = data[i];
65422
+
65423
+ if (bestValue < value) {
65424
+ bestValue = value;
65425
+ bestIndex = i;
65426
+ }
65427
+
65428
+ }
65429
+
65430
+ const width = this.width;
65431
+
65432
+ const itemIndex = (bestIndex / itemSize) | 0;
65433
+
65434
+ const x = itemIndex % width;
65435
+ const y = (itemIndex / width) | 0;
65436
+
65437
+ return {
65438
+ index: bestIndex,
65439
+ value: bestValue,
65440
+ x,
65441
+ y
65442
+ };
65443
+ }
65444
+
65445
+ /**
65446
+ *
65447
+ * @param {Sampler2D} sampler
65448
+ * @param {number} [channel=0]
65449
+ * @returns {undefined|{x: number, index:number, y: number, value: number}}
65450
+ */
65451
+ function sampler2d_channel_compute_min(sampler, channel=0){
65452
+ const itemSize = sampler.itemSize;
65453
+
65454
+ assert.isNumber(channel, "channel");
65455
+ assert.isNonNegativeInteger(channel , 'channel');
65456
+ assert.lessThan(channel, itemSize, `channel must be less than itemSize(=${itemSize}), was ${channel}`);
65457
+
65458
+ const data = sampler.data;
65459
+
65460
+ const l = data.length;
65461
+
65462
+ if (l === 0) {
65463
+ //no data
65464
+ return undefined;
65465
+ }
65466
+
65467
+ let bestValue = data[channel];
65468
+ let bestIndex = channel;
65469
+
65470
+ for (let i = channel + itemSize; i < l; i += itemSize) {
65471
+ const value = data[i];
65472
+
65473
+ if (bestValue > value) {
65474
+ bestValue = value;
65475
+ bestIndex = i;
65476
+ }
65477
+
65478
+ }
65479
+
65480
+ const width = this.width;
65481
+
65482
+ const itemIndex = (bestIndex / itemSize) | 0;
65483
+
65484
+ const x = itemIndex % width;
65485
+ const y = (itemIndex / width) | 0;
65486
+
65487
+ return {
65488
+ index: bestIndex,
65489
+ value: bestValue,
65490
+ x,
65491
+ y
65492
+ };
65493
+ }
65494
+
65572
65495
  /**
65573
65496
  *
65574
65497
  * @return {WorkerProxy}
@@ -65596,8 +65519,8 @@ function makeTerrainWorkerProxy() {
65596
65519
 
65597
65520
  useSampler(function (sampler) {
65598
65521
 
65599
- const min = sampler.computeMin();
65600
- const max = sampler.computeMax();
65522
+ const min = sampler2d_channel_compute_min(sampler);
65523
+ const max = sampler2d_channel_compute_max(sampler);
65601
65524
 
65602
65525
  resolve({
65603
65526
  min: min.value,
@@ -105684,213 +105607,223 @@ class TooltipManager {
105684
105607
  */
105685
105608
 
105686
105609
 
105687
- /**
105688
- *
105689
- * @param {number} x
105690
- * @param {number} y
105691
- * @param {number} width
105692
- * @param {number} height
105693
- * @constructor
105694
- */
105695
- 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
+ }
105696
105633
 
105697
105634
  /**
105698
- * @type {Vector2}
105635
+ *
105636
+ * @param {number} x
105637
+ * @param {number} y
105638
+ * @param {number} width
105639
+ * @param {number} height
105699
105640
  */
105700
- 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
+ }
105701
105645
 
105702
105646
  /**
105703
- * @type {Vector2}
105647
+ *
105648
+ * @returns {Rectangle}
105704
105649
  */
105705
- this.size = new Vector2(width, height);
105706
- }
105650
+ clone() {
105651
+ return new Rectangle(this.position.x, this.position.y, this.size.x, this.size.y);
105652
+ }
105707
105653
 
105708
- /**
105709
- *
105710
- * @param {number} x
105711
- * @param {number} y
105712
- * @param {number} width
105713
- * @param {number} height
105714
- */
105715
- Rectangle.prototype.set = function set(x, y, width, height) {
105716
- this.size.set(width, height);
105717
- this.position.set(x, y);
105718
- };
105654
+ /**
105655
+ *
105656
+ * @param {Rectangle} other
105657
+ */
105658
+ copy(other) {
105659
+ this.position.copy(other.position);
105660
+ this.size.copy(other.size);
105661
+ }
105719
105662
 
105720
- /**
105721
- *
105722
- * @returns {Rectangle}
105723
- */
105724
- Rectangle.prototype.clone = function () {
105725
- return new Rectangle(this.position.x, this.position.y, this.size.x, this.size.y);
105726
- };
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;
105727
105674
 
105728
- /**
105729
- *
105730
- * @param {Rectangle} other
105731
- */
105732
- Rectangle.prototype.copy = function (other) {
105733
- this.position.copy(other.position);
105734
- this.size.copy(other.size);
105735
- };
105675
+ const _x0 = p.x;
105676
+ const _y0 = p.y;
105736
105677
 
105737
- /**
105738
- *
105739
- * @param {number} x0
105740
- * @param {number} y0
105741
- * @param {number} x1
105742
- * @param {number} y1
105743
- * @returns {boolean}
105744
- */
105745
- Rectangle.prototype._intersects = function (x0, y0, x1, y1) {
105746
- const p = this.position;
105747
- const s = this.size;
105678
+ return intersects1D(x0, x1, _x0, s.x + _x0) && intersects1D(y0, y1, _y0, _y0 + s.y);
105679
+ }
105748
105680
 
105749
- const _x0 = p.x;
105750
- 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
+ }
105751
105693
 
105752
- return intersects1D(x0, x1, _x0, s.x + _x0) && intersects1D(y0, y1, _y0, _y0 + s.y);
105753
- };
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;
105754
105705
 
105755
- /**
105756
- *
105757
- * @param {Rectangle} other
105758
- * @returns {boolean}
105759
- */
105760
- Rectangle.prototype.intersects = function (other) {
105761
- const x0 = other.position.x;
105762
- const y0 = other.position.y;
105763
- const y1 = other.size.y + y0;
105764
- const x1 = other.size.x + x0;
105765
- return this._intersects(x0, y0, x1, y1);
105766
- };
105706
+ const _x0 = p.x;
105707
+ const _y0 = p.y;
105767
105708
 
105768
- /**
105769
- *
105770
- * @param {number} x0
105771
- * @param {number} y0
105772
- * @param {number} x1
105773
- * @param {number} y1
105774
- * @returns {boolean}
105775
- */
105776
- Rectangle.prototype._overlaps = function (x0, y0, x1, y1) {
105777
- const p = this.position;
105778
- const s = this.size;
105709
+ return overlap1D(x0, x1, _x0, s.x + _x0) && overlap1D(y0, y1, _y0, _y0 + s.y);
105710
+ }
105779
105711
 
105780
- const _x0 = p.x;
105781
- 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
+ }
105782
105719
 
105783
- return overlap1D(x0, x1, _x0, s.x + _x0) && overlap1D(y0, y1, _y0, _y0 + s.y);
105784
- };
105720
+ _resizeToFit(x0, y0, x1, y1) {
105721
+ const size = this.size;
105785
105722
 
105786
- Rectangle.prototype.overlaps = function (other) {
105787
- const x0 = other.position.x;
105788
- const y0 = other.position.y;
105789
- const y1 = other.size.y + y0;
105790
- const x1 = other.size.x + x0;
105791
- return this._overlaps(x0, y0, x1, y1);
105792
- };
105723
+ const _x0 = this.position.x;
105724
+ const _y0 = this.position.y;
105793
105725
 
105794
- Rectangle.prototype._resizeToFit = function (x0, y0, x1, y1) {
105795
- const size = this.size;
105726
+ let _y1 = size.y + _y0;
105727
+ let _x1 = size.x + _x0;
105796
105728
 
105797
- const _x0 = this.position.x;
105798
- const _y0 = this.position.y;
105729
+ if (Number.isNaN(_x1)) {
105730
+ _x1 = -Infinity;
105731
+ }
105732
+ if (Number.isNaN(_y1)) {
105733
+ _y1 = -Infinity;
105734
+ }
105799
105735
 
105800
- let _y1 = size.y + _y0;
105801
- 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);
105802
105740
 
105803
- if (Number.isNaN(_x1)) {
105804
- _x1 = -Infinity;
105805
- }
105806
- if (Number.isNaN(_y1)) {
105807
- _y1 = -Infinity;
105741
+ this.position.set(nX0, nY0);
105742
+ size.set(nX1 - nX0, nY1 - nY0);
105808
105743
  }
105809
105744
 
105810
- const nX0 = min2(x0, _x0);
105811
- const nY0 = min2(y0, _y0);
105812
- const nX1 = max2(x1, _x1);
105813
- 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;
105814
105750
 
105815
- this.position.set(nX0, nY0);
105816
- size.set(nX1 - nX0, nY1 - nY0);
105817
- };
105751
+ return this._resizeToFit(x0, y0, x1, y1);
105752
+ }
105818
105753
 
105819
- Rectangle.prototype.resizeToFit = function (other) {
105820
- const x0 = other.position.x;
105821
- const y0 = other.position.y;
105822
- const y1 = other.size.y + y0;
105823
- const x1 = other.size.x + x0;
105754
+ _contains(x0, y0, x1, y1) {
105755
+ const size = this.size;
105824
105756
 
105825
- return this._resizeToFit(x0, y0, x1, y1);
105826
- };
105757
+ const _x0 = this.position.x;
105758
+ const _y0 = this.position.y;
105827
105759
 
105828
- Rectangle.prototype._contains = function (x0, y0, x1, y1) {
105829
- const size = this.size;
105760
+ const _y1 = size.y + _y0;
105761
+ const _x1 = size.x + _x0;
105830
105762
 
105831
- const _x0 = this.position.x;
105832
- const _y0 = this.position.y;
105763
+ return x0 >= _x0 && x1 <= _x1 && y0 >= _y0 && y1 <= _y1;
105764
+ }
105833
105765
 
105834
- const _y1 = size.y + _y0;
105835
- 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;
105836
105771
 
105837
- return x0 >= _x0 && x1 <= _x1 && y0 >= _y0 && y1 <= _y1;
105838
- };
105772
+ return this._contains(x0, y0, x1, y1);
105773
+ }
105839
105774
 
105840
- Rectangle.prototype.contains = function (other) {
105841
- const x0 = other.position.x;
105842
- const y0 = other.position.y;
105843
- const y1 = other.size.y + y0;
105844
- 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;
105845
105782
 
105846
- return this._contains(x0, y0, x1, y1);
105847
- };
105783
+ const x = p.x + s.x / 2;
105784
+ const y = p.y + s.y / 2;
105848
105785
 
105849
- /**
105850
- *
105851
- * @param {Vector2} result
105852
- */
105853
- Rectangle.prototype.computeCenter = function (result) {
105854
- const p = this.position;
105855
- const s = this.size;
105786
+ result.set(x, y);
105787
+ }
105856
105788
 
105857
- const x = p.x + s.x / 2;
105858
- const y = p.y + s.y / 2;
105789
+ /**
105790
+ *
105791
+ * @return {number}
105792
+ */
105793
+ computeArea() {
105794
+ return this.size.x * this.size.y;
105795
+ }
105859
105796
 
105860
- result.set(x, y);
105861
- };
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
+ }
105862
105808
 
105863
- /**
105864
- *
105865
- * @return {number}
105866
- */
105867
- Rectangle.prototype.computeArea = function () {
105868
- return this.size.x * this.size.y;
105869
- };
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
+ }
105870
105821
 
105871
105822
  /**
105872
- *
105873
- * @param {Array.<number>|Float32Array|Float64Array|Uint8Array} target
105874
- * @param {number} [targetOffset=0]
105823
+ * @readonly
105824
+ * @type {boolean}
105875
105825
  */
105876
- Rectangle.prototype.toArray = function (target, targetOffset = 0) {
105877
- target[targetOffset] = this.position.x;
105878
- target[targetOffset + 1] = this.position.y;
105879
- target[targetOffset + 2] = this.size.x;
105880
- target[targetOffset + 3] = this.size.y;
105881
- };
105882
-
105883
- Rectangle.prototype.toJSON = function () {
105884
- return {
105885
- position: this.position.toJSON(),
105886
- size: this.size.toJSON()
105887
- };
105888
- };
105889
-
105890
- Rectangle.prototype.fromJSON = function (json) {
105891
- this.position.fromJSON(json.position);
105892
- this.size.fromJSON(json.size);
105893
- };
105826
+ Rectangle.prototype.isRectangle = true;
105894
105827
 
105895
105828
  class VisualTip {
105896
105829
  /**