diff options
Diffstat (limited to 'chromium/third_party/catapult/tracing/third_party/gl-matrix')
51 files changed, 15354 insertions, 0 deletions
diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/BUILDING.md b/chromium/third_party/catapult/tracing/third_party/gl-matrix/BUILDING.md new file mode 100644 index 00000000000..9170ab3d5b1 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/BUILDING.md @@ -0,0 +1,7 @@ +Building for the browser +======================== + + +To build `gl-matrix.js` and `gl-matrix-min.js` for use in the browser run the following command: + + webpack && webpack --config webpack.config.min.js
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/LICENSE.md b/chromium/third_party/catapult/tracing/third_party/gl-matrix/LICENSE.md new file mode 100644 index 00000000000..79698edab2c --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.chromium b/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.chromium new file mode 100644 index 00000000000..4e5c3d49ea1 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.chromium @@ -0,0 +1,15 @@ +Name: gl-matrix +Short Name: gl-matrix +URL: https://github.com/toji/gl-matrix +Version: 0 +Revision: 8fc4869031e4ab1daf771e5206c2578e044cf495 +Date: Tue Feb 12 14:21:14 2013 -0800 +License: BSD +License File: NOT_SHIPPED +Security Critical: no + +Description: +Matrix math in javascript + +Local Modifications: +None. diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.md b/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.md new file mode 100644 index 00000000000..ad66cb07f84 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/README.md @@ -0,0 +1,22 @@ +glMatrix +======================= + +Javascript has evolved into a language capable of handling realtime 3D graphics, +via WebGL, and computationally intensive tasks such as physics simulations. +These types of applications demand high performance vector and matrix math, +which is something that Javascript doesn't provide by default. +glMatrix to the rescue! + +glMatrix is designed to perform vector and matrix operations stupidly fast! By +hand-tuning each function for maximum performance and encouraging efficient +usage patterns through API conventions, glMatrix will help you get the most out +of your browsers Javascript engine. + +Learn More +---------------------- +For documentation, news, tutorials, and more visit the [glMatrix Homepage](http://glmatrix.net/) + +Contributing +---------------------- +Contributions are welcome! Please make pull requests agains the `dev` branch, +and please provide unit tests for new functionality. (See TESTING.md for details) diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/TESTING.md b/chromium/third_party/catapult/tracing/third_party/gl-matrix/TESTING.md new file mode 100644 index 00000000000..affd5b27b41 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/TESTING.md @@ -0,0 +1,12 @@ +Running the test suite +======================= + + +The unit tests are built upon the following tools: + +* Jasmine -- the underlying test suite which executes the test and reports feedback +* node.js -- used for testing at the command line, via the `jasmine-node` package + +To run the unit tests use `jasmine-node`: + + jasmine-node spec
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/VERSION b/chromium/third_party/catapult/tracing/third_party/gl-matrix/VERSION new file mode 100644 index 00000000000..cc6612c36e0 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/VERSION @@ -0,0 +1 @@ +2.3.0
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/bower.json b/chromium/third_party/catapult/tracing/third_party/gl-matrix/bower.json new file mode 100644 index 00000000000..7e52c486673 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/bower.json @@ -0,0 +1,27 @@ +{ + "name": "gl-matrix", + "homepage": "http://glmatrix.net", + "authors": [ + "Brandon Jones <tojiro@gmail.com>", + "Colin MacKenzie IV <sinisterchipmunk@gmail.com>" + ], + "description": "Javascript Matrix and Vector library for High Performance WebGL apps", + "main": "dist/gl-matrix-min.js", + "ignore": [ + "**/.*", + "jsdoc-template", + "spec", + "src", + "tasks", + "Gemfile", + "Gemfile.lock", + "Rakefile", + "TESTING.md" + ], + "keywords": [ + "webGL", + "matrix", + "vector" + ], + "license": "MIT" +} diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix-min.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix-min.js new file mode 100644 index 00000000000..62db82edfd9 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix-min.js @@ -0,0 +1,29 @@ +/** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.1 + */ + +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +!function(t,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define(n);else{var r=n();for(var a in r)("object"==typeof exports?exports:t)[a]=r[a]}}(this,function(){return function(t){function n(a){if(r[a])return r[a].exports;var e=r[a]={exports:{},id:a,loaded:!1};return t[a].call(e.exports,e,e.exports,n),e.loaded=!0,e.exports}var r={};return n.m=t,n.c=r,n.p="",n(0)}([function(t,n,r){n.glMatrix=r(1),n.mat2=r(2),n.mat2d=r(3),n.mat3=r(4),n.mat4=r(5),n.quat=r(6),n.vec2=r(9),n.vec3=r(7),n.vec4=r(8)},function(t,n,r){var a={};a.EPSILON=1e-6,a.ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array,a.RANDOM=Math.random,a.setMatrixArrayType=function(t){GLMAT_ARRAY_TYPE=t};var e=Math.PI/180;a.toRadian=function(t){return t*e},t.exports=a},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},e.clone=function(t){var n=new a.ARRAY_TYPE(4);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},e.transpose=function(t,n){if(t===n){var r=n[1];t[1]=n[2],t[2]=r}else t[0]=n[0],t[1]=n[2],t[2]=n[1],t[3]=n[3];return t},e.invert=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=r*u-e*a;return o?(o=1/o,t[0]=u*o,t[1]=-a*o,t[2]=-e*o,t[3]=r*o,t):null},e.adjoint=function(t,n){var r=n[0];return t[0]=n[3],t[1]=-n[1],t[2]=-n[2],t[3]=r,t},e.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},e.multiply=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=r[0],c=r[1],f=r[2],s=r[3];return t[0]=a*i+u*c,t[1]=e*i+o*c,t[2]=a*f+u*s,t[3]=e*f+o*s,t},e.mul=e.multiply,e.rotate=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=Math.sin(r),c=Math.cos(r);return t[0]=a*c+u*i,t[1]=e*c+o*i,t[2]=a*-i+u*c,t[3]=e*-i+o*c,t},e.scale=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=r[0],c=r[1];return t[0]=a*i,t[1]=e*i,t[2]=u*c,t[3]=o*c,t},e.fromRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=a,t[1]=r,t[2]=-r,t[3]=a,t},e.fromScaling=function(t,n){return t[0]=n[0],t[1]=0,t[2]=0,t[3]=n[1],t},e.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},e.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2))},e.LDU=function(t,n,r,a){return t[2]=a[2]/a[0],r[0]=a[0],r[1]=a[1],r[3]=a[3]-t[2]*r[1],[t,n,r]},t.exports=e},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},e.clone=function(t){var n=new a.ARRAY_TYPE(6);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},e.invert=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=r*u-a*e;return c?(c=1/c,t[0]=u*c,t[1]=-a*c,t[2]=-e*c,t[3]=r*c,t[4]=(e*i-u*o)*c,t[5]=(a*o-r*i)*c,t):null},e.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},e.multiply=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=r[0],s=r[1],h=r[2],M=r[3],l=r[4],v=r[5];return t[0]=a*f+u*s,t[1]=e*f+o*s,t[2]=a*h+u*M,t[3]=e*h+o*M,t[4]=a*l+u*v+i,t[5]=e*l+o*v+c,t},e.mul=e.multiply,e.rotate=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=Math.sin(r),s=Math.cos(r);return t[0]=a*s+u*f,t[1]=e*s+o*f,t[2]=a*-f+u*s,t[3]=e*-f+o*s,t[4]=i,t[5]=c,t},e.scale=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=r[0],s=r[1];return t[0]=a*f,t[1]=e*f,t[2]=u*s,t[3]=o*s,t[4]=i,t[5]=c,t},e.translate=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=r[0],s=r[1];return t[0]=a,t[1]=e,t[2]=u,t[3]=o,t[4]=a*f+u*s+i,t[5]=e*f+o*s+c,t},e.fromRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=a,t[1]=r,t[2]=-r,t[3]=a,t[4]=0,t[5]=0,t},e.fromScaling=function(t,n){return t[0]=n[0],t[1]=0,t[2]=0,t[3]=n[1],t[4]=0,t[5]=0,t},e.fromTranslation=function(t,n){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=n[0],t[5]=n[1],t},e.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},e.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+1)},t.exports=e},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(9);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},e.fromMat4=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[4],t[4]=n[5],t[5]=n[6],t[6]=n[8],t[7]=n[9],t[8]=n[10],t},e.clone=function(t){var n=new a.ARRAY_TYPE(9);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},e.transpose=function(t,n){if(t===n){var r=n[1],a=n[2],e=n[5];t[1]=n[3],t[2]=n[6],t[3]=r,t[5]=n[7],t[6]=a,t[7]=e}else t[0]=n[0],t[1]=n[3],t[2]=n[6],t[3]=n[1],t[4]=n[4],t[5]=n[7],t[6]=n[2],t[7]=n[5],t[8]=n[8];return t},e.invert=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=n[6],f=n[7],s=n[8],h=s*o-i*f,M=-s*u+i*c,l=f*u-o*c,v=r*h+a*M+e*l;return v?(v=1/v,t[0]=h*v,t[1]=(-s*a+e*f)*v,t[2]=(i*a-e*o)*v,t[3]=M*v,t[4]=(s*r-e*c)*v,t[5]=(-i*r+e*u)*v,t[6]=l*v,t[7]=(-f*r+a*c)*v,t[8]=(o*r-a*u)*v,t):null},e.adjoint=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=n[6],f=n[7],s=n[8];return t[0]=o*s-i*f,t[1]=e*f-a*s,t[2]=a*i-e*o,t[3]=i*c-u*s,t[4]=r*s-e*c,t[5]=e*u-r*i,t[6]=u*f-o*c,t[7]=a*c-r*f,t[8]=r*o-a*u,t},e.determinant=function(t){var n=t[0],r=t[1],a=t[2],e=t[3],u=t[4],o=t[5],i=t[6],c=t[7],f=t[8];return n*(f*u-o*c)+r*(-f*e+o*i)+a*(c*e-u*i)},e.multiply=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=n[6],s=n[7],h=n[8],M=r[0],l=r[1],v=r[2],m=r[3],p=r[4],d=r[5],A=r[6],R=r[7],w=r[8];return t[0]=M*a+l*o+v*f,t[1]=M*e+l*i+v*s,t[2]=M*u+l*c+v*h,t[3]=m*a+p*o+d*f,t[4]=m*e+p*i+d*s,t[5]=m*u+p*c+d*h,t[6]=A*a+R*o+w*f,t[7]=A*e+R*i+w*s,t[8]=A*u+R*c+w*h,t},e.mul=e.multiply,e.translate=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=n[6],s=n[7],h=n[8],M=r[0],l=r[1];return t[0]=a,t[1]=e,t[2]=u,t[3]=o,t[4]=i,t[5]=c,t[6]=M*a+l*o+f,t[7]=M*e+l*i+s,t[8]=M*u+l*c+h,t},e.rotate=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=n[6],s=n[7],h=n[8],M=Math.sin(r),l=Math.cos(r);return t[0]=l*a+M*o,t[1]=l*e+M*i,t[2]=l*u+M*c,t[3]=l*o-M*a,t[4]=l*i-M*e,t[5]=l*c-M*u,t[6]=f,t[7]=s,t[8]=h,t},e.scale=function(t,n,r){var a=r[0],e=r[1];return t[0]=a*n[0],t[1]=a*n[1],t[2]=a*n[2],t[3]=e*n[3],t[4]=e*n[4],t[5]=e*n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t},e.fromTranslation=function(t,n){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=n[0],t[7]=n[1],t[8]=1,t},e.fromRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=a,t[1]=r,t[2]=0,t[3]=-r,t[4]=a,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},e.fromScaling=function(t,n){return t[0]=n[0],t[1]=0,t[2]=0,t[3]=0,t[4]=n[1],t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},e.fromMat2d=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=0,t[3]=n[2],t[4]=n[3],t[5]=0,t[6]=n[4],t[7]=n[5],t[8]=1,t},e.fromQuat=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=r+r,i=a+a,c=e+e,f=r*o,s=a*o,h=a*i,M=e*o,l=e*i,v=e*c,m=u*o,p=u*i,d=u*c;return t[0]=1-h-v,t[3]=s-d,t[6]=M+p,t[1]=s+d,t[4]=1-f-v,t[7]=l-m,t[2]=M-p,t[5]=l+m,t[8]=1-f-h,t},e.normalFromMat4=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=n[6],f=n[7],s=n[8],h=n[9],M=n[10],l=n[11],v=n[12],m=n[13],p=n[14],d=n[15],A=r*i-a*o,R=r*c-e*o,w=r*f-u*o,q=a*c-e*i,Y=a*f-u*i,g=e*f-u*c,y=s*m-h*v,x=s*p-M*v,P=s*d-l*v,E=h*p-M*m,T=h*d-l*m,b=M*d-l*p,D=A*b-R*T+w*E+q*P-Y*x+g*y;return D?(D=1/D,t[0]=(i*b-c*T+f*E)*D,t[1]=(c*P-o*b-f*x)*D,t[2]=(o*T-i*P+f*y)*D,t[3]=(e*T-a*b-u*E)*D,t[4]=(r*b-e*P+u*x)*D,t[5]=(a*P-r*T-u*y)*D,t[6]=(m*g-p*Y+d*q)*D,t[7]=(p*w-v*g-d*R)*D,t[8]=(v*Y-m*w+d*A)*D,t):null},e.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},e.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2))},t.exports=e},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.clone=function(t){var n=new a.ARRAY_TYPE(16);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.transpose=function(t,n){if(t===n){var r=n[1],a=n[2],e=n[3],u=n[6],o=n[7],i=n[11];t[1]=n[4],t[2]=n[8],t[3]=n[12],t[4]=r,t[6]=n[9],t[7]=n[13],t[8]=a,t[9]=u,t[11]=n[14],t[12]=e,t[13]=o,t[14]=i}else t[0]=n[0],t[1]=n[4],t[2]=n[8],t[3]=n[12],t[4]=n[1],t[5]=n[5],t[6]=n[9],t[7]=n[13],t[8]=n[2],t[9]=n[6],t[10]=n[10],t[11]=n[14],t[12]=n[3],t[13]=n[7],t[14]=n[11],t[15]=n[15];return t},e.invert=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=n[6],f=n[7],s=n[8],h=n[9],M=n[10],l=n[11],v=n[12],m=n[13],p=n[14],d=n[15],A=r*i-a*o,R=r*c-e*o,w=r*f-u*o,q=a*c-e*i,Y=a*f-u*i,g=e*f-u*c,y=s*m-h*v,x=s*p-M*v,P=s*d-l*v,E=h*p-M*m,T=h*d-l*m,b=M*d-l*p,D=A*b-R*T+w*E+q*P-Y*x+g*y;return D?(D=1/D,t[0]=(i*b-c*T+f*E)*D,t[1]=(e*T-a*b-u*E)*D,t[2]=(m*g-p*Y+d*q)*D,t[3]=(M*Y-h*g-l*q)*D,t[4]=(c*P-o*b-f*x)*D,t[5]=(r*b-e*P+u*x)*D,t[6]=(p*w-v*g-d*R)*D,t[7]=(s*g-M*w+l*R)*D,t[8]=(o*T-i*P+f*y)*D,t[9]=(a*P-r*T-u*y)*D,t[10]=(v*Y-m*w+d*A)*D,t[11]=(h*w-s*Y-l*A)*D,t[12]=(i*x-o*E-c*y)*D,t[13]=(r*E-a*x+e*y)*D,t[14]=(m*R-v*q-p*A)*D,t[15]=(s*q-h*R+M*A)*D,t):null},e.adjoint=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=n[4],i=n[5],c=n[6],f=n[7],s=n[8],h=n[9],M=n[10],l=n[11],v=n[12],m=n[13],p=n[14],d=n[15];return t[0]=i*(M*d-l*p)-h*(c*d-f*p)+m*(c*l-f*M),t[1]=-(a*(M*d-l*p)-h*(e*d-u*p)+m*(e*l-u*M)),t[2]=a*(c*d-f*p)-i*(e*d-u*p)+m*(e*f-u*c),t[3]=-(a*(c*l-f*M)-i*(e*l-u*M)+h*(e*f-u*c)),t[4]=-(o*(M*d-l*p)-s*(c*d-f*p)+v*(c*l-f*M)),t[5]=r*(M*d-l*p)-s*(e*d-u*p)+v*(e*l-u*M),t[6]=-(r*(c*d-f*p)-o*(e*d-u*p)+v*(e*f-u*c)),t[7]=r*(c*l-f*M)-o*(e*l-u*M)+s*(e*f-u*c),t[8]=o*(h*d-l*m)-s*(i*d-f*m)+v*(i*l-f*h),t[9]=-(r*(h*d-l*m)-s*(a*d-u*m)+v*(a*l-u*h)),t[10]=r*(i*d-f*m)-o*(a*d-u*m)+v*(a*f-u*i),t[11]=-(r*(i*l-f*h)-o*(a*l-u*h)+s*(a*f-u*i)),t[12]=-(o*(h*p-M*m)-s*(i*p-c*m)+v*(i*M-c*h)),t[13]=r*(h*p-M*m)-s*(a*p-e*m)+v*(a*M-e*h),t[14]=-(r*(i*p-c*m)-o*(a*p-e*m)+v*(a*c-e*i)),t[15]=r*(i*M-c*h)-o*(a*M-e*h)+s*(a*c-e*i),t},e.determinant=function(t){var n=t[0],r=t[1],a=t[2],e=t[3],u=t[4],o=t[5],i=t[6],c=t[7],f=t[8],s=t[9],h=t[10],M=t[11],l=t[12],v=t[13],m=t[14],p=t[15],d=n*o-r*u,A=n*i-a*u,R=n*c-e*u,w=r*i-a*o,q=r*c-e*o,Y=a*c-e*i,g=f*v-s*l,y=f*m-h*l,x=f*p-M*l,P=s*m-h*v,E=s*p-M*v,T=h*p-M*m;return d*T-A*E+R*P+w*x-q*y+Y*g},e.multiply=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=n[6],s=n[7],h=n[8],M=n[9],l=n[10],v=n[11],m=n[12],p=n[13],d=n[14],A=n[15],R=r[0],w=r[1],q=r[2],Y=r[3];return t[0]=R*a+w*i+q*h+Y*m,t[1]=R*e+w*c+q*M+Y*p,t[2]=R*u+w*f+q*l+Y*d,t[3]=R*o+w*s+q*v+Y*A,R=r[4],w=r[5],q=r[6],Y=r[7],t[4]=R*a+w*i+q*h+Y*m,t[5]=R*e+w*c+q*M+Y*p,t[6]=R*u+w*f+q*l+Y*d,t[7]=R*o+w*s+q*v+Y*A,R=r[8],w=r[9],q=r[10],Y=r[11],t[8]=R*a+w*i+q*h+Y*m,t[9]=R*e+w*c+q*M+Y*p,t[10]=R*u+w*f+q*l+Y*d,t[11]=R*o+w*s+q*v+Y*A,R=r[12],w=r[13],q=r[14],Y=r[15],t[12]=R*a+w*i+q*h+Y*m,t[13]=R*e+w*c+q*M+Y*p,t[14]=R*u+w*f+q*l+Y*d,t[15]=R*o+w*s+q*v+Y*A,t},e.mul=e.multiply,e.translate=function(t,n,r){var a,e,u,o,i,c,f,s,h,M,l,v,m=r[0],p=r[1],d=r[2];return n===t?(t[12]=n[0]*m+n[4]*p+n[8]*d+n[12],t[13]=n[1]*m+n[5]*p+n[9]*d+n[13],t[14]=n[2]*m+n[6]*p+n[10]*d+n[14],t[15]=n[3]*m+n[7]*p+n[11]*d+n[15]):(a=n[0],e=n[1],u=n[2],o=n[3],i=n[4],c=n[5],f=n[6],s=n[7],h=n[8],M=n[9],l=n[10],v=n[11],t[0]=a,t[1]=e,t[2]=u,t[3]=o,t[4]=i,t[5]=c,t[6]=f,t[7]=s,t[8]=h,t[9]=M,t[10]=l,t[11]=v,t[12]=a*m+i*p+h*d+n[12],t[13]=e*m+c*p+M*d+n[13],t[14]=u*m+f*p+l*d+n[14],t[15]=o*m+s*p+v*d+n[15]),t},e.scale=function(t,n,r){var a=r[0],e=r[1],u=r[2];return t[0]=n[0]*a,t[1]=n[1]*a,t[2]=n[2]*a,t[3]=n[3]*a,t[4]=n[4]*e,t[5]=n[5]*e,t[6]=n[6]*e,t[7]=n[7]*e,t[8]=n[8]*u,t[9]=n[9]*u,t[10]=n[10]*u,t[11]=n[11]*u,t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],t},e.rotate=function(t,n,r,e){var u,o,i,c,f,s,h,M,l,v,m,p,d,A,R,w,q,Y,g,y,x,P,E,T,b=e[0],D=e[1],L=e[2],_=Math.sqrt(b*b+D*D+L*L);return Math.abs(_)<a.EPSILON?null:(_=1/_,b*=_,D*=_,L*=_,u=Math.sin(r),o=Math.cos(r),i=1-o,c=n[0],f=n[1],s=n[2],h=n[3],M=n[4],l=n[5],v=n[6],m=n[7],p=n[8],d=n[9],A=n[10],R=n[11],w=b*b*i+o,q=D*b*i+L*u,Y=L*b*i-D*u,g=b*D*i-L*u,y=D*D*i+o,x=L*D*i+b*u,P=b*L*i+D*u,E=D*L*i-b*u,T=L*L*i+o,t[0]=c*w+M*q+p*Y,t[1]=f*w+l*q+d*Y,t[2]=s*w+v*q+A*Y,t[3]=h*w+m*q+R*Y,t[4]=c*g+M*y+p*x,t[5]=f*g+l*y+d*x,t[6]=s*g+v*y+A*x,t[7]=h*g+m*y+R*x,t[8]=c*P+M*E+p*T,t[9]=f*P+l*E+d*T,t[10]=s*P+v*E+A*T,t[11]=h*P+m*E+R*T,n!==t&&(t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15]),t)},e.rotateX=function(t,n,r){var a=Math.sin(r),e=Math.cos(r),u=n[4],o=n[5],i=n[6],c=n[7],f=n[8],s=n[9],h=n[10],M=n[11];return n!==t&&(t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15]),t[4]=u*e+f*a,t[5]=o*e+s*a,t[6]=i*e+h*a,t[7]=c*e+M*a,t[8]=f*e-u*a,t[9]=s*e-o*a,t[10]=h*e-i*a,t[11]=M*e-c*a,t},e.rotateY=function(t,n,r){var a=Math.sin(r),e=Math.cos(r),u=n[0],o=n[1],i=n[2],c=n[3],f=n[8],s=n[9],h=n[10],M=n[11];return n!==t&&(t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15]),t[0]=u*e-f*a,t[1]=o*e-s*a,t[2]=i*e-h*a,t[3]=c*e-M*a,t[8]=u*a+f*e,t[9]=o*a+s*e,t[10]=i*a+h*e,t[11]=c*a+M*e,t},e.rotateZ=function(t,n,r){var a=Math.sin(r),e=Math.cos(r),u=n[0],o=n[1],i=n[2],c=n[3],f=n[4],s=n[5],h=n[6],M=n[7];return n!==t&&(t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15]),t[0]=u*e+f*a,t[1]=o*e+s*a,t[2]=i*e+h*a,t[3]=c*e+M*a,t[4]=f*e-u*a,t[5]=s*e-o*a,t[6]=h*e-i*a,t[7]=M*e-c*a,t},e.fromTranslation=function(t,n){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t},e.fromScaling=function(t,n){return t[0]=n[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=n[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.fromRotation=function(t,n,r){var e,u,o,i=r[0],c=r[1],f=r[2],s=Math.sqrt(i*i+c*c+f*f);return Math.abs(s)<a.EPSILON?null:(s=1/s,i*=s,c*=s,f*=s,e=Math.sin(n),u=Math.cos(n),o=1-u,t[0]=i*i*o+u,t[1]=c*i*o+f*e,t[2]=f*i*o-c*e,t[3]=0,t[4]=i*c*o-f*e,t[5]=c*c*o+u,t[6]=f*c*o+i*e,t[7]=0,t[8]=i*f*o+c*e,t[9]=c*f*o-i*e,t[10]=f*f*o+u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)},e.fromXRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.fromYRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=a,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.fromZRotation=function(t,n){var r=Math.sin(n),a=Math.cos(n);return t[0]=a,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.fromRotationTranslation=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=a+a,c=e+e,f=u+u,s=a*i,h=a*c,M=a*f,l=e*c,v=e*f,m=u*f,p=o*i,d=o*c,A=o*f;return t[0]=1-(l+m),t[1]=h+A,t[2]=M-d,t[3]=0,t[4]=h-A,t[5]=1-(s+m),t[6]=v+p,t[7]=0,t[8]=M+d,t[9]=v-p,t[10]=1-(s+l),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},e.fromRotationTranslationScale=function(t,n,r,a){var e=n[0],u=n[1],o=n[2],i=n[3],c=e+e,f=u+u,s=o+o,h=e*c,M=e*f,l=e*s,v=u*f,m=u*s,p=o*s,d=i*c,A=i*f,R=i*s,w=a[0],q=a[1],Y=a[2];return t[0]=(1-(v+p))*w,t[1]=(M+R)*w,t[2]=(l-A)*w,t[3]=0,t[4]=(M-R)*q,t[5]=(1-(h+p))*q,t[6]=(m+d)*q,t[7]=0,t[8]=(l+A)*Y,t[9]=(m-d)*Y,t[10]=(1-(h+v))*Y,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},e.fromRotationTranslationScaleOrigin=function(t,n,r,a,e){var u=n[0],o=n[1],i=n[2],c=n[3],f=u+u,s=o+o,h=i+i,M=u*f,l=u*s,v=u*h,m=o*s,p=o*h,d=i*h,A=c*f,R=c*s,w=c*h,q=a[0],Y=a[1],g=a[2],y=e[0],x=e[1],P=e[2];return t[0]=(1-(m+d))*q,t[1]=(l+w)*q,t[2]=(v-R)*q,t[3]=0,t[4]=(l-w)*Y,t[5]=(1-(M+d))*Y,t[6]=(p+A)*Y,t[7]=0,t[8]=(v+R)*g,t[9]=(p-A)*g,t[10]=(1-(M+m))*g,t[11]=0,t[12]=r[0]+y-(t[0]*y+t[4]*x+t[8]*P),t[13]=r[1]+x-(t[1]*y+t[5]*x+t[9]*P),t[14]=r[2]+P-(t[2]*y+t[6]*x+t[10]*P),t[15]=1,t},e.fromQuat=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=r+r,i=a+a,c=e+e,f=r*o,s=a*o,h=a*i,M=e*o,l=e*i,v=e*c,m=u*o,p=u*i,d=u*c;return t[0]=1-h-v,t[1]=s+d,t[2]=M-p,t[3]=0,t[4]=s-d,t[5]=1-f-v,t[6]=l+m,t[7]=0,t[8]=M+p,t[9]=l-m,t[10]=1-f-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.frustum=function(t,n,r,a,e,u,o){var i=1/(r-n),c=1/(e-a),f=1/(u-o);return t[0]=2*u*i,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*u*c,t[6]=0,t[7]=0,t[8]=(r+n)*i,t[9]=(e+a)*c,t[10]=(o+u)*f,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*u*2*f,t[15]=0,t},e.perspective=function(t,n,r,a,e){var u=1/Math.tan(n/2),o=1/(a-e);return t[0]=u/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(e+a)*o,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*e*a*o,t[15]=0,t},e.perspectiveFromFieldOfView=function(t,n,r,a){var e=Math.tan(n.upDegrees*Math.PI/180),u=Math.tan(n.downDegrees*Math.PI/180),o=Math.tan(n.leftDegrees*Math.PI/180),i=Math.tan(n.rightDegrees*Math.PI/180),c=2/(o+i),f=2/(e+u);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=f,t[6]=0,t[7]=0,t[8]=-((o-i)*c*.5),t[9]=(e-u)*f*.5,t[10]=a/(r-a),t[11]=-1,t[12]=0,t[13]=0,t[14]=a*r/(r-a),t[15]=0,t},e.ortho=function(t,n,r,a,e,u,o){var i=1/(n-r),c=1/(a-e),f=1/(u-o);return t[0]=-2*i,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*f,t[11]=0,t[12]=(n+r)*i,t[13]=(e+a)*c,t[14]=(o+u)*f,t[15]=1,t},e.lookAt=function(t,n,r,u){var o,i,c,f,s,h,M,l,v,m,p=n[0],d=n[1],A=n[2],R=u[0],w=u[1],q=u[2],Y=r[0],g=r[1],y=r[2];return Math.abs(p-Y)<a.EPSILON&&Math.abs(d-g)<a.EPSILON&&Math.abs(A-y)<a.EPSILON?e.identity(t):(M=p-Y,l=d-g,v=A-y,m=1/Math.sqrt(M*M+l*l+v*v),M*=m,l*=m,v*=m,o=w*v-q*l,i=q*M-R*v,c=R*l-w*M,m=Math.sqrt(o*o+i*i+c*c),m?(m=1/m,o*=m,i*=m,c*=m):(o=0,i=0,c=0),f=l*c-v*i,s=v*o-M*c,h=M*i-l*o,m=Math.sqrt(f*f+s*s+h*h),m?(m=1/m,f*=m,s*=m,h*=m):(f=0,s=0,h=0),t[0]=o,t[1]=f,t[2]=M,t[3]=0,t[4]=i,t[5]=s,t[6]=l,t[7]=0,t[8]=c,t[9]=h,t[10]=v,t[11]=0,t[12]=-(o*p+i*d+c*A),t[13]=-(f*p+s*d+h*A),t[14]=-(M*p+l*d+v*A),t[15]=1,t)},e.str=function(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"},e.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2)+Math.pow(t[9],2)+Math.pow(t[10],2)+Math.pow(t[11],2)+Math.pow(t[12],2)+Math.pow(t[13],2)+Math.pow(t[14],2)+Math.pow(t[15],2))},t.exports=e},function(t,n,r){var a=r(1),e=r(4),u=r(7),o=r(8),i={};i.create=function(){var t=new a.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},i.rotationTo=function(){var t=u.create(),n=u.fromValues(1,0,0),r=u.fromValues(0,1,0);return function(a,e,o){var c=u.dot(e,o);return-.999999>c?(u.cross(t,n,e),u.length(t)<1e-6&&u.cross(t,r,e),u.normalize(t,t),i.setAxisAngle(a,t,Math.PI),a):c>.999999?(a[0]=0,a[1]=0,a[2]=0,a[3]=1,a):(u.cross(t,e,o),a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=1+c,i.normalize(a,a))}}(),i.setAxes=function(){var t=e.create();return function(n,r,a,e){return t[0]=a[0],t[3]=a[1],t[6]=a[2],t[1]=e[0],t[4]=e[1],t[7]=e[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],i.normalize(n,i.fromMat3(n,t))}}(),i.clone=o.clone,i.fromValues=o.fromValues,i.copy=o.copy,i.set=o.set,i.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},i.setAxisAngle=function(t,n,r){r=.5*r;var a=Math.sin(r);return t[0]=a*n[0],t[1]=a*n[1],t[2]=a*n[2],t[3]=Math.cos(r),t},i.add=o.add,i.multiply=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3],i=r[0],c=r[1],f=r[2],s=r[3];return t[0]=a*s+o*i+e*f-u*c,t[1]=e*s+o*c+u*i-a*f,t[2]=u*s+o*f+a*c-e*i,t[3]=o*s-a*i-e*c-u*f,t},i.mul=i.multiply,i.scale=o.scale,i.rotateX=function(t,n,r){r*=.5;var a=n[0],e=n[1],u=n[2],o=n[3],i=Math.sin(r),c=Math.cos(r);return t[0]=a*c+o*i,t[1]=e*c+u*i,t[2]=u*c-e*i,t[3]=o*c-a*i,t},i.rotateY=function(t,n,r){r*=.5;var a=n[0],e=n[1],u=n[2],o=n[3],i=Math.sin(r),c=Math.cos(r);return t[0]=a*c-u*i,t[1]=e*c+o*i,t[2]=u*c+a*i,t[3]=o*c-e*i,t},i.rotateZ=function(t,n,r){r*=.5;var a=n[0],e=n[1],u=n[2],o=n[3],i=Math.sin(r),c=Math.cos(r);return t[0]=a*c+e*i,t[1]=e*c-a*i,t[2]=u*c+o*i,t[3]=o*c-u*i,t},i.calculateW=function(t,n){var r=n[0],a=n[1],e=n[2];return t[0]=r,t[1]=a,t[2]=e,t[3]=Math.sqrt(Math.abs(1-r*r-a*a-e*e)),t},i.dot=o.dot,i.lerp=o.lerp,i.slerp=function(t,n,r,a){var e,u,o,i,c,f=n[0],s=n[1],h=n[2],M=n[3],l=r[0],v=r[1],m=r[2],p=r[3];return u=f*l+s*v+h*m+M*p,0>u&&(u=-u,l=-l,v=-v,m=-m,p=-p),1-u>1e-6?(e=Math.acos(u),o=Math.sin(e),i=Math.sin((1-a)*e)/o,c=Math.sin(a*e)/o):(i=1-a,c=a),t[0]=i*f+c*l,t[1]=i*s+c*v,t[2]=i*h+c*m,t[3]=i*M+c*p,t},i.sqlerp=function(){var t=i.create(),n=i.create();return function(r,a,e,u,o,c){return i.slerp(t,a,o,c),i.slerp(n,e,u,c),i.slerp(r,t,n,2*c*(1-c)),r}}(),i.invert=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=r*r+a*a+e*e+u*u,i=o?1/o:0;return t[0]=-r*i,t[1]=-a*i,t[2]=-e*i,t[3]=u*i,t},i.conjugate=function(t,n){return t[0]=-n[0],t[1]=-n[1],t[2]=-n[2],t[3]=n[3],t},i.length=o.length,i.len=i.length,i.squaredLength=o.squaredLength,i.sqrLen=i.squaredLength,i.normalize=o.normalize,i.fromMat3=function(t,n){var r,a=n[0]+n[4]+n[8];if(a>0)r=Math.sqrt(a+1),t[3]=.5*r,r=.5/r,t[0]=(n[5]-n[7])*r,t[1]=(n[6]-n[2])*r,t[2]=(n[1]-n[3])*r;else{var e=0;n[4]>n[0]&&(e=1),n[8]>n[3*e+e]&&(e=2);var u=(e+1)%3,o=(e+2)%3;r=Math.sqrt(n[3*e+e]-n[3*u+u]-n[3*o+o]+1),t[e]=.5*r,r=.5/r,t[3]=(n[3*u+o]-n[3*o+u])*r,t[u]=(n[3*u+e]+n[3*e+u])*r,t[o]=(n[3*o+e]+n[3*e+o])*r}return t},i.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t.exports=i},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(3);return t[0]=0,t[1]=0,t[2]=0,t},e.clone=function(t){var n=new a.ARRAY_TYPE(3);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n},e.fromValues=function(t,n,r){var e=new a.ARRAY_TYPE(3);return e[0]=t,e[1]=n,e[2]=r,e},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t},e.set=function(t,n,r,a){return t[0]=n,t[1]=r,t[2]=a,t},e.add=function(t,n,r){return t[0]=n[0]+r[0],t[1]=n[1]+r[1],t[2]=n[2]+r[2],t},e.subtract=function(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t},e.sub=e.subtract,e.multiply=function(t,n,r){return t[0]=n[0]*r[0],t[1]=n[1]*r[1],t[2]=n[2]*r[2],t},e.mul=e.multiply,e.divide=function(t,n,r){return t[0]=n[0]/r[0],t[1]=n[1]/r[1],t[2]=n[2]/r[2],t},e.div=e.divide,e.min=function(t,n,r){return t[0]=Math.min(n[0],r[0]),t[1]=Math.min(n[1],r[1]),t[2]=Math.min(n[2],r[2]),t},e.max=function(t,n,r){return t[0]=Math.max(n[0],r[0]),t[1]=Math.max(n[1],r[1]),t[2]=Math.max(n[2],r[2]),t},e.scale=function(t,n,r){return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t},e.scaleAndAdd=function(t,n,r,a){return t[0]=n[0]+r[0]*a,t[1]=n[1]+r[1]*a,t[2]=n[2]+r[2]*a,t},e.distance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1],e=n[2]-t[2];return Math.sqrt(r*r+a*a+e*e)},e.dist=e.distance,e.squaredDistance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1],e=n[2]-t[2];return r*r+a*a+e*e},e.sqrDist=e.squaredDistance,e.length=function(t){var n=t[0],r=t[1],a=t[2];return Math.sqrt(n*n+r*r+a*a)},e.len=e.length,e.squaredLength=function(t){var n=t[0],r=t[1],a=t[2];return n*n+r*r+a*a},e.sqrLen=e.squaredLength,e.negate=function(t,n){return t[0]=-n[0],t[1]=-n[1],t[2]=-n[2],t},e.inverse=function(t,n){return t[0]=1/n[0],t[1]=1/n[1],t[2]=1/n[2],t},e.normalize=function(t,n){var r=n[0],a=n[1],e=n[2],u=r*r+a*a+e*e;return u>0&&(u=1/Math.sqrt(u),t[0]=n[0]*u,t[1]=n[1]*u,t[2]=n[2]*u),t},e.dot=function(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]},e.cross=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=r[0],i=r[1],c=r[2];return t[0]=e*c-u*i,t[1]=u*o-a*c,t[2]=a*i-e*o,t},e.lerp=function(t,n,r,a){var e=n[0],u=n[1],o=n[2];return t[0]=e+a*(r[0]-e),t[1]=u+a*(r[1]-u),t[2]=o+a*(r[2]-o),t},e.hermite=function(t,n,r,a,e,u){var o=u*u,i=o*(2*u-3)+1,c=o*(u-2)+u,f=o*(u-1),s=o*(3-2*u);return t[0]=n[0]*i+r[0]*c+a[0]*f+e[0]*s,t[1]=n[1]*i+r[1]*c+a[1]*f+e[1]*s,t[2]=n[2]*i+r[2]*c+a[2]*f+e[2]*s,t},e.bezier=function(t,n,r,a,e,u){var o=1-u,i=o*o,c=u*u,f=i*o,s=3*u*i,h=3*c*o,M=c*u;return t[0]=n[0]*f+r[0]*s+a[0]*h+e[0]*M,t[1]=n[1]*f+r[1]*s+a[1]*h+e[1]*M,t[2]=n[2]*f+r[2]*s+a[2]*h+e[2]*M,t},e.random=function(t,n){n=n||1;var r=2*a.RANDOM()*Math.PI,e=2*a.RANDOM()-1,u=Math.sqrt(1-e*e)*n;return t[0]=Math.cos(r)*u,t[1]=Math.sin(r)*u,t[2]=e*n,t},e.transformMat4=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=r[3]*a+r[7]*e+r[11]*u+r[15];return o=o||1,t[0]=(r[0]*a+r[4]*e+r[8]*u+r[12])/o,t[1]=(r[1]*a+r[5]*e+r[9]*u+r[13])/o,t[2]=(r[2]*a+r[6]*e+r[10]*u+r[14])/o,t},e.transformMat3=function(t,n,r){var a=n[0],e=n[1],u=n[2];return t[0]=a*r[0]+e*r[3]+u*r[6],t[1]=a*r[1]+e*r[4]+u*r[7],t[2]=a*r[2]+e*r[5]+u*r[8],t},e.transformQuat=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=r[0],i=r[1],c=r[2],f=r[3],s=f*a+i*u-c*e,h=f*e+c*a-o*u,M=f*u+o*e-i*a,l=-o*a-i*e-c*u;return t[0]=s*f+l*-o+h*-c-M*-i,t[1]=h*f+l*-i+M*-o-s*-c,t[2]=M*f+l*-c+s*-i-h*-o,t},e.rotateX=function(t,n,r,a){var e=[],u=[];return e[0]=n[0]-r[0],e[1]=n[1]-r[1],e[2]=n[2]-r[2],u[0]=e[0],u[1]=e[1]*Math.cos(a)-e[2]*Math.sin(a),u[2]=e[1]*Math.sin(a)+e[2]*Math.cos(a),t[0]=u[0]+r[0],t[1]=u[1]+r[1],t[2]=u[2]+r[2],t},e.rotateY=function(t,n,r,a){var e=[],u=[];return e[0]=n[0]-r[0],e[1]=n[1]-r[1],e[2]=n[2]-r[2],u[0]=e[2]*Math.sin(a)+e[0]*Math.cos(a),u[1]=e[1],u[2]=e[2]*Math.cos(a)-e[0]*Math.sin(a),t[0]=u[0]+r[0],t[1]=u[1]+r[1],t[2]=u[2]+r[2],t},e.rotateZ=function(t,n,r,a){var e=[],u=[];return e[0]=n[0]-r[0],e[1]=n[1]-r[1],e[2]=n[2]-r[2],u[0]=e[0]*Math.cos(a)-e[1]*Math.sin(a),u[1]=e[0]*Math.sin(a)+e[1]*Math.cos(a),u[2]=e[2],t[0]=u[0]+r[0],t[1]=u[1]+r[1],t[2]=u[2]+r[2],t},e.forEach=function(){var t=e.create();return function(n,r,a,e,u,o){var i,c;for(r||(r=3),a||(a=0),c=e?Math.min(e*r+a,n.length):n.length,i=a;c>i;i+=r)t[0]=n[i],t[1]=n[i+1],t[2]=n[i+2],u(t,t,o),n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2];return n}}(),e.angle=function(t,n){var r=e.fromValues(t[0],t[1],t[2]),a=e.fromValues(n[0],n[1],n[2]);e.normalize(r,r),e.normalize(a,a);var u=e.dot(r,a);return u>1?0:Math.acos(u)},e.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},t.exports=e},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},e.clone=function(t){var n=new a.ARRAY_TYPE(4);return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n},e.fromValues=function(t,n,r,e){var u=new a.ARRAY_TYPE(4);return u[0]=t,u[1]=n,u[2]=r,u[3]=e,u},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t},e.set=function(t,n,r,a,e){return t[0]=n,t[1]=r,t[2]=a,t[3]=e,t},e.add=function(t,n,r){return t[0]=n[0]+r[0],t[1]=n[1]+r[1],t[2]=n[2]+r[2],t[3]=n[3]+r[3],t},e.subtract=function(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t[3]=n[3]-r[3],t},e.sub=e.subtract,e.multiply=function(t,n,r){return t[0]=n[0]*r[0],t[1]=n[1]*r[1],t[2]=n[2]*r[2],t[3]=n[3]*r[3],t},e.mul=e.multiply,e.divide=function(t,n,r){return t[0]=n[0]/r[0],t[1]=n[1]/r[1],t[2]=n[2]/r[2],t[3]=n[3]/r[3],t},e.div=e.divide,e.min=function(t,n,r){return t[0]=Math.min(n[0],r[0]),t[1]=Math.min(n[1],r[1]),t[2]=Math.min(n[2],r[2]),t[3]=Math.min(n[3],r[3]),t},e.max=function(t,n,r){return t[0]=Math.max(n[0],r[0]),t[1]=Math.max(n[1],r[1]),t[2]=Math.max(n[2],r[2]),t[3]=Math.max(n[3],r[3]),t},e.scale=function(t,n,r){return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=n[3]*r,t},e.scaleAndAdd=function(t,n,r,a){return t[0]=n[0]+r[0]*a,t[1]=n[1]+r[1]*a,t[2]=n[2]+r[2]*a,t[3]=n[3]+r[3]*a,t},e.distance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1],e=n[2]-t[2],u=n[3]-t[3];return Math.sqrt(r*r+a*a+e*e+u*u)},e.dist=e.distance,e.squaredDistance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1],e=n[2]-t[2],u=n[3]-t[3];return r*r+a*a+e*e+u*u},e.sqrDist=e.squaredDistance,e.length=function(t){var n=t[0],r=t[1],a=t[2],e=t[3];return Math.sqrt(n*n+r*r+a*a+e*e)},e.len=e.length,e.squaredLength=function(t){var n=t[0],r=t[1],a=t[2],e=t[3];return n*n+r*r+a*a+e*e},e.sqrLen=e.squaredLength,e.negate=function(t,n){return t[0]=-n[0],t[1]=-n[1],t[2]=-n[2],t[3]=-n[3],t},e.inverse=function(t,n){return t[0]=1/n[0],t[1]=1/n[1],t[2]=1/n[2],t[3]=1/n[3],t},e.normalize=function(t,n){var r=n[0],a=n[1],e=n[2],u=n[3],o=r*r+a*a+e*e+u*u;return o>0&&(o=1/Math.sqrt(o),t[0]=r*o,t[1]=a*o,t[2]=e*o,t[3]=u*o),t},e.dot=function(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3]},e.lerp=function(t,n,r,a){var e=n[0],u=n[1],o=n[2],i=n[3];return t[0]=e+a*(r[0]-e),t[1]=u+a*(r[1]-u),t[2]=o+a*(r[2]-o),t[3]=i+a*(r[3]-i),t},e.random=function(t,n){return n=n||1,t[0]=a.RANDOM(),t[1]=a.RANDOM(),t[2]=a.RANDOM(),t[3]=a.RANDOM(),e.normalize(t,t),e.scale(t,t,n),t},e.transformMat4=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=n[3];return t[0]=r[0]*a+r[4]*e+r[8]*u+r[12]*o,t[1]=r[1]*a+r[5]*e+r[9]*u+r[13]*o,t[2]=r[2]*a+r[6]*e+r[10]*u+r[14]*o,t[3]=r[3]*a+r[7]*e+r[11]*u+r[15]*o,t},e.transformQuat=function(t,n,r){var a=n[0],e=n[1],u=n[2],o=r[0],i=r[1],c=r[2],f=r[3],s=f*a+i*u-c*e,h=f*e+c*a-o*u,M=f*u+o*e-i*a,l=-o*a-i*e-c*u;return t[0]=s*f+l*-o+h*-c-M*-i,t[1]=h*f+l*-i+M*-o-s*-c,t[2]=M*f+l*-c+s*-i-h*-o,t[3]=n[3],t},e.forEach=function(){var t=e.create();return function(n,r,a,e,u,o){var i,c;for(r||(r=4),a||(a=0),c=e?Math.min(e*r+a,n.length):n.length,i=a;c>i;i+=r)t[0]=n[i],t[1]=n[i+1],t[2]=n[i+2],t[3]=n[i+3],u(t,t,o),n[i]=t[0],n[i+1]=t[1],n[i+2]=t[2],n[i+3]=t[3];return n}}(),e.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t.exports=e},function(t,n,r){var a=r(1),e={};e.create=function(){var t=new a.ARRAY_TYPE(2);return t[0]=0,t[1]=0,t},e.clone=function(t){var n=new a.ARRAY_TYPE(2);return n[0]=t[0],n[1]=t[1],n},e.fromValues=function(t,n){var r=new a.ARRAY_TYPE(2);return r[0]=t,r[1]=n,r},e.copy=function(t,n){return t[0]=n[0],t[1]=n[1],t},e.set=function(t,n,r){return t[0]=n,t[1]=r,t},e.add=function(t,n,r){return t[0]=n[0]+r[0],t[1]=n[1]+r[1],t},e.subtract=function(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t},e.sub=e.subtract,e.multiply=function(t,n,r){return t[0]=n[0]*r[0],t[1]=n[1]*r[1],t},e.mul=e.multiply,e.divide=function(t,n,r){return t[0]=n[0]/r[0],t[1]=n[1]/r[1],t},e.div=e.divide,e.min=function(t,n,r){return t[0]=Math.min(n[0],r[0]),t[1]=Math.min(n[1],r[1]),t},e.max=function(t,n,r){return t[0]=Math.max(n[0],r[0]),t[1]=Math.max(n[1],r[1]),t},e.scale=function(t,n,r){return t[0]=n[0]*r,t[1]=n[1]*r,t},e.scaleAndAdd=function(t,n,r,a){return t[0]=n[0]+r[0]*a,t[1]=n[1]+r[1]*a,t},e.distance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1];return Math.sqrt(r*r+a*a)},e.dist=e.distance,e.squaredDistance=function(t,n){var r=n[0]-t[0],a=n[1]-t[1];return r*r+a*a},e.sqrDist=e.squaredDistance,e.length=function(t){var n=t[0],r=t[1];return Math.sqrt(n*n+r*r)},e.len=e.length,e.squaredLength=function(t){var n=t[0],r=t[1];return n*n+r*r},e.sqrLen=e.squaredLength,e.negate=function(t,n){return t[0]=-n[0],t[1]=-n[1],t},e.inverse=function(t,n){return t[0]=1/n[0],t[1]=1/n[1],t},e.normalize=function(t,n){var r=n[0],a=n[1],e=r*r+a*a;return e>0&&(e=1/Math.sqrt(e),t[0]=n[0]*e,t[1]=n[1]*e),t},e.dot=function(t,n){return t[0]*n[0]+t[1]*n[1]},e.cross=function(t,n,r){var a=n[0]*r[1]-n[1]*r[0];return t[0]=t[1]=0,t[2]=a,t},e.lerp=function(t,n,r,a){var e=n[0],u=n[1];return t[0]=e+a*(r[0]-e),t[1]=u+a*(r[1]-u),t},e.random=function(t,n){n=n||1;var r=2*a.RANDOM()*Math.PI;return t[0]=Math.cos(r)*n,t[1]=Math.sin(r)*n,t},e.transformMat2=function(t,n,r){var a=n[0],e=n[1];return t[0]=r[0]*a+r[2]*e,t[1]=r[1]*a+r[3]*e,t},e.transformMat2d=function(t,n,r){var a=n[0],e=n[1];return t[0]=r[0]*a+r[2]*e+r[4],t[1]=r[1]*a+r[3]*e+r[5],t},e.transformMat3=function(t,n,r){ +var a=n[0],e=n[1];return t[0]=r[0]*a+r[3]*e+r[6],t[1]=r[1]*a+r[4]*e+r[7],t},e.transformMat4=function(t,n,r){var a=n[0],e=n[1];return t[0]=r[0]*a+r[4]*e+r[12],t[1]=r[1]*a+r[5]*e+r[13],t},e.forEach=function(){var t=e.create();return function(n,r,a,e,u,o){var i,c;for(r||(r=2),a||(a=0),c=e?Math.min(e*r+a,n.length):n.length,i=a;c>i;i+=r)t[0]=n[i],t[1]=n[i+1],u(t,t,o),n[i]=t[0],n[i+1]=t[1];return n}}(),e.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},t.exports=e}])});
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix.js new file mode 100644 index 00000000000..ab1e9b0aa58 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/dist/gl-matrix.js @@ -0,0 +1,5020 @@ +/** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.1 + */ + +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define(factory); + else { + var a = factory(); + for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; + } +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.1 + */ + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + // END HEADER + + exports.glMatrix = __webpack_require__(1); + exports.mat2 = __webpack_require__(2); + exports.mat2d = __webpack_require__(3); + exports.mat3 = __webpack_require__(4); + exports.mat4 = __webpack_require__(5); + exports.quat = __webpack_require__(6); + exports.vec2 = __webpack_require__(9); + exports.vec3 = __webpack_require__(7); + exports.vec4 = __webpack_require__(8); + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + /** + * @class Common utilities + * @name glMatrix + */ + var glMatrix = {}; + + // Constants + glMatrix.EPSILON = 0.000001; + glMatrix.ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array; + glMatrix.RANDOM = Math.random; + + /** + * Sets the type of array used when creating new vectors and matrices + * + * @param {Type} type Array type, such as Float32Array or Array + */ + glMatrix.setMatrixArrayType = function(type) { + GLMAT_ARRAY_TYPE = type; + } + + var degree = Math.PI / 180; + + /** + * Convert Degree To Radian + * + * @param {Number} Angle in Degrees + */ + glMatrix.toRadian = function(a){ + return a * degree; + } + + module.exports = glMatrix; + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2x2 Matrix + * @name mat2 + */ + var mat2 = {}; + + /** + * Creates a new identity mat2 + * + * @returns {mat2} a new 2x2 matrix + */ + mat2.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Creates a new mat2 initialized with values from an existing matrix + * + * @param {mat2} a matrix to clone + * @returns {mat2} a new 2x2 matrix + */ + mat2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Copy the values from one mat2 to another + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Set a mat2 to the identity matrix + * + * @param {mat2} out the receiving matrix + * @returns {mat2} out + */ + mat2.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Transpose the values of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a1 = a[1]; + out[1] = a[2]; + out[2] = a1; + } else { + out[0] = a[0]; + out[1] = a[2]; + out[2] = a[1]; + out[3] = a[3]; + } + + return out; + }; + + /** + * Inverts a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + + // Calculate the determinant + det = a0 * a3 - a2 * a1; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = a3 * det; + out[1] = -a1 * det; + out[2] = -a2 * det; + out[3] = a0 * det; + + return out; + }; + + /** + * Calculates the adjugate of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ + mat2.adjoint = function(out, a) { + // Caching this value is nessecary if out == a + var a0 = a[0]; + out[0] = a[3]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a0; + + return out; + }; + + /** + * Calculates the determinant of a mat2 + * + * @param {mat2} a the source matrix + * @returns {Number} determinant of a + */ + mat2.determinant = function (a) { + return a[0] * a[3] - a[2] * a[1]; + }; + + /** + * Multiplies two mat2's + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ + mat2.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = a0 * b0 + a2 * b1; + out[1] = a1 * b0 + a3 * b1; + out[2] = a0 * b2 + a2 * b3; + out[3] = a1 * b2 + a3 * b3; + return out; + }; + + /** + * Alias for {@link mat2.multiply} + * @function + */ + mat2.mul = mat2.multiply; + + /** + * Rotates a mat2 by the given angle + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ + mat2.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + s = Math.sin(rad), + 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; + return out; + }; + + /** + * Scales the mat2 by the dimensions in the given vec2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat2} out + **/ + mat2.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + v0 = v[0], v1 = v[1]; + out[0] = a0 * v0; + out[1] = a1 * v0; + out[2] = a2 * v1; + out[3] = a3 * v1; + return out; + }; + + /** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.rotate(dest, dest, rad); + * + * @param {mat2} out mat2 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ + mat2.fromRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + out[0] = c; + out[1] = s; + out[2] = -s; + out[3] = c; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.scale(dest, dest, vec); + * + * @param {mat2} out mat2 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat2} out + */ + mat2.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = v[1]; + return out; + } + + /** + * Returns a string representation of a mat2 + * + * @param {mat2} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat2.str = function (a) { + return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + /** + * Returns Frobenius norm of a mat2 + * + * @param {mat2} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat2.frob = function (a) { + return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2))) + }; + + /** + * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix + * @param {mat2} L the lower triangular matrix + * @param {mat2} D the diagonal matrix + * @param {mat2} U the upper triangular matrix + * @param {mat2} a the input matrix to factorize + */ + + mat2.LDU = function (L, D, U, a) { + L[2] = a[2]/a[0]; + U[0] = a[0]; + U[1] = a[1]; + U[3] = a[3] - L[2] * U[1]; + return [L, D, U]; + }; + + + module.exports = mat2; + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2x3 Matrix + * @name 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. + */ + var mat2d = {}; + + /** + * Creates a new identity mat2d + * + * @returns {mat2d} a new 2x3 matrix + */ + mat2d.create = function() { + var out = new glMatrix.ARRAY_TYPE(6); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + 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 + */ + mat2d.clone = function(a) { + var 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 + */ + mat2d.copy = function(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 + */ + mat2d.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; + }; + + /** + * Inverts a mat2d + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ + mat2d.invert = function(out, a) { + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], + atx = a[4], aty = a[5]; + + var 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 + */ + mat2d.determinant = function (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 + */ + mat2d.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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; + }; + + /** + * Alias for {@link mat2d.multiply} + * @function + */ + mat2d.mul = mat2d.multiply; + + /** + * 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 + */ + mat2d.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + s = Math.sin(rad), + 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 + **/ + mat2d.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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 + **/ + mat2d.translate = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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 + */ + mat2d.fromRotation = function(out, rad) { + var 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 + */ + mat2d.fromScaling = function(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 + */ + mat2d.fromTranslation = function(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 + */ + mat2d.str = function (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 + */ + mat2d.frob = function (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)) + }; + + module.exports = mat2d; + + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 3x3 Matrix + * @name mat3 + */ + var mat3 = {}; + + /** + * Creates a new identity mat3 + * + * @returns {mat3} a new 3x3 matrix + */ + mat3.create = function() { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + }; + + /** + * Copies the upper-left 3x3 values into the given mat3. + * + * @param {mat3} out the receiving 3x3 matrix + * @param {mat4} a the source 4x4 matrix + * @returns {mat3} out + */ + mat3.fromMat4 = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[4]; + out[4] = a[5]; + out[5] = a[6]; + out[6] = a[8]; + out[7] = a[9]; + out[8] = a[10]; + return out; + }; + + /** + * Creates a new mat3 initialized with values from an existing matrix + * + * @param {mat3} a matrix to clone + * @returns {mat3} a new 3x3 matrix + */ + mat3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Copy the values from one mat3 to another + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.copy = function(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]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Set a mat3 to the identity matrix + * + * @param {mat3} out the receiving matrix + * @returns {mat3} out + */ + mat3.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + }; + + /** + * Transpose the values of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a12 = a[5]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a01; + out[5] = a[7]; + out[6] = a02; + out[7] = a12; + } else { + out[0] = a[0]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a[1]; + out[4] = a[4]; + out[5] = a[7]; + out[6] = a[2]; + out[7] = a[5]; + out[8] = a[8]; + } + + return out; + }; + + /** + * Inverts a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b01 = a22 * a11 - a12 * a21, + b11 = -a22 * a10 + a12 * a20, + b21 = a21 * a10 - a11 * a20, + + // Calculate the determinant + det = a00 * b01 + a01 * b11 + a02 * b21; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = b01 * det; + out[1] = (-a22 * a01 + a02 * a21) * det; + out[2] = (a12 * a01 - a02 * a11) * det; + out[3] = b11 * det; + out[4] = (a22 * a00 - a02 * a20) * det; + out[5] = (-a12 * a00 + a02 * a10) * det; + out[6] = b21 * det; + out[7] = (-a21 * a00 + a01 * a20) * det; + out[8] = (a11 * a00 - a01 * a10) * det; + return out; + }; + + /** + * Calculates the adjugate of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ + mat3.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + out[0] = (a11 * a22 - a12 * a21); + out[1] = (a02 * a21 - a01 * a22); + out[2] = (a01 * a12 - a02 * a11); + out[3] = (a12 * a20 - a10 * a22); + out[4] = (a00 * a22 - a02 * a20); + out[5] = (a02 * a10 - a00 * a12); + out[6] = (a10 * a21 - a11 * a20); + out[7] = (a01 * a20 - a00 * a21); + out[8] = (a00 * a11 - a01 * a10); + return out; + }; + + /** + * Calculates the determinant of a mat3 + * + * @param {mat3} a the source matrix + * @returns {Number} determinant of a + */ + mat3.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); + }; + + /** + * Multiplies two mat3's + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ + mat3.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b00 = b[0], b01 = b[1], b02 = b[2], + b10 = b[3], b11 = b[4], b12 = b[5], + b20 = b[6], b21 = b[7], b22 = b[8]; + + out[0] = b00 * a00 + b01 * a10 + b02 * a20; + out[1] = b00 * a01 + b01 * a11 + b02 * a21; + out[2] = b00 * a02 + b01 * a12 + b02 * a22; + + out[3] = b10 * a00 + b11 * a10 + b12 * a20; + out[4] = b10 * a01 + b11 * a11 + b12 * a21; + out[5] = b10 * a02 + b11 * a12 + b12 * a22; + + out[6] = b20 * a00 + b21 * a10 + b22 * a20; + out[7] = b20 * a01 + b21 * a11 + b22 * a21; + out[8] = b20 * a02 + b21 * a12 + b22 * a22; + return out; + }; + + /** + * Alias for {@link mat3.multiply} + * @function + */ + mat3.mul = mat3.multiply; + + /** + * Translate a mat3 by the given vector + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to translate + * @param {vec2} v vector to translate by + * @returns {mat3} out + */ + mat3.translate = function(out, a, v) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + x = v[0], y = v[1]; + + out[0] = a00; + out[1] = a01; + out[2] = a02; + + out[3] = a10; + out[4] = a11; + out[5] = a12; + + out[6] = x * a00 + y * a10 + a20; + out[7] = x * a01 + y * a11 + a21; + out[8] = x * a02 + y * a12 + a22; + return out; + }; + + /** + * Rotates a mat3 by the given angle + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ + mat3.rotate = function (out, a, rad) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + s = Math.sin(rad), + c = Math.cos(rad); + + out[0] = c * a00 + s * a10; + out[1] = c * a01 + s * a11; + out[2] = c * a02 + s * a12; + + out[3] = c * a10 - s * a00; + out[4] = c * a11 - s * a01; + out[5] = c * a12 - s * a02; + + out[6] = a20; + out[7] = a21; + out[8] = a22; + return out; + }; + + /** + * Scales the mat3 by the dimensions in the given vec2 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat3} out + **/ + mat3.scale = function(out, a, v) { + var x = v[0], y = v[1]; + + out[0] = x * a[0]; + out[1] = x * a[1]; + out[2] = x * a[2]; + + out[3] = y * a[3]; + out[4] = y * a[4]; + out[5] = y * a[5]; + + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; + }; + + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.translate(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Translation vector + * @returns {mat3} out + */ + mat3.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = v[0]; + out[7] = v[1]; + out[8] = 1; + return out; + } + + /** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.rotate(dest, dest, rad); + * + * @param {mat3} out mat3 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ + mat3.fromRotation = function(out, rad) { + var s = Math.sin(rad), c = Math.cos(rad); + + out[0] = c; + out[1] = s; + out[2] = 0; + + out[3] = -s; + out[4] = c; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.scale(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat3} out + */ + mat3.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + + out[3] = 0; + out[4] = v[1]; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; + } + + /** + * Copies the values from a mat2d into a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat2d} a the matrix to copy + * @returns {mat3} out + **/ + mat3.fromMat2d = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = 0; + + out[3] = a[2]; + out[4] = a[3]; + out[5] = 0; + + out[6] = a[4]; + out[7] = a[5]; + out[8] = 1; + return out; + }; + + /** + * Calculates a 3x3 matrix from the given quaternion + * + * @param {mat3} out mat3 receiving operation result + * @param {quat} q Quaternion to create matrix from + * + * @returns {mat3} out + */ + mat3.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[3] = yx - wz; + out[6] = zx + wy; + + out[1] = yx + wz; + out[4] = 1 - xx - zz; + out[7] = zy - wx; + + out[2] = zx - wy; + out[5] = zy + wx; + out[8] = 1 - xx - yy; + + return out; + }; + + /** + * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix + * + * @param {mat3} out mat3 receiving operation result + * @param {mat4} a Mat4 to derive the normal matrix from + * + * @returns {mat3} out + */ + mat3.normalFromMat4 = function (out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + + out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + + out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + + return out; + }; + + /** + * Returns a string representation of a mat3 + * + * @param {mat3} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat3.str = function (a) { + return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + + a[6] + ', ' + a[7] + ', ' + a[8] + ')'; + }; + + /** + * Returns Frobenius norm of a mat3 + * + * @param {mat3} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat3.frob = function (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) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2))) + }; + + + module.exports = mat3; + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 4x4 Matrix + * @name mat4 + */ + var mat4 = {}; + + /** + * Creates a new identity mat4 + * + * @returns {mat4} a new 4x4 matrix + */ + mat4.create = function() { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + }; + + /** + * Creates a new mat4 initialized with values from an existing matrix + * + * @param {mat4} a matrix to clone + * @returns {mat4} a new 4x4 matrix + */ + mat4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Copy the values from one mat4 to another + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.copy = function(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]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Set a mat4 to the identity matrix + * + * @param {mat4} out the receiving matrix + * @returns {mat4} out + */ + mat4.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + }; + + /** + * Transpose the values of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a03 = a[3], + a12 = a[6], a13 = a[7], + a23 = a[11]; + + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a01; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a02; + out[9] = a12; + out[11] = a[14]; + out[12] = a03; + out[13] = a13; + out[14] = a23; + } else { + out[0] = a[0]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a[1]; + out[5] = a[5]; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a[2]; + out[9] = a[6]; + out[10] = a[10]; + out[11] = a[14]; + out[12] = a[3]; + out[13] = a[7]; + out[14] = a[11]; + out[15] = a[15]; + } + + return out; + }; + + /** + * Inverts a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + + return out; + }; + + /** + * Calculates the adjugate of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + mat4.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); + out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); + out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); + out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); + out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); + out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); + out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); + out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); + out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); + out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); + out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); + out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); + out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); + out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); + out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); + out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); + return out; + }; + + /** + * Calculates the determinant of a mat4 + * + * @param {mat4} a the source matrix + * @returns {Number} determinant of a + */ + mat4.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32; + + // Calculate the determinant + return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + }; + + /** + * Multiplies two mat4's + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + mat4.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + // Cache only the current line of the second matrix + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; + out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; + out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; + out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + return out; + }; + + /** + * Alias for {@link mat4.multiply} + * @function + */ + mat4.mul = mat4.multiply; + + /** + * Translate a mat4 by the given vector + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ + mat4.translate = function (out, a, v) { + var x = v[0], y = v[1], z = v[2], + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23; + + if (a === out) { + out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; + out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; + out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; + out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; + } else { + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; + out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; + out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; + + out[12] = a00 * x + a10 * y + a20 * z + a[12]; + out[13] = a01 * x + a11 * y + a21 * z + a[13]; + out[14] = a02 * x + a12 * y + a22 * z + a[14]; + out[15] = a03 * x + a13 * y + a23 * z + a[15]; + } + + return out; + }; + + /** + * Scales the mat4 by the dimensions in the given vec3 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ + mat4.scale = function(out, a, v) { + var x = v[0], y = v[1], z = v[2]; + + out[0] = a[0] * x; + out[1] = a[1] * x; + out[2] = a[2] * x; + out[3] = a[3] * x; + out[4] = a[4] * y; + out[5] = a[5] * y; + out[6] = a[6] * y; + out[7] = a[7] * y; + out[8] = a[8] * z; + out[9] = a[9] * z; + out[10] = a[10] * z; + out[11] = a[11] * z; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + }; + + /** + * Rotates a mat4 by the given angle around the given axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + mat4.rotate = function (out, a, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t, + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23, + b00, b01, b02, + b10, b11, b12, + b20, b21, b22; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + // Construct the elements of the rotation matrix + b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; + b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; + b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; + + // Perform rotation-specific matrix multiplication + out[0] = a00 * b00 + a10 * b01 + a20 * b02; + out[1] = a01 * b00 + a11 * b01 + a21 * b02; + out[2] = a02 * b00 + a12 * b01 + a22 * b02; + out[3] = a03 * b00 + a13 * b01 + a23 * b02; + out[4] = a00 * b10 + a10 * b11 + a20 * b12; + out[5] = a01 * b10 + a11 * b11 + a21 * b12; + out[6] = a02 * b10 + a12 * b11 + a22 * b12; + out[7] = a03 * b10 + a13 * b11 + a23 * b12; + out[8] = a00 * b20 + a10 * b21 + a20 * b22; + out[9] = a01 * b20 + a11 * b21 + a21 * b22; + out[10] = a02 * b20 + a12 * b21 + a22 * b22; + out[11] = a03 * b20 + a13 * b21 + a23 * b22; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + return out; + }; + + /** + * Rotates a matrix by the given angle around the X axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateX = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[4] = a10 * c + a20 * s; + out[5] = a11 * c + a21 * s; + out[6] = a12 * c + a22 * s; + out[7] = a13 * c + a23 * s; + out[8] = a20 * c - a10 * s; + out[9] = a21 * c - a11 * s; + out[10] = a22 * c - a12 * s; + out[11] = a23 * c - a13 * s; + return out; + }; + + /** + * Rotates a matrix by the given angle around the Y axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateY = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c - a20 * s; + out[1] = a01 * c - a21 * s; + out[2] = a02 * c - a22 * s; + out[3] = a03 * c - a23 * s; + out[8] = a00 * s + a20 * c; + out[9] = a01 * s + a21 * c; + out[10] = a02 * s + a22 * c; + out[11] = a03 * s + a23 * c; + return out; + }; + + /** + * Rotates a matrix by the given angle around the Z axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.rotateZ = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c + a10 * s; + out[1] = a01 * c + a11 * s; + out[2] = a02 * c + a12 * s; + out[3] = a03 * c + a13 * s; + out[4] = a10 * c - a00 * s; + out[5] = a11 * c - a01 * s; + out[6] = a12 * c - a02 * s; + out[7] = a13 * c - a03 * s; + return out; + }; + + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + mat4.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.scale(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Scaling vector + * @returns {mat4} out + */ + mat4.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = v[1]; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = v[2]; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a given angle around a given axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotate(dest, dest, rad, axis); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + mat4.fromRotation = function(out, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + // Perform rotation-specific matrix multiplication + out[0] = x * x * t + c; + out[1] = y * x * t + z * s; + out[2] = z * x * t - y * s; + out[3] = 0; + out[4] = x * y * t - z * s; + out[5] = y * y * t + c; + out[6] = z * y * t + x * s; + out[7] = 0; + out[8] = x * z * t + y * s; + out[9] = y * z * t - x * s; + out[10] = z * z * t + c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the X axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateX(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromXRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = c; + out[6] = s; + out[7] = 0; + out[8] = 0; + out[9] = -s; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the Y axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateY(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromYRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = 0; + out[2] = -s; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = s; + out[9] = 0; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from the given angle around the Z axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateZ(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + mat4.fromZRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = s; + out[2] = 0; + out[3] = 0; + out[4] = -s; + out[5] = c; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + + /** + * Creates a matrix from a quaternion rotation and vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + mat4.fromRotationTranslation = function (out, q, v) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; + }; + + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @returns {mat4} out + */ + mat4.fromRotationTranslationScale = function (out, q, v, s) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + sx = s[0], + sy = s[1], + sz = s[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; + }; + + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * mat4.translate(dest, origin); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * mat4.translate(dest, negativeOrigin); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @param {vec3} o The origin vector around which to scale and rotate + * @returns {mat4} out + */ + mat4.fromRotationTranslationScaleOrigin = function (out, q, v, s, o) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + + sx = s[0], + sy = s[1], + sz = s[2], + + ox = o[0], + oy = o[1], + oz = o[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0] + ox - (out[0] * ox + out[4] * oy + out[8] * oz); + out[13] = v[1] + oy - (out[1] * ox + out[5] * oy + out[9] * oz); + out[14] = v[2] + oz - (out[2] * ox + out[6] * oy + out[10] * oz); + out[15] = 1; + + return out; + }; + + mat4.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[1] = yx + wz; + out[2] = zx - wy; + out[3] = 0; + + out[4] = yx - wz; + out[5] = 1 - xx - zz; + out[6] = zy + wx; + out[7] = 0; + + out[8] = zx + wy; + out[9] = zy - wx; + out[10] = 1 - xx - yy; + out[11] = 0; + + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + + return out; + }; + + /** + * Generates a frustum matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Number} left Left bound of the frustum + * @param {Number} right Right bound of the frustum + * @param {Number} bottom Bottom bound of the frustum + * @param {Number} top Top bound of the frustum + * @param {Number} near Near bound of the frustum + * @param {Number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.frustum = function (out, left, right, bottom, top, near, far) { + var rl = 1 / (right - left), + tb = 1 / (top - bottom), + nf = 1 / (near - far); + out[0] = (near * 2) * rl; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = (near * 2) * tb; + out[6] = 0; + out[7] = 0; + out[8] = (right + left) * rl; + out[9] = (top + bottom) * tb; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (far * near * 2) * nf; + out[15] = 0; + return out; + }; + + /** + * Generates a perspective projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fovy Vertical field of view in radians + * @param {number} aspect Aspect ratio. typically viewport width/height + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.perspective = function (out, fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf = 1 / (near - far); + out[0] = f / aspect; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = f; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (2 * far * near) * nf; + out[15] = 0; + return out; + }; + + /** + * Generates a perspective projection matrix with the given field of view. + * This is primarily useful for generating projection matrices to be used + * with the still experiemental WebVR API. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.perspectiveFromFieldOfView = function (out, fov, near, far) { + var upTan = Math.tan(fov.upDegrees * Math.PI/180.0), + downTan = Math.tan(fov.downDegrees * Math.PI/180.0), + leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0), + rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0), + xScale = 2.0 / (leftTan + rightTan), + yScale = 2.0 / (upTan + downTan); + + out[0] = xScale; + out[1] = 0.0; + out[2] = 0.0; + out[3] = 0.0; + out[4] = 0.0; + out[5] = yScale; + out[6] = 0.0; + out[7] = 0.0; + out[8] = -((leftTan - rightTan) * xScale * 0.5); + out[9] = ((upTan - downTan) * yScale * 0.5); + out[10] = far / (near - far); + out[11] = -1.0; + out[12] = 0.0; + out[13] = 0.0; + out[14] = (far * near) / (near - far); + out[15] = 0.0; + return out; + } + + /** + * Generates a orthogonal projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} left Left bound of the frustum + * @param {number} right Right bound of the frustum + * @param {number} bottom Bottom bound of the frustum + * @param {number} top Top bound of the frustum + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + mat4.ortho = function (out, left, right, bottom, top, near, far) { + var lr = 1 / (left - right), + bt = 1 / (bottom - top), + nf = 1 / (near - far); + out[0] = -2 * lr; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = -2 * bt; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 2 * nf; + out[11] = 0; + out[12] = (left + right) * lr; + out[13] = (top + bottom) * bt; + out[14] = (far + near) * nf; + out[15] = 1; + return out; + }; + + /** + * Generates a look-at matrix with the given eye position, focal point, and up axis + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ + mat4.lookAt = function (out, eye, center, up) { + var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, + eyex = eye[0], + eyey = eye[1], + eyez = eye[2], + upx = up[0], + upy = up[1], + upz = up[2], + centerx = center[0], + centery = center[1], + centerz = center[2]; + + if (Math.abs(eyex - centerx) < glMatrix.EPSILON && + Math.abs(eyey - centery) < glMatrix.EPSILON && + Math.abs(eyez - centerz) < glMatrix.EPSILON) { + return mat4.identity(out); + } + + z0 = eyex - centerx; + z1 = eyey - centery; + z2 = eyez - centerz; + + len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + z0 *= len; + z1 *= len; + z2 *= len; + + x0 = upy * z2 - upz * z1; + x1 = upz * z0 - upx * z2; + x2 = upx * z1 - upy * z0; + len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (!len) { + x0 = 0; + x1 = 0; + x2 = 0; + } else { + len = 1 / len; + x0 *= len; + x1 *= len; + x2 *= len; + } + + y0 = z1 * x2 - z2 * x1; + y1 = z2 * x0 - z0 * x2; + y2 = z0 * x1 - z1 * x0; + + len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (!len) { + y0 = 0; + y1 = 0; + y2 = 0; + } else { + len = 1 / len; + y0 *= len; + y1 *= len; + y2 *= len; + } + + out[0] = x0; + out[1] = y0; + out[2] = z0; + out[3] = 0; + out[4] = x1; + out[5] = y1; + out[6] = z1; + out[7] = 0; + out[8] = x2; + out[9] = y2; + out[10] = z2; + out[11] = 0; + out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); + out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); + out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); + out[15] = 1; + + return out; + }; + + /** + * Returns a string representation of a mat4 + * + * @param {mat4} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ + mat4.str = function (a) { + 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] + ')'; + }; + + /** + * Returns Frobenius norm of a mat4 + * + * @param {mat4} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + mat4.frob = function (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) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) + }; + + + module.exports = mat4; + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + var mat3 = __webpack_require__(4); + var vec3 = __webpack_require__(7); + var vec4 = __webpack_require__(8); + + /** + * @class Quaternion + * @name quat + */ + var quat = {}; + + /** + * Creates a new identity quat + * + * @returns {quat} a new quaternion + */ + quat.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Sets a quaternion to represent the shortest rotation from one + * vector to another. + * + * Both vectors are assumed to be unit length. + * + * @param {quat} out the receiving quaternion. + * @param {vec3} a the initial vector + * @param {vec3} b the destination vector + * @returns {quat} out + */ + quat.rotationTo = (function() { + var tmpvec3 = vec3.create(); + var xUnitVec3 = vec3.fromValues(1,0,0); + var yUnitVec3 = vec3.fromValues(0,1,0); + + return function(out, a, b) { + var dot = vec3.dot(a, b); + if (dot < -0.999999) { + vec3.cross(tmpvec3, xUnitVec3, a); + if (vec3.length(tmpvec3) < 0.000001) + vec3.cross(tmpvec3, yUnitVec3, a); + vec3.normalize(tmpvec3, tmpvec3); + quat.setAxisAngle(out, tmpvec3, Math.PI); + return out; + } else if (dot > 0.999999) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + } else { + vec3.cross(tmpvec3, a, b); + out[0] = tmpvec3[0]; + out[1] = tmpvec3[1]; + out[2] = tmpvec3[2]; + out[3] = 1 + dot; + return quat.normalize(out, out); + } + }; + })(); + + /** + * Sets the specified quaternion with values corresponding to the given + * axes. Each axis is a vec3 and is expected to be unit length and + * perpendicular to all other specified axes. + * + * @param {vec3} view the vector representing the viewing direction + * @param {vec3} right the vector representing the local "right" direction + * @param {vec3} up the vector representing the local "up" direction + * @returns {quat} out + */ + quat.setAxes = (function() { + var matr = mat3.create(); + + return function(out, view, right, up) { + matr[0] = right[0]; + matr[3] = right[1]; + matr[6] = right[2]; + + matr[1] = up[0]; + matr[4] = up[1]; + matr[7] = up[2]; + + matr[2] = -view[0]; + matr[5] = -view[1]; + matr[8] = -view[2]; + + return quat.normalize(out, quat.fromMat3(out, matr)); + }; + })(); + + /** + * Creates a new quat initialized with values from an existing quaternion + * + * @param {quat} a quaternion to clone + * @returns {quat} a new quaternion + * @function + */ + quat.clone = vec4.clone; + + /** + * Creates a new quat initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} a new quaternion + * @function + */ + quat.fromValues = vec4.fromValues; + + /** + * Copy the values from one quat to another + * + * @param {quat} out the receiving quaternion + * @param {quat} a the source quaternion + * @returns {quat} out + * @function + */ + quat.copy = vec4.copy; + + /** + * Set the components of a quat to the given values + * + * @param {quat} out the receiving quaternion + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} out + * @function + */ + quat.set = vec4.set; + + /** + * Set a quat to the identity quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ + quat.identity = function(out) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + }; + + /** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * + * @param {quat} out the receiving quaternion + * @param {vec3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @returns {quat} out + **/ + quat.setAxisAngle = function(out, axis, rad) { + rad = rad * 0.5; + var s = Math.sin(rad); + out[0] = s * axis[0]; + out[1] = s * axis[1]; + out[2] = s * axis[2]; + out[3] = Math.cos(rad); + return out; + }; + + /** + * Adds two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + * @function + */ + quat.add = vec4.add; + + /** + * Multiplies two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + */ + quat.multiply = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + out[0] = ax * bw + aw * bx + ay * bz - az * by; + out[1] = ay * bw + aw * by + az * bx - ax * bz; + out[2] = az * bw + aw * bz + ax * by - ay * bx; + out[3] = aw * bw - ax * bx - ay * by - az * bz; + return out; + }; + + /** + * Alias for {@link quat.multiply} + * @function + */ + quat.mul = quat.multiply; + + /** + * Scales a quat by a scalar number + * + * @param {quat} out the receiving vector + * @param {quat} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {quat} out + * @function + */ + quat.scale = vec4.scale; + + /** + * Rotates a quaternion by the given angle about the X axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateX = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + aw * bx; + out[1] = ay * bw + az * bx; + out[2] = az * bw - ay * bx; + out[3] = aw * bw - ax * bx; + return out; + }; + + /** + * Rotates a quaternion by the given angle about the Y axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateY = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + by = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw - az * by; + out[1] = ay * bw + aw * by; + out[2] = az * bw + ax * by; + out[3] = aw * bw - ay * by; + return out; + }; + + /** + * Rotates a quaternion by the given angle about the Z axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + quat.rotateZ = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bz = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + ay * bz; + out[1] = ay * bw - ax * bz; + out[2] = az * bw + aw * bz; + out[3] = aw * bw - az * bz; + return out; + }; + + /** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate W component of + * @returns {quat} out + */ + quat.calculateW = function (out, a) { + var x = a[0], y = a[1], z = a[2]; + + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + return out; + }; + + /** + * Calculates the dot product of two quat's + * + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {Number} dot product of a and b + * @function + */ + quat.dot = vec4.dot; + + /** + * Performs a linear interpolation between two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + * @function + */ + quat.lerp = vec4.lerp; + + /** + * Performs a spherical linear interpolation between two quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + */ + quat.slerp = function (out, a, b, t) { + // benchmarks: + // http://jsperf.com/quaternion-slerp-implementations + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + var omega, cosom, sinom, scale0, scale1; + + // calc cosine + cosom = ax * bx + ay * by + az * bz + aw * bw; + // adjust signs (if necessary) + if ( cosom < 0.0 ) { + cosom = -cosom; + bx = - bx; + by = - by; + bz = - bz; + bw = - bw; + } + // calculate coefficients + if ( (1.0 - cosom) > 0.000001 ) { + // standard case (slerp) + omega = Math.acos(cosom); + sinom = Math.sin(omega); + scale0 = Math.sin((1.0 - t) * omega) / sinom; + scale1 = Math.sin(t * omega) / sinom; + } else { + // "from" and "to" quaternions are very close + // ... so we can do a linear interpolation + scale0 = 1.0 - t; + scale1 = t; + } + // calculate final values + out[0] = scale0 * ax + scale1 * bx; + out[1] = scale0 * ay + scale1 * by; + out[2] = scale0 * az + scale1 * bz; + out[3] = scale0 * aw + scale1 * bw; + + return out; + }; + + /** + * Performs a spherical linear interpolation with two control points + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {quat} c the third operand + * @param {quat} d the fourth operand + * @param {Number} t interpolation amount + * @returns {quat} out + */ + quat.sqlerp = (function () { + var temp1 = quat.create(); + var temp2 = quat.create(); + + return function (out, a, b, c, d, t) { + quat.slerp(temp1, a, d, t); + quat.slerp(temp2, b, c, t); + quat.slerp(out, temp1, temp2, 2 * t * (1 - t)); + + return out; + }; + }()); + + /** + * Calculates the inverse of a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate inverse of + * @returns {quat} out + */ + quat.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, + invDot = dot ? 1.0/dot : 0; + + // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 + + out[0] = -a0*invDot; + out[1] = -a1*invDot; + out[2] = -a2*invDot; + out[3] = a3*invDot; + return out; + }; + + /** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate conjugate of + * @returns {quat} out + */ + quat.conjugate = function (out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Calculates the length of a quat + * + * @param {quat} a vector to calculate length of + * @returns {Number} length of a + * @function + */ + quat.length = vec4.length; + + /** + * Alias for {@link quat.length} + * @function + */ + quat.len = quat.length; + + /** + * Calculates the squared length of a quat + * + * @param {quat} a vector to calculate squared length of + * @returns {Number} squared length of a + * @function + */ + quat.squaredLength = vec4.squaredLength; + + /** + * Alias for {@link quat.squaredLength} + * @function + */ + quat.sqrLen = quat.squaredLength; + + /** + * Normalize a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quaternion to normalize + * @returns {quat} out + * @function + */ + quat.normalize = vec4.normalize; + + /** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {quat} out the receiving quaternion + * @param {mat3} m rotation matrix + * @returns {quat} out + * @function + */ + quat.fromMat3 = function(out, m) { + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + var fTrace = m[0] + m[4] + m[8]; + var fRoot; + + if ( fTrace > 0.0 ) { + // |w| > 1/2, may as well choose w > 1/2 + fRoot = Math.sqrt(fTrace + 1.0); // 2w + out[3] = 0.5 * fRoot; + fRoot = 0.5/fRoot; // 1/(4w) + out[0] = (m[5]-m[7])*fRoot; + out[1] = (m[6]-m[2])*fRoot; + out[2] = (m[1]-m[3])*fRoot; + } else { + // |w| <= 1/2 + var i = 0; + if ( m[4] > m[0] ) + i = 1; + if ( m[8] > m[i*3+i] ) + i = 2; + var j = (i+1)%3; + var k = (i+2)%3; + + fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); + out[i] = 0.5 * fRoot; + fRoot = 0.5 / fRoot; + out[3] = (m[j*3+k] - m[k*3+j]) * fRoot; + out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; + out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; + } + + return out; + }; + + /** + * Returns a string representation of a quatenion + * + * @param {quat} vec vector to represent as a string + * @returns {String} string representation of the vector + */ + quat.str = function (a) { + return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + module.exports = quat; + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 3 Dimensional Vector + * @name vec3 + */ + var vec3 = {}; + + /** + * Creates a new, empty vec3 + * + * @returns {vec3} a new 3D vector + */ + vec3.create = function() { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = 0; + out[1] = 0; + out[2] = 0; + return out; + }; + + /** + * Creates a new vec3 initialized with values from an existing vector + * + * @param {vec3} a vector to clone + * @returns {vec3} a new 3D vector + */ + vec3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + }; + + /** + * Creates a new vec3 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} a new 3D vector + */ + vec3.fromValues = function(x, y, z) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = x; + out[1] = y; + out[2] = z; + return out; + }; + + /** + * Copy the values from one vec3 to another + * + * @param {vec3} out the receiving vector + * @param {vec3} a the source vector + * @returns {vec3} out + */ + vec3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + }; + + /** + * Set the components of a vec3 to the given values + * + * @param {vec3} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} out + */ + vec3.set = function(out, x, y, z) { + out[0] = x; + out[1] = y; + out[2] = z; + return out; + }; + + /** + * Adds two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + return out; + }; + + /** + * Alias for {@link vec3.subtract} + * @function + */ + vec3.sub = vec3.subtract; + + /** + * Multiplies two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + return out; + }; + + /** + * Alias for {@link vec3.multiply} + * @function + */ + vec3.mul = vec3.multiply; + + /** + * Divides two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + return out; + }; + + /** + * Alias for {@link vec3.divide} + * @function + */ + vec3.div = vec3.divide; + + /** + * Returns the minimum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + return out; + }; + + /** + * Returns the maximum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + return out; + }; + + /** + * Scales a vec3 by a scalar number + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec3} out + */ + vec3.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + return out; + }; + + /** + * Adds two vec3's after scaling the second operand by a scalar value + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec3} out + */ + vec3.scaleAndAdd = function(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); + return out; + }; + + /** + * Calculates the euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} distance between a and b + */ + vec3.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return Math.sqrt(x*x + y*y + z*z); + }; + + /** + * Alias for {@link vec3.distance} + * @function + */ + vec3.dist = vec3.distance; + + /** + * Calculates the squared euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} squared distance between a and b + */ + vec3.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return x*x + y*y + z*z; + }; + + /** + * Alias for {@link vec3.squaredDistance} + * @function + */ + vec3.sqrDist = vec3.squaredDistance; + + /** + * Calculates the length of a vec3 + * + * @param {vec3} a vector to calculate length of + * @returns {Number} length of a + */ + vec3.length = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return Math.sqrt(x*x + y*y + z*z); + }; + + /** + * Alias for {@link vec3.length} + * @function + */ + vec3.len = vec3.length; + + /** + * Calculates the squared length of a vec3 + * + * @param {vec3} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec3.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return x*x + y*y + z*z; + }; + + /** + * Alias for {@link vec3.squaredLength} + * @function + */ + vec3.sqrLen = vec3.squaredLength; + + /** + * Negates the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to negate + * @returns {vec3} out + */ + vec3.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + return out; + }; + + /** + * Returns the inverse of the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to invert + * @returns {vec3} out + */ + vec3.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + return out; + }; + + /** + * Normalize a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to normalize + * @returns {vec3} out + */ + vec3.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2]; + var len = x*x + y*y + z*z; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} dot product of a and b + */ + vec3.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + }; + + /** + * Computes the cross product of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + vec3.cross = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], + bx = b[0], by = b[1], bz = b[2]; + + out[0] = ay * bz - az * by; + out[1] = az * bx - ax * bz; + out[2] = ax * by - ay * bx; + return out; + }; + + /** + * Performs a linear interpolation between two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + return out; + }; + + /** + * Performs a hermite interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.hermite = function (out, a, b, c, d, t) { + var factorTimes2 = t * t, + factor1 = factorTimes2 * (2 * t - 3) + 1, + factor2 = factorTimes2 * (t - 2) + t, + factor3 = factorTimes2 * (t - 1), + factor4 = factorTimes2 * (3 - 2 * t); + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; + }; + + /** + * Performs a bezier interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ + vec3.bezier = function (out, a, b, c, d, t) { + var inverseFactor = 1 - t, + inverseFactorTimesTwo = inverseFactor * inverseFactor, + factorTimes2 = t * t, + factor1 = inverseFactorTimesTwo * inverseFactor, + factor2 = 3 * t * inverseFactorTimesTwo, + factor3 = 3 * factorTimes2 * inverseFactor, + factor4 = factorTimes2 * t; + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec3} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec3} out + */ + vec3.random = function (out, scale) { + scale = scale || 1.0; + + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + var z = (glMatrix.RANDOM() * 2.0) - 1.0; + var zScale = Math.sqrt(1.0-z*z) * scale; + + out[0] = Math.cos(r) * zScale; + out[1] = Math.sin(r) * zScale; + out[2] = z * scale; + return out; + }; + + /** + * Transforms the vec3 with a mat4. + * 4th vector component is implicitly '1' + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec3} out + */ + vec3.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], + w = m[3] * x + m[7] * y + m[11] * z + m[15]; + w = w || 1.0; + out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; + out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; + out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; + return out; + }; + + /** + * Transforms the vec3 with a mat3. + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m the 3x3 matrix to transform with + * @returns {vec3} out + */ + vec3.transformMat3 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2]; + out[0] = x * m[0] + y * m[3] + z * m[6]; + out[1] = x * m[1] + y * m[4] + z * m[7]; + out[2] = x * m[2] + y * m[5] + z * m[8]; + return out; + }; + + /** + * Transforms the vec3 with a quat + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec3} out + */ + vec3.transformQuat = function(out, a, q) { + // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations + + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + return out; + }; + + /** + * Rotate a 3D vector around the x-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ + vec3.rotateX = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]; + r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c); + r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; + }; + + /** + * Rotate a 3D vector around the y-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ + vec3.rotateY = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c); + r[1] = p[1]; + r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; + }; + + /** + * Rotate a 3D vector around the z-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ + vec3.rotateZ = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c); + r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c); + r[2] = p[2]; + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; + }; + + /** + * Perform some operation over an array of vec3s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + vec3.forEach = (function() { + var vec = vec3.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 3; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; + } + + return a; + }; + })(); + + /** + * Get the angle between two 3D vectors + * @param {vec3} a The first operand + * @param {vec3} b The second operand + * @returns {Number} The angle in radians + */ + vec3.angle = function(a, b) { + + var tempA = vec3.fromValues(a[0], a[1], a[2]); + var tempB = vec3.fromValues(b[0], b[1], b[2]); + + vec3.normalize(tempA, tempA); + vec3.normalize(tempB, tempB); + + var cosine = vec3.dot(tempA, tempB); + + if(cosine > 1.0){ + return 0; + } else { + return Math.acos(cosine); + } + }; + + /** + * Returns a string representation of a vector + * + * @param {vec3} vec vector to represent as a string + * @returns {String} string representation of the vector + */ + vec3.str = function (a) { + return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; + }; + + module.exports = vec3; + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 4 Dimensional Vector + * @name vec4 + */ + var vec4 = {}; + + /** + * Creates a new, empty vec4 + * + * @returns {vec4} a new 4D vector + */ + vec4.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + return out; + }; + + /** + * Creates a new vec4 initialized with values from an existing vector + * + * @param {vec4} a vector to clone + * @returns {vec4} a new 4D vector + */ + vec4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Creates a new vec4 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} a new 4D vector + */ + vec4.fromValues = function(x, y, z, w) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + }; + + /** + * Copy the values from one vec4 to another + * + * @param {vec4} out the receiving vector + * @param {vec4} a the source vector + * @returns {vec4} out + */ + vec4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + }; + + /** + * Set the components of a vec4 to the given values + * + * @param {vec4} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} out + */ + vec4.set = function(out, x, y, z, w) { + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + }; + + /** + * Adds two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.add = function(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]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.subtract = function(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]; + return out; + }; + + /** + * Alias for {@link vec4.subtract} + * @function + */ + vec4.sub = vec4.subtract; + + /** + * Multiplies two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.multiply = function(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]; + return out; + }; + + /** + * Alias for {@link vec4.multiply} + * @function + */ + vec4.mul = vec4.multiply; + + /** + * Divides two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.divide = function(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]; + return out; + }; + + /** + * Alias for {@link vec4.divide} + * @function + */ + vec4.div = vec4.divide; + + /** + * Returns the minimum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + out[3] = Math.min(a[3], b[3]); + return out; + }; + + /** + * Returns the maximum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + vec4.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + out[3] = Math.max(a[3], b[3]); + return out; + }; + + /** + * Scales a vec4 by a scalar number + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec4} out + */ + vec4.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; + }; + + /** + * Adds two vec4's after scaling the second operand by a scalar value + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec4} out + */ + vec4.scaleAndAdd = function(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); + return out; + }; + + /** + * Calculates the euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} distance between a and b + */ + vec4.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); + }; + + /** + * Alias for {@link vec4.distance} + * @function + */ + vec4.dist = vec4.distance; + + /** + * Calculates the squared euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} squared distance between a and b + */ + vec4.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return x*x + y*y + z*z + w*w; + }; + + /** + * Alias for {@link vec4.squaredDistance} + * @function + */ + vec4.sqrDist = vec4.squaredDistance; + + /** + * Calculates the length of a vec4 + * + * @param {vec4} a vector to calculate length of + * @returns {Number} length of a + */ + vec4.length = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); + }; + + /** + * Alias for {@link vec4.length} + * @function + */ + vec4.len = vec4.length; + + /** + * Calculates the squared length of a vec4 + * + * @param {vec4} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec4.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return x*x + y*y + z*z + w*w; + }; + + /** + * Alias for {@link vec4.squaredLength} + * @function + */ + vec4.sqrLen = vec4.squaredLength; + + /** + * Negates the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to negate + * @returns {vec4} out + */ + vec4.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = -a[3]; + return out; + }; + + /** + * Returns the inverse of the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to invert + * @returns {vec4} out + */ + vec4.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + out[3] = 1.0 / a[3]; + return out; + }; + + /** + * Normalize a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to normalize + * @returns {vec4} out + */ + vec4.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + var len = x*x + y*y + z*z + w*w; + if (len > 0) { + len = 1 / Math.sqrt(len); + out[0] = x * len; + out[1] = y * len; + out[2] = z * len; + out[3] = w * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} dot product of a and b + */ + vec4.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + }; + + /** + * Performs a linear interpolation between two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec4} out + */ + vec4.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + out[3] = aw + t * (b[3] - aw); + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec4} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec4} out + */ + vec4.random = function (out, scale) { + scale = scale || 1.0; + + //TODO: This is a pretty awful way of doing this. Find something better. + out[0] = glMatrix.RANDOM(); + out[1] = glMatrix.RANDOM(); + out[2] = glMatrix.RANDOM(); + out[3] = glMatrix.RANDOM(); + vec4.normalize(out, out); + vec4.scale(out, out, scale); + return out; + }; + + /** + * Transforms the vec4 with a mat4. + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec4} out + */ + vec4.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], w = a[3]; + out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; + out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; + out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; + out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; + return out; + }; + + /** + * Transforms the vec4 with a quat + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec4} out + */ + vec4.transformQuat = function(out, a, q) { + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + out[3] = a[3]; + return out; + }; + + /** + * Perform some operation over an array of vec4s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + vec4.forEach = (function() { + var vec = vec4.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 4; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; + } + + return a; + }; + })(); + + /** + * Returns a string representation of a vector + * + * @param {vec4} vec vector to represent as a string + * @returns {String} string representation of the vector + */ + vec4.str = function (a) { + return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + }; + + module.exports = vec4; + + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + /* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + + var glMatrix = __webpack_require__(1); + + /** + * @class 2 Dimensional Vector + * @name vec2 + */ + var vec2 = {}; + + /** + * Creates a new, empty vec2 + * + * @returns {vec2} a new 2D vector + */ + vec2.create = function() { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = 0; + out[1] = 0; + return out; + }; + + /** + * Creates a new vec2 initialized with values from an existing vector + * + * @param {vec2} a vector to clone + * @returns {vec2} a new 2D vector + */ + vec2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = a[0]; + out[1] = a[1]; + return out; + }; + + /** + * Creates a new vec2 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} a new 2D vector + */ + vec2.fromValues = function(x, y) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = x; + out[1] = y; + return out; + }; + + /** + * Copy the values from one vec2 to another + * + * @param {vec2} out the receiving vector + * @param {vec2} a the source vector + * @returns {vec2} out + */ + vec2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + return out; + }; + + /** + * Set the components of a vec2 to the given values + * + * @param {vec2} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} out + */ + vec2.set = function(out, x, y) { + out[0] = x; + out[1] = y; + return out; + }; + + /** + * Adds two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + return out; + }; + + /** + * Subtracts vector b from vector a + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + return out; + }; + + /** + * Alias for {@link vec2.subtract} + * @function + */ + vec2.sub = vec2.subtract; + + /** + * Multiplies two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + return out; + }; + + /** + * Alias for {@link vec2.multiply} + * @function + */ + vec2.mul = vec2.multiply; + + /** + * Divides two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + return out; + }; + + /** + * Alias for {@link vec2.divide} + * @function + */ + vec2.div = vec2.divide; + + /** + * Returns the minimum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + return out; + }; + + /** + * Returns the maximum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ + vec2.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + return out; + }; + + /** + * Scales a vec2 by a scalar number + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec2} out + */ + vec2.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + return out; + }; + + /** + * Adds two vec2's after scaling the second operand by a scalar value + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec2} out + */ + vec2.scaleAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + return out; + }; + + /** + * Calculates the euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} distance between a and b + */ + vec2.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return Math.sqrt(x*x + y*y); + }; + + /** + * Alias for {@link vec2.distance} + * @function + */ + vec2.dist = vec2.distance; + + /** + * Calculates the squared euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} squared distance between a and b + */ + vec2.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return x*x + y*y; + }; + + /** + * Alias for {@link vec2.squaredDistance} + * @function + */ + vec2.sqrDist = vec2.squaredDistance; + + /** + * Calculates the length of a vec2 + * + * @param {vec2} a vector to calculate length of + * @returns {Number} length of a + */ + vec2.length = function (a) { + var x = a[0], + y = a[1]; + return Math.sqrt(x*x + y*y); + }; + + /** + * Alias for {@link vec2.length} + * @function + */ + vec2.len = vec2.length; + + /** + * Calculates the squared length of a vec2 + * + * @param {vec2} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + vec2.squaredLength = function (a) { + var x = a[0], + y = a[1]; + return x*x + y*y; + }; + + /** + * Alias for {@link vec2.squaredLength} + * @function + */ + vec2.sqrLen = vec2.squaredLength; + + /** + * Negates the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to negate + * @returns {vec2} out + */ + vec2.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + return out; + }; + + /** + * Returns the inverse of the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to invert + * @returns {vec2} out + */ + vec2.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + return out; + }; + + /** + * Normalize a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to normalize + * @returns {vec2} out + */ + vec2.normalize = function(out, a) { + var x = a[0], + y = a[1]; + var len = x*x + y*y; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + } + return out; + }; + + /** + * Calculates the dot product of two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} dot product of a and b + */ + vec2.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1]; + }; + + /** + * Computes the cross product of two vec2's + * Note that the cross product must by definition produce a 3D vector + * + * @param {vec3} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec3} out + */ + vec2.cross = function(out, a, b) { + var z = a[0] * b[1] - a[1] * b[0]; + out[0] = out[1] = 0; + out[2] = z; + return out; + }; + + /** + * Performs a linear interpolation between two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec2} out + */ + vec2.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + return out; + }; + + /** + * Generates a random vector with the given scale + * + * @param {vec2} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec2} out + */ + vec2.random = function (out, scale) { + scale = scale || 1.0; + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + out[0] = Math.cos(r) * scale; + out[1] = Math.sin(r) * scale; + return out; + }; + + /** + * Transforms the vec2 with a mat2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat2 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y; + out[1] = m[1] * x + m[3] * y; + return out; + }; + + /** + * Transforms the vec2 with a mat2d + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2d} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat2d = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y + m[4]; + out[1] = m[1] * x + m[3] * y + m[5]; + return out; + }; + + /** + * Transforms the vec2 with a mat3 + * 3rd vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat3} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat3 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[3] * y + m[6]; + out[1] = m[1] * x + m[4] * y + m[7]; + return out; + }; + + /** + * Transforms the vec2 with a mat4 + * 3rd vector component is implicitly '0' + * 4th vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec2} out + */ + vec2.transformMat4 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[4] * y + m[12]; + out[1] = m[1] * x + m[5] * y + m[13]; + return out; + }; + + /** + * Perform some operation over an array of vec2s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + vec2.forEach = (function() { + var vec = vec2.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 2; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; + } + + return a; + }; + })(); + + /** + * Returns a string representation of a vector + * + * @param {vec2} vec vector to represent as a string + * @returns {String} string representation of the vector + */ + vec2.str = function (a) { + return 'vec2(' + a[0] + ', ' + a[1] + ')'; + }; + + module.exports = vec2; + + +/***/ } +/******/ ]) +}); +;
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allclasses.tmpl b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allclasses.tmpl new file mode 100644 index 00000000000..e89da024d82 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allclasses.tmpl @@ -0,0 +1,14 @@ +<div align="center">{+new Link().toFile("index.html").withText("Class Index")+} +| {+new Link().toFile("files.html").withText("File Index")+}</div> +<hr /> +<h2>Classes</h2> +<ul class="classList"> + <for each="thisClass" in="data"> + <li>{! + if (thisClass.alias != "_global_") { + output += new Link().toClass(thisClass.alias); + } + !}</li> + </for> +</ul> +<hr />
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allfiles.tmpl b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allfiles.tmpl new file mode 100644 index 00000000000..c6e40c9a4fe --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/allfiles.tmpl @@ -0,0 +1,65 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset={+IO.encoding+}" /> + {! Link.base = ""; /* all generated links will be relative to this */ !} + <title>glMatrix - File Index</title> + <meta name="generator" content="JsDoc Toolkit" /> + + <style type="text/css"> + {+include("static/default.css")+} + </style> + </head> + + <body> + {+include("static/header.html")+} + + <div class="wrapper"> + + <header id="index"> + {+publish.classesIndex+} + </header> + + <section id="content"> + <h1 class="classTitle">File Index</h1> + + <for each="item" in="data"> + <div> + <h2>{+new Link().toSrc(item.alias).withText(item.name)+}</h2> + <if test="item.desc">{+resolveLinks(item.desc)+}</if> + <dl> + <if test="item.author"> + <dt class="heading">Author:</dt> + <dd>{+item.author+}</dd> + </if> + <if test="item.version"> + <dt class="heading">Version:</dt> + <dd>{+item.version+}</dd> + </if> + {! var locations = item.comment.getTag('location').map(function($){return $.toString().replace(/(^\$ ?| ?\$$)/g, '').replace(/^HeadURL: https:/g, 'http:');}) !} + <if test="locations.length"> + <dt class="heading">Location:</dt> + <for each="location" in="locations"> + <dd><a href="{+location+}">{+location+}</a></dd> + </for> + </if> + </dl> + </div> + <hr /> + </for> + + </section> + + <footer> + <small> + <if test="JSDOC.opt.D.copyright">©{+JSDOC.opt.D.copyright+}<br /></if> + Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blank">JsDoc Toolkit</a> {+JSDOC.VERSION+} on {+new Date()+} + <br/><br/> + Theme based on Github Pages template by <a href="https://github.com/orderedlist">orderedlist</a> + </small> + </footer> + + </div> + </body> +</html>
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/class.tmpl b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/class.tmpl new file mode 100644 index 00000000000..cb1d2b0f3d6 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/class.tmpl @@ -0,0 +1,340 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset={+IO.encoding+}" /> + <meta name="generator" content="JsDoc Toolkit" /> + {! Link.base = "../"; /* all generated links will be relative to this */ !} + <title>glMatrix - {+data.alias+}</title> + + <style type="text/css"> + {+include("static/default.css")+} + </style> + </head> + + <body> +<!-- ============================== header ================================= --> + <!-- begin static/header.html --> + {+include("static/header.html")+} + <!-- end static/header.html --> + + <div class="wrapper"> +<!-- ============================== classes index ============================ --> + <header id="index"> + <!-- begin publish.classesIndex --> + {+publish.classesIndex+} + <!-- end publish.classesIndex --> + </header> + + <section id="content"> +<!-- ============================== class title ============================ --> + <h1 class="classTitle"> + {! + var classType = ""; + + if (data.isBuiltin()) { + classType += "Built-In "; + } + + if (data.isNamespace) { + if (data.is('FUNCTION')) { + classType += "Function "; + } + classType += "Namespace "; + } + else { + classType += "Class "; + } + !} + {+classType+}{+data.alias+} + </h1> + +<!-- ============================== class summary ========================== --> + <p class="description"> + <if test="data.version"><br />Version + {+ data.version +}.<br /> + </if> + <if test="data.augments.length"><br />Extends + {+ + data.augments + .sort() + .map( + function($) { return new Link().toSymbol($); } + ) + .join(", ") + +}.<br /> + </if> + + {+resolveLinks(data.classDesc)+} + + <if test="data.desc"> + <div class="description">{+resolveLinks(summarize(data.desc))+}</div> + </if> + + <if test="!data.isBuiltin()">{# isn't defined in any file #} + <br /><i>Defined in: </i> {+new Link().toSrc(data.srcFile)+}. + </if> + </p> + +<!-- ============================== properties summary ===================== --> + <if test="data.properties.length"> + {! var ownProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace}).sort(makeSortby("name")); !} + <if test="ownProperties.length"> + <table class="summaryTable" cellspacing="0" summary="A summary of the fields documented in the class {+data.alias+}."> + <caption>Field Summary</caption> + <thead> + <tr> + <th scope="col">Field Attributes</th> + <th scope="col">Field Name and Description</th> + </tr> + </thead> + <tbody> + <for each="member" in="ownProperties"> + <tr> + <td class="attributes">{! + if (member.isPrivate) output += "<private> "; + if (member.isInner) output += "<inner> "; + if (member.isStatic) output += "<static> "; + if (member.isConstant) output += "<constant> "; + !} </td> + <td class="nameDescription"> + <div class="fixedFont"> + <if test="member.isStatic && member.memberOf != '_global_'">{+member.memberOf+}.</if><b>{+new Link().toSymbol(member.alias).withText(member.name)+}</b> + </div> + <div class="description">{+resolveLinks(summarize(member.desc))+}</div> + </td> + </tr> + </for> + </tbody> + </table> + </if> + + <if test="data.inheritsFrom.length"> + <dl class="inheritsList"> + {! + var borrowedMembers = data.properties.filter(function($) {return $.memberOf != data.alias}); + + var contributers = []; + borrowedMembers.map(function($) {if (contributers.indexOf($.memberOf) < 0) contributers.push($.memberOf)}); + for (var i = 0, l = contributers.length; i < l; i++) { + output += + "<dt>Fields borrowed from class "+new Link().toSymbol(contributers[i])+": </dt>" + + + "<dd>" + + borrowedMembers + .filter( + function($) { return $.memberOf == contributers[i] } + ) + .sort(makeSortby("name")) + .map( + function($) { return new Link().toSymbol($.alias).withText($.name) } + ) + .join(", ") + + + "</dd>"; + } + !} + </dl> + </if> + </if> + +<!-- ============================== methods summary ======================== --> + <if test="data.methods.length"> + {! var ownMethods = data.methods.filter(function($){return $.memberOf == data.alias && !$.isNamespace}).sort(makeSortby("name")); !} + <if test="ownMethods.length"> + <h2>Methods</h2> + <table class="summaryTable" cellspacing="0" summary="A summary of the methods documented in the class {+data.alias+}."> + <tbody> + <for each="member" in="ownMethods"> + <tr> + <td class="nameDescription"> + <code class="fixedFont"><if test="member.isStatic && member.memberOf != '_global_'">{+member.memberOf+}.</if><b>{+new Link().toSymbol(member.alias).withText(member.name.replace(/\^\d+$/, ''))+}</b>{+makeSignature(member.params)+} + </code> + <div class="description">{+resolveLinks(summarize(member.desc))+}</div> + </td> + </tr> + </for> + </tbody> + </table> + </if> + </if> + +<!-- ============================== field details ========================== --> + <if test="defined(ownProperties) && ownProperties.length"> + <div class="sectionTitle"> + Field Detail + </div> + <for each="member" in="ownProperties"> + <a name="{+Link.symbolNameToLinkName(member)+}"> </a> + <div class="fixedFont">{! + if (member.isPrivate) output += "<private> "; + if (member.isInner) output += "<inner> "; + if (member.isStatic) output += "<static> "; + if (member.isConstant) output += "<constant> "; + !} + + <if test="member.type"><span class="light">{{+new Link().toSymbol(member.type)+}}</span></if> + <if test="member.isStatic && member.memberOf != '_global_'"><span class="light">{+member.memberOf+}.</span></if><b>{+member.name+}</b> + + </div> + <div class="description"> + {+resolveLinks(member.desc)+} + <if test="member.srcFile != data.srcFile"> + <br /> + <i>Defined in: </i> {+new Link().toSrc(member.srcFile)+}. + </if> + <if test="member.author"><br /><i>Author: </i>{+member.author+}.</if> + </div> + + <if test="member.example.length"> + <for each="example" in="member.example"> + <pre class="code">{+example+}</pre> + </for> + </if> + + <if test="member.deprecated"> + <dl class="detailList"> + <dt class="heading">Deprecated:</dt> + <dt> + {+ resolveLinks(member.deprecated) +} + </dt> + </dl> + </if> + <if test="member.since"> + <dl class="detailList"> + <dt class="heading">Since:</dt> + <dd>{+ member.since +}</dd> + </dl> + </if> + <if test="member.see.length"> + <dl class="detailList"> + <dt class="heading">See:</dt> + <for each="item" in="member.see"> + <dd>{+ new Link().toSymbol(item) +}</dd> + </for> + </dl> + </if> + <if test="member.defaultValue"> + <dl class="detailList"> + <dt class="heading">Default Value:</dt> + <dd> + {+resolveLinks(member.defaultValue)+} + </dd> + </dl> + </if> + + <if test="!$member_last"><hr /></if> + </for> + </if> + +<!-- ============================== method details ========================= --> + <if test="defined(ownMethods) && ownMethods.length"> + <h2>Method Detail</h2> + <for each="member" in="ownMethods"> + <a name="{+Link.symbolNameToLinkName(member)+}"> </a> + <h3 class="fixedFont"> + <if test="member.type"><span class="light">{{+new Link().toSymbol(member.type)+}}</span></if> + <if test="member.isStatic && member.memberOf != '_global_'"><span class="light">{+member.memberOf+}.</span></if><b>{+member.name.replace(/\^\d+$/, '')+}</b>{+makeSignature(member.params)+} + </h3> + + <div style="margin-left: 1em;"> + <p class="description"> + {+resolveLinks(member.desc)+} + <if test="member.srcFile != data.srcFile"> + <br /> + <i>Defined in: </i> {+new Link().toSrc(member.srcFile)+}. + </if> + <if test="member.author"><br /><i>Author: </i>{+member.author+}.</if> + </p> + + <if test="member.example.length"> + <for each="example" in="member.example"> + <pre class="code">{+example+}</pre> + </for> + </if> + + <if test="member.params.length"> + <dl class="detailList"> + <dt class="heading">Parameters:</dt> + <for each="item" in="member.params"> + <dt> + {+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+}<b>{+item.name+}</b> + <if test="item.isOptional"><i>Optional<if test="item.defaultValue">, Default: {+item.defaultValue+}</if></i></if> + </dt> + <dd>{+resolveLinks(item.desc)+}</dd> + </for> + </dl> + </if> + <if test="member.deprecated"> + <dl class="detailList"> + <dt class="heading">Deprecated:</dt> + <dt> + {+ resolveLinks(member.deprecated) +} + </dt> + </dl> + </if> + <if test="member.since"> + <dl class="detailList"> + <dt class="heading">Since:</dt> + <dd>{+ member.since +}</dd> + </dl> + </dl> + </if> + <if test="member.exceptions.length"> + <dl class="detailList"> + <dt class="heading">Throws:</dt> + <for each="item" in="member.exceptions"> + <dt> + {+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+} <b>{+item.name+}</b> + </dt> + <dd>{+resolveLinks(item.desc)+}</dd> + </for> + </dl> + </if> + <if test="member.returns.length"> + <dl class="detailList"> + <dt class="heading">Returns:</dt> + <for each="item" in="member.returns"> + <dd>{+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+}{+resolveLinks(item.desc)+}</dd> + </for> + </dl> + </if> + <if test="member.requires.length"> + <dl class="detailList"> + <dt class="heading">Requires:</dt> + <for each="item" in="member.requires"> + <dd>{+ resolveLinks(item) +}</dd> + </for> + </dl> + </if> + <if test="member.see.length"> + <dl class="detailList"> + <dt class="heading">See:</dt> + <for each="item" in="member.see"> + <dd>{+ new Link().toSymbol(item) +}</dd> + </for> + </dl> + </if> + + <if test="!$member_last"><hr /></if> + </div> + </for> + </if> + + <hr /> + </section> + + +<!-- ============================== footer ================================= --> + <footer> + <small> + <if test="JSDOC.opt.D.copyright">©{+JSDOC.opt.D.copyright+}<br /></if> + Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blank">JsDoc Toolkit</a> {+JSDOC.VERSION+} on {+new Date()+} + <br/><br/> + Theme based on Github Pages template by <a href="https://github.com/orderedlist">orderedlist</a> + </small> + </footer> + + </div> + </body> +</html> diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/index.tmpl b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/index.tmpl new file mode 100644 index 00000000000..7c92dd40ccd --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/index.tmpl @@ -0,0 +1,52 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset={+IO.encoding+}" /> + + <title>glMatrix - Index</title> + <meta name="generator" content="JsDoc Toolkit" /> + + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> + + <style type="text/css"> + {+include("static/default.css")+} + </style> + </head> + + <body> + {+include("static/header.html")+} + + <div class="wrapper"> + + <header id="index"> + {+publish.classesIndex+} + </header> + + <section id="content"> + <h1 class="classTitle">Class Index</h1> + + <for each="thisClass" in="data"> + <if test="thisClass.alias != '_global_'"> + <div> + <h2>{+(new Link().toSymbol(thisClass.alias))+}</h2> + {+resolveLinks(summarize(thisClass.classDesc))+} + </div> + <hr /> + </if> + </for> + + </section> + + <footer> + <small> + <if test="JSDOC.opt.D.copyright">©{+JSDOC.opt.D.copyright+}<br /></if> + Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blank">JsDoc Toolkit</a> {+JSDOC.VERSION+} on {+new Date()+} + <br/><br/> + Theme based on Github Pages template by <a href="https://github.com/orderedlist">orderedlist</a> + </small> + </footer> + + </div> + </body> +</html>
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/publish.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/publish.js new file mode 100644 index 00000000000..82c20045e94 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/publish.js @@ -0,0 +1,201 @@ +/** Called automatically by JsDoc Toolkit. */ +function publish(symbolSet) { + publish.conf = { // trailing slash expected for dirs + ext: ".html", + outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/", + templatesDir: JSDOC.opt.t || SYS.pwd+"../jsdoc-template/", + symbolsDir: "symbols/", + srcDir: "symbols/src/" + }; + + // is source output is suppressed, just display the links to the source file + if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) { + Link.prototype._makeSrcLink = function(srcFilePath) { + return "<"+srcFilePath+">"; + } + } + + // create the folders and subfolders to hold the output + IO.mkPath((publish.conf.outDir+"symbols/src").split("/")); + + // used to allow Link to check the details of things being linked to + Link.symbolSet = symbolSet; + + // create the required templates + try { + var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl"); + var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl"); + } + catch(e) { + print("Couldn't create the required templates: "+e); + quit(); + } + + // some ustility filters + function hasNoParent($) {return ($.memberOf == "")} + function isaFile($) {return ($.is("FILE"))} + function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)} + + // get an array version of the symbolset, useful for filtering + var symbols = symbolSet.toArray(); + + // create the hilited source code files + var files = JSDOC.opt.srcFiles; + for (var i = 0, l = files.length; i < l; i++) { + var file = files[i]; + var srcDir = publish.conf.outDir + "symbols/src/"; + makeSrcFile(file, srcDir); + } + + // get a list of all the classes in the symbolset + var classes = symbols.filter(isaClass).sort(makeSortby("alias")); + + // create a filemap in which outfiles must be to be named uniquely, ignoring case + if (JSDOC.opt.u) { + var filemapCounts = {}; + Link.filemap = {}; + for (var i = 0, l = classes.length; i < l; i++) { + var lcAlias = classes[i].alias.toLowerCase(); + + if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1; + else filemapCounts[lcAlias]++; + + Link.filemap[classes[i].alias] = + (filemapCounts[lcAlias] > 1)? + lcAlias+"_"+filemapCounts[lcAlias] : lcAlias; + } + } + + // create a class index, displayed in the left-hand column of every class page + Link.base = "../"; + publish.classesIndex = classesTemplate.process(classes); // kept in memory + + // create each of the class pages + for (var i = 0, l = classes.length; i < l; i++) { + var symbol = classes[i]; + + symbol.events = symbol.getEvents(); // 1 order matters + symbol.methods = symbol.getMethods(); // 2 + + Link.currentSymbol= symbol; + var output = ""; + output = classTemplate.process(symbol); + + IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output); + } + + // regenerate the index with different relative links, used in the index pages + Link.base = ""; + publish.classesIndex = classesTemplate.process(classes); + + // create the class index page + try { + var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl"); + } + catch(e) { print(e.message); quit(); } + + var classesIndex = classesindexTemplate.process(classes); + IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex); + classesindexTemplate = classesIndex = classes = null; + + // create the file index page + try { + var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl"); + } + catch(e) { print(e.message); quit(); } + + var documentedFiles = symbols.filter(isaFile); // files that have file-level docs + var allFiles = []; // not all files have file-level docs, but we need to list every one + + for (var i = 0; i < files.length; i++) { + allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */"))); + } + + for (var i = 0; i < documentedFiles.length; i++) { + var offset = files.indexOf(documentedFiles[i].alias); + allFiles[offset] = documentedFiles[i]; + } + + allFiles = allFiles.sort(makeSortby("name")); + + // output the file index page + var filesIndex = fileindexTemplate.process(allFiles); + IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex); + fileindexTemplate = filesIndex = files = null; +} + + +/** Just the first sentence (up to a full stop). Should not break on dotted variable names. */ +function summarize(desc) { + if (typeof desc != "undefined") + return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i)? RegExp.$1 : desc; +} + +/** Make a symbol sorter by some attribute. */ +function makeSortby(attribute) { + return function(a, b) { + if (a[attribute] != undefined && b[attribute] != undefined) { + a = a[attribute].toLowerCase(); + b = b[attribute].toLowerCase(); + if (a < b) return -1; + if (a > b) return 1; + return 0; + } + } +} + +/** Pull in the contents of an external file at the given path. */ +function include(path) { + var path = publish.conf.templatesDir+path; + return IO.readFile(path); +} + +/** Turn a raw source file into a code-hilited page in the docs. */ +function makeSrcFile(path, srcDir, name) { + if (JSDOC.opt.s) return; + + if (!name) { + name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_"); + name = name.replace(/\:/g, "_"); + } + + var src = {path: path, name:name, charset: IO.encoding, hilited: ""}; + + if (defined(JSDOC.PluginManager)) { + JSDOC.PluginManager.run("onPublishSrc", src); + } + + if (src.hilited) { + IO.saveFile(srcDir, name+publish.conf.ext, src.hilited); + } +} + +/** Build output for displaying function parameters. */ +function makeSignature(params) { + if (!params) return "()"; + var signature = "(" + + + params.filter( + function($) { + return $.name.indexOf(".") == -1; // don't show config params in signature + } + ).map( + function($) { + return $.name; + } + ).join(", ") + + + ")"; + return signature; +} + +/** Find symbol {@link ...} strings in text and turn into html links */ +function resolveLinks(str, from) { + str = str.replace(/\{@link ([^} ]+) ?\}/gi, + function(match, symbolName) { + return new Link().toSymbol(symbolName); + } + ); + + return str; +} diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/default.css b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/default.css new file mode 100644 index 00000000000..efcf7827133 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/default.css @@ -0,0 +1,428 @@ +/* default.css */ + +/* + +body +{ + font: 12px "Lucida Grande", Tahoma, Arial, Helvetica, sans-serif; + width: 800px; +} + +.header +{ + clear: both; + background-color: #ccc; + padding: 8px; +} + +h1 +{ + font-size: 150%; + font-weight: bold; + padding: 0; + margin: 1em 0 0 .3em; +} + +hr +{ + border: none 0; + border-top: 1px solid #7F8FB1; + height: 1px; +} + +pre.code +{ + display: block; + padding: 8px; + border: 1px dashed #ccc; +} + +#index +{ + margin-top: 24px; + float: left; + width: 160px; + position: absolute; + left: 8px; + background-color: #F3F3F3; + padding: 8px; +} + +#content +{ + margin-left: 190px; + width: 600px; +} + +.classList +{ + list-style-type: none; + padding: 0; + margin: 0 0 0 8px; + font-family: arial, sans-serif; + font-size: 1em; + overflow: auto; +} + +.classList li +{ + padding: 0; + margin: 0 0 8px 0; +} + +.summaryTable { width: 100%; } + +h1.classTitle +{ + font-size:170%; + line-height:130%; +} + +h2 { font-size: 110%; } +caption, div.sectionTitle +{ + background-color: #7F8FB1; + color: #fff; + font-size:130%; + text-align: left; + padding: 2px 6px 2px 6px; + border: 1px #7F8FB1 solid; +} + +div.sectionTitle { margin-bottom: 8px; } +.summaryTable thead { display: none; } + +.summaryTable td +{ + vertical-align: top; + padding: 4px; + border-bottom: 1px #7F8FB1 solid; + border-right: 1px #7F8FB1 solid; + border-left: 1px #7F8FB1 solid; +} + +.summaryTable td.attributes +{ + border-left: 1px #7F8FB1 solid; + width: 140px; + text-align: right; +} + +td.attributes, .fixedFont +{ + line-height: 15px; + color: #002EBE; + font-family: "Courier New",Courier,monospace; + font-size: 13px; +} + +.summaryTable td.nameDescription +{ + text-align: left; + font-size: 13px; + line-height: 15px; +} + +.summaryTable td.nameDescription, .description +{ + line-height: 15px; + padding: 4px; + padding-left: 4px; +} + +.summaryTable { margin-bottom: 8px; } + +ul.inheritsList +{ + list-style: square; + margin-left: 20px; + padding-left: 0; +} + +.detailList { + margin-left: 20px; + line-height: 15px; +} +.detailList dt { margin-left: 20px; } + +.detailList .heading +{ + font-weight: bold; + padding-bottom: 6px; + margin-left: 0; +} + +.light, td.attributes, .light a:link, .light a:visited +{ + color: #777; + font-style: italic; +} + +.fineprint +{ + text-align: right; + font-size: 10px; +} + +*/ + +/* Copied from styles.css generated by Github Pages */ + +@import url(https://fonts.googleapis.com/css?family=Lato:300italic,700italic,300,700); + +body { + padding:50px; + font:14px/1.5 Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + color:#777; + font-weight:300; +} + +h1, h2, h3, h4, h5, h6 { + color:#222; + margin:0 0 20px; +} + +p, ul, ol, table, pre, dl { + margin:0 0 20px; +} + +h1, h2, h3 { + line-height:1.1; +} + +h1 { + font-size:28px; +} + +h2 { + color:#393939; +} + +h3, h4, h5, h6 { + color:#494949; +} + +a { + color:#39c; + font-weight:400; + text-decoration:none; +} + +a small { + font-size:11px; + color:#777; + margin-top:-0.6em; + display:block; +} + +.wrapper { + width:860px; + margin:0 auto; +} + +blockquote { + border-left:1px solid #e5e5e5; + margin:0; + padding:0 0 0 20px; + font-style:italic; +} + +code, pre { + font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal; + color:#333; + font-size:12px; +} + +pre { + padding:8px 15px; + background: #f8f8f8; + border-radius:5px; + border:1px solid #e5e5e5; + overflow-x: auto; +} + +table { + width:100%; + border-collapse:collapse; +} + +th, td { + text-align:left; + padding:5px 10px; + border-bottom:1px solid #e5e5e5; +} + +dt { + color:#444; + font-weight:700; +} + +th { + color:#444; +} + +img { + max-width:100%; +} + +header { + width:270px; + float:left; + position:fixed; +} + +header ul { + list-style:none; + padding:0; + + /*background: #eee; + background: -moz-linear-gradient(top, #f8f8f8 0%, #dddddd 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); + background: -webkit-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: -o-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: -ms-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + + border-radius:5px; + border:1px solid #d2d2d2; + box-shadow:inset #fff 0 1px 0, inset rgba(0,0,0,0.03) 0 -1px 0;*/ + width:270px; +} + +header li { + width:89px; + /*float:left; + border-right:1px solid #d2d2d2; + height:40px;*/ +} + +header ul a { + line-height:1; + font-size:11px; + color:#999; + display:block; + text-align:center; + padding-top:6px; + /*height:40px;*/ +} + +strong { + color:#222; + font-weight:700; +} + +/*header ul li + li { + width:88px; + border-left:1px solid #fff; +} + +header ul li + li + li { + border-right:none; + width:89px; +}*/ + +header ul a strong { + font-size:14px; + display:block; + color:#222; +} + +section { + width:500px; + float:right; + padding-bottom:50px; +} + +small { + font-size:11px; +} + +hr { + border:0; + background:#e5e5e5; + height:1px; + margin:0 0 20px; +} + +footer { + width:270px; + float:left; + position:fixed; + bottom:50px; +} + +@media print, screen and (max-width: 960px) { + + div.wrapper { + width:auto; + margin:0; + } + + header, section, footer { + float:none; + position:static; + width:auto; + } + + header { + /*padding-right:320px;*/ + padding: 0; + } + + section { + border:1px solid #e5e5e5; + border-width:1px 0; + padding:20px 0; + margin:0 0 20px; + } + + header a small { + display:inline; + } + + header ul { + position:static; + height:40px; + width: auto; + } + + header ul li { + float: left; + } +} + +@media print, screen and (max-width: 720px) { + body { + word-wrap:break-word; + } + + header { + padding:0; + } + + header ul, header p.view { + position:static; + } + + pre, code { + word-wrap:normal; + } +} + +@media print, screen and (max-width: 480px) { + body { + padding:15px; + } + + /*header ul { + display:none; + }*/ +} + +@media print { + body { + padding:0.4in; + font-size:12pt; + color:#444; + } +} diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/header.html b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/header.html new file mode 100644 index 00000000000..353b735a4ca --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/header.html @@ -0,0 +1,2 @@ +<div id="header"> +</div>
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/index.html b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/index.html new file mode 100644 index 00000000000..d51d4efaa15 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/static/index.html @@ -0,0 +1,19 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <title>glMatrix Documentation</title> +</head> +<frameset cols="20%,80%"> + <frame src="allclasses-frame.html" name="packageFrame" /> + <frame src="splash.html" name="classFrame" /> + <noframes> + <body> + <p> + This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + </p> + </body> + </noframes> +</frameset> +</html>
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/symbol.tmpl b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/symbol.tmpl new file mode 100644 index 00000000000..f8f4bd1f6f2 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/jsdoc-template/symbol.tmpl @@ -0,0 +1,35 @@ +<symbol alias="{+data.alias+}"> + <name>{+data.name+}</name> + <memberOf>{+data.memberOf+}</memberOf> + <isStatic>{+data.isStatic+}</isStatic> + <isa>{+data.isa+}</isa> + <desc>{+data.desc+}</desc> + <classDesc>{+data.classDesc+}</classDesc> + + <methods><for each="method" in="data.methods"> + <method> + <name>{+method.name+}</name> + <memberOf>{+method.memberOf+}</memberOf> + <isStatic>{+method.isStatic+}</isStatic> + <desc>{+method.desc+}</desc> + <params><for each="param" in="method.params"> + <param> + <type>{+param.type+}</type> + <name>{+param.name+}</name> + <desc>{+param.desc+}</desc> + <defaultValue>{+param.defaultValue+}</defaultValue> + </param></for> + </params> + </method></for> + </methods> + + <properties><for each="property" in="data.properties"> + <property> + <name>{+property.name+}</name> + <memberOf>{+property.memberOf+}</memberOf> + <isStatic>{+property.isStatic+}</isStatic> + <desc>{+property.desc+}</desc> + <type>{+property.type+}</type> + </property></for> + </properties> +</symbol> diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/package.json b/chromium/third_party/catapult/tracing/third_party/gl-matrix/package.json new file mode 100644 index 00000000000..f92ab7d2083 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/package.json @@ -0,0 +1,30 @@ +{ + "name": "gl-matrix", + "description": "Javascript Matrix and Vector library for High Performance WebGL apps", + "version": "2.3.1", + "main": "src/gl-matrix.js", + "homepage": "http://glmatrix.net", + "bugs": { + "url": "https://github.com/toji/gl-matrix/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/toji/gl-matrix.git" + }, + "contributors": [ + { + "name": "Brandon Jones", + "email": "tojiro@gmail.com" + }, + { + "name": "Colin MacKenzie IV", + "email": "sinisterchipmunk@gmail.com" + } + ], + "devDependencies": { + "jasmine-node": "1.2.2", + "node-libs-browser": "^0.5.2", + "webpack": "^1.9.10" + }, + "license": "MIT" +} diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/common-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/common-spec.js new file mode 100644 index 00000000000..b6649d09587 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/common-spec.js @@ -0,0 +1,14 @@ +/* +* common.js unit test +*/ + +describe("glMatrix", function(){ + var result; + + var glMatrix = require("../../src/gl-matrix/common.js"); + + describe("toRadian", function(){ + beforeEach(function(){ result = glMatrix.toRadian(180); }); + it("should return a value of 3.141592654(Math.PI)", function(){ expect(result).toBeEqualish(Math.PI); }); + }); +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2-spec.js new file mode 100644 index 00000000000..e901d332a6c --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2-spec.js @@ -0,0 +1,210 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("mat2", function() { + var mat2 = require("../../src/gl-matrix/mat2.js"); + + var out, matA, matB, identity, result; + + beforeEach(function() { + matA = [1, 2, + 3, 4]; + + matB = [5, 6, + 7, 8]; + + out = [0, 0, + 0, 0]; + + identity = [1, 0, + 0, 1]; + }); + + describe("create", function() { + beforeEach(function() { result = mat2.create(); }); + it("should return a 4 element array initialized to a 2x2 identity matrix", function() { expect(result).toBeEqualish(identity); }); + }); + + describe("clone", function() { + beforeEach(function() { result = mat2.clone(matA); }); + it("should return a 4 element array initialized to the values in matA", function() { expect(result).toBeEqualish(matA); }); + }); + + describe("copy", function() { + beforeEach(function() { result = mat2.copy(out, matA); }); + it("should place values into out", function() { expect(out).toBeEqualish(matA); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("identity", function() { + beforeEach(function() { result = mat2.identity(out); }); + it("should place values into out", function() { expect(result).toBeEqualish(identity); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("transpose", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.transpose(out, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 3, 2, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.transpose(matA, matA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([1, 3, 2, 4]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("invert", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.invert(out, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-2, 1, 1.5, -0.5]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.invert(matA, matA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([-2, 1, 1.5, -0.5]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("adjoint", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.adjoint(out, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([4, -2, -3, 1]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.adjoint(matA, matA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([4, -2, -3, 1]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("determinant", function() { + beforeEach(function() { result = mat2.determinant(matA); }); + + it("should return the determinant", function() { expect(result).toEqual(-2); }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(mat2.mul).toEqual(mat2.multiply); }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.multiply(out, matA, matB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([23, 34, 31, 46]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify matB", function() { expect(matB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.multiply(matA, matA, matB); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([23, 34, 31, 46]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + it("should not modify matB", function() { expect(matB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when matB is the output matrix", function() { + beforeEach(function() { result = mat2.multiply(matB, matA, matB); }); + + it("should place values into matB", function() { expect(matB).toBeEqualish([23, 34, 31, 46]); }); + it("should return matB", function() { expect(result).toBe(matB); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("rotate", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.rotate(out, matA, Math.PI * 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4, -1, -2]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.rotate(matA, matA, Math.PI * 0.5); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([3, 4, -1, -2]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("scale", function() { + var vecA; + beforeEach(function() { vecA = [2, 3]; }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2.scale(out, matA, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 9, 12]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2.scale(matA, matA, vecA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([2, 4, 9, 12]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = mat2.str(matA); }); + + it("should return a string representation of the matrix", function() { expect(result).toEqual("mat2(1, 2, 3, 4)"); }); + }); + + describe("frob", function() { + beforeEach(function() { result = mat2.frob(matA); }); + it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(3, 2) + Math.pow(4, 2))); }); + }); + + describe("LDU", function() { + beforeEach(function() {L = mat2.create(); D = mat2.create(); U = mat2.create(); result = mat2.LDU(L, D, U, [4,3,6,3]); + L_result = mat2.create(); L_result[2] = 1.5; + D_result = mat2.create(); + U_result = mat2.create(); + U_result[0] = 4; U_result[1] = 3; U_result[3] = -1.5; + }); + it("should return a lower triangular, a diagonal and an upper triangular matrix", function() { + expect(result[0]).toBeEqualish(L_result); + expect(result[1]).toBeEqualish(D_result); + expect(result[2]).toBeEqualish(U_result); + }); + }); + +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2d-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2d-spec.js new file mode 100644 index 00000000000..dda0ddd6bc2 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat2d-spec.js @@ -0,0 +1,194 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("mat2d", function() { + var mat2d = require("../../src/gl-matrix/mat2d.js"); + + var out, matA, matB, identity, result; + + beforeEach(function() { + matA = [1, 2, + 3, 4, + 5, 6]; + + oldA = [1, 2, + 3, 4, + 5, 6]; + + matB = [7, 8, + 9, 10, + 11, 12]; + + oldB = [7, 8, + 9, 10, + 11, 12]; + + out = [0, 0, + 0, 0, + 0, 0]; + + identity = [1, 0, + 0, 1, + 0, 0]; + }); + + describe("create", function() { + beforeEach(function() { result = mat2d.create(); }); + it("should return a 6 element array initialized to a 2x3 identity matrix", function() { expect(result).toBeEqualish(identity); }); + }); + + describe("clone", function() { + beforeEach(function() { result = mat2d.clone(matA); }); + it("should return a 6 element array initialized to the values in matA", function() { expect(result).toBeEqualish(matA); }); + }); + + describe("copy", function() { + beforeEach(function() { result = mat2d.copy(out, matA); }); + it("should place values into out", function() { expect(out).toBeEqualish(matA); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("identity", function() { + beforeEach(function() { result = mat2d.identity(out); }); + it("should place values into out", function() { expect(result).toBeEqualish(identity); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("invert", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2d.invert(out, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([ -2, 1, 1.5, -0.5, 1, -2 ]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2d.invert(matA, matA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([ -2, 1, 1.5, -0.5, 1, -2 ]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("determinant", function() { + beforeEach(function() { result = mat2d.determinant(matA); }); + + it("should return the determinant", function() { expect(result).toEqual(-2); }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(mat2d.mul).toEqual(mat2d.multiply); }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2d.multiply(out, matA, matB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([31, 46, 39, 58, 52, 76]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + it("should not modify matB", function() { expect(matB).toBeEqualish(oldB); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2d.multiply(matA, matA, matB); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([31, 46, 39, 58, 52, 76]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + it("should not modify matB", function() { expect(matB).toBeEqualish(oldB); }); + }); + + describe("when matB is the output matrix", function() { + beforeEach(function() { result = mat2d.multiply(matB, matA, matB); }); + + it("should place values into matB", function() { expect(matB).toBeEqualish([31, 46, 39, 58, 52, 76]); }); + it("should return matB", function() { expect(result).toBe(matB); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + }); + }); + + describe("rotate", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2d.rotate(out, matA, Math.PI * 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4, -1, -2, 5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2d.rotate(matA, matA, Math.PI * 0.5); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([3, 4, -1, -2, 5, 6]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("scale", function() { + var vecA; + beforeEach(function() { vecA = [2, 3]; }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2d.scale(out, matA, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 9, 12, 5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2d.scale(matA, matA, vecA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([2, 4, 9, 12, 5, 6]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("translate", function() { + var vecA; + beforeEach(function() { vecA = [2, 3]; }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat2d.translate(out, matA, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3, 4, 16, 22]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { expect(matA).toBeEqualish(oldA); }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat2d.translate(matA, matA, vecA); }); + + it("should place values into matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4, 16, 22]); }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = mat2d.str(matA); }); + + it("should return a string representation of the matrix", function() { expect(result).toEqual("mat2d(1, 2, 3, 4, 5, 6)"); }); + }); + + describe("frob", function() { + beforeEach(function() { result = mat2d.frob(matA); }); + it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(3, 2) + Math.pow(4, 2) + Math.pow(5, 2) + Math.pow(6, 2) + 1)); }); + }); + +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat3-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat3-spec.js new file mode 100644 index 00000000000..9a9d55a71de --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat3-spec.js @@ -0,0 +1,347 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("mat3", function() { + var mat3 = require("../../src/gl-matrix/mat3.js"); + var mat4 = require("../../src/gl-matrix/mat4.js"); + var vec3 = require("../../src/gl-matrix/vec3.js"); + + var out, matA, matB, identity, result; + + beforeEach(function() { + matA = [1, 0, 0, + 0, 1, 0, + 1, 2, 1]; + + matB = [1, 0, 0, + 0, 1, 0, + 3, 4, 1]; + + out = [0, 0, 0, + 0, 0, 0, + 0, 0, 0]; + + identity = [1, 0, 0, + 0, 1, 0, + 0, 0, 1]; + }); + + describe("normalFromMat4", function() { + beforeEach(function() { + matA = [1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1]; + result = mat3.normalFromMat4(out, matA); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + describe("with translation and rotation", function() { + beforeEach(function() { + mat4.translate(matA, matA, [2, 4, 6]); + mat4.rotateX(matA, matA, Math.PI / 2); + + result = mat3.normalFromMat4(out, matA); + }); + + it("should give rotated matrix", function() { + expect(result).toBeEqualish([1, 0, 0, + 0, 0, 1, + 0,-1, 0]); + }); + + describe("and scale", function() { + beforeEach(function() { + mat4.scale(matA, matA, [2, 3, 4]); + + result = mat3.normalFromMat4(out, matA); + }); + + it("should give rotated matrix", function() { + expect(result).toBeEqualish([0.5, 0, 0, + 0, 0, 0.333333, + 0, -0.25, 0]); + }); + }); + }); + }); + + describe("fromQuat", function() { + var q; + + beforeEach(function() { + q = [ 0, -0.7071067811865475, 0, 0.7071067811865475 ]; + result = mat3.fromQuat(out, q); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should rotate a vector the same as the original quat", function() { + expect(vec3.transformMat3([], [0,0,-1], out)).toBeEqualish(vec3.transformQuat([], [0,0,-1], q)); + }); + + it("should rotate a vector by PI/2 radians", function() { + expect(vec3.transformMat3([], [0,0,-1], out)).toBeEqualish([1,0,0]); + }); + }); + + describe("fromMat4", function() { + beforeEach(function() { + result = mat3.fromMat4(out, [ 1, 2, 3, 4, + 5, 6, 7, 8, + 9,10,11,12, + 13,14,15,16]); }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should calculate proper mat3", function() { + expect(out).toBeEqualish([ 1, 2, 3, + 5, 6, 7, + 9,10,11]); + }); + }); + + describe("scale", function() { + beforeEach(function() { result = mat3.scale(out, matA, [2,2]); }); + it("should return out", function() { expect(result).toBe(out); }); + it('should place proper values in out', function() { + expect(out).toBeEqualish([ 2, 0, 0, + 0, 2, 0, + 1, 2, 1 ]); + }); + }); + + describe("create", function() { + beforeEach(function() { result = mat3.create(); }); + it("should return a 9 element array initialized to a 3x3 identity matrix", function() { expect(result).toBeEqualish(identity); }); + }); + + describe("clone", function() { + beforeEach(function() { result = mat3.clone(matA); }); + it("should return a 9 element array initialized to the values in matA", function() { expect(result).toBeEqualish(matA); }); + }); + + describe("copy", function() { + beforeEach(function() { result = mat3.copy(out, matA); }); + it("should place values into out", function() { expect(out).toBeEqualish(matA); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("identity", function() { + beforeEach(function() { result = mat3.identity(out); }); + it("should place values into out", function() { expect(result).toBeEqualish(identity); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("transpose", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat3.transpose(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 1, + 0, 1, 2, + 0, 0, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 1, 2, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat3.transpose(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 1, + 0, 1, 2, + 0, 0, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("invert", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat3.invert(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + -1, -2, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 1, 2, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat3.invert(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + -1, -2, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("adjoint", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat3.adjoint(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + -1, -2, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 1, 2, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat3.adjoint(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + -1, -2, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("determinant", function() { + beforeEach(function() { result = mat3.determinant(matA); }); + + it("should return the determinant", function() { expect(result).toEqual(1); }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(mat3.mul).toEqual(mat3.multiply); }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat3.multiply(out, matA, matB); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 4, 6, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 1, 2, 1 + ]); + }); + it("should not modify matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 3, 4, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat3.multiply(matA, matA, matB); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 4, 6, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + it("should not modify matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 3, 4, 1 + ]); + }); + }); + + describe("when matB is the output matrix", function() { + beforeEach(function() { result = mat3.multiply(matB, matA, matB); }); + + it("should place values into matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 4, 6, 1 + ]); + }); + it("should return matB", function() { expect(result).toBe(matB); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, + 0, 1, 0, + 1, 2, 1 + ]); + }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = mat3.str(matA); }); + + it("should return a string representation of the matrix", function() { expect(result).toEqual("mat3(1, 0, 0, 0, 1, 0, 1, 2, 1)"); }); + }); + + describe("frob", function() { + beforeEach(function() { result = mat3.frob(matA); }); + it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(0, 2) + Math.pow(0, 2) + Math.pow(0, 2) + Math.pow(1, 2) + Math.pow(0, 2) + Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(1, 2))); }); + }); + +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat4-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat4-spec.js new file mode 100644 index 00000000000..9b7a67f4ee6 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/mat4-spec.js @@ -0,0 +1,637 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("mat4", function() { + var mat4 = require("../../src/gl-matrix/mat4.js"); + var vec3 = require("../../src/gl-matrix/vec3.js"); + + var out, matA, matB, identity, result; + + beforeEach(function() { + // Attempting to portray a semi-realistic transform matrix + matA = [1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1]; + + matB = [1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 4, 5, 6, 1]; + + out = [0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0]; + + identity = [1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1]; + }); + + describe("create", function() { + beforeEach(function() { result = mat4.create(); }); + it("should return a 16 element array initialized to a 4x4 identity matrix", function() { expect(result).toBeEqualish(identity); }); + }); + + describe("clone", function() { + beforeEach(function() { result = mat4.clone(matA); }); + it("should return a 16 element array initialized to the values in matA", function() { expect(result).toBeEqualish(matA); }); + }); + + describe("copy", function() { + beforeEach(function() { result = mat4.copy(out, matA); }); + it("should place values into out", function() { expect(out).toBeEqualish(matA); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("identity", function() { + beforeEach(function() { result = mat4.identity(out); }); + it("should place values into out", function() { expect(result).toBeEqualish(identity); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("transpose", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.transpose(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 1, + 0, 1, 0, 2, + 0, 0, 1, 3, + 0, 0, 0, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.transpose(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 1, + 0, 1, 0, 2, + 0, 0, 1, 3, + 0, 0, 0, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("invert", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.invert(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + -1, -2, -3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.invert(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + -1, -2, -3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("adjoint", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.adjoint(out, matA); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + -1, -2, -3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.adjoint(matA, matA); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + -1, -2, -3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("determinant", function() { + beforeEach(function() { result = mat4.determinant(matA); }); + + it("should return the determinant", function() { expect(result).toEqual(1); }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(mat4.mul).toEqual(mat4.multiply); }); + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.multiply(out, matA, matB); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 5, 7, 9, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + it("should not modify matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 4, 5, 6, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.multiply(matA, matA, matB); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 5, 7, 9, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + it("should not modify matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 4, 5, 6, 1 + ]); + }); + }); + + describe("when matB is the output matrix", function() { + beforeEach(function() { result = mat4.multiply(matB, matA, matB); }); + + it("should place values into matB", function() { + expect(matB).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 5, 7, 9, 1 + ]); + }); + it("should return matB", function() { expect(result).toBe(matB); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + }); + + describe("translate", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.translate(out, matA, [4, 5, 6]); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 5, 7, 9, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.translate(matA, matA, [4, 5, 6]); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 5, 7, 9, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("scale", function() { + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.scale(out, matA, [4, 5, 6]); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 4, 0, 0, 0, + 0, 5, 0, 0, + 0, 0, 6, 0, + 1, 2, 3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.scale(matA, matA, [4, 5, 6]); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 4, 0, 0, 0, + 0, 5, 0, 0, + 0, 0, 6, 0, + 1, 2, 3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("rotate", function() { + var rad = Math.PI * 0.5; + var axis = [1, 0, 0]; + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.rotate(out, matA, rad, axis); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, Math.cos(rad), Math.sin(rad), 0, + 0, -Math.sin(rad), Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.rotate(matA, matA, rad, axis); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, Math.cos(rad), Math.sin(rad), 0, + 0, -Math.sin(rad), Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("rotateX", function() { + var rad = Math.PI * 0.5; + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.rotateX(out, matA, rad); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + 1, 0, 0, 0, + 0, Math.cos(rad), Math.sin(rad), 0, + 0, -Math.sin(rad), Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.rotateX(matA, matA, rad); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, Math.cos(rad), Math.sin(rad), 0, + 0, -Math.sin(rad), Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("rotateY", function() { + var rad = Math.PI * 0.5; + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.rotateY(out, matA, rad); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + Math.cos(rad), 0, -Math.sin(rad), 0, + 0, 1, 0, 0, + Math.sin(rad), 0, Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.rotateY(matA, matA, rad); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + Math.cos(rad), 0, -Math.sin(rad), 0, + 0, 1, 0, 0, + Math.sin(rad), 0, Math.cos(rad), 0, + 1, 2, 3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + describe("rotateZ", function() { + var rad = Math.PI * 0.5; + + describe("with a separate output matrix", function() { + beforeEach(function() { result = mat4.rotateZ(out, matA, rad); }); + + it("should place values into out", function() { + expect(out).toBeEqualish([ + Math.cos(rad), Math.sin(rad), 0, 0, + -Math.sin(rad), Math.cos(rad), 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify matA", function() { + expect(matA).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + }); + + describe("when matA is the output matrix", function() { + beforeEach(function() { result = mat4.rotateZ(matA, matA, rad); }); + + it("should place values into matA", function() { + expect(matA).toBeEqualish([ + Math.cos(rad), Math.sin(rad), 0, 0, + -Math.sin(rad), Math.cos(rad), 0, 0, + 0, 0, 1, 0, + 1, 2, 3, 1 + ]); + }); + it("should return matA", function() { expect(result).toBe(matA); }); + }); + }); + + // TODO: fromRotationTranslation + + describe("frustum", function() { + beforeEach(function() { result = mat4.frustum(out, -1, 1, -1, 1, -1, 1); }); + it("should place values into out", function() { expect(result).toBeEqualish([ + -1, 0, 0, 0, + 0, -1, 0, 0, + 0, 0, 0, -1, + 0, 0, 1, 0 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("perspective", function() { + var fovy = Math.PI * 0.5; + beforeEach(function() { result = mat4.perspective(out, fovy, 1, 0, 1); }); + it("should place values into out", function() { expect(result).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, -1, -1, + 0, 0, 0, 0 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + + describe("with nonzero near, 45deg fovy, and realistic aspect ratio", function() { + beforeEach(function() { result = mat4.perspective(out, 45 * Math.PI / 180.0, 640/480, 0.1, 200); }); + it("should calculate correct matrix", function() { expect(result).toBeEqualish([ + 1.81066, 0, 0, 0, + 0, 2.414213, 0, 0, + 0, 0, -1.001, -1, + 0, 0, -0.2001, 0 + ]); }); + }); + }); + + describe("ortho", function() { + beforeEach(function() { result = mat4.ortho(out, -1, 1, -1, 1, -1, 1); }); + it("should place values into out", function() { expect(result).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, -1, 0, + 0, 0, 0, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("lookAt", function() { + var eye = [0, 0, 1]; + var center = [0, 0, -1]; + var up = [0, 1, 0]; + var view, up, right; + + describe("looking down", function() { + beforeEach(function() { + view = [0, -1, 0]; + up = [0, 0, -1]; + right= [1, 0, 0]; + result = mat4.lookAt(out, [0, 0, 0], view, up); + }); + + it("should transform view into local -Z", function() { + result = vec3.transformMat4([], view, out); + expect(result).toBeEqualish([0, 0, -1]); + }); + + it("should transform up into local +Y", function() { + result = vec3.transformMat4([], up, out); + expect(result).toBeEqualish([0, 1, 0]); + }); + + it("should transform right into local +X", function() { + result = vec3.transformMat4([], right, out); + expect(result).toBeEqualish([1, 0, 0]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("#74", function() { + beforeEach(function() { + mat4.lookAt(out, [0,2,0], [0,0.6,0], [0,0,-1]); + }); + + it("should transform a point 'above' into local +Y", function() { + result = vec3.transformMat4([], [0, 2, -1], out); + expect(result).toBeEqualish([0, 1, 0]); + }); + + it("should transform a point 'right of' into local +X", function() { + result = vec3.transformMat4([], [1, 2, 0], out); + expect(result).toBeEqualish([1, 0, 0]); + }); + + it("should transform a point 'in front of' into local -Z", function() { + result = vec3.transformMat4([], [0, 1, 0], out); + expect(result).toBeEqualish([0, 0, -1]); + }); + }); + + beforeEach(function() { + eye = [0, 0, 1]; + center = [0, 0, -1]; + up = [0, 1, 0]; + result = mat4.lookAt(out, eye, center, up); + }); + it("should place values into out", function() { expect(result).toBeEqualish([ + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, -1, 1 + ]); + }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("str", function() { + beforeEach(function() { result = mat4.str(matA); }); + + it("should return a string representation of the matrix", function() { expect(result).toEqual("mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1)"); }); + }); + + describe("frob", function() { + beforeEach(function() { result = mat4.frob(matA); }); + it("should return the Frobenius Norm of the matrix", function() { expect(result).toEqual( Math.sqrt(Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(1, 2) + Math.pow(2, 2) + Math.pow(3, 2) )); }); + }); + + +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/quat-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/quat-spec.js new file mode 100644 index 00000000000..4f5150014d0 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/quat-spec.js @@ -0,0 +1,559 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("quat", function() { + var mat3 = require("../../src/gl-matrix/mat3.js"); + var mat4 = require("../../src/gl-matrix/mat4.js"); + var quat = require("../../src/gl-matrix/quat.js"); + var vec3 = require("../../src/gl-matrix/vec3.js"); + + var out, quatA, quatB, result; + var vec, id, deg90; + + beforeEach(function() { + quatA = [1, 2, 3, 4]; + quatB = [5, 6, 7, 8]; + out = [0, 0, 0, 0]; + vec = [1, 1, -1]; + id = [0, 0, 0, 1]; + deg90 = Math.PI / 2; + }); + + describe("slerp", function() { + describe("the normal case", function() { + beforeEach(function() { + result = quat.slerp(out, [0, 0, 0, 1], [0, 1, 0, 0], 0.5); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should calculate proper quat", function() { + expect(result).toBeEqualish([0, 0.707106, 0, 0.707106]); + }); + }); + + describe("where a == b", function() { + beforeEach(function() { + result = quat.slerp(out, [0, 0, 0, 1], [0, 0, 0, 1], 0.5); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should calculate proper quat", function() { + expect(result).toBeEqualish([0, 0, 0, 1]); + }); + }); + + describe("where theta == 180deg", function() { + beforeEach(function() { + quat.rotateX(quatA, [1,0,0,0], Math.PI); // 180 deg + result = quat.slerp(out, [1,0,0,0], quatA, 1); + }); + + it("should calculate proper quat", function() { + expect(result).toBeEqualish([0,0,0,-1]); + }); + }); + + describe("where a == -b", function() { + beforeEach(function() { + result = quat.slerp(out, [1, 0, 0, 0], [-1, 0, 0, 0], 0.5); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should calculate proper quat", function() { + expect(result).toBeEqualish([1, 0, 0, 0]); + }); + }); + }); + + describe("rotateX", function() { + beforeEach(function() { + result = quat.rotateX(out, id, deg90); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should transform vec accordingly", function() { + vec3.transformQuat(vec, [0,0,-1], out); + expect(vec).toBeEqualish([0, 1, 0]); + }); + }); + + describe("rotateY", function() { + beforeEach(function() { + result = quat.rotateY(out, id, deg90); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should transform vec accordingly", function() { + vec3.transformQuat(vec, [0,0,-1], out); + expect(vec).toBeEqualish([-1, 0, 0]); + }); + }); + + describe("rotateZ", function() { + beforeEach(function() { + result = quat.rotateZ(out, id, deg90); + }); + + it("should return out", function() { expect(result).toBe(out); }); + it("should transform vec accordingly", function() { + vec3.transformQuat(vec, [0,1,0], out); + expect(vec).toBeEqualish([-1, 0, 0]); + }); + }); + + describe("fromMat3", function() { + var matr; + + describe("legacy", function() { + beforeEach(function() { + matr = [ 1, 0, 0, + 0, 0, -1, + 0, 1, 0 ]; + result = quat.fromMat3(out, matr); + }); + + it("should set dest to the correct value", function() { + expect(result).toBeEqualish([-0.707106, 0, 0, 0.707106]); + }); + }); + + describe("where trace > 0", function() { + beforeEach(function() { + matr = [ 1, 0, 0, + 0, 0, -1, + 0, 1, 0 ]; + result = quat.fromMat3(out, matr); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should produce the correct transformation", function() { + expect(vec3.transformQuat([], [0,1,0], out)).toBeEqualish([0,0,-1]); + }); + }); + + describe("from a normal matrix looking 'backward'", function() { + beforeEach(function() { + matr = mat3.create(); + mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [0, 0, 1], [0, 1, 0])))); + result = quat.fromMat3(out, matr); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should produce the same transformation as the given matrix", function() { + expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); + }); + }); + + describe("from a normal matrix looking 'left' and 'upside down'", function() { + beforeEach(function() { + matr = mat3.create(); + mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [-1, 0, 0], [0, -1, 0])))); + result = quat.fromMat3(out, matr); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should produce the same transformation as the given matrix", function() { + expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); + }); + }); + + describe("from a normal matrix looking 'upside down'", function() { + beforeEach(function() { + matr = mat3.create(); + mat3.transpose(matr, mat3.invert(matr, mat3.fromMat4(matr, mat4.lookAt(mat4.create(), [0, 0, 0], [0, 0, -1], [0, -1, 0])))); + result = quat.fromMat3(out, matr); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should produce the same transformation as the given matrix", function() { + expect(vec3.transformQuat([], [3,2,-1], quat.normalize(out, out))).toBeEqualish(vec3.transformMat3([], [3,2,-1], matr)); + }); + }); + }); + + describe("setAxes", function() { + var r; + beforeEach(function() { r = vec3.create(); }); + + describe("looking left", function() { + var view, up, right; + beforeEach(function() { + view = [-1, 0, 0]; + up = [ 0, 1, 0]; + right= [ 0, 0,-1]; + result = quat.setAxes([], view, right, up); + }); + + it("should transform local view into world left", function() { + r = vec3.transformQuat([], [0,0,-1], result); + expect(r).toBeEqualish([1, 0, 0]); + }); + + it("should transform local right into world front", function() { + r = vec3.transformQuat([], [1,0,0], result); + expect(r).toBeEqualish([0, 0, 1]); + }); + }); + + describe("given opengl defaults", function() { + var view, up, right; + beforeEach(function() { + view = [0, 0, -1]; + up = [0, 1, 0]; + right= [1, 0, 0]; + result = quat.setAxes(out, view, right, up); + }); + + it("should return out", function() { + expect(result).toBe(out); + }); + + it("should produce identity", function() { + expect(out).toBeEqualish([0, 0, 0, 1]); + }); + }); + + describe("legacy example", function() { + var view, up, right; + beforeEach(function() { + right= [1, 0, 0]; + up = [0, 0, 1]; + view = [0, -1, 0]; + result = quat.setAxes(out, view, right, up); + }); + + xit("should set correct quat4 values", function() { + expect(result).toBeEqualish([0.707106, 0, 0, 0.707106]); + }); + }); + }); + + describe("rotationTo", function() { + var r; + beforeEach(function() { r = vec3.create(); }); + + describe("at right angle", function() { + beforeEach(function() { + result = quat.rotationTo(out, [0, 1, 0], [1, 0, 0]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("should calculate proper quaternion", function() { + expect(out).toBeEqualish([0, 0, -0.707106, 0.707106]); + }); + }); + + describe("when vectors are parallel", function() { + beforeEach(function() { + result = quat.rotationTo(out, [0, 1, 0], [0, 1, 0]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("multiplying A should produce B", function() { + expect(vec3.transformQuat(r, [0, 1, 0], out)).toBeEqualish([0, 1, 0]); + }); + }); + + describe("when vectors are opposed X", function() { + beforeEach(function() { + result = quat.rotationTo(out, [1, 0, 0], [-1, 0, 0]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("multiplying A should produce B", function() { + expect(vec3.transformQuat(r, [1, 0, 0], out)).toBeEqualish([-1, 0, 0]); + }); + }); + + describe("when vectors are opposed Y", function() { + beforeEach(function() { + result = quat.rotationTo(out, [0, 1, 0], [0, -1, 0]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("multiplying A should produce B", function() { + expect(vec3.transformQuat(r, [0, 1, 0], out)).toBeEqualish([0, -1, 0]); + }); + }); + + describe("when vectors are opposed Z", function() { + beforeEach(function() { + result = quat.rotationTo(out, [0, 0, 1], [0, 0, -1]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + + it("multiplying A should produce B", function() { + expect(vec3.transformQuat(r, [0, 0, 1], out)).toBeEqualish([0, 0, -1]); + }); + }); + }); + + describe("create", function() { + beforeEach(function() { result = quat.create(); }); + it("should return a 4 element array initialized to an identity quaternion", function() { expect(result).toBeEqualish([0, 0, 0, 1]); }); + }); + + describe("clone", function() { + beforeEach(function() { result = quat.clone(quatA); }); + it("should return a 4 element array initialized to the values in quatA", function() { expect(result).toBeEqualish(quatA); }); + }); + + describe("fromValues", function() { + beforeEach(function() { result = quat.fromValues(1, 2, 3, 4); }); + it("should return a 4 element array initialized to the values passed", function() { expect(result).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("copy", function() { + beforeEach(function() { result = quat.copy(out, quatA); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("set", function() { + beforeEach(function() { result = quat.set(out, 1, 2, 3, 4); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("identity", function() { + beforeEach(function() { result = quat.identity(out); }); + it("should place values into out", function() { expect(result).toBeEqualish([0, 0, 0, 1]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("setAxisAngle", function() { + beforeEach(function() { result = quat.setAxisAngle(out, [1, 0, 0], Math.PI * 0.5); }); + it("should place values into out", function() { expect(result).toBeEqualish([0.707106, 0, 0, 0.707106]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("add", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.add(out, quatA, quatB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([6, 8, 10, 12]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.add(quatA, quatA, quatB); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([6, 8, 10, 12]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatB is the output quaternion", function() { + beforeEach(function() { result = quat.add(quatB, quatA, quatB); }); + + it("should place values into quatB", function() { expect(quatB).toBeEqualish([6, 8, 10, 12]); }); + it("should return quatB", function() { expect(result).toBe(quatB); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(quat.mul).toEqual(quat.multiply); }); + + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.multiply(out, quatA, quatB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([24, 48, 48, -6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.multiply(quatA, quatA, quatB); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([24, 48, 48, -6]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatB is the output quaternion", function() { + beforeEach(function() { result = quat.multiply(quatB, quatA, quatB); }); + + it("should place values into quatB", function() { expect(quatB).toBeEqualish([24, 48, 48, -6]); }); + it("should return quatB", function() { expect(result).toBe(quatB); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("scale", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.scale(out, quatA, 2); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 6, 8]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.scale(quatA, quatA, 2); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([2, 4, 6, 8]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + }); + }); + + describe("length", function() { + it("should have an alias called 'len'", function() { expect(quat.len).toEqual(quat.length); }); + + beforeEach(function() { result = quat.length(quatA); }); + + it("should return the length", function() { expect(result).toBeCloseTo(5.477225); }); + }); + + describe("squaredLength", function() { + it("should have an alias called 'sqrLen'", function() { expect(quat.sqrLen).toEqual(quat.squaredLength); }); + + beforeEach(function() { result = quat.squaredLength(quatA); }); + + it("should return the squared length", function() { expect(result).toEqual(30); }); + }); + + describe("normalize", function() { + beforeEach(function() { quatA = [5, 0, 0, 0]; }); + + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.normalize(out, quatA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 0, 0, 0]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([5, 0, 0, 0]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.normalize(quatA, quatA); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([1, 0, 0, 0]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + }); + }); + + describe("lerp", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.lerp(out, quatA, quatB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4, 5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.lerp(quatA, quatA, quatB, 0.5); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([3, 4, 5, 6]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatB is the output quaternion", function() { + beforeEach(function() { result = quat.lerp(quatB, quatA, quatB, 0.5); }); + + it("should place values into quatB", function() { expect(quatB).toBeEqualish([3, 4, 5, 6]); }); + it("should return quatB", function() { expect(result).toBe(quatB); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + /*describe("slerp", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.slerp(out, quatA, quatB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4, 5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.slerp(quatA, quatA, quatB, 0.5); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([3, 4, 5, 6]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + it("should not modify quatB", function() { expect(quatB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when quatB is the output quaternion", function() { + beforeEach(function() { result = quat.slerp(quatB, quatA, quatB, 0.5); }); + + it("should place values into quatB", function() { expect(quatB).toBeEqualish([3, 4, 5, 6]); }); + it("should return quatB", function() { expect(result).toBe(quatB); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + });*/ + + // TODO: slerp, calcuateW, rotateX, rotateY, rotateZ + + describe("invert", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.invert(out, quatA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-0.033333, -0.066666, -0.1, 0.133333]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.invert(quatA, quatA); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([-0.033333, -0.066666, -0.1, 0.133333]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + }); + }); + + describe("conjugate", function() { + describe("with a separate output quaternion", function() { + beforeEach(function() { result = quat.conjugate(out, quatA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-1, -2, -3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify quatA", function() { expect(quatA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when quatA is the output quaternion", function() { + beforeEach(function() { result = quat.conjugate(quatA, quatA); }); + + it("should place values into quatA", function() { expect(quatA).toBeEqualish([-1, -2, -3, 4]); }); + it("should return quatA", function() { expect(result).toBe(quatA); }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = quat.str(quatA); }); + + it("should return a string representation of the quaternion", function() { expect(result).toEqual("quat(1, 2, 3, 4)"); }); + }); +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec2-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec2-spec.js new file mode 100644 index 00000000000..254c52739c3 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec2-spec.js @@ -0,0 +1,549 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("vec2", function() { + var vec2 = require("../../src/gl-matrix/vec2.js"); + + var out, vecA, vecB, result; + + beforeEach(function() { vecA = [1, 2]; vecB = [3, 4]; out = [0, 0]; }); + + describe("create", function() { + beforeEach(function() { result = vec2.create(); }); + it("should return a 2 element array initialized to 0s", function() { expect(result).toBeEqualish([0, 0]); }); + }); + + describe("clone", function() { + beforeEach(function() { result = vec2.clone(vecA); }); + it("should return a 2 element array initialized to the values in vecA", function() { expect(result).toBeEqualish(vecA); }); + }); + + describe("fromValues", function() { + beforeEach(function() { result = vec2.fromValues(1, 2); }); + it("should return a 2 element array initialized to the values passed", function() { expect(result).toBeEqualish([1, 2]); }); + }); + + describe("copy", function() { + beforeEach(function() { result = vec2.copy(out, vecA); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("set", function() { + beforeEach(function() { result = vec2.set(out, 1, 2); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("add", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.add(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([4, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.add(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([4, 6]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.add(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([4, 6]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("subtract", function() { + it("should have an alias called 'sub'", function() { expect(vec2.sub).toEqual(vec2.subtract); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.subtract(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-2, -2]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.subtract(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-2, -2]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.subtract(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([-2, -2]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(vec2.mul).toEqual(vec2.multiply); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.multiply(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 8]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.multiply(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 8]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.multiply(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 8]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("divide", function() { + it("should have an alias called 'div'", function() { expect(vec2.div).toEqual(vec2.divide); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.divide(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([0.3333333, 0.5]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.divide(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([0.3333333, 0.5]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.divide(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([0.3333333, 0.5]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("min", function() { + beforeEach(function() { vecA = [1, 4]; vecB = [3, 2]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.min(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 2]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 2]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.min(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 2]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.min(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([1, 2]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 4]); }); + }); + }); + + describe("max", function() { + beforeEach(function() { vecA = [1, 4]; vecB = [3, 2]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.max(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 2]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.max(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 4]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 2]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.max(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 4]); }); + }); + }); + + describe("scale", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.scale(out, vecA, 2); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.scale(vecA, vecA, 2); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2, 4]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("scaleAndAdd", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.scaleAndAdd(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2.5, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.scaleAndAdd(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2.5, 4]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.scaleAndAdd(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([2.5, 4]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("distance", function() { + it("should have an alias called 'dist'", function() { expect(vec2.dist).toEqual(vec2.distance); }); + + beforeEach(function() { result = vec2.distance(vecA, vecB); }); + + it("should return the distance", function() { expect(result).toBeCloseTo(2.828427); }); + }); + + describe("squaredDistance", function() { + it("should have an alias called 'sqrDist'", function() { expect(vec2.sqrDist).toEqual(vec2.squaredDistance); }); + + beforeEach(function() { result = vec2.squaredDistance(vecA, vecB); }); + + it("should return the squared distance", function() { expect(result).toEqual(8); }); + }); + + describe("length", function() { + it("should have an alias called 'len'", function() { expect(vec2.len).toEqual(vec2.length); }); + + beforeEach(function() { result = vec2.length(vecA); }); + + it("should return the length", function() { expect(result).toBeCloseTo(2.236067); }); + }); + + describe("squaredLength", function() { + it("should have an alias called 'sqrLen'", function() { expect(vec2.sqrLen).toEqual(vec2.squaredLength); }); + + beforeEach(function() { result = vec2.squaredLength(vecA); }); + + it("should return the squared length", function() { expect(result).toEqual(5); }); + }); + + describe("negate", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.negate(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-1, -2]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.negate(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-1, -2]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("normalize", function() { + beforeEach(function() { vecA = [5, 0]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.normalize(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 0]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([5, 0]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.normalize(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 0]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("dot", function() { + beforeEach(function() { result = vec2.dot(vecA, vecB); }); + + it("should return the dot product", function() { expect(result).toEqual(11); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("cross", function() { + var out3; + + beforeEach(function() { + out3 = [0, 0, 0]; + result = vec2.cross(out3, vecA, vecB); + }); + + it("should place values into out", function() { expect(out3).toBeEqualish([0, 0, -2]); }); + it("should return out", function() { expect(result).toBe(out3); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("lerp", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.lerp(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.lerp(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2, 3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec2.lerp(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([2, 3]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + }); + + describe("random", function() { + describe("with no scale", function() { + beforeEach(function() { result = vec2.random(out); }); + + it("should result in a unit length vector", function() { expect(vec2.length(out)).toBeCloseTo(1.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with a scale", function() { + beforeEach(function() { result = vec2.random(out, 5.0); }); + + it("should result in a unit length vector", function() { expect(vec2.length(out)).toBeCloseTo(5.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + }); + + describe("transformMat2", function() { + var matA; + beforeEach(function() { matA = [1, 2, 3, 4]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.transformMat2(out, vecA, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([7, 10]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.transformMat2(vecA, vecA, matA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([7, 10]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("transformMat2d", function() { + var matA; + beforeEach(function() { matA = [1, 2, 3, 4, 5, 6]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec2.transformMat2d(out, vecA, matA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([12, 16]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec2.transformMat2d(vecA, vecA, matA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([12, 16]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify matA", function() { expect(matA).toBeEqualish([1, 2, 3, 4, 5, 6]); }); + }); + }); + + describe("forEach", function() { + var vecArray; + + beforeEach(function() { + vecArray = [ + 1, 2, + 3, 4, + 0, 0 + ]; + }); + + describe("when performing operations that take no extra arguments", function() { + beforeEach(function() { result = vec2.forEach(vecArray, 0, 0, 0, vec2.normalize); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 0.447214, 0.894427, + 0.6, 0.8, + 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + + describe("when performing operations that takes one extra arguments", function() { + beforeEach(function() { result = vec2.forEach(vecArray, 0, 0, 0, vec2.add, vecA); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 2, 4, + 4, 6, + 1, 2 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when specifying an offset", function() { + beforeEach(function() { result = vec2.forEach(vecArray, 0, 2, 0, vec2.add, vecA); }); + + it("should update all values except the first vector", function() { + expect(vecArray).toBeEqualish([ + 1, 2, + 4, 6, + 1, 2 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when specifying a count", function() { + beforeEach(function() { result = vec2.forEach(vecArray, 0, 0, 2, vec2.add, vecA); }); + + it("should update all values except the last vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, + 4, 6, + 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when specifying a stride", function() { + beforeEach(function() { result = vec2.forEach(vecArray, 4, 0, 0, vec2.add, vecA); }); + + it("should update all values except the second vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, + 3, 4, + 1, 2 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2]); }); + }); + + describe("when calling a function that does not modify the out variable", function() { + beforeEach(function() { + result = vec2.forEach(vecArray, 0, 0, 0, function(out, vec) {}); + }); + + it("values should remain unchanged", function() { + expect(vecArray).toBeEqualish([ + 1, 2, + 3, 4, + 0, 0, + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = vec2.str(vecA); }); + + it("should return a string representation of the vector", function() { expect(result).toEqual("vec2(1, 2)"); }); + }); +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec3-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec3-spec.js new file mode 100644 index 00000000000..8ef944f1a24 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec3-spec.js @@ -0,0 +1,661 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("vec3", function() { + var mat3 = require("../../src/gl-matrix/mat3.js"); + var mat4 = require("../../src/gl-matrix/mat4.js"); + var vec3 = require("../../src/gl-matrix/vec3.js"); + + var out, vecA, vecB, result; + + beforeEach(function() { vecA = [1, 2, 3]; vecB = [4, 5, 6]; out = [0, 0, 0]; }); + + describe('rotateX', function(){ + describe('rotation around world origin [0, 0, 0]', function(){ + beforeEach(function(){ vecA = [0, 1, 0]; vecB = [0, 0, 0]; result = vec3.rotateX(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -1, 0]); }); + }); + describe('rotation around an arbitrary origin', function(){ + beforeEach(function(){ vecA = [2, 7, 0]; vecB = [2, 5, 0]; result = vec3.rotateX(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([2, 3, 0]); }); + }); + }); + + describe('rotateY', function(){ + describe('rotation around world origin [0, 0, 0]', function(){ + beforeEach(function(){ vecA = [1, 0, 0]; vecB = [0, 0, 0]; result = vec3.rotateY(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([-1, 0, 0]); }); + }); + describe('rotation around an arbitrary origin', function(){ + beforeEach(function(){ vecA = [-2, 3, 10]; vecB = [-4, 3, 10]; result = vec3.rotateY(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([-6, 3, 10]); }); + }); + }); + + describe('rotateZ', function(){ + describe('rotation around world origin [0, 0, 0]', function(){ + beforeEach(function(){ vecA = [0, 1, 0]; vecB = [0, 0, 0]; result = vec3.rotateZ(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -1, 0]); }); + }); + describe('rotation around an arbitrary origin', function(){ + beforeEach(function(){ vecA = [0, 6, -5]; vecB = [0, 0, -5]; result = vec3.rotateZ(out, vecA, vecB, Math.PI); }); + it("should return the rotated vector", function(){ expect(result).toBeEqualish([0, -6, -5]); }); + }); + }); + + describe('transformMat4', function() { + var matr; + describe("with an identity", function() { + beforeEach(function() { matr = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] }); + + beforeEach(function() { result = vec3.transformMat4(out, vecA, matr); }); + + it("should produce the input", function() { + expect(out).toBeEqualish([1, 2, 3]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with a lookAt", function() { + beforeEach(function() { matr = mat4.lookAt(mat4.create(), [5, 6, 7], [2, 6, 7], [0, 1, 0]); }); + + beforeEach(function() { result = vec3.transformMat4(out, vecA, matr); }); + + it("should rotate and translate the input", function() { + expect(out).toBeEqualish([ 4, -4, -4 ]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with a perspective matrix (#92)", function() { + it("should transform a point from perspective(pi/2, 4/3, 1, 100)", function() { + matr = [0.750, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, -1.02, -1, + 0, 0, -2.02, 0]; + result = vec3.transformMat4([], [10, 20, 30], matr); + expect(result).toBeEqualish([-0.25, -0.666666, 1.087333]); + }); + }); + + }); + + describe('transformMat3', function() { + var matr; + describe("with an identity", function() { + beforeEach(function() { matr = [1, 0, 0, 0, 1, 0, 0, 0, 1 ] }); + + beforeEach(function() { result = vec3.transformMat3(out, vecA, matr); }); + + it("should produce the input", function() { + expect(out).toBeEqualish([1, 2, 3]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with 90deg about X", function() { + beforeEach(function() { + result = vec3.transformMat3(out, [0,1,0], [1,0,0,0,0,1,0,-1,0]); + }); + + it("should produce correct output", function() { + expect(out).toBeEqualish([0,0,1]); + }); + }); + + describe("with 90deg about Y", function() { + beforeEach(function() { + result = vec3.transformMat3(out, [1,0,0], [0,0,-1,0,1,0,1,0,0]); + }); + + it("should produce correct output", function() { + expect(out).toBeEqualish([0,0,-1]); + }); + }); + + describe("with 90deg about Z", function() { + beforeEach(function() { + result = vec3.transformMat3(out, [1,0,0], [0,1,0,-1,0,0,0,0,1]); + }); + + it("should produce correct output", function() { + expect(out).toBeEqualish([0,1,0]); + }); + }); + + describe("with a lookAt normal matrix", function() { + beforeEach(function() { + matr = mat4.lookAt(mat4.create(), [5, 6, 7], [2, 6, 7], [0, 1, 0]); + var n = mat3.create(); + matr = mat3.transpose(n, mat3.invert(n, mat3.fromMat4(n, matr))); + }); + + beforeEach(function() { result = vec3.transformMat3(out, [1,0,0], matr); }); + + it("should rotate the input", function() { + expect(out).toBeEqualish([ 0,0,1 ]); + }); + + it("should return out", function() { expect(result).toBe(out); }); + }); + }); + + describe("create", function() { + beforeEach(function() { result = vec3.create(); }); + it("should return a 3 element array initialized to 0s", function() { expect(result).toBeEqualish([0, 0, 0]); }); + }); + + describe("clone", function() { + beforeEach(function() { result = vec3.clone(vecA); }); + it("should return a 3 element array initialized to the values in vecA", function() { expect(result).toBeEqualish(vecA); }); + }); + + describe("fromValues", function() { + beforeEach(function() { result = vec3.fromValues(1, 2, 3); }); + it("should return a 3 element array initialized to the values passed", function() { expect(result).toBeEqualish([1, 2, 3]); }); + }); + + describe("copy", function() { + beforeEach(function() { result = vec3.copy(out, vecA); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("set", function() { + beforeEach(function() { result = vec3.set(out, 1, 2, 3); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("add", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.add(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([5, 7, 9]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.add(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([5, 7, 9]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.add(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([5, 7, 9]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("subtract", function() { + it("should have an alias called 'sub'", function() { expect(vec3.sub).toEqual(vec3.subtract); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.subtract(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-3, -3, -3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.subtract(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-3, -3, -3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.subtract(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([-3, -3, -3]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(vec3.mul).toEqual(vec3.multiply); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.multiply(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([4, 10, 18]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.multiply(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([4, 10, 18]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.multiply(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([4, 10, 18]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("divide", function() { + it("should have an alias called 'div'", function() { expect(vec3.div).toEqual(vec3.divide); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.divide(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([0.25, 0.4, 0.5]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.divide(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([0.25, 0.4, 0.5]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.divide(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([0.25, 0.4, 0.5]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("min", function() { + beforeEach(function() { vecA = [1, 3, 1]; vecB = [3, 1, 3]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.min(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 1, 1]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.min(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 1, 1]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.min(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([1, 1, 1]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1]); }); + }); + }); + + describe("max", function() { + beforeEach(function() { vecA = [1, 3, 1]; vecB = [3, 1, 3]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.max(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 3, 3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.max(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 3, 3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.max(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 3, 3]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1]); }); + }); + }); + + describe("scale", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.scale(out, vecA, 2); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.scale(vecA, vecA, 2); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2, 4, 6]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("scaleAndAdd", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.scaleAndAdd(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4.5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.scaleAndAdd(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 4.5, 6]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.scaleAndAdd(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 4.5, 6]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("distance", function() { + it("should have an alias called 'dist'", function() { expect(vec3.dist).toEqual(vec3.distance); }); + + beforeEach(function() { result = vec3.distance(vecA, vecB); }); + + it("should return the distance", function() { expect(result).toBeCloseTo(5.196152); }); + }); + + describe("squaredDistance", function() { + it("should have an alias called 'sqrDist'", function() { expect(vec3.sqrDist).toEqual(vec3.squaredDistance); }); + + beforeEach(function() { result = vec3.squaredDistance(vecA, vecB); }); + + it("should return the squared distance", function() { expect(result).toEqual(27); }); + }); + + describe("length", function() { + it("should have an alias called 'len'", function() { expect(vec3.len).toEqual(vec3.length); }); + + beforeEach(function() { result = vec3.length(vecA); }); + + it("should return the length", function() { expect(result).toBeCloseTo(3.741657); }); + }); + + describe("squaredLength", function() { + it("should have an alias called 'sqrLen'", function() { expect(vec3.sqrLen).toEqual(vec3.squaredLength); }); + + beforeEach(function() { result = vec3.squaredLength(vecA); }); + + it("should return the squared length", function() { expect(result).toEqual(14); }); + }); + + describe("negate", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.negate(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-1, -2, -3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.negate(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-1, -2, -3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("normalize", function() { + beforeEach(function() { vecA = [5, 0, 0]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.normalize(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 0, 0]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([5, 0, 0]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.normalize(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 0, 0]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("dot", function() { + beforeEach(function() { result = vec3.dot(vecA, vecB); }); + + it("should return the dot product", function() { expect(result).toEqual(32); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("cross", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.cross(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-3, 6, -3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.cross(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-3, 6, -3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.cross(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([-3, 6, -3]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("lerp", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec3.lerp(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2.5, 3.5, 4.5]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec3.lerp(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2.5, 3.5, 4.5]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec3.lerp(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([2.5, 3.5, 4.5]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + }); + + describe("random", function() { + describe("with no scale", function() { + beforeEach(function() { result = vec3.random(out); }); + + it("should result in a unit length vector", function() { expect(vec3.length(out)).toBeCloseTo(1.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with a scale", function() { + beforeEach(function() { result = vec3.random(out, 5.0); }); + + it("should result in a unit length vector", function() { expect(vec3.length(out)).toBeCloseTo(5.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + }); + + describe("forEach", function() { + var vecArray; + + beforeEach(function() { + vecArray = [ + 1, 2, 3, + 4, 5, 6, + 0, 0, 0 + ]; + }); + + describe("when performing operations that take no extra arguments", function() { + beforeEach(function() { result = vec3.forEach(vecArray, 0, 0, 0, vec3.normalize); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 0.267261, 0.534522, 0.801783, + 0.455842, 0.569802, 0.683763, + 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + + describe("when performing operations that takes one extra arguments", function() { + beforeEach(function() { result = vec3.forEach(vecArray, 0, 0, 0, vec3.add, vecA); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, + 5, 7, 9, + 1, 2, 3 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when specifying an offset", function() { + beforeEach(function() { result = vec3.forEach(vecArray, 0, 3, 0, vec3.add, vecA); }); + + it("should update all values except the first vector", function() { + expect(vecArray).toBeEqualish([ + 1, 2, 3, + 5, 7, 9, + 1, 2, 3 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when specifying a count", function() { + beforeEach(function() { result = vec3.forEach(vecArray, 0, 0, 2, vec3.add, vecA); }); + + it("should update all values except the last vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, + 5, 7, 9, + 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when specifying a stride", function() { + beforeEach(function() { result = vec3.forEach(vecArray, 6, 0, 0, vec3.add, vecA); }); + + it("should update all values except the second vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, + 4, 5, 6, + 1, 2, 3 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + }); + + describe("when calling a function that does not modify the out variable", function() { + beforeEach(function() { + result = vec3.forEach(vecArray, 0, 0, 0, function(out, vec) {}); + }); + + it("values should remain unchanged", function() { + expect(vecArray).toBeEqualish([ + 1, 2, 3, + 4, 5, 6, + 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + }); + + describe("angle", function() { + beforeEach(function() { result = vec3.angle(vecA, vecB); }); + + it("should return the angle", function() { expect(result).toBeEqualish(0.225726); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([4, 5, 6]); }); + }); + + describe("str", function() { + beforeEach(function() { result = vec3.str(vecA); }); + + it("should return a string representation of the vector", function() { expect(result).toEqual("vec3(1, 2, 3)"); }); + }); +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec4-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec4-spec.js new file mode 100644 index 00000000000..0c65908cb4a --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/vec4-spec.js @@ -0,0 +1,492 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +describe("vec4", function() { + var vec3 = require("../../src/gl-matrix/vec3.js"); + var vec4 = require("../../src/gl-matrix/vec4.js"); + + var out, vecA, vecB, result; + + beforeEach(function() { vecA = [1, 2, 3, 4]; vecB = [5, 6, 7, 8]; out = [0, 0, 0, 0]; }); + + describe("create", function() { + beforeEach(function() { result = vec4.create(); }); + it("should return a 4 element array initialized to 0s", function() { expect(result).toBeEqualish([0, 0, 0, 0]); }); + }); + + describe("clone", function() { + beforeEach(function() { result = vec4.clone(vecA); }); + it("should return a 4 element array initialized to the values in vecA", function() { expect(result).toBeEqualish(vecA); }); + }); + + describe("fromValues", function() { + beforeEach(function() { result = vec4.fromValues(1, 2, 3, 4); }); + it("should return a 4 element array initialized to the values passed", function() { expect(result).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("copy", function() { + beforeEach(function() { result = vec4.copy(out, vecA); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("set", function() { + beforeEach(function() { result = vec4.set(out, 1, 2, 3, 4); }); + it("should place values into out", function() { expect(out).toBeEqualish([1, 2, 3, 4]); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("add", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.add(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([6, 8, 10, 12]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.add(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([6, 8, 10, 12]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.add(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([6, 8, 10, 12]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("subtract", function() { + it("should have an alias called 'sub'", function() { expect(vec4.sub).toEqual(vec4.subtract); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.subtract(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-4, -4, -4, -4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.subtract(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-4, -4, -4, -4]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.subtract(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([-4, -4, -4, -4]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("multiply", function() { + it("should have an alias called 'mul'", function() { expect(vec4.mul).toEqual(vec4.multiply); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.multiply(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([5, 12, 21, 32]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.multiply(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([5, 12, 21, 32]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.multiply(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([5, 12, 21, 32]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("divide", function() { + it("should have an alias called 'div'", function() { expect(vec4.div).toEqual(vec4.divide); }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.divide(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([0.2, 0.333333, 0.428571, 0.5]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.divide(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([0.2, 0.333333, 0.428571, 0.5]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.divide(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([0.2, 0.333333, 0.428571, 0.5]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("min", function() { + beforeEach(function() { vecA = [1, 3, 1, 3]; vecB = [3, 1, 3, 1]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.min(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 1, 1, 1]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3, 1]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.min(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 1, 1, 1]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3, 1]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.min(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([1, 1, 1, 1]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1, 3]); }); + }); + }); + + describe("max", function() { + beforeEach(function() { vecA = [1, 3, 1, 3]; vecB = [3, 1, 3, 1]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.max(out, vecA, vecB); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 3, 3, 3]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1, 3]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3, 1]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.max(vecA, vecA, vecB); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 3, 3, 3]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 1, 3, 1]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.max(vecB, vecA, vecB); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 3, 3, 3]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 3, 1, 3]); }); + }); + }); + + describe("scale", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.scale(out, vecA, 2); }); + + it("should place values into out", function() { expect(out).toBeEqualish([2, 4, 6, 8]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.scale(vecA, vecA, 2); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([2, 4, 6, 8]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("scaleAndAdd", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.scaleAndAdd(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3.5, 5, 6.5, 8]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.scaleAndAdd(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3.5, 5, 6.5, 8]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.scaleAndAdd(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3.5, 5, 6.5, 8]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("distance", function() { + it("should have an alias called 'dist'", function() { expect(vec4.dist).toEqual(vec4.distance); }); + + beforeEach(function() { result = vec4.distance(vecA, vecB); }); + + it("should return the distance", function() { expect(result).toBeCloseTo(8); }); + }); + + describe("squaredDistance", function() { + it("should have an alias called 'sqrDist'", function() { expect(vec4.sqrDist).toEqual(vec4.squaredDistance); }); + + beforeEach(function() { result = vec4.squaredDistance(vecA, vecB); }); + + it("should return the squared distance", function() { expect(result).toEqual(64); }); + }); + + describe("length", function() { + it("should have an alias called 'len'", function() { expect(vec4.len).toEqual(vec4.length); }); + + beforeEach(function() { result = vec4.length(vecA); }); + + it("should return the length", function() { expect(result).toBeCloseTo(5.477225); }); + }); + + describe("squaredLength", function() { + it("should have an alias called 'sqrLen'", function() { expect(vec4.sqrLen).toEqual(vec4.squaredLength); }); + + beforeEach(function() { result = vec4.squaredLength(vecA); }); + + it("should return the squared length", function() { expect(result).toEqual(30); }); + }); + + describe("negate", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.negate(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([-1, -2, -3, -4]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.negate(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([-1, -2, -3, -4]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("normalize", function() { + beforeEach(function() { vecA = [5, 0, 0, 0]; }); + + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.normalize(out, vecA); }); + + it("should place values into out", function() { expect(out).toBeEqualish([1, 0, 0, 0]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([5, 0, 0, 0]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.normalize(vecA, vecA); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([1, 0, 0, 0]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + }); + }); + + describe("dot", function() { + beforeEach(function() { result = vec4.dot(vecA, vecB); }); + + it("should return the dot product", function() { expect(result).toEqual(70); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("lerp", function() { + describe("with a separate output vector", function() { + beforeEach(function() { result = vec4.lerp(out, vecA, vecB, 0.5); }); + + it("should place values into out", function() { expect(out).toBeEqualish([3, 4, 5, 6]); }); + it("should return out", function() { expect(result).toBe(out); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecA is the output vector", function() { + beforeEach(function() { result = vec4.lerp(vecA, vecA, vecB, 0.5); }); + + it("should place values into vecA", function() { expect(vecA).toBeEqualish([3, 4, 5, 6]); }); + it("should return vecA", function() { expect(result).toBe(vecA); }); + it("should not modify vecB", function() { expect(vecB).toBeEqualish([5, 6, 7, 8]); }); + }); + + describe("when vecB is the output vector", function() { + beforeEach(function() { result = vec4.lerp(vecB, vecA, vecB, 0.5); }); + + it("should place values into vecB", function() { expect(vecB).toBeEqualish([3, 4, 5, 6]); }); + it("should return vecB", function() { expect(result).toBe(vecB); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + }); + + describe("random", function() { + describe("with no scale", function() { + beforeEach(function() { result = vec4.random(out); }); + + it("should result in a unit length vector", function() { expect(vec4.length(out)).toBeCloseTo(1.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + + describe("with a scale", function() { + beforeEach(function() { result = vec4.random(out, 5.0); }); + + it("should result in a unit length vector", function() { expect(vec4.length(out)).toBeCloseTo(5.0); }); + it("should return out", function() { expect(result).toBe(out); }); + }); + }); + + describe("forEach", function() { + var vecArray; + + beforeEach(function() { + vecArray = [ + 1, 2, 3, 4, + 5, 6, 7, 8, + 0, 0, 0, 0 + ]; + }); + + describe("when performing operations that take no extra arguments", function() { + beforeEach(function() { result = vec4.forEach(vecArray, 0, 0, 0, vec4.normalize); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 0.182574, 0.365148, 0.547722, 0.730296, + 0.379049, 0.454858, 0.530668, 0.606478, + 0, 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + + describe("when performing operations that takes one extra arguments", function() { + beforeEach(function() { result = vec4.forEach(vecArray, 0, 0, 0, vec4.add, vecA); }); + + it("should update all values", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, 8, + 6, 8, 10, 12, + 1, 2, 3, 4 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when specifying an offset", function() { + beforeEach(function() { result = vec4.forEach(vecArray, 0, 4, 0, vec4.add, vecA); }); + + it("should update all values except the first vector", function() { + expect(vecArray).toBeEqualish([ + 1, 2, 3, 4, + 6, 8, 10, 12, + 1, 2, 3, 4 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when specifying a count", function() { + beforeEach(function() { result = vec4.forEach(vecArray, 0, 0, 2, vec4.add, vecA); }); + + it("should update all values except the last vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, 8, + 6, 8, 10, 12, + 0, 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when specifying a stride", function() { + beforeEach(function() { result = vec4.forEach(vecArray, 8, 0, 0, vec4.add, vecA); }); + + it("should update all values except the second vector", function() { + expect(vecArray).toBeEqualish([ + 2, 4, 6, 8, + 5, 6, 7, 8, + 1, 2, 3, 4 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + it("should not modify vecA", function() { expect(vecA).toBeEqualish([1, 2, 3, 4]); }); + }); + + describe("when calling a function that does not modify the out variable", function() { + beforeEach(function() { + result = vec3.forEach(vecArray, 0, 0, 0, function(out, vec) {}); + }); + + it("values should remain unchanged", function() { + expect(vecArray).toBeEqualish([ + 1, 2, 3, 4, + 5, 6, 7, 8, + 0, 0, 0, 0 + ]); + }); + it("should return vecArray", function() { expect(result).toBe(vecArray); }); + }); + }); + + describe("str", function() { + beforeEach(function() { result = vec4.str(vecA); }); + + it("should return a string representation of the vector", function() { expect(result).toEqual("vec4(1, 2, 3, 4)"); }); + }); +}); diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/worker-spec.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/worker-spec.js new file mode 100644 index 00000000000..8b1754f4db1 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/gl-matrix/worker-spec.js @@ -0,0 +1,44 @@ +/* spec tests gl-matrix when embedded into a Web Worker */ + +// only test with workers if workers are available +if (typeof(Worker) !== 'undefined') { + describe("Embedded within Web Workers", function() { + it("should initialize successfully", function() { + var xhr = new XMLHttpRequest(); + var source = null; + xhr.onreadystatechange = function() { + if (this.readyState == this.DONE) { + if (this.status == 200) { + source = this.responseText; + } + } + }; + xhr.open("GET", "/dist/gl-matrix-min.js"); + xhr.send(); + + var result = null; + + waitsFor(function() { + if (!source) return false; + var blob = new Blob([ + source, + "self.postMessage(vec3.create());" + ], + {type: "application/javascript"} + ); + + var worker = new Worker(URL.createObjectURL(blob)); + worker.onmessage = function(e) { + result = e.data; + }; + return true; + }); + + waitsFor(function() { + if (!result) return false; + expect(result).toBeEqualish([0, 0, 0]); + return true; + }); + }); + }); +} diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/helpers/spec-helper.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/helpers/spec-helper.js new file mode 100644 index 00000000000..58e36714505 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/helpers/spec-helper.js @@ -0,0 +1,32 @@ +var HELPER_MATCHERS = (function() { + var EPSILON = 0.00001; + + return { + /* + Returns true if `actual` has the same length as `expected`, and + if each element of both arrays is within 0.000001 of each other. + This is a way to check for "equal enough" conditions, as a way + of working around floating point imprecision. + */ + toBeEqualish: function(expected) { + if (typeof(this.actual) == 'number') + return Math.abs(this.actual - expected) < EPSILON; + + if (this.actual.length != expected.length) return false; + for (var i = 0; i < this.actual.length; i++) { + if (isNaN(this.actual[i]) !== isNaN(expected[i])) + return false; + if (Math.abs(this.actual[i] - expected[i]) >= EPSILON) + return false; + } + return true; + } + }; +})(); + +beforeEach(function() { + this.addMatchers(HELPER_MATCHERS); +}); + +if (typeof(global) != 'undefined') + global.HELPER_MATCHERS = HELPER_MATCHERS; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/jasmine.yml b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/jasmine.yml new file mode 100644 index 00000000000..afb56ec62c9 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/spec/jasmine.yml @@ -0,0 +1,74 @@ +# src_files +# +# Return an array of filepaths relative to src_dir to include before jasmine specs. +# Default: [] +# +# EXAMPLE: +# +# src_files: +# - lib/source1.js +# - lib/source2.js +# - dist/**/*.js +# +src_files: + - src/gl-matrix.js + - src/gl-matrix/common.js + +# stylesheets +# +# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs. +# Default: [] +# +# EXAMPLE: +# +# stylesheets: +# - css/style.css +# - stylesheets/*.css +# +stylesheets: + +# helpers +# +# Return an array of filepaths relative to spec_dir to include before jasmine specs. +# Default: ["helpers/**/*.js"] +# +# EXAMPLE: +# +# helpers: +# - helpers/**/*.js +# +helpers: + +# spec_files +# +# Return an array of filepaths relative to spec_dir to include. +# Default: ["**/*[sS]pec.js"] +# +# EXAMPLE: +# +# spec_files: +# - **/*[sS]pec.js +# +spec_files: + +# src_dir +# +# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank. +# Default: project root +# +# EXAMPLE: +# +# src_dir: public +# +src_dir: + +# spec_dir +# +# Spec directory path. Your spec_files must be returned relative to this path. +# Default: spec/javascripts +# +# EXAMPLE: +# +# spec_dir: spec/javascripts +# +spec_dir: spec diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix.js new file mode 100644 index 00000000000..da4fe60dfd2 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix.js @@ -0,0 +1,37 @@ +/** + * @fileoverview gl-matrix - High performance matrix and vector operations + * @author Brandon Jones + * @author Colin MacKenzie IV + * @version 2.3.1 + */ + +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ +// END HEADER + +exports.glMatrix = require("./gl-matrix/common.js"); +exports.mat2 = require("./gl-matrix/mat2.js"); +exports.mat2d = require("./gl-matrix/mat2d.js"); +exports.mat3 = require("./gl-matrix/mat3.js"); +exports.mat4 = require("./gl-matrix/mat4.js"); +exports.quat = require("./gl-matrix/quat.js"); +exports.vec2 = require("./gl-matrix/vec2.js"); +exports.vec3 = require("./gl-matrix/vec3.js"); +exports.vec4 = require("./gl-matrix/vec4.js");
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/common.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/common.js new file mode 100644 index 00000000000..5253421532e --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/common.js @@ -0,0 +1,52 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +/** + * @class Common utilities + * @name glMatrix + */ +var glMatrix = {}; + +// Constants +glMatrix.EPSILON = 0.000001; +glMatrix.ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array; +glMatrix.RANDOM = Math.random; + +/** + * Sets the type of array used when creating new vectors and matrices + * + * @param {Type} type Array type, such as Float32Array or Array + */ +glMatrix.setMatrixArrayType = function(type) { + GLMAT_ARRAY_TYPE = type; +} + +var degree = Math.PI / 180; + +/** +* Convert Degree To Radian +* +* @param {Number} Angle in Degrees +*/ +glMatrix.toRadian = function(a){ + return a * degree; +} + +module.exports = glMatrix; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2.js new file mode 100644 index 00000000000..012a5c1af6b --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2.js @@ -0,0 +1,302 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 2x2 Matrix + * @name mat2 + */ +var mat2 = {}; + +/** + * Creates a new identity mat2 + * + * @returns {mat2} a new 2x2 matrix + */ +mat2.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Creates a new mat2 initialized with values from an existing matrix + * + * @param {mat2} a matrix to clone + * @returns {mat2} a new 2x2 matrix + */ +mat2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Copy the values from one mat2 to another + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Set a mat2 to the identity matrix + * + * @param {mat2} out the receiving matrix + * @returns {mat2} out + */ +mat2.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Transpose the values of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a1 = a[1]; + out[1] = a[2]; + out[2] = a1; + } else { + out[0] = a[0]; + out[1] = a[2]; + out[2] = a[1]; + out[3] = a[3]; + } + + return out; +}; + +/** + * Inverts a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + + // Calculate the determinant + det = a0 * a3 - a2 * a1; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = a3 * det; + out[1] = -a1 * det; + out[2] = -a2 * det; + out[3] = a0 * det; + + return out; +}; + +/** + * Calculates the adjugate of a mat2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the source matrix + * @returns {mat2} out + */ +mat2.adjoint = function(out, a) { + // Caching this value is nessecary if out == a + var a0 = a[0]; + out[0] = a[3]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a0; + + return out; +}; + +/** + * Calculates the determinant of a mat2 + * + * @param {mat2} a the source matrix + * @returns {Number} determinant of a + */ +mat2.determinant = function (a) { + return a[0] * a[3] - a[2] * a[1]; +}; + +/** + * Multiplies two mat2's + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the first operand + * @param {mat2} b the second operand + * @returns {mat2} out + */ +mat2.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = a0 * b0 + a2 * b1; + out[1] = a1 * b0 + a3 * b1; + out[2] = a0 * b2 + a2 * b3; + out[3] = a1 * b2 + a3 * b3; + return out; +}; + +/** + * Alias for {@link mat2.multiply} + * @function + */ +mat2.mul = mat2.multiply; + +/** + * Rotates a mat2 by the given angle + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ +mat2.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + s = Math.sin(rad), + 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; + return out; +}; + +/** + * Scales the mat2 by the dimensions in the given vec2 + * + * @param {mat2} out the receiving matrix + * @param {mat2} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat2} out + **/ +mat2.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + v0 = v[0], v1 = v[1]; + out[0] = a0 * v0; + out[1] = a1 * v0; + out[2] = a2 * v1; + out[3] = a3 * v1; + return out; +}; + +/** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.rotate(dest, dest, rad); + * + * @param {mat2} out mat2 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat2} out + */ +mat2.fromRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + out[0] = c; + out[1] = s; + out[2] = -s; + out[3] = c; + return out; +} + +/** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat2.identity(dest); + * mat2.scale(dest, dest, vec); + * + * @param {mat2} out mat2 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat2} out + */ +mat2.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = v[1]; + return out; +} + +/** + * Returns a string representation of a mat2 + * + * @param {mat2} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat2.str = function (a) { + return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; + +/** + * Returns Frobenius norm of a mat2 + * + * @param {mat2} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ +mat2.frob = function (a) { + return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2))) +}; + +/** + * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix + * @param {mat2} L the lower triangular matrix + * @param {mat2} D the diagonal matrix + * @param {mat2} U the upper triangular matrix + * @param {mat2} a the input matrix to factorize + */ + +mat2.LDU = function (L, D, U, a) { + L[2] = a[2]/a[0]; + U[0] = a[0]; + U[1] = a[1]; + U[3] = a[3] - L[2] * U[1]; + return [L, D, U]; +}; + + +module.exports = mat2; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2d.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2d.js new file mode 100644 index 00000000000..df3a0e6a0b3 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat2d.js @@ -0,0 +1,317 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 2x3 Matrix + * @name 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. + */ +var mat2d = {}; + +/** + * Creates a new identity mat2d + * + * @returns {mat2d} a new 2x3 matrix + */ +mat2d.create = function() { + var out = new glMatrix.ARRAY_TYPE(6); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + 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 + */ +mat2d.clone = function(a) { + var 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 + */ +mat2d.copy = function(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 + */ +mat2d.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 1; + out[4] = 0; + out[5] = 0; + return out; +}; + +/** + * Inverts a mat2d + * + * @param {mat2d} out the receiving matrix + * @param {mat2d} a the source matrix + * @returns {mat2d} out + */ +mat2d.invert = function(out, a) { + var aa = a[0], ab = a[1], ac = a[2], ad = a[3], + atx = a[4], aty = a[5]; + + var 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 + */ +mat2d.determinant = function (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 + */ +mat2d.multiply = function (out, a, b) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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; +}; + +/** + * Alias for {@link mat2d.multiply} + * @function + */ +mat2d.mul = mat2d.multiply; + +/** + * 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 + */ +mat2d.rotate = function (out, a, rad) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + s = Math.sin(rad), + 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 + **/ +mat2d.scale = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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 + **/ +mat2d.translate = function(out, a, v) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], + 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 + */ +mat2d.fromRotation = function(out, rad) { + var 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 + */ +mat2d.fromScaling = function(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 + */ +mat2d.fromTranslation = function(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 + */ +mat2d.str = function (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 + */ +mat2d.frob = function (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)) +}; + +module.exports = mat2d; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat3.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat3.js new file mode 100644 index 00000000000..bdda05ef020 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat3.js @@ -0,0 +1,565 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 3x3 Matrix + * @name mat3 + */ +var mat3 = {}; + +/** + * Creates a new identity mat3 + * + * @returns {mat3} a new 3x3 matrix + */ +mat3.create = function() { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +}; + +/** + * Copies the upper-left 3x3 values into the given mat3. + * + * @param {mat3} out the receiving 3x3 matrix + * @param {mat4} a the source 4x4 matrix + * @returns {mat3} out + */ +mat3.fromMat4 = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[4]; + out[4] = a[5]; + out[5] = a[6]; + out[6] = a[8]; + out[7] = a[9]; + out[8] = a[10]; + return out; +}; + +/** + * Creates a new mat3 initialized with values from an existing matrix + * + * @param {mat3} a matrix to clone + * @returns {mat3} a new 3x3 matrix + */ +mat3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(9); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Copy the values from one mat3 to another + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.copy = function(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]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Set a mat3 to the identity matrix + * + * @param {mat3} out the receiving matrix + * @returns {mat3} out + */ +mat3.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +}; + +/** + * Transpose the values of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a12 = a[5]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a01; + out[5] = a[7]; + out[6] = a02; + out[7] = a12; + } else { + out[0] = a[0]; + out[1] = a[3]; + out[2] = a[6]; + out[3] = a[1]; + out[4] = a[4]; + out[5] = a[7]; + out[6] = a[2]; + out[7] = a[5]; + out[8] = a[8]; + } + + return out; +}; + +/** + * Inverts a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b01 = a22 * a11 - a12 * a21, + b11 = -a22 * a10 + a12 * a20, + b21 = a21 * a10 - a11 * a20, + + // Calculate the determinant + det = a00 * b01 + a01 * b11 + a02 * b21; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = b01 * det; + out[1] = (-a22 * a01 + a02 * a21) * det; + out[2] = (a12 * a01 - a02 * a11) * det; + out[3] = b11 * det; + out[4] = (a22 * a00 - a02 * a20) * det; + out[5] = (-a12 * a00 + a02 * a10) * det; + out[6] = b21 * det; + out[7] = (-a21 * a00 + a01 * a20) * det; + out[8] = (a11 * a00 - a01 * a10) * det; + return out; +}; + +/** + * Calculates the adjugate of a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the source matrix + * @returns {mat3} out + */ +mat3.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + out[0] = (a11 * a22 - a12 * a21); + out[1] = (a02 * a21 - a01 * a22); + out[2] = (a01 * a12 - a02 * a11); + out[3] = (a12 * a20 - a10 * a22); + out[4] = (a00 * a22 - a02 * a20); + out[5] = (a02 * a10 - a00 * a12); + out[6] = (a10 * a21 - a11 * a20); + out[7] = (a01 * a20 - a00 * a21); + out[8] = (a00 * a11 - a01 * a10); + return out; +}; + +/** + * Calculates the determinant of a mat3 + * + * @param {mat3} a the source matrix + * @returns {Number} determinant of a + */ +mat3.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); +}; + +/** + * Multiplies two mat3's + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the first operand + * @param {mat3} b the second operand + * @returns {mat3} out + */ +mat3.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + b00 = b[0], b01 = b[1], b02 = b[2], + b10 = b[3], b11 = b[4], b12 = b[5], + b20 = b[6], b21 = b[7], b22 = b[8]; + + out[0] = b00 * a00 + b01 * a10 + b02 * a20; + out[1] = b00 * a01 + b01 * a11 + b02 * a21; + out[2] = b00 * a02 + b01 * a12 + b02 * a22; + + out[3] = b10 * a00 + b11 * a10 + b12 * a20; + out[4] = b10 * a01 + b11 * a11 + b12 * a21; + out[5] = b10 * a02 + b11 * a12 + b12 * a22; + + out[6] = b20 * a00 + b21 * a10 + b22 * a20; + out[7] = b20 * a01 + b21 * a11 + b22 * a21; + out[8] = b20 * a02 + b21 * a12 + b22 * a22; + return out; +}; + +/** + * Alias for {@link mat3.multiply} + * @function + */ +mat3.mul = mat3.multiply; + +/** + * Translate a mat3 by the given vector + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to translate + * @param {vec2} v vector to translate by + * @returns {mat3} out + */ +mat3.translate = function(out, a, v) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + x = v[0], y = v[1]; + + out[0] = a00; + out[1] = a01; + out[2] = a02; + + out[3] = a10; + out[4] = a11; + out[5] = a12; + + out[6] = x * a00 + y * a10 + a20; + out[7] = x * a01 + y * a11 + a21; + out[8] = x * a02 + y * a12 + a22; + return out; +}; + +/** + * Rotates a mat3 by the given angle + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ +mat3.rotate = function (out, a, rad) { + var a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8], + + s = Math.sin(rad), + c = Math.cos(rad); + + out[0] = c * a00 + s * a10; + out[1] = c * a01 + s * a11; + out[2] = c * a02 + s * a12; + + out[3] = c * a10 - s * a00; + out[4] = c * a11 - s * a01; + out[5] = c * a12 - s * a02; + + out[6] = a20; + out[7] = a21; + out[8] = a22; + return out; +}; + +/** + * Scales the mat3 by the dimensions in the given vec2 + * + * @param {mat3} out the receiving matrix + * @param {mat3} a the matrix to rotate + * @param {vec2} v the vec2 to scale the matrix by + * @returns {mat3} out + **/ +mat3.scale = function(out, a, v) { + var x = v[0], y = v[1]; + + out[0] = x * a[0]; + out[1] = x * a[1]; + out[2] = x * a[2]; + + out[3] = y * a[3]; + out[4] = y * a[4]; + out[5] = y * a[5]; + + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + return out; +}; + +/** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.translate(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Translation vector + * @returns {mat3} out + */ +mat3.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 1; + out[5] = 0; + out[6] = v[0]; + out[7] = v[1]; + out[8] = 1; + return out; +} + +/** + * Creates a matrix from a given angle + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.rotate(dest, dest, rad); + * + * @param {mat3} out mat3 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat3} out + */ +mat3.fromRotation = function(out, rad) { + var s = Math.sin(rad), c = Math.cos(rad); + + out[0] = c; + out[1] = s; + out[2] = 0; + + out[3] = -s; + out[4] = c; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +} + +/** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat3.identity(dest); + * mat3.scale(dest, dest, vec); + * + * @param {mat3} out mat3 receiving operation result + * @param {vec2} v Scaling vector + * @returns {mat3} out + */ +mat3.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + + out[3] = 0; + out[4] = v[1]; + out[5] = 0; + + out[6] = 0; + out[7] = 0; + out[8] = 1; + return out; +} + +/** + * Copies the values from a mat2d into a mat3 + * + * @param {mat3} out the receiving matrix + * @param {mat2d} a the matrix to copy + * @returns {mat3} out + **/ +mat3.fromMat2d = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = 0; + + out[3] = a[2]; + out[4] = a[3]; + out[5] = 0; + + out[6] = a[4]; + out[7] = a[5]; + out[8] = 1; + return out; +}; + +/** +* Calculates a 3x3 matrix from the given quaternion +* +* @param {mat3} out mat3 receiving operation result +* @param {quat} q Quaternion to create matrix from +* +* @returns {mat3} out +*/ +mat3.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[3] = yx - wz; + out[6] = zx + wy; + + out[1] = yx + wz; + out[4] = 1 - xx - zz; + out[7] = zy - wx; + + out[2] = zx - wy; + out[5] = zy + wx; + out[8] = 1 - xx - yy; + + return out; +}; + +/** +* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix +* +* @param {mat3} out mat3 receiving operation result +* @param {mat4} a Mat4 to derive the normal matrix from +* +* @returns {mat3} out +*/ +mat3.normalFromMat4 = function (out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + + out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + + out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + + return out; +}; + +/** + * Returns a string representation of a mat3 + * + * @param {mat3} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat3.str = function (a) { + return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + + a[6] + ', ' + a[7] + ', ' + a[8] + ')'; +}; + +/** + * Returns Frobenius norm of a mat3 + * + * @param {mat3} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ +mat3.frob = function (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) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2))) +}; + + +module.exports = mat3; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat4.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat4.js new file mode 100644 index 00000000000..b82526d1365 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/mat4.js @@ -0,0 +1,1283 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 4x4 Matrix + * @name mat4 + */ +var mat4 = {}; + +/** + * Creates a new identity mat4 + * + * @returns {mat4} a new 4x4 matrix + */ +mat4.create = function() { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +}; + +/** + * Creates a new mat4 initialized with values from an existing matrix + * + * @param {mat4} a matrix to clone + * @returns {mat4} a new 4x4 matrix + */ +mat4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(16); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Copy the values from one mat4 to another + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.copy = function(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]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Set a mat4 to the identity matrix + * + * @param {mat4} out the receiving matrix + * @returns {mat4} out + */ +mat4.identity = function(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +}; + +/** + * Transpose the values of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.transpose = function(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], a02 = a[2], a03 = a[3], + a12 = a[6], a13 = a[7], + a23 = a[11]; + + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a01; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a02; + out[9] = a12; + out[11] = a[14]; + out[12] = a03; + out[13] = a13; + out[14] = a23; + } else { + out[0] = a[0]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a[1]; + out[5] = a[5]; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a[2]; + out[9] = a[6]; + out[10] = a[10]; + out[11] = a[14]; + out[12] = a[3]; + out[13] = a[7]; + out[14] = a[11]; + out[15] = a[15]; + } + + return out; +}; + +/** + * Inverts a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.invert = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + // Calculate the determinant + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + + return out; +}; + +/** + * Calculates the adjugate of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ +mat4.adjoint = function(out, a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22)); + out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); + out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12)); + out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); + out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); + out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22)); + out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); + out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12)); + out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21)); + out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); + out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11)); + out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); + out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); + out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21)); + out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); + out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11)); + return out; +}; + +/** + * Calculates the determinant of a mat4 + * + * @param {mat4} a the source matrix + * @returns {Number} determinant of a + */ +mat4.determinant = function (a) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32; + + // Calculate the determinant + return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; +}; + +/** + * Multiplies two mat4's + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ +mat4.multiply = function (out, a, b) { + var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], + a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], + a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], + a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15]; + + // Cache only the current line of the second matrix + var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3]; + out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7]; + out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11]; + out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + + b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15]; + out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; + out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; + out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; + out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; + return out; +}; + +/** + * Alias for {@link mat4.multiply} + * @function + */ +mat4.mul = mat4.multiply; + +/** + * Translate a mat4 by the given vector + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ +mat4.translate = function (out, a, v) { + var x = v[0], y = v[1], z = v[2], + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23; + + if (a === out) { + out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; + out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; + out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; + out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; + } else { + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03; + out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13; + out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23; + + out[12] = a00 * x + a10 * y + a20 * z + a[12]; + out[13] = a01 * x + a11 * y + a21 * z + a[13]; + out[14] = a02 * x + a12 * y + a22 * z + a[14]; + out[15] = a03 * x + a13 * y + a23 * z + a[15]; + } + + return out; +}; + +/** + * Scales the mat4 by the dimensions in the given vec3 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ +mat4.scale = function(out, a, v) { + var x = v[0], y = v[1], z = v[2]; + + out[0] = a[0] * x; + out[1] = a[1] * x; + out[2] = a[2] * x; + out[3] = a[3] * x; + out[4] = a[4] * y; + out[5] = a[5] * y; + out[6] = a[6] * y; + out[7] = a[7] * y; + out[8] = a[8] * z; + out[9] = a[9] * z; + out[10] = a[10] * z; + out[11] = a[11] * z; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; +}; + +/** + * Rotates a mat4 by the given angle around the given axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ +mat4.rotate = function (out, a, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t, + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23, + b00, b01, b02, + b10, b11, b12, + b20, b21, b22; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3]; + a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7]; + a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11]; + + // Construct the elements of the rotation matrix + b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s; + b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s; + b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c; + + // Perform rotation-specific matrix multiplication + out[0] = a00 * b00 + a10 * b01 + a20 * b02; + out[1] = a01 * b00 + a11 * b01 + a21 * b02; + out[2] = a02 * b00 + a12 * b01 + a22 * b02; + out[3] = a03 * b00 + a13 * b01 + a23 * b02; + out[4] = a00 * b10 + a10 * b11 + a20 * b12; + out[5] = a01 * b10 + a11 * b11 + a21 * b12; + out[6] = a02 * b10 + a12 * b11 + a22 * b12; + out[7] = a03 * b10 + a13 * b11 + a23 * b12; + out[8] = a00 * b20 + a10 * b21 + a20 * b22; + out[9] = a01 * b20 + a11 * b21 + a21 * b22; + out[10] = a02 * b20 + a12 * b21 + a22 * b22; + out[11] = a03 * b20 + a13 * b21 + a23 * b22; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + return out; +}; + +/** + * Rotates a matrix by the given angle around the X axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateX = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[4] = a10 * c + a20 * s; + out[5] = a11 * c + a21 * s; + out[6] = a12 * c + a22 * s; + out[7] = a13 * c + a23 * s; + out[8] = a20 * c - a10 * s; + out[9] = a21 * c - a11 * s; + out[10] = a22 * c - a12 * s; + out[11] = a23 * c - a13 * s; + return out; +}; + +/** + * Rotates a matrix by the given angle around the Y axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateY = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + + if (a !== out) { // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c - a20 * s; + out[1] = a01 * c - a21 * s; + out[2] = a02 * c - a22 * s; + out[3] = a03 * c - a23 * s; + out[8] = a00 * s + a20 * c; + out[9] = a01 * s + a21 * c; + out[10] = a02 * s + a22 * c; + out[11] = a03 * s + a23 * c; + return out; +}; + +/** + * Rotates a matrix by the given angle around the Z axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.rotateZ = function (out, a, rad) { + var s = Math.sin(rad), + c = Math.cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3], + a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + + if (a !== out) { // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + // Perform axis-specific matrix multiplication + out[0] = a00 * c + a10 * s; + out[1] = a01 * c + a11 * s; + out[2] = a02 * c + a12 * s; + out[3] = a03 * c + a13 * s; + out[4] = a10 * c - a00 * s; + out[5] = a11 * c - a01 * s; + out[6] = a12 * c - a02 * s; + out[7] = a13 * c - a03 * s; + return out; +}; + +/** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Translation vector + * @returns {mat4} out + */ +mat4.fromTranslation = function(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.scale(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Scaling vector + * @returns {mat4} out + */ +mat4.fromScaling = function(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = v[1]; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = v[2]; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from a given angle around a given axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotate(dest, dest, rad, axis); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ +mat4.fromRotation = function(out, rad, axis) { + var x = axis[0], y = axis[1], z = axis[2], + len = Math.sqrt(x * x + y * y + z * z), + s, c, t; + + if (Math.abs(len) < glMatrix.EPSILON) { return null; } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + + // Perform rotation-specific matrix multiplication + out[0] = x * x * t + c; + out[1] = y * x * t + z * s; + out[2] = z * x * t - y * s; + out[3] = 0; + out[4] = x * y * t - z * s; + out[5] = y * y * t + c; + out[6] = z * y * t + x * s; + out[7] = 0; + out[8] = x * z * t + y * s; + out[9] = y * z * t - x * s; + out[10] = z * z * t + c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from the given angle around the X axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateX(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.fromXRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = c; + out[6] = s; + out[7] = 0; + out[8] = 0; + out[9] = -s; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from the given angle around the Y axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateY(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.fromYRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = 0; + out[2] = -s; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = s; + out[9] = 0; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from the given angle around the Z axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateZ(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ +mat4.fromZRotation = function(out, rad) { + var s = Math.sin(rad), + c = Math.cos(rad); + + // Perform axis-specific matrix multiplication + out[0] = c; + out[1] = s; + out[2] = 0; + out[3] = 0; + out[4] = -s; + out[5] = c; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; +} + +/** + * Creates a matrix from a quaternion rotation and vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @returns {mat4} out + */ +mat4.fromRotationTranslation = function (out, q, v) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; +}; + +/** + * Creates a matrix from a quaternion rotation, vector translation and vector scale + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @returns {mat4} out + */ +mat4.fromRotationTranslationScale = function (out, q, v, s) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + sx = s[0], + sy = s[1], + sz = s[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + + return out; +}; + +/** + * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * mat4.translate(dest, origin); + * var quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * mat4.translate(dest, negativeOrigin); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @param {vec3} o The origin vector around which to scale and rotate + * @returns {mat4} out + */ +mat4.fromRotationTranslationScaleOrigin = function (out, q, v, s, o) { + // Quaternion math + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + xy = x * y2, + xz = x * z2, + yy = y * y2, + yz = y * z2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2, + + sx = s[0], + sy = s[1], + sz = s[2], + + ox = o[0], + oy = o[1], + oz = o[2]; + + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0] + ox - (out[0] * ox + out[4] * oy + out[8] * oz); + out[13] = v[1] + oy - (out[1] * ox + out[5] * oy + out[9] * oz); + out[14] = v[2] + oz - (out[2] * ox + out[6] * oy + out[10] * oz); + out[15] = 1; + + return out; +}; + +mat4.fromQuat = function (out, q) { + var x = q[0], y = q[1], z = q[2], w = q[3], + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2; + + out[0] = 1 - yy - zz; + out[1] = yx + wz; + out[2] = zx - wy; + out[3] = 0; + + out[4] = yx - wz; + out[5] = 1 - xx - zz; + out[6] = zy + wx; + out[7] = 0; + + out[8] = zx + wy; + out[9] = zy - wx; + out[10] = 1 - xx - yy; + out[11] = 0; + + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + + return out; +}; + +/** + * Generates a frustum matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Number} left Left bound of the frustum + * @param {Number} right Right bound of the frustum + * @param {Number} bottom Bottom bound of the frustum + * @param {Number} top Top bound of the frustum + * @param {Number} near Near bound of the frustum + * @param {Number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.frustum = function (out, left, right, bottom, top, near, far) { + var rl = 1 / (right - left), + tb = 1 / (top - bottom), + nf = 1 / (near - far); + out[0] = (near * 2) * rl; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = (near * 2) * tb; + out[6] = 0; + out[7] = 0; + out[8] = (right + left) * rl; + out[9] = (top + bottom) * tb; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (far * near * 2) * nf; + out[15] = 0; + return out; +}; + +/** + * Generates a perspective projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fovy Vertical field of view in radians + * @param {number} aspect Aspect ratio. typically viewport width/height + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.perspective = function (out, fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf = 1 / (near - far); + out[0] = f / aspect; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = f; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = (2 * far * near) * nf; + out[15] = 0; + return out; +}; + +/** + * Generates a perspective projection matrix with the given field of view. + * This is primarily useful for generating projection matrices to be used + * with the still experiemental WebVR API. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.perspectiveFromFieldOfView = function (out, fov, near, far) { + var upTan = Math.tan(fov.upDegrees * Math.PI/180.0), + downTan = Math.tan(fov.downDegrees * Math.PI/180.0), + leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0), + rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0), + xScale = 2.0 / (leftTan + rightTan), + yScale = 2.0 / (upTan + downTan); + + out[0] = xScale; + out[1] = 0.0; + out[2] = 0.0; + out[3] = 0.0; + out[4] = 0.0; + out[5] = yScale; + out[6] = 0.0; + out[7] = 0.0; + out[8] = -((leftTan - rightTan) * xScale * 0.5); + out[9] = ((upTan - downTan) * yScale * 0.5); + out[10] = far / (near - far); + out[11] = -1.0; + out[12] = 0.0; + out[13] = 0.0; + out[14] = (far * near) / (near - far); + out[15] = 0.0; + return out; +} + +/** + * Generates a orthogonal projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} left Left bound of the frustum + * @param {number} right Right bound of the frustum + * @param {number} bottom Bottom bound of the frustum + * @param {number} top Top bound of the frustum + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ +mat4.ortho = function (out, left, right, bottom, top, near, far) { + var lr = 1 / (left - right), + bt = 1 / (bottom - top), + nf = 1 / (near - far); + out[0] = -2 * lr; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = -2 * bt; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 2 * nf; + out[11] = 0; + out[12] = (left + right) * lr; + out[13] = (top + bottom) * bt; + out[14] = (far + near) * nf; + out[15] = 1; + return out; +}; + +/** + * Generates a look-at matrix with the given eye position, focal point, and up axis + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ +mat4.lookAt = function (out, eye, center, up) { + var x0, x1, x2, y0, y1, y2, z0, z1, z2, len, + eyex = eye[0], + eyey = eye[1], + eyez = eye[2], + upx = up[0], + upy = up[1], + upz = up[2], + centerx = center[0], + centery = center[1], + centerz = center[2]; + + if (Math.abs(eyex - centerx) < glMatrix.EPSILON && + Math.abs(eyey - centery) < glMatrix.EPSILON && + Math.abs(eyez - centerz) < glMatrix.EPSILON) { + return mat4.identity(out); + } + + z0 = eyex - centerx; + z1 = eyey - centery; + z2 = eyez - centerz; + + len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + z0 *= len; + z1 *= len; + z2 *= len; + + x0 = upy * z2 - upz * z1; + x1 = upz * z0 - upx * z2; + x2 = upx * z1 - upy * z0; + len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (!len) { + x0 = 0; + x1 = 0; + x2 = 0; + } else { + len = 1 / len; + x0 *= len; + x1 *= len; + x2 *= len; + } + + y0 = z1 * x2 - z2 * x1; + y1 = z2 * x0 - z0 * x2; + y2 = z0 * x1 - z1 * x0; + + len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (!len) { + y0 = 0; + y1 = 0; + y2 = 0; + } else { + len = 1 / len; + y0 *= len; + y1 *= len; + y2 *= len; + } + + out[0] = x0; + out[1] = y0; + out[2] = z0; + out[3] = 0; + out[4] = x1; + out[5] = y1; + out[6] = z1; + out[7] = 0; + out[8] = x2; + out[9] = y2; + out[10] = z2; + out[11] = 0; + out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); + out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); + out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); + out[15] = 1; + + return out; +}; + +/** + * Returns a string representation of a mat4 + * + * @param {mat4} mat matrix to represent as a string + * @returns {String} string representation of the matrix + */ +mat4.str = function (a) { + 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] + ')'; +}; + +/** + * Returns Frobenius norm of a mat4 + * + * @param {mat4} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ +mat4.frob = function (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) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) )) +}; + + +module.exports = mat4; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/quat.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/quat.js new file mode 100644 index 00000000000..2990f7ba52f --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/quat.js @@ -0,0 +1,553 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); +var mat3 = require("./mat3.js"); +var vec3 = require("./vec3.js"); +var vec4 = require("./vec4.js"); + +/** + * @class Quaternion + * @name quat + */ +var quat = {}; + +/** + * Creates a new identity quat + * + * @returns {quat} a new quaternion + */ +quat.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Sets a quaternion to represent the shortest rotation from one + * vector to another. + * + * Both vectors are assumed to be unit length. + * + * @param {quat} out the receiving quaternion. + * @param {vec3} a the initial vector + * @param {vec3} b the destination vector + * @returns {quat} out + */ +quat.rotationTo = (function() { + var tmpvec3 = vec3.create(); + var xUnitVec3 = vec3.fromValues(1,0,0); + var yUnitVec3 = vec3.fromValues(0,1,0); + + return function(out, a, b) { + var dot = vec3.dot(a, b); + if (dot < -0.999999) { + vec3.cross(tmpvec3, xUnitVec3, a); + if (vec3.length(tmpvec3) < 0.000001) + vec3.cross(tmpvec3, yUnitVec3, a); + vec3.normalize(tmpvec3, tmpvec3); + quat.setAxisAngle(out, tmpvec3, Math.PI); + return out; + } else if (dot > 0.999999) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + } else { + vec3.cross(tmpvec3, a, b); + out[0] = tmpvec3[0]; + out[1] = tmpvec3[1]; + out[2] = tmpvec3[2]; + out[3] = 1 + dot; + return quat.normalize(out, out); + } + }; +})(); + +/** + * Sets the specified quaternion with values corresponding to the given + * axes. Each axis is a vec3 and is expected to be unit length and + * perpendicular to all other specified axes. + * + * @param {vec3} view the vector representing the viewing direction + * @param {vec3} right the vector representing the local "right" direction + * @param {vec3} up the vector representing the local "up" direction + * @returns {quat} out + */ +quat.setAxes = (function() { + var matr = mat3.create(); + + return function(out, view, right, up) { + matr[0] = right[0]; + matr[3] = right[1]; + matr[6] = right[2]; + + matr[1] = up[0]; + matr[4] = up[1]; + matr[7] = up[2]; + + matr[2] = -view[0]; + matr[5] = -view[1]; + matr[8] = -view[2]; + + return quat.normalize(out, quat.fromMat3(out, matr)); + }; +})(); + +/** + * Creates a new quat initialized with values from an existing quaternion + * + * @param {quat} a quaternion to clone + * @returns {quat} a new quaternion + * @function + */ +quat.clone = vec4.clone; + +/** + * Creates a new quat initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} a new quaternion + * @function + */ +quat.fromValues = vec4.fromValues; + +/** + * Copy the values from one quat to another + * + * @param {quat} out the receiving quaternion + * @param {quat} a the source quaternion + * @returns {quat} out + * @function + */ +quat.copy = vec4.copy; + +/** + * Set the components of a quat to the given values + * + * @param {quat} out the receiving quaternion + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} out + * @function + */ +quat.set = vec4.set; + +/** + * Set a quat to the identity quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ +quat.identity = function(out) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; +}; + +/** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * + * @param {quat} out the receiving quaternion + * @param {vec3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @returns {quat} out + **/ +quat.setAxisAngle = function(out, axis, rad) { + rad = rad * 0.5; + var s = Math.sin(rad); + out[0] = s * axis[0]; + out[1] = s * axis[1]; + out[2] = s * axis[2]; + out[3] = Math.cos(rad); + return out; +}; + +/** + * Adds two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + * @function + */ +quat.add = vec4.add; + +/** + * Multiplies two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + */ +quat.multiply = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + out[0] = ax * bw + aw * bx + ay * bz - az * by; + out[1] = ay * bw + aw * by + az * bx - ax * bz; + out[2] = az * bw + aw * bz + ax * by - ay * bx; + out[3] = aw * bw - ax * bx - ay * by - az * bz; + return out; +}; + +/** + * Alias for {@link quat.multiply} + * @function + */ +quat.mul = quat.multiply; + +/** + * Scales a quat by a scalar number + * + * @param {quat} out the receiving vector + * @param {quat} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {quat} out + * @function + */ +quat.scale = vec4.scale; + +/** + * Rotates a quaternion by the given angle about the X axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateX = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + aw * bx; + out[1] = ay * bw + az * bx; + out[2] = az * bw - ay * bx; + out[3] = aw * bw - ax * bx; + return out; +}; + +/** + * Rotates a quaternion by the given angle about the Y axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateY = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + by = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw - az * by; + out[1] = ay * bw + aw * by; + out[2] = az * bw + ax * by; + out[3] = aw * bw - ay * by; + return out; +}; + +/** + * Rotates a quaternion by the given angle about the Z axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ +quat.rotateZ = function (out, a, rad) { + rad *= 0.5; + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bz = Math.sin(rad), bw = Math.cos(rad); + + out[0] = ax * bw + ay * bz; + out[1] = ay * bw - ax * bz; + out[2] = az * bw + aw * bz; + out[3] = aw * bw - az * bz; + return out; +}; + +/** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate W component of + * @returns {quat} out + */ +quat.calculateW = function (out, a) { + var x = a[0], y = a[1], z = a[2]; + + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + return out; +}; + +/** + * Calculates the dot product of two quat's + * + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {Number} dot product of a and b + * @function + */ +quat.dot = vec4.dot; + +/** + * Performs a linear interpolation between two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + * @function + */ +quat.lerp = vec4.lerp; + +/** + * Performs a spherical linear interpolation between two quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {quat} out + */ +quat.slerp = function (out, a, b, t) { + // benchmarks: + // http://jsperf.com/quaternion-slerp-implementations + + var ax = a[0], ay = a[1], az = a[2], aw = a[3], + bx = b[0], by = b[1], bz = b[2], bw = b[3]; + + var omega, cosom, sinom, scale0, scale1; + + // calc cosine + cosom = ax * bx + ay * by + az * bz + aw * bw; + // adjust signs (if necessary) + if ( cosom < 0.0 ) { + cosom = -cosom; + bx = - bx; + by = - by; + bz = - bz; + bw = - bw; + } + // calculate coefficients + if ( (1.0 - cosom) > 0.000001 ) { + // standard case (slerp) + omega = Math.acos(cosom); + sinom = Math.sin(omega); + scale0 = Math.sin((1.0 - t) * omega) / sinom; + scale1 = Math.sin(t * omega) / sinom; + } else { + // "from" and "to" quaternions are very close + // ... so we can do a linear interpolation + scale0 = 1.0 - t; + scale1 = t; + } + // calculate final values + out[0] = scale0 * ax + scale1 * bx; + out[1] = scale0 * ay + scale1 * by; + out[2] = scale0 * az + scale1 * bz; + out[3] = scale0 * aw + scale1 * bw; + + return out; +}; + +/** + * Performs a spherical linear interpolation with two control points + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {quat} c the third operand + * @param {quat} d the fourth operand + * @param {Number} t interpolation amount + * @returns {quat} out + */ +quat.sqlerp = (function () { + var temp1 = quat.create(); + var temp2 = quat.create(); + + return function (out, a, b, c, d, t) { + quat.slerp(temp1, a, d, t); + quat.slerp(temp2, b, c, t); + quat.slerp(out, temp1, temp2, 2 * t * (1 - t)); + + return out; + }; +}()); + +/** + * Calculates the inverse of a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate inverse of + * @returns {quat} out + */ +quat.invert = function(out, a) { + var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], + dot = a0*a0 + a1*a1 + a2*a2 + a3*a3, + invDot = dot ? 1.0/dot : 0; + + // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 + + out[0] = -a0*invDot; + out[1] = -a1*invDot; + out[2] = -a2*invDot; + out[3] = a3*invDot; + return out; +}; + +/** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate conjugate of + * @returns {quat} out + */ +quat.conjugate = function (out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Calculates the length of a quat + * + * @param {quat} a vector to calculate length of + * @returns {Number} length of a + * @function + */ +quat.length = vec4.length; + +/** + * Alias for {@link quat.length} + * @function + */ +quat.len = quat.length; + +/** + * Calculates the squared length of a quat + * + * @param {quat} a vector to calculate squared length of + * @returns {Number} squared length of a + * @function + */ +quat.squaredLength = vec4.squaredLength; + +/** + * Alias for {@link quat.squaredLength} + * @function + */ +quat.sqrLen = quat.squaredLength; + +/** + * Normalize a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quaternion to normalize + * @returns {quat} out + * @function + */ +quat.normalize = vec4.normalize; + +/** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {quat} out the receiving quaternion + * @param {mat3} m rotation matrix + * @returns {quat} out + * @function + */ +quat.fromMat3 = function(out, m) { + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + var fTrace = m[0] + m[4] + m[8]; + var fRoot; + + if ( fTrace > 0.0 ) { + // |w| > 1/2, may as well choose w > 1/2 + fRoot = Math.sqrt(fTrace + 1.0); // 2w + out[3] = 0.5 * fRoot; + fRoot = 0.5/fRoot; // 1/(4w) + out[0] = (m[5]-m[7])*fRoot; + out[1] = (m[6]-m[2])*fRoot; + out[2] = (m[1]-m[3])*fRoot; + } else { + // |w| <= 1/2 + var i = 0; + if ( m[4] > m[0] ) + i = 1; + if ( m[8] > m[i*3+i] ) + i = 2; + var j = (i+1)%3; + var k = (i+2)%3; + + fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); + out[i] = 0.5 * fRoot; + fRoot = 0.5 / fRoot; + out[3] = (m[j*3+k] - m[k*3+j]) * fRoot; + out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; + out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; + } + + return out; +}; + +/** + * Returns a string representation of a quatenion + * + * @param {quat} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +quat.str = function (a) { + return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; + +module.exports = quat; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec2.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec2.js new file mode 100644 index 00000000000..9e790563af5 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec2.js @@ -0,0 +1,523 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 2 Dimensional Vector + * @name vec2 + */ +var vec2 = {}; + +/** + * Creates a new, empty vec2 + * + * @returns {vec2} a new 2D vector + */ +vec2.create = function() { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = 0; + out[1] = 0; + return out; +}; + +/** + * Creates a new vec2 initialized with values from an existing vector + * + * @param {vec2} a vector to clone + * @returns {vec2} a new 2D vector + */ +vec2.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = a[0]; + out[1] = a[1]; + return out; +}; + +/** + * Creates a new vec2 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} a new 2D vector + */ +vec2.fromValues = function(x, y) { + var out = new glMatrix.ARRAY_TYPE(2); + out[0] = x; + out[1] = y; + return out; +}; + +/** + * Copy the values from one vec2 to another + * + * @param {vec2} out the receiving vector + * @param {vec2} a the source vector + * @returns {vec2} out + */ +vec2.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + return out; +}; + +/** + * Set the components of a vec2 to the given values + * + * @param {vec2} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @returns {vec2} out + */ +vec2.set = function(out, x, y) { + out[0] = x; + out[1] = y; + return out; +}; + +/** + * Adds two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + return out; +}; + +/** + * Subtracts vector b from vector a + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + return out; +}; + +/** + * Alias for {@link vec2.subtract} + * @function + */ +vec2.sub = vec2.subtract; + +/** + * Multiplies two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + return out; +}; + +/** + * Alias for {@link vec2.multiply} + * @function + */ +vec2.mul = vec2.multiply; + +/** + * Divides two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + return out; +}; + +/** + * Alias for {@link vec2.divide} + * @function + */ +vec2.div = vec2.divide; + +/** + * Returns the minimum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + return out; +}; + +/** + * Returns the maximum of two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec2} out + */ +vec2.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + return out; +}; + +/** + * Scales a vec2 by a scalar number + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec2} out + */ +vec2.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + return out; +}; + +/** + * Adds two vec2's after scaling the second operand by a scalar value + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec2} out + */ +vec2.scaleAndAdd = function(out, a, b, scale) { + out[0] = a[0] + (b[0] * scale); + out[1] = a[1] + (b[1] * scale); + return out; +}; + +/** + * Calculates the euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} distance between a and b + */ +vec2.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return Math.sqrt(x*x + y*y); +}; + +/** + * Alias for {@link vec2.distance} + * @function + */ +vec2.dist = vec2.distance; + +/** + * Calculates the squared euclidian distance between two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} squared distance between a and b + */ +vec2.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1]; + return x*x + y*y; +}; + +/** + * Alias for {@link vec2.squaredDistance} + * @function + */ +vec2.sqrDist = vec2.squaredDistance; + +/** + * Calculates the length of a vec2 + * + * @param {vec2} a vector to calculate length of + * @returns {Number} length of a + */ +vec2.length = function (a) { + var x = a[0], + y = a[1]; + return Math.sqrt(x*x + y*y); +}; + +/** + * Alias for {@link vec2.length} + * @function + */ +vec2.len = vec2.length; + +/** + * Calculates the squared length of a vec2 + * + * @param {vec2} a vector to calculate squared length of + * @returns {Number} squared length of a + */ +vec2.squaredLength = function (a) { + var x = a[0], + y = a[1]; + return x*x + y*y; +}; + +/** + * Alias for {@link vec2.squaredLength} + * @function + */ +vec2.sqrLen = vec2.squaredLength; + +/** + * Negates the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to negate + * @returns {vec2} out + */ +vec2.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + return out; +}; + +/** + * Returns the inverse of the components of a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to invert + * @returns {vec2} out + */ +vec2.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + return out; +}; + +/** + * Normalize a vec2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a vector to normalize + * @returns {vec2} out + */ +vec2.normalize = function(out, a) { + var x = a[0], + y = a[1]; + var len = x*x + y*y; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + } + return out; +}; + +/** + * Calculates the dot product of two vec2's + * + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {Number} dot product of a and b + */ +vec2.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1]; +}; + +/** + * Computes the cross product of two vec2's + * Note that the cross product must by definition produce a 3D vector + * + * @param {vec3} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @returns {vec3} out + */ +vec2.cross = function(out, a, b) { + var z = a[0] * b[1] - a[1] * b[0]; + out[0] = out[1] = 0; + out[2] = z; + return out; +}; + +/** + * Performs a linear interpolation between two vec2's + * + * @param {vec2} out the receiving vector + * @param {vec2} a the first operand + * @param {vec2} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec2} out + */ +vec2.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + return out; +}; + +/** + * Generates a random vector with the given scale + * + * @param {vec2} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec2} out + */ +vec2.random = function (out, scale) { + scale = scale || 1.0; + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + out[0] = Math.cos(r) * scale; + out[1] = Math.sin(r) * scale; + return out; +}; + +/** + * Transforms the vec2 with a mat2 + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2} m matrix to transform with + * @returns {vec2} out + */ +vec2.transformMat2 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y; + out[1] = m[1] * x + m[3] * y; + return out; +}; + +/** + * Transforms the vec2 with a mat2d + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat2d} m matrix to transform with + * @returns {vec2} out + */ +vec2.transformMat2d = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[2] * y + m[4]; + out[1] = m[1] * x + m[3] * y + m[5]; + return out; +}; + +/** + * Transforms the vec2 with a mat3 + * 3rd vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat3} m matrix to transform with + * @returns {vec2} out + */ +vec2.transformMat3 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[3] * y + m[6]; + out[1] = m[1] * x + m[4] * y + m[7]; + return out; +}; + +/** + * Transforms the vec2 with a mat4 + * 3rd vector component is implicitly '0' + * 4th vector component is implicitly '1' + * + * @param {vec2} out the receiving vector + * @param {vec2} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec2} out + */ +vec2.transformMat4 = function(out, a, m) { + var x = a[0], + y = a[1]; + out[0] = m[0] * x + m[4] * y + m[12]; + out[1] = m[1] * x + m[5] * y + m[13]; + return out; +}; + +/** + * Perform some operation over an array of vec2s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ +vec2.forEach = (function() { + var vec = vec2.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 2; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; + } + + return a; + }; +})(); + +/** + * Returns a string representation of a vector + * + * @param {vec2} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +vec2.str = function (a) { + return 'vec2(' + a[0] + ', ' + a[1] + ')'; +}; + +module.exports = vec2; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec3.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec3.js new file mode 100644 index 00000000000..c0676feefcd --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec3.js @@ -0,0 +1,709 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 3 Dimensional Vector + * @name vec3 + */ +var vec3 = {}; + +/** + * Creates a new, empty vec3 + * + * @returns {vec3} a new 3D vector + */ +vec3.create = function() { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = 0; + out[1] = 0; + out[2] = 0; + return out; +}; + +/** + * Creates a new vec3 initialized with values from an existing vector + * + * @param {vec3} a vector to clone + * @returns {vec3} a new 3D vector + */ +vec3.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; +}; + +/** + * Creates a new vec3 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} a new 3D vector + */ +vec3.fromValues = function(x, y, z) { + var out = new glMatrix.ARRAY_TYPE(3); + out[0] = x; + out[1] = y; + out[2] = z; + return out; +}; + +/** + * Copy the values from one vec3 to another + * + * @param {vec3} out the receiving vector + * @param {vec3} a the source vector + * @returns {vec3} out + */ +vec3.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; +}; + +/** + * Set the components of a vec3 to the given values + * + * @param {vec3} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} out + */ +vec3.set = function(out, x, y, z) { + out[0] = x; + out[1] = y; + out[2] = z; + return out; +}; + +/** + * Adds two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.add = function(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + return out; +}; + +/** + * Subtracts vector b from vector a + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.subtract = function(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + return out; +}; + +/** + * Alias for {@link vec3.subtract} + * @function + */ +vec3.sub = vec3.subtract; + +/** + * Multiplies two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.multiply = function(out, a, b) { + out[0] = a[0] * b[0]; + out[1] = a[1] * b[1]; + out[2] = a[2] * b[2]; + return out; +}; + +/** + * Alias for {@link vec3.multiply} + * @function + */ +vec3.mul = vec3.multiply; + +/** + * Divides two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.divide = function(out, a, b) { + out[0] = a[0] / b[0]; + out[1] = a[1] / b[1]; + out[2] = a[2] / b[2]; + return out; +}; + +/** + * Alias for {@link vec3.divide} + * @function + */ +vec3.div = vec3.divide; + +/** + * Returns the minimum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + return out; +}; + +/** + * Returns the maximum of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + return out; +}; + +/** + * Scales a vec3 by a scalar number + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec3} out + */ +vec3.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + return out; +}; + +/** + * Adds two vec3's after scaling the second operand by a scalar value + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec3} out + */ +vec3.scaleAndAdd = function(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); + return out; +}; + +/** + * Calculates the euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} distance between a and b + */ +vec3.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return Math.sqrt(x*x + y*y + z*z); +}; + +/** + * Alias for {@link vec3.distance} + * @function + */ +vec3.dist = vec3.distance; + +/** + * Calculates the squared euclidian distance between two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} squared distance between a and b + */ +vec3.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2]; + return x*x + y*y + z*z; +}; + +/** + * Alias for {@link vec3.squaredDistance} + * @function + */ +vec3.sqrDist = vec3.squaredDistance; + +/** + * Calculates the length of a vec3 + * + * @param {vec3} a vector to calculate length of + * @returns {Number} length of a + */ +vec3.length = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return Math.sqrt(x*x + y*y + z*z); +}; + +/** + * Alias for {@link vec3.length} + * @function + */ +vec3.len = vec3.length; + +/** + * Calculates the squared length of a vec3 + * + * @param {vec3} a vector to calculate squared length of + * @returns {Number} squared length of a + */ +vec3.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2]; + return x*x + y*y + z*z; +}; + +/** + * Alias for {@link vec3.squaredLength} + * @function + */ +vec3.sqrLen = vec3.squaredLength; + +/** + * Negates the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to negate + * @returns {vec3} out + */ +vec3.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + return out; +}; + +/** + * Returns the inverse of the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to invert + * @returns {vec3} out + */ +vec3.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + return out; +}; + +/** + * Normalize a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to normalize + * @returns {vec3} out + */ +vec3.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2]; + var len = x*x + y*y + z*z; + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; + } + return out; +}; + +/** + * Calculates the dot product of two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} dot product of a and b + */ +vec3.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +}; + +/** + * Computes the cross product of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ +vec3.cross = function(out, a, b) { + var ax = a[0], ay = a[1], az = a[2], + bx = b[0], by = b[1], bz = b[2]; + + out[0] = ay * bz - az * by; + out[1] = az * bx - ax * bz; + out[2] = ax * by - ay * bx; + return out; +}; + +/** + * Performs a linear interpolation between two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ +vec3.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + return out; +}; + +/** + * Performs a hermite interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ +vec3.hermite = function (out, a, b, c, d, t) { + var factorTimes2 = t * t, + factor1 = factorTimes2 * (2 * t - 3) + 1, + factor2 = factorTimes2 * (t - 2) + t, + factor3 = factorTimes2 * (t - 1), + factor4 = factorTimes2 * (3 - 2 * t); + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; +}; + +/** + * Performs a bezier interpolation with two control points + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @param {vec3} c the third operand + * @param {vec3} d the fourth operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec3} out + */ +vec3.bezier = function (out, a, b, c, d, t) { + var inverseFactor = 1 - t, + inverseFactorTimesTwo = inverseFactor * inverseFactor, + factorTimes2 = t * t, + factor1 = inverseFactorTimesTwo * inverseFactor, + factor2 = 3 * t * inverseFactorTimesTwo, + factor3 = 3 * factorTimes2 * inverseFactor, + factor4 = factorTimes2 * t; + + out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4; + out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4; + out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4; + + return out; +}; + +/** + * Generates a random vector with the given scale + * + * @param {vec3} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec3} out + */ +vec3.random = function (out, scale) { + scale = scale || 1.0; + + var r = glMatrix.RANDOM() * 2.0 * Math.PI; + var z = (glMatrix.RANDOM() * 2.0) - 1.0; + var zScale = Math.sqrt(1.0-z*z) * scale; + + out[0] = Math.cos(r) * zScale; + out[1] = Math.sin(r) * zScale; + out[2] = z * scale; + return out; +}; + +/** + * Transforms the vec3 with a mat4. + * 4th vector component is implicitly '1' + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec3} out + */ +vec3.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], + w = m[3] * x + m[7] * y + m[11] * z + m[15]; + w = w || 1.0; + out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; + out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; + out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; + return out; +}; + +/** + * Transforms the vec3 with a mat3. + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m the 3x3 matrix to transform with + * @returns {vec3} out + */ +vec3.transformMat3 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2]; + out[0] = x * m[0] + y * m[3] + z * m[6]; + out[1] = x * m[1] + y * m[4] + z * m[7]; + out[2] = x * m[2] + y * m[5] + z * m[8]; + return out; +}; + +/** + * Transforms the vec3 with a quat + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec3} out + */ +vec3.transformQuat = function(out, a, q) { + // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations + + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + return out; +}; + +/** + * Rotate a 3D vector around the x-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ +vec3.rotateX = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]; + r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c); + r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; +}; + +/** + * Rotate a 3D vector around the y-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ +vec3.rotateY = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c); + r[1] = p[1]; + r[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c); + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; +}; + +/** + * Rotate a 3D vector around the z-axis + * @param {vec3} out The receiving vec3 + * @param {vec3} a The vec3 point to rotate + * @param {vec3} b The origin of the rotation + * @param {Number} c The angle of rotation + * @returns {vec3} out + */ +vec3.rotateZ = function(out, a, b, c){ + var p = [], r=[]; + //Translate point to the origin + p[0] = a[0] - b[0]; + p[1] = a[1] - b[1]; + p[2] = a[2] - b[2]; + + //perform rotation + r[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c); + r[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c); + r[2] = p[2]; + + //translate to correct position + out[0] = r[0] + b[0]; + out[1] = r[1] + b[1]; + out[2] = r[2] + b[2]; + + return out; +}; + +/** + * Perform some operation over an array of vec3s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ +vec3.forEach = (function() { + var vec = vec3.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 3; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; + } + + return a; + }; +})(); + +/** + * Get the angle between two 3D vectors + * @param {vec3} a The first operand + * @param {vec3} b The second operand + * @returns {Number} The angle in radians + */ +vec3.angle = function(a, b) { + + var tempA = vec3.fromValues(a[0], a[1], a[2]); + var tempB = vec3.fromValues(b[0], b[1], b[2]); + + vec3.normalize(tempA, tempA); + vec3.normalize(tempB, tempB); + + var cosine = vec3.dot(tempA, tempB); + + if(cosine > 1.0){ + return 0; + } else { + return Math.acos(cosine); + } +}; + +/** + * Returns a string representation of a vector + * + * @param {vec3} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +vec3.str = function (a) { + return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')'; +}; + +module.exports = vec3; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec4.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec4.js new file mode 100644 index 00000000000..f18d17440ae --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/src/gl-matrix/vec4.js @@ -0,0 +1,537 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var glMatrix = require("./common.js"); + +/** + * @class 4 Dimensional Vector + * @name vec4 + */ +var vec4 = {}; + +/** + * Creates a new, empty vec4 + * + * @returns {vec4} a new 4D vector + */ +vec4.create = function() { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + return out; +}; + +/** + * Creates a new vec4 initialized with values from an existing vector + * + * @param {vec4} a vector to clone + * @returns {vec4} a new 4D vector + */ +vec4.clone = function(a) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Creates a new vec4 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} a new 4D vector + */ +vec4.fromValues = function(x, y, z, w) { + var out = new glMatrix.ARRAY_TYPE(4); + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; +}; + +/** + * Copy the values from one vec4 to another + * + * @param {vec4} out the receiving vector + * @param {vec4} a the source vector + * @returns {vec4} out + */ +vec4.copy = function(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; +}; + +/** + * Set the components of a vec4 to the given values + * + * @param {vec4} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} out + */ +vec4.set = function(out, x, y, z, w) { + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; +}; + +/** + * Adds two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.add = function(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]; + return out; +}; + +/** + * Subtracts vector b from vector a + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.subtract = function(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]; + return out; +}; + +/** + * Alias for {@link vec4.subtract} + * @function + */ +vec4.sub = vec4.subtract; + +/** + * Multiplies two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.multiply = function(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]; + return out; +}; + +/** + * Alias for {@link vec4.multiply} + * @function + */ +vec4.mul = vec4.multiply; + +/** + * Divides two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.divide = function(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]; + return out; +}; + +/** + * Alias for {@link vec4.divide} + * @function + */ +vec4.div = vec4.divide; + +/** + * Returns the minimum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.min = function(out, a, b) { + out[0] = Math.min(a[0], b[0]); + out[1] = Math.min(a[1], b[1]); + out[2] = Math.min(a[2], b[2]); + out[3] = Math.min(a[3], b[3]); + return out; +}; + +/** + * Returns the maximum of two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ +vec4.max = function(out, a, b) { + out[0] = Math.max(a[0], b[0]); + out[1] = Math.max(a[1], b[1]); + out[2] = Math.max(a[2], b[2]); + out[3] = Math.max(a[3], b[3]); + return out; +}; + +/** + * Scales a vec4 by a scalar number + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec4} out + */ +vec4.scale = function(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; +}; + +/** + * Adds two vec4's after scaling the second operand by a scalar value + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} scale the amount to scale b by before adding + * @returns {vec4} out + */ +vec4.scaleAndAdd = function(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); + return out; +}; + +/** + * Calculates the euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} distance between a and b + */ +vec4.distance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); +}; + +/** + * Alias for {@link vec4.distance} + * @function + */ +vec4.dist = vec4.distance; + +/** + * Calculates the squared euclidian distance between two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} squared distance between a and b + */ +vec4.squaredDistance = function(a, b) { + var x = b[0] - a[0], + y = b[1] - a[1], + z = b[2] - a[2], + w = b[3] - a[3]; + return x*x + y*y + z*z + w*w; +}; + +/** + * Alias for {@link vec4.squaredDistance} + * @function + */ +vec4.sqrDist = vec4.squaredDistance; + +/** + * Calculates the length of a vec4 + * + * @param {vec4} a vector to calculate length of + * @returns {Number} length of a + */ +vec4.length = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return Math.sqrt(x*x + y*y + z*z + w*w); +}; + +/** + * Alias for {@link vec4.length} + * @function + */ +vec4.len = vec4.length; + +/** + * Calculates the squared length of a vec4 + * + * @param {vec4} a vector to calculate squared length of + * @returns {Number} squared length of a + */ +vec4.squaredLength = function (a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + return x*x + y*y + z*z + w*w; +}; + +/** + * Alias for {@link vec4.squaredLength} + * @function + */ +vec4.sqrLen = vec4.squaredLength; + +/** + * Negates the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to negate + * @returns {vec4} out + */ +vec4.negate = function(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = -a[3]; + return out; +}; + +/** + * Returns the inverse of the components of a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to invert + * @returns {vec4} out + */ +vec4.inverse = function(out, a) { + out[0] = 1.0 / a[0]; + out[1] = 1.0 / a[1]; + out[2] = 1.0 / a[2]; + out[3] = 1.0 / a[3]; + return out; +}; + +/** + * Normalize a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to normalize + * @returns {vec4} out + */ +vec4.normalize = function(out, a) { + var x = a[0], + y = a[1], + z = a[2], + w = a[3]; + var len = x*x + y*y + z*z + w*w; + if (len > 0) { + len = 1 / Math.sqrt(len); + out[0] = x * len; + out[1] = y * len; + out[2] = z * len; + out[3] = w * len; + } + return out; +}; + +/** + * Calculates the dot product of two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} dot product of a and b + */ +vec4.dot = function (a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +}; + +/** + * Performs a linear interpolation between two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} t interpolation amount between the two inputs + * @returns {vec4} out + */ +vec4.lerp = function (out, a, b, t) { + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + out[3] = aw + t * (b[3] - aw); + return out; +}; + +/** + * Generates a random vector with the given scale + * + * @param {vec4} out the receiving vector + * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned + * @returns {vec4} out + */ +vec4.random = function (out, scale) { + scale = scale || 1.0; + + //TODO: This is a pretty awful way of doing this. Find something better. + out[0] = glMatrix.RANDOM(); + out[1] = glMatrix.RANDOM(); + out[2] = glMatrix.RANDOM(); + out[3] = glMatrix.RANDOM(); + vec4.normalize(out, out); + vec4.scale(out, out, scale); + return out; +}; + +/** + * Transforms the vec4 with a mat4. + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec4} out + */ +vec4.transformMat4 = function(out, a, m) { + var x = a[0], y = a[1], z = a[2], w = a[3]; + out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; + out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; + out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; + out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; + return out; +}; + +/** + * Transforms the vec4 with a quat + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec4} out + */ +vec4.transformQuat = function(out, a, q) { + var x = a[0], y = a[1], z = a[2], + qx = q[0], qy = q[1], qz = q[2], qw = q[3], + + // calculate quat * vec + ix = qw * x + qy * z - qz * y, + iy = qw * y + qz * x - qx * z, + iz = qw * z + qx * y - qy * x, + iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; + out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; + out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; + out[3] = a[3]; + return out; +}; + +/** + * Perform some operation over an array of vec4s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ +vec4.forEach = (function() { + var vec = vec4.create(); + + return function(a, stride, offset, count, fn, arg) { + var i, l; + if(!stride) { + stride = 4; + } + + if(!offset) { + offset = 0; + } + + if(count) { + l = Math.min((count * stride) + offset, a.length); + } else { + l = a.length; + } + + for(i = offset; i < l; i += stride) { + vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3]; + fn(vec, vec, arg); + a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3]; + } + + return a; + }; +})(); + +/** + * Returns a string representation of a vector + * + * @param {vec4} vec vector to represent as a string + * @returns {String} string representation of the vector + */ +vec4.str = function (a) { + return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; +}; + +module.exports = vec4; diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build.rake b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build.rake new file mode 100644 index 00000000000..a1783aabc7c --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build.rake @@ -0,0 +1,2 @@ +desc "compile & minify sources into a single file" +task :build => ['build:compile', 'build:minify'] diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/compile.rake b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/compile.rake new file mode 100644 index 00000000000..905e393d889 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/compile.rake @@ -0,0 +1,5 @@ +namespace :build do + task :compile do + compile + end +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/minify.rake b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/minify.rake new file mode 100644 index 00000000000..ea5fec42af5 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/build/minify.rake @@ -0,0 +1,5 @@ +namespace :build do + task :minify do + minify + end +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/default.rake b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/default.rake new file mode 100644 index 00000000000..c057922037d --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/default.rake @@ -0,0 +1 @@ +task :default => ['test:node', 'test:ci'] diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/release.rake b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/release.rake new file mode 100644 index 00000000000..c70f70cfc13 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/release.rake @@ -0,0 +1,21 @@ +desc "tag and release gl-matrix v#{GLMatrix::VERSION}" +task :release do + require 'thor' + Bundler.ui = Bundler::UI::Shell.new(Thor::Shell::Basic.new) + Bundler.ui.debug! if ENV['DEBUG'] + + # Sanity check: rebuild files just in case dev forgot to. + # If so, files will change and release will abort since changes + # were not checked in. + Rake::Task['build'].invoke + + release do + # Put other release-related stuff here, such as publishing docs; + # if anything fails, gl-matrix will be untagged and not pushed. + # + # Example: + # + # Rake::Task['doc:publish'].invoke + # + end +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix.rb b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix.rb new file mode 100644 index 00000000000..cecdc615a97 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix.rb @@ -0,0 +1,84 @@ +# Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# +# 2. Altered source versions must be plainly marked as such, and must not +# be misrepresented as being the original software. +# +# 3. This notice may not be removed or altered from any source distribution. +# +$:.unshift File.expand_path('.', File.dirname(__FILE__)) +require 'sprockets' +require 'jasmine' + +class Jasmine::Config + def simple_config_file + File.expand_path GLMatrix.base_path.join('spec/jasmine.yml') + end +end + +class Rack::Jasmine::Runner + alias_method :jasmine_call, :call + def call(env) + GLMatrix.compile + jasmine_call env + end +end + +module GLMatrix + autoload :ReleaseHelper, 'gl-matrix/release_helper' + autoload :Version, 'gl-matrix/version' + autoload :VERSION, 'gl-matrix/version' + + module_function + + def release(&block) + GLMatrix::ReleaseHelper.release &block + end + + def sprockets + env = Sprockets::Environment.new base_path + env.append_path base_path.join('src') + env + end + + def base_path + Pathname.new File.expand_path('../..', File.dirname(__FILE__)) + end + + # Compiles the source file to the dest file. If a block + # is given, the source file is yielded and replaced with + # the result. Returns the destination as a Pathname. + def compile(source = 'gl-matrix.js', dest = 'dist/gl-matrix.js') + dest = base_path.join dest + js = sprockets[source] + js = yield js if block_given? + + File.open dest, "w" do |f| + f.puts js + end + + puts "compiled #{source} to #{dest.relative_path_from base_path}" + dest + end + + def minify(source = 'gl-matrix.js', dest = 'dist/gl-matrix-min.js') + dest = compile source, dest do |js| + Uglifier.compile js + end + + puts "minified #{source} to #{dest.relative_path_from base_path}" + end + +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/release_helper.rb b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/release_helper.rb new file mode 100644 index 00000000000..4aca02baf88 --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/release_helper.rb @@ -0,0 +1,104 @@ +# Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# +# 2. Altered source versions must be plainly marked as such, and must not +# be misrepresented as being the original software. +# +# 3. This notice may not be removed or altered from any source distribution. + +# Pretty much everything here was ripped from Bundler. +# https://github.com/carlhuda/bundler/blob/master/lib/bundler/gem_helper.rb +module GLMatrix::ReleaseHelper + module_function + + def release + guard_clean + guard_already_tagged + tag_version { + yield if block_given? + git_push + } + end + + def base + GLMatrix.base_path.to_s + end + + def git_push + perform_git_push + perform_git_push ' --tags' + Bundler.ui.confirm "Pushed git commits and tags" + end + + def perform_git_push(options = '') + cmd = "git push #{options}" + out, code = sh_with_code(cmd) + raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0 + end + + def guard_already_tagged + if sh('git tag').split(/\n/).include?(version_tag) + raise("This tag has already been committed to the repo.") + end + end + + def guard_clean + clean? or raise("There are files that need to be committed first.") + end + + def clean? + sh_with_code("git diff --exit-code")[1] == 0 + end + + def tag_version + sh "git tag -a -m \"Version #{version}\" #{version_tag}" + Bundler.ui.confirm "Tagged #{version_tag}" + yield if block_given? + rescue + Bundler.ui.error "Untagged #{version_tag} due to error" + sh_with_code "git tag -d #{version_tag}" + raise + end + + def version + GLMatrix::VERSION + end + + def version_tag + "v#{version}" + end + + def name + "gl-matrix" + end + + def sh(cmd, &block) + out, code = sh_with_code(cmd, &block) + code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out) + end + + def sh_with_code(cmd, &block) + cmd << " 2>&1" + outbuf = '' + Bundler.ui.debug(cmd) + Dir.chdir(base) { + outbuf = `#{cmd}` + if $? == 0 + block.call(outbuf) if block + end + } + [outbuf, $?] + end +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/version.rb b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/version.rb new file mode 100644 index 00000000000..73bb9d2889d --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/tasks/support/gl-matrix/version.rb @@ -0,0 +1,28 @@ +# Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# +# 2. Altered source versions must be plainly marked as such, and must not +# be misrepresented as being the original software. +# +# 3. This notice may not be removed or altered from any source distribution. + +module GLMatrix + module Version + MAJOR, MINOR, PATCH, REL = *File.read(base_path.join 'VERSION').split(".") + STRING = [MAJOR, MINOR, PATCH, REL].compact.join '.' + end + + VERSION = Version::STRING +end diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.js new file mode 100644 index 00000000000..b9eace3a5ad --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.js @@ -0,0 +1,47 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var fs = require('fs'); +var webpack = require('webpack'); + +var entryFile = './src/gl-matrix.js'; + +// Read the comments from the top of the main gl-matrix file and append them to +// the minified version. +var header = ''; +var mainFile = fs.readFileSync(entryFile, { encoding: 'utf8' }); +if (mainFile) { + var headerIndex = mainFile.indexOf('\/\/ END HEADER'); + if (headerIndex >= 0) { + header = mainFile.substr(0, headerIndex); + } +} + +module.exports = { + entry: entryFile, + output: { + path: __dirname + '/dist', + filename: 'gl-matrix.js', + libraryTarget: 'umd' + }, + plugins: [ + new webpack.BannerPlugin(header, { raw: true }), + ] +};
\ No newline at end of file diff --git a/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.min.js b/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.min.js new file mode 100644 index 00000000000..c7f91092d1b --- /dev/null +++ b/chromium/third_party/catapult/tracing/third_party/gl-matrix/webpack.config.min.js @@ -0,0 +1,28 @@ +/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +var webpack = require('webpack'); +module.exports = require('./webpack.config.js'); + +module.exports.plugins.unshift( + new webpack.optimize.UglifyJsPlugin() +); + +module.exports.output.filename = 'gl-matrix-min.js';
\ No newline at end of file |