@vertexvis/geometry 0.24.5-canary.4 → 1.0.0-testing.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/angle.d.ts +35 -35
  2. package/dist/boundingBox.d.ts +49 -49
  3. package/dist/boundingSphere.d.ts +14 -14
  4. package/dist/bundle.cjs.js +2148 -2148
  5. package/dist/bundle.cjs.js.map +1 -1
  6. package/dist/bundle.esm.js +2148 -2148
  7. package/dist/bundle.esm.js.map +1 -1
  8. package/dist/cdn/bundle.esm.js +2149 -2183
  9. package/dist/cdn/bundle.esm.js.map +1 -1
  10. package/dist/cdn/bundle.esm.min.js +1 -15
  11. package/dist/cdn/bundle.esm.min.js.map +1 -1
  12. package/dist/dimensions.d.ts +94 -94
  13. package/dist/euler.d.ts +57 -57
  14. package/dist/index.d.ts +21 -21
  15. package/dist/line3.d.ts +48 -48
  16. package/dist/math.d.ts +20 -20
  17. package/dist/matrix.d.ts +73 -73
  18. package/dist/matrix2.d.ts +29 -29
  19. package/dist/matrix4.d.ts +285 -285
  20. package/dist/plane.d.ts +51 -51
  21. package/dist/point.d.ts +80 -80
  22. package/dist/quaternion.d.ts +65 -65
  23. package/dist/ray.d.ts +52 -52
  24. package/dist/rectangle.d.ts +125 -125
  25. package/dist/vector3.d.ts +226 -226
  26. package/dist/vector4.d.ts +23 -23
  27. package/package.json +10 -10
  28. package/dist/cdn/__tests__/angle.test.d.ts +0 -1
  29. package/dist/cdn/__tests__/boundingBox.test.d.ts +0 -1
  30. package/dist/cdn/__tests__/boundingSphere.test.d.ts +0 -1
  31. package/dist/cdn/__tests__/dimensions.test.d.ts +0 -1
  32. package/dist/cdn/__tests__/euler.test.d.ts +0 -1
  33. package/dist/cdn/__tests__/line3.test.d.ts +0 -1
  34. package/dist/cdn/__tests__/math.spec.d.ts +0 -1
  35. package/dist/cdn/__tests__/matrix.test.d.ts +0 -1
  36. package/dist/cdn/__tests__/matrix2.test.d.ts +0 -1
  37. package/dist/cdn/__tests__/matrix4.test.d.ts +0 -1
  38. package/dist/cdn/__tests__/plane.test.d.ts +0 -1
  39. package/dist/cdn/__tests__/point.test.d.ts +0 -1
  40. package/dist/cdn/__tests__/quaternion.test.d.ts +0 -1
  41. package/dist/cdn/__tests__/ray.test.d.ts +0 -1
  42. package/dist/cdn/__tests__/rectangle.test.d.ts +0 -1
  43. package/dist/cdn/__tests__/vector3.test.d.ts +0 -1
  44. package/dist/cdn/__tests__/vector4.test.d.ts +0 -1
  45. package/dist/cdn/angle.d.ts +0 -35
  46. package/dist/cdn/boundingBox.d.ts +0 -49
  47. package/dist/cdn/boundingSphere.d.ts +0 -14
  48. package/dist/cdn/dimensions.d.ts +0 -94
  49. package/dist/cdn/euler.d.ts +0 -57
  50. package/dist/cdn/index.d.ts +0 -21
  51. package/dist/cdn/line3.d.ts +0 -48
  52. package/dist/cdn/math.d.ts +0 -20
  53. package/dist/cdn/matrix.d.ts +0 -73
  54. package/dist/cdn/matrix2.d.ts +0 -29
  55. package/dist/cdn/matrix4.d.ts +0 -285
  56. package/dist/cdn/plane.d.ts +0 -51
  57. package/dist/cdn/point.d.ts +0 -80
  58. package/dist/cdn/quaternion.d.ts +0 -65
  59. package/dist/cdn/ray.d.ts +0 -52
  60. package/dist/cdn/rectangle.d.ts +0 -125
  61. package/dist/cdn/vector3.d.ts +0 -226
  62. package/dist/cdn/vector4.d.ts +0 -23
@@ -1,173 +1,173 @@
1
1
  import { __assign, __spreadArray } from 'tslib';
2
2
 
3
- /**
4
- * Clamps the given value between `min` and `max`.
5
- *
6
- * @param value The value to clamp.
7
- * @param min The min possible value.
8
- * @param max The max possible value.
9
- * @returns `value` or a value clamped to `min` or `max`.
10
- */
11
- function clamp(value, min, max) {
12
- return Math.max(min, Math.min(max, value));
13
- }
14
- /**
15
- * Linear interpolates a value between `a` and `b` by `t`. If `t` is 0, then the
16
- * result will be `a`. If `t` is 1, then the result will be `b`. `t` will be
17
- * clamped to a value between 0 and 1.
18
- *
19
- * @param a The start value.
20
- * @param b The end value.
21
- * @param t The interpolation value between 0 and 1.
22
- * @returns The interpolated value between `a` and `b`.
23
- */
24
- function lerp$2(a, b, t) {
25
- t = clamp(t, 0, 1);
26
- return t * (b - a) + a;
3
+ /**
4
+ * Clamps the given value between `min` and `max`.
5
+ *
6
+ * @param value The value to clamp.
7
+ * @param min The min possible value.
8
+ * @param max The max possible value.
9
+ * @returns `value` or a value clamped to `min` or `max`.
10
+ */
11
+ function clamp(value, min, max) {
12
+ return Math.max(min, Math.min(max, value));
13
+ }
14
+ /**
15
+ * Linear interpolates a value between `a` and `b` by `t`. If `t` is 0, then the
16
+ * result will be `a`. If `t` is 1, then the result will be `b`. `t` will be
17
+ * clamped to a value between 0 and 1.
18
+ *
19
+ * @param a The start value.
20
+ * @param b The end value.
21
+ * @param t The interpolation value between 0 and 1.
22
+ * @returns The interpolated value between `a` and `b`.
23
+ */
24
+ function lerp$2(a, b, t) {
25
+ t = clamp(t, 0, 1);
26
+ return t * (b - a) + a;
27
27
  }
28
28
 
29
- /**
30
- * Returns a new `Point` with the given horizontal and vertical position.
31
- */
32
- function create$d(x, y) {
33
- if (x === void 0) { x = 0; }
34
- if (y === void 0) { y = 0; }
35
- return { x: x, y: y };
36
- }
37
- /**
38
- * Converts a polar coordinate (length and angle) into a Cartesian coordinate.
39
- */
40
- function polar(length, radians) {
41
- var x = Math.cos(radians) * length;
42
- var y = Math.sin(radians) * length;
43
- return create$d(x, y);
44
- }
45
- /**
46
- * Returns the distance between two points.
47
- */
48
- function distance$2(a, b) {
49
- var delta = subtract$1(a, b);
50
- return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
51
- }
52
- /**
53
- * Returns a new `Point` where `b` is subtracted from `a`.
54
- */
55
- function subtract$1(a, b) {
56
- return { x: a.x - b.x, y: a.y - b.y };
57
- }
58
- /**
59
- * Returns a new `Point` where `b` is added to `a`.
60
- */
61
- function add$1(a, b) {
62
- return { x: a.x + b.x, y: a.y + b.y };
63
- }
64
- /**
65
- * Returns `true` if the `x` and `y` positions of `a` and `b` are equal.
66
- */
67
- function isEqual$3(a, b) {
68
- return a.x === b.x && a.y === b.y;
69
- }
70
- /**
71
- * Performs a linear interpolation between `a` and `b` and returns the result.
72
- * The value of `t` is clamped between `[0, 1]`.
73
- *
74
- * @param a The start value.
75
- * @param b The end value.
76
- * @param t A value between 0 and 1.
77
- * @returns A point between `a` and `b`.
78
- */
79
- function lerp$1(a, b, t) {
80
- return {
81
- x: lerp$2(a.x, b.x, t),
82
- y: lerp$2(a.y, b.y, t),
83
- };
84
- }
85
- /**
86
- * Returns a new `Point` where `x` and `y` are inverted.
87
- */
88
- function negate$1(pt) {
89
- return create$d(-pt.x, -pt.y);
90
- }
91
- /**
92
- * Returns a new `Point` where `x` and `y` are multiplied by the given scale
93
- * factors.
94
- */
95
- function scale$5(pt, scaleX, scaleY) {
96
- return {
97
- x: pt.x * scaleX,
98
- y: pt.y * scaleY,
99
- };
100
- }
101
- /**
102
- * Returns a new `Point` where `x` and `y` are multiplied by the given scale
103
- * factor.
104
- */
105
- function scaleProportional(pt, scale) {
106
- return {
107
- x: pt.x * scale,
108
- y: pt.y * scale,
109
- };
110
- }
111
- /**
112
- * Returns the magnitude of a point.
113
- */
114
- function magnitude$2(pt) {
115
- return Math.sqrt(pt.x * pt.x + pt.y * pt.y);
116
- }
117
- /**
118
- * Transforms a vector into the corresponding normal (unit) vector.
119
- */
120
- function normalizeVector(pt) {
121
- var magnitudeOfPoint = magnitude$2(pt);
122
- if (magnitudeOfPoint === 0) {
123
- return create$d(0, 0);
124
- }
125
- else {
126
- return scaleProportional(pt, 1 / magnitudeOfPoint);
127
- }
128
- }
129
- /**
130
- * Returns a new normal (unit) vector pointing between the two given points.
131
- */
132
- function normalDirectionVector(ptA, ptB) {
133
- return normalizeVector(subtract$1(ptB, ptA));
134
- }
135
- /**
136
- * Returns a vector orthogonal to the vector between the two given points.
137
- */
138
- function orthogonalVector(ptA, ptB) {
139
- var unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
140
- // Handle vectors that are parallel to the x or y axis
141
- if (unitVectorBetweenPoints.x === 0 || unitVectorBetweenPoints.y === 0) {
142
- return create$d(-1 * unitVectorBetweenPoints.y, unitVectorBetweenPoints.x);
143
- }
144
- if (Math.abs(unitVectorBetweenPoints.x) > Math.abs(unitVectorBetweenPoints.y)) {
145
- var vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
146
- var vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
147
- return normalizeVector(create$d(vectorXValue, vectorYValue));
148
- }
149
- else {
150
- var vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
151
- var vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
152
- return normalizeVector(create$d(vectorXValue, vectorYValue));
153
- }
154
- }
155
- /**
156
- * Parses a JSON string representation of a Point and returns an object.
157
- *
158
- * @param json A JSON string, either in the form `[x,y]` or `{"x": 0, "y": 0}`
159
- * @returns A parsed Point.
160
- */
161
- function fromJson$5(json) {
162
- var obj = JSON.parse(json);
163
- if (Array.isArray(obj)) {
164
- var x = obj[0], y = obj[1];
165
- return create$d(x, y);
166
- }
167
- else {
168
- var x = obj.x, y = obj.y;
169
- return create$d(x, y);
170
- }
29
+ /**
30
+ * Returns a new `Point` with the given horizontal and vertical position.
31
+ */
32
+ function create$d(x, y) {
33
+ if (x === void 0) { x = 0; }
34
+ if (y === void 0) { y = 0; }
35
+ return { x: x, y: y };
36
+ }
37
+ /**
38
+ * Converts a polar coordinate (length and angle) into a Cartesian coordinate.
39
+ */
40
+ function polar(length, radians) {
41
+ var x = Math.cos(radians) * length;
42
+ var y = Math.sin(radians) * length;
43
+ return create$d(x, y);
44
+ }
45
+ /**
46
+ * Returns the distance between two points.
47
+ */
48
+ function distance$2(a, b) {
49
+ var delta = subtract$1(a, b);
50
+ return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
51
+ }
52
+ /**
53
+ * Returns a new `Point` where `b` is subtracted from `a`.
54
+ */
55
+ function subtract$1(a, b) {
56
+ return { x: a.x - b.x, y: a.y - b.y };
57
+ }
58
+ /**
59
+ * Returns a new `Point` where `b` is added to `a`.
60
+ */
61
+ function add$1(a, b) {
62
+ return { x: a.x + b.x, y: a.y + b.y };
63
+ }
64
+ /**
65
+ * Returns `true` if the `x` and `y` positions of `a` and `b` are equal.
66
+ */
67
+ function isEqual$3(a, b) {
68
+ return a.x === b.x && a.y === b.y;
69
+ }
70
+ /**
71
+ * Performs a linear interpolation between `a` and `b` and returns the result.
72
+ * The value of `t` is clamped between `[0, 1]`.
73
+ *
74
+ * @param a The start value.
75
+ * @param b The end value.
76
+ * @param t A value between 0 and 1.
77
+ * @returns A point between `a` and `b`.
78
+ */
79
+ function lerp$1(a, b, t) {
80
+ return {
81
+ x: lerp$2(a.x, b.x, t),
82
+ y: lerp$2(a.y, b.y, t),
83
+ };
84
+ }
85
+ /**
86
+ * Returns a new `Point` where `x` and `y` are inverted.
87
+ */
88
+ function negate$1(pt) {
89
+ return create$d(-pt.x, -pt.y);
90
+ }
91
+ /**
92
+ * Returns a new `Point` where `x` and `y` are multiplied by the given scale
93
+ * factors.
94
+ */
95
+ function scale$5(pt, scaleX, scaleY) {
96
+ return {
97
+ x: pt.x * scaleX,
98
+ y: pt.y * scaleY,
99
+ };
100
+ }
101
+ /**
102
+ * Returns a new `Point` where `x` and `y` are multiplied by the given scale
103
+ * factor.
104
+ */
105
+ function scaleProportional(pt, scale) {
106
+ return {
107
+ x: pt.x * scale,
108
+ y: pt.y * scale,
109
+ };
110
+ }
111
+ /**
112
+ * Returns the magnitude of a point.
113
+ */
114
+ function magnitude$2(pt) {
115
+ return Math.sqrt(pt.x * pt.x + pt.y * pt.y);
116
+ }
117
+ /**
118
+ * Transforms a vector into the corresponding normal (unit) vector.
119
+ */
120
+ function normalizeVector(pt) {
121
+ var magnitudeOfPoint = magnitude$2(pt);
122
+ if (magnitudeOfPoint === 0) {
123
+ return create$d(0, 0);
124
+ }
125
+ else {
126
+ return scaleProportional(pt, 1 / magnitudeOfPoint);
127
+ }
128
+ }
129
+ /**
130
+ * Returns a new normal (unit) vector pointing between the two given points.
131
+ */
132
+ function normalDirectionVector(ptA, ptB) {
133
+ return normalizeVector(subtract$1(ptB, ptA));
134
+ }
135
+ /**
136
+ * Returns a vector orthogonal to the vector between the two given points.
137
+ */
138
+ function orthogonalVector(ptA, ptB) {
139
+ var unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
140
+ // Handle vectors that are parallel to the x or y axis
141
+ if (unitVectorBetweenPoints.x === 0 || unitVectorBetweenPoints.y === 0) {
142
+ return create$d(-1 * unitVectorBetweenPoints.y, unitVectorBetweenPoints.x);
143
+ }
144
+ if (Math.abs(unitVectorBetweenPoints.x) > Math.abs(unitVectorBetweenPoints.y)) {
145
+ var vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
146
+ var vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
147
+ return normalizeVector(create$d(vectorXValue, vectorYValue));
148
+ }
149
+ else {
150
+ var vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
151
+ var vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
152
+ return normalizeVector(create$d(vectorXValue, vectorYValue));
153
+ }
154
+ }
155
+ /**
156
+ * Parses a JSON string representation of a Point and returns an object.
157
+ *
158
+ * @param json A JSON string, either in the form `[x,y]` or `{"x": 0, "y": 0}`
159
+ * @returns A parsed Point.
160
+ */
161
+ function fromJson$5(json) {
162
+ var obj = JSON.parse(json);
163
+ if (Array.isArray(obj)) {
164
+ var x = obj[0], y = obj[1];
165
+ return create$d(x, y);
166
+ }
167
+ else {
168
+ var x = obj.x, y = obj.y;
169
+ return create$d(x, y);
170
+ }
171
171
  }
172
172
 
173
173
  var point = /*#__PURE__*/Object.freeze({
@@ -189,54 +189,54 @@ var point = /*#__PURE__*/Object.freeze({
189
189
  fromJson: fromJson$5
190
190
  });
191
191
 
192
- /**
193
- * Returns an `Angle` between two points, in radians.
194
- *
195
- * @param a The starting point.
196
- * @param b The ending point.
197
- * @returns An angle in radians.
198
- */
199
- function fromPoints$1(a, b) {
200
- var delta = subtract$1(b, a);
201
- var theta = Math.atan2(delta.y, delta.x);
202
- return theta;
203
- }
204
- /**
205
- * Returns an `Angle` between two points, in degrees.
206
- *
207
- * An angle of 0 represents an upward vector, and increases in a clockwise
208
- * direction.
209
- *
210
- * @deprecated Use {@link fromPoints} instead.
211
- */
212
- function fromPointsInDegrees(a, b) {
213
- var delta = subtract$1(b, a);
214
- var theta = Math.atan2(delta.y, delta.x);
215
- return normalize$2(toDegrees(theta) - 270);
216
- }
217
- /**
218
- * Normalizes the given angle, in degrees, to a number greater than or equal to 0 and less than 360.
219
- */
220
- function normalize$2(degrees) {
221
- return (degrees + 3600) % 360;
222
- }
223
- /**
224
- * Normalizes the given angle, in radians, to a number greater than or equal to 0 and less than 2 PI.
225
- */
226
- function normalizeRadians(radians) {
227
- return toRadians(normalize$2(toDegrees(radians)));
228
- }
229
- /**
230
- * Converts the given radians to degrees.
231
- */
232
- function toDegrees(radians) {
233
- return radians * (180 / Math.PI);
234
- }
235
- /**
236
- * Converts the given degrees to radians.
237
- */
238
- function toRadians(degrees) {
239
- return degrees * (Math.PI / 180);
192
+ /**
193
+ * Returns an `Angle` between two points, in radians.
194
+ *
195
+ * @param a The starting point.
196
+ * @param b The ending point.
197
+ * @returns An angle in radians.
198
+ */
199
+ function fromPoints$1(a, b) {
200
+ var delta = subtract$1(b, a);
201
+ var theta = Math.atan2(delta.y, delta.x);
202
+ return theta;
203
+ }
204
+ /**
205
+ * Returns an `Angle` between two points, in degrees.
206
+ *
207
+ * An angle of 0 represents an upward vector, and increases in a clockwise
208
+ * direction.
209
+ *
210
+ * @deprecated Use {@link fromPoints} instead.
211
+ */
212
+ function fromPointsInDegrees(a, b) {
213
+ var delta = subtract$1(b, a);
214
+ var theta = Math.atan2(delta.y, delta.x);
215
+ return normalize$2(toDegrees(theta) - 270);
216
+ }
217
+ /**
218
+ * Normalizes the given angle, in degrees, to a number greater than or equal to 0 and less than 360.
219
+ */
220
+ function normalize$2(degrees) {
221
+ return (degrees + 3600) % 360;
222
+ }
223
+ /**
224
+ * Normalizes the given angle, in radians, to a number greater than or equal to 0 and less than 2 PI.
225
+ */
226
+ function normalizeRadians(radians) {
227
+ return toRadians(normalize$2(toDegrees(radians)));
228
+ }
229
+ /**
230
+ * Converts the given radians to degrees.
231
+ */
232
+ function toDegrees(radians) {
233
+ return radians * (180 / Math.PI);
234
+ }
235
+ /**
236
+ * Converts the given degrees to radians.
237
+ */
238
+ function toRadians(degrees) {
239
+ return degrees * (Math.PI / 180);
240
240
  }
241
241
 
242
242
  var angle = /*#__PURE__*/Object.freeze({
@@ -249,527 +249,527 @@ var angle = /*#__PURE__*/Object.freeze({
249
249
  toRadians: toRadians
250
250
  });
251
251
 
252
- /**
253
- * Creates a 4x4 matrix from a set of row-major components.
254
- */
255
- function fromValues(
256
- /* eslint-disable prettier/prettier */
257
- m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
258
- /* eslint-disable prettier/prettier */
259
- return [
260
- m11, m21, m31, m41,
261
- m12, m22, m32, m42,
262
- m13, m23, m33, m43,
263
- m14, m24, m34, m44,
264
- ];
265
- /* eslint-enable prettier/prettier */
266
- }
267
- /**
268
- * Creates a `Matrix4` from an object representation.
269
- */
270
- function fromObject(obj) {
271
- /* eslint-disable prettier/prettier */
272
- return fromValues(obj.m11, obj.m12, obj.m13, obj.m14, obj.m21, obj.m22, obj.m23, obj.m24, obj.m31, obj.m32, obj.m33, obj.m34, obj.m41, obj.m42, obj.m43, obj.m44);
273
- /* eslint-enable prettier/prettier */
274
- }
275
- /**
276
- * Returns a new [identity matrix](https://en.wikipedia.org/wiki/Identity_matrix).
277
- */
278
- function makeIdentity() {
279
- return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
280
- }
281
- /**
282
- * Returns a matrix with all values as 0.
283
- */
284
- function makeZero() {
285
- return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
286
- }
287
- /**
288
- * Creates a translation matrix.
289
- *
290
- * ```
291
- * 1, 0, 0, 0,
292
- * 0, 1, 0, 0,
293
- * 0, 0, 1, 0,
294
- * x, y, z, 1
295
- * ```
296
- *
297
- * @param translation A vector representing the translation components.
298
- * @returns A translation matrix.
299
- */
300
- function makeTranslation(translation) {
301
- var x = translation.x, y = translation.y, z = translation.z;
302
- /* eslint-disable prettier/prettier */
303
- return [
304
- 1, 0, 0, 0,
305
- 0, 1, 0, 0,
306
- 0, 0, 1, 0,
307
- x, y, z, 1,
308
- ];
309
- /* eslint-enable prettier/prettier */
310
- }
311
- /**
312
- * Creates a rotation matrix.
313
- *
314
- * ```
315
- * 1-2y²-2z², 2xy-2zw, 2xz+2yw, 0,
316
- * 2xy+2zw, 1-2x²-2z², 2yz-2xw, 0,
317
- * 2xz-2yw, 2yz+2xw, 1-2x²-2y², 0,
318
- * 0, 0, 0, 1,
319
- * ```
320
- *
321
- * @param rotation A quaternion representing the rotation.
322
- * @see https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion
323
- * @returns A rotation matrix.
324
- */
325
- function makeRotation(rotation) {
326
- var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
327
- var x2 = x + x, y2 = y + y, z2 = z + z;
328
- var xx = x * x2, xy = x * y2, xz = x * z2;
329
- var yy = y * y2, yz = y * z2, zz = z * z2;
330
- var wx = w * x2, wy = w * y2, wz = w * z2;
331
- /* eslint-disable prettier/prettier */
332
- return [
333
- 1 - (yy + zz), xy + wz, xz - wy, 0,
334
- xy - wz, 1 - (xx + zz), yz + wx, 0,
335
- xz + wy, yz - wx, 1 - (xx + yy), 0,
336
- 0, 0, 0, 1
337
- ];
338
- /* eslint-enable prettier/prettier */
339
- }
340
- /**
341
- * Creates a scale matrix.
342
- *
343
- * ```
344
- * x, 0, 0, 0,
345
- * 0, y, 0, 0,
346
- * 0, 0, z, 0,
347
- * 0, 0, 0, 1
348
- * ```
349
- *
350
- * @param scale A vector representing the different scale components.
351
- * @returns A scale matrix.
352
- */
353
- function makeScale(scale) {
354
- var x = scale.x, y = scale.y, z = scale.z;
355
- /* eslint-disable prettier/prettier */
356
- return [
357
- x, 0, 0, 0,
358
- 0, y, 0, 0,
359
- 0, 0, z, 0,
360
- 0, 0, 0, 1,
361
- ];
362
- /* eslint-enable prettier/prettier */
363
- }
364
- /**
365
- * Creates a matrix that has translation, rotation and scale applied to it.
366
- *
367
- * @param translation The translation applied to the matrix.
368
- * @param rotation The rotation applied to the matrix.
369
- * @param scale The scale applied to the matrix.
370
- * @returns A transformed matrix.
371
- */
372
- function makeTRS(translation, rotation, scale) {
373
- var t = makeTranslation(translation);
374
- var r = makeRotation(rotation);
375
- var s = makeScale(scale);
376
- return multiply$2(multiply$2(t, r), s);
377
- }
378
- /**
379
- * Returns a matrix that has the basis components (upper left 3x3 matrix) set to
380
- * the following x, y, and z axis.
381
- *
382
- * ```
383
- * x.x y.x z.x 0
384
- * x.y y.y z.y 0
385
- * x.z y.z z.z 0
386
- * 0 0 0 0
387
- * ```
388
- *
389
- * @param x The x axis to set.
390
- * @param y The y axis to set.
391
- * @param z The z axis to set.
392
- * @returns A matrix with its basis components populated.
393
- */
394
- function makeBasis(x, y, z) {
395
- /* eslint-disable prettier/prettier */
396
- return [
397
- x.x, x.y, x.z, 0,
398
- y.x, y.y, y.z, 0,
399
- z.x, z.y, z.z, 0,
400
- 0, 0, 0, 1
401
- ];
402
- /* eslint-enable prettier/prettier */
403
- }
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
- /**
429
- * Creates a matrix used for [perspective
430
- * projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
431
- *
432
- * The viewing volume is frustum-shaped and defined by the six parameters. Left,
433
- * right, top, and bottom specify coordinates in the near clipping plane where
434
- * the frustum edges intersect it, and the near and far parameters define the
435
- * forward distances of the view volume. The resulting volume can be vertically
436
- * and horizontally asymmetrical around the center of the near plane.
437
- *
438
- * @param left The left coordinate at the near plane.
439
- * @param right The right coordinate at the near plane.
440
- * @param top The top coordinate at the near plane.
441
- * @param bottom The bottom coordinate at the near plane.
442
- * @param near The near distance.
443
- * @param far The far distance.
444
- * @returns A matrix representing a view frustum.
445
- */
446
- function makeFrustum(left, right, top, bottom, near, far) {
447
- var x = (2 * near) / (right - left);
448
- var y = (2 * near) / (top - bottom);
449
- var a = (right + left) / (right - left);
450
- var b = (top + bottom) / (top - bottom);
451
- var c = -(far + near) / (far - near);
452
- var d = (-2 * far * near) / (far - near);
453
- /* eslint-disable prettier/prettier */
454
- return [
455
- x, 0, 0, 0,
456
- 0, y, 0, 0,
457
- a, b, c, -1,
458
- 0, 0, d, 0
459
- ];
460
- /* eslint-enable prettier/prettier */
461
- }
462
- /**
463
- * Creates a perspective projection matrix.
464
- *
465
- * Related to: gluPerspective. The viewing volume is frustum-shaped amd defined
466
- * by the four parameters. The fovy and aspect ratio are used to compute the
467
- * positions of the left, right, top, and bottom sides of the viewing volume in
468
- * the zNear plane. The fovy is the y field-of-view, the angle made by the top
469
- * and bottom sides of frustum if they were to intersect. The aspect ratio is
470
- * the width of the frustum divided by its height. Note that the resulting
471
- * volume is both vertically and horizontally symmetrical around the center of
472
- * the near plane.
473
- *
474
- * @param near The near Z value.
475
- * @param far The far Z value.
476
- * @param fovY The field of view.
477
- * @param aspect The aspect ratio.
478
- * @returns A matrix.
479
- */
480
- function makePerspective(near, far, fovY, aspect) {
481
- var ymax = near * Math.tan(toRadians(fovY / 2.0));
482
- var xmax = ymax * aspect;
483
- var left = -xmax;
484
- var right = xmax;
485
- var top = ymax;
486
- var bottom = -ymax;
487
- return makeFrustum(left, right, top, bottom, near, far);
488
- }
489
- /**
490
- * Creates an orthographic projection matrix.
491
- *
492
- * Related to: gluOrtho. The viewing volume is cube-shaped and defined by
493
- * the six parameters. The left and right values represent the coordinates of
494
- * the vertical clipping planes, top and bottom values represent the coordinates
495
- * of the horizontal clipping planes, and near and far values represent the
496
- * coordinates of the depth clipping planes.
497
- *
498
- * @param left The coordinate of the left horizontal clipping plane.
499
- * @param right The coordinate of the right horizontal clipping plane.
500
- * @param bottom The coordinate of the bottom vertical clipping plane.
501
- * @param top The coordinate of the top vertical clipping plane.
502
- * @param near The coordinate of the near depth clipping plane.
503
- * @param far The coordinate of the far depth clipping plane.
504
- * @returns A matrix.
505
- */
506
- function makeOrthographic(left, right, bottom, top, near, far) {
507
- var w = 1.0 / (right - left);
508
- var h = 1.0 / (top - bottom);
509
- var d = 1.0 / (far - near);
510
- var x = (right + left) * w;
511
- var y = (top + bottom) * h;
512
- var z = (far + near) * d;
513
- /* eslint-disable prettier/prettier */
514
- return [
515
- 2 * w, 0, 0, -x,
516
- 0, 2 * h, 0, -y,
517
- 0, 0, -2 * d, -z,
518
- 0, 0, 0, 1
519
- ];
520
- /* eslint-enable prettier/prettier */
521
- }
522
- /**
523
- * Matrix becomes a combination of an inverse translation and rotation.
524
- *
525
- * Related to: gluLookAt. This creates the inverse of makeLookAtMatrix. The
526
- * matrix will be an opposite translation from the 'eye' position, and it will
527
- * rotate things in the opposite direction of the eye-to-center orientation.
528
- * This is definitely confusing, but the main reason to use this transform is to
529
- * set up a view matrix for a camera that's looking at a certain point. To
530
- * achieve the effect of moving the camera somewhere and rotating it so that it
531
- * points at something, the rest of the world is moved in the opposite direction
532
- * and rotated in the opposite way around the camera. This way, you get the same
533
- * effect as moving the actual camera, but all the projection math can still be
534
- * done with the camera positioned at the origin (which makes it way simpler).
535
- *
536
- * @param position The position of the object.
537
- * @param lookAt The point which the object is looking at.
538
- * @param up The direction which the object considers up.
539
- * @returns A matrix.
540
- */
541
- function makeLookAtView(position, lookAt, up) {
542
- var z = normalize(subtract(position, lookAt));
543
- var x = normalize(cross(up, z));
544
- var y = cross(z, x);
545
- var dotX = -dot$1(x, position);
546
- var dotY = -dot$1(y, position);
547
- var dotZ = -dot$1(z, position);
548
- /* eslint-disable prettier/prettier */
549
- return [
550
- x.x, y.x, z.x, 0,
551
- x.y, y.y, z.y, 0,
552
- x.z, y.z, z.z, 0,
553
- dotX, dotY, dotZ, 1,
554
- ];
555
- /* eslint-enable prettier/prettier */
556
- }
557
- /**
558
- * Matrix becomes a combination of translation and rotation.
559
- *
560
- * Matrix becomes a combination of a translation to the position of 'eye' and a
561
- * rotation matrix which orients an object to point towards 'center' along its
562
- * z-axis. Use this function if you want an object to look at a point from
563
- * another point in space.
564
- *
565
- * @param position The position of the object.
566
- * @param lookAt The point which the object is looking at.
567
- * @param up The direction which the object considers up.
568
- * @returns A matrix.
569
- */
570
- function makeLookAt(position, lookAt, up) {
571
- var z = normalize(subtract(position, lookAt));
572
- var x = normalize(cross(up, z));
573
- var y = cross(z, x);
574
- /* eslint-disable prettier/prettier */
575
- return [
576
- x.x, x.y, x.z, 0,
577
- y.x, y.y, y.z, 0,
578
- z.x, z.y, z.z, 0,
579
- position.x, position.y, position.z, 1
580
- ];
581
- /* eslint-enable prettier/prettier */
582
- }
583
- /**
584
- * Returns the inverse of the given matrix. If the determinate of the matrix is
585
- * zero, then a zero matrix is returned.
586
- */
587
- function invert(matrix) {
588
- var a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
589
- var a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
590
- var a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
591
- var a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
592
- var b00 = a00 * a11 - a01 * a10;
593
- var b01 = a00 * a12 - a02 * a10;
594
- var b02 = a00 * a13 - a03 * a10;
595
- var b03 = a01 * a12 - a02 * a11;
596
- var b04 = a01 * a13 - a03 * a11;
597
- var b05 = a02 * a13 - a03 * a12;
598
- var b06 = a20 * a31 - a21 * a30;
599
- var b07 = a20 * a32 - a22 * a30;
600
- var b08 = a20 * a33 - a23 * a30;
601
- var b09 = a21 * a32 - a22 * a31;
602
- var b10 = a21 * a33 - a23 * a31;
603
- var b11 = a22 * a33 - a23 * a32;
604
- // Calculate the determinant
605
- var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
606
- if (!det) {
607
- return makeZero();
608
- }
609
- det = 1.0 / det;
610
- return [
611
- (a11 * b11 - a12 * b10 + a13 * b09) * det,
612
- (a02 * b10 - a01 * b11 - a03 * b09) * det,
613
- (a31 * b05 - a32 * b04 + a33 * b03) * det,
614
- (a22 * b04 - a21 * b05 - a23 * b03) * det,
615
- (a12 * b08 - a10 * b11 - a13 * b07) * det,
616
- (a00 * b11 - a02 * b08 + a03 * b07) * det,
617
- (a32 * b02 - a30 * b05 - a33 * b01) * det,
618
- (a20 * b05 - a22 * b02 + a23 * b01) * det,
619
- (a10 * b10 - a11 * b08 + a13 * b06) * det,
620
- (a01 * b08 - a00 * b10 - a03 * b06) * det,
621
- (a30 * b04 - a31 * b02 + a33 * b00) * det,
622
- (a21 * b02 - a20 * b04 - a23 * b00) * det,
623
- (a11 * b07 - a10 * b09 - a12 * b06) * det,
624
- (a00 * b09 - a01 * b07 + a02 * b06) * det,
625
- (a31 * b01 - a30 * b03 - a32 * b00) * det,
626
- (a20 * b03 - a21 * b01 + a22 * b00) * det,
627
- ];
628
- }
629
- /**
630
- * Returns a rotation matrix looking from position towards target and oriented
631
- * by an up vector.
632
- *
633
- * @param m The matrix to transform.
634
- * @param position The point from which to look at target.
635
- * @param target The point to look at.
636
- * @param up The orientation.
637
- * @returns A rotation matrix.
638
- */
639
- function lookAt(m, position, target, up) {
640
- var z = subtract(position, target);
641
- if (magnitudeSquared(z) === 0) {
642
- z = __assign(__assign({}, z), { z: 1 });
643
- }
644
- z = normalize(z);
645
- var x = cross(up, z);
646
- if (magnitudeSquared(x) === 0) {
647
- if (Math.abs(up.z) === 1) {
648
- z = __assign(__assign({}, z), { x: z.x + 0.0001 });
649
- }
650
- else {
651
- z = __assign(__assign({}, z), { z: z.z + 0.0001 });
652
- }
653
- z = normalize(z);
654
- x = cross(up, z);
655
- }
656
- x = normalize(x);
657
- var y = cross(z, x);
658
- var res = __spreadArray([], m, true);
659
- /* eslint-disable prettier/prettier */
660
- res[0] = x.x;
661
- res[4] = y.x;
662
- res[8] = z.x;
663
- res[1] = x.y;
664
- res[5] = y.y;
665
- res[9] = z.y;
666
- res[2] = x.z;
667
- res[6] = y.z;
668
- res[10] = z.z;
669
- /* eslint-enable prettier/prettier */
670
- return res;
671
- }
672
- /**
673
- * Returns a post-multiplied matrix.
674
- */
675
- function multiply$2(a, b) {
676
- var ae = a;
677
- var be = b;
678
- var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
679
- var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
680
- var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
681
- var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
682
- var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
683
- var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
684
- var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
685
- var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
686
- var mat = makeIdentity();
687
- mat[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
688
- mat[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
689
- mat[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
690
- mat[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
691
- mat[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
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;
704
- }
705
- /**
706
- * Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
707
- * matrix.
708
- */
709
- function transpose(matrix) {
710
- /* eslint-disable prettier/prettier */
711
- return [
712
- matrix[0], matrix[4], matrix[8], matrix[12],
713
- matrix[1], matrix[5], matrix[9], matrix[13],
714
- matrix[2], matrix[6], matrix[10], matrix[14],
715
- matrix[3], matrix[7], matrix[11], matrix[15],
716
- ];
717
- /* eslint-enable prettier/prettier */
718
- }
719
- /**
720
- * Multiplies the columns of a matrix by the given vector.
721
- */
722
- function scale$4(matrix, scale) {
723
- var x = scale.x, y = scale.y, z = scale.z;
724
- var m = __spreadArray([], matrix, true);
725
- /* eslint-disable prettier/prettier */
726
- m[0] *= x;
727
- m[4] *= y;
728
- m[8] *= z;
729
- m[1] *= x;
730
- m[5] *= y;
731
- m[9] *= z;
732
- m[2] *= x;
733
- m[6] *= y;
734
- m[10] *= z;
735
- m[3] *= x;
736
- m[7] *= y;
737
- m[11] *= z;
738
- /* eslint-enable prettier/prettier */
739
- return m;
740
- }
741
- function position(matrix, other) {
742
- var m = __spreadArray([], matrix, true);
743
- m[12] = other[12];
744
- m[13] = other[13];
745
- m[14] = other[14];
746
- return m;
747
- }
748
- /**
749
- * Returns true if the matrix is an identity matrix.
750
- */
751
- function isIdentity(matrix) {
752
- var identity = makeIdentity();
753
- return matrix.every(function (v, i) { return v === identity[i]; });
754
- }
755
- /**
756
- * Returns an object representation of a `Matrix4`.
757
- */
758
- function toObject(m) {
759
- /* eslint-disable prettier/prettier */
760
- return {
761
- m11: m[0], m12: m[4], m13: m[8], m14: m[12],
762
- m21: m[1], m22: m[5], m23: m[9], m24: m[13],
763
- m31: m[2], m32: m[6], m33: m[10], m34: m[14],
764
- m41: m[3], m42: m[7], m43: m[11], m44: m[15],
765
- };
766
- /* eslint-enable prettier/prettier */
767
- }
768
- /**
769
- * A type guard to check if `obj` is of type `Matrix4`.
770
- */
771
- function isType$2(obj) {
772
- return Array.isArray(obj) && obj.length === 16;
252
+ /**
253
+ * Creates a 4x4 matrix from a set of row-major components.
254
+ */
255
+ function fromValues(
256
+ /* eslint-disable prettier/prettier */
257
+ m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
258
+ /* eslint-disable prettier/prettier */
259
+ return [
260
+ m11, m21, m31, m41,
261
+ m12, m22, m32, m42,
262
+ m13, m23, m33, m43,
263
+ m14, m24, m34, m44,
264
+ ];
265
+ /* eslint-enable prettier/prettier */
266
+ }
267
+ /**
268
+ * Creates a `Matrix4` from an object representation.
269
+ */
270
+ function fromObject(obj) {
271
+ /* eslint-disable prettier/prettier */
272
+ return fromValues(obj.m11, obj.m12, obj.m13, obj.m14, obj.m21, obj.m22, obj.m23, obj.m24, obj.m31, obj.m32, obj.m33, obj.m34, obj.m41, obj.m42, obj.m43, obj.m44);
273
+ /* eslint-enable prettier/prettier */
274
+ }
275
+ /**
276
+ * Returns a new [identity matrix](https://en.wikipedia.org/wiki/Identity_matrix).
277
+ */
278
+ function makeIdentity() {
279
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
280
+ }
281
+ /**
282
+ * Returns a matrix with all values as 0.
283
+ */
284
+ function makeZero() {
285
+ return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
286
+ }
287
+ /**
288
+ * Creates a translation matrix.
289
+ *
290
+ * ```
291
+ * 1, 0, 0, 0,
292
+ * 0, 1, 0, 0,
293
+ * 0, 0, 1, 0,
294
+ * x, y, z, 1
295
+ * ```
296
+ *
297
+ * @param translation A vector representing the translation components.
298
+ * @returns A translation matrix.
299
+ */
300
+ function makeTranslation(translation) {
301
+ var x = translation.x, y = translation.y, z = translation.z;
302
+ /* eslint-disable prettier/prettier */
303
+ return [
304
+ 1, 0, 0, 0,
305
+ 0, 1, 0, 0,
306
+ 0, 0, 1, 0,
307
+ x, y, z, 1,
308
+ ];
309
+ /* eslint-enable prettier/prettier */
310
+ }
311
+ /**
312
+ * Creates a rotation matrix.
313
+ *
314
+ * ```
315
+ * 1-2y²-2z², 2xy-2zw, 2xz+2yw, 0,
316
+ * 2xy+2zw, 1-2x²-2z², 2yz-2xw, 0,
317
+ * 2xz-2yw, 2yz+2xw, 1-2x²-2y², 0,
318
+ * 0, 0, 0, 1,
319
+ * ```
320
+ *
321
+ * @param rotation A quaternion representing the rotation.
322
+ * @see https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion
323
+ * @returns A rotation matrix.
324
+ */
325
+ function makeRotation(rotation) {
326
+ var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
327
+ var x2 = x + x, y2 = y + y, z2 = z + z;
328
+ var xx = x * x2, xy = x * y2, xz = x * z2;
329
+ var yy = y * y2, yz = y * z2, zz = z * z2;
330
+ var wx = w * x2, wy = w * y2, wz = w * z2;
331
+ /* eslint-disable prettier/prettier */
332
+ return [
333
+ 1 - (yy + zz), xy + wz, xz - wy, 0,
334
+ xy - wz, 1 - (xx + zz), yz + wx, 0,
335
+ xz + wy, yz - wx, 1 - (xx + yy), 0,
336
+ 0, 0, 0, 1
337
+ ];
338
+ /* eslint-enable prettier/prettier */
339
+ }
340
+ /**
341
+ * Creates a scale matrix.
342
+ *
343
+ * ```
344
+ * x, 0, 0, 0,
345
+ * 0, y, 0, 0,
346
+ * 0, 0, z, 0,
347
+ * 0, 0, 0, 1
348
+ * ```
349
+ *
350
+ * @param scale A vector representing the different scale components.
351
+ * @returns A scale matrix.
352
+ */
353
+ function makeScale(scale) {
354
+ var x = scale.x, y = scale.y, z = scale.z;
355
+ /* eslint-disable prettier/prettier */
356
+ return [
357
+ x, 0, 0, 0,
358
+ 0, y, 0, 0,
359
+ 0, 0, z, 0,
360
+ 0, 0, 0, 1,
361
+ ];
362
+ /* eslint-enable prettier/prettier */
363
+ }
364
+ /**
365
+ * Creates a matrix that has translation, rotation and scale applied to it.
366
+ *
367
+ * @param translation The translation applied to the matrix.
368
+ * @param rotation The rotation applied to the matrix.
369
+ * @param scale The scale applied to the matrix.
370
+ * @returns A transformed matrix.
371
+ */
372
+ function makeTRS(translation, rotation, scale) {
373
+ var t = makeTranslation(translation);
374
+ var r = makeRotation(rotation);
375
+ var s = makeScale(scale);
376
+ return multiply$2(multiply$2(t, r), s);
377
+ }
378
+ /**
379
+ * Returns a matrix that has the basis components (upper left 3x3 matrix) set to
380
+ * the following x, y, and z axis.
381
+ *
382
+ * ```
383
+ * x.x y.x z.x 0
384
+ * x.y y.y z.y 0
385
+ * x.z y.z z.z 0
386
+ * 0 0 0 0
387
+ * ```
388
+ *
389
+ * @param x The x axis to set.
390
+ * @param y The y axis to set.
391
+ * @param z The z axis to set.
392
+ * @returns A matrix with its basis components populated.
393
+ */
394
+ function makeBasis(x, y, z) {
395
+ /* eslint-disable prettier/prettier */
396
+ return [
397
+ x.x, x.y, x.z, 0,
398
+ y.x, y.y, y.z, 0,
399
+ z.x, z.y, z.z, 0,
400
+ 0, 0, 0, 1
401
+ ];
402
+ /* eslint-enable prettier/prettier */
403
+ }
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
+ /**
429
+ * Creates a matrix used for [perspective
430
+ * projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
431
+ *
432
+ * The viewing volume is frustum-shaped and defined by the six parameters. Left,
433
+ * right, top, and bottom specify coordinates in the near clipping plane where
434
+ * the frustum edges intersect it, and the near and far parameters define the
435
+ * forward distances of the view volume. The resulting volume can be vertically
436
+ * and horizontally asymmetrical around the center of the near plane.
437
+ *
438
+ * @param left The left coordinate at the near plane.
439
+ * @param right The right coordinate at the near plane.
440
+ * @param top The top coordinate at the near plane.
441
+ * @param bottom The bottom coordinate at the near plane.
442
+ * @param near The near distance.
443
+ * @param far The far distance.
444
+ * @returns A matrix representing a view frustum.
445
+ */
446
+ function makeFrustum(left, right, top, bottom, near, far) {
447
+ var x = (2 * near) / (right - left);
448
+ var y = (2 * near) / (top - bottom);
449
+ var a = (right + left) / (right - left);
450
+ var b = (top + bottom) / (top - bottom);
451
+ var c = -(far + near) / (far - near);
452
+ var d = (-2 * far * near) / (far - near);
453
+ /* eslint-disable prettier/prettier */
454
+ return [
455
+ x, 0, 0, 0,
456
+ 0, y, 0, 0,
457
+ a, b, c, -1,
458
+ 0, 0, d, 0
459
+ ];
460
+ /* eslint-enable prettier/prettier */
461
+ }
462
+ /**
463
+ * Creates a perspective projection matrix.
464
+ *
465
+ * Related to: gluPerspective. The viewing volume is frustum-shaped amd defined
466
+ * by the four parameters. The fovy and aspect ratio are used to compute the
467
+ * positions of the left, right, top, and bottom sides of the viewing volume in
468
+ * the zNear plane. The fovy is the y field-of-view, the angle made by the top
469
+ * and bottom sides of frustum if they were to intersect. The aspect ratio is
470
+ * the width of the frustum divided by its height. Note that the resulting
471
+ * volume is both vertically and horizontally symmetrical around the center of
472
+ * the near plane.
473
+ *
474
+ * @param near The near Z value.
475
+ * @param far The far Z value.
476
+ * @param fovY The field of view.
477
+ * @param aspect The aspect ratio.
478
+ * @returns A matrix.
479
+ */
480
+ function makePerspective(near, far, fovY, aspect) {
481
+ var ymax = near * Math.tan(toRadians(fovY / 2.0));
482
+ var xmax = ymax * aspect;
483
+ var left = -xmax;
484
+ var right = xmax;
485
+ var top = ymax;
486
+ var bottom = -ymax;
487
+ return makeFrustum(left, right, top, bottom, near, far);
488
+ }
489
+ /**
490
+ * Creates an orthographic projection matrix.
491
+ *
492
+ * Related to: gluOrtho. The viewing volume is cube-shaped and defined by
493
+ * the six parameters. The left and right values represent the coordinates of
494
+ * the vertical clipping planes, top and bottom values represent the coordinates
495
+ * of the horizontal clipping planes, and near and far values represent the
496
+ * coordinates of the depth clipping planes.
497
+ *
498
+ * @param left The coordinate of the left horizontal clipping plane.
499
+ * @param right The coordinate of the right horizontal clipping plane.
500
+ * @param bottom The coordinate of the bottom vertical clipping plane.
501
+ * @param top The coordinate of the top vertical clipping plane.
502
+ * @param near The coordinate of the near depth clipping plane.
503
+ * @param far The coordinate of the far depth clipping plane.
504
+ * @returns A matrix.
505
+ */
506
+ function makeOrthographic(left, right, bottom, top, near, far) {
507
+ var w = 1.0 / (right - left);
508
+ var h = 1.0 / (top - bottom);
509
+ var d = 1.0 / (far - near);
510
+ var x = (right + left) * w;
511
+ var y = (top + bottom) * h;
512
+ var z = (far + near) * d;
513
+ /* eslint-disable prettier/prettier */
514
+ return [
515
+ 2 * w, 0, 0, -x,
516
+ 0, 2 * h, 0, -y,
517
+ 0, 0, -2 * d, -z,
518
+ 0, 0, 0, 1
519
+ ];
520
+ /* eslint-enable prettier/prettier */
521
+ }
522
+ /**
523
+ * Matrix becomes a combination of an inverse translation and rotation.
524
+ *
525
+ * Related to: gluLookAt. This creates the inverse of makeLookAtMatrix. The
526
+ * matrix will be an opposite translation from the 'eye' position, and it will
527
+ * rotate things in the opposite direction of the eye-to-center orientation.
528
+ * This is definitely confusing, but the main reason to use this transform is to
529
+ * set up a view matrix for a camera that's looking at a certain point. To
530
+ * achieve the effect of moving the camera somewhere and rotating it so that it
531
+ * points at something, the rest of the world is moved in the opposite direction
532
+ * and rotated in the opposite way around the camera. This way, you get the same
533
+ * effect as moving the actual camera, but all the projection math can still be
534
+ * done with the camera positioned at the origin (which makes it way simpler).
535
+ *
536
+ * @param position The position of the object.
537
+ * @param lookAt The point which the object is looking at.
538
+ * @param up The direction which the object considers up.
539
+ * @returns A matrix.
540
+ */
541
+ function makeLookAtView(position, lookAt, up) {
542
+ var z = normalize(subtract(position, lookAt));
543
+ var x = normalize(cross(up, z));
544
+ var y = cross(z, x);
545
+ var dotX = -dot$1(x, position);
546
+ var dotY = -dot$1(y, position);
547
+ var dotZ = -dot$1(z, position);
548
+ /* eslint-disable prettier/prettier */
549
+ return [
550
+ x.x, y.x, z.x, 0,
551
+ x.y, y.y, z.y, 0,
552
+ x.z, y.z, z.z, 0,
553
+ dotX, dotY, dotZ, 1,
554
+ ];
555
+ /* eslint-enable prettier/prettier */
556
+ }
557
+ /**
558
+ * Matrix becomes a combination of translation and rotation.
559
+ *
560
+ * Matrix becomes a combination of a translation to the position of 'eye' and a
561
+ * rotation matrix which orients an object to point towards 'center' along its
562
+ * z-axis. Use this function if you want an object to look at a point from
563
+ * another point in space.
564
+ *
565
+ * @param position The position of the object.
566
+ * @param lookAt The point which the object is looking at.
567
+ * @param up The direction which the object considers up.
568
+ * @returns A matrix.
569
+ */
570
+ function makeLookAt(position, lookAt, up) {
571
+ var z = normalize(subtract(position, lookAt));
572
+ var x = normalize(cross(up, z));
573
+ var y = cross(z, x);
574
+ /* eslint-disable prettier/prettier */
575
+ return [
576
+ x.x, x.y, x.z, 0,
577
+ y.x, y.y, y.z, 0,
578
+ z.x, z.y, z.z, 0,
579
+ position.x, position.y, position.z, 1
580
+ ];
581
+ /* eslint-enable prettier/prettier */
582
+ }
583
+ /**
584
+ * Returns the inverse of the given matrix. If the determinate of the matrix is
585
+ * zero, then a zero matrix is returned.
586
+ */
587
+ function invert(matrix) {
588
+ var a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
589
+ var a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
590
+ var a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
591
+ var a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
592
+ var b00 = a00 * a11 - a01 * a10;
593
+ var b01 = a00 * a12 - a02 * a10;
594
+ var b02 = a00 * a13 - a03 * a10;
595
+ var b03 = a01 * a12 - a02 * a11;
596
+ var b04 = a01 * a13 - a03 * a11;
597
+ var b05 = a02 * a13 - a03 * a12;
598
+ var b06 = a20 * a31 - a21 * a30;
599
+ var b07 = a20 * a32 - a22 * a30;
600
+ var b08 = a20 * a33 - a23 * a30;
601
+ var b09 = a21 * a32 - a22 * a31;
602
+ var b10 = a21 * a33 - a23 * a31;
603
+ var b11 = a22 * a33 - a23 * a32;
604
+ // Calculate the determinant
605
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
606
+ if (!det) {
607
+ return makeZero();
608
+ }
609
+ det = 1.0 / det;
610
+ return [
611
+ (a11 * b11 - a12 * b10 + a13 * b09) * det,
612
+ (a02 * b10 - a01 * b11 - a03 * b09) * det,
613
+ (a31 * b05 - a32 * b04 + a33 * b03) * det,
614
+ (a22 * b04 - a21 * b05 - a23 * b03) * det,
615
+ (a12 * b08 - a10 * b11 - a13 * b07) * det,
616
+ (a00 * b11 - a02 * b08 + a03 * b07) * det,
617
+ (a32 * b02 - a30 * b05 - a33 * b01) * det,
618
+ (a20 * b05 - a22 * b02 + a23 * b01) * det,
619
+ (a10 * b10 - a11 * b08 + a13 * b06) * det,
620
+ (a01 * b08 - a00 * b10 - a03 * b06) * det,
621
+ (a30 * b04 - a31 * b02 + a33 * b00) * det,
622
+ (a21 * b02 - a20 * b04 - a23 * b00) * det,
623
+ (a11 * b07 - a10 * b09 - a12 * b06) * det,
624
+ (a00 * b09 - a01 * b07 + a02 * b06) * det,
625
+ (a31 * b01 - a30 * b03 - a32 * b00) * det,
626
+ (a20 * b03 - a21 * b01 + a22 * b00) * det,
627
+ ];
628
+ }
629
+ /**
630
+ * Returns a rotation matrix looking from position towards target and oriented
631
+ * by an up vector.
632
+ *
633
+ * @param m The matrix to transform.
634
+ * @param position The point from which to look at target.
635
+ * @param target The point to look at.
636
+ * @param up The orientation.
637
+ * @returns A rotation matrix.
638
+ */
639
+ function lookAt(m, position, target, up) {
640
+ var z = subtract(position, target);
641
+ if (magnitudeSquared(z) === 0) {
642
+ z = __assign(__assign({}, z), { z: 1 });
643
+ }
644
+ z = normalize(z);
645
+ var x = cross(up, z);
646
+ if (magnitudeSquared(x) === 0) {
647
+ if (Math.abs(up.z) === 1) {
648
+ z = __assign(__assign({}, z), { x: z.x + 0.0001 });
649
+ }
650
+ else {
651
+ z = __assign(__assign({}, z), { z: z.z + 0.0001 });
652
+ }
653
+ z = normalize(z);
654
+ x = cross(up, z);
655
+ }
656
+ x = normalize(x);
657
+ var y = cross(z, x);
658
+ var res = __spreadArray([], m, true);
659
+ /* eslint-disable prettier/prettier */
660
+ res[0] = x.x;
661
+ res[4] = y.x;
662
+ res[8] = z.x;
663
+ res[1] = x.y;
664
+ res[5] = y.y;
665
+ res[9] = z.y;
666
+ res[2] = x.z;
667
+ res[6] = y.z;
668
+ res[10] = z.z;
669
+ /* eslint-enable prettier/prettier */
670
+ return res;
671
+ }
672
+ /**
673
+ * Returns a post-multiplied matrix.
674
+ */
675
+ function multiply$2(a, b) {
676
+ var ae = a;
677
+ var be = b;
678
+ var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
679
+ var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
680
+ var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
681
+ var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
682
+ var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
683
+ var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
684
+ var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
685
+ var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
686
+ var mat = makeIdentity();
687
+ mat[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
688
+ mat[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
689
+ mat[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
690
+ mat[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
691
+ mat[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
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;
704
+ }
705
+ /**
706
+ * Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
707
+ * matrix.
708
+ */
709
+ function transpose(matrix) {
710
+ /* eslint-disable prettier/prettier */
711
+ return [
712
+ matrix[0], matrix[4], matrix[8], matrix[12],
713
+ matrix[1], matrix[5], matrix[9], matrix[13],
714
+ matrix[2], matrix[6], matrix[10], matrix[14],
715
+ matrix[3], matrix[7], matrix[11], matrix[15],
716
+ ];
717
+ /* eslint-enable prettier/prettier */
718
+ }
719
+ /**
720
+ * Multiplies the columns of a matrix by the given vector.
721
+ */
722
+ function scale$4(matrix, scale) {
723
+ var x = scale.x, y = scale.y, z = scale.z;
724
+ var m = __spreadArray([], matrix, true);
725
+ /* eslint-disable prettier/prettier */
726
+ m[0] *= x;
727
+ m[4] *= y;
728
+ m[8] *= z;
729
+ m[1] *= x;
730
+ m[5] *= y;
731
+ m[9] *= z;
732
+ m[2] *= x;
733
+ m[6] *= y;
734
+ m[10] *= z;
735
+ m[3] *= x;
736
+ m[7] *= y;
737
+ m[11] *= z;
738
+ /* eslint-enable prettier/prettier */
739
+ return m;
740
+ }
741
+ function position(matrix, other) {
742
+ var m = __spreadArray([], matrix, true);
743
+ m[12] = other[12];
744
+ m[13] = other[13];
745
+ m[14] = other[14];
746
+ return m;
747
+ }
748
+ /**
749
+ * Returns true if the matrix is an identity matrix.
750
+ */
751
+ function isIdentity(matrix) {
752
+ var identity = makeIdentity();
753
+ return matrix.every(function (v, i) { return v === identity[i]; });
754
+ }
755
+ /**
756
+ * Returns an object representation of a `Matrix4`.
757
+ */
758
+ function toObject(m) {
759
+ /* eslint-disable prettier/prettier */
760
+ return {
761
+ m11: m[0], m12: m[4], m13: m[8], m14: m[12],
762
+ m21: m[1], m22: m[5], m23: m[9], m24: m[13],
763
+ m31: m[2], m32: m[6], m33: m[10], m34: m[14],
764
+ m41: m[3], m42: m[7], m43: m[11], m44: m[15],
765
+ };
766
+ /* eslint-enable prettier/prettier */
767
+ }
768
+ /**
769
+ * A type guard to check if `obj` is of type `Matrix4`.
770
+ */
771
+ function isType$2(obj) {
772
+ return Array.isArray(obj) && obj.length === 16;
773
773
  }
774
774
 
775
775
  var matrix4 = /*#__PURE__*/Object.freeze({
@@ -800,155 +800,155 @@ var matrix4 = /*#__PURE__*/Object.freeze({
800
800
  isType: isType$2
801
801
  });
802
802
 
803
- /**
804
- * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
805
- * in radians. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
806
- * returned.
807
- *
808
- * @param value The values to populate the Euler angles with.
809
- * @returns A set of Euler angles.
810
- */
811
- function create$c(value) {
812
- var _a, _b, _c, _d;
813
- if (value === void 0) { value = {}; }
814
- return {
815
- x: (_a = value.x) !== null && _a !== void 0 ? _a : 0,
816
- y: (_b = value.y) !== null && _b !== void 0 ? _b : 0,
817
- z: (_c = value.z) !== null && _c !== void 0 ? _c : 0,
818
- order: (_d = value.order) !== null && _d !== void 0 ? _d : 'xyz',
819
- };
820
- }
821
- /**
822
- * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
823
- * in degrees. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
824
- * returned.
825
- *
826
- * @param value The values to populate the Euler angles with.
827
- * @returns A set of Euler angles.
828
- */
829
- function fromDegrees(value) {
830
- if (value === void 0) { value = {}; }
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;
832
- return create$c({
833
- x: toRadians(x),
834
- y: toRadians(y),
835
- z: toRadians(z),
836
- order: order,
837
- });
838
- }
839
- /**
840
- * Creates a set of Euler angles from the rotation components of a 4x4 matrix. The
841
- * rotation components are represented by the upper 3x3 of the matrix.
842
- *
843
- * Note that there are two solutions for the Euler angle of the 2nd applied
844
- * rotation (i.e. y for xyz) because sin(theta) = sin(PI-theta).
845
- * The returned angle will always be the solution between -PI/2 and PI/2.
846
- *
847
- * @param matrix A pure rotation matrix, unscaled.
848
- * @param order The order that the rotations are applied.
849
- */
850
- function fromRotationMatrix(matrix, order) {
851
- if (order === void 0) { order = 'xyz'; }
852
- var m = toObject(matrix);
853
- var x = 0, y = 0, z = 0;
854
- if (order === 'xyz') {
855
- y = Math.asin(clamp(m.m13, -1, 1));
856
- if (Math.abs(m.m13) < 0.9999999) {
857
- x = Math.atan2(-m.m23, m.m33);
858
- z = Math.atan2(-m.m12, m.m11);
859
- }
860
- else {
861
- x = Math.atan2(m.m32, m.m22);
862
- z = 0;
863
- }
864
- }
865
- else if (order === 'yxz') {
866
- x = Math.asin(-clamp(m.m23, -1, 1));
867
- if (Math.abs(m.m23) < 0.9999999) {
868
- y = Math.atan2(m.m13, m.m33);
869
- z = Math.atan2(m.m21, m.m22);
870
- }
871
- else {
872
- y = Math.atan2(-m.m31, m.m11);
873
- z = 0;
874
- }
875
- }
876
- else if (order === 'zxy') {
877
- x = Math.asin(clamp(m.m32, -1, 1));
878
- if (Math.abs(m.m32) < 0.9999999) {
879
- y = Math.atan2(-m.m31, m.m33);
880
- z = Math.atan2(-m.m12, m.m22);
881
- }
882
- else {
883
- y = 0;
884
- z = Math.atan2(m.m21, m.m11);
885
- }
886
- }
887
- else if (order === 'zyx') {
888
- y = Math.asin(-clamp(m.m31, -1, 1));
889
- if (Math.abs(m.m31) < 0.9999999) {
890
- x = Math.atan2(m.m32, m.m33);
891
- z = Math.atan2(m.m21, m.m11);
892
- }
893
- else {
894
- x = 0;
895
- z = Math.atan2(-m.m12, m.m22);
896
- }
897
- }
898
- else if (order === 'yzx') {
899
- z = Math.asin(clamp(m.m21, -1, 1));
900
- if (Math.abs(m.m21) < 0.9999999) {
901
- x = Math.atan2(-m.m23, m.m22);
902
- y = Math.atan2(-m.m31, m.m11);
903
- }
904
- else {
905
- x = 0;
906
- y = Math.atan2(m.m13, m.m33);
907
- }
908
- }
909
- else if (order === 'xzy') {
910
- z = Math.asin(-clamp(m.m12, -1, 1));
911
- if (Math.abs(m.m12) < 0.9999999) {
912
- x = Math.atan2(m.m32, m.m22);
913
- y = Math.atan2(m.m13, m.m11);
914
- }
915
- else {
916
- x = Math.atan2(-m.m23, m.m33);
917
- y = 0;
918
- }
919
- }
920
- return { x: x, y: y, z: z, order: order };
921
- }
922
- /**
923
- * Returns a set of Euler angles that was decoded from a JSON string. Supports either
924
- * extracting values from an array `[x, y, z, order]` or object `{x, y, z,
925
- * order}`.
926
- *
927
- * @param json A JSON object.
928
- * @returns A set of Euler angles.
929
- */
930
- function fromJson$4(json) {
931
- var obj = JSON.parse(json);
932
- if (Array.isArray(obj)) {
933
- var x = obj[0], y = obj[1], z = obj[2], _a = obj[3], order = _a === void 0 ? 'xyz' : _a;
934
- return { x: x, y: y, z: z, order: order };
935
- }
936
- else {
937
- var x = obj.x, y = obj.y, z = obj.z, _b = obj.order, order = _b === void 0 ? 'xyz' : _b;
938
- return { x: x, y: y, z: z, order: order };
939
- }
940
- }
941
- /**
942
- * Type guard that checks if the given type is a set of Euler angles.
943
- */
944
- function isType$1(obj) {
945
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
946
- var o = obj;
947
- return (o != null &&
948
- o.hasOwnProperty('x') &&
949
- o.hasOwnProperty('y') &&
950
- o.hasOwnProperty('z') &&
951
- o.hasOwnProperty('order'));
803
+ /**
804
+ * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
805
+ * in radians. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
806
+ * returned.
807
+ *
808
+ * @param value The values to populate the Euler angles with.
809
+ * @returns A set of Euler angles.
810
+ */
811
+ function create$c(value) {
812
+ var _a, _b, _c, _d;
813
+ if (value === void 0) { value = {}; }
814
+ return {
815
+ x: (_a = value.x) !== null && _a !== void 0 ? _a : 0,
816
+ y: (_b = value.y) !== null && _b !== void 0 ? _b : 0,
817
+ z: (_c = value.z) !== null && _c !== void 0 ? _c : 0,
818
+ order: (_d = value.order) !== null && _d !== void 0 ? _d : 'xyz',
819
+ };
820
+ }
821
+ /**
822
+ * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
823
+ * in degrees. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
824
+ * returned.
825
+ *
826
+ * @param value The values to populate the Euler angles with.
827
+ * @returns A set of Euler angles.
828
+ */
829
+ function fromDegrees(value) {
830
+ if (value === void 0) { value = {}; }
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;
832
+ return create$c({
833
+ x: toRadians(x),
834
+ y: toRadians(y),
835
+ z: toRadians(z),
836
+ order: order,
837
+ });
838
+ }
839
+ /**
840
+ * Creates a set of Euler angles from the rotation components of a 4x4 matrix. The
841
+ * rotation components are represented by the upper 3x3 of the matrix.
842
+ *
843
+ * Note that there are two solutions for the Euler angle of the 2nd applied
844
+ * rotation (i.e. y for xyz) because sin(theta) = sin(PI-theta).
845
+ * The returned angle will always be the solution between -PI/2 and PI/2.
846
+ *
847
+ * @param matrix A pure rotation matrix, unscaled.
848
+ * @param order The order that the rotations are applied.
849
+ */
850
+ function fromRotationMatrix(matrix, order) {
851
+ if (order === void 0) { order = 'xyz'; }
852
+ var m = toObject(matrix);
853
+ var x = 0, y = 0, z = 0;
854
+ if (order === 'xyz') {
855
+ y = Math.asin(clamp(m.m13, -1, 1));
856
+ if (Math.abs(m.m13) < 0.9999999) {
857
+ x = Math.atan2(-m.m23, m.m33);
858
+ z = Math.atan2(-m.m12, m.m11);
859
+ }
860
+ else {
861
+ x = Math.atan2(m.m32, m.m22);
862
+ z = 0;
863
+ }
864
+ }
865
+ else if (order === 'yxz') {
866
+ x = Math.asin(-clamp(m.m23, -1, 1));
867
+ if (Math.abs(m.m23) < 0.9999999) {
868
+ y = Math.atan2(m.m13, m.m33);
869
+ z = Math.atan2(m.m21, m.m22);
870
+ }
871
+ else {
872
+ y = Math.atan2(-m.m31, m.m11);
873
+ z = 0;
874
+ }
875
+ }
876
+ else if (order === 'zxy') {
877
+ x = Math.asin(clamp(m.m32, -1, 1));
878
+ if (Math.abs(m.m32) < 0.9999999) {
879
+ y = Math.atan2(-m.m31, m.m33);
880
+ z = Math.atan2(-m.m12, m.m22);
881
+ }
882
+ else {
883
+ y = 0;
884
+ z = Math.atan2(m.m21, m.m11);
885
+ }
886
+ }
887
+ else if (order === 'zyx') {
888
+ y = Math.asin(-clamp(m.m31, -1, 1));
889
+ if (Math.abs(m.m31) < 0.9999999) {
890
+ x = Math.atan2(m.m32, m.m33);
891
+ z = Math.atan2(m.m21, m.m11);
892
+ }
893
+ else {
894
+ x = 0;
895
+ z = Math.atan2(-m.m12, m.m22);
896
+ }
897
+ }
898
+ else if (order === 'yzx') {
899
+ z = Math.asin(clamp(m.m21, -1, 1));
900
+ if (Math.abs(m.m21) < 0.9999999) {
901
+ x = Math.atan2(-m.m23, m.m22);
902
+ y = Math.atan2(-m.m31, m.m11);
903
+ }
904
+ else {
905
+ x = 0;
906
+ y = Math.atan2(m.m13, m.m33);
907
+ }
908
+ }
909
+ else if (order === 'xzy') {
910
+ z = Math.asin(-clamp(m.m12, -1, 1));
911
+ if (Math.abs(m.m12) < 0.9999999) {
912
+ x = Math.atan2(m.m32, m.m22);
913
+ y = Math.atan2(m.m13, m.m11);
914
+ }
915
+ else {
916
+ x = Math.atan2(-m.m23, m.m33);
917
+ y = 0;
918
+ }
919
+ }
920
+ return { x: x, y: y, z: z, order: order };
921
+ }
922
+ /**
923
+ * Returns a set of Euler angles that was decoded from a JSON string. Supports either
924
+ * extracting values from an array `[x, y, z, order]` or object `{x, y, z,
925
+ * order}`.
926
+ *
927
+ * @param json A JSON object.
928
+ * @returns A set of Euler angles.
929
+ */
930
+ function fromJson$4(json) {
931
+ var obj = JSON.parse(json);
932
+ if (Array.isArray(obj)) {
933
+ var x = obj[0], y = obj[1], z = obj[2], _a = obj[3], order = _a === void 0 ? 'xyz' : _a;
934
+ return { x: x, y: y, z: z, order: order };
935
+ }
936
+ else {
937
+ var x = obj.x, y = obj.y, z = obj.z, _b = obj.order, order = _b === void 0 ? 'xyz' : _b;
938
+ return { x: x, y: y, z: z, order: order };
939
+ }
940
+ }
941
+ /**
942
+ * Type guard that checks if the given type is a set of Euler angles.
943
+ */
944
+ function isType$1(obj) {
945
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
946
+ var o = obj;
947
+ return (o != null &&
948
+ o.hasOwnProperty('x') &&
949
+ o.hasOwnProperty('y') &&
950
+ o.hasOwnProperty('z') &&
951
+ o.hasOwnProperty('order'));
952
952
  }
953
953
 
954
954
  var euler = /*#__PURE__*/Object.freeze({
@@ -960,198 +960,198 @@ var euler = /*#__PURE__*/Object.freeze({
960
960
  isType: isType$1
961
961
  });
962
962
 
963
- /**
964
- * Returns a new quaternion. If `value` is undefined, then `{x: 0, y: 0, z: 0,
965
- * w: 1}` is returned.
966
- */
967
- function create$b(value) {
968
- if (value === void 0) { value = {}; }
969
- return __assign({ x: 0, y: 0, z: 0, w: 1 }, value);
970
- }
971
- /**
972
- * Parses a JSON string representation of a `Quaternion`.
973
- *
974
- * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
975
- * @returns A parsed `Quaternion`.
976
- */
977
- function fromJson$3(json) {
978
- var obj = JSON.parse(json);
979
- if (Array.isArray(obj)) {
980
- var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
981
- return create$b({ x: x, y: y, z: z, w: w });
982
- }
983
- else {
984
- return create$b(obj);
985
- }
986
- }
987
- /**
988
- * Returns a quaternion with that will have a magnitude of 1.
989
- */
990
- function normalize$1(q) {
991
- return scale$3(1 / magnitude$1(q), q);
992
- }
993
- /**
994
- * Returns the magnitude of the provided quaternion.
995
- */
996
- function magnitude$1(q) {
997
- return Math.sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
998
- }
999
- /**
1000
- * Returns a quaternion where each component is multiplied by the `scalar`.
1001
- */
1002
- function scale$3(scalar, q) {
1003
- return create$b({
1004
- w: q.w * scalar,
1005
- x: q.x * scalar,
1006
- y: q.y * scalar,
1007
- z: q.z * scalar,
1008
- });
1009
- }
1010
- /**
1011
- * Creates a `Quaternion` that is rotated the given radians around an axis.
1012
- *
1013
- * @param axis The axis to rotate around.
1014
- * @param radians The rotation, in radians.
1015
- * @returns A rotated quaternion.
1016
- */
1017
- function fromAxisAngle(axis, radians) {
1018
- var halfAngle = radians / 2;
1019
- var s = Math.sin(halfAngle);
1020
- var x = axis.x * s;
1021
- var y = axis.y * s;
1022
- var z = axis.z * s;
1023
- var w = Math.cos(halfAngle);
1024
- return { x: x, y: y, z: z, w: w };
1025
- }
1026
- /**
1027
- * Returns a quaternion using the upper 3x3 of a pure rotation matrix
1028
- * (unscaled).
1029
- */
1030
- function fromMatrixRotation(matrix) {
1031
- var m = toObject(matrix);
1032
- var scale = fromMatrixScale(matrix);
1033
- var is1 = 1 / scale.x;
1034
- var is2 = 1 / scale.y;
1035
- var is3 = 1 / scale.z;
1036
- var sm11 = m.m11 * is1;
1037
- var sm12 = m.m21 * is2;
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;
1046
- if (trace > 0) {
1047
- var s = Math.sqrt(trace + 1.0) * 2;
1048
- return {
1049
- x: (sm23 - sm32) / s,
1050
- y: (sm31 - sm13) / s,
1051
- z: (sm12 - sm21) / s,
1052
- w: 0.25 * s,
1053
- };
1054
- }
1055
- else if (sm11 > sm22 && sm11 > sm33) {
1056
- var s = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1057
- return {
1058
- x: 0.25 * s,
1059
- y: (sm12 + sm21) / s,
1060
- z: (sm31 + sm13) / s,
1061
- w: (sm23 - sm32) / s,
1062
- };
1063
- }
1064
- else if (sm22 > sm33) {
1065
- var s = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1066
- return {
1067
- x: (sm12 + sm21) / s,
1068
- y: 0.25 * s,
1069
- z: (sm23 + sm32) / s,
1070
- w: (sm31 - sm13) / s,
1071
- };
1072
- }
1073
- else {
1074
- var s = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1075
- return {
1076
- x: (sm31 + sm13) / s,
1077
- y: (sm23 + sm32) / s,
1078
- z: 0.25 * s,
1079
- w: (sm12 - sm21) / s,
1080
- };
1081
- }
1082
- }
1083
- function fromEuler(euler) {
1084
- var ex = euler.x, ey = euler.y, ez = euler.z, order = euler.order;
1085
- var c1 = Math.cos(ex / 2);
1086
- var c2 = Math.cos(ey / 2);
1087
- var c3 = Math.cos(ez / 2);
1088
- var s1 = Math.sin(ex / 2);
1089
- var s2 = Math.sin(ey / 2);
1090
- var s3 = Math.sin(ez / 2);
1091
- var x = 0, y = 0, z = 0, w = 0;
1092
- switch (order) {
1093
- case 'xyz':
1094
- x = s1 * c2 * c3 + c1 * s2 * s3;
1095
- y = c1 * s2 * c3 - s1 * c2 * s3;
1096
- z = c1 * c2 * s3 + s1 * s2 * c3;
1097
- w = c1 * c2 * c3 - s1 * s2 * s3;
1098
- break;
1099
- case 'yxz':
1100
- x = s1 * c2 * c3 + c1 * s2 * s3;
1101
- y = c1 * s2 * c3 - s1 * c2 * s3;
1102
- z = c1 * c2 * s3 - s1 * s2 * c3;
1103
- w = c1 * c2 * c3 + s1 * s2 * s3;
1104
- break;
1105
- case 'zxy':
1106
- x = s1 * c2 * c3 - c1 * s2 * s3;
1107
- y = c1 * s2 * c3 + s1 * c2 * s3;
1108
- z = c1 * c2 * s3 + s1 * s2 * c3;
1109
- w = c1 * c2 * c3 - s1 * s2 * s3;
1110
- break;
1111
- case 'zyx':
1112
- x = s1 * c2 * c3 - c1 * s2 * s3;
1113
- y = c1 * s2 * c3 + s1 * c2 * s3;
1114
- z = c1 * c2 * s3 - s1 * s2 * c3;
1115
- w = c1 * c2 * c3 + s1 * s2 * s3;
1116
- break;
1117
- case 'yzx':
1118
- x = s1 * c2 * c3 + c1 * s2 * s3;
1119
- y = c1 * s2 * c3 + s1 * c2 * s3;
1120
- z = c1 * c2 * s3 - s1 * s2 * c3;
1121
- w = c1 * c2 * c3 - s1 * s2 * s3;
1122
- break;
1123
- case 'xzy':
1124
- x = s1 * c2 * c3 - c1 * s2 * s3;
1125
- y = c1 * s2 * c3 - s1 * c2 * s3;
1126
- z = c1 * c2 * s3 + s1 * s2 * c3;
1127
- w = c1 * c2 * c3 + s1 * s2 * s3;
1128
- break;
1129
- }
1130
- return { x: x, y: y, z: z, w: w };
1131
- }
1132
- /**
1133
- * Multiplies `a` x `b` and returns a new quaternion with the result.
1134
- */
1135
- function multiply$1(a, b) {
1136
- // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
1137
- return {
1138
- x: a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y,
1139
- y: a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z,
1140
- z: a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x,
1141
- w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
1142
- };
1143
- }
1144
- /**
1145
- * Type guard that checks if the given type is a Quaternion.
1146
- */
1147
- function isType(obj) {
1148
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1149
- var o = obj;
1150
- return (o != null &&
1151
- o.hasOwnProperty('x') &&
1152
- o.hasOwnProperty('y') &&
1153
- o.hasOwnProperty('z') &&
1154
- o.hasOwnProperty('w'));
963
+ /**
964
+ * Returns a new quaternion. If `value` is undefined, then `{x: 0, y: 0, z: 0,
965
+ * w: 1}` is returned.
966
+ */
967
+ function create$b(value) {
968
+ if (value === void 0) { value = {}; }
969
+ return __assign({ x: 0, y: 0, z: 0, w: 1 }, value);
970
+ }
971
+ /**
972
+ * Parses a JSON string representation of a `Quaternion`.
973
+ *
974
+ * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
975
+ * @returns A parsed `Quaternion`.
976
+ */
977
+ function fromJson$3(json) {
978
+ var obj = JSON.parse(json);
979
+ if (Array.isArray(obj)) {
980
+ var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
981
+ return create$b({ x: x, y: y, z: z, w: w });
982
+ }
983
+ else {
984
+ return create$b(obj);
985
+ }
986
+ }
987
+ /**
988
+ * Returns a quaternion with that will have a magnitude of 1.
989
+ */
990
+ function normalize$1(q) {
991
+ return scale$3(1 / magnitude$1(q), q);
992
+ }
993
+ /**
994
+ * Returns the magnitude of the provided quaternion.
995
+ */
996
+ function magnitude$1(q) {
997
+ return Math.sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
998
+ }
999
+ /**
1000
+ * Returns a quaternion where each component is multiplied by the `scalar`.
1001
+ */
1002
+ function scale$3(scalar, q) {
1003
+ return create$b({
1004
+ w: q.w * scalar,
1005
+ x: q.x * scalar,
1006
+ y: q.y * scalar,
1007
+ z: q.z * scalar,
1008
+ });
1009
+ }
1010
+ /**
1011
+ * Creates a `Quaternion` that is rotated the given radians around an axis.
1012
+ *
1013
+ * @param axis The axis to rotate around.
1014
+ * @param radians The rotation, in radians.
1015
+ * @returns A rotated quaternion.
1016
+ */
1017
+ function fromAxisAngle(axis, radians) {
1018
+ var halfAngle = radians / 2;
1019
+ var s = Math.sin(halfAngle);
1020
+ var x = axis.x * s;
1021
+ var y = axis.y * s;
1022
+ var z = axis.z * s;
1023
+ var w = Math.cos(halfAngle);
1024
+ return { x: x, y: y, z: z, w: w };
1025
+ }
1026
+ /**
1027
+ * Returns a quaternion using the upper 3x3 of a pure rotation matrix
1028
+ * (unscaled).
1029
+ */
1030
+ function fromMatrixRotation(matrix) {
1031
+ var m = toObject(matrix);
1032
+ var scale = fromMatrixScale(matrix);
1033
+ var is1 = 1 / scale.x;
1034
+ var is2 = 1 / scale.y;
1035
+ var is3 = 1 / scale.z;
1036
+ var sm11 = m.m11 * is1;
1037
+ var sm12 = m.m21 * is2;
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;
1046
+ if (trace > 0) {
1047
+ var s = Math.sqrt(trace + 1.0) * 2;
1048
+ return {
1049
+ x: (sm23 - sm32) / s,
1050
+ y: (sm31 - sm13) / s,
1051
+ z: (sm12 - sm21) / s,
1052
+ w: 0.25 * s,
1053
+ };
1054
+ }
1055
+ else if (sm11 > sm22 && sm11 > sm33) {
1056
+ var s = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1057
+ return {
1058
+ x: 0.25 * s,
1059
+ y: (sm12 + sm21) / s,
1060
+ z: (sm31 + sm13) / s,
1061
+ w: (sm23 - sm32) / s,
1062
+ };
1063
+ }
1064
+ else if (sm22 > sm33) {
1065
+ var s = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1066
+ return {
1067
+ x: (sm12 + sm21) / s,
1068
+ y: 0.25 * s,
1069
+ z: (sm23 + sm32) / s,
1070
+ w: (sm31 - sm13) / s,
1071
+ };
1072
+ }
1073
+ else {
1074
+ var s = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1075
+ return {
1076
+ x: (sm31 + sm13) / s,
1077
+ y: (sm23 + sm32) / s,
1078
+ z: 0.25 * s,
1079
+ w: (sm12 - sm21) / s,
1080
+ };
1081
+ }
1082
+ }
1083
+ function fromEuler(euler) {
1084
+ var ex = euler.x, ey = euler.y, ez = euler.z, order = euler.order;
1085
+ var c1 = Math.cos(ex / 2);
1086
+ var c2 = Math.cos(ey / 2);
1087
+ var c3 = Math.cos(ez / 2);
1088
+ var s1 = Math.sin(ex / 2);
1089
+ var s2 = Math.sin(ey / 2);
1090
+ var s3 = Math.sin(ez / 2);
1091
+ var x = 0, y = 0, z = 0, w = 0;
1092
+ switch (order) {
1093
+ case 'xyz':
1094
+ x = s1 * c2 * c3 + c1 * s2 * s3;
1095
+ y = c1 * s2 * c3 - s1 * c2 * s3;
1096
+ z = c1 * c2 * s3 + s1 * s2 * c3;
1097
+ w = c1 * c2 * c3 - s1 * s2 * s3;
1098
+ break;
1099
+ case 'yxz':
1100
+ x = s1 * c2 * c3 + c1 * s2 * s3;
1101
+ y = c1 * s2 * c3 - s1 * c2 * s3;
1102
+ z = c1 * c2 * s3 - s1 * s2 * c3;
1103
+ w = c1 * c2 * c3 + s1 * s2 * s3;
1104
+ break;
1105
+ case 'zxy':
1106
+ x = s1 * c2 * c3 - c1 * s2 * s3;
1107
+ y = c1 * s2 * c3 + s1 * c2 * s3;
1108
+ z = c1 * c2 * s3 + s1 * s2 * c3;
1109
+ w = c1 * c2 * c3 - s1 * s2 * s3;
1110
+ break;
1111
+ case 'zyx':
1112
+ x = s1 * c2 * c3 - c1 * s2 * s3;
1113
+ y = c1 * s2 * c3 + s1 * c2 * s3;
1114
+ z = c1 * c2 * s3 - s1 * s2 * c3;
1115
+ w = c1 * c2 * c3 + s1 * s2 * s3;
1116
+ break;
1117
+ case 'yzx':
1118
+ x = s1 * c2 * c3 + c1 * s2 * s3;
1119
+ y = c1 * s2 * c3 + s1 * c2 * s3;
1120
+ z = c1 * c2 * s3 - s1 * s2 * c3;
1121
+ w = c1 * c2 * c3 - s1 * s2 * s3;
1122
+ break;
1123
+ case 'xzy':
1124
+ x = s1 * c2 * c3 - c1 * s2 * s3;
1125
+ y = c1 * s2 * c3 - s1 * c2 * s3;
1126
+ z = c1 * c2 * s3 + s1 * s2 * c3;
1127
+ w = c1 * c2 * c3 + s1 * s2 * s3;
1128
+ break;
1129
+ }
1130
+ return { x: x, y: y, z: z, w: w };
1131
+ }
1132
+ /**
1133
+ * Multiplies `a` x `b` and returns a new quaternion with the result.
1134
+ */
1135
+ function multiply$1(a, b) {
1136
+ // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
1137
+ return {
1138
+ x: a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y,
1139
+ y: a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z,
1140
+ z: a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x,
1141
+ w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
1142
+ };
1143
+ }
1144
+ /**
1145
+ * Type guard that checks if the given type is a Quaternion.
1146
+ */
1147
+ function isType(obj) {
1148
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1149
+ var o = obj;
1150
+ return (o != null &&
1151
+ o.hasOwnProperty('x') &&
1152
+ o.hasOwnProperty('y') &&
1153
+ o.hasOwnProperty('z') &&
1154
+ o.hasOwnProperty('w'));
1155
1155
  }
1156
1156
 
1157
1157
  var quaternion = /*#__PURE__*/Object.freeze({
@@ -1168,383 +1168,383 @@ var quaternion = /*#__PURE__*/Object.freeze({
1168
1168
  isType: isType
1169
1169
  });
1170
1170
 
1171
- function create$a() {
1172
- 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
- if (args.length === 1) {
1178
- return {
1179
- x: (_a = args[0].x) !== null && _a !== void 0 ? _a : 0,
1180
- y: (_b = args[0].y) !== null && _b !== void 0 ? _b : 0,
1181
- z: (_c = args[0].z) !== null && _c !== void 0 ? _c : 0,
1182
- };
1183
- }
1184
- else if (args.length === 3) {
1185
- return {
1186
- x: (_d = args[0]) !== null && _d !== void 0 ? _d : 0,
1187
- y: (_e = args[1]) !== null && _e !== void 0 ? _e : 0,
1188
- z: (_f = args[2]) !== null && _f !== void 0 ? _f : 0,
1189
- };
1190
- }
1191
- return {
1192
- x: 0,
1193
- y: 0,
1194
- z: 0,
1195
- };
1196
- }
1197
- /* eslint-enable @typescript-eslint/no-explicit-any */
1198
- /* eslint-enable padding-line-between-statements */
1199
- /**
1200
- * Checks if each component of the given vector is populated with a numeric
1201
- * component. A component is invalid if it contains a non-finite or NaN value.
1202
- */
1203
- function isValid$1(_a) {
1204
- var x = _a.x, y = _a.y, z = _a.z;
1205
- return [x, y, z].every(function (v) { return isFinite(v) && !isNaN(v); });
1206
- }
1207
- /**
1208
- * Returns a vector representing the scale elements of `matrix`.
1209
- */
1210
- function fromMatrixScale(matrix) {
1211
- var m = toObject(matrix);
1212
- return {
1213
- x: Math.hypot(m.m11, m.m21, m.m31),
1214
- y: Math.hypot(m.m12, m.m22, m.m32),
1215
- z: Math.hypot(m.m13, m.m23, m.m33),
1216
- };
1217
- }
1218
- /**
1219
- * Returns a vector representing the position elements of `matrix`.
1220
- */
1221
- function fromMatrixPosition(matrix) {
1222
- var m = toObject(matrix);
1223
- return { x: m.m14, y: m.m24, z: m.m34 };
1224
- }
1225
- /**
1226
- * Parses a JSON string representation of a Vector3 and returns an object.
1227
- *
1228
- * @param json A JSON string, either in the form `[x,y,z]` or `{"x": 0, "y": 0, "z": 0}`
1229
- * @returns A parsed Vector3.
1230
- */
1231
- function fromJson$2(json) {
1232
- var obj = JSON.parse(json);
1233
- if (Array.isArray(obj)) {
1234
- var x = obj[0], y = obj[1], z = obj[2];
1235
- return create$a(x, y, z);
1236
- }
1237
- else {
1238
- var x = obj.x, y = obj.y, z = obj.z;
1239
- return create$a(x, y, z);
1240
- }
1241
- }
1242
- /**
1243
- * Creates a `Vector3` from an array. Pass `offset` to read values from the
1244
- * starting index.
1245
- *
1246
- * @see #toArray()
1247
- * @see #create()
1248
- */
1249
- function fromArray(nums, offset) {
1250
- if (offset === void 0) { offset = 0; }
1251
- var x = nums[offset];
1252
- var y = nums[offset + 1];
1253
- var z = nums[offset + 2];
1254
- return create$a(x, y, z);
1255
- }
1256
- /**
1257
- * Converts a Vector3 to an array where the values of the vector will be
1258
- * represented as [x, y, z];
1259
- *
1260
- * @see #fromArray()
1261
- * @see #create()
1262
- */
1263
- function toArray(_a) {
1264
- var x = _a.x, y = _a.y, z = _a.z;
1265
- return [x, y, z];
1266
- }
1267
- /**
1268
- * Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
1269
- */
1270
- function right() {
1271
- return create$a(1, 0, 0);
1272
- }
1273
- /**
1274
- * Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
1275
- */
1276
- function up() {
1277
- return create$a(0, 1, 0);
1278
- }
1279
- /**
1280
- * Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
1281
- */
1282
- function forward() {
1283
- return create$a(0, 0, -1);
1284
- }
1285
- /**
1286
- * Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
1287
- */
1288
- function left() {
1289
- return create$a(-1, 0, 0);
1290
- }
1291
- /**
1292
- * Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
1293
- */
1294
- function down() {
1295
- return create$a(0, -1, 0);
1296
- }
1297
- /**
1298
- * Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
1299
- */
1300
- function back() {
1301
- return create$a(0, 0, 1);
1302
- }
1303
- /**
1304
- * Returns a vector at the origin, Vector3(0, 0, 0).
1305
- */
1306
- function origin() {
1307
- return create$a(0, 0, 0);
1308
- }
1309
- /**
1310
- * Returns a vector with that will have a magnitude of 1.
1311
- */
1312
- function normalize(vector) {
1313
- var length = magnitude(vector);
1314
- return { x: vector.x / length, y: vector.y / length, z: vector.z / length };
1315
- }
1316
- /**
1317
- * Returns the straight-line length from (0, 0, 0) to the given vector.
1318
- */
1319
- function magnitude(vector) {
1320
- return Math.sqrt(magnitudeSquared(vector));
1321
- }
1322
- /**
1323
- * Returns the straight-line length from (0, 0, 0) to the given vector).
1324
- *
1325
- * When comparing lengths of vectors, you should use this function as it's
1326
- * slightly more efficient to calculate.
1327
- */
1328
- function magnitudeSquared(vector) {
1329
- return vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
1330
- }
1331
- /**
1332
- * Returns a vector that is the cross product of two vectors.
1333
- *
1334
- * The cross product of two vectors results in a third vector which is
1335
- * perpendicular to the two input vectors. The result's magnitude is equal to
1336
- * the magnitudes of the two inputs multiplied together and then multiplied by
1337
- * the sine of the angle between the inputs. You can determine the direction of
1338
- * the result vector using the "left hand rule".
1339
- */
1340
- function cross(a, b) {
1341
- return {
1342
- x: a.y * b.z - a.z * b.y,
1343
- y: a.z * b.x - a.x * b.z,
1344
- z: a.x * b.y - a.y * b.x,
1345
- };
1346
- }
1347
- /**
1348
- * Returns a vector that is the sum of two vectors.
1349
- */
1350
- function add(a) {
1351
- var vectors = [];
1352
- for (var _i = 1; _i < arguments.length; _i++) {
1353
- vectors[_i - 1] = arguments[_i];
1354
- }
1355
- return vectors.reduce(function (res, next) {
1356
- return { x: res.x + next.x, y: res.y + next.y, z: res.z + next.z };
1357
- }, a);
1358
- }
1359
- /**
1360
- * Returns a vector that is the difference between two vectors.
1361
- */
1362
- function subtract(a) {
1363
- var vectors = [];
1364
- for (var _i = 1; _i < arguments.length; _i++) {
1365
- vectors[_i - 1] = arguments[_i];
1366
- }
1367
- return vectors.reduce(function (res, next) {
1368
- return { x: res.x - next.x, y: res.y - next.y, z: res.z - next.z };
1369
- }, a);
1370
- }
1371
- /**
1372
- * Returns a vector that where each component of `b` is multiplied with `a`.
1373
- */
1374
- function multiply(a, b) {
1375
- return { x: a.x * b.x, y: a.y * b.y, z: a.z * b.z };
1376
- }
1377
- /**
1378
- * Returns a vector where each value of a vector is multiplied by the `scalar`.
1379
- */
1380
- function scale$2(scalar, vector) {
1381
- return { x: vector.x * scalar, y: vector.y * scalar, z: vector.z * scalar };
1382
- }
1383
- /**
1384
- * Returns a value representing the dot product of two vectors.
1385
- *
1386
- * The dot product is a float value equal to the magnitudes of the two vectors
1387
- * multiplied together and then multiplied by the cosine of the angle between
1388
- * them.
1389
- */
1390
- function dot$1(a, b) {
1391
- return a.x * b.x + a.y * b.y + a.z * b.z;
1392
- }
1393
- /**
1394
- * Returns the angle, in radians, between two vectors.
1395
- *
1396
- * The angle returned is the unsigned angle between the two vectors. This means
1397
- * the smaller of the two possible angles between the two vectors is used. The
1398
- * result is never greater than 180 degrees.
1399
- */
1400
- function angleTo(a, b) {
1401
- var theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
1402
- // Clamp to avoid numerical problems.
1403
- return Math.acos(theta);
1404
- }
1405
- /**
1406
- * Returns the Euler angle, in radians with the `xyz` ordering, between two vectors.
1407
- *
1408
- * This method will normalize both vectors for the calculation, and uses the
1409
- * algorithm described in https://www.xarg.org/proof/quaternion-from-two-vectors/.
1410
- */
1411
- function eulerTo(a, b) {
1412
- var normalizedA = normalize(a);
1413
- var normalizedB = normalize(b);
1414
- var dotDelta = Math.cos(toRadians(1));
1415
- var dotAB = dot$1(normalizedA, normalizedB);
1416
- var vectorsAreParallel = Math.abs(dotAB) > dotDelta;
1417
- if (vectorsAreParallel) {
1418
- return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
1419
- }
1420
- var normalizedQ = normalize$1(create$b(__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
1421
- return fromRotationMatrix(makeRotation(normalizedQ));
1422
- }
1423
- /**
1424
- * Performs a projection of a `vector` onto `onNormal`.
1425
- *
1426
- * A projection is represented as the nearest point along a normal to a vector,
1427
- * which constructs a triangle from the origin, to the vector, to the projected
1428
- * point.
1429
- *
1430
- * ```
1431
- * Vector --> * * <-- Projected
1432
- * \
1433
- * \ | <-- Normal
1434
- * \|
1435
- * * <-- Origin
1436
- * ```
1437
- */
1438
- function project(vector, onNormal) {
1439
- return scale$2(dot$1(onNormal, vector) / magnitude(onNormal), onNormal);
1440
- }
1441
- /**
1442
- * Returns a vector that is rotated about an origin point.
1443
- *
1444
- * @param angle The angle to rotate, in radians.
1445
- * @param point The origin point to rotate around.
1446
- * @param axisDirection The direction used to compute the axis.
1447
- * @param axisPosition The point of the axis.
1448
- */
1449
- function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
1450
- if (angle !== 0) {
1451
- var x = point.x, y = point.y, z = point.z;
1452
- var a = axisPosition.x, b = axisPosition.y, c = axisPosition.z;
1453
- var u = axisDirection.x, v = axisDirection.y, w = axisDirection.z;
1454
- var newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
1455
- (1 - Math.cos(angle)) +
1456
- x * Math.cos(angle) +
1457
- (-c * v + b * w - w * y + v * z) * Math.sin(angle);
1458
- var newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
1459
- (1 - Math.cos(angle)) +
1460
- y * Math.cos(angle) +
1461
- (c * u - a * w + w * x - u * z) * Math.sin(angle);
1462
- var newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
1463
- (1 - Math.cos(angle)) +
1464
- z * Math.cos(angle) +
1465
- (-b * u + a * v - v * x + u * y) * Math.sin(angle);
1466
- return { x: newX, y: newY, z: newZ };
1467
- }
1468
- else {
1469
- return point;
1470
- }
1471
- }
1472
- /**
1473
- * Returns a vector that is multiplied with a matrix.
1474
- */
1475
- function transformMatrix$1(vector, m) {
1476
- var x = vector.x, y = vector.y, z = vector.z;
1477
- var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
1478
- return {
1479
- x: (m[0] * x + m[4] * y + m[8] * z + m[12]) * w,
1480
- y: (m[1] * x + m[5] * y + m[9] * z + m[13]) * w,
1481
- z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
1482
- };
1483
- }
1484
- /**
1485
- * Euclidean distance between two vectors
1486
- */
1487
- function distance$1(a, b) {
1488
- return Math.sqrt(distanceSquared$1(a, b));
1489
- }
1490
- /**
1491
- * Returns the squared distance between two vectors. If you're just comparing
1492
- * distances, this is slightly more efficient than `distanceTo`.
1493
- */
1494
- function distanceSquared$1(a, b) {
1495
- var _a = subtract(a, b), dx = _a.x, dy = _a.y, dz = _a.z;
1496
- return dx * dx + dy * dy + dz * dz;
1497
- }
1498
- /**
1499
- * Returns `true` if two vectors have the same values.
1500
- */
1501
- function isEqual$2(a, b) {
1502
- return a.x === b.x && a.y === b.y && a.z === b.z;
1503
- }
1504
- /**
1505
- * Returns a vector that contains the largest components of `a` and `b`.
1506
- */
1507
- function max(a, b) {
1508
- return create$a(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1509
- }
1510
- /**
1511
- * Returns a vector that contains the smallest components of `a` and `b`.
1512
- */
1513
- function min(a, b) {
1514
- return create$a(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1515
- }
1516
- /**
1517
- * Returns a vector that each of its component negated.
1518
- */
1519
- function negate(vector) {
1520
- return { x: -vector.x, y: -vector.y, z: -vector.z };
1521
- }
1522
- /**
1523
- * Performs a linear interpolation between `a` and `b` and returns the result.
1524
- * The value of `t` is clamped between `[0, 1]`.
1525
- *
1526
- * @param a The start value.
1527
- * @param b The end value.
1528
- * @param t A value between 0 and 1.
1529
- * @returns A point between `a` and `b`.
1530
- */
1531
- function lerp(a, b, t) {
1532
- return {
1533
- x: lerp$2(a.x, b.x, t),
1534
- y: lerp$2(a.y, b.y, t),
1535
- z: lerp$2(a.z, b.z, t),
1536
- };
1537
- }
1538
- /**
1539
- * Maps a normalized device coordinate (NDC) space to world space coordinates.
1540
- *
1541
- * @param ndc A point in normalized device coordinates.
1542
- * @param worldMatrix A camera's world matrix.
1543
- * @param projectionMatrixInverse A camera's inverse projection matrix.
1544
- * @returns A point in world space coordinates.
1545
- */
1546
- function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1547
- return transformMatrix$1(transformMatrix$1(ndc, projectionMatrixInverse), worldMatrix);
1171
+ function create$a() {
1172
+ 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
+ if (args.length === 1) {
1178
+ return {
1179
+ x: (_a = args[0].x) !== null && _a !== void 0 ? _a : 0,
1180
+ y: (_b = args[0].y) !== null && _b !== void 0 ? _b : 0,
1181
+ z: (_c = args[0].z) !== null && _c !== void 0 ? _c : 0,
1182
+ };
1183
+ }
1184
+ else if (args.length === 3) {
1185
+ return {
1186
+ x: (_d = args[0]) !== null && _d !== void 0 ? _d : 0,
1187
+ y: (_e = args[1]) !== null && _e !== void 0 ? _e : 0,
1188
+ z: (_f = args[2]) !== null && _f !== void 0 ? _f : 0,
1189
+ };
1190
+ }
1191
+ return {
1192
+ x: 0,
1193
+ y: 0,
1194
+ z: 0,
1195
+ };
1196
+ }
1197
+ /* eslint-enable @typescript-eslint/no-explicit-any */
1198
+ /* eslint-enable padding-line-between-statements */
1199
+ /**
1200
+ * Checks if each component of the given vector is populated with a numeric
1201
+ * component. A component is invalid if it contains a non-finite or NaN value.
1202
+ */
1203
+ function isValid$1(_a) {
1204
+ var x = _a.x, y = _a.y, z = _a.z;
1205
+ return [x, y, z].every(function (v) { return isFinite(v) && !isNaN(v); });
1206
+ }
1207
+ /**
1208
+ * Returns a vector representing the scale elements of `matrix`.
1209
+ */
1210
+ function fromMatrixScale(matrix) {
1211
+ var m = toObject(matrix);
1212
+ return {
1213
+ x: Math.hypot(m.m11, m.m21, m.m31),
1214
+ y: Math.hypot(m.m12, m.m22, m.m32),
1215
+ z: Math.hypot(m.m13, m.m23, m.m33),
1216
+ };
1217
+ }
1218
+ /**
1219
+ * Returns a vector representing the position elements of `matrix`.
1220
+ */
1221
+ function fromMatrixPosition(matrix) {
1222
+ var m = toObject(matrix);
1223
+ return { x: m.m14, y: m.m24, z: m.m34 };
1224
+ }
1225
+ /**
1226
+ * Parses a JSON string representation of a Vector3 and returns an object.
1227
+ *
1228
+ * @param json A JSON string, either in the form `[x,y,z]` or `{"x": 0, "y": 0, "z": 0}`
1229
+ * @returns A parsed Vector3.
1230
+ */
1231
+ function fromJson$2(json) {
1232
+ var obj = JSON.parse(json);
1233
+ if (Array.isArray(obj)) {
1234
+ var x = obj[0], y = obj[1], z = obj[2];
1235
+ return create$a(x, y, z);
1236
+ }
1237
+ else {
1238
+ var x = obj.x, y = obj.y, z = obj.z;
1239
+ return create$a(x, y, z);
1240
+ }
1241
+ }
1242
+ /**
1243
+ * Creates a `Vector3` from an array. Pass `offset` to read values from the
1244
+ * starting index.
1245
+ *
1246
+ * @see #toArray()
1247
+ * @see #create()
1248
+ */
1249
+ function fromArray(nums, offset) {
1250
+ if (offset === void 0) { offset = 0; }
1251
+ var x = nums[offset];
1252
+ var y = nums[offset + 1];
1253
+ var z = nums[offset + 2];
1254
+ return create$a(x, y, z);
1255
+ }
1256
+ /**
1257
+ * Converts a Vector3 to an array where the values of the vector will be
1258
+ * represented as [x, y, z];
1259
+ *
1260
+ * @see #fromArray()
1261
+ * @see #create()
1262
+ */
1263
+ function toArray(_a) {
1264
+ var x = _a.x, y = _a.y, z = _a.z;
1265
+ return [x, y, z];
1266
+ }
1267
+ /**
1268
+ * Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
1269
+ */
1270
+ function right() {
1271
+ return create$a(1, 0, 0);
1272
+ }
1273
+ /**
1274
+ * Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
1275
+ */
1276
+ function up() {
1277
+ return create$a(0, 1, 0);
1278
+ }
1279
+ /**
1280
+ * Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
1281
+ */
1282
+ function forward() {
1283
+ return create$a(0, 0, -1);
1284
+ }
1285
+ /**
1286
+ * Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
1287
+ */
1288
+ function left() {
1289
+ return create$a(-1, 0, 0);
1290
+ }
1291
+ /**
1292
+ * Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
1293
+ */
1294
+ function down() {
1295
+ return create$a(0, -1, 0);
1296
+ }
1297
+ /**
1298
+ * Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
1299
+ */
1300
+ function back() {
1301
+ return create$a(0, 0, 1);
1302
+ }
1303
+ /**
1304
+ * Returns a vector at the origin, Vector3(0, 0, 0).
1305
+ */
1306
+ function origin() {
1307
+ return create$a(0, 0, 0);
1308
+ }
1309
+ /**
1310
+ * Returns a vector with that will have a magnitude of 1.
1311
+ */
1312
+ function normalize(vector) {
1313
+ var length = magnitude(vector);
1314
+ return { x: vector.x / length, y: vector.y / length, z: vector.z / length };
1315
+ }
1316
+ /**
1317
+ * Returns the straight-line length from (0, 0, 0) to the given vector.
1318
+ */
1319
+ function magnitude(vector) {
1320
+ return Math.sqrt(magnitudeSquared(vector));
1321
+ }
1322
+ /**
1323
+ * Returns the straight-line length from (0, 0, 0) to the given vector).
1324
+ *
1325
+ * When comparing lengths of vectors, you should use this function as it's
1326
+ * slightly more efficient to calculate.
1327
+ */
1328
+ function magnitudeSquared(vector) {
1329
+ return vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
1330
+ }
1331
+ /**
1332
+ * Returns a vector that is the cross product of two vectors.
1333
+ *
1334
+ * The cross product of two vectors results in a third vector which is
1335
+ * perpendicular to the two input vectors. The result's magnitude is equal to
1336
+ * the magnitudes of the two inputs multiplied together and then multiplied by
1337
+ * the sine of the angle between the inputs. You can determine the direction of
1338
+ * the result vector using the "left hand rule".
1339
+ */
1340
+ function cross(a, b) {
1341
+ return {
1342
+ x: a.y * b.z - a.z * b.y,
1343
+ y: a.z * b.x - a.x * b.z,
1344
+ z: a.x * b.y - a.y * b.x,
1345
+ };
1346
+ }
1347
+ /**
1348
+ * Returns a vector that is the sum of two vectors.
1349
+ */
1350
+ function add(a) {
1351
+ var vectors = [];
1352
+ for (var _i = 1; _i < arguments.length; _i++) {
1353
+ vectors[_i - 1] = arguments[_i];
1354
+ }
1355
+ return vectors.reduce(function (res, next) {
1356
+ return { x: res.x + next.x, y: res.y + next.y, z: res.z + next.z };
1357
+ }, a);
1358
+ }
1359
+ /**
1360
+ * Returns a vector that is the difference between two vectors.
1361
+ */
1362
+ function subtract(a) {
1363
+ var vectors = [];
1364
+ for (var _i = 1; _i < arguments.length; _i++) {
1365
+ vectors[_i - 1] = arguments[_i];
1366
+ }
1367
+ return vectors.reduce(function (res, next) {
1368
+ return { x: res.x - next.x, y: res.y - next.y, z: res.z - next.z };
1369
+ }, a);
1370
+ }
1371
+ /**
1372
+ * Returns a vector that where each component of `b` is multiplied with `a`.
1373
+ */
1374
+ function multiply(a, b) {
1375
+ return { x: a.x * b.x, y: a.y * b.y, z: a.z * b.z };
1376
+ }
1377
+ /**
1378
+ * Returns a vector where each value of a vector is multiplied by the `scalar`.
1379
+ */
1380
+ function scale$2(scalar, vector) {
1381
+ return { x: vector.x * scalar, y: vector.y * scalar, z: vector.z * scalar };
1382
+ }
1383
+ /**
1384
+ * Returns a value representing the dot product of two vectors.
1385
+ *
1386
+ * The dot product is a float value equal to the magnitudes of the two vectors
1387
+ * multiplied together and then multiplied by the cosine of the angle between
1388
+ * them.
1389
+ */
1390
+ function dot$1(a, b) {
1391
+ return a.x * b.x + a.y * b.y + a.z * b.z;
1392
+ }
1393
+ /**
1394
+ * Returns the angle, in radians, between two vectors.
1395
+ *
1396
+ * The angle returned is the unsigned angle between the two vectors. This means
1397
+ * the smaller of the two possible angles between the two vectors is used. The
1398
+ * result is never greater than 180 degrees.
1399
+ */
1400
+ function angleTo(a, b) {
1401
+ var theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
1402
+ // Clamp to avoid numerical problems.
1403
+ return Math.acos(theta);
1404
+ }
1405
+ /**
1406
+ * Returns the Euler angle, in radians with the `xyz` ordering, between two vectors.
1407
+ *
1408
+ * This method will normalize both vectors for the calculation, and uses the
1409
+ * algorithm described in https://www.xarg.org/proof/quaternion-from-two-vectors/.
1410
+ */
1411
+ function eulerTo(a, b) {
1412
+ var normalizedA = normalize(a);
1413
+ var normalizedB = normalize(b);
1414
+ var dotDelta = Math.cos(toRadians(1));
1415
+ var dotAB = dot$1(normalizedA, normalizedB);
1416
+ var vectorsAreParallel = Math.abs(dotAB) > dotDelta;
1417
+ if (vectorsAreParallel) {
1418
+ return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
1419
+ }
1420
+ var normalizedQ = normalize$1(create$b(__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
1421
+ return fromRotationMatrix(makeRotation(normalizedQ));
1422
+ }
1423
+ /**
1424
+ * Performs a projection of a `vector` onto `onNormal`.
1425
+ *
1426
+ * A projection is represented as the nearest point along a normal to a vector,
1427
+ * which constructs a triangle from the origin, to the vector, to the projected
1428
+ * point.
1429
+ *
1430
+ * ```
1431
+ * Vector --> * * <-- Projected
1432
+ * \
1433
+ * \ | <-- Normal
1434
+ * \|
1435
+ * * <-- Origin
1436
+ * ```
1437
+ */
1438
+ function project(vector, onNormal) {
1439
+ return scale$2(dot$1(onNormal, vector) / magnitude(onNormal), onNormal);
1440
+ }
1441
+ /**
1442
+ * Returns a vector that is rotated about an origin point.
1443
+ *
1444
+ * @param angle The angle to rotate, in radians.
1445
+ * @param point The origin point to rotate around.
1446
+ * @param axisDirection The direction used to compute the axis.
1447
+ * @param axisPosition The point of the axis.
1448
+ */
1449
+ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
1450
+ if (angle !== 0) {
1451
+ var x = point.x, y = point.y, z = point.z;
1452
+ var a = axisPosition.x, b = axisPosition.y, c = axisPosition.z;
1453
+ var u = axisDirection.x, v = axisDirection.y, w = axisDirection.z;
1454
+ var newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
1455
+ (1 - Math.cos(angle)) +
1456
+ x * Math.cos(angle) +
1457
+ (-c * v + b * w - w * y + v * z) * Math.sin(angle);
1458
+ var newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
1459
+ (1 - Math.cos(angle)) +
1460
+ y * Math.cos(angle) +
1461
+ (c * u - a * w + w * x - u * z) * Math.sin(angle);
1462
+ var newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
1463
+ (1 - Math.cos(angle)) +
1464
+ z * Math.cos(angle) +
1465
+ (-b * u + a * v - v * x + u * y) * Math.sin(angle);
1466
+ return { x: newX, y: newY, z: newZ };
1467
+ }
1468
+ else {
1469
+ return point;
1470
+ }
1471
+ }
1472
+ /**
1473
+ * Returns a vector that is multiplied with a matrix.
1474
+ */
1475
+ function transformMatrix$1(vector, m) {
1476
+ var x = vector.x, y = vector.y, z = vector.z;
1477
+ var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
1478
+ return {
1479
+ x: (m[0] * x + m[4] * y + m[8] * z + m[12]) * w,
1480
+ y: (m[1] * x + m[5] * y + m[9] * z + m[13]) * w,
1481
+ z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
1482
+ };
1483
+ }
1484
+ /**
1485
+ * Euclidean distance between two vectors
1486
+ */
1487
+ function distance$1(a, b) {
1488
+ return Math.sqrt(distanceSquared$1(a, b));
1489
+ }
1490
+ /**
1491
+ * Returns the squared distance between two vectors. If you're just comparing
1492
+ * distances, this is slightly more efficient than `distanceTo`.
1493
+ */
1494
+ function distanceSquared$1(a, b) {
1495
+ var _a = subtract(a, b), dx = _a.x, dy = _a.y, dz = _a.z;
1496
+ return dx * dx + dy * dy + dz * dz;
1497
+ }
1498
+ /**
1499
+ * Returns `true` if two vectors have the same values.
1500
+ */
1501
+ function isEqual$2(a, b) {
1502
+ return a.x === b.x && a.y === b.y && a.z === b.z;
1503
+ }
1504
+ /**
1505
+ * Returns a vector that contains the largest components of `a` and `b`.
1506
+ */
1507
+ function max(a, b) {
1508
+ return create$a(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1509
+ }
1510
+ /**
1511
+ * Returns a vector that contains the smallest components of `a` and `b`.
1512
+ */
1513
+ function min(a, b) {
1514
+ return create$a(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1515
+ }
1516
+ /**
1517
+ * Returns a vector that each of its component negated.
1518
+ */
1519
+ function negate(vector) {
1520
+ return { x: -vector.x, y: -vector.y, z: -vector.z };
1521
+ }
1522
+ /**
1523
+ * Performs a linear interpolation between `a` and `b` and returns the result.
1524
+ * The value of `t` is clamped between `[0, 1]`.
1525
+ *
1526
+ * @param a The start value.
1527
+ * @param b The end value.
1528
+ * @param t A value between 0 and 1.
1529
+ * @returns A point between `a` and `b`.
1530
+ */
1531
+ function lerp(a, b, t) {
1532
+ return {
1533
+ x: lerp$2(a.x, b.x, t),
1534
+ y: lerp$2(a.y, b.y, t),
1535
+ z: lerp$2(a.z, b.z, t),
1536
+ };
1537
+ }
1538
+ /**
1539
+ * Maps a normalized device coordinate (NDC) space to world space coordinates.
1540
+ *
1541
+ * @param ndc A point in normalized device coordinates.
1542
+ * @param worldMatrix A camera's world matrix.
1543
+ * @param projectionMatrixInverse A camera's inverse projection matrix.
1544
+ * @returns A point in world space coordinates.
1545
+ */
1546
+ function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1547
+ return transformMatrix$1(transformMatrix$1(ndc, projectionMatrixInverse), worldMatrix);
1548
1548
  }
1549
1549
 
1550
1550
  var vector3 = /*#__PURE__*/Object.freeze({
@@ -1587,64 +1587,64 @@ var vector3 = /*#__PURE__*/Object.freeze({
1587
1587
  transformNdcToWorldSpace: transformNdcToWorldSpace
1588
1588
  });
1589
1589
 
1590
- /**
1591
- * Returns a `BoundingBox` with the given min and max points.
1592
- */
1593
- var create$9 = function (min, max) {
1594
- return { min: min, max: max };
1595
- };
1596
- /**
1597
- * Construct a minimal bounding box for a set of vectors, such that all vectors
1598
- * are contained by the bounding box.
1599
- */
1600
- var fromVectors = function (vectors) {
1601
- return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
1602
- };
1603
- /**
1604
- * Returns the center point of the given `BoundingBox`.
1605
- */
1606
- var center$3 = function (boundingBox) {
1607
- return scale$2(0.5, add(boundingBox.min, boundingBox.max));
1608
- };
1609
- /**
1610
- * Returns the diagonal vector between the `min` and `max` vectors of the
1611
- * given `BoundingBox`.
1612
- */
1613
- var diagonal = function (boundingBox) {
1614
- return subtract(boundingBox.max, boundingBox.min);
1615
- };
1616
- /**
1617
- * Returns a floating-point spatial error tolerance based on the extents of the box.
1618
- */
1619
- var epsilon = function (boundingBox) {
1620
- return (Math.max(Math.max(magnitude(boundingBox.max), magnitude(boundingBox.min)), magnitude(diagonal(boundingBox))) * 1e-6);
1621
- };
1622
- function union(box) {
1623
- var rest = [];
1624
- for (var _i = 1; _i < arguments.length; _i++) {
1625
- rest[_i - 1] = arguments[_i];
1626
- }
1627
- var boxes = __spreadArray([box], rest, true);
1628
- return boxes.reduce(function (a, b) {
1629
- return create$9(min(a.min, b.min), max(a.max, b.max));
1630
- });
1631
- }
1632
- /* eslint-enable padding-line-between-statements */
1633
- /**
1634
- * Returns the distance between the min and max for the provided
1635
- * bounding box for each axis.
1636
- */
1637
- var lengths = function (box) {
1638
- return create$a(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z);
1639
- };
1640
- /**
1641
- * Checks if each component of the given bounding box is populated with a numeric
1642
- * component. A component is invalid if it contains a non-finite or NaN value.
1643
- */
1644
- function isValid(boundingBox) {
1645
- var maxIsValid = isValid$1(boundingBox.max);
1646
- var minIsValid = isValid$1(boundingBox.min);
1647
- return maxIsValid && minIsValid;
1590
+ /**
1591
+ * Returns a `BoundingBox` with the given min and max points.
1592
+ */
1593
+ var create$9 = function (min, max) {
1594
+ return { min: min, max: max };
1595
+ };
1596
+ /**
1597
+ * Construct a minimal bounding box for a set of vectors, such that all vectors
1598
+ * are contained by the bounding box.
1599
+ */
1600
+ var fromVectors = function (vectors) {
1601
+ return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
1602
+ };
1603
+ /**
1604
+ * Returns the center point of the given `BoundingBox`.
1605
+ */
1606
+ var center$3 = function (boundingBox) {
1607
+ return scale$2(0.5, add(boundingBox.min, boundingBox.max));
1608
+ };
1609
+ /**
1610
+ * Returns the diagonal vector between the `min` and `max` vectors of the
1611
+ * given `BoundingBox`.
1612
+ */
1613
+ var diagonal = function (boundingBox) {
1614
+ return subtract(boundingBox.max, boundingBox.min);
1615
+ };
1616
+ /**
1617
+ * Returns a floating-point spatial error tolerance based on the extents of the box.
1618
+ */
1619
+ var epsilon = function (boundingBox) {
1620
+ return (Math.max(Math.max(magnitude(boundingBox.max), magnitude(boundingBox.min)), magnitude(diagonal(boundingBox))) * 1e-6);
1621
+ };
1622
+ function union(box) {
1623
+ var rest = [];
1624
+ for (var _i = 1; _i < arguments.length; _i++) {
1625
+ rest[_i - 1] = arguments[_i];
1626
+ }
1627
+ var boxes = __spreadArray([box], rest, true);
1628
+ return boxes.reduce(function (a, b) {
1629
+ return create$9(min(a.min, b.min), max(a.max, b.max));
1630
+ });
1631
+ }
1632
+ /* eslint-enable padding-line-between-statements */
1633
+ /**
1634
+ * Returns the distance between the min and max for the provided
1635
+ * bounding box for each axis.
1636
+ */
1637
+ var lengths = function (box) {
1638
+ return create$a(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z);
1639
+ };
1640
+ /**
1641
+ * Checks if each component of the given bounding box is populated with a numeric
1642
+ * component. A component is invalid if it contains a non-finite or NaN value.
1643
+ */
1644
+ function isValid(boundingBox) {
1645
+ var maxIsValid = isValid$1(boundingBox.max);
1646
+ var minIsValid = isValid$1(boundingBox.min);
1647
+ return maxIsValid && minIsValid;
1648
1648
  }
1649
1649
 
1650
1650
  var boundingBox = /*#__PURE__*/Object.freeze({
@@ -1659,16 +1659,16 @@ var boundingBox = /*#__PURE__*/Object.freeze({
1659
1659
  isValid: isValid
1660
1660
  });
1661
1661
 
1662
- /**
1663
- * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
1664
- */
1665
- var create$8 = function (boundingBox$1) {
1666
- var boundingBoxCenter = center$3(boundingBox$1);
1667
- var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1668
- var radius = magnitude(centerToBoundingPlane);
1669
- var length = Math.max(radius, magnitude(boundingBoxCenter));
1670
- var epsilon = length === 0 ? 1.0 : length * 1e-6;
1671
- return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
1662
+ /**
1663
+ * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
1664
+ */
1665
+ var create$8 = function (boundingBox$1) {
1666
+ var boundingBoxCenter = center$3(boundingBox$1);
1667
+ var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1668
+ var radius = magnitude(centerToBoundingPlane);
1669
+ var length = Math.max(radius, magnitude(boundingBoxCenter));
1670
+ var epsilon = length === 0 ? 1.0 : length * 1e-6;
1671
+ return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
1672
1672
  };
1673
1673
 
1674
1674
  var boundingSphere = /*#__PURE__*/Object.freeze({
@@ -1676,196 +1676,196 @@ var boundingSphere = /*#__PURE__*/Object.freeze({
1676
1676
  create: create$8
1677
1677
  });
1678
1678
 
1679
- /**
1680
- * Returns a new `Rectangle` with the given position and size.
1681
- */
1682
- function create$7(x, y, width, height) {
1683
- return { x: x, y: y, width: width, height: height };
1684
- }
1685
- /**
1686
- * Returns a new `Rectangle` at the origin point and given size.
1687
- */
1688
- function fromDimensions(dimensions) {
1689
- return create$7(0, 0, dimensions.width, dimensions.height);
1690
- }
1691
- /**
1692
- * Returns a new `Rectangle` with the given position and size.
1693
- */
1694
- function fromPointAndDimensions(point, dimensions) {
1695
- return create$7(point.x, point.y, dimensions.width, dimensions.height);
1696
- }
1697
- /**
1698
- * Returns a new `Rectangle` with the given top-left and bottom-right positions.
1699
- * The returned rectangle will always returns a positive width and height.
1700
- */
1701
- function fromPoints(topLeftPt, bottomRightPt) {
1702
- var minX = Math.min(topLeftPt.x, bottomRightPt.x);
1703
- var minY = Math.min(topLeftPt.y, bottomRightPt.y);
1704
- var maxX = Math.max(topLeftPt.x, bottomRightPt.x);
1705
- var maxY = Math.max(topLeftPt.y, bottomRightPt.y);
1706
- return create$7(minX, minY, maxX - minX, maxY - minY);
1707
- }
1708
- /**
1709
- * Returns a rectangle where the longest length of `rect` will be equal to the
1710
- * shortest length of `to`. The shortest length of `rect` will be proportionally
1711
- * scaled to match the aspect ratio of `rect`. The returned rectangle will be
1712
- * centered within `to`.
1713
- *
1714
- * @see {@link cropFit}
1715
- */
1716
- function containFit$1(to, rect) {
1717
- var scale = Math.min(to.width / rect.width, to.height / rect.height);
1718
- var dimensions$1 = proportionalScale(scale, rect);
1719
- var position = subtract$1(center$2(to), center$1(dimensions$1));
1720
- return fromPointAndDimensions(position, dimensions$1);
1721
- }
1722
- /**
1723
- * Returns a rectangle where the shortest length of `rect` will be equal to the
1724
- * longest length of `to`. The longest length of `rect` will be proportionally
1725
- * scaled to match the aspect ratio of `rect`. The returned rectangle will be
1726
- * centered within `to`.
1727
- *
1728
- * @see {@link containFit}
1729
- */
1730
- function cropFit$1(to, rect) {
1731
- var scale = Math.max(to.width / rect.width, to.height / rect.height);
1732
- var dimensions$1 = proportionalScale(scale, rect);
1733
- var position = subtract$1(center$2(to), center$1(dimensions$1));
1734
- return fromPointAndDimensions(position, dimensions$1);
1735
- }
1736
- /**
1737
- * Returns a rectangle where each side of `rect` will be reduced proportionally
1738
- * to have an area less than or equal to the provided `to` value. The returned
1739
- * rectangle will be centered within the original bounds of `rect`.
1740
- *
1741
- * @param to - the maximum area this rectangle can have
1742
- * @param rect - the rectangle to scale to fit the specified area
1743
- */
1744
- function scaleFit$1(to, rect) {
1745
- var scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
1746
- var dimensions$1 = floor(proportionalScale(scale, rect));
1747
- var position = subtract$1(center$2(rect), center$1(dimensions$1));
1748
- return fromPointAndDimensions(position, dimensions$1);
1749
- }
1750
- /**
1751
- * Returns a rectangle where the position and dimensions are scaled by the given
1752
- * factors. If `scaleY` is omitted, then the position and dimensions are scaled
1753
- * uniformly by `scaleOrScaleX`.
1754
- *
1755
- * @param rect The rectangle to scale.
1756
- * @param scaleOrScaleX The uniform scale factor, or the horizontal scale
1757
- * factor.
1758
- * @param scaleY The vertical scale factor.
1759
- * @returns A scaled rectangle.
1760
- */
1761
- function scale$1(rect, scaleOrScaleX, scaleY) {
1762
- if (scaleY == null) {
1763
- return scale$1(rect, scaleOrScaleX, scaleOrScaleX);
1764
- }
1765
- else {
1766
- var x = rect.x, y = rect.y, width = rect.width, height = rect.height;
1767
- var scaleX = scaleOrScaleX;
1768
- return create$7(x * scaleX, y * scaleY, width * scaleX, height * scaleY);
1769
- }
1770
- }
1771
- /**
1772
- * Returns true if two rectangles are equal in position and size.
1773
- */
1774
- function isEqual$1(a, b) {
1775
- return isEqual$3(a, b) && isEqual(a, b);
1776
- }
1777
- /**
1778
- * Returns a rectangle that has its position shifted by a given offset. The
1779
- * size of the rectangle is unchanged.
1780
- */
1781
- function offset(delta, rect) {
1782
- return fromPointAndDimensions(add$1(topLeft(rect), delta), rect);
1783
- }
1784
- /**
1785
- * Returns the area of the rectangle.
1786
- */
1787
- function area$1(rect) {
1788
- return rect.width * rect.height;
1789
- }
1790
- /**
1791
- * Returns the center point of the rectangle.
1792
- */
1793
- function center$2(rect) {
1794
- return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
1795
- }
1796
- /**
1797
- * Returns the top-left position of the rectangle, as a point.
1798
- */
1799
- function topLeft(rect) {
1800
- return create$d(rect.x, rect.y);
1801
- }
1802
- /**
1803
- * Returns the bottom-right position of the rectangle, as a point.
1804
- */
1805
- function bottomRight(rect) {
1806
- return create$d(rect.x + rect.width, rect.y + rect.height);
1807
- }
1808
- /**
1809
- * Returns `true` if the given rectangle has a portrait aspect ratio.
1810
- */
1811
- function isPortrait(rect) {
1812
- return rect.width < rect.height;
1813
- }
1814
- /**
1815
- * Returns `true` if the given rectangle has a landscape aspect ratio.
1816
- */
1817
- function isLandscape(rect) {
1818
- return rect.width > rect.height;
1819
- }
1820
- /**
1821
- * Returns `true` if the given rectangle has a square aspect ratio.
1822
- */
1823
- function isSquare(rect) {
1824
- return rect.width === rect.height;
1825
- }
1826
- /**
1827
- * Pads a rectangle by the given amount, maintaining the center position.
1828
- *
1829
- * @param rect The rectangle to apply padding to.
1830
- * @param padding The padding to add.
1831
- */
1832
- function pad(rect, padding) {
1833
- return create$7(rect.x - padding, rect.y - padding, rect.width + padding * 2, rect.height + padding * 2);
1834
- }
1835
- /**
1836
- * Returns `true` if the given rectangle contains all the given `points`.
1837
- *
1838
- * @param rect The rectangle to check against.
1839
- * @param points The points to check.
1840
- */
1841
- function containsPoints(rect) {
1842
- var points = [];
1843
- for (var _i = 1; _i < arguments.length; _i++) {
1844
- points[_i - 1] = arguments[_i];
1845
- }
1846
- return points.every(function (point) {
1847
- return (rect.x <= point.x &&
1848
- rect.x + rect.width >= point.x &&
1849
- rect.y <= point.y &&
1850
- rect.y + rect.height >= point.y);
1851
- });
1852
- }
1853
- /**
1854
- * Parses a JSON string representation of a Rectangle and returns an object.
1855
- *
1856
- * @param json A JSON string, either in the form `[x,y,width,height]` or `{"x": 0, "y": 0, "width": 10, "height": 10}`
1857
- * @returns A parsed Point.
1858
- */
1859
- function fromJson$1(json) {
1860
- var obj = JSON.parse(json);
1861
- if (Array.isArray(obj)) {
1862
- var x = obj[0], y = obj[1], width = obj[2], height = obj[3];
1863
- return create$7(x, y, width, height);
1864
- }
1865
- else {
1866
- var x = obj.x, y = obj.y, width = obj.width, height = obj.height;
1867
- return create$7(x, y, width, height);
1868
- }
1679
+ /**
1680
+ * Returns a new `Rectangle` with the given position and size.
1681
+ */
1682
+ function create$7(x, y, width, height) {
1683
+ return { x: x, y: y, width: width, height: height };
1684
+ }
1685
+ /**
1686
+ * Returns a new `Rectangle` at the origin point and given size.
1687
+ */
1688
+ function fromDimensions(dimensions) {
1689
+ return create$7(0, 0, dimensions.width, dimensions.height);
1690
+ }
1691
+ /**
1692
+ * Returns a new `Rectangle` with the given position and size.
1693
+ */
1694
+ function fromPointAndDimensions(point, dimensions) {
1695
+ return create$7(point.x, point.y, dimensions.width, dimensions.height);
1696
+ }
1697
+ /**
1698
+ * Returns a new `Rectangle` with the given top-left and bottom-right positions.
1699
+ * The returned rectangle will always returns a positive width and height.
1700
+ */
1701
+ function fromPoints(topLeftPt, bottomRightPt) {
1702
+ var minX = Math.min(topLeftPt.x, bottomRightPt.x);
1703
+ var minY = Math.min(topLeftPt.y, bottomRightPt.y);
1704
+ var maxX = Math.max(topLeftPt.x, bottomRightPt.x);
1705
+ var maxY = Math.max(topLeftPt.y, bottomRightPt.y);
1706
+ return create$7(minX, minY, maxX - minX, maxY - minY);
1707
+ }
1708
+ /**
1709
+ * Returns a rectangle where the longest length of `rect` will be equal to the
1710
+ * shortest length of `to`. The shortest length of `rect` will be proportionally
1711
+ * scaled to match the aspect ratio of `rect`. The returned rectangle will be
1712
+ * centered within `to`.
1713
+ *
1714
+ * @see {@link cropFit}
1715
+ */
1716
+ function containFit$1(to, rect) {
1717
+ var scale = Math.min(to.width / rect.width, to.height / rect.height);
1718
+ var dimensions$1 = proportionalScale(scale, rect);
1719
+ var position = subtract$1(center$2(to), center$1(dimensions$1));
1720
+ return fromPointAndDimensions(position, dimensions$1);
1721
+ }
1722
+ /**
1723
+ * Returns a rectangle where the shortest length of `rect` will be equal to the
1724
+ * longest length of `to`. The longest length of `rect` will be proportionally
1725
+ * scaled to match the aspect ratio of `rect`. The returned rectangle will be
1726
+ * centered within `to`.
1727
+ *
1728
+ * @see {@link containFit}
1729
+ */
1730
+ function cropFit$1(to, rect) {
1731
+ var scale = Math.max(to.width / rect.width, to.height / rect.height);
1732
+ var dimensions$1 = proportionalScale(scale, rect);
1733
+ var position = subtract$1(center$2(to), center$1(dimensions$1));
1734
+ return fromPointAndDimensions(position, dimensions$1);
1735
+ }
1736
+ /**
1737
+ * Returns a rectangle where each side of `rect` will be reduced proportionally
1738
+ * to have an area less than or equal to the provided `to` value. The returned
1739
+ * rectangle will be centered within the original bounds of `rect`.
1740
+ *
1741
+ * @param to - the maximum area this rectangle can have
1742
+ * @param rect - the rectangle to scale to fit the specified area
1743
+ */
1744
+ function scaleFit$1(to, rect) {
1745
+ var scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
1746
+ var dimensions$1 = floor(proportionalScale(scale, rect));
1747
+ var position = subtract$1(center$2(rect), center$1(dimensions$1));
1748
+ return fromPointAndDimensions(position, dimensions$1);
1749
+ }
1750
+ /**
1751
+ * Returns a rectangle where the position and dimensions are scaled by the given
1752
+ * factors. If `scaleY` is omitted, then the position and dimensions are scaled
1753
+ * uniformly by `scaleOrScaleX`.
1754
+ *
1755
+ * @param rect The rectangle to scale.
1756
+ * @param scaleOrScaleX The uniform scale factor, or the horizontal scale
1757
+ * factor.
1758
+ * @param scaleY The vertical scale factor.
1759
+ * @returns A scaled rectangle.
1760
+ */
1761
+ function scale$1(rect, scaleOrScaleX, scaleY) {
1762
+ if (scaleY == null) {
1763
+ return scale$1(rect, scaleOrScaleX, scaleOrScaleX);
1764
+ }
1765
+ else {
1766
+ var x = rect.x, y = rect.y, width = rect.width, height = rect.height;
1767
+ var scaleX = scaleOrScaleX;
1768
+ return create$7(x * scaleX, y * scaleY, width * scaleX, height * scaleY);
1769
+ }
1770
+ }
1771
+ /**
1772
+ * Returns true if two rectangles are equal in position and size.
1773
+ */
1774
+ function isEqual$1(a, b) {
1775
+ return isEqual$3(a, b) && isEqual(a, b);
1776
+ }
1777
+ /**
1778
+ * Returns a rectangle that has its position shifted by a given offset. The
1779
+ * size of the rectangle is unchanged.
1780
+ */
1781
+ function offset(delta, rect) {
1782
+ return fromPointAndDimensions(add$1(topLeft(rect), delta), rect);
1783
+ }
1784
+ /**
1785
+ * Returns the area of the rectangle.
1786
+ */
1787
+ function area$1(rect) {
1788
+ return rect.width * rect.height;
1789
+ }
1790
+ /**
1791
+ * Returns the center point of the rectangle.
1792
+ */
1793
+ function center$2(rect) {
1794
+ return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
1795
+ }
1796
+ /**
1797
+ * Returns the top-left position of the rectangle, as a point.
1798
+ */
1799
+ function topLeft(rect) {
1800
+ return create$d(rect.x, rect.y);
1801
+ }
1802
+ /**
1803
+ * Returns the bottom-right position of the rectangle, as a point.
1804
+ */
1805
+ function bottomRight(rect) {
1806
+ return create$d(rect.x + rect.width, rect.y + rect.height);
1807
+ }
1808
+ /**
1809
+ * Returns `true` if the given rectangle has a portrait aspect ratio.
1810
+ */
1811
+ function isPortrait(rect) {
1812
+ return rect.width < rect.height;
1813
+ }
1814
+ /**
1815
+ * Returns `true` if the given rectangle has a landscape aspect ratio.
1816
+ */
1817
+ function isLandscape(rect) {
1818
+ return rect.width > rect.height;
1819
+ }
1820
+ /**
1821
+ * Returns `true` if the given rectangle has a square aspect ratio.
1822
+ */
1823
+ function isSquare(rect) {
1824
+ return rect.width === rect.height;
1825
+ }
1826
+ /**
1827
+ * Pads a rectangle by the given amount, maintaining the center position.
1828
+ *
1829
+ * @param rect The rectangle to apply padding to.
1830
+ * @param padding The padding to add.
1831
+ */
1832
+ function pad(rect, padding) {
1833
+ return create$7(rect.x - padding, rect.y - padding, rect.width + padding * 2, rect.height + padding * 2);
1834
+ }
1835
+ /**
1836
+ * Returns `true` if the given rectangle contains all the given `points`.
1837
+ *
1838
+ * @param rect The rectangle to check against.
1839
+ * @param points The points to check.
1840
+ */
1841
+ function containsPoints(rect) {
1842
+ var points = [];
1843
+ for (var _i = 1; _i < arguments.length; _i++) {
1844
+ points[_i - 1] = arguments[_i];
1845
+ }
1846
+ return points.every(function (point) {
1847
+ return (rect.x <= point.x &&
1848
+ rect.x + rect.width >= point.x &&
1849
+ rect.y <= point.y &&
1850
+ rect.y + rect.height >= point.y);
1851
+ });
1852
+ }
1853
+ /**
1854
+ * Parses a JSON string representation of a Rectangle and returns an object.
1855
+ *
1856
+ * @param json A JSON string, either in the form `[x,y,width,height]` or `{"x": 0, "y": 0, "width": 10, "height": 10}`
1857
+ * @returns A parsed Point.
1858
+ */
1859
+ function fromJson$1(json) {
1860
+ var obj = JSON.parse(json);
1861
+ if (Array.isArray(obj)) {
1862
+ var x = obj[0], y = obj[1], width = obj[2], height = obj[3];
1863
+ return create$7(x, y, width, height);
1864
+ }
1865
+ else {
1866
+ var x = obj.x, y = obj.y, width = obj.width, height = obj.height;
1867
+ return create$7(x, y, width, height);
1868
+ }
1869
1869
  }
1870
1870
 
1871
1871
  var rectangle = /*#__PURE__*/Object.freeze({
@@ -1892,143 +1892,143 @@ var rectangle = /*#__PURE__*/Object.freeze({
1892
1892
  fromJson: fromJson$1
1893
1893
  });
1894
1894
 
1895
- /**
1896
- * Returns a `Dimensions` with the given width and height.
1897
- *
1898
- */
1899
- var create$6 = function (width, height) {
1900
- return { width: width, height: height };
1901
- };
1902
- /**
1903
- * Returns a `Dimensions` with the same width and height.
1904
- */
1905
- var square = function (size) {
1906
- return create$6(size, size);
1907
- };
1908
- /**
1909
- * Returns `true` if two dimensions have the same width and height. Otherwise
1910
- * `false`.
1911
- */
1912
- var isEqual = function (a, b) {
1913
- return a.width === b.width && a.height === b.height;
1914
- };
1915
- /**
1916
- * Returns a scaled dimensions, where the width is scaled by `scaleX` and height
1917
- * is scaled by `scaleY`.
1918
- */
1919
- var scale = function (scaleX, scaleY, dimensions) {
1920
- return {
1921
- width: dimensions.width * scaleX,
1922
- height: dimensions.height * scaleY,
1923
- };
1924
- };
1925
- /**
1926
- * Returns a dimension where each length is scaled by `scaleFactor`.
1927
- */
1928
- var proportionalScale = function (scaleFactor, dimensions) {
1929
- return scale(scaleFactor, scaleFactor, dimensions);
1930
- };
1931
- /**
1932
- * Returns a `Dimensions` where the lengths of `dimensions` are trimmed to fit
1933
- * into `to`.
1934
- */
1935
- var trim = function (to, dimensions) {
1936
- return {
1937
- width: Math.min(to.width, dimensions.width),
1938
- height: Math.min(to.height, dimensions.height),
1939
- };
1940
- };
1941
- /**
1942
- * Returns a `Dimensions` where the longest length of `dimensions` will be equal
1943
- * to the shortest length of `to`. The shortest length of `dimensions` will be
1944
- * proportionally scaled to match the aspect ratio of `dimensions`.
1945
- *
1946
- * @see #cropFit()
1947
- */
1948
- var containFit = function (to, dimensions) {
1949
- var _a = containFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1950
- return { width: width, height: height };
1951
- };
1952
- /**
1953
- * Returns a `Dimensions` where the shortest length of `dimensions` will be
1954
- * equal to the longest length of `to`. The longest length of `dimensions` will
1955
- * be proportionally scaled to match the aspect ratio of `dimensions`.
1956
- *
1957
- * @see #containFit()
1958
- */
1959
- var cropFit = function (to, dimensions) {
1960
- var _a = cropFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1961
- return { width: width, height: height };
1962
- };
1963
- /**
1964
- * Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally
1965
- * to have an area less than or equal to the provided `to` value. The returned
1966
- * dimensions will be centered within the original bounds of `dimensions`.
1967
- *
1968
- * @param to - the maximum area this dimensions can have
1969
- * @param dimensions - the dimensions to scale to fit the specified area
1970
- */
1971
- var scaleFit = function (to, dimensions) {
1972
- var _a = scaleFit$1(to, toRectangle(dimensions)), width = _a.width, height = _a.height;
1973
- return { width: width, height: height };
1974
- };
1975
- /**
1976
- * Returns a `Dimensions` with each length rounded.
1977
- */
1978
- var round = function (dimensions) {
1979
- return {
1980
- width: Math.round(dimensions.width),
1981
- height: Math.round(dimensions.height),
1982
- };
1983
- };
1984
- /**
1985
- * Returns a `Dimensions` with each length rounded down.
1986
- */
1987
- var floor = function (dimensions) {
1988
- return {
1989
- width: Math.floor(dimensions.width),
1990
- height: Math.floor(dimensions.height),
1991
- };
1992
- };
1993
- /**
1994
- * Returns the center point of the given `dimensions`.
1995
- */
1996
- var center$1 = function (dimensions) {
1997
- return { x: dimensions.width / 2, y: dimensions.height / 2 };
1998
- };
1999
- /**
2000
- * Returns the aspect ratio of the given `dimensions`, as defined by width over
2001
- * height.
2002
- */
2003
- var aspectRatio = function (_a) {
2004
- var width = _a.width, height = _a.height;
2005
- return width / height;
2006
- };
2007
- /**
2008
- * Returns the area of the given `dimensions`.
2009
- */
2010
- var area = function (_a) {
2011
- var width = _a.width, height = _a.height;
2012
- return width * height;
2013
- };
2014
- /**
2015
- * Returns a `Dimensions` fitted to the provided aspect ratio.
2016
- *
2017
- * @param ratio - Aspect ratio to fit the provided Dimensions to
2018
- * @param dimensions - Dimensions to fit to the specified ratio
2019
- */
2020
- var fitToRatio = function (ratio, dimensions) {
2021
- if (dimensions.width >= dimensions.height * ratio) {
2022
- return create$6(dimensions.height * ratio, dimensions.height);
2023
- }
2024
- return create$6(dimensions.width, dimensions.width / ratio);
2025
- };
2026
- /**
2027
- * Converts a dimension to a rectangle, with an optional position.
2028
- */
2029
- function toRectangle(dimensions, position) {
2030
- if (position === void 0) { position = create$d(); }
2031
- return fromPointAndDimensions(position, dimensions);
1895
+ /**
1896
+ * Returns a `Dimensions` with the given width and height.
1897
+ *
1898
+ */
1899
+ var create$6 = function (width, height) {
1900
+ return { width: width, height: height };
1901
+ };
1902
+ /**
1903
+ * Returns a `Dimensions` with the same width and height.
1904
+ */
1905
+ var square = function (size) {
1906
+ return create$6(size, size);
1907
+ };
1908
+ /**
1909
+ * Returns `true` if two dimensions have the same width and height. Otherwise
1910
+ * `false`.
1911
+ */
1912
+ var isEqual = function (a, b) {
1913
+ return a.width === b.width && a.height === b.height;
1914
+ };
1915
+ /**
1916
+ * Returns a scaled dimensions, where the width is scaled by `scaleX` and height
1917
+ * is scaled by `scaleY`.
1918
+ */
1919
+ var scale = function (scaleX, scaleY, dimensions) {
1920
+ return {
1921
+ width: dimensions.width * scaleX,
1922
+ height: dimensions.height * scaleY,
1923
+ };
1924
+ };
1925
+ /**
1926
+ * Returns a dimension where each length is scaled by `scaleFactor`.
1927
+ */
1928
+ var proportionalScale = function (scaleFactor, dimensions) {
1929
+ return scale(scaleFactor, scaleFactor, dimensions);
1930
+ };
1931
+ /**
1932
+ * Returns a `Dimensions` where the lengths of `dimensions` are trimmed to fit
1933
+ * into `to`.
1934
+ */
1935
+ var trim = function (to, dimensions) {
1936
+ return {
1937
+ width: Math.min(to.width, dimensions.width),
1938
+ height: Math.min(to.height, dimensions.height),
1939
+ };
1940
+ };
1941
+ /**
1942
+ * Returns a `Dimensions` where the longest length of `dimensions` will be equal
1943
+ * to the shortest length of `to`. The shortest length of `dimensions` will be
1944
+ * proportionally scaled to match the aspect ratio of `dimensions`.
1945
+ *
1946
+ * @see #cropFit()
1947
+ */
1948
+ var containFit = function (to, dimensions) {
1949
+ var _a = containFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1950
+ return { width: width, height: height };
1951
+ };
1952
+ /**
1953
+ * Returns a `Dimensions` where the shortest length of `dimensions` will be
1954
+ * equal to the longest length of `to`. The longest length of `dimensions` will
1955
+ * be proportionally scaled to match the aspect ratio of `dimensions`.
1956
+ *
1957
+ * @see #containFit()
1958
+ */
1959
+ var cropFit = function (to, dimensions) {
1960
+ var _a = cropFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1961
+ return { width: width, height: height };
1962
+ };
1963
+ /**
1964
+ * Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally
1965
+ * to have an area less than or equal to the provided `to` value. The returned
1966
+ * dimensions will be centered within the original bounds of `dimensions`.
1967
+ *
1968
+ * @param to - the maximum area this dimensions can have
1969
+ * @param dimensions - the dimensions to scale to fit the specified area
1970
+ */
1971
+ var scaleFit = function (to, dimensions) {
1972
+ var _a = scaleFit$1(to, toRectangle(dimensions)), width = _a.width, height = _a.height;
1973
+ return { width: width, height: height };
1974
+ };
1975
+ /**
1976
+ * Returns a `Dimensions` with each length rounded.
1977
+ */
1978
+ var round = function (dimensions) {
1979
+ return {
1980
+ width: Math.round(dimensions.width),
1981
+ height: Math.round(dimensions.height),
1982
+ };
1983
+ };
1984
+ /**
1985
+ * Returns a `Dimensions` with each length rounded down.
1986
+ */
1987
+ var floor = function (dimensions) {
1988
+ return {
1989
+ width: Math.floor(dimensions.width),
1990
+ height: Math.floor(dimensions.height),
1991
+ };
1992
+ };
1993
+ /**
1994
+ * Returns the center point of the given `dimensions`.
1995
+ */
1996
+ var center$1 = function (dimensions) {
1997
+ return { x: dimensions.width / 2, y: dimensions.height / 2 };
1998
+ };
1999
+ /**
2000
+ * Returns the aspect ratio of the given `dimensions`, as defined by width over
2001
+ * height.
2002
+ */
2003
+ var aspectRatio = function (_a) {
2004
+ var width = _a.width, height = _a.height;
2005
+ return width / height;
2006
+ };
2007
+ /**
2008
+ * Returns the area of the given `dimensions`.
2009
+ */
2010
+ var area = function (_a) {
2011
+ var width = _a.width, height = _a.height;
2012
+ return width * height;
2013
+ };
2014
+ /**
2015
+ * Returns a `Dimensions` fitted to the provided aspect ratio.
2016
+ *
2017
+ * @param ratio - Aspect ratio to fit the provided Dimensions to
2018
+ * @param dimensions - Dimensions to fit to the specified ratio
2019
+ */
2020
+ var fitToRatio = function (ratio, dimensions) {
2021
+ if (dimensions.width >= dimensions.height * ratio) {
2022
+ return create$6(dimensions.height * ratio, dimensions.height);
2023
+ }
2024
+ return create$6(dimensions.width, dimensions.width / ratio);
2025
+ };
2026
+ /**
2027
+ * Converts a dimension to a rectangle, with an optional position.
2028
+ */
2029
+ function toRectangle(dimensions, position) {
2030
+ if (position === void 0) { position = create$d(); }
2031
+ return fromPointAndDimensions(position, dimensions);
2032
2032
  }
2033
2033
 
2034
2034
  var dimensions = /*#__PURE__*/Object.freeze({
@@ -2051,57 +2051,57 @@ var dimensions = /*#__PURE__*/Object.freeze({
2051
2051
  toRectangle: toRectangle
2052
2052
  });
2053
2053
 
2054
- /**
2055
- * Creates a new `Line3`. If unspecified, the start and end values of the line
2056
- * will be at origin.
2057
- *
2058
- * @param values The values to assign to the line.
2059
- */
2060
- function create$5(values) {
2061
- var _a, _b;
2062
- if (values === void 0) { values = {}; }
2063
- return {
2064
- start: (_a = values.start) !== null && _a !== void 0 ? _a : origin(),
2065
- end: (_b = values.end) !== null && _b !== void 0 ? _b : origin(),
2066
- };
2067
- }
2068
- /**
2069
- * Returns the point that is halfway between start and end.
2070
- */
2071
- function center(line) {
2072
- return lerp(line.start, line.end, 0.5);
2073
- }
2074
- /**
2075
- * Returns a line where the start and end points are transformed with the given
2076
- * matrix.
2077
- *
2078
- * @param line The line to transform.
2079
- * @param matrix The matrix to apply.
2080
- * @returns A transformed line.
2081
- */
2082
- function transformMatrix(line, matrix) {
2083
- var start = transformMatrix$1(line.start, matrix);
2084
- var end = transformMatrix$1(line.end, matrix);
2085
- return { start: start, end: end };
2086
- }
2087
- /**
2088
- * Euclidean distance between the start and end points of the line.
2089
- */
2090
- function distance(line) {
2091
- return distance$1(line.start, line.end);
2092
- }
2093
- /**
2094
- * Returns the squared distance between a line's start and end point. If you're
2095
- * just comparing distances, this is slightly more efficient than `distanceTo`.
2096
- */
2097
- function distanceSquared(line) {
2098
- return distanceSquared$1(line.start, line.end);
2099
- }
2100
- /**
2101
- * Returns a vector describing the direction of the line from start to end.
2102
- */
2103
- function direction(line) {
2104
- return subtract(line.end, line.start);
2054
+ /**
2055
+ * Creates a new `Line3`. If unspecified, the start and end values of the line
2056
+ * will be at origin.
2057
+ *
2058
+ * @param values The values to assign to the line.
2059
+ */
2060
+ function create$5(values) {
2061
+ var _a, _b;
2062
+ if (values === void 0) { values = {}; }
2063
+ return {
2064
+ start: (_a = values.start) !== null && _a !== void 0 ? _a : origin(),
2065
+ end: (_b = values.end) !== null && _b !== void 0 ? _b : origin(),
2066
+ };
2067
+ }
2068
+ /**
2069
+ * Returns the point that is halfway between start and end.
2070
+ */
2071
+ function center(line) {
2072
+ return lerp(line.start, line.end, 0.5);
2073
+ }
2074
+ /**
2075
+ * Returns a line where the start and end points are transformed with the given
2076
+ * matrix.
2077
+ *
2078
+ * @param line The line to transform.
2079
+ * @param matrix The matrix to apply.
2080
+ * @returns A transformed line.
2081
+ */
2082
+ function transformMatrix(line, matrix) {
2083
+ var start = transformMatrix$1(line.start, matrix);
2084
+ var end = transformMatrix$1(line.end, matrix);
2085
+ return { start: start, end: end };
2086
+ }
2087
+ /**
2088
+ * Euclidean distance between the start and end points of the line.
2089
+ */
2090
+ function distance(line) {
2091
+ return distance$1(line.start, line.end);
2092
+ }
2093
+ /**
2094
+ * Returns the squared distance between a line's start and end point. If you're
2095
+ * just comparing distances, this is slightly more efficient than `distanceTo`.
2096
+ */
2097
+ function distanceSquared(line) {
2098
+ return distanceSquared$1(line.start, line.end);
2099
+ }
2100
+ /**
2101
+ * Returns a vector describing the direction of the line from start to end.
2102
+ */
2103
+ function direction(line) {
2104
+ return subtract(line.end, line.start);
2105
2105
  }
2106
2106
 
2107
2107
  var line3 = /*#__PURE__*/Object.freeze({
@@ -2114,66 +2114,66 @@ var line3 = /*#__PURE__*/Object.freeze({
2114
2114
  direction: direction
2115
2115
  });
2116
2116
 
2117
- /**
2118
- * Creates a new matrix. If arguments are undefined, returns an identity matrix.
2119
- */
2120
- var create$4 = function (a, b, c, d, tx, ty) {
2121
- if (a === void 0) { a = 1; }
2122
- if (b === void 0) { b = 0; }
2123
- if (c === void 0) { c = 0; }
2124
- if (d === void 0) { d = 1; }
2125
- if (tx === void 0) { tx = 0; }
2126
- if (ty === void 0) { ty = 0; }
2127
- return { a: a, b: b, c: c, d: d, tx: tx, ty: ty };
2128
- };
2129
- /**
2130
- * Returns an identity matrix.
2131
- */
2132
- var identity = function () {
2133
- return create$4();
2134
- };
2135
- /**
2136
- * Creates a matrix that is translated by the given `tx` and `ty` values.
2137
- */
2138
- var translation = function (tx, ty) {
2139
- return translate(tx, ty, identity());
2140
- };
2141
- /**
2142
- * Creates a matrix that is rotated by the given degrees.
2143
- */
2144
- var rotation = function (degrees) {
2145
- return rotate(degrees, identity());
2146
- };
2147
- /**
2148
- * Rotates the given matrix by the given degrees.
2149
- */
2150
- var rotate = function (degrees, matrix) {
2151
- var radians = toRadians(degrees);
2152
- var cos = Math.cos(radians);
2153
- var sin = Math.sin(radians);
2154
- var a = matrix.a * cos + matrix.c * sin;
2155
- var b = matrix.b * cos + matrix.d * sin;
2156
- var c = matrix.a * -sin + matrix.c * cos;
2157
- var d = matrix.b * -sin + matrix.d * cos;
2158
- return create$4(a, b, c, d, matrix.tx, matrix.ty);
2159
- };
2160
- /**
2161
- * Translates the given matrix along the horizontal and vertical axis by the
2162
- * given `dx` and `dy` delta values.
2163
- */
2164
- var translate = function (dx, dy, matrix) {
2165
- var newTx = matrix.a * dx + matrix.c * dy + matrix.tx;
2166
- var newTy = matrix.b * dx + matrix.d * dy + matrix.ty;
2167
- return create$4(matrix.a, matrix.b, matrix.c, matrix.d, newTx, newTy);
2168
- };
2169
- /**
2170
- * Returns the result of applying a geometric transformation of a matrix on the
2171
- * given point.
2172
- */
2173
- var transformPoint = function (matrix, pt) {
2174
- var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
2175
- var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
2176
- return create$d(x, y);
2117
+ /**
2118
+ * Creates a new matrix. If arguments are undefined, returns an identity matrix.
2119
+ */
2120
+ var create$4 = function (a, b, c, d, tx, ty) {
2121
+ if (a === void 0) { a = 1; }
2122
+ if (b === void 0) { b = 0; }
2123
+ if (c === void 0) { c = 0; }
2124
+ if (d === void 0) { d = 1; }
2125
+ if (tx === void 0) { tx = 0; }
2126
+ if (ty === void 0) { ty = 0; }
2127
+ return { a: a, b: b, c: c, d: d, tx: tx, ty: ty };
2128
+ };
2129
+ /**
2130
+ * Returns an identity matrix.
2131
+ */
2132
+ var identity = function () {
2133
+ return create$4();
2134
+ };
2135
+ /**
2136
+ * Creates a matrix that is translated by the given `tx` and `ty` values.
2137
+ */
2138
+ var translation = function (tx, ty) {
2139
+ return translate(tx, ty, identity());
2140
+ };
2141
+ /**
2142
+ * Creates a matrix that is rotated by the given degrees.
2143
+ */
2144
+ var rotation = function (degrees) {
2145
+ return rotate(degrees, identity());
2146
+ };
2147
+ /**
2148
+ * Rotates the given matrix by the given degrees.
2149
+ */
2150
+ var rotate = function (degrees, matrix) {
2151
+ var radians = toRadians(degrees);
2152
+ var cos = Math.cos(radians);
2153
+ var sin = Math.sin(radians);
2154
+ var a = matrix.a * cos + matrix.c * sin;
2155
+ var b = matrix.b * cos + matrix.d * sin;
2156
+ var c = matrix.a * -sin + matrix.c * cos;
2157
+ var d = matrix.b * -sin + matrix.d * cos;
2158
+ return create$4(a, b, c, d, matrix.tx, matrix.ty);
2159
+ };
2160
+ /**
2161
+ * Translates the given matrix along the horizontal and vertical axis by the
2162
+ * given `dx` and `dy` delta values.
2163
+ */
2164
+ var translate = function (dx, dy, matrix) {
2165
+ var newTx = matrix.a * dx + matrix.c * dy + matrix.tx;
2166
+ var newTy = matrix.b * dx + matrix.d * dy + matrix.ty;
2167
+ return create$4(matrix.a, matrix.b, matrix.c, matrix.d, newTx, newTy);
2168
+ };
2169
+ /**
2170
+ * Returns the result of applying a geometric transformation of a matrix on the
2171
+ * given point.
2172
+ */
2173
+ var transformPoint = function (matrix, pt) {
2174
+ var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
2175
+ var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
2176
+ return create$d(x, y);
2177
2177
  };
2178
2178
 
2179
2179
  var matrix = /*#__PURE__*/Object.freeze({
@@ -2187,45 +2187,45 @@ var matrix = /*#__PURE__*/Object.freeze({
2187
2187
  transformPoint: transformPoint
2188
2188
  });
2189
2189
 
2190
- function create$3() {
2191
- var args = [];
2192
- for (var _i = 0; _i < arguments.length; _i++) {
2193
- args[_i] = arguments[_i];
2194
- }
2195
- if (args.length === 2) {
2196
- return {
2197
- a: args[0].x,
2198
- b: args[0].y,
2199
- c: args[1].x,
2200
- d: args[1].y,
2201
- };
2202
- }
2203
- else if (args.length === 4) {
2204
- return {
2205
- a: args[0],
2206
- b: args[1],
2207
- c: args[2],
2208
- d: args[3],
2209
- };
2210
- }
2211
- return {
2212
- a: 0,
2213
- b: 0,
2214
- c: 0,
2215
- d: 0,
2216
- };
2217
- }
2218
- /**
2219
- * Returns the determinant of the provided matrix.
2220
- */
2221
- function determinant(matrix) {
2222
- return matrix.a * matrix.d - matrix.b * matrix.c;
2223
- }
2224
- /**
2225
- * Returns the dot product of the two vectors represented in this matrix.
2226
- */
2227
- function dot(matrix) {
2228
- return matrix.a * matrix.c + matrix.b * matrix.d;
2190
+ function create$3() {
2191
+ var args = [];
2192
+ for (var _i = 0; _i < arguments.length; _i++) {
2193
+ args[_i] = arguments[_i];
2194
+ }
2195
+ if (args.length === 2) {
2196
+ return {
2197
+ a: args[0].x,
2198
+ b: args[0].y,
2199
+ c: args[1].x,
2200
+ d: args[1].y,
2201
+ };
2202
+ }
2203
+ else if (args.length === 4) {
2204
+ return {
2205
+ a: args[0],
2206
+ b: args[1],
2207
+ c: args[2],
2208
+ d: args[3],
2209
+ };
2210
+ }
2211
+ return {
2212
+ a: 0,
2213
+ b: 0,
2214
+ c: 0,
2215
+ d: 0,
2216
+ };
2217
+ }
2218
+ /**
2219
+ * Returns the determinant of the provided matrix.
2220
+ */
2221
+ function determinant(matrix) {
2222
+ return matrix.a * matrix.d - matrix.b * matrix.c;
2223
+ }
2224
+ /**
2225
+ * Returns the dot product of the two vectors represented in this matrix.
2226
+ */
2227
+ function dot(matrix) {
2228
+ return matrix.a * matrix.c + matrix.b * matrix.d;
2229
2229
  }
2230
2230
 
2231
2231
  var matrix2 = /*#__PURE__*/Object.freeze({
@@ -2235,75 +2235,75 @@ var matrix2 = /*#__PURE__*/Object.freeze({
2235
2235
  dot: dot
2236
2236
  });
2237
2237
 
2238
- /**
2239
- * Creates a new plane. Defaults to a normal of `[0,0,0]` and constant of `0`.
2240
- *
2241
- * @param values Values to assign to the plane.
2242
- * @returns A new plane.
2243
- */
2244
- function create$2(values) {
2245
- if (values === void 0) { values = {}; }
2246
- return __assign({ normal: origin(), constant: 0 }, values);
2247
- }
2248
- /**
2249
- * Creates a plane from a normal and an arbitrary point on a plane.
2250
- *
2251
- * @param normal A normal.
2252
- * @param point A point on the plane.
2253
- * @returns A new plane.
2254
- */
2255
- function fromNormalAndCoplanarPoint(normal, point) {
2256
- var constant = -dot$1(point, normal);
2257
- return create$2({ normal: normal, constant: constant });
2258
- }
2259
- /**
2260
- * Returns the perpendicular distance from the plane to the given point.
2261
- *
2262
- * @param plane The plane.
2263
- * @param point The point to calculate distance from `plane`.
2264
- * @returns A distance.
2265
- */
2266
- function distanceToPoint(plane, point) {
2267
- return dot$1(plane.normal, point) + plane.constant;
2268
- }
2269
- /**
2270
- * Returns the point where the line intersects with this plane. If the line does
2271
- * not intersect, then `undefined` is returned. If the line is on the plane,
2272
- * then the starting point of the line is returned.
2273
- *
2274
- * @param plane The plane to intersect.
2275
- * @param line The line to intersect.
2276
- * @returns An intersecting point on the plane and line.
2277
- */
2278
- function intersectLine(plane, line) {
2279
- var direction$1 = direction(line);
2280
- var denominator = dot$1(plane.normal, direction$1);
2281
- if (denominator === 0) {
2282
- if (distanceToPoint(plane, line.start) === 0) {
2283
- return line.start;
2284
- }
2285
- else {
2286
- return undefined;
2287
- }
2288
- }
2289
- var t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
2290
- if (t < 0 || t > 1) {
2291
- return undefined;
2292
- }
2293
- else {
2294
- return add(scale$2(t, direction$1), line.start);
2295
- }
2296
- }
2297
- /**
2298
- * Projects the given `point` onto the given `plane`.
2299
- *
2300
- * @param plane The plane to project onto.
2301
- * @param point The point to project.
2302
- * @returns The projected point.
2303
- */
2304
- function projectPoint(plane, point) {
2305
- var d = distanceToPoint(plane, point);
2306
- return add(point, scale$2(-d, plane.normal));
2238
+ /**
2239
+ * Creates a new plane. Defaults to a normal of `[0,0,0]` and constant of `0`.
2240
+ *
2241
+ * @param values Values to assign to the plane.
2242
+ * @returns A new plane.
2243
+ */
2244
+ function create$2(values) {
2245
+ if (values === void 0) { values = {}; }
2246
+ return __assign({ normal: origin(), constant: 0 }, values);
2247
+ }
2248
+ /**
2249
+ * Creates a plane from a normal and an arbitrary point on a plane.
2250
+ *
2251
+ * @param normal A normal.
2252
+ * @param point A point on the plane.
2253
+ * @returns A new plane.
2254
+ */
2255
+ function fromNormalAndCoplanarPoint(normal, point) {
2256
+ var constant = -dot$1(point, normal);
2257
+ return create$2({ normal: normal, constant: constant });
2258
+ }
2259
+ /**
2260
+ * Returns the perpendicular distance from the plane to the given point.
2261
+ *
2262
+ * @param plane The plane.
2263
+ * @param point The point to calculate distance from `plane`.
2264
+ * @returns A distance.
2265
+ */
2266
+ function distanceToPoint(plane, point) {
2267
+ return dot$1(plane.normal, point) + plane.constant;
2268
+ }
2269
+ /**
2270
+ * Returns the point where the line intersects with this plane. If the line does
2271
+ * not intersect, then `undefined` is returned. If the line is on the plane,
2272
+ * then the starting point of the line is returned.
2273
+ *
2274
+ * @param plane The plane to intersect.
2275
+ * @param line The line to intersect.
2276
+ * @returns An intersecting point on the plane and line.
2277
+ */
2278
+ function intersectLine(plane, line) {
2279
+ var direction$1 = direction(line);
2280
+ var denominator = dot$1(plane.normal, direction$1);
2281
+ if (denominator === 0) {
2282
+ if (distanceToPoint(plane, line.start) === 0) {
2283
+ return line.start;
2284
+ }
2285
+ else {
2286
+ return undefined;
2287
+ }
2288
+ }
2289
+ var t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
2290
+ if (t < 0 || t > 1) {
2291
+ return undefined;
2292
+ }
2293
+ else {
2294
+ return add(scale$2(t, direction$1), line.start);
2295
+ }
2296
+ }
2297
+ /**
2298
+ * Projects the given `point` onto the given `plane`.
2299
+ *
2300
+ * @param plane The plane to project onto.
2301
+ * @param point The point to project.
2302
+ * @returns The projected point.
2303
+ */
2304
+ function projectPoint(plane, point) {
2305
+ var d = distanceToPoint(plane, point);
2306
+ return add(point, scale$2(-d, plane.normal));
2307
2307
  }
2308
2308
 
2309
2309
  var plane = /*#__PURE__*/Object.freeze({
@@ -2315,64 +2315,64 @@ var plane = /*#__PURE__*/Object.freeze({
2315
2315
  projectPoint: projectPoint
2316
2316
  });
2317
2317
 
2318
- /**
2319
- * Creates a new ray with the given values, or using default values if none are
2320
- * provided. The direction defaults to `{x: 0, y: 0, z: -1}` if undefined.
2321
- *
2322
- * @param value The values of the ray.
2323
- * @returns A new ray.
2324
- */
2325
- function create$1(value) {
2326
- var _a, _b;
2327
- if (value === void 0) { value = {}; }
2328
- return {
2329
- origin: (_a = value.origin) !== null && _a !== void 0 ? _a : origin(),
2330
- direction: (_b = value.direction) !== null && _b !== void 0 ? _b : forward(),
2331
- };
2332
- }
2333
- /**
2334
- * Returns a point at the given distance along this ray.
2335
- *
2336
- * @param ray The ray to get the point on.
2337
- * @param distance A distance from origin along the ray's direction.
2338
- * @returns A point on the ray.
2339
- */
2340
- function at(ray, distance) {
2341
- return add(scale$2(distance, ray.direction), ray.origin);
2342
- }
2343
- /**
2344
- * Computes the distance of the `ray`s origin to the given `plane`. Returns a
2345
- * distance of 0 if the ray is coplanar and returns `undefined` if the ray does
2346
- * not intersect with the plane.
2347
- *
2348
- * @param ray The ray to get the distance for.
2349
- * @param plane The plane to compute the distance to.
2350
- * @returns The distance to the plane, or `undefined` if it cannot be computed.
2351
- */
2352
- function distanceToPlane(ray, plane$1) {
2353
- var d = dot$1(plane$1.normal, ray.direction);
2354
- if (d === 0) {
2355
- // Ray is on plane.
2356
- return distanceToPoint(plane$1, ray.origin) === 0 ? 0 : undefined;
2357
- }
2358
- else {
2359
- var t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
2360
- // Checks if ray intersects plane.
2361
- return t >= 0 ? t : undefined;
2362
- }
2363
- }
2364
- /**
2365
- * Computes the intersection point of the given `ray` to the given `plane`. If
2366
- * the ray does not intersect with the plane, then `undefined` is returned.
2367
- *
2368
- * @param ray The ray to intersect.
2369
- * @param plane The plane to intersect with.
2370
- * @returns The intersection point, or `undefined` if the ray does not
2371
- * intersect.
2372
- */
2373
- function intersectPlane(ray, plane) {
2374
- var t = distanceToPlane(ray, plane);
2375
- return t != null ? at(ray, t) : undefined;
2318
+ /**
2319
+ * Creates a new ray with the given values, or using default values if none are
2320
+ * provided. The direction defaults to `{x: 0, y: 0, z: -1}` if undefined.
2321
+ *
2322
+ * @param value The values of the ray.
2323
+ * @returns A new ray.
2324
+ */
2325
+ function create$1(value) {
2326
+ var _a, _b;
2327
+ if (value === void 0) { value = {}; }
2328
+ return {
2329
+ origin: (_a = value.origin) !== null && _a !== void 0 ? _a : origin(),
2330
+ direction: (_b = value.direction) !== null && _b !== void 0 ? _b : forward(),
2331
+ };
2332
+ }
2333
+ /**
2334
+ * Returns a point at the given distance along this ray.
2335
+ *
2336
+ * @param ray The ray to get the point on.
2337
+ * @param distance A distance from origin along the ray's direction.
2338
+ * @returns A point on the ray.
2339
+ */
2340
+ function at(ray, distance) {
2341
+ return add(scale$2(distance, ray.direction), ray.origin);
2342
+ }
2343
+ /**
2344
+ * Computes the distance of the `ray`s origin to the given `plane`. Returns a
2345
+ * distance of 0 if the ray is coplanar and returns `undefined` if the ray does
2346
+ * not intersect with the plane.
2347
+ *
2348
+ * @param ray The ray to get the distance for.
2349
+ * @param plane The plane to compute the distance to.
2350
+ * @returns The distance to the plane, or `undefined` if it cannot be computed.
2351
+ */
2352
+ function distanceToPlane(ray, plane$1) {
2353
+ var d = dot$1(plane$1.normal, ray.direction);
2354
+ if (d === 0) {
2355
+ // Ray is on plane.
2356
+ return distanceToPoint(plane$1, ray.origin) === 0 ? 0 : undefined;
2357
+ }
2358
+ else {
2359
+ var t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
2360
+ // Checks if ray intersects plane.
2361
+ return t >= 0 ? t : undefined;
2362
+ }
2363
+ }
2364
+ /**
2365
+ * Computes the intersection point of the given `ray` to the given `plane`. If
2366
+ * the ray does not intersect with the plane, then `undefined` is returned.
2367
+ *
2368
+ * @param ray The ray to intersect.
2369
+ * @param plane The plane to intersect with.
2370
+ * @returns The intersection point, or `undefined` if the ray does not
2371
+ * intersect.
2372
+ */
2373
+ function intersectPlane(ray, plane) {
2374
+ var t = distanceToPlane(ray, plane);
2375
+ return t != null ? at(ray, t) : undefined;
2376
2376
  }
2377
2377
 
2378
2378
  var ray = /*#__PURE__*/Object.freeze({
@@ -2383,29 +2383,29 @@ var ray = /*#__PURE__*/Object.freeze({
2383
2383
  intersectPlane: intersectPlane
2384
2384
  });
2385
2385
 
2386
- /**
2387
- * Returns a new Vector4. If `value` is undefined, then `{x: 0, y: 0, z: 0,
2388
- * w: 0}` is returned.
2389
- */
2390
- function create(value) {
2391
- if (value === void 0) { value = {}; }
2392
- return __assign({ x: 0, y: 0, z: 0, w: 0 }, value);
2393
- }
2394
- /**
2395
- * Parses a JSON string representation of a `Vector4`.
2396
- *
2397
- * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
2398
- * @returns A parsed `Vector4`.
2399
- */
2400
- function fromJson(json) {
2401
- var obj = JSON.parse(json);
2402
- if (Array.isArray(obj)) {
2403
- var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
2404
- return create({ x: x, y: y, z: z, w: w });
2405
- }
2406
- else {
2407
- return create(obj);
2408
- }
2386
+ /**
2387
+ * Returns a new Vector4. If `value` is undefined, then `{x: 0, y: 0, z: 0,
2388
+ * w: 0}` is returned.
2389
+ */
2390
+ function create(value) {
2391
+ if (value === void 0) { value = {}; }
2392
+ return __assign({ x: 0, y: 0, z: 0, w: 0 }, value);
2393
+ }
2394
+ /**
2395
+ * Parses a JSON string representation of a `Vector4`.
2396
+ *
2397
+ * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
2398
+ * @returns A parsed `Vector4`.
2399
+ */
2400
+ function fromJson(json) {
2401
+ var obj = JSON.parse(json);
2402
+ if (Array.isArray(obj)) {
2403
+ var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
2404
+ return create({ x: x, y: y, z: z, w: w });
2405
+ }
2406
+ else {
2407
+ return create(obj);
2408
+ }
2409
2409
  }
2410
2410
 
2411
2411
  var vector4 = /*#__PURE__*/Object.freeze({