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