@woosh/meep-engine 2.121.9 → 2.121.11
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/package.json +1 -1
- package/src/core/binary/to_half_float_uint16.d.ts +1 -2
- package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
- package/src/core/binary/to_half_float_uint16.js +1 -2
- package/src/core/geom/Quaternion.d.ts.map +1 -1
- package/src/core/geom/Quaternion.js +36 -21
- package/src/core/geom/Vector2.d.ts.map +1 -1
- package/src/core/geom/Vector2.js +71 -45
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +107 -67
- package/src/core/geom/Vector4.d.ts +230 -40
- package/src/core/geom/Vector4.d.ts.map +1 -1
- package/src/core/geom/Vector4.js +24 -0
- package/src/core/geom/packing/max-rect/cutArea.d.ts.map +1 -1
- package/src/core/geom/packing/max-rect/cutArea.js +7 -8
- package/src/core/geom/packing/miniball/Miniball.d.ts +188 -11
- package/src/core/geom/packing/miniball/PointSet.d.ts +46 -3
- package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
- package/src/core/geom/vec3/v3_slerp.js +2 -0
- package/src/core/math/EPSILON.d.ts.map +1 -1
- package/src/core/math/EPSILON.js +1 -1
- package/src/engine/graphics/ecs/trail2d/Trail2D.d.ts +6 -1
- package/src/engine/graphics/ecs/trail2d/Trail2D.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.d.ts +1 -1
- package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.d.ts.map +1 -1
- package/src/generation/markers/transform/MarkerNodeTransformRotateRandom.js +1 -1
- package/editor/tools/GridPaintTool.d.ts +0 -17
- package/editor/tools/GridPaintTool.d.ts.map +0 -1
- package/editor/tools/SelectionTool.d.ts +0 -27
- package/editor/tools/SelectionTool.d.ts.map +0 -1
- package/editor/tools/TopDownCameraControlTool.d.ts +0 -13
- package/editor/tools/TopDownCameraControlTool.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to_half_float_uint16.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/to_half_float_uint16.js"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"to_half_float_uint16.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/to_half_float_uint16.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,0CAHW,MAAM,GACJ,MAAM,CA2DlB"}
|
|
@@ -2,8 +2,7 @@ const _floatView = new Float32Array(1);
|
|
|
2
2
|
const _int32View = new Int32Array(_floatView.buffer);
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Converts float32 to float16 (stored as uint16 value).
|
|
5
|
+
* Converts float32 to float16 (encoded as uint16 value).
|
|
7
6
|
* @param {number} val
|
|
8
7
|
* @returns {number}
|
|
9
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH;IAoPI;;;;;OAKG;IACH,2BAJW,OAAO,SACP,MAAM,GACJ,UAAU,CAQtB;
|
|
1
|
+
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH;IAoPI;;;;;OAKG;IACH,2BAJW,OAAO,SACP,MAAM,GACJ,UAAU,CAQtB;IA2oCD;;;;OAIG;IACH,kCAFa,UAAU,CAQtB;IAED;;;;;;;OAOG;IACH,0BALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,UAAU,CAQtB;IAED;;;;;;OAMG;IACH,6BALW,UAAU,QACV,UAAU,MACV,UAAU,aACV,MAAM,QAuBhB;IAn8CD;;;;;;;OAOG;IACH,gBANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAsChB;IA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,MAAW,MAAM,GAChB,UAAU,CAyBrB;IAED,mBAEC;IA8DL,mBA5Ke,MAAM,EAAE,WACR,MAAM,UA2KS;IAC9B,kBA/Je,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CA6JG;IAC5B,kBAhKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CA8JG;IAC5B,qBA7yBe,MAAM,KACN,MAAM,KACN,MAAM,gBA2yBe;IAQpC;;;;OAIG;IACH,uBAFU,OAAO,CAEgB;IAv4C7B;;OAEG;IACH,sDAOC;CA22CJ;;kBASS,UAAU;kBAaV,MAAM;;;mBAr/CG,4BAA4B;oBAW3B,cAAc"}
|
|
@@ -6,8 +6,6 @@ import { EPSILON } from "../math/EPSILON.js";
|
|
|
6
6
|
import { epsilonEquals } from "../math/epsilonEquals.js";
|
|
7
7
|
import { lerp } from "../math/lerp.js";
|
|
8
8
|
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
9
|
-
import { quat_decode_from_uint32 } from "./3d/quaternion/quat_decode_from_uint32.js";
|
|
10
|
-
import { quat_encode_to_uint32 } from "./3d/quaternion/quat_encode_to_uint32.js";
|
|
11
9
|
import { v3_dot } from "./vec3/v3_dot.js";
|
|
12
10
|
import { v4_length } from "./vec4/v4_length.js";
|
|
13
11
|
import Vector3 from "./Vector3.js";
|
|
@@ -537,15 +535,13 @@ export class Quaternion {
|
|
|
537
535
|
}
|
|
538
536
|
|
|
539
537
|
/**
|
|
540
|
-
*
|
|
538
|
+
* @deprecated use {@link random} instead
|
|
541
539
|
* @param {function():number} random
|
|
542
540
|
*/
|
|
543
541
|
setRandom(random) {
|
|
544
542
|
assert.isFunction(random, 'random');
|
|
545
543
|
|
|
546
|
-
this.
|
|
547
|
-
|
|
548
|
-
return this.normalize();
|
|
544
|
+
return this.random(random);
|
|
549
545
|
}
|
|
550
546
|
|
|
551
547
|
/**
|
|
@@ -879,12 +875,14 @@ export class Quaternion {
|
|
|
879
875
|
|
|
880
876
|
/**
|
|
881
877
|
* NOTE: Vectors need to be normalized
|
|
882
|
-
*
|
|
878
|
+
*
|
|
883
879
|
* @param {Vector3} from
|
|
884
880
|
* @param {Vector3} to
|
|
885
881
|
* @returns {this}
|
|
886
882
|
*/
|
|
887
883
|
fromUnitVectors(from, to) {
|
|
884
|
+
// Based on blog post: http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
|
|
885
|
+
|
|
888
886
|
assert.ok(from.isNormalized(), `from vector is not normalized, length = ${from.length()}`);
|
|
889
887
|
assert.ok(to.isNormalized(), `to vector is not normalized, length = ${to.length()}`);
|
|
890
888
|
|
|
@@ -916,14 +914,13 @@ export class Quaternion {
|
|
|
916
914
|
|
|
917
915
|
scratch_v3_a.normalize();
|
|
918
916
|
|
|
919
|
-
this.set(
|
|
917
|
+
return this.set(
|
|
920
918
|
scratch_v3_a.x,
|
|
921
919
|
scratch_v3_a.y,
|
|
922
920
|
scratch_v3_a.z,
|
|
923
921
|
0
|
|
924
922
|
);
|
|
925
923
|
|
|
926
|
-
return;
|
|
927
924
|
}
|
|
928
925
|
|
|
929
926
|
const m = Math.sqrt(2 + 2 * uv_dot);
|
|
@@ -1101,6 +1098,7 @@ export class Quaternion {
|
|
|
1101
1098
|
*/
|
|
1102
1099
|
slerpQuaternions(from, to, t) {
|
|
1103
1100
|
assert.isNumber(t, 't');
|
|
1101
|
+
assert.notNaN(t, 't');
|
|
1104
1102
|
|
|
1105
1103
|
// see https://github.com/glampert/vectormath/blob/7105ef341303fe83b3dacd6883d9333989126069/scalar/quaternion.hpp#L90
|
|
1106
1104
|
|
|
@@ -1114,10 +1112,9 @@ export class Quaternion {
|
|
|
1114
1112
|
bz = to.z,
|
|
1115
1113
|
bw = to.w;
|
|
1116
1114
|
|
|
1117
|
-
let cos_angle, scale0, scale1;
|
|
1118
1115
|
|
|
1119
|
-
// calc cosine
|
|
1120
|
-
cos_angle = ax * bx + ay * by + az * bz + aw * bw;
|
|
1116
|
+
// calc cosine ( dot product )
|
|
1117
|
+
let cos_angle = ax * bx + ay * by + az * bz + aw * bw;
|
|
1121
1118
|
|
|
1122
1119
|
// adjust signs (if necessary)
|
|
1123
1120
|
if (cos_angle < 0.0) {
|
|
@@ -1128,6 +1125,8 @@ export class Quaternion {
|
|
|
1128
1125
|
bw = -bw;
|
|
1129
1126
|
}
|
|
1130
1127
|
|
|
1128
|
+
let scale0, scale1;
|
|
1129
|
+
|
|
1131
1130
|
// calculate coefficients
|
|
1132
1131
|
if ((1.0 - cos_angle) > EPSILON) {
|
|
1133
1132
|
// standard case (slerp)
|
|
@@ -1159,19 +1158,26 @@ export class Quaternion {
|
|
|
1159
1158
|
* @see https://github.com/toji/gl-matrix/blob/master/src/gl-matrix/quat.js
|
|
1160
1159
|
* @param {Quaternion} other
|
|
1161
1160
|
* @param {number} t
|
|
1161
|
+
* @returns {this}
|
|
1162
1162
|
*/
|
|
1163
1163
|
slerp(other, t) {
|
|
1164
|
-
this.slerpQuaternions(this, other, t);
|
|
1164
|
+
return this.slerpQuaternions(this, other, t);
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
1167
|
/**
|
|
1168
1168
|
*
|
|
1169
1169
|
* @param {function(x:number,y:number,z:number,w:number)} handler
|
|
1170
|
+
* @param {*} [thisArg]
|
|
1171
|
+
* @returns {this}
|
|
1170
1172
|
*/
|
|
1171
|
-
process(handler) {
|
|
1172
|
-
handler
|
|
1173
|
+
process(handler, thisArg) {
|
|
1174
|
+
assert.isFunction(handler, 'handler');
|
|
1173
1175
|
|
|
1174
|
-
this.
|
|
1176
|
+
handler.call(thisArg, this.x, this.y, this.z, this.w);
|
|
1177
|
+
|
|
1178
|
+
this.onChanged.add(handler, thisArg);
|
|
1179
|
+
|
|
1180
|
+
return this;
|
|
1175
1181
|
}
|
|
1176
1182
|
|
|
1177
1183
|
/**
|
|
@@ -1310,7 +1316,7 @@ export class Quaternion {
|
|
|
1310
1316
|
* @param {number} value
|
|
1311
1317
|
*/
|
|
1312
1318
|
decodeFromUint32(value) {
|
|
1313
|
-
|
|
1319
|
+
throw new Error('deprecated, use `quat_decode_from_uint32` instead');
|
|
1314
1320
|
}
|
|
1315
1321
|
|
|
1316
1322
|
/**
|
|
@@ -1319,7 +1325,7 @@ export class Quaternion {
|
|
|
1319
1325
|
* @returns {number}
|
|
1320
1326
|
*/
|
|
1321
1327
|
encodeToUint32() {
|
|
1322
|
-
|
|
1328
|
+
throw new Error('deprecated, use `quat_encode_to_uint32` instead');
|
|
1323
1329
|
}
|
|
1324
1330
|
|
|
1325
1331
|
/**
|
|
@@ -1404,13 +1410,17 @@ export class Quaternion {
|
|
|
1404
1410
|
|
|
1405
1411
|
/**
|
|
1406
1412
|
* Randomly orient current quaternion
|
|
1407
|
-
* @param {function():number} [random]
|
|
1413
|
+
* @param {function():number} [random] Defaults to {@link Math.random}
|
|
1408
1414
|
* @return {Quaternion}
|
|
1409
1415
|
*/
|
|
1410
1416
|
random(random = Math.random) {
|
|
1417
|
+
assert.isFunction(random, 'random');
|
|
1418
|
+
|
|
1411
1419
|
// Based on http://planning.cs.uiuc.edu/node198.html
|
|
1412
1420
|
const u1 = random();
|
|
1413
1421
|
|
|
1422
|
+
assert.isNumber(u1, 'u1'); // validating random roll
|
|
1423
|
+
|
|
1414
1424
|
const sqrt1u1 = Math.sqrt(1 - u1);
|
|
1415
1425
|
const sqrtu1 = Math.sqrt(u1);
|
|
1416
1426
|
|
|
@@ -1468,14 +1478,19 @@ export class Quaternion {
|
|
|
1468
1478
|
* @param {Quaternion} to
|
|
1469
1479
|
* @param {number} max_delta in radians
|
|
1470
1480
|
*/
|
|
1471
|
-
static rotateTowards(
|
|
1481
|
+
static rotateTowards(
|
|
1482
|
+
result,
|
|
1483
|
+
from,
|
|
1484
|
+
to,
|
|
1485
|
+
max_delta
|
|
1486
|
+
) {
|
|
1472
1487
|
assert.isNumber(max_delta, 'max_delta');
|
|
1473
1488
|
assert.notNaN(max_delta, 'max_delta');
|
|
1474
1489
|
|
|
1475
1490
|
const angle = from.angleTo(to);
|
|
1476
1491
|
|
|
1477
1492
|
if (angle === 0) {
|
|
1478
|
-
// we're already where we need
|
|
1493
|
+
// we're already where we need to be. Also - avoid division by 0
|
|
1479
1494
|
result.copy(to);
|
|
1480
1495
|
} else {
|
|
1481
1496
|
// clamp to 1, to make sure we don't overshoot
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector2.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IACI
|
|
1
|
+
{"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector2.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IACI;;;;OAIG;IACH,gBAHW,MAAM,MACN,MAAM,EA0BhB;IAjBG;;;OAGG;IACH,GAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,GAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,oBAFU,MAAM,CAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,CAAC,CAEhB;IAGjC;;;;;OAKG;IACH,iBAJW,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,GACJ,IAAI,CAOhB;IAED;;;;OAIG;IACH,eAHW,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,QAQhB;IAED,iBAMC;IAED;;;;;OAKG;IACH,OAJW,MAAM,KACN,MAAM,GACJ,IAAI,CAuBhB;IAED;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,GACJ,IAAI,CAahB;IAED;;;;OAIG;IACH,QAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;OAIG;IACH,QAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;;OAKG;IACH,QAJW,MAAM,KACN,MAAM,GACJ,IAAI,CAIhB;IAED;;;;OAIG;IACH,WAHW,OAAO,GACL,IAAI,CAIhB;IAED;;;;;OAKG;IACH,cAJW,OAAO,KACP,OAAO,GACL,IAAI,CAIh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ACJ;;mBAIS,OAAO;qBAMP,OAAO;qBAMP,OAAO;sBAMP,OAAO;qBAMP,OAAO;oBAKP,OAAO;;yBAsBP,MAAM;;;mBAttBG,4BAA4B;4BAQnB,uBAAuB"}
|
package/src/core/geom/Vector2.js
CHANGED
|
@@ -21,7 +21,6 @@ export class Vector2 {
|
|
|
21
21
|
*
|
|
22
22
|
* @param {number} [x=0]
|
|
23
23
|
* @param {number} [y=0]
|
|
24
|
-
* @constructor
|
|
25
24
|
*/
|
|
26
25
|
constructor(x = 0, y = 0) {
|
|
27
26
|
assert.isNumber(x, 'x');
|
|
@@ -42,16 +41,21 @@ export class Vector2 {
|
|
|
42
41
|
*/
|
|
43
42
|
this.y = y;
|
|
44
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @readonly
|
|
46
|
+
* @type {Signal<number,number,number,number>}
|
|
47
|
+
*/
|
|
45
48
|
this.onChanged = new Signal();
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
*
|
|
50
53
|
* @param {number[]|Float32Array} array
|
|
51
|
-
* @param {number} offset
|
|
54
|
+
* @param {number} [offset]
|
|
55
|
+
* @returns {this}
|
|
52
56
|
*/
|
|
53
57
|
fromArray(array, offset = 0) {
|
|
54
|
-
this.set(
|
|
58
|
+
return this.set(
|
|
55
59
|
array[offset],
|
|
56
60
|
array[offset + 1]
|
|
57
61
|
);
|
|
@@ -60,9 +64,12 @@ export class Vector2 {
|
|
|
60
64
|
/**
|
|
61
65
|
*
|
|
62
66
|
* @param {number[]|Float32Array} array
|
|
63
|
-
* @param {number} offset
|
|
67
|
+
* @param {number} [offset]
|
|
64
68
|
*/
|
|
65
69
|
toArray(array, offset = 0) {
|
|
70
|
+
assert.isArrayLike(array, 'array');
|
|
71
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
72
|
+
|
|
66
73
|
array[offset] = this.x;
|
|
67
74
|
array[offset + 1] = this.y;
|
|
68
75
|
}
|
|
@@ -79,7 +86,7 @@ export class Vector2 {
|
|
|
79
86
|
*
|
|
80
87
|
* @param {number} x
|
|
81
88
|
* @param {number} y
|
|
82
|
-
* @returns {
|
|
89
|
+
* @returns {this}
|
|
83
90
|
*/
|
|
84
91
|
set(x, y) {
|
|
85
92
|
assert.isNumber(x, 'x');
|
|
@@ -98,7 +105,9 @@ export class Vector2 {
|
|
|
98
105
|
if (this.onChanged.hasHandlers()) {
|
|
99
106
|
this.onChanged.send4(x, y, oldX, oldY);
|
|
100
107
|
}
|
|
108
|
+
|
|
101
109
|
}
|
|
110
|
+
|
|
102
111
|
return this;
|
|
103
112
|
}
|
|
104
113
|
|
|
@@ -106,6 +115,7 @@ export class Vector2 {
|
|
|
106
115
|
*
|
|
107
116
|
* @param {number} x
|
|
108
117
|
* @param {number} y
|
|
118
|
+
* @returns {this}
|
|
109
119
|
*/
|
|
110
120
|
setSilent(x, y) {
|
|
111
121
|
assert.isNumber(x, 'x');
|
|
@@ -117,12 +127,13 @@ export class Vector2 {
|
|
|
117
127
|
this.x = x;
|
|
118
128
|
this.y = y;
|
|
119
129
|
|
|
130
|
+
return this;
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
/**
|
|
123
134
|
*
|
|
124
135
|
* @param {number} x
|
|
125
|
-
* @returns {
|
|
136
|
+
* @returns {this}
|
|
126
137
|
*/
|
|
127
138
|
setX(x) {
|
|
128
139
|
return this.set(x, this.y);
|
|
@@ -131,7 +142,7 @@ export class Vector2 {
|
|
|
131
142
|
/**
|
|
132
143
|
*
|
|
133
144
|
* @param {number} y
|
|
134
|
-
* @returns {
|
|
145
|
+
* @returns {this}
|
|
135
146
|
*/
|
|
136
147
|
setY(y) {
|
|
137
148
|
return this.set(this.x, y);
|
|
@@ -141,7 +152,7 @@ export class Vector2 {
|
|
|
141
152
|
*
|
|
142
153
|
* @param {number} x
|
|
143
154
|
* @param {number} y
|
|
144
|
-
* @returns {
|
|
155
|
+
* @returns {this}
|
|
145
156
|
*/
|
|
146
157
|
_sub(x, y) {
|
|
147
158
|
return this.set(this.x - x, this.y - y);
|
|
@@ -150,7 +161,7 @@ export class Vector2 {
|
|
|
150
161
|
/**
|
|
151
162
|
*
|
|
152
163
|
* @param {Vector2} other
|
|
153
|
-
* @returns {
|
|
164
|
+
* @returns {this}
|
|
154
165
|
*/
|
|
155
166
|
sub(other) {
|
|
156
167
|
return this._sub(other.x, other.y);
|
|
@@ -160,14 +171,15 @@ export class Vector2 {
|
|
|
160
171
|
*
|
|
161
172
|
* @param {Vector2} a
|
|
162
173
|
* @param {Vector2} b
|
|
174
|
+
* @returns {this}
|
|
163
175
|
*/
|
|
164
176
|
subVectors(a, b) {
|
|
165
|
-
this.set(a.x - b.x, a.y - b.y);
|
|
177
|
+
return this.set(a.x - b.x, a.y - b.y);
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
/**
|
|
169
181
|
* performs Math.floor operation on x and y
|
|
170
|
-
* @returns {
|
|
182
|
+
* @returns {this}
|
|
171
183
|
*/
|
|
172
184
|
floor() {
|
|
173
185
|
return this.set(Math.floor(this.x), Math.floor(this.y));
|
|
@@ -175,7 +187,7 @@ export class Vector2 {
|
|
|
175
187
|
|
|
176
188
|
/**
|
|
177
189
|
* performs Math.ceil operation on x and y
|
|
178
|
-
* @returns {
|
|
190
|
+
* @returns {this}
|
|
179
191
|
*/
|
|
180
192
|
ceil() {
|
|
181
193
|
return this.set(Math.ceil(this.x), Math.ceil(this.y));
|
|
@@ -183,16 +195,17 @@ export class Vector2 {
|
|
|
183
195
|
|
|
184
196
|
/**
|
|
185
197
|
* Round both components to nearest integer
|
|
198
|
+
* @returns {this}
|
|
186
199
|
*/
|
|
187
200
|
round() {
|
|
188
201
|
const x = Math.round(this.x);
|
|
189
202
|
const y = Math.round(this.y);
|
|
190
|
-
this.set(x, y);
|
|
203
|
+
return this.set(x, y);
|
|
191
204
|
}
|
|
192
205
|
|
|
193
206
|
/**
|
|
194
207
|
* performs Math.abs operation on x and y
|
|
195
|
-
* @returns {
|
|
208
|
+
* @returns {this}
|
|
196
209
|
*/
|
|
197
210
|
abs() {
|
|
198
211
|
return this.set(Math.abs(this.x), Math.abs(this.y));
|
|
@@ -202,7 +215,7 @@ export class Vector2 {
|
|
|
202
215
|
*
|
|
203
216
|
* @param {number} x
|
|
204
217
|
* @param {number} y
|
|
205
|
-
* @returns {
|
|
218
|
+
* @returns {this}
|
|
206
219
|
*/
|
|
207
220
|
_mod(x, y) {
|
|
208
221
|
return this.set(this.x % x, this.y % y);
|
|
@@ -211,7 +224,7 @@ export class Vector2 {
|
|
|
211
224
|
/**
|
|
212
225
|
*
|
|
213
226
|
* @param {Vector2} other
|
|
214
|
-
* @returns {
|
|
227
|
+
* @returns {this}
|
|
215
228
|
*/
|
|
216
229
|
mod(other) {
|
|
217
230
|
return this._mod(other.x, other.y);
|
|
@@ -220,7 +233,7 @@ export class Vector2 {
|
|
|
220
233
|
/**
|
|
221
234
|
*
|
|
222
235
|
* @param {Vector2} other
|
|
223
|
-
* @returns {
|
|
236
|
+
* @returns {this}
|
|
224
237
|
*/
|
|
225
238
|
divide(other) {
|
|
226
239
|
return this.set(this.x / other.x, this.y / other.y);
|
|
@@ -229,7 +242,7 @@ export class Vector2 {
|
|
|
229
242
|
/**
|
|
230
243
|
*
|
|
231
244
|
* @param {Vector2} other
|
|
232
|
-
* @returns {
|
|
245
|
+
* @returns {this}
|
|
233
246
|
*/
|
|
234
247
|
multiply(other) {
|
|
235
248
|
return this._multiply(other.x, other.y);
|
|
@@ -239,20 +252,21 @@ export class Vector2 {
|
|
|
239
252
|
*
|
|
240
253
|
* @param {number} x
|
|
241
254
|
* @param {number} y
|
|
242
|
-
* @returns {
|
|
255
|
+
* @returns {this}
|
|
243
256
|
*/
|
|
244
257
|
_multiply(x, y) {
|
|
245
258
|
return this.set(this.x * x, this.y * y);
|
|
246
259
|
}
|
|
247
260
|
|
|
248
261
|
/**
|
|
249
|
-
*
|
|
262
|
+
* Component-size MAX operator
|
|
250
263
|
* @param {Vector2} other
|
|
251
|
-
* @returns {
|
|
264
|
+
* @returns {this}
|
|
252
265
|
*/
|
|
253
266
|
max(other) {
|
|
254
267
|
const x = max2(this.x, other.x);
|
|
255
268
|
const y = max2(this.y, other.y);
|
|
269
|
+
|
|
256
270
|
return this.set(x, y);
|
|
257
271
|
}
|
|
258
272
|
|
|
@@ -268,7 +282,7 @@ export class Vector2 {
|
|
|
268
282
|
/**
|
|
269
283
|
*
|
|
270
284
|
* @param {Vector2} other
|
|
271
|
-
* @returns {
|
|
285
|
+
* @returns {this}
|
|
272
286
|
*/
|
|
273
287
|
copy(other) {
|
|
274
288
|
return this.set(other.x, other.y);
|
|
@@ -284,7 +298,7 @@ export class Vector2 {
|
|
|
284
298
|
|
|
285
299
|
/**
|
|
286
300
|
*
|
|
287
|
-
* @returns {
|
|
301
|
+
* @returns {this}
|
|
288
302
|
*/
|
|
289
303
|
negate() {
|
|
290
304
|
return this.set(-this.x, -this.y);
|
|
@@ -294,7 +308,7 @@ export class Vector2 {
|
|
|
294
308
|
*
|
|
295
309
|
* @param {number} x
|
|
296
310
|
* @param {number} y
|
|
297
|
-
* @returns {
|
|
311
|
+
* @returns {this}
|
|
298
312
|
*/
|
|
299
313
|
_add(x, y) {
|
|
300
314
|
return this.set(this.x + x, this.y + y);
|
|
@@ -303,7 +317,7 @@ export class Vector2 {
|
|
|
303
317
|
/**
|
|
304
318
|
*
|
|
305
319
|
* @param {Vector2} other
|
|
306
|
-
* @returns {
|
|
320
|
+
* @returns {this}
|
|
307
321
|
*/
|
|
308
322
|
add(other) {
|
|
309
323
|
return this._add(other.x, other.y);
|
|
@@ -311,7 +325,8 @@ export class Vector2 {
|
|
|
311
325
|
|
|
312
326
|
/**
|
|
313
327
|
*
|
|
314
|
-
* @param {
|
|
328
|
+
* @param {number} val
|
|
329
|
+
* @returns {this}
|
|
315
330
|
*/
|
|
316
331
|
addScalar(val) {
|
|
317
332
|
return this._add(val, val);
|
|
@@ -320,23 +335,25 @@ export class Vector2 {
|
|
|
320
335
|
/**
|
|
321
336
|
*
|
|
322
337
|
* @param {number} val
|
|
338
|
+
* @returns {this}
|
|
323
339
|
*/
|
|
324
340
|
setScalar(val) {
|
|
325
|
-
this.set(val, val);
|
|
341
|
+
return this.set(val, val);
|
|
326
342
|
}
|
|
327
343
|
|
|
328
344
|
/**
|
|
329
345
|
*
|
|
330
346
|
* @param {number} val
|
|
347
|
+
* @returns {this}
|
|
331
348
|
*/
|
|
332
349
|
divideScalar(val) {
|
|
333
|
-
this.multiplyScalar(1 / val);
|
|
350
|
+
return this.multiplyScalar(1 / val);
|
|
334
351
|
}
|
|
335
352
|
|
|
336
353
|
/**
|
|
337
354
|
*
|
|
338
|
-
* @param {
|
|
339
|
-
* @returns {
|
|
355
|
+
* @param {number} val
|
|
356
|
+
* @returns {this}
|
|
340
357
|
*/
|
|
341
358
|
multiplyScalar(val) {
|
|
342
359
|
assert.isNumber(val, 'val');
|
|
@@ -408,10 +425,11 @@ export class Vector2 {
|
|
|
408
425
|
|
|
409
426
|
/**
|
|
410
427
|
*
|
|
411
|
-
* @param {
|
|
412
|
-
* @param {
|
|
413
|
-
* @param {
|
|
414
|
-
* @param {
|
|
428
|
+
* @param {number} minX
|
|
429
|
+
* @param {number} minY
|
|
430
|
+
* @param {number} maxX
|
|
431
|
+
* @param {number} maxY
|
|
432
|
+
* @returns {this}
|
|
415
433
|
*/
|
|
416
434
|
clamp(minX, minY, maxX, maxY) {
|
|
417
435
|
const x = clamp(this.x, minX, maxX);
|
|
@@ -421,8 +439,9 @@ export class Vector2 {
|
|
|
421
439
|
|
|
422
440
|
/**
|
|
423
441
|
*
|
|
424
|
-
* @param {
|
|
425
|
-
* @param {
|
|
442
|
+
* @param {number} lowX
|
|
443
|
+
* @param {number} lowY
|
|
444
|
+
* @returns {this}
|
|
426
445
|
*/
|
|
427
446
|
clampLow(lowX, lowY) {
|
|
428
447
|
const x = max2(this.x, lowX);
|
|
@@ -432,8 +451,9 @@ export class Vector2 {
|
|
|
432
451
|
|
|
433
452
|
/**
|
|
434
453
|
*
|
|
435
|
-
* @param {
|
|
436
|
-
* @param {
|
|
454
|
+
* @param {number} highX
|
|
455
|
+
* @param {number} highY
|
|
456
|
+
* @returns {this}
|
|
437
457
|
*/
|
|
438
458
|
clampHigh(highX, highY) {
|
|
439
459
|
const x = min2(this.x, highX);
|
|
@@ -467,17 +487,19 @@ export class Vector2 {
|
|
|
467
487
|
* @param {Vector2} a
|
|
468
488
|
* @param {Vector2} b
|
|
469
489
|
* @param {number} fraction
|
|
490
|
+
* @returns {this}
|
|
470
491
|
*/
|
|
471
492
|
lerpVectors(a, b, fraction) {
|
|
472
493
|
const x = lerp(a.x, b.x, fraction);
|
|
473
494
|
const y = lerp(a.y, b.y, fraction);
|
|
474
495
|
|
|
475
|
-
this.set(x, y);
|
|
496
|
+
return this.set(x, y);
|
|
476
497
|
}
|
|
477
498
|
|
|
478
499
|
/**
|
|
479
500
|
*
|
|
480
501
|
* @param {number[]} matrix3
|
|
502
|
+
* @returns {this}
|
|
481
503
|
*/
|
|
482
504
|
applyMatrix3(matrix3) {
|
|
483
505
|
const x = this.x;
|
|
@@ -486,7 +508,7 @@ export class Vector2 {
|
|
|
486
508
|
const _x = matrix3[0] * x + matrix3[3] * y + matrix3[6];
|
|
487
509
|
const _y = matrix3[1] * x + matrix3[4] * y + matrix3[7];
|
|
488
510
|
|
|
489
|
-
this.set(_x, _y);
|
|
511
|
+
return this.set(_x, _y);
|
|
490
512
|
}
|
|
491
513
|
|
|
492
514
|
/**
|
|
@@ -529,18 +551,19 @@ export class Vector2 {
|
|
|
529
551
|
|
|
530
552
|
/**
|
|
531
553
|
* Normalizes the vector, preserving its direction, but making magnitude equal to 1
|
|
554
|
+
* @returns {this}
|
|
532
555
|
*/
|
|
533
556
|
normalize() {
|
|
534
557
|
const l = this.length();
|
|
535
558
|
|
|
536
559
|
if (l === 0) {
|
|
537
560
|
//special case, can't normalize 0 length vector
|
|
538
|
-
return;
|
|
561
|
+
return this;
|
|
539
562
|
}
|
|
540
563
|
|
|
541
564
|
const m = 1 / l;
|
|
542
565
|
|
|
543
|
-
this.multiplyScalar(m);
|
|
566
|
+
return this.multiplyScalar(m);
|
|
544
567
|
}
|
|
545
568
|
|
|
546
569
|
|
|
@@ -558,6 +581,7 @@ export class Vector2 {
|
|
|
558
581
|
/**
|
|
559
582
|
* Rotation is counter-clockwise
|
|
560
583
|
* @param {number} angle in radians
|
|
584
|
+
* @returns {this}
|
|
561
585
|
*/
|
|
562
586
|
rotate(angle) {
|
|
563
587
|
const sin = Math.sin(angle);
|
|
@@ -569,14 +593,14 @@ export class Vector2 {
|
|
|
569
593
|
const x = _x * cos - _y * sin
|
|
570
594
|
const y = _x * sin + _y * cos;
|
|
571
595
|
|
|
572
|
-
this.set(x, y);
|
|
596
|
+
return this.set(x, y);
|
|
573
597
|
}
|
|
574
598
|
|
|
575
599
|
/**
|
|
576
600
|
*
|
|
577
601
|
* @param {function} processor
|
|
578
602
|
* @param {*} [thisArg]
|
|
579
|
-
* @returns {
|
|
603
|
+
* @returns {this}
|
|
580
604
|
*/
|
|
581
605
|
process(processor, thisArg) {
|
|
582
606
|
processor.call(thisArg, this.x, this.y);
|
|
@@ -596,7 +620,9 @@ export class Vector2 {
|
|
|
596
620
|
* @returns {boolean}
|
|
597
621
|
*/
|
|
598
622
|
equals(other) {
|
|
599
|
-
return this.x === other.x
|
|
623
|
+
return this.x === other.x
|
|
624
|
+
&& this.y === other.y
|
|
625
|
+
;
|
|
600
626
|
}
|
|
601
627
|
|
|
602
628
|
/**
|