@vertexvis/geometry 1.0.2-canary.2 → 1.0.2-canary.20
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/dist/bundle.cjs +428 -449
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.js +428 -449
- package/dist/bundle.js.map +1 -1
- package/dist/cdn/bundle.js +428 -449
- package/dist/cdn/bundle.js.map +1 -1
- package/dist/cdn/bundle.min.js +1 -1
- package/dist/cdn/bundle.min.js.map +1 -1
- package/dist/euler.d.ts +1 -1
- package/dist/matrix4.d.ts +33 -25
- package/dist/vector3.d.ts +22 -1
- package/package.json +6 -6
package/dist/bundle.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Clamps the given value between `min` and `max`.
|
|
7
5
|
*
|
|
@@ -31,24 +29,22 @@ function lerp$2(a, b, t) {
|
|
|
31
29
|
/**
|
|
32
30
|
* Returns a new `Point` with the given horizontal and vertical position.
|
|
33
31
|
*/
|
|
34
|
-
function create$d(x, y) {
|
|
35
|
-
|
|
36
|
-
if (y === void 0) { y = 0; }
|
|
37
|
-
return { x: x, y: y };
|
|
32
|
+
function create$d(x = 0, y = 0) {
|
|
33
|
+
return { x, y };
|
|
38
34
|
}
|
|
39
35
|
/**
|
|
40
36
|
* Converts a polar coordinate (length and angle) into a Cartesian coordinate.
|
|
41
37
|
*/
|
|
42
38
|
function polar(length, radians) {
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const x = Math.cos(radians) * length;
|
|
40
|
+
const y = Math.sin(radians) * length;
|
|
45
41
|
return create$d(x, y);
|
|
46
42
|
}
|
|
47
43
|
/**
|
|
48
44
|
* Returns the distance between two points.
|
|
49
45
|
*/
|
|
50
46
|
function distance$2(a, b) {
|
|
51
|
-
|
|
47
|
+
const delta = subtract$1(a, b);
|
|
52
48
|
return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
@@ -120,7 +116,7 @@ function magnitude$2(pt) {
|
|
|
120
116
|
* Transforms a vector into the corresponding normal (unit) vector.
|
|
121
117
|
*/
|
|
122
118
|
function normalizeVector(pt) {
|
|
123
|
-
|
|
119
|
+
const magnitudeOfPoint = magnitude$2(pt);
|
|
124
120
|
if (magnitudeOfPoint === 0) {
|
|
125
121
|
return create$d(0, 0);
|
|
126
122
|
}
|
|
@@ -138,19 +134,19 @@ function normalDirectionVector(ptA, ptB) {
|
|
|
138
134
|
* Returns a vector orthogonal to the vector between the two given points.
|
|
139
135
|
*/
|
|
140
136
|
function orthogonalVector(ptA, ptB) {
|
|
141
|
-
|
|
137
|
+
const unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
|
|
142
138
|
// Handle vectors that are parallel to the x or y axis
|
|
143
139
|
if (unitVectorBetweenPoints.x === 0 || unitVectorBetweenPoints.y === 0) {
|
|
144
140
|
return create$d(-1 * unitVectorBetweenPoints.y, unitVectorBetweenPoints.x);
|
|
145
141
|
}
|
|
146
142
|
if (Math.abs(unitVectorBetweenPoints.x) > Math.abs(unitVectorBetweenPoints.y)) {
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
const vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
|
|
144
|
+
const vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
|
|
149
145
|
return normalizeVector(create$d(vectorXValue, vectorYValue));
|
|
150
146
|
}
|
|
151
147
|
else {
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
|
|
149
|
+
const vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
|
|
154
150
|
return normalizeVector(create$d(vectorXValue, vectorYValue));
|
|
155
151
|
}
|
|
156
152
|
}
|
|
@@ -161,13 +157,13 @@ function orthogonalVector(ptA, ptB) {
|
|
|
161
157
|
* @returns A parsed Point.
|
|
162
158
|
*/
|
|
163
159
|
function fromJson$5(json) {
|
|
164
|
-
|
|
160
|
+
const obj = JSON.parse(json);
|
|
165
161
|
if (Array.isArray(obj)) {
|
|
166
|
-
|
|
162
|
+
const [x, y] = obj;
|
|
167
163
|
return create$d(x, y);
|
|
168
164
|
}
|
|
169
165
|
else {
|
|
170
|
-
|
|
166
|
+
const { x, y } = obj;
|
|
171
167
|
return create$d(x, y);
|
|
172
168
|
}
|
|
173
169
|
}
|
|
@@ -199,8 +195,8 @@ var point = /*#__PURE__*/Object.freeze({
|
|
|
199
195
|
* @returns An angle in radians.
|
|
200
196
|
*/
|
|
201
197
|
function fromPoints$1(a, b) {
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
const delta = subtract$1(b, a);
|
|
199
|
+
const theta = Math.atan2(delta.y, delta.x);
|
|
204
200
|
return theta;
|
|
205
201
|
}
|
|
206
202
|
/**
|
|
@@ -212,8 +208,8 @@ function fromPoints$1(a, b) {
|
|
|
212
208
|
* @deprecated Use {@link fromPoints} instead.
|
|
213
209
|
*/
|
|
214
210
|
function fromPointsInDegrees(a, b) {
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
const delta = subtract$1(b, a);
|
|
212
|
+
const theta = Math.atan2(delta.y, delta.x);
|
|
217
213
|
return normalize$2(toDegrees(theta) - 270);
|
|
218
214
|
}
|
|
219
215
|
/**
|
|
@@ -259,10 +255,10 @@ function fromValues(
|
|
|
259
255
|
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
|
260
256
|
/* eslint-disable prettier/prettier */
|
|
261
257
|
return [
|
|
262
|
-
m11,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
258
|
+
m11, m12, m13, m14,
|
|
259
|
+
m21, m22, m23, m24,
|
|
260
|
+
m31, m32, m33, m34,
|
|
261
|
+
m41, m42, m43, m44,
|
|
266
262
|
];
|
|
267
263
|
/* eslint-enable prettier/prettier */
|
|
268
264
|
}
|
|
@@ -300,7 +296,7 @@ function makeZero() {
|
|
|
300
296
|
* @returns A translation matrix.
|
|
301
297
|
*/
|
|
302
298
|
function makeTranslation(translation) {
|
|
303
|
-
|
|
299
|
+
const { x, y, z } = translation;
|
|
304
300
|
/* eslint-disable prettier/prettier */
|
|
305
301
|
return [
|
|
306
302
|
1, 0, 0, 0,
|
|
@@ -325,16 +321,16 @@ function makeTranslation(translation) {
|
|
|
325
321
|
* @returns A rotation matrix.
|
|
326
322
|
*/
|
|
327
323
|
function makeRotation(rotation) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
324
|
+
const { x, y, z, w } = rotation;
|
|
325
|
+
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
326
|
+
const xx = x * x2, xy = x * y2, xz = x * z2;
|
|
327
|
+
const yy = y * y2, yz = y * z2, zz = z * z2;
|
|
328
|
+
const wx = w * x2, wy = w * y2, wz = w * z2;
|
|
333
329
|
/* eslint-disable prettier/prettier */
|
|
334
330
|
return [
|
|
335
|
-
1 - (yy + zz), xy
|
|
336
|
-
xy
|
|
337
|
-
xz
|
|
331
|
+
1 - (yy + zz), xy - wz, xz + wy, 0,
|
|
332
|
+
xy + wz, 1 - (xx + zz), yz - wx, 0,
|
|
333
|
+
xz - wy, yz + wx, 1 - (xx + yy), 0,
|
|
338
334
|
0, 0, 0, 1
|
|
339
335
|
];
|
|
340
336
|
/* eslint-enable prettier/prettier */
|
|
@@ -353,7 +349,7 @@ function makeRotation(rotation) {
|
|
|
353
349
|
* @returns A scale matrix.
|
|
354
350
|
*/
|
|
355
351
|
function makeScale(scale) {
|
|
356
|
-
|
|
352
|
+
const { x, y, z } = scale;
|
|
357
353
|
/* eslint-disable prettier/prettier */
|
|
358
354
|
return [
|
|
359
355
|
x, 0, 0, 0,
|
|
@@ -364,33 +360,33 @@ function makeScale(scale) {
|
|
|
364
360
|
/* eslint-enable prettier/prettier */
|
|
365
361
|
}
|
|
366
362
|
/**
|
|
367
|
-
* Creates a matrix that has translation, rotation and scale applied to it.
|
|
363
|
+
* Creates a matrix that has translation, rotation, and scale applied to it.
|
|
368
364
|
*
|
|
369
365
|
* @param translation The translation applied to the matrix.
|
|
370
366
|
* @param rotation The rotation applied to the matrix.
|
|
371
367
|
* @param scale The scale applied to the matrix.
|
|
372
|
-
* @returns A transformed matrix.
|
|
368
|
+
* @returns A transformed matrix in column-major form.
|
|
373
369
|
*/
|
|
374
370
|
function makeTRS(translation, rotation, scale) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return multiply$2(multiply$2(
|
|
371
|
+
const t = makeTranslation(translation);
|
|
372
|
+
const r = transpose(makeRotation(rotation));
|
|
373
|
+
const s = makeScale(scale);
|
|
374
|
+
return multiply$2(s, multiply$2(r, t));
|
|
379
375
|
}
|
|
380
376
|
/**
|
|
381
377
|
* Returns a matrix that has the basis components (upper left 3x3 matrix) set to
|
|
382
378
|
* the following x, y, and z axis.
|
|
383
379
|
*
|
|
384
380
|
* ```
|
|
385
|
-
* x.x y.
|
|
386
|
-
* x.y y.
|
|
387
|
-
* x.
|
|
381
|
+
* x.x x.y x.z 0
|
|
382
|
+
* y.x y.y y.z 0
|
|
383
|
+
* z.x z.y z.z 0
|
|
388
384
|
* 0 0 0 0
|
|
389
385
|
* ```
|
|
390
386
|
*
|
|
391
|
-
* @param x The x
|
|
392
|
-
* @param y The y
|
|
393
|
-
* @param z The z
|
|
387
|
+
* @param x The x-axis to set.
|
|
388
|
+
* @param y The y-axis to set.
|
|
389
|
+
* @param z The z-axis to set.
|
|
394
390
|
* @returns A matrix with its basis components populated.
|
|
395
391
|
*/
|
|
396
392
|
function makeBasis(x, y, z) {
|
|
@@ -403,30 +399,6 @@ function makeBasis(x, y, z) {
|
|
|
403
399
|
];
|
|
404
400
|
/* eslint-enable prettier/prettier */
|
|
405
401
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Creates a rotation matrix that is rotated around a given axis by the given
|
|
408
|
-
* angle.
|
|
409
|
-
*
|
|
410
|
-
* @param axis The axis of rotation.
|
|
411
|
-
* @param radians The angle of rotation.
|
|
412
|
-
* @returns A rotation matrix.
|
|
413
|
-
*/
|
|
414
|
-
function makeRotationAxis(axis, radians) {
|
|
415
|
-
var c = Math.cos(radians);
|
|
416
|
-
var s = Math.sin(radians);
|
|
417
|
-
var t = 1 - c;
|
|
418
|
-
var x = axis.x, y = axis.y, z = axis.z;
|
|
419
|
-
var tx = t * x;
|
|
420
|
-
var ty = t * y;
|
|
421
|
-
/* eslint-disable prettier/prettier */
|
|
422
|
-
return [
|
|
423
|
-
tx * x + c, tx * y + s * z, tx * z - s * y, 0,
|
|
424
|
-
tx * y - s * z, ty * y + c, ty * z + s * x, 0,
|
|
425
|
-
tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
|
|
426
|
-
0, 0, 0, 1
|
|
427
|
-
];
|
|
428
|
-
/* eslint-enable prettier/prettier */
|
|
429
|
-
}
|
|
430
402
|
/**
|
|
431
403
|
* Creates a matrix used for [perspective
|
|
432
404
|
* projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
|
|
@@ -446,12 +418,12 @@ function makeRotationAxis(axis, radians) {
|
|
|
446
418
|
* @returns A matrix representing a view frustum.
|
|
447
419
|
*/
|
|
448
420
|
function makeFrustum(left, right, top, bottom, near, far) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
421
|
+
const x = (2 * near) / (right - left);
|
|
422
|
+
const y = (2 * near) / (top - bottom);
|
|
423
|
+
const a = (right + left) / (right - left);
|
|
424
|
+
const b = (top + bottom) / (top - bottom);
|
|
425
|
+
const c = -(far + near) / (far - near);
|
|
426
|
+
const d = (-2 * far * near) / (far - near);
|
|
455
427
|
/* eslint-disable prettier/prettier */
|
|
456
428
|
return [
|
|
457
429
|
x, 0, 0, 0,
|
|
@@ -480,12 +452,12 @@ function makeFrustum(left, right, top, bottom, near, far) {
|
|
|
480
452
|
* @returns A matrix.
|
|
481
453
|
*/
|
|
482
454
|
function makePerspective(near, far, fovY, aspect) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
455
|
+
const ymax = near * Math.tan(toRadians(fovY / 2.0));
|
|
456
|
+
const xmax = ymax * aspect;
|
|
457
|
+
const left = -xmax;
|
|
458
|
+
const right = xmax;
|
|
459
|
+
const top = ymax;
|
|
460
|
+
const bottom = -ymax;
|
|
489
461
|
return makeFrustum(left, right, top, bottom, near, far);
|
|
490
462
|
}
|
|
491
463
|
/**
|
|
@@ -506,12 +478,12 @@ function makePerspective(near, far, fovY, aspect) {
|
|
|
506
478
|
* @returns A matrix.
|
|
507
479
|
*/
|
|
508
480
|
function makeOrthographic(left, right, bottom, top, near, far) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
481
|
+
const w = 1.0 / (right - left);
|
|
482
|
+
const h = 1.0 / (top - bottom);
|
|
483
|
+
const d = 1.0 / (far - near);
|
|
484
|
+
const x = (right + left) * w;
|
|
485
|
+
const y = (top + bottom) * h;
|
|
486
|
+
const z = (far + near) * d;
|
|
515
487
|
/* eslint-disable prettier/prettier */
|
|
516
488
|
return [
|
|
517
489
|
2 * w, 0, 0, -x,
|
|
@@ -541,12 +513,12 @@ function makeOrthographic(left, right, bottom, top, near, far) {
|
|
|
541
513
|
* @returns A matrix.
|
|
542
514
|
*/
|
|
543
515
|
function makeLookAtView(position, lookAt, up) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
516
|
+
const z = normalize(subtract(position, lookAt));
|
|
517
|
+
const x = normalize(cross(up, z));
|
|
518
|
+
const y = cross(z, x);
|
|
519
|
+
const dotX = -dot$1(x, position);
|
|
520
|
+
const dotY = -dot$1(y, position);
|
|
521
|
+
const dotZ = -dot$1(z, position);
|
|
550
522
|
/* eslint-disable prettier/prettier */
|
|
551
523
|
return [
|
|
552
524
|
x.x, y.x, z.x, 0,
|
|
@@ -570,9 +542,9 @@ function makeLookAtView(position, lookAt, up) {
|
|
|
570
542
|
* @returns A matrix.
|
|
571
543
|
*/
|
|
572
544
|
function makeLookAt(position, lookAt, up) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
545
|
+
const z = normalize(subtract(position, lookAt));
|
|
546
|
+
const x = normalize(cross(up, z));
|
|
547
|
+
const y = cross(z, x);
|
|
576
548
|
/* eslint-disable prettier/prettier */
|
|
577
549
|
return [
|
|
578
550
|
x.x, x.y, x.z, 0,
|
|
@@ -587,45 +559,45 @@ function makeLookAt(position, lookAt, up) {
|
|
|
587
559
|
* zero, then a zero matrix is returned.
|
|
588
560
|
*/
|
|
589
561
|
function invert(matrix) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
562
|
+
const a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
|
|
563
|
+
const a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
|
|
564
|
+
const a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
|
|
565
|
+
const a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
|
|
566
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
567
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
568
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
569
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
570
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
571
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
572
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
573
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
574
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
575
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
576
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
577
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
606
578
|
// Calculate the determinant
|
|
607
|
-
|
|
579
|
+
const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
608
580
|
if (!det) {
|
|
609
581
|
return makeZero();
|
|
610
582
|
}
|
|
611
|
-
|
|
583
|
+
const oneOverDet = 1 / det;
|
|
612
584
|
return [
|
|
613
|
-
(a11 * b11 - a12 * b10 + a13 * b09) *
|
|
614
|
-
(a02 * b10 - a01 * b11 - a03 * b09) *
|
|
615
|
-
(a31 * b05 - a32 * b04 + a33 * b03) *
|
|
616
|
-
(a22 * b04 - a21 * b05 - a23 * b03) *
|
|
617
|
-
(a12 * b08 - a10 * b11 - a13 * b07) *
|
|
618
|
-
(a00 * b11 - a02 * b08 + a03 * b07) *
|
|
619
|
-
(a32 * b02 - a30 * b05 - a33 * b01) *
|
|
620
|
-
(a20 * b05 - a22 * b02 + a23 * b01) *
|
|
621
|
-
(a10 * b10 - a11 * b08 + a13 * b06) *
|
|
622
|
-
(a01 * b08 - a00 * b10 - a03 * b06) *
|
|
623
|
-
(a30 * b04 - a31 * b02 + a33 * b00) *
|
|
624
|
-
(a21 * b02 - a20 * b04 - a23 * b00) *
|
|
625
|
-
(a11 * b07 - a10 * b09 - a12 * b06) *
|
|
626
|
-
(a00 * b09 - a01 * b07 + a02 * b06) *
|
|
627
|
-
(a31 * b01 - a30 * b03 - a32 * b00) *
|
|
628
|
-
(a20 * b03 - a21 * b01 + a22 * b00) *
|
|
585
|
+
(a11 * b11 - a12 * b10 + a13 * b09) * oneOverDet,
|
|
586
|
+
(a02 * b10 - a01 * b11 - a03 * b09) * oneOverDet,
|
|
587
|
+
(a31 * b05 - a32 * b04 + a33 * b03) * oneOverDet,
|
|
588
|
+
(a22 * b04 - a21 * b05 - a23 * b03) * oneOverDet,
|
|
589
|
+
(a12 * b08 - a10 * b11 - a13 * b07) * oneOverDet,
|
|
590
|
+
(a00 * b11 - a02 * b08 + a03 * b07) * oneOverDet,
|
|
591
|
+
(a32 * b02 - a30 * b05 - a33 * b01) * oneOverDet,
|
|
592
|
+
(a20 * b05 - a22 * b02 + a23 * b01) * oneOverDet,
|
|
593
|
+
(a10 * b10 - a11 * b08 + a13 * b06) * oneOverDet,
|
|
594
|
+
(a01 * b08 - a00 * b10 - a03 * b06) * oneOverDet,
|
|
595
|
+
(a30 * b04 - a31 * b02 + a33 * b00) * oneOverDet,
|
|
596
|
+
(a21 * b02 - a20 * b04 - a23 * b00) * oneOverDet,
|
|
597
|
+
(a11 * b07 - a10 * b09 - a12 * b06) * oneOverDet,
|
|
598
|
+
(a00 * b09 - a01 * b07 + a02 * b06) * oneOverDet,
|
|
599
|
+
(a31 * b01 - a30 * b03 - a32 * b00) * oneOverDet,
|
|
600
|
+
(a20 * b03 - a21 * b01 + a22 * b00) * oneOverDet,
|
|
629
601
|
];
|
|
630
602
|
}
|
|
631
603
|
/**
|
|
@@ -639,70 +611,58 @@ function invert(matrix) {
|
|
|
639
611
|
* @returns A rotation matrix.
|
|
640
612
|
*/
|
|
641
613
|
function lookAt(m, position, target, up) {
|
|
642
|
-
|
|
614
|
+
let z = subtract(position, target);
|
|
643
615
|
if (magnitudeSquared(z) === 0) {
|
|
644
|
-
z =
|
|
616
|
+
z = { ...z, z: 1 };
|
|
645
617
|
}
|
|
646
618
|
z = normalize(z);
|
|
647
|
-
|
|
619
|
+
let x = cross(up, z);
|
|
648
620
|
if (magnitudeSquared(x) === 0) {
|
|
649
621
|
if (Math.abs(up.z) === 1) {
|
|
650
|
-
z =
|
|
622
|
+
z = { ...z, x: z.x + 0.0001 };
|
|
651
623
|
}
|
|
652
624
|
else {
|
|
653
|
-
z =
|
|
625
|
+
z = { ...z, z: z.z + 0.0001 };
|
|
654
626
|
}
|
|
655
627
|
z = normalize(z);
|
|
656
628
|
x = cross(up, z);
|
|
657
629
|
}
|
|
658
630
|
x = normalize(x);
|
|
659
|
-
|
|
660
|
-
|
|
631
|
+
const y = cross(z, x);
|
|
632
|
+
const res = [...m];
|
|
661
633
|
/* eslint-disable prettier/prettier */
|
|
662
634
|
res[0] = x.x;
|
|
663
|
-
res[4] = y.x;
|
|
664
|
-
res[8] = z.x;
|
|
665
635
|
res[1] = x.y;
|
|
666
|
-
res[5] = y.y;
|
|
667
|
-
res[9] = z.y;
|
|
668
636
|
res[2] = x.z;
|
|
637
|
+
res[4] = y.x;
|
|
638
|
+
res[5] = y.y;
|
|
669
639
|
res[6] = y.z;
|
|
640
|
+
res[8] = z.x;
|
|
641
|
+
res[9] = z.y;
|
|
670
642
|
res[10] = z.z;
|
|
671
643
|
/* eslint-enable prettier/prettier */
|
|
672
644
|
return res;
|
|
673
645
|
}
|
|
674
646
|
/**
|
|
675
|
-
* Returns a post-multiplied matrix.
|
|
647
|
+
* Returns a post-multiplied matrix equal to ab.
|
|
676
648
|
*/
|
|
677
649
|
function multiply$2(a, b) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
695
|
-
mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
696
|
-
mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
697
|
-
mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
698
|
-
mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
699
|
-
mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
700
|
-
mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
701
|
-
mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
702
|
-
mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
703
|
-
mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
704
|
-
mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
705
|
-
return mat;
|
|
650
|
+
const result = makeIdentity();
|
|
651
|
+
// Consider each row i in the final matrix
|
|
652
|
+
for (let i = 0; i < 4; i++) {
|
|
653
|
+
// Consider each column j in the final matrix
|
|
654
|
+
for (let j = 0; j < 4; j++) {
|
|
655
|
+
// Calculate the value at row i and column j
|
|
656
|
+
let value = 0;
|
|
657
|
+
for (let k = 0; k < 4; k++) {
|
|
658
|
+
// Calculate (ik + kj) and add it to the value
|
|
659
|
+
value += a[i * 4 + k] * b[k * 4 + j];
|
|
660
|
+
}
|
|
661
|
+
const positionInResultingMatrix = 4 * i + j;
|
|
662
|
+
result[positionInResultingMatrix] = value;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return result;
|
|
706
666
|
}
|
|
707
667
|
/**
|
|
708
668
|
* Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
|
|
@@ -719,45 +679,60 @@ function transpose(matrix) {
|
|
|
719
679
|
/* eslint-enable prettier/prettier */
|
|
720
680
|
}
|
|
721
681
|
/**
|
|
722
|
-
* Multiplies the columns of a matrix by the given vector.
|
|
682
|
+
* Multiplies the columns of a row-major matrix by the given vector.
|
|
723
683
|
*/
|
|
724
684
|
function scale$4(matrix, scale) {
|
|
725
|
-
|
|
726
|
-
|
|
685
|
+
const { x, y, z } = scale;
|
|
686
|
+
const m = [...matrix];
|
|
727
687
|
/* eslint-disable prettier/prettier */
|
|
728
688
|
m[0] *= x;
|
|
729
|
-
m[4] *= y;
|
|
730
|
-
m[8] *= z;
|
|
731
689
|
m[1] *= x;
|
|
732
|
-
m[5] *= y;
|
|
733
|
-
m[9] *= z;
|
|
734
690
|
m[2] *= x;
|
|
735
|
-
m[6] *= y;
|
|
736
|
-
m[10] *= z;
|
|
737
691
|
m[3] *= x;
|
|
692
|
+
m[4] *= y;
|
|
693
|
+
m[5] *= y;
|
|
694
|
+
m[6] *= y;
|
|
738
695
|
m[7] *= y;
|
|
696
|
+
m[8] *= z;
|
|
697
|
+
m[9] *= z;
|
|
698
|
+
m[10] *= z;
|
|
739
699
|
m[11] *= z;
|
|
740
700
|
/* eslint-enable prettier/prettier */
|
|
741
701
|
return m;
|
|
742
702
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
703
|
+
/**
|
|
704
|
+
* Sets the position of the matrix given as the first parameter
|
|
705
|
+
* to the position of the matrix given as the second parameter.
|
|
706
|
+
* Both matrices should have row-major format.
|
|
707
|
+
*/
|
|
708
|
+
function position(originalMatrix, matrixWithDesiredPosition) {
|
|
709
|
+
const m = [...originalMatrix];
|
|
710
|
+
m[12] = matrixWithDesiredPosition[12];
|
|
711
|
+
m[13] = matrixWithDesiredPosition[13];
|
|
712
|
+
m[14] = matrixWithDesiredPosition[14];
|
|
748
713
|
return m;
|
|
749
714
|
}
|
|
750
715
|
/**
|
|
751
716
|
* Returns true if the matrix is an identity matrix.
|
|
752
717
|
*/
|
|
753
718
|
function isIdentity(matrix) {
|
|
754
|
-
|
|
755
|
-
return matrix.every(
|
|
719
|
+
const identity = makeIdentity();
|
|
720
|
+
return matrix.every((v, i) => v === identity[i]);
|
|
756
721
|
}
|
|
757
722
|
/**
|
|
758
723
|
* Returns an object representation of a `Matrix4`.
|
|
724
|
+
* @param m A Matrix4 item written in column-major form.
|
|
725
|
+
*
|
|
726
|
+
* @deprecated Use {@link toObjectColumnMajor} or {@link toObjectRowMajor} instead.
|
|
759
727
|
*/
|
|
760
728
|
function toObject(m) {
|
|
729
|
+
return toObjectColumnMajor(m);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Returns an object representation of a `Matrix4`.
|
|
733
|
+
* @param m A Matrix4 item written in column-major form.
|
|
734
|
+
*/
|
|
735
|
+
function toObjectColumnMajor(m) {
|
|
761
736
|
/* eslint-disable prettier/prettier */
|
|
762
737
|
return {
|
|
763
738
|
m11: m[0], m12: m[4], m13: m[8], m14: m[12],
|
|
@@ -767,6 +742,20 @@ function toObject(m) {
|
|
|
767
742
|
};
|
|
768
743
|
/* eslint-enable prettier/prettier */
|
|
769
744
|
}
|
|
745
|
+
/**
|
|
746
|
+
* Returns an object representation of a `Matrix4`.
|
|
747
|
+
* @param m A Matrix4 item written in row-major form.
|
|
748
|
+
*/
|
|
749
|
+
function toObjectRowMajor(m) {
|
|
750
|
+
/* eslint-disable prettier/prettier */
|
|
751
|
+
return {
|
|
752
|
+
m11: m[0], m12: m[1], m13: m[2], m14: m[3],
|
|
753
|
+
m21: m[4], m22: m[5], m23: m[6], m24: m[7],
|
|
754
|
+
m31: m[8], m32: m[9], m33: m[10], m34: m[11],
|
|
755
|
+
m41: m[12], m42: m[13], m43: m[14], m44: m[15],
|
|
756
|
+
};
|
|
757
|
+
/* eslint-enable prettier/prettier */
|
|
758
|
+
}
|
|
770
759
|
/**
|
|
771
760
|
* A type guard to check if `obj` is of type `Matrix4`.
|
|
772
761
|
*/
|
|
@@ -790,7 +779,6 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
790
779
|
makeOrthographic: makeOrthographic,
|
|
791
780
|
makePerspective: makePerspective,
|
|
792
781
|
makeRotation: makeRotation,
|
|
793
|
-
makeRotationAxis: makeRotationAxis,
|
|
794
782
|
makeScale: makeScale,
|
|
795
783
|
makeTRS: makeTRS,
|
|
796
784
|
makeTranslation: makeTranslation,
|
|
@@ -799,6 +787,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
799
787
|
position: position,
|
|
800
788
|
scale: scale$4,
|
|
801
789
|
toObject: toObject,
|
|
790
|
+
toObjectColumnMajor: toObjectColumnMajor,
|
|
791
|
+
toObjectRowMajor: toObjectRowMajor,
|
|
802
792
|
transpose: transpose
|
|
803
793
|
});
|
|
804
794
|
|
|
@@ -810,9 +800,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
810
800
|
* @param value The values to populate the Euler angles with.
|
|
811
801
|
* @returns A set of Euler angles.
|
|
812
802
|
*/
|
|
813
|
-
function create$c(value) {
|
|
803
|
+
function create$c(value = {}) {
|
|
814
804
|
var _a, _b, _c, _d;
|
|
815
|
-
if (value === void 0) { value = {}; }
|
|
816
805
|
return {
|
|
817
806
|
x: (_a = value.x) !== null && _a !== void 0 ? _a : 0,
|
|
818
807
|
y: (_b = value.y) !== null && _b !== void 0 ? _b : 0,
|
|
@@ -828,14 +817,13 @@ function create$c(value) {
|
|
|
828
817
|
* @param value The values to populate the Euler angles with.
|
|
829
818
|
* @returns A set of Euler angles.
|
|
830
819
|
*/
|
|
831
|
-
function fromDegrees(value) {
|
|
832
|
-
|
|
833
|
-
var _a = value.x, x = _a === void 0 ? 0 : _a, _b = value.y, y = _b === void 0 ? 0 : _b, _c = value.z, z = _c === void 0 ? 0 : _c, order = value.order;
|
|
820
|
+
function fromDegrees(value = {}) {
|
|
821
|
+
const { x = 0, y = 0, z = 0, order } = value;
|
|
834
822
|
return create$c({
|
|
835
823
|
x: toRadians(x),
|
|
836
824
|
y: toRadians(y),
|
|
837
825
|
z: toRadians(z),
|
|
838
|
-
order
|
|
826
|
+
order,
|
|
839
827
|
});
|
|
840
828
|
}
|
|
841
829
|
/**
|
|
@@ -849,10 +837,11 @@ function fromDegrees(value) {
|
|
|
849
837
|
* @param matrix A pure rotation matrix, unscaled.
|
|
850
838
|
* @param order The order that the rotations are applied.
|
|
851
839
|
*/
|
|
852
|
-
function fromRotationMatrix(matrix, order) {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
840
|
+
function fromRotationMatrix(matrix, order = 'xyz', matrixIsColumnMajor = true) {
|
|
841
|
+
const m = matrixIsColumnMajor
|
|
842
|
+
? toObjectColumnMajor(matrix)
|
|
843
|
+
: toObjectRowMajor(matrix);
|
|
844
|
+
let x = 0, y = 0, z = 0;
|
|
856
845
|
if (order === 'xyz') {
|
|
857
846
|
y = Math.asin(clamp(m.m13, -1, 1));
|
|
858
847
|
if (Math.abs(m.m13) < 0.9999999) {
|
|
@@ -919,7 +908,7 @@ function fromRotationMatrix(matrix, order) {
|
|
|
919
908
|
y = 0;
|
|
920
909
|
}
|
|
921
910
|
}
|
|
922
|
-
return { x
|
|
911
|
+
return { x, y, z, order };
|
|
923
912
|
}
|
|
924
913
|
/**
|
|
925
914
|
* Returns a set of Euler angles that was decoded from a JSON string. Supports either
|
|
@@ -930,14 +919,14 @@ function fromRotationMatrix(matrix, order) {
|
|
|
930
919
|
* @returns A set of Euler angles.
|
|
931
920
|
*/
|
|
932
921
|
function fromJson$4(json) {
|
|
933
|
-
|
|
922
|
+
const obj = JSON.parse(json);
|
|
934
923
|
if (Array.isArray(obj)) {
|
|
935
|
-
|
|
936
|
-
return { x
|
|
924
|
+
const [x, y, z, order = 'xyz'] = obj;
|
|
925
|
+
return { x, y, z, order };
|
|
937
926
|
}
|
|
938
927
|
else {
|
|
939
|
-
|
|
940
|
-
return { x
|
|
928
|
+
const { x, y, z, order = 'xyz' } = obj;
|
|
929
|
+
return { x, y, z, order };
|
|
941
930
|
}
|
|
942
931
|
}
|
|
943
932
|
/**
|
|
@@ -945,7 +934,7 @@ function fromJson$4(json) {
|
|
|
945
934
|
*/
|
|
946
935
|
function isType$1(obj) {
|
|
947
936
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
948
|
-
|
|
937
|
+
const o = obj;
|
|
949
938
|
return (o != null &&
|
|
950
939
|
o.hasOwnProperty('x') &&
|
|
951
940
|
o.hasOwnProperty('y') &&
|
|
@@ -966,9 +955,8 @@ var euler = /*#__PURE__*/Object.freeze({
|
|
|
966
955
|
* Returns a new quaternion. If `value` is undefined, then `{x: 0, y: 0, z: 0,
|
|
967
956
|
* w: 1}` is returned.
|
|
968
957
|
*/
|
|
969
|
-
function create$b(value) {
|
|
970
|
-
|
|
971
|
-
return tslib.__assign({ x: 0, y: 0, z: 0, w: 1 }, value);
|
|
958
|
+
function create$b(value = {}) {
|
|
959
|
+
return { x: 0, y: 0, z: 0, w: 1, ...value };
|
|
972
960
|
}
|
|
973
961
|
/**
|
|
974
962
|
* Parses a JSON string representation of a `Quaternion`.
|
|
@@ -977,10 +965,10 @@ function create$b(value) {
|
|
|
977
965
|
* @returns A parsed `Quaternion`.
|
|
978
966
|
*/
|
|
979
967
|
function fromJson$3(json) {
|
|
980
|
-
|
|
968
|
+
const obj = JSON.parse(json);
|
|
981
969
|
if (Array.isArray(obj)) {
|
|
982
|
-
|
|
983
|
-
return create$b({ x
|
|
970
|
+
const [x, y, z, w] = obj;
|
|
971
|
+
return create$b({ x, y, z, w });
|
|
984
972
|
}
|
|
985
973
|
else {
|
|
986
974
|
return create$b(obj);
|
|
@@ -1017,80 +1005,72 @@ function scale$3(scalar, q) {
|
|
|
1017
1005
|
* @returns A rotated quaternion.
|
|
1018
1006
|
*/
|
|
1019
1007
|
function fromAxisAngle(axis, radians) {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
return { x
|
|
1008
|
+
const halfAngle = radians / 2;
|
|
1009
|
+
const s = Math.sin(halfAngle);
|
|
1010
|
+
const x = axis.x * s;
|
|
1011
|
+
const y = axis.y * s;
|
|
1012
|
+
const z = axis.z * s;
|
|
1013
|
+
const w = Math.cos(halfAngle);
|
|
1014
|
+
return { x, y, z, w };
|
|
1027
1015
|
}
|
|
1028
1016
|
/**
|
|
1029
1017
|
* Returns a quaternion using the upper 3x3 of a pure rotation matrix
|
|
1030
1018
|
* (unscaled).
|
|
1031
1019
|
*/
|
|
1032
1020
|
function fromMatrixRotation(matrix) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
var sm13 = m.m31 * is3;
|
|
1041
|
-
var sm21 = m.m12 * is1;
|
|
1042
|
-
var sm22 = m.m22 * is2;
|
|
1043
|
-
var sm23 = m.m32 * is3;
|
|
1044
|
-
var sm31 = m.m13 * is1;
|
|
1045
|
-
var sm32 = m.m23 * is2;
|
|
1046
|
-
var sm33 = m.m33 * is3;
|
|
1047
|
-
var trace = sm11 + sm22 + sm33;
|
|
1021
|
+
// Determine the scalars for each vector
|
|
1022
|
+
const scale = fromMatrixScale(matrix);
|
|
1023
|
+
const oneOverScaleVector = create$a(1 / scale.x, 1 / scale.y, 1 / scale.z);
|
|
1024
|
+
// Scale the matrix
|
|
1025
|
+
const scaledMatrix = scale$4(matrix, oneOverScaleVector);
|
|
1026
|
+
const sM = toObjectRowMajor(scaledMatrix);
|
|
1027
|
+
const trace = sM.m11 + sM.m22 + sM.m33;
|
|
1048
1028
|
if (trace > 0) {
|
|
1049
|
-
|
|
1029
|
+
const s = Math.sqrt(trace + 1) * 2;
|
|
1050
1030
|
return {
|
|
1051
|
-
x: (
|
|
1052
|
-
y: (
|
|
1053
|
-
z: (
|
|
1031
|
+
x: (sM.m23 - sM.m32) / s,
|
|
1032
|
+
y: (sM.m31 - sM.m13) / s,
|
|
1033
|
+
z: (sM.m12 - sM.m21) / s,
|
|
1054
1034
|
w: 0.25 * s,
|
|
1055
1035
|
};
|
|
1056
1036
|
}
|
|
1057
|
-
else if (
|
|
1058
|
-
|
|
1037
|
+
else if (sM.m11 > sM.m22 && sM.m11 > sM.m33) {
|
|
1038
|
+
const s = Math.sqrt(1 + sM.m11 - sM.m22 - sM.m33) * 2;
|
|
1059
1039
|
return {
|
|
1060
1040
|
x: 0.25 * s,
|
|
1061
|
-
y: (
|
|
1062
|
-
z: (
|
|
1063
|
-
w: (
|
|
1041
|
+
y: (sM.m12 + sM.m21) / s,
|
|
1042
|
+
z: (sM.m31 + sM.m13) / s,
|
|
1043
|
+
w: (sM.m23 - sM.m32) / s,
|
|
1064
1044
|
};
|
|
1065
1045
|
}
|
|
1066
|
-
else if (
|
|
1067
|
-
|
|
1046
|
+
else if (sM.m22 > sM.m33) {
|
|
1047
|
+
const s = Math.sqrt(1 + sM.m22 - sM.m11 - sM.m33) * 2;
|
|
1068
1048
|
return {
|
|
1069
|
-
x: (
|
|
1049
|
+
x: (sM.m12 + sM.m21) / s,
|
|
1070
1050
|
y: 0.25 * s,
|
|
1071
|
-
z: (
|
|
1072
|
-
w: (
|
|
1051
|
+
z: (sM.m23 + sM.m32) / s,
|
|
1052
|
+
w: (sM.m31 - sM.m13) / s,
|
|
1073
1053
|
};
|
|
1074
1054
|
}
|
|
1075
1055
|
else {
|
|
1076
|
-
|
|
1056
|
+
const s = Math.sqrt(1 + sM.m33 - sM.m11 - sM.m22) * 2;
|
|
1077
1057
|
return {
|
|
1078
|
-
x: (
|
|
1079
|
-
y: (
|
|
1058
|
+
x: (sM.m31 + sM.m13) / s,
|
|
1059
|
+
y: (sM.m23 + sM.m32) / s,
|
|
1080
1060
|
z: 0.25 * s,
|
|
1081
|
-
w: (
|
|
1061
|
+
w: (sM.m12 - sM.m21) / s,
|
|
1082
1062
|
};
|
|
1083
1063
|
}
|
|
1084
1064
|
}
|
|
1085
1065
|
function fromEuler(euler) {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1066
|
+
const { x: ex, y: ey, z: ez, order } = euler;
|
|
1067
|
+
const c1 = Math.cos(ex / 2);
|
|
1068
|
+
const c2 = Math.cos(ey / 2);
|
|
1069
|
+
const c3 = Math.cos(ez / 2);
|
|
1070
|
+
const s1 = Math.sin(ex / 2);
|
|
1071
|
+
const s2 = Math.sin(ey / 2);
|
|
1072
|
+
const s3 = Math.sin(ez / 2);
|
|
1073
|
+
let x = 0, y = 0, z = 0, w = 0;
|
|
1094
1074
|
switch (order) {
|
|
1095
1075
|
case 'xyz':
|
|
1096
1076
|
x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
@@ -1129,7 +1109,7 @@ function fromEuler(euler) {
|
|
|
1129
1109
|
w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
1130
1110
|
break;
|
|
1131
1111
|
}
|
|
1132
|
-
return { x
|
|
1112
|
+
return { x, y, z, w };
|
|
1133
1113
|
}
|
|
1134
1114
|
/**
|
|
1135
1115
|
* Multiplies `a` x `b` and returns a new quaternion with the result.
|
|
@@ -1148,7 +1128,7 @@ function multiply$1(a, b) {
|
|
|
1148
1128
|
*/
|
|
1149
1129
|
function isType(obj) {
|
|
1150
1130
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1151
|
-
|
|
1131
|
+
const o = obj;
|
|
1152
1132
|
return (o != null &&
|
|
1153
1133
|
o.hasOwnProperty('x') &&
|
|
1154
1134
|
o.hasOwnProperty('y') &&
|
|
@@ -1170,12 +1150,8 @@ var quaternion = /*#__PURE__*/Object.freeze({
|
|
|
1170
1150
|
scale: scale$3
|
|
1171
1151
|
});
|
|
1172
1152
|
|
|
1173
|
-
function create$a() {
|
|
1153
|
+
function create$a(...args) {
|
|
1174
1154
|
var _a, _b, _c, _d, _e, _f;
|
|
1175
|
-
var args = [];
|
|
1176
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1177
|
-
args[_i] = arguments[_i];
|
|
1178
|
-
}
|
|
1179
1155
|
if (args.length === 1) {
|
|
1180
1156
|
return {
|
|
1181
1157
|
x: (_a = args[0].x) !== null && _a !== void 0 ? _a : 0,
|
|
@@ -1202,27 +1178,33 @@ function create$a() {
|
|
|
1202
1178
|
* Checks if each component of the given vector is populated with a numeric
|
|
1203
1179
|
* component. A component is invalid if it contains a non-finite or NaN value.
|
|
1204
1180
|
*/
|
|
1205
|
-
function isValid$1(
|
|
1206
|
-
|
|
1207
|
-
|
|
1181
|
+
function isValid$1({ x, y, z }) {
|
|
1182
|
+
return [x, y, z].every((v) => isFinite(v) && !isNaN(v));
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Checks if every component of the given vector is zero.
|
|
1186
|
+
* Useful for detecting potentially problematic camera vectors, for example.
|
|
1187
|
+
*/
|
|
1188
|
+
function isZeroVector({ x, y, z }) {
|
|
1189
|
+
return [x, y, z].every((v) => v === 0);
|
|
1208
1190
|
}
|
|
1209
1191
|
/**
|
|
1210
1192
|
* Returns a vector representing the scale elements of `matrix`.
|
|
1211
1193
|
*/
|
|
1212
1194
|
function fromMatrixScale(matrix) {
|
|
1213
|
-
|
|
1195
|
+
const m = toObjectRowMajor(matrix);
|
|
1214
1196
|
return {
|
|
1215
|
-
x: Math.hypot(m.m11, m.
|
|
1216
|
-
y: Math.hypot(m.
|
|
1217
|
-
z: Math.hypot(m.
|
|
1197
|
+
x: Math.hypot(m.m11, m.m12, m.m13),
|
|
1198
|
+
y: Math.hypot(m.m21, m.m22, m.m23),
|
|
1199
|
+
z: Math.hypot(m.m31, m.m32, m.m33),
|
|
1218
1200
|
};
|
|
1219
1201
|
}
|
|
1220
1202
|
/**
|
|
1221
1203
|
* Returns a vector representing the position elements of `matrix`.
|
|
1222
1204
|
*/
|
|
1223
1205
|
function fromMatrixPosition(matrix) {
|
|
1224
|
-
|
|
1225
|
-
return { x: m.
|
|
1206
|
+
const m = toObjectRowMajor(matrix);
|
|
1207
|
+
return { x: m.m41, y: m.m42, z: m.m43 };
|
|
1226
1208
|
}
|
|
1227
1209
|
/**
|
|
1228
1210
|
* Parses a JSON string representation of a Vector3 and returns an object.
|
|
@@ -1231,13 +1213,13 @@ function fromMatrixPosition(matrix) {
|
|
|
1231
1213
|
* @returns A parsed Vector3.
|
|
1232
1214
|
*/
|
|
1233
1215
|
function fromJson$2(json) {
|
|
1234
|
-
|
|
1216
|
+
const obj = JSON.parse(json);
|
|
1235
1217
|
if (Array.isArray(obj)) {
|
|
1236
|
-
|
|
1218
|
+
const [x, y, z] = obj;
|
|
1237
1219
|
return create$a(x, y, z);
|
|
1238
1220
|
}
|
|
1239
1221
|
else {
|
|
1240
|
-
|
|
1222
|
+
const { x, y, z } = obj;
|
|
1241
1223
|
return create$a(x, y, z);
|
|
1242
1224
|
}
|
|
1243
1225
|
}
|
|
@@ -1248,11 +1230,10 @@ function fromJson$2(json) {
|
|
|
1248
1230
|
* @see #toArray()
|
|
1249
1231
|
* @see #create()
|
|
1250
1232
|
*/
|
|
1251
|
-
function fromArray(nums, offset) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
var z = nums[offset + 2];
|
|
1233
|
+
function fromArray(nums, offset = 0) {
|
|
1234
|
+
const x = nums[offset];
|
|
1235
|
+
const y = nums[offset + 1];
|
|
1236
|
+
const z = nums[offset + 2];
|
|
1256
1237
|
return create$a(x, y, z);
|
|
1257
1238
|
}
|
|
1258
1239
|
/**
|
|
@@ -1262,8 +1243,7 @@ function fromArray(nums, offset) {
|
|
|
1262
1243
|
* @see #fromArray()
|
|
1263
1244
|
* @see #create()
|
|
1264
1245
|
*/
|
|
1265
|
-
function toArray(
|
|
1266
|
-
var x = _a.x, y = _a.y, z = _a.z;
|
|
1246
|
+
function toArray({ x, y, z }) {
|
|
1267
1247
|
return [x, y, z];
|
|
1268
1248
|
}
|
|
1269
1249
|
/**
|
|
@@ -1312,7 +1292,7 @@ function origin() {
|
|
|
1312
1292
|
* Returns a vector with that will have a magnitude of 1.
|
|
1313
1293
|
*/
|
|
1314
1294
|
function normalize(vector) {
|
|
1315
|
-
|
|
1295
|
+
const length = magnitude(vector);
|
|
1316
1296
|
return { x: vector.x / length, y: vector.y / length, z: vector.z / length };
|
|
1317
1297
|
}
|
|
1318
1298
|
/**
|
|
@@ -1349,24 +1329,16 @@ function cross(a, b) {
|
|
|
1349
1329
|
/**
|
|
1350
1330
|
* Returns a vector that is the sum of two vectors.
|
|
1351
1331
|
*/
|
|
1352
|
-
function add(a) {
|
|
1353
|
-
|
|
1354
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1355
|
-
vectors[_i - 1] = arguments[_i];
|
|
1356
|
-
}
|
|
1357
|
-
return vectors.reduce(function (res, next) {
|
|
1332
|
+
function add(a, ...vectors) {
|
|
1333
|
+
return vectors.reduce((res, next) => {
|
|
1358
1334
|
return { x: res.x + next.x, y: res.y + next.y, z: res.z + next.z };
|
|
1359
1335
|
}, a);
|
|
1360
1336
|
}
|
|
1361
1337
|
/**
|
|
1362
1338
|
* Returns a vector that is the difference between two vectors.
|
|
1363
1339
|
*/
|
|
1364
|
-
function subtract(a) {
|
|
1365
|
-
|
|
1366
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1367
|
-
vectors[_i - 1] = arguments[_i];
|
|
1368
|
-
}
|
|
1369
|
-
return vectors.reduce(function (res, next) {
|
|
1340
|
+
function subtract(a, ...vectors) {
|
|
1341
|
+
return vectors.reduce((res, next) => {
|
|
1370
1342
|
return { x: res.x - next.x, y: res.y - next.y, z: res.z - next.z };
|
|
1371
1343
|
}, a);
|
|
1372
1344
|
}
|
|
@@ -1400,7 +1372,7 @@ function dot$1(a, b) {
|
|
|
1400
1372
|
* result is never greater than 180 degrees.
|
|
1401
1373
|
*/
|
|
1402
1374
|
function angleTo(a, b) {
|
|
1403
|
-
|
|
1375
|
+
const theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
|
|
1404
1376
|
// Clamp to avoid numerical problems.
|
|
1405
1377
|
return Math.acos(theta);
|
|
1406
1378
|
}
|
|
@@ -1411,16 +1383,19 @@ function angleTo(a, b) {
|
|
|
1411
1383
|
* algorithm described in https://www.xarg.org/proof/quaternion-from-two-vectors/.
|
|
1412
1384
|
*/
|
|
1413
1385
|
function eulerTo(a, b) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1386
|
+
const normalizedA = normalize(a);
|
|
1387
|
+
const normalizedB = normalize(b);
|
|
1388
|
+
const dotDelta = Math.cos(toRadians(1));
|
|
1389
|
+
const dotAB = dot$1(normalizedA, normalizedB);
|
|
1390
|
+
const vectorsAreParallel = Math.abs(dotAB) > dotDelta;
|
|
1419
1391
|
if (vectorsAreParallel) {
|
|
1420
1392
|
return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
|
|
1421
1393
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1394
|
+
const normalizedQ = normalize$1(create$b({
|
|
1395
|
+
w: 1 + dotAB,
|
|
1396
|
+
...cross(normalizedA, normalizedB),
|
|
1397
|
+
}));
|
|
1398
|
+
return fromRotationMatrix(makeRotation(normalizedQ), 'xyz', false);
|
|
1424
1399
|
}
|
|
1425
1400
|
/**
|
|
1426
1401
|
* Performs a projection of a `vector` onto `onNormal`.
|
|
@@ -1450,18 +1425,18 @@ function project(vector, onNormal) {
|
|
|
1450
1425
|
*/
|
|
1451
1426
|
function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
|
|
1452
1427
|
if (angle !== 0) {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1428
|
+
const { x, y, z } = point;
|
|
1429
|
+
const { x: a, y: b, z: c } = axisPosition;
|
|
1430
|
+
const { x: u, y: v, z: w } = axisDirection;
|
|
1431
|
+
const newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
|
|
1457
1432
|
(1 - Math.cos(angle)) +
|
|
1458
1433
|
x * Math.cos(angle) +
|
|
1459
1434
|
(-c * v + b * w - w * y + v * z) * Math.sin(angle);
|
|
1460
|
-
|
|
1435
|
+
const newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
|
|
1461
1436
|
(1 - Math.cos(angle)) +
|
|
1462
1437
|
y * Math.cos(angle) +
|
|
1463
1438
|
(c * u - a * w + w * x - u * z) * Math.sin(angle);
|
|
1464
|
-
|
|
1439
|
+
const newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
|
|
1465
1440
|
(1 - Math.cos(angle)) +
|
|
1466
1441
|
z * Math.cos(angle) +
|
|
1467
1442
|
(-b * u + a * v - v * x + u * y) * Math.sin(angle);
|
|
@@ -1472,17 +1447,43 @@ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
|
|
|
1472
1447
|
}
|
|
1473
1448
|
}
|
|
1474
1449
|
/**
|
|
1475
|
-
* Returns a vector that is multiplied with a matrix.
|
|
1450
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1451
|
+
* @param vector A Vector3 item.
|
|
1452
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1453
|
+
*
|
|
1454
|
+
* @deprecated Use {@link multiplyByTransformMatrixColumnMajor} or {@link multiplyByTransformMatrixRowMajor} instead.
|
|
1476
1455
|
*/
|
|
1477
1456
|
function transformMatrix$1(vector, m) {
|
|
1478
|
-
|
|
1479
|
-
|
|
1457
|
+
return multiplyByTransformMatrixColumnMajor(vector, m);
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1461
|
+
* @param vector A Vector3 item.
|
|
1462
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1463
|
+
*/
|
|
1464
|
+
function multiplyByTransformMatrixColumnMajor(vector, m) {
|
|
1465
|
+
const { x, y, z } = vector;
|
|
1466
|
+
const w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
|
|
1480
1467
|
return {
|
|
1481
1468
|
x: (m[0] * x + m[4] * y + m[8] * z + m[12]) * w,
|
|
1482
1469
|
y: (m[1] * x + m[5] * y + m[9] * z + m[13]) * w,
|
|
1483
1470
|
z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
|
|
1484
1471
|
};
|
|
1485
1472
|
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Returns a vector that is multiplied with a matrix in row-major form.
|
|
1475
|
+
* @param vector A Vector3 item.
|
|
1476
|
+
* @param m A Matrix4 item written in row-major form.
|
|
1477
|
+
*/
|
|
1478
|
+
function multiplyByTransformMatrixRowMajor(vector, m) {
|
|
1479
|
+
const { x, y, z } = vector;
|
|
1480
|
+
const w = 1 / (m[12] * x + m[13] * y + m[14] * z + m[15]);
|
|
1481
|
+
return {
|
|
1482
|
+
x: (m[0] * x + m[1] * y + m[2] * z + m[3]) * w,
|
|
1483
|
+
y: (m[4] * x + m[5] * y + m[6] * z + m[7]) * w,
|
|
1484
|
+
z: (m[8] * x + m[9] * y + m[10] * z + m[11]) * w,
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1486
1487
|
/**
|
|
1487
1488
|
* Euclidean distance between two vectors
|
|
1488
1489
|
*/
|
|
@@ -1494,7 +1495,7 @@ function distance$1(a, b) {
|
|
|
1494
1495
|
* distances, this is slightly more efficient than `distanceTo`.
|
|
1495
1496
|
*/
|
|
1496
1497
|
function distanceSquared$1(a, b) {
|
|
1497
|
-
|
|
1498
|
+
const { x: dx, y: dy, z: dz } = subtract(a, b);
|
|
1498
1499
|
return dx * dx + dy * dy + dz * dz;
|
|
1499
1500
|
}
|
|
1500
1501
|
/**
|
|
@@ -1546,7 +1547,7 @@ function lerp(a, b, t) {
|
|
|
1546
1547
|
* @returns A point in world space coordinates.
|
|
1547
1548
|
*/
|
|
1548
1549
|
function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
|
|
1549
|
-
return
|
|
1550
|
+
return multiplyByTransformMatrixColumnMajor(multiplyByTransformMatrixColumnMajor(ndc, projectionMatrixInverse), worldMatrix);
|
|
1550
1551
|
}
|
|
1551
1552
|
|
|
1552
1553
|
var vector3 = /*#__PURE__*/Object.freeze({
|
|
@@ -1568,6 +1569,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
|
|
|
1568
1569
|
fromMatrixScale: fromMatrixScale,
|
|
1569
1570
|
isEqual: isEqual$2,
|
|
1570
1571
|
isValid: isValid$1,
|
|
1572
|
+
isZeroVector: isZeroVector,
|
|
1571
1573
|
left: left,
|
|
1572
1574
|
lerp: lerp,
|
|
1573
1575
|
magnitude: magnitude,
|
|
@@ -1575,6 +1577,8 @@ var vector3 = /*#__PURE__*/Object.freeze({
|
|
|
1575
1577
|
max: max,
|
|
1576
1578
|
min: min,
|
|
1577
1579
|
multiply: multiply,
|
|
1580
|
+
multiplyByTransformMatrixColumnMajor: multiplyByTransformMatrixColumnMajor,
|
|
1581
|
+
multiplyByTransformMatrixRowMajor: multiplyByTransformMatrixRowMajor,
|
|
1578
1582
|
negate: negate,
|
|
1579
1583
|
normalize: normalize,
|
|
1580
1584
|
origin: origin,
|
|
@@ -1592,42 +1596,38 @@ var vector3 = /*#__PURE__*/Object.freeze({
|
|
|
1592
1596
|
/**
|
|
1593
1597
|
* Returns a `BoundingBox` with the given min and max points.
|
|
1594
1598
|
*/
|
|
1595
|
-
|
|
1596
|
-
return { min
|
|
1599
|
+
const create$9 = (min, max) => {
|
|
1600
|
+
return { min, max };
|
|
1597
1601
|
};
|
|
1598
1602
|
/**
|
|
1599
1603
|
* Construct a minimal bounding box for a set of vectors, such that all vectors
|
|
1600
1604
|
* are contained by the bounding box.
|
|
1601
1605
|
*/
|
|
1602
|
-
|
|
1603
|
-
return union
|
|
1606
|
+
const fromVectors = (vectors) => {
|
|
1607
|
+
return union(...vectors.map((v) => create$9(v, v)));
|
|
1604
1608
|
};
|
|
1605
1609
|
/**
|
|
1606
1610
|
* Returns the center point of the given `BoundingBox`.
|
|
1607
1611
|
*/
|
|
1608
|
-
|
|
1612
|
+
const center$3 = (boundingBox) => {
|
|
1609
1613
|
return scale$2(0.5, add(boundingBox.min, boundingBox.max));
|
|
1610
1614
|
};
|
|
1611
1615
|
/**
|
|
1612
1616
|
* Returns the diagonal vector between the `min` and `max` vectors of the
|
|
1613
1617
|
* given `BoundingBox`.
|
|
1614
1618
|
*/
|
|
1615
|
-
|
|
1619
|
+
const diagonal = (boundingBox) => {
|
|
1616
1620
|
return subtract(boundingBox.max, boundingBox.min);
|
|
1617
1621
|
};
|
|
1618
1622
|
/**
|
|
1619
1623
|
* Returns a floating-point spatial error tolerance based on the extents of the box.
|
|
1620
1624
|
*/
|
|
1621
|
-
|
|
1625
|
+
const epsilon = (boundingBox) => {
|
|
1622
1626
|
return (Math.max(Math.max(magnitude(boundingBox.max), magnitude(boundingBox.min)), magnitude(diagonal(boundingBox))) * 1e-6);
|
|
1623
1627
|
};
|
|
1624
|
-
function union(box) {
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
rest[_i - 1] = arguments[_i];
|
|
1628
|
-
}
|
|
1629
|
-
var boxes = tslib.__spreadArray([box], rest, true);
|
|
1630
|
-
return boxes.reduce(function (a, b) {
|
|
1628
|
+
function union(box, ...rest) {
|
|
1629
|
+
const boxes = [box, ...rest];
|
|
1630
|
+
return boxes.reduce((a, b) => {
|
|
1631
1631
|
return create$9(min(a.min, b.min), max(a.max, b.max));
|
|
1632
1632
|
});
|
|
1633
1633
|
}
|
|
@@ -1636,7 +1636,7 @@ function union(box) {
|
|
|
1636
1636
|
* Returns the distance between the min and max for the provided
|
|
1637
1637
|
* bounding box for each axis.
|
|
1638
1638
|
*/
|
|
1639
|
-
|
|
1639
|
+
const lengths = (box) => {
|
|
1640
1640
|
return create$a(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z);
|
|
1641
1641
|
};
|
|
1642
1642
|
/**
|
|
@@ -1644,8 +1644,8 @@ var lengths = function (box) {
|
|
|
1644
1644
|
* component. A component is invalid if it contains a non-finite or NaN value.
|
|
1645
1645
|
*/
|
|
1646
1646
|
function isValid(boundingBox) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1647
|
+
const maxIsValid = isValid$1(boundingBox.max);
|
|
1648
|
+
const minIsValid = isValid$1(boundingBox.min);
|
|
1649
1649
|
return maxIsValid && minIsValid;
|
|
1650
1650
|
}
|
|
1651
1651
|
|
|
@@ -1664,13 +1664,13 @@ var boundingBox = /*#__PURE__*/Object.freeze({
|
|
|
1664
1664
|
/**
|
|
1665
1665
|
* Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
|
|
1666
1666
|
*/
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
return { center: boundingBoxCenter, radius
|
|
1667
|
+
const create$8 = (boundingBox$1) => {
|
|
1668
|
+
const boundingBoxCenter = center$3(boundingBox$1);
|
|
1669
|
+
const centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
|
|
1670
|
+
const radius = magnitude(centerToBoundingPlane);
|
|
1671
|
+
const length = Math.max(radius, magnitude(boundingBoxCenter));
|
|
1672
|
+
const epsilon = length === 0 ? 1.0 : length * 1e-6;
|
|
1673
|
+
return { center: boundingBoxCenter, radius, epsilon };
|
|
1674
1674
|
};
|
|
1675
1675
|
|
|
1676
1676
|
var boundingSphere = /*#__PURE__*/Object.freeze({
|
|
@@ -1682,7 +1682,7 @@ var boundingSphere = /*#__PURE__*/Object.freeze({
|
|
|
1682
1682
|
* Returns a new `Rectangle` with the given position and size.
|
|
1683
1683
|
*/
|
|
1684
1684
|
function create$7(x, y, width, height) {
|
|
1685
|
-
return { x
|
|
1685
|
+
return { x, y, width, height };
|
|
1686
1686
|
}
|
|
1687
1687
|
/**
|
|
1688
1688
|
* Returns a new `Rectangle` at the origin point and given size.
|
|
@@ -1701,10 +1701,10 @@ function fromPointAndDimensions(point, dimensions) {
|
|
|
1701
1701
|
* The returned rectangle will always returns a positive width and height.
|
|
1702
1702
|
*/
|
|
1703
1703
|
function fromPoints(topLeftPt, bottomRightPt) {
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1704
|
+
const minX = Math.min(topLeftPt.x, bottomRightPt.x);
|
|
1705
|
+
const minY = Math.min(topLeftPt.y, bottomRightPt.y);
|
|
1706
|
+
const maxX = Math.max(topLeftPt.x, bottomRightPt.x);
|
|
1707
|
+
const maxY = Math.max(topLeftPt.y, bottomRightPt.y);
|
|
1708
1708
|
return create$7(minX, minY, maxX - minX, maxY - minY);
|
|
1709
1709
|
}
|
|
1710
1710
|
/**
|
|
@@ -1716,9 +1716,9 @@ function fromPoints(topLeftPt, bottomRightPt) {
|
|
|
1716
1716
|
* @see {@link cropFit}
|
|
1717
1717
|
*/
|
|
1718
1718
|
function containFit$1(to, rect) {
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1719
|
+
const scale = Math.min(to.width / rect.width, to.height / rect.height);
|
|
1720
|
+
const dimensions$1 = proportionalScale(scale, rect);
|
|
1721
|
+
const position = subtract$1(center$2(to), center$1(dimensions$1));
|
|
1722
1722
|
return fromPointAndDimensions(position, dimensions$1);
|
|
1723
1723
|
}
|
|
1724
1724
|
/**
|
|
@@ -1730,9 +1730,9 @@ function containFit$1(to, rect) {
|
|
|
1730
1730
|
* @see {@link containFit}
|
|
1731
1731
|
*/
|
|
1732
1732
|
function cropFit$1(to, rect) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1733
|
+
const scale = Math.max(to.width / rect.width, to.height / rect.height);
|
|
1734
|
+
const dimensions$1 = proportionalScale(scale, rect);
|
|
1735
|
+
const position = subtract$1(center$2(to), center$1(dimensions$1));
|
|
1736
1736
|
return fromPointAndDimensions(position, dimensions$1);
|
|
1737
1737
|
}
|
|
1738
1738
|
/**
|
|
@@ -1744,9 +1744,9 @@ function cropFit$1(to, rect) {
|
|
|
1744
1744
|
* @param rect - the rectangle to scale to fit the specified area
|
|
1745
1745
|
*/
|
|
1746
1746
|
function scaleFit$1(to, rect) {
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1747
|
+
const scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
|
|
1748
|
+
const dimensions$1 = floor(proportionalScale(scale, rect));
|
|
1749
|
+
const position = subtract$1(center$2(rect), center$1(dimensions$1));
|
|
1750
1750
|
return fromPointAndDimensions(position, dimensions$1);
|
|
1751
1751
|
}
|
|
1752
1752
|
/**
|
|
@@ -1765,8 +1765,8 @@ function scale$1(rect, scaleOrScaleX, scaleY) {
|
|
|
1765
1765
|
return scale$1(rect, scaleOrScaleX, scaleOrScaleX);
|
|
1766
1766
|
}
|
|
1767
1767
|
else {
|
|
1768
|
-
|
|
1769
|
-
|
|
1768
|
+
const { x, y, width, height } = rect;
|
|
1769
|
+
const scaleX = scaleOrScaleX;
|
|
1770
1770
|
return create$7(x * scaleX, y * scaleY, width * scaleX, height * scaleY);
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
@@ -1840,12 +1840,8 @@ function pad(rect, padding) {
|
|
|
1840
1840
|
* @param rect The rectangle to check against.
|
|
1841
1841
|
* @param points The points to check.
|
|
1842
1842
|
*/
|
|
1843
|
-
function containsPoints(rect) {
|
|
1844
|
-
|
|
1845
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1846
|
-
points[_i - 1] = arguments[_i];
|
|
1847
|
-
}
|
|
1848
|
-
return points.every(function (point) {
|
|
1843
|
+
function containsPoints(rect, ...points) {
|
|
1844
|
+
return points.every((point) => {
|
|
1849
1845
|
return (rect.x <= point.x &&
|
|
1850
1846
|
rect.x + rect.width >= point.x &&
|
|
1851
1847
|
rect.y <= point.y &&
|
|
@@ -1859,13 +1855,13 @@ function containsPoints(rect) {
|
|
|
1859
1855
|
* @returns A parsed Point.
|
|
1860
1856
|
*/
|
|
1861
1857
|
function fromJson$1(json) {
|
|
1862
|
-
|
|
1858
|
+
const obj = JSON.parse(json);
|
|
1863
1859
|
if (Array.isArray(obj)) {
|
|
1864
|
-
|
|
1860
|
+
const [x, y, width, height] = obj;
|
|
1865
1861
|
return create$7(x, y, width, height);
|
|
1866
1862
|
}
|
|
1867
1863
|
else {
|
|
1868
|
-
|
|
1864
|
+
const { x, y, width, height } = obj;
|
|
1869
1865
|
return create$7(x, y, width, height);
|
|
1870
1866
|
}
|
|
1871
1867
|
}
|
|
@@ -1898,27 +1894,27 @@ var rectangle = /*#__PURE__*/Object.freeze({
|
|
|
1898
1894
|
* Returns a `Dimensions` with the given width and height.
|
|
1899
1895
|
*
|
|
1900
1896
|
*/
|
|
1901
|
-
|
|
1902
|
-
return { width
|
|
1897
|
+
const create$6 = (width, height) => {
|
|
1898
|
+
return { width, height };
|
|
1903
1899
|
};
|
|
1904
1900
|
/**
|
|
1905
1901
|
* Returns a `Dimensions` with the same width and height.
|
|
1906
1902
|
*/
|
|
1907
|
-
|
|
1903
|
+
const square = (size) => {
|
|
1908
1904
|
return create$6(size, size);
|
|
1909
1905
|
};
|
|
1910
1906
|
/**
|
|
1911
1907
|
* Returns `true` if two dimensions have the same width and height. Otherwise
|
|
1912
1908
|
* `false`.
|
|
1913
1909
|
*/
|
|
1914
|
-
|
|
1910
|
+
const isEqual = (a, b) => {
|
|
1915
1911
|
return a.width === b.width && a.height === b.height;
|
|
1916
1912
|
};
|
|
1917
1913
|
/**
|
|
1918
1914
|
* Returns a scaled dimensions, where the width is scaled by `scaleX` and height
|
|
1919
1915
|
* is scaled by `scaleY`.
|
|
1920
1916
|
*/
|
|
1921
|
-
|
|
1917
|
+
const scale = (scaleX, scaleY, dimensions) => {
|
|
1922
1918
|
return {
|
|
1923
1919
|
width: dimensions.width * scaleX,
|
|
1924
1920
|
height: dimensions.height * scaleY,
|
|
@@ -1927,14 +1923,14 @@ var scale = function (scaleX, scaleY, dimensions) {
|
|
|
1927
1923
|
/**
|
|
1928
1924
|
* Returns a dimension where each length is scaled by `scaleFactor`.
|
|
1929
1925
|
*/
|
|
1930
|
-
|
|
1926
|
+
const proportionalScale = (scaleFactor, dimensions) => {
|
|
1931
1927
|
return scale(scaleFactor, scaleFactor, dimensions);
|
|
1932
1928
|
};
|
|
1933
1929
|
/**
|
|
1934
1930
|
* Returns a `Dimensions` where the lengths of `dimensions` are trimmed to fit
|
|
1935
1931
|
* into `to`.
|
|
1936
1932
|
*/
|
|
1937
|
-
|
|
1933
|
+
const trim = (to, dimensions) => {
|
|
1938
1934
|
return {
|
|
1939
1935
|
width: Math.min(to.width, dimensions.width),
|
|
1940
1936
|
height: Math.min(to.height, dimensions.height),
|
|
@@ -1947,9 +1943,9 @@ var trim = function (to, dimensions) {
|
|
|
1947
1943
|
*
|
|
1948
1944
|
* @see #cropFit()
|
|
1949
1945
|
*/
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
return { width
|
|
1946
|
+
const containFit = (to, dimensions) => {
|
|
1947
|
+
const { width, height } = containFit$1(toRectangle(to), toRectangle(dimensions));
|
|
1948
|
+
return { width, height };
|
|
1953
1949
|
};
|
|
1954
1950
|
/**
|
|
1955
1951
|
* Returns a `Dimensions` where the shortest length of `dimensions` will be
|
|
@@ -1958,9 +1954,9 @@ var containFit = function (to, dimensions) {
|
|
|
1958
1954
|
*
|
|
1959
1955
|
* @see #containFit()
|
|
1960
1956
|
*/
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
return { width
|
|
1957
|
+
const cropFit = (to, dimensions) => {
|
|
1958
|
+
const { width, height } = cropFit$1(toRectangle(to), toRectangle(dimensions));
|
|
1959
|
+
return { width, height };
|
|
1964
1960
|
};
|
|
1965
1961
|
/**
|
|
1966
1962
|
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally
|
|
@@ -1970,14 +1966,14 @@ var cropFit = function (to, dimensions) {
|
|
|
1970
1966
|
* @param to - the maximum area this dimensions can have
|
|
1971
1967
|
* @param dimensions - the dimensions to scale to fit the specified area
|
|
1972
1968
|
*/
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
return { width
|
|
1969
|
+
const scaleFit = (to, dimensions) => {
|
|
1970
|
+
const { width, height } = scaleFit$1(to, toRectangle(dimensions));
|
|
1971
|
+
return { width, height };
|
|
1976
1972
|
};
|
|
1977
1973
|
/**
|
|
1978
1974
|
* Returns a `Dimensions` with each length rounded.
|
|
1979
1975
|
*/
|
|
1980
|
-
|
|
1976
|
+
const round = (dimensions) => {
|
|
1981
1977
|
return {
|
|
1982
1978
|
width: Math.round(dimensions.width),
|
|
1983
1979
|
height: Math.round(dimensions.height),
|
|
@@ -1986,7 +1982,7 @@ var round = function (dimensions) {
|
|
|
1986
1982
|
/**
|
|
1987
1983
|
* Returns a `Dimensions` with each length rounded down.
|
|
1988
1984
|
*/
|
|
1989
|
-
|
|
1985
|
+
const floor = (dimensions) => {
|
|
1990
1986
|
return {
|
|
1991
1987
|
width: Math.floor(dimensions.width),
|
|
1992
1988
|
height: Math.floor(dimensions.height),
|
|
@@ -1995,22 +1991,20 @@ var floor = function (dimensions) {
|
|
|
1995
1991
|
/**
|
|
1996
1992
|
* Returns the center point of the given `dimensions`.
|
|
1997
1993
|
*/
|
|
1998
|
-
|
|
1994
|
+
const center$1 = (dimensions) => {
|
|
1999
1995
|
return { x: dimensions.width / 2, y: dimensions.height / 2 };
|
|
2000
1996
|
};
|
|
2001
1997
|
/**
|
|
2002
1998
|
* Returns the aspect ratio of the given `dimensions`, as defined by width over
|
|
2003
1999
|
* height.
|
|
2004
2000
|
*/
|
|
2005
|
-
|
|
2006
|
-
var width = _a.width, height = _a.height;
|
|
2001
|
+
const aspectRatio = ({ width, height }) => {
|
|
2007
2002
|
return width / height;
|
|
2008
2003
|
};
|
|
2009
2004
|
/**
|
|
2010
2005
|
* Returns the area of the given `dimensions`.
|
|
2011
2006
|
*/
|
|
2012
|
-
|
|
2013
|
-
var width = _a.width, height = _a.height;
|
|
2007
|
+
const area = ({ width, height }) => {
|
|
2014
2008
|
return width * height;
|
|
2015
2009
|
};
|
|
2016
2010
|
/**
|
|
@@ -2019,7 +2013,7 @@ var area = function (_a) {
|
|
|
2019
2013
|
* @param ratio - Aspect ratio to fit the provided Dimensions to
|
|
2020
2014
|
* @param dimensions - Dimensions to fit to the specified ratio
|
|
2021
2015
|
*/
|
|
2022
|
-
|
|
2016
|
+
const fitToRatio = (ratio, dimensions) => {
|
|
2023
2017
|
if (dimensions.width >= dimensions.height * ratio) {
|
|
2024
2018
|
return create$6(dimensions.height * ratio, dimensions.height);
|
|
2025
2019
|
}
|
|
@@ -2028,8 +2022,7 @@ var fitToRatio = function (ratio, dimensions) {
|
|
|
2028
2022
|
/**
|
|
2029
2023
|
* Converts a dimension to a rectangle, with an optional position.
|
|
2030
2024
|
*/
|
|
2031
|
-
function toRectangle(dimensions, position) {
|
|
2032
|
-
if (position === void 0) { position = create$d(); }
|
|
2025
|
+
function toRectangle(dimensions, position = create$d()) {
|
|
2033
2026
|
return fromPointAndDimensions(position, dimensions);
|
|
2034
2027
|
}
|
|
2035
2028
|
|
|
@@ -2059,9 +2052,8 @@ var dimensions = /*#__PURE__*/Object.freeze({
|
|
|
2059
2052
|
*
|
|
2060
2053
|
* @param values The values to assign to the line.
|
|
2061
2054
|
*/
|
|
2062
|
-
function create$5(values) {
|
|
2055
|
+
function create$5(values = {}) {
|
|
2063
2056
|
var _a, _b;
|
|
2064
|
-
if (values === void 0) { values = {}; }
|
|
2065
2057
|
return {
|
|
2066
2058
|
start: (_a = values.start) !== null && _a !== void 0 ? _a : origin(),
|
|
2067
2059
|
end: (_b = values.end) !== null && _b !== void 0 ? _b : origin(),
|
|
@@ -2082,9 +2074,9 @@ function center(line) {
|
|
|
2082
2074
|
* @returns A transformed line.
|
|
2083
2075
|
*/
|
|
2084
2076
|
function transformMatrix(line, matrix) {
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
return { start
|
|
2077
|
+
const start = multiplyByTransformMatrixColumnMajor(line.start, matrix);
|
|
2078
|
+
const end = multiplyByTransformMatrixColumnMajor(line.end, matrix);
|
|
2079
|
+
return { start, end };
|
|
2088
2080
|
}
|
|
2089
2081
|
/**
|
|
2090
2082
|
* Euclidean distance between the start and end points of the line.
|
|
@@ -2119,62 +2111,56 @@ var line3 = /*#__PURE__*/Object.freeze({
|
|
|
2119
2111
|
/**
|
|
2120
2112
|
* Creates a new matrix. If arguments are undefined, returns an identity matrix.
|
|
2121
2113
|
*/
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
if (b === void 0) { b = 0; }
|
|
2125
|
-
if (c === void 0) { c = 0; }
|
|
2126
|
-
if (d === void 0) { d = 1; }
|
|
2127
|
-
if (tx === void 0) { tx = 0; }
|
|
2128
|
-
if (ty === void 0) { ty = 0; }
|
|
2129
|
-
return { a: a, b: b, c: c, d: d, tx: tx, ty: ty };
|
|
2114
|
+
const create$4 = (a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) => {
|
|
2115
|
+
return { a, b, c, d, tx, ty };
|
|
2130
2116
|
};
|
|
2131
2117
|
/**
|
|
2132
2118
|
* Returns an identity matrix.
|
|
2133
2119
|
*/
|
|
2134
|
-
|
|
2120
|
+
const identity = () => {
|
|
2135
2121
|
return create$4();
|
|
2136
2122
|
};
|
|
2137
2123
|
/**
|
|
2138
2124
|
* Creates a matrix that is translated by the given `tx` and `ty` values.
|
|
2139
2125
|
*/
|
|
2140
|
-
|
|
2126
|
+
const translation = (tx, ty) => {
|
|
2141
2127
|
return translate(tx, ty, identity());
|
|
2142
2128
|
};
|
|
2143
2129
|
/**
|
|
2144
2130
|
* Creates a matrix that is rotated by the given degrees.
|
|
2145
2131
|
*/
|
|
2146
|
-
|
|
2132
|
+
const rotation = (degrees) => {
|
|
2147
2133
|
return rotate(degrees, identity());
|
|
2148
2134
|
};
|
|
2149
2135
|
/**
|
|
2150
2136
|
* Rotates the given matrix by the given degrees.
|
|
2151
2137
|
*/
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2138
|
+
const rotate = (degrees, matrix) => {
|
|
2139
|
+
const radians = toRadians(degrees);
|
|
2140
|
+
const cos = Math.cos(radians);
|
|
2141
|
+
const sin = Math.sin(radians);
|
|
2142
|
+
const a = matrix.a * cos + matrix.c * sin;
|
|
2143
|
+
const b = matrix.b * cos + matrix.d * sin;
|
|
2144
|
+
const c = matrix.a * -sin + matrix.c * cos;
|
|
2145
|
+
const d = matrix.b * -sin + matrix.d * cos;
|
|
2160
2146
|
return create$4(a, b, c, d, matrix.tx, matrix.ty);
|
|
2161
2147
|
};
|
|
2162
2148
|
/**
|
|
2163
2149
|
* Translates the given matrix along the horizontal and vertical axis by the
|
|
2164
2150
|
* given `dx` and `dy` delta values.
|
|
2165
2151
|
*/
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2152
|
+
const translate = (dx, dy, matrix) => {
|
|
2153
|
+
const newTx = matrix.a * dx + matrix.c * dy + matrix.tx;
|
|
2154
|
+
const newTy = matrix.b * dx + matrix.d * dy + matrix.ty;
|
|
2169
2155
|
return create$4(matrix.a, matrix.b, matrix.c, matrix.d, newTx, newTy);
|
|
2170
2156
|
};
|
|
2171
2157
|
/**
|
|
2172
2158
|
* Returns the result of applying a geometric transformation of a matrix on the
|
|
2173
2159
|
* given point.
|
|
2174
2160
|
*/
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2161
|
+
const transformPoint = (matrix, pt) => {
|
|
2162
|
+
const x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
|
|
2163
|
+
const y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
|
|
2178
2164
|
return create$d(x, y);
|
|
2179
2165
|
};
|
|
2180
2166
|
|
|
@@ -2189,11 +2175,7 @@ var matrix = /*#__PURE__*/Object.freeze({
|
|
|
2189
2175
|
translation: translation
|
|
2190
2176
|
});
|
|
2191
2177
|
|
|
2192
|
-
function create$3() {
|
|
2193
|
-
var args = [];
|
|
2194
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2195
|
-
args[_i] = arguments[_i];
|
|
2196
|
-
}
|
|
2178
|
+
function create$3(...args) {
|
|
2197
2179
|
if (args.length === 2) {
|
|
2198
2180
|
return {
|
|
2199
2181
|
a: args[0].x,
|
|
@@ -2243,9 +2225,8 @@ var matrix2 = /*#__PURE__*/Object.freeze({
|
|
|
2243
2225
|
* @param values Values to assign to the plane.
|
|
2244
2226
|
* @returns A new plane.
|
|
2245
2227
|
*/
|
|
2246
|
-
function create$2(values) {
|
|
2247
|
-
|
|
2248
|
-
return tslib.__assign({ normal: origin(), constant: 0 }, values);
|
|
2228
|
+
function create$2(values = {}) {
|
|
2229
|
+
return { normal: origin(), constant: 0, ...values };
|
|
2249
2230
|
}
|
|
2250
2231
|
/**
|
|
2251
2232
|
* Creates a plane from a normal and an arbitrary point on a plane.
|
|
@@ -2255,8 +2236,8 @@ function create$2(values) {
|
|
|
2255
2236
|
* @returns A new plane.
|
|
2256
2237
|
*/
|
|
2257
2238
|
function fromNormalAndCoplanarPoint(normal, point) {
|
|
2258
|
-
|
|
2259
|
-
return create$2({ normal
|
|
2239
|
+
const constant = -dot$1(point, normal);
|
|
2240
|
+
return create$2({ normal, constant });
|
|
2260
2241
|
}
|
|
2261
2242
|
/**
|
|
2262
2243
|
* Returns the perpendicular distance from the plane to the given point.
|
|
@@ -2278,8 +2259,8 @@ function distanceToPoint(plane, point) {
|
|
|
2278
2259
|
* @returns An intersecting point on the plane and line.
|
|
2279
2260
|
*/
|
|
2280
2261
|
function intersectLine(plane, line) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2262
|
+
const direction$1 = direction(line);
|
|
2263
|
+
const denominator = dot$1(plane.normal, direction$1);
|
|
2283
2264
|
if (denominator === 0) {
|
|
2284
2265
|
if (distanceToPoint(plane, line.start) === 0) {
|
|
2285
2266
|
return line.start;
|
|
@@ -2288,7 +2269,7 @@ function intersectLine(plane, line) {
|
|
|
2288
2269
|
return undefined;
|
|
2289
2270
|
}
|
|
2290
2271
|
}
|
|
2291
|
-
|
|
2272
|
+
const t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
|
|
2292
2273
|
if (t < 0 || t > 1) {
|
|
2293
2274
|
return undefined;
|
|
2294
2275
|
}
|
|
@@ -2304,7 +2285,7 @@ function intersectLine(plane, line) {
|
|
|
2304
2285
|
* @returns The projected point.
|
|
2305
2286
|
*/
|
|
2306
2287
|
function projectPoint(plane, point) {
|
|
2307
|
-
|
|
2288
|
+
const d = distanceToPoint(plane, point);
|
|
2308
2289
|
return add(point, scale$2(-d, plane.normal));
|
|
2309
2290
|
}
|
|
2310
2291
|
|
|
@@ -2324,9 +2305,8 @@ var plane = /*#__PURE__*/Object.freeze({
|
|
|
2324
2305
|
* @param value The values of the ray.
|
|
2325
2306
|
* @returns A new ray.
|
|
2326
2307
|
*/
|
|
2327
|
-
function create$1(value) {
|
|
2308
|
+
function create$1(value = {}) {
|
|
2328
2309
|
var _a, _b;
|
|
2329
|
-
if (value === void 0) { value = {}; }
|
|
2330
2310
|
return {
|
|
2331
2311
|
origin: (_a = value.origin) !== null && _a !== void 0 ? _a : origin(),
|
|
2332
2312
|
direction: (_b = value.direction) !== null && _b !== void 0 ? _b : forward(),
|
|
@@ -2352,13 +2332,13 @@ function at(ray, distance) {
|
|
|
2352
2332
|
* @returns The distance to the plane, or `undefined` if it cannot be computed.
|
|
2353
2333
|
*/
|
|
2354
2334
|
function distanceToPlane(ray, plane$1) {
|
|
2355
|
-
|
|
2335
|
+
const d = dot$1(plane$1.normal, ray.direction);
|
|
2356
2336
|
if (d === 0) {
|
|
2357
2337
|
// Ray is on plane.
|
|
2358
2338
|
return distanceToPoint(plane$1, ray.origin) === 0 ? 0 : undefined;
|
|
2359
2339
|
}
|
|
2360
2340
|
else {
|
|
2361
|
-
|
|
2341
|
+
const t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
|
|
2362
2342
|
// Checks if ray intersects plane.
|
|
2363
2343
|
return t >= 0 ? t : undefined;
|
|
2364
2344
|
}
|
|
@@ -2373,7 +2353,7 @@ function distanceToPlane(ray, plane$1) {
|
|
|
2373
2353
|
* intersect.
|
|
2374
2354
|
*/
|
|
2375
2355
|
function intersectPlane(ray, plane) {
|
|
2376
|
-
|
|
2356
|
+
const t = distanceToPlane(ray, plane);
|
|
2377
2357
|
return t != null ? at(ray, t) : undefined;
|
|
2378
2358
|
}
|
|
2379
2359
|
|
|
@@ -2389,9 +2369,8 @@ var ray = /*#__PURE__*/Object.freeze({
|
|
|
2389
2369
|
* Returns a new Vector4. If `value` is undefined, then `{x: 0, y: 0, z: 0,
|
|
2390
2370
|
* w: 0}` is returned.
|
|
2391
2371
|
*/
|
|
2392
|
-
function create(value) {
|
|
2393
|
-
|
|
2394
|
-
return tslib.__assign({ x: 0, y: 0, z: 0, w: 0 }, value);
|
|
2372
|
+
function create(value = {}) {
|
|
2373
|
+
return { x: 0, y: 0, z: 0, w: 0, ...value };
|
|
2395
2374
|
}
|
|
2396
2375
|
/**
|
|
2397
2376
|
* Parses a JSON string representation of a `Vector4`.
|
|
@@ -2400,10 +2379,10 @@ function create(value) {
|
|
|
2400
2379
|
* @returns A parsed `Vector4`.
|
|
2401
2380
|
*/
|
|
2402
2381
|
function fromJson(json) {
|
|
2403
|
-
|
|
2382
|
+
const obj = JSON.parse(json);
|
|
2404
2383
|
if (Array.isArray(obj)) {
|
|
2405
|
-
|
|
2406
|
-
return create({ x
|
|
2384
|
+
const [x, y, z, w] = obj;
|
|
2385
|
+
return create({ x, y, z, w });
|
|
2407
2386
|
}
|
|
2408
2387
|
else {
|
|
2409
2388
|
return create(obj);
|