| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 | 
							- <!DOCTYPE html>
 
- <html lang="en">
 
- <head>
 
-     <meta charset="utf-8">
 
-     <title>JSDoc: Source: mat2d.js</title>
 
-     <script src="scripts/prettify/prettify.js"> </script>
 
-     <script src="scripts/prettify/lang-css.js"> </script>
 
-     <!--[if lt IE 9]>
 
-       <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
 
-     <![endif]-->
 
-     <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
 
-     <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
 
- </head>
 
- <body>
 
- <div id="main">
 
-     <h1 class="page-title">Source: mat2d.js</h1>
 
-     
 
-     
 
-     <section>
 
-         <article>
 
-             <pre class="prettyprint source linenums"><code>import * as glMatrix from "./common.js";
 
- /**
 
-  * 2x3 Matrix
 
-  * @module mat2d
 
-  *
 
-  * @description
 
-  * A mat2d contains six elements defined as:
 
-  * <pre>
 
-  * [a, c, tx,
 
-  *  b, d, ty]
 
-  * </pre>
 
-  * This is a short form for the 3x3 matrix:
 
-  * <pre>
 
-  * [a, c, tx,
 
-  *  b, d, ty,
 
-  *  0, 0, 1]
 
-  * </pre>
 
-  * The last row is ignored so the array is shorter and operations are faster.
 
-  */
 
- /**
 
-  * Creates a new identity mat2d
 
-  *
 
-  * @returns {mat2d} a new 2x3 matrix
 
-  */
 
- export function create() {
 
-   let out = new glMatrix.ARRAY_TYPE(6);
 
-   if(glMatrix.ARRAY_TYPE != Float32Array) {
 
-     out[1] = 0;
 
-     out[2] = 0;
 
-     out[4] = 0;
 
-     out[5] = 0;
 
-   }
 
-   out[0] = 1;
 
-   out[3] = 1;
 
-   return out;
 
- }
 
- /**
 
-  * Creates a new mat2d initialized with values from an existing matrix
 
-  *
 
-  * @param {mat2d} a matrix to clone
 
-  * @returns {mat2d} a new 2x3 matrix
 
-  */
 
- export function clone(a) {
 
-   let out = new glMatrix.ARRAY_TYPE(6);
 
-   out[0] = a[0];
 
-   out[1] = a[1];
 
-   out[2] = a[2];
 
-   out[3] = a[3];
 
-   out[4] = a[4];
 
-   out[5] = a[5];
 
-   return out;
 
- }
 
- /**
 
-  * Copy the values from one mat2d to another
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the source matrix
 
-  * @returns {mat2d} out
 
-  */
 
- export function copy(out, a) {
 
-   out[0] = a[0];
 
-   out[1] = a[1];
 
-   out[2] = a[2];
 
-   out[3] = a[3];
 
-   out[4] = a[4];
 
-   out[5] = a[5];
 
-   return out;
 
- }
 
- /**
 
-  * Set a mat2d to the identity matrix
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @returns {mat2d} out
 
-  */
 
- export function identity(out) {
 
-   out[0] = 1;
 
-   out[1] = 0;
 
-   out[2] = 0;
 
-   out[3] = 1;
 
-   out[4] = 0;
 
-   out[5] = 0;
 
-   return out;
 
- }
 
- /**
 
-  * Create a new mat2d with the given values
 
-  *
 
-  * @param {Number} a Component A (index 0)
 
-  * @param {Number} b Component B (index 1)
 
-  * @param {Number} c Component C (index 2)
 
-  * @param {Number} d Component D (index 3)
 
-  * @param {Number} tx Component TX (index 4)
 
-  * @param {Number} ty Component TY (index 5)
 
-  * @returns {mat2d} A new mat2d
 
-  */
 
- export function fromValues(a, b, c, d, tx, ty) {
 
-   let out = new glMatrix.ARRAY_TYPE(6);
 
-   out[0] = a;
 
-   out[1] = b;
 
-   out[2] = c;
 
-   out[3] = d;
 
-   out[4] = tx;
 
-   out[5] = ty;
 
-   return out;
 
- }
 
- /**
 
-  * Set the components of a mat2d to the given values
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {Number} a Component A (index 0)
 
-  * @param {Number} b Component B (index 1)
 
-  * @param {Number} c Component C (index 2)
 
-  * @param {Number} d Component D (index 3)
 
-  * @param {Number} tx Component TX (index 4)
 
-  * @param {Number} ty Component TY (index 5)
 
-  * @returns {mat2d} out
 
-  */
 
- export function set(out, a, b, c, d, tx, ty) {
 
-   out[0] = a;
 
-   out[1] = b;
 
-   out[2] = c;
 
-   out[3] = d;
 
-   out[4] = tx;
 
-   out[5] = ty;
 
-   return out;
 
- }
 
- /**
 
-  * Inverts a mat2d
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the source matrix
 
-  * @returns {mat2d} out
 
-  */
 
- export function invert(out, a) {
 
-   let aa = a[0], ab = a[1], ac = a[2], ad = a[3];
 
-   let atx = a[4], aty = a[5];
 
-   let det = aa * ad - ab * ac;
 
-   if(!det){
 
-     return null;
 
-   }
 
-   det = 1.0 / det;
 
-   out[0] = ad * det;
 
-   out[1] = -ab * det;
 
-   out[2] = -ac * det;
 
-   out[3] = aa * det;
 
-   out[4] = (ac * aty - ad * atx) * det;
 
-   out[5] = (ab * atx - aa * aty) * det;
 
-   return out;
 
- }
 
- /**
 
-  * Calculates the determinant of a mat2d
 
-  *
 
-  * @param {mat2d} a the source matrix
 
-  * @returns {Number} determinant of a
 
-  */
 
- export function determinant(a) {
 
-   return a[0] * a[3] - a[1] * a[2];
 
- }
 
- /**
 
-  * Multiplies two mat2d's
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the first operand
 
-  * @param {mat2d} b the second operand
 
-  * @returns {mat2d} out
 
-  */
 
- export function multiply(out, a, b) {
 
-   let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
 
-   let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
 
-   out[0] = a0 * b0 + a2 * b1;
 
-   out[1] = a1 * b0 + a3 * b1;
 
-   out[2] = a0 * b2 + a2 * b3;
 
-   out[3] = a1 * b2 + a3 * b3;
 
-   out[4] = a0 * b4 + a2 * b5 + a4;
 
-   out[5] = a1 * b4 + a3 * b5 + a5;
 
-   return out;
 
- }
 
- /**
 
-  * Rotates a mat2d by the given angle
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the matrix to rotate
 
-  * @param {Number} rad the angle to rotate the matrix by
 
-  * @returns {mat2d} out
 
-  */
 
- export function rotate(out, a, rad) {
 
-   let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
 
-   let s = Math.sin(rad);
 
-   let c = Math.cos(rad);
 
-   out[0] = a0 *  c + a2 * s;
 
-   out[1] = a1 *  c + a3 * s;
 
-   out[2] = a0 * -s + a2 * c;
 
-   out[3] = a1 * -s + a3 * c;
 
-   out[4] = a4;
 
-   out[5] = a5;
 
-   return out;
 
- }
 
- /**
 
-  * Scales the mat2d by the dimensions in the given vec2
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the matrix to translate
 
-  * @param {vec2} v the vec2 to scale the matrix by
 
-  * @returns {mat2d} out
 
-  **/
 
- export function scale(out, a, v) {
 
-   let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
 
-   let v0 = v[0], v1 = v[1];
 
-   out[0] = a0 * v0;
 
-   out[1] = a1 * v0;
 
-   out[2] = a2 * v1;
 
-   out[3] = a3 * v1;
 
-   out[4] = a4;
 
-   out[5] = a5;
 
-   return out;
 
- }
 
- /**
 
-  * Translates the mat2d by the dimensions in the given vec2
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the matrix to translate
 
-  * @param {vec2} v the vec2 to translate the matrix by
 
-  * @returns {mat2d} out
 
-  **/
 
- export function translate(out, a, v) {
 
-   let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
 
-   let v0 = v[0], v1 = v[1];
 
-   out[0] = a0;
 
-   out[1] = a1;
 
-   out[2] = a2;
 
-   out[3] = a3;
 
-   out[4] = a0 * v0 + a2 * v1 + a4;
 
-   out[5] = a1 * v0 + a3 * v1 + a5;
 
-   return out;
 
- }
 
- /**
 
-  * Creates a matrix from a given angle
 
-  * This is equivalent to (but much faster than):
 
-  *
 
-  *     mat2d.identity(dest);
 
-  *     mat2d.rotate(dest, dest, rad);
 
-  *
 
-  * @param {mat2d} out mat2d receiving operation result
 
-  * @param {Number} rad the angle to rotate the matrix by
 
-  * @returns {mat2d} out
 
-  */
 
- export function fromRotation(out, rad) {
 
-   let s = Math.sin(rad), c = Math.cos(rad);
 
-   out[0] = c;
 
-   out[1] = s;
 
-   out[2] = -s;
 
-   out[3] = c;
 
-   out[4] = 0;
 
-   out[5] = 0;
 
-   return out;
 
- }
 
- /**
 
-  * Creates a matrix from a vector scaling
 
-  * This is equivalent to (but much faster than):
 
-  *
 
-  *     mat2d.identity(dest);
 
-  *     mat2d.scale(dest, dest, vec);
 
-  *
 
-  * @param {mat2d} out mat2d receiving operation result
 
-  * @param {vec2} v Scaling vector
 
-  * @returns {mat2d} out
 
-  */
 
- export function fromScaling(out, v) {
 
-   out[0] = v[0];
 
-   out[1] = 0;
 
-   out[2] = 0;
 
-   out[3] = v[1];
 
-   out[4] = 0;
 
-   out[5] = 0;
 
-   return out;
 
- }
 
- /**
 
-  * Creates a matrix from a vector translation
 
-  * This is equivalent to (but much faster than):
 
-  *
 
-  *     mat2d.identity(dest);
 
-  *     mat2d.translate(dest, dest, vec);
 
-  *
 
-  * @param {mat2d} out mat2d receiving operation result
 
-  * @param {vec2} v Translation vector
 
-  * @returns {mat2d} out
 
-  */
 
- export function fromTranslation(out, v) {
 
-   out[0] = 1;
 
-   out[1] = 0;
 
-   out[2] = 0;
 
-   out[3] = 1;
 
-   out[4] = v[0];
 
-   out[5] = v[1];
 
-   return out;
 
- }
 
- /**
 
-  * Returns a string representation of a mat2d
 
-  *
 
-  * @param {mat2d} a matrix to represent as a string
 
-  * @returns {String} string representation of the matrix
 
-  */
 
- export function str(a) {
 
-   return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
 
-           a[3] + ', ' + a[4] + ', ' + a[5] + ')';
 
- }
 
- /**
 
-  * Returns Frobenius norm of a mat2d
 
-  *
 
-  * @param {mat2d} a the matrix to calculate Frobenius norm of
 
-  * @returns {Number} Frobenius norm
 
-  */
 
- export function frob(a) {
 
-   return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + 1))
 
- }
 
- /**
 
-  * Adds two mat2d's
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the first operand
 
-  * @param {mat2d} b the second operand
 
-  * @returns {mat2d} out
 
-  */
 
- export function add(out, a, b) {
 
-   out[0] = a[0] + b[0];
 
-   out[1] = a[1] + b[1];
 
-   out[2] = a[2] + b[2];
 
-   out[3] = a[3] + b[3];
 
-   out[4] = a[4] + b[4];
 
-   out[5] = a[5] + b[5];
 
-   return out;
 
- }
 
- /**
 
-  * Subtracts matrix b from matrix a
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the first operand
 
-  * @param {mat2d} b the second operand
 
-  * @returns {mat2d} out
 
-  */
 
- export function subtract(out, a, b) {
 
-   out[0] = a[0] - b[0];
 
-   out[1] = a[1] - b[1];
 
-   out[2] = a[2] - b[2];
 
-   out[3] = a[3] - b[3];
 
-   out[4] = a[4] - b[4];
 
-   out[5] = a[5] - b[5];
 
-   return out;
 
- }
 
- /**
 
-  * Multiply each element of the matrix by a scalar.
 
-  *
 
-  * @param {mat2d} out the receiving matrix
 
-  * @param {mat2d} a the matrix to scale
 
-  * @param {Number} b amount to scale the matrix's elements by
 
-  * @returns {mat2d} out
 
-  */
 
- export function multiplyScalar(out, a, b) {
 
-   out[0] = a[0] * b;
 
-   out[1] = a[1] * b;
 
-   out[2] = a[2] * b;
 
-   out[3] = a[3] * b;
 
-   out[4] = a[4] * b;
 
-   out[5] = a[5] * b;
 
-   return out;
 
- }
 
- /**
 
-  * Adds two mat2d's after multiplying each element of the second operand by a scalar value.
 
-  *
 
-  * @param {mat2d} out the receiving vector
 
-  * @param {mat2d} a the first operand
 
-  * @param {mat2d} b the second operand
 
-  * @param {Number} scale the amount to scale b's elements by before adding
 
-  * @returns {mat2d} out
 
-  */
 
- export function multiplyScalarAndAdd(out, a, b, scale) {
 
-   out[0] = a[0] + (b[0] * scale);
 
-   out[1] = a[1] + (b[1] * scale);
 
-   out[2] = a[2] + (b[2] * scale);
 
-   out[3] = a[3] + (b[3] * scale);
 
-   out[4] = a[4] + (b[4] * scale);
 
-   out[5] = a[5] + (b[5] * scale);
 
-   return out;
 
- }
 
- /**
 
-  * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
 
-  *
 
-  * @param {mat2d} a The first matrix.
 
-  * @param {mat2d} b The second matrix.
 
-  * @returns {Boolean} True if the matrices are equal, false otherwise.
 
-  */
 
- export function exactEquals(a, b) {
 
-   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];
 
- }
 
- /**
 
-  * Returns whether or not the matrices have approximately the same elements in the same position.
 
-  *
 
-  * @param {mat2d} a The first matrix.
 
-  * @param {mat2d} b The second matrix.
 
-  * @returns {Boolean} True if the matrices are equal, false otherwise.
 
-  */
 
- export function equals(a, b) {
 
-   let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
 
-   let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
 
-   return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
 
-           Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
 
-           Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
 
-           Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
 
-           Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
 
-           Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)));
 
- }
 
- /**
 
-  * Alias for {@link mat2d.multiply}
 
-  * @function
 
-  */
 
- export const mul = multiply;
 
- /**
 
-  * Alias for {@link mat2d.subtract}
 
-  * @function
 
-  */
 
- export const sub = subtract;
 
- </code></pre>
 
-         </article>
 
-     </section>
 
- </div>
 
- <nav>
 
-     <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-glMatrix.html">glMatrix</a></li><li><a href="module-mat2.html">mat2</a></li><li><a href="module-mat2d.html">mat2d</a></li><li><a href="module-mat3.html">mat3</a></li><li><a href="module-mat4.html">mat4</a></li><li><a href="module-quat.html">quat</a></li><li><a href="module-quat2.html">quat2</a></li><li><a href="module-vec2.html">vec2</a></li><li><a href="module-vec3.html">vec3</a></li><li><a href="module-vec4.html">vec4</a></li></ul>
 
- </nav>
 
- <br class="clear">
 
- <footer>
 
-     Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Jul 13 2018 11:51:33 GMT+0200 (W. Europe Daylight Time)
 
- </footer>
 
- <script> prettyPrint(); </script>
 
- <script src="scripts/linenumber.js"> </script>
 
- </body>
 
- </html>
 
 
  |