mathue 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +88 -0
- package/dist/index.d.ts +2189 -0
- package/dist/mathue.cjs +1 -0
- package/dist/mathue.js +701 -0
- package/dist/mathue.umd.cjs +1 -0
- package/package.json +56 -0
package/dist/mathue.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function*e(e,t){let n=t?.start??0,r=t?.step??1;if(r!==0&&!(r>0&&n>e)&&!(r<0&&n<e))for(let t=n;r>0?t<e:t>e;t+=r)yield t}function t(e){let t=0;for(let n of e)t+=n;return t}function n(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var r=0,i=1,a=2,o=3,s=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[r]}set x(e){this.elements[r]=e}get y(){return this.elements[i]}set y(e){this.elements[i]=e}get z(){return this.elements[a]}set z(e){this.elements[a]=e}get w(){return this.elements[o]}set w(e){this.elements[o]=e}static zero(){return new e(0,0,0,0)}static one(){return new e(1,1,1,1)}clone(){let{x:t,y:n,z:r,w:i}=this;return new e(t,n,r,i)}isZero(){let{x:e,y:t,z:n,w:r}=this;return e===0&&t===0&&n===0&&r===0}set(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}copy(e){let{x:t,y:n,z:r,w:i}=e;this.set(t,n,r,i)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}length(){let{x:e,y:t,z:n,w:r}=this;return Math.sqrt(e**2+t**2+n**2+r**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},c=1e-8,l=class t{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=s.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new t(e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this.elements[9]=l,this.elements[10]=u,this.elements[11]=d,this.elements[12]=f,this.elements[13]=p,this.elements[14]=m,this.elements[15]=h,this}copy(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=e.elements;this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}setIdentity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}setQuaternion(e){let{a:t,b:n,c:r,d:i}=e,a=2/e.squaredNorm(),o=n**2,s=r**2,c=i**2,l=t*n,u=t*r,d=t*i,f=n*r,p=n*i,m=r*i;return this.set(1-a*(s+c),a*(f-d),a*(p+u),0,a*(f+d),1-a*(o+c),a*(m-l),0,a*(p-u),a*(m+l),1-a*(o+s),0,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements,[_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M]=e.elements;return this.elements[0]=_*t+v*a+y*l+b*p,this.elements[1]=_*n+v*o+y*u+b*m,this.elements[2]=_*r+v*s+y*d+b*h,this.elements[3]=_*i+v*c+y*f+b*g,this.elements[4]=x*t+S*a+C*l+w*p,this.elements[5]=x*n+S*o+C*u+w*m,this.elements[6]=x*r+S*s+C*d+w*h,this.elements[7]=x*i+S*c+C*f+w*g,this.elements[8]=T*t+E*a+D*l+O*p,this.elements[9]=T*n+E*o+D*u+O*m,this.elements[10]=T*r+E*s+D*d+O*h,this.elements[11]=T*i+E*c+D*f+O*g,this.elements[12]=k*t+A*a+j*l+M*p,this.elements[13]=k*n+A*o+j*u+M*m,this.elements[14]=k*r+A*s+j*d+M*h,this.elements[15]=k*i+A*c+j*f+M*g,this}determinant(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return e*(a*(u*h-d*m)-o*(l*h-d*p)+s*(l*m-u*p))-t*(i*(u*h-d*m)-o*(c*h-d*f)+s*(c*m-u*f))+n*(i*(l*h-d*p)-a*(c*h-d*f)+s*(c*p-l*f))-r*(i*(l*m-u*p)-a*(c*m-u*f)+o*(c*p-l*f))}invert(){let e=this.determinant();if(Math.abs(e)<c)return null;let[t,n,r,i,a,o,s,l,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-l*g,S=o*_-l*h,C=o*g-s*h,w=s*p-l*f,T=o*p-l*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-l*m,A=a*g-s*m,j=a*p-l*u,M=a*f-s*u,N=u*h-d*m,P=a*h-o*m,F=a*d-o*u;return this.elements[0]=(o*v-s*y+l*b)/e,this.elements[1]=-(n*v-r*y+i*b)/e,this.elements[2]=(n*x-r*S+i*C)/e,this.elements[3]=-(n*w-r*T+i*E)/e,this.elements[4]=-(a*v-s*D+l*O)/e,this.elements[5]=(t*v-r*D+i*O)/e,this.elements[6]=-(t*x-r*k+i*A)/e,this.elements[7]=(t*w-r*j+i*M)/e,this.elements[8]=(a*y-o*D+l*N)/e,this.elements[9]=-(t*y-n*D+i*N)/e,this.elements[10]=(t*S-n*k+i*P)/e,this.elements[11]=-(t*T-n*j+i*F)/e,this.elements[12]=-(a*b-o*O+s*N)/e,this.elements[13]=(t*b-n*O+r*N)/e,this.elements[14]=-(t*C-n*A+r*P)/e,this.elements[15]=(t*E-n*M+r*F)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return this.elements[1]=i,this.elements[2]=c,this.elements[3]=f,this.elements[4]=t,this.elements[6]=l,this.elements[7]=p,this.elements[8]=n,this.elements[9]=o,this.elements[11]=m,this.elements[12]=r,this.elements[13]=s,this.elements[14]=d,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}scale(t){let{order:n}=this;for(let r of e(n)){let i=r===n-1?1:t.elements[r];for(let t of e(n)){let e=r*n+t;this.elements[e]*=i}}return this}translate(e){let{x:t,y:n,z:r}=e,[i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y]=this.elements;return this.elements[12]=i*t+c*n+f*r+g,this.elements[13]=a*t+l*n+p*r+_,this.elements[14]=o*t+u*n+m*r+v,this.elements[15]=s*t+d*n+h*r+y,this}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:l}=n,u=e.x-t.x,d=e.y-t.y,f=e.z-t.z,p=Math.sqrt(u**2+d**2+f**2);if(p<c)return this;u/=p,d/=p,f/=p;let m=s*f-l*d,h=l*u-o*f,g=o*d-s*u,_=Math.sqrt(m**2+h**2+g**2);_>0&&(m/=_,h/=_,g/=_);let v=d*g-f*h,y=f*m-u*g,b=u*h-d*m,x=Math.sqrt(v**2+y**2+b**2);x>0&&(v/=x,y/=x,b/=x);let S=-(m*r+h*i+g*a),C=-(v*r+y*i+b*a),w=-(u*r+d*i+f*a);return this.set(m,v,u,0,h,y,d,0,g,b,f,0,S,C,w,1),this}perspective(e,t,n,r){let i=1/Math.tan(e/2);return this.set(i/r,0,0,0,0,i,0,0,0,0,1,-1,0,0,1,0),n===1/0?(this.elements[10]=-1,this.elements[14]=-2*t):(this.elements[10]=-(n+t)/(n-t),this.elements[14]=-2*n*t/(n-t)),this}_applyVector(e,n,r,i){let{tmpVector:a}=t;a.set(e,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*e+u*n+m*r+v*i,C=s*e+d*n+h*r+y*i,w=c*e+f*n+g*r+b*i,T=l*e+p*n+_*r+x*i;return a.set(S,C,w,T),a}},u=0,d=1,f=2,p=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[u]}set x(e){this.elements[u]=e}get y(){return this.elements[d]}set y(e){this.elements[d]=e}get z(){return this.elements[f]}set z(e){this.elements[f]=e}static zero(){return new e(0,0,0)}static one(){return new e(1,1,1)}clone(){let{x:t,y:n,z:r}=this;return new e(t,n,r)}isZero(){let{x:e,y:t,z:n}=this;return e===0&&t===0&&n===0}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){let{x:t,y:n,z:r}=e;return this.set(t,n,r)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}length(){let{x:e,y:t,z:n}=this;return Math.sqrt(e**2+t**2+n**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}cross(e){let{x:t,y:n,z:r}=this,{x:i,y:a,z:o}=e,s=n*o-r*a,c=r*i-t*o,l=t*a-n*i;return this.set(s,c,l)}crossTo(e,t){return t.copy(this),t.cross(e)}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z);return this.set(r,i,a),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},m=1e-8,h=class t{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=p.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l]=this.elements;return new t(e,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this}copy(e){let[t,n,r,i,a,o,s,c,l]=e.elements;this.set(t,n,r,i,a,o,s,c,l)}setIdentity(){return this.set(1,0,0,0,1,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l]=this.elements,[u,d,f,p,m,h,g,_,v]=e.elements;return this.elements[0]=u*t+d*i+f*s,this.elements[1]=u*n+d*a+f*c,this.elements[2]=u*r+d*o+f*l,this.elements[3]=p*t+m*i+h*s,this.elements[4]=p*n+m*a+h*c,this.elements[5]=p*r+m*o+h*l,this.elements[6]=g*t+_*i+v*s,this.elements[7]=g*n+_*a+v*c,this.elements[8]=g*r+_*o+v*l,this}determinant(){let[e,t,n,r,i,a,o,s,c]=this.elements;return e*(c*i-a*s)+t*(-c*r+a*o)+n*(s*r-i*o)}invert(){let e=this.determinant();if(Math.abs(e)<m)return null;let[t,n,r,i,a,o,s,c,l]=this.elements,u=l*a-o*c,d=-l*i+o*s,f=c*i-a*s;return this.elements[0]=u/e,this.elements[1]=(-l*n+r*c)/e,this.elements[2]=(o*n-r*a)/e,this.elements[3]=d/e,this.elements[4]=(l*t-r*s)/e,this.elements[5]=(-o*t+r*i)/e,this.elements[6]=f/e,this.elements[7]=(-c*t+n*s)/e,this.elements[8]=(a*t-n*i)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c]=this.elements;return this.elements[1]=r,this.elements[2]=o,this.elements[3]=t,this.elements[5]=s,this.elements[6]=n,this.elements[7]=a,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}_applyVector(e,n,r){let{tmpVector:i}=t;i.set(e,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*e+c*n+d*r,h=o*e+l*n+f*r,g=s*e+u*n+p*r;return i.set(m,h,g),i}},g=class{_phi;_theta;_radius;constructor(e,t,n){this._phi=e,this._theta=t,this._radius=n}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get radius(){return this._radius}set radius(e){this._radius=e}toVector3(e){let{phi:t,theta:n,radius:r}=this,{cos:i,sin:a}=Math,o=a(n),s=r*o*i(t),c=r*o*a(t),l=r*i(n);e.set(s,c,l)}toTangentZ(e){let{phi:t,theta:n}=this,{cos:r,sin:i}=Math,a=r(n),o=-a*r(t),s=-a*i(t),c=i(n);e.set(o,s,c)}},_=class e{_a;_b;_c;_d;static temporary=e.identity();constructor(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r}get a(){return this._a}get b(){return this._b}get c(){return this._c}get d(){return this._d}static identity(){return new e(1,0,0,0)}static fromAxisAndAngle(t,n){let r=e.identity();return r.setAxisAndAngle(t,n),r}clone(){let{a:t,b:n,c:r,d:i}=this;return new e(t,n,r,i)}set(e,t,n,r){return this._a=e,this._b=t,this._c=n,this._d=r,this}copy(e){let{a:t,b:n,c:r,d:i}=e;return this.set(t,n,r,i)}setIdentity(){this.set(1,0,0,0)}setAxisAndAngle(e,t){if(e.isZero())return this.setIdentity();e.normalize();let{x:n,y:r,z:i}=e,a=Math.sin(t/2);this.set(Math.cos(t/2),n*a,r*a,i*a)}squaredNorm(){let{a:e,b:t,c:n,d:r}=this;return e**2+t**2+n**2+r**2}norm(){return Math.sqrt(this.squaredNorm())}conjugate(){return this._b*=-1,this._c*=-1,this._d*=-1,this}add(e){let{a:t,b:n,c:r,d:i}=e;return this._a+=t,this._b+=n,this._c+=r,this._d+=i,this}subtract(e){let{a:t,b:n,c:r,d:i}=e;return this._a-=t,this._b-=n,this._c-=r,this._d-=i,this}multiply(e){let{a:t,b:n,c:r,d:i}=this,{a,b:o,c:s,d:c}=e;return this._a=t*a-n*o-r*s-i*c,this._b=t*o+n*a+r*c-i*s,this._c=t*s-n*c+r*a+i*o,this._d=t*c+n*s-r*o+i*a,this}invert(){let e=this.squaredNorm();return e<=0?null:this.conjugate().divideScalar(e)}divide(t){let{temporary:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}multiplyScalar(e){return this._a*=e,this._b*=e,this._c*=e,this._d*=e,this}divideScalar(e){return this._a/=e,this._b/=e,this._c/=e,this._d/=e,this}rotateX(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(0,0,1),t),this.multiply(n)}},v=0,y=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[v]}set x(e){this.elements[v]=e}static zero(){return new e(0)}static one(){return new e(1)}clone(){let{x:t}=this;return new e(t)}isZero(){return this.x===0}set(e){return this.x=e,this}copy(e){return this.x=e.x,this}add(e){return this.x+=e.x,this}subtract(e){return this.x-=e.x,this}multiplyScalar(e){return this.x*=e,this}divideScalar(e){return this.x/=e,this}length(){return Math.abs(this.x)}normalize(){return this.x/=this.length(),this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0);return this.set(r),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},b=0,x=1,S=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[b]}set x(e){this.elements[b]=e}get y(){return this.elements[x]}set y(e){this.elements[x]=e}static zero(){return new e(0,0)}static one(){return new e(1,1)}clone(){let{x:t,y:n}=this;return new e(t,n)}isZero(){let{x:e,y:t}=this;return e===0&&t===0}set(e,t){return this.x=e,this.y=t,this}copy(e){let{x:t,y:n}=e;return this.set(t,n)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this}length(){let{x:e,y:t}=this;return Math.sqrt(e**2+t**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}rotate(e){let{cos:t,sin:n}=Math,r=this.x*t(e)-this.y*n(e),i=this.x*n(e)+this.y*t(e);return this.x=r,this.y=i,this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0);return this.set(r,i),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};exports.Matrix3=h,exports.Matrix4=l,exports.PolarCoordinate3=g,exports.Quaternion=_,exports.Vector1=y,exports.Vector2=S,exports.Vector3=p,exports.Vector4=s,exports.range=e,exports.sum=t,exports.sumMap=n;
|