Best JavaScript code snippet using fast-check-monorepo
gl-matrix-3.3.0.js
Source:gl-matrix-3.3.0.js
1/*!2@fileoverview gl-matrix - High performance matrix and vector operations3@author Brandon Jones4@author Colin MacKenzie IV5@version 3.3.06Copyright (c) 2015-2020, Brandon Jones, Colin MacKenzie IV.7Permission is hereby granted, free of charge, to any person obtaining a copy8of this software and associated documentation files (the "Software"), to deal9in the Software without restriction, including without limitation the rights10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11copies of the Software, and to permit persons to whom the Software is12furnished to do so, subject to the following conditions:13The above copyright notice and this permission notice shall be included in14all copies or substantial portions of the Software.15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21THE SOFTWARE.22*/23(function (global, factory) {24 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :25 typeof define === 'function' && define.amd ? define(['exports'], factory) :26 (global = global || self, factory(global.glMatrix = {}));27}(this, (function (exports) { 'use strict';28 /**29 * Common utilities30 * @module glMatrix31 */32 // Configuration Constants33 var EPSILON = 0.000001;34 var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;35 var RANDOM = Math.random;36 /**37 * Sets the type of array used when creating new vectors and matrices38 *39 * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array40 */41 function setMatrixArrayType(type) {42 ARRAY_TYPE = type;43 }44 var degree = Math.PI / 180;45 /**46 * Convert Degree To Radian47 *48 * @param {Number} a Angle in Degrees49 */50 function toRadian(a) {51 return a * degree;52 }53 /**54 * Tests whether or not the arguments have approximately the same value, within an absolute55 * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less56 * than or equal to 1.0, and a relative tolerance is used for larger values)57 *58 * @param {Number} a The first number to test.59 * @param {Number} b The second number to test.60 * @returns {Boolean} True if the numbers are approximately equal, false otherwise.61 */62 function equals(a, b) {63 return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));64 }65 if (!Math.hypot) Math.hypot = function () {66 var y = 0,67 i = arguments.length;68 while (i--) {69 y += arguments[i] * arguments[i];70 }71 return Math.sqrt(y);72 };73 var common = /*#__PURE__*/Object.freeze({74 __proto__: null,75 EPSILON: EPSILON,76 get ARRAY_TYPE () { return ARRAY_TYPE; },77 RANDOM: RANDOM,78 setMatrixArrayType: setMatrixArrayType,79 toRadian: toRadian,80 equals: equals81 });82 /**83 * 2x2 Matrix84 * @module mat285 */86 /**87 * Creates a new identity mat288 *89 * @returns {mat2} a new 2x2 matrix90 */91 function create() {92 var out = new ARRAY_TYPE(4);93 if (ARRAY_TYPE != Float32Array) {94 out[1] = 0;95 out[2] = 0;96 }97 out[0] = 1;98 out[3] = 1;99 return out;100 }101 /**102 * Creates a new mat2 initialized with values from an existing matrix103 *104 * @param {ReadonlyMat2} a matrix to clone105 * @returns {mat2} a new 2x2 matrix106 */107 function clone(a) {108 var out = new ARRAY_TYPE(4);109 out[0] = a[0];110 out[1] = a[1];111 out[2] = a[2];112 out[3] = a[3];113 return out;114 }115 /**116 * Copy the values from one mat2 to another117 *118 * @param {mat2} out the receiving matrix119 * @param {ReadonlyMat2} a the source matrix120 * @returns {mat2} out121 */122 function copy(out, a) {123 out[0] = a[0];124 out[1] = a[1];125 out[2] = a[2];126 out[3] = a[3];127 return out;128 }129 /**130 * Set a mat2 to the identity matrix131 *132 * @param {mat2} out the receiving matrix133 * @returns {mat2} out134 */135 function identity(out) {136 out[0] = 1;137 out[1] = 0;138 out[2] = 0;139 out[3] = 1;140 return out;141 }142 /**143 * Create a new mat2 with the given values144 *145 * @param {Number} m00 Component in column 0, row 0 position (index 0)146 * @param {Number} m01 Component in column 0, row 1 position (index 1)147 * @param {Number} m10 Component in column 1, row 0 position (index 2)148 * @param {Number} m11 Component in column 1, row 1 position (index 3)149 * @returns {mat2} out A new 2x2 matrix150 */151 function fromValues(m00, m01, m10, m11) {152 var out = new ARRAY_TYPE(4);153 out[0] = m00;154 out[1] = m01;155 out[2] = m10;156 out[3] = m11;157 return out;158 }159 /**160 * Set the components of a mat2 to the given values161 *162 * @param {mat2} out the receiving matrix163 * @param {Number} m00 Component in column 0, row 0 position (index 0)164 * @param {Number} m01 Component in column 0, row 1 position (index 1)165 * @param {Number} m10 Component in column 1, row 0 position (index 2)166 * @param {Number} m11 Component in column 1, row 1 position (index 3)167 * @returns {mat2} out168 */169 function set(out, m00, m01, m10, m11) {170 out[0] = m00;171 out[1] = m01;172 out[2] = m10;173 out[3] = m11;174 return out;175 }176 /**177 * Transpose the values of a mat2178 *179 * @param {mat2} out the receiving matrix180 * @param {ReadonlyMat2} a the source matrix181 * @returns {mat2} out182 */183 function transpose(out, a) {184 // If we are transposing ourselves we can skip a few steps but have to cache185 // some values186 if (out === a) {187 var a1 = a[1];188 out[1] = a[2];189 out[2] = a1;190 } else {191 out[0] = a[0];192 out[1] = a[2];193 out[2] = a[1];194 out[3] = a[3];195 }196 return out;197 }198 /**199 * Inverts a mat2200 *201 * @param {mat2} out the receiving matrix202 * @param {ReadonlyMat2} a the source matrix203 * @returns {mat2} out204 */205 function invert(out, a) {206 var a0 = a[0],207 a1 = a[1],208 a2 = a[2],209 a3 = a[3]; // Calculate the determinant210 var det = a0 * a3 - a2 * a1;211 if (!det) {212 return null;213 }214 det = 1.0 / det;215 out[0] = a3 * det;216 out[1] = -a1 * det;217 out[2] = -a2 * det;218 out[3] = a0 * det;219 return out;220 }221 /**222 * Calculates the adjugate of a mat2223 *224 * @param {mat2} out the receiving matrix225 * @param {ReadonlyMat2} a the source matrix226 * @returns {mat2} out227 */228 function adjoint(out, a) {229 // Caching this value is nessecary if out == a230 var a0 = a[0];231 out[0] = a[3];232 out[1] = -a[1];233 out[2] = -a[2];234 out[3] = a0;235 return out;236 }237 /**238 * Calculates the determinant of a mat2239 *240 * @param {ReadonlyMat2} a the source matrix241 * @returns {Number} determinant of a242 */243 function determinant(a) {244 return a[0] * a[3] - a[2] * a[1];245 }246 /**247 * Multiplies two mat2's248 *249 * @param {mat2} out the receiving matrix250 * @param {ReadonlyMat2} a the first operand251 * @param {ReadonlyMat2} b the second operand252 * @returns {mat2} out253 */254 function multiply(out, a, b) {255 var a0 = a[0],256 a1 = a[1],257 a2 = a[2],258 a3 = a[3];259 var b0 = b[0],260 b1 = b[1],261 b2 = b[2],262 b3 = b[3];263 out[0] = a0 * b0 + a2 * b1;264 out[1] = a1 * b0 + a3 * b1;265 out[2] = a0 * b2 + a2 * b3;266 out[3] = a1 * b2 + a3 * b3;267 return out;268 }269 /**270 * Rotates a mat2 by the given angle271 *272 * @param {mat2} out the receiving matrix273 * @param {ReadonlyMat2} a the matrix to rotate274 * @param {Number} rad the angle to rotate the matrix by275 * @returns {mat2} out276 */277 function rotate(out, a, rad) {278 var a0 = a[0],279 a1 = a[1],280 a2 = a[2],281 a3 = a[3];282 var s = Math.sin(rad);283 var c = Math.cos(rad);284 out[0] = a0 * c + a2 * s;285 out[1] = a1 * c + a3 * s;286 out[2] = a0 * -s + a2 * c;287 out[3] = a1 * -s + a3 * c;288 return out;289 }290 /**291 * Scales the mat2 by the dimensions in the given vec2292 *293 * @param {mat2} out the receiving matrix294 * @param {ReadonlyMat2} a the matrix to rotate295 * @param {ReadonlyVec2} v the vec2 to scale the matrix by296 * @returns {mat2} out297 **/298 function scale(out, a, v) {299 var a0 = a[0],300 a1 = a[1],301 a2 = a[2],302 a3 = a[3];303 var v0 = v[0],304 v1 = v[1];305 out[0] = a0 * v0;306 out[1] = a1 * v0;307 out[2] = a2 * v1;308 out[3] = a3 * v1;309 return out;310 }311 /**312 * Creates a matrix from a given angle313 * This is equivalent to (but much faster than):314 *315 * mat2.identity(dest);316 * mat2.rotate(dest, dest, rad);317 *318 * @param {mat2} out mat2 receiving operation result319 * @param {Number} rad the angle to rotate the matrix by320 * @returns {mat2} out321 */322 function fromRotation(out, rad) {323 var s = Math.sin(rad);324 var c = Math.cos(rad);325 out[0] = c;326 out[1] = s;327 out[2] = -s;328 out[3] = c;329 return out;330 }331 /**332 * Creates a matrix from a vector scaling333 * This is equivalent to (but much faster than):334 *335 * mat2.identity(dest);336 * mat2.scale(dest, dest, vec);337 *338 * @param {mat2} out mat2 receiving operation result339 * @param {ReadonlyVec2} v Scaling vector340 * @returns {mat2} out341 */342 function fromScaling(out, v) {343 out[0] = v[0];344 out[1] = 0;345 out[2] = 0;346 out[3] = v[1];347 return out;348 }349 /**350 * Returns a string representation of a mat2351 *352 * @param {ReadonlyMat2} a matrix to represent as a string353 * @returns {String} string representation of the matrix354 */355 function str(a) {356 return "mat2(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";357 }358 /**359 * Returns Frobenius norm of a mat2360 *361 * @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of362 * @returns {Number} Frobenius norm363 */364 function frob(a) {365 return Math.hypot(a[0], a[1], a[2], a[3]);366 }367 /**368 * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix369 * @param {ReadonlyMat2} L the lower triangular matrix370 * @param {ReadonlyMat2} D the diagonal matrix371 * @param {ReadonlyMat2} U the upper triangular matrix372 * @param {ReadonlyMat2} a the input matrix to factorize373 */374 function LDU(L, D, U, a) {375 L[2] = a[2] / a[0];376 U[0] = a[0];377 U[1] = a[1];378 U[3] = a[3] - L[2] * U[1];379 return [L, D, U];380 }381 /**382 * Adds two mat2's383 *384 * @param {mat2} out the receiving matrix385 * @param {ReadonlyMat2} a the first operand386 * @param {ReadonlyMat2} b the second operand387 * @returns {mat2} out388 */389 function add(out, a, b) {390 out[0] = a[0] + b[0];391 out[1] = a[1] + b[1];392 out[2] = a[2] + b[2];393 out[3] = a[3] + b[3];394 return out;395 }396 /**397 * Subtracts matrix b from matrix a398 *399 * @param {mat2} out the receiving matrix400 * @param {ReadonlyMat2} a the first operand401 * @param {ReadonlyMat2} b the second operand402 * @returns {mat2} out403 */404 function subtract(out, a, b) {405 out[0] = a[0] - b[0];406 out[1] = a[1] - b[1];407 out[2] = a[2] - b[2];408 out[3] = a[3] - b[3];409 return out;410 }411 /**412 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)413 *414 * @param {ReadonlyMat2} a The first matrix.415 * @param {ReadonlyMat2} b The second matrix.416 * @returns {Boolean} True if the matrices are equal, false otherwise.417 */418 function exactEquals(a, b) {419 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];420 }421 /**422 * Returns whether or not the matrices have approximately the same elements in the same position.423 *424 * @param {ReadonlyMat2} a The first matrix.425 * @param {ReadonlyMat2} b The second matrix.426 * @returns {Boolean} True if the matrices are equal, false otherwise.427 */428 function equals$1(a, b) {429 var a0 = a[0],430 a1 = a[1],431 a2 = a[2],432 a3 = a[3];433 var b0 = b[0],434 b1 = b[1],435 b2 = b[2],436 b3 = b[3];437 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));438 }439 /**440 * Multiply each element of the matrix by a scalar.441 *442 * @param {mat2} out the receiving matrix443 * @param {ReadonlyMat2} a the matrix to scale444 * @param {Number} b amount to scale the matrix's elements by445 * @returns {mat2} out446 */447 function multiplyScalar(out, a, b) {448 out[0] = a[0] * b;449 out[1] = a[1] * b;450 out[2] = a[2] * b;451 out[3] = a[3] * b;452 return out;453 }454 /**455 * Adds two mat2's after multiplying each element of the second operand by a scalar value.456 *457 * @param {mat2} out the receiving vector458 * @param {ReadonlyMat2} a the first operand459 * @param {ReadonlyMat2} b the second operand460 * @param {Number} scale the amount to scale b's elements by before adding461 * @returns {mat2} out462 */463 function multiplyScalarAndAdd(out, a, b, scale) {464 out[0] = a[0] + b[0] * scale;465 out[1] = a[1] + b[1] * scale;466 out[2] = a[2] + b[2] * scale;467 out[3] = a[3] + b[3] * scale;468 return out;469 }470 /**471 * Alias for {@link mat2.multiply}472 * @function473 */474 var mul = multiply;475 /**476 * Alias for {@link mat2.subtract}477 * @function478 */479 var sub = subtract;480 var mat2 = /*#__PURE__*/Object.freeze({481 __proto__: null,482 create: create,483 clone: clone,484 copy: copy,485 identity: identity,486 fromValues: fromValues,487 set: set,488 transpose: transpose,489 invert: invert,490 adjoint: adjoint,491 determinant: determinant,492 multiply: multiply,493 rotate: rotate,494 scale: scale,495 fromRotation: fromRotation,496 fromScaling: fromScaling,497 str: str,498 frob: frob,499 LDU: LDU,500 add: add,501 subtract: subtract,502 exactEquals: exactEquals,503 equals: equals$1,504 multiplyScalar: multiplyScalar,505 multiplyScalarAndAdd: multiplyScalarAndAdd,506 mul: mul,507 sub: sub508 });509 /**510 * 2x3 Matrix511 * @module mat2d512 * @description513 * A mat2d contains six elements defined as:514 * <pre>515 * [a, b,516 * c, d,517 * tx, ty]518 * </pre>519 * This is a short form for the 3x3 matrix:520 * <pre>521 * [a, b, 0,522 * c, d, 0,523 * tx, ty, 1]524 * </pre>525 * The last column is ignored so the array is shorter and operations are faster.526 */527 /**528 * Creates a new identity mat2d529 *530 * @returns {mat2d} a new 2x3 matrix531 */532 function create$1() {533 var out = new ARRAY_TYPE(6);534 if (ARRAY_TYPE != Float32Array) {535 out[1] = 0;536 out[2] = 0;537 out[4] = 0;538 out[5] = 0;539 }540 out[0] = 1;541 out[3] = 1;542 return out;543 }544 /**545 * Creates a new mat2d initialized with values from an existing matrix546 *547 * @param {ReadonlyMat2d} a matrix to clone548 * @returns {mat2d} a new 2x3 matrix549 */550 function clone$1(a) {551 var out = new ARRAY_TYPE(6);552 out[0] = a[0];553 out[1] = a[1];554 out[2] = a[2];555 out[3] = a[3];556 out[4] = a[4];557 out[5] = a[5];558 return out;559 }560 /**561 * Copy the values from one mat2d to another562 *563 * @param {mat2d} out the receiving matrix564 * @param {ReadonlyMat2d} a the source matrix565 * @returns {mat2d} out566 */567 function copy$1(out, a) {568 out[0] = a[0];569 out[1] = a[1];570 out[2] = a[2];571 out[3] = a[3];572 out[4] = a[4];573 out[5] = a[5];574 return out;575 }576 /**577 * Set a mat2d to the identity matrix578 *579 * @param {mat2d} out the receiving matrix580 * @returns {mat2d} out581 */582 function identity$1(out) {583 out[0] = 1;584 out[1] = 0;585 out[2] = 0;586 out[3] = 1;587 out[4] = 0;588 out[5] = 0;589 return out;590 }591 /**592 * Create a new mat2d with the given values593 *594 * @param {Number} a Component A (index 0)595 * @param {Number} b Component B (index 1)596 * @param {Number} c Component C (index 2)597 * @param {Number} d Component D (index 3)598 * @param {Number} tx Component TX (index 4)599 * @param {Number} ty Component TY (index 5)600 * @returns {mat2d} A new mat2d601 */602 function fromValues$1(a, b, c, d, tx, ty) {603 var out = new ARRAY_TYPE(6);604 out[0] = a;605 out[1] = b;606 out[2] = c;607 out[3] = d;608 out[4] = tx;609 out[5] = ty;610 return out;611 }612 /**613 * Set the components of a mat2d to the given values614 *615 * @param {mat2d} out the receiving matrix616 * @param {Number} a Component A (index 0)617 * @param {Number} b Component B (index 1)618 * @param {Number} c Component C (index 2)619 * @param {Number} d Component D (index 3)620 * @param {Number} tx Component TX (index 4)621 * @param {Number} ty Component TY (index 5)622 * @returns {mat2d} out623 */624 function set$1(out, a, b, c, d, tx, ty) {625 out[0] = a;626 out[1] = b;627 out[2] = c;628 out[3] = d;629 out[4] = tx;630 out[5] = ty;631 return out;632 }633 /**634 * Inverts a mat2d635 *636 * @param {mat2d} out the receiving matrix637 * @param {ReadonlyMat2d} a the source matrix638 * @returns {mat2d} out639 */640 function invert$1(out, a) {641 var aa = a[0],642 ab = a[1],643 ac = a[2],644 ad = a[3];645 var atx = a[4],646 aty = a[5];647 var det = aa * ad - ab * ac;648 if (!det) {649 return null;650 }651 det = 1.0 / det;652 out[0] = ad * det;653 out[1] = -ab * det;654 out[2] = -ac * det;655 out[3] = aa * det;656 out[4] = (ac * aty - ad * atx) * det;657 out[5] = (ab * atx - aa * aty) * det;658 return out;659 }660 /**661 * Calculates the determinant of a mat2d662 *663 * @param {ReadonlyMat2d} a the source matrix664 * @returns {Number} determinant of a665 */666 function determinant$1(a) {667 return a[0] * a[3] - a[1] * a[2];668 }669 /**670 * Multiplies two mat2d's671 *672 * @param {mat2d} out the receiving matrix673 * @param {ReadonlyMat2d} a the first operand674 * @param {ReadonlyMat2d} b the second operand675 * @returns {mat2d} out676 */677 function multiply$1(out, a, b) {678 var a0 = a[0],679 a1 = a[1],680 a2 = a[2],681 a3 = a[3],682 a4 = a[4],683 a5 = a[5];684 var b0 = b[0],685 b1 = b[1],686 b2 = b[2],687 b3 = b[3],688 b4 = b[4],689 b5 = b[5];690 out[0] = a0 * b0 + a2 * b1;691 out[1] = a1 * b0 + a3 * b1;692 out[2] = a0 * b2 + a2 * b3;693 out[3] = a1 * b2 + a3 * b3;694 out[4] = a0 * b4 + a2 * b5 + a4;695 out[5] = a1 * b4 + a3 * b5 + a5;696 return out;697 }698 /**699 * Rotates a mat2d by the given angle700 *701 * @param {mat2d} out the receiving matrix702 * @param {ReadonlyMat2d} a the matrix to rotate703 * @param {Number} rad the angle to rotate the matrix by704 * @returns {mat2d} out705 */706 function rotate$1(out, a, rad) {707 var a0 = a[0],708 a1 = a[1],709 a2 = a[2],710 a3 = a[3],711 a4 = a[4],712 a5 = a[5];713 var s = Math.sin(rad);714 var c = Math.cos(rad);715 out[0] = a0 * c + a2 * s;716 out[1] = a1 * c + a3 * s;717 out[2] = a0 * -s + a2 * c;718 out[3] = a1 * -s + a3 * c;719 out[4] = a4;720 out[5] = a5;721 return out;722 }723 /**724 * Scales the mat2d by the dimensions in the given vec2725 *726 * @param {mat2d} out the receiving matrix727 * @param {ReadonlyMat2d} a the matrix to translate728 * @param {ReadonlyVec2} v the vec2 to scale the matrix by729 * @returns {mat2d} out730 **/731 function scale$1(out, a, v) {732 var a0 = a[0],733 a1 = a[1],734 a2 = a[2],735 a3 = a[3],736 a4 = a[4],737 a5 = a[5];738 var v0 = v[0],739 v1 = v[1];740 out[0] = a0 * v0;741 out[1] = a1 * v0;742 out[2] = a2 * v1;743 out[3] = a3 * v1;744 out[4] = a4;745 out[5] = a5;746 return out;747 }748 /**749 * Translates the mat2d by the dimensions in the given vec2750 *751 * @param {mat2d} out the receiving matrix752 * @param {ReadonlyMat2d} a the matrix to translate753 * @param {ReadonlyVec2} v the vec2 to translate the matrix by754 * @returns {mat2d} out755 **/756 function translate(out, a, v) {757 var a0 = a[0],758 a1 = a[1],759 a2 = a[2],760 a3 = a[3],761 a4 = a[4],762 a5 = a[5];763 var v0 = v[0],764 v1 = v[1];765 out[0] = a0;766 out[1] = a1;767 out[2] = a2;768 out[3] = a3;769 out[4] = a0 * v0 + a2 * v1 + a4;770 out[5] = a1 * v0 + a3 * v1 + a5;771 return out;772 }773 /**774 * Creates a matrix from a given angle775 * This is equivalent to (but much faster than):776 *777 * mat2d.identity(dest);778 * mat2d.rotate(dest, dest, rad);779 *780 * @param {mat2d} out mat2d receiving operation result781 * @param {Number} rad the angle to rotate the matrix by782 * @returns {mat2d} out783 */784 function fromRotation$1(out, rad) {785 var s = Math.sin(rad),786 c = Math.cos(rad);787 out[0] = c;788 out[1] = s;789 out[2] = -s;790 out[3] = c;791 out[4] = 0;792 out[5] = 0;793 return out;794 }795 /**796 * Creates a matrix from a vector scaling797 * This is equivalent to (but much faster than):798 *799 * mat2d.identity(dest);800 * mat2d.scale(dest, dest, vec);801 *802 * @param {mat2d} out mat2d receiving operation result803 * @param {ReadonlyVec2} v Scaling vector804 * @returns {mat2d} out805 */806 function fromScaling$1(out, v) {807 out[0] = v[0];808 out[1] = 0;809 out[2] = 0;810 out[3] = v[1];811 out[4] = 0;812 out[5] = 0;813 return out;814 }815 /**816 * Creates a matrix from a vector translation817 * This is equivalent to (but much faster than):818 *819 * mat2d.identity(dest);820 * mat2d.translate(dest, dest, vec);821 *822 * @param {mat2d} out mat2d receiving operation result823 * @param {ReadonlyVec2} v Translation vector824 * @returns {mat2d} out825 */826 function fromTranslation(out, v) {827 out[0] = 1;828 out[1] = 0;829 out[2] = 0;830 out[3] = 1;831 out[4] = v[0];832 out[5] = v[1];833 return out;834 }835 /**836 * Returns a string representation of a mat2d837 *838 * @param {ReadonlyMat2d} a matrix to represent as a string839 * @returns {String} string representation of the matrix840 */841 function str$1(a) {842 return "mat2d(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ")";843 }844 /**845 * Returns Frobenius norm of a mat2d846 *847 * @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of848 * @returns {Number} Frobenius norm849 */850 function frob$1(a) {851 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);852 }853 /**854 * Adds two mat2d's855 *856 * @param {mat2d} out the receiving matrix857 * @param {ReadonlyMat2d} a the first operand858 * @param {ReadonlyMat2d} b the second operand859 * @returns {mat2d} out860 */861 function add$1(out, a, b) {862 out[0] = a[0] + b[0];863 out[1] = a[1] + b[1];864 out[2] = a[2] + b[2];865 out[3] = a[3] + b[3];866 out[4] = a[4] + b[4];867 out[5] = a[5] + b[5];868 return out;869 }870 /**871 * Subtracts matrix b from matrix a872 *873 * @param {mat2d} out the receiving matrix874 * @param {ReadonlyMat2d} a the first operand875 * @param {ReadonlyMat2d} b the second operand876 * @returns {mat2d} out877 */878 function subtract$1(out, a, b) {879 out[0] = a[0] - b[0];880 out[1] = a[1] - b[1];881 out[2] = a[2] - b[2];882 out[3] = a[3] - b[3];883 out[4] = a[4] - b[4];884 out[5] = a[5] - b[5];885 return out;886 }887 /**888 * Multiply each element of the matrix by a scalar.889 *890 * @param {mat2d} out the receiving matrix891 * @param {ReadonlyMat2d} a the matrix to scale892 * @param {Number} b amount to scale the matrix's elements by893 * @returns {mat2d} out894 */895 function multiplyScalar$1(out, a, b) {896 out[0] = a[0] * b;897 out[1] = a[1] * b;898 out[2] = a[2] * b;899 out[3] = a[3] * b;900 out[4] = a[4] * b;901 out[5] = a[5] * b;902 return out;903 }904 /**905 * Adds two mat2d's after multiplying each element of the second operand by a scalar value.906 *907 * @param {mat2d} out the receiving vector908 * @param {ReadonlyMat2d} a the first operand909 * @param {ReadonlyMat2d} b the second operand910 * @param {Number} scale the amount to scale b's elements by before adding911 * @returns {mat2d} out912 */913 function multiplyScalarAndAdd$1(out, a, b, scale) {914 out[0] = a[0] + b[0] * scale;915 out[1] = a[1] + b[1] * scale;916 out[2] = a[2] + b[2] * scale;917 out[3] = a[3] + b[3] * scale;918 out[4] = a[4] + b[4] * scale;919 out[5] = a[5] + b[5] * scale;920 return out;921 }922 /**923 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)924 *925 * @param {ReadonlyMat2d} a The first matrix.926 * @param {ReadonlyMat2d} b The second matrix.927 * @returns {Boolean} True if the matrices are equal, false otherwise.928 */929 function exactEquals$1(a, b) {930 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];931 }932 /**933 * Returns whether or not the matrices have approximately the same elements in the same position.934 *935 * @param {ReadonlyMat2d} a The first matrix.936 * @param {ReadonlyMat2d} b The second matrix.937 * @returns {Boolean} True if the matrices are equal, false otherwise.938 */939 function equals$2(a, b) {940 var a0 = a[0],941 a1 = a[1],942 a2 = a[2],943 a3 = a[3],944 a4 = a[4],945 a5 = a[5];946 var b0 = b[0],947 b1 = b[1],948 b2 = b[2],949 b3 = b[3],950 b4 = b[4],951 b5 = b[5];952 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));953 }954 /**955 * Alias for {@link mat2d.multiply}956 * @function957 */958 var mul$1 = multiply$1;959 /**960 * Alias for {@link mat2d.subtract}961 * @function962 */963 var sub$1 = subtract$1;964 var mat2d = /*#__PURE__*/Object.freeze({965 __proto__: null,966 create: create$1,967 clone: clone$1,968 copy: copy$1,969 identity: identity$1,970 fromValues: fromValues$1,971 set: set$1,972 invert: invert$1,973 determinant: determinant$1,974 multiply: multiply$1,975 rotate: rotate$1,976 scale: scale$1,977 translate: translate,978 fromRotation: fromRotation$1,979 fromScaling: fromScaling$1,980 fromTranslation: fromTranslation,981 str: str$1,982 frob: frob$1,983 add: add$1,984 subtract: subtract$1,985 multiplyScalar: multiplyScalar$1,986 multiplyScalarAndAdd: multiplyScalarAndAdd$1,987 exactEquals: exactEquals$1,988 equals: equals$2,989 mul: mul$1,990 sub: sub$1991 });992 /**993 * 3x3 Matrix994 * @module mat3995 */996 /**997 * Creates a new identity mat3998 *999 * @returns {mat3} a new 3x3 matrix1000 */1001 function create$2() {1002 var out = new ARRAY_TYPE(9);1003 if (ARRAY_TYPE != Float32Array) {1004 out[1] = 0;1005 out[2] = 0;1006 out[3] = 0;1007 out[5] = 0;1008 out[6] = 0;1009 out[7] = 0;1010 }1011 out[0] = 1;1012 out[4] = 1;1013 out[8] = 1;1014 return out;1015 }1016 /**1017 * Copies the upper-left 3x3 values into the given mat3.1018 *1019 * @param {mat3} out the receiving 3x3 matrix1020 * @param {ReadonlyMat4} a the source 4x4 matrix1021 * @returns {mat3} out1022 */1023 function fromMat4(out, a) {1024 out[0] = a[0];1025 out[1] = a[1];1026 out[2] = a[2];1027 out[3] = a[4];1028 out[4] = a[5];1029 out[5] = a[6];1030 out[6] = a[8];1031 out[7] = a[9];1032 out[8] = a[10];1033 return out;1034 }1035 /**1036 * Creates a new mat3 initialized with values from an existing matrix1037 *1038 * @param {ReadonlyMat3} a matrix to clone1039 * @returns {mat3} a new 3x3 matrix1040 */1041 function clone$2(a) {1042 var out = new ARRAY_TYPE(9);1043 out[0] = a[0];1044 out[1] = a[1];1045 out[2] = a[2];1046 out[3] = a[3];1047 out[4] = a[4];1048 out[5] = a[5];1049 out[6] = a[6];1050 out[7] = a[7];1051 out[8] = a[8];1052 return out;1053 }1054 /**1055 * Copy the values from one mat3 to another1056 *1057 * @param {mat3} out the receiving matrix1058 * @param {ReadonlyMat3} a the source matrix1059 * @returns {mat3} out1060 */1061 function copy$2(out, a) {1062 out[0] = a[0];1063 out[1] = a[1];1064 out[2] = a[2];1065 out[3] = a[3];1066 out[4] = a[4];1067 out[5] = a[5];1068 out[6] = a[6];1069 out[7] = a[7];1070 out[8] = a[8];1071 return out;1072 }1073 /**1074 * Create a new mat3 with the given values1075 *1076 * @param {Number} m00 Component in column 0, row 0 position (index 0)1077 * @param {Number} m01 Component in column 0, row 1 position (index 1)1078 * @param {Number} m02 Component in column 0, row 2 position (index 2)1079 * @param {Number} m10 Component in column 1, row 0 position (index 3)1080 * @param {Number} m11 Component in column 1, row 1 position (index 4)1081 * @param {Number} m12 Component in column 1, row 2 position (index 5)1082 * @param {Number} m20 Component in column 2, row 0 position (index 6)1083 * @param {Number} m21 Component in column 2, row 1 position (index 7)1084 * @param {Number} m22 Component in column 2, row 2 position (index 8)1085 * @returns {mat3} A new mat31086 */1087 function fromValues$2(m00, m01, m02, m10, m11, m12, m20, m21, m22) {1088 var out = new ARRAY_TYPE(9);1089 out[0] = m00;1090 out[1] = m01;1091 out[2] = m02;1092 out[3] = m10;1093 out[4] = m11;1094 out[5] = m12;1095 out[6] = m20;1096 out[7] = m21;1097 out[8] = m22;1098 return out;1099 }1100 /**1101 * Set the components of a mat3 to the given values1102 *1103 * @param {mat3} out the receiving matrix1104 * @param {Number} m00 Component in column 0, row 0 position (index 0)1105 * @param {Number} m01 Component in column 0, row 1 position (index 1)1106 * @param {Number} m02 Component in column 0, row 2 position (index 2)1107 * @param {Number} m10 Component in column 1, row 0 position (index 3)1108 * @param {Number} m11 Component in column 1, row 1 position (index 4)1109 * @param {Number} m12 Component in column 1, row 2 position (index 5)1110 * @param {Number} m20 Component in column 2, row 0 position (index 6)1111 * @param {Number} m21 Component in column 2, row 1 position (index 7)1112 * @param {Number} m22 Component in column 2, row 2 position (index 8)1113 * @returns {mat3} out1114 */1115 function set$2(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {1116 out[0] = m00;1117 out[1] = m01;1118 out[2] = m02;1119 out[3] = m10;1120 out[4] = m11;1121 out[5] = m12;1122 out[6] = m20;1123 out[7] = m21;1124 out[8] = m22;1125 return out;1126 }1127 /**1128 * Set a mat3 to the identity matrix1129 *1130 * @param {mat3} out the receiving matrix1131 * @returns {mat3} out1132 */1133 function identity$2(out) {1134 out[0] = 1;1135 out[1] = 0;1136 out[2] = 0;1137 out[3] = 0;1138 out[4] = 1;1139 out[5] = 0;1140 out[6] = 0;1141 out[7] = 0;1142 out[8] = 1;1143 return out;1144 }1145 /**1146 * Transpose the values of a mat31147 *1148 * @param {mat3} out the receiving matrix1149 * @param {ReadonlyMat3} a the source matrix1150 * @returns {mat3} out1151 */1152 function transpose$1(out, a) {1153 // If we are transposing ourselves we can skip a few steps but have to cache some values1154 if (out === a) {1155 var a01 = a[1],1156 a02 = a[2],1157 a12 = a[5];1158 out[1] = a[3];1159 out[2] = a[6];1160 out[3] = a01;1161 out[5] = a[7];1162 out[6] = a02;1163 out[7] = a12;1164 } else {1165 out[0] = a[0];1166 out[1] = a[3];1167 out[2] = a[6];1168 out[3] = a[1];1169 out[4] = a[4];1170 out[5] = a[7];1171 out[6] = a[2];1172 out[7] = a[5];1173 out[8] = a[8];1174 }1175 return out;1176 }1177 /**1178 * Inverts a mat31179 *1180 * @param {mat3} out the receiving matrix1181 * @param {ReadonlyMat3} a the source matrix1182 * @returns {mat3} out1183 */1184 function invert$2(out, a) {1185 var a00 = a[0],1186 a01 = a[1],1187 a02 = a[2];1188 var a10 = a[3],1189 a11 = a[4],1190 a12 = a[5];1191 var a20 = a[6],1192 a21 = a[7],1193 a22 = a[8];1194 var b01 = a22 * a11 - a12 * a21;1195 var b11 = -a22 * a10 + a12 * a20;1196 var b21 = a21 * a10 - a11 * a20; // Calculate the determinant1197 var det = a00 * b01 + a01 * b11 + a02 * b21;1198 if (!det) {1199 return null;1200 }1201 det = 1.0 / det;1202 out[0] = b01 * det;1203 out[1] = (-a22 * a01 + a02 * a21) * det;1204 out[2] = (a12 * a01 - a02 * a11) * det;1205 out[3] = b11 * det;1206 out[4] = (a22 * a00 - a02 * a20) * det;1207 out[5] = (-a12 * a00 + a02 * a10) * det;1208 out[6] = b21 * det;1209 out[7] = (-a21 * a00 + a01 * a20) * det;1210 out[8] = (a11 * a00 - a01 * a10) * det;1211 return out;1212 }1213 /**1214 * Calculates the adjugate of a mat31215 *1216 * @param {mat3} out the receiving matrix1217 * @param {ReadonlyMat3} a the source matrix1218 * @returns {mat3} out1219 */1220 function adjoint$1(out, a) {1221 var a00 = a[0],1222 a01 = a[1],1223 a02 = a[2];1224 var a10 = a[3],1225 a11 = a[4],1226 a12 = a[5];1227 var a20 = a[6],1228 a21 = a[7],1229 a22 = a[8];1230 out[0] = a11 * a22 - a12 * a21;1231 out[1] = a02 * a21 - a01 * a22;1232 out[2] = a01 * a12 - a02 * a11;1233 out[3] = a12 * a20 - a10 * a22;1234 out[4] = a00 * a22 - a02 * a20;1235 out[5] = a02 * a10 - a00 * a12;1236 out[6] = a10 * a21 - a11 * a20;1237 out[7] = a01 * a20 - a00 * a21;1238 out[8] = a00 * a11 - a01 * a10;1239 return out;1240 }1241 /**1242 * Calculates the determinant of a mat31243 *1244 * @param {ReadonlyMat3} a the source matrix1245 * @returns {Number} determinant of a1246 */1247 function determinant$2(a) {1248 var a00 = a[0],1249 a01 = a[1],1250 a02 = a[2];1251 var a10 = a[3],1252 a11 = a[4],1253 a12 = a[5];1254 var a20 = a[6],1255 a21 = a[7],1256 a22 = a[8];1257 return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);1258 }1259 /**1260 * Multiplies two mat3's1261 *1262 * @param {mat3} out the receiving matrix1263 * @param {ReadonlyMat3} a the first operand1264 * @param {ReadonlyMat3} b the second operand1265 * @returns {mat3} out1266 */1267 function multiply$2(out, a, b) {1268 var a00 = a[0],1269 a01 = a[1],1270 a02 = a[2];1271 var a10 = a[3],1272 a11 = a[4],1273 a12 = a[5];1274 var a20 = a[6],1275 a21 = a[7],1276 a22 = a[8];1277 var b00 = b[0],1278 b01 = b[1],1279 b02 = b[2];1280 var b10 = b[3],1281 b11 = b[4],1282 b12 = b[5];1283 var b20 = b[6],1284 b21 = b[7],1285 b22 = b[8];1286 out[0] = b00 * a00 + b01 * a10 + b02 * a20;1287 out[1] = b00 * a01 + b01 * a11 + b02 * a21;1288 out[2] = b00 * a02 + b01 * a12 + b02 * a22;1289 out[3] = b10 * a00 + b11 * a10 + b12 * a20;1290 out[4] = b10 * a01 + b11 * a11 + b12 * a21;1291 out[5] = b10 * a02 + b11 * a12 + b12 * a22;1292 out[6] = b20 * a00 + b21 * a10 + b22 * a20;1293 out[7] = b20 * a01 + b21 * a11 + b22 * a21;1294 out[8] = b20 * a02 + b21 * a12 + b22 * a22;1295 return out;1296 }1297 /**1298 * Translate a mat3 by the given vector1299 *1300 * @param {mat3} out the receiving matrix1301 * @param {ReadonlyMat3} a the matrix to translate1302 * @param {ReadonlyVec2} v vector to translate by1303 * @returns {mat3} out1304 */1305 function translate$1(out, a, v) {1306 var a00 = a[0],1307 a01 = a[1],1308 a02 = a[2],1309 a10 = a[3],1310 a11 = a[4],1311 a12 = a[5],1312 a20 = a[6],1313 a21 = a[7],1314 a22 = a[8],1315 x = v[0],1316 y = v[1];1317 out[0] = a00;1318 out[1] = a01;1319 out[2] = a02;1320 out[3] = a10;1321 out[4] = a11;1322 out[5] = a12;1323 out[6] = x * a00 + y * a10 + a20;1324 out[7] = x * a01 + y * a11 + a21;1325 out[8] = x * a02 + y * a12 + a22;1326 return out;1327 }1328 /**1329 * Rotates a mat3 by the given angle1330 *1331 * @param {mat3} out the receiving matrix1332 * @param {ReadonlyMat3} a the matrix to rotate1333 * @param {Number} rad the angle to rotate the matrix by1334 * @returns {mat3} out1335 */1336 function rotate$2(out, a, rad) {1337 var a00 = a[0],1338 a01 = a[1],1339 a02 = a[2],1340 a10 = a[3],1341 a11 = a[4],1342 a12 = a[5],1343 a20 = a[6],1344 a21 = a[7],1345 a22 = a[8],1346 s = Math.sin(rad),1347 c = Math.cos(rad);1348 out[0] = c * a00 + s * a10;1349 out[1] = c * a01 + s * a11;1350 out[2] = c * a02 + s * a12;1351 out[3] = c * a10 - s * a00;1352 out[4] = c * a11 - s * a01;1353 out[5] = c * a12 - s * a02;1354 out[6] = a20;1355 out[7] = a21;1356 out[8] = a22;1357 return out;1358 }1359 /**1360 * Scales the mat3 by the dimensions in the given vec21361 *1362 * @param {mat3} out the receiving matrix1363 * @param {ReadonlyMat3} a the matrix to rotate1364 * @param {ReadonlyVec2} v the vec2 to scale the matrix by1365 * @returns {mat3} out1366 **/1367 function scale$2(out, a, v) {1368 var x = v[0],1369 y = v[1];1370 out[0] = x * a[0];1371 out[1] = x * a[1];1372 out[2] = x * a[2];1373 out[3] = y * a[3];1374 out[4] = y * a[4];1375 out[5] = y * a[5];1376 out[6] = a[6];1377 out[7] = a[7];1378 out[8] = a[8];1379 return out;1380 }1381 /**1382 * Creates a matrix from a vector translation1383 * This is equivalent to (but much faster than):1384 *1385 * mat3.identity(dest);1386 * mat3.translate(dest, dest, vec);1387 *1388 * @param {mat3} out mat3 receiving operation result1389 * @param {ReadonlyVec2} v Translation vector1390 * @returns {mat3} out1391 */1392 function fromTranslation$1(out, v) {1393 out[0] = 1;1394 out[1] = 0;1395 out[2] = 0;1396 out[3] = 0;1397 out[4] = 1;1398 out[5] = 0;1399 out[6] = v[0];1400 out[7] = v[1];1401 out[8] = 1;1402 return out;1403 }1404 /**1405 * Creates a matrix from a given angle1406 * This is equivalent to (but much faster than):1407 *1408 * mat3.identity(dest);1409 * mat3.rotate(dest, dest, rad);1410 *1411 * @param {mat3} out mat3 receiving operation result1412 * @param {Number} rad the angle to rotate the matrix by1413 * @returns {mat3} out1414 */1415 function fromRotation$2(out, rad) {1416 var s = Math.sin(rad),1417 c = Math.cos(rad);1418 out[0] = c;1419 out[1] = s;1420 out[2] = 0;1421 out[3] = -s;1422 out[4] = c;1423 out[5] = 0;1424 out[6] = 0;1425 out[7] = 0;1426 out[8] = 1;1427 return out;1428 }1429 /**1430 * Creates a matrix from a vector scaling1431 * This is equivalent to (but much faster than):1432 *1433 * mat3.identity(dest);1434 * mat3.scale(dest, dest, vec);1435 *1436 * @param {mat3} out mat3 receiving operation result1437 * @param {ReadonlyVec2} v Scaling vector1438 * @returns {mat3} out1439 */1440 function fromScaling$2(out, v) {1441 out[0] = v[0];1442 out[1] = 0;1443 out[2] = 0;1444 out[3] = 0;1445 out[4] = v[1];1446 out[5] = 0;1447 out[6] = 0;1448 out[7] = 0;1449 out[8] = 1;1450 return out;1451 }1452 /**1453 * Copies the values from a mat2d into a mat31454 *1455 * @param {mat3} out the receiving matrix1456 * @param {ReadonlyMat2d} a the matrix to copy1457 * @returns {mat3} out1458 **/1459 function fromMat2d(out, a) {1460 out[0] = a[0];1461 out[1] = a[1];1462 out[2] = 0;1463 out[3] = a[2];1464 out[4] = a[3];1465 out[5] = 0;1466 out[6] = a[4];1467 out[7] = a[5];1468 out[8] = 1;1469 return out;1470 }1471 /**1472 * Calculates a 3x3 matrix from the given quaternion1473 *1474 * @param {mat3} out mat3 receiving operation result1475 * @param {ReadonlyQuat} q Quaternion to create matrix from1476 *1477 * @returns {mat3} out1478 */1479 function fromQuat(out, q) {1480 var x = q[0],1481 y = q[1],1482 z = q[2],1483 w = q[3];1484 var x2 = x + x;1485 var y2 = y + y;1486 var z2 = z + z;1487 var xx = x * x2;1488 var yx = y * x2;1489 var yy = y * y2;1490 var zx = z * x2;1491 var zy = z * y2;1492 var zz = z * z2;1493 var wx = w * x2;1494 var wy = w * y2;1495 var wz = w * z2;1496 out[0] = 1 - yy - zz;1497 out[3] = yx - wz;1498 out[6] = zx + wy;1499 out[1] = yx + wz;1500 out[4] = 1 - xx - zz;1501 out[7] = zy - wx;1502 out[2] = zx - wy;1503 out[5] = zy + wx;1504 out[8] = 1 - xx - yy;1505 return out;1506 }1507 /**1508 * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix1509 *1510 * @param {mat3} out mat3 receiving operation result1511 * @param {ReadonlyMat4} a Mat4 to derive the normal matrix from1512 *1513 * @returns {mat3} out1514 */1515 function normalFromMat4(out, a) {1516 var a00 = a[0],1517 a01 = a[1],1518 a02 = a[2],1519 a03 = a[3];1520 var a10 = a[4],1521 a11 = a[5],1522 a12 = a[6],1523 a13 = a[7];1524 var a20 = a[8],1525 a21 = a[9],1526 a22 = a[10],1527 a23 = a[11];1528 var a30 = a[12],1529 a31 = a[13],1530 a32 = a[14],1531 a33 = a[15];1532 var b00 = a00 * a11 - a01 * a10;1533 var b01 = a00 * a12 - a02 * a10;1534 var b02 = a00 * a13 - a03 * a10;1535 var b03 = a01 * a12 - a02 * a11;1536 var b04 = a01 * a13 - a03 * a11;1537 var b05 = a02 * a13 - a03 * a12;1538 var b06 = a20 * a31 - a21 * a30;1539 var b07 = a20 * a32 - a22 * a30;1540 var b08 = a20 * a33 - a23 * a30;1541 var b09 = a21 * a32 - a22 * a31;1542 var b10 = a21 * a33 - a23 * a31;1543 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant1544 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;1545 if (!det) {1546 return null;1547 }1548 det = 1.0 / det;1549 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;1550 out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;1551 out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;1552 out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;1553 out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;1554 out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;1555 out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;1556 out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;1557 out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;1558 return out;1559 }1560 /**1561 * Generates a 2D projection matrix with the given bounds1562 *1563 * @param {mat3} out mat3 frustum matrix will be written into1564 * @param {number} width Width of your gl context1565 * @param {number} height Height of gl context1566 * @returns {mat3} out1567 */1568 function projection(out, width, height) {1569 out[0] = 2 / width;1570 out[1] = 0;1571 out[2] = 0;1572 out[3] = 0;1573 out[4] = -2 / height;1574 out[5] = 0;1575 out[6] = -1;1576 out[7] = 1;1577 out[8] = 1;1578 return out;1579 }1580 /**1581 * Returns a string representation of a mat31582 *1583 * @param {ReadonlyMat3} a matrix to represent as a string1584 * @returns {String} string representation of the matrix1585 */1586 function str$2(a) {1587 return "mat3(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ")";1588 }1589 /**1590 * Returns Frobenius norm of a mat31591 *1592 * @param {ReadonlyMat3} a the matrix to calculate Frobenius norm of1593 * @returns {Number} Frobenius norm1594 */1595 function frob$2(a) {1596 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);1597 }1598 /**1599 * Adds two mat3's1600 *1601 * @param {mat3} out the receiving matrix1602 * @param {ReadonlyMat3} a the first operand1603 * @param {ReadonlyMat3} b the second operand1604 * @returns {mat3} out1605 */1606 function add$2(out, a, b) {1607 out[0] = a[0] + b[0];1608 out[1] = a[1] + b[1];1609 out[2] = a[2] + b[2];1610 out[3] = a[3] + b[3];1611 out[4] = a[4] + b[4];1612 out[5] = a[5] + b[5];1613 out[6] = a[6] + b[6];1614 out[7] = a[7] + b[7];1615 out[8] = a[8] + b[8];1616 return out;1617 }1618 /**1619 * Subtracts matrix b from matrix a1620 *1621 * @param {mat3} out the receiving matrix1622 * @param {ReadonlyMat3} a the first operand1623 * @param {ReadonlyMat3} b the second operand1624 * @returns {mat3} out1625 */1626 function subtract$2(out, a, b) {1627 out[0] = a[0] - b[0];1628 out[1] = a[1] - b[1];1629 out[2] = a[2] - b[2];1630 out[3] = a[3] - b[3];1631 out[4] = a[4] - b[4];1632 out[5] = a[5] - b[5];1633 out[6] = a[6] - b[6];1634 out[7] = a[7] - b[7];1635 out[8] = a[8] - b[8];1636 return out;1637 }1638 /**1639 * Multiply each element of the matrix by a scalar.1640 *1641 * @param {mat3} out the receiving matrix1642 * @param {ReadonlyMat3} a the matrix to scale1643 * @param {Number} b amount to scale the matrix's elements by1644 * @returns {mat3} out1645 */1646 function multiplyScalar$2(out, a, b) {1647 out[0] = a[0] * b;1648 out[1] = a[1] * b;1649 out[2] = a[2] * b;1650 out[3] = a[3] * b;1651 out[4] = a[4] * b;1652 out[5] = a[5] * b;1653 out[6] = a[6] * b;1654 out[7] = a[7] * b;1655 out[8] = a[8] * b;1656 return out;1657 }1658 /**1659 * Adds two mat3's after multiplying each element of the second operand by a scalar value.1660 *1661 * @param {mat3} out the receiving vector1662 * @param {ReadonlyMat3} a the first operand1663 * @param {ReadonlyMat3} b the second operand1664 * @param {Number} scale the amount to scale b's elements by before adding1665 * @returns {mat3} out1666 */1667 function multiplyScalarAndAdd$2(out, a, b, scale) {1668 out[0] = a[0] + b[0] * scale;1669 out[1] = a[1] + b[1] * scale;1670 out[2] = a[2] + b[2] * scale;1671 out[3] = a[3] + b[3] * scale;1672 out[4] = a[4] + b[4] * scale;1673 out[5] = a[5] + b[5] * scale;1674 out[6] = a[6] + b[6] * scale;1675 out[7] = a[7] + b[7] * scale;1676 out[8] = a[8] + b[8] * scale;1677 return out;1678 }1679 /**1680 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)1681 *1682 * @param {ReadonlyMat3} a The first matrix.1683 * @param {ReadonlyMat3} b The second matrix.1684 * @returns {Boolean} True if the matrices are equal, false otherwise.1685 */1686 function exactEquals$2(a, b) {1687 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8];1688 }1689 /**1690 * Returns whether or not the matrices have approximately the same elements in the same position.1691 *1692 * @param {ReadonlyMat3} a The first matrix.1693 * @param {ReadonlyMat3} b The second matrix.1694 * @returns {Boolean} True if the matrices are equal, false otherwise.1695 */1696 function equals$3(a, b) {1697 var a0 = a[0],1698 a1 = a[1],1699 a2 = a[2],1700 a3 = a[3],1701 a4 = a[4],1702 a5 = a[5],1703 a6 = a[6],1704 a7 = a[7],1705 a8 = a[8];1706 var b0 = b[0],1707 b1 = b[1],1708 b2 = b[2],1709 b3 = b[3],1710 b4 = b[4],1711 b5 = b[5],1712 b6 = b[6],1713 b7 = b[7],1714 b8 = b[8];1715 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8));1716 }1717 /**1718 * Alias for {@link mat3.multiply}1719 * @function1720 */1721 var mul$2 = multiply$2;1722 /**1723 * Alias for {@link mat3.subtract}1724 * @function1725 */1726 var sub$2 = subtract$2;1727 var mat3 = /*#__PURE__*/Object.freeze({1728 __proto__: null,1729 create: create$2,1730 fromMat4: fromMat4,1731 clone: clone$2,1732 copy: copy$2,1733 fromValues: fromValues$2,1734 set: set$2,1735 identity: identity$2,1736 transpose: transpose$1,1737 invert: invert$2,1738 adjoint: adjoint$1,1739 determinant: determinant$2,1740 multiply: multiply$2,1741 translate: translate$1,1742 rotate: rotate$2,1743 scale: scale$2,1744 fromTranslation: fromTranslation$1,1745 fromRotation: fromRotation$2,1746 fromScaling: fromScaling$2,1747 fromMat2d: fromMat2d,1748 fromQuat: fromQuat,1749 normalFromMat4: normalFromMat4,1750 projection: projection,1751 str: str$2,1752 frob: frob$2,1753 add: add$2,1754 subtract: subtract$2,1755 multiplyScalar: multiplyScalar$2,1756 multiplyScalarAndAdd: multiplyScalarAndAdd$2,1757 exactEquals: exactEquals$2,1758 equals: equals$3,1759 mul: mul$2,1760 sub: sub$21761 });1762 /**1763 * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.1764 * @module mat41765 */1766 /**1767 * Creates a new identity mat41768 *1769 * @returns {mat4} a new 4x4 matrix1770 */1771 function create$3() {1772 var out = new ARRAY_TYPE(16);1773 if (ARRAY_TYPE != Float32Array) {1774 out[1] = 0;1775 out[2] = 0;1776 out[3] = 0;1777 out[4] = 0;1778 out[6] = 0;1779 out[7] = 0;1780 out[8] = 0;1781 out[9] = 0;1782 out[11] = 0;1783 out[12] = 0;1784 out[13] = 0;1785 out[14] = 0;1786 }1787 out[0] = 1;1788 out[5] = 1;1789 out[10] = 1;1790 out[15] = 1;1791 return out;1792 }1793 /**1794 * Creates a new mat4 initialized with values from an existing matrix1795 *1796 * @param {ReadonlyMat4} a matrix to clone1797 * @returns {mat4} a new 4x4 matrix1798 */1799 function clone$3(a) {1800 var out = new ARRAY_TYPE(16);1801 out[0] = a[0];1802 out[1] = a[1];1803 out[2] = a[2];1804 out[3] = a[3];1805 out[4] = a[4];1806 out[5] = a[5];1807 out[6] = a[6];1808 out[7] = a[7];1809 out[8] = a[8];1810 out[9] = a[9];1811 out[10] = a[10];1812 out[11] = a[11];1813 out[12] = a[12];1814 out[13] = a[13];1815 out[14] = a[14];1816 out[15] = a[15];1817 return out;1818 }1819 /**1820 * Copy the values from one mat4 to another1821 *1822 * @param {mat4} out the receiving matrix1823 * @param {ReadonlyMat4} a the source matrix1824 * @returns {mat4} out1825 */1826 function copy$3(out, a) {1827 out[0] = a[0];1828 out[1] = a[1];1829 out[2] = a[2];1830 out[3] = a[3];1831 out[4] = a[4];1832 out[5] = a[5];1833 out[6] = a[6];1834 out[7] = a[7];1835 out[8] = a[8];1836 out[9] = a[9];1837 out[10] = a[10];1838 out[11] = a[11];1839 out[12] = a[12];1840 out[13] = a[13];1841 out[14] = a[14];1842 out[15] = a[15];1843 return out;1844 }1845 /**1846 * Create a new mat4 with the given values1847 *1848 * @param {Number} m00 Component in column 0, row 0 position (index 0)1849 * @param {Number} m01 Component in column 0, row 1 position (index 1)1850 * @param {Number} m02 Component in column 0, row 2 position (index 2)1851 * @param {Number} m03 Component in column 0, row 3 position (index 3)1852 * @param {Number} m10 Component in column 1, row 0 position (index 4)1853 * @param {Number} m11 Component in column 1, row 1 position (index 5)1854 * @param {Number} m12 Component in column 1, row 2 position (index 6)1855 * @param {Number} m13 Component in column 1, row 3 position (index 7)1856 * @param {Number} m20 Component in column 2, row 0 position (index 8)1857 * @param {Number} m21 Component in column 2, row 1 position (index 9)1858 * @param {Number} m22 Component in column 2, row 2 position (index 10)1859 * @param {Number} m23 Component in column 2, row 3 position (index 11)1860 * @param {Number} m30 Component in column 3, row 0 position (index 12)1861 * @param {Number} m31 Component in column 3, row 1 position (index 13)1862 * @param {Number} m32 Component in column 3, row 2 position (index 14)1863 * @param {Number} m33 Component in column 3, row 3 position (index 15)1864 * @returns {mat4} A new mat41865 */1866 function fromValues$3(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1867 var out = new ARRAY_TYPE(16);1868 out[0] = m00;1869 out[1] = m01;1870 out[2] = m02;1871 out[3] = m03;1872 out[4] = m10;1873 out[5] = m11;1874 out[6] = m12;1875 out[7] = m13;1876 out[8] = m20;1877 out[9] = m21;1878 out[10] = m22;1879 out[11] = m23;1880 out[12] = m30;1881 out[13] = m31;1882 out[14] = m32;1883 out[15] = m33;1884 return out;1885 }1886 /**1887 * Set the components of a mat4 to the given values1888 *1889 * @param {mat4} out the receiving matrix1890 * @param {Number} m00 Component in column 0, row 0 position (index 0)1891 * @param {Number} m01 Component in column 0, row 1 position (index 1)1892 * @param {Number} m02 Component in column 0, row 2 position (index 2)1893 * @param {Number} m03 Component in column 0, row 3 position (index 3)1894 * @param {Number} m10 Component in column 1, row 0 position (index 4)1895 * @param {Number} m11 Component in column 1, row 1 position (index 5)1896 * @param {Number} m12 Component in column 1, row 2 position (index 6)1897 * @param {Number} m13 Component in column 1, row 3 position (index 7)1898 * @param {Number} m20 Component in column 2, row 0 position (index 8)1899 * @param {Number} m21 Component in column 2, row 1 position (index 9)1900 * @param {Number} m22 Component in column 2, row 2 position (index 10)1901 * @param {Number} m23 Component in column 2, row 3 position (index 11)1902 * @param {Number} m30 Component in column 3, row 0 position (index 12)1903 * @param {Number} m31 Component in column 3, row 1 position (index 13)1904 * @param {Number} m32 Component in column 3, row 2 position (index 14)1905 * @param {Number} m33 Component in column 3, row 3 position (index 15)1906 * @returns {mat4} out1907 */1908 function set$3(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {1909 out[0] = m00;1910 out[1] = m01;1911 out[2] = m02;1912 out[3] = m03;1913 out[4] = m10;1914 out[5] = m11;1915 out[6] = m12;1916 out[7] = m13;1917 out[8] = m20;1918 out[9] = m21;1919 out[10] = m22;1920 out[11] = m23;1921 out[12] = m30;1922 out[13] = m31;1923 out[14] = m32;1924 out[15] = m33;1925 return out;1926 }1927 /**1928 * Set a mat4 to the identity matrix1929 *1930 * @param {mat4} out the receiving matrix1931 * @returns {mat4} out1932 */1933 function identity$3(out) {1934 out[0] = 1;1935 out[1] = 0;1936 out[2] = 0;1937 out[3] = 0;1938 out[4] = 0;1939 out[5] = 1;1940 out[6] = 0;1941 out[7] = 0;1942 out[8] = 0;1943 out[9] = 0;1944 out[10] = 1;1945 out[11] = 0;1946 out[12] = 0;1947 out[13] = 0;1948 out[14] = 0;1949 out[15] = 1;1950 return out;1951 }1952 /**1953 * Transpose the values of a mat41954 *1955 * @param {mat4} out the receiving matrix1956 * @param {ReadonlyMat4} a the source matrix1957 * @returns {mat4} out1958 */1959 function transpose$2(out, a) {1960 // If we are transposing ourselves we can skip a few steps but have to cache some values1961 if (out === a) {1962 var a01 = a[1],1963 a02 = a[2],1964 a03 = a[3];1965 var a12 = a[6],1966 a13 = a[7];1967 var a23 = a[11];1968 out[1] = a[4];1969 out[2] = a[8];1970 out[3] = a[12];1971 out[4] = a01;1972 out[6] = a[9];1973 out[7] = a[13];1974 out[8] = a02;1975 out[9] = a12;1976 out[11] = a[14];1977 out[12] = a03;1978 out[13] = a13;1979 out[14] = a23;1980 } else {1981 out[0] = a[0];1982 out[1] = a[4];1983 out[2] = a[8];1984 out[3] = a[12];1985 out[4] = a[1];1986 out[5] = a[5];1987 out[6] = a[9];1988 out[7] = a[13];1989 out[8] = a[2];1990 out[9] = a[6];1991 out[10] = a[10];1992 out[11] = a[14];1993 out[12] = a[3];1994 out[13] = a[7];1995 out[14] = a[11];1996 out[15] = a[15];1997 }1998 return out;1999 }2000 /**2001 * Inverts a mat42002 *2003 * @param {mat4} out the receiving matrix2004 * @param {ReadonlyMat4} a the source matrix2005 * @returns {mat4} out2006 */2007 function invert$3(out, a) {2008 var a00 = a[0],2009 a01 = a[1],2010 a02 = a[2],2011 a03 = a[3];2012 var a10 = a[4],2013 a11 = a[5],2014 a12 = a[6],2015 a13 = a[7];2016 var a20 = a[8],2017 a21 = a[9],2018 a22 = a[10],2019 a23 = a[11];2020 var a30 = a[12],2021 a31 = a[13],2022 a32 = a[14],2023 a33 = a[15];2024 var b00 = a00 * a11 - a01 * a10;2025 var b01 = a00 * a12 - a02 * a10;2026 var b02 = a00 * a13 - a03 * a10;2027 var b03 = a01 * a12 - a02 * a11;2028 var b04 = a01 * a13 - a03 * a11;2029 var b05 = a02 * a13 - a03 * a12;2030 var b06 = a20 * a31 - a21 * a30;2031 var b07 = a20 * a32 - a22 * a30;2032 var b08 = a20 * a33 - a23 * a30;2033 var b09 = a21 * a32 - a22 * a31;2034 var b10 = a21 * a33 - a23 * a31;2035 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2036 var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2037 if (!det) {2038 return null;2039 }2040 det = 1.0 / det;2041 out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;2042 out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;2043 out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;2044 out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;2045 out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;2046 out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;2047 out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;2048 out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;2049 out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;2050 out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;2051 out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;2052 out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;2053 out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;2054 out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;2055 out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;2056 out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;2057 return out;2058 }2059 /**2060 * Calculates the adjugate of a mat42061 *2062 * @param {mat4} out the receiving matrix2063 * @param {ReadonlyMat4} a the source matrix2064 * @returns {mat4} out2065 */2066 function adjoint$2(out, a) {2067 var a00 = a[0],2068 a01 = a[1],2069 a02 = a[2],2070 a03 = a[3];2071 var a10 = a[4],2072 a11 = a[5],2073 a12 = a[6],2074 a13 = a[7];2075 var a20 = a[8],2076 a21 = a[9],2077 a22 = a[10],2078 a23 = a[11];2079 var a30 = a[12],2080 a31 = a[13],2081 a32 = a[14],2082 a33 = a[15];2083 out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);2084 out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));2085 out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);2086 out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));2087 out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));2088 out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);2089 out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));2090 out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);2091 out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);2092 out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));2093 out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);2094 out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));2095 out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));2096 out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);2097 out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));2098 out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);2099 return out;2100 }2101 /**2102 * Calculates the determinant of a mat42103 *2104 * @param {ReadonlyMat4} a the source matrix2105 * @returns {Number} determinant of a2106 */2107 function determinant$3(a) {2108 var a00 = a[0],2109 a01 = a[1],2110 a02 = a[2],2111 a03 = a[3];2112 var a10 = a[4],2113 a11 = a[5],2114 a12 = a[6],2115 a13 = a[7];2116 var a20 = a[8],2117 a21 = a[9],2118 a22 = a[10],2119 a23 = a[11];2120 var a30 = a[12],2121 a31 = a[13],2122 a32 = a[14],2123 a33 = a[15];2124 var b00 = a00 * a11 - a01 * a10;2125 var b01 = a00 * a12 - a02 * a10;2126 var b02 = a00 * a13 - a03 * a10;2127 var b03 = a01 * a12 - a02 * a11;2128 var b04 = a01 * a13 - a03 * a11;2129 var b05 = a02 * a13 - a03 * a12;2130 var b06 = a20 * a31 - a21 * a30;2131 var b07 = a20 * a32 - a22 * a30;2132 var b08 = a20 * a33 - a23 * a30;2133 var b09 = a21 * a32 - a22 * a31;2134 var b10 = a21 * a33 - a23 * a31;2135 var b11 = a22 * a33 - a23 * a32; // Calculate the determinant2136 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;2137 }2138 /**2139 * Multiplies two mat4s2140 *2141 * @param {mat4} out the receiving matrix2142 * @param {ReadonlyMat4} a the first operand2143 * @param {ReadonlyMat4} b the second operand2144 * @returns {mat4} out2145 */2146 function multiply$3(out, a, b) {2147 var a00 = a[0],2148 a01 = a[1],2149 a02 = a[2],2150 a03 = a[3];2151 var a10 = a[4],2152 a11 = a[5],2153 a12 = a[6],2154 a13 = a[7];2155 var a20 = a[8],2156 a21 = a[9],2157 a22 = a[10],2158 a23 = a[11];2159 var a30 = a[12],2160 a31 = a[13],2161 a32 = a[14],2162 a33 = a[15]; // Cache only the current line of the second matrix2163 var b0 = b[0],2164 b1 = b[1],2165 b2 = b[2],2166 b3 = b[3];2167 out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2168 out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2169 out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2170 out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2171 b0 = b[4];2172 b1 = b[5];2173 b2 = b[6];2174 b3 = b[7];2175 out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2176 out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2177 out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2178 out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2179 b0 = b[8];2180 b1 = b[9];2181 b2 = b[10];2182 b3 = b[11];2183 out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2184 out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2185 out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2186 out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2187 b0 = b[12];2188 b1 = b[13];2189 b2 = b[14];2190 b3 = b[15];2191 out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;2192 out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;2193 out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;2194 out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;2195 return out;2196 }2197 /**2198 * Translate a mat4 by the given vector2199 *2200 * @param {mat4} out the receiving matrix2201 * @param {ReadonlyMat4} a the matrix to translate2202 * @param {ReadonlyVec3} v vector to translate by2203 * @returns {mat4} out2204 */2205 function translate$2(out, a, v) {2206 var x = v[0],2207 y = v[1],2208 z = v[2];2209 var a00, a01, a02, a03;2210 var a10, a11, a12, a13;2211 var a20, a21, a22, a23;2212 if (a === out) {2213 out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];2214 out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];2215 out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];2216 out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];2217 } else {2218 a00 = a[0];2219 a01 = a[1];2220 a02 = a[2];2221 a03 = a[3];2222 a10 = a[4];2223 a11 = a[5];2224 a12 = a[6];2225 a13 = a[7];2226 a20 = a[8];2227 a21 = a[9];2228 a22 = a[10];2229 a23 = a[11];2230 out[0] = a00;2231 out[1] = a01;2232 out[2] = a02;2233 out[3] = a03;2234 out[4] = a10;2235 out[5] = a11;2236 out[6] = a12;2237 out[7] = a13;2238 out[8] = a20;2239 out[9] = a21;2240 out[10] = a22;2241 out[11] = a23;2242 out[12] = a00 * x + a10 * y + a20 * z + a[12];2243 out[13] = a01 * x + a11 * y + a21 * z + a[13];2244 out[14] = a02 * x + a12 * y + a22 * z + a[14];2245 out[15] = a03 * x + a13 * y + a23 * z + a[15];2246 }2247 return out;2248 }2249 /**2250 * Scales the mat4 by the dimensions in the given vec3 not using vectorization2251 *2252 * @param {mat4} out the receiving matrix2253 * @param {ReadonlyMat4} a the matrix to scale2254 * @param {ReadonlyVec3} v the vec3 to scale the matrix by2255 * @returns {mat4} out2256 **/2257 function scale$3(out, a, v) {2258 var x = v[0],2259 y = v[1],2260 z = v[2];2261 out[0] = a[0] * x;2262 out[1] = a[1] * x;2263 out[2] = a[2] * x;2264 out[3] = a[3] * x;2265 out[4] = a[4] * y;2266 out[5] = a[5] * y;2267 out[6] = a[6] * y;2268 out[7] = a[7] * y;2269 out[8] = a[8] * z;2270 out[9] = a[9] * z;2271 out[10] = a[10] * z;2272 out[11] = a[11] * z;2273 out[12] = a[12];2274 out[13] = a[13];2275 out[14] = a[14];2276 out[15] = a[15];2277 return out;2278 }2279 /**2280 * Rotates a mat4 by the given angle around the given axis2281 *2282 * @param {mat4} out the receiving matrix2283 * @param {ReadonlyMat4} a the matrix to rotate2284 * @param {Number} rad the angle to rotate the matrix by2285 * @param {ReadonlyVec3} axis the axis to rotate around2286 * @returns {mat4} out2287 */2288 function rotate$3(out, a, rad, axis) {2289 var x = axis[0],2290 y = axis[1],2291 z = axis[2];2292 var len = Math.hypot(x, y, z);2293 var s, c, t;2294 var a00, a01, a02, a03;2295 var a10, a11, a12, a13;2296 var a20, a21, a22, a23;2297 var b00, b01, b02;2298 var b10, b11, b12;2299 var b20, b21, b22;2300 if (len < EPSILON) {2301 return null;2302 }2303 len = 1 / len;2304 x *= len;2305 y *= len;2306 z *= len;2307 s = Math.sin(rad);2308 c = Math.cos(rad);2309 t = 1 - c;2310 a00 = a[0];2311 a01 = a[1];2312 a02 = a[2];2313 a03 = a[3];2314 a10 = a[4];2315 a11 = a[5];2316 a12 = a[6];2317 a13 = a[7];2318 a20 = a[8];2319 a21 = a[9];2320 a22 = a[10];2321 a23 = a[11]; // Construct the elements of the rotation matrix2322 b00 = x * x * t + c;2323 b01 = y * x * t + z * s;2324 b02 = z * x * t - y * s;2325 b10 = x * y * t - z * s;2326 b11 = y * y * t + c;2327 b12 = z * y * t + x * s;2328 b20 = x * z * t + y * s;2329 b21 = y * z * t - x * s;2330 b22 = z * z * t + c; // Perform rotation-specific matrix multiplication2331 out[0] = a00 * b00 + a10 * b01 + a20 * b02;2332 out[1] = a01 * b00 + a11 * b01 + a21 * b02;2333 out[2] = a02 * b00 + a12 * b01 + a22 * b02;2334 out[3] = a03 * b00 + a13 * b01 + a23 * b02;2335 out[4] = a00 * b10 + a10 * b11 + a20 * b12;2336 out[5] = a01 * b10 + a11 * b11 + a21 * b12;2337 out[6] = a02 * b10 + a12 * b11 + a22 * b12;2338 out[7] = a03 * b10 + a13 * b11 + a23 * b12;2339 out[8] = a00 * b20 + a10 * b21 + a20 * b22;2340 out[9] = a01 * b20 + a11 * b21 + a21 * b22;2341 out[10] = a02 * b20 + a12 * b21 + a22 * b22;2342 out[11] = a03 * b20 + a13 * b21 + a23 * b22;2343 if (a !== out) {2344 // If the source and destination differ, copy the unchanged last row2345 out[12] = a[12];2346 out[13] = a[13];2347 out[14] = a[14];2348 out[15] = a[15];2349 }2350 return out;2351 }2352 /**2353 * Rotates a matrix by the given angle around the X axis2354 *2355 * @param {mat4} out the receiving matrix2356 * @param {ReadonlyMat4} a the matrix to rotate2357 * @param {Number} rad the angle to rotate the matrix by2358 * @returns {mat4} out2359 */2360 function rotateX(out, a, rad) {2361 var s = Math.sin(rad);2362 var c = Math.cos(rad);2363 var a10 = a[4];2364 var a11 = a[5];2365 var a12 = a[6];2366 var a13 = a[7];2367 var a20 = a[8];2368 var a21 = a[9];2369 var a22 = a[10];2370 var a23 = a[11];2371 if (a !== out) {2372 // If the source and destination differ, copy the unchanged rows2373 out[0] = a[0];2374 out[1] = a[1];2375 out[2] = a[2];2376 out[3] = a[3];2377 out[12] = a[12];2378 out[13] = a[13];2379 out[14] = a[14];2380 out[15] = a[15];2381 } // Perform axis-specific matrix multiplication2382 out[4] = a10 * c + a20 * s;2383 out[5] = a11 * c + a21 * s;2384 out[6] = a12 * c + a22 * s;2385 out[7] = a13 * c + a23 * s;2386 out[8] = a20 * c - a10 * s;2387 out[9] = a21 * c - a11 * s;2388 out[10] = a22 * c - a12 * s;2389 out[11] = a23 * c - a13 * s;2390 return out;2391 }2392 /**2393 * Rotates a matrix by the given angle around the Y axis2394 *2395 * @param {mat4} out the receiving matrix2396 * @param {ReadonlyMat4} a the matrix to rotate2397 * @param {Number} rad the angle to rotate the matrix by2398 * @returns {mat4} out2399 */2400 function rotateY(out, a, rad) {2401 var s = Math.sin(rad);2402 var c = Math.cos(rad);2403 var a00 = a[0];2404 var a01 = a[1];2405 var a02 = a[2];2406 var a03 = a[3];2407 var a20 = a[8];2408 var a21 = a[9];2409 var a22 = a[10];2410 var a23 = a[11];2411 if (a !== out) {2412 // If the source and destination differ, copy the unchanged rows2413 out[4] = a[4];2414 out[5] = a[5];2415 out[6] = a[6];2416 out[7] = a[7];2417 out[12] = a[12];2418 out[13] = a[13];2419 out[14] = a[14];2420 out[15] = a[15];2421 } // Perform axis-specific matrix multiplication2422 out[0] = a00 * c - a20 * s;2423 out[1] = a01 * c - a21 * s;2424 out[2] = a02 * c - a22 * s;2425 out[3] = a03 * c - a23 * s;2426 out[8] = a00 * s + a20 * c;2427 out[9] = a01 * s + a21 * c;2428 out[10] = a02 * s + a22 * c;2429 out[11] = a03 * s + a23 * c;2430 return out;2431 }2432 /**2433 * Rotates a matrix by the given angle around the Z axis2434 *2435 * @param {mat4} out the receiving matrix2436 * @param {ReadonlyMat4} a the matrix to rotate2437 * @param {Number} rad the angle to rotate the matrix by2438 * @returns {mat4} out2439 */2440 function rotateZ(out, a, rad) {2441 var s = Math.sin(rad);2442 var c = Math.cos(rad);2443 var a00 = a[0];2444 var a01 = a[1];2445 var a02 = a[2];2446 var a03 = a[3];2447 var a10 = a[4];2448 var a11 = a[5];2449 var a12 = a[6];2450 var a13 = a[7];2451 if (a !== out) {2452 // If the source and destination differ, copy the unchanged last row2453 out[8] = a[8];2454 out[9] = a[9];2455 out[10] = a[10];2456 out[11] = a[11];2457 out[12] = a[12];2458 out[13] = a[13];2459 out[14] = a[14];2460 out[15] = a[15];2461 } // Perform axis-specific matrix multiplication2462 out[0] = a00 * c + a10 * s;2463 out[1] = a01 * c + a11 * s;2464 out[2] = a02 * c + a12 * s;2465 out[3] = a03 * c + a13 * s;2466 out[4] = a10 * c - a00 * s;2467 out[5] = a11 * c - a01 * s;2468 out[6] = a12 * c - a02 * s;2469 out[7] = a13 * c - a03 * s;2470 return out;2471 }2472 /**2473 * Creates a matrix from a vector translation2474 * This is equivalent to (but much faster than):2475 *2476 * mat4.identity(dest);2477 * mat4.translate(dest, dest, vec);2478 *2479 * @param {mat4} out mat4 receiving operation result2480 * @param {ReadonlyVec3} v Translation vector2481 * @returns {mat4} out2482 */2483 function fromTranslation$2(out, v) {2484 out[0] = 1;2485 out[1] = 0;2486 out[2] = 0;2487 out[3] = 0;2488 out[4] = 0;2489 out[5] = 1;2490 out[6] = 0;2491 out[7] = 0;2492 out[8] = 0;2493 out[9] = 0;2494 out[10] = 1;2495 out[11] = 0;2496 out[12] = v[0];2497 out[13] = v[1];2498 out[14] = v[2];2499 out[15] = 1;2500 return out;2501 }2502 /**2503 * Creates a matrix from a vector scaling2504 * This is equivalent to (but much faster than):2505 *2506 * mat4.identity(dest);2507 * mat4.scale(dest, dest, vec);2508 *2509 * @param {mat4} out mat4 receiving operation result2510 * @param {ReadonlyVec3} v Scaling vector2511 * @returns {mat4} out2512 */2513 function fromScaling$3(out, v) {2514 out[0] = v[0];2515 out[1] = 0;2516 out[2] = 0;2517 out[3] = 0;2518 out[4] = 0;2519 out[5] = v[1];2520 out[6] = 0;2521 out[7] = 0;2522 out[8] = 0;2523 out[9] = 0;2524 out[10] = v[2];2525 out[11] = 0;2526 out[12] = 0;2527 out[13] = 0;2528 out[14] = 0;2529 out[15] = 1;2530 return out;2531 }2532 /**2533 * Creates a matrix from a given angle around a given axis2534 * This is equivalent to (but much faster than):2535 *2536 * mat4.identity(dest);2537 * mat4.rotate(dest, dest, rad, axis);2538 *2539 * @param {mat4} out mat4 receiving operation result2540 * @param {Number} rad the angle to rotate the matrix by2541 * @param {ReadonlyVec3} axis the axis to rotate around2542 * @returns {mat4} out2543 */2544 function fromRotation$3(out, rad, axis) {2545 var x = axis[0],2546 y = axis[1],2547 z = axis[2];2548 var len = Math.hypot(x, y, z);2549 var s, c, t;2550 if (len < EPSILON) {2551 return null;2552 }2553 len = 1 / len;2554 x *= len;2555 y *= len;2556 z *= len;2557 s = Math.sin(rad);2558 c = Math.cos(rad);2559 t = 1 - c; // Perform rotation-specific matrix multiplication2560 out[0] = x * x * t + c;2561 out[1] = y * x * t + z * s;2562 out[2] = z * x * t - y * s;2563 out[3] = 0;2564 out[4] = x * y * t - z * s;2565 out[5] = y * y * t + c;2566 out[6] = z * y * t + x * s;2567 out[7] = 0;2568 out[8] = x * z * t + y * s;2569 out[9] = y * z * t - x * s;2570 out[10] = z * z * t + c;2571 out[11] = 0;2572 out[12] = 0;2573 out[13] = 0;2574 out[14] = 0;2575 out[15] = 1;2576 return out;2577 }2578 /**2579 * Creates a matrix from the given angle around the X axis2580 * This is equivalent to (but much faster than):2581 *2582 * mat4.identity(dest);2583 * mat4.rotateX(dest, dest, rad);2584 *2585 * @param {mat4} out mat4 receiving operation result2586 * @param {Number} rad the angle to rotate the matrix by2587 * @returns {mat4} out2588 */2589 function fromXRotation(out, rad) {2590 var s = Math.sin(rad);2591 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2592 out[0] = 1;2593 out[1] = 0;2594 out[2] = 0;2595 out[3] = 0;2596 out[4] = 0;2597 out[5] = c;2598 out[6] = s;2599 out[7] = 0;2600 out[8] = 0;2601 out[9] = -s;2602 out[10] = c;2603 out[11] = 0;2604 out[12] = 0;2605 out[13] = 0;2606 out[14] = 0;2607 out[15] = 1;2608 return out;2609 }2610 /**2611 * Creates a matrix from the given angle around the Y axis2612 * This is equivalent to (but much faster than):2613 *2614 * mat4.identity(dest);2615 * mat4.rotateY(dest, dest, rad);2616 *2617 * @param {mat4} out mat4 receiving operation result2618 * @param {Number} rad the angle to rotate the matrix by2619 * @returns {mat4} out2620 */2621 function fromYRotation(out, rad) {2622 var s = Math.sin(rad);2623 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2624 out[0] = c;2625 out[1] = 0;2626 out[2] = -s;2627 out[3] = 0;2628 out[4] = 0;2629 out[5] = 1;2630 out[6] = 0;2631 out[7] = 0;2632 out[8] = s;2633 out[9] = 0;2634 out[10] = c;2635 out[11] = 0;2636 out[12] = 0;2637 out[13] = 0;2638 out[14] = 0;2639 out[15] = 1;2640 return out;2641 }2642 /**2643 * Creates a matrix from the given angle around the Z axis2644 * This is equivalent to (but much faster than):2645 *2646 * mat4.identity(dest);2647 * mat4.rotateZ(dest, dest, rad);2648 *2649 * @param {mat4} out mat4 receiving operation result2650 * @param {Number} rad the angle to rotate the matrix by2651 * @returns {mat4} out2652 */2653 function fromZRotation(out, rad) {2654 var s = Math.sin(rad);2655 var c = Math.cos(rad); // Perform axis-specific matrix multiplication2656 out[0] = c;2657 out[1] = s;2658 out[2] = 0;2659 out[3] = 0;2660 out[4] = -s;2661 out[5] = c;2662 out[6] = 0;2663 out[7] = 0;2664 out[8] = 0;2665 out[9] = 0;2666 out[10] = 1;2667 out[11] = 0;2668 out[12] = 0;2669 out[13] = 0;2670 out[14] = 0;2671 out[15] = 1;2672 return out;2673 }2674 /**2675 * Creates a matrix from a quaternion rotation and vector translation2676 * This is equivalent to (but much faster than):2677 *2678 * mat4.identity(dest);2679 * mat4.translate(dest, vec);2680 * let quatMat = mat4.create();2681 * quat4.toMat4(quat, quatMat);2682 * mat4.multiply(dest, quatMat);2683 *2684 * @param {mat4} out mat4 receiving operation result2685 * @param {quat4} q Rotation quaternion2686 * @param {ReadonlyVec3} v Translation vector2687 * @returns {mat4} out2688 */2689 function fromRotationTranslation(out, q, v) {2690 // Quaternion math2691 var x = q[0],2692 y = q[1],2693 z = q[2],2694 w = q[3];2695 var x2 = x + x;2696 var y2 = y + y;2697 var z2 = z + z;2698 var xx = x * x2;2699 var xy = x * y2;2700 var xz = x * z2;2701 var yy = y * y2;2702 var yz = y * z2;2703 var zz = z * z2;2704 var wx = w * x2;2705 var wy = w * y2;2706 var wz = w * z2;2707 out[0] = 1 - (yy + zz);2708 out[1] = xy + wz;2709 out[2] = xz - wy;2710 out[3] = 0;2711 out[4] = xy - wz;2712 out[5] = 1 - (xx + zz);2713 out[6] = yz + wx;2714 out[7] = 0;2715 out[8] = xz + wy;2716 out[9] = yz - wx;2717 out[10] = 1 - (xx + yy);2718 out[11] = 0;2719 out[12] = v[0];2720 out[13] = v[1];2721 out[14] = v[2];2722 out[15] = 1;2723 return out;2724 }2725 /**2726 * Creates a new mat4 from a dual quat.2727 *2728 * @param {mat4} out Matrix2729 * @param {ReadonlyQuat2} a Dual Quaternion2730 * @returns {mat4} mat4 receiving operation result2731 */2732 function fromQuat2(out, a) {2733 var translation = new ARRAY_TYPE(3);2734 var bx = -a[0],2735 by = -a[1],2736 bz = -a[2],2737 bw = a[3],2738 ax = a[4],2739 ay = a[5],2740 az = a[6],2741 aw = a[7];2742 var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense2743 if (magnitude > 0) {2744 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;2745 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;2746 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;2747 } else {2748 translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;2749 translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;2750 translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;2751 }2752 fromRotationTranslation(out, a, translation);2753 return out;2754 }2755 /**2756 * Returns the translation vector component of a transformation2757 * matrix. If a matrix is built with fromRotationTranslation,2758 * the returned vector will be the same as the translation vector2759 * originally supplied.2760 * @param {vec3} out Vector to receive translation component2761 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2762 * @return {vec3} out2763 */2764 function getTranslation(out, mat) {2765 out[0] = mat[12];2766 out[1] = mat[13];2767 out[2] = mat[14];2768 return out;2769 }2770 /**2771 * Returns the scaling factor component of a transformation2772 * matrix. If a matrix is built with fromRotationTranslationScale2773 * with a normalized Quaternion paramter, the returned vector will be2774 * the same as the scaling vector2775 * originally supplied.2776 * @param {vec3} out Vector to receive scaling factor component2777 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2778 * @return {vec3} out2779 */2780 function getScaling(out, mat) {2781 var m11 = mat[0];2782 var m12 = mat[1];2783 var m13 = mat[2];2784 var m21 = mat[4];2785 var m22 = mat[5];2786 var m23 = mat[6];2787 var m31 = mat[8];2788 var m32 = mat[9];2789 var m33 = mat[10];2790 out[0] = Math.hypot(m11, m12, m13);2791 out[1] = Math.hypot(m21, m22, m23);2792 out[2] = Math.hypot(m31, m32, m33);2793 return out;2794 }2795 /**2796 * Returns a quaternion representing the rotational component2797 * of a transformation matrix. If a matrix is built with2798 * fromRotationTranslation, the returned quaternion will be the2799 * same as the quaternion originally supplied.2800 * @param {quat} out Quaternion to receive the rotation component2801 * @param {ReadonlyMat4} mat Matrix to be decomposed (input)2802 * @return {quat} out2803 */2804 function getRotation(out, mat) {2805 var scaling = new ARRAY_TYPE(3);2806 getScaling(scaling, mat);2807 var is1 = 1 / scaling[0];2808 var is2 = 1 / scaling[1];2809 var is3 = 1 / scaling[2];2810 var sm11 = mat[0] * is1;2811 var sm12 = mat[1] * is2;2812 var sm13 = mat[2] * is3;2813 var sm21 = mat[4] * is1;2814 var sm22 = mat[5] * is2;2815 var sm23 = mat[6] * is3;2816 var sm31 = mat[8] * is1;2817 var sm32 = mat[9] * is2;2818 var sm33 = mat[10] * is3;2819 var trace = sm11 + sm22 + sm33;2820 var S = 0;2821 if (trace > 0) {2822 S = Math.sqrt(trace + 1.0) * 2;2823 out[3] = 0.25 * S;2824 out[0] = (sm23 - sm32) / S;2825 out[1] = (sm31 - sm13) / S;2826 out[2] = (sm12 - sm21) / S;2827 } else if (sm11 > sm22 && sm11 > sm33) {2828 S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;2829 out[3] = (sm23 - sm32) / S;2830 out[0] = 0.25 * S;2831 out[1] = (sm12 + sm21) / S;2832 out[2] = (sm31 + sm13) / S;2833 } else if (sm22 > sm33) {2834 S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;2835 out[3] = (sm31 - sm13) / S;2836 out[0] = (sm12 + sm21) / S;2837 out[1] = 0.25 * S;2838 out[2] = (sm23 + sm32) / S;2839 } else {2840 S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;2841 out[3] = (sm12 - sm21) / S;2842 out[0] = (sm31 + sm13) / S;2843 out[1] = (sm23 + sm32) / S;2844 out[2] = 0.25 * S;2845 }2846 return out;2847 }2848 /**2849 * Creates a matrix from a quaternion rotation, vector translation and vector scale2850 * This is equivalent to (but much faster than):2851 *2852 * mat4.identity(dest);2853 * mat4.translate(dest, vec);2854 * let quatMat = mat4.create();2855 * quat4.toMat4(quat, quatMat);2856 * mat4.multiply(dest, quatMat);2857 * mat4.scale(dest, scale)2858 *2859 * @param {mat4} out mat4 receiving operation result2860 * @param {quat4} q Rotation quaternion2861 * @param {ReadonlyVec3} v Translation vector2862 * @param {ReadonlyVec3} s Scaling vector2863 * @returns {mat4} out2864 */2865 function fromRotationTranslationScale(out, q, v, s) {2866 // Quaternion math2867 var x = q[0],2868 y = q[1],2869 z = q[2],2870 w = q[3];2871 var x2 = x + x;2872 var y2 = y + y;2873 var z2 = z + z;2874 var xx = x * x2;2875 var xy = x * y2;2876 var xz = x * z2;2877 var yy = y * y2;2878 var yz = y * z2;2879 var zz = z * z2;2880 var wx = w * x2;2881 var wy = w * y2;2882 var wz = w * z2;2883 var sx = s[0];2884 var sy = s[1];2885 var sz = s[2];2886 out[0] = (1 - (yy + zz)) * sx;2887 out[1] = (xy + wz) * sx;2888 out[2] = (xz - wy) * sx;2889 out[3] = 0;2890 out[4] = (xy - wz) * sy;2891 out[5] = (1 - (xx + zz)) * sy;2892 out[6] = (yz + wx) * sy;2893 out[7] = 0;2894 out[8] = (xz + wy) * sz;2895 out[9] = (yz - wx) * sz;2896 out[10] = (1 - (xx + yy)) * sz;2897 out[11] = 0;2898 out[12] = v[0];2899 out[13] = v[1];2900 out[14] = v[2];2901 out[15] = 1;2902 return out;2903 }2904 /**2905 * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin2906 * This is equivalent to (but much faster than):2907 *2908 * mat4.identity(dest);2909 * mat4.translate(dest, vec);2910 * mat4.translate(dest, origin);2911 * let quatMat = mat4.create();2912 * quat4.toMat4(quat, quatMat);2913 * mat4.multiply(dest, quatMat);2914 * mat4.scale(dest, scale)2915 * mat4.translate(dest, negativeOrigin);2916 *2917 * @param {mat4} out mat4 receiving operation result2918 * @param {quat4} q Rotation quaternion2919 * @param {ReadonlyVec3} v Translation vector2920 * @param {ReadonlyVec3} s Scaling vector2921 * @param {ReadonlyVec3} o The origin vector around which to scale and rotate2922 * @returns {mat4} out2923 */2924 function fromRotationTranslationScaleOrigin(out, q, v, s, o) {2925 // Quaternion math2926 var x = q[0],2927 y = q[1],2928 z = q[2],2929 w = q[3];2930 var x2 = x + x;2931 var y2 = y + y;2932 var z2 = z + z;2933 var xx = x * x2;2934 var xy = x * y2;2935 var xz = x * z2;2936 var yy = y * y2;2937 var yz = y * z2;2938 var zz = z * z2;2939 var wx = w * x2;2940 var wy = w * y2;2941 var wz = w * z2;2942 var sx = s[0];2943 var sy = s[1];2944 var sz = s[2];2945 var ox = o[0];2946 var oy = o[1];2947 var oz = o[2];2948 var out0 = (1 - (yy + zz)) * sx;2949 var out1 = (xy + wz) * sx;2950 var out2 = (xz - wy) * sx;2951 var out4 = (xy - wz) * sy;2952 var out5 = (1 - (xx + zz)) * sy;2953 var out6 = (yz + wx) * sy;2954 var out8 = (xz + wy) * sz;2955 var out9 = (yz - wx) * sz;2956 var out10 = (1 - (xx + yy)) * sz;2957 out[0] = out0;2958 out[1] = out1;2959 out[2] = out2;2960 out[3] = 0;2961 out[4] = out4;2962 out[5] = out5;2963 out[6] = out6;2964 out[7] = 0;2965 out[8] = out8;2966 out[9] = out9;2967 out[10] = out10;2968 out[11] = 0;2969 out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);2970 out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);2971 out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);2972 out[15] = 1;2973 return out;2974 }2975 /**2976 * Calculates a 4x4 matrix from the given quaternion2977 *2978 * @param {mat4} out mat4 receiving operation result2979 * @param {ReadonlyQuat} q Quaternion to create matrix from2980 *2981 * @returns {mat4} out2982 */2983 function fromQuat$1(out, q) {2984 var x = q[0],2985 y = q[1],2986 z = q[2],2987 w = q[3];2988 var x2 = x + x;2989 var y2 = y + y;2990 var z2 = z + z;2991 var xx = x * x2;2992 var yx = y * x2;2993 var yy = y * y2;2994 var zx = z * x2;2995 var zy = z * y2;2996 var zz = z * z2;2997 var wx = w * x2;2998 var wy = w * y2;2999 var wz = w * z2;3000 out[0] = 1 - yy - zz;3001 out[1] = yx + wz;3002 out[2] = zx - wy;3003 out[3] = 0;3004 out[4] = yx - wz;3005 out[5] = 1 - xx - zz;3006 out[6] = zy + wx;3007 out[7] = 0;3008 out[8] = zx + wy;3009 out[9] = zy - wx;3010 out[10] = 1 - xx - yy;3011 out[11] = 0;3012 out[12] = 0;3013 out[13] = 0;3014 out[14] = 0;3015 out[15] = 1;3016 return out;3017 }3018 /**3019 * Generates a frustum matrix with the given bounds3020 *3021 * @param {mat4} out mat4 frustum matrix will be written into3022 * @param {Number} left Left bound of the frustum3023 * @param {Number} right Right bound of the frustum3024 * @param {Number} bottom Bottom bound of the frustum3025 * @param {Number} top Top bound of the frustum3026 * @param {Number} near Near bound of the frustum3027 * @param {Number} far Far bound of the frustum3028 * @returns {mat4} out3029 */3030 function frustum(out, left, right, bottom, top, near, far) {3031 var rl = 1 / (right - left);3032 var tb = 1 / (top - bottom);3033 var nf = 1 / (near - far);3034 out[0] = near * 2 * rl;3035 out[1] = 0;3036 out[2] = 0;3037 out[3] = 0;3038 out[4] = 0;3039 out[5] = near * 2 * tb;3040 out[6] = 0;3041 out[7] = 0;3042 out[8] = (right + left) * rl;3043 out[9] = (top + bottom) * tb;3044 out[10] = (far + near) * nf;3045 out[11] = -1;3046 out[12] = 0;3047 out[13] = 0;3048 out[14] = far * near * 2 * nf;3049 out[15] = 0;3050 return out;3051 }3052 /**3053 * Generates a perspective projection matrix with the given bounds.3054 * Passing null/undefined/no value for far will generate infinite projection matrix.3055 *3056 * @param {mat4} out mat4 frustum matrix will be written into3057 * @param {number} fovy Vertical field of view in radians3058 * @param {number} aspect Aspect ratio. typically viewport width/height3059 * @param {number} near Near bound of the frustum3060 * @param {number} far Far bound of the frustum, can be null or Infinity3061 * @returns {mat4} out3062 */3063 function perspective(out, fovy, aspect, near, far) {3064 var f = 1.0 / Math.tan(fovy / 2),3065 nf;3066 out[0] = f / aspect;3067 out[1] = 0;3068 out[2] = 0;3069 out[3] = 0;3070 out[4] = 0;3071 out[5] = f;3072 out[6] = 0;3073 out[7] = 0;3074 out[8] = 0;3075 out[9] = 0;3076 out[11] = -1;3077 out[12] = 0;3078 out[13] = 0;3079 out[15] = 0;3080 if (far != null && far !== Infinity) {3081 nf = 1 / (near - far);3082 out[10] = (far + near) * nf;3083 out[14] = 2 * far * near * nf;3084 } else {3085 out[10] = -1;3086 out[14] = -2 * near;3087 }3088 //out[10] = -out[10];3089 //out[14] = -out[14];3090 return out;3091 }3092 /**3093 * Generates a perspective projection matrix with the given field of view.3094 * This is primarily useful for generating projection matrices to be used3095 * with the still experiemental WebVR API.3096 *3097 * @param {mat4} out mat4 frustum matrix will be written into3098 * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees3099 * @param {number} near Near bound of the frustum3100 * @param {number} far Far bound of the frustum3101 * @returns {mat4} out3102 */3103 function perspectiveFromFieldOfView(out, fov, near, far) {3104 var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);3105 var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);3106 var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);3107 var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);3108 var xScale = 2.0 / (leftTan + rightTan);3109 var yScale = 2.0 / (upTan + downTan);3110 out[0] = xScale;3111 out[1] = 0.0;3112 out[2] = 0.0;3113 out[3] = 0.0;3114 out[4] = 0.0;3115 out[5] = yScale;3116 out[6] = 0.0;3117 out[7] = 0.0;3118 out[8] = -((leftTan - rightTan) * xScale * 0.5);3119 out[9] = (upTan - downTan) * yScale * 0.5;3120 out[10] = far / (near - far);3121 out[11] = -1.0;3122 out[12] = 0.0;3123 out[13] = 0.0;3124 out[14] = far * near / (near - far);3125 out[15] = 0.0;3126 return out;3127 }3128 /**3129 * Generates a orthogonal projection matrix with the given bounds3130 *3131 * @param {mat4} out mat4 frustum matrix will be written into3132 * @param {number} left Left bound of the frustum3133 * @param {number} right Right bound of the frustum3134 * @param {number} bottom Bottom bound of the frustum3135 * @param {number} top Top bound of the frustum3136 * @param {number} near Near bound of the frustum3137 * @param {number} far Far bound of the frustum3138 * @returns {mat4} out3139 */3140 function ortho(out, left, right, bottom, top, near, far) {3141 var lr = 1 / (left - right);3142 var bt = 1 / (bottom - top);3143 var nf = 1 / (near - far);3144 out[0] = -2 * lr;3145 out[1] = 0;3146 out[2] = 0;3147 out[3] = 0;3148 out[4] = 0;3149 out[5] = -2 * bt;3150 out[6] = 0;3151 out[7] = 0;3152 out[8] = 0;3153 out[9] = 0;3154 out[10] = 2 * nf;3155 out[11] = 0;3156 out[12] = (left + right) * lr;3157 out[13] = (top + bottom) * bt;3158 out[14] = (far + near) * nf;3159 out[15] = 1;3160 return out;3161 }3162 /**3163 * Generates a look-at matrix with the given eye position, focal point, and up axis.3164 * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.3165 *3166 * @param {mat4} out mat4 frustum matrix will be written into3167 * @param {ReadonlyVec3} eye Position of the viewer3168 * @param {ReadonlyVec3} center Point the viewer is looking at3169 * @param {ReadonlyVec3} up vec3 pointing up3170 * @returns {mat4} out3171 */3172 function lookAt(out, eye, center, up) {3173 var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;3174 var eyex = eye[0];3175 var eyey = eye[1];3176 var eyez = eye[2];3177 var upx = up[0];3178 var upy = up[1];3179 var upz = up[2];3180 var centerx = center[0];3181 var centery = center[1];3182 var centerz = center[2];3183 if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {3184 return identity$3(out);3185 }3186 z0 = eyex - centerx;3187 z1 = eyey - centery;3188 z2 = eyez - centerz;3189 len = 1 / Math.hypot(z0, z1, z2);3190 z0 *= len;3191 z1 *= len;3192 z2 *= len;3193 x0 = upy * z2 - upz * z1;3194 x1 = upz * z0 - upx * z2;3195 x2 = upx * z1 - upy * z0;3196 len = Math.hypot(x0, x1, x2);3197 if (!len) {3198 x0 = 0;3199 x1 = 0;3200 x2 = 0;3201 } else {3202 len = 1 / len;3203 x0 *= len;3204 x1 *= len;3205 x2 *= len;3206 }3207 y0 = z1 * x2 - z2 * x1;3208 y1 = z2 * x0 - z0 * x2;3209 y2 = z0 * x1 - z1 * x0;3210 len = Math.hypot(y0, y1, y2);3211 if (!len) {3212 y0 = 0;3213 y1 = 0;3214 y2 = 0;3215 } else {3216 len = 1 / len;3217 y0 *= len;3218 y1 *= len;3219 y2 *= len;3220 }3221 out[0] = x0;3222 out[1] = y0;3223 out[2] = z0;3224 out[3] = 0;3225 out[4] = x1;3226 out[5] = y1;3227 out[6] = z1;3228 out[7] = 0;3229 out[8] = x2;3230 out[9] = y2;3231 out[10] = z2;3232 out[11] = 0;3233 out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);3234 out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);3235 out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);3236 out[15] = 1;3237 return out;3238 }3239 /**3240 * Generates a matrix that makes something look at something else.3241 *3242 * @param {mat4} out mat4 frustum matrix will be written into3243 * @param {ReadonlyVec3} eye Position of the viewer3244 * @param {ReadonlyVec3} center Point the viewer is looking at3245 * @param {ReadonlyVec3} up vec3 pointing up3246 * @returns {mat4} out3247 */3248 function targetTo(out, eye, target, up) {3249 var eyex = eye[0],3250 eyey = eye[1],3251 eyez = eye[2],3252 upx = up[0],3253 upy = up[1],3254 upz = up[2];3255 var z0 = eyex - target[0],3256 z1 = eyey - target[1],3257 z2 = eyez - target[2];3258 var len = z0 * z0 + z1 * z1 + z2 * z2;3259 if (len > 0) {3260 len = 1 / Math.sqrt(len);3261 z0 *= len;3262 z1 *= len;3263 z2 *= len;3264 }3265 var x0 = upy * z2 - upz * z1,3266 x1 = upz * z0 - upx * z2,3267 x2 = upx * z1 - upy * z0;3268 len = x0 * x0 + x1 * x1 + x2 * x2;3269 if (len > 0) {3270 len = 1 / Math.sqrt(len);3271 x0 *= len;3272 x1 *= len;3273 x2 *= len;3274 }3275 out[0] = x0;3276 out[1] = x1;3277 out[2] = x2;3278 out[3] = 0;3279 out[4] = z1 * x2 - z2 * x1;3280 out[5] = z2 * x0 - z0 * x2;3281 out[6] = z0 * x1 - z1 * x0;3282 out[7] = 0;3283 out[8] = z0;3284 out[9] = z1;3285 out[10] = z2;3286 out[11] = 0;3287 out[12] = eyex;3288 out[13] = eyey;3289 out[14] = eyez;3290 out[15] = 1;3291 return out;3292 }3293 /**3294 * Returns a string representation of a mat43295 *3296 * @param {ReadonlyMat4} a matrix to represent as a string3297 * @returns {String} string representation of the matrix3298 */3299 function str$3(a) {3300 return "mat4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ", " + a[9] + ", " + a[10] + ", " + a[11] + ", " + a[12] + ", " + a[13] + ", " + a[14] + ", " + a[15] + ")";3301 }3302 /**3303 * Returns Frobenius norm of a mat43304 *3305 * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of3306 * @returns {Number} Frobenius norm3307 */3308 function frob$3(a) {3309 return Math.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]);3310 }3311 /**3312 * Adds two mat4's3313 *3314 * @param {mat4} out the receiving matrix3315 * @param {ReadonlyMat4} a the first operand3316 * @param {ReadonlyMat4} b the second operand3317 * @returns {mat4} out3318 */3319 function add$3(out, a, b) {3320 out[0] = a[0] + b[0];3321 out[1] = a[1] + b[1];3322 out[2] = a[2] + b[2];3323 out[3] = a[3] + b[3];3324 out[4] = a[4] + b[4];3325 out[5] = a[5] + b[5];3326 out[6] = a[6] + b[6];3327 out[7] = a[7] + b[7];3328 out[8] = a[8] + b[8];3329 out[9] = a[9] + b[9];3330 out[10] = a[10] + b[10];3331 out[11] = a[11] + b[11];3332 out[12] = a[12] + b[12];3333 out[13] = a[13] + b[13];3334 out[14] = a[14] + b[14];3335 out[15] = a[15] + b[15];3336 return out;3337 }3338 /**3339 * Subtracts matrix b from matrix a3340 *3341 * @param {mat4} out the receiving matrix3342 * @param {ReadonlyMat4} a the first operand3343 * @param {ReadonlyMat4} b the second operand3344 * @returns {mat4} out3345 */3346 function subtract$3(out, a, b) {3347 out[0] = a[0] - b[0];3348 out[1] = a[1] - b[1];3349 out[2] = a[2] - b[2];3350 out[3] = a[3] - b[3];3351 out[4] = a[4] - b[4];3352 out[5] = a[5] - b[5];3353 out[6] = a[6] - b[6];3354 out[7] = a[7] - b[7];3355 out[8] = a[8] - b[8];3356 out[9] = a[9] - b[9];3357 out[10] = a[10] - b[10];3358 out[11] = a[11] - b[11];3359 out[12] = a[12] - b[12];3360 out[13] = a[13] - b[13];3361 out[14] = a[14] - b[14];3362 out[15] = a[15] - b[15];3363 return out;3364 }3365 /**3366 * Multiply each element of the matrix by a scalar.3367 *3368 * @param {mat4} out the receiving matrix3369 * @param {ReadonlyMat4} a the matrix to scale3370 * @param {Number} b amount to scale the matrix's elements by3371 * @returns {mat4} out3372 */3373 function multiplyScalar$3(out, a, b) {3374 out[0] = a[0] * b;3375 out[1] = a[1] * b;3376 out[2] = a[2] * b;3377 out[3] = a[3] * b;3378 out[4] = a[4] * b;3379 out[5] = a[5] * b;3380 out[6] = a[6] * b;3381 out[7] = a[7] * b;3382 out[8] = a[8] * b;3383 out[9] = a[9] * b;3384 out[10] = a[10] * b;3385 out[11] = a[11] * b;3386 out[12] = a[12] * b;3387 out[13] = a[13] * b;3388 out[14] = a[14] * b;3389 out[15] = a[15] * b;3390 return out;3391 }3392 /**3393 * Adds two mat4's after multiplying each element of the second operand by a scalar value.3394 *3395 * @param {mat4} out the receiving vector3396 * @param {ReadonlyMat4} a the first operand3397 * @param {ReadonlyMat4} b the second operand3398 * @param {Number} scale the amount to scale b's elements by before adding3399 * @returns {mat4} out3400 */3401 function multiplyScalarAndAdd$3(out, a, b, scale) {3402 out[0] = a[0] + b[0] * scale;3403 out[1] = a[1] + b[1] * scale;3404 out[2] = a[2] + b[2] * scale;3405 out[3] = a[3] + b[3] * scale;3406 out[4] = a[4] + b[4] * scale;3407 out[5] = a[5] + b[5] * scale;3408 out[6] = a[6] + b[6] * scale;3409 out[7] = a[7] + b[7] * scale;3410 out[8] = a[8] + b[8] * scale;3411 out[9] = a[9] + b[9] * scale;3412 out[10] = a[10] + b[10] * scale;3413 out[11] = a[11] + b[11] * scale;3414 out[12] = a[12] + b[12] * scale;3415 out[13] = a[13] + b[13] * scale;3416 out[14] = a[14] + b[14] * scale;3417 out[15] = a[15] + b[15] * scale;3418 return out;3419 }3420 /**3421 * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)3422 *3423 * @param {ReadonlyMat4} a The first matrix.3424 * @param {ReadonlyMat4} b The second matrix.3425 * @returns {Boolean} True if the matrices are equal, false otherwise.3426 */3427 function exactEquals$3(a, b) {3428 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];3429 }3430 /**3431 * Returns whether or not the matrices have approximately the same elements in the same position.3432 *3433 * @param {ReadonlyMat4} a The first matrix.3434 * @param {ReadonlyMat4} b The second matrix.3435 * @returns {Boolean} True if the matrices are equal, false otherwise.3436 */3437 function equals$4(a, b) {3438 var a0 = a[0],3439 a1 = a[1],3440 a2 = a[2],3441 a3 = a[3];3442 var a4 = a[4],3443 a5 = a[5],3444 a6 = a[6],3445 a7 = a[7];3446 var a8 = a[8],3447 a9 = a[9],3448 a10 = a[10],3449 a11 = a[11];3450 var a12 = a[12],3451 a13 = a[13],3452 a14 = a[14],3453 a15 = a[15];3454 var b0 = b[0],3455 b1 = b[1],3456 b2 = b[2],3457 b3 = b[3];3458 var b4 = b[4],3459 b5 = b[5],3460 b6 = b[6],3461 b7 = b[7];3462 var b8 = b[8],3463 b9 = b[9],3464 b10 = b[10],3465 b11 = b[11];3466 var b12 = b[12],3467 b13 = b[13],3468 b14 = b[14],3469 b15 = b[15];3470 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));3471 }3472 /**3473 * Alias for {@link mat4.multiply}3474 * @function3475 */3476 var mul$3 = multiply$3;3477 /**3478 * Alias for {@link mat4.subtract}3479 * @function3480 */3481 var sub$3 = subtract$3;3482 var mat4 = /*#__PURE__*/Object.freeze({3483 __proto__: null,3484 create: create$3,3485 clone: clone$3,3486 copy: copy$3,3487 fromValues: fromValues$3,3488 set: set$3,3489 identity: identity$3,3490 transpose: transpose$2,3491 invert: invert$3,3492 adjoint: adjoint$2,3493 determinant: determinant$3,3494 multiply: multiply$3,3495 translate: translate$2,3496 scale: scale$3,3497 rotate: rotate$3,3498 rotateX: rotateX,3499 rotateY: rotateY,3500 rotateZ: rotateZ,3501 fromTranslation: fromTranslation$2,3502 fromScaling: fromScaling$3,3503 fromRotation: fromRotation$3,3504 fromXRotation: fromXRotation,3505 fromYRotation: fromYRotation,3506 fromZRotation: fromZRotation,3507 fromRotationTranslation: fromRotationTranslation,3508 fromQuat2: fromQuat2,3509 getTranslation: getTranslation,3510 getScaling: getScaling,3511 getRotation: getRotation,3512 fromRotationTranslationScale: fromRotationTranslationScale,3513 fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin,3514 fromQuat: fromQuat$1,3515 frustum: frustum,3516 perspective: perspective,3517 perspectiveFromFieldOfView: perspectiveFromFieldOfView,3518 ortho: ortho,3519 lookAt: lookAt,3520 targetTo: targetTo,3521 str: str$3,3522 frob: frob$3,3523 add: add$3,3524 subtract: subtract$3,3525 multiplyScalar: multiplyScalar$3,3526 multiplyScalarAndAdd: multiplyScalarAndAdd$3,3527 exactEquals: exactEquals$3,3528 equals: equals$4,3529 mul: mul$3,3530 sub: sub$33531 });3532 /**3533 * 3 Dimensional Vector3534 * @module vec33535 */3536 /**3537 * Creates a new, empty vec33538 *3539 * @returns {vec3} a new 3D vector3540 */3541 function create$4() {3542 var out = new ARRAY_TYPE(3);3543 if (ARRAY_TYPE != Float32Array) {3544 out[0] = 0;3545 out[1] = 0;3546 out[2] = 0;3547 }3548 return out;3549 }3550 /**3551 * Creates a new vec3 initialized with values from an existing vector3552 *3553 * @param {ReadonlyVec3} a vector to clone3554 * @returns {vec3} a new 3D vector3555 */3556 function clone$4(a) {3557 var out = new ARRAY_TYPE(3);3558 out[0] = a[0];3559 out[1] = a[1];3560 out[2] = a[2];3561 return out;3562 }3563 /**3564 * Calculates the length of a vec33565 *3566 * @param {ReadonlyVec3} a vector to calculate length of3567 * @returns {Number} length of a3568 */3569 function length(a) {3570 var x = a[0];3571 var y = a[1];3572 var z = a[2];3573 return Math.hypot(x, y, z);3574 }3575 /**3576 * Creates a new vec3 initialized with the given values3577 *3578 * @param {Number} x X component3579 * @param {Number} y Y component3580 * @param {Number} z Z component3581 * @returns {vec3} a new 3D vector3582 */3583 function fromValues$4(x, y, z) {3584 var out = new ARRAY_TYPE(3);3585 out[0] = x;3586 out[1] = y;3587 out[2] = z;3588 return out;3589 }3590 /**3591 * Copy the values from one vec3 to another3592 *3593 * @param {vec3} out the receiving vector3594 * @param {ReadonlyVec3} a the source vector3595 * @returns {vec3} out3596 */3597 function copy$4(out, a) {3598 out[0] = a[0];3599 out[1] = a[1];3600 out[2] = a[2];3601 return out;3602 }3603 /**3604 * Set the components of a vec3 to the given values3605 *3606 * @param {vec3} out the receiving vector3607 * @param {Number} x X component3608 * @param {Number} y Y component3609 * @param {Number} z Z component3610 * @returns {vec3} out3611 */3612 function set$4(out, x, y, z) {3613 out[0] = x;3614 out[1] = y;3615 out[2] = z;3616 return out;3617 }3618 /**3619 * Adds two vec3's3620 *3621 * @param {vec3} out the receiving vector3622 * @param {ReadonlyVec3} a the first operand3623 * @param {ReadonlyVec3} b the second operand3624 * @returns {vec3} out3625 */3626 function add$4(out, a, b) {3627 out[0] = a[0] + b[0];3628 out[1] = a[1] + b[1];3629 out[2] = a[2] + b[2];3630 return out;3631 }3632 /**3633 * Subtracts vector b from vector a3634 *3635 * @param {vec3} out the receiving vector3636 * @param {ReadonlyVec3} a the first operand3637 * @param {ReadonlyVec3} b the second operand3638 * @returns {vec3} out3639 */3640 function subtract$4(out, a, b) {3641 out[0] = a[0] - b[0];3642 out[1] = a[1] - b[1];3643 out[2] = a[2] - b[2];3644 return out;3645 }3646 /**3647 * Multiplies two vec3's3648 *3649 * @param {vec3} out the receiving vector3650 * @param {ReadonlyVec3} a the first operand3651 * @param {ReadonlyVec3} b the second operand3652 * @returns {vec3} out3653 */3654 function multiply$4(out, a, b) {3655 out[0] = a[0] * b[0];3656 out[1] = a[1] * b[1];3657 out[2] = a[2] * b[2];3658 return out;3659 }3660 /**3661 * Divides two vec3's3662 *3663 * @param {vec3} out the receiving vector3664 * @param {ReadonlyVec3} a the first operand3665 * @param {ReadonlyVec3} b the second operand3666 * @returns {vec3} out3667 */3668 function divide(out, a, b) {3669 out[0] = a[0] / b[0];3670 out[1] = a[1] / b[1];3671 out[2] = a[2] / b[2];3672 return out;3673 }3674 /**3675 * Math.ceil the components of a vec33676 *3677 * @param {vec3} out the receiving vector3678 * @param {ReadonlyVec3} a vector to ceil3679 * @returns {vec3} out3680 */3681 function ceil(out, a) {3682 out[0] = Math.ceil(a[0]);3683 out[1] = Math.ceil(a[1]);3684 out[2] = Math.ceil(a[2]);3685 return out;3686 }3687 /**3688 * Math.floor the components of a vec33689 *3690 * @param {vec3} out the receiving vector3691 * @param {ReadonlyVec3} a vector to floor3692 * @returns {vec3} out3693 */3694 function floor(out, a) {3695 out[0] = Math.floor(a[0]);3696 out[1] = Math.floor(a[1]);3697 out[2] = Math.floor(a[2]);3698 return out;3699 }3700 /**3701 * Returns the minimum of two vec3's3702 *3703 * @param {vec3} out the receiving vector3704 * @param {ReadonlyVec3} a the first operand3705 * @param {ReadonlyVec3} b the second operand3706 * @returns {vec3} out3707 */3708 function min(out, a, b) {3709 out[0] = Math.min(a[0], b[0]);3710 out[1] = Math.min(a[1], b[1]);3711 out[2] = Math.min(a[2], b[2]);3712 return out;3713 }3714 /**3715 * Returns the maximum of two vec3's3716 *3717 * @param {vec3} out the receiving vector3718 * @param {ReadonlyVec3} a the first operand3719 * @param {ReadonlyVec3} b the second operand3720 * @returns {vec3} out3721 */3722 function max(out, a, b) {3723 out[0] = Math.max(a[0], b[0]);3724 out[1] = Math.max(a[1], b[1]);3725 out[2] = Math.max(a[2], b[2]);3726 return out;3727 }3728 /**3729 * Math.round the components of a vec33730 *3731 * @param {vec3} out the receiving vector3732 * @param {ReadonlyVec3} a vector to round3733 * @returns {vec3} out3734 */3735 function round(out, a) {3736 out[0] = Math.round(a[0]);3737 out[1] = Math.round(a[1]);3738 out[2] = Math.round(a[2]);3739 return out;3740 }3741 /**3742 * Scales a vec3 by a scalar number3743 *3744 * @param {vec3} out the receiving vector3745 * @param {ReadonlyVec3} a the vector to scale3746 * @param {Number} b amount to scale the vector by3747 * @returns {vec3} out3748 */3749 function scale$4(out, a, b) {3750 out[0] = a[0] * b;3751 out[1] = a[1] * b;3752 out[2] = a[2] * b;3753 return out;3754 }3755 /**3756 * Adds two vec3's after scaling the second operand by a scalar value3757 *3758 * @param {vec3} out the receiving vector3759 * @param {ReadonlyVec3} a the first operand3760 * @param {ReadonlyVec3} b the second operand3761 * @param {Number} scale the amount to scale b by before adding3762 * @returns {vec3} out3763 */3764 function scaleAndAdd(out, a, b, scale) {3765 out[0] = a[0] + b[0] * scale;3766 out[1] = a[1] + b[1] * scale;3767 out[2] = a[2] + b[2] * scale;3768 return out;3769 }3770 /**3771 * Calculates the euclidian distance between two vec3's3772 *3773 * @param {ReadonlyVec3} a the first operand3774 * @param {ReadonlyVec3} b the second operand3775 * @returns {Number} distance between a and b3776 */3777 function distance(a, b) {3778 var x = b[0] - a[0];3779 var y = b[1] - a[1];3780 var z = b[2] - a[2];3781 return Math.hypot(x, y, z);3782 }3783 /**3784 * Calculates the squared euclidian distance between two vec3's3785 *3786 * @param {ReadonlyVec3} a the first operand3787 * @param {ReadonlyVec3} b the second operand3788 * @returns {Number} squared distance between a and b3789 */3790 function squaredDistance(a, b) {3791 var x = b[0] - a[0];3792 var y = b[1] - a[1];3793 var z = b[2] - a[2];3794 return x * x + y * y + z * z;3795 }3796 /**3797 * Calculates the squared length of a vec33798 *3799 * @param {ReadonlyVec3} a vector to calculate squared length of3800 * @returns {Number} squared length of a3801 */3802 function squaredLength(a) {3803 var x = a[0];3804 var y = a[1];3805 var z = a[2];3806 return x * x + y * y + z * z;3807 }3808 /**3809 * Negates the components of a vec33810 *3811 * @param {vec3} out the receiving vector3812 * @param {ReadonlyVec3} a vector to negate3813 * @returns {vec3} out3814 */3815 function negate(out, a) {3816 out[0] = -a[0];3817 out[1] = -a[1];3818 out[2] = -a[2];3819 return out;3820 }3821 /**3822 * Returns the inverse of the components of a vec33823 *3824 * @param {vec3} out the receiving vector3825 * @param {ReadonlyVec3} a vector to invert3826 * @returns {vec3} out3827 */3828 function inverse(out, a) {3829 out[0] = 1.0 / a[0];3830 out[1] = 1.0 / a[1];3831 out[2] = 1.0 / a[2];3832 return out;3833 }3834 /**3835 * Normalize a vec33836 *3837 * @param {vec3} out the receiving vector3838 * @param {ReadonlyVec3} a vector to normalize3839 * @returns {vec3} out3840 */3841 function normalize(out, a) {3842 var x = a[0];3843 var y = a[1];3844 var z = a[2];3845 var len = x * x + y * y + z * z;3846 if (len > 0) {3847 //TODO: evaluate use of glm_invsqrt here?3848 len = 1 / Math.sqrt(len);3849 }3850 out[0] = a[0] * len;3851 out[1] = a[1] * len;3852 out[2] = a[2] * len;3853 return out;3854 }3855 /**3856 * Calculates the dot product of two vec3's3857 *3858 * @param {ReadonlyVec3} a the first operand3859 * @param {ReadonlyVec3} b the second operand3860 * @returns {Number} dot product of a and b3861 */3862 function dot(a, b) {3863 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];3864 }3865 /**3866 * Computes the cross product of two vec3's3867 *3868 * @param {vec3} out the receiving vector3869 * @param {ReadonlyVec3} a the first operand3870 * @param {ReadonlyVec3} b the second operand3871 * @returns {vec3} out3872 */3873 function cross(out, a, b) {3874 var ax = a[0],3875 ay = a[1],3876 az = a[2];3877 var bx = b[0],3878 by = b[1],3879 bz = b[2];3880 out[0] = ay * bz - az * by;3881 out[1] = az * bx - ax * bz;3882 out[2] = ax * by - ay * bx;3883 return out;3884 }3885 /**3886 * Performs a linear interpolation between two vec3's3887 *3888 * @param {vec3} out the receiving vector3889 * @param {ReadonlyVec3} a the first operand3890 * @param {ReadonlyVec3} b the second operand3891 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3892 * @returns {vec3} out3893 */3894 function lerp(out, a, b, t) {3895 var ax = a[0];3896 var ay = a[1];3897 var az = a[2];3898 out[0] = ax + t * (b[0] - ax);3899 out[1] = ay + t * (b[1] - ay);3900 out[2] = az + t * (b[2] - az);3901 return out;3902 }3903 /**3904 * Performs a hermite interpolation with two control points3905 *3906 * @param {vec3} out the receiving vector3907 * @param {ReadonlyVec3} a the first operand3908 * @param {ReadonlyVec3} b the second operand3909 * @param {ReadonlyVec3} c the third operand3910 * @param {ReadonlyVec3} d the fourth operand3911 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3912 * @returns {vec3} out3913 */3914 function hermite(out, a, b, c, d, t) {3915 var factorTimes2 = t * t;3916 var factor1 = factorTimes2 * (2 * t - 3) + 1;3917 var factor2 = factorTimes2 * (t - 2) + t;3918 var factor3 = factorTimes2 * (t - 1);3919 var factor4 = factorTimes2 * (3 - 2 * t);3920 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3921 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3922 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3923 return out;3924 }3925 /**3926 * Performs a bezier interpolation with two control points3927 *3928 * @param {vec3} out the receiving vector3929 * @param {ReadonlyVec3} a the first operand3930 * @param {ReadonlyVec3} b the second operand3931 * @param {ReadonlyVec3} c the third operand3932 * @param {ReadonlyVec3} d the fourth operand3933 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs3934 * @returns {vec3} out3935 */3936 function bezier(out, a, b, c, d, t) {3937 var inverseFactor = 1 - t;3938 var inverseFactorTimesTwo = inverseFactor * inverseFactor;3939 var factorTimes2 = t * t;3940 var factor1 = inverseFactorTimesTwo * inverseFactor;3941 var factor2 = 3 * t * inverseFactorTimesTwo;3942 var factor3 = 3 * factorTimes2 * inverseFactor;3943 var factor4 = factorTimes2 * t;3944 out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;3945 out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;3946 out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;3947 return out;3948 }3949 /**3950 * Generates a random vector with the given scale3951 *3952 * @param {vec3} out the receiving vector3953 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned3954 * @returns {vec3} out3955 */3956 function random(out, scale) {3957 scale = scale || 1.0;3958 var r = RANDOM() * 2.0 * Math.PI;3959 var z = RANDOM() * 2.0 - 1.0;3960 var zScale = Math.sqrt(1.0 - z * z) * scale;3961 out[0] = Math.cos(r) * zScale;3962 out[1] = Math.sin(r) * zScale;3963 out[2] = z * scale;3964 return out;3965 }3966 /**3967 * Transforms the vec3 with a mat4.3968 * 4th vector component is implicitly '1'3969 *3970 * @param {vec3} out the receiving vector3971 * @param {ReadonlyVec3} a the vector to transform3972 * @param {ReadonlyMat4} m matrix to transform with3973 * @returns {vec3} out3974 */3975 function transformMat4(out, a, m) {3976 var x = a[0],3977 y = a[1],3978 z = a[2];3979 var w = m[3] * x + m[7] * y + m[11] * z + m[15];3980 w = w || 1.0;3981 out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;3982 out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;3983 out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;3984 return out;3985 }3986 /**3987 * Transforms the vec3 with a mat3.3988 *3989 * @param {vec3} out the receiving vector3990 * @param {ReadonlyVec3} a the vector to transform3991 * @param {ReadonlyMat3} m the 3x3 matrix to transform with3992 * @returns {vec3} out3993 */3994 function transformMat3(out, a, m) {3995 var x = a[0],3996 y = a[1],3997 z = a[2];3998 out[0] = x * m[0] + y * m[3] + z * m[6];3999 out[1] = x * m[1] + y * m[4] + z * m[7];4000 out[2] = x * m[2] + y * m[5] + z * m[8];4001 return out;4002 }4003 /**4004 * Transforms the vec3 with a quat4005 * Can also be used for dual quaternions. (Multiply it with the real part)4006 *4007 * @param {vec3} out the receiving vector4008 * @param {ReadonlyVec3} a the vector to transform4009 * @param {ReadonlyQuat} q quaternion to transform with4010 * @returns {vec3} out4011 */4012 function transformQuat(out, a, q) {4013 // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed4014 var qx = q[0],4015 qy = q[1],4016 qz = q[2],4017 qw = q[3];4018 var x = a[0],4019 y = a[1],4020 z = a[2]; // var qvec = [qx, qy, qz];4021 // var uv = vec3.cross([], qvec, a);4022 var uvx = qy * z - qz * y,4023 uvy = qz * x - qx * z,4024 uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);4025 var uuvx = qy * uvz - qz * uvy,4026 uuvy = qz * uvx - qx * uvz,4027 uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);4028 var w2 = qw * 2;4029 uvx *= w2;4030 uvy *= w2;4031 uvz *= w2; // vec3.scale(uuv, uuv, 2);4032 uuvx *= 2;4033 uuvy *= 2;4034 uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));4035 out[0] = x + uvx + uuvx;4036 out[1] = y + uvy + uuvy;4037 out[2] = z + uvz + uuvz;4038 return out;4039 }4040 /**4041 * Rotate a 3D vector around the x-axis4042 * @param {vec3} out The receiving vec34043 * @param {ReadonlyVec3} a The vec3 point to rotate4044 * @param {ReadonlyVec3} b The origin of the rotation4045 * @param {Number} rad The angle of rotation in radians4046 * @returns {vec3} out4047 */4048 function rotateX$1(out, a, b, rad) {4049 var p = [],4050 r = []; //Translate point to the origin4051 p[0] = a[0] - b[0];4052 p[1] = a[1] - b[1];4053 p[2] = a[2] - b[2]; //perform rotation4054 r[0] = p[0];4055 r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);4056 r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); //translate to correct position4057 out[0] = r[0] + b[0];4058 out[1] = r[1] + b[1];4059 out[2] = r[2] + b[2];4060 return out;4061 }4062 /**4063 * Rotate a 3D vector around the y-axis4064 * @param {vec3} out The receiving vec34065 * @param {ReadonlyVec3} a The vec3 point to rotate4066 * @param {ReadonlyVec3} b The origin of the rotation4067 * @param {Number} rad The angle of rotation in radians4068 * @returns {vec3} out4069 */4070 function rotateY$1(out, a, b, rad) {4071 var p = [],4072 r = []; //Translate point to the origin4073 p[0] = a[0] - b[0];4074 p[1] = a[1] - b[1];4075 p[2] = a[2] - b[2]; //perform rotation4076 r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);4077 r[1] = p[1];4078 r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); //translate to correct position4079 out[0] = r[0] + b[0];4080 out[1] = r[1] + b[1];4081 out[2] = r[2] + b[2];4082 return out;4083 }4084 /**4085 * Rotate a 3D vector around the z-axis4086 * @param {vec3} out The receiving vec34087 * @param {ReadonlyVec3} a The vec3 point to rotate4088 * @param {ReadonlyVec3} b The origin of the rotation4089 * @param {Number} rad The angle of rotation in radians4090 * @returns {vec3} out4091 */4092 function rotateZ$1(out, a, b, rad) {4093 var p = [],4094 r = []; //Translate point to the origin4095 p[0] = a[0] - b[0];4096 p[1] = a[1] - b[1];4097 p[2] = a[2] - b[2]; //perform rotation4098 r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);4099 r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);4100 r[2] = p[2]; //translate to correct position4101 out[0] = r[0] + b[0];4102 out[1] = r[1] + b[1];4103 out[2] = r[2] + b[2];4104 return out;4105 }4106 /**4107 * Get the angle between two 3D vectors4108 * @param {ReadonlyVec3} a The first operand4109 * @param {ReadonlyVec3} b The second operand4110 * @returns {Number} The angle in radians4111 */4112 function angle(a, b) {4113 var ax = a[0],4114 ay = a[1],4115 az = a[2],4116 bx = b[0],4117 by = b[1],4118 bz = b[2],4119 mag1 = Math.sqrt(ax * ax + ay * ay + az * az),4120 mag2 = Math.sqrt(bx * bx + by * by + bz * bz),4121 mag = mag1 * mag2,4122 cosine = mag && dot(a, b) / mag;4123 return Math.acos(Math.min(Math.max(cosine, -1), 1));4124 }4125 /**4126 * Set the components of a vec3 to zero4127 *4128 * @param {vec3} out the receiving vector4129 * @returns {vec3} out4130 */4131 function zero(out) {4132 out[0] = 0.0;4133 out[1] = 0.0;4134 out[2] = 0.0;4135 return out;4136 }4137 /**4138 * Returns a string representation of a vector4139 *4140 * @param {ReadonlyVec3} a vector to represent as a string4141 * @returns {String} string representation of the vector4142 */4143 function str$4(a) {4144 return "vec3(" + a[0] + ", " + a[1] + ", " + a[2] + ")";4145 }4146 /**4147 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4148 *4149 * @param {ReadonlyVec3} a The first vector.4150 * @param {ReadonlyVec3} b The second vector.4151 * @returns {Boolean} True if the vectors are equal, false otherwise.4152 */4153 function exactEquals$4(a, b) {4154 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];4155 }4156 /**4157 * Returns whether or not the vectors have approximately the same elements in the same position.4158 *4159 * @param {ReadonlyVec3} a The first vector.4160 * @param {ReadonlyVec3} b The second vector.4161 * @returns {Boolean} True if the vectors are equal, false otherwise.4162 */4163 function equals$5(a, b) {4164 var a0 = a[0],4165 a1 = a[1],4166 a2 = a[2];4167 var b0 = b[0],4168 b1 = b[1],4169 b2 = b[2];4170 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));4171 }4172 /**4173 * Alias for {@link vec3.subtract}4174 * @function4175 */4176 var sub$4 = subtract$4;4177 /**4178 * Alias for {@link vec3.multiply}4179 * @function4180 */4181 var mul$4 = multiply$4;4182 /**4183 * Alias for {@link vec3.divide}4184 * @function4185 */4186 var div = divide;4187 /**4188 * Alias for {@link vec3.distance}4189 * @function4190 */4191 var dist = distance;4192 /**4193 * Alias for {@link vec3.squaredDistance}4194 * @function4195 */4196 var sqrDist = squaredDistance;4197 /**4198 * Alias for {@link vec3.length}4199 * @function4200 */4201 var len = length;4202 /**4203 * Alias for {@link vec3.squaredLength}4204 * @function4205 */4206 var sqrLen = squaredLength;4207 /**4208 * Perform some operation over an array of vec3s.4209 *4210 * @param {Array} a the array of vectors to iterate over4211 * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed4212 * @param {Number} offset Number of elements to skip at the beginning of the array4213 * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array4214 * @param {Function} fn Function to call for each vector in the array4215 * @param {Object} [arg] additional argument to pass to fn4216 * @returns {Array} a4217 * @function4218 */4219 var forEach = function () {4220 var vec = create$4();4221 return function (a, stride, offset, count, fn, arg) {4222 var i, l;4223 if (!stride) {4224 stride = 3;4225 }4226 if (!offset) {4227 offset = 0;4228 }4229 if (count) {4230 l = Math.min(count * stride + offset, a.length);4231 } else {4232 l = a.length;4233 }4234 for (i = offset; i < l; i += stride) {4235 vec[0] = a[i];4236 vec[1] = a[i + 1];4237 vec[2] = a[i + 2];4238 fn(vec, vec, arg);4239 a[i] = vec[0];4240 a[i + 1] = vec[1];4241 a[i + 2] = vec[2];4242 }4243 return a;4244 };4245 }();4246 var vec3 = /*#__PURE__*/Object.freeze({4247 __proto__: null,4248 create: create$4,4249 clone: clone$4,4250 length: length,4251 fromValues: fromValues$4,4252 copy: copy$4,4253 set: set$4,4254 add: add$4,4255 subtract: subtract$4,4256 multiply: multiply$4,4257 divide: divide,4258 ceil: ceil,4259 floor: floor,4260 min: min,4261 max: max,4262 round: round,4263 scale: scale$4,4264 scaleAndAdd: scaleAndAdd,4265 distance: distance,4266 squaredDistance: squaredDistance,4267 squaredLength: squaredLength,4268 negate: negate,4269 inverse: inverse,4270 normalize: normalize,4271 dot: dot,4272 cross: cross,4273 lerp: lerp,4274 hermite: hermite,4275 bezier: bezier,4276 random: random,4277 transformMat4: transformMat4,4278 transformMat3: transformMat3,4279 transformQuat: transformQuat,4280 rotateX: rotateX$1,4281 rotateY: rotateY$1,4282 rotateZ: rotateZ$1,4283 angle: angle,4284 zero: zero,4285 str: str$4,4286 exactEquals: exactEquals$4,4287 equals: equals$5,4288 sub: sub$4,4289 mul: mul$4,4290 div: div,4291 dist: dist,4292 sqrDist: sqrDist,4293 len: len,4294 sqrLen: sqrLen,4295 forEach: forEach4296 });4297 /**4298 * 4 Dimensional Vector4299 * @module vec44300 */4301 /**4302 * Creates a new, empty vec44303 *4304 * @returns {vec4} a new 4D vector4305 */4306 function create$5() {4307 var out = new ARRAY_TYPE(4);4308 if (ARRAY_TYPE != Float32Array) {4309 out[0] = 0;4310 out[1] = 0;4311 out[2] = 0;4312 out[3] = 0;4313 }4314 return out;4315 }4316 /**4317 * Creates a new vec4 initialized with values from an existing vector4318 *4319 * @param {ReadonlyVec4} a vector to clone4320 * @returns {vec4} a new 4D vector4321 */4322 function clone$5(a) {4323 var out = new ARRAY_TYPE(4);4324 out[0] = a[0];4325 out[1] = a[1];4326 out[2] = a[2];4327 out[3] = a[3];4328 return out;4329 }4330 /**4331 * Creates a new vec4 initialized with the given values4332 *4333 * @param {Number} x X component4334 * @param {Number} y Y component4335 * @param {Number} z Z component4336 * @param {Number} w W component4337 * @returns {vec4} a new 4D vector4338 */4339 function fromValues$5(x, y, z, w) {4340 var out = new ARRAY_TYPE(4);4341 out[0] = x;4342 out[1] = y;4343 out[2] = z;4344 out[3] = w;4345 return out;4346 }4347 /**4348 * Copy the values from one vec4 to another4349 *4350 * @param {vec4} out the receiving vector4351 * @param {ReadonlyVec4} a the source vector4352 * @returns {vec4} out4353 */4354 function copy$5(out, a) {4355 out[0] = a[0];4356 out[1] = a[1];4357 out[2] = a[2];4358 out[3] = a[3];4359 return out;4360 }4361 /**4362 * Set the components of a vec4 to the given values4363 *4364 * @param {vec4} out the receiving vector4365 * @param {Number} x X component4366 * @param {Number} y Y component4367 * @param {Number} z Z component4368 * @param {Number} w W component4369 * @returns {vec4} out4370 */4371 function set$5(out, x, y, z, w) {4372 out[0] = x;4373 out[1] = y;4374 out[2] = z;4375 out[3] = w;4376 return out;4377 }4378 /**4379 * Adds two vec4's4380 *4381 * @param {vec4} out the receiving vector4382 * @param {ReadonlyVec4} a the first operand4383 * @param {ReadonlyVec4} b the second operand4384 * @returns {vec4} out4385 */4386 function add$5(out, a, b) {4387 out[0] = a[0] + b[0];4388 out[1] = a[1] + b[1];4389 out[2] = a[2] + b[2];4390 out[3] = a[3] + b[3];4391 return out;4392 }4393 /**4394 * Subtracts vector b from vector a4395 *4396 * @param {vec4} out the receiving vector4397 * @param {ReadonlyVec4} a the first operand4398 * @param {ReadonlyVec4} b the second operand4399 * @returns {vec4} out4400 */4401 function subtract$5(out, a, b) {4402 out[0] = a[0] - b[0];4403 out[1] = a[1] - b[1];4404 out[2] = a[2] - b[2];4405 out[3] = a[3] - b[3];4406 return out;4407 }4408 /**4409 * Multiplies two vec4's4410 *4411 * @param {vec4} out the receiving vector4412 * @param {ReadonlyVec4} a the first operand4413 * @param {ReadonlyVec4} b the second operand4414 * @returns {vec4} out4415 */4416 function multiply$5(out, a, b) {4417 out[0] = a[0] * b[0];4418 out[1] = a[1] * b[1];4419 out[2] = a[2] * b[2];4420 out[3] = a[3] * b[3];4421 return out;4422 }4423 /**4424 * Divides two vec4's4425 *4426 * @param {vec4} out the receiving vector4427 * @param {ReadonlyVec4} a the first operand4428 * @param {ReadonlyVec4} b the second operand4429 * @returns {vec4} out4430 */4431 function divide$1(out, a, b) {4432 out[0] = a[0] / b[0];4433 out[1] = a[1] / b[1];4434 out[2] = a[2] / b[2];4435 out[3] = a[3] / b[3];4436 return out;4437 }4438 /**4439 * Math.ceil the components of a vec44440 *4441 * @param {vec4} out the receiving vector4442 * @param {ReadonlyVec4} a vector to ceil4443 * @returns {vec4} out4444 */4445 function ceil$1(out, a) {4446 out[0] = Math.ceil(a[0]);4447 out[1] = Math.ceil(a[1]);4448 out[2] = Math.ceil(a[2]);4449 out[3] = Math.ceil(a[3]);4450 return out;4451 }4452 /**4453 * Math.floor the components of a vec44454 *4455 * @param {vec4} out the receiving vector4456 * @param {ReadonlyVec4} a vector to floor4457 * @returns {vec4} out4458 */4459 function floor$1(out, a) {4460 out[0] = Math.floor(a[0]);4461 out[1] = Math.floor(a[1]);4462 out[2] = Math.floor(a[2]);4463 out[3] = Math.floor(a[3]);4464 return out;4465 }4466 /**4467 * Returns the minimum of two vec4's4468 *4469 * @param {vec4} out the receiving vector4470 * @param {ReadonlyVec4} a the first operand4471 * @param {ReadonlyVec4} b the second operand4472 * @returns {vec4} out4473 */4474 function min$1(out, a, b) {4475 out[0] = Math.min(a[0], b[0]);4476 out[1] = Math.min(a[1], b[1]);4477 out[2] = Math.min(a[2], b[2]);4478 out[3] = Math.min(a[3], b[3]);4479 return out;4480 }4481 /**4482 * Returns the maximum of two vec4's4483 *4484 * @param {vec4} out the receiving vector4485 * @param {ReadonlyVec4} a the first operand4486 * @param {ReadonlyVec4} b the second operand4487 * @returns {vec4} out4488 */4489 function max$1(out, a, b) {4490 out[0] = Math.max(a[0], b[0]);4491 out[1] = Math.max(a[1], b[1]);4492 out[2] = Math.max(a[2], b[2]);4493 out[3] = Math.max(a[3], b[3]);4494 return out;4495 }4496 /**4497 * Math.round the components of a vec44498 *4499 * @param {vec4} out the receiving vector4500 * @param {ReadonlyVec4} a vector to round4501 * @returns {vec4} out4502 */4503 function round$1(out, a) {4504 out[0] = Math.round(a[0]);4505 out[1] = Math.round(a[1]);4506 out[2] = Math.round(a[2]);4507 out[3] = Math.round(a[3]);4508 return out;4509 }4510 /**4511 * Scales a vec4 by a scalar number4512 *4513 * @param {vec4} out the receiving vector4514 * @param {ReadonlyVec4} a the vector to scale4515 * @param {Number} b amount to scale the vector by4516 * @returns {vec4} out4517 */4518 function scale$5(out, a, b) {4519 out[0] = a[0] * b;4520 out[1] = a[1] * b;4521 out[2] = a[2] * b;4522 out[3] = a[3] * b;4523 return out;4524 }4525 /**4526 * Adds two vec4's after scaling the second operand by a scalar value4527 *4528 * @param {vec4} out the receiving vector4529 * @param {ReadonlyVec4} a the first operand4530 * @param {ReadonlyVec4} b the second operand4531 * @param {Number} scale the amount to scale b by before adding4532 * @returns {vec4} out4533 */4534 function scaleAndAdd$1(out, a, b, scale) {4535 out[0] = a[0] + b[0] * scale;4536 out[1] = a[1] + b[1] * scale;4537 out[2] = a[2] + b[2] * scale;4538 out[3] = a[3] + b[3] * scale;4539 return out;4540 }4541 /**4542 * Calculates the euclidian distance between two vec4's4543 *4544 * @param {ReadonlyVec4} a the first operand4545 * @param {ReadonlyVec4} b the second operand4546 * @returns {Number} distance between a and b4547 */4548 function distance$1(a, b) {4549 var x = b[0] - a[0];4550 var y = b[1] - a[1];4551 var z = b[2] - a[2];4552 var w = b[3] - a[3];4553 return Math.hypot(x, y, z, w);4554 }4555 /**4556 * Calculates the squared euclidian distance between two vec4's4557 *4558 * @param {ReadonlyVec4} a the first operand4559 * @param {ReadonlyVec4} b the second operand4560 * @returns {Number} squared distance between a and b4561 */4562 function squaredDistance$1(a, b) {4563 var x = b[0] - a[0];4564 var y = b[1] - a[1];4565 var z = b[2] - a[2];4566 var w = b[3] - a[3];4567 return x * x + y * y + z * z + w * w;4568 }4569 /**4570 * Calculates the length of a vec44571 *4572 * @param {ReadonlyVec4} a vector to calculate length of4573 * @returns {Number} length of a4574 */4575 function length$1(a) {4576 var x = a[0];4577 var y = a[1];4578 var z = a[2];4579 var w = a[3];4580 return Math.hypot(x, y, z, w);4581 }4582 /**4583 * Calculates the squared length of a vec44584 *4585 * @param {ReadonlyVec4} a vector to calculate squared length of4586 * @returns {Number} squared length of a4587 */4588 function squaredLength$1(a) {4589 var x = a[0];4590 var y = a[1];4591 var z = a[2];4592 var w = a[3];4593 return x * x + y * y + z * z + w * w;4594 }4595 /**4596 * Negates the components of a vec44597 *4598 * @param {vec4} out the receiving vector4599 * @param {ReadonlyVec4} a vector to negate4600 * @returns {vec4} out4601 */4602 function negate$1(out, a) {4603 out[0] = -a[0];4604 out[1] = -a[1];4605 out[2] = -a[2];4606 out[3] = -a[3];4607 return out;4608 }4609 /**4610 * Returns the inverse of the components of a vec44611 *4612 * @param {vec4} out the receiving vector4613 * @param {ReadonlyVec4} a vector to invert4614 * @returns {vec4} out4615 */4616 function inverse$1(out, a) {4617 out[0] = 1.0 / a[0];4618 out[1] = 1.0 / a[1];4619 out[2] = 1.0 / a[2];4620 out[3] = 1.0 / a[3];4621 return out;4622 }4623 /**4624 * Normalize a vec44625 *4626 * @param {vec4} out the receiving vector4627 * @param {ReadonlyVec4} a vector to normalize4628 * @returns {vec4} out4629 */4630 function normalize$1(out, a) {4631 var x = a[0];4632 var y = a[1];4633 var z = a[2];4634 var w = a[3];4635 var len = x * x + y * y + z * z + w * w;4636 if (len > 0) {4637 len = 1 / Math.sqrt(len);4638 }4639 out[0] = x * len;4640 out[1] = y * len;4641 out[2] = z * len;4642 out[3] = w * len;4643 return out;4644 }4645 /**4646 * Calculates the dot product of two vec4's4647 *4648 * @param {ReadonlyVec4} a the first operand4649 * @param {ReadonlyVec4} b the second operand4650 * @returns {Number} dot product of a and b4651 */4652 function dot$1(a, b) {4653 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];4654 }4655 /**4656 * Returns the cross-product of three vectors in a 4-dimensional space4657 *4658 * @param {ReadonlyVec4} result the receiving vector4659 * @param {ReadonlyVec4} U the first vector4660 * @param {ReadonlyVec4} V the second vector4661 * @param {ReadonlyVec4} W the third vector4662 * @returns {vec4} result4663 */4664 function cross$1(out, u, v, w) {4665 var A = v[0] * w[1] - v[1] * w[0],4666 B = v[0] * w[2] - v[2] * w[0],4667 C = v[0] * w[3] - v[3] * w[0],4668 D = v[1] * w[2] - v[2] * w[1],4669 E = v[1] * w[3] - v[3] * w[1],4670 F = v[2] * w[3] - v[3] * w[2];4671 var G = u[0];4672 var H = u[1];4673 var I = u[2];4674 var J = u[3];4675 out[0] = H * F - I * E + J * D;4676 out[1] = -(G * F) + I * C - J * B;4677 out[2] = G * E - H * C + J * A;4678 out[3] = -(G * D) + H * B - I * A;4679 return out;4680 }4681 /**4682 * Performs a linear interpolation between two vec4's4683 *4684 * @param {vec4} out the receiving vector4685 * @param {ReadonlyVec4} a the first operand4686 * @param {ReadonlyVec4} b the second operand4687 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs4688 * @returns {vec4} out4689 */4690 function lerp$1(out, a, b, t) {4691 var ax = a[0];4692 var ay = a[1];4693 var az = a[2];4694 var aw = a[3];4695 out[0] = ax + t * (b[0] - ax);4696 out[1] = ay + t * (b[1] - ay);4697 out[2] = az + t * (b[2] - az);4698 out[3] = aw + t * (b[3] - aw);4699 return out;4700 }4701 /**4702 * Generates a random vector with the given scale4703 *4704 * @param {vec4} out the receiving vector4705 * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned4706 * @returns {vec4} out4707 */4708 function random$1(out, scale) {4709 scale = scale || 1.0; // Marsaglia, George. Choosing a Point from the Surface of a4710 // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.4711 // http://projecteuclid.org/euclid.aoms/1177692644;4712 var v1, v2, v3, v4;4713 var s1, s2;4714 do {4715 v1 = RANDOM() * 2 - 1;4716 v2 = RANDOM() * 2 - 1;4717 s1 = v1 * v1 + v2 * v2;4718 } while (s1 >= 1);4719 do {4720 v3 = RANDOM() * 2 - 1;4721 v4 = RANDOM() * 2 - 1;4722 s2 = v3 * v3 + v4 * v4;4723 } while (s2 >= 1);4724 var d = Math.sqrt((1 - s1) / s2);4725 out[0] = scale * v1;4726 out[1] = scale * v2;4727 out[2] = scale * v3 * d;4728 out[3] = scale * v4 * d;4729 return out;4730 }4731 /**4732 * Transforms the vec4 with a mat4.4733 *4734 * @param {vec4} out the receiving vector4735 * @param {ReadonlyVec4} a the vector to transform4736 * @param {ReadonlyMat4} m matrix to transform with4737 * @returns {vec4} out4738 */4739 function transformMat4$1(out, a, m) {4740 var x = a[0],4741 y = a[1],4742 z = a[2],4743 w = a[3];4744 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;4745 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;4746 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;4747 out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;4748 return out;4749 }4750 /**4751 * Transforms the vec4 with a quat4752 *4753 * @param {vec4} out the receiving vector4754 * @param {ReadonlyVec4} a the vector to transform4755 * @param {ReadonlyQuat} q quaternion to transform with4756 * @returns {vec4} out4757 */4758 function transformQuat$1(out, a, q) {4759 var x = a[0],4760 y = a[1],4761 z = a[2];4762 var qx = q[0],4763 qy = q[1],4764 qz = q[2],4765 qw = q[3]; // calculate quat * vec4766 var ix = qw * x + qy * z - qz * y;4767 var iy = qw * y + qz * x - qx * z;4768 var iz = qw * z + qx * y - qy * x;4769 var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat4770 out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;4771 out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;4772 out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;4773 out[3] = a[3];4774 return out;4775 }4776 /**4777 * Set the components of a vec4 to zero4778 *4779 * @param {vec4} out the receiving vector4780 * @returns {vec4} out4781 */4782 function zero$1(out) {4783 out[0] = 0.0;4784 out[1] = 0.0;4785 out[2] = 0.0;4786 out[3] = 0.0;4787 return out;4788 }4789 /**4790 * Returns a string representation of a vector4791 *4792 * @param {ReadonlyVec4} a vector to represent as a string4793 * @returns {String} string representation of the vector4794 */4795 function str$5(a) {4796 return "vec4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";4797 }4798 /**4799 * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)4800 *4801 * @param {ReadonlyVec4} a The first vector.4802 * @param {ReadonlyVec4} b The second vector.4803 * @returns {Boolean} True if the vectors are equal, false otherwise.4804 */4805 function exactEquals$5(a, b) {4806 return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];4807 }4808 /**4809 * Returns whether or not the vectors have approximately the same elements in the same position.4810 *4811 * @param {ReadonlyVec4} a The first vector.4812 * @param {ReadonlyVec4} b The second vector.4813 * @returns {Boolean} True if the vectors are equal, false otherwise.4814 */4815 function equals$6(a, b) {4816 var a0 = a[0],4817 a1 = a[1],4818 a2 = a[2],4819 a3 = a[3];4820 var b0 = b[0],4821 b1 = b[1],4822 b2 = b[2],4823 b3 = b[3];4824 return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));4825 }4826 /**4827 * Alias for {@link vec4.subtract}4828 * @function4829 */4830 var sub$5 = subtract$5;4831 /**4832 * Alias for {@link vec4.multiply}4833 * @function4834 */4835 var mul$5 = multiply$5;4836 /**4837 * Alias for {@link vec4.divide}4838 * @function4839 */4840 var div$1 = divide$1;4841 /**4842 * Alias for {@link vec4.distance}4843 * @function4844 */4845 var dist$1 = distance$1;4846 /**4847 * Alias for {@link vec4.squaredDistance}4848 * @function4849 */4850 var sqrDist$1 = squaredDistance$1;4851 /**4852 * Alias for {@link vec4.length}4853 * @function4854 */4855 var len$1 = length$1;4856 /**4857 * Alias for {@link vec4.squaredLength}4858 * @function4859 */4860 var sqrLen$1 = squaredLength$1;4861 /**4862 * Perform some operation over an array of vec4s.4863 *4864 * @param {Array} a the array of vectors to iterate over4865 * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed4866 * @param {Number} offset Number of elements to skip at the beginning of the array4867 * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array4868 * @param {Function} fn Function to call for each vector in the array4869 * @param {Object} [arg] additional argument to pass to fn4870 * @returns {Array} a4871 * @function4872 */4873 var forEach$1 = function () {4874 var vec = create$5();4875 return function (a, stride, offset, count, fn, arg) {4876 var i, l;4877 if (!stride) {4878 stride = 4;4879 }4880 if (!offset) {4881 offset = 0;4882 }4883 if (count) {4884 l = Math.min(count * stride + offset, a.length);4885 } else {4886 l = a.length;4887 }4888 for (i = offset; i < l; i += stride) {4889 vec[0] = a[i];4890 vec[1] = a[i + 1];4891 vec[2] = a[i + 2];4892 vec[3] = a[i + 3];4893 fn(vec, vec, arg);4894 a[i] = vec[0];4895 a[i + 1] = vec[1];4896 a[i + 2] = vec[2];4897 a[i + 3] = vec[3];4898 }4899 return a;4900 };4901 }();4902 var vec4 = /*#__PURE__*/Object.freeze({4903 __proto__: null,4904 create: create$5,4905 clone: clone$5,4906 fromValues: fromValues$5,4907 copy: copy$5,4908 set: set$5,4909 add: add$5,4910 subtract: subtract$5,4911 multiply: multiply$5,4912 divide: divide$1,4913 ceil: ceil$1,4914 floor: floor$1,4915 min: min$1,4916 max: max$1,4917 round: round$1,4918 scale: scale$5,4919 scaleAndAdd: scaleAndAdd$1,4920 distance: distance$1,4921 squaredDistance: squaredDistance$1,4922 length: length$1,4923 squaredLength: squaredLength$1,4924 negate: negate$1,4925 inverse: inverse$1,4926 normalize: normalize$1,4927 dot: dot$1,4928 cross: cross$1,4929 lerp: lerp$1,4930 random: random$1,4931 transformMat4: transformMat4$1,4932 transformQuat: transformQuat$1,4933 zero: zero$1,4934 str: str$5,4935 exactEquals: exactEquals$5,4936 equals: equals$6,4937 sub: sub$5,4938 mul: mul$5,4939 div: div$1,4940 dist: dist$1,4941 sqrDist: sqrDist$1,4942 len: len$1,4943 sqrLen: sqrLen$1,4944 forEach: forEach$14945 });4946 /**4947 * Quaternion4948 * @module quat4949 */4950 /**4951 * Creates a new identity quat4952 *4953 * @returns {quat} a new quaternion4954 */4955 function create$6() {4956 var out = new ARRAY_TYPE(4);4957 if (ARRAY_TYPE != Float32Array) {4958 out[0] = 0;4959 out[1] = 0;4960 out[2] = 0;4961 }4962 out[3] = 1;4963 return out;4964 }4965 /**4966 * Set a quat to the identity quaternion4967 *4968 * @param {quat} out the receiving quaternion4969 * @returns {quat} out4970 */4971 function identity$4(out) {4972 out[0] = 0;4973 out[1] = 0;4974 out[2] = 0;4975 out[3] = 1;4976 return out;4977 }4978 /**4979 * Sets a quat from the given angle and rotation axis,4980 * then returns it.4981 *4982 * @param {quat} out the receiving quaternion4983 * @param {ReadonlyVec3} axis the axis around which to rotate4984 * @param {Number} rad the angle in radians4985 * @returns {quat} out4986 **/4987 function setAxisAngle(out, axis, rad) {4988 rad = rad * 0.5;4989 var s = Math.sin(rad);4990 out[0] = s * axis[0];4991 out[1] = s * axis[1];4992 out[2] = s * axis[2];4993 out[3] = Math.cos(rad);4994 return out;4995 }4996 /**4997 * Gets the rotation axis and angle for a given4998 * quaternion. If a quaternion is created with4999 * setAxisAngle, this method will return the same5000 * values as providied in the original parameter list5001 * OR functionally equivalent values.5002 * Example: The quaternion formed by axis [0, 0, 1] and5003 * angle -90 is the same as the quaternion formed by5004 * [0, 0, 1] and 270. This method favors the latter.5005 * @param {vec3} out_axis Vector receiving the axis of rotation5006 * @param {ReadonlyQuat} q Quaternion to be decomposed5007 * @return {Number} Angle, in radians, of the rotation5008 */5009 function getAxisAngle(out_axis, q) {5010 var rad = Math.acos(q[3]) * 2.0;5011 var s = Math.sin(rad / 2.0);5012 if (s > EPSILON) {5013 out_axis[0] = q[0] / s;5014 out_axis[1] = q[1] / s;5015 out_axis[2] = q[2] / s;5016 } else {5017 // If s is zero, return any axis (no rotation - axis does not matter)5018 out_axis[0] = 1;5019 out_axis[1] = 0;5020 out_axis[2] = 0;5021 }5022 return rad;5023 }5024 /**5025 * Gets the angular distance between two unit quaternions5026 *5027 * @param {ReadonlyQuat} a Origin unit quaternion5028 * @param {ReadonlyQuat} b Destination unit quaternion5029 * @return {Number} Angle, in radians, between the two quaternions5030 */5031 function getAngle(a, b) {5032 var dotproduct = dot$2(a, b);5033 return Math.acos(2 * dotproduct * dotproduct - 1);5034 }5035 /**5036 * Multiplies two quat's5037 *5038 * @param {quat} out the receiving quaternion5039 * @param {ReadonlyQuat} a the first operand5040 * @param {ReadonlyQuat} b the second operand5041 * @returns {quat} out5042 */5043 function multiply$6(out, a, b) {5044 var ax = a[0],5045 ay = a[1],5046 az = a[2],5047 aw = a[3];5048 var bx = b[0],5049 by = b[1],5050 bz = b[2],5051 bw = b[3];5052 out[0] = ax * bw + aw * bx + ay * bz - az * by;5053 out[1] = ay * bw + aw * by + az * bx - ax * bz;5054 out[2] = az * bw + aw * bz + ax * by - ay * bx;5055 out[3] = aw * bw - ax * bx - ay * by - az * bz;5056 return out;5057 }5058 /**5059 * Rotates a quaternion by the given angle about the X axis5060 *5061 * @param {quat} out quat receiving operation result5062 * @param {ReadonlyQuat} a quat to rotate5063 * @param {number} rad angle (in radians) to rotate5064 * @returns {quat} out5065 */5066 function rotateX$2(out, a, rad) {5067 rad *= 0.5;5068 var ax = a[0],5069 ay = a[1],5070 az = a[2],5071 aw = a[3];5072 var bx = Math.sin(rad),5073 bw = Math.cos(rad);5074 out[0] = ax * bw + aw * bx;5075 out[1] = ay * bw + az * bx;5076 out[2] = az * bw - ay * bx;5077 out[3] = aw * bw - ax * bx;5078 return out;5079 }5080 /**5081 * Rotates a quaternion by the given angle about the Y axis5082 *5083 * @param {quat} out quat receiving operation result5084 * @param {ReadonlyQuat} a quat to rotate5085 * @param {number} rad angle (in radians) to rotate5086 * @returns {quat} out5087 */5088 function rotateY$2(out, a, rad) {5089 rad *= 0.5;5090 var ax = a[0],5091 ay = a[1],5092 az = a[2],5093 aw = a[3];5094 var by = Math.sin(rad),5095 bw = Math.cos(rad);5096 out[0] = ax * bw - az * by;5097 out[1] = ay * bw + aw * by;5098 out[2] = az * bw + ax * by;5099 out[3] = aw * bw - ay * by;5100 return out;5101 }5102 /**5103 * Rotates a quaternion by the given angle about the Z axis5104 *5105 * @param {quat} out quat receiving operation result5106 * @param {ReadonlyQuat} a quat to rotate5107 * @param {number} rad angle (in radians) to rotate5108 * @returns {quat} out5109 */5110 function rotateZ$2(out, a, rad) {5111 rad *= 0.5;5112 var ax = a[0],5113 ay = a[1],5114 az = a[2],5115 aw = a[3];5116 var bz = Math.sin(rad),5117 bw = Math.cos(rad);5118 out[0] = ax * bw + ay * bz;5119 out[1] = ay * bw - ax * bz;5120 out[2] = az * bw + aw * bz;5121 out[3] = aw * bw - az * bz;5122 return out;5123 }5124 /**5125 * Calculates the W component of a quat from the X, Y, and Z components.5126 * Assumes that quaternion is 1 unit in length.5127 * Any existing W component will be ignored.5128 *5129 * @param {quat} out the receiving quaternion5130 * @param {ReadonlyQuat} a quat to calculate W component of5131 * @returns {quat} out5132 */5133 function calculateW(out, a) {5134 var x = a[0],5135 y = a[1],5136 z = a[2];5137 out[0] = x;5138 out[1] = y;5139 out[2] = z;5140 out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));5141 return out;5142 }5143 /**5144 * Calculate the exponential of a unit quaternion.5145 *5146 * @param {quat} out the receiving quaternion5147 * @param {ReadonlyQuat} a quat to calculate the exponential of5148 * @returns {quat} out5149 */5150 function exp(out, a) {5151 var x = a[0],5152 y = a[1],5153 z = a[2],5154 w = a[3];5155 var r = Math.sqrt(x * x + y * y + z * z);5156 var et = Math.exp(w);5157 var s = r > 0 ? et * Math.sin(r) / r : 0;5158 out[0] = x * s;5159 out[1] = y * s;5160 out[2] = z * s;5161 out[3] = et * Math.cos(r);5162 return out;5163 }5164 /**5165 * Calculate the natural logarithm of a unit quaternion.5166 *5167 * @param {quat} out the receiving quaternion5168 * @param {ReadonlyQuat} a quat to calculate the exponential of5169 * @returns {quat} out5170 */5171 function ln(out, a) {5172 var x = a[0],5173 y = a[1],5174 z = a[2],5175 w = a[3];5176 var r = Math.sqrt(x * x + y * y + z * z);5177 var t = r > 0 ? Math.atan2(r, w) / r : 0;5178 out[0] = x * t;5179 out[1] = y * t;5180 out[2] = z * t;5181 out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);5182 return out;5183 }5184 /**5185 * Calculate the scalar power of a unit quaternion.5186 *5187 * @param {quat} out the receiving quaternion5188 * @param {ReadonlyQuat} a quat to calculate the exponential of5189 * @param {Number} b amount to scale the quaternion by5190 * @returns {quat} out5191 */5192 function pow(out, a, b) {5193 ln(out, a);5194 scale$6(out, out, b);5195 exp(out, out);5196 return out;5197 }5198 /**5199 * Performs a spherical linear interpolation between two quat5200 *5201 * @param {quat} out the receiving quaternion5202 * @param {ReadonlyQuat} a the first operand5203 * @param {ReadonlyQuat} b the second operand5204 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5205 * @returns {quat} out5206 */5207 function slerp(out, a, b, t) {5208 // benchmarks:5209 // http://jsperf.com/quaternion-slerp-implementations5210 var ax = a[0],5211 ay = a[1],5212 az = a[2],5213 aw = a[3];5214 var bx = b[0],5215 by = b[1],5216 bz = b[2],5217 bw = b[3];5218 var omega, cosom, sinom, scale0, scale1; // calc cosine5219 cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)5220 if (cosom < 0.0) {5221 cosom = -cosom;5222 bx = -bx;5223 by = -by;5224 bz = -bz;5225 bw = -bw;5226 } // calculate coefficients5227 if (1.0 - cosom > EPSILON) {5228 // standard case (slerp)5229 omega = Math.acos(cosom);5230 sinom = Math.sin(omega);5231 scale0 = Math.sin((1.0 - t) * omega) / sinom;5232 scale1 = Math.sin(t * omega) / sinom;5233 } else {5234 // "from" and "to" quaternions are very close5235 // ... so we can do a linear interpolation5236 scale0 = 1.0 - t;5237 scale1 = t;5238 } // calculate final values5239 out[0] = scale0 * ax + scale1 * bx;5240 out[1] = scale0 * ay + scale1 * by;5241 out[2] = scale0 * az + scale1 * bz;5242 out[3] = scale0 * aw + scale1 * bw;5243 return out;5244 }5245 /**5246 * Generates a random unit quaternion5247 *5248 * @param {quat} out the receiving quaternion5249 * @returns {quat} out5250 */5251 function random$2(out) {5252 // Implementation of http://planning.cs.uiuc.edu/node198.html5253 // TODO: Calling random 3 times is probably not the fastest solution5254 var u1 = RANDOM();5255 var u2 = RANDOM();5256 var u3 = RANDOM();5257 var sqrt1MinusU1 = Math.sqrt(1 - u1);5258 var sqrtU1 = Math.sqrt(u1);5259 out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);5260 out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);5261 out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);5262 out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);5263 return out;5264 }5265 /**5266 * Calculates the inverse of a quat5267 *5268 * @param {quat} out the receiving quaternion5269 * @param {ReadonlyQuat} a quat to calculate inverse of5270 * @returns {quat} out5271 */5272 function invert$4(out, a) {5273 var a0 = a[0],5274 a1 = a[1],5275 a2 = a[2],5276 a3 = a[3];5277 var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;5278 var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 05279 out[0] = -a0 * invDot;5280 out[1] = -a1 * invDot;5281 out[2] = -a2 * invDot;5282 out[3] = a3 * invDot;5283 return out;5284 }5285 /**5286 * Calculates the conjugate of a quat5287 * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.5288 *5289 * @param {quat} out the receiving quaternion5290 * @param {ReadonlyQuat} a quat to calculate conjugate of5291 * @returns {quat} out5292 */5293 function conjugate(out, a) {5294 out[0] = -a[0];5295 out[1] = -a[1];5296 out[2] = -a[2];5297 out[3] = a[3];5298 return out;5299 }5300 /**5301 * Creates a quaternion from the given 3x3 rotation matrix.5302 *5303 * NOTE: The resultant quaternion is not normalized, so you should be sure5304 * to renormalize the quaternion yourself where necessary.5305 *5306 * @param {quat} out the receiving quaternion5307 * @param {ReadonlyMat3} m rotation matrix5308 * @returns {quat} out5309 * @function5310 */5311 function fromMat3(out, m) {5312 // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes5313 // article "Quaternion Calculus and Fast Animation".5314 var fTrace = m[0] + m[4] + m[8];5315 var fRoot;5316 if (fTrace > 0.0) {5317 // |w| > 1/2, may as well choose w > 1/25318 fRoot = Math.sqrt(fTrace + 1.0); // 2w5319 out[3] = 0.5 * fRoot;5320 fRoot = 0.5 / fRoot; // 1/(4w)5321 out[0] = (m[5] - m[7]) * fRoot;5322 out[1] = (m[6] - m[2]) * fRoot;5323 out[2] = (m[1] - m[3]) * fRoot;5324 } else {5325 // |w| <= 1/25326 var i = 0;5327 if (m[4] > m[0]) i = 1;5328 if (m[8] > m[i * 3 + i]) i = 2;5329 var j = (i + 1) % 3;5330 var k = (i + 2) % 3;5331 fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);5332 out[i] = 0.5 * fRoot;5333 fRoot = 0.5 / fRoot;5334 out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;5335 out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;5336 out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;5337 }5338 return out;5339 }5340 /**5341 * Creates a quaternion from the given euler angle x, y, z.5342 *5343 * @param {quat} out the receiving quaternion5344 * @param {x} Angle to rotate around X axis in degrees.5345 * @param {y} Angle to rotate around Y axis in degrees.5346 * @param {z} Angle to rotate around Z axis in degrees.5347 * @returns {quat} out5348 * @function5349 */5350 function fromEuler(out, x, y, z) {5351 var halfToRad = 0.5 * Math.PI / 180.0;5352 x *= halfToRad;5353 y *= halfToRad;5354 z *= halfToRad;5355 var sx = Math.sin(x);5356 var cx = Math.cos(x);5357 var sy = Math.sin(y);5358 var cy = Math.cos(y);5359 var sz = Math.sin(z);5360 var cz = Math.cos(z);5361 out[0] = sx * cy * cz - cx * sy * sz;5362 out[1] = cx * sy * cz + sx * cy * sz;5363 out[2] = cx * cy * sz - sx * sy * cz;5364 out[3] = cx * cy * cz + sx * sy * sz;5365 return out;5366 }5367 /**5368 * Returns a string representation of a quatenion5369 *5370 * @param {ReadonlyQuat} a vector to represent as a string5371 * @returns {String} string representation of the vector5372 */5373 function str$6(a) {5374 return "quat(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";5375 }5376 /**5377 * Creates a new quat initialized with values from an existing quaternion5378 *5379 * @param {ReadonlyQuat} a quaternion to clone5380 * @returns {quat} a new quaternion5381 * @function5382 */5383 var clone$6 = clone$5;5384 /**5385 * Creates a new quat initialized with the given values5386 *5387 * @param {Number} x X component5388 * @param {Number} y Y component5389 * @param {Number} z Z component5390 * @param {Number} w W component5391 * @returns {quat} a new quaternion5392 * @function5393 */5394 var fromValues$6 = fromValues$5;5395 /**5396 * Copy the values from one quat to another5397 *5398 * @param {quat} out the receiving quaternion5399 * @param {ReadonlyQuat} a the source quaternion5400 * @returns {quat} out5401 * @function5402 */5403 var copy$6 = copy$5;5404 /**5405 * Set the components of a quat to the given values5406 *5407 * @param {quat} out the receiving quaternion5408 * @param {Number} x X component5409 * @param {Number} y Y component5410 * @param {Number} z Z component5411 * @param {Number} w W component5412 * @returns {quat} out5413 * @function5414 */5415 var set$6 = set$5;5416 /**5417 * Adds two quat's5418 *5419 * @param {quat} out the receiving quaternion5420 * @param {ReadonlyQuat} a the first operand5421 * @param {ReadonlyQuat} b the second operand5422 * @returns {quat} out5423 * @function5424 */5425 var add$6 = add$5;5426 /**5427 * Alias for {@link quat.multiply}5428 * @function5429 */5430 var mul$6 = multiply$6;5431 /**5432 * Scales a quat by a scalar number5433 *5434 * @param {quat} out the receiving vector5435 * @param {ReadonlyQuat} a the vector to scale5436 * @param {Number} b amount to scale the vector by5437 * @returns {quat} out5438 * @function5439 */5440 var scale$6 = scale$5;5441 /**5442 * Calculates the dot product of two quat's5443 *5444 * @param {ReadonlyQuat} a the first operand5445 * @param {ReadonlyQuat} b the second operand5446 * @returns {Number} dot product of a and b5447 * @function5448 */5449 var dot$2 = dot$1;5450 /**5451 * Performs a linear interpolation between two quat's5452 *5453 * @param {quat} out the receiving quaternion5454 * @param {ReadonlyQuat} a the first operand5455 * @param {ReadonlyQuat} b the second operand5456 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5457 * @returns {quat} out5458 * @function5459 */5460 var lerp$2 = lerp$1;5461 /**5462 * Calculates the length of a quat5463 *5464 * @param {ReadonlyQuat} a vector to calculate length of5465 * @returns {Number} length of a5466 */5467 var length$2 = length$1;5468 /**5469 * Alias for {@link quat.length}5470 * @function5471 */5472 var len$2 = length$2;5473 /**5474 * Calculates the squared length of a quat5475 *5476 * @param {ReadonlyQuat} a vector to calculate squared length of5477 * @returns {Number} squared length of a5478 * @function5479 */5480 var squaredLength$2 = squaredLength$1;5481 /**5482 * Alias for {@link quat.squaredLength}5483 * @function5484 */5485 var sqrLen$2 = squaredLength$2;5486 /**5487 * Normalize a quat5488 *5489 * @param {quat} out the receiving quaternion5490 * @param {ReadonlyQuat} a quaternion to normalize5491 * @returns {quat} out5492 * @function5493 */5494 var normalize$2 = normalize$1;5495 /**5496 * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)5497 *5498 * @param {ReadonlyQuat} a The first quaternion.5499 * @param {ReadonlyQuat} b The second quaternion.5500 * @returns {Boolean} True if the vectors are equal, false otherwise.5501 */5502 var exactEquals$6 = exactEquals$5;5503 /**5504 * Returns whether or not the quaternions have approximately the same elements in the same position.5505 *5506 * @param {ReadonlyQuat} a The first vector.5507 * @param {ReadonlyQuat} b The second vector.5508 * @returns {Boolean} True if the vectors are equal, false otherwise.5509 */5510 var equals$7 = equals$6;5511 /**5512 * Sets a quaternion to represent the shortest rotation from one5513 * vector to another.5514 *5515 * Both vectors are assumed to be unit length.5516 *5517 * @param {quat} out the receiving quaternion.5518 * @param {ReadonlyVec3} a the initial vector5519 * @param {ReadonlyVec3} b the destination vector5520 * @returns {quat} out5521 */5522 var rotationTo = function () {5523 var tmpvec3 = create$4();5524 var xUnitVec3 = fromValues$4(1, 0, 0);5525 var yUnitVec3 = fromValues$4(0, 1, 0);5526 return function (out, a, b) {5527 var dot$1 = dot(a, b);5528 if (dot$1 < -0.999999) {5529 cross(tmpvec3, xUnitVec3, a);5530 if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);5531 normalize(tmpvec3, tmpvec3);5532 setAxisAngle(out, tmpvec3, Math.PI);5533 return out;5534 } else if (dot$1 > 0.999999) {5535 out[0] = 0;5536 out[1] = 0;5537 out[2] = 0;5538 out[3] = 1;5539 return out;5540 } else {5541 cross(tmpvec3, a, b);5542 out[0] = tmpvec3[0];5543 out[1] = tmpvec3[1];5544 out[2] = tmpvec3[2];5545 out[3] = 1 + dot$1;5546 return normalize$2(out, out);5547 }5548 };5549 }();5550 /**5551 * Performs a spherical linear interpolation with two control points5552 *5553 * @param {quat} out the receiving quaternion5554 * @param {ReadonlyQuat} a the first operand5555 * @param {ReadonlyQuat} b the second operand5556 * @param {ReadonlyQuat} c the third operand5557 * @param {ReadonlyQuat} d the fourth operand5558 * @param {Number} t interpolation amount, in the range [0-1], between the two inputs5559 * @returns {quat} out5560 */5561 var sqlerp = function () {5562 var temp1 = create$6();5563 var temp2 = create$6();5564 return function (out, a, b, c, d, t) {5565 slerp(temp1, a, d, t);5566 slerp(temp2, b, c, t);5567 slerp(out, temp1, temp2, 2 * t * (1 - t));5568 return out;5569 };5570 }();5571 /**5572 * Sets the specified quaternion with values corresponding to the given5573 * axes. Each axis is a vec3 and is expected to be unit length and5574 * perpendicular to all other specified axes.5575 *5576 * @param {ReadonlyVec3} view the vector representing the viewing direction5577 * @param {ReadonlyVec3} right the vector representing the local "right" direction5578 * @param {ReadonlyVec3} up the vector representing the local "up" direction5579 * @returns {quat} out5580 */5581 var setAxes = function () {5582 var matr = create$2();5583 return function (out, view, right, up) {5584 matr[0] = right[0];5585 matr[3] = right[1];5586 matr[6] = right[2];5587 matr[1] = up[0];5588 matr[4] = up[1];5589 matr[7] = up[2];5590 matr[2] = -view[0];5591 matr[5] = -view[1];5592 matr[8] = -view[2];5593 return normalize$2(out, fromMat3(out, matr));5594 };5595 }();5596 var quat = /*#__PURE__*/Object.freeze({5597 __proto__: null,5598 create: create$6,5599 identity: identity$4,5600 setAxisAngle: setAxisAngle,5601 getAxisAngle: getAxisAngle,5602 getAngle: getAngle,5603 multiply: multiply$6,5604 rotateX: rotateX$2,5605 rotateY: rotateY$2,5606 rotateZ: rotateZ$2,5607 calculateW: calculateW,5608 exp: exp,5609 ln: ln,5610 pow: pow,5611 slerp: slerp,5612 random: random$2,5613 invert: invert$4,5614 conjugate: conjugate,5615 fromMat3: fromMat3,5616 fromEuler: fromEuler,5617 str: str$6,5618 clone: clone$6,5619 fromValues: fromValues$6,5620 copy: copy$6,5621 set: set$6,5622 add: add$6,5623 mul: mul$6,5624 scale: scale$6,5625 dot: dot$2,5626 lerp: lerp$2,5627 length: length$2,5628 len: len$2,5629 squaredLength: squaredLength$2,5630 sqrLen: sqrLen$2,5631 normalize: normalize$2,5632 exactEquals: exactEquals$6,5633 equals: equals$7,5634 rotationTo: rotationTo,5635 sqlerp: sqlerp,5636 setAxes: setAxes5637 });5638 /**5639 * Dual Quaternion<br>5640 * Format: [real, dual]<br>5641 * Quaternion format: XYZW<br>5642 * Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.<br>5643 * @module quat25644 */5645 /**5646 * Creates a new identity dual quat5647 *5648 * @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]5649 */5650 function create$7() {5651 var dq = new ARRAY_TYPE(8);5652 if (ARRAY_TYPE != Float32Array) {5653 dq[0] = 0;5654 dq[1] = 0;5655 dq[2] = 0;5656 dq[4] = 0;5657 dq[5] = 0;5658 dq[6] = 0;5659 dq[7] = 0;5660 }5661 dq[3] = 1;5662 return dq;5663 }5664 /**5665 * Creates a new quat initialized with values from an existing quaternion5666 *5667 * @param {ReadonlyQuat2} a dual quaternion to clone5668 * @returns {quat2} new dual quaternion5669 * @function5670 */5671 function clone$7(a) {5672 var dq = new ARRAY_TYPE(8);5673 dq[0] = a[0];5674 dq[1] = a[1];5675 dq[2] = a[2];5676 dq[3] = a[3];5677 dq[4] = a[4];5678 dq[5] = a[5];5679 dq[6] = a[6];