mathue 0.1.1 → 0.1.2

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/dist/index.d.ts CHANGED
@@ -3,6 +3,21 @@ export declare interface AdditiveGroup<T> {
3
3
  subtract(other: T): T;
4
4
  }
5
5
 
6
+ /**
7
+ * Options for transforming a 3D vector by a 4x4 matrix.
8
+ */
9
+ export declare type ApplyMatrix4Options = {
10
+ /**
11
+ * Determines whether the vector is treated as a direction or a point.
12
+ *
13
+ * - `true`: Treated as a **direction** (w = 0).
14
+ * - `false` (default): Treated as a **point** (w = 1).
15
+ *
16
+ * @default false
17
+ */
18
+ asDirection?: boolean;
19
+ };
20
+
6
21
  export declare interface Clonable<T> {
7
22
  clone(): T;
8
23
  }
@@ -656,12 +671,25 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
656
671
  * ```
657
672
  */
658
673
  lookAt(position: Vector3, target: Vector3, up: Vector3): Matrix4;
674
+ /**
675
+ * Sets projection matrix of orthographic camera (mutates this)
676
+ * @param left left boundary of the view frustum (negative X coordinate)
677
+ * @param right right boundary of the view frustum (positive X coordinate)
678
+ * @param bottom bottom boundary of the view frustum (negative Y coordinate)
679
+ * @param top top boundary of the view frustum (positive Y coordinate)
680
+ * @param near near clipping plane distance (positive value)
681
+ * @param far far clipping plane distance (positive value)
682
+ * @param options options for orthographic projection matrix
683
+ * @returns this instance, for method chaining
684
+ */
685
+ orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number, options?: ProjectionOptions): Matrix4;
659
686
  /**
660
687
  * Sets projection matrix of perspective camera (mutates this)
661
688
  * @param verticalFov vertical field of view in radians
662
689
  * @param near near clipping plane distance
663
690
  * @param far far clipping plane distance
664
691
  * @param aspect aspect ratio (width / height)
692
+ * @param options options for perspective projection matrix
665
693
  * @returns this instance, for method chaining
666
694
  *
667
695
  * @example
@@ -671,10 +699,15 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
671
699
  * const near = 0.01;
672
700
  * const far = 4.0;
673
701
  * const aspect = 300 / 150;
702
+ *
703
+ * // for OpenGL, WebGL
674
704
  * m.perspective(fov, near, far, aspect);
705
+ *
706
+ * // for WebGPU, Vulkan, DirectX, Metal
707
+ * m.perspective(fov, near, far, aspect, {depthZeroToOne: true});
675
708
  * ```
676
709
  */
677
- perspective(verticalFov: number, near: number, far: number, aspect: number): Matrix4;
710
+ perspective(verticalFov: number, near: number, far: number, aspect: number, options?: ProjectionOptions): Matrix4;
678
711
  /** @ignore */
679
712
  _applyVector(x: number, y: number, z: number, w: number): Vector4;
680
713
  }
@@ -717,27 +750,27 @@ export declare class PolarCoordinate3 {
717
750
  private _theta;
718
751
  private _radius;
719
752
  /**
720
- * @param phi polar angle phi in range [0, π] in radians
721
- * @param theta azimuthal angle theta in range [0, 2π] in radians
753
+ * @param phi azimuthal angle theta in range [0, 2π] in radians
754
+ * @param theta polar angle phi in range [0, π] in radians
722
755
  * @param radius radial distance from the origin, must be non-negative
723
756
  */
724
757
  constructor(phi: number, theta: number, radius: number);
725
758
  /**
726
- * Gets polar angle phi in range [0, π] in radians, measured from positive z-axis.
759
+ * Gets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
727
760
  */
728
761
  get phi(): number;
729
762
  /**
730
- * Sets polar angle phi in range [0, π] in radians, measured from positive z-axis.
731
- * @param value polar angle in range [0, π]
763
+ * Sets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
764
+ * @param value azimuthal angle in range [0, 2π]
732
765
  */
733
766
  set phi(value: number);
734
767
  /**
735
- * Gets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
768
+ * Gets polar angle phi in range [0, π] in radians, measured from positive z-axis.
736
769
  */
737
770
  get theta(): number;
738
771
  /**
739
- * Sets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
740
- * @param value azimuthal angle in range [0, 2π]
772
+ * Sets polar angle phi in range [0, π] in radians, measured from positive z-axis.
773
+ * @param value polar angle in range [0, π]
741
774
  */
742
775
  set theta(value: number);
743
776
  /**
@@ -749,19 +782,36 @@ export declare class PolarCoordinate3 {
749
782
  */
750
783
  set radius(value: number);
751
784
  /**
752
- * Converts polar coordinate to Vector3 and stores result in `out` vector.
785
+ * Converts polar coordinate to Vector3 and stores result in `out` vector. (mutates out)
753
786
  * @param out vector instance to receive result
754
787
  * @returns {void}
755
788
  */
756
789
  toVector3(out: Vector3): void;
757
790
  /**
758
- * Converts to tangent vector pointing positive z-axis direction, and sotres result in `out` vector.
791
+ * Converts to tangent vector pointing positive z-axis direction, and sotres result in `out` vector. (mutates out)
759
792
  * @param out vector instance to receive result
760
793
  * @returns {void}
761
794
  */
762
795
  toTangentZ(out: Vector3): void;
763
796
  }
764
797
 
798
+ /**
799
+ * Options for generating a projection matrix.
800
+ */
801
+ export declare type ProjectionOptions = {
802
+ /**
803
+ * Determines the normalized device coordinate (NDC) Z range for the clip planes. [1, 2]
804
+ *
805
+ * - `false` (default): Corresponds to a Z range of **[-1, 1]**, which matches the clip volume
806
+ * requirements for **WebGL and OpenGL**. [1]
807
+ * - `true`: Corresponds to a Z range of ****, which matches the clip volume
808
+ * requirements for modern APIs such as **WebGPU, Vulkan, DirectX, and Metal**. [2]
809
+ *
810
+ * @default false
811
+ */
812
+ depthZeroToOne?: boolean;
813
+ };
814
+
765
815
  /**
766
816
  * Represents a quaternion using Hamilton's notation: q = a + bi + cj + dk
767
817
  */
@@ -1925,9 +1975,10 @@ export declare class Vector3 implements Vector<3>, AdditiveGroup<Vector3>, Scala
1925
1975
  /**
1926
1976
  * Applies matrix to this vector (mutates this)
1927
1977
  * @param matrix
1978
+ * @param options
1928
1979
  * @returns this instance, for method chaining
1929
1980
  */
1930
- applyMatrix4(matrix: Matrix4): Vector3;
1981
+ applyMatrix4(matrix: Matrix4, options?: ApplyMatrix4Options): Vector3;
1931
1982
  /**
1932
1983
  * Applies quaternion to this vector (mutates this)
1933
1984
  * @param quaternion
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||=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.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=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,[i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y]=this.elements;return this.setIdentity(),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}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}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.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}},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.setRotation(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.setRotation(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;
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;
package/dist/mathue.js CHANGED
@@ -104,7 +104,7 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
104
104
  let { x: r, y: i, z: a, w: o } = this, s = n._applyVector(r, i, a, o);
105
105
  return this.copy(s), this;
106
106
  }
107
- }, EPSILON$1 = 1e-8, Matrix4 = class t {
107
+ }, EPSILON$1 = 1e-8, DEFAULT_DEPTH_ZERO_TO_ONE = !1, Matrix4 = class t {
108
108
  order = 4;
109
109
  elements;
110
110
  static _tmpMatrix;
@@ -151,12 +151,12 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
151
151
  return this;
152
152
  }
153
153
  setTranslation(e) {
154
- 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;
155
- return this.setIdentity(), 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;
154
+ let { x: t, y: n, z: r } = e;
155
+ return this.setIdentity(), this.elements[12] = t, this.elements[13] = n, this.elements[14] = r, this;
156
156
  }
157
157
  setRotation(e) {
158
158
  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;
159
- 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;
159
+ 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;
160
160
  }
161
161
  add(t) {
162
162
  let { order: n } = this;
@@ -220,9 +220,19 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
220
220
  let S = -(m * r + h * i + g * a), C = -(v * r + y * i + b * a), w = -(u * r + d * i + f * a);
221
221
  return this.set(m, v, u, 0, h, y, d, 0, g, b, f, 0, S, C, w, 1), this;
222
222
  }
223
- perspective(e, t, n, r) {
224
- let i = 1 / Math.tan(e / 2);
225
- return this.set(i / r, 0, 0, 0, 0, i, 0, 0, 0, 0, 1, -1, 0, 0, 1, 0), n === Infinity ? (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;
223
+ orthographic(e, t, n, r, i, a, o) {
224
+ let s = o?.depthZeroToOne ?? DEFAULT_DEPTH_ZERO_TO_ONE, 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;
225
+ return this.set(2 / c, 0, 0, 0, 0, 2 / u, 0, 0, 0, 0, f, 0, p, m, h, 1), this;
226
+ }
227
+ perspective(e, t, n, r, i) {
228
+ let a = 1 / Math.tan(e / 2);
229
+ this.set(a / r, 0, 0, 0, 0, a, 0, 0, 0, 0, 1, -1, 0, 0, 1, 0);
230
+ let o = i?.depthZeroToOne ?? DEFAULT_DEPTH_ZERO_TO_ONE, s = o ? 1 : 2;
231
+ if (n !== Infinity) {
232
+ let e = o ? n : n + t;
233
+ this.elements[10] = -e / (n - t), this.elements[14] = -s * n * t / (n - t);
234
+ } else this.elements[10] = -1, this.elements[14] = -s * t;
235
+ return this;
226
236
  }
227
237
  _applyVector(e, n, r, i) {
228
238
  let { tmpVector: a } = t;
@@ -230,7 +240,7 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
230
240
  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;
231
241
  return a.set(S, C, w, T), a;
232
242
  }
233
- }, INDEX_X$2 = 0, INDEX_Y$1 = 1, INDEX_Z = 2, Vector3 = class e {
243
+ }, INDEX_X$2 = 0, INDEX_Y$1 = 1, INDEX_Z = 2, DEFAULT_AS_DIRECTION = !1, Vector3 = class e {
234
244
  dimension = 3;
235
245
  elements;
236
246
  static _tmpMatrix3;
@@ -320,11 +330,11 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
320
330
  let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z);
321
331
  return this.set(r, i, a), this;
322
332
  }
323
- applyMatrix4(t) {
324
- let { tmpMatrix4: n } = e;
325
- n.copy(t);
326
- let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z, 0);
327
- return this.set(r, i, a), this;
333
+ applyMatrix4(t, n) {
334
+ let { tmpMatrix4: r } = e;
335
+ r.copy(t);
336
+ let i = n?.asDirection ?? DEFAULT_AS_DIRECTION, 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;
337
+ return this.set(u, d, f), this;
328
338
  }
329
339
  applyQuaternion(t) {
330
340
  let { tmpMatrix4: n } = e;
@@ -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||=u.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=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,[i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y]=this.elements;return this.setIdentity(),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}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}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(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}},d=0,f=1,p=2,m=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.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){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.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}},h=1e-8,g=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||=m.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)<h)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}},_=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)}},v=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 m(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new m(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new m(0,0,1),t),this.multiply(n)}},y=0,b=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.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[y]}set x(e){this.elements[y]=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}},x=0,S=1,C=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.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[x]}set x(e){this.elements[x]=e}get y(){return this.elements[S]}set y(e){this.elements[S]=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=g,e.Matrix4=u,e.PolarCoordinate3=_,e.Quaternion=v,e.Vector1=b,e.Vector2=C,e.Vector3=m,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}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});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mathue",
3
3
  "description": "TypeScript math library",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
@@ -45,7 +45,10 @@
45
45
  "preview": "vite preview",
46
46
  "test": "vitest run",
47
47
  "test:cov": "vitest run --coverage",
48
- "docs": "typedoc"
48
+ "docs": "typedoc",
49
+ "version:major": "npm version major --git-tag-version false",
50
+ "version:minor": "npm version minor --git-tag-version false",
51
+ "version:patch": "npm version patch --git-tag-version false"
49
52
  },
50
53
  "devDependencies": {
51
54
  "@types/node": "^24.9.2",