(function(p,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(p=typeof globalThis<"u"?globalThis:p||self,S(p.vectrix={}))})(this,function(p){"use strict";var lt=Object.defineProperty;var ft=(p,S,I)=>S in p?lt(p,S,{enumerable:!0,configurable:!0,writable:!0,value:I}):p[S]=I;var N=(p,S,I)=>(ft(p,typeof S!="symbol"?S+"":S,I),I);function S(o){function t(a,...s){if(s[0]===a)return a;const u=a.dimension,e=[];t:for(const c of s){if(Number.isFinite(c))e.push(c);else if(c&&typeof c=="object"&&typeof c[Symbol.iterator]=="function"){for(const h of c)if(e.push(Number.isFinite(h)?h:0),e.length>=u)break t}else e.push(0);if(e.length>=u)break}if(e.lengthu)return!1;return!0}function x(a,s,u=o()){for(let e=0;enew C);class C extends ${constructor(...t){super(),B.set(this,...t)}get dimension(){return 2}set(...t){return B.set(this,...t)}clone(t){return B.clone(this,t)}equals(t,r){return B.equals(this,t,r)}add(t,r=this){return B.add(this,t,r)}subtract(t,r=this){return B.subtract(this,t,r)}scale(t,r=this){return B.scale(this,t,r)}normalize(t=this){return B.normalize(this,t)}transform(t,r=this){return B.transform(this,t,r)}dot(t){return B.dot(this,t)}zero(){return B.zero(this)}toArray(){return B.toArray(this)}}const K=Object.assign((...o)=>new C(...o),B);class F extends ${get 2(){return this._nums[2]}set 2(t){this._nums[2]=t}get z(){return this[2]}set z(t){this[2]=t}get xz(){return new C(this.x,this.z)}get yz(){return new C(this.y,this.z)}get zx(){return new C(this.z,this.x)}get zy(){return new C(this.z,this.y)}get xyz(){return new m(this.x,this.y,this.z)}get xzy(){return new m(this.x,this.z,this.y)}get yxz(){return new m(this.y,this.x,this.z)}get yzx(){return new m(this.y,this.z,this.x)}get zxy(){return new m(this.z,this.x,this.y)}get zyx(){return new m(this.z,this.y,this.x)}}function Q(o){function t(r,l,x=o()){const[P,A,_]=r,[v,D,E]=l;return x[0]=A*E-_*D,x[1]=_*v-P*E,x[2]=P*D-A*v,x}return{...S(o),cross:t}}const q=Q(()=>new m);class m extends F{constructor(...t){super(),q.set(this,...t)}get dimension(){return 3}set(...t){return q.set(this,...t)}clone(t){return q.clone(this,t)}equals(t,r){return q.equals(this,t,r)}add(t,r=this){return q.add(this,t,r)}subtract(t,r=this){return q.subtract(this,t,r)}scale(t,r=this){return q.scale(this,t,r)}normalize(t=this){return q.normalize(this,t)}transform(t,r=this){return q.transform(this,t,r)}dot(t){return q.dot(this,t)}cross(t,r=this){return q.cross(this,t,r)}zero(){return q.zero(this)}toArray(){return q.toArray(this)}}const W=Object.assign((...o)=>new m(...o),q);class tt extends F{get 3(){return this._nums[3]}set 3(t){this._nums[3]=t}get w(){return this[3]}set w(t){this[3]=t}get xw(){return new C(this.x,this.w)}get yw(){return new C(this.y,this.w)}get zw(){return new C(this.z,this.w)}get wx(){return new C(this.w,this.x)}get wy(){return new C(this.w,this.y)}get wz(){return new C(this.w,this.z)}get xyw(){return new m(this.x,this.y,this.w)}get xzw(){return new m(this.x,this.z,this.w)}get xwy(){return new m(this.x,this.w,this.y)}get xwz(){return new m(this.x,this.w,this.z)}get yxw(){return new m(this.y,this.x,this.w)}get yzw(){return new m(this.y,this.z,this.w)}get ywx(){return new m(this.y,this.w,this.x)}get ywz(){return new m(this.y,this.w,this.z)}get zxw(){return new m(this.z,this.x,this.w)}get zyw(){return new m(this.z,this.y,this.w)}get zwx(){return new m(this.z,this.w,this.x)}get zwy(){return new m(this.z,this.w,this.y)}get wxy(){return new m(this.w,this.x,this.y)}get wxz(){return new m(this.w,this.x,this.z)}get wyx(){return new m(this.w,this.y,this.x)}get wyz(){return new m(this.w,this.y,this.z)}get wzx(){return new m(this.w,this.z,this.x)}get wzy(){return new m(this.w,this.z,this.y)}get xyzw(){return new d(this.x,this.y,this.z,this.w)}get xywz(){return new d(this.x,this.y,this.w,this.z)}get xzyw(){return new d(this.x,this.z,this.y,this.w)}get xzwy(){return new d(this.x,this.z,this.w,this.y)}get xwyz(){return new d(this.x,this.w,this.y,this.z)}get xwzy(){return new d(this.x,this.w,this.z,this.y)}get yxzw(){return new d(this.y,this.x,this.z,this.w)}get yxwz(){return new d(this.y,this.x,this.w,this.z)}get yzxw(){return new d(this.y,this.z,this.x,this.w)}get yzwx(){return new d(this.y,this.z,this.w,this.x)}get ywxz(){return new d(this.y,this.w,this.x,this.z)}get ywzx(){return new d(this.y,this.w,this.z,this.x)}get zxyw(){return new d(this.z,this.x,this.y,this.w)}get zxwy(){return new d(this.z,this.x,this.w,this.y)}get zyxw(){return new d(this.z,this.y,this.x,this.w)}get zywx(){return new d(this.z,this.y,this.w,this.x)}get zwxy(){return new d(this.z,this.w,this.x,this.y)}get zwyx(){return new d(this.z,this.w,this.y,this.x)}get wxyz(){return new d(this.w,this.x,this.y,this.z)}get wxzy(){return new d(this.w,this.x,this.z,this.y)}get wyxz(){return new d(this.w,this.y,this.x,this.z)}get wyzx(){return new d(this.w,this.y,this.z,this.x)}get wzxy(){return new d(this.w,this.z,this.x,this.y)}get wzyx(){return new d(this.w,this.z,this.y,this.x)}}const R=S(()=>new d);class d extends tt{constructor(...t){super(),R.set(this,...t)}get dimension(){return 4}set(...t){return R.set(this,...t)}clone(t){return R.clone(this,t)}equals(t,r){return R.equals(this,t,r)}add(t,r=this){return R.add(this,t,r)}subtract(t,r=this){return R.subtract(this,t,r)}scale(t,r=this){return R.scale(this,t,r)}normalize(t=this){return R.normalize(this,t)}transform(t,r=this){return R.transform(this,t,r)}dot(t){return R.dot(this,t)}zero(){return R.zero(this)}toArray(){return R.toArray(this)}}const rt=Object.assign((...o)=>new d(...o),R);class et{constructor(){N(this,"_vecs",[])}[Symbol.iterator](){return this._vecs[Symbol.iterator]()}}class H extends et{get 0(){return this._vecs[0]}set 0(t){this._vecs[0].set(t)}get 1(){return this._vecs[1]}set 1(t){this._vecs[1].set(t)}}function U(o,t){function r(n,...i){if(i[0]===n)return n;const y=n.dimension,w=[];for(let f=0;f=i.length)break t;const G=i[O];w[f][V]=Number.isFinite(G)?G:0}else if(i[0]&&typeof i[0]=="object"&&typeof i[0][Symbol.iterator]=="function")for(let f=0;f=i.length);f++)w[f].set(i[f]);return n._vecs=w,n}function l(n,i=t()){return r(i,n)}function x(n,i,y=0){for(let w=0;wi.toArray()).flat()}function c(n){return e(v(n))}function h(n){return b(n)}function b(n){return n._vecs.map(i=>i.toArray())}function g(n){return b(v(n))}return{set:r,clone:l,equals:x,multiplyScalar:P,multiply:A,multiplication:_,transpose:v,minor:D,cofactor:E,determinant:L,invert:a,identity:s,toArray:u,toColMajorArray:e,toRowMajorArray:c,toArray2D:h,toColMajorArray2D:b,toRowMajorArray2D:g}}function nt(){return{...U(()=>new C,()=>new k)}}const j=nt();class k extends H{constructor(...t){super(),j.set(this,...t)}get dimension(){return 2}_sub(t,r){return this[(t+1)%2][(r+1)%2]}set(...t){return j.set(this,...t)}clone(t){return j.clone(this,t)}equals(t,r){return j.equals(this,t,r)}multiplyScalar(t,r=this){return j.multiplyScalar(this,t,r)}multiply(t,r=this){return j.multiply(this,t,r)}multiplication(t,r=this){return j.multiplication(t,r)}transpose(t=this){return j.transpose(this,t)}minor(t,r){return j.minor(this,t,r)}cofactor(t,r){return j.cofactor(this,t,r)}determinant(){return j.determinant(this)}invert(t=this){return j.invert(this,t)}identity(){return j.identity(this)}toArray(){return j.toArray(this)}toColMajorArray(){return j.toColMajorArray(this)}toRowMajorArray(){return j.toRowMajorArray(this)}toArray2D(){return j.toArray2D(this)}toColMajorArray2D(){return j.toColMajorArray2D(this)}toRowMajorArray2D(){return j.toRowMajorArray2D(this)}}const st=Object.assign((...o)=>new k(...o),j);class J extends H{get 2(){return this._vecs[2]}set 2(t){this._vecs[2].set(t)}}function it(){const o=()=>new m,t=()=>new T,r=U(o,t);function l(A,_,v=t()){const D=[1,0,0,0,1,0,A,_,1];return r.set(v,D)}function x(A,_,v=t()){const D=[A,0,0,0,_,0,0,0,1];return r.set(v,D)}function P(A,_=t()){const v=Math.cos(A),D=Math.sin(A),E=[v,D,0,-D,v,0,0,0,1];return r.set(_,E)}return{...r,translation:l,scaling:x,rotation:P}}const M=it();class T extends J{constructor(...t){super(),M.set(this,...t)}get dimension(){return 3}_sub(t,r){const l=this.toColMajorArray2D();l.splice(t,1);for(const x of l)x.splice(r,1);return new k(l)}set(...t){return M.set(this,...t)}clone(t){return M.clone(this,t)}equals(t,r){return M.equals(this,t,r)}multiplyScalar(t,r=this){return M.multiplyScalar(this,t,r)}multiply(t,r=this){return M.multiply(this,t,r)}multiplication(t,r=this){return M.multiplication(t,r)}transpose(t=this){return M.transpose(this,t)}minor(t,r){return M.minor(this,t,r)}cofactor(t,r){return M.cofactor(this,t,r)}determinant(){return M.determinant(this)}invert(t=this){return M.invert(this,t)}identity(){return M.identity(this)}translation(t,r,l=this){return M.translation(t,r,l)}scaling(t,r,l=this){return M.scaling(t,r,l)}rotation(t,r=this){return M.rotation(t,r)}toArray(){return M.toArray(this)}toColMajorArray(){return M.toColMajorArray(this)}toRowMajorArray(){return M.toRowMajorArray(this)}toArray2D(){return M.toArray2D(this)}toColMajorArray2D(){return M.toColMajorArray2D(this)}toRowMajorArray2D(){return M.toRowMajorArray2D(this)}}const ot=Object.assign((...o)=>new T(...o),M);class ut extends J{get 3(){return this._vecs[3]}set 3(t){this._vecs[3].set(t)}}const ht=[1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18,1e-19,1e-20,1e-21],X={WEBGL:{left:-1,right:1,bottom:-1,top:1,near:-1,far:1},WEBGPU:{left:-1,right:1,bottom:-1,top:1,near:0,far:1}};function ct(){const o=()=>new d,t=()=>new Y,r=U(o,t);function l(s,u,e,c=t()){const h=[1,0,0,0,0,1,0,0,0,0,1,0,s,u,e,1];return r.set(c,h)}function x(s,u,e,c=t()){const h=[s,0,0,0,0,u,0,0,0,0,e,0,0,0,0,1];return r.set(c,h)}function P(s,u=t()){const e=Math.cos(s),c=Math.sin(s),h=[1,0,0,0,0,e,c,0,0,-c,e,0,0,0,0,1];return r.set(u,h)}function A(s,u=t()){const e=Math.cos(s),c=Math.sin(s),h=[e,0,-c,0,0,1,0,0,c,0,e,0,0,0,0,1];return r.set(u,h)}function _(s,u=t()){const e=Math.cos(s),c=Math.sin(s),h=[e,c,0,0,-c,e,0,0,0,0,1,0,0,0,0,1];return r.set(u,h)}function v(s,u,e,c=t()){return r.multiplication([_(e),A(u),P(s)],c)}function D(s,u,e,c,h,b,g=X.WEBGL,n=t()){const i=u-s,y=c-e,w=b-h,f=(g.right-g.left)/i,V=(g.top-g.bottom)/y,O=-(g.far-g.near)/w,G=(g.left*u-g.right*s)/i,Z=(g.bottom*c-g.top*e)/y,yt=(g.near*b-g.far*h)/w,wt=[f,0,0,0,0,V,0,0,0,0,O,0,G,Z,yt,1];return r.set(n,wt)}function E(s,u,e,c,h=X.WEBGL,b=t()){const n=1/Math.tan(s/2),i=(h.top-h.bottom)*n/2,y=(h.top+h.bottom)/2,w=(h.right-h.left)*n/(2*u),f=(h.right+h.left)/2,V=-1/(c-e),O=(h.far*c-h.near*e)*V,G=(h.far-h.near)*e*c*V,Z=[w,0,0,0,0,i,0,0,f,y,O,-1,0,0,G,0];return r.set(b,Z)}function L(s,u,e,c=t()){if(s.equals(u))return r.identity();const h=W.subtract(s,u).normalize(),b=W.cross(e,h).normalize(),g=W.cross(h,b).normalize(),n=[b.x,b.y,b.z,0,g.x,g.y,g.z,0,h.x,h.y,h.z,0,s.x,s.y,s.z,1];return r.set(c,n)}function a(s,u,e,c=t()){return r.invert(L(s,u,e,c))}return{...r,translation:l,scaling:x,rotationX:P,rotationY:A,rotationZ:_,rotationXYZ:v,orthographic:D,perspective:E,targetTo:L,lookAt:a}}const z=ct();class Y extends ut{constructor(...t){super(),z.set(this,...t)}get dimension(){return 4}_sub(t,r){const l=this.toColMajorArray2D();l.splice(t,1);for(const x of l)x.splice(r,1);return new T(l)}set(...t){return z.set(this,...t)}clone(t){return z.clone(this,t)}equals(t,r){return z.equals(this,t,r)}multiplyScalar(t,r=this){return z.multiplyScalar(this,t,r)}multiply(t,r=this){return z.multiply(this,t,r)}multiplication(t,r=this){return z.multiplication(t,r)}transpose(t=this){return z.transpose(this,t)}minor(t,r){return z.minor(this,t,r)}cofactor(t,r){return z.cofactor(this,t,r)}determinant(){return z.determinant(this)}invert(t=this){return z.invert(this,t)}identity(){return z.identity(this)}toArray(){return z.toArray(this)}translation(t,r,l,x=this){return z.translation(t,r,l,x)}scaling(t,r,l,x=this){return z.scaling(t,r,l,x)}rotationX(t,r=this){return z.rotationX(t,r)}rotationY(t,r=this){return z.rotationY(t,r)}rotationZ(t,r=this){return z.rotationZ(t,r)}rotationXYZ(t,r,l,x=this){return z.rotationXYZ(t,r,l,x)}orthographic(t,r,l,x,P,A,_,v=this){return z.orthographic(t,r,l,x,P,A,_,v)}perspective(t,r,l,x,P,A=this){return z.perspective(t,r,l,x,P,A)}targetTo(t,r,l,x=this){return z.targetTo(t,r,l,x)}lookAt(t,r,l,x=this){return z.lookAt(t,r,l,x)}toColMajorArray(){return z.toColMajorArray(this)}toRowMajorArray(){return z.toRowMajorArray(this)}toArray2D(){return z.toArray2D(this)}toColMajorArray2D(){return z.toColMajorArray2D(this)}toRowMajorArray2D(){return z.toRowMajorArray2D(this)}}const at=Object.assign((...o)=>new Y(...o),z);p.CLIP=X,p.Matrix2=k,p.Matrix3=T,p.Matrix4=Y,p.PRECISION=ht,p.Vector2=C,p.Vector3=m,p.Vector4=d,p.mat2=st,p.mat3=ot,p.mat4=at,p.vec2=K,p.vec3=W,p.vec4=rt,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});