@hatiolab/things-scene 10.0.0-beta.98 → 10.0.0-beta.99

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.
@@ -3,4 +3,4 @@ const t={x:0,y:0,z:0,w:1};function e(t){const e=t/2;return{x:0,y:Math.sin(e),z:0
3
3
  * @license
4
4
  * Copyright 2010-2026 Three.js Authors
5
5
  * SPDX-License-Identifier: MIT
6
- */const u=2e3;function d(...t){t=function(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return t}(t);const e="THREE."+t.shift();{const s=t[0];s&&s.isStackTrace?console.warn(s.getError(e)):console.warn(e,...t)}}function y(t,e,s){return Math.max(e,Math.min(s,t))}class _{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let h=s[i+0],a=s[i+1],c=s[i+2],l=s[i+3],u=r[n+0],d=r[n+1],y=r[n+2],_=r[n+3];if(l!==_||h!==u||a!==d||c!==y){let t=h*u+a*d+c*y+l*_;t<0&&(u=-u,d=-d,y=-y,_=-_,t=-t);let e=1-o;if(t<.9995){const s=Math.acos(t),i=Math.sin(s);e=Math.sin(e*s)/i,h=h*e+u*(o=Math.sin(o*s)/i),a=a*e+d*o,c=c*e+y*o,l=l*e+_*o}else{h=h*e+u*o,a=a*e+d*o,c=c*e+y*o,l=l*e+_*o;const t=1/Math.sqrt(h*h+a*a+c*c+l*l);h*=t,a*=t,c*=t,l*=t}}t[e]=h,t[e+1]=a,t[e+2]=c,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],h=s[i+1],a=s[i+2],c=s[i+3],l=r[n],u=r[n+1],d=r[n+2],y=r[n+3];return t[e]=o*y+c*l+h*d-a*u,t[e+1]=h*y+c*u+a*l-o*d,t[e+2]=a*y+c*d+o*u-h*l,t[e+3]=c*y-o*l-h*u-a*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,h=Math.sin,a=o(s/2),c=o(i/2),l=o(r/2),u=h(s/2),y=h(i/2),_=h(r/2);switch(n){case"XYZ":this._x=u*c*l+a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l-u*y*_;break;case"YXZ":this._x=u*c*l+a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l+u*y*_;break;case"ZXY":this._x=u*c*l-a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l-u*y*_;break;case"ZYX":this._x=u*c*l-a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l+u*y*_;break;case"YZX":this._x=u*c*l+a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l-u*y*_;break;case"XZY":this._x=u*c*l-a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l+u*y*_;break;default:d("Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],h=e[9],a=e[2],c=e[6],l=e[10],u=s+o+l;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(c-h)*t,this._y=(r-a)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(c-h)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+a)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-a)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(h+c)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+a)/t,this._y=(h+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(y(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,h=e._y,a=e._z,c=e._w;return this._x=s*c+n*o+i*a-r*h,this._y=i*c+n*h+r*o-s*a,this._z=r*c+n*a+s*h-i*o,this._w=n*c-s*o-i*h-r*a,this._onChangeCallback(),this}slerp(t,e){let s=t._x,i=t._y,r=t._z,n=t._w,o=this.dot(t);o<0&&(s=-s,i=-i,r=-r,n=-n,o=-o);let h=1-e;if(o<.9995){const t=Math.acos(o),a=Math.sin(t);h=Math.sin(h*t)/a,e=Math.sin(e*t)/a,this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+r*e,this._w=this._w*h+n*e,this._onChangeCallback()}else this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+r*e,this._w=this._w*h+n*e,this.normalize();return this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class x{constructor(t=0,e=0,s=0){x.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(p.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(p.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,h=t.w,a=2*(n*i-o*s),c=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+h*a+n*l-o*c,this.y=s+h*c+o*a-r*l,this.z=i+h*l+r*c-n*a,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=y(this.x,t.x,e.x),this.y=y(this.y,t.y,e.y),this.z=y(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=y(this.x,t,e),this.y=y(this.y,t,e),this.z=y(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(y(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,h=e.z;return this.x=i*h-r*o,this.y=r*n-s*h,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return m.copy(this).projectOnVector(t),this.sub(m)}reflect(t){return this.sub(m.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(y(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const m=new x,p=new _;class f{constructor(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x){f.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x)}set(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x){const m=this.elements;return m[0]=t,m[4]=e,m[8]=s,m[12]=i,m[1]=r,m[5]=n,m[9]=o,m[13]=h,m[2]=a,m[6]=c,m[10]=l,m[14]=u,m[3]=d,m[7]=y,m[11]=_,m[15]=x,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new f).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,s=t.elements,i=1/g.setFromMatrixColumn(t,0).length(),r=1/g.setFromMatrixColumn(t,1).length(),n=1/g.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),h=Math.cos(i),a=Math.sin(i),c=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=h*c,e[4]=-h*l,e[8]=a,e[1]=s+i*a,e[5]=t-r*a,e[9]=-o*h,e[2]=r-t*a,e[6]=i+s*a,e[10]=n*h}else if("YXZ"===t.order){const t=h*c,s=h*l,i=a*c,r=a*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*a,e[1]=n*l,e[5]=n*c,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*h}else if("ZXY"===t.order){const t=h*c,s=h*l,i=a*c,r=a*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*c,e[9]=r-t*o,e[2]=-n*a,e[6]=o,e[10]=n*h}else if("ZYX"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=h*c,e[4]=i*a-s,e[8]=t*a+r,e[1]=h*l,e[5]=r*a+t,e[9]=s*a-i,e[2]=-a,e[6]=o*h,e[10]=n*h}else if("YZX"===t.order){const t=n*h,s=n*a,i=o*h,r=o*a;e[0]=h*c,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*c,e[9]=-o*c,e[2]=-a*c,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*h,s=n*a,i=o*h,r=o*a;e[0]=h*c,e[4]=-l,e[8]=a*c,e[1]=t*l+r,e[5]=n*c,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*c,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(M,t,w)}lookAt(t,e,s){const i=this.elements;return C.subVectors(t,e),0===C.lengthSq()&&(C.z=1),C.normalize(),b.crossVectors(s,C),0===b.lengthSq()&&(1===Math.abs(s.z)?C.x+=1e-4:C.z+=1e-4,C.normalize(),b.crossVectors(s,C)),b.normalize(),S.crossVectors(C,b),i[0]=b.x,i[4]=S.x,i[8]=C.x,i[1]=b.y,i[5]=S.y,i[9]=C.y,i[2]=b.z,i[6]=S.z,i[10]=C.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],h=s[8],a=s[12],c=s[1],l=s[5],u=s[9],d=s[13],y=s[2],_=s[6],x=s[10],m=s[14],p=s[3],f=s[7],g=s[11],z=s[15],M=i[0],w=i[4],b=i[8],S=i[12],C=i[1],k=i[5],v=i[9],R=i[13],I=i[2],E=i[6],F=i[10],T=i[14],N=i[3],A=i[7],j=i[11],q=i[15];return r[0]=n*M+o*C+h*I+a*N,r[4]=n*w+o*k+h*E+a*A,r[8]=n*b+o*v+h*F+a*j,r[12]=n*S+o*R+h*T+a*q,r[1]=c*M+l*C+u*I+d*N,r[5]=c*w+l*k+u*E+d*A,r[9]=c*b+l*v+u*F+d*j,r[13]=c*S+l*R+u*T+d*q,r[2]=y*M+_*C+x*I+m*N,r[6]=y*w+_*k+x*E+m*A,r[10]=y*b+_*v+x*F+m*j,r[14]=y*S+_*R+x*T+m*q,r[3]=p*M+f*C+g*I+z*N,r[7]=p*w+f*k+g*E+z*A,r[11]=p*b+f*v+g*F+z*j,r[15]=p*S+f*R+g*T+z*q,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],h=t[9],a=t[13],c=t[2],l=t[6],u=t[10],d=t[14],y=t[3],_=t[7],x=t[11],m=t[15],p=h*d-a*u,f=o*d-a*l,g=o*u-h*l,z=n*d-a*c,M=n*u-h*c,w=n*l-o*c;return e*(_*p-x*f+m*g)-s*(y*p-x*z+m*M)+i*(y*f-_*z+m*w)-r*(y*g-_*M+x*w)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],h=t[6],a=t[7],c=t[8],l=t[9],u=t[10],d=t[11],y=t[12],_=t[13],x=t[14],m=t[15],p=e*o-s*n,f=e*h-i*n,g=e*a-r*n,z=s*h-i*o,M=s*a-r*o,w=i*a-r*h,b=c*_-l*y,S=c*x-u*y,C=c*m-d*y,k=l*x-u*_,v=l*m-d*_,R=u*m-d*x,I=p*R-f*v+g*k+z*C-M*S+w*b;if(0===I)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/I;return t[0]=(o*R-h*v+a*k)*E,t[1]=(i*v-s*R-r*k)*E,t[2]=(_*w-x*M+m*z)*E,t[3]=(u*M-l*w-d*z)*E,t[4]=(h*C-n*R-a*S)*E,t[5]=(e*R-i*C+r*S)*E,t[6]=(x*g-y*w-m*f)*E,t[7]=(c*w-u*g+d*f)*E,t[8]=(n*v-o*C+a*b)*E,t[9]=(s*C-e*v-r*b)*E,t[10]=(y*M-_*g+m*p)*E,t[11]=(l*g-c*M-d*p)*E,t[12]=(o*S-n*k-h*b)*E,t[13]=(e*k-s*S+i*b)*E,t[14]=(_*f-y*z-x*p)*E,t[15]=(c*z-l*f+u*p)*E,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,h=t.z,a=r*n,c=r*o;return this.set(a*n+s,a*o-i*h,a*h+i*o,0,a*o+i*h,c*o+s,c*h-i*n,0,a*h-i*o,c*h+i*n,r*h*h+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,h=e._w,a=r+r,c=n+n,l=o+o,u=r*a,d=r*c,y=r*l,_=n*c,x=n*l,m=o*l,p=h*a,f=h*c,g=h*l,z=s.x,M=s.y,w=s.z;return i[0]=(1-(_+m))*z,i[1]=(d+g)*z,i[2]=(y-f)*z,i[3]=0,i[4]=(d-g)*M,i[5]=(1-(u+m))*M,i[6]=(x+p)*M,i[7]=0,i[8]=(y+f)*w,i[9]=(x-p)*w,i[10]=(1-(u+_))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return s.set(1,1,1),e.identity(),this;let n=g.set(i[0],i[1],i[2]).length();const o=g.set(i[4],i[5],i[6]).length(),h=g.set(i[8],i[9],i[10]).length();r<0&&(n=-n),z.copy(this);const a=1/n,c=1/o,l=1/h;return z.elements[0]*=a,z.elements[1]*=a,z.elements[2]*=a,z.elements[4]*=c,z.elements[5]*=c,z.elements[6]*=c,z.elements[8]*=l,z.elements[9]*=l,z.elements[10]*=l,e.setFromRotationMatrix(z),s.x=n,s.y=o,s.z=h,this}makePerspective(t,e,s,i,r,n,o=2e3,h=!1){const a=this.elements,c=2*r/(e-t),l=2*r/(s-i),d=(e+t)/(e-t),y=(s+i)/(s-i);let _,x;if(h)_=r/(n-r),x=n*r/(n-r);else if(o===u)_=-(n+r)/(n-r),x=-2*n*r/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);_=-n/(n-r),x=-n*r/(n-r)}return a[0]=c,a[4]=0,a[8]=d,a[12]=0,a[1]=0,a[5]=l,a[9]=y,a[13]=0,a[2]=0,a[6]=0,a[10]=_,a[14]=x,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3,h=!1){const a=this.elements,c=2/(e-t),l=2/(s-i),d=-(e+t)/(e-t),y=-(s+i)/(s-i);let _,x;if(h)_=1/(n-r),x=n/(n-r);else if(o===u)_=-2/(n-r),x=-(n+r)/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);_=-1/(n-r),x=-r/(n-r)}return a[0]=c,a[4]=0,a[8]=0,a[12]=d,a[1]=0,a[5]=l,a[9]=0,a[13]=y,a[2]=0,a[6]=0,a[10]=_,a[14]=x,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const g=new x,z=new f,M=new x(0,0,0),w=new x(1,1,1),b=new x,S=new x,C=new x,k=new f,v=new _;class R{constructor(t=0,e=0,s=0,i=R.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],h=i[1],a=i[5],c=i[9],l=i[2],u=i[6],_=i[10];switch(e){case"XYZ":this._y=Math.asin(y(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,_),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,a),this._z=0);break;case"YXZ":this._x=Math.asin(-y(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(o,_),this._z=Math.atan2(h,a)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(y(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-l,_),this._z=Math.atan2(-n,a)):(this._y=0,this._z=Math.atan2(h,r));break;case"ZYX":this._y=Math.asin(-y(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(u,_),this._z=Math.atan2(h,r)):(this._x=0,this._z=Math.atan2(-n,a));break;case"YZX":this._z=Math.asin(y(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(-c,a),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,_));break;case"XZY":this._z=Math.asin(-y(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,a),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-c,_),this._y=0);break;default:d("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return k.makeRotationFromQuaternion(t),this.setFromRotationMatrix(k,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return v.setFromEuler(this),this.setFromQuaternion(v,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}R.DEFAULT_ORDER="XYZ","undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"183"}})),"undefined"!=typeof window&&(window.__THREE__?d("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="183");const I=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};function E(t){if(!t)return;const e=t?.state?.id??t?.id;return"string"==typeof e?e:void 0}function F(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},s=t.sourceId??E(t.source),i=t.targetId??E(t.target),r=t.carrierId??E(t.carrier);return void 0!==s&&(e.sourceId=s),void 0!==i&&(e.targetId=i),void 0!==r&&(e.carrierId=r),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=I);let T=1;class N{constructor(t){this._phase="pending",this._slot=null,this.id="xfer-"+T++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:I.now}}get phase(){return this._phase}get timeline(){return this._timeline}async execute(){this._phase="planning",this._timeline.planStartAt=I.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return A.append(e),e}this._slot=t.slot}else{if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return A.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}if(this._timeline.planEndAt=I.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=I.now;try{await this.physical()}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return A.append(e),e}this._timeline.physicalEndAt=I.now}this._phase="handoff",this._timeline.handoffAt=I.now;const e=this.target.accept??this.target.receive;await e.call(this.target,this.carrier,this.options),this._phase="committed",this._timeline.committedAt=I.now;const s=this._buildReceipt();return A.append(s),s}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",A.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:E(this.source),targetId:E(this.target),carrierId:E(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason}}}const A=new class{constructor(){this._entries=[],this._maxEntries=1e3,this._listeners=new Set}append(t){this._entries.push(t),this._entries.length>this._maxEntries&&this._entries.shift(),this._listeners.forEach(e=>e(t))}entries(){return[...this._entries]}forCarrier(t){const e=E(t);return this._entries.filter(s=>s.carrier===t||e&&s.carrierId===e)}forCarrierId(t){return this._entries.filter(e=>e.carrierId===t)}forSourceId(t){return this._entries.filter(e=>e.sourceId===t)}forTargetId(t){return this._entries.filter(e=>e.targetId===t)}forPhase(t){return this._entries.filter(e=>e.phase===t)}inTimeRange(t,e,s="init"){return"init"===s?this._entries.filter(s=>s.timeline.initiatedAt>=t&&s.timeline.initiatedAt<=e):this._entries.filter(s=>{const i=s.timeline.initiatedAt,r=s.timeline.committedAt??s.timeline.handoffAt??s.timeline.physicalEndAt??s.timeline.planEndAt??i;return i<=e&&r>=t})}groupByRejectReason(){const t=new Map;for(const e of this._entries)if(e.rejectReason){const s=t.get(e.rejectReason)??[];s.push(e),t.set(e.rejectReason,s)}return t}stats(){const t=this._entries.length,e={};let s=0,i=0;for(const t of this._entries)e[t.phase]=(e[t.phase]??0)+1,"committed"===t.phase&&void 0!==t.timeline.committedAt&&(s+=t.timeline.committedAt-t.timeline.initiatedAt,i++);const r=e["rolled-back"]??0;return{total:t,byPhase:e,committed:e.committed??0,rolledBack:r,rejectionRate:t>0?r/t:0,avgTransferDurationMs:i>0?s/i:0}}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._entries.length=0}setMaxEntries(t){this._maxEntries=Math.max(1,t)}toJSON(){return this._entries.map(F)}fromJSON(t){this._entries=t.map(t=>({transferId:t.transferId,source:void 0,target:void 0,carrier:void 0,sourceId:t.sourceId,targetId:t.targetId,carrierId:t.carrierId,phase:t.phase,timeline:{...t.timeline},slotId:t.slotId,rejectReason:t.rejectReason}))}replayTo(t){for(const e of this._entries)t(e)}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=A);const j=new R,q="_transferSlotId";function P(t){return class extends t{get slots(){return[]}get arrangementStrategy(){return c}canReceive(t){return null!==this.findSlot(t)}findSlot(t){const e=this.slots;if(!e.length)return null;for(const s of e){if(s.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!s.allowedTypes.includes(e))continue}const e=s.maxCount??this.arrangementStrategy.capacity(s);if(!(this._countOccupied(s.id)>=e))return s}return null}async receive(t,e={}){const s=this.findSlot(t);if(!s)return void this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const i=this._countOccupied(s.id),r=this.arrangementStrategy.positionAt(i,s,i,t);t[q]=s.id;const{animated:n=!1,duration:o,ease:h}=e;this.reparent?.(t,{animated:n,duration:o,ease:h}),!n&&t._realObject&&(t._realObject.suppressTransform=!1);{const e=this._realObject?.receivingSurfaceY??0,i={};if(r&&(i.left=r.x,i.top=r.y),0!==e)i.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const t=this._realObject?.geometricOffsetY??0;i.zPos=s.localPosition.z+t}const n=this.acceptanceRotation?.(t,s);n&&(j.setFromQuaternion(new _(n.x,n.y,n.z,n.w),"XYZ"),i.rotationX=j.x,i.rotation=-j.y,i.rotationY=j.z),Object.keys(i).length&&t.setState?.(i)}this.trigger("transfer-received",{type:"transfer-received",component:t,container:this,slotId:s.id})}async dispatch(t,e,s={}){const i=new N({source:this,target:e,carrier:t,options:s,physical:async()=>{delete t[q]}}),r=await i.execute();"rolled-back"!==r.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:r.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}acceptanceRotation(t,e){}canAccept(t){const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const s=this.findSlot(t);if(!s){const s=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!s||t.allowedTypes.includes(s))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:s}}accept(t,e){return this.receive(t,e)}deliveryWorldRotation(t){const e=this.acceptanceRotation?.(t);if(!e)return;const s=this._realObject?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new _;s.getWorldQuaternion(i);const r=new _(e.x,e.y,e.z,e.w);return i.clone().multiply(r)}deliveryWorldPosition(t){const e=this._realObject,s=e?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new x;s.getWorldPosition(i);const r=e.receivingSurfaceY;if("number"==typeof r&&0!==r){const t=e.geometricOffsetY??0,n=new x(0,r-t,0);return s.localToWorld(n),{x:i.x,y:n.y,z:i.z}}return{x:i.x,y:i.y,z:i.z}}attachPointFor(t){const e=t?.[q];if(!e)return null;const s=this.slots.find(t=>t.id===e);return s?{position:s.localPosition??{x:0,y:0,z:0},rotation:s.localRotation??{x:0,y:0,z:0},slotId:s.id}:null}_countOccupied(t){const e=this.components;return e?e.filter(e=>e[q]===t).length:0}}}let Y=1;function O(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const L={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class X{constructor(t=L){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+Y++},s=(this._byResource.get(e.resource)??[]).filter(t=>O(t.timeWindow,e.timeWindow));if(0===s.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=s.map(t=>{const s=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:s}});if(i.every(t=>"b-yields"===t.decision)){const i=s.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:s.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>O(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const s=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);s<0?e.push(t):e.splice(s,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const s=e.findIndex(e=>e.id===t.id);if(s<0)return!1;e.splice(s,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const Z=new X;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=Z);class W{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,s=1/0;for(const i of this.nodes.values()){const r=V(i.position,t);r<s&&(s=r,e=i)}return e}}function V(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}function Q(t,e){return Math.sqrt(V(t,e))}function D(t,e,s={}){const i=new W,r=s.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const s=`${e.id}:start`,n=`${e.id}:end`;i.addNode({id:s,position:t[0],type:"lane-start"}),i.addNode({id:n,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:s,endNodeId:n});let o=0;for(let e=1;e<t.length;e++)o+=Q(t[e-1],t[e]);const h=o/(e.speedLimit??r)*1e3;i.addEdge({fromNode:s,toNode:n,resource:e.id,distance:o,durationMs:h,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:n,toNode:s,resource:e.id,distance:o,durationMs:h,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const s of t.lanes){const r=i.laneEndpoints.get(s);if(!r)continue;const n=i.nodes.get(r.startNodeId).position,o=i.nodes.get(r.endNodeId).position;let h=0,a=0,c=0;for(const e of t.lanes){if(e===s)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const r=i.nodes.get(t.startNodeId).position,l=i.nodes.get(t.endNodeId).position;h+=Math.min(V(n,r),V(n,l)),a+=Math.min(V(o,r),V(o,l)),c++}if(0===c)continue;const l=h<a?r.startNodeId:r.endNodeId;e.push({laneId:s,nodeId:l,pos:i.nodes.get(l).position})}for(let s=0;s<e.length;s++)for(let r=0;r<e.length;r++){if(s===r)continue;const n=e[s],o=e[r],h=Q(n.pos,o.pos);i.addEdge({fromNode:n.nodeId,toNode:o.nodeId,resource:t.id,distance:h,durationMs:t.crossingTimeMs,forward:!0})}}return i}function H(t,e,s,i={}){const r=t.nodes.get(e),n=t.nodes.get(s);if(!r||!n)return null;const o=i.speed?.max??100,h=e=>{const s=t.nodes.get(e);var i,r;return(i=s.position,r=n.position,Math.sqrt(function(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}(i,r)))/o*1e3},a=new Map,c=new Set,l=new Set,u={nodeId:e,gScore:0,fScore:h(e)};a.set(e,u),c.add(e);const d=i.startSimMs??0,y=i.deadlineSimMs;for(;c.size>0;){let e=null,i=null;for(const t of c){const s=a.get(t);(!i||s.fScore<i.fScore||s.fScore===i.fScore&&t<e)&&(i=s,e=t)}if(!i||!e)return null;if(e===s){const t=[];let e=i,s=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,r=d+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:r,endSimMs:r+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),s+=i.distance,e=a.get(i.fromNodeId)}const r=i.gScore;return void 0!==y&&d+r>y?null:{segments:t,totalDurationMs:r,totalDistance:s}}c.delete(e),l.add(e);for(const s of t.edgesFrom(e)){if(l.has(s.toNode))continue;const e=i.gScore+s.durationMs,r=a.get(s.toNode);if(!r||e<r.gScore){const i=t.nodes.get(s.fromNode),r=t.nodes.get(s.toNode),n={nodeId:s.toNode,gScore:e,fScore:e+h(s.toNode),cameFromEdge:{fromNodeId:s.fromNode,resource:s.resource,distance:s.distance,durationMs:s.durationMs,fromPos:i.position,toPos:r.position}};a.set(s.toNode,n),c.add(s.toNode)}}}return null}function B(t,e,s=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:s,metadata:i}))}const G=.5;function $(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=.5}function J(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n||!Number.isFinite(s)||Math.abs(s)<1e-9)return null;const o=Math.abs(s),h=(n*n+4*o*o)/(8*o),a=s>0?1:-1,c=h-o,l=(t.x+e.x)/2-a*(r/n)*c,u=(t.y+e.y)/2-a*-(i/n)*c;return{cx:l,cy:u,radius:h,startAngle:Math.atan2(t.y-u,t.x-l),endAngle:Math.atan2(e.y-u,e.x-l),clockwise:s<0}}function U(t,e,s=0,i=16){const r=e.x-t.x,n=e.y-t.y,o=Math.sqrt(r*r+n*n);if(0===o)return null;const h=n/o,a=-(r/o),c=Number.isFinite(s)?s:0,l=Math.abs(c)>=1e-6?c:i;return{x:(t.x+e.x)/2+h*l,y:(t.y+e.y)/2+a*l,perpX:h,perpY:a}}function K(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n)return 0;const o=r/n,h=-(i/n),a=(t.x+e.x)/2,c=(t.y+e.y)/2;let l=(s.x-a)*o+(s.y-c)*h;if(Math.abs(l)<.5)return 0;return l>n&&(l=n),l<-n&&(l=-n),l}function tt(t,e){const s=t.radius,i=Number.isFinite(e)?e:0;return null!=s&&Number.isFinite(s)?Math.max(0,s):Math.max(0,i)}function et(t,e,s,i,r=16){const n=t.x-e.x,o=t.y-e.y,h=Math.sqrt(n*n+o*o);if(0===h)return null;const a=s.x-e.x,c=s.y-e.y,l=Math.sqrt(a*a+c*c);if(0===l)return null;const u=n/h+a/l,d=o/h+c/l,y=Math.sqrt(u*u+d*d);if(y<1e-9)return null;const _=u/y,x=d/y,m=Math.max(i,r);return{x:e.x+_*m,y:e.y+x*m,bisectorX:_,bisectorY:x}}function st(t,e,s,i){const r=t.x-e.x,n=t.y-e.y,o=Math.sqrt(r*r+n*n),h=s.x-e.x,a=s.y-e.y,c=Math.sqrt(h*h+a*a);if(0===o||0===c)return 0;const l=r/o+h/c,u=n/o+a/c,d=Math.sqrt(l*l+u*u);if(d<1e-9)return 0;const y=l/d,_=u/d,x=(i.x-e.x)*y+(i.y-e.y)*_,m=Math.min(o,c)/2;return Math.max(0,Math.min(x,m))}function it(t){if(0===t.length)return 0;let e;for(const s of t){const t=s.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}const rt={closed:!0,round:0,divisions:24};class nt{constructor(t,e){this.points=t,this.closed=e;const s=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,r=t[e].y-t[e-1].y;s.push(s[e-1]+Math.sqrt(i*i+r*r))}this.cumulative=s,this.length=s[s.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let s=t;this.closed?s=(t%e+e)%e:s<0?s=0:s>e&&(s=e);const i=this.cumulative;let r=0,n=i.length-2;for(;r<n;){const t=r+n>>1;i[t+1]<=s?r=t+1:n=t}const o=i[r+1]-i[r],h=o>0?(s-i[r])/o:0,a=this.points[r],c=this.points[r+1],l=c.x-a.x,u=c.y-a.y;return{x:a.x+l*h,y:a.y+u*h,theta:0===l&&0===u?0:Math.atan2(u,l)}}}function ot(t,e={}){const s={...rt,...e},i=t.length;if(0===i)return new nt([],s.closed);if(1===i)return new nt([{x:t[0].x,y:t[0].y}],s.closed);const r=[],n=(t,e)=>{if(r.length>0){const s=r[r.length-1];if(Math.abs(s.x-t)<1e-9&&Math.abs(s.y-e)<1e-9)return}r.push({x:t,y:e})},o=(s.closed,i);for(let e=0;e<o;e++){const r=0===e?s.closed?i-1:-1:e-1,o=e===i-1?s.closed?0:-1:e+1,h=r>=0?t[r]:null,a=t[e],c=o>=0?t[o]:null;if(h&&h.x===a.x&&h.y===a.y)continue;const l=h&&c?tt(a,s.round):0;let u,d,y,_;if(h){const t=Math.sqrt((h.x-a.x)**2+(h.y-a.y)**2),e=0!==t?Math.atan2(h.x-a.x,h.y-a.y):0,s=Math.min(l,t/2);u=Math.sin(e)*s+a.x,d=Math.cos(e)*s+a.y}else u=a.x,d=a.y;if(c){const t=Math.sqrt((c.x-a.x)**2+(c.y-a.y)**2),e=0!==t?Math.atan2(c.x-a.x,c.y-a.y):0,s=Math.min(l,t/2);y=Math.sin(e)*s+a.x,_=Math.cos(e)*s+a.y}else y=a.x,_=a.y;if(n(u,d),l>0&&h&&c)for(let t=1;t<=s.divisions;t++){const e=t/s.divisions,i=1-e;n(i*i*u+2*i*e*a.x+e*e*y,i*i*d+2*i*e*a.y+e*e*_)}else u===y&&d===_||n(y,_);if(c&&$(a)){const t=tt(c,s.round),e=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),i=0!==e?Math.atan2(a.x-c.x,a.y-c.y):0,r=Math.min(t,e/2),o=J({x:y,y:_},{x:Math.sin(i)*r+c.x,y:Math.cos(i)*r+c.y},a.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=s.divisions;e++){const i=e/s.divisions,r=o.startAngle+t*i;n(o.cx+o.radius*Math.cos(r),o.cy+o.radius*Math.sin(r))}}}}if(s.closed&&r.length>0){const t=r[0],e=r[r.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&r.push({x:t.x,y:t.y})}return new nt(r,s.closed)}function ht(t,e){return ot(t,e).length}export{G as BULGE_EPSILON,l as CenteringSlotStrategy,P as ContainerCapacity,a as FixedSlotStrategy,W as NavGraph,nt as PolygonPathPolyline,X as ReservationTable,q as TRANSFER_SLOT_KEY,N as Transfer,D as buildNavGraph,K as bulgeFromDrag,U as bulgeHandlePosition,h as chooseNearestPickupFrame,J as computeArcParams,et as cornerHandlePosition,st as cornerRadiusFromDrag,tt as effectiveCornerRadius,o as filterByToolType,c as fixedSlotStrategy,ot as flattenPolygonPath,I as globalSimClock,$ as hasArc,H as planPathAStar,B as planToReservations,ht as polygonPathLength,e as quatFromYaw,F as receiptToJSON,r as rectangularFootprintFrames,Z as reservationTable,L as standardYieldPolicy,n as topApproachFrame,A as transferLog,it as uniformZ};
6
+ */const u=2e3;function d(...t){t=function(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return t}(t);const e="THREE."+t.shift();{const s=t[0];s&&s.isStackTrace?console.warn(s.getError(e)):console.warn(e,...t)}}function y(t,e,s){return Math.max(e,Math.min(s,t))}class _{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let h=s[i+0],a=s[i+1],c=s[i+2],l=s[i+3],u=r[n+0],d=r[n+1],y=r[n+2],_=r[n+3];if(l!==_||h!==u||a!==d||c!==y){let t=h*u+a*d+c*y+l*_;t<0&&(u=-u,d=-d,y=-y,_=-_,t=-t);let e=1-o;if(t<.9995){const s=Math.acos(t),i=Math.sin(s);e=Math.sin(e*s)/i,h=h*e+u*(o=Math.sin(o*s)/i),a=a*e+d*o,c=c*e+y*o,l=l*e+_*o}else{h=h*e+u*o,a=a*e+d*o,c=c*e+y*o,l=l*e+_*o;const t=1/Math.sqrt(h*h+a*a+c*c+l*l);h*=t,a*=t,c*=t,l*=t}}t[e]=h,t[e+1]=a,t[e+2]=c,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],h=s[i+1],a=s[i+2],c=s[i+3],l=r[n],u=r[n+1],d=r[n+2],y=r[n+3];return t[e]=o*y+c*l+h*d-a*u,t[e+1]=h*y+c*u+a*l-o*d,t[e+2]=a*y+c*d+o*u-h*l,t[e+3]=c*y-o*l-h*u-a*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,h=Math.sin,a=o(s/2),c=o(i/2),l=o(r/2),u=h(s/2),y=h(i/2),_=h(r/2);switch(n){case"XYZ":this._x=u*c*l+a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l-u*y*_;break;case"YXZ":this._x=u*c*l+a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l+u*y*_;break;case"ZXY":this._x=u*c*l-a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l-u*y*_;break;case"ZYX":this._x=u*c*l-a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l+u*y*_;break;case"YZX":this._x=u*c*l+a*y*_,this._y=a*y*l+u*c*_,this._z=a*c*_-u*y*l,this._w=a*c*l-u*y*_;break;case"XZY":this._x=u*c*l-a*y*_,this._y=a*y*l-u*c*_,this._z=a*c*_+u*y*l,this._w=a*c*l+u*y*_;break;default:d("Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],h=e[9],a=e[2],c=e[6],l=e[10],u=s+o+l;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(c-h)*t,this._y=(r-a)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(c-h)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+a)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-a)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(h+c)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+a)/t,this._y=(h+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(y(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,h=e._y,a=e._z,c=e._w;return this._x=s*c+n*o+i*a-r*h,this._y=i*c+n*h+r*o-s*a,this._z=r*c+n*a+s*h-i*o,this._w=n*c-s*o-i*h-r*a,this._onChangeCallback(),this}slerp(t,e){let s=t._x,i=t._y,r=t._z,n=t._w,o=this.dot(t);o<0&&(s=-s,i=-i,r=-r,n=-n,o=-o);let h=1-e;if(o<.9995){const t=Math.acos(o),a=Math.sin(t);h=Math.sin(h*t)/a,e=Math.sin(e*t)/a,this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+r*e,this._w=this._w*h+n*e,this._onChangeCallback()}else this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+r*e,this._w=this._w*h+n*e,this.normalize();return this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class x{constructor(t=0,e=0,s=0){x.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(p.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(p.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,h=t.w,a=2*(n*i-o*s),c=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+h*a+n*l-o*c,this.y=s+h*c+o*a-r*l,this.z=i+h*l+r*c-n*a,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=y(this.x,t.x,e.x),this.y=y(this.y,t.y,e.y),this.z=y(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=y(this.x,t,e),this.y=y(this.y,t,e),this.z=y(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(y(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,h=e.z;return this.x=i*h-r*o,this.y=r*n-s*h,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return m.copy(this).projectOnVector(t),this.sub(m)}reflect(t){return this.sub(m.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(y(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const m=new x,p=new _;class f{constructor(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x){f.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x)}set(t,e,s,i,r,n,o,h,a,c,l,u,d,y,_,x){const m=this.elements;return m[0]=t,m[4]=e,m[8]=s,m[12]=i,m[1]=r,m[5]=n,m[9]=o,m[13]=h,m[2]=a,m[6]=c,m[10]=l,m[14]=u,m[3]=d,m[7]=y,m[11]=_,m[15]=x,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new f).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,s=t.elements,i=1/g.setFromMatrixColumn(t,0).length(),r=1/g.setFromMatrixColumn(t,1).length(),n=1/g.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),h=Math.cos(i),a=Math.sin(i),c=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=h*c,e[4]=-h*l,e[8]=a,e[1]=s+i*a,e[5]=t-r*a,e[9]=-o*h,e[2]=r-t*a,e[6]=i+s*a,e[10]=n*h}else if("YXZ"===t.order){const t=h*c,s=h*l,i=a*c,r=a*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*a,e[1]=n*l,e[5]=n*c,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*h}else if("ZXY"===t.order){const t=h*c,s=h*l,i=a*c,r=a*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*c,e[9]=r-t*o,e[2]=-n*a,e[6]=o,e[10]=n*h}else if("ZYX"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=h*c,e[4]=i*a-s,e[8]=t*a+r,e[1]=h*l,e[5]=r*a+t,e[9]=s*a-i,e[2]=-a,e[6]=o*h,e[10]=n*h}else if("YZX"===t.order){const t=n*h,s=n*a,i=o*h,r=o*a;e[0]=h*c,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*c,e[9]=-o*c,e[2]=-a*c,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*h,s=n*a,i=o*h,r=o*a;e[0]=h*c,e[4]=-l,e[8]=a*c,e[1]=t*l+r,e[5]=n*c,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*c,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(M,t,w)}lookAt(t,e,s){const i=this.elements;return C.subVectors(t,e),0===C.lengthSq()&&(C.z=1),C.normalize(),b.crossVectors(s,C),0===b.lengthSq()&&(1===Math.abs(s.z)?C.x+=1e-4:C.z+=1e-4,C.normalize(),b.crossVectors(s,C)),b.normalize(),S.crossVectors(C,b),i[0]=b.x,i[4]=S.x,i[8]=C.x,i[1]=b.y,i[5]=S.y,i[9]=C.y,i[2]=b.z,i[6]=S.z,i[10]=C.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],h=s[8],a=s[12],c=s[1],l=s[5],u=s[9],d=s[13],y=s[2],_=s[6],x=s[10],m=s[14],p=s[3],f=s[7],g=s[11],z=s[15],M=i[0],w=i[4],b=i[8],S=i[12],C=i[1],k=i[5],v=i[9],R=i[13],I=i[2],E=i[6],F=i[10],T=i[14],N=i[3],A=i[7],j=i[11],q=i[15];return r[0]=n*M+o*C+h*I+a*N,r[4]=n*w+o*k+h*E+a*A,r[8]=n*b+o*v+h*F+a*j,r[12]=n*S+o*R+h*T+a*q,r[1]=c*M+l*C+u*I+d*N,r[5]=c*w+l*k+u*E+d*A,r[9]=c*b+l*v+u*F+d*j,r[13]=c*S+l*R+u*T+d*q,r[2]=y*M+_*C+x*I+m*N,r[6]=y*w+_*k+x*E+m*A,r[10]=y*b+_*v+x*F+m*j,r[14]=y*S+_*R+x*T+m*q,r[3]=p*M+f*C+g*I+z*N,r[7]=p*w+f*k+g*E+z*A,r[11]=p*b+f*v+g*F+z*j,r[15]=p*S+f*R+g*T+z*q,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],h=t[9],a=t[13],c=t[2],l=t[6],u=t[10],d=t[14],y=t[3],_=t[7],x=t[11],m=t[15],p=h*d-a*u,f=o*d-a*l,g=o*u-h*l,z=n*d-a*c,M=n*u-h*c,w=n*l-o*c;return e*(_*p-x*f+m*g)-s*(y*p-x*z+m*M)+i*(y*f-_*z+m*w)-r*(y*g-_*M+x*w)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],h=t[6],a=t[7],c=t[8],l=t[9],u=t[10],d=t[11],y=t[12],_=t[13],x=t[14],m=t[15],p=e*o-s*n,f=e*h-i*n,g=e*a-r*n,z=s*h-i*o,M=s*a-r*o,w=i*a-r*h,b=c*_-l*y,S=c*x-u*y,C=c*m-d*y,k=l*x-u*_,v=l*m-d*_,R=u*m-d*x,I=p*R-f*v+g*k+z*C-M*S+w*b;if(0===I)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/I;return t[0]=(o*R-h*v+a*k)*E,t[1]=(i*v-s*R-r*k)*E,t[2]=(_*w-x*M+m*z)*E,t[3]=(u*M-l*w-d*z)*E,t[4]=(h*C-n*R-a*S)*E,t[5]=(e*R-i*C+r*S)*E,t[6]=(x*g-y*w-m*f)*E,t[7]=(c*w-u*g+d*f)*E,t[8]=(n*v-o*C+a*b)*E,t[9]=(s*C-e*v-r*b)*E,t[10]=(y*M-_*g+m*p)*E,t[11]=(l*g-c*M-d*p)*E,t[12]=(o*S-n*k-h*b)*E,t[13]=(e*k-s*S+i*b)*E,t[14]=(_*f-y*z-x*p)*E,t[15]=(c*z-l*f+u*p)*E,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,h=t.z,a=r*n,c=r*o;return this.set(a*n+s,a*o-i*h,a*h+i*o,0,a*o+i*h,c*o+s,c*h-i*n,0,a*h-i*o,c*h+i*n,r*h*h+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,h=e._w,a=r+r,c=n+n,l=o+o,u=r*a,d=r*c,y=r*l,_=n*c,x=n*l,m=o*l,p=h*a,f=h*c,g=h*l,z=s.x,M=s.y,w=s.z;return i[0]=(1-(_+m))*z,i[1]=(d+g)*z,i[2]=(y-f)*z,i[3]=0,i[4]=(d-g)*M,i[5]=(1-(u+m))*M,i[6]=(x+p)*M,i[7]=0,i[8]=(y+f)*w,i[9]=(x-p)*w,i[10]=(1-(u+_))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return s.set(1,1,1),e.identity(),this;let n=g.set(i[0],i[1],i[2]).length();const o=g.set(i[4],i[5],i[6]).length(),h=g.set(i[8],i[9],i[10]).length();r<0&&(n=-n),z.copy(this);const a=1/n,c=1/o,l=1/h;return z.elements[0]*=a,z.elements[1]*=a,z.elements[2]*=a,z.elements[4]*=c,z.elements[5]*=c,z.elements[6]*=c,z.elements[8]*=l,z.elements[9]*=l,z.elements[10]*=l,e.setFromRotationMatrix(z),s.x=n,s.y=o,s.z=h,this}makePerspective(t,e,s,i,r,n,o=2e3,h=!1){const a=this.elements,c=2*r/(e-t),l=2*r/(s-i),d=(e+t)/(e-t),y=(s+i)/(s-i);let _,x;if(h)_=r/(n-r),x=n*r/(n-r);else if(o===u)_=-(n+r)/(n-r),x=-2*n*r/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);_=-n/(n-r),x=-n*r/(n-r)}return a[0]=c,a[4]=0,a[8]=d,a[12]=0,a[1]=0,a[5]=l,a[9]=y,a[13]=0,a[2]=0,a[6]=0,a[10]=_,a[14]=x,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3,h=!1){const a=this.elements,c=2/(e-t),l=2/(s-i),d=-(e+t)/(e-t),y=-(s+i)/(s-i);let _,x;if(h)_=1/(n-r),x=n/(n-r);else if(o===u)_=-2/(n-r),x=-(n+r)/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);_=-1/(n-r),x=-r/(n-r)}return a[0]=c,a[4]=0,a[8]=0,a[12]=d,a[1]=0,a[5]=l,a[9]=0,a[13]=y,a[2]=0,a[6]=0,a[10]=_,a[14]=x,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const g=new x,z=new f,M=new x(0,0,0),w=new x(1,1,1),b=new x,S=new x,C=new x,k=new f,v=new _;class R{constructor(t=0,e=0,s=0,i=R.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],h=i[1],a=i[5],c=i[9],l=i[2],u=i[6],_=i[10];switch(e){case"XYZ":this._y=Math.asin(y(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,_),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,a),this._z=0);break;case"YXZ":this._x=Math.asin(-y(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(o,_),this._z=Math.atan2(h,a)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(y(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-l,_),this._z=Math.atan2(-n,a)):(this._y=0,this._z=Math.atan2(h,r));break;case"ZYX":this._y=Math.asin(-y(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(u,_),this._z=Math.atan2(h,r)):(this._x=0,this._z=Math.atan2(-n,a));break;case"YZX":this._z=Math.asin(y(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(-c,a),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,_));break;case"XZY":this._z=Math.asin(-y(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,a),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-c,_),this._y=0);break;default:d("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return k.makeRotationFromQuaternion(t),this.setFromRotationMatrix(k,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return v.setFromEuler(this),this.setFromQuaternion(v,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}R.DEFAULT_ORDER="XYZ","undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"183"}})),"undefined"!=typeof window&&(window.__THREE__?d("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="183");const I=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};function E(t){if(!t)return;const e=t?.state?.id??t?.id;return"string"==typeof e?e:void 0}function F(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},s=t.sourceId??E(t.source),i=t.targetId??E(t.target),r=t.carrierId??E(t.carrier);return void 0!==s&&(e.sourceId=s),void 0!==i&&(e.targetId=i),void 0!==r&&(e.carrierId=r),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=I);let T=1;class N{constructor(t){this._phase="pending",this._slot=null,this.id="xfer-"+T++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:I.now}}get phase(){return this._phase}get timeline(){return this._timeline}async execute(){this._phase="planning",this._timeline.planStartAt=I.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return A.append(e),e}this._slot=t.slot}else{if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return A.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}if(this._timeline.planEndAt=I.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=I.now;try{await this.physical()}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return A.append(e),e}this._timeline.physicalEndAt=I.now}this._phase="handoff",this._timeline.handoffAt=I.now;const e=this.target.accept??this.target.receive;await e.call(this.target,this.carrier,this.options),this._phase="committed",this._timeline.committedAt=I.now;const s=this._buildReceipt();return A.append(s),s}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",A.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:E(this.source),targetId:E(this.target),carrierId:E(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason}}}const A=new class{constructor(){this._entries=[],this._maxEntries=1e3,this._listeners=new Set}append(t){this._entries.push(t),this._entries.length>this._maxEntries&&this._entries.shift(),this._listeners.forEach(e=>e(t))}entries(){return[...this._entries]}forCarrier(t){const e=E(t);return this._entries.filter(s=>s.carrier===t||e&&s.carrierId===e)}forCarrierId(t){return this._entries.filter(e=>e.carrierId===t)}forSourceId(t){return this._entries.filter(e=>e.sourceId===t)}forTargetId(t){return this._entries.filter(e=>e.targetId===t)}forPhase(t){return this._entries.filter(e=>e.phase===t)}inTimeRange(t,e,s="init"){return"init"===s?this._entries.filter(s=>s.timeline.initiatedAt>=t&&s.timeline.initiatedAt<=e):this._entries.filter(s=>{const i=s.timeline.initiatedAt,r=s.timeline.committedAt??s.timeline.handoffAt??s.timeline.physicalEndAt??s.timeline.planEndAt??i;return i<=e&&r>=t})}groupByRejectReason(){const t=new Map;for(const e of this._entries)if(e.rejectReason){const s=t.get(e.rejectReason)??[];s.push(e),t.set(e.rejectReason,s)}return t}stats(){const t=this._entries.length,e={};let s=0,i=0;for(const t of this._entries)e[t.phase]=(e[t.phase]??0)+1,"committed"===t.phase&&void 0!==t.timeline.committedAt&&(s+=t.timeline.committedAt-t.timeline.initiatedAt,i++);const r=e["rolled-back"]??0;return{total:t,byPhase:e,committed:e.committed??0,rolledBack:r,rejectionRate:t>0?r/t:0,avgTransferDurationMs:i>0?s/i:0}}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._entries.length=0}setMaxEntries(t){this._maxEntries=Math.max(1,t)}toJSON(){return this._entries.map(F)}fromJSON(t){this._entries=t.map(t=>({transferId:t.transferId,source:void 0,target:void 0,carrier:void 0,sourceId:t.sourceId,targetId:t.targetId,carrierId:t.carrierId,phase:t.phase,timeline:{...t.timeline},slotId:t.slotId,rejectReason:t.rejectReason}))}replayTo(t){for(const e of this._entries)t(e)}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=A);const j=new R,q="_transferSlotId";function P(t){return class extends t{get slots(){return[]}get arrangementStrategy(){return c}canReceive(t){return null!==this.findSlot(t)}findSlot(t){const e=this.slots;if(!e.length)return null;for(const s of e){if(s.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!s.allowedTypes.includes(e))continue}const e=s.maxCount??this.arrangementStrategy.capacity(s);if(!(this._countOccupied(s.id)>=e))return s}return null}async receive(t,e={}){const s=this.findSlot(t);if(!s)return void this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const i=this._countOccupied(s.id),r=this.arrangementStrategy.positionAt(i,s,i,t);t[q]=s.id;const{animated:n=!1,duration:o,ease:h}=e;this.reparent?.(t,{animated:n,duration:o,ease:h}),!n&&t._realObject&&(t._realObject.suppressTransform=!1);{const e=this._realObject?.receivingSurfaceY??0,i={};if(r&&(i.left=r.x,i.top=r.y),0!==e)i.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const t=this._realObject?.geometricOffsetY??0;i.zPos=s.localPosition.z+t}const n=this.acceptanceRotation?.(t,s);n&&(j.setFromQuaternion(new _(n.x,n.y,n.z,n.w),"XYZ"),i.rotationX=j.x,i.rotation=-j.y,i.rotationY=j.z);const o=this.normalizePose?.(t,s);o&&Object.assign(i,o),Object.keys(i).length&&t.setState?.(i)}this.trigger("transfer-received",{type:"transfer-received",component:t,container:this,slotId:s.id})}async dispatch(t,e,s={}){const i=new N({source:this,target:e,carrier:t,options:s,physical:async()=>{delete t[q]}}),r=await i.execute();"rolled-back"!==r.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:r.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}acceptanceRotation(t,e){}canAccept(t){const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const s=this.findSlot(t);if(!s){const s=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!s||t.allowedTypes.includes(s))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:s}}accept(t,e){return this.receive(t,e)}deliveryWorldRotation(t){const e=this.acceptanceRotation?.(t);if(!e)return;const s=this._realObject?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new _;s.getWorldQuaternion(i);const r=new _(e.x,e.y,e.z,e.w);return i.clone().multiply(r)}deliveryWorldPosition(t){const e=this._realObject,s=e?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new x;s.getWorldPosition(i);const r=e.receivingSurfaceY;if("number"==typeof r&&0!==r){const t=e.geometricOffsetY??0,n=new x(0,r-t,0);return s.localToWorld(n),{x:i.x,y:n.y,z:i.z}}return{x:i.x,y:i.y,z:i.z}}attachPointFor(t){const e=t?.[q];if(!e)return null;const s=this.slots.find(t=>t.id===e);return s?{position:s.localPosition??{x:0,y:0,z:0},rotation:s.localRotation??{x:0,y:0,z:0},slotId:s.id}:null}_countOccupied(t){const e=this.components;return e?e.filter(e=>e[q]===t).length:0}}}let O=1;function Y(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const L={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class X{constructor(t=L){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+O++},s=(this._byResource.get(e.resource)??[]).filter(t=>Y(t.timeWindow,e.timeWindow));if(0===s.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=s.map(t=>{const s=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:s}});if(i.every(t=>"b-yields"===t.decision)){const i=s.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:s.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>Y(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const s=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);s<0?e.push(t):e.splice(s,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const s=e.findIndex(e=>e.id===t.id);if(s<0)return!1;e.splice(s,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const Z=new X;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=Z);class W{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,s=1/0;for(const i of this.nodes.values()){const r=V(i.position,t);r<s&&(s=r,e=i)}return e}}function V(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}function Q(t,e){return Math.sqrt(V(t,e))}function D(t,e,s={}){const i=new W,r=s.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const s=`${e.id}:start`,n=`${e.id}:end`;i.addNode({id:s,position:t[0],type:"lane-start"}),i.addNode({id:n,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:s,endNodeId:n});let o=0;for(let e=1;e<t.length;e++)o+=Q(t[e-1],t[e]);const h=o/(e.speedLimit??r)*1e3;i.addEdge({fromNode:s,toNode:n,resource:e.id,distance:o,durationMs:h,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:n,toNode:s,resource:e.id,distance:o,durationMs:h,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const s of t.lanes){const r=i.laneEndpoints.get(s);if(!r)continue;const n=i.nodes.get(r.startNodeId).position,o=i.nodes.get(r.endNodeId).position;let h=0,a=0,c=0;for(const e of t.lanes){if(e===s)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const r=i.nodes.get(t.startNodeId).position,l=i.nodes.get(t.endNodeId).position;h+=Math.min(V(n,r),V(n,l)),a+=Math.min(V(o,r),V(o,l)),c++}if(0===c)continue;const l=h<a?r.startNodeId:r.endNodeId;e.push({laneId:s,nodeId:l,pos:i.nodes.get(l).position})}for(let s=0;s<e.length;s++)for(let r=0;r<e.length;r++){if(s===r)continue;const n=e[s],o=e[r],h=Q(n.pos,o.pos);i.addEdge({fromNode:n.nodeId,toNode:o.nodeId,resource:t.id,distance:h,durationMs:t.crossingTimeMs,forward:!0})}}return i}function H(t,e,s,i={}){const r=t.nodes.get(e),n=t.nodes.get(s);if(!r||!n)return null;const o=i.speed?.max??100,h=e=>{const s=t.nodes.get(e);var i,r;return(i=s.position,r=n.position,Math.sqrt(function(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}(i,r)))/o*1e3},a=new Map,c=new Set,l=new Set,u={nodeId:e,gScore:0,fScore:h(e)};a.set(e,u),c.add(e);const d=i.startSimMs??0,y=i.deadlineSimMs;for(;c.size>0;){let e=null,i=null;for(const t of c){const s=a.get(t);(!i||s.fScore<i.fScore||s.fScore===i.fScore&&t<e)&&(i=s,e=t)}if(!i||!e)return null;if(e===s){const t=[];let e=i,s=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,r=d+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:r,endSimMs:r+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),s+=i.distance,e=a.get(i.fromNodeId)}const r=i.gScore;return void 0!==y&&d+r>y?null:{segments:t,totalDurationMs:r,totalDistance:s}}c.delete(e),l.add(e);for(const s of t.edgesFrom(e)){if(l.has(s.toNode))continue;const e=i.gScore+s.durationMs,r=a.get(s.toNode);if(!r||e<r.gScore){const i=t.nodes.get(s.fromNode),r=t.nodes.get(s.toNode),n={nodeId:s.toNode,gScore:e,fScore:e+h(s.toNode),cameFromEdge:{fromNodeId:s.fromNode,resource:s.resource,distance:s.distance,durationMs:s.durationMs,fromPos:i.position,toPos:r.position}};a.set(s.toNode,n),c.add(s.toNode)}}}return null}function B(t,e,s=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:s,metadata:i}))}const G=.5;function $(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=.5}function J(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n||!Number.isFinite(s)||Math.abs(s)<1e-9)return null;const o=Math.abs(s),h=(n*n+4*o*o)/(8*o),a=s>0?1:-1,c=h-o,l=(t.x+e.x)/2-a*(r/n)*c,u=(t.y+e.y)/2-a*-(i/n)*c;return{cx:l,cy:u,radius:h,startAngle:Math.atan2(t.y-u,t.x-l),endAngle:Math.atan2(e.y-u,e.x-l),clockwise:s<0}}function U(t,e,s=0,i=16){const r=e.x-t.x,n=e.y-t.y,o=Math.sqrt(r*r+n*n);if(0===o)return null;const h=n/o,a=-(r/o),c=Number.isFinite(s)?s:0,l=Math.abs(c)>=1e-6?c:i;return{x:(t.x+e.x)/2+h*l,y:(t.y+e.y)/2+a*l,perpX:h,perpY:a}}function K(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n)return 0;const o=r/n,h=-(i/n),a=(t.x+e.x)/2,c=(t.y+e.y)/2;let l=(s.x-a)*o+(s.y-c)*h;if(Math.abs(l)<.5)return 0;return l>n&&(l=n),l<-n&&(l=-n),l}function tt(t,e){const s=t.radius,i=Number.isFinite(e)?e:0;return null!=s&&Number.isFinite(s)?Math.max(0,s):Math.max(0,i)}function et(t,e,s,i,r=16){const n=t.x-e.x,o=t.y-e.y,h=Math.sqrt(n*n+o*o);if(0===h)return null;const a=s.x-e.x,c=s.y-e.y,l=Math.sqrt(a*a+c*c);if(0===l)return null;const u=n/h+a/l,d=o/h+c/l,y=Math.sqrt(u*u+d*d);if(y<1e-9)return null;const _=u/y,x=d/y,m=Math.max(i,r);return{x:e.x+_*m,y:e.y+x*m,bisectorX:_,bisectorY:x}}function st(t,e,s,i){const r=t.x-e.x,n=t.y-e.y,o=Math.sqrt(r*r+n*n),h=s.x-e.x,a=s.y-e.y,c=Math.sqrt(h*h+a*a);if(0===o||0===c)return 0;const l=r/o+h/c,u=n/o+a/c,d=Math.sqrt(l*l+u*u);if(d<1e-9)return 0;const y=l/d,_=u/d,x=(i.x-e.x)*y+(i.y-e.y)*_,m=Math.min(o,c)/2;return Math.max(0,Math.min(x,m))}function it(t){if(0===t.length)return 0;let e;for(const s of t){const t=s.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}const rt={closed:!0,round:0,divisions:24};class nt{constructor(t,e){this.points=t,this.closed=e;const s=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,r=t[e].y-t[e-1].y;s.push(s[e-1]+Math.sqrt(i*i+r*r))}this.cumulative=s,this.length=s[s.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let s=t;this.closed?s=(t%e+e)%e:s<0?s=0:s>e&&(s=e);const i=this.cumulative;let r=0,n=i.length-2;for(;r<n;){const t=r+n>>1;i[t+1]<=s?r=t+1:n=t}const o=i[r+1]-i[r],h=o>0?(s-i[r])/o:0,a=this.points[r],c=this.points[r+1],l=c.x-a.x,u=c.y-a.y;return{x:a.x+l*h,y:a.y+u*h,theta:0===l&&0===u?0:Math.atan2(u,l)}}}function ot(t,e={}){const s={...rt,...e},i=t.length;if(0===i)return new nt([],s.closed);if(1===i)return new nt([{x:t[0].x,y:t[0].y}],s.closed);const r=[],n=(t,e)=>{if(r.length>0){const s=r[r.length-1];if(Math.abs(s.x-t)<1e-9&&Math.abs(s.y-e)<1e-9)return}r.push({x:t,y:e})},o=(s.closed,i);for(let e=0;e<o;e++){const r=0===e?s.closed?i-1:-1:e-1,o=e===i-1?s.closed?0:-1:e+1,h=r>=0?t[r]:null,a=t[e],c=o>=0?t[o]:null;if(h&&h.x===a.x&&h.y===a.y)continue;const l=h&&c?tt(a,s.round):0;let u,d,y,_;if(h){const t=Math.sqrt((h.x-a.x)**2+(h.y-a.y)**2),e=0!==t?Math.atan2(h.x-a.x,h.y-a.y):0,s=Math.min(l,t/2);u=Math.sin(e)*s+a.x,d=Math.cos(e)*s+a.y}else u=a.x,d=a.y;if(c){const t=Math.sqrt((c.x-a.x)**2+(c.y-a.y)**2),e=0!==t?Math.atan2(c.x-a.x,c.y-a.y):0,s=Math.min(l,t/2);y=Math.sin(e)*s+a.x,_=Math.cos(e)*s+a.y}else y=a.x,_=a.y;if(n(u,d),l>0&&h&&c)for(let t=1;t<=s.divisions;t++){const e=t/s.divisions,i=1-e;n(i*i*u+2*i*e*a.x+e*e*y,i*i*d+2*i*e*a.y+e*e*_)}else u===y&&d===_||n(y,_);if(c&&$(a)){const t=tt(c,s.round),e=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),i=0!==e?Math.atan2(a.x-c.x,a.y-c.y):0,r=Math.min(t,e/2),o=J({x:y,y:_},{x:Math.sin(i)*r+c.x,y:Math.cos(i)*r+c.y},a.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=s.divisions;e++){const i=e/s.divisions,r=o.startAngle+t*i;n(o.cx+o.radius*Math.cos(r),o.cy+o.radius*Math.sin(r))}}}}if(s.closed&&r.length>0){const t=r[0],e=r[r.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&r.push({x:t.x,y:t.y})}return new nt(r,s.closed)}function ht(t,e){return ot(t,e).length}export{G as BULGE_EPSILON,l as CenteringSlotStrategy,P as ContainerCapacity,a as FixedSlotStrategy,W as NavGraph,nt as PolygonPathPolyline,X as ReservationTable,q as TRANSFER_SLOT_KEY,N as Transfer,D as buildNavGraph,K as bulgeFromDrag,U as bulgeHandlePosition,h as chooseNearestPickupFrame,J as computeArcParams,et as cornerHandlePosition,st as cornerRadiusFromDrag,tt as effectiveCornerRadius,o as filterByToolType,c as fixedSlotStrategy,ot as flattenPolygonPath,I as globalSimClock,$ as hasArc,H as planPathAStar,B as planToReservations,ht as polygonPathLength,e as quatFromYaw,F as receiptToJSON,r as rectangularFootprintFrames,Z as reservationTable,L as standardYieldPolicy,n as topApproachFrame,A as transferLog,it as uniformZ};