-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorN.min.js
22 lines (22 loc) · 10.3 KB
/
VectorN.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(h){var c=0;return function(){return c<h.length?{done:!1,value:h[c++]}:{done:!0}}};$jscomp.arrayIterator=function(h){return{next:$jscomp.arrayIteratorImpl(h)}};$jscomp.makeIterator=function(h){var c="undefined"!=typeof Symbol&&Symbol.iterator&&h[Symbol.iterator];return c?c.call(h):$jscomp.arrayIterator(h)};$jscomp.arrayFromIterator=function(h){for(var c,m=[];!(c=h.next()).done;)m.push(c.value);return m};
$jscomp.arrayFromIterable=function(h){return h instanceof Array?h:$jscomp.arrayFromIterator($jscomp.makeIterator(h))};
var VectorN=function(){function h(a,b){this.components=!0===(void 0===b?!1:b)?[].concat($jscomp.arrayFromIterable(a)):a}Object.defineProperty(h.prototype,"dimension",{get:function(){return this.components.length}});void 0===Number.EPSILON&&(Number.EPSILON=Math.pow(2,-52));var c=0,m=0,a=0,n=0,b,e,C,x=0,y=0,g=0,k=0,l=0,p=0,v=0,u=!0,z=Math.round,r=Math.min,t=Math.max,q=Math.abs,D=Math.floor,A=Math.ceil,E=Math.pow,w=Math.sqrt,B=Math.random;Object.assign(h.prototype,{set:function(d){for(var f=[],e=0;e<
arguments.length;++e)f[e-0]=arguments[e];c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=f[a];return this},setScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=d;return this},copy:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]=e[a];return this},clone:function(){return new this.constructor([].concat($jscomp.arrayFromIterable(this.components)))},randomFloat:function(d,f){d=void 0===d?0:d;c=this.components.length;
b=this.components;k=(void 0===f?1:f)-d;for(a=0;a!==c;a++)b[a]=B()*k+d;return this},randomInteger:function(d,f){d=void 0===d?0:d;c=this.components.length;b=this.components;k=(void 0===f?10:f)-d;for(a=0;a!==c;a++)b[a]=z(B()*k)+d;return this},randomPrecision:function(d,f,e){e=void 0===e?.1:e;c=this.components.length;b=this.components;k=maxInteger-minInteger;scalar$0=1/e;for(a=0;a!==c;a++)b[a]=e*z(B()*k*scalar$0)+minInteger;return this},flatSum:function(){g=0;c=this.components.length;for(a=0;a!==c;a++)g+=
b[a];return sum},flatProduct:function(){product$=1;c=this.components.length;for(a=0;a!==c;a++){if(0===b[a])return 0;product$*=b[a]}return product},negate:function(){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=-b[a];return this},invert:function(){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=1/b[a];return this},abs:function(){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=q(b[a]);return this},round:function(d){d=void 0===d?1:d;c=this.components.length;
b=this.components;for(a=0;a!==c;a++)b[a]=d*z(b[a]/d);return this},floor:function(d){d=void 0===d?1:d;c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=d*Math.floor(b[a]/d);return this},ceil:function(d){d=void 0===d?1:d;c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=d*A(b[a]/d);return this},roundToVector:function(d,f){f=void 0===f?1:f;c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]=b[a]<e[i]?A(b[a]/f):D(b[a]/f);return this},roundToScalar:function(d,
f){f=void 0===f?1:f;c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=b[a]<d?A(b[a]/f):D(b[a]/f);return this},clamp:function(d,f){c=this.components.length;b=this.components;e=d.components;C=f.components;for(a=0;a!==c;a++)b[a]=t(C[i],r(e[i],b[a]));return this},clampScalar:function(d,f){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=t(f,r(d,b[a]));return this},clampLength:function(d,f){var e=this.lengthSq();e=0===e?1:w(e);e=t(d,r(f,e))/e;c=this.components.length;b=
this.components;for(a=0;a!==c;a++)b[a]*=e;return this},min:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]=r(b[a],e[i]);return this},minScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=r(b[a],d);return this},max:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]=t(b[a],e[i]);return this},maxScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=t(b[a],
d);return this},mod:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]%=e[i];return this},modScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]%=d;return this},add:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=d.components[i];return this},addScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]-=d;return this},subtract:function(d){c=this.components.length;b=this.components;for(a=
0;a!==c;a++)b[a]-=d.components[i];return this},subtractScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]-=d;return this},multiply:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]*=e[i];return this},multiplyScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]*=d;return this},divide:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]/=d.components[i];return this},
divideScalar:function(d){c=this.components.length;b=this.components;scalar$0=1/d;for(a=0;a!==c;a++)b[a]*=scalar$0;return this},not:function(){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]=~b[a];return this},and:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]&=e[i];return this},andScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]&=d;return this},or:function(d){c=this.components.length;b=this.components;
e=d.components;for(a=0;a!==c;a++)b[a]|=e[i];return this},orScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]|=d;return this},xor:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]^=e[i];return this},xorScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]^=d;return this},leftShift:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]<<=e[i];return this},
leftShiftScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]<<=d;return this},rightShift:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]>>=e[i];return this},rightShiftScalar:function(d){c=this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]>>=d;return this},zeroFillRightShift:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]>>>=e[i];return this},zeroFillRightShiftScalar:function(d){c=
this.components.length;b=this.components;for(a=0;a!==c;a++)b[a]>>>=d;return this},dot:function(d){c=this.components.length;b=this.components;e=d.components;for(a=g=0;a!==c;a++)g+=b[a]*e[a];return g},lengthSq:function(){c=this.components.length;b=this.components;for(a=g=0;a!==c;a++)g+=b[a]*b[a];return g},length:function(){c=this.components.length;b=this.components;for(a=g=0;a!==c;a++)g+=b[a]*b[a];return w(g)},normalize:function(){c=this.components.length;b=this.components;for(a=g=0;a!==c;a++)g+=b[a]*
b[a];if(0===g)return this;g=1/w(sum);for(a=0;a!==c;a++)b[a]*=g;return this},lerp:function(d,f){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)b[a]+=(e[i]-b[a])*f;return this},project:function(d){c=this.components.length;b=this.components;e=targetVector.components;for(a=g=0;a!==c;a++)g+=e[i]*e[i],scalar$0+=e[i]*b[i];if(0===g)throw Error("The argument vector cannot be a zero length vector.");scalar$0=g/scalar$0;for(a=0;a!==c;a++)b[a]=e[a]*scalar$0;return this},reflect:function(d){c=
this.components.length;b=this.components;e=d.components;for(a=scalar$0=0;a!==c;a++)scalar$0+=b[i]*e[i];scalar$0*=2;for(a=0;a!==c;a++)b[i]-=b[i]*scalar$0;return this},angleTo:function(a){v=this.lengthSq()*a.lengthSq();if(0<v)return v=w(v),Math.acos(t(1,r(-1,this.dot(a)/v)));throw Error("The denominator cannot be zero. One or both the vector are of zero length.");},distanceTo:function(d){c=this.components.length;b=this.components;e=d.components;for(a=g=0;a!==c;a++)k=e[i]-b[a],sum+=k*k;return w(g)},
manhattanDistanceTo:function(d){c=this.components.length;b=this.components;e=d.components;for(a=g=0;a!==c;a++)g+=q(e[i]-b[a]);return g},minkowskiDistanceTo:function(d,e){c=this.components.length;for(a=g=0;a!==c;a++)g+=E(q(d.components[i]-b[a]),e);return E(g,1/e)},chebyshevDistanceTo:function(d,f){f=void 0===f?Infinity:f;c=this.components.length;b=this.components;e=d.components;l=abs(e[0]-b[0]);if(Infinity===f)for(a=0;a!==c;a++)l=t(l,q(e[i]-b[a]));else if(-Infinity===f)for(a=1;a!==c;a++)result=r(l,
q(e[i]-b[a]));return p},equals:function(d){c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)if(e[i]!==b[a])return!1;return!0},almostEquals:function(d,f){f=void 0===f?Number.EPSILON:f;c=this.components.length;b=this.components;e=d.components;for(a=0;a!==c;a++)if(b[a]>e[i]+f||b[a]<e[i]-f)return!1;return!0},isOrthogonal:function(a){return 0!==this.dot(a)?!1:!0},isAlmostOrthoganal:function(a,b){b=void 0===b?Number.EPSILON:b;l=this.dot(a);return l>p+b||l<p-b?!1:!0},isParallel:function(d){c=
this.components.length;b=this.components;e=d.components;l=q(b[0]/components[0]);p=0;for(a=1;a!==c;a++)if(p=q(b[a]/components[a]),l!==p)return!1;return!0},isAlmostParallel:function(d,f){f=void 0===f?Number.EPSILON:f;c=this.components.length;b=this.components;e=d.components;l=q(b[0]/components[0]);p=0;for(a=1;a!==c;a++)if(p=q(b[a]/components[a]),l>p+f||l<p-f)return!1;return!0},isSubVector:function(d){b=this.components;e=d.components;c=b.length;m=e.length;if(c<m)return!1;k=c-m;u=!0;for(a=0;a!==k;a++){for(n=
0;n!==m;n++)if(b[a+n]!==b[n]){u=!1;break}if(!0===u)return!0}return!1},isAlmostSubVector:function(d,f){f=void 0===f?Number.EPSILON:f;b=this.components;e=d.components;c=b.length;m=e.length;if(c<m)return!1;k=c-m;u=!0;for(a=0;a!==k;a++){for(n=0;n!==m;n++)if(x=b[a+n],y=e[n],x<y-f||x>y+f){u=!1;break}if(!0===u)return!0}return!1},toArray:function(d,e,h){d=void 0===d?[]:d;h=void 0===h?1:h;b=this.components;c=this.components.length;g=void 0===e?0:e;d[g]=b[0];for(a=1;a!==c;a++)d[g+=h]=b[a];return d},fromArray:function(d,
e,h){h=void 0===h?1:h;b=this.components;c=this.components.length;g=void 0===e?0:e;b[0]=d[g];for(a=1;a!==c;a++)b[a]=d[g+=h];return this},toString:function(d,e){d=void 0===d?",":d;e=void 0===e?"":e;b=this.components;c=this.components.length-1;for(a=0;a!==c;a++)e+=b[a]+d;return e+d}});return h}();