mathue 0.1.2 → 0.1.3
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/README.md +53 -0
- package/dist/index.d.ts +60 -0
- package/dist/mathue.cjs +1 -1
- package/dist/mathue.js +30 -0
- package/dist/mathue.umd.cjs +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -79,6 +79,59 @@ model.setIdentity()
|
|
|
79
79
|
.multiplyScale(scale);
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
```ts
|
|
83
|
+
// Calculates view matrix
|
|
84
|
+
const phi = 0.25 * Math.PI;
|
|
85
|
+
const theta = 0.5 * Math.PI;
|
|
86
|
+
const radius = 2;
|
|
87
|
+
const polar = new PolarCoordinate3(phi, theta, radius);
|
|
88
|
+
|
|
89
|
+
// A camera on a sphere looking at the origin
|
|
90
|
+
const target = Vector3.zero();
|
|
91
|
+
const position = Vector3.zero();
|
|
92
|
+
const up = Vector3.zero();
|
|
93
|
+
polar.toVector3(position);
|
|
94
|
+
polar.toTangentZ(tangent);
|
|
95
|
+
|
|
96
|
+
const view = Matrix4.identity();
|
|
97
|
+
view.lookAt(position, target, up);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// Calculates projection matrix (Perspective camera)
|
|
102
|
+
const {projection, clientSize, _verticalFov, _near, _far} = this;
|
|
103
|
+
const verticalFov = 0.5 * Math.PI;
|
|
104
|
+
const near = 0.1;
|
|
105
|
+
const far = 4.0;
|
|
106
|
+
const aspect = 1.5; // width / height
|
|
107
|
+
|
|
108
|
+
// for WebGL, OpenGL, ...
|
|
109
|
+
const projection = Matrix4.identity();
|
|
110
|
+
projection.perspective(verticalFov, near, far, aspect);
|
|
111
|
+
|
|
112
|
+
// for WebGPU, Vulkan, DirectX, Metal, ...
|
|
113
|
+
const options = { depthZeroToOne: true };
|
|
114
|
+
projection.perspective(verticalFov, near, far, aspect, options);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// Calculates projection matrix (Orthographic camera)
|
|
119
|
+
const left = -3;
|
|
120
|
+
const right = 3;
|
|
121
|
+
const bottom = -2;
|
|
122
|
+
const top = 2;
|
|
123
|
+
const near = 0.1;
|
|
124
|
+
const far = 4.0;
|
|
125
|
+
|
|
126
|
+
// for WebGL, OpenGL, ...
|
|
127
|
+
const projection = Matrix4.identity();
|
|
128
|
+
projection.orthographic(left, right, bottom, top, near, far);
|
|
129
|
+
|
|
130
|
+
// for WebGPU, Vulkan, DirectX, Metal, ...
|
|
131
|
+
const options = { depthZeroToOne: true };
|
|
132
|
+
projection.orthographic(left, right, bottom, top, near, far, options);
|
|
133
|
+
```
|
|
134
|
+
|
|
82
135
|
<br>
|
|
83
136
|
|
|
84
137
|
## 📚 API Overview
|
package/dist/index.d.ts
CHANGED
|
@@ -1275,6 +1275,12 @@ export declare class Vector1 implements Vector<1>, AdditiveGroup<Vector1>, Scala
|
|
|
1275
1275
|
* ```
|
|
1276
1276
|
*/
|
|
1277
1277
|
set x(x: number);
|
|
1278
|
+
/**
|
|
1279
|
+
* Sets x component (mutate this)
|
|
1280
|
+
* @param x
|
|
1281
|
+
* @returns this instance, for method chaining
|
|
1282
|
+
*/
|
|
1283
|
+
setX(x: number): Vector1;
|
|
1278
1284
|
/**
|
|
1279
1285
|
* Creates a zero vector instance
|
|
1280
1286
|
* @returns new zero vector instance
|
|
@@ -1513,6 +1519,18 @@ export declare class Vector2 implements Vector<2>, AdditiveGroup<Vector2>, Scala
|
|
|
1513
1519
|
* ```
|
|
1514
1520
|
*/
|
|
1515
1521
|
set y(y: number);
|
|
1522
|
+
/**
|
|
1523
|
+
* Sets x component (mutate this)
|
|
1524
|
+
* @param x
|
|
1525
|
+
* @returns this instance, for method chaining
|
|
1526
|
+
*/
|
|
1527
|
+
setX(x: number): Vector2;
|
|
1528
|
+
/**
|
|
1529
|
+
* Sets y component (mutate this)
|
|
1530
|
+
* @param y
|
|
1531
|
+
* @returns this instance, for method chaining
|
|
1532
|
+
*/
|
|
1533
|
+
setY(y: number): Vector2;
|
|
1516
1534
|
/**
|
|
1517
1535
|
* Creates a zero vector instance
|
|
1518
1536
|
* @returns new zero vector instance
|
|
@@ -1780,6 +1798,24 @@ export declare class Vector3 implements Vector<3>, AdditiveGroup<Vector3>, Scala
|
|
|
1780
1798
|
* ```
|
|
1781
1799
|
*/
|
|
1782
1800
|
set z(z: number);
|
|
1801
|
+
/**
|
|
1802
|
+
* Sets x component (mutate this)
|
|
1803
|
+
* @param x
|
|
1804
|
+
* @returns this instance, for method chaining
|
|
1805
|
+
*/
|
|
1806
|
+
setX(x: number): Vector3;
|
|
1807
|
+
/**
|
|
1808
|
+
* Sets y component (mutate this)
|
|
1809
|
+
* @param y
|
|
1810
|
+
* @returns this instance, for method chaining
|
|
1811
|
+
*/
|
|
1812
|
+
setY(y: number): Vector3;
|
|
1813
|
+
/**
|
|
1814
|
+
* Sets z component (mutate this)
|
|
1815
|
+
* @param z
|
|
1816
|
+
* @returns this instance, for method chaining
|
|
1817
|
+
*/
|
|
1818
|
+
setZ(z: number): Vector3;
|
|
1783
1819
|
/**
|
|
1784
1820
|
* Creates a zero vector instance
|
|
1785
1821
|
* @returns new zero vector instance
|
|
@@ -2081,6 +2117,30 @@ export declare class Vector4 implements Vector<4>, AdditiveGroup<Vector4>, Scala
|
|
|
2081
2117
|
* ```
|
|
2082
2118
|
*/
|
|
2083
2119
|
set w(w: number);
|
|
2120
|
+
/**
|
|
2121
|
+
* Sets x component (mutate this)
|
|
2122
|
+
* @param x
|
|
2123
|
+
* @returns this instance, for method chaining
|
|
2124
|
+
*/
|
|
2125
|
+
setX(x: number): Vector4;
|
|
2126
|
+
/**
|
|
2127
|
+
* Sets y component (mutate this)
|
|
2128
|
+
* @param y
|
|
2129
|
+
* @returns this instance, for method chaining
|
|
2130
|
+
*/
|
|
2131
|
+
setY(y: number): Vector4;
|
|
2132
|
+
/**
|
|
2133
|
+
* Sets z component (mutate this)
|
|
2134
|
+
* @param z
|
|
2135
|
+
* @returns this instance, for method chaining
|
|
2136
|
+
*/
|
|
2137
|
+
setZ(z: number): Vector4;
|
|
2138
|
+
/**
|
|
2139
|
+
* Sets w component (mutate this)
|
|
2140
|
+
* @param w
|
|
2141
|
+
* @returns this instance, for method chaining
|
|
2142
|
+
*/
|
|
2143
|
+
setW(w: number): Vector4;
|
|
2084
2144
|
/**
|
|
2085
2145
|
* Creates a zero vector instance
|
|
2086
2146
|
* @returns new zero vector instance
|
package/dist/mathue.cjs
CHANGED
|
@@ -1 +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||=u.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.setRotation(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=!1,u=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}setScale(t){this.setIdentity();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}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(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}multiplyScale(e){return this.multiply(t.tmpMatrix.setScale(e))}multiplyTranslation(e){return this.multiply(t.tmpMatrix.setTranslation(e))}multiplyRotation(e){return this.multiply(t.tmpMatrix.setRotation(e))}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}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}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??l,c=t-e,u=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/u,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/u,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??l,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return 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}},d=0,f=1,p=2,m=!1,h=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[d]}set x(e){this.elements[d]=e}get y(){return this.elements[f]}set y(e){this.elements[f]=e}get z(){return this.elements[p]}set z(e){this.elements[p]=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,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??m,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},g=1e-8,_=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||=h.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)<g)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}},v=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)}},y=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 h(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,0,1),t),this.multiply(n)}},b=0,x=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[b]}set x(e){this.elements[b]=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.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},S=0,C=1,w=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[S]}set x(e){this.elements[S]=e}get y(){return this.elements[C]}set y(e){this.elements[C]=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.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};exports.Matrix3=_,exports.Matrix4=u,exports.PolarCoordinate3=v,exports.Quaternion=y,exports.Vector1=x,exports.Vector2=w,exports.Vector3=h,exports.Vector4=s,exports.range=e,exports.sum=t,exports.sumMap=n;
|
|
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||=u.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}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}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.setRotation(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=!1,u=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}setScale(t){this.setIdentity();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}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(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}multiplyScale(e){return this.multiply(t.tmpMatrix.setScale(e))}multiplyTranslation(e){return this.multiply(t.tmpMatrix.setTranslation(e))}multiplyRotation(e){return this.multiply(t.tmpMatrix.setRotation(e))}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}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}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??l,c=t-e,u=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/u,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/u,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??l,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return 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}},d=0,f=1,p=2,m=!1,h=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[d]}set x(e){this.elements[d]=e}get y(){return this.elements[f]}set y(e){this.elements[f]=e}get z(){return this.elements[p]}set z(e){this.elements[p]=e}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}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,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??m,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},g=1e-8,_=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||=h.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)<g)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}},v=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)}},y=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 h(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,0,1),t),this.multiply(n)}},b=0,x=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[b]}set x(e){this.elements[b]=e}setX(e){return this.x=e,this}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.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},S=0,C=1,w=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[S]}set x(e){this.elements[S]=e}get y(){return this.elements[C]}set y(e){this.elements[C]=e}setX(e){return this.x=e,this}setY(e){return this.y=e,this}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.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};exports.Matrix3=_,exports.Matrix4=u,exports.PolarCoordinate3=v,exports.Quaternion=y,exports.Vector1=x,exports.Vector2=w,exports.Vector3=h,exports.Vector4=s,exports.range=e,exports.sum=t,exports.sumMap=n;
|
package/dist/mathue.js
CHANGED
|
@@ -51,6 +51,18 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
51
51
|
set w(e) {
|
|
52
52
|
this.elements[INDEX_W] = e;
|
|
53
53
|
}
|
|
54
|
+
setX(e) {
|
|
55
|
+
return this.x = e, this;
|
|
56
|
+
}
|
|
57
|
+
setY(e) {
|
|
58
|
+
return this.y = e, this;
|
|
59
|
+
}
|
|
60
|
+
setZ(e) {
|
|
61
|
+
return this.z = e, this;
|
|
62
|
+
}
|
|
63
|
+
setW(e) {
|
|
64
|
+
return this.w = e, this;
|
|
65
|
+
}
|
|
54
66
|
static zero() {
|
|
55
67
|
return new e(0, 0, 0, 0);
|
|
56
68
|
}
|
|
@@ -276,6 +288,15 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
276
288
|
set z(e) {
|
|
277
289
|
this.elements[INDEX_Z] = e;
|
|
278
290
|
}
|
|
291
|
+
setX(e) {
|
|
292
|
+
return this.x = e, this;
|
|
293
|
+
}
|
|
294
|
+
setY(e) {
|
|
295
|
+
return this.y = e, this;
|
|
296
|
+
}
|
|
297
|
+
setZ(e) {
|
|
298
|
+
return this.z = e, this;
|
|
299
|
+
}
|
|
279
300
|
static zero() {
|
|
280
301
|
return new e(0, 0, 0);
|
|
281
302
|
}
|
|
@@ -573,6 +594,9 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
573
594
|
set x(e) {
|
|
574
595
|
this.elements[INDEX_X$1] = e;
|
|
575
596
|
}
|
|
597
|
+
setX(e) {
|
|
598
|
+
return this.x = e, this;
|
|
599
|
+
}
|
|
576
600
|
static zero() {
|
|
577
601
|
return new e(0);
|
|
578
602
|
}
|
|
@@ -654,6 +678,12 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
654
678
|
set y(e) {
|
|
655
679
|
this.elements[INDEX_Y] = e;
|
|
656
680
|
}
|
|
681
|
+
setX(e) {
|
|
682
|
+
return this.x = e, this;
|
|
683
|
+
}
|
|
684
|
+
setY(e) {
|
|
685
|
+
return this.y = e, this;
|
|
686
|
+
}
|
|
657
687
|
static zero() {
|
|
658
688
|
return new e(0, 0);
|
|
659
689
|
}
|
package/dist/mathue.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.mathue={}))})(this,function(e){function*t(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 n(e){let t=0;for(let n of e)t+=n;return t}function r(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var i=0,a=1,o=2,s=3,c=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[i]}set x(e){this.elements[i]=e}get y(){return this.elements[a]}set y(e){this.elements[a]=e}get z(){return this.elements[o]}set z(e){this.elements[o]=e}get w(){return this.elements[s]}set w(e){this.elements[s]=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.setRotation(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},l=1e-8,u=!1,d=class e{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=c.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 e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new e(t,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}setScale(e){this.setIdentity();let{order:n}=this;for(let r of t(n)){let i=r===n-1?1:e.elements[r];for(let e of t(n)){let t=r*n+e;this.elements[t]*=i}}return this}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(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(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;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}multiplyScale(t){return this.multiply(e.tmpMatrix.setScale(t))}multiplyTranslation(t){return this.multiply(e.tmpMatrix.setTranslation(t))}multiplyRotation(t){return this.multiply(e.tmpMatrix.setRotation(t))}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)<l)return null;let[t,n,r,i,a,o,s,c,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-c*g,S=o*_-c*h,C=o*g-s*h,w=s*p-c*f,T=o*p-c*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-c*m,A=a*g-s*m,j=a*p-c*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+c*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+c*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+c*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(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:c}=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<l)return this;u/=p,d/=p,f/=p;let m=s*f-c*d,h=c*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}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??u,c=t-e,l=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/l,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/l,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??u,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return this}_applyVector(t,n,r,i){let{tmpVector:a}=e;a.set(t,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*t+u*n+m*r+v*i,C=s*t+d*n+h*r+y*i,w=c*t+f*n+g*r+b*i,T=l*t+p*n+_*r+x*i;return a.set(S,C,w,T),a}},f=0,p=1,m=2,h=!1,g=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[f]}set x(e){this.elements[f]=e}get y(){return this.elements[p]}set y(e){this.elements[p]=e}get z(){return this.elements[m]}set z(e){this.elements[m]=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,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??h,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},_=1e-8,v=class e{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=g.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 e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l]=this.elements;return new e(t,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(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;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)<_)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(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}_applyVector(t,n,r){let{tmpVector:i}=e;i.set(t,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*t+c*n+d*r,h=o*t+l*n+f*r,g=s*t+u*n+p*r;return i.set(m,h,g),i}},y=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)}},b=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 g(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,0,1),t),this.multiply(n)}},x=0,S=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[x]}set x(e){this.elements[x]=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.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},C=0,w=1,T=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[C]}set x(e){this.elements[C]=e}get y(){return this.elements[w]}set y(e){this.elements[w]=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.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};e.Matrix3=v,e.Matrix4=d,e.PolarCoordinate3=y,e.Quaternion=b,e.Vector1=S,e.Vector2=T,e.Vector3=g,e.Vector4=c,e.range=t,e.sum=n,e.sumMap=r});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.mathue={}))})(this,function(e){function*t(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 n(e){let t=0;for(let n of e)t+=n;return t}function r(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var i=0,a=1,o=2,s=3,c=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[i]}set x(e){this.elements[i]=e}get y(){return this.elements[a]}set y(e){this.elements[a]=e}get z(){return this.elements[o]}set z(e){this.elements[o]=e}get w(){return this.elements[s]}set w(e){this.elements[s]=e}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}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.setRotation(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},l=1e-8,u=!1,d=class e{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=c.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 e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new e(t,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}setScale(e){this.setIdentity();let{order:n}=this;for(let r of t(n)){let i=r===n-1?1:e.elements[r];for(let e of t(n)){let t=r*n+e;this.elements[t]*=i}}return this}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(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(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;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}multiplyScale(t){return this.multiply(e.tmpMatrix.setScale(t))}multiplyTranslation(t){return this.multiply(e.tmpMatrix.setTranslation(t))}multiplyRotation(t){return this.multiply(e.tmpMatrix.setRotation(t))}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)<l)return null;let[t,n,r,i,a,o,s,c,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-c*g,S=o*_-c*h,C=o*g-s*h,w=s*p-c*f,T=o*p-c*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-c*m,A=a*g-s*m,j=a*p-c*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+c*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+c*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+c*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(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:c}=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<l)return this;u/=p,d/=p,f/=p;let m=s*f-c*d,h=c*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}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??u,c=t-e,l=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/l,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/l,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??u,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return this}_applyVector(t,n,r,i){let{tmpVector:a}=e;a.set(t,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*t+u*n+m*r+v*i,C=s*t+d*n+h*r+y*i,w=c*t+f*n+g*r+b*i,T=l*t+p*n+_*r+x*i;return a.set(S,C,w,T),a}},f=0,p=1,m=2,h=!1,g=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[f]}set x(e){this.elements[f]=e}get y(){return this.elements[p]}set y(e){this.elements[p]=e}get z(){return this.elements[m]}set z(e){this.elements[m]=e}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}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,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??h,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},_=1e-8,v=class e{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=g.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 e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l]=this.elements;return new e(t,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(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;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)<_)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(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}_applyVector(t,n,r){let{tmpVector:i}=e;i.set(t,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*t+c*n+d*r,h=o*t+l*n+f*r,g=s*t+u*n+p*r;return i.set(m,h,g),i}},y=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)}},b=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 g(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,0,1),t),this.multiply(n)}},x=0,S=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[x]}set x(e){this.elements[x]=e}setX(e){return this.x=e,this}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.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},C=0,w=1,T=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[C]}set x(e){this.elements[C]=e}get y(){return this.elements[w]}set y(e){this.elements[w]=e}setX(e){return this.x=e,this}setY(e){return this.y=e,this}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.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};e.Matrix3=v,e.Matrix4=d,e.PolarCoordinate3=y,e.Quaternion=b,e.Vector1=S,e.Vector2=T,e.Vector3=g,e.Vector4=c,e.range=t,e.sum=n,e.sumMap=r});
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathue",
|
|
3
3
|
"description": "TypeScript math library",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"main": "dist/mathue.js",
|
|
9
|
+
"browser": "./dist/mathue.umd.cjs",
|
|
10
|
+
"unpkg": "./dist/mathue.umd.cjs",
|
|
11
|
+
"jsdelivr": "./dist/mathue.umd.cjs",
|
|
9
12
|
"files": [
|
|
10
13
|
"dist"
|
|
11
14
|
],
|