function _usingCtx2(){var r="function"==typeof SuppressedError?SuppressedError:function(r,n){var e=new Error;return e.name="SuppressedError",e.suppressed=n,e.error=r,e},n={},e=[];function using(r,n){if(null!=n){if(Object(n)!==n)throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");if(r)var o=n[Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose")];if(null==o&&(o=n[Symbol.dispose||Symbol.for("Symbol.dispose")]),"function"!=typeof o)throw new TypeError("Property [Symbol.dispose] is not a function.");e.push({v:n,d:o,a:r})}return n}return{e:n,u:using.bind(null,!1),a:using.bind(null,!0),d:function(){var o=this.e;function next(){for(;r=e.pop();)try{var r,t=r.d.call(r.v);if(r.a)return Promise.resolve(t).then(next,err)}catch(r){return err(r)}if(o!==n)throw o}function err(e){return o=o!==n?new r(o,e):e,next()}return next()}}}import{EPSILON,fequal}from"../scalar.js";import{dot,normalize}from"./helpers.js";import{BYTES_PER_FLOAT64,ManagedFloat64Array,memoryManager}from"./memory.js";import{Vec3}from"./vec.js";const ID=[0,0,0,1];export class Quat extends ManagedFloat64Array{static identity(){const q=new Quat(memoryManager.create(4));q.set(ID);return q}static fromUnitVecs(from,to){try{var _usingCtx=_usingCtx2();const dot=from.dot(to);if(fequal(dot,-1))try{var _usingCtx3=_usingCtx2();const[,y,z]=from;const v=_usingCtx3.u(new Vec3(0,z,-y));return Quat.fromAxisAngle(v,Math.PI)}catch(_){_usingCtx3.e=_}finally{_usingCtx3.d()}else if(fequal(dot,1)){return Quat.identity()}const v=_usingCtx.u(new Vec3);v.copy(from,0,0,3);v.cross(to);const q=new Quat(memoryManager.create(4));q.set([...v,1+dot]);q.normalize();return q}catch(_){_usingCtx.e=_}finally{_usingCtx.d()}}static fromAxisAngle(axis,angle){const view=memoryManager.view;const ptr=axis.byteOffset/BYTES_PER_FLOAT64;const sinHalf=Math.sin(angle/2);const q=new Quat(memoryManager.create(4));q.set([view[ptr+0]*sinHalf,view[ptr+1]*sinHalf,view[ptr+2]*sinHalf,Math.cos(angle/2)]);return q}static fromAngleX(angle){const q=new Quat(memoryManager.create(4));q.set([Math.sin(angle/2),0,0,Math.cos(angle/2)]);return q}static fromAngleY(angle){const q=new Quat(memoryManager.create(4));q.set([0,Math.sin(angle/2),0,Math.cos(angle/2)]);return q}static fromAngleZ(angle){const q=new Quat(memoryManager.create(4));q.set([0,0,Math.sin(angle/2),Math.cos(angle/2)]);return q}constructor(ptr){super(ptr)}get length(){return 4}mul(rhs){const left=this.byteOffset/BYTES_PER_FLOAT64|0;const right=rhs.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;const x=view[left+3]*view[right+0]+view[left+0]*view[right+3]+view[left+1]*view[right+2]-view[left+2]*view[right+1];const y=view[left+3]*view[right+1]+view[left+1]*view[right+3]+view[left+2]*view[right+0]-view[left+0]*view[right+2];const z=view[left+3]*view[right+2]+view[left+2]*view[right+3]+view[left+0]*view[right+1]-view[left+1]*view[right+0];const w=view[left+3]*view[right+3]-view[left+0]*view[right+0]-view[left+1]*view[right+1]-view[left+2]*view[right+2];view[left+0]=x;view[left+1]=y;view[left+2]=z;view[left+3]=w;return this}rotate(v){try{var _usingCtx4=_usingCtx2();const view=memoryManager.view;const q1=_usingCtx4.u(new Quat(memoryManager.create(4)));const q2=_usingCtx4.u(new Quat(memoryManager.create(4)));q1.copy(this,0,0,4);q2.copy(v,0,0,3);view[q2.byteOffset/BYTES_PER_FLOAT64+3|0]=0;q1.mul(q2);q2.copy(this,0,0,4);q2.invert();q1.mul(q2);v.copy(q1,0,0,3);return v}catch(_){_usingCtx4.e=_}finally{_usingCtx4.d()}}dot(rhs){return dot(this,rhs)}lerp(rhs,t){const left=this.byteOffset/BYTES_PER_FLOAT64|0;const right=rhs.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;const cosTheta=dot(this,rhs);const magB=cosTheta<0?-1:1;for(let i=0;iEPSILON){const theta=Math.acos(cosTheta);const sinTheta=Math.sin(theta);scale0=Math.sin((1-t)*theta)/sinTheta;scale1=Math.sin(t*theta)/sinTheta}scale1*=magB;for(let i=0;i