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