brepjs-cad 0.178.0 → 0.178.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/brepjs-cad.cjs +2 -2
- package/dist/brepjs-cad.js +2 -2
- package/dist/cli/main.cjs +2 -2
- package/dist/cli/main.js +2 -2
- package/dist/{diff-DmFtXXiX.js → diff-BWViPAX9.js} +1 -1
- package/dist/{diff-CBp5KDNZ.cjs → diff-D7RFNl0i.cjs} +1 -1
- package/dist/{evaluate-C6FBiEVI.js → evaluate-CCAuI59o.js} +1 -1
- package/dist/{evaluate-sRn-Xvw4.cjs → evaluate-l_HV-BxG.cjs} +1 -1
- package/dist/export3dm/export3dm.cjs +1 -1
- package/dist/export3dm/export3dm.js +1 -1
- package/dist/preview/preview.cjs +2 -2
- package/dist/preview/preview.js +2 -2
- package/dist/{usingCtx-BDYtpr4t.js → usingCtx-CmdCNNMh.js} +1 -1
- package/dist/{usingCtx-LY0tPCbQ.cjs → usingCtx-De4No9jK.cjs} +1 -1
- package/package.json +11 -11
- package/viewer/dist/assets/{brepjs-DzoFdLQN.js → brepjs-Dv5a2RdT.js} +2 -2
- package/viewer/dist/assets/{index-DpWxoifW.js → index-CSl2dBNf.js} +2 -2
- package/viewer/dist/assets/{kernelWorker-C7TmNmhp.js → kernelWorker-DUucDcdG.js} +1 -1
- package/viewer/dist/index.html +1 -1
- package/viewer/dist/wasm/occt-wasm.js +1 -1
- package/viewer/dist/wasm/occt-wasm.wasm +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function t(e,t){return e[t]}function n(e,t=0){return[e[t],e[t+1],e[t+2]]}var r=class extends Error{location;constructor(e,t){super(`Bug in ${e}: ${t}`),this.name=`BrepBugError`,this.location=e}};function i(e,t){throw new r(e,t)}var a={exact:!0,brepExport:!0,exactMeasurement:!0,tessellationModel:`extract-time`},o={exact:!0,brepExport:!0,exactMeasurement:!0,tessellationModel:`none`},s=Symbol.for(`brepjs.kernel.unsupportedOperation`),c=class extends Error{constructor(e){super(e),this.name=`UnsupportedKernelOperationError`,Object.defineProperty(this,s,{value:!0})}};function l(e){return e instanceof Error&&Reflect.get(e,s)===!0}function u(e,t){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}function d(e,t){return{x:e.y*t.z-e.z*t.y,y:e.z*t.x-e.x*t.z,z:e.x*t.y-e.y*t.x}}function f(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}function p(e){return Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z)}function m(e,t){let n=e.x-t.x,r=e.y-t.y,i=e.z-t.z;return n*n+r*r+i*i}function h(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function g(e,t){let n=e[t];if(n===void 0)throw Error(`Index ${t} out of bounds`);return n}function _(e,t,n,r){let i=d(u(h(e,n),h(e,t)),u(h(e,r),h(e,t))),a=p(i),o=a>1e-14?{x:i.x/a,y:i.y/a,z:i.z/a}:i;return{a:t,b:n,c:r,normal:o,offset:f(o,h(e,t)),alive:!0,outsidePoints:[]}}function v(e,t){return f(e.normal,t)-e.offset}function y(e,t){let n=t*t,r=[];for(let t of e){let e=!1;for(let i of r)if(m(t,i)<n){e=!0;break}e||r.push(t)}return r}function b(e){let t=e.length;if(t<4)return null;let n=0,r=1,i=m(h(e,0),h(e,1));for(let a=0;a<t;a++)for(let o=a+1;o<t;o++){let t=m(h(e,a),h(e,o));t>i&&(i=t,n=a,r=o)}if(i<1e-20)return null;let a=u(h(e,r),h(e,n)),o=-1,s=-1;for(let i=0;i<t;i++){if(i===n||i===r)continue;let t=d(a,u(h(e,i),h(e,n))),c=f(t,t);c>s&&(s=c,o=i)}if(o===-1||s<1e-20)return null;let c=d(u(h(e,r),h(e,n)),u(h(e,o),h(e,n))),l=p(c);if(l<1e-14)return null;let g={x:c.x/l,y:c.y/l,z:c.z/l},_=f(g,h(e,n)),v=-1,y=-1;for(let i=0;i<t;i++){if(i===n||i===r||i===o)continue;let t=Math.abs(f(g,h(e,i))-_);t>y&&(y=t,v=i)}return v===-1||y<1e-14?null:f(g,h(e,v))-_>0?[n,o,r,v]:[n,r,o,v]}function x(e,t){let n=y(e,t);if(n.length<4)throw Error(n.length===0?`No points provided for convex hull`:`Fewer than 4 non-coincident points; cannot form a 3D convex hull`);let r=b(n);if(r===null)throw Error(`All points are coplanar; cannot form a 3D convex hull`);let[i,a,o,s]=r,c={x:(h(n,i).x+h(n,a).x+h(n,o).x+h(n,s).x)/4,y:(h(n,i).y+h(n,a).y+h(n,o).y+h(n,s).y)/4,z:(h(n,i).z+h(n,a).z+h(n,o).z+h(n,s).z)/4};function l(e,t,r){let i=_(n,e,t,r),a={x:(h(n,e).x+h(n,t).x+h(n,r).x)/3,y:(h(n,e).y+h(n,t).y+h(n,r).y)/3,z:(h(n,e).z+h(n,t).z+h(n,r).z)/3},o=u(c,a);return f(i.normal,o)>0?_(n,e,r,t):i}let d=[l(i,a,o),l(i,o,s),l(i,s,a),l(a,s,o)],p=new Set([i,a,o,s]),m=1e-10;for(let e=0;e<n.length;e++)if(!p.has(e)){for(let t of d)if(v(t,h(n,e))>m){t.outsidePoints.push(e);break}}for(let e=0;e<n.length*4;e++){let e=null;for(let t of d)if(t.alive&&t.outsidePoints.length>0){e=t;break}if(e===null)break;let t=g(e.outsidePoints,0),r=v(e,h(n,t));for(let i=1;i<e.outsidePoints.length;i++){let a=g(e.outsidePoints,i),o=v(e,h(n,a));o>r&&(r=o,t=a)}let i=[];for(let e of d)e.alive&&v(e,h(n,t))>m&&i.push(e);let a=new Map;for(let e of i){let t=[[e.a,e.b],[e.b,e.c],[e.c,e.a]];for(let[e,n]of t){let t=e<n?`${e}-${n}`:`${n}-${e}`,r=a.get(t);r?r.count++:a.set(t,{a:e,b:n,count:1})}}let o=[];for(let e of a.values())e.count===1&&o.push({a:e.a,b:e.b});let s=[];for(let e of i){for(let n of e.outsidePoints)n!==t&&s.push(n);e.alive=!1,e.outsidePoints=[]}let c=[];for(let e of o){let r=_(n,e.a,e.b,t);c.push(r),d.push(r)}for(let e of s)for(let t of c)if(v(t,h(n,e))>m){t.outsidePoints.push(e);break}}let x=[];for(let e of d)e.alive&&x.push([e.a,e.b,e.c]);return{faces:x,points:n}}function S(e,t){switch(e.__bk2d){case`line`:return[e.ox+e.dx*t,e.oy+e.dy*t];case`circle`:{let n=e.sense?t:-t;return[e.cx+e.radius*Math.cos(n),e.cy+e.radius*Math.sin(n)]}case`ellipse`:{let n=e.sense?t:-t,r=Math.cos(e.xDirAngle),i=Math.sin(e.xDirAngle),a=e.majorRadius*Math.cos(n),o=e.minorRadius*Math.sin(n);return[e.cx+a*r-o*i,e.cy+a*i+o*r]}case`bezier`:return Te(e.poles,t);case`bspline`:return Ee(e,t);case`trimmed`:{let n=e.tStart+t*(e.tEnd-e.tStart);return S(e.basis,n)}}}function C(e,t){switch(e.__bk2d){case`line`:return[e.dx,e.dy];case`circle`:{let n=e.sense?t:-t,r=e.sense?1:-1;return[-e.radius*Math.sin(n)*r,e.radius*Math.cos(n)*r]}case`ellipse`:{let n=e.sense?t:-t,r=e.sense?1:-1,i=Math.cos(e.xDirAngle),a=Math.sin(e.xDirAngle),o=-e.majorRadius*Math.sin(n)*r,s=e.minorRadius*Math.cos(n)*r;return[o*i-s*a,o*a+s*i]}case`bezier`:{let n=1e-8,r=Te(e.poles,Math.max(0,t-n)),i=Te(e.poles,Math.min(1,t+n)),a=Math.min(1,t+n)-Math.max(0,t-n);return[(i[0]-r[0])/a,(i[1]-r[1])/a]}case`bspline`:{let n=1e-8,r=e.knots[0],i=e.knots[e.knots.length-1],a=Ee(e,Math.max(r,t-n)),o=Ee(e,Math.min(i,t+n)),s=Math.min(i,t+n)-Math.max(r,t-n);return[(o[0]-a[0])/s,(o[1]-a[1])/s]}case`trimmed`:{let n=e.tStart+t*(e.tEnd-e.tStart),r=C(e.basis,n),i=e.tEnd-e.tStart;return[r[0]*i,r[1]*i]}}}function w(e){switch(e.__bk2d){case`line`:return{first:0,last:e.len};case`circle`:case`ellipse`:return{first:0,last:2*Math.PI};case`bezier`:return{first:0,last:1};case`bspline`:return{first:e.knots[0],last:e.knots[e.knots.length-1]};case`trimmed`:return{first:0,last:1}}}function ee(e){switch(e.__bk2d){case`line`:return`LINE`;case`circle`:return`CIRCLE`;case`ellipse`:return`ELLIPSE`;case`bezier`:return`BEZIER_CURVE`;case`bspline`:return`BSPLINE_CURVE`;case`trimmed`:return`TRIMMED_`+ee(e.basis)}}function te(e,t,n,r){let i=n-e,a=r-t,o=Math.sqrt(i*i+a*a);return{__bk2d:`line`,ox:e,oy:t,dx:o>0?i/o:1,dy:o>0?a/o:0,len:o}}function ne(e,t,n,r=!0){return{__bk2d:`circle`,cx:e,cy:t,radius:n,sense:r}}function re(e,t,n,r,i,a){let o=2*(e*(r-a)+n*(a-t)+i*(t-r));if(Math.abs(o)<1e-12)return te(e,t,i,a);let s=((e*e+t*t)*(r-a)+(n*n+r*r)*(a-t)+(i*i+a*a)*(t-r))/o,c=((e*e+t*t)*(i-n)+(n*n+r*r)*(e-i)+(i*i+a*a)*(n-e))/o,l=Math.sqrt((e-s)**2+(t-c)**2),u=Math.atan2(t-c,e-s),d=Math.atan2(r-c,n-s),f=Math.atan2(a-c,i-s),p=d-u;p<0&&(p+=2*Math.PI);let m=f-u;m<0&&(m+=2*Math.PI);let h=p<m,g=ne(s,c,l,h);if(!h){let e=-u,t=-f;return t<e-1e-9&&(t+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:e,tEnd:t}}let _=f;return _<u-1e-9&&(_+=2*Math.PI),{__bk2d:`trimmed`,basis:g,tStart:u,tEnd:_}}function ie(e,t,n,r,i,a){let o=Math.sqrt(n*n+r*r),s=o>0?n/o:0,c=o>0?r/o:0,l=e-i,u=t-a,d=2*(u*s-l*c);if(Math.abs(d)<1e-12)return te(e,t,i,a);let f=-(l*l+u*u)/d,p=e-f*c,m=t+f*s,h=Math.abs(f),g=Math.atan2(t-m,e-p),_=Math.atan2(a-m,i-p),v=-(t-m)/h,y=(e-p)/h,b=s*v+c*y,x;if(b>0){let e=_-g;e<=0&&(e+=2*Math.PI),x=g+e/2}else{let e=_-g;e>=0&&(e-=2*Math.PI),x=g+e/2}return re(e,t,p+h*Math.cos(x),m+h*Math.sin(x),i,a)}function ae(e,t,n,r,i=1,a=0,o=!0){return{__bk2d:`ellipse`,cx:e,cy:t,majorRadius:n,minorRadius:r,xDirAngle:Math.atan2(a,i),sense:o}}function oe(e){return{__bk2d:`bezier`,poles:[...e]}}function se(e,t,n){switch(e.__bk2d){case`line`:return{...e,ox:e.ox+t,oy:e.oy+n};case`circle`:return{...e,cx:e.cx+t,cy:e.cy+n};case`ellipse`:return{...e,cx:e.cx+t,cy:e.cy+n};case`bezier`:return{...e,poles:e.poles.map(([e,r])=>[e+t,r+n])};case`bspline`:return{...e,poles:e.poles.map(([e,r])=>[e+t,r+n])};case`trimmed`:return{...e,basis:se(e.basis,t,n)}}}function ce(e,t,n,r){let i=Math.cos(t),a=Math.sin(t),o=(e,t)=>{let o=e-n,s=t-r;return[n+o*i-s*a,r+o*a+s*i]};switch(e.__bk2d){case`line`:{let[t,n]=o(e.ox,e.oy),r=e.dx*i-e.dy*a,s=e.dx*a+e.dy*i;return{...e,ox:t,oy:n,dx:r,dy:s}}case`circle`:{let[t,n]=o(e.cx,e.cy);return{...e,cx:t,cy:n}}case`ellipse`:{let[n,r]=o(e.cx,e.cy);return{...e,cx:n,cy:r,xDirAngle:e.xDirAngle+t}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>o(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>o(e,t))};case`trimmed`:{let i=ce(e.basis,t,n,r);if(i.__bk2d===`circle`){let n=i.sense?t:-t;return{...e,basis:i,tStart:e.tStart+n,tEnd:e.tEnd+n}}return{...e,basis:i}}}}function le(e,t,n,r){let i=(e,i)=>[n+(e-n)*t,r+(i-r)*t];switch(e.__bk2d){case`line`:{let[t,n]=i(e.ox,e.oy),[r,a]=i(e.ox+e.dx*e.len,e.oy+e.dy*e.len),o=r-t,s=a-n,c=Math.sqrt(o*o+s*s);return{...e,ox:t,oy:n,dx:c>0?o/c:e.dx,dy:c>0?s/c:e.dy,len:c}}case`circle`:{let[n,r]=i(e.cx,e.cy);return{...e,cx:n,cy:r,radius:e.radius*Math.abs(t)}}case`ellipse`:{let[n,r]=i(e.cx,e.cy);return{...e,cx:n,cy:r,majorRadius:e.majorRadius*Math.abs(t),minorRadius:e.minorRadius*Math.abs(t)}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>i(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>i(e,t))};case`trimmed`:return{...e,basis:le(e.basis,t,n,r)}}}function ue(e,t,n){return ce(e,Math.PI,t,n)}function de(e,t,n,r,i){let a=Math.sqrt(r*r+i*i);if(a<1e-15)return e;let o=r/a,s=i/a,c=(e,r)=>{let i=e-t,a=r-n,c=i*o+a*s;return[t+2*c*o-i,n+2*c*s-a]};switch(e.__bk2d){case`line`:{let[t,n]=c(e.ox,e.oy),r=2*(e.dx*o+e.dy*s)*o-e.dx,i=2*(e.dx*o+e.dy*s)*s-e.dy;return{...e,ox:t,oy:n,dx:r,dy:i}}case`circle`:{let[t,n]=c(e.cx,e.cy);return{...e,cx:t,cy:n,sense:!e.sense}}case`ellipse`:{let[t,n]=c(e.cx,e.cy),r=o*o-s*s,i=2*o*s,a=Math.atan2(i*Math.cos(e.xDirAngle)-r*Math.sin(e.xDirAngle),r*Math.cos(e.xDirAngle)+i*Math.sin(e.xDirAngle));return{...e,cx:t,cy:n,xDirAngle:a,sense:!e.sense}}case`bezier`:return{...e,poles:e.poles.map(([e,t])=>c(e,t))};case`bspline`:return{...e,poles:e.poles.map(([e,t])=>c(e,t))};case`trimmed`:{let a=de(e.basis,t,n,r,i);if(e.basis.__bk2d===`circle`&&a.__bk2d===`circle`){let t=Math.atan2(s,o),n=e.basis.sense?-2*t:2*t;return{...e,basis:a,tStart:e.tStart+n,tEnd:e.tEnd+n}}return{...e,basis:a}}}}function fe(e,t,n){let r=pe(e),i=pe(t);return r.__bk2d===`line`&&i.__bk2d===`line`?ge(e,r,t,i,n):r.__bk2d===`line`&&i.__bk2d===`circle`?{points:_e(e,r,t,i,n),segments:[]}:r.__bk2d===`circle`&&i.__bk2d===`line`?{points:_e(t,i,e,r,n),segments:[]}:r.__bk2d===`circle`&&i.__bk2d===`circle`?{points:ye(e,r,t,i,n),segments:[]}:be(e,t,n,e===t)}function pe(e){let t=e;for(;t.__bk2d===`trimmed`;)t=t.basis;return t}function me(e,t,n){let r=w(e);return t>=r.first-n&&t<=r.last+n}function he(e,t,n){let r=w(e);if(!isFinite(r.first)||!isFinite(r.last))return null;let i=(r.last-r.first)/80,a=r.first,o=1/0;for(let s=0;s<=80;s++){let c=r.first+s*i,[l,u]=S(e,c),d=(l-t)**2+(u-n)**2;d<o&&(o=d,a=c)}let[s,c]=S(e,r.first),[l,u]=S(e,r.last),[d,f]=S(e,(r.first+r.last)/2),p=Math.max(Math.sqrt((l-s)**2+(u-c)**2),Math.sqrt((d-s)**2+(f-c)**2),1e-6)*.1;return o<p*p?a:null}function ge(e,t,n,r,i){let a=t.dx*r.dy-t.dy*r.dx;if(Math.abs(a)>=1e-14){let o=r.ox-t.ox,s=r.oy-t.oy,c=(o*r.dy-s*r.dx)/a,l=(o*t.dy-s*t.dx)/a;return!me(e,c,i)||!me(n,l,i)?{points:[],segments:[]}:{points:[[t.ox+c*t.dx,t.oy+c*t.dy]],segments:[]}}let o=r.ox-t.ox,s=r.oy-t.oy,c=o*t.dy-s*t.dx;if(Math.abs(c)>i)return{points:[],segments:[]};let l=w(e),u=w(n),d=S(n,u.first),f=S(n,u.last),p=(d[0]-t.ox)*t.dx+(d[1]-t.oy)*t.dy,m=(f[0]-t.ox)*t.dx+(f[1]-t.oy)*t.dy,h=Math.max(l.first,Math.min(p,m)),g=Math.min(l.last,Math.max(p,m));return g-h<i?{points:[],segments:[]}:{points:[],segments:[te(t.ox+h*t.dx,t.oy+h*t.dy,t.ox+g*t.dx,t.oy+g*t.dy)]}}function _e(e,t,n,r,i){let a=t.ox-r.cx,o=t.oy-r.cy,s=t.dx*t.dx+t.dy*t.dy,c=2*(a*t.dx+o*t.dy),l=a*a+o*o-r.radius*r.radius,u=c*c-4*s*l;if(u<-i)return[];let d=[],f=Math.sqrt(Math.max(0,u)),p=(-c-f)/(2*s),m=(-c+f)/(2*s);for(let r of u<i*i?[p]:[p,m]){if(!me(e,r,i))continue;let a=t.ox+r*t.dx,o=t.oy+r*t.dy,s=he(n,a,o);if(s===null)continue;let[c,l]=S(n,s);(c-a)**2+(l-o)**2>i*i*1e6||d.push([a,o])}return d}function ve(e,t,n){let r=w(e),i=w(t),a=Math.abs(r.last-r.first-2*Math.PI)<1e-10,o=Math.abs(i.last-i.first-2*Math.PI)<1e-10;if(a&&o)return[];if(a)return[S(t,i.first),S(t,i.last)];if(o)return[S(e,r.first),S(e,r.last)];let s=[],c=[[t,S(e,r.first)],[t,S(e,r.last)],[e,S(t,i.first)],[e,S(t,i.last)]];for(let[e,t]of c){let r=he(e,t[0],t[1]);if(r!==null){let[i,a]=S(e,r);(i-t[0])**2+(a-t[1])**2<n*n*100&&s.push(t)}}let l=[];for(let e of s)l.some(([t,r])=>(t-e[0])**2+(r-e[1])**2<n*n*100)||l.push(e);return l}function ye(e,t,n,r,i){let a=r.cx-t.cx,o=r.cy-t.cy,s=Math.sqrt(a*a+o*o);if(s>t.radius+r.radius+i||s<Math.abs(t.radius-r.radius)-i)return[];if(s<1e-14)return Math.abs(t.radius-r.radius)>i?[]:ve(e,n,i);let c=(t.radius*t.radius-r.radius*r.radius+s*s)/(2*s),l=t.radius*t.radius-c*c,u=Math.sqrt(Math.max(0,l)),d=t.cx+c*a/s,f=t.cy+c*o/s,p=u<i?[[d,f]]:[[d+u*o/s,f-u*a/s],[d-u*o/s,f+u*a/s]],m=[];for(let[t,r]of p){let a=he(e,t,r),o=he(n,t,r);if(a===null||o===null)continue;let[s,c]=S(e,a),[l,u]=S(n,o),d=(i*10)**2;(s-t)**2+(c-r)**2>d||(l-t)**2+(u-r)**2>d||m.push([t,r])}return m}function be(e,t,n,r=!1){let i=w(e),a=w(t);if(!isFinite(i.first)||!isFinite(i.last)||!isFinite(a.first)||!isFinite(a.last))return{points:[],segments:[]};let o=[],s=[];for(let n=0;n<=100;n++){let r=i.first+(i.last-i.first)*n/100,[c,l]=S(e,r);o.push({t:r,x:c,y:l});let u=a.first+(a.last-a.first)*n/100,[d,f]=S(t,u);s.push({t:u,x:d,y:f})}let c=Math.max(n*100,.5),l=new Float64Array(600);for(let e=0;e<100;e++){let t=s[e],n=s[e+1],r=e*6;l[r]=Math.min(t.x,n.x),l[r+1]=Math.max(t.x,n.x),l[r+2]=Math.min(t.y,n.y),l[r+3]=Math.max(t.y,n.y),l[r+4]=(t.t+n.t)/2}let u=[],d=(i.last-i.first)/5;for(let e=0;e<100;e++){let t=o[e],n=o[e+1],i=Math.min(t.x,n.x)-c,a=Math.max(t.x,n.x)+c,s=Math.min(t.y,n.y)-c,f=Math.max(t.y,n.y)+c,p=(t.t+n.t)/2;for(let e=0;e<100;e++){let t=e*6;if(a<l[t]||l[t+1]<i||f<l[t+2]||l[t+3]<s)continue;let n=l[t+4];r&&Math.abs(p-n)<d||u.push({t1:p,t2:n})}}let f=n*n,p=[];for(let{t1:o,t2:s}of u){let c=o,l=s;for(let n=0;n<20;n++){let[n,r]=S(e,c),[o,s]=S(t,l),u=n-o,d=r-s;if(u*u+d*d<f)break;let p=C(e,c),m=C(t,l),h=p[0]*-m[1]- -m[0]*p[1];if(Math.abs(h)<1e-14)break;let g=(-u*-m[1]- -d*-m[0])/h,_=(p[0]*-d-p[1]*-u)/h;c+=g,l+=_,c=Math.max(i.first,Math.min(i.last,c)),l=Math.max(a.first,Math.min(a.last,l))}let[u,d]=S(e,c),[m,h]=S(t,l);if(!(r&&Math.abs(c-l)<(i.last-i.first)*.05)&&(u-m)**2+(d-h)**2<n*n*1e6){let e=(u+m)/2,t=(d+h)/2,r=!1;for(let[i,a]of p)if((i-e)**2+(a-t)**2<n*n*1e4){r=!0;break}r||p.push([e,t])}}return{points:p,segments:[]}}function xe(e){return JSON.stringify(e)}function Se(e){return JSON.parse(e)}function Ce(){return{__bk2d_bbox:!0,xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}function we(e,t,n){let r=t.__bk2d===`trimmed`?t.basis:t;if(r.__bk2d===`line`){let n=w(t);if(!isFinite(n.first)||!isFinite(n.last))return;let[r,i]=S(t,n.first),[a,o]=S(t,n.last);e.xMin=Math.min(e.xMin,r,a),e.yMin=Math.min(e.yMin,i,o),e.xMax=Math.max(e.xMax,r,a),e.yMax=Math.max(e.yMax,i,o);return}if(r.__bk2d===`circle`){let n=w(t);if(!isFinite(n.first)||!isFinite(n.last))return;let{cx:i,cy:a,radius:o,sense:s}=r,[c,l]=S(t,n.first),[u,d]=S(t,n.last),f=Math.min(c,u),p=Math.max(c,u),m=Math.min(l,d),h=Math.max(l,d),g=t.__bk2d===`trimmed`?t.tStart:n.first,_=t.__bk2d===`trimmed`?t.tEnd:n.last;for(let e=0;e<4;e++){let t=e*Math.PI/2,n=s?t:-t;for(let e=0;e<=1;e++){let r=n+e*2*Math.PI;if(r>=g-1e-10&&r<=_+1e-10){let e=i+o*Math.cos(t),n=a+o*Math.sin(t);f=Math.min(f,e),p=Math.max(p,e),m=Math.min(m,n),h=Math.max(h,n);break}}}e.xMin=Math.min(e.xMin,f),e.yMin=Math.min(e.yMin,m),e.xMax=Math.max(e.xMax,p),e.yMax=Math.max(e.yMax,h);return}let i=w(t);if(!isFinite(i.first)||!isFinite(i.last))return;let a=(i.last-i.first)/20;for(let n=0;n<=20;n++){let[r,o]=S(t,i.first+n*a);r<e.xMin&&(e.xMin=r),o<e.yMin&&(e.yMin=o),r>e.xMax&&(e.xMax=r),o>e.yMax&&(e.yMax=o)}}function Te(e,t){let n=e.length,r=e.map(([e,t])=>[e,t]);for(let e=1;e<n;e++)for(let i=0;i<n-e;i++){let e=r[i],n=r[i+1];e[0]=(1-t)*e[0]+t*n[0],e[1]=(1-t)*e[1]+t*n[1]}return r[0]}function Ee(e,t){let n=[];for(let t=0;t<e.knots.length;t++){let r=e.multiplicities[t]??1;for(let i=0;i<r;i++)n.push(e.knots[t])}let r=e.degree,i=e.poles.length,a=n.length,o=Math.max(n[r],Math.min(n[a-r-1],t)),s=r;for(let e=r;e<a-r-1;e++)if(o>=n[e]&&o<n[e+1]){s=e;break}o>=n[a-r-1]&&(s=a-r-2);let c=[];for(let t=0;t<=r;t++){let n=Math.min(s-r+t,i-1),a=e.poles[Math.max(0,n)];c.push([a[0],a[1]])}for(let e=1;e<=r;e++)for(let t=r;t>=e;t--){let i=s-r+t,a=n[i]??0,l=(n[i+r-e+1]??1)-a,u=l>1e-15?(o-a)/l:0,d=c[t],f=c[t-1];d[0]=(1-u)*f[0]+u*d[0],d[1]=(1-u)*f[1]+u*d[1]}return c[r]}var De=.001,Oe=.1,ke={nx:0,ny:0,nz:0,ax:0,ay:0,az:0,bx:0,by:0,bz:0,cx:0,cy:0,cz:0};function Ae(e,t,n){let r=(t[n*3]??0)*3,i=(t[n*3+1]??0)*3,a=(t[n*3+2]??0)*3,o=e[r]??0,s=e[r+1]??0,c=e[r+2]??0,l=e[i]??0,u=e[i+1]??0,d=e[i+2]??0,f=e[a]??0,p=e[a+1]??0,m=e[a+2]??0,h=l-o,g=u-s,_=d-c,v=f-o,y=p-s,b=m-c,x=g*b-_*y,S=_*v-h*b,C=h*y-g*v,w=Math.hypot(x,S,C)||1;return x/=w,S/=w,C/=w,ke.nx=x,ke.ny=S,ke.nz=C,ke.ax=o,ke.ay=s,ke.az=c,ke.bx=l,ke.by=u,ke.bz=d,ke.cx=f,ke.cy=p,ke.cz=m,ke}function je(e,t){let n=Math.floor(t.length/3),r=new ArrayBuffer(84+n*50),i=new DataView(r);i.setUint32(80,n,!0);let a=84;for(let r=0;r<n;r++){let n=Ae(e,t,r);i.setFloat32(a,n.nx,!0),i.setFloat32(a+4,n.ny,!0),i.setFloat32(a+8,n.nz,!0),i.setFloat32(a+12,n.ax,!0),i.setFloat32(a+16,n.ay,!0),i.setFloat32(a+20,n.az,!0),i.setFloat32(a+24,n.bx,!0),i.setFloat32(a+28,n.by,!0),i.setFloat32(a+32,n.bz,!0),i.setFloat32(a+36,n.cx,!0),i.setFloat32(a+40,n.cy,!0),i.setFloat32(a+44,n.cz,!0),i.setUint16(a+48,0,!0),a+=50}return r}function Me(e,t){let n=Math.floor(t.length/3),r=[`solid brepjs`];for(let i=0;i<n;i++){let n=Ae(e,t,i);r.push(`facet normal ${n.nx} ${n.ny} ${n.nz}`),r.push(`outer loop`),r.push(`vertex ${n.ax} ${n.ay} ${n.az}`),r.push(`vertex ${n.bx} ${n.by} ${n.bz}`),r.push(`vertex ${n.cx} ${n.cy} ${n.cz}`),r.push(`endloop`),r.push(`endfacet`)}return r.push(`endsolid brepjs`),r.join(`
|
|
2
2
|
`)+`
|
|
3
|
-
`}var Ne=()=>{};function T(e,t){return{__occtWasm:!0,type:e,id:t,delete:Ne,HashCode(e){return t%e},IsNull(){return!1}}}function Pe(e){return typeof e==`object`&&!!e&&e.__occtWasm}function E(e){if(Pe(e))return e.id;if(typeof e==`number`)return e;throw Error(`occt-wasm: expected an OcctWasmHandle or number, got `+typeof e)}function Fe(e){switch(e.toLowerCase()){case`vertex`:return`vertex`;case`edge`:return`edge`;case`wire`:return`wire`;case`face`:return`face`;case`shell`:return`shell`;case`solid`:return`solid`;case`compsolid`:return`compsolid`;case`compound`:return`compound`;default:return`compound`}}function D(e,t){return T(Fe(e.getShapeType(t)),t)}function Ie(e,t){let n=new e.VectorUint32;for(let e of t)n.push_back(e);return n}function Le(e,t){let n=new e.VectorInt;for(let e of t)n.push_back(e);return n}function Re(e,t){let n=new e.VectorDouble;for(let e of t)n.push_back(e);return n}function ze(e){let t=[],n=e.size();for(let r=0;r<n;r++)t.push(e.get(r));return t}function Be(e,t){let n=Array(16).fill(0);for(let r=0;r<4;r++)for(let i=0;i<4;i++)for(let a=0;a<4;a++)n[r*4+i]=n[r*4+i]+e[r*4+a]*t[a*4+i];return n}function Ve(e,t){if(typeof t==`number`)return t;if(Array.isArray(t))return t[0];if(e.length===0)throw Error(`occt-wasm: no edges provided`);let n=t(e[0]);return typeof n==`number`?n:n[0]}function He(e,t,n){let[r,i,a]=n,o=Math.sqrt(r*r+i*i+a*a);if(o<1e-10)return t;let s=r/o,c=i/o,l=a/o;if(Math.abs(l-1)<1e-10)return t;if(Math.abs(l+1)<1e-10)return e.rotate(t,0,0,0,1,0,0,Math.PI);let u=-c,d=s,f=Math.sqrt(u*u+d*d);if(f<1e-10)return t;let p=Math.acos(Math.max(-1,Math.min(1,l)));return e.rotate(t,0,0,0,u/f,d/f,0,p)}function Ue(e,t){return new Proxy(e,{get(e,n,r){let i=Reflect.get(e,n,r);return typeof i==`function`?function(...n){try{return i.apply(e,n)}catch(e){let n=WebAssembly.Exception;if(n&&e instanceof n)try{let[,n]=t.getExceptionMessage(e);throw Error(n,{cause:e})}catch(e){if(e instanceof Error&&!(e instanceof n))throw e}throw e}}:i}})}function We(e,t){let n=function(){return T(`compound`,t.makeNullShape())};return Object.assign(Object.create(e),{TopoDS_Solid:n,TopoDS_Face:n,TopoDS_Shape:n,TopoDS_Wire:n,TopoDS_Edge:n,TopoDS_Vertex:n,TopoDS_Shell:n,TopoDS_Compound:n,gp_Pnt_3:function(e,n,r){return T(`vertex`,t.makeVertex(e,n,r))},BRepBuilderAPI_MakeEdge_3:function(e,n){let r=e,i=n,a=t.vertexPosition(r.id),o=t.vertexPosition(i.id),s=t.makeLineEdge(a.get(0),a.get(1),a.get(2),o.get(0),o.get(1),o.get(2));return a.delete(),o.delete(),{Edge:()=>T(`edge`,s),delete(){}}}})}function Ge(e,t){let n=E(t),r=e.getSubShapes(n,`solid`);try{if(r.size()>1){let t=e.fuseAll(r);return{id:t,dispose:()=>{e.release(t)}}}return{id:n,dispose:()=>{}}}finally{for(let t=0,i=r.size();t<i;t++){let i=r.get(t);i!==n&&e.release(i)}r.delete()}}function Ke(e,t,n,r){return D(e,e.fuse(E(t),E(n)))}function qe(e,t,n,r){let i=Ge(e,n);try{return D(e,e.cut(E(t),i.id))}finally{i.dispose()}}function Je(e,t,n,r){let i=Ge(e,n);try{return D(e,e.intersect(E(t),i.id))}finally{i.dispose()}}function Ye(e,t,n,r){return D(e,e.section(E(t),E(n)))}function Xe(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.fuseAll(i))}finally{i.delete()}}function Ze(e,t,n,r,i){let a=Ie(t,r.map(E));try{return D(e,e.cutAll(E(n),a))}finally{a.delete()}}function Qe(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.split(E(n),i))}finally{i.delete()}}function $e(e,t,n,r){let i=[];return e.isNull(E(t))&&i.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),e.isNull(E(n))&&i.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is null`}),i.length===0&&!e.isValid(E(t))&&i.push({operand:`base`,issue:`not-valid`,message:`Base shape is not valid`}),i.length===0&&!e.isValid(E(n))&&i.push({operand:`tool`,issue:`not-valid`,message:`Tool shape is not valid`}),{valid:i.length===0,issues:i}}function et(e,t,n,r,i,a){throw Error(`occt-wasm: meshBoolean is not supported (use brepkit for mesh booleans)`)}function tt(e,t,n){return n!==t&&e.release(t),n}function nt(e,t,n,r){return T(`solid`,e.makeBox(t,n,r))}function rt(e,t,n,r,i){let a=e.makeCylinder(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function it(e,t,n){let r=e.makeSphere(t);return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=tt(e,r,e.translate(r,n[0],n[1],n[2]))),T(`solid`,r)}function at(e,t,n,r,i,a){let o=e.makeCone(t,n,r);return a&&(o=tt(e,o,He(e,o,a))),i&&(i[0]!==0||i[1]!==0||i[2]!==0)&&(o=tt(e,o,e.translate(o,i[0],i[1],i[2]))),T(`solid`,o)}function ot(e,t,n,r,i){let a=e.makeTorus(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function st(e,t,n,r){return T(`solid`,e.makeEllipsoid(t,n,r))}function ct(e,t,n){return T(`solid`,e.makeBoxFromCorners(t[0],t[1],t[2],n[0],n[1],n[2]))}function lt(e,t,n){return T(`face`,e.makeRectangle(t,n))}function ut(e,t,n){let r=e.getSubShapes(E(t),n),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(n,r.get(t)))}finally{r.delete()}return i}function dt(e,t){return Pe(t)?t.type:Fe(e.getShapeType(E(t)))}function ft(e,t,n){return e.isSame(E(t),E(n))}function pt(e,t,n){return e.isEqual(E(t),E(n))}function mt(e,t,n){return n?T(n,e.downcast(E(t),n)):t}function ht(e,t){return D(e,e.copy(E(t)))}function gt(e,t,n){return e.hashCode(E(t),n)}function _t(e,t){return e.isNull(E(t))}function vt(e,t){return e.shapeOrientation(E(t)).toLowerCase()}function yt(e,n){let r=e.edgeToFaceMap(E(n),1e6),i;try{i=ze(r)}finally{r.delete()}let a={};for(let e=0;e+1<i.length;e+=2){let n=t(i,e),r=t(i,e+1);a[n]||(a[n]=[]),a[n].push(r)}return JSON.stringify(a)}function bt(e,t,n){return e.subShapeCount(E(t),n)}function xt(e,t,n,r){let i=e.subShapeHashes(E(t),n,r);try{return ze(i)}finally{i.delete()}}function St(e,t,n){let r=e.sharedEdges(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`edge`,r.get(t)))}finally{r.delete()}return i}function Ct(e,t,n){let r=e.adjacentFaces(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`face`,r.get(t)))}finally{r.delete()}return i}function wt(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.sew(i,r??1e-6))}finally{i.delete()}}var Tt=1e-6;function Et(e,t){return e.isValid(E(t))}function Dt(e,t){let n=e.healSolid(E(t),Tt);return n===0?null:D(e,n)}function Ot(e,t){return D(e,e.healFace(E(t),Tt))}function kt(e,t,n){return D(e,e.healWire(E(t),Tt))}function At(e,t,n){return 0}function jt(e,t,n){return e.removeDegenerateEdges(E(t)),0}function Mt(e,t){return e.fixFaceOrientations(E(t)),0}function Nt(e,t){return D(e,e.fixShape(E(t)))}function Pt(e,t,n,r){let i=e.tessellate(E(n),r.tolerance,r.angularTolerance);try{let e=i.positionCount,n=i.normalCount,a=i.indexCount,o=i.getPositionsPtr()>>2,s=i.getNormalsPtr()>>2,c=i.getIndicesPtr()>>2,l=new Float32Array(e);for(let n=0;n<e;n++)l[n]=t.HEAPF32[o+n]??0;let u=new Float32Array(n);if(!r.skipNormals)for(let e=0;e<n;e++)u[e]=t.HEAPF32[s+e]??0;let d=i.uvCount,f=new Float32Array(r.includeUVs?d:0);if(r.includeUVs&&d>0){let e=i.getUvsPtr()>>2;for(let n=0;n<d;n++)f[n]=t.HEAPF32[e+n]??0}let p=new Uint32Array(a);for(let e=0;e<a;e++)p[e]=t.HEAPU32[c+e]??0;let m=[],h=i.faceGroupCount;if(h>0){let e=i.getFaceGroupsPtr()>>2;for(let n=0;n<h;n+=3)m.push({start:t.HEAP32[e+n]??0,count:t.HEAP32[e+n+1]??0,faceHash:t.HEAP32[e+n+2]??0})}return{vertices:l,normals:r.skipNormals?new Float32Array:u,triangles:p,uvs:f,faceGroups:m}}finally{i.delete()}}function Ft(e,t,n,r){for(let i=0;i+1<n;i++){let n=t+i*3,a=e[n]??0,o=e[n+1]??0,s=e[n+2]??0,c=e[n+3]??0,l=e[n+4]??0,u=e[n+5]??0;(a!==c||o!==l||s!==u)&&r.push(a,o,s,c,l,u)}}function It(e,t,n,r,i){let a=e.wireframe(E(n),r);try{let e=t.HEAPF32,n=a.getPointsPtr()>>2,r=[],i=[],o=a.edgeGroupCount,s=o>0?a.getEdgeGroupsPtr()>>2:0;for(let a=0;a<o;a+=3){let o=n+(t.HEAP32[s+a]??0),c=Math.floor((t.HEAP32[s+a+1]??0)/3),l=r.length/3;Ft(e,o,c,r),i.push({start:l,count:r.length/3-l,edgeHash:t.HEAP32[s+a+2]??0})}return{lines:new Float32Array(r),edgeGroups:i}}finally{a.delete()}}function Lt(e,t){return e.hasTriangulation(E(t))}function Rt(e,t,n,r){e.meshShape(E(t),n,r).delete()}var zt={line:`LINE`,circle:`CIRCLE`,ellipse:`ELLIPSE`,hyperbola:`HYPERBOLA`,parabola:`PARABOLA`,bezier:`BEZIER_CURVE`,bspline:`BSPLINE_CURVE`,offset:`OFFSET_CURVE`,other:`OTHER_CURVE`};function Bt(e,t){let n=e.curveType(E(t));return zt[n]??n.toUpperCase()}function Vt(e,t){let n=e.curveParameters(E(t));try{return[n.get(0),n.get(1)]}finally{n.delete()}}function Ht(e,t,n){let r=e.curvePointAtParam(E(t),n);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function Ut(e,t,n){let r=e.curveTangent(E(t),n);try{let i=e.curvePointAtParam(E(t),n);try{return{point:[i.get(0),i.get(1),i.get(2)],tangent:[r.get(0),r.get(1),r.get(2)]}}finally{i.delete()}}finally{r.delete()}}function Wt(e,t){return e.curveIsClosed(E(t))}function Gt(e,t){return e.curveIsPeriodic(E(t))}function Kt(e,t){return 2*Math.PI}function qt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.interpolatePoints(a,r?.periodic??!1))}finally{a.delete()}}function Jt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.approximatePoints(a,r?.tolerance??.001))}finally{a.delete()}}function Yt(e,t,n){return T(`edge`,e.curveDegreeElevate(E(t),n))}function Xt(e,t,n,r){return T(`edge`,e.curveKnotInsert(E(t),n,r))}function Zt(e,t,n,r){return T(`edge`,e.curveKnotRemove(E(t),n,r))}function Qt(e,t,n){let r=e.curveSplit(E(t),n);try{return[T(`edge`,r.get(0)),T(`edge`,r.get(1))]}finally{r.delete()}}function $t(e,t){let n=en(e,t);if(!n||n.poles.length<2)return null;let r=n.poles[n.poles.length-2];return r?[r[0],r[1],r[2]]:null}function en(e,t){try{let n=e.getNurbsCurveData(E(t));try{let e=n.poles.size()/3,t=[];for(let r=0;r<e;r++)t.push([n.poles.get(r*3),n.poles.get(r*3+1),n.poles.get(r*3+2)]);let r=[];for(let e=0;e<n.knots.size();e++)r.push(n.knots.get(e));let i=[];for(let e=0;e<n.multiplicities.size();e++)i.push(n.multiplicities.get(e));let a=[];if(n.rational)for(let e=0;e<n.weights.size();e++)a.push(n.weights.get(e));else for(let t=0;t<e;t++)a.push(1);return{degree:n.degree,poles:t,weights:a,knots:r,multiplicities:i,isPeriodic:n.periodic,isRational:n.rational}}finally{n.delete()}}catch{return null}}function tn(e,t){let n=e.vertexPosition(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function nn(e,t){return e.surfaceType(E(t)).toLowerCase()}function rn(e,t){let n=e.uvBounds(E(t));try{return{uMin:n.get(0),uMax:n.get(1),vMin:n.get(2),vMax:n.get(3)}}finally{n.delete()}}function an(e,t){return T(`wire`,e.outerWire(E(t)))}function on(e,t){return T(`face`,e.reverseSurfaceU(E(t)))}function sn(e,t,n,r){let i=e.surfaceNormal(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}function cn(e,t,n,r){let i=e.pointOnSurface(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}var ln=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],un=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dn=e=>Math.hypot(e[0],e[1],e[2]),fn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];function pn(e,t){if(nn(e,t)!==`cylinder`)return null;let n=rn(e,t),r=.5*(n.vMin+n.vMax),i=n.uMin+.25*(n.uMax-n.uMin),a=n.uMin+.5*(n.uMax-n.uMin),o=sn(e,t,i,r),s=sn(e,t,a,r),c=cn(e,t,i,r),l=cn(e,t,a,r),u=fn(o,s),d=dn(u),f=dn(ln(o,s));if(d<1e-9||f<1e-9)return null;let p=[u[0]/d,u[1]/d,u[2]/d],m=dn(ln(c,l))/f,h=[c[0]-m*o[0],c[1]-m*o[1],c[2]-m*o[2]],g=dn(ln(h,[l[0]-m*s[0],l[1]-m*s[1],l[2]-m*s[2]]))<1e-6?h:[c[0]+m*o[0],c[1]+m*o[1],c[2]+m*o[2]];return{origin:g,direction:p,radius:m,isDirect:(vt(e,t)===`reversed`?-1:1)*un(o,ln(c,g))>0}}function mn(e,t,n){let r=ln(t,e),i=ln(n,e),a=fn(r,i),o=un(a,a);if(o<1e-18)return null;let s=un(r,r),c=un(i,i),l=fn([s*i[0]-c*r[0],s*i[1]-c*r[1],s*i[2]-c*r[2]],a),u=1/(2*o);return[e[0]+l[0]*u,e[1]+l[1]*u,e[2]+l[2]*u]}function hn(e,t,n,r,i){return mn(cn(e,t,n+.1*(r-n),i),cn(e,t,n+.45*(r-n),i),cn(e,t,n+.8*(r-n),i))}function gn(e,t){let n=rn(e,t),r=[.2,.5,.8].map(r=>hn(e,t,n.uMin,n.uMax,n.vMin+r*(n.vMax-n.vMin))).filter(e=>e!==null);if(r.length<2)return null;let i=null,a=1e-9;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=r[e],o=r[t];if(!n||!o)continue;let s=ln(o,n),c=dn(s);c>a&&(a=c,i={origin:n,direction:[s[0]/c,s[1]/c,s[2]/c]})}return i}function _n(e,t){let n=nn(e,t);if(n===`cylinder`){let n=pn(e,t);return n?{origin:n.origin,direction:n.direction}:null}return n===`cone`||n===`torus`||n===`revolution`?gn(e,t):null}function vn(e,t){let n=e.getFaceCylinderData(E(t));try{return n.size()<2?null:{radius:n.get(0),isDirect:n.get(1)===1}}finally{n.delete()}}function yn(e,t,n){let r=e.uvFromPoint(E(t),n[0],n[1],n[2]);try{return r.size()<2?null:[r.get(0),r.get(1)]}finally{r.delete()}}function bn(e,t,n){let r=e.projectPointOnFace(E(t),n[0],n[1],n[2]);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function xn(e,t,n,r,i){return e.classifyPointOnFace(E(t),n,r).toLowerCase()}function Sn(e,t,n,r,i,a){let[o,s,c]=r,[l,u,d]=i,f=!!a,[p,m,h]=a??[1,0,0],g=e.projectEdges(E(n),o,s,c,l,u,d,p,m,h,f),_=n=>n===0?T(`compound`,e.makeCompound(new t.VectorUint32)):T(`compound`,n);return{visible:{outline:_(g.visibleOutline),smooth:_(g.visibleSmooth),sharp:_(g.visibleSharp)},hidden:{outline:_(g.hiddenOutline),smooth:_(g.hiddenSmooth),sharp:_(g.hiddenSharp)}}}function Cn(e,t){return e.getVolume(E(t))}function wn(e,t){return e.getSurfaceArea(E(t))}function Tn(e,t){return e.getLength(E(t))}function En(e,t){let n=e.getCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function Dn(e,t){let n=e.getLinearCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function On(e,t){let n=e.getBoundingBox(E(t),!0);return{min:[n.xmin,n.ymin,n.zmin],max:[n.xmax,n.ymax,n.zmax]}}function kn(e,t){try{let n=e.getSurfaceCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}catch{return[0,0,0]}}function An(e,t,n){return{volume:Cn(e,t),area:wn(e,t),length:n?Tn(e,t):0,centerOfMass:En(e,t),boundingBox:On(e,t)}}function jn(e,t){let n=E(t);return{distanceTo(t){return{value:e.distanceBetween(n,E(t)),point1:[0,0,0],point2:[0,0,0]}},dispose:Ne}}var Mn=256;function Nn(e,t,n){let r=[],i=e.getSubShapes(n,`vertex`);try{let t=i.size();for(let n=0;n<t;n++){let t=e.vertexPosition(i.get(n));r.push([t.get(0),t.get(1),t.get(2)]),t.delete()}}finally{i.delete()}let a=e.getBoundingBox(n,!0),o=Math.sqrt((a.xmax-a.xmin)**2+(a.ymax-a.ymin)**2+(a.zmax-a.zmin)**2),s=Math.max(o*.01,1e-4),c;try{c=e.tessellate(n,s,.5)}catch{return r}try{let e=c.positionCount;if(e>0){let n=c.getPositionsPtr()>>2,i=t.HEAPF32,a=Math.floor(e/3),o=(a>Mn?Math.ceil(a/Mn):1)*3;for(let t=0;t<e;t+=o)r.push([i[n+t]??0,i[n+t+1]??0,i[n+t+2]??0])}}finally{c.delete()}return r}function Pn(e,t,n,r){let i=E(n),a=E(r),o=e.distanceBetween(i,a),s=Nn(e,t,i),c=Nn(e,t,a);if(s.length===0||c.length===0)return{value:o,point1:[0,0,0],point2:[0,0,0]};let l=1/0,u=s[0]??[0,0,0],d=c[0]??[0,0,0];for(let e of s)for(let t of c){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],a=n*n+r*r+i*i;a<l&&(l=a,u=e,d=t)}return{value:o,point1:u,point2:d}}function Fn(e,t,n,r){let i=e.pointOnSurface(t,n,r),a=[i.get(0),i.get(1),i.get(2)];return i.delete(),a}function In(e,t,n,r){let i=e.uvBounds(t),a=i.get(0),o=i.get(1),s=i.get(2),c=i.get(3);i.delete();let l=Math.max(Math.max(o-a,1e-12)*.001,1e-6),u=Math.max(Math.max(c-s,1e-12)*.001,1e-6),d=Math.min(Math.max(n,a+l),o-l),f=Math.min(Math.max(r,s+u),c-u),p=Fn(e,t,d,f),m=Fn(e,t,d+l,f),h=Fn(e,t,d-l,f),g=Fn(e,t,d,f+u),_=Fn(e,t,d,f-u),v=Fn(e,t,d+l,f+u),y=Fn(e,t,d+l,f-u),b=Fn(e,t,d-l,f+u),x=Fn(e,t,d-l,f-u),S=l*l,C=u*u,w=4*l*u;return{Pu:[(m[0]-h[0])/(2*l),(m[1]-h[1])/(2*l),(m[2]-h[2])/(2*l)],Pv:[(g[0]-_[0])/(2*u),(g[1]-_[1])/(2*u),(g[2]-_[2])/(2*u)],Puu:[(m[0]-2*p[0]+h[0])/S,(m[1]-2*p[1]+h[1])/S,(m[2]-2*p[2]+h[2])/S],Pvv:[(g[0]-2*p[0]+_[0])/C,(g[1]-2*p[1]+_[1])/C,(g[2]-2*p[2]+_[2])/C],Puv:[(v[0]-y[0]-b[0]+x[0])/w,(v[1]-y[1]-b[1]+x[1])/w,(v[2]-y[2]-b[2]+x[2])/w]}}function Ln(e,t,n,r){return Math.abs(e)+Math.abs(t)>=Math.abs(n)+Math.abs(r)?Math.abs(e)+Math.abs(t)<1e-12?[1,0]:[-t,e]:Math.abs(n)+Math.abs(r)<1e-12?[0,1]:[-r,n]}function Rn(e,t,n){let r=e[0]*t[0]+e[1]*n[0],i=e[0]*t[1]+e[1]*n[1],a=e[0]*t[2]+e[1]*n[2],o=Math.sqrt(r*r+i*i+a*a);return o<1e-12?[1,0,0]:[r/o,i/o,a/o]}function zn(e,t){let n=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(n<1e-12)return{maxDirection:[1,0,0],minDirection:[0,1,0]};let r=e[0]/n,i=e[1]/n,a=e[2]/n,o=r*t[0]+i*t[1]+a*t[2],s=t[0]-o*r,c=t[1]-o*i,l=t[2]-o*a,u=Math.sqrt(s*s+c*c+l*l);if(u<1e-12){let e=Math.abs(r)<.9?[1,0,0]:[0,1,0],t=i*e[2]-a*e[1],n=a*e[0]-r*e[2],o=r*e[1]-i*e[0],s=Math.sqrt(t*t+n*n+o*o)||1;return{maxDirection:[r,i,a],minDirection:[t/s,n/s,o/s]}}return{maxDirection:[r,i,a],minDirection:[s/u,c/u,l/u]}}function Bn(e,t,n,r,i,a){let{Pu:o,Pv:s,Puu:c,Pvv:l,Puv:u}=In(e,t,n,r),d=o[1]*s[2]-o[2]*s[1],f=o[2]*s[0]-o[0]*s[2],p=o[0]*s[1]-o[1]*s[0],m=Math.sqrt(d*d+f*f+p*p),h=o[0]*o[0]+o[1]*o[1]+o[2]*o[2],g=o[0]*s[0]+o[1]*s[1]+o[2]*s[2],_=s[0]*s[0]+s[1]*s[1]+s[2]*s[2];if(m<1e-12||h*_-g*g<1e-24)return zn(o,s);let v=(c[0]*d+c[1]*f+c[2]*p)/m,y=(u[0]*d+u[1]*f+u[2]*p)/m,b=(l[0]*d+l[1]*f+l[2]*p)/m,x=h*_-g*g,S=(v*_-y*g)/x,C=(y*_-b*g)/x,w=(y*h-v*g)/x,ee=(b*h-y*g)/x;if(Math.abs(i-a)<1e-9*(Math.abs(i)+Math.abs(a)+1))return zn(o,s);let te=Ln(S-i,C,w,ee-i),ne=Ln(S-a,C,w,ee-a);return{maxDirection:Rn(te,o,s),minDirection:Rn(ne,o,s)}}function Vn(e,t,n,r){let i=E(t),a=e.surfaceCurvature(i,n,r),o=a.get(0),s=a.get(1),c=a.get(2),l=a.get(3);a.delete();let{maxDirection:u,minDirection:d}=Bn(e,i,n,r,c,l);return{gaussian:s,mean:o,max:c,min:l,maxDirection:u,minDirection:d}}var Hn=2147483647;function Un(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.fillet(E(n),o,a))}finally{o.delete()}}function Wn(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.chamfer(E(n),o,a))}finally{o.delete()}}function Gn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.chamferDistAngle(E(n),o,i,a))}finally{o.delete()}}function Kn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.shell(E(n),o,i,a??.001))}finally{o.delete()}}function qn(e,t,n){return D(e,e.thicken(E(t),n,.001))}function Jn(e,t,n,r){return D(e,e.offset(E(t),n,r??1e-6))}function Yn(e,t,n,r,i){let a=e.filletVariable(t,n,r,i),o=!0;try{let t=e.getSubShapes(a,`solid`);try{let n=t.size()===1?t.get(0):-1;for(let r=0,i=t.size();r<i;r++){let i=t.get(r);i!==n&&e.release(i)}return n===-1?(o=!1,D(e,a)):D(e,n)}finally{t.delete()}}finally{o&&e.release(a)}}function Xn(e,t,n){let r=JSON.parse(n);if(r.edgeId!==void 0&&r.startRadius!==void 0&&r.endRadius!==void 0)return Yn(e,E(t),r.edgeId,r.startRadius,r.endRadius);if(r.edge!==void 0&&Array.isArray(r.radii)&&r.radii.length>0){let n=r.radii;if(n.length>2)throw new c(`occt-wasm: filletVariable supports only a linear (<=2-point) radius profile; a multi-point variable radius requires the brepkit kernel`);let i=n[0].radius,a=n[n.length-1].radius,o=E(t),s=e.getSubShapes(o,`edge`),l=-1;try{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);if(e.hashCode(n,Hn)===r.edge){l=n;break}}}finally{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);n!==l&&e.release(n)}s.delete()}if(l===-1)throw new c(`occt-wasm: filletVariable: target edge not found on the shape`);try{return Yn(e,o,l,i,a)}finally{e.release(l)}}throw new c(`occt-wasm: filletVariable: unrecognized spec`)}function Zn(e,t,n,r,i,a){let o=E(t);for(let t of n){let n=(typeof a==`function`?a(t):a)*Math.PI/180;o=e.draft(o,E(t),n,r[0],r[1],r[2])}return D(e,o)}function Qn(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.defeature(E(n),i,0))}finally{i.delete()}}function $n(e,t,n,r){let i=0;return r===`intersection`||r===1?i=1:r===`tangent`||r===2?i=2:typeof r==`number`&&(i=r),D(e,e.offsetWire2D(E(t),n,i))}function er(e,t){return D(e,e.simplify(E(t)))}function tr(e,t){return D(e,e.reverseShape(E(t)))}var nr=0,rr=1,ir=3,ar=0;function or(e){switch(e){case`round`:return 2;case`right`:return 1;default:return 0}}var sr=0,cr=1,lr=2;function ur(e){let t=e?.profile;return t===`linear`?cr:t===`s-curve`?lr:sr}var dr=new Set;function fr(e,t,n){t.length===0||dr.has(e)||(dr.add(e),console.warn(`occt-wasm: sweep ignored ${t.join(`, `)} — ${n}.`))}function pr(e,t){let n=e.getSubShapes(E(t),`wire`);try{return{shape:t,firstShape:n.size()>0?D(e,n.get(0)):t,lastShape:n.size()>1?D(e,n.get(n.size()-1)):t}}finally{n.delete()}}function mr(e,t,n,r){let i=n[0]*r,a=n[1]*r,o=n[2]*r;return D(e,e.extrude(E(t),i,a,o))}function hr(e,t,n,r){let i=n.origin,a=n.direction;return D(e,e.revolve(E(t),i.x,i.y,i.z,a.x,a.y,a.z,r))}function gr(e,t,n,r,i,a){let o=i?E(i):0,s=a?E(a):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,!0,r??!1,o,s)):D(e,e.loft(c,!0,r??!1))}finally{c.delete()}}function _r(e,t,n,r){let i=r?.transitionMode??0;return D(e,e.sweep(E(t),E(n),i))}function vr(e,t,n){return D(e,e.simplePipe(E(t),E(n)))}function yr(e){let t=e?.auxiliary?ir:e?.frenet?rr:nr,n=e?.tolerance;return{mode:t,transitionMode:or(e?.transitionMode),auxiliaryId:e?.auxiliary?E(e.auxiliary):0,contact:e?.contact??!1,correction:e?.correction??!1,tol3d:n??0,boundTol:n===void 0?0:e?.boundTolerance??n,tolAngular:n===void 0?0:e?.angularTolerance??1e-7}}function br(e,t,n,r){let i=r?.shellMode??!1,a=yr(r),o=ur(r?.law),s=typeof e.sweepFull==`function`?xr(e,t,n,r,a,o):typeof e.sweepAdvanced==`function`?Cr(e,t,n,r,a,o):wr(e,t,n,r,o);return i?pr(e,s):s}function xr(e,t,n,r,i,a){if(r?.support)try{return Sr(e,t,n,r,i,a,E(r.support))}catch(o){if(!(o instanceof Error)||!o.message.includes(`not a valid spine support`))throw o;return fr(`support-invalid`,[`support`],`the support shape does not carry the spine, so OCCT swept with its default frame`),Sr(e,t,n,r,i,a,0)}return Sr(e,t,n,r,i,a,0)}function Sr(e,t,n,r,i,a,o){let s=r?.law;if(typeof e.sweepFull!=`function`)throw Error(`occt-wasm: sweepFull is unavailable`);return D(e,e.sweepFull(E(t),E(n),i.mode,0,0,1,i.auxiliaryId,!1,ar,i.transitionMode,i.contact,i.correction,i.tol3d,i.boundTol,i.tolAngular,o,r?.maxDegree??0,r?.maxSegments??0,a,s?.length??0,s?.endFactor??1))}function Cr(e,t,n,r,i,a){if(fr(`sweepFull`,[...a===sr?[]:[`law`],...r?.support?[`support`]:[],...r?.maxDegree?[`maxDegree`]:[],...r?.maxSegments?[`maxSegments`]:[]],`sweepFull requires occt-wasm >= 4.2.0`),typeof e.sweepAdvanced!=`function`)throw Error(`occt-wasm: sweepAdvanced is unavailable`);return D(e,e.sweepAdvanced(E(t),E(n),i.mode,0,0,1,i.auxiliaryId,!1,ar,i.transitionMode,i.contact,i.correction,i.tol3d,i.boundTol,i.tolAngular))}function wr(e,t,n,r,i){return fr(`sweepAdvanced`,[...r?.auxiliary?[`auxiliary`]:[],...r?.contact?[`contact`]:[],...r?.correction?[`correction`]:[],...r?.tolerance===void 0?[]:[`tolerance`],...r?.transitionMode===`right`?[`transitionMode 'right'`]:[],...i===sr?[]:[`law`],...r?.support?[`support`]:[],...r?.maxDegree?[`maxDegree`]:[],...r?.maxSegments?[`maxSegments`]:[]],`sweepAdvanced requires occt-wasm >= 4.1.0`),D(e,e.sweepPipeShell(E(t),E(n),r?.frenet??!1,r?.transitionMode===`round`))}function Tr(e,t,n,r){let i=r?.solid??!0,a=r?.ruled??!1,o=r?.startVertex?E(r.startVertex):0,s=r?.endVertex?E(r.endVertex):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,i,a,o,s)):D(e,e.loft(c,i,a))}finally{c.delete()}}function Er(e,t,n,r){let i={__occtWasmLaw:!0,profile:t,length:n,endFactor:r,Trim(e,t,n){return{...i,trimFirst:e,trimLast:t}},delete(){}};return i}function Dr(e,t,n,r,i){return D(e,e.revolveVec(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i))}function Or(e,t,n,r,i,a,o){let s=i??10;return D(e,e.draftPrism(E(t),0,0,s,a))}function kr(e){let t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let n of e)if(n.type===`translate`)t=Be([1,0,0,n.x,0,1,0,n.y,0,0,1,n.z,0,0,0,1],t);else{let e=n.axis??[0,0,1],r=n.center??[0,0,0],i=n.angle*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=1-a,c=Math.sqrt(e[0]**2+e[1]**2+e[2]**2),[l,u,d]=[e[0]/c,e[1]/c,e[2]/c],f=s*l*l+a,p=s*l*u-o*d,m=s*l*d+o*u,h=s*u*l+o*d,g=s*u*u+a,_=s*u*d-o*l,v=s*d*l-o*u,y=s*d*u+o*l,b=s*d*d+a;t=Be([f,p,m,r[0]-(f*r[0]+p*r[1]+m*r[2]),h,g,_,r[1]-(h*r[0]+g*r[1]+_*r[2]),v,y,b,r[2]-(v*r[0]+y*r[1]+b*r[2]),0,0,0,1],t)}return{handle:{__type:`transform_matrix`,matrix:t,delete:Ne},dispose:Ne}}function Ar(e){let t=e,n;return Array.isArray(t)?n=t:typeof t==`object`&&t&&(Array.isArray(t.matrix)?n=t.matrix:Array.isArray(t.elements)&&(n=t.elements)),n&&n.length===16&&(n=n.slice(0,12)),n&&n.length>=12?n:void 0}function jr(e,t,n,r){let i=Ar(r);if(i){let r=Re(t,i);try{return D(e,e.transform(E(n),r))}finally{r.delete()}}return T(e.getShapeType(E(n)),e.copy(E(n)))}function Mr(e,t,n,r){if(typeof e.located==`function`){let i=Ar(r);if(i){let r=Re(t,i);try{return D(e,e.located(E(n),r))}finally{r.delete()}}}return jr(e,t,n,r)}function Nr(e,t,n,r,i){return D(e,e.translate(E(t),n,r,i))}function Pr(e,t,n,r,i){let a=r??[0,0,1],o=i??[0,0,0];return D(e,e.rotate(E(t),o[0],o[1],o[2],a[0],a[1],a[2],n))}function Fr(e,t,n,r){return D(e,e.mirror(E(t),n[0],n[1],n[2],r[0],r[1],r[2]))}function Ir(e,t,n,r){return D(e,e.scale(E(t),n[0],n[1],n[2],r))}function Lr(e,t,n,r,i,a){let o=Re(t,[r[0],r[1],r[2],i[0],r[3],r[4],r[5],i[1],r[6],r[7],r[8],i[2]]);try{return D(e,e.generalTransform(E(n),o))}finally{o.delete()}}function Rr(e,t,n,r,i){let a=e.curvePointAtParam(E(r),i),[o,s,c]=(()=>{try{return[a.get(0),a.get(1),a.get(2)]}finally{a.delete()}})(),l=e.curveTangent(E(r),i),[u,d,f]=(()=>{try{return[l.get(0),l.get(1),l.get(2)]}finally{l.delete()}})(),p,m,h;Math.abs(u)<.9?(p=0,m=f,h=-d):(p=-f,m=0,h=u);let g=Math.sqrt(p*p+m*m+h*h);p/=g,m/=g,h/=g;let _=d*h-f*m,v=f*p-u*h,y=u*m-d*p,b=new t.VectorDouble;b.push_back(p),b.push_back(_),b.push_back(u),b.push_back(o),b.push_back(m),b.push_back(v),b.push_back(d),b.push_back(s),b.push_back(h),b.push_back(y),b.push_back(f),b.push_back(c);try{return D(e,e.transform(E(n),b))}finally{b.delete()}}function zr(e,t,n,r,i){let a=e.linearPattern(E(t),n[0],n[1],n[2],r,i),o=e.getSubShapes(a,`solid`),s=[];try{let e=o.size();for(let t=0;t<e;t++)s.push(T(`solid`,o.get(t)))}finally{o.delete()}if(s.length===0){let t=e.iterShapes(a);try{let n=t.size();for(let r=0;r<n;r++)s.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(a),s}function Br(e,t,n,r,i,a){let o=e.circularPattern(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i,a),s=e.getSubShapes(o,`solid`),c=[];try{let e=s.size();for(let t=0;t<e;t++)c.push(T(`solid`,s.get(t)))}finally{s.delete()}if(c.length===0){let t=e.iterShapes(o);try{let n=t.size();for(let r=0;r<n;r++)c.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(o),c}function Vr(e,t){return t.map(t=>{switch(t.type){case`translate`:return Nr(e,t.shape,t.x,t.y,t.z);case`rotate`:return Pr(e,t.shape,t.angle,t.axis,t.center);case`scale`:return Ir(e,t.shape,t.center,t.factor);case`mirror`:return Fr(e,t.shape,t.origin,t.normal);default:throw Error(`occt-wasm: transformBatch unknown type`)}})}function Hr(e,t){if(t===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,r=1/0,i=1/0,a=-1/0,o=-1/0,s=-1/0;for(let c=0;c<t;c++){let t=c*3,l=e[t]??0,u=e[t+1]??0,d=e[t+2]??0;l<n&&(n=l),u<r&&(r=u),d<i&&(i=d),l>a&&(a=l),u>o&&(o=u),d>s&&(s=d)}return{min:[n,r,i],max:[a,o,s]}}function Ur(e,t,n,r,i,a,o,s){return{asset:{version:`2.0`,generator:`brepjs occt-wasm`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0,NORMAL:1},indices:2,mode:4}]}],buffers:[{byteLength:o}],bufferViews:[{buffer:0,byteOffset:0,byteLength:r,target:34962},{buffer:0,byteOffset:r,byteLength:i,target:34962},{buffer:0,byteOffset:r+i,byteLength:a,target:34963}],accessors:[{bufferView:0,componentType:5126,count:e,type:`VEC3`,min:s.min,max:s.max},{bufferView:1,componentType:5126,count:t,type:`VEC3`},{bufferView:2,componentType:5125,count:n,type:`SCALAR`}]}}function Wr(e,t,n){if(n.length===1)return e.exportStep(E(n[0]));let r=t(n);return e.exportStep(E(r))}function Gr(e,t,n,r=De,i=Oe){let{vertices:a,triangles:o}=e(t,{tolerance:r,angularTolerance:i,skipNormals:!0});return n?je(a,o):Me(a,o)}function Kr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importStep(n))]}function qr(e,t,n){let r=typeof n==`string`?new TextEncoder().encode(n):new Uint8Array(n),i=t;if(i.FS)i.FS.writeFile(`/tmp/import.stl`,r);else{let t=Array.from(r,e=>String.fromCharCode(e)).join(``);return D(e,e.importStl(t))}return D(e,e.importStl(``))}function Jr(e,t,n){if(n.length===1)return e.exportIges(E(n[0]));let r=t(n);return e.exportIges(E(r))}function Yr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importIges(n))]}function Xr(e,t,n,r){if(n.length===0)return``;let i=ni(e,t,n);try{return ri(e,i)}finally{i.delete()}}function Zr(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=i.length/3,c=a.length/3,l=o.length,u=i.byteLength,d=a.byteLength,f=o.byteLength,p=u+d+f,m=p+(4-p%4)%4,h=Ur(s,c,l,u,d,f,m,Hr(i,s)),g=new TextEncoder().encode(JSON.stringify(h)),_=g.byteLength+(4-g.byteLength%4)%4,v=20+_+8+m,y=new ArrayBuffer(v),b=new DataView(y);b.setUint32(0,1179937895,!0),b.setUint32(4,2,!0),b.setUint32(8,v,!0),b.setUint32(12,_,!0),b.setUint32(16,1313821514,!0);let x=new Uint8Array(y,20,_);x.set(g);for(let e=g.byteLength;e<_;e++)x[e]=32;let S=20+_;b.setUint32(S,m,!0),b.setUint32(S+4,5130562,!0);let C=S+8;return new Uint8Array(y,C,u).set(new Uint8Array(i.buffer,i.byteOffset,u)),new Uint8Array(y,C+u,d).set(new Uint8Array(a.buffer,a.byteOffset,d)),new Uint8Array(y,C+u+d,f).set(new Uint8Array(o.buffer,o.byteOffset,f)),y}function Qr(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=[`# brepjs OBJ export`],c=i.length/3;for(let e=0;e<c;e++){let t=e*3;s.push(`v ${i[t]??0} ${i[t+1]??0} ${i[t+2]??0}`)}let l=a.length/3;for(let e=0;e<l;e++){let t=e*3;s.push(`vn ${a[t]??0} ${a[t+1]??0} ${a[t+2]??0}`)}let u=e=>{let t=(o[e]??0)+1,n=(o[e+1]??0)+1,r=(o[e+2]??0)+1;s.push(`f ${t}//${t} ${n}//${n} ${r}//${r}`)};if(r.faceGroups.length>0)for(let e of r.faceGroups){s.push(`g face_${e.faceHash}`);let t=e.count/3;for(let n=0;n<t;n++)u(e.start+n*3)}else{let e=o.length/3;for(let t=0;t<e;t++)u(t*3)}return new TextEncoder().encode(s.join(`
|
|
3
|
+
`}var Ne=()=>{};function T(e,t){return{__occtWasm:!0,type:e,id:t,delete:Ne,HashCode(e){return t%e},IsNull(){return!1}}}function Pe(e){return typeof e==`object`&&!!e&&e.__occtWasm}function E(e){if(Pe(e))return e.id;if(typeof e==`number`)return e;throw Error(`occt-wasm: expected an OcctWasmHandle or number, got `+typeof e)}function Fe(e){switch(e.toLowerCase()){case`vertex`:return`vertex`;case`edge`:return`edge`;case`wire`:return`wire`;case`face`:return`face`;case`shell`:return`shell`;case`solid`:return`solid`;case`compsolid`:return`compsolid`;case`compound`:return`compound`;default:return`compound`}}function D(e,t){return T(Fe(e.getShapeType(t)),t)}function Ie(e,t){let n=new e.VectorUint32;for(let e of t)n.push_back(e);return n}function Le(e,t){let n=new e.VectorInt;for(let e of t)n.push_back(e);return n}function Re(e,t){let n=new e.VectorDouble;for(let e of t)n.push_back(e);return n}function ze(e){let t=[],n=e.size();for(let r=0;r<n;r++)t.push(e.get(r));return t}function Be(e,t){let n=Array(16).fill(0);for(let r=0;r<4;r++)for(let i=0;i<4;i++)for(let a=0;a<4;a++)n[r*4+i]=n[r*4+i]+e[r*4+a]*t[a*4+i];return n}function Ve(e,t){if(typeof t==`number`)return t;if(Array.isArray(t))return t[0];if(e.length===0)throw Error(`occt-wasm: no edges provided`);let n=t(e[0]);return typeof n==`number`?n:n[0]}function He(e,t,n){let[r,i,a]=n,o=Math.sqrt(r*r+i*i+a*a);if(o<1e-10)return t;let s=r/o,c=i/o,l=a/o;if(Math.abs(l-1)<1e-10)return t;if(Math.abs(l+1)<1e-10)return e.rotate(t,0,0,0,1,0,0,Math.PI);let u=-c,d=s,f=Math.sqrt(u*u+d*d);if(f<1e-10)return t;let p=Math.acos(Math.max(-1,Math.min(1,l)));return e.rotate(t,0,0,0,u/f,d/f,0,p)}function Ue(e,t){return new Proxy(e,{get(e,n,r){let i=Reflect.get(e,n,r);return typeof i==`function`?function(...n){try{return i.apply(e,n)}catch(e){let n=WebAssembly.Exception;if(n&&e instanceof n)try{let[,n]=t.getExceptionMessage(e);throw Error(n,{cause:e})}catch(e){if(e instanceof Error&&!(e instanceof n))throw e}throw e}}:i}})}function We(e,t){let n=function(){return T(`compound`,t.makeNullShape())};return Object.assign(Object.create(e),{TopoDS_Solid:n,TopoDS_Face:n,TopoDS_Shape:n,TopoDS_Wire:n,TopoDS_Edge:n,TopoDS_Vertex:n,TopoDS_Shell:n,TopoDS_Compound:n,gp_Pnt_3:function(e,n,r){return T(`vertex`,t.makeVertex(e,n,r))},BRepBuilderAPI_MakeEdge_3:function(e,n){let r=e,i=n,a=t.vertexPosition(r.id),o=t.vertexPosition(i.id),s=t.makeLineEdge(a.get(0),a.get(1),a.get(2),o.get(0),o.get(1),o.get(2));return a.delete(),o.delete(),{Edge:()=>T(`edge`,s),delete(){}}}})}function Ge(e,t){let n=E(t),r=e.getSubShapes(n,`solid`);try{if(r.size()>1){let t=e.fuseAll(r);return{id:t,dispose:()=>{e.release(t)}}}return{id:n,dispose:()=>{}}}finally{for(let t=0,i=r.size();t<i;t++){let i=r.get(t);i!==n&&e.release(i)}r.delete()}}function Ke(e,t,n,r){return D(e,e.fuse(E(t),E(n)))}function qe(e,t,n,r){let i=Ge(e,n);try{return D(e,e.cut(E(t),i.id))}finally{i.dispose()}}function Je(e,t,n,r){let i=Ge(e,n);try{return D(e,e.intersect(E(t),i.id))}finally{i.dispose()}}function Ye(e,t,n,r){return D(e,e.section(E(t),E(n)))}function Xe(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.fuseAll(i))}finally{i.delete()}}function Ze(e,t,n,r,i){let a=Ie(t,r.map(E));try{return D(e,e.cutAll(E(n),a))}finally{a.delete()}}function Qe(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.split(E(n),i))}finally{i.delete()}}function $e(e,t,n,r){let i=[];return e.isNull(E(t))&&i.push({operand:`base`,issue:`null-shape`,message:`Base shape is null`}),e.isNull(E(n))&&i.push({operand:`tool`,issue:`null-shape`,message:`Tool shape is null`}),i.length===0&&!e.isValid(E(t))&&i.push({operand:`base`,issue:`not-valid`,message:`Base shape is not valid`}),i.length===0&&!e.isValid(E(n))&&i.push({operand:`tool`,issue:`not-valid`,message:`Tool shape is not valid`}),{valid:i.length===0,issues:i}}function et(e,t,n,r,i,a){throw Error(`occt-wasm: meshBoolean is not supported (use brepkit for mesh booleans)`)}function tt(e,t,n){return n!==t&&e.release(t),n}function nt(e,t,n,r){return T(`solid`,e.makeBox(t,n,r))}function rt(e,t,n,r,i){let a=e.makeCylinder(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function it(e,t,n){let r=e.makeSphere(t);return n&&(n[0]!==0||n[1]!==0||n[2]!==0)&&(r=tt(e,r,e.translate(r,n[0],n[1],n[2]))),T(`solid`,r)}function at(e,t,n,r,i,a){let o=e.makeCone(t,n,r);return a&&(o=tt(e,o,He(e,o,a))),i&&(i[0]!==0||i[1]!==0||i[2]!==0)&&(o=tt(e,o,e.translate(o,i[0],i[1],i[2]))),T(`solid`,o)}function ot(e,t,n,r,i){let a=e.makeTorus(t,n);return i&&(a=tt(e,a,He(e,a,i))),r&&(r[0]!==0||r[1]!==0||r[2]!==0)&&(a=tt(e,a,e.translate(a,r[0],r[1],r[2]))),T(`solid`,a)}function st(e,t,n,r){return T(`solid`,e.makeEllipsoid(t,n,r))}function ct(e,t,n){return T(`solid`,e.makeBoxFromCorners(t[0],t[1],t[2],n[0],n[1],n[2]))}function lt(e,t,n){return T(`face`,e.makeRectangle(t,n))}function ut(e,t,n){let r=e.getSubShapes(E(t),n),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(n,r.get(t)))}finally{r.delete()}return i}function dt(e,t){return Pe(t)?t.type:Fe(e.getShapeType(E(t)))}function ft(e,t,n){return e.isSame(E(t),E(n))}function pt(e,t,n){return e.isEqual(E(t),E(n))}function mt(e,t,n){return n?T(n,e.downcast(E(t),n)):t}function ht(e,t){return D(e,e.copy(E(t)))}function gt(e,t,n){return e.hashCode(E(t),n)}function _t(e,t){return e.isNull(E(t))}function vt(e,t){return e.shapeOrientation(E(t)).toLowerCase()}function yt(e,n){let r=e.edgeToFaceMap(E(n),1e6),i;try{i=ze(r)}finally{r.delete()}let a={};for(let e=0;e+1<i.length;e+=2){let n=t(i,e),r=t(i,e+1);a[n]||(a[n]=[]),a[n].push(r)}return JSON.stringify(a)}function bt(e,t,n){return e.subShapeCount(E(t),n)}function xt(e,t,n,r){let i=e.subShapeHashes(E(t),n,r);try{return ze(i)}finally{i.delete()}}function St(e,t,n){let r=e.sharedEdges(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`edge`,r.get(t)))}finally{r.delete()}return i}function Ct(e,t,n){let r=e.adjacentFaces(E(t),E(n)),i=[];try{let e=r.size();for(let t=0;t<e;t++)i.push(T(`face`,r.get(t)))}finally{r.delete()}return i}function wt(e,t,n,r){let i=Ie(t,n.map(E));try{return D(e,e.sew(i,r??1e-6))}finally{i.delete()}}var Tt=1e-6;function Et(e,t){return e.isValid(E(t))}function Dt(e,t){let n=e.healSolid(E(t),Tt);return n===0?null:D(e,n)}function Ot(e,t){return D(e,e.healFace(E(t),Tt))}function kt(e,t,n){return D(e,e.healWire(E(t),Tt))}function At(e,t,n){return 0}function jt(e,t,n){return e.removeDegenerateEdges(E(t)),0}function Mt(e,t){return e.fixFaceOrientations(E(t)),0}function Nt(e,t){return D(e,e.fixShape(E(t)))}function Pt(e,t,n,r){let i=e.tessellate(E(n),r.tolerance,r.angularTolerance);try{let e=i.positionCount,n=i.normalCount,a=i.indexCount,o=i.getPositionsPtr()>>2,s=i.getNormalsPtr()>>2,c=i.getIndicesPtr()>>2,l=new Float32Array(e);for(let n=0;n<e;n++)l[n]=t.HEAPF32[o+n]??0;let u=new Float32Array(n);if(!r.skipNormals)for(let e=0;e<n;e++)u[e]=t.HEAPF32[s+e]??0;let d=i.uvCount,f=new Float32Array(r.includeUVs?d:0);if(r.includeUVs&&d>0){let e=i.getUvsPtr()>>2;for(let n=0;n<d;n++)f[n]=t.HEAPF32[e+n]??0}let p=new Uint32Array(a);for(let e=0;e<a;e++)p[e]=t.HEAPU32[c+e]??0;let m=[],h=i.faceGroupCount;if(h>0){let e=i.getFaceGroupsPtr()>>2;for(let n=0;n<h;n+=3)m.push({start:t.HEAP32[e+n]??0,count:t.HEAP32[e+n+1]??0,faceHash:t.HEAP32[e+n+2]??0})}return{vertices:l,normals:r.skipNormals?new Float32Array:u,triangles:p,uvs:f,faceGroups:m}}finally{i.delete()}}function Ft(e,t,n,r){for(let i=0;i+1<n;i++){let n=t+i*3,a=e[n]??0,o=e[n+1]??0,s=e[n+2]??0,c=e[n+3]??0,l=e[n+4]??0,u=e[n+5]??0;(a!==c||o!==l||s!==u)&&r.push(a,o,s,c,l,u)}}function It(e,t,n,r,i){let a=e.wireframe(E(n),r);try{let e=t.HEAPF32,n=a.getPointsPtr()>>2,r=[],i=[],o=a.edgeGroupCount,s=o>0?a.getEdgeGroupsPtr()>>2:0;for(let a=0;a<o;a+=3){let o=n+(t.HEAP32[s+a]??0),c=Math.floor((t.HEAP32[s+a+1]??0)/3),l=r.length/3;Ft(e,o,c,r),i.push({start:l,count:r.length/3-l,edgeHash:t.HEAP32[s+a+2]??0})}return{lines:new Float32Array(r),edgeGroups:i}}finally{a.delete()}}function Lt(e,t){return e.hasTriangulation(E(t))}function Rt(e,t,n,r){e.meshShape(E(t),n,r).delete()}var zt={line:`LINE`,circle:`CIRCLE`,ellipse:`ELLIPSE`,hyperbola:`HYPERBOLA`,parabola:`PARABOLA`,bezier:`BEZIER_CURVE`,bspline:`BSPLINE_CURVE`,offset:`OFFSET_CURVE`,other:`OTHER_CURVE`};function Bt(e,t){let n=e.curveType(E(t));return zt[n]??n.toUpperCase()}function Vt(e,t){let n=e.curveParameters(E(t));try{return[n.get(0),n.get(1)]}finally{n.delete()}}function Ht(e,t,n){let r=e.curvePointAtParam(E(t),n);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function Ut(e,t,n){let r=e.curveTangent(E(t),n);try{let i=e.curvePointAtParam(E(t),n);try{return{point:[i.get(0),i.get(1),i.get(2)],tangent:[r.get(0),r.get(1),r.get(2)]}}finally{i.delete()}}finally{r.delete()}}function Wt(e,t){return e.curveIsClosed(E(t))}function Gt(e,t){return e.curveIsPeriodic(E(t))}function Kt(e,t){return 2*Math.PI}function qt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.interpolatePoints(a,r?.periodic??!1))}finally{a.delete()}}function Jt(e,t,n,r){let i=[];for(let e of n)i.push(e[0],e[1],e[2]);let a=Re(t,i);try{return T(`edge`,e.approximatePoints(a,r?.tolerance??.001))}finally{a.delete()}}function Yt(e,t,n){return T(`edge`,e.curveDegreeElevate(E(t),n))}function Xt(e,t,n,r){return T(`edge`,e.curveKnotInsert(E(t),n,r))}function Zt(e,t,n,r){return T(`edge`,e.curveKnotRemove(E(t),n,r))}function Qt(e,t,n){let r=e.curveSplit(E(t),n);try{return[T(`edge`,r.get(0)),T(`edge`,r.get(1))]}finally{r.delete()}}function $t(e,t){let n=en(e,t);if(!n||n.poles.length<2)return null;let r=n.poles[n.poles.length-2];return r?[r[0],r[1],r[2]]:null}function en(e,t){try{let n=e.getNurbsCurveData(E(t));try{let e=n.poles.size()/3,t=[];for(let r=0;r<e;r++)t.push([n.poles.get(r*3),n.poles.get(r*3+1),n.poles.get(r*3+2)]);let r=[];for(let e=0;e<n.knots.size();e++)r.push(n.knots.get(e));let i=[];for(let e=0;e<n.multiplicities.size();e++)i.push(n.multiplicities.get(e));let a=[];if(n.rational)for(let e=0;e<n.weights.size();e++)a.push(n.weights.get(e));else for(let t=0;t<e;t++)a.push(1);return{degree:n.degree,poles:t,weights:a,knots:r,multiplicities:i,isPeriodic:n.periodic,isRational:n.rational}}finally{n.delete()}}catch{return null}}function tn(e,t){let n=e.vertexPosition(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function nn(e,t){return e.surfaceType(E(t)).toLowerCase()}function rn(e,t){let n=e.uvBounds(E(t));try{return{uMin:n.get(0),uMax:n.get(1),vMin:n.get(2),vMax:n.get(3)}}finally{n.delete()}}function an(e,t){return T(`wire`,e.outerWire(E(t)))}function on(e,t){return T(`face`,e.reverseSurfaceU(E(t)))}function sn(e,t,n,r){let i=e.surfaceNormal(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}function cn(e,t,n,r){let i=e.pointOnSurface(E(t),n,r);try{return[i.get(0),i.get(1),i.get(2)]}finally{i.delete()}}var ln=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],un=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dn=e=>Math.hypot(e[0],e[1],e[2]),fn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];function pn(e,t){if(nn(e,t)!==`cylinder`)return null;let n=rn(e,t),r=.5*(n.vMin+n.vMax),i=n.uMin+.25*(n.uMax-n.uMin),a=n.uMin+.5*(n.uMax-n.uMin),o=sn(e,t,i,r),s=sn(e,t,a,r),c=cn(e,t,i,r),l=cn(e,t,a,r),u=fn(o,s),d=dn(u),f=dn(ln(o,s));if(d<1e-9||f<1e-9)return null;let p=[u[0]/d,u[1]/d,u[2]/d],m=dn(ln(c,l))/f,h=[c[0]-m*o[0],c[1]-m*o[1],c[2]-m*o[2]],g=dn(ln(h,[l[0]-m*s[0],l[1]-m*s[1],l[2]-m*s[2]]))<1e-6?h:[c[0]+m*o[0],c[1]+m*o[1],c[2]+m*o[2]];return{origin:g,direction:p,radius:m,isDirect:(vt(e,t)===`reversed`?-1:1)*un(o,ln(c,g))>0}}function mn(e,t,n){let r=ln(t,e),i=ln(n,e),a=fn(r,i),o=un(a,a);if(o<1e-18)return null;let s=un(r,r),c=un(i,i),l=fn([s*i[0]-c*r[0],s*i[1]-c*r[1],s*i[2]-c*r[2]],a),u=1/(2*o);return[e[0]+l[0]*u,e[1]+l[1]*u,e[2]+l[2]*u]}function hn(e,t,n,r,i){return mn(cn(e,t,n+.1*(r-n),i),cn(e,t,n+.45*(r-n),i),cn(e,t,n+.8*(r-n),i))}function gn(e,t){let n=rn(e,t),r=[.2,.5,.8].map(r=>hn(e,t,n.uMin,n.uMax,n.vMin+r*(n.vMax-n.vMin))).filter(e=>e!==null);if(r.length<2)return null;let i=null,a=1e-9;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=r[e],o=r[t];if(!n||!o)continue;let s=ln(o,n),c=dn(s);c>a&&(a=c,i={origin:n,direction:[s[0]/c,s[1]/c,s[2]/c]})}return i}function _n(e,t){let n=nn(e,t);if(n===`cylinder`){let n=pn(e,t);return n?{origin:n.origin,direction:n.direction}:null}return n===`cone`||n===`torus`||n===`revolution`?gn(e,t):null}function vn(e,t){let n=e.getFaceCylinderData(E(t));try{return n.size()<2?null:{radius:n.get(0),isDirect:n.get(1)===1}}finally{n.delete()}}function yn(e,t,n){let r=e.uvFromPoint(E(t),n[0],n[1],n[2]);try{return r.size()<2?null:[r.get(0),r.get(1)]}finally{r.delete()}}function bn(e,t,n){let r=e.projectPointOnFace(E(t),n[0],n[1],n[2]);try{return[r.get(0),r.get(1),r.get(2)]}finally{r.delete()}}function xn(e,t,n,r,i){return e.classifyPointOnFace(E(t),n,r).toLowerCase()}function Sn(e,t,n,r,i,a){let[o,s,c]=r,[l,u,d]=i,f=!!a,[p,m,h]=a??[1,0,0],g=e.projectEdges(E(n),o,s,c,l,u,d,p,m,h,f),_=n=>n===0?T(`compound`,e.makeCompound(new t.VectorUint32)):T(`compound`,n);return{visible:{outline:_(g.visibleOutline),smooth:_(g.visibleSmooth),sharp:_(g.visibleSharp)},hidden:{outline:_(g.hiddenOutline),smooth:_(g.hiddenSmooth),sharp:_(g.hiddenSharp)}}}function Cn(e,t){return e.getVolume(E(t))}function wn(e,t){return e.getSurfaceArea(E(t))}function Tn(e,t){return e.getLength(E(t))}function En(e,t){let n=e.getCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function Dn(e,t){let n=e.getLinearCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}function On(e,t){let n=e.getBoundingBox(E(t),!0);return{min:[n.xmin,n.ymin,n.zmin],max:[n.xmax,n.ymax,n.zmax]}}function kn(e,t){try{let n=e.getSurfaceCenterOfMass(E(t));try{return[n.get(0),n.get(1),n.get(2)]}finally{n.delete()}}catch{return[0,0,0]}}function An(e,t,n){return{volume:Cn(e,t),area:wn(e,t),length:n?Tn(e,t):0,centerOfMass:En(e,t),boundingBox:On(e,t)}}function jn(e,t){let n=E(t);return{distanceTo(t){return{value:e.distanceBetween(n,E(t)),point1:[0,0,0],point2:[0,0,0]}},dispose:Ne}}var Mn=256;function Nn(e,t,n){let r=[],i=e.getSubShapes(n,`vertex`);try{let t=i.size();for(let n=0;n<t;n++){let t=e.vertexPosition(i.get(n));r.push([t.get(0),t.get(1),t.get(2)]),t.delete()}}finally{i.delete()}let a=e.getBoundingBox(n,!0),o=Math.sqrt((a.xmax-a.xmin)**2+(a.ymax-a.ymin)**2+(a.zmax-a.zmin)**2),s=Math.max(o*.01,1e-4),c;try{c=e.tessellate(n,s,.5)}catch{return r}try{let e=c.positionCount;if(e>0){let n=c.getPositionsPtr()>>2,i=t.HEAPF32,a=Math.floor(e/3),o=(a>Mn?Math.ceil(a/Mn):1)*3;for(let t=0;t<e;t+=o)r.push([i[n+t]??0,i[n+t+1]??0,i[n+t+2]??0])}}finally{c.delete()}return r}function Pn(e,t,n,r){let i=E(n),a=E(r),o=e.distanceBetween(i,a),s=Nn(e,t,i),c=Nn(e,t,a);if(s.length===0||c.length===0)return{value:o,point1:[0,0,0],point2:[0,0,0]};let l=1/0,u=s[0]??[0,0,0],d=c[0]??[0,0,0];for(let e of s)for(let t of c){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],a=n*n+r*r+i*i;a<l&&(l=a,u=e,d=t)}return{value:o,point1:u,point2:d}}function Fn(e,t,n,r){let i=e.pointOnSurface(t,n,r),a=[i.get(0),i.get(1),i.get(2)];return i.delete(),a}function In(e,t,n,r){let i=e.uvBounds(t),a=i.get(0),o=i.get(1),s=i.get(2),c=i.get(3);i.delete();let l=Math.max(Math.max(o-a,1e-12)*.001,1e-6),u=Math.max(Math.max(c-s,1e-12)*.001,1e-6),d=Math.min(Math.max(n,a+l),o-l),f=Math.min(Math.max(r,s+u),c-u),p=Fn(e,t,d,f),m=Fn(e,t,d+l,f),h=Fn(e,t,d-l,f),g=Fn(e,t,d,f+u),_=Fn(e,t,d,f-u),v=Fn(e,t,d+l,f+u),y=Fn(e,t,d+l,f-u),b=Fn(e,t,d-l,f+u),x=Fn(e,t,d-l,f-u),S=l*l,C=u*u,w=4*l*u;return{Pu:[(m[0]-h[0])/(2*l),(m[1]-h[1])/(2*l),(m[2]-h[2])/(2*l)],Pv:[(g[0]-_[0])/(2*u),(g[1]-_[1])/(2*u),(g[2]-_[2])/(2*u)],Puu:[(m[0]-2*p[0]+h[0])/S,(m[1]-2*p[1]+h[1])/S,(m[2]-2*p[2]+h[2])/S],Pvv:[(g[0]-2*p[0]+_[0])/C,(g[1]-2*p[1]+_[1])/C,(g[2]-2*p[2]+_[2])/C],Puv:[(v[0]-y[0]-b[0]+x[0])/w,(v[1]-y[1]-b[1]+x[1])/w,(v[2]-y[2]-b[2]+x[2])/w]}}function Ln(e,t,n,r){return Math.abs(e)+Math.abs(t)>=Math.abs(n)+Math.abs(r)?Math.abs(e)+Math.abs(t)<1e-12?[1,0]:[-t,e]:Math.abs(n)+Math.abs(r)<1e-12?[0,1]:[-r,n]}function Rn(e,t,n){let r=e[0]*t[0]+e[1]*n[0],i=e[0]*t[1]+e[1]*n[1],a=e[0]*t[2]+e[1]*n[2],o=Math.sqrt(r*r+i*i+a*a);return o<1e-12?[1,0,0]:[r/o,i/o,a/o]}function zn(e,t){let n=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(n<1e-12)return{maxDirection:[1,0,0],minDirection:[0,1,0]};let r=e[0]/n,i=e[1]/n,a=e[2]/n,o=r*t[0]+i*t[1]+a*t[2],s=t[0]-o*r,c=t[1]-o*i,l=t[2]-o*a,u=Math.sqrt(s*s+c*c+l*l);if(u<1e-12){let e=Math.abs(r)<.9?[1,0,0]:[0,1,0],t=i*e[2]-a*e[1],n=a*e[0]-r*e[2],o=r*e[1]-i*e[0],s=Math.sqrt(t*t+n*n+o*o)||1;return{maxDirection:[r,i,a],minDirection:[t/s,n/s,o/s]}}return{maxDirection:[r,i,a],minDirection:[s/u,c/u,l/u]}}function Bn(e,t,n,r,i,a){let{Pu:o,Pv:s,Puu:c,Pvv:l,Puv:u}=In(e,t,n,r),d=o[1]*s[2]-o[2]*s[1],f=o[2]*s[0]-o[0]*s[2],p=o[0]*s[1]-o[1]*s[0],m=Math.sqrt(d*d+f*f+p*p),h=o[0]*o[0]+o[1]*o[1]+o[2]*o[2],g=o[0]*s[0]+o[1]*s[1]+o[2]*s[2],_=s[0]*s[0]+s[1]*s[1]+s[2]*s[2];if(m<1e-12||h*_-g*g<1e-24)return zn(o,s);let v=(c[0]*d+c[1]*f+c[2]*p)/m,y=(u[0]*d+u[1]*f+u[2]*p)/m,b=(l[0]*d+l[1]*f+l[2]*p)/m,x=h*_-g*g,S=(v*_-y*g)/x,C=(y*_-b*g)/x,w=(y*h-v*g)/x,ee=(b*h-y*g)/x;if(Math.abs(i-a)<1e-9*(Math.abs(i)+Math.abs(a)+1))return zn(o,s);let te=Ln(S-i,C,w,ee-i),ne=Ln(S-a,C,w,ee-a);return{maxDirection:Rn(te,o,s),minDirection:Rn(ne,o,s)}}function Vn(e,t,n,r){let i=E(t),a=e.surfaceCurvature(i,n,r),o=a.get(0),s=a.get(1),c=a.get(2),l=a.get(3);a.delete();let{maxDirection:u,minDirection:d}=Bn(e,i,n,r,c,l);return{gaussian:s,mean:o,max:c,min:l,maxDirection:u,minDirection:d}}var Hn=2147483647;function Un(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.fillet(E(n),o,a))}finally{o.delete()}}function Wn(e,t,n,r,i){let a=Ve(r,i),o=Ie(t,r.map(E));try{return D(e,e.chamfer(E(n),o,a))}finally{o.delete()}}function Gn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.chamferDistAngle(E(n),o,i,a))}finally{o.delete()}}function Kn(e,t,n,r,i,a){let o=Ie(t,r.map(E));try{return D(e,e.shell(E(n),o,i,a??.001))}finally{o.delete()}}function qn(e,t,n){return D(e,e.thicken(E(t),n,.001))}function Jn(e,t,n,r){return D(e,e.offset(E(t),n,r??1e-6))}function Yn(e,t,n,r,i){let a=e.filletVariable(t,n,r,i),o=!0;try{let t=e.getSubShapes(a,`solid`);try{let n=t.size()===1?t.get(0):-1;for(let r=0,i=t.size();r<i;r++){let i=t.get(r);i!==n&&e.release(i)}return n===-1?(o=!1,D(e,a)):D(e,n)}finally{t.delete()}}finally{o&&e.release(a)}}function Xn(e,t,n){let r=JSON.parse(n);if(r.edgeId!==void 0&&r.startRadius!==void 0&&r.endRadius!==void 0)return Yn(e,E(t),r.edgeId,r.startRadius,r.endRadius);if(r.edge!==void 0&&Array.isArray(r.radii)&&r.radii.length>0){let n=r.radii;if(n.length>2)throw new c(`occt-wasm: filletVariable supports only a linear (<=2-point) radius profile; a multi-point variable radius requires the brepkit kernel`);let i=n[0].radius,a=n[n.length-1].radius,o=E(t),s=e.getSubShapes(o,`edge`),l=-1;try{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);if(e.hashCode(n,Hn)===r.edge){l=n;break}}}finally{for(let t=0,n=s.size();t<n;t++){let n=s.get(t);n!==l&&e.release(n)}s.delete()}if(l===-1)throw new c(`occt-wasm: filletVariable: target edge not found on the shape`);try{return Yn(e,o,l,i,a)}finally{e.release(l)}}throw new c(`occt-wasm: filletVariable: unrecognized spec`)}function Zn(e,t,n,r,i,a){let o=E(t);for(let t of n){let n=(typeof a==`function`?a(t):a)*Math.PI/180;o=e.draft(o,E(t),n,r[0],r[1],r[2])}return D(e,o)}function Qn(e,t,n,r){let i=Ie(t,r.map(E));try{return D(e,e.defeature(E(n),i,0))}finally{i.delete()}}function $n(e,t,n,r){let i=0;return r===`intersection`||r===1?i=1:r===`tangent`||r===2?i=2:typeof r==`number`&&(i=r),D(e,e.offsetWire2D(E(t),n,i))}function er(e,t){return D(e,e.simplify(E(t)))}function tr(e,t){return D(e,e.reverseShape(E(t)))}var nr=0,rr=1,ir=3,ar=0;function or(e){switch(e){case`round`:return 2;case`right`:return 1;default:return 0}}var sr=0,cr=1,lr=2;function ur(e){let t=e?.profile;return t===`linear`?cr:t===`s-curve`?lr:sr}var dr=new Set;function fr(e,t,n){t.length===0||dr.has(e)||(dr.add(e),console.warn(`occt-wasm: sweep ignored ${t.join(`, `)} — ${n}.`))}function pr(e,t){let n=e.getSubShapes(E(t),`wire`);try{return{shape:t,firstShape:n.size()>0?D(e,n.get(0)):t,lastShape:n.size()>1?D(e,n.get(n.size()-1)):t}}finally{n.delete()}}function mr(e,t,n,r){let i=n[0]*r,a=n[1]*r,o=n[2]*r;return D(e,e.extrude(E(t),i,a,o))}function hr(e,t,n,r){let i=n.origin,a=n.direction;return D(e,e.revolve(E(t),i.x,i.y,i.z,a.x,a.y,a.z,r))}function gr(e,t,n,r,i,a){let o=i?E(i):0,s=a?E(a):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,!0,r??!1,o,s)):D(e,e.loft(c,!0,r??!1))}finally{c.delete()}}function _r(e,t,n,r){let i=r?.transitionMode??0;return D(e,e.sweep(E(t),E(n),i))}function vr(e,t,n){return D(e,e.simplePipe(E(t),E(n)))}function yr(e){let t=e?.auxiliary?ir:e?.frenet?rr:nr,n=e?.tolerance;return{mode:t,transitionMode:or(e?.transitionMode),auxiliaryId:e?.auxiliary?E(e.auxiliary):0,contact:e?.contact??!1,correction:e?.correction??!1,tol3d:n??0,boundTol:n===void 0?0:e?.boundTolerance??n,tolAngular:n===void 0?0:e?.angularTolerance??1e-7}}function br(e,t,n,r){let i=r?.shellMode??!1,a=yr(r),o=ur(r?.law),s=typeof e.sweepFull==`function`?xr(e,t,n,r,a,o):typeof e.sweepAdvanced==`function`?Cr(e,t,n,r,a,o):wr(e,t,n,r,o);return i?pr(e,s):s}function xr(e,t,n,r,i,a){if(r?.support)try{return Sr(e,t,n,r,i,a,E(r.support))}catch(o){if(!(o instanceof Error)||!o.message.includes(`not a valid spine support`))throw o;return fr(`support-invalid`,[`support`],`the support shape does not carry the spine, so OCCT swept with its default frame`),Sr(e,t,n,r,i,a,0)}return Sr(e,t,n,r,i,a,0)}function Sr(e,t,n,r,i,a,o){let s=r?.law;if(typeof e.sweepFull!=`function`)throw Error(`occt-wasm: sweepFull is unavailable`);return D(e,e.sweepFull(E(t),E(n),i.mode,0,0,1,i.auxiliaryId,!1,ar,i.transitionMode,i.contact,i.correction,i.tol3d,i.boundTol,i.tolAngular,o,r?.maxDegree??0,r?.maxSegments??0,a,s?.length??0,s?.endFactor??1))}function Cr(e,t,n,r,i,a){if(fr(`sweepFull`,[...a===sr?[]:[`law`],...r?.support?[`support`]:[],...r?.maxDegree?[`maxDegree`]:[],...r?.maxSegments?[`maxSegments`]:[]],`sweepFull requires occt-wasm >= 4.2.0`),typeof e.sweepAdvanced!=`function`)throw Error(`occt-wasm: sweepAdvanced is unavailable`);return D(e,e.sweepAdvanced(E(t),E(n),i.mode,0,0,1,i.auxiliaryId,!1,ar,i.transitionMode,i.contact,i.correction,i.tol3d,i.boundTol,i.tolAngular))}function wr(e,t,n,r,i){return fr(`sweepAdvanced`,[...r?.auxiliary?[`auxiliary`]:[],...r?.contact?[`contact`]:[],...r?.correction?[`correction`]:[],...r?.tolerance===void 0?[]:[`tolerance`],...r?.transitionMode===`right`?[`transitionMode 'right'`]:[],...i===sr?[]:[`law`],...r?.support?[`support`]:[],...r?.maxDegree?[`maxDegree`]:[],...r?.maxSegments?[`maxSegments`]:[]],`sweepAdvanced requires occt-wasm >= 4.1.0`),D(e,e.sweepPipeShell(E(t),E(n),r?.frenet??!1,r?.transitionMode===`round`))}function Tr(e,t,n,r){let i=r?.solid??!0,a=r?.ruled??!1,o=r?.startVertex?E(r.startVertex):0,s=r?.endVertex?E(r.endVertex):0,c=Ie(t,n.map(E));try{return o||s?D(e,e.loftWithVertices(c,i,a,o,s)):D(e,e.loft(c,i,a))}finally{c.delete()}}function Er(e,t,n,r){let i={__occtWasmLaw:!0,profile:t,length:n,endFactor:r,Trim(e,t,n){return{...i,trimFirst:e,trimLast:t}},delete(){}};return i}function Dr(e,t,n,r,i){return D(e,e.revolveVec(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i))}function Or(e,t,n,r,i,a,o){let s=i??10;return D(e,e.draftPrism(E(t),0,0,s,a))}function kr(e){let t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];for(let n of e)if(n.type===`translate`)t=Be([1,0,0,n.x,0,1,0,n.y,0,0,1,n.z,0,0,0,1],t);else{let e=n.axis??[0,0,1],r=n.center??[0,0,0],i=n.angle*Math.PI/180,a=Math.cos(i),o=Math.sin(i),s=1-a,c=Math.sqrt(e[0]**2+e[1]**2+e[2]**2),[l,u,d]=[e[0]/c,e[1]/c,e[2]/c],f=s*l*l+a,p=s*l*u-o*d,m=s*l*d+o*u,h=s*u*l+o*d,g=s*u*u+a,_=s*u*d-o*l,v=s*d*l-o*u,y=s*d*u+o*l,b=s*d*d+a;t=Be([f,p,m,r[0]-(f*r[0]+p*r[1]+m*r[2]),h,g,_,r[1]-(h*r[0]+g*r[1]+_*r[2]),v,y,b,r[2]-(v*r[0]+y*r[1]+b*r[2]),0,0,0,1],t)}return{handle:{__type:`transform_matrix`,matrix:t,delete:Ne},dispose:Ne}}function Ar(e){let t=e,n;return Array.isArray(t)?n=t:typeof t==`object`&&t&&(Array.isArray(t.matrix)?n=t.matrix:Array.isArray(t.elements)&&(n=t.elements)),n&&n.length===16&&(n=n.slice(0,12)),n&&n.length>=12?n:void 0}function jr(e,t,n,r){let i=Ar(r);if(i){let r=Re(t,i);try{return D(e,e.transform(E(n),r))}finally{r.delete()}}return T(e.getShapeType(E(n)),e.copy(E(n)))}function Mr(e,t,n,r){if(typeof e.located==`function`){let i=Ar(r);if(i){let r=Re(t,i);try{return D(e,e.located(E(n),r))}finally{r.delete()}}}return jr(e,t,n,r)}function Nr(e,t,n,r,i){return D(e,e.translate(E(t),n,r,i))}function Pr(e,t,n,r,i){let a=r??[0,0,1],o=i??[0,0,0];return D(e,e.rotate(E(t),o[0],o[1],o[2],a[0],a[1],a[2],n))}function Fr(e,t,n,r){return D(e,e.mirror(E(t),n[0],n[1],n[2],r[0],r[1],r[2]))}function Ir(e,t,n,r){return D(e,e.scale(E(t),n[0],n[1],n[2],r))}function Lr(e,t,n,r,i,a){let o=Re(t,[r[0],r[1],r[2],i[0],r[3],r[4],r[5],i[1],r[6],r[7],r[8],i[2]]);try{return D(e,a?e.transform(E(n),o):e.generalTransform(E(n),o))}finally{o.delete()}}function Rr(e,t,n,r,i){let a=e.curvePointAtParam(E(r),i),[o,s,c]=(()=>{try{return[a.get(0),a.get(1),a.get(2)]}finally{a.delete()}})(),l=e.curveTangent(E(r),i),[u,d,f]=(()=>{try{return[l.get(0),l.get(1),l.get(2)]}finally{l.delete()}})(),p,m,h;Math.abs(u)<.9?(p=0,m=f,h=-d):(p=-f,m=0,h=u);let g=Math.sqrt(p*p+m*m+h*h);p/=g,m/=g,h/=g;let _=d*h-f*m,v=f*p-u*h,y=u*m-d*p,b=new t.VectorDouble;b.push_back(p),b.push_back(_),b.push_back(u),b.push_back(o),b.push_back(m),b.push_back(v),b.push_back(d),b.push_back(s),b.push_back(h),b.push_back(y),b.push_back(f),b.push_back(c);try{return D(e,e.transform(E(n),b))}finally{b.delete()}}function zr(e,t,n,r,i){let a=e.linearPattern(E(t),n[0],n[1],n[2],r,i),o=e.getSubShapes(a,`solid`),s=[];try{let e=o.size();for(let t=0;t<e;t++)s.push(T(`solid`,o.get(t)))}finally{o.delete()}if(s.length===0){let t=e.iterShapes(a);try{let n=t.size();for(let r=0;r<n;r++)s.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(a),s}function Br(e,t,n,r,i,a){let o=e.circularPattern(E(t),n[0],n[1],n[2],r[0],r[1],r[2],i,a),s=e.getSubShapes(o,`solid`),c=[];try{let e=s.size();for(let t=0;t<e;t++)c.push(T(`solid`,s.get(t)))}finally{s.delete()}if(c.length===0){let t=e.iterShapes(o);try{let n=t.size();for(let r=0;r<n;r++)c.push(D(e,t.get(r)))}finally{t.delete()}}return e.release(o),c}function Vr(e,t){return t.map(t=>{switch(t.type){case`translate`:return Nr(e,t.shape,t.x,t.y,t.z);case`rotate`:return Pr(e,t.shape,t.angle,t.axis,t.center);case`scale`:return Ir(e,t.shape,t.center,t.factor);case`mirror`:return Fr(e,t.shape,t.origin,t.normal);default:throw Error(`occt-wasm: transformBatch unknown type`)}})}function Hr(e,t){if(t===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,r=1/0,i=1/0,a=-1/0,o=-1/0,s=-1/0;for(let c=0;c<t;c++){let t=c*3,l=e[t]??0,u=e[t+1]??0,d=e[t+2]??0;l<n&&(n=l),u<r&&(r=u),d<i&&(i=d),l>a&&(a=l),u>o&&(o=u),d>s&&(s=d)}return{min:[n,r,i],max:[a,o,s]}}function Ur(e,t,n,r,i,a,o,s){return{asset:{version:`2.0`,generator:`brepjs occt-wasm`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0,NORMAL:1},indices:2,mode:4}]}],buffers:[{byteLength:o}],bufferViews:[{buffer:0,byteOffset:0,byteLength:r,target:34962},{buffer:0,byteOffset:r,byteLength:i,target:34962},{buffer:0,byteOffset:r+i,byteLength:a,target:34963}],accessors:[{bufferView:0,componentType:5126,count:e,type:`VEC3`,min:s.min,max:s.max},{bufferView:1,componentType:5126,count:t,type:`VEC3`},{bufferView:2,componentType:5125,count:n,type:`SCALAR`}]}}function Wr(e,t,n){if(n.length===1)return e.exportStep(E(n[0]));let r=t(n);return e.exportStep(E(r))}function Gr(e,t,n,r=De,i=Oe){let{vertices:a,triangles:o}=e(t,{tolerance:r,angularTolerance:i,skipNormals:!0});return n?je(a,o):Me(a,o)}function Kr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importStep(n))]}function qr(e,t,n){let r=typeof n==`string`?new TextEncoder().encode(n):new Uint8Array(n),i=t;if(i.FS)i.FS.writeFile(`/tmp/import.stl`,r);else{let t=Array.from(r,e=>String.fromCharCode(e)).join(``);return D(e,e.importStl(t))}return D(e,e.importStl(``))}function Jr(e,t,n){if(n.length===1)return e.exportIges(E(n[0]));let r=t(n);return e.exportIges(E(r))}function Yr(e,t){let n=typeof t==`string`?t:new TextDecoder().decode(t);return[D(e,e.importIges(n))]}function Xr(e,t,n,r){if(n.length===0)return``;let i=ni(e,t,n);try{return ri(e,i)}finally{i.delete()}}function Zr(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=i.length/3,c=a.length/3,l=o.length,u=i.byteLength,d=a.byteLength,f=o.byteLength,p=u+d+f,m=p+(4-p%4)%4,h=Ur(s,c,l,u,d,f,m,Hr(i,s)),g=new TextEncoder().encode(JSON.stringify(h)),_=g.byteLength+(4-g.byteLength%4)%4,v=20+_+8+m,y=new ArrayBuffer(v),b=new DataView(y);b.setUint32(0,1179937895,!0),b.setUint32(4,2,!0),b.setUint32(8,v,!0),b.setUint32(12,_,!0),b.setUint32(16,1313821514,!0);let x=new Uint8Array(y,20,_);x.set(g);for(let e=g.byteLength;e<_;e++)x[e]=32;let S=20+_;b.setUint32(S,m,!0),b.setUint32(S+4,5130562,!0);let C=S+8;return new Uint8Array(y,C,u).set(new Uint8Array(i.buffer,i.byteOffset,u)),new Uint8Array(y,C+u,d).set(new Uint8Array(a.buffer,a.byteOffset,d)),new Uint8Array(y,C+u+d,f).set(new Uint8Array(o.buffer,o.byteOffset,f)),y}function Qr(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=[`# brepjs OBJ export`],c=i.length/3;for(let e=0;e<c;e++){let t=e*3;s.push(`v ${i[t]??0} ${i[t+1]??0} ${i[t+2]??0}`)}let l=a.length/3;for(let e=0;e<l;e++){let t=e*3;s.push(`vn ${a[t]??0} ${a[t+1]??0} ${a[t+2]??0}`)}let u=e=>{let t=(o[e]??0)+1,n=(o[e+1]??0)+1,r=(o[e+2]??0)+1;s.push(`f ${t}//${t} ${n}//${n} ${r}//${r}`)};if(r.faceGroups.length>0)for(let e of r.faceGroups){s.push(`g face_${e.faceHash}`);let t=e.count/3;for(let n=0;n<t;n++)u(e.start+n*3)}else{let e=o.length/3;for(let t=0;t<e;t++)u(t*3)}return new TextEncoder().encode(s.join(`
|
|
4
4
|
`)+`
|
|
5
5
|
`).buffer}function $r(e,t,n){let r=e(t,{tolerance:n,angularTolerance:.5,skipNormals:!1}),i=r.vertices,a=r.normals,o=r.triangles,s=i.length/3,c=o.length/3,l=a.length===i.length,u=[`ply`,`format ascii 1.0`,`comment brepjs PLY export`,`element vertex ${s}`,`property float x`,`property float y`,`property float z`];l&&u.push(`property float nx`,`property float ny`,`property float nz`),u.push(`element face ${c}`,`property list uchar int vertex_index`,`end_header`);for(let e=0;e<s;e++){let t=e*3,n=i[t]??0,r=i[t+1]??0,o=i[t+2]??0;if(l){let e=a[t]??0,i=a[t+1]??0,s=a[t+2]??0;u.push(`${n} ${r} ${o} ${e} ${i} ${s}`)}else u.push(`${n} ${r} ${o}`)}for(let e=0;e<c;e++){let t=o[e*3]??0,n=o[e*3+1]??0,r=o[e*3+2]??0;u.push(`3 ${t} ${n} ${r}`)}return new TextEncoder().encode(u.join(`
|
|
6
6
|
`)+`
|
|
@@ -12,7 +12,7 @@ var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);function
|
|
|
12
12
|
`)){let t=e.trim();if(t.startsWith(`v `)){let e=t.slice(2).trim().split(/\s+/);r.push(Number(e[0]),Number(e[1]),Number(e[2]))}else if(t.startsWith(`f `)){let e=t.slice(2).trim().split(/\s+/).map(e=>{let t=e.split(`/`)[0]??``,n=Number(t);return n>0?n-1:r.length/3+n});for(let t=1;t+1<e.length;t++)i.push(e[0]??0,e[t]??0,e[t+1]??0)}}return iw(e,{vertProperties:Float32Array.from(r),triVerts:Uint32Array.from(i)})}function ow(e,t){let n=new Uint8Array(t),r=new TextDecoder().decode(n.subarray(0,Math.min(n.length,80))).trimStart().toLowerCase().startsWith(`solid`)&&lw(n),i=[];if(r){let e=new TextDecoder().decode(n).match(/vertex\s+(\S+)\s+(\S+)\s+(\S+)/g)??[];for(let t of e){let e=t.trim().split(/\s+/);i.push(Number(e[1]),Number(e[2]),Number(e[3]))}}else{let e=new DataView(t),n=e.getUint32(80,!0),r=84;for(let t=0;t<n;t++){r+=12;for(let t=0;t<3;t++)i.push(e.getFloat32(r,!0),e.getFloat32(r+4,!0),e.getFloat32(r+8,!0)),r+=12;r+=2}}let a=cw(i);return iw(e,{vertProperties:Float32Array.from(a.vertices),triVerts:Uint32Array.from(a.indices)})}var sw=1e6;function cw(e){let t=[],n=[],r=new Map;for(let i=0;i+2<e.length;i+=3){let a=e[i]??0,o=e[i+1]??0,s=e[i+2]??0,c=`${Math.round(a*sw)},${Math.round(o*sw)},${Math.round(s*sw)}`,l=r.get(c);l===void 0&&(l=t.length/3,r.set(c,l),t.push(a,o,s)),n.push(l)}return{vertices:t,indices:n}}function lw(e){return e.length<84||84+new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0)*50!==e.length}var uw=1e-6;function dw(e,t){let n=N(t);if(n.replayable)return nC(n,e)}function fw(e,t){let n=YC(t),r=Math.floor(n.triVerts.length/3),i=[];for(let t=0;t<r;t++){let[r,a,o]=$C(n,t),s=e.buildTriFace(QC(n,r),QC(n,a),QC(n,o));s&&i.push(s)}if(i.length===0)throw Error(`manifold: cannot export — shape has no triangles to facet`);return e.sewAndSolidify(i,uw)}function pw(e){let t=My(`B-rep export`),n=dw(t,e);return n===void 0?(console.warn(`manifold: exact B-rep unavailable (non-replayable op-graph); exporting faceted approximation`),{occt:t,brep:fw(t,e)}):{occt:t,brep:n}}function mw(e,t,n,r){let i=t.mesh(n,{tolerance:.01,angularTolerance:.5});return iw(e,{vertProperties:Float32Array.from(i.vertices),triVerts:Uint32Array.from(i.triangles)},r)}var hw=1179937895,gw=2,_w=1313821514,vw=5130562,yw=5126,bw=5125,xw=5123,Sw=5121,Cw=34962,ww=34963,Tw=4;function Ew(e){return e+3&-4}function Dw(e){let t=YC(e),n=t.numProp&&t.numProp>=3?t.numProp:3,r=Math.floor(t.vertProperties.length/n),i=t.triVerts.length,a=new Float32Array(r*3),o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let e=0;e<r;e++){let r=t.vertProperties[e*n]??0,i=t.vertProperties[e*n+1]??0,f=t.vertProperties[e*n+2]??0;a[e*3]=r,a[e*3+1]=i,a[e*3+2]=f,r<o&&(o=r),i<s&&(s=i),f<c&&(c=f),r>l&&(l=r),i>u&&(u=i),f>d&&(d=f)}r===0&&(o=s=c=l=u=d=0);let f=Uint32Array.from(t.triVerts),p=a.byteLength,m=Ew(p),h=m+f.byteLength,g={asset:{version:`2.0`,generator:`brepjs manifold kernel`},scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0}],meshes:[{primitives:[{attributes:{POSITION:0},indices:1,mode:Tw}]}],accessors:[{bufferView:0,componentType:yw,count:r,type:`VEC3`,min:[o,s,c],max:[l,u,d]},{bufferView:1,componentType:bw,count:i,type:`SCALAR`}],bufferViews:[{buffer:0,byteOffset:0,byteLength:p,target:Cw},{buffer:0,byteOffset:m,byteLength:f.byteLength,target:ww}],buffers:[{byteLength:h}]},_=new TextEncoder().encode(JSON.stringify(g)),v=Ew(_.length),y=Ew(h),b=20+v+8+y,x=new ArrayBuffer(b),S=new DataView(x),C=new Uint8Array(x);S.setUint32(0,hw,!0),S.setUint32(4,gw,!0),S.setUint32(8,b,!0);let w=12;S.setUint32(w,v,!0),S.setUint32(w+4,_w,!0),w+=8,C.set(_,w);for(let e=_.length;e<v;e++)C[w+e]=32;return w+=v,S.setUint32(w,y,!0),S.setUint32(w+4,vw,!0),w+=8,C.set(new Uint8Array(a.buffer,a.byteOffset,p),w),C.set(new Uint8Array(f.buffer,f.byteOffset,f.byteLength),w+m),x}function Ow(e,t){let n=new DataView(t);if(n.getUint32(0,!0)!==hw)throw Error(`manifold: importGLB — not a binary glTF (bad magic)`);let r=n.getUint32(8,!0),i,a,o=12;for(;o<r;){let e=n.getUint32(o,!0),r=n.getUint32(o+4,!0),s=new Uint8Array(t,o+8,e);r===_w?i=JSON.parse(new TextDecoder().decode(s)):r===vw&&(a=s),o+=8+e}if(!i||typeof i!=`object`||!a)throw Error(`manifold: importGLB — missing JSON or BIN chunk`);let s=i,c=s.meshes?.[0]?.primitives[0],l=s.accessors??[],u=s.bufferViews??[];if(!c||c.attributes.POSITION===void 0)throw Error(`manifold: importGLB — no POSITION attribute`);let d=l[c.attributes.POSITION];if(!d)throw Error(`manifold: importGLB — invalid POSITION accessor`);let f=u[d.bufferView];if(!f)throw Error(`manifold: importGLB — invalid POSITION bufferView`);let p=new Float32Array(a.buffer.slice(a.byteOffset+(f.byteOffset??0),a.byteOffset+(f.byteOffset??0)+d.count*3*4)),m;if(c.indices!==void 0){let e=l[c.indices];if(!e)throw Error(`manifold: importGLB — invalid indices accessor`);let t=u[e.bufferView];if(!t)throw Error(`manifold: importGLB — invalid indices bufferView`);let n=e.componentType===bw?4:e.componentType===xw?2:+(e.componentType===Sw);if(n===0)throw Error(`manifold: importGLB — unsupported index component type ${e.componentType}`);let r=a.byteOffset+(t.byteOffset??0),i=new DataView(a.buffer,r,e.count*n);m=new Uint32Array(e.count);for(let t=0;t<e.count;t++){let e=t*n;m[t]=n===4?i.getUint32(e,!0):n===2?i.getUint16(e,!0):i.getUint8(e)}}else m=Uint32Array.from({length:d.count},(e,t)=>t);return iw(e,{vertProperties:p,triVerts:m},`importGLB`)}function kw(e){return{exportSTL:(e,t)=>tw(e,t),exportOBJ:e=>nw(e),exportPLY:e=>rw(e),importSTL:t=>ow(e,typeof t==`string`?new TextEncoder().encode(t).buffer:t),importOBJ:t=>aw(e,t),exportSTEP:e=>My(`exportSTEP`).exportSTEP(e.map(e=>pw(e).brep)),exportIGES:e=>My(`exportIGES`).exportIGES(e.map(e=>pw(e).brep)),toBREP:e=>{let{occt:t,brep:n}=pw(e);return t.toBREP(n)},exportSTEPAssembly:(e,t)=>{let n=My(`exportSTEPAssembly`),r=e.map(e=>{let t={shape:pw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return n.exportSTEPAssembly(r,t)},createXCAFDocument:e=>{let t=My(`createXCAFDocument`),n=e.map(e=>{let t={shape:pw(e.shape).brep,name:e.name};return e.color===void 0?t:{...t,color:e.color}});return t.createXCAFDocument(n)},writeXCAFToSTEP:(e,t)=>My(`writeXCAFToSTEP`).writeXCAFToSTEP(e,t),exportSTEPConfigured:(e,t)=>{let n=My(`exportSTEPConfigured`),r=e.map(e=>{let t={shape:pw(e.shape).brep},n=e.name===void 0?t:{...t,name:e.name};return e.color===void 0?n:{...n,color:e.color}});return n.exportSTEPConfigured(r,t)},importSTEP:t=>{let n=My(`importSTEP`);return n.importSTEP(t).map(t=>mw(e,n,t,`importSTEP`))},importIGES:t=>{let n=My(`importIGES`);return n.importIGES(t).map(t=>mw(e,n,t,`importIGES`))},fromBREP:t=>{let n=My(`fromBREP`);return mw(e,n,n.fromBREP(t),`fromBREP`)},exportGLB:e=>Dw(e),importGLB:t=>Ow(e,t),export3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)},import3MF:()=>{throw Error(`manifold: 3MF IO is unsupported on the mesh kernel; export GLB/STL/OBJ or use a B-rep kernel`)}}}function Aw(e){return M(e).getMesh()}function jw(e,t){let n=t*(e.numProp&&e.numProp>=3?e.numProp:3);return[e.vertProperties[n]??0,e.vertProperties[n+1]??0,e.vertProperties[n+2]??0]}function Mw(e,t){let n=e;if(n&&n.__manifoldSub&&n.occt){let e=jy();if(!e)throw new c(`manifold: sub-shape geometry query requires a registered occt kernel`);return t(n.occt,e)}let r=ky(e);if(!r)throw Error(`manifold: exact geometry query requires a manifold shape handle`);let i=jy();if(!i)throw new c(`manifold: exact geometry query unsupported on manifold kernel; no B-rep kernel registered`);if(!r.node.replayable)throw Error(`manifold: exact geometry query unsupported; shape originates from a non-replayable op (raw mesh import or mesh boolean)`);let a=Ny.get(r.node);return a===void 0&&(a=nC(r.node,i),Ny.set(r.node,a)),t(a,i)}function Nw(e){let t=ky(e);if(!t)return;let n=t.node;return n.op===`profileEdge`?n.params?.curve:void 0}function Pw(e){return{curveType:e=>{let t=Nw(e);return t?Ob(t):LC(e)?e.curveType:Mw(e,(e,t)=>t.curveType(e))},curveParameters:e=>{let t=Nw(e);if(t){let e=kb(t);return[e.first,e.last]}return LC(e)?[0,e.length]:Mw(e,(e,t)=>t.curveParameters(e))},curvePointAtParam:(e,t)=>{let n=Nw(e);return n?Ab(n,t):LC(e)?RC(e,t):Mw(e,(e,n)=>n.curvePointAtParam(e,t))},curveTangent:(e,t)=>{let n=Nw(e);return n?{point:Ab(n,t),tangent:jb(n,t)}:LC(e)?{point:RC(e,t),tangent:zC(e,t)}:Mw(e,(e,n)=>n.curveTangent(e,t))},curveIsClosed:e=>{let t=Nw(e);return t?Nb(t):Mw(e,(e,t)=>t.curveIsClosed(e))},curveIsPeriodic:e=>{let t=Nw(e);return t?Pb(t):Mw(e,(e,t)=>t.curveIsPeriodic(e))},curvePeriod:e=>{let t=Nw(e);return t?Fb(t):Mw(e,(e,t)=>t.curvePeriod(e))},interpolatePoints:(e,t)=>My(`interpolatePoints`).interpolatePoints(e,t),approximatePoints:(e,t)=>My(`approximatePoints`).approximatePoints(e,t),curveDegreeElevate:(e,t)=>Mw(e,(e,n)=>n.curveDegreeElevate(e,t)),curveKnotInsert:(e,t,n)=>Mw(e,(e,r)=>r.curveKnotInsert(e,t,n)),curveKnotRemove:(e,t,n)=>Mw(e,(e,r)=>r.curveKnotRemove(e,t,n)),curveSplit:(e,t)=>Mw(e,(e,n)=>n.curveSplit(e,t)),createCurveAdaptor:e=>Mw(e,(e,t)=>t.createCurveAdaptor(e)),getBezierPenultimatePole:e=>Mw(e,(e,t)=>t.getBezierPenultimatePole(e)),getNurbsCurveData:e=>Mw(e,(e,t)=>t.getNurbsCurveData?.(e)??null),vertexPosition:e=>IC(e)?e.point:ky(e)?jw(Aw(e),0):Mw(e,(e,t)=>t.vertexPosition(e)),surfaceType:e=>{if(DC(e))return`plane`;let t=ky(e);return t&&t.node.op===`profileFace`?`plane`:Mw(e,(e,t)=>t.surfaceType(e))},uvBounds:e=>DC(e)?{uMin:0,uMax:1,vMin:0,vMax:1}:Mw(e,(e,t)=>t.uvBounds(e)),outerWire:e=>Mw(e,(e,t)=>t.outerWire(e)),surfaceNormal:(e,t,n)=>DC(e)?e.normal:Mw(e,(e,r)=>r.surfaceNormal(e,t,n)),pointOnSurface:(e,t,n)=>Mw(e,(e,r)=>r.pointOnSurface(e,t,n)),uvFromPoint:(e,t)=>Mw(e,(e,n)=>n.uvFromPoint(e,t)),projectPointOnFace:(e,t)=>Mw(e,(e,n)=>n.projectPointOnFace(e,t)),classifyPointOnFace:(e,t,n,r)=>Mw(e,(e,i)=>i.classifyPointOnFace(e,t,n,r)),classifyPointRobust:(e,t,n)=>Mw(e,(e,r)=>r.classifyPointRobust(e,t,n)),classifyPointWinding:(e,t,n)=>Mw(e,(e,r)=>r.classifyPointWinding(e,t,n)),approximateSurfaceLspia:(e,t,n,r,i,a,o,s,c)=>My(`approximateSurfaceLspia`).approximateSurfaceLspia(e,t,n,r,i,a,o,s,c),untrimFace:(e,t,n)=>Mw(e,(e,r)=>r.untrimFace(e,t,n)),getSurfaceCylinderData:e=>Mw(e,(e,t)=>t.getSurfaceCylinderData(e)),getSurfaceAxis:e=>Mw(e,(e,t)=>t.getSurfaceAxis(e)),reverseSurfaceU:e=>My(`reverseSurfaceU`).reverseSurfaceU(e),detectSmallFeatures:(e,t,n)=>Mw(e,(e,r)=>r.detectSmallFeatures(e,t,n)),recognizeFeatures:(e,t)=>Mw(e,(e,n)=>n.recognizeFeatures(e,t)),projectEdges:(e,t,n,r)=>Mw(e,(e,i)=>i.projectEdges(e,t,n,r)),getNurbsSurfaceData:e=>Mw(e,(e,t)=>t.getNurbsSurfaceData?.(e)??null)}}var Fw={hasErrors:!1,hasWarnings:!1,messages:[]};function Iw(){return{modified:new Map,generated:new Map,deleted:new Set}}function Lw(e){return{shape:e,evolution:Iw()}}function Rw(e){return{shape:e,evolution:Iw(),diagnostics:Fw}}function zw(e){let t=xb(e),n=Wy(e),r=ES(e);return{translateWithHistory:(e,n,r,i)=>Lw(t.translate(e,n,r,i)),rotateWithHistory:(e,n,r,i,a,o)=>Lw(t.rotate(e,n,a,o)),mirrorWithHistory:(e,n,r)=>Lw(t.mirror(e,n,r)),scaleWithHistory:(e,n,r)=>Lw(t.scale(e,n,r)),generalTransformWithHistory:(e,n,r,i)=>Lw(t.generalTransform(e,n,r,i)),fuseWithHistory:(e,t,r,i,a)=>Rw(n.fuse(e,t,a)),cutWithHistory:(e,t,r,i,a)=>Rw(n.cut(e,t,a)),intersectWithHistory:(e,t,r,i,a)=>Rw(n.intersect(e,t,a)),filletWithHistory:(e,t,n)=>Lw(r.fillet(e,t,n)),chamferWithHistory:(e,t,n)=>Lw(r.chamfer(e,t,n)),shellWithHistory:(e,t,n,i,a,o)=>Lw(r.shell(e,t,n,o)),thickenWithHistory:(e,t)=>Lw(r.thicken(e,t)),offsetWithHistory:(e,t,n,i,a)=>Lw(r.offset(e,t,a)),draftWithHistory:(e,t,n,i,a)=>Lw(r.draft(e,t,n,i,a)),applyComposedTransformWithHistory:(e,n)=>Lw(t.transform(e,n))}}function Bw(e){let t=e?.manifold;if(!t||typeof t.isEmpty==`function`&&t.isEmpty())return!1;if(typeof t.status==`function`){let e=t.status(),n=typeof e==`number`?e:Number(e?.value??e);if(!Number.isNaN(n)&&n!==0)return!1}return!0}function Vw(e){return{isValid:e=>Bw(e),isValidStrict:e=>Bw(e),healSolid:e=>Bw(e)?e:null,healFace:e=>e,healWire:e=>e,mergeCoincidentVertices:()=>0,removeDegenerateEdges:()=>0,fixFaceOrientations:()=>0,fixShape:e=>e,fixSelfIntersection:e=>e}}var Hw=.004;function Uw(e,t,n){if(e.k===`line`){let r=e.p2[0]-e.p1[0],i=e.p2[1]-e.p1[1],a=Math.hypot(r,i);if(a===0)return 0;let o=((t-e.p1[0])*r+(n-e.p1[1])*i)/a;return Math.min(Math.max(o,0),a)}if(e.k===`conic`){let r=Math.hypot(e.u[0],e.u[1]),i=Math.hypot(e.v[0],e.v[1]);if(Math.abs(r-i)<1e-12&&Math.abs(e.u[0]*e.v[0]+e.u[1]*e.v[1])<1e-12){let a=t-e.c[0],o=n-e.c[1];return Gw(Math.atan2((a*e.v[0]+o*e.v[1])/(i*i||1),(a*e.u[0]+o*e.u[1])/(r*r||1)),e.a0,e.a1)}return Ww(e.a0,e.a1,r=>Kw(e,r,t,n),eT(e,Hw))}return Ww(0,1,r=>Kw(e,r,t,n),eT(e,Hw))}function Ww(e,t,n,r){let i=Math.max(8,r),a=0,o=1/0;for(let r=0;r<=i;r++){let s=n(e+(t-e)*r/i);s<o&&(o=s,a=r)}return Jw(e+(t-e)*Math.max(0,a-1)/i,e+(t-e)*Math.min(i,a+1)/i,n)}function Gw(e,t,n){if(n-t>=2*Math.PI-1e-12)return e;let r=e;for(;r<t;)r+=2*Math.PI;for(;r>t+2*Math.PI;)r-=2*Math.PI;return r<=n?r:r-n<t+2*Math.PI-r?n:t}function Kw(e,t,n,r){let i=qw(e,t),a=i[0]-n,o=i[1]-r;return a*a+o*o}function qw(e,t){if(e.k===`line`){let n=e.p2[0]-e.p1[0],r=e.p2[1]-e.p1[1],i=Math.hypot(n,r)||1;return[e.p1[0]+n*t/i,e.p1[1]+r*t/i]}return e.k===`bezier`?fT(e.pts,t):[e.c[0]+e.u[0]*Math.cos(t)+e.v[0]*Math.sin(t),e.c[1]+e.u[1]*Math.cos(t)+e.v[1]*Math.sin(t)]}function Jw(e,t,n){let r=(Math.sqrt(5)-1)/2,i=e,a=t,o=a-r*(a-i),s=i+r*(a-i);for(let e=0;e<80&&a-i>1e-12;e++)n(o)<n(s)?(a=s,s=o,o=a-r*(a-i)):(i=o,o=s,s=i+r*(a-i));return(i+a)/2}function Yw(e,t,n){let r=gT(e),i=gT(t),a=[],o=[];for(let s=0;s+1<r.length;s++)for(let c=0;c+1<i.length;c++){let l=$w(r[s],r[s+1],i[c],i[c+1]);if(!l)continue;let u=l;for(let n=0;n<24;n++){let n=qw(e,Uw(e,u[0],u[1])),r=qw(t,Uw(t,n[0],n[1])),i=Math.hypot(r[0]-u[0],r[1]-u[1]);if(u=[(n[0]+r[0])/2,(n[1]+r[1])/2],i<1e-12)break}let d=Uw(e,u[0],u[1]),f=Uw(t,u[0],u[1]),p=Qw(qw(e,d),qw(t,f));Math.hypot(p[0],p[1])>Math.max(n,1e-7)||a.some(e=>Math.hypot(e[0]-u[0],e[1]-u[1])<=Math.max(n,1e-9))||(a.push(u),o.push(d))}return Zw(a,o,Xw(e,t,n,a,o),n)}function Xw(e,t,n,r,i){let{first:a,last:o}=tT(e),s=[];for(let r=0;r<=192;r++){let i=qw(e,a+(o-a)*r/192),c=Uw(t,i[0],i[1]);s.push(Math.sqrt(Kw(t,c,i[0],i[1]))<=Math.max(n,1e-9))}let c=[],l=-1;for(let t=0;t<=193;t++){let u=t<=192&&s[t]===!0;if(u&&l<0&&(l=t),u||l<0)continue;let d=a+(o-a)*l/192,f=a+(o-a)*(t-1)/192,p=0;for(let n=l;n<t-1;n++){let t=qw(e,a+(o-a)*n/192),r=qw(e,a+(o-a)*(n+1)/192);p+=Math.hypot(r[0]-t[0],r[1]-t[1])}if(p>Math.max(n,Hw))c.push(nT(e,d,f));else{let t=qw(e,d);r.some(e=>Math.hypot(e[0]-t[0],e[1]-t[1])<=Math.max(n,1e-9))||(r.push(t),i.push(d))}l=-1}return c}function Zw(e,t,n,r){if(n.length===0)return{points:e,params:t,segments:n};let i=[];for(let t=0;t<e.length;t++){let a=e[t];n.some(e=>{let t=Uw(e,a[0],a[1]);return Math.sqrt(Kw(e,t,a[0],a[1]))<=Math.max(r,Hw)})||i.push(t)}return{points:i.map(t=>e[t]),params:i.map(e=>t[e]),segments:n}}function Qw(e,t){return[e[0]-t[0],e[1]-t[1]]}function $w(e,t,n,r){let i=t[0]-e[0],a=t[1]-e[1],o=r[0]-n[0],s=r[1]-n[1],c=i*s-a*o;if(Math.abs(c)<1e-15)return null;let l=((n[0]-e[0])*s-(n[1]-e[1])*o)/c,u=((n[0]-e[0])*a-(n[1]-e[1])*i)/c;return l<-1e-9||l>1+1e-9||u<-1e-9||u>1+1e-9?null:[e[0]+i*l,e[1]+a*l]}function eT(e,t){let n=Math.max(t,1e-9);if(e.k===`line`)return 2;let r;if(e.k===`conic`){let t=Math.max(Math.hypot(e.u[0],e.u[1]),Math.hypot(e.v[0],e.v[1]));r=Math.abs(e.a1-e.a0)*t}else{r=0;for(let t=0;t+1<e.pts.length;t++){let n=e.pts[t],i=e.pts[t+1];r+=Math.hypot(i[0]-n[0],i[1]-n[1])}}return Math.min(2e4,Math.max(64,Math.ceil(2*r/n)))}function tT(e){return e.k===`conic`?{first:e.a0,last:e.a1}:e.k===`line`?{first:0,last:Math.hypot(e.p2[0]-e.p1[0],e.p2[1]-e.p1[1])}:{first:0,last:1}}function nT(e,t,n){if(e.k===`conic`)return{...e,a0:t,a1:n};if(e.k===`line`){let r=qw(e,t),i=qw(e,n);return{...e,p1:r,p2:i}}let r=iT(e.pts,t),i=1-t,a=i<=1e-15?1:(n-t)/i;return{...e,pts:rT(r,a)}}function rT(e,t){let n=[],r=e.map(e=>[e[0],e[1]]);for(n.push(r[0]);r.length>1;){let e=[];for(let n=0;n+1<r.length;n++){let i=r[n],a=r[n+1];e.push([i[0]+(a[0]-i[0])*t,i[1]+(a[1]-i[1])*t])}r=e,n.push(r[0])}return n}function iT(e,t){let n=[],r=e.map(e=>[e[0],e[1]]);for(n.push(r[r.length-1]);r.length>1;){let e=[];for(let n=0;n+1<r.length;n++){let i=r[n],a=r[n+1];e.push([i[0]+(a[0]-i[0])*t,i[1]+(a[1]-i[1])*t])}r=e,n.push(r[r.length-1])}return n.reverse()}function aT(e){return!!e&&typeof e==`object`&&e.__nativeC2d===!0}function oT(e,t){return{__nativeC2d:!0,k:`line`,p1:e,p2:t}}function sT(e,t,n,r,i){return{__nativeC2d:!0,k:`conic`,c:e,u:t,v:n,a0:r,a1:i}}function cT(e,[t,n]){return[e.a*t+e.b*n+e.tx,e.c*t+e.d*n+e.ty]}function lT(e,[t,n]){return[e.a*t+e.b*n,e.c*t+e.d*n]}function uT(e,t){return{a:e.a*t.a+e.b*t.c,b:e.a*t.b+e.b*t.d,c:e.c*t.a+e.d*t.c,d:e.c*t.b+e.d*t.d,tx:e.a*t.tx+e.b*t.ty+e.tx,ty:e.c*t.tx+e.d*t.ty+e.ty}}function dT(e,t){return e.k===`line`?oT(cT(t,e.p1),cT(t,e.p2)):e.k===`bezier`?{__nativeC2d:!0,k:`bezier`,pts:e.pts.map(e=>cT(t,e))}:sT(cT(t,e.c),lT(t,e.u),lT(t,e.v),e.a0,e.a1)}function fT(e,t){let n=e.map(e=>[e[0],e[1]]);for(let e=1;e<n.length;e++)for(let r=0;r<n.length-e;r++){let e=n[r]??[0,0],i=n[r+1]??[0,0];n[r]=[e[0]*(1-t)+i[0]*t,e[1]*(1-t)+i[1]*t]}return n[0]??[0,0]}function pT(e,t){let n=Math.cos(t),r=Math.sin(t);return[e.c[0]+e.u[0]*n+e.v[0]*r,e.c[1]+e.u[1]*n+e.v[1]*r]}function mT(e,t){let n=e.length-1;if(n<1)return[0,0];let r=[];for(let t=0;t<n;t++){let i=e[t]??[0,0],a=e[t+1]??[0,0];r.push([n*(a[0]-i[0]),n*(a[1]-i[1])])}return fT(r,t)}function hT(e){let t=Math.abs(e.a1-e.a0),n=Math.hypot(e.u[0],e.u[1]),r=Math.hypot(e.v[0],e.v[1]),i=Math.max(n,r);if(i<=Hw)return Math.max(2,Math.ceil(t/(2*Math.PI)*8));let a=2*Math.acos(Math.max(-1,1-Hw/i));return Math.max(2,Math.ceil(t/a))}function gT(e){if(e.k===`line`)return[e.p1,e.p2];if(e.k===`bezier`){let t=[];for(let n=0;n<=24;n++)t.push(fT(e.pts,n/24));return t}let t=e.a1-e.a0,n=hT(e),r=[];for(let i=0;i<=n;i++){let a=e.a0+t*i/n,o=Math.cos(a),s=Math.sin(a);r.push([e.c[0]+e.u[0]*o+e.v[0]*s,e.c[1]+e.u[1]*o+e.v[1]*s])}return r}function _T(e,t,n){let r=e[0],i=e[1],a=t[0],o=t[1],s=n[0],c=n[1],l=2*(r*(o-c)+a*(c-i)+s*(i-o));if(Math.abs(l)<1e-12)return oT(e,n);let u=((r*r+i*i)*(o-c)+(a*a+o*o)*(c-i)+(s*s+c*c)*(i-o))/l,d=((r*r+i*i)*(s-a)+(a*a+o*o)*(r-s)+(s*s+c*c)*(a-r))/l,f=[u,d],p=Math.hypot(r-u,i-d),m=e=>Math.atan2(e[1]-d,e[0]-u),h=m(e),g=m(t),_=m(n),v=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),y=v(g-h),b=v(_-h);return _=y<=b?h+b:h-v(h-_),sT(f,[p,0],[0,p],h,_)}function vT(e,t){let n={delete:()=>{},isEmpty:()=>!1};function r(e,...n){let r=t(),i=r?.[e];if(!i)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return i.call(r,...n)}let i=e=>e;function a(e){let n=t();if(!n)throw Error(`manifold 2D: ${e} needs an OCCT kernel (none registered)`);return n}function o(e){if(!aT(e))return e;let t=a(`toOcct`),n=i(e);if(n.k===`line`)return t.makeLine2d(n.p1[0],n.p1[1],n.p2[0],n.p2[1]);if(n.k===`bezier`)return t.makeBezier2d(n.pts);let r=Math.hypot(n.u[0],n.u[1]),o=Math.hypot(n.v[0],n.v[1]),s=Math.abs(Math.abs(n.a1-n.a0)-2*Math.PI)<1e-9,c=n.u[0]*n.v[1]-n.u[1]*n.v[0]>=0;if(Math.abs(r-o)<1e-9*Math.max(1,r)){if(s)return t.makeCircle2d(n.c[0],n.c[1],r,c);let e=pT(n,n.a0),i=pT(n,(n.a0+n.a1)/2),a=pT(n,n.a1);return t.makeArc2dThreePoints(e[0],e[1],i[0],i[1],a[0],a[1])}let l=n.u[0]*n.v[0]+n.u[1]*n.v[1];if(Math.abs(l)<1e-9*Math.max(1,r*o)){let e=n.u[0]/r,i=n.u[1]/r;return s?t.makeEllipse2d(n.c[0],n.c[1],r,o,e,i,c):t.makeEllipseArc2d(n.c[0],n.c[1],r,o,n.a0,n.a1,e,i,c)}return t.makeBSpline2d(gT(n).map(e=>[e[0],e[1]]))}let s={createPoint2d:(e,t)=>({x:e,y:t}),createDirection2d:(e,t)=>({x:e,y:t}),createVector2d:(e,t)=>({x:e,y:t}),createAxis2d:(e,t,n,r)=>({px:e,py:t,dx:n,dy:r}),wrapCurve2dHandle:e=>e,createCurve2dAdaptor:e=>e,makeLine2d:(e,t,n,r)=>oT([e,t],[n,r]),makeCircle2d:(e,t,n,r=!0)=>sT([e,t],[n,0],r?[0,n]:[0,-n],0,2*Math.PI),makeArc2dThreePoints:(e,t,n,r,i,a)=>_T([e,t],[n,r],[i,a]),makeArc2dTangent:(e,t,n,r,i,a)=>{let o=Math.hypot(n,r)||1,s=-r/o,c=n/o,l=[i-e,a-t],u=s*l[0]+c*l[1];if(Math.abs(u)<1e-12)return oT([e,t],[i,a]);let d=(l[0]*l[0]+l[1]*l[1])/(2*u),f=e+s*d,p=t+c*d,m=Math.hypot(e-f,t-p),h=Math.atan2(t-p,e-f),g=Math.atan2(a-p,i-f);s*n+c*r;let _=e=>(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),v=[-(t-p),e-f];return g=v[0]*n+v[1]*r>=0?h+_(g-h):h-_(h-g),sT([f,p],[m,0],[0,m],h,g)},makeEllipse2d:(e,t,n,r,i=1,a=0,o=!0)=>{let s=Math.hypot(i,a)||1,c=i/s*n,l=a/s*n,u=-a/s*r*(o?1:-1),d=i/s*r*(o?1:-1);return sT([e,t],[c,l],[u,d],0,2*Math.PI)},makeEllipseArc2d:(e,t,n,r,i,a,o=1,s=0,c=!0)=>{let l=Math.hypot(o,s)||1,u=o/l*n,d=s/l*n,f=-s/l*r*(c?1:-1),p=o/l*r*(c?1:-1);return sT([e,t],[u,d],[f,p],i,a)},makeBezier2d:e=>({__nativeC2d:!0,k:`bezier`,pts:e.map(e=>[e[0],e[1]])}),evaluateCurve2d:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return[n.p1[0]+e*t/i,n.p1[1]+r*t/i]}return n.k===`bezier`?fT(n.pts,t):[n.c[0]+n.u[0]*Math.cos(t)+n.v[0]*Math.sin(t),n.c[1]+n.u[1]*Math.cos(t)+n.v[1]*Math.sin(t)]},evaluateCurve2dD1:(e,t)=>{let n=i(e);if(n.k===`line`){let e=n.p2[0]-n.p1[0],r=n.p2[1]-n.p1[1],i=Math.hypot(e,r)||1;return{point:[n.p1[0]+e*t/i,n.p1[1]+r*t/i],tangent:[e/i,r/i]}}if(n.k===`bezier`)return{point:fT(n.pts,t),tangent:mT(n.pts,t)};let r=Math.cos(t),a=Math.sin(t);return{point:[n.c[0]+n.u[0]*r+n.v[0]*a,n.c[1]+n.u[1]*r+n.v[1]*a],tangent:[-n.u[0]*a+n.v[0]*r,-n.u[1]*a+n.v[1]*r]}},getCurve2dBounds:e=>{let t=i(e);return t.k===`conic`?{first:t.a0,last:t.a1}:t.k===`line`?{first:0,last:Math.hypot(t.p2[0]-t.p1[0],t.p2[1]-t.p1[1])}:{first:0,last:1}},getCurve2dType:e=>{let t=i(e);return t.k===`line`?`LINE`:t.k===`bezier`?`BEZIER`:`CIRCLE`},reverseCurve2d:e=>{let t=i(e);if(t.k===`line`){let e=t.p1;t.p1=t.p2,t.p2=e}else if(t.k===`bezier`)t.pts.reverse();else{let e=t.a0;t.a0=t.a1,t.a1=e}},copyCurve2d:e=>structuredClone(i(e)),trimCurve2d:(e,t,n)=>{let r=i(e);if(r.k===`conic`)return sT(r.c,r.u,r.v,t,n);if(r.k===`line`){let e=r.p2[0]-r.p1[0],i=r.p2[1]-r.p1[1],a=Math.hypot(e,i)||1;return oT([r.p1[0]+e*t/a,r.p1[1]+i*t/a],[r.p1[0]+e*n/a,r.p1[1]+i*n/a])}return structuredClone(r)},createIdentityGTrsf2d:()=>({a:1,b:0,c:0,d:1,tx:0,ty:0}),createTranslationGTrsf2d:(e,t)=>({a:1,b:0,c:0,d:1,tx:e,ty:t}),createRotationGTrsf2d:(e,t,n)=>{let r=Math.cos(e),i=Math.sin(e);return{a:r,b:-i,c:i,d:r,tx:t-(r*t-i*n),ty:n-(i*t+r*n)}},createScaleGTrsf2d:(e,t,n)=>({a:e,b:0,c:0,d:e,tx:t-e*t,ty:n-e*n}),createMirrorGTrsf2d:(e,t,n,r=0,i=0,a=1,o=0)=>{if(n===`point`)return{a:-1,b:0,c:0,d:-1,tx:2*e,ty:2*t};let s=Math.hypot(a,o)||1,c=a/s,l=o/s,u=c*c-l*l,d=2*c*l;return{a:u,b:d,c:d,d:-u,tx:r-(u*r+d*i),ty:i-(d*r-u*i)}},createAffinityGTrsf2d:(e,t,n,r,i)=>{let a=Math.hypot(n,r)||1,o=n/a,s=r/a,c=-s,l=o,u=o*o+i*c*c,d=o*s+i*c*l,f=s*o+i*l*c,p=s*s+i*l*l;return{a:u,b:d,c:f,d:p,tx:e-(u*e+d*t),ty:t-(f*e+p*t)}},setGTrsf2dTranslationPart:(e,t,n)=>{let r=e;r.tx=t,r.ty=n},multiplyGTrsf2d:(e,t)=>{let n=uT(e,t);Object.assign(e,n)},transformCurve2dGeneral:(e,t)=>dT(i(e),t),translateCurve2d:(e,t,n)=>dT(i(e),{a:1,b:0,c:0,d:1,tx:t,ty:n}),rotateCurve2d:(e,t,n,r)=>{let a=Math.cos(t),o=Math.sin(t);return dT(i(e),{a,b:-o,c:o,d:a,tx:n-(a*n-o*r),ty:r-(o*n+a*r)})},scaleCurve2d:(e,t,n,r)=>dT(i(e),{a:t,b:0,c:0,d:t,tx:n-t*n,ty:r-t*r}),mirrorCurve2dAtPoint:(e,t,n)=>dT(i(e),{a:-1,b:0,c:0,d:-1,tx:2*t,ty:2*n}),mirrorCurve2dAcrossAxis:(e,t,n,r,a)=>{let o=Math.hypot(r,a)||1,s=r/o,c=a/o,l=s*s-c*c,u=2*s*c;return dT(i(e),{a:l,b:u,c:u,d:-l,tx:t-(l*t+u*n),ty:n-(u*t-l*n)})},affinityTransform2d:(e,t,n,r,a,o)=>{let s=Math.hypot(r,a)||1,c=r/s,l=a/s,u=-l,d=c,f=c*c+o*u*u,p=c*l+o*u*d,m=l*c+o*d*u,h=l*l+o*d*d;return dT(i(e),{a:f,b:p,c:m,d:h,tx:t-(f*t+p*n),ty:n-(m*t+h*n)})},createBoundingBox2d:()=>({min:[1/0,1/0],max:[-1/0,-1/0]}),addCurveToBBox2d:(e,t)=>{let n=e,r;if(aT(t))r=gT(i(t));else{let e=a(`addCurveToBBox2d`),{first:n,last:i}=e.getCurve2dBounds(t);r=[];for(let a=0;a<=32;a++)r.push(e.evaluateCurve2d(t,n+(i-n)*a/32))}for(let[e,t]of r)e<n.min[0]&&(n.min[0]=e),t<n.min[1]&&(n.min[1]=t),e>n.max[0]&&(n.max[0]=e),t>n.max[1]&&(n.max[1]=t)},getBBox2dBounds:e=>{let t=e;return{xMin:t.min[0],yMin:t.min[1],xMax:t.max[0],yMax:t.max[1]}},mergeBBox2d:(e,t)=>{let n=e,r=t;n.min[0]=Math.min(n.min[0],r.min[0]),n.min[1]=Math.min(n.min[1],r.min[1]),n.max[0]=Math.max(n.max[0],r.max[0]),n.max[1]=Math.max(n.max[1],r.max[1])},isBBox2dOut:(e,t)=>{let n=e,r=t;return n.max[0]<r.min[0]||n.min[0]>r.max[0]||n.max[1]<r.min[1]||n.min[1]>r.max[1]},isBBox2dOutPoint:(e,t,n)=>{let r=e;return t<r.min[0]||t>r.max[0]||n<r.min[1]||n>r.max[1]},getCurve2dCircleData:e=>{let t=i(e);if(t.k!==`conic`)return null;let n=Math.hypot(t.u[0],t.u[1]),r=Math.hypot(t.v[0],t.v[1]);return Math.abs(n-r)>1e-6?null:{cx:t.c[0],cy:t.c[1],radius:n,isDirect:!0}},liftCurve2dToPlane:(e,t,r,a)=>{let o=r[0],s=r[1],c=r[2],l=a[0],u=a[1],d=a[2],f=s*d-c*u,p=c*l-o*d,m=o*u-s*l,h=gT(i(e)).map(([e,n])=>[t[0]+l*e+f*n,t[1]+u*e+p*n,t[2]+d*e+m*n]);return Dy(n,j(`profileEdge`,{pts:h},[]))},makeBSpline2d:(e,t)=>a(`makeBSpline2d`).makeBSpline2d(e,t),offsetCurve2d:(e,t)=>a(`offsetCurve2d`).offsetCurve2d(o(e),t),intersectCurves2d:(e,t,n)=>{if(!aT(e)||!aT(t))return a(`intersectCurves2d`).intersectCurves2d(o(e),o(t),n);let{points:r,segments:s}=Yw(i(e),i(t),n);return{points:r.map(e=>[e[0],e[1]]),segments:s}},projectPointOnCurve2d:(e,t,n)=>{if(!aT(e))return a(`projectPointOnCurve2d`).projectPointOnCurve2d(o(e),t,n);let r=i(e),s=Uw(r,t,n);return{param:s,distance:Math.sqrt(Kw(r,s,t,n))}},distanceBetweenCurves2d:(e,t,n,r,s,c)=>{if(!aT(e)||!aT(t))return a(`distanceBetweenCurves2d`).distanceBetweenCurves2d(o(e),o(t),n,r,s,c);let l=i(e),u=i(t),d=1/0;for(let e=0;e<=256;e++){let t=qw(l,n+(r-n)*e/256),i=Uw(u,t[0],t[1]);d=Math.min(d,Math.sqrt(Kw(u,Math.min(Math.max(i,Math.min(s,c)),Math.max(s,c)),t[0],t[1])))}return d},approximateCurve2dAsBSpline:(e,t,n,r)=>a(`approximateCurve2dAsBSpline`).approximateCurve2dAsBSpline(o(e),t,n,r),decomposeBSpline2dToBeziers:e=>a(`decomposeBSpline2dToBeziers`).decomposeBSpline2dToBeziers(o(e)),serializeCurve2d:e=>aT(e)?JSON.stringify({__nativeC2d:1,c:i(e)}):a(`serializeCurve2d`).serializeCurve2d(o(e)),deserializeCurve2d:e=>e.startsWith(`{"__nativeC2d"`)?{__nativeC2d:!0,...JSON.parse(e).c}:a(`deserializeCurve2d`).deserializeCurve2d(e),splitCurve2d:(e,t)=>{if(!aT(e))return a(`splitCurve2d`).splitCurve2d(o(e),t);let n=i(e),{first:r,last:s}=tT(n),c=[r,...t.filter(e=>e>r&&e<s).sort((e,t)=>e-t),s],l=[];for(let e=0;e+1<c.length;e++)l.push(nT(n,c[e]??0,c[e+1]??0));return l},getCurve2dEllipseData:e=>a(`getCurve2dEllipseData`).getCurve2dEllipseData(o(e)),getCurve2dBezierPoles:e=>a(`getCurve2dBezierPoles`).getCurve2dBezierPoles(o(e)),getCurve2dBezierDegree:e=>a(`getCurve2dBezierDegree`).getCurve2dBezierDegree(o(e)),getCurve2dBSplineData:e=>a(`getCurve2dBSplineData`).getCurve2dBSplineData(o(e)),buildEdgeOnSurface:(e,t)=>a(`buildEdgeOnSurface`).buildEdgeOnSurface(o(e),t),extractSurfaceFromFace:e=>a(`extractSurfaceFromFace`).extractSurfaceFromFace(e),extractCurve2dFromEdge:(e,t)=>a(`extractCurve2dFromEdge`).extractCurve2dFromEdge(e,t),buildCurves3d:e=>{a(`buildCurves3d`).buildCurves3d(e)},fixWireOnFace:(e,t,n)=>a(`fixWireOnFace`).fixWireOnFace(e,t,n),fillSurface:(e,t)=>a(`fillSurface`).fillSurface(e,t)};for(let e of[`evaluateCurve2d`,`evaluateCurve2dD1`,`getCurve2dBounds`,`getCurve2dType`,`reverseCurve2d`,`copyCurve2d`,`trimCurve2d`,`transformCurve2dGeneral`,`translateCurve2d`,`rotateCurve2d`,`scaleCurve2d`,`mirrorCurve2dAtPoint`,`mirrorCurve2dAcrossAxis`,`affinityTransform2d`,`getCurve2dCircleData`,`liftCurve2dToPlane`]){let t=s[e];t&&(s[e]=((n,...i)=>aT(n)?t(n,...i):r(e,n,...i)))}return s}var yT=`createPoint2d.createDirection2d.createVector2d.createAxis2d.wrapCurve2dHandle.createCurve2dAdaptor.makeLine2d.makeCircle2d.makeArc2dThreePoints.makeArc2dTangent.makeEllipse2d.makeEllipseArc2d.makeBezier2d.makeBSpline2d.evaluateCurve2d.evaluateCurve2dD1.getCurve2dBounds.getCurve2dType.trimCurve2d.reverseCurve2d.copyCurve2d.offsetCurve2d.translateCurve2d.rotateCurve2d.scaleCurve2d.mirrorCurve2dAtPoint.mirrorCurve2dAcrossAxis.affinityTransform2d.createIdentityGTrsf2d.createAffinityGTrsf2d.createTranslationGTrsf2d.createMirrorGTrsf2d.createRotationGTrsf2d.createScaleGTrsf2d.setGTrsf2dTranslationPart.multiplyGTrsf2d.transformCurve2dGeneral.intersectCurves2d.projectPointOnCurve2d.distanceBetweenCurves2d.approximateCurve2dAsBSpline.decomposeBSpline2dToBeziers.createBoundingBox2d.addCurveToBBox2d.getBBox2dBounds.mergeBBox2d.isBBox2dOut.isBBox2dOutPoint.getCurve2dCircleData.getCurve2dEllipseData.getCurve2dBezierPoles.getCurve2dBezierDegree.getCurve2dBSplineData.serializeCurve2d.deserializeCurve2d.splitCurve2d.liftCurve2dToPlane.buildEdgeOnSurface.extractSurfaceFromFace.extractCurve2dFromEdge.buildCurves3d.fixWireOnFace.fillSurface`.split(`.`);function bT(e){let t=jy();if(!t)throw Error(`manifold: ${e} unsupported on manifold kernel; no B-rep kernel registered`);return t}function xT(e){let t={};for(let e of yT)t[e]=(...t)=>bT(e)[e](...t);let n=vT(e,()=>jy());return Object.assign(t,n),t}function ST(e){return{sketchNew:()=>wy(`sketchNew`),sketchAddPoint:()=>wy(`sketchAddPoint`),sketchAddArc:()=>wy(`sketchAddArc`),sketchAddConstraint:()=>wy(`sketchAddConstraint`),sketchSolve:()=>wy(`sketchSolve`),sketchDof:()=>wy(`sketchDof`)}}function CT(e){return{projectEdges:()=>wy(`projectEdges`)}}function wT(e){return{dispose(e){let t=ky(e);if(t){let e=Ny.get(t.node);e!==void 0&&(jy()?.dispose(e),Ny.delete(t.node))}(e?.manifold)?.delete?.()},executeBatch:()=>wy(`executeBatch`),checkpoint:()=>wy(`checkpoint`),checkpointCount:()=>0,restoreCheckpoint:()=>wy(`restoreCheckpoint`),discardCheckpoint:()=>wy(`discardCheckpoint`)}}var TT={draft:30,standard:10,fine:3},ET=class{oc;kernelId=`manifold`;capabilities={exact:!1,brepExport:!1,exactMeasurement:!1,tessellationModel:`build-time`};setQuality(e){let t=this.oc;t.setCircularSegments?.(0),t.setMinCircularEdgeLength?.(0),t.setMinCircularAngle?.(TT[e])}constructor(e){this.oc=e,Object.assign(this,zy(e),Wy(e),xb(e),Ox(e),eS(e),ES(e),PS(e),wC(e),JC(e),kw(e),Pw(e),zw(e),Vw(e),xT(e),ST(e),CT(e),wT(e))}};function DT(e){return import(e)}var OT=new Map,kT=null,AT=null;function jT(e){MT(`manifold`,new ET(e))}function MT(e,t){OT.set(e,t),kT||=e,e===kT&&(AT=t)}function P(e){if(!e&&AT)return AT;let t=e??kT;if(!t)throw Error(`brepjs kernel not initialized. Call initFromOC() or registerKernel() before using the library.`);let n=OT.get(t);if(!n)throw Error(`brepjs: kernel '${t}' is not registered.`);return n}function NT(e){let t=P(e);if(!_o(t))throw Error(`brepjs: current kernel does not support 2D operations.`);return t}function PT(){return kT}function FT(e,t){let n=kT;kT=e,AT=OT.get(e)??null;try{let e=t();if(e instanceof Promise)throw Error(`withKernel() callback returned a Promise. Async code must use getKernel(id) directly — the kernel override is restored synchronously in finally.`);return e}finally{kT=n,AT=n?OT.get(n)??null:null}}function IT(e){return P(e).capabilities}function LT(e,t){let n=mo();try{go(e),P().setQuality?.(e);let n=t();if(n instanceof Promise)throw Error(`withQuality() callback returned a Promise. Async code must read currentQuality()/getKernel() directly.`);return n}finally{go(n),P().setQuality?.(n)}}var RT=new Map;function zT(e,t){RT.set(e,t)}function BT(e){return RT.get(e)}function VT(e,t){let n=RT.get(e);if(!n)throw Error(`withTier: no tier registered for "${e}". Call registerKernelTier("${e}", { kernel, quality }) first.`);return FT(n.kernel,()=>LT(n.quality,t))}function HT(e){No(),qc(),Eo(),Cc(),wc(),zc(),Bc();let t=new kf(e);MT(`occt`,t),kT=`occt`,AT=t}function UT(){let e=P(),t=e.makeBox(1,1,1);try{e.dispose(t)}catch{}}async function WT(){if(kT)return kT;try{let{OcctKernel:e}=await DT(`occt-wasm`),t=await e.init();return MT(`occt-wasm`,uo.fromKernel(t)),`occt-wasm`}catch{}try{return HT(await(await DT(`brepjs-opencascade`)).default()),`occt`}catch{}try{let e=await DT(`brepkit-wasm`);return typeof e.default==`function`&&await e.default(),MT(`brepkit`,new Cy(new e.BrepKernel)),`brepkit`}catch{}throw Error(`brepjs: no kernel package found. Install one of:
|
|
13
13
|
npm install occt-wasm (recommended, default)
|
|
14
14
|
npm install brepjs-opencascade
|
|
15
|
-
npm install brepkit-wasm`)}function GT(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}var KT=Symbol;KT.dispose??=Symbol.for(`Symbol.dispose`),KT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var qT=globalThis;qT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var JT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function YT(){return{...JT}}function XT(){JT.liveHandles=0,JT.peakHandles=0,JT.gcCollected=0,JT.scopeEnters=0,JT.scopeExits=0}function ZT(){JT.liveHandles++,JT.liveHandles>JT.peakHandles&&(JT.peakHandles=JT.liveHandles)}function QT(){JT.liveHandles--}function $T(){JT.gcCollected++,JT.liveHandles--}var eE=new FinalizationRegistry(e=>{$T();try{e.delete()}catch{}});function tE(e){let t=P(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,QT(),eE.unregister(o),i();try{t.dispose(e)}catch{}}},o={get wrapped(){if(n)throw Error(`Shape handle has been disposed`);return e},get disposed(){return n},[Symbol.dispose](){a()},delete(){a()},onDispose(e){if(n){e();return}(r??=[]).push(e)}};return ZT(),eE.register(o,{delete:()=>{t.dispose(e)}},o),o}function nE(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function rE(e){let t=P(),n;try{n=t.checkpoint()}catch(t){if(!l(t))throw t;return e()}let r;try{r=e()}catch(e){try{t.restoreCheckpoint(n)}catch{}throw e}return t.restoreCheckpoint(n),r}function iE(e){let t=!1,n={get value(){if(t)throw Error(`kernel handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){if(!t){t=!0,QT(),eE.unregister(n);try{e.delete()}catch{}}}};return ZT(),eE.register(n,e,n),n}var aE=class{handles=[];constructor(){JT.scopeEnters++}register(e){return this.handles.push(()=>{try{let t=e[Symbol.dispose];typeof t==`function`?t.call(e):e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){JT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function oE(e){try{var t=GT();return e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}function sE(e,t){eE.register(e,t,t)}function cE(e){eE.unregister(e)}function lE(e){try{var t=GT();return e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}async function uE(e){try{var t=GT();return await e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}function dE(e){return!e.disposed}function fE(e){return e.__is2D!==!0}function pE(e){return e.__is2D===!0}function mE(e){if(!fE(e))throw Error(`Expected 3D shape, got 2D`);return e}function hE(e){if(!pE(e))throw Error(`Expected 2D shape, got 3D`);return e}var gE=new WeakMap;function _E(e,t){gE.set(e,t)}function vE(e,t){let n=gE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return gE.set(t,r),r}function yE(e){return vE(P(),e.wrapped)}function bE(e,t){return t===`2D`&&(e.__is2D=!0),e}function xE(e,t){return bE(tE(e),t)}function SE(e,t){return bE(tE(e),t)}function CE(e,t){return bE(tE(e),t)}function wE(e,t){return bE(tE(e),t)}function TE(e){return bE(tE(e))}function EE(e){return bE(tE(e))}function DE(e){return bE(tE(e))}function OE(e,t){return bE(tE(e),t)}function kE(e){return yE(e)===`vertex`}function AE(e){return yE(e)===`edge`}function jE(e){return yE(e)===`wire`}function ME(e){return yE(e)===`face`}function NE(e){return yE(e)===`shell`}function PE(e){return yE(e)===`solid`}function FE(e){return yE(e)===`compound`}function IE(e){let t=yE(e);return t===`shell`||t===`solid`||t===`compsolid`||t===`compound`&&fE(e)}function LE(e){let t=yE(e);return t===`edge`||t===`wire`}function RE(e,t){let n=P(),r=vE(n,e),i=n.downcast(e,r);return r===`vertex`?xE(i,t):r===`edge`?SE(i,t):r===`wire`?CE(i,t):r===`face`?wE(i,t):r===`shell`?TE(i):r===`solid`?EE(i):r===`compsolid`?DE(i):OE(i,t)}function zE(e){return RE(e)}function BE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||P().dispose(e)}function F(e,t){let n=RE(e,t);return BE(e,n),n}function VE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=P();e.dispose(n),e.dispose(t)}}function I(e){P().dispose(e.wrapped),e[Symbol.dispose]()}function HE(e,t,n){_E(e,t);let r=P().downcast(e,t);return t===`vertex`?xE(r,n):t===`edge`?SE(r,n):t===`wire`?CE(r,n):t===`face`?wE(r,n):t===`shell`?TE(r):t===`solid`?EE(r):t===`compsolid`?DE(r):OE(r,n)}function UE(e,t,n){let r=HE(e,t,n);return BE(e,r),r}function WE(e,t,n){return _E(e,t),bE(nE(e),n)}function L(e){return{ok:!0,value:e}}function R(e){return{ok:!1,error:e}}var GE=L(void 0);function KE(e){return e.ok}function z(e){return!e.ok}function qE(e,t){return e.ok?L(t(e.value)):e}function JE(e,t){return e.ok?e:R(t(e.error))}function YE(e,t){return e.ok?t(e.value):e}var XE=YE;function ZE(e,t){return e.ok?e:t}function QE(e,t){return e.ok?e:t(e.error)}function $E(e,t){return e.ok?t.ok?L([e.value,t.value]):t:e}var eD=dD;function tD(e,t){return e.ok&&t(e.value),e}function nD(e,t){return e.ok||t(e.error),e}function rD(e){return e.ok?e.value:e}function iD(e,t,n){return e.ok?L(t(e.value)):R(n(e.error))}function aD(e,t){return e==null?R(t()):L(e)}function oD(e){if(typeof e==`object`&&e&&`kind`in e&&`code`in e&&`message`in e){let t=e;return`[${t.kind}] ${t.code}: ${t.message}`}return String(e)}function B(e){if(e.ok)return e.value;throw Error(`Called unwrap() on an Err: ${oD(e.error)}`)}function sD(e,t){return e.ok?e.value:t}function cD(e,t){return e.ok?e.value:t(e.error)}function lD(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function uD(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function dD(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return L(t)}function fD(e,t){try{return L(e())}catch(e){return R(t(e))}}async function pD(e,t){try{return L(await e())}catch(e){return R(t(e))}}function mD(e){function t(e){return typeof e==`object`&&!!e&&`ok`in e&&typeof e.ok==`boolean`}let n=t(e)?e:L(e);function r(e){return{then(t){return e.ok?r(t(e.value)):r(e)},get result(){return e}}}return r(n)}var V={BSPLINE_FAILED:`BSPLINE_FAILED`,FACE_BUILD_FAILED:`FACE_BUILD_FAILED`,SWEEP_FAILED:`SWEEP_FAILED`,LOFT_FAILED:`LOFT_FAILED`,FUSE_FAILED:`FUSE_FAILED`,CUT_FAILED:`CUT_FAILED`,HEAL_NO_EFFECT:`HEAL_NO_EFFECT`,BOOLEAN_HAS_ERRORS:`BOOLEAN_HAS_ERRORS`,VARIABLE_FILLET_FAILED:`VARIABLE_FILLET_FAILED`,POSITION_ON_CURVE_FAILED:`POSITION_ON_CURVE_FAILED`,FIX_SHAPE_FAILED:`FIX_SHAPE_FAILED`,SOLID_FROM_SHELL_FAILED:`SOLID_FROM_SHELL_FAILED`,FIX_SELF_INTERSECTION_FAILED:`FIX_SELF_INTERSECTION_FAILED`,MESH_FAILED:`MESH_FAILED`,ELLIPSE_RADII:`ELLIPSE_RADII`,FUSE_ALL_EMPTY:`FUSE_ALL_EMPTY`,FILLET_NO_EDGES:`FILLET_NO_EDGES`,CHAMFER_NO_EDGES:`CHAMFER_NO_EDGES`,CHAMFER_ANGLE_NO_EDGES:`CHAMFER_ANGLE_NO_EDGES`,CHAMFER_ANGLE_BAD_DISTANCE:`CHAMFER_ANGLE_BAD_DISTANCE`,CHAMFER_ANGLE_BAD_ANGLE:`CHAMFER_ANGLE_BAD_ANGLE`,BEZIER_MIN_POINTS:`BEZIER_MIN_POINTS`,POLYGON_MIN_POINTS:`POLYGON_MIN_POINTS`,ZERO_LENGTH_EXTRUSION:`ZERO_LENGTH_EXTRUSION`,ZERO_TWIST_ANGLE:`ZERO_TWIST_ANGLE`,LOFT_EMPTY:`LOFT_EMPTY`,UNSUPPORTED_PROFILE:`UNSUPPORTED_PROFILE`,UNKNOWN_PLANE:`UNKNOWN_PLANE`,NULL_SHAPE_INPUT:`NULL_SHAPE_INPUT`,INVALID_FILLET_RADIUS:`INVALID_FILLET_RADIUS`,INVALID_CHAMFER_DISTANCE:`INVALID_CHAMFER_DISTANCE`,INVALID_THICKNESS:`INVALID_THICKNESS`,ZERO_OFFSET:`ZERO_OFFSET`,NO_EDGES:`NO_EDGES`,NO_FACES:`NO_FACES`,DRAFT_NO_FACES:`DRAFT_NO_FACES`,DRAFT_INVALID_ANGLE:`DRAFT_INVALID_ANGLE`,DRAFT_NOT_3D:`DRAFT_NOT_3D`,DRAFT_FAILED:`DRAFT_FAILED`,FUSE_NOT_3D:`FUSE_NOT_3D`,CUT_NOT_3D:`CUT_NOT_3D`,INTERSECT_NOT_3D:`INTERSECT_NOT_3D`,FUSE_ALL_NOT_3D:`FUSE_ALL_NOT_3D`,CUT_ALL_NOT_3D:`CUT_ALL_NOT_3D`,LOFT_NOT_3D:`LOFT_NOT_3D`,SWEEP_NOT_3D:`SWEEP_NOT_3D`,REVOLUTION_NOT_3D:`REVOLUTION_NOT_3D`,FILLET_NOT_3D:`FILLET_NOT_3D`,CHAMFER_NOT_3D:`CHAMFER_NOT_3D`,CHAMFER_ANGLE_NOT_3D:`CHAMFER_ANGLE_NOT_3D`,CHAMFER_ANGLE_FAILED:`CHAMFER_ANGLE_FAILED`,CSG_NOT_3D:`CSG_NOT_3D`,SHELL_NOT_3D:`SHELL_NOT_3D`,OFFSET_NOT_3D:`OFFSET_NOT_3D`,NULL_SHAPE:`NULL_SHAPE`,NO_WRAPPER:`NO_WRAPPER`,WELD_NOT_SHELL:`WELD_NOT_SHELL`,SOLID_BUILD_FAILED:`SOLID_BUILD_FAILED`,OFFSET_NOT_WIRE:`OFFSET_NOT_WIRE`,UNKNOWN_SURFACE_TYPE:`UNKNOWN_SURFACE_TYPE`,UNKNOWN_CURVE_TYPE:`UNKNOWN_CURVE_TYPE`,SWEEP_START_NOT_WIRE:`SWEEP_START_NOT_WIRE`,SWEEP_END_NOT_WIRE:`SWEEP_END_NOT_WIRE`,STEP_EXPORT_FAILED:`STEP_EXPORT_FAILED`,STEP_EXPORT_CONFIGURED_FAILED:`STEP_EXPORT_CONFIGURED_FAILED`,STEP_FILE_READ_ERROR:`STEP_FILE_READ_ERROR`,STEP_EXPORT_CRASHED:`STEP_EXPORT_CRASHED`,STEP_EXPORT_UNSERIALIZABLE:`STEP_EXPORT_UNSERIALIZABLE`,STL_EXPORT_FAILED:`STL_EXPORT_FAILED`,STL_FILE_READ_ERROR:`STL_FILE_READ_ERROR`,STL_EXPORT_CRASHED:`STL_EXPORT_CRASHED`,STL_EXPORT_UNSERIALIZABLE:`STL_EXPORT_UNSERIALIZABLE`,STEP_IMPORT_FAILED:`STEP_IMPORT_FAILED`,STL_IMPORT_FAILED:`STL_IMPORT_FAILED`,IGES_EXPORT_FAILED:`IGES_EXPORT_FAILED`,IGES_IMPORT_FAILED:`IGES_IMPORT_FAILED`,DXF_IMPORT_FAILED:`DXF_IMPORT_FAILED`,OBJ_IMPORT_FAILED:`OBJ_IMPORT_FAILED`,THREEMF_IMPORT_FAILED:`THREEMF_IMPORT_FAILED`,PARAMETER_NOT_FOUND:`PARAMETER_NOT_FOUND`,INTERSECTION_FAILED:`INTERSECTION_FAILED`,SELF_INTERSECTION_FAILED:`SELF_INTERSECTION_FAILED`,STRAIGHT_SKELETON_FAILED:`STRAIGHT_SKELETON_FAILED`,CENTER_OF_MASS_FAILED:`CENTER_OF_MASS_FAILED`,COMPOUND_NO_FACES:`COMPOUND_NO_FACES`,COMPOUND_FACE_NOT_FOUND:`COMPOUND_FACE_NOT_FOUND`,FINDER_NOT_UNIQUE:`FINDER_NOT_UNIQUE`,HULL_EMPTY_INPUT:`HULL_EMPTY_INPUT`,HULL_FAILED:`HULL_FAILED`,HULL_DEGENERATE:`HULL_DEGENERATE`,HULL_NOT_3D:`HULL_NOT_3D`,MINKOWSKI_FAILED:`MINKOWSKI_FAILED`,MINKOWSKI_NULL_TOOL:`MINKOWSKI_NULL_TOOL`,MINKOWSKI_NOT_3D:`MINKOWSKI_NOT_3D`,POLYHEDRON_INSUFFICIENT_POINTS:`POLYHEDRON_INSUFFICIENT_POINTS`,POLYHEDRON_INSUFFICIENT_FACES:`POLYHEDRON_INSUFFICIENT_FACES`,POLYHEDRON_INVALID_INDEX:`POLYHEDRON_INVALID_INDEX`,POLYHEDRON_FAILED:`POLYHEDRON_FAILED`,VALIDATION_FAILED:`VALIDATION_FAILED`,ROOF_FAILED:`ROOF_FAILED`,MULTI_SWEEP_INSUFFICIENT_SECTIONS:`MULTI_SWEEP_INSUFFICIENT_SECTIONS`,MULTI_SWEEP_FAILED:`MULTI_SWEEP_FAILED`,GUIDED_SWEEP_FAILED:`GUIDED_SWEEP_FAILED`,SURFACE_GRID_TOO_SMALL:`SURFACE_GRID_TOO_SMALL`,SURFACE_GRID_JAGGED:`SURFACE_GRID_JAGGED`,SURFACE_FAILED:`SURFACE_FAILED`,ASSEMBLY_MATE_INVALID:`ASSEMBLY_MATE_INVALID`,ASSEMBLY_SOLVE_FAILED:`ASSEMBLY_SOLVE_FAILED`,ASSEMBLY_NOT_CONVERGED:`ASSEMBLY_NOT_CONVERGED`,BLUEPRINT_EMPTY_CURVES:`BLUEPRINT_EMPTY_CURVES`,COMPOUND_BLUEPRINT_EMPTY:`COMPOUND_BLUEPRINT_EMPTY`,GLB_IMPORT_FAILED:`GLB_IMPORT_FAILED`,FONT_FETCH_FAILED:`FONT_FETCH_FAILED`,FONT_PARSE_FAILED:`FONT_PARSE_FAILED`,NO_FONT_LOADED:`NO_FONT_LOADED`,CURVE2D_CONSTRUCTION_FAILED:`CURVE2D_CONSTRUCTION_FAILED`,CURVE2D_INVALID_RADIUS:`CURVE2D_INVALID_RADIUS`,CURVE2D_TRANSFORM_FAILED:`CURVE2D_TRANSFORM_FAILED`,CURVE2D_QUERY_FAILED:`CURVE2D_QUERY_FAILED`,CURVE2D_INTERSECTION_FAILED:`CURVE2D_INTERSECTION_FAILED`,CURVE2D_BRIDGE_FAILED:`CURVE2D_BRIDGE_FAILED`,CLONE_FAILED:`CLONE_FAILED`,SIMPLIFY_FAILED:`SIMPLIFY_FAILED`,TO_BREP_FAILED:`TO_BREP_FAILED`,UNSUPPORTED_CAPABILITY:`UNSUPPORTED_CAPABILITY`};function hD(e,t,n,r,i,a){let o={kind:e,code:t,message:n,cause:r};if(a){let e={...o,suggestion:a};return i?{...e,metadata:i}:e}return i?{...o,metadata:i}:o}function H(e,t,n,r,i){return hD(`KERNEL_OPERATION`,e,t,n,r,i)}function U(e,t,n,r,i){return hD(`VALIDATION`,e,t,n,r,i)}function gD(e,t,n,r,i){return hD(`TYPE_CAST`,e,t,n,r,i)}function _D(e,t,n,r,i){return hD(`SKETCHER_STATE`,e,t,n,r,i)}function vD(e,t,n,r,i){return hD(`MODULE_INIT`,e,t,n,r,i)}function yD(e,t,n,r,i){return hD(`COMPUTATION`,e,t,n,r,i)}function bD(e,t,n,r,i){return hD(`IO`,e,t,n,r,i)}function xD(e,t,n,r,i){return hD(`QUERY`,e,t,n,r,i)}function SD(e,t,n,r,i){return hD(`UNSUPPORTED`,e,t,n,r,i)}function CD(e,n,r){return(n<0||n>=e.length)&&i(r??`safeIndex`,`Index ${n} is out of bounds (array length ${e.length})`),t(e,n)}var W=2147483647,wD=Math.PI/180,TD=180/Math.PI,ED=[{pattern:/invalid edge configuration|edges?.*(not|fail|invalid)/i,translation:`The edges may not form a continuous loop. Check that edges connect end-to-end without gaps.`},{pattern:/BRepAlgoAPI.*failed|boolean.*operation.*failed/i,translation:`Boolean operation failed. Common causes: overlapping faces, zero-thickness geometry, or degenerate shapes. Try healing input shapes first.`},{pattern:/fillet.*radius.*too.*large|fillet.*failed/i,translation:`Fillet operation failed. The radius may be too large for the selected edges. Try reducing the radius or check that edges have enough room.`},{pattern:/chamfer.*failed|chamfer.*distance.*too.*large/i,translation:`Chamfer operation failed. The distance may be too large for the selected edges. Try reducing the distance or check edge geometry.`},{pattern:/shell.*failed|offset.*failed/i,translation:`Shell/offset operation failed. The thickness may be too large, or the shape may have complex geometry. Try reducing thickness.`},{pattern:/sweep.*failed|pipe.*failed/i,translation:`Sweep operation failed. Check that the profile and spine are compatible, and that the spine has no sharp twists or self-intersections.`},{pattern:/loft.*failed/i,translation:`Loft operation failed. Profiles may be incompatible or have different orientations. Ensure profiles are ordered consistently.`},{pattern:/extrude.*failed|prism.*failed/i,translation:`Extrusion failed. The profile may be invalid or self-intersecting. Check that the profile forms a valid closed wire.`},{pattern:/revolve.*failed|revolution.*failed/i,translation:`Revolution operation failed. The profile may intersect the axis of revolution, or the angle may be invalid.`},{pattern:/self.*intersect|self-intersect/i,translation:`Shape has self-intersections. The operation resulted in overlapping geometry. Simplify the input or adjust parameters.`},{pattern:/degener|degenerat/i,translation:`Degenerate geometry detected. The shape has edges or faces with zero length/area. Check input geometry for collapsed elements.`},{pattern:/BRepCheck.*fail|shape.*invalid|shape.*not.*valid/i,translation:`Shape validation failed. The resulting shape has invalid topology. Try healing the shape or checking input geometry.`}],DD={FUSE_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,CUT_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,FUSE_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,CUT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,INTERSECT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,SWEEP_FAILED:`Ensure the spine curve has no sharp corners or self-intersections. Try simplifying the profile or using a smoother path.`,LOFT_FAILED:`Check that all profiles have the same number of edges and consistent orientation. Try reordering profiles.`,FILLET_NOT_3D:`The fillet radius may be too large for the selected edges. Try a smaller radius or check that adjacent faces have enough room.`,CHAMFER_NOT_3D:`The chamfer distance may be too large. Try a smaller distance or check edge geometry.`,SHELL_NOT_3D:`The shell thickness may be too large for the shape. Try reducing thickness or removing problematic faces.`,OFFSET_NOT_3D:`The offset distance may be too large for the shape geometry. Try a smaller distance.`,DRAFT_FAILED:`The draft angle may be too large or the selected faces incompatible. Try a smaller angle or different faces.`};function OD(e){return DD[e]}function kD(e){for(let{pattern:t,translation:n}of ED)if(t.test(e))return`${n} (kernel: ${e})`;return e}function AD(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var jD={KERNEL_OPERATION:(e,t,n,r)=>AD(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>AD(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>AD(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>AD(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>AD(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>AD(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>AD(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>AD(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>AD(`UNSUPPORTED`,e,t,n,r)};function MD(e,t,n,r=`KERNEL_OPERATION`){try{return L(F(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?kD(i):i,o=OD(t);return R(jD[r](t,`${n}: ${a}`,e,o))}}function ND(e,t,n,r=`KERNEL_OPERATION`){try{return L(e())}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?kD(i):i,o=OD(t);return R(jD[r](t,`${n}: ${a}`,e,o))}}function PD(e,t,n,r=`KERNEL_OPERATION`){try{var i=GT();let a=i.u(new aE);return MD(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function FD(e,t){let n=P().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=UE(n[e],t);return r}function ID(e,t){let n=P();if(n.subShapeCount)return n.subShapeCount(e.wrapped,t);let r=n.iterShapes(e.wrapped,t);for(let e of r)n.dispose(e);return r.length}function LD(e,t){let n=P();if(n.subShapeHashes)return n.subShapeHashes(e.wrapped,t,W);let r=new Set;for(let i of n.iterShapes(e.wrapped,t))r.add(n.hashCode(i,W)),n.dispose(i);return[...r]}var RD=new WeakMap;function zD(e){let t=RD.get(e);if(!t)return;RD.delete(e);let n=[t.edges,t.faces,t.wires,t.vertices,t.shells,t.solids,t.compSolids];for(let e of n)if(e)for(let t of e)t[Symbol.dispose]()}var BD=new WeakSet;function VD(e){let t=e.wrapped,n=RD.get(t);return n||(n={},RD.set(t,n)),BD.has(e)||(BD.add(e),e.onDispose(()=>{zD(t)})),n}function HD(e){return RD.get(e.wrapped)}function UD(e){zD(e.wrapped)}function WD(e){let t=VD(e);if(t.edges)return t.edges;let n=FD(e.wrapped,`edge`);return t.edges=n,n}function GD(e){let t=VD(e);if(t.faces)return t.faces;let n=FD(e.wrapped,`face`);return t.faces=n,n}function KD(e){let t=VD(e);if(t.wires)return t.wires;let n=FD(e.wrapped,`wire`);return t.wires=n,n}function qD(e){let t=VD(e);if(t.vertices)return t.vertices;let n=FD(e.wrapped,`vertex`);return t.vertices=n,n}function JD(e){let t=VD(e);if(t.solids)return t.solids;let n=FD(e.wrapped,`solid`);return t.solids=n,n}function YD(e){let t=VD(e);if(t.shells)return t.shells;let n=FD(e.wrapped,`shell`);return t.shells=n,n}function XD(e){let t=VD(e);if(t.compSolids)return t.compSolids;let n=FD(e.wrapped,`compsolid`);return t.compSolids=n,n}function*ZD(e){for(let t of P().iterShapes(e.wrapped,`edge`))yield UE(t,`edge`)}function*QD(e){for(let t of P().iterShapes(e.wrapped,`face`))yield UE(t,`face`)}function*$D(e){for(let t of P().iterShapes(e.wrapped,`wire`))yield UE(t,`wire`)}function*eO(e){for(let t of P().iterShapes(e.wrapped,`vertex`))yield UE(t,`vertex`)}function*tO(e){for(let t of P().iterShapes(e.wrapped,`solid`))yield UE(t,`solid`)}function*nO(e){for(let t of P().iterShapes(e.wrapped,`shell`))yield UE(t,`shell`)}function*rO(e){for(let t of P().iterShapes(e.wrapped,`compsolid`))yield UE(t,`compsolid`)}function iO(e){let t=VD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=P().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function aO(e){return vE(P(),e.wrapped)}function oO(e){let t=VD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=P().surfaceType(e.wrapped);return t.surfaceType=n,n}function sO(e){let t=VD(e);if(t.isValid!==void 0)return t.isValid;let n=P().isValid(e.wrapped);return t.isValid=n,n}function cO(e){return{kind:aO(e),faceCount:ID(e,`face`),edgeCount:ID(e,`edge`),wireCount:ID(e,`wire`),vertexCount:ID(e,`vertex`),valid:sO(e),bounds:iO(e)}}function lO(e){return P().vertexPosition(e.wrapped)}function uO(e){return P().curveIsClosed(e.wrapped)}function dO(e){return P().isValid(e.wrapped)}function fO(e){let t=P();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function pO(e){return P().isValid(e.wrapped)}function mO(e){return uO(e)?L(e):R(`Wire is not closed: start and end points do not coincide`)}function hO(e){return dO(e)?L(e):R(`Face orientation is inconsistent or face is invalid`)}function gO(e){return fO(e)?L(e):R(`Shell is not manifold: has free edges or is invalid`)}function _O(e){return pO(e)?L(e):R(`Solid failed BRepCheck validation`)}function vO(e){return P().surfaceType(e.wrapped)===`plane`}function yO(e){let t=P(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function bO(e){return vO(e)?L(e):R(`Face is not planar: underlying surface is not a geometric plane`)}function xO(e){return yO(e)?L(e):R(`Wire is not planar: edges do not lie in a common plane`)}function SO(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function CO(e){return[e[0],e[1]]}var wO={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function TO(e){if(typeof e==`string`){let t=wO[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function EO(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function DO(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function OO(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function kO(e){return[-e[0],-e[1],-e[2]]}function AO(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function jO(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function MO(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function NO(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function PO(e,t){return MO(DO(e,t))}function FO(e){let t=MO(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function IO(e,t,n=1e-5){return Math.abs(e[0]-t[0])<n&&Math.abs(e[1]-t[1])<n&&Math.abs(e[2]-t[2])<n}function LO(e,t=1e-10){return NO(e)<t*t}function RO(e,t){let n=AO(e,t),r=MO(e),i=MO(t);if(r<1e-10||i<1e-10)return 0;let a=Math.max(-1,Math.min(1,n/(r*i)));return Math.acos(a)}function zO(e,t,n){let r=DO(e,t),i=NO(n);return i<1e-20?e:DO(e,OO(n,AO(r,n)/i))}function BO(e,t,n){let r=FO(t),i=Math.cos(n),a=Math.sin(n),o=AO(e,r),s=jO(r,e);return[e[0]*i+s[0]*a+r[0]*o*(1-i),e[1]*i+s[1]*a+r[1]*o*(1-i),e[2]*i+s[2]*a+r[2]*o*(1-i)]}var VO=e=>Math.round(e*1e3)/1e3;function HO(e){return`x: ${VO(e[0])}, y: ${VO(e[1])}, z: ${VO(e[2])}`}function UO(e,t=null,n=[0,0,1]){let r=FO(n);if(LO(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=FO(t);else{let[e,t,n]=r,a=Math.abs(e),o=Math.abs(t),s=Math.abs(n),c;c=a<=o&&a<=s?[1,0,0]:o<=s?[0,1,0]:[0,0,1];let l=c[1]*n-c[2]*t,u=c[2]*e-c[0]*n,d=c[0]*t-c[1]*e;i=Math.sqrt(l*l+u*u+d*d)>1e-12?FO([l,u,d]):[1,0,0]}if(LO(i))throw Error(`Plane xDir must be non-zero`);let a=FO(jO(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var WO={XY:{xDir:[1,0,0],normal:[0,0,1]},YZ:{xDir:[0,1,0],normal:[1,0,0]},ZX:{xDir:[0,0,1],normal:[0,1,0]},XZ:{xDir:[1,0,0],normal:[0,-1,0]},YX:{xDir:[0,1,0],normal:[0,0,-1]},ZY:{xDir:[0,0,1],normal:[-1,0,0]},front:{xDir:[1,0,0],normal:[0,0,1]},back:{xDir:[-1,0,0],normal:[0,0,-1]},left:{xDir:[0,0,1],normal:[-1,0,0]},right:{xDir:[0,0,-1],normal:[1,0,0]},top:{xDir:[1,0,0],normal:[0,1,0]},bottom:{xDir:[1,0,0],normal:[0,-1,0]}};function GO(e,t=[0,0,0]){let n=WO[e];if(!n)return R(U(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?OO(n.normal,t):SO(t),L(UO(r,n.xDir,n.normal))}function KO(e,t){return typeof e==`string`?GO(e,t):L(e)}function qO(e,t){return e&&typeof e!=`string`?{...e}:B(KO(e??`XY`,t))}function JO(e,t){let[n,r]=t;return EO(EO(e.origin,OO(e.xDir,n)),OO(e.yDir,r))}function YO(e,t){return{...e,origin:EO(e.origin,t)}}function XO(e,t,n=[1,0,0]){let r=t*wD,i=BO(e.zDir,n,r),a=BO(e.xDir,n,r),o=FO(jO(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var ZO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},QO=e=>ZO[e],$O={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},ek=function*(e,t){let n=P().iterShapes(e,$O[t]);for(let e of n)yield e},tk=e=>P().isNull(e)?R(gD(`NULL_SHAPE`,`This shape has no type, it is null`)):L(e.ShapeType());function nk(e){if(P().isNull(e))return R(gD(`NULL_SHAPE`,`This shape has no type, it is null`));try{return L(P().downcast(e))}catch(e){return R(gD(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function rk(e){if(P().isNull(e))return R(gD(`NULL_SHAPE`,`Cannot copy a null shape`));try{return L(P().copyShape(e))}catch(e){return R(gD(`NO_WRAPPER`,`Could not copy this shape`,e))}}function ik(e){return P().isNull(e)?R(gD(`NULL_SHAPE`,`Cannot cast a null shape`)):L(RE(e))}function ak(e){return P().shapeType(e.wrapped)===`compsolid`}function ok(e){return ik(P().fromBREP(e))}var sk={plane:`PLANE`,cylinder:`CYLINDRE`,cone:`CONE`,sphere:`SPHERE`,torus:`TORUS`,bezier:`BEZIER_SURFACE`,bspline:`BSPLINE_SURFACE`,revolution:`REVOLUTION_SURFACE`,extrusion:`EXTRUSION_SURFACE`,offset:`OFFSET_SURFACE`,other:`OTHER_SURFACE`};function ck(e){return L(sk[oO(e)])}function lk(e){return B(ck(e))}function uk(e){return P().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function dk(e){return RE(P().reverseShape(e.wrapped))}function fk(e){return P().uvBounds(e.wrapped)}function pk(e,t,n){let r=fk(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return P().pointOnSurface(e.wrapped,i,a)}function mk(e,t){let n=SO(t);return P().uvFromPoint(e.wrapped,n)||[0,0]}function hk(e,t){let n=SO(t);try{let t=n,r=P().uvFromPoint(e.wrapped,t);if(!r)return R(gD(`PROJECTION_FAILED`,`No projection found on the face`));let i=P().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return L({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return R(gD(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function gk(e,t){let n,r;if(t)[n,r]=mk(e,t);else{let t=fk(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return P().surfaceNormal(e.wrapped,n,r)}function _k(e){return P().surfaceCenterOfMass(e.wrapped)}function vk(e){return P().getSurfaceAxis(e.wrapped)}function yk(e,t,n=1e-6){let[r,i]=mk(e,t);return P().classifyPointOnFace(e.wrapped,r,i,n)}function bk(e){return RE(P().outerWire(e.wrapped))}function xk(e){return RE(P().removeHolesFromFace(e.wrapped))}function Sk(e){let t=bk(e);return Array.from(ek(e.wrapped,`wire`)).map(e=>RE(B(nk(e)))).filter(e=>!P().isSame(e.wrapped,t.wrapped))}function Ck(e,t){let n=VD(e),r=new Map;for(let n of LD(e,`face`))r.set(n,t);n.faceOrigins=r}function wk(e){return HD(e)?.faceOrigins}function Tk(e,t,n){let r=new Map;for(let e of t){let t=wk(e);if(t)for(let[e,n]of t)r.set(e,n)}if(r.size===0)return;let i=new Map;for(let[t,n]of r){if(e.deleted.has(t))continue;let r=e.modified.get(t);if(r&&r.length>0)for(let e of r)i.set(e,n);else i.set(t,n);let a=e.generated.get(t);if(a)for(let e of a)i.has(e)||i.set(e,n)}if(i.size>0){let e=VD(n);e.faceOrigins=i}}var Ek=100,Dk=.985,Ok=.1;function kk(e,t,n,r){let i=-1/0,a;for(let n of r){let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(r<.707)continue;let o=t[0]-n.centroid[0],s=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=o*o+s*s+c*c;if(l>Ek)continue;let u=r-l/Ek;u>i&&(i=u,a=n.origin)}if(a!==void 0)return a;if(!n)return;let o=1/0,s;for(let n of r){if(!n.planar)continue;let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(Math.abs(r)<Dk)continue;let i=t[0]-n.centroid[0],a=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=i*n.normal[0]+a*n.normal[1]+c*n.normal[2];if(l*l>Ok)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function Ak(e,t){let n=new Map;for(let t of e){let e=wk(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=P(),i=new Map,a=GD(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,W),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=wk(n);if(e)for(let i of GD(n)){let n=r.hashCode(i.wrapped,W),a=e.get(n);if(a!==void 0)try{let e=r.uvBounds(i.wrapped),n=r.surfaceNormal(i.wrapped,.5*(e.uMin+e.uMax),.5*(e.vMin+e.vMax)),o=r.surfaceCenterOfMass(i.wrapped),s=r.surfaceType(i.wrapped)===`plane`;t.push({origin:a,normal:n,centroid:o,planar:s})}catch{}}}if(t.length>0)for(let e of o){let n=r.hashCode(e.wrapped,W);try{let a=r.uvBounds(e.wrapped),o=kk(r.surfaceNormal(e.wrapped,.5*(a.uMin+a.uMax),.5*(a.vMin+a.vMax)),r.surfaceCenterOfMass(e.wrapped),r.surfaceType(e.wrapped)===`plane`,t);o!==void 0&&i.set(n,o)}catch{}}}if(i.size>0){let e=VD(t);e.faceOrigins=i}}function jk(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function Mk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function Nk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function Pk(e){return Array.from(Array(e).keys())}function Fk(e){return Pk(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function Ik(e,t){return SE(P().makeLineEdge([...e],[...t]))}function Lk(e,t=[0,0,0],n=[0,0,1]){return SE(P().makeCircleEdge([...t],[...n],e))}function Rk(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?R(U(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):L(SE(P().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function zk(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return CE(P().makeHelixWire(e,t,n,[...r],[...i],a))}function Bk(e,t,n){return SE(P().makeArcEdge([...e],[...t],[...n]))}function Vk(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?R(U(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):L(SE(P().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function Hk(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return L(SE(P().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return R(H(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function Uk(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return L(SE(P().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return R(H(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function Wk(e){if(e.length<2)return R(U(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return L(SE(P().makeBezierEdge(t)))}function Gk(e,t,n){return SE(P().makeTangentArc([...e],[...t],[...n]))}function Kk(e){try{return L(CE(P().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return R(H(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function qk(e,t){try{let n=P().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=Zk(wE(n),t);return vO(e)?L(e):R(U(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=wE(n);return vO(r)?L(r):R(U(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return R(H(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function Jk(e){return qk(bk(e))}function Yk(e,t){return wE(P().makeFaceOnSurface(e.wrapped,t.wrapped))}function Xk(e){try{return YE(ik(P().makeNonPlanarFace(e.wrapped)),e=>ME(e)?L(e):R(H(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return R(H(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function Zk(e,t){return wE(P().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function Qk(e){try{var t=GT();if(e.length<3)return R(U(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new aE);return YE(Kk(Fk([e,n]).map(([e,t])=>r.register(Ik(e,t)))),e=>qk(r.register(e)))}catch(e){t.e=e}finally{t.d()}}var $k=new WeakMap,eA=new WeakMap;function tA(e){return $k.has(e.wrapped)}function nA(e){let t=$k.get(e.wrapped);return t||(t=new Map,$k.set(e.wrapped,t)),t}function rA(e){let t=eA.get(e.wrapped);return t||(t=new Map,eA.set(e.wrapped,t)),t}function iA(e,t,n){let r=Array.isArray(t)?t:GD(e).filter(t),i=nA(e),a=i.get(n)??new Set;for(let e of r)a.add(P().hashCode(e.wrapped,W));return i.set(n,a),e}function aA(e,t){let n=$k.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of GD(e)){let e=P().hashCode(t.wrapped,W);r.has(e)&&i.push(t)}return i}function oA(e){let t=new Map,n=$k.get(e.wrapped);if(!n)return t;let r=GD(e),i=new Map;for(let e of r)i.set(P().hashCode(e.wrapped,W),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function sA(e,t,n){return rA(e).set(t,n),e}function cA(e,t){return eA.get(e.wrapped)?.get(t)}function lA(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function uA(e,t,n){let r=nA(n);for(let i of t){let t=$k.get(i.wrapped);if(!t)continue;let a=new Map;for(let[e,n]of t)for(let t of n){let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let[t,n]of a){if(e.deleted.has(t))continue;let i=e.modified.get(t),a=i&&i.length>0?i:[t];for(let e of a)for(let t of n)lA(r,t,e)}let o=eA.get(i.wrapped);if(o){let e=rA(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var dA=new WeakMap,fA=new WeakMap;function pA(e){return dA.has(e.wrapped)||fA.has(e.wrapped)}function mA(e){let t=fA.get(e.wrapped);return t||(t=new Map,fA.set(e.wrapped,t)),t}function hA(e){if(typeof e==`string`){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2)),[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}return e.length===3?[e[0],e[1],e[2],1]:[e[0],e[1],e[2],e[3]]}function gA(e,t){return dA.set(e.wrapped,hA(t)),e}function _A(e,t,n){let r=hA(n),i=mA(e);for(let e of t)i.set(P().hashCode(e.wrapped,W),r);return e}function vA(e){return dA.get(e.wrapped)}function yA(e,t){let n=fA.get(e.wrapped);if(n)return n.get(P().hashCode(t.wrapped,W))}function bA(e,t,n){for(let e of t){let t=dA.get(e.wrapped);if(t){dA.set(n.wrapped,t);break}}let r=mA(n);for(let n of t){let t=fA.get(n.wrapped);if(!(!t||t.size===0))for(let[n,i]of t){if(e.deleted.has(n))continue;let t=e.modified.get(n);if(t&&t.length>0)for(let e of t)r.set(e,i);else r.set(n,i)}}}function xA(e){return wk(e)!==void 0||tA(e)||pA(e)}function SA(e){if(!e.some(xA))return[];let t=[];for(let n of e)t.push(...LD(n,`face`));return t}function CA(e,t,n){Tk(e,t,n),uA(e,t,n),bA(e,t,n)}function wA(e,t){Ak(e,t)}function TA(e,t){let n=P(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t!==void 0&&o!==void 0&&a.set(n.hashCode(t,W),[n.hashCode(o,W)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);CA({modified:a,generated:new Map,deleted:new Set},[e],t)}function EA(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function DA(e,t,n,r,i){let a=RE(e);if(!IE(a)){let o=yE(a).toUpperCase();return BE(e,a),I(a),R(gD(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return BE(e,a),L(a)}function OA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`fuse: first operand`);if(z(c))return c;let l=EA(t,`fuse: second operand`);if(z(l))return l;if(!s)return DA(P().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=SA([e,t]),{shape:d,evolution:f,diagnostics:p}=P().fuseWithHistory(e.wrapped,t.wrapped,u,W,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(P().isNull(d))return P().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),DA(P().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=DA(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&CA(f,[e,t],m.value),m}function kA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`cut: base`);if(z(c))return c;let l=EA(t,`cut: tool`);if(z(l))return l;if(!s)return DA(P().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=SA([e,t]),{shape:d,evolution:f,diagnostics:p}=P().cutWithHistory(e.wrapped,t.wrapped,u,W,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(P().isNull(d))return P().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),DA(P().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=DA(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&CA(f,[e,t],m.value),m}function AA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=EA(e,`intersect: first operand`);if(z(s))return s;let c=EA(t,`intersect: second operand`);if(z(c))return c;if(!o)return DA(P().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=SA([e,t]),{shape:u,evolution:d,diagnostics:f}=P().intersectWithHistory(e.wrapped,t.wrapped,l,W,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(P().isNull(u))return P().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),DA(P().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=DA(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&CA(d,[e,t],p.value),p}function jA(e,t,n,r,i,a,o,s,c){if(s?.aborted)throw s.reason;let l=n-t;if(l===1)return L({shape:jk(e,t),owned:!1});if(l===2){let n=OA(jk(e,t),jk(e,t+1),{optimisation:r,simplify:a?i:!1,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return z(n)?n:L({shape:n.value,owned:!0})}let u=t+Math.ceil(l/2),d=jA(e,t,u,r,i,!1,o,s,c);if(z(d))return d;let f=jA(e,u,n,r,i,!1,o,s,c);if(z(f))return d.value.owned&&I(d.value.shape),f;let p=OA(d.value.shape,f.value.shape,{optimisation:r,simplify:i,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return d.value.owned&&I(d.value.shape),f.value.owned&&I(f.value.shape),z(p)?p:L({shape:p.value,owned:!0})}function MA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return R(U(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return L(Mk(e));for(let t=0;t<e.length;t++){let n=EA(jk(e,t),`fuseAll: shape at index ${t}`);if(z(n))return n}if(r===`native`){let o=DA(P().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&wA(e,o.value),o}let c=jA(e,0,e.length,t,n,!0,s,i,a);return z(c)?c:L(c.value.shape)}function NA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(t.length===0)return L(e);let c=EA(e,`cutAll: base`);if(z(c))return c;for(let e=0;e<t.length;e++){let n=EA(jk(t,e),`cutAll: tool at index ${e}`);if(z(n))return n}let l=[e,...t],u=DA(P().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&wA(l,u.value),u}function PA(e,t,n){if(n!==void 0)return{size:n,center:t.origin};let{min:r,max:i}=P().boundingBox(e.wrapped),a=[(r[0]+i[0])/2,(r[1]+i[1])/2,(r[2]+i[2])/2],o=AO(DO(a,t.origin),t.zDir),s=DO(a,OO(t.zDir,o)),c=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);return{size:Math.max(c,1),center:s}}function FA(e,t,n){let r=P(),i=OO(e.xDir,t),a=OO(e.yDir,t),o=OO(e.xDir,-t),s=OO(e.yDir,-t),c=n,l=[...EO(EO(c,o),s)],u=[...EO(EO(c,i),s)],d=[...EO(EO(c,i),a)],f=[...EO(EO(c,o),a)],p=[r.makeLineEdge(l,u),r.makeLineEdge(u,d),r.makeLineEdge(d,f),r.makeLineEdge(f,l)],m=r.makeWire(p),h=r.makeFace(m,!0);for(let e of p)r.dispose(e);return r.dispose(m),h}function IA(e,t,{approximation:n=!0,planeSize:r}={}){if(P().isNull(e.wrapped))return R(U(V.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=typeof t==`string`?B(KO(t)):t,{size:a,center:o}=PA(e,i,r),s=FA(i,a,o);try{return L(F(P().section(e.wrapped,s,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return R(H(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{P().dispose(s)}}function LA(e){let t=P(),n=new Map,r=new Map;for(let i of e){let e=qD(i),a=e[0]?t.hashCode(e[0].wrapped,W):-1,o=e.length>1&&e[1]?t.hashCode(e[1].wrapped,W):a;r.set(i,[a,o]);for(let e of[a,o]){let t=n.get(e)??[];t.push(i),n.set(e,t)}}return{vertexToEdges:n,edgeVertexHashes:r}}function RA(e,t,n){let r=t.vertexToEdges.get(e);if(r)for(let i of r){if(n.has(i))continue;let r=t.edgeVertexHashes.get(i);if(r)return n.add(i),{edge:i,nextTip:r[0]===e?r[1]:r[0]}}}function zA(e,t,n){n.add(e);let r=[e],i=t.edgeVertexHashes.get(e);if(!i)return r;let a=[i[1],i[0]];for(let e=0;e<2;e++){let i=a[e];if(i===void 0)continue;let o=RA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=RA(i,t,n)}return r}function BA(e){let t=P(),n=LA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=zA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(F(n))}catch{}}return i}function VA(e){let t=P(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function HA(e,t,n={}){let r=IA(e,t,n);if(!r.ok)return r;let i=KD(r.value);if(i.length===0){let e=WD(r.value);if(e.length===0)return R(H(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...BA(e))}if(i.length===0)return R(H(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=VA(i),o=jk(i,a),s=i.filter((e,t)=>t!==a);return qk(o,s.length>0?s:void 0)}function UA(e,t){if(t.length===0)return L(e);if(P().isNull(e.wrapped))return R(U(V.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(P().isNull(jk(t,e).wrapped))return R(U(V.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return L(F(P().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return R(H(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function WA(e,t,n={}){let r=[];for(let i of t){let t=IA(e,i,n);if(z(t))return t;r.push(t.value)}return L(r)}function GA(e,t,n){if(t.length===0)return L(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=P(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return KA(e,t,n);if(o===null)return R(H(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=F(o);return IE(s)?L(s):(I(s),R(gD(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return R(H(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function KA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?OA(r,e.tool,i):e.op===`cut`?kA(r,e.tool,i):AA(r,e.tool,i);if(z(t))return t;r=B(t)}return L(r)}function qA(e){return F(P().sew(e.map(e=>e.wrapped)))}function JA(e,t=!1){let n=qA(e);return!t&&!NE(n)?R(gD(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):L(n)}function YA(e,t,n=[0,0,0],r=[0,0,1]){return EE(P().makeCylinder(e,t,[...n],[...r]))}function XA(e){return EE(P().makeSphere(e))}function ZA(e,t,n,r=[0,0,0],i=[0,0,1]){return EE(P().makeCone(e,t,n,[...r],[...i]))}function QA(e,t,n=[0,0,0],r=[0,0,1]){return EE(P().makeTorus(e,t,[...n],[...r]))}function $A(e,t,n){return EE(P().makeEllipsoid(e,t,n))}function ej(e){return xE(P().makeVertex(e[0],e[1],e[2]))}function tj(e,t,n=1e-6){return YE(nk(P().offset(e.wrapped,t,n)),e=>YE(ik(e),e=>IE(e)?L(e):R(gD(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function nj(e){return OE(P().makeCompound(e.map(e=>e.wrapped)))}function rj(e){try{var t=GT();let n=t.u(qA(e)),r=F(P().solidFromShell(n.wrapped));return PE(r)?L(r):(I(r),R(gD(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function ij(e,t){let n=SA([e]),{shape:r,evolution:i}=P().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,W),a=F(r);return CA(i,[e],a),a}function aj(e,t,n=[0,0,0],r=[0,0,1]){let i=SA([e]),{shape:a,evolution:o}=P().rotateWithHistory(e.wrapped,t*wD,i,W,r,n),s=F(a);return CA(o,[e],s),s}function oj(e,t=[0,1,0],n=[0,0,0]){let r=SA([e]),{shape:i,evolution:a}=P().mirrorWithHistory(e.wrapped,n,t,r,W),o=F(i);return CA(a,[e],o),o}function sj(e,t,n=[0,0,0]){let r=SA([e]),{shape:i,evolution:a}=P().scaleWithHistory(e.wrapped,n,t,r,W),o=F(i);return CA(a,[e],o),o}function cj(e,t,n){let r=P().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?L(sj(e,c[0])):R(U(V.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function lj(e){if(`linear`in e)return L({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?R(U(V.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):L({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function uj(e){return e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6])}function dj(e){let t=1e-8,n=e[0]*e[0]+e[3]*e[3]+e[6]*e[6],r=e[1]*e[1]+e[4]*e[4]+e[7]*e[7],i=e[2]*e[2]+e[5]*e[5]+e[8]*e[8],a=e[0]*e[1]+e[3]*e[4]+e[6]*e[7],o=e[0]*e[2]+e[3]*e[5]+e[6]*e[8],s=e[1]*e[2]+e[4]*e[5]+e[7]*e[8];return!(Math.abs(a)>t||Math.abs(o)>t||Math.abs(s)>t||Math.abs(n-r)>t||Math.abs(n-i)>t)}function fj(e,t){let n=lj(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=uj(r);if(Math.abs(a)<1e-12)return R(U(V.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(dj(r)){let t=SA([e]),{shape:n,evolution:a}=P().generalTransformWithHistory(e.wrapped,r,i,!0,t,W),o=F(n);return CA(a,[e],o),L(o)}let o=F(P().generalTransformNonOrthogonal(e.wrapped,r,i));return wA([e],o),L(o)}function pj(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=P().composeTransform(t);return{trsf:n,cleanup:r}}function mj(e,t){let{trsf:n,cleanup:r}=pj(`type`in t?[t]:t),i;try{i=F(P().locate(e.wrapped,n))}finally{r()}return xA(e)&&TA(e,i),i}function hj(e,t){let n=SA([e]),{shape:r,evolution:i}=P().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,W),a=F(r);return CA(i,[e],a),a}function gj(e,t,n,r){let i=EE(P().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=GT();return ij(o.u(i),[a[0]-e/2,a[1]-t/2,a[2]-n/2])}catch(e){o.e=e}finally{o.d()}return i}function _j(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=YA(e,t,r,i);if(n?.centered)try{var o=GT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return ij(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function vj(e,t){let n=XA(e);if(t?.at)try{var r=GT();return ij(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function yj(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=ZA(e,t,n,i,a);if(r?.centered)try{var s=GT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return ij(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function bj(e,t,n){return QA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function xj(e,t,n,r){let i=$A(e,t,n);if(r?.at)try{var a=GT();return ij(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function Sj(e,t){return Ik(e,t)}function Cj(e,t){let n=t?.axis??[0,0,1];return Lk(e,t?.at??[0,0,0],n)}function wj(e,t,n){let r=n?.axis??[0,0,1];return Rk(e,t,n?.at??[0,0,0],r,n?.xDir)}function Tj(e,t,n,r){return zk(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function Ej(e,t,n){return Bk(e,t,n)}function Dj(e,t,n,r,i){let a=i?.axis??[0,0,1];return Vk(e,t,n*wD,r*wD,i?.at??[0,0,0],a,i?.xDir)}function Oj(e,t){return Hk(e,t)}function kj(e){return Wk(e)}function Aj(e,t,n){return Gk(e,t,n)}function jj(e){return Kk(e)}function Mj(e){return YE(Kk(e),e=>uO(e)?L(e):R(U(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function Nj(e,t){return qk(e,t)}function Pj(e){return Xk(e)}function Fj(e,t){return Yk(e,t)}function Ij(e){return Qk(e)}function Lj(e){return ej(e)}function Rj(e){return nj(e)}function zj(e){return rj(e)}function Bj(e,t,n){return tj(e,t,n)}function Vj(e,t){return JA(e,t)}function Hj(e,t){return Zk(e,t)}function Uj(e){return MD(()=>P().copyShape(e.wrapped),V.CLONE_FAILED,`Failed to clone shape`)}function Wj(e){return ND(()=>P().toBREP(e.wrapped),V.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function Gj(e){return P().hashCode(e.wrapped,W)}function Kj(e){return P().isNull(e.wrapped)}function qj(e,t){return P().isSame(e.wrapped,t.wrapped)}function Jj(e,t){return P().isEqual(e.wrapped,t.wrapped)}function Yj(e){return MD(()=>P().simplify(e.wrapped),V.SIMPLIFY_FAILED,`Failed to simplify shape`)}function Xj(e){return P().curveType(e.wrapped)}function Zj(e){let[t]=P().curveParameters(e.wrapped);return P().curvePointAtParam(e.wrapped,t)}function Qj(e){let[,t]=P().curveParameters(e.wrapped);return P().curvePointAtParam(e.wrapped,t)}function $j(e,t=.5){let[n,r]=P().curveParameters(e.wrapped),i=n+(r-n)*t;return P().curvePointAtParam(e.wrapped,i)}function eM(e,t=.5){let[n,r]=P().curveParameters(e.wrapped),i=n+(r-n)*t;return P().curveTangent(e.wrapped,i).tangent}function tM(e){return P().length(e.wrapped)}function nM(e){if(Xj(e)!==`CIRCLE`)return null;let t=$j(e,0),n=$j(e,1/3),r=$j(e,2/3),i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],a=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],o=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],s=o[0]*o[0]+o[1]*o[1]+o[2]*o[2];if(s<1e-18)return null;let c=i[0]*i[0]+i[1]*i[1]+i[2]*i[2],l=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],u=[c*a[0]-l*i[0],c*a[1]-l*i[1],c*a[2]-l*i[2]],d=[u[1]*o[2]-u[2]*o[1],u[2]*o[0]-u[0]*o[2],u[0]*o[1]-u[1]*o[0]],f=1/(2*s),p=[t[0]+d[0]*f,t[1]+d[1]*f,t[2]+d[2]*f],m=Math.sqrt(s);return{origin:p,direction:[o[0]/m,o[1]/m,o[2]/m]}}function rM(e){return P().curveIsClosed(e.wrapped)}function iM(e){return P().curveIsPeriodic(e.wrapped)}function aM(e){return P().curvePeriod(e.wrapped)}function oM(e){return P().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function sM(e){return F(P().reverseShape(e.wrapped))}function cM(e,t={}){if(e.length<2)return R(gD(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=F(P().interpolatePoints(e,t));return AE(n)?L(n):(I(n),R(gD(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return R(gD(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function lM(e,t={}){if(e.length<2)return R(gD(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=F(P().approximatePoints(e,t));return AE(n)?L(n):(I(n),R(gD(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return R(gD(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function uM(e,t,n=`arc`){let r=F(P().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return jE(r)?L(r):(I(r),R(gD(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function dM(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function fM(e,t){return`edge:${e}:${t}`}var pM=new WeakMap,mM=new WeakMap;function hM(e,t){let n=pM.get(e);if(n)return n.get(t)}function gM(e,t,n){let r=pM.get(e);r||(r=new Map,pM.set(e,r)),r.set(t,n)}function _M(e,t){let n=mM.get(e);if(n)return n.get(t)}function vM(e,t,n){let r=mM.get(e);r||(r=new Map,mM.set(e,r)),r.set(t,n)}function yM(){pM=new WeakMap,mM=new WeakMap}function bM(){let e=new WeakMap,t=new WeakMap;return{getMesh(t,n){return e.get(t)?.get(n)},setMesh(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,r)},getEdgeMesh(e,n){return t.get(e)?.get(n)},setEdgeMesh(e,n,r){let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(n,r)},clear(){e=new WeakMap,t=new WeakMap}}}var xM=10;function SM(e,t){let n;try{let e=iO(t),r=e.xMax-e.xMin,i=e.yMax-e.yMin,a=e.zMax-e.zMin;n=Math.sqrt(r*r+i*i+a*a)}catch{return e}return e*Math.max(1,n/xM)}function CM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=dM(r,i,a,o);if(s){let t=hM(e.wrapped,l);if(t)return t}let u=P().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=wk(e),f={vertices:u.vertices,normals:u.normals,triangles:u.triangles,uvs:u.uvs,faceGroups:u.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:d?.get(e.faceHash)??0}))};return s&&gM(e.wrapped,l,f),f}function wM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=fM(r,i);if(a){let t=_M(e.wrapped,o);if(t)return t}let s=P().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&vM(e.wrapped,o,c),c}function TM(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?bD(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?bD(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):bD(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function EM(e){let t;try{t=JD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{iO(e)}catch(e){if(e instanceof TypeError)throw e;n.push(t)}}),n.length===0?`; could not localize the offending sub-solid among ${t.length} solids`:`; offending sub-solid${n.length>1?`s`:``} (of ${t.length}): index ${n.join(`, `)}`}function DM(e,t){try{return iO(e),null}catch(n){if(n instanceof TypeError)throw n;return bD(`${t}_EXPORT_UNSERIALIZABLE`,`${t} export aborted: the shape contains degenerate geometry the ${t} writer cannot serialize (bounding-box evaluation failed); export was skipped to avoid crashing the kernel${EM(e)}`,n)}}function OM(e){let t=DM(e,`STEP`);if(t)return R(t);try{let t=P().exportSTEP([e.wrapped]);return L(new Blob([t],{type:`application/STEP`}))}catch(e){return R(TM(e,`STEP`))}}function kM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=DM(e,`STL`);if(o)return R(o);try{P().hasTriangulation(e.wrapped)||P().meshShape(e.wrapped,r,i);let t=P().exportSTL(e.wrapped,a,r,i);return L(new Blob([t],{type:`application/sla`}))}catch(e){return R(TM(e,`STL`))}}function AM(e){try{let t=P().exportIGES([e.wrapped]);return L(new Blob([t],{type:`application/iges`}))}catch(e){return R(bD(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function jM(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:CM(e,{tolerance:n,angularTolerance:i}),fine:CM(e,{tolerance:r,angularTolerance:i*.2})}}function MM(e){let t=iO(e),n=t.xMax-t.xMin,r=t.yMax-t.yMin,i=t.zMax-t.zMin;return Math.sqrt(n*n+r*r+i*i)||1}function NM(e,t){let n;if(t.tolerances&&t.tolerances.length>0)n=[...t.tolerances];else{let r=Math.max(1,Math.floor(t.levels??3)),i=t.spacing??4,a=(t.relativeTolerance??5e-4)*MM(e)||2**-52;n=[];for(let e=r-1;e>=0;e--)n.push(a*i**e)}return n.sort((e,t)=>t-e),n}function PM(e,t,n){return Math.min(e/t*n,1)}function FM(e,t={}){let n=t.angularTolerance??ho().angularTolerance,r=t.cache??!0,i=NM(e,t),a=Math.min(...i);return i.map(i=>{let o=PM(i,a,n);return{tolerance:i,angularTolerance:o,mesh:CM(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function IM(){return new Promise(e=>{setTimeout(e,0)})}async function LM(e,t={}){let n=t.angularTolerance??ho().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>CM(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=NM(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=PM(c,o,n),u;try{u=await i(e,c,l)}catch(e){if(t.signal?.aborted)break;throw e}let d={tolerance:c,angularTolerance:l,mesh:u};if(s.push(d),t.onLevel?.(d,r),t.signal?.aborted||r===a.length-1)break;await IM()}return s}function RM(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function zM(e){return{position:e.vertices,normal:e.normals,index:e.triangles,groups:e.faceGroups.map((e,t)=>({start:e.start,count:e.count,materialIndex:t,faceId:e.faceId}))}}function BM(e){return{position:e.lines}}function VM(e,t){return{coarse:RM(e.coarse),fine:RM(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function HM(e,t){let n=t?.step??50,r=t?.distances;if(r&&r.length!==e.length)throw Error(`toLODGeometryLevels: distances must have one entry per level (got ${r.length} for ${e.length} levels)`);let i=e.length-1;return e.map((e,t)=>({geometry:RM(e.mesh),distance:r?.[t]??(i-t)*n}))}function UM(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function WM(e,t){if(typeof e==`number`&&e<=0)return R(U(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return R(U(t.code,t.pair,void 0,void 0,t.pairHint))}function GM(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(P().hashCode(e,W));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function KM(e,t,n,r,i){let a=F(t);return IE(a)?(CA(e,n,a),L(a)):(I(a),R(H(r,i)))}function qM(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(P().hashCode(e,W));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function JM(e,t){let n=UM(e,`thicken: shape`);if(z(n))return n;try{let n=SA([e]),{shape:r,evolution:i}=P().thickenWithHistory(e.wrapped,t,n,W),a=F(r);return CA(i,[e],a),L(a)}catch(e){return R(H(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function YM(e,t,n){let r=UM(e,`fillet: shape`);if(z(r))return r;let i=WM(n,{code:`INVALID_FILLET_RADIUS`,scalar:`Fillet radius must be positive`,pair:`Fillet radii must both be positive`,scalarHint:`Provide a positive radius value greater than 0`,pairHint:`Both radius values must be greater than 0`});if(i)return i;let a=t??WD(e);if(a.length===0)return R(U(V.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=GM(a,n);return e?L({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):R(U(V.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return L({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function XM(e,t,n,{trackEvolution:r=!0}={}){let i=YM(e,t,n);if(z(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=F(P().fillet(e.wrapped,t,o));return IE(n)?L(n):(I(n),R(H(V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}let n=SA([e]),{shape:i,evolution:s}=P().filletWithHistory(e.wrapped,t,o,n,W);return KM(s,i,[e],V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return R(H(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function ZM(e,t,n){let r=UM(e,`chamfer: shape`);if(z(r))return r;let i=WM(n,{code:`INVALID_CHAMFER_DISTANCE`,scalar:`Chamfer distance must be positive`,pair:`Chamfer distances must both be positive`,scalarHint:`Provide a positive distance value greater than 0`,pairHint:`Both distance values must be greater than 0`});if(i)return i;let a=t??WD(e);if(a.length===0)return R(U(V.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=GM(a,n);if(!e)return R(U(V.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=SA([e]),{shape:o,evolution:s}=P().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,W);return KM(s,o,[e],V.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return R(H(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function QM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=UM(e,`shell: shape`);if(z(a))return a;if(n<=0)return R(U(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return R(U(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=F(P().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return IE(i)?L(i):(I(i),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}let a=SA([e]),{shape:o,evolution:s}=P().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,W,r),c=F(o);return IE(c)?(CA(s,[e],c),L(c)):(I(c),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return R(H(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function $M(e,t,n=1e-6){let r=UM(e,`offset: shape`);if(z(r))return r;if(Math.abs(t)<1e-10)return R(U(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=SA([e]),{shape:i,evolution:a}=P().offsetWithHistory(e.wrapped,t,r,W,n),o=F(i);return IE(o)?(CA(a,[e],o),L(o)):(I(o),R(H(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`)))}catch(e){return R(H(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function eN(e,t,n){let r=UM(e,`draft: shape`);if(z(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return R(U(V.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return R(U(V.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return R(U(V.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function tN(e,t,n,r,i){let a=eN(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=qM(t,i);if(a.length===0)return R(U(V.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=SA([e]),{shape:c,evolution:l}=P().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,W);return KM(l,c,[e],V.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return R(H(V.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function nN(e,t,n){if(n.length===0)return R(U(V.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return R(U(V.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=P();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,W),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=F(r.filletVariable(e.wrapped,i));return IE(a)?PE(a)?L(a):(I(a),R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(I(a),R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function rN(e,t,n,r){if(t.length===0)return R(U(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return R(U(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return R(U(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=P(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return R(H(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=nk(i);if(z(a))return P().dispose(i),a;let o=F(a.value);return BE(i,o),IE(o)?L(o):(I(o),R(gD(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function iN(e){let t=P();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function aN(e){let t=P();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var oN={cut:kA,cutAll:NA,fuse:OA,fuseAll:MA};function sN(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function cN(e,t,n={}){return lN(oN,e,t,n)}function lN(e,t,n,r={}){if(r.signal?.aborted)throw r.signal.reason;let i={totalInputs:n.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},a=uN(e,t,n,0,r,i);return z(a)?a:L({shape:a.value,telemetry:sN(i)})}function uN(e,t,n,r,i,a){if(n.length===0)return L(t);if(n.length===1)return dN(e,t,n,r,i,a);a.batchAttempts++;let o=gN(()=>e.cutAll(t,n,i));if(o&&o.ok)return a.batchSucceeded++,o;if(i.signal?.aborted)throw i.signal.reason;let s=Math.floor(n.length/2),c=uN(e,t,n.slice(0,s),r,i,a);return c.ok?uN(e,c.value,n.slice(s),r+s,i,a):c}function dN(e,t,n,r,i,a){a.singletonFallbacks++;let o=Mk(n),s=gN(()=>e.cut(t,o,i));if(s&&s.ok)return s;if(i.signal?.aborted)throw i.signal.reason;return a.failedInputs.add(r),L(t)}function fN(e,t={}){return pN(oN,e,t)}function pN(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return R(U(V.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=mN(e,t,0,n,r);return z(i)?i:L({shape:i.value,telemetry:sN(r)})}function mN(e,t,n,r,i){if(t.length===1)return L(Mk(t));i.batchAttempts++;let a=gN(()=>e.fuseAll(t,r));if(a&&a.ok)return i.batchSucceeded++,a;if(r.signal?.aborted)throw r.signal.reason;let o=Math.floor(t.length/2);return hN(e,mN(e,t.slice(0,o),n,r,i),mN(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function hN(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=gN(()=>e.fuse(t.value,n.value,o));if(c&&c.ok)return c;for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(t.ok){for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(n.ok){for(let e=0;e<a;e++)s.failedInputs.add(i+e);return n}return t}function gN(e){try{return e()}catch{return null}}function _N(e,t,n){return P().checkBoolean(e.wrapped,t.wrapped,n)}function vN(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function yN(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function bN(e,t,n,r){let i=RE(e);if(!IE(i)){let a=yE(i).toUpperCase();return BE(e,i),I(i),R(gD(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return BE(e,i),L(i)}function xN(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(P().hashCode(e,2147483647))??1}}function SN(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=vN(e,`fuseWithEvolution: first operand`);if(z(o))return o;let s=vN(t,`fuseWithEvolution: second operand`);if(z(s))return s;let c=SA([e,t]),{shape:l,evolution:u}=P().fuseWithHistory(e.wrapped,t.wrapped,c,W,{optimisation:n,simplify:r,fuzzyValue:a}),d=bN(l,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`);return d.ok?(CA(u,[e,t],d.value),L({shape:d.value,evolution:u})):d}function CN(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=vN(e,`cutWithEvolution: base`);if(z(o))return o;let s=vN(t,`cutWithEvolution: tool`);if(z(s))return s;let c=SA([e,t]),{shape:l,evolution:u}=P().cutWithHistory(e.wrapped,t.wrapped,c,W,{optimisation:n,simplify:r,fuzzyValue:a}),d=bN(l,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`);return d.ok?(CA(u,[e,t],d.value),L({shape:d.value,evolution:u})):d}function wN(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=vN(e,`intersectWithEvolution: first operand`);if(z(a))return a;let o=vN(t,`intersectWithEvolution: second operand`);if(z(o))return o;let s=SA([e,t]),{shape:c,evolution:l}=P().intersectWithHistory(e.wrapped,t.wrapped,s,W,{simplify:n,fuzzyValue:i}),u=bN(c,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`);return u.ok?(CA(l,[e,t],u.value),L({shape:u.value,evolution:l})):u}function TN(e,t,n){let r=yN(e,`filletWithEvolution: shape`);if(z(r))return r;if(typeof n==`number`&&n<=0)return R(U(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return R(U(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??WD(e);if(i.length===0)return R(U(V.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=xN(i,n);if(!e)return R(U(V.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=SA([e]),{shape:o,evolution:s}=P().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,W),c=F(o);return IE(c)?(CA(s,[e],c),L({shape:c,evolution:s})):(I(c),R(H(V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return R(H(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function EN(e,t,n){let r=yN(e,`chamferWithEvolution: shape`);if(z(r))return r;if(typeof n==`number`&&n<=0)return R(U(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return R(U(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??WD(e);if(i.length===0)return R(U(V.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=xN(i,n);if(!e)return R(U(V.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=SA([e]),{shape:o,evolution:s}=P().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,W),c=F(o);return IE(c)?(CA(s,[e],c),L({shape:c,evolution:s})):(I(c),R(H(V.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return R(H(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function DN(e,t,n,r=.001){let i=yN(e,`shellWithEvolution: shape`);if(z(i))return i;if(n<=0)return R(U(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return R(U(`NO_FACES`,`At least one face must be specified for shell`));try{let i=SA([e]),{shape:a,evolution:o}=P().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,W,r),s=F(a);return IE(s)?(CA(o,[e],s),L({shape:s,evolution:o})):(I(s),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return R(H(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function ON(e,t,n){try{let r=F(P().positionOnCurve(e.wrapped,t.wrapped,n));return IE(r)?L(r):(I(r),R(H(V.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return R(H(V.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function kN(e){return sO(e)}function AN(e){if(!PE(e))return R(U(`NOT_A_SOLID`,`Input shape is not a solid`));let t=kN(e);try{let n=P().healSolid(e.wrapped);if(!n)return t?L(e):R(H(V.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=F(n);return PE(r)?(UD(r),kN(r)?L(r):(I(r),R(H(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(I(r),R(H(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return R(H(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function jN(e){if(!ME(e))return R(U(`NOT_A_FACE`,`Input shape is not a face`));try{let t=F(P().healFace(e.wrapped));return ME(t)?L(t):(I(t),R(H(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return R(H(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function MN(e,t){if(!jE(e))return R(U(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=F(P().healWire(e.wrapped,t?.wrapped));return jE(n)?L(n):(I(n),R(H(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return R(H(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function NN(e){return PE(e)?AN(e):ME(e)?jN(e):jE(e)?MN(e):L(e)}function PN(e,t){let n=t?.fixWires!==!1,r=t?.fixFaces!==!1,i=t?.fixSolids!==!1,a=t?.fixSelfIntersection===!0,o=t?.sewTolerance,s=[],c=[];if(kN(e))return L({shape:e,report:{isValid:!0,alreadyValid:!0,wiresHealed:0,facesHealed:0,solidHealed:!1,steps:[`Shape already valid`],diagnostics:[{name:`validation`,attempted:!0,succeeded:!0}]}});s.push(`Shape invalid — applying shape-level healing`);let l=KD(e).length,u=GD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&I(n)};if(o!==void 0)try{p(F(P().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=KD(d),t=0;for(let n of e)try{P().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(PE(d)&&i||ME(d)&&r||jE(d)&&n){let t=NN(d);KE(t)?(p(t.value),PE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):ME(e)?(s.push(`Applied ShapeFix_Face`),c.push({name:`healFace`,attempted:!0,succeeded:!0})):(s.push(`Applied ShapeFix_Wire`),c.push({name:`healWire`,attempted:!0,succeeded:!0}))):(s.push(`Shape-level healing failed`),c.push({name:`healShape`,attempted:!0,succeeded:!1}))}else c.push({name:`healShape`,attempted:!1,succeeded:!1,detail:`skipped by options`});let m=KD(d).length,h=GD(d).length,g=Math.abs(m-l),_=Math.abs(h-u);g>0&&s.push(`Wire count changed by ${g}`),_>0&&s.push(`Face count changed by ${_}`);let v=kN(d);return s.push(v?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:v}),L({shape:d,report:{isValid:v,alreadyValid:!1,wiresHealed:g,facesHealed:_,solidHealed:f,steps:s,diagnostics:c}})}function FN(e){try{return L(F(P().fixShape(e.wrapped)))}catch(e){return R(H(V.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function IN(e){try{let t=F(P().solidFromShell(e.wrapped));return PE(t)?kN(t)?L(t):(I(t),R(H(V.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(I(t),R(H(V.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return R(H(V.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function LN(e){try{let t=F(P().fixSelfIntersection(e.wrapped));return jE(t)?L(t):(I(t),R(H(V.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return R(H(V.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function RN(e,{profile:t,endFactor:n=1}){return e<1e-10?R(U(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?R(U(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):L(P().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function zN(e,t){let n=P(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),F(i)}function BN(e,t,n,r,i,a=!1){return F(P().makeHelixWire(e,t,n,[...r],[...i],a))}function VN(e){let t=F(e.shape),n=F(e.firstShape),r=F(e.lastShape),i=()=>{I(t),I(n),I(r)};return IE(t)?jE(n)?jE(r)?L([t,n,r]):(i(),R(gD(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),R(gD(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),R(gD(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function HN(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=F(P().simplePipe(e.wrapped,t.wrapped));return IE(n)?L(n):(I(n),R(gD(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=P(),_=s===`round`||!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return VN(v);let y=F(v);return IE(y)?L(y):(I(y),R(gD(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function UN(e,t,n,r){return HN(e,zN(t,EO(t,n)),{support:r})}function WN(e,t,n,r,i=!1){try{var a=GT();let o=MO(n);if(o<1e-10)return R(U(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=EO(t,n),c=a.u(zN(t,s)),l=null;if(r){let e=RN(o,r);if(z(e))return e;l=e.value}return HN(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function GN(e,t,n,r,i,a=!1){try{var o=GT();if(Math.abs(t)<1e-10)return R(U(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=MO(r);if(s<1e-10)return R(U(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=EO(n,r),l=o.u(zN(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(BN(d,s,1,n,r,u)),p=null;if(i){let e=RN(s,i);if(z(e))return e;p=e.value}return HN(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function KN(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return U(V.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return U(V.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function qN(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return R(U(V.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return L(o)}function JN(e,t,n){if(e.length<2)return R(U(V.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=KN(e);if(o)return R(o);try{let n=P(),o=qN(e,t,n);if(z(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=F(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return IE(o)?L(o):(I(o),R(gD(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}finally{for(let e of l)n.dispose(e);for(let e of c)n.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return R(H(V.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function YN(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=P(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=F(typeof l==`object`&&`shape`in l?l.shape:l);return IE(u)?L(u):(I(u),R(gD(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return R(H(V.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function XN(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return R(U(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=P(),s=n?o.makeVertex(...SO(n)):void 0,c=r?o.makeVertex(...SO(r)):void 0;try{let n=F(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return IE(n)?L(n):(I(n),R(gD(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return R(H(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function ZN(e){if(e.length===0)return L([]);let t=P(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...SO(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...SO(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=F(t);if(!IE(e))return I(e),R(gD(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return L(n)}catch(e){return R(H(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var QN=new WeakMap;function $N(e,t){return QN.get(e)?.get(t)}function eP(e,t,n){let r=QN.get(e);r||(r=new Map,QN.set(e,r)),r.set(t,n)}function tP(e){return P().isNull(e.wrapped)}function nP(e){return R(U(V.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function rP(e){let t=$N(e.wrapped,`volume`);if(t)return L(t);if(tP(e))return nP(`measureVolumeProps`);let n=P(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return eP(e.wrapped,`volume`,t),L(t)}let i=n.volume(e.wrapped),a=ND(()=>n.centerOfMass(e.wrapped),V.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return eP(e.wrapped,`volume`,o),L(o)}function iP(e){let t=$N(e.wrapped,`surface`);if(t)return L(t);if(tP(e))return nP(`measureSurfaceProps`);let n=P(),r=n.area(e.wrapped),i=ND(()=>n.centerOfMass(e.wrapped),V.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return eP(e.wrapped,`surface`,a),L(a)}function aP(e){let t=$N(e.wrapped,`linear`);if(t)return L(t);if(tP(e))return nP(`measureLinearProps`);let n=P(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return eP(e.wrapped,`linear`,i),L(i)}function oP(e){let t=rP(e);return t.ok?L(t.value.mass):t}function sP(e){let t=iP(e);return t.ok?L(t.value.mass):t}function cP(e){let t=aP(e);return t.ok?L(t.value.mass):t}function lP(e,t){return tP(e)||tP(t)?nP(`measureDistance`):L(P().distance(e.wrapped,t.wrapped).value)}function uP(e,t){if(tP(e)||tP(t))return nP(`measureDistanceProps`);let n=P().distance(e.wrapped,t.wrapped);return L({distance:n.value,point1:n.point1,point2:n.point2})}function dP(e){if(tP(e))return nP(`createDistanceQuery`);let t=P().createDistanceQuery(e.wrapped);return L({distanceTo(e){return tP(e)?nP(`createDistanceQuery.distanceTo`):L(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function fP(e,t,n){if(tP(e))return nP(`measureCurvatureAt`);let r=P().surfaceCurvature(e.wrapped,t,n);return L({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function pP(e){if(tP(e))return nP(`measureCurvatureAtMid`);let t=fk(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=P().surfaceCurvature(e.wrapped,n,r);return L({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function mP(e,t){return e.map(e=>WE(e,t))}function hP(e,t){let n=P(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,W),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=UE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function gP(e){let t=P(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,W),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function _P(e,t,n){let r=P();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function vP(e){let t=VD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=P(),r=GD(e),i=gP(WD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`edge`)){let r=n.hashCode(t,W),o=_P(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.edge,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({edge:o.wrapped,face:e.wrapped})}return t.edgeToFaces=a,a}function yP(e){let t=VD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=P(),r=GD(e),i=gP(qD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`vertex`)){let r=n.hashCode(t,W),o=_P(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.vertex,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({vertex:o.wrapped,face:e.wrapped})}return t.vertexToFaces=a,a}function bP(e,t){let n=P(),r=vP(e),i=n.hashCode(t.wrapped,W),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.edge,t.wrapped))continue;let r=n.hashCode(e.face,W),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return mP(o,`face`)}function xP(e,t){let n=P(),r=yP(e),i=n.hashCode(t.wrapped,W),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.vertex,t.wrapped))continue;let r=n.hashCode(e.face,W),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return mP(o,`face`)}function SP(e){return hP(e.wrapped,`edge`)}function CP(e){return hP(e.wrapped,`vertex`)}function wP(e){return hP(e.wrapped,`wire`)}function TP(e){return hP(e.wrapped,`vertex`)}function EP(e,t){let n=P(),r=vP(e),i=hP(t.wrapped,`edge`),a=[],o=new Map;for(let e of i){let i=n.hashCode(e.wrapped,W),s=r.get(i)??[];for(let e of s){if(n.isSame(e.face,t.wrapped))continue;let r=n.hashCode(e.face,W),i=o.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),a.push(e.face)):(o.set(r,[e.face]),a.push(e.face))}}for(let e of i)e[Symbol.dispose]();return mP(a,`face`)}var DP=new Map;function OP(e,t){let n=P(),r=PT()??``;if(DP.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>UE(e,`edge`));return DP.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;DP.set(r,!1)}}return kP(e,t)}function kP(e,t){let n=P(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,W),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(UE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var AP=new Map;function jP(e,t){let n=P(),r=PT()??``;if(AP.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);AP.set(r,!0);try{return i.map(e=>n.hashCode(e,W))}finally{for(let e of i)n.dispose(e)}}catch(e){if(!l(e))throw e;AP.set(r,!1)}return EP(e,t).map(e=>n.hashCode(e.wrapped,W))}function MP(e,t){let n=0,r=lk(t);if(e.surfaceType!==void 0){if(r===e.surfaceType)n+=1;else return-1/0}if(e.normal!==void 0){let r=gk(t),i=e.normal[0]*r[0]+e.normal[1]*r[1]+e.normal[2]*r[2];if(i<.707)return-1/0;n+=i}if(e.centroid!==void 0){let r=_k(t),i=e.centroid[0]-r[0],a=e.centroid[1]-r[1],o=e.centroid[2]-r[2],s=i*i+a*a+o*o;if(s>100)return-1/0;n-=s/100}if(e.area!==void 0&&e.area>0){let r=sP(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function NP(e){let t=lk(e),n=gk(e),r=_k(e),i=sP(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var PP=.9;function FP(e){if(e[2]>PP)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>PP)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>PP)return`box:right`;if(e[0]<-.9)return`box:left`}function IP(e,t){if(lk(t)!==`PLANE`)return;let n=gk(t)[2];if(n>PP)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function LP(e){return lk(e)===`CYLINDRE`?`cylinder:lateral`:IP(`cylinder`,e)}function RP(e){return lk(e)===`CONE`?`cone:lateral`:IP(`cone`,e)}function zP(e){return lk(e)===`SPHERE`?`sphere:surface`:void 0}var BP={box:e=>FP(gk(e)),cylinder:LP,cone:RP,sphere:zP};function VP(e,t){let n=new Map,r=BP[t],i=P(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=HE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[Gj(e)]),a++}finally{VE(e,o)}}return n}function HP(e,t,n){return{origin:e,role:t,hint:NP(n)}}function UP(e,t){let n=[];for(let r of e){if(t.deleted.has(r))continue;let e=t.modified.get(r),i=e&&e.length>0?e:[r];for(let e of i)n.includes(e)||n.push(e)}return n}function WP(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=UP(t,n);r.length>0&&i.set(e,r)}let a=new Map;for(let[n,r]of e)a.set(n,n===t?i:r);return a}var GP=.1,KP=.5;function qP(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>KP&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>KP?r-a<GP&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-GP).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function JP(e,t,n,r){let i=GD(n),a=r??MP,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(Gj(e)));if(t.length===1){let[e]=t;if(e!==void 0)return{face:e,confidence:`exact`}}else if(t.length===0)return{ref:e,reason:`deleted`};else{let n=qP(e.hint,t,a);if(n.kind===`match`)return{face:n.face,confidence:`geometric-fallback`};if(n.kind===`ambiguous`)return{ref:e,reason:`ambiguous`,candidates:n.candidates}}}let s=qP(e.hint,i,a);return s.kind===`match`?{face:s.face,confidence:`geometric-fallback`}:s.kind===`ambiguous`?{ref:e,reason:`ambiguous`,candidates:s.candidates}:{ref:e,reason:`not-found`}}function YP(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function XP(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=lO(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function ZP(e,t,n){let r=n.get(t);if(!r)return;let i=Gj(e);for(let[e,t]of r)if(t.includes(i))return e}function QP(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:GD(e).filter(e=>i.includes(Gj(e)))}function $P(e){let t=cP(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:XP(TP(e))}}function eF(e){let t=new Set,n=[];for(let r of e){let e=Gj(r);t.has(e)||(t.add(e),n.push(r))}return n}var tF=1e-6;function nF(e,t){if(t.length===void 0&&t.midpoint===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=0;if(t.length!==void 0){let n=cP(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=XP(TP(a));n!==void 0&&(e+=YP(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<tF))return n}function rF(e,t,n,r){let[i,a]=bP(n,t);if(i===void 0||a===void 0)return;let o=ZP(i,e,r),s=ZP(a,e,r);if(o!==void 0&&s!==void 0)return{origin:e,faceRoles:[o,s],hint:$P(t)}}function iF(e,t,n){let[r,i]=e.faceRoles,a=QP(n,e.origin,r,t),o=QP(n,e.origin,i,t);if(a.length===0||o.length===0)return{ref:e,reason:`not-found`};let s=[];for(let e of a)for(let t of o)s.push(...OP(e,t));let c=eF(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=nF(c,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:c}:{edge:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var aF=3,oF=1e-6;function sF(e,t){let n=new Set;for(let r of e)for(let e of CP(r)){let r=Gj(e);n.add(r),t.has(r)||t.set(r,e)}return n}function cF(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function lF(e){let t=new Map,n;for(let r of e){let e=sF(r,t);n=n===void 0?e:cF(n,e)}if(n===void 0)return[];let r=[];for(let e of n){let n=t.get(e);n!==void 0&&r.push(n)}return r}function uF(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=YP(lO(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<oF))return n}function dF(e,t,n,r){let i=xP(n,t);if(i.length<aF)return;let a=new Set;for(let t of i){let n=ZP(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<aF))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:lO(t)}}}function fF(e,t,n){let r=[];for(let i of e.faceRoles){let a=QP(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=lF(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=uF(i,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:i}:{vertex:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var pF=.99,mF=.1,hF=1e-6;function gF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function _F(e,t){return GD(e).filter(e=>gF(gk(e),t)>pF)}function vF(e,t,n){let r=new Set([...t,...n].map(Gj)),i=new Set;for(let n of t)for(let t of jP(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of jP(e,t))r.has(n)||o.has(n)||!i.has(n)||(o.add(n),a.push(n));if(a.length===0)return[];let s=new Map(GD(e).map(e=>[Gj(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function yF(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=YP(_k(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<hF))return n}function bF(e,t,n,r,i){let[a,o]=bP(r,n);if(a===void 0||o===void 0)return;let s=ZP(a,e,i),c=ZP(o,e,i);if(s!==void 0&&c!==void 0)return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:gk(a),normalB:gk(o),edgeMidpoint:XP(TP(n))}}}function xF(e,t,n){let r=QP(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=_F(n,e.hint.normalA));let i=QP(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=_F(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=vF(n,r,i).filter(t=>gF(gk(t),e.hint.normalA)>mF&&gF(gk(t),e.hint.normalB)>mF);if(a.length===1){let[e]=a;if(e!==void 0)return{face:e,confidence:`geometric-fallback`}}if(a.length>1){let t=e.hint.edgeMidpoint&&yF(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function SF(e){return typeof e==`object`&&!!e&&`origin`in e}function CF(e){return SF(e)&&`betweenRoles`in e&&`op`in e}function wF(e){return SF(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function TF(e){return SF(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function EF(e){return SF(e)&&typeof e.role==`string`}function DF(e){return EF(e)||wF(e)||TF(e)||CF(e)}function OF(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function kF(e,t,n){if(CF(e)){let r=xF(e,t,n);return`face`in r?{ok:!0,entity:r.face}:OF(r.reason,r.candidates)}if(wF(e)){let r=iF(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:OF(r.reason,r.candidates)}if(TF(e)){let r=fF(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:OF(r.reason,r.candidates)}let r=JP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:OF(r.reason,r.candidates)}function AF(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,VP(t,e.origin)]]);return n.set(e.origin,i),i}function jF(e,t){return kF(e,AF(e,t,new Map),t)}function MF(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t!==Object.prototype&&t!==null?!1:!(`wrapped`in e)}function NF(e,t){let n=new Map,r=e=>{if(DF(e)){let r=kF(e,AF(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(MF(e)){let t={};for(let[n,i]of Object.entries(e))t[n]=r(i);return t}return e},i={...e};for(let[t,n]of Object.entries(e))i[t]=r(n);return i}function PF(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(Number(e)^crypto.getRandomValues(new Uint8Array(1))[0]&15>>Number(e)/4).toString(16))}function FF(e=[]){let t=e.map(({shape:e,name:t,color:n,alpha:r})=>{let i=n??`#f00`;i.indexOf(`#`)===0&&(i=i.slice(1)),i.length===3&&(i=i.replace(/([0-9a-f])/gi,`$1$1`));let a=parseInt(i.substring(0,2),16),o=parseInt(i.substring(2,4),16),s=parseInt(i.substring(4,6),16),c=Math.round((r??1)*255);return{shape:e.wrapped,name:t??PF(),color:[a,o,s,c]}});return iE(P().createXCAFDocument(t))}function IF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function LF(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function RF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function zF(e){return RF(LF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function BF(e,t){let[n,r,i,a]=e,o=2*(i*t[2]-a*t[1]),s=2*(a*t[0]-r*t[2]),c=2*(r*t[1]-i*t[0]);return[t[0]+n*o+(i*c-a*s),t[1]+n*s+(a*o-r*c),t[2]+n*c+(r*s-i*o)]}function VF(e,t){let n=t/2,r=Math.sin(n),i=RF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function HF(e,t){let n=RF(e),r=RF(t),i=IF(n,r);if(i>=1-1e-9)return[1,0,0,0];if(i<=-1+1e-9)return VF(zF(n),Math.PI);let a=LF(n,r),o=Math.hypot(1+i,a[0],a[1],a[2])||1;return[(1+i)/o,a[0]/o,a[1]/o,a[2]/o]}function UF(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;return[n*o-r*s-i*c-a*l,n*s+r*o+i*l-a*c,n*c-r*l+i*o+a*s,n*l+r*c-i*s+a*o]}function WF(e,t,n,r,i){if(n<1)return R(U(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=FO(t),o=P().linearPattern(e.wrapped,[...a],r,n).map(e=>F(e));try{return MA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function GF(e,t,n,r=360,i=[0,0,0],a){if(n<1)return R(U(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=P().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>F(e));try{return MA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function KF(e,t,n,r,i,a,o,s){if(r<1||i<1)return R(U(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(LO(n))return R(U(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=P(),l=FO(t),u=FO(n);if(typeof c.gridPattern==`function`)return L(F(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=WF(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=WF(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function qF(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=P(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??PF(),color:[a,o,s,Math.round((i??1)*255)]}}),o=i.createXCAFDocument(a);try{let e=i.writeXCAFToSTEP(o,{unit:t,modelUnit:n});return e?L(new Blob([e],{type:`application/STEP`})):R(bD(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function JF(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function YF(e,t){return{...e,children:[...e.children,t]}}function XF(e,t){let n=e.children.findIndex(e=>e.name===t);if(n===-1)return e;let r=[...e.children];return r.splice(n,1),{...e,children:r}}function ZF(e,t){return{...e,...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function QF(e,t){if(e.name===t)return e;for(let n of e.children){let e=QF(n,t);if(e)return e}}function $F(e,t,n=0){t(e,n);for(let r of e.children)$F(r,t,n+1)}function eI(e){let t=1;for(let n of e.children)t+=eI(n);return t}function tI(e){let t=[];return $F(e,e=>{e.shape&&t.push(e.shape)}),t}var nI=Math.PI/180;function rI(e,t,n){return Math.min(n,Math.max(t,e))}function iI(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function aI(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function oI(e){return iI(aI(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function sI(e,t,n,r,i){let a=n.min??r,o=n.max??i,s=Math.min(a,o),c=Math.max(a,o);return{kind:e,axis:iI(t),min:s,max:c,value:rI(n.value??0,s,c)}}function cI(e,t,n,r,i){let a=i[0]??{kind:`rotation`,axis:[0,0,1],min:0,max:0,value:0};return{type:e,parent:t,child:n,axis:{origin:r.origin,direction:iI(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function lI(e,t,n,r={}){return cI(`revolute`,e,t,n,[sI(`rotation`,n.direction,r,-180,180)])}function uI(e,t,n,r={}){return cI(`prismatic`,e,t,n,[sI(`translation`,n.direction,r,0,100)])}function dI(e,t,n,r={}){return cI(`cylindrical`,e,t,n,[sI(`rotation`,n.direction,r.rotation??{},-180,180),sI(`translation`,n.direction,r.translation??{},0,100)])}function fI(e,t,n,r={}){let i=iI(n.direction),a;if(r.uDirection){let e=r.uDirection,t=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],n=[e[0]-t*i[0],e[1]-t*i[1],e[2]-t*i[2]];a=Math.hypot(n[0],n[1],n[2])<1e-9?oI(i):iI(n)}else a=oI(i);let o=iI(aI(i,a));return cI(`planar`,e,t,{origin:n.origin,direction:i},[sI(`translation`,a,r.u??{},-100,100),sI(`translation`,o,r.v??{},-100,100),sI(`rotation`,i,r.rotation??{},-180,180)])}function pI(e,t,n,r={}){return cI(`spherical`,e,t,{origin:n,direction:[0,0,1]},[sI(`rotation`,[1,0,0],r.x??{},-180,180),sI(`rotation`,[0,1,0],r.y??{},-180,180),sI(`rotation`,[0,0,1],r.z??{},-180,180)])}function mI(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:rI(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function hI(e,t){return mI(e,[t])}function gI(e,t,n){if(t.kind===`translation`)return{position:[t.axis[0]*n,t.axis[1]*n,t.axis[2]*n],rotation:[1,0,0,0]};let r=VF(t.axis,n*nI),i=BF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function _I(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=yI;for(let t=0;t<e.dofs.length;t++){let o=e.dofs[t];if(!o)continue;let s=n?n[t]??o.value:t===0?r??o.value:o.value;a=bI(a,gI(i,o,rI(s,o.min,o.max)))}return a}function vI(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var yI={position:[0,0,0],rotation:[1,0,0,0]};function bI(e,t){let n=BF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:UF(e.rotation,t.rotation)}}function xI(e){let t=[];return $F(e,e=>{e.joints&&t.push(...e.joints)}),t}function SI(e,t={}){let n=[],r=new Set;$F(e,e=>{r.add(e.name),e.joints&&n.push(...e.joints)});let i=new Map;for(let e of n)i.set(e.child,e),r.add(e.parent),r.add(e.child);let a=new Map;for(let e of r)i.has(e)||a.set(e,yI);let o=[...n],s=!0;for(;s&&o.length>0;){s=!1;for(let e=o.length-1;e>=0;e--){let n=o[e];if(!n)continue;let r=a.get(n.parent);if(!r||(o.splice(e,1),s=!0,a.has(n.child)))continue;let i=t[n.child]??n.value,c=n.offset?bI(_I(n,i),n.offset):_I(n,i);a.set(n.child,bI(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,yI);return a}function CI(e){return xI(e).reduce((e,t)=>e+t.dofs.length,0)}var wI={position:[0,0,0],rotation:[1,0,0,0]};function TI(e,t){let n=BF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function EI(e){return[e[0],-e[1],-e[2],-e[3]]}function DI(e,t){let[n,r,i,a]=UF(t,EI(e)),o=Math.hypot(n,r,i,a)||1;n/=o,r/=o,i/=o,a/=o,n<0&&(n=-n,r=-r,i=-i,a=-a);let s=Math.hypot(r,i,a);if(s<1e-12)return[0,0,0];let c=2*Math.atan2(s,n)/s;return[r*c,i*c,a*c]}function OI(e,t){let n=[];$F(e,e=>{e.joints&&n.push(...e.joints)});let r=new Map;for(let e of n)r.set(e.child,e);let i=[],a=new Set,o=t;for(;o&&r.has(o)&&!a.has(o);){a.add(o);let e=r.get(o);if(!e)break;i.push(e),o=e.parent}return i.reverse()}function kI(e,t){return e[t]??0}function AI(e,t,n){let r=n+1,i=new Float64Array(n*r);for(let a=0;a<n;a++){for(let t=0;t<n;t++)i[a*r+t]=kI(e,a*n+t);i[a*r+n]=kI(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(kI(i,a*r+e))>Math.abs(kI(i,t*r+e))&&(t=a);if(Math.abs(kI(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=kI(i,e*r+n);i[e*r+n]=kI(i,t*r+n),i[t*r+n]=a}let a=kI(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=kI(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=kI(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=kI(i,t*r+a)-n*kI(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=kI(i,e*r+n);return a}function jI(e,t){let n=[],r=[],i=[],a=[];for(let o of e){let e=t?.[o.child];n.push({child:o.child,count:o.dofs.length}),o.dofs.forEach((t,n)=>{let o=(Array.isArray(e)?e[n]:n===0?e:void 0)??t.value;r.push(Math.min(t.max,Math.max(t.min,o))),i.push(t.min),a.push(t.max)})}return{segments:n,q:Float64Array.from(r),lo:Float64Array.from(i),hi:Float64Array.from(a)}}function MI(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(kI(t,r++));n[i.child]=e}return n}function NI(e,t,n,r,i){let a=TI(t,r);if(e[0]=n.position[0]-a[0],e[1]=n.position[1]-a[1],e[2]=n.position[2]-a[2],i===6&&n.rotation){let r=DI(t.rotation,n.rotation);e[3]=r[0],e[4]=r[1],e[5]=r[2]}let o=0;for(let t=0;t<i;t++)o+=kI(e,t)**2;return Math.sqrt(o)}function PI(e,t,n,r,i,a,o,s,c,l){let u=TI(o,s);for(let d=0;d<n;d++){let f=kI(t,d),p=f+c>kI(a,d)&&f-c>=kI(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=TI(m,s);if(e[d]=(h[0]-u[0])/p,e[n+d]=(h[1]-u[1])/p,e[2*n+d]=(h[2]-u[2])/p,r===6){let t=DI(o.rotation,m.rotation);e[3*n+d]=t[0]/p,e[4*n+d]=t[1]/p,e[5*n+d]=t[2]/p}}}function FI(e,t,n,r,i){let a=new Float64Array(r*r),o=i*i;for(let t=0;t<r;t++)for(let i=0;i<r;i++){let s=0;for(let r=0;r<n;r++)s+=kI(e,t*n+r)*kI(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=AI(a,t,r);if(!s)return null;let c=new Float64Array(n);for(let t=0;t<n;t++){let i=0;for(let a=0;a<r;a++)i+=kI(e,a*n+t)*kI(s,a);c[t]=i}return c}function II(e,t,n,r={}){let i=r.maxIterations??200,a=r.tolerance??1e-5,o=r.damping??.05,s=r.tip??[0,0,0],c=n.rotation===void 0?3:6,{segments:l,q:u,lo:d,hi:f}=jI(OI(e,t),r.seed),p=u.length,m=n=>SI(e,MI(l,n)).get(t)??wI,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=NI(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){PI(g,u,p,c,d,f,_,s,1e-6,m);let e=FI(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=kI(u,t)+kI(e,t);u[t]=Math.min(kI(f,t),Math.max(kI(d,t),n))}_=m(u),v=NI(h,_,n,s,c)}return{values:MI(l,u),converged:v<=a,iterations:y,error:v}}function LI(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function RI(e,t,n,r){let i=[];$F(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:LI(e,t[e.child]),b:LI(e,n[e.child])})),o=Math.max(1,Math.floor(r)),s=[];for(let t=0;t<=o;t++){let n=t/o,r={};for(let e of a)r[e.child]=e.a.map((t,r)=>t+((e.b[r]??t)-t)*n);s.push({t:n,values:r,poses:SI(e,r)})}return s}var zI=Math.PI/180;function BI(e,t,n,r){let i=e*zI,a=r*zI,o=UF(VF([0,0,1],i),VF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function VI(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=BI(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?uI(i,a,s,c):lI(i,a,s,c),offset:o}})}var HI=Math.PI/180,UI=180/Math.PI;function WI(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function GI(e){return String(e===0?0:e)}function KI(e){return`${GI(e[0])} ${GI(e[1])} ${GI(e[2])}`}function qI(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];$F(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return R(U(V.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return R(U(V.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${WI(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${WI(e)}">`,` <visual><geometry><mesh filename="${WI(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${WI(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*HI:e.min,a=t?e.max*HI:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${WI(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${WI(e.parent)}"/>`,` <child link="${WI(e.child)}"/>`,` <origin xyz="${KI(o)}" rpy="0 0 0"/>`,` <axis xyz="${KI(e.axis.direction)}"/>`,` <limit lower="${GI(n)}" upper="${GI(a)}" effort="${GI(r)}" velocity="${GI(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),L(c.join(`
|
|
15
|
+
npm install brepkit-wasm`)}function GT(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}var KT=Symbol;KT.dispose??=Symbol.for(`Symbol.dispose`),KT.asyncDispose??=Symbol.for(`Symbol.asyncDispose`);var qT=globalThis;qT.FinalizationRegistry||=(console.warn(`brepjs: FinalizationRegistry unavailable — garbage collection will not work`),class{register(e,t,n){}unregister(e){return!1}});var JT={liveHandles:0,peakHandles:0,gcCollected:0,scopeEnters:0,scopeExits:0};function YT(){return{...JT}}function XT(){JT.liveHandles=0,JT.peakHandles=0,JT.gcCollected=0,JT.scopeEnters=0,JT.scopeExits=0}function ZT(){JT.liveHandles++,JT.liveHandles>JT.peakHandles&&(JT.peakHandles=JT.liveHandles)}function QT(){JT.liveHandles--}function $T(){JT.gcCollected++,JT.liveHandles--}var eE=new FinalizationRegistry(e=>{$T();try{e.delete()}catch{}});function tE(e){let t=P(),n=!1,r,i=()=>{if(r){for(let e of r)try{e()}catch{}r=void 0}},a=()=>{if(!n){n=!0,QT(),eE.unregister(o),i();try{t.dispose(e)}catch{}}},o={get wrapped(){if(n)throw Error(`Shape handle has been disposed`);return e},get disposed(){return n},[Symbol.dispose](){a()},delete(){a()},onDispose(e){if(n){e();return}(r??=[]).push(e)}};return ZT(),eE.register(o,{delete:()=>{t.dispose(e)}},o),o}function nE(e){let t=()=>{};return{get wrapped(){return e},get disposed(){return!1},[Symbol.dispose]:t,delete:t,onDispose:t}}function rE(e){let t=P(),n;try{n=t.checkpoint()}catch(t){if(!l(t))throw t;return e()}let r;try{r=e()}catch(e){try{t.restoreCheckpoint(n)}catch{}throw e}return t.restoreCheckpoint(n),r}function iE(e){let t=!1,n={get value(){if(t)throw Error(`kernel handle has been disposed`);return e},get disposed(){return t},[Symbol.dispose](){if(!t){t=!0,QT(),eE.unregister(n);try{e.delete()}catch{}}}};return ZT(),eE.register(n,e,n),n}var aE=class{handles=[];constructor(){JT.scopeEnters++}register(e){return this.handles.push(()=>{try{let t=e[Symbol.dispose];typeof t==`function`?t.call(e):e.delete()}catch{}}),e}track(e){return this.handles.push(()=>{try{e[Symbol.dispose]()}catch{}}),e}[Symbol.dispose](){JT.scopeExits++;for(let e=this.handles.length-1;e>=0;e--)this.handles[e]?.();this.handles.length=0}};function oE(e){try{var t=GT();return e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}function sE(e,t){eE.register(e,t,t)}function cE(e){eE.unregister(e)}function lE(e){try{var t=GT();return e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}async function uE(e){try{var t=GT();return await e(t.u(new aE))}catch(e){t.e=e}finally{t.d()}}function dE(e){return!e.disposed}function fE(e){return e.__is2D!==!0}function pE(e){return e.__is2D===!0}function mE(e){if(!fE(e))throw Error(`Expected 3D shape, got 2D`);return e}function hE(e){if(!pE(e))throw Error(`Expected 2D shape, got 3D`);return e}var gE=new WeakMap;function _E(e,t){gE.set(e,t)}function vE(e,t){let n=gE.get(t);if(n!==void 0)return n;let r=e.shapeType(t);return gE.set(t,r),r}function yE(e){return vE(P(),e.wrapped)}function bE(e,t){return t===`2D`&&(e.__is2D=!0),e}function xE(e,t){return bE(tE(e),t)}function SE(e,t){return bE(tE(e),t)}function CE(e,t){return bE(tE(e),t)}function wE(e,t){return bE(tE(e),t)}function TE(e){return bE(tE(e))}function EE(e){return bE(tE(e))}function DE(e){return bE(tE(e))}function OE(e,t){return bE(tE(e),t)}function kE(e){return yE(e)===`vertex`}function AE(e){return yE(e)===`edge`}function jE(e){return yE(e)===`wire`}function ME(e){return yE(e)===`face`}function NE(e){return yE(e)===`shell`}function PE(e){return yE(e)===`solid`}function FE(e){return yE(e)===`compound`}function IE(e){let t=yE(e);return t===`shell`||t===`solid`||t===`compsolid`||t===`compound`&&fE(e)}function LE(e){let t=yE(e);return t===`edge`||t===`wire`}function RE(e,t){let n=P(),r=vE(n,e),i=n.downcast(e,r);return r===`vertex`?xE(i,t):r===`edge`?SE(i,t):r===`wire`?CE(i,t):r===`face`?wE(i,t):r===`shell`?TE(i):r===`solid`?EE(i):r===`compsolid`?DE(i):OE(i,t)}function zE(e){return RE(e)}function BE(e,t){let n=e.id,r=t.wrapped.id;(n!==void 0&&r!==void 0?n===r:t.wrapped===e)||P().dispose(e)}function F(e,t){let n=RE(e,t);return BE(e,n),n}function VE(e,t){let n=e.wrapped;if(e[Symbol.dispose](),n!==t){let e=P();e.dispose(n),e.dispose(t)}}function I(e){P().dispose(e.wrapped),e[Symbol.dispose]()}function HE(e,t,n){_E(e,t);let r=P().downcast(e,t);return t===`vertex`?xE(r,n):t===`edge`?SE(r,n):t===`wire`?CE(r,n):t===`face`?wE(r,n):t===`shell`?TE(r):t===`solid`?EE(r):t===`compsolid`?DE(r):OE(r,n)}function UE(e,t,n){let r=HE(e,t,n);return BE(e,r),r}function WE(e,t,n){return _E(e,t),bE(nE(e),n)}function L(e){return{ok:!0,value:e}}function R(e){return{ok:!1,error:e}}var GE=L(void 0);function KE(e){return e.ok}function z(e){return!e.ok}function qE(e,t){return e.ok?L(t(e.value)):e}function JE(e,t){return e.ok?e:R(t(e.error))}function YE(e,t){return e.ok?t(e.value):e}var XE=YE;function ZE(e,t){return e.ok?e:t}function QE(e,t){return e.ok?e:t(e.error)}function $E(e,t){return e.ok?t.ok?L([e.value,t.value]):t:e}var eD=dD;function tD(e,t){return e.ok&&t(e.value),e}function nD(e,t){return e.ok||t(e.error),e}function rD(e){return e.ok?e.value:e}function iD(e,t,n){return e.ok?L(t(e.value)):R(n(e.error))}function aD(e,t){return e==null?R(t()):L(e)}function oD(e){if(typeof e==`object`&&e&&`kind`in e&&`code`in e&&`message`in e){let t=e;return`[${t.kind}] ${t.code}: ${t.message}`}return String(e)}function B(e){if(e.ok)return e.value;throw Error(`Called unwrap() on an Err: ${oD(e.error)}`)}function sD(e,t){return e.ok?e.value:t}function cD(e,t){return e.ok?e.value:t(e.error)}function lD(e){if(!e.ok)return e.error;throw Error(`Called unwrapErr() on an Ok: ${String(e.value)}`)}function uD(e,t){return e.ok?t.ok(e.value):t.err(e.error)}function dD(e){let t=[];for(let n of e){if(!n.ok)return n;t.push(n.value)}return L(t)}function fD(e,t){try{return L(e())}catch(e){return R(t(e))}}async function pD(e,t){try{return L(await e())}catch(e){return R(t(e))}}function mD(e){function t(e){return typeof e==`object`&&!!e&&`ok`in e&&typeof e.ok==`boolean`}let n=t(e)?e:L(e);function r(e){return{then(t){return e.ok?r(t(e.value)):r(e)},get result(){return e}}}return r(n)}var V={BSPLINE_FAILED:`BSPLINE_FAILED`,FACE_BUILD_FAILED:`FACE_BUILD_FAILED`,SWEEP_FAILED:`SWEEP_FAILED`,LOFT_FAILED:`LOFT_FAILED`,FUSE_FAILED:`FUSE_FAILED`,CUT_FAILED:`CUT_FAILED`,HEAL_NO_EFFECT:`HEAL_NO_EFFECT`,BOOLEAN_HAS_ERRORS:`BOOLEAN_HAS_ERRORS`,VARIABLE_FILLET_FAILED:`VARIABLE_FILLET_FAILED`,POSITION_ON_CURVE_FAILED:`POSITION_ON_CURVE_FAILED`,FIX_SHAPE_FAILED:`FIX_SHAPE_FAILED`,SOLID_FROM_SHELL_FAILED:`SOLID_FROM_SHELL_FAILED`,FIX_SELF_INTERSECTION_FAILED:`FIX_SELF_INTERSECTION_FAILED`,MESH_FAILED:`MESH_FAILED`,ELLIPSE_RADII:`ELLIPSE_RADII`,FUSE_ALL_EMPTY:`FUSE_ALL_EMPTY`,FILLET_NO_EDGES:`FILLET_NO_EDGES`,CHAMFER_NO_EDGES:`CHAMFER_NO_EDGES`,CHAMFER_ANGLE_NO_EDGES:`CHAMFER_ANGLE_NO_EDGES`,CHAMFER_ANGLE_BAD_DISTANCE:`CHAMFER_ANGLE_BAD_DISTANCE`,CHAMFER_ANGLE_BAD_ANGLE:`CHAMFER_ANGLE_BAD_ANGLE`,BEZIER_MIN_POINTS:`BEZIER_MIN_POINTS`,POLYGON_MIN_POINTS:`POLYGON_MIN_POINTS`,ZERO_LENGTH_EXTRUSION:`ZERO_LENGTH_EXTRUSION`,ZERO_TWIST_ANGLE:`ZERO_TWIST_ANGLE`,LOFT_EMPTY:`LOFT_EMPTY`,UNSUPPORTED_PROFILE:`UNSUPPORTED_PROFILE`,UNKNOWN_PLANE:`UNKNOWN_PLANE`,NULL_SHAPE_INPUT:`NULL_SHAPE_INPUT`,INVALID_FILLET_RADIUS:`INVALID_FILLET_RADIUS`,INVALID_CHAMFER_DISTANCE:`INVALID_CHAMFER_DISTANCE`,INVALID_THICKNESS:`INVALID_THICKNESS`,ZERO_OFFSET:`ZERO_OFFSET`,NO_EDGES:`NO_EDGES`,NO_FACES:`NO_FACES`,DRAFT_NO_FACES:`DRAFT_NO_FACES`,DRAFT_INVALID_ANGLE:`DRAFT_INVALID_ANGLE`,DRAFT_NOT_3D:`DRAFT_NOT_3D`,DRAFT_FAILED:`DRAFT_FAILED`,FUSE_NOT_3D:`FUSE_NOT_3D`,CUT_NOT_3D:`CUT_NOT_3D`,INTERSECT_NOT_3D:`INTERSECT_NOT_3D`,FUSE_ALL_NOT_3D:`FUSE_ALL_NOT_3D`,CUT_ALL_NOT_3D:`CUT_ALL_NOT_3D`,LOFT_NOT_3D:`LOFT_NOT_3D`,SWEEP_NOT_3D:`SWEEP_NOT_3D`,REVOLUTION_NOT_3D:`REVOLUTION_NOT_3D`,FILLET_NOT_3D:`FILLET_NOT_3D`,CHAMFER_NOT_3D:`CHAMFER_NOT_3D`,CHAMFER_ANGLE_NOT_3D:`CHAMFER_ANGLE_NOT_3D`,CHAMFER_ANGLE_FAILED:`CHAMFER_ANGLE_FAILED`,CSG_NOT_3D:`CSG_NOT_3D`,SHELL_NOT_3D:`SHELL_NOT_3D`,OFFSET_NOT_3D:`OFFSET_NOT_3D`,NULL_SHAPE:`NULL_SHAPE`,NO_WRAPPER:`NO_WRAPPER`,WELD_NOT_SHELL:`WELD_NOT_SHELL`,SOLID_BUILD_FAILED:`SOLID_BUILD_FAILED`,OFFSET_NOT_WIRE:`OFFSET_NOT_WIRE`,UNKNOWN_SURFACE_TYPE:`UNKNOWN_SURFACE_TYPE`,UNKNOWN_CURVE_TYPE:`UNKNOWN_CURVE_TYPE`,SWEEP_START_NOT_WIRE:`SWEEP_START_NOT_WIRE`,SWEEP_END_NOT_WIRE:`SWEEP_END_NOT_WIRE`,STEP_EXPORT_FAILED:`STEP_EXPORT_FAILED`,STEP_EXPORT_CONFIGURED_FAILED:`STEP_EXPORT_CONFIGURED_FAILED`,STEP_FILE_READ_ERROR:`STEP_FILE_READ_ERROR`,STEP_EXPORT_CRASHED:`STEP_EXPORT_CRASHED`,STEP_EXPORT_UNSERIALIZABLE:`STEP_EXPORT_UNSERIALIZABLE`,STL_EXPORT_FAILED:`STL_EXPORT_FAILED`,STL_FILE_READ_ERROR:`STL_FILE_READ_ERROR`,STL_EXPORT_CRASHED:`STL_EXPORT_CRASHED`,STL_EXPORT_UNSERIALIZABLE:`STL_EXPORT_UNSERIALIZABLE`,STEP_IMPORT_FAILED:`STEP_IMPORT_FAILED`,STL_IMPORT_FAILED:`STL_IMPORT_FAILED`,IGES_EXPORT_FAILED:`IGES_EXPORT_FAILED`,IGES_IMPORT_FAILED:`IGES_IMPORT_FAILED`,DXF_IMPORT_FAILED:`DXF_IMPORT_FAILED`,OBJ_IMPORT_FAILED:`OBJ_IMPORT_FAILED`,THREEMF_IMPORT_FAILED:`THREEMF_IMPORT_FAILED`,PARAMETER_NOT_FOUND:`PARAMETER_NOT_FOUND`,INTERSECTION_FAILED:`INTERSECTION_FAILED`,SELF_INTERSECTION_FAILED:`SELF_INTERSECTION_FAILED`,STRAIGHT_SKELETON_FAILED:`STRAIGHT_SKELETON_FAILED`,CENTER_OF_MASS_FAILED:`CENTER_OF_MASS_FAILED`,COMPOUND_NO_FACES:`COMPOUND_NO_FACES`,COMPOUND_FACE_NOT_FOUND:`COMPOUND_FACE_NOT_FOUND`,FINDER_NOT_UNIQUE:`FINDER_NOT_UNIQUE`,HULL_EMPTY_INPUT:`HULL_EMPTY_INPUT`,HULL_FAILED:`HULL_FAILED`,HULL_DEGENERATE:`HULL_DEGENERATE`,HULL_NOT_3D:`HULL_NOT_3D`,MINKOWSKI_FAILED:`MINKOWSKI_FAILED`,MINKOWSKI_NULL_TOOL:`MINKOWSKI_NULL_TOOL`,MINKOWSKI_NOT_3D:`MINKOWSKI_NOT_3D`,POLYHEDRON_INSUFFICIENT_POINTS:`POLYHEDRON_INSUFFICIENT_POINTS`,POLYHEDRON_INSUFFICIENT_FACES:`POLYHEDRON_INSUFFICIENT_FACES`,POLYHEDRON_INVALID_INDEX:`POLYHEDRON_INVALID_INDEX`,POLYHEDRON_FAILED:`POLYHEDRON_FAILED`,VALIDATION_FAILED:`VALIDATION_FAILED`,ROOF_FAILED:`ROOF_FAILED`,MULTI_SWEEP_INSUFFICIENT_SECTIONS:`MULTI_SWEEP_INSUFFICIENT_SECTIONS`,MULTI_SWEEP_FAILED:`MULTI_SWEEP_FAILED`,GUIDED_SWEEP_FAILED:`GUIDED_SWEEP_FAILED`,SURFACE_GRID_TOO_SMALL:`SURFACE_GRID_TOO_SMALL`,SURFACE_GRID_JAGGED:`SURFACE_GRID_JAGGED`,SURFACE_FAILED:`SURFACE_FAILED`,ASSEMBLY_MATE_INVALID:`ASSEMBLY_MATE_INVALID`,ASSEMBLY_SOLVE_FAILED:`ASSEMBLY_SOLVE_FAILED`,ASSEMBLY_NOT_CONVERGED:`ASSEMBLY_NOT_CONVERGED`,BLUEPRINT_EMPTY_CURVES:`BLUEPRINT_EMPTY_CURVES`,COMPOUND_BLUEPRINT_EMPTY:`COMPOUND_BLUEPRINT_EMPTY`,GLB_IMPORT_FAILED:`GLB_IMPORT_FAILED`,FONT_FETCH_FAILED:`FONT_FETCH_FAILED`,FONT_PARSE_FAILED:`FONT_PARSE_FAILED`,NO_FONT_LOADED:`NO_FONT_LOADED`,CURVE2D_CONSTRUCTION_FAILED:`CURVE2D_CONSTRUCTION_FAILED`,CURVE2D_INVALID_RADIUS:`CURVE2D_INVALID_RADIUS`,CURVE2D_TRANSFORM_FAILED:`CURVE2D_TRANSFORM_FAILED`,CURVE2D_QUERY_FAILED:`CURVE2D_QUERY_FAILED`,CURVE2D_INTERSECTION_FAILED:`CURVE2D_INTERSECTION_FAILED`,CURVE2D_BRIDGE_FAILED:`CURVE2D_BRIDGE_FAILED`,CLONE_FAILED:`CLONE_FAILED`,SIMPLIFY_FAILED:`SIMPLIFY_FAILED`,TO_BREP_FAILED:`TO_BREP_FAILED`,UNSUPPORTED_CAPABILITY:`UNSUPPORTED_CAPABILITY`};function hD(e,t,n,r,i,a){let o={kind:e,code:t,message:n,cause:r};if(a){let e={...o,suggestion:a};return i?{...e,metadata:i}:e}return i?{...o,metadata:i}:o}function H(e,t,n,r,i){return hD(`KERNEL_OPERATION`,e,t,n,r,i)}function U(e,t,n,r,i){return hD(`VALIDATION`,e,t,n,r,i)}function gD(e,t,n,r,i){return hD(`TYPE_CAST`,e,t,n,r,i)}function _D(e,t,n,r,i){return hD(`SKETCHER_STATE`,e,t,n,r,i)}function vD(e,t,n,r,i){return hD(`MODULE_INIT`,e,t,n,r,i)}function yD(e,t,n,r,i){return hD(`COMPUTATION`,e,t,n,r,i)}function bD(e,t,n,r,i){return hD(`IO`,e,t,n,r,i)}function xD(e,t,n,r,i){return hD(`QUERY`,e,t,n,r,i)}function SD(e,t,n,r,i){return hD(`UNSUPPORTED`,e,t,n,r,i)}function CD(e,n,r){return(n<0||n>=e.length)&&i(r??`safeIndex`,`Index ${n} is out of bounds (array length ${e.length})`),t(e,n)}var W=2147483647,wD=Math.PI/180,TD=180/Math.PI,ED=[{pattern:/invalid edge configuration|edges?.*(not|fail|invalid)/i,translation:`The edges may not form a continuous loop. Check that edges connect end-to-end without gaps.`},{pattern:/BRepAlgoAPI.*failed|boolean.*operation.*failed/i,translation:`Boolean operation failed. Common causes: overlapping faces, zero-thickness geometry, or degenerate shapes. Try healing input shapes first.`},{pattern:/fillet.*radius.*too.*large|fillet.*failed/i,translation:`Fillet operation failed. The radius may be too large for the selected edges. Try reducing the radius or check that edges have enough room.`},{pattern:/chamfer.*failed|chamfer.*distance.*too.*large/i,translation:`Chamfer operation failed. The distance may be too large for the selected edges. Try reducing the distance or check edge geometry.`},{pattern:/shell.*failed|offset.*failed/i,translation:`Shell/offset operation failed. The thickness may be too large, or the shape may have complex geometry. Try reducing thickness.`},{pattern:/sweep.*failed|pipe.*failed/i,translation:`Sweep operation failed. Check that the profile and spine are compatible, and that the spine has no sharp twists or self-intersections.`},{pattern:/loft.*failed/i,translation:`Loft operation failed. Profiles may be incompatible or have different orientations. Ensure profiles are ordered consistently.`},{pattern:/extrude.*failed|prism.*failed/i,translation:`Extrusion failed. The profile may be invalid or self-intersecting. Check that the profile forms a valid closed wire.`},{pattern:/revolve.*failed|revolution.*failed/i,translation:`Revolution operation failed. The profile may intersect the axis of revolution, or the angle may be invalid.`},{pattern:/self.*intersect|self-intersect/i,translation:`Shape has self-intersections. The operation resulted in overlapping geometry. Simplify the input or adjust parameters.`},{pattern:/degener|degenerat/i,translation:`Degenerate geometry detected. The shape has edges or faces with zero length/area. Check input geometry for collapsed elements.`},{pattern:/BRepCheck.*fail|shape.*invalid|shape.*not.*valid/i,translation:`Shape validation failed. The resulting shape has invalid topology. Try healing the shape or checking input geometry.`}],DD={FUSE_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,CUT_FAILED:`Try autoHeal() on both operands before the boolean operation. Check for overlapping faces or zero-thickness geometry.`,FUSE_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,CUT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,INTERSECT_NOT_3D:`The boolean result was not a 3D solid. Ensure both input shapes are valid 3D solids, not shells or open surfaces.`,SWEEP_FAILED:`Ensure the spine curve has no sharp corners or self-intersections. Try simplifying the profile or using a smoother path.`,LOFT_FAILED:`Check that all profiles have the same number of edges and consistent orientation. Try reordering profiles.`,FILLET_NOT_3D:`The fillet radius may be too large for the selected edges. Try a smaller radius or check that adjacent faces have enough room.`,CHAMFER_NOT_3D:`The chamfer distance may be too large. Try a smaller distance or check edge geometry.`,SHELL_NOT_3D:`The shell thickness may be too large for the shape. Try reducing thickness or removing problematic faces.`,OFFSET_NOT_3D:`The offset distance may be too large for the shape geometry. Try a smaller distance.`,DRAFT_FAILED:`The draft angle may be too large or the selected faces incompatible. Try a smaller angle or different faces.`};function OD(e){return DD[e]}function kD(e){for(let{pattern:t,translation:n}of ED)if(t.test(e))return`${n} (kernel: ${e})`;return e}function AD(e,t,n,r,i){let a={kind:e,code:t,message:n,cause:r};return i?{...a,suggestion:i}:a}var jD={KERNEL_OPERATION:(e,t,n,r)=>AD(`KERNEL_OPERATION`,e,t,n,r),VALIDATION:(e,t,n,r)=>AD(`VALIDATION`,e,t,n,r),TYPE_CAST:(e,t,n,r)=>AD(`TYPE_CAST`,e,t,n,r),SKETCHER_STATE:(e,t,n,r)=>AD(`SKETCHER_STATE`,e,t,n,r),MODULE_INIT:(e,t,n,r)=>AD(`MODULE_INIT`,e,t,n,r),COMPUTATION:(e,t,n,r)=>AD(`COMPUTATION`,e,t,n,r),IO:(e,t,n,r)=>AD(`IO`,e,t,n,r),QUERY:(e,t,n,r)=>AD(`QUERY`,e,t,n,r),UNSUPPORTED:(e,t,n,r)=>AD(`UNSUPPORTED`,e,t,n,r)};function MD(e,t,n,r=`KERNEL_OPERATION`){try{return L(F(e()))}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?kD(i):i,o=OD(t);return R(jD[r](t,`${n}: ${a}`,e,o))}}function ND(e,t,n,r=`KERNEL_OPERATION`){try{return L(e())}catch(e){let i=e instanceof Error?e.message:String(e),a=r===`KERNEL_OPERATION`?kD(i):i,o=OD(t);return R(jD[r](t,`${n}: ${a}`,e,o))}}function PD(e,t,n,r=`KERNEL_OPERATION`){try{var i=GT();let a=i.u(new aE);return MD(()=>e(a),t,n,r)}catch(e){i.e=e}finally{i.d()}}function FD(e,t){let n=P().iterShapes(e,t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=UE(n[e],t);return r}function ID(e,t){let n=P();if(n.subShapeCount)return n.subShapeCount(e.wrapped,t);let r=n.iterShapes(e.wrapped,t);for(let e of r)n.dispose(e);return r.length}function LD(e,t){let n=P();if(n.subShapeHashes)return n.subShapeHashes(e.wrapped,t,W);let r=new Set;for(let i of n.iterShapes(e.wrapped,t))r.add(n.hashCode(i,W)),n.dispose(i);return[...r]}var RD=new WeakMap;function zD(e){let t=RD.get(e);if(!t)return;RD.delete(e);let n=[t.edges,t.faces,t.wires,t.vertices,t.shells,t.solids,t.compSolids];for(let e of n)if(e)for(let t of e)t[Symbol.dispose]()}var BD=new WeakSet;function VD(e){let t=e.wrapped,n=RD.get(t);return n||(n={},RD.set(t,n)),BD.has(e)||(BD.add(e),e.onDispose(()=>{zD(t)})),n}function HD(e){return RD.get(e.wrapped)}function UD(e){zD(e.wrapped)}function WD(e){let t=VD(e);if(t.edges)return t.edges;let n=FD(e.wrapped,`edge`);return t.edges=n,n}function GD(e){let t=VD(e);if(t.faces)return t.faces;let n=FD(e.wrapped,`face`);return t.faces=n,n}function KD(e){let t=VD(e);if(t.wires)return t.wires;let n=FD(e.wrapped,`wire`);return t.wires=n,n}function qD(e){let t=VD(e);if(t.vertices)return t.vertices;let n=FD(e.wrapped,`vertex`);return t.vertices=n,n}function JD(e){let t=VD(e);if(t.solids)return t.solids;let n=FD(e.wrapped,`solid`);return t.solids=n,n}function YD(e){let t=VD(e);if(t.shells)return t.shells;let n=FD(e.wrapped,`shell`);return t.shells=n,n}function XD(e){let t=VD(e);if(t.compSolids)return t.compSolids;let n=FD(e.wrapped,`compsolid`);return t.compSolids=n,n}function*ZD(e){for(let t of P().iterShapes(e.wrapped,`edge`))yield UE(t,`edge`)}function*QD(e){for(let t of P().iterShapes(e.wrapped,`face`))yield UE(t,`face`)}function*$D(e){for(let t of P().iterShapes(e.wrapped,`wire`))yield UE(t,`wire`)}function*eO(e){for(let t of P().iterShapes(e.wrapped,`vertex`))yield UE(t,`vertex`)}function*tO(e){for(let t of P().iterShapes(e.wrapped,`solid`))yield UE(t,`solid`)}function*nO(e){for(let t of P().iterShapes(e.wrapped,`shell`))yield UE(t,`shell`)}function*rO(e){for(let t of P().iterShapes(e.wrapped,`compsolid`))yield UE(t,`compsolid`)}function iO(e){let t=VD(e);if(t.bounds)return t.bounds;let{min:n,max:r}=P().boundingBox(e.wrapped),i={xMin:n[0],xMax:r[0],yMin:n[1],yMax:r[1],zMin:n[2],zMax:r[2]};return t.bounds=i,i}function aO(e){return vE(P(),e.wrapped)}function oO(e){let t=VD(e);if(t.surfaceType!==void 0)return t.surfaceType;let n=P().surfaceType(e.wrapped);return t.surfaceType=n,n}function sO(e){let t=VD(e);if(t.isValid!==void 0)return t.isValid;let n=P().isValid(e.wrapped);return t.isValid=n,n}function cO(e){return{kind:aO(e),faceCount:ID(e,`face`),edgeCount:ID(e,`edge`),wireCount:ID(e,`wire`),vertexCount:ID(e,`vertex`),valid:sO(e),bounds:iO(e)}}function lO(e){return P().vertexPosition(e.wrapped)}function uO(e){return P().curveIsClosed(e.wrapped)}function dO(e){return P().isValid(e.wrapped)}function fO(e){let t=P();if(!t.isValid(e.wrapped))return!1;let n=t.isValidStrict?.bind(t)??t.isValid.bind(t);try{let r=t.solidFromShell(e.wrapped),i=n(r);try{t.dispose(r)}catch{}return i}catch{return!1}}function pO(e){return P().isValid(e.wrapped)}function mO(e){return uO(e)?L(e):R(`Wire is not closed: start and end points do not coincide`)}function hO(e){return dO(e)?L(e):R(`Face orientation is inconsistent or face is invalid`)}function gO(e){return fO(e)?L(e):R(`Shell is not manifold: has free edges or is invalid`)}function _O(e){return pO(e)?L(e):R(`Solid failed BRepCheck validation`)}function vO(e){return P().surfaceType(e.wrapped)===`plane`}function yO(e){let t=P(),n=n=>{try{let r=t.makeFace(e.wrapped,n),i=t.surfaceType(r);try{t.dispose(r)}catch{}return i===`plane`}catch{return!1}};return n(!0)?!0:n(!1)}function bO(e){return vO(e)?L(e):R(`Face is not planar: underlying surface is not a geometric plane`)}function xO(e){return yO(e)?L(e):R(`Wire is not planar: edges do not lie in a common plane`)}function SO(e){return e.length===2?[e[0],e[1],0]:[e[0],e[1],e[2]]}function CO(e){return[e[0],e[1]]}var wO={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function TO(e){if(typeof e==`string`){let t=wO[e];if(!t)throw Error(`Unknown direction: ${e}`);return t}return e}function EO(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function DO(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function OO(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function kO(e){return[-e[0],-e[1],-e[2]]}function AO(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function jO(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function MO(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function NO(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function PO(e,t){return MO(DO(e,t))}function FO(e){let t=MO(e);return t<1e-10?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function IO(e,t,n=1e-5){return Math.abs(e[0]-t[0])<n&&Math.abs(e[1]-t[1])<n&&Math.abs(e[2]-t[2])<n}function LO(e,t=1e-10){return NO(e)<t*t}function RO(e,t){let n=AO(e,t),r=MO(e),i=MO(t);if(r<1e-10||i<1e-10)return 0;let a=Math.max(-1,Math.min(1,n/(r*i)));return Math.acos(a)}function zO(e,t,n){let r=DO(e,t),i=NO(n);return i<1e-20?e:DO(e,OO(n,AO(r,n)/i))}function BO(e,t,n){let r=FO(t),i=Math.cos(n),a=Math.sin(n),o=AO(e,r),s=jO(r,e);return[e[0]*i+s[0]*a+r[0]*o*(1-i),e[1]*i+s[1]*a+r[1]*o*(1-i),e[2]*i+s[2]*a+r[2]*o*(1-i)]}var VO=e=>Math.round(e*1e3)/1e3;function HO(e){return`x: ${VO(e[0])}, y: ${VO(e[1])}, z: ${VO(e[2])}`}function UO(e,t=null,n=[0,0,1]){let r=FO(n);if(LO(r))throw Error(`Plane normal must be non-zero`);let i;if(t)i=FO(t);else{let[e,t,n]=r,a=Math.abs(e),o=Math.abs(t),s=Math.abs(n),c;c=a<=o&&a<=s?[1,0,0]:o<=s?[0,1,0]:[0,0,1];let l=c[1]*n-c[2]*t,u=c[2]*e-c[0]*n,d=c[0]*t-c[1]*e;i=Math.sqrt(l*l+u*u+d*d)>1e-12?FO([l,u,d]):[1,0,0]}if(LO(i))throw Error(`Plane xDir must be non-zero`);let a=FO(jO(r,i));return{origin:e,xDir:i,yDir:a,zDir:r}}var WO={XY:{xDir:[1,0,0],normal:[0,0,1]},YZ:{xDir:[0,1,0],normal:[1,0,0]},ZX:{xDir:[0,0,1],normal:[0,1,0]},XZ:{xDir:[1,0,0],normal:[0,-1,0]},YX:{xDir:[0,1,0],normal:[0,0,-1]},ZY:{xDir:[0,0,1],normal:[-1,0,0]},front:{xDir:[1,0,0],normal:[0,0,1]},back:{xDir:[-1,0,0],normal:[0,0,-1]},left:{xDir:[0,0,1],normal:[-1,0,0]},right:{xDir:[0,0,-1],normal:[1,0,0]},top:{xDir:[1,0,0],normal:[0,1,0]},bottom:{xDir:[1,0,0],normal:[0,-1,0]}};function GO(e,t=[0,0,0]){let n=WO[e];if(!n)return R(U(`UNKNOWN_PLANE`,`Could not find plane ${e}`));let r;return r=typeof t==`number`?OO(n.normal,t):SO(t),L(UO(r,n.xDir,n.normal))}function KO(e,t){return typeof e==`string`?GO(e,t):L(e)}function qO(e,t){return e&&typeof e!=`string`?{...e}:B(KO(e??`XY`,t))}function JO(e,t){let[n,r]=t;return EO(EO(e.origin,OO(e.xDir,n)),OO(e.yDir,r))}function YO(e,t){return{...e,origin:EO(e.origin,t)}}function XO(e,t,n=[1,0,0]){let r=t*wD,i=BO(e.zDir,n,r),a=BO(e.xDir,n,r),o=FO(jO(i,a));return{origin:e.origin,xDir:a,yDir:o,zDir:i}}var ZO={compound:0,solidCompound:1,solid:2,shell:3,face:4,wire:5,edge:6,vertex:7,shape:8},QO=e=>ZO[e],$O={vertex:`vertex`,edge:`edge`,wire:`wire`,face:`face`,shell:`shell`,solid:`solid`,solidCompound:`compsolid`,compound:`compound`,shape:`compound`},ek=function*(e,t){let n=P().iterShapes(e,$O[t]);for(let e of n)yield e},tk=e=>P().isNull(e)?R(gD(`NULL_SHAPE`,`This shape has no type, it is null`)):L(e.ShapeType());function nk(e){if(P().isNull(e))return R(gD(`NULL_SHAPE`,`This shape has no type, it is null`));try{return L(P().downcast(e))}catch(e){return R(gD(`NO_WRAPPER`,`Could not find a wrapper for this shape type`,e))}}function rk(e){if(P().isNull(e))return R(gD(`NULL_SHAPE`,`Cannot copy a null shape`));try{return L(P().copyShape(e))}catch(e){return R(gD(`NO_WRAPPER`,`Could not copy this shape`,e))}}function ik(e){return P().isNull(e)?R(gD(`NULL_SHAPE`,`Cannot cast a null shape`)):L(RE(e))}function ak(e){return P().shapeType(e.wrapped)===`compsolid`}function ok(e){return ik(P().fromBREP(e))}var sk={plane:`PLANE`,cylinder:`CYLINDRE`,cone:`CONE`,sphere:`SPHERE`,torus:`TORUS`,bezier:`BEZIER_SURFACE`,bspline:`BSPLINE_SURFACE`,revolution:`REVOLUTION_SURFACE`,extrusion:`EXTRUSION_SURFACE`,offset:`OFFSET_SURFACE`,other:`OTHER_SURFACE`};function ck(e){return L(sk[oO(e)])}function lk(e){return B(ck(e))}function uk(e){return P().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function dk(e){return RE(P().reverseShape(e.wrapped))}function fk(e){return P().uvBounds(e.wrapped)}function pk(e,t,n){let r=fk(e),i=t*(r.uMax-r.uMin)+r.uMin,a=n*(r.vMax-r.vMin)+r.vMin;return P().pointOnSurface(e.wrapped,i,a)}function mk(e,t){let n=SO(t);return P().uvFromPoint(e.wrapped,n)||[0,0]}function hk(e,t){let n=SO(t);try{let t=n,r=P().uvFromPoint(e.wrapped,t);if(!r)return R(gD(`PROJECTION_FAILED`,`No projection found on the face`));let i=P().projectPointOnFace(e.wrapped,t),a=n[0]-i[0],o=n[1]-i[1],s=n[2]-i[2];return L({uv:r,point:i,distance:Math.sqrt(a*a+o*o+s*s)})}catch(e){return R(gD(`PROJECTION_FAILED`,`Point projection failed: ${e instanceof Error?e.message:String(e)}`))}}function gk(e,t){let n,r;if(t)[n,r]=mk(e,t);else{let t=fk(e);n=.5*(t.uMin+t.uMax),r=.5*(t.vMin+t.vMax)}return P().surfaceNormal(e.wrapped,n,r)}function _k(e){return P().surfaceCenterOfMass(e.wrapped)}function vk(e){return P().getSurfaceAxis(e.wrapped)}function yk(e,t,n=1e-6){let[r,i]=mk(e,t);return P().classifyPointOnFace(e.wrapped,r,i,n)}function bk(e){return RE(P().outerWire(e.wrapped))}function xk(e){return RE(P().removeHolesFromFace(e.wrapped))}function Sk(e){let t=bk(e);return Array.from(ek(e.wrapped,`wire`)).map(e=>RE(B(nk(e)))).filter(e=>!P().isSame(e.wrapped,t.wrapped))}function Ck(e,t){let n=VD(e),r=new Map;for(let n of LD(e,`face`))r.set(n,t);n.faceOrigins=r}function wk(e){return HD(e)?.faceOrigins}function Tk(e,t,n){let r=new Map;for(let e of t){let t=wk(e);if(t)for(let[e,n]of t)r.set(e,n)}if(r.size===0)return;let i=new Map;for(let[t,n]of r){if(e.deleted.has(t))continue;let r=e.modified.get(t);if(r&&r.length>0)for(let e of r)i.set(e,n);else i.set(t,n);let a=e.generated.get(t);if(a)for(let e of a)i.has(e)||i.set(e,n)}if(i.size>0){let e=VD(n);e.faceOrigins=i}}var Ek=100,Dk=.985,Ok=.1;function kk(e,t,n,r){let i=-1/0,a;for(let n of r){let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(r<.707)continue;let o=t[0]-n.centroid[0],s=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=o*o+s*s+c*c;if(l>Ek)continue;let u=r-l/Ek;u>i&&(i=u,a=n.origin)}if(a!==void 0)return a;if(!n)return;let o=1/0,s;for(let n of r){if(!n.planar)continue;let r=e[0]*n.normal[0]+e[1]*n.normal[1]+e[2]*n.normal[2];if(Math.abs(r)<Dk)continue;let i=t[0]-n.centroid[0],a=t[1]-n.centroid[1],c=t[2]-n.centroid[2],l=i*n.normal[0]+a*n.normal[1]+c*n.normal[2];if(l*l>Ok)continue;let u=Math.max(0,i*i+a*a+c*c-l*l);u<o&&(o=u,s=n.origin)}return s}function Ak(e,t){let n=new Map;for(let t of e){let e=wk(t);if(e)for(let[t,r]of e)n.set(t,r)}if(n.size===0)return;let r=P(),i=new Map,a=GD(t),o=[];for(let e of a){let t=r.hashCode(e.wrapped,W),a=n.get(t);a===void 0?o.push(e):i.set(t,a)}if(o.length>0){let t=[];for(let n of e){let e=wk(n);if(e)for(let i of GD(n)){let n=r.hashCode(i.wrapped,W),a=e.get(n);if(a!==void 0)try{let e=r.uvBounds(i.wrapped),n=r.surfaceNormal(i.wrapped,.5*(e.uMin+e.uMax),.5*(e.vMin+e.vMax)),o=r.surfaceCenterOfMass(i.wrapped),s=r.surfaceType(i.wrapped)===`plane`;t.push({origin:a,normal:n,centroid:o,planar:s})}catch{}}}if(t.length>0)for(let e of o){let n=r.hashCode(e.wrapped,W);try{let a=r.uvBounds(e.wrapped),o=kk(r.surfaceNormal(e.wrapped,.5*(a.uMin+a.uMax),.5*(a.vMin+a.vMax)),r.surfaceCenterOfMass(e.wrapped),r.surfaceType(e.wrapped)===`plane`,t);o!==void 0&&i.set(n,o)}catch{}}}if(i.size>0){let e=VD(t);e.faceOrigins=i}}function jk(e,t,n){if(t<0||t>=e.length)throw Error(n??`Index ${t} out of bounds (length ${e.length})`);return e[t]}function Mk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[0]}function Nk(e,t){if(e.length===0)throw Error(t??`Expected non-empty array`);return e[e.length-1]}function Pk(e){return Array.from(Array(e).keys())}function Fk(e){return Pk(Math.min(...e.map(e=>e.length))).map(t=>e.map(e=>e[t]))}function Ik(e,t){return SE(P().makeLineEdge([...e],[...t]))}function Lk(e,t=[0,0,0],n=[0,0,1]){return SE(P().makeCircleEdge([...t],[...n],e))}function Rk(e,t,n=[0,0,0],r=[0,0,1],i){return t>e?R(U(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):L(SE(P().makeEllipseEdge([...n],[...r],e,t,i?[...i]:void 0)))}function zk(e,t,n,r=[0,0,0],i=[0,0,1],a=!1){return CE(P().makeHelixWire(e,t,n,[...r],[...i],a))}function Bk(e,t,n){return SE(P().makeArcEdge([...e],[...t],[...n]))}function Vk(e,t,n,r,i=[0,0,0],a=[0,0,1],o){return t>e?R(U(`ELLIPSE_RADII`,`The minor radius must be smaller than the major one`)):L(SE(P().makeEllipseArc([...i],[...a],e,t,n,r,o?[...o]:void 0)))}function Hk(e,{tolerance:t=.001,smoothing:n=null,degMax:r=6,degMin:i=1}={}){try{let a=e.map(e=>[...e]);return L(SE(P().approximatePoints(a,{tolerance:t,degMin:i,degMax:r,smoothing:n})))}catch(e){return R(H(`BSPLINE_FAILED`,`B-spline approximation failed`,e))}}function Uk(e,{periodic:t=!1,tolerance:n=1e-7}={}){try{let r=e.map(e=>[...e]);return L(SE(P().interpolatePoints(r,{periodic:t,tolerance:n})))}catch(e){return R(H(`BSPLINE_INTERP_FAILED`,`B-spline interpolation failed`,e))}}function Wk(e){if(e.length<2)return R(U(`BEZIER_MIN_POINTS`,`Need at least 2 points for a Bezier curve, got ${e.length}`,void 0,{pointCount:e.length}));let t=e.map(e=>[...e]);return L(SE(P().makeBezierEdge(t)))}function Gk(e,t,n){return SE(P().makeTangentArc([...e],[...t],[...n]))}function Kk(e){try{return L(CE(P().makeWireFromMixed(e.map(e=>e.wrapped))))}catch(e){return R(H(`WIRE_BUILD_FAILED`,`Failed to build the wire: ${e instanceof Error?e.message:`unknown error`}`))}}function qk(e,t){try{let n=P().makeFace(e.wrapped,!0);if(t&&t.length>0){let e=Zk(wE(n),t);return vO(e)?L(e):R(U(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}let r=wE(n);return vO(r)?L(r):R(U(`FACE_NOT_PLANAR`,`makeFace produced a non-planar face — wire may not be truly planar`))}catch(e){return R(H(`FACE_BUILD_FAILED`,`Failed to build the face. Your wire might be non planar.`,e))}}function Jk(e){return qk(bk(e))}function Yk(e,t){return wE(P().makeFaceOnSurface(e.wrapped,t.wrapped))}function Xk(e){try{return YE(ik(P().makeNonPlanarFace(e.wrapped)),e=>ME(e)?L(e):R(H(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`)))}catch(e){return R(H(`FACE_BUILD_FAILED`,`Failed to create a non-planar face`,e))}}function Zk(e,t){return wE(P().addHolesInFace(e.wrapped,t.map(e=>e.wrapped)))}function Qk(e){try{var t=GT();if(e.length<3)return R(U(`POLYGON_MIN_POINTS`,`You need at least 3 points to make a polygon`));let n=[...e.slice(1),e[0]],r=t.u(new aE);return YE(Kk(Fk([e,n]).map(([e,t])=>r.register(Ik(e,t)))),e=>qk(r.register(e)))}catch(e){t.e=e}finally{t.d()}}var $k=new WeakMap,eA=new WeakMap;function tA(e){return $k.has(e.wrapped)}function nA(e){let t=$k.get(e.wrapped);return t||(t=new Map,$k.set(e.wrapped,t)),t}function rA(e){let t=eA.get(e.wrapped);return t||(t=new Map,eA.set(e.wrapped,t)),t}function iA(e,t,n){let r=Array.isArray(t)?t:GD(e).filter(t),i=nA(e),a=i.get(n)??new Set;for(let e of r)a.add(P().hashCode(e.wrapped,W));return i.set(n,a),e}function aA(e,t){let n=$k.get(e.wrapped);if(!n)return[];let r=n.get(t);if(!r||r.size===0)return[];let i=[];for(let t of GD(e)){let e=P().hashCode(t.wrapped,W);r.has(e)&&i.push(t)}return i}function oA(e){let t=new Map,n=$k.get(e.wrapped);if(!n)return t;let r=GD(e),i=new Map;for(let e of r)i.set(P().hashCode(e.wrapped,W),e);for(let[e,r]of n){let n=[];for(let e of r){let t=i.get(e);t&&n.push(t)}n.length>0&&t.set(e,n)}return t}function sA(e,t,n){return rA(e).set(t,n),e}function cA(e,t){return eA.get(e.wrapped)?.get(t)}function lA(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function uA(e,t,n){let r=nA(n);for(let i of t){let t=$k.get(i.wrapped);if(!t)continue;let a=new Map;for(let[e,n]of t)for(let t of n){let n=a.get(t)??[];n.push(e),a.set(t,n)}for(let[t,n]of a){if(e.deleted.has(t))continue;let i=e.modified.get(t),a=i&&i.length>0?i:[t];for(let e of a)for(let t of n)lA(r,t,e)}let o=eA.get(i.wrapped);if(o){let e=rA(n);for(let[t,n]of o)e.has(t)||e.set(t,n)}}}var dA=new WeakMap,fA=new WeakMap;function pA(e){return dA.has(e.wrapped)||fA.has(e.wrapped)}function mA(e){let t=fA.get(e.wrapped);return t||(t=new Map,fA.set(e.wrapped,t)),t}function hA(e){if(typeof e==`string`){let t=e.startsWith(`#`)?e.slice(1):e;return t.length===3&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2)),[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}return e.length===3?[e[0],e[1],e[2],1]:[e[0],e[1],e[2],e[3]]}function gA(e,t){return dA.set(e.wrapped,hA(t)),e}function _A(e,t,n){let r=hA(n),i=mA(e);for(let e of t)i.set(P().hashCode(e.wrapped,W),r);return e}function vA(e){return dA.get(e.wrapped)}function yA(e,t){let n=fA.get(e.wrapped);if(n)return n.get(P().hashCode(t.wrapped,W))}function bA(e,t,n){for(let e of t){let t=dA.get(e.wrapped);if(t){dA.set(n.wrapped,t);break}}let r=mA(n);for(let n of t){let t=fA.get(n.wrapped);if(!(!t||t.size===0))for(let[n,i]of t){if(e.deleted.has(n))continue;let t=e.modified.get(n);if(t&&t.length>0)for(let e of t)r.set(e,i);else r.set(n,i)}}}function xA(e){return wk(e)!==void 0||tA(e)||pA(e)}function SA(e){if(!e.some(xA))return[];let t=[];for(let n of e)t.push(...LD(n,`face`));return t}function CA(e,t,n){Tk(e,t,n),uA(e,t,n),bA(e,t,n)}function wA(e,t){Ak(e,t)}function TA(e,t){let n=P(),r=[...n.iterShapes(e.wrapped,`face`)],i=[...n.iterShapes(t.wrapped,`face`)];if(r.length!==i.length)return;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],o=i[e];t!==void 0&&o!==void 0&&a.set(n.hashCode(t,W),[n.hashCode(o,W)])}for(let e of r)n.dispose(e);for(let e of i)n.dispose(e);CA({modified:a,generated:new Map,deleted:new Set},[e],t)}function EA(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function DA(e,t,n,r,i){let a=RE(e);if(!IE(a)){let o=yE(a).toUpperCase();return BE(e,a),I(a),R(gD(t,`${n}. Got ${o} instead.`,void 0,i?{diagnostics:i}:void 0,r))}return BE(e,a),L(a)}function OA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`fuse: first operand`);if(z(c))return c;let l=EA(t,`fuse: second operand`);if(z(l))return l;if(!s)return DA(P().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);let u=SA([e,t]),{shape:d,evolution:f,diagnostics:p}=P().fuseWithHistory(e.wrapped,t.wrapped,u,W,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(P().isNull(d))return P().dispose(d),console.warn(`brepjs: fuse history path produced null result; retrying without evolution tracking.`,p),DA(P().fuse(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`);console.warn(`brepjs: fuse reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=DA(d,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`,p);return m.ok&&CA(f,[e,t],m.value),m}function kA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;let c=EA(e,`cut: base`);if(z(c))return c;let l=EA(t,`cut: tool`);if(z(l))return l;if(!s)return DA(P().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);let u=SA([e,t]),{shape:d,evolution:f,diagnostics:p}=P().cutWithHistory(e.wrapped,t.wrapped,u,W,{optimisation:n,simplify:r,fuzzyValue:a});if(p.hasErrors){if(P().isNull(d))return P().dispose(d),console.warn(`brepjs: cut history path produced null result; retrying without evolution tracking.`,p),DA(P().cut(e.wrapped,t.wrapped,{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_NOT_3D`,`Cut did not produce a 3D shape`);console.warn(`brepjs: cut reported OCCT warnings/errors but produced a shape. Continuing with result.`,p)}let m=DA(d,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`,p);return m.ok&&CA(f,[e,t],m.value),m}function AA(e,t,{simplify:n=!1,signal:r,fuzzyValue:i,unsafe:a,trackEvolution:o=!0}={}){if(r?.aborted)throw r.reason;let s=EA(e,`intersect: first operand`);if(z(s))return s;let c=EA(t,`intersect: second operand`);if(z(c))return c;if(!o)return DA(P().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);let l=SA([e,t]),{shape:u,evolution:d,diagnostics:f}=P().intersectWithHistory(e.wrapped,t.wrapped,l,W,{simplify:n,fuzzyValue:i});if(f.hasErrors){if(P().isNull(u))return P().dispose(u),console.warn(`brepjs: intersect history path produced null result; retrying without evolution tracking.`,f),DA(P().intersect(e.wrapped,t.wrapped,{simplify:n,fuzzyValue:i}),`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`);console.warn(`brepjs: intersect reported OCCT warnings/errors but produced a shape. Continuing with result.`,f)}let p=DA(u,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`,f);return p.ok&&CA(d,[e,t],p.value),p}function jA(e,t,n,r,i,a,o,s,c){if(s?.aborted)throw s.reason;let l=n-t;if(l===1)return L({shape:jk(e,t),owned:!1});if(l===2){let n=OA(jk(e,t),jk(e,t+1),{optimisation:r,simplify:a?i:!1,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return z(n)?n:L({shape:n.value,owned:!0})}let u=t+Math.ceil(l/2),d=jA(e,t,u,r,i,!1,o,s,c);if(z(d))return d;let f=jA(e,u,n,r,i,!1,o,s,c);if(z(f))return d.value.owned&&I(d.value.shape),f;let p=OA(d.value.shape,f.value.shape,{optimisation:r,simplify:i,trackEvolution:o,fuzzyValue:c,unsafe:!0,...s?{signal:s}:{}});return d.value.owned&&I(d.value.shape),f.value.owned&&I(f.value.shape),z(p)?p:L({shape:p.value,owned:!0})}function MA(e,{optimisation:t=`none`,simplify:n=!1,strategy:r=`native`,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(e.length===0)return R(U(`FUSE_ALL_EMPTY`,`fuseAll requires at least one shape`));if(e.length===1)return L(Mk(e));for(let t=0;t<e.length;t++){let n=EA(jk(e,t),`fuseAll: shape at index ${t}`);if(z(n))return n}if(r===`native`){let o=DA(P().fuseAll(e.map(e=>e.wrapped),{optimisation:t,simplify:n,strategy:r,fuzzyValue:a,...i?{signal:i}:{}}),`FUSE_ALL_NOT_3D`,`fuseAll did not produce a 3D shape`);return o.ok&&s&&wA(e,o.value),o}let c=jA(e,0,e.length,t,n,!0,s,i,a);return z(c)?c:L(c.value.shape)}function NA(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a,unsafe:o,trackEvolution:s=!0}={}){if(i?.aborted)throw i.reason;if(t.length===0)return L(e);let c=EA(e,`cutAll: base`);if(z(c))return c;for(let e=0;e<t.length;e++){let n=EA(jk(t,e),`cutAll: tool at index ${e}`);if(z(n))return n}let l=[e,...t],u=DA(P().cutAll(e.wrapped,t.map(e=>e.wrapped),{optimisation:n,simplify:r,fuzzyValue:a}),`CUT_ALL_NOT_3D`,`cutAll did not produce a 3D shape`);return u.ok&&s&&wA(l,u.value),u}function PA(e,t,n){if(n!==void 0)return{size:n,center:t.origin};let{min:r,max:i}=P().boundingBox(e.wrapped),a=[(r[0]+i[0])/2,(r[1]+i[1])/2,(r[2]+i[2])/2],o=AO(DO(a,t.origin),t.zDir),s=DO(a,OO(t.zDir,o)),c=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);return{size:Math.max(c,1),center:s}}function FA(e,t,n){let r=P(),i=OO(e.xDir,t),a=OO(e.yDir,t),o=OO(e.xDir,-t),s=OO(e.yDir,-t),c=n,l=[...EO(EO(c,o),s)],u=[...EO(EO(c,i),s)],d=[...EO(EO(c,i),a)],f=[...EO(EO(c,o),a)],p=[r.makeLineEdge(l,u),r.makeLineEdge(u,d),r.makeLineEdge(d,f),r.makeLineEdge(f,l)],m=r.makeWire(p),h=r.makeFace(m,!0);for(let e of p)r.dispose(e);return r.dispose(m),h}function IA(e,t,{approximation:n=!0,planeSize:r}={}){if(P().isNull(e.wrapped))return R(U(V.NULL_SHAPE_INPUT,`section: shape is a null shape`));let i=typeof t==`string`?B(KO(t)):t,{size:a,center:o}=PA(e,i,r),s=FA(i,a,o);try{return L(F(P().section(e.wrapped,s,n)))}catch(e){let n=e instanceof Error?e.message:String(e),r=typeof t==`string`?t:`custom`;return R(H(`SECTION_FAILED`,`Section with ${r} plane failed: ${n}`,e,{operation:`section`,plane:r},`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`))}finally{P().dispose(s)}}function LA(e){let t=P(),n=new Map,r=new Map;for(let i of e){let e=qD(i),a=e[0]?t.hashCode(e[0].wrapped,W):-1,o=e.length>1&&e[1]?t.hashCode(e[1].wrapped,W):a;r.set(i,[a,o]);for(let e of[a,o]){let t=n.get(e)??[];t.push(i),n.set(e,t)}}return{vertexToEdges:n,edgeVertexHashes:r}}function RA(e,t,n){let r=t.vertexToEdges.get(e);if(r)for(let i of r){if(n.has(i))continue;let r=t.edgeVertexHashes.get(i);if(r)return n.add(i),{edge:i,nextTip:r[0]===e?r[1]:r[0]}}}function zA(e,t,n){n.add(e);let r=[e],i=t.edgeVertexHashes.get(e);if(!i)return r;let a=[i[1],i[0]];for(let e=0;e<2;e++){let i=a[e];if(i===void 0)continue;let o=RA(i,t,n);for(;o;)e===0?r.push(o.edge):r.unshift(o.edge),i=o.nextTip,o=RA(i,t,n)}return r}function BA(e){let t=P(),n=LA(e),r=new Set,i=[];for(let a of e){if(r.has(a))continue;let e=zA(a,n,r);try{let n=t.makeWire(e.map(e=>e.wrapped));i.push(F(n))}catch{}}return i}function VA(e){let t=P(),n=0,r=-1;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=t.boundingBox(a.wrapped),s=o.max[0]-o.min[0],c=o.max[1]-o.min[1],l=o.max[2]-o.min[2],u=s*s+c*c+l*l;u>r&&(r=u,n=i)}return n}function HA(e,t,n={}){let r=IA(e,t,n);if(!r.ok)return r;let i=KD(r.value);if(i.length===0){let e=WD(r.value);if(e.length===0)return R(H(`SECTION_FAILED`,`sectionToFace: section produced no geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));i.push(...BA(e))}if(i.length===0)return R(H(`SECTION_FAILED`,`sectionToFace: section produced no usable geometry`,void 0,void 0,`The cutting plane may not intersect the shape. Verify plane position relative to shape bounds.`));let a=VA(i),o=jk(i,a),s=i.filter((e,t)=>t!==a);return qk(o,s.length>0?s:void 0)}function UA(e,t){if(t.length===0)return L(e);if(P().isNull(e.wrapped))return R(U(V.NULL_SHAPE_INPUT,`split: shape is a null shape`));for(let e=0;e<t.length;e++)if(P().isNull(jk(t,e).wrapped))return R(U(V.NULL_SHAPE_INPUT,`splitShape: tool at index ${e} is a null shape`));try{return L(F(P().split(e.wrapped,t.map(e=>e.wrapped))))}catch(e){let n=e instanceof Error?e.message:String(e);return R(H(`SPLIT_FAILED`,`Split operation failed on ${t.length} tool(s): ${n}`,e,{operation:`split`,toolCount:t.length},`The splitting tools may not intersect the shape. Ensure tools cross through the shape's interior.`))}}function WA(e,t,n={}){let r=[];for(let i of t){let t=IA(e,i,n);if(z(t))return t;r.push(t.value)}return L(r)}function GA(e,t,n){if(t.length===0)return L(e);let r=n?.optimisation===`commonFace`?1:n?.optimisation===`sameFace`?2:0,i=P(),a=t.map(e=>({op:e.op,tool:e.tool.wrapped}));try{let o=i.booleanPipeline?.(e.wrapped,a,{glueMode:r});if(o===void 0)return KA(e,t,n);if(o===null)return R(H(`BOOLEAN_PIPELINE_FAILED`,`Boolean pipeline returned null shape`));let s=F(o);return IE(s)?L(s):(I(s),R(gD(`BOOLEAN_PIPELINE_NOT_3D`,`Pipeline result is not a 3D shape`)))}catch(e){return R(H(`BOOLEAN_PIPELINE_FAILED`,e instanceof Error?e.message:String(e)))}}function KA(e,t,n){let r=e,i={...n?.optimisation?{optimisation:n.optimisation}:{},unsafe:!0};for(let e of t){let t=e.op===`fuse`?OA(r,e.tool,i):e.op===`cut`?kA(r,e.tool,i):AA(r,e.tool,i);if(z(t))return t;r=B(t)}return L(r)}function qA(e){return F(P().sew(e.map(e=>e.wrapped)))}function JA(e,t=!1){let n=qA(e);return!t&&!NE(n)?R(gD(`WELD_NOT_SHELL`,`Could not make a shell from faces and shells`)):L(n)}function YA(e,t,n=[0,0,0],r=[0,0,1]){return EE(P().makeCylinder(e,t,[...n],[...r]))}function XA(e){return EE(P().makeSphere(e))}function ZA(e,t,n,r=[0,0,0],i=[0,0,1]){return EE(P().makeCone(e,t,n,[...r],[...i]))}function QA(e,t,n=[0,0,0],r=[0,0,1]){return EE(P().makeTorus(e,t,[...n],[...r]))}function $A(e,t,n){return EE(P().makeEllipsoid(e,t,n))}function ej(e){return xE(P().makeVertex(e[0],e[1],e[2]))}function tj(e,t,n=1e-6){return YE(nk(P().offset(e.wrapped,t,n)),e=>YE(ik(e),e=>IE(e)?L(e):R(gD(`OFFSET_NOT_3D`,`Could not offset to a 3d shape`))))}function nj(e){return OE(P().makeCompound(e.map(e=>e.wrapped)))}function rj(e){try{var t=GT();let n=t.u(qA(e)),r=F(P().solidFromShell(n.wrapped));return PE(r)?L(r):(I(r),R(gD(`SOLID_BUILD_FAILED`,`Could not make a solid of faces and shells`)))}catch(e){t.e=e}finally{t.d()}}function ij(e,t){let n=SA([e]),{shape:r,evolution:i}=P().translateWithHistory(e.wrapped,t[0],t[1],t[2],n,W),a=F(r);return CA(i,[e],a),a}function aj(e,t,n=[0,0,0],r=[0,0,1]){let i=SA([e]),{shape:a,evolution:o}=P().rotateWithHistory(e.wrapped,t*wD,i,W,r,n),s=F(a);return CA(o,[e],s),s}function oj(e,t=[0,1,0],n=[0,0,0]){let r=SA([e]),{shape:i,evolution:a}=P().mirrorWithHistory(e.wrapped,n,t,r,W),o=F(i);return CA(a,[e],o),o}function sj(e,t,n=[0,0,0]){let r=SA([e]),{shape:i,evolution:a}=P().scaleWithHistory(e.wrapped,n,t,r,W),o=F(i);return CA(a,[e],o),o}function cj(e,t,n){let r=P().boundingBox(e.wrapped),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]],a=n?.auto===!0;function o(e,t,n){return e!==void 0&&t>1e-12?e/t:e===void 0&&a?n:1}let s=1;a&&(t[0]!==void 0&&i[0]>1e-12?s=t[0]/i[0]:t[1]!==void 0&&i[1]>1e-12?s=t[1]/i[1]:t[2]!==void 0&&i[2]>1e-12&&(s=t[2]/i[2]));let c=[o(t[0],i[0],s),o(t[1],i[1],s),o(t[2],i[2],s)];return Math.abs(c[0]-c[1])<1e-6&&Math.abs(c[1]-c[2])<1e-6?L(sj(e,c[0])):R(U(V.VALIDATION_FAILED,`resize: non-uniform scaling is not supported (WASM build lacks BRepBuilderAPI_GTransform).`,void 0,void 0,`Use auto: true to scale proportionally, or set all three dimensions to achieve uniform scaling.`))}function lj(e){if(`linear`in e)return L({linear:e.linear,translation:e.translation});let[t,n,r,i]=e,a=1e-10;return Math.abs(i[0])>a||Math.abs(i[1])>a||Math.abs(i[2])>a||Math.abs(i[3]-1)>a?R(U(V.VALIDATION_FAILED,`applyMatrix: invalid bottom row [${String(i[0])}, ${String(i[1])}, ${String(i[2])}, ${String(i[3])}]. Must be [0, 0, 0, 1] for an affine transform.`)):L({linear:[t[0],t[1],t[2],n[0],n[1],n[2],r[0],r[1],r[2]],translation:[t[3],n[3],r[3]]})}function uj(e){return e[0]*(e[4]*e[8]-e[5]*e[7])-e[1]*(e[3]*e[8]-e[5]*e[6])+e[2]*(e[3]*e[7]-e[4]*e[6])}function dj(e){let t=e[0]*e[0]+e[3]*e[3]+e[6]*e[6],n=e[1]*e[1]+e[4]*e[4]+e[7]*e[7],r=e[2]*e[2]+e[5]*e[5]+e[8]*e[8],i=e[0]*e[1]+e[3]*e[4]+e[6]*e[7],a=e[0]*e[2]+e[3]*e[5]+e[6]*e[8],o=e[1]*e[2]+e[4]*e[5]+e[7]*e[8],s=1e-5*(t+n+r)/3;return!(!Number.isFinite(s)||Math.abs(i)>s||Math.abs(a)>s||Math.abs(o)>s||Math.abs(t-n)>s||Math.abs(t-r)>s)}function fj(e,t){let n=lj(t);if(!n.ok)return n;let{linear:r,translation:i}=n.value,a=uj(r);if(Math.abs(a)<1e-12)return R(U(V.VALIDATION_FAILED,`applyMatrix: singular matrix (determinant ≈ 0). Cannot apply a non-invertible transform.`));if(dj(r)){let t=SA([e]),{shape:n,evolution:a}=P().generalTransformWithHistory(e.wrapped,r,i,!0,t,W),o=F(n);return CA(a,[e],o),L(o)}let o=F(P().generalTransformNonOrthogonal(e.wrapped,r,i));return wA([e],o),L(o)}function pj(e){let t=e.map(e=>e.type===`translate`?{type:`translate`,x:e.v[0],y:e.v[1],z:e.v[2]}:{type:`rotate`,angle:e.angle,axis:e.axis,center:e.center}),{handle:n,dispose:r}=P().composeTransform(t);return{trsf:n,cleanup:r}}function mj(e,t){let{trsf:n,cleanup:r}=pj(`type`in t?[t]:t),i;try{i=F(P().locate(e.wrapped,n))}finally{r()}return xA(e)&&TA(e,i),i}function hj(e,t){let n=SA([e]),{shape:r,evolution:i}=P().applyComposedTransformWithHistory(e.wrapped,t.trsf,n,W),a=F(r);return CA(i,[e],a),a}function gj(e,t,n,r){let i=EE(P().makeBox(e,t,n)),a=r?.at??(r?.centered?[0,0,0]:void 0);if(a)try{var o=GT();return ij(o.u(i),[a[0]-e/2,a[1]-t/2,a[2]-n/2])}catch(e){o.e=e}finally{o.d()}return i}function _j(e,t,n){let r=n?.at??[0,0,0],i=n?.axis??[0,0,1],a=YA(e,t,r,i);if(n?.centered)try{var o=GT();let e=[-i[0]*t*.5,-i[1]*t*.5,-i[2]*t*.5];return ij(o.u(a),e)}catch(e){o.e=e}finally{o.d()}return a}function vj(e,t){let n=XA(e);if(t?.at)try{var r=GT();return ij(r.u(n),t.at)}catch(e){r.e=e}finally{r.d()}return n}function yj(e,t,n,r){let i=r?.at??[0,0,0],a=r?.axis??[0,0,1],o=ZA(e,t,n,i,a);if(r?.centered)try{var s=GT();let e=[-a[0]*n*.5,-a[1]*n*.5,-a[2]*n*.5];return ij(s.u(o),e)}catch(e){s.e=e}finally{s.d()}return o}function bj(e,t,n){return QA(e,t,n?.at??[0,0,0],n?.axis??[0,0,1])}function xj(e,t,n,r){let i=$A(e,t,n);if(r?.at)try{var a=GT();return ij(a.u(i),r.at)}catch(e){a.e=e}finally{a.d()}return i}function Sj(e,t){return Ik(e,t)}function Cj(e,t){let n=t?.axis??[0,0,1];return Lk(e,t?.at??[0,0,0],n)}function wj(e,t,n){let r=n?.axis??[0,0,1];return Rk(e,t,n?.at??[0,0,0],r,n?.xDir)}function Tj(e,t,n,r){return zk(e,t,n,r?.at??[0,0,0],r?.axis??[0,0,1],r?.lefthand??!1)}function Ej(e,t,n){return Bk(e,t,n)}function Dj(e,t,n,r,i){let a=i?.axis??[0,0,1];return Vk(e,t,n*wD,r*wD,i?.at??[0,0,0],a,i?.xDir)}function Oj(e,t){return Hk(e,t)}function kj(e){return Wk(e)}function Aj(e,t,n){return Gk(e,t,n)}function jj(e){return Kk(e)}function Mj(e){return YE(Kk(e),e=>uO(e)?L(e):R(U(`WIRE_NOT_CLOSED`,`Assembled wire is not closed: start and end points do not coincide`)))}function Nj(e,t){return qk(e,t)}function Pj(e){return Xk(e)}function Fj(e,t){return Yk(e,t)}function Ij(e){return Qk(e)}function Lj(e){return ej(e)}function Rj(e){return nj(e)}function zj(e){return rj(e)}function Bj(e,t,n){return tj(e,t,n)}function Vj(e,t){return JA(e,t)}function Hj(e,t){return Zk(e,t)}function Uj(e){return MD(()=>P().copyShape(e.wrapped),V.CLONE_FAILED,`Failed to clone shape`)}function Wj(e){return ND(()=>P().toBREP(e.wrapped),V.TO_BREP_FAILED,`Failed to serialize shape to BREP`)}function Gj(e){return P().hashCode(e.wrapped,W)}function Kj(e){return P().isNull(e.wrapped)}function qj(e,t){return P().isSame(e.wrapped,t.wrapped)}function Jj(e,t){return P().isEqual(e.wrapped,t.wrapped)}function Yj(e){return MD(()=>P().simplify(e.wrapped),V.SIMPLIFY_FAILED,`Failed to simplify shape`)}function Xj(e){return P().curveType(e.wrapped)}function Zj(e){let[t]=P().curveParameters(e.wrapped);return P().curvePointAtParam(e.wrapped,t)}function Qj(e){let[,t]=P().curveParameters(e.wrapped);return P().curvePointAtParam(e.wrapped,t)}function $j(e,t=.5){let[n,r]=P().curveParameters(e.wrapped),i=n+(r-n)*t;return P().curvePointAtParam(e.wrapped,i)}function eM(e,t=.5){let[n,r]=P().curveParameters(e.wrapped),i=n+(r-n)*t;return P().curveTangent(e.wrapped,i).tangent}function tM(e){return P().length(e.wrapped)}function nM(e){if(Xj(e)!==`CIRCLE`)return null;let t=$j(e,0),n=$j(e,1/3),r=$j(e,2/3),i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],a=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],o=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],s=o[0]*o[0]+o[1]*o[1]+o[2]*o[2];if(s<1e-18)return null;let c=i[0]*i[0]+i[1]*i[1]+i[2]*i[2],l=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],u=[c*a[0]-l*i[0],c*a[1]-l*i[1],c*a[2]-l*i[2]],d=[u[1]*o[2]-u[2]*o[1],u[2]*o[0]-u[0]*o[2],u[0]*o[1]-u[1]*o[0]],f=1/(2*s),p=[t[0]+d[0]*f,t[1]+d[1]*f,t[2]+d[2]*f],m=Math.sqrt(s);return{origin:p,direction:[o[0]/m,o[1]/m,o[2]/m]}}function rM(e){return P().curveIsClosed(e.wrapped)}function iM(e){return P().curveIsPeriodic(e.wrapped)}function aM(e){return P().curvePeriod(e.wrapped)}function oM(e){return P().shapeOrientation(e.wrapped)===`forward`?`forward`:`backward`}function sM(e){return F(P().reverseShape(e.wrapped))}function cM(e,t={}){if(e.length<2)return R(gD(`INTERPOLATE_MIN_POINTS`,`Interpolation requires at least 2 points`));try{let n=F(P().interpolatePoints(e,t));return AE(n)?L(n):(I(n),R(gD(`INTERPOLATE_NOT_EDGE`,`Interpolation did not produce an edge`)))}catch(e){return R(gD(`INTERPOLATE_FAILED`,`Interpolation failed: ${e instanceof Error?e.message:String(e)}`))}}function lM(e,t={}){if(e.length<2)return R(gD(`APPROXIMATE_MIN_POINTS`,`Approximation requires at least 2 points`));try{let n=F(P().approximatePoints(e,t));return AE(n)?L(n):(I(n),R(gD(`APPROXIMATE_NOT_EDGE`,`Approximation did not produce an edge`)))}catch(e){return R(gD(`APPROXIMATE_FAILED`,`Approximation failed: ${e instanceof Error?e.message:String(e)}`))}}function uM(e,t,n=`arc`){let r=F(P().offsetWire2D(e.wrapped,t,{arc:`arc`,intersection:`intersection`,tangent:`tangent`,chamfer:`intersection`}[n]));return jE(r)?L(r):(I(r),R(gD(`OFFSET_NOT_WIRE`,`Offset did not produce a Wire`)))}function dM(e,t,n,r=!1){return`${e}:${t}:${n}:${r}`}function fM(e,t){return`edge:${e}:${t}`}var pM=new WeakMap,mM=new WeakMap;function hM(e,t){let n=pM.get(e);if(n)return n.get(t)}function gM(e,t,n){let r=pM.get(e);r||(r=new Map,pM.set(e,r)),r.set(t,n)}function _M(e,t){let n=mM.get(e);if(n)return n.get(t)}function vM(e,t,n){let r=mM.get(e);r||(r=new Map,mM.set(e,r)),r.set(t,n)}function yM(){pM=new WeakMap,mM=new WeakMap}function bM(){let e=new WeakMap,t=new WeakMap;return{getMesh(t,n){return e.get(t)?.get(n)},setMesh(t,n,r){let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,r)},getEdgeMesh(e,n){return t.get(e)?.get(n)},setEdgeMesh(e,n,r){let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(n,r)},clear(){e=new WeakMap,t=new WeakMap}}}var xM=10;function SM(e,t){let n;try{let e=iO(t),r=e.xMax-e.xMin,i=e.yMax-e.yMin,a=e.zMax-e.zMin;n=Math.sqrt(r*r+i*i+a*a)}catch{return e}return e*Math.max(1,n/xM)}function CM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,skipNormals:a=!1,includeUVs:o=!1,cache:s=!0,signal:c}=t;c?.throwIfAborted();let l=dM(r,i,a,o);if(s){let t=hM(e.wrapped,l);if(t)return t}let u=P().mesh(e.wrapped,{tolerance:r,angularTolerance:i,skipNormals:a,includeUVs:o,...c?{signal:c}:{}}),d=wk(e),f={vertices:u.vertices,normals:u.normals,triangles:u.triangles,uvs:u.uvs,faceGroups:u.faceGroups.map(e=>({start:e.start,count:e.count,faceId:e.faceHash,origin:d?.get(e.faceHash)??0}))};return s&&gM(e.wrapped,l,f),f}function wM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,cache:a=!0}=t,o=fM(r,i);if(a){let t=_M(e.wrapped,o);if(t)return t}let s=P().meshEdges(e.wrapped,r,i),c={lines:s.lines,edgeGroups:s.edgeGroups.map(e=>({start:e.start,count:e.count,edgeId:e.edgeHash}))};return a&&vM(e.wrapped,o,c),c}function TM(e,t){return e instanceof Error&&e.message.startsWith(`${t} export failed`)?bD(`${t}_EXPORT_FAILED`,`Failed to write ${t} file`,e):e instanceof WebAssembly.RuntimeError?bD(`${t}_EXPORT_CRASHED`,`${t} export crashed the kernel (${e.message}); the shape likely contains geometry the ${t} writer cannot serialize`,e):bD(`${t}_FILE_READ_ERROR`,`Failed to read exported ${t} file`,e)}function EM(e){let t;try{t=JD(e)}catch{return``}if(t.length<=1)return``;let n=[];return t.forEach((e,t)=>{try{iO(e)}catch(e){if(e instanceof TypeError)throw e;n.push(t)}}),n.length===0?`; could not localize the offending sub-solid among ${t.length} solids`:`; offending sub-solid${n.length>1?`s`:``} (of ${t.length}): index ${n.join(`, `)}`}function DM(e,t){try{return iO(e),null}catch(n){if(n instanceof TypeError)throw n;return bD(`${t}_EXPORT_UNSERIALIZABLE`,`${t} export aborted: the shape contains degenerate geometry the ${t} writer cannot serialize (bounding-box evaluation failed); export was skipped to avoid crashing the kernel${EM(e)}`,n)}}function OM(e){let t=DM(e,`STEP`);if(t)return R(t);try{let t=P().exportSTEP([e.wrapped]);return L(new Blob([t],{type:`application/STEP`}))}catch(e){return R(TM(e,`STEP`))}}function kM(e,t={}){let n=ho(),{tolerance:r=SM(n.tolerance,e),angularTolerance:i=n.angularTolerance,binary:a=!1}=t,o=DM(e,`STL`);if(o)return R(o);try{P().hasTriangulation(e.wrapped)||P().meshShape(e.wrapped,r,i);let t=P().exportSTL(e.wrapped,a,r,i);return L(new Blob([t],{type:`application/sla`}))}catch(e){return R(TM(e,`STL`))}}function AM(e){try{let t=P().exportIGES([e.wrapped]);return L(new Blob([t],{type:`application/iges`}))}catch(e){return R(bD(`IGES_EXPORT_FAILED`,`Failed to write IGES file`,e))}}function jM(e,t){let n=t?.coarseTolerance??.5,r=t?.fineTolerance??.05,i=t?.angularTolerance??.5;return{coarse:CM(e,{tolerance:n,angularTolerance:i}),fine:CM(e,{tolerance:r,angularTolerance:i*.2})}}function MM(e){let t=iO(e),n=t.xMax-t.xMin,r=t.yMax-t.yMin,i=t.zMax-t.zMin;return Math.sqrt(n*n+r*r+i*i)||1}function NM(e,t){let n;if(t.tolerances&&t.tolerances.length>0)n=[...t.tolerances];else{let r=Math.max(1,Math.floor(t.levels??3)),i=t.spacing??4,a=(t.relativeTolerance??5e-4)*MM(e)||2**-52;n=[];for(let e=r-1;e>=0;e--)n.push(a*i**e)}return n.sort((e,t)=>t-e),n}function PM(e,t,n){return Math.min(e/t*n,1)}function FM(e,t={}){let n=t.angularTolerance??ho().angularTolerance,r=t.cache??!0,i=NM(e,t),a=Math.min(...i);return i.map(i=>{let o=PM(i,a,n);return{tolerance:i,angularTolerance:o,mesh:CM(e,{tolerance:i,angularTolerance:o,cache:r,...t.signal?{signal:t.signal}:{}})}})}function IM(){return new Promise(e=>{setTimeout(e,0)})}async function LM(e,t={}){let n=t.angularTolerance??ho().angularTolerance,r=t.cache??!0,i=t.meshLevel??((e,n,i)=>CM(e,{tolerance:n,angularTolerance:i,cache:r,...t.signal?{signal:t.signal}:{}})),a=NM(e,t),o=Math.min(...a),s=[];for(let[r,c]of a.entries()){if(t.signal?.aborted)break;let l=PM(c,o,n),u;try{u=await i(e,c,l)}catch(e){if(t.signal?.aborted)break;throw e}let d={tolerance:c,angularTolerance:l,mesh:u};if(s.push(d),t.onLevel?.(d,r),t.signal?.aborted||r===a.length-1)break;await IM()}return s}function RM(e){return{position:e.vertices,normal:e.normals,index:e.triangles}}function zM(e){return{position:e.vertices,normal:e.normals,index:e.triangles,groups:e.faceGroups.map((e,t)=>({start:e.start,count:e.count,materialIndex:t,faceId:e.faceId}))}}function BM(e){return{position:e.lines}}function VM(e,t){return{coarse:RM(e.coarse),fine:RM(e.fine),coarseDistance:t?.coarse??50,fineDistance:t?.fine??0}}function HM(e,t){let n=t?.step??50,r=t?.distances;if(r&&r.length!==e.length)throw Error(`toLODGeometryLevels: distances must have one entry per level (got ${r.length} for ${e.length} levels)`);let i=e.length-1;return e.map((e,t)=>({geometry:RM(e.mesh),distance:r?.[t]??(i-t)*n}))}function UM(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function WM(e,t){if(typeof e==`number`&&e<=0)return R(U(t.code,t.scalar,void 0,void 0,t.scalarHint));if(Array.isArray(e)&&(e[0]<=0||e[1]<=0))return R(U(t.code,t.pair,void 0,void 0,t.pairHint))}function GM(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return n.length===0?null:{edges:n,kernelParam:e=>{let t=r.get(P().hashCode(e,W));if(t===void 0)throw Error(`fillet/chamfer: edge hash not found — possible hash collision`);return t}}}function KM(e,t,n,r,i){let a=F(t);return IE(a)?(CA(e,n,a),L(a)):(I(a),R(H(r,i)))}function qM(e,t){if(typeof t!=`function`)return{filteredFaces:[...e],kernelAngle:t};let n=[],r=new Map;for(let i of e){let e=t(i);e===null||e===0||Math.abs(e)>=90||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return{filteredFaces:n,kernelAngle:e=>{let t=r.get(P().hashCode(e,W));if(t===void 0)throw Error(`draft: face hash not found — possible hash collision`);return t}}}function JM(e,t){let n=UM(e,`thicken: shape`);if(z(n))return n;try{let n=SA([e]),{shape:r,evolution:i}=P().thickenWithHistory(e.wrapped,t,n,W),a=F(r);return CA(i,[e],a),L(a)}catch(e){return R(H(`THICKEN_FAILED`,`Thicken operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function YM(e,t,n){let r=UM(e,`fillet: shape`);if(z(r))return r;let i=WM(n,{code:`INVALID_FILLET_RADIUS`,scalar:`Fillet radius must be positive`,pair:`Fillet radii must both be positive`,scalarHint:`Provide a positive radius value greater than 0`,pairHint:`Both radius values must be greater than 0`});if(i)return i;let a=t??WD(e);if(a.length===0)return R(U(V.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));if(typeof n==`function`){let e=GM(a,n);return e?L({filteredEdges:e.edges,kernelRadius:e.kernelParam,selectedCount:a.length}):R(U(V.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`))}return L({filteredEdges:[...a],kernelRadius:n,selectedCount:a.length})}function XM(e,t,n,{trackEvolution:r=!0}={}){let i=YM(e,t,n);if(z(i))return i;let{filteredEdges:a,kernelRadius:o,selectedCount:s}=i.value;try{let t=a.map(e=>e.wrapped);if(!r){let n=F(P().fillet(e.wrapped,t,o));return IE(n)?L(n):(I(n),R(H(V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}let n=SA([e]),{shape:i,evolution:s}=P().filletWithHistory(e.wrapped,t,o,n,W);return KM(s,i,[e],V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)}catch(e){return R(H(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:s,radius:n}))}}function ZM(e,t,n){let r=UM(e,`chamfer: shape`);if(z(r))return r;let i=WM(n,{code:`INVALID_CHAMFER_DISTANCE`,scalar:`Chamfer distance must be positive`,pair:`Chamfer distances must both be positive`,scalarHint:`Provide a positive distance value greater than 0`,pairHint:`Both distance values must be greater than 0`});if(i)return i;let a=t??WD(e);if(a.length===0)return R(U(V.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=GM(a,n);if(!e)return R(U(V.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...a],r=n;let i=SA([e]),{shape:o,evolution:s}=P().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,i,W);return KM(s,o,[e],V.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)}catch(e){return R(H(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:a.length,distance:n}))}}function QM(e,t,n,r=.001,{trackEvolution:i=!0}={}){let a=UM(e,`shell: shape`);if(z(a))return a;if(n<=0)return R(U(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return R(U(`NO_FACES`,`At least one face must be specified for shell`));try{if(!i){let i=F(P().shell(e.wrapped,t.map(e=>e.wrapped),n,r));return IE(i)?L(i):(I(i),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}let a=SA([e]),{shape:o,evolution:s}=P().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,a,W,r),c=F(o);return IE(c)?(CA(s,[e],c),L(c)):(I(c),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return R(H(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function $M(e,t,n=1e-6){let r=UM(e,`offset: shape`);if(z(r))return r;if(Math.abs(t)<1e-10)return R(U(`ZERO_OFFSET`,`Offset distance cannot be zero`));try{let r=SA([e]),{shape:i,evolution:a}=P().offsetWithHistory(e.wrapped,t,r,W,n),o=F(i);return IE(o)?(CA(a,[e],o),L(o)):(I(o),R(H(`OFFSET_RESULT_NOT_3D`,`Offset result is not a 3D shape`)))}catch(e){return R(H(`OFFSET_FAILED`,`Offset operation failed: ${e instanceof Error?e.message:String(e)}`,e))}}function eN(e,t,n){let r=UM(e,`draft: shape`);if(z(r))return r;if(typeof n==`number`){if(Math.abs(n)<1e-10)return R(U(V.DRAFT_INVALID_ANGLE,`Draft angle cannot be zero`,void 0,void 0,`Provide a non-zero angle in degrees`));if(Math.abs(n)>=90)return R(U(V.DRAFT_INVALID_ANGLE,`Draft angle must be between -90 and 90 degrees (exclusive)`,void 0,void 0,`Typical draft angles are 1-5 degrees for injection molding`))}if(t.length===0)return R(U(V.DRAFT_NO_FACES,`No faces specified for draft`,void 0,void 0,`Select at least one face to apply the draft angle to`))}function tN(e,t,n,r,i){let a=eN(e,t,i);if(a)return a;try{let{filteredFaces:a,kernelAngle:o}=qM(t,i);if(a.length===0)return R(U(V.DRAFT_NO_FACES,`No faces with valid draft angle`,void 0,void 0,`Check that the angle callback returns non-zero values between -90 and 90 degrees`));let s=SA([e]),{shape:c,evolution:l}=P().draftWithHistory(e.wrapped,a.map(e=>e.wrapped),[n[0],n[1],n[2]],[r[0],r[1],r[2]],o,s,W);return KM(l,c,[e],V.DRAFT_NOT_3D,`Draft result is not a 3D shape`)}catch(e){let n=e instanceof Error?e.message:String(e);return R(H(V.DRAFT_FAILED,`Draft operation failed: ${n}`,e,{operation:`draft`,faceCount:t.length,angle:i}))}}function nN(e,t,n){if(n.length===0)return R(U(V.VARIABLE_FILLET_FAILED,`radii must contain at least one radius spec`));for(let e of n)if(e.radius<=0)return R(U(V.VARIABLE_FILLET_FAILED,`All radius values must be positive`));let r=P();try{let i=JSON.stringify({edge:r.hashCode(t.wrapped,W),radii:n.map(e=>({param:e.param,radius:e.radius}))}),a=F(r.filletVariable(e.wrapped,i));return IE(a)?PE(a)?L(a):(I(a),R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a solid`))):(I(a),R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet did not produce a 3D shape`)))}catch(e){return R(H(V.VARIABLE_FILLET_FAILED,`Variable-radius fillet failed`,e))}}function rN(e,t,n,r){if(t.length===0)return R(U(`CHAMFER_ANGLE_NO_EDGES`,`chamferDistAngle requires at least one edge`,void 0,{edgeCount:0}));if(n<=0)return R(U(`CHAMFER_ANGLE_BAD_DISTANCE`,`distance must be positive, got ${n}`,void 0,{distance:n}));if(r<=0||r>=90)return R(U(`CHAMFER_ANGLE_BAD_ANGLE`,`angleDeg must be in range (0, 90), got ${r}`,void 0,{angleDeg:r}));let i;try{let a=P(),o=t.map(e=>e.wrapped);i=a.chamferDistAngle(e.wrapped,o,n,r)}catch(e){return R(H(`CHAMFER_ANGLE_FAILED`,`chamferDistAngle kernel call failed: ${e instanceof Error?e.message:String(e)}`,e,{distance:n,angleDeg:r,edgeCount:t.length}))}let a=nk(i);if(z(a))return P().dispose(i),a;let o=F(a.value);return BE(i,o),IE(o)?L(o):(I(o),R(gD(`CHAMFER_ANGLE_NOT_3D`,`chamferDistAngle did not produce a 3D shape`)))}function iN(e){let t=P();return t.getNurbsCurveData?t.getNurbsCurveData(e.wrapped):null}function aN(e){let t=P();return t.getNurbsSurfaceData?t.getNurbsSurfaceData(e.wrapped):null}var oN={cut:kA,cutAll:NA,fuse:OA,fuseAll:MA};function sN(e){return{totalInputs:e.totalInputs,batchAttempts:e.batchAttempts,batchSucceeded:e.batchSucceeded,singletonFallbacks:e.singletonFallbacks,failedInputs:[...e.failedInputs].sort((e,t)=>e-t)}}function cN(e,t,n={}){return lN(oN,e,t,n)}function lN(e,t,n,r={}){if(r.signal?.aborted)throw r.signal.reason;let i={totalInputs:n.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},a=uN(e,t,n,0,r,i);return z(a)?a:L({shape:a.value,telemetry:sN(i)})}function uN(e,t,n,r,i,a){if(n.length===0)return L(t);if(n.length===1)return dN(e,t,n,r,i,a);a.batchAttempts++;let o=gN(()=>e.cutAll(t,n,i));if(o&&o.ok)return a.batchSucceeded++,o;if(i.signal?.aborted)throw i.signal.reason;let s=Math.floor(n.length/2),c=uN(e,t,n.slice(0,s),r,i,a);return c.ok?uN(e,c.value,n.slice(s),r+s,i,a):c}function dN(e,t,n,r,i,a){a.singletonFallbacks++;let o=Mk(n),s=gN(()=>e.cut(t,o,i));if(s&&s.ok)return s;if(i.signal?.aborted)throw i.signal.reason;return a.failedInputs.add(r),L(t)}function fN(e,t={}){return pN(oN,e,t)}function pN(e,t,n={}){if(n.signal?.aborted)throw n.signal.reason;if(t.length===0)return R(U(V.FUSE_ALL_EMPTY,`fuseAllBisect requires at least one shape`));let r={totalInputs:t.length,batchAttempts:0,batchSucceeded:0,singletonFallbacks:0,failedInputs:new Set},i=mN(e,t,0,n,r);return z(i)?i:L({shape:i.value,telemetry:sN(r)})}function mN(e,t,n,r,i){if(t.length===1)return L(Mk(t));i.batchAttempts++;let a=gN(()=>e.fuseAll(t,r));if(a&&a.ok)return i.batchSucceeded++,a;if(r.signal?.aborted)throw r.signal.reason;let o=Math.floor(t.length/2);return hN(e,mN(e,t.slice(0,o),n,r,i),mN(e,t.slice(o),n+o,r,i),t,n,o,r,i)}function hN(e,t,n,r,i,a,o,s){if(t.ok&&n.ok){s.singletonFallbacks++;let c=gN(()=>e.fuse(t.value,n.value,o));if(c&&c.ok)return c;for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(t.ok){for(let e=a;e<r.length;e++)s.failedInputs.add(i+e);return t}if(n.ok){for(let e=0;e<a;e++)s.failedInputs.add(i+e);return n}return t}function gN(e){try{return e()}catch{return null}}function _N(e,t,n){return P().checkBoolean(e.wrapped,t.wrapped,n)}function vN(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function yN(e,t){return P().isNull(e.wrapped)?R(U(V.NULL_SHAPE_INPUT,`${t} is a null shape`)):L(void 0)}function bN(e,t,n,r){let i=RE(e);if(!IE(i)){let a=yE(i).toUpperCase();return BE(e,i),I(i),R(gD(t,`${n}. Got ${a} instead.`,void 0,void 0,r))}return BE(e,i),L(i)}function xN(e,t){let n=[],r=new Map;for(let i of e){let e=t(i)??0;typeof e==`number`&&e<=0||Array.isArray(e)&&(e[0]<=0||e[1]<=0)||(n.push(i),r.set(P().hashCode(i.wrapped,W),e))}return n.length===0?null:{edges:n,kernelParam:e=>r.get(P().hashCode(e,2147483647))??1}}function SN(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=vN(e,`fuseWithEvolution: first operand`);if(z(o))return o;let s=vN(t,`fuseWithEvolution: second operand`);if(z(s))return s;let c=SA([e,t]),{shape:l,evolution:u}=P().fuseWithHistory(e.wrapped,t.wrapped,c,W,{optimisation:n,simplify:r,fuzzyValue:a}),d=bN(l,`FUSE_NOT_3D`,`Fuse did not produce a 3D shape`,`Common causes: overlapping coplanar faces, zero-thickness geometry, or non-manifold input. Try autoHeal() on inputs first.`);return d.ok?(CA(u,[e,t],d.value),L({shape:d.value,evolution:u})):d}function CN(e,t,{optimisation:n=`none`,simplify:r=!1,signal:i,fuzzyValue:a}={}){if(i?.aborted)throw i.reason;let o=vN(e,`cutWithEvolution: base`);if(z(o))return o;let s=vN(t,`cutWithEvolution: tool`);if(z(s))return s;let c=SA([e,t]),{shape:l,evolution:u}=P().cutWithHistory(e.wrapped,t.wrapped,c,W,{optimisation:n,simplify:r,fuzzyValue:a}),d=bN(l,`CUT_NOT_3D`,`Cut did not produce a 3D shape`,`Common causes: tool does not fully intersect the base, or produces a zero-thickness sliver. Ensure the tool extends through the shape.`);return d.ok?(CA(u,[e,t],d.value),L({shape:d.value,evolution:u})):d}function wN(e,t,{simplify:n=!1,signal:r,fuzzyValue:i}={}){if(r?.aborted)throw r.reason;let a=vN(e,`intersectWithEvolution: first operand`);if(z(a))return a;let o=vN(t,`intersectWithEvolution: second operand`);if(z(o))return o;let s=SA([e,t]),{shape:c,evolution:l}=P().intersectWithHistory(e.wrapped,t.wrapped,s,W,{simplify:n,fuzzyValue:i}),u=bN(c,`INTERSECT_NOT_3D`,`Intersect did not produce a 3D shape`,`Shapes may not overlap. Verify they share a common volume before intersecting.`);return u.ok?(CA(l,[e,t],u.value),L({shape:u.value,evolution:l})):u}function TN(e,t,n){let r=yN(e,`filletWithEvolution: shape`);if(z(r))return r;if(typeof n==`number`&&n<=0)return R(U(`INVALID_FILLET_RADIUS`,`Fillet radius must be positive`,void 0,void 0,`Provide a positive radius value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return R(U(`INVALID_FILLET_RADIUS`,`Fillet radii must both be positive`,void 0,void 0,`Both radius values must be greater than 0`));let i=t??WD(e);if(i.length===0)return R(U(V.FILLET_NO_EDGES,`No edges found for fillet`,void 0,void 0,`Check that the shape has edges, or adjust your edge finder criteria`));try{let t,r;if(typeof n==`function`){let e=xN(i,n);if(!e)return R(U(V.FILLET_NO_EDGES,`No edges with positive radius for fillet`,void 0,void 0,`Check that the radius callback returns positive values`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=SA([e]),{shape:o,evolution:s}=P().filletWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,W),c=F(o);return IE(c)?(CA(s,[e],c),L({shape:c,evolution:s})):(I(c),R(H(V.FILLET_NOT_3D,`Fillet result is not a 3D shape`)))}catch(e){return R(H(`FILLET_FAILED`,`Fillet operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`fillet`,edgeCount:i.length,radius:n}))}}function EN(e,t,n){let r=yN(e,`chamferWithEvolution: shape`);if(z(r))return r;if(typeof n==`number`&&n<=0)return R(U(`INVALID_CHAMFER_DISTANCE`,`Chamfer distance must be positive`,void 0,void 0,`Provide a positive distance value greater than 0`));if(Array.isArray(n)&&(n[0]<=0||n[1]<=0))return R(U(`INVALID_CHAMFER_DISTANCE`,`Chamfer distances must both be positive`,void 0,void 0,`Both distance values must be greater than 0`));let i=t??WD(e);if(i.length===0)return R(U(V.CHAMFER_NO_EDGES,`No edges found for chamfer`));try{let t,r;if(typeof n==`function`){let e=xN(i,n);if(!e)return R(U(V.CHAMFER_NO_EDGES,`No edges with positive distance for chamfer`));t=e.edges,r=e.kernelParam}else t=[...i],r=n;let a=SA([e]),{shape:o,evolution:s}=P().chamferWithHistory(e.wrapped,t.map(e=>e.wrapped),r,a,W),c=F(o);return IE(c)?(CA(s,[e],c),L({shape:c,evolution:s})):(I(c),R(H(V.CHAMFER_NOT_3D,`Chamfer result is not a 3D shape`)))}catch(e){return R(H(`CHAMFER_FAILED`,`Chamfer operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`chamfer`,edgeCount:i.length,distance:n}))}}function DN(e,t,n,r=.001){let i=yN(e,`shellWithEvolution: shape`);if(z(i))return i;if(n<=0)return R(U(`INVALID_THICKNESS`,`Shell thickness must be positive`));if(t.length===0)return R(U(`NO_FACES`,`At least one face must be specified for shell`));try{let i=SA([e]),{shape:a,evolution:o}=P().shellWithHistory(e.wrapped,t.map(e=>e.wrapped),n,i,W,r),s=F(a);return IE(s)?(CA(o,[e],s),L({shape:s,evolution:o})):(I(s),R(H(`SHELL_RESULT_NOT_3D`,`Shell result is not a 3D shape`)))}catch(e){return R(H(`SHELL_FAILED`,`Shell operation failed: ${e instanceof Error?e.message:String(e)}`,e,{operation:`shell`,faceCount:t.length,thickness:n}))}}function ON(e,t,n){try{let r=F(P().positionOnCurve(e.wrapped,t.wrapped,n));return IE(r)?L(r):(I(r),R(H(V.POSITION_ON_CURVE_FAILED,`positionOnCurve did not produce a 3D shape`)))}catch(e){return R(H(V.POSITION_ON_CURVE_FAILED,`Failed to position shape on curve at param ${n}`,e))}}function kN(e){return sO(e)}function AN(e){if(!PE(e))return R(U(`NOT_A_SOLID`,`Input shape is not a solid`));let t=kN(e);try{let n=P().healSolid(e.wrapped);if(!n)return t?L(e):R(H(V.HEAL_NO_EFFECT,`Solid healing had no effect — shape is still invalid`));let r=F(n);return PE(r)?(UD(r),kN(r)?L(r):(I(r),R(H(`HEAL_SOLID_INCOMPLETE`,`Healed result is still invalid after ShapeFix_Solid`)))):(I(r),R(H(`HEAL_RESULT_NOT_SOLID`,`Healed result is not a solid`)))}catch(e){return R(H(`HEAL_SOLID_FAILED`,`Solid healing failed`,e))}}function jN(e){if(!ME(e))return R(U(`NOT_A_FACE`,`Input shape is not a face`));try{let t=F(P().healFace(e.wrapped));return ME(t)?L(t):(I(t),R(H(`HEAL_RESULT_NOT_FACE`,`Healed result is not a face`)))}catch(e){return R(H(`HEAL_FACE_FAILED`,`Face healing failed`,e))}}function MN(e,t){if(!jE(e))return R(U(`NOT_A_WIRE`,`Input shape is not a wire`));try{let n=F(P().healWire(e.wrapped,t?.wrapped));return jE(n)?L(n):(I(n),R(H(`HEAL_RESULT_NOT_WIRE`,`Healed result is not a wire`)))}catch(e){return R(H(`HEAL_WIRE_FAILED`,`Wire healing failed`,e))}}function NN(e){return PE(e)?AN(e):ME(e)?jN(e):jE(e)?MN(e):L(e)}function PN(e,t){let n=t?.fixWires!==!1,r=t?.fixFaces!==!1,i=t?.fixSolids!==!1,a=t?.fixSelfIntersection===!0,o=t?.sewTolerance,s=[],c=[];if(kN(e))return L({shape:e,report:{isValid:!0,alreadyValid:!0,wiresHealed:0,facesHealed:0,solidHealed:!1,steps:[`Shape already valid`],diagnostics:[{name:`validation`,attempted:!0,succeeded:!0}]}});s.push(`Shape invalid — applying shape-level healing`);let l=KD(e).length,u=GD(e).length,d=e,f=!1,p=t=>{let n=d;d=t,n!==e&&n.wrapped!==t.wrapped&&I(n)};if(o!==void 0)try{p(F(P().sew([d.wrapped],o))),s.push(`Applied sewing with tolerance ${o}`),c.push({name:`sew`,attempted:!0,succeeded:!0,detail:`tolerance=${o}`})}catch(e){let t=e instanceof Error?e.message:String(e);s.push(`Sewing failed: ${t}`),c.push({name:`sew`,attempted:!0,succeeded:!1,detail:t})}if(a&&n){let e=KD(d),t=0;for(let n of e)try{P().fixSelfIntersection(n.wrapped),t++}catch{}s.push(`Self-intersection fix: ${t}/${e.length} wires`),c.push({name:`fixSelfIntersection`,attempted:!0,succeeded:t>0,detail:`${t}/${e.length} wires fixed`})}if(PE(d)&&i||ME(d)&&r||jE(d)&&n){let t=NN(d);KE(t)?(p(t.value),PE(e)?(f=!0,s.push(`Applied ShapeFix_Solid`),c.push({name:`healSolid`,attempted:!0,succeeded:!0})):ME(e)?(s.push(`Applied ShapeFix_Face`),c.push({name:`healFace`,attempted:!0,succeeded:!0})):(s.push(`Applied ShapeFix_Wire`),c.push({name:`healWire`,attempted:!0,succeeded:!0}))):(s.push(`Shape-level healing failed`),c.push({name:`healShape`,attempted:!0,succeeded:!1}))}else c.push({name:`healShape`,attempted:!1,succeeded:!1,detail:`skipped by options`});let m=KD(d).length,h=GD(d).length,g=Math.abs(m-l),_=Math.abs(h-u);g>0&&s.push(`Wire count changed by ${g}`),_>0&&s.push(`Face count changed by ${_}`);let v=kN(d);return s.push(v?`Final validation: valid`:`Final validation: still invalid`),c.push({name:`finalValidation`,attempted:!0,succeeded:v}),L({shape:d,report:{isValid:v,alreadyValid:!1,wiresHealed:g,facesHealed:_,solidHealed:f,steps:s,diagnostics:c}})}function FN(e){try{return L(F(P().fixShape(e.wrapped)))}catch(e){return R(H(V.FIX_SHAPE_FAILED,`ShapeFix_Shape failed`,e))}}function IN(e){try{let t=F(P().solidFromShell(e.wrapped));return PE(t)?kN(t)?L(t):(I(t),R(H(V.SOLID_FROM_SHELL_FAILED,`solidFromShell produced an invalid solid`))):(I(t),R(H(V.SOLID_FROM_SHELL_FAILED,`solidFromShell did not produce a solid`)))}catch(e){return R(H(V.SOLID_FROM_SHELL_FAILED,`Failed to create solid from shell`,e))}}function LN(e){try{let t=F(P().fixSelfIntersection(e.wrapped));return jE(t)?L(t):(I(t),R(H(V.FIX_SELF_INTERSECTION_FAILED,`Result is not a wire`)))}catch(e){return R(H(V.FIX_SELF_INTERSECTION_FAILED,`Failed to fix wire self-intersection`,e))}}function RN(e,{profile:t,endFactor:n=1}){return e<1e-10?R(U(`INVALID_EXTRUSION_LENGTH`,`Extrusion length too small (< 1e-10)`)):t!==`s-curve`&&t!==`linear`?R(U(`UNSUPPORTED_PROFILE`,`Unsupported extrusion profile: ${String(t)}`)):L(P().buildExtrusionLaw(t,e,n).Trim(0,e,1e-6))}function zN(e,t){let n=P(),r=n.makeLineEdge([...e],[...t]),i=n.makeWire([r]);return n.dispose(r),F(i)}function BN(e,t,n,r,i,a=!1){return F(P().makeHelixWire(e,t,n,[...r],[...i],a))}function VN(e){let t=F(e.shape),n=F(e.firstShape),r=F(e.lastShape),i=()=>{I(t),I(n),I(r)};return IE(t)?jE(n)?jE(r)?L([t,n,r]):(i(),R(gD(`SWEEP_END_NOT_WIRE`,`Sweep did not produce an end Wire`))):(i(),R(gD(`SWEEP_START_NOT_WIRE`,`Sweep did not produce a start Wire`))):(i(),R(gD(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function HN(e,t,n={},r=!1){if(n.mode===`simple`&&!r){let n=F(P().simplePipe(e.wrapped,t.wrapped));return IE(n)?L(n):(I(n),R(gD(`SWEEP_NOT_3D`,`Simple pipe did not produce a 3D shape`)))}let{frenet:i=!1,auxiliarySpine:a,law:o=null,transitionMode:s=`right`,withContact:c,support:l,forceProfileSpineOthogonality:u,tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h}=n,g=P(),_=s===`round`||!!u,v=g.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:s,contact:!!c,correction:_,frenet:i,shellMode:r,...a?.wrapped?{auxiliary:a.wrapped}:{},...o===null?{}:{law:o},...l===null?{}:{support:l},tolerance:d,boundTolerance:f,angularTolerance:p,maxDegree:m,maxSegments:h});if(r&&typeof v==`object`&&`firstShape`in v)return VN(v);let y=F(v);return IE(y)?L(y):(I(y),R(gD(`SWEEP_NOT_3D`,`Sweep did not produce a 3D shape`)))}function UN(e,t,n,r){return HN(e,zN(t,EO(t,n)),{support:r})}function WN(e,t,n,r,i=!1){try{var a=GT();let o=MO(n);if(o<1e-10)return R(U(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let s=EO(t,n),c=a.u(zN(t,s)),l=null;if(r){let e=RN(o,r);if(z(e))return e;l=e.value}return HN(e,c,{law:l},i)}catch(e){a.e=e}finally{a.d()}}function GN(e,t,n,r,i,a=!1){try{var o=GT();if(Math.abs(t)<1e-10)return R(U(`ZERO_TWIST_ANGLE`,`Twist angle cannot be zero`));let s=MO(r);if(s<1e-10)return R(U(`ZERO_LENGTH_EXTRUSION`,`Extrusion vector cannot have zero length`));let c=EO(n,r),l=o.u(zN(n,c)),u=t<0,d=360/Math.abs(t)*s,f=o.u(BN(d,s,1,n,r,u)),p=null;if(i){let e=RN(s,i);if(z(e))return e;p=e.value}return HN(e,l,{auxiliarySpine:f,law:p},a)}catch(e){o.e=e}finally{o.d()}}function KN(e){let t=e.map(e=>e.location);for(let e=0;e<t.length;e++){let n=t[e];if(n!==void 0&&(n<0||n>1))return U(V.MULTI_SWEEP_FAILED,`Section ${e} location ${n} is out of range [0, 1]`)}let n=t.filter(e=>e!==void 0);for(let e=1;e<n.length;e++)if((n[e]??0)<=(n[e-1]??0))return U(V.MULTI_SWEEP_FAILED,`Section locations must be strictly increasing`)}function qN(e,t,n){let[r,i]=n.curveParameters(t.wrapped),a=i-r,o=Array(e.length);for(let t=0;t<e.length;t++){let n=e[t]?.location;o[t]=n===void 0?NaN:r+n*a}let s=-1,c=r;for(let t=0;t<=e.length;t++){let n=t===e.length;if(!n&&!Number.isNaN(o[t]??NaN)||n){let e=n?i:o[t]??i,a=t-s-1;for(let t=1;t<=a;t++)o[s+t]=c+t/(a+1)*(e-c);n||(s=t,c=o[t]??r)}}for(let e=1;e<o.length;e++)if((o[e]??0)<=(o[e-1]??0))return R(U(V.MULTI_SWEEP_FAILED,`Computed section parameters are not strictly increasing at index ${e} (${o[e-1]?.toFixed(4)} >= ${o[e]?.toFixed(4)})`));return L(o)}function JN(e,t,n){if(e.length<2)return R(U(V.MULTI_SWEEP_INSUFFICIENT_SECTIONS,`Multi-section sweep requires at least 2 sections, got ${e.length}`));let{solid:r=!0,ruled:i=!1,tolerance:a=1e-6}=n??{},o=KN(e);if(o)return R(o);try{let n=P(),o=qN(e,t,n);if(z(o))return o;let s=o.value,c=[],l=[];try{for(let r=0;r<e.length;r++){let i=s[r],a=e[r];if(i===void 0||a===void 0)continue;let o=n.positionOnCurve(a.wire.wrapped,t.wrapped,i);c.push(o),l.push(n.downcast(o,`wire`))}let o=F(n.loftAdvanced(l,{solid:r,ruled:i,tolerance:a}));return IE(o)?L(o):(I(o),R(gD(`MULTI_SWEEP_NOT_3D`,`Multi-section sweep did not produce a 3D shape`)))}finally{for(let e of l)n.dispose(e);for(let e of c)n.dispose(e)}}catch(e){let t=e instanceof Error?e.message:String(e);return R(H(V.MULTI_SWEEP_FAILED,`Multi-section sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function YN(e,t,n,r={}){let{transition:i=`transformed`,solid:a=!0,tolerance:o}=r;try{let r=P(),s=!a,c=n.length>0?n[0]?.wrapped:void 0,l=r.sweepPipeShell(e.wrapped,t.wrapped,{transitionMode:i,...c?{auxiliary:c}:{},shellMode:s,...o===void 0?{}:{tolerance:o,boundTolerance:o}}),u=F(typeof l==`object`&&`shape`in l?l.shape:l);return IE(u)?L(u):(I(u),R(gD(`GUIDED_SWEEP_NOT_3D`,`Guided sweep did not produce a 3D shape`)))}catch(e){let t=e instanceof Error?e.message:String(e);return R(H(V.GUIDED_SWEEP_FAILED,`Guided sweep failed: ${t}`,e,void 0,`Common causes: profile too large for path curvature, self-intersecting result, or discontinuous path. Try simplifying the profile or path.`))}}function XN(e,{ruled:t=!0,startPoint:n,endPoint:r,tolerance:i=1e-6}={},a=!1){if(e.length===0&&!n&&!r)return R(U(`LOFT_EMPTY`,`Loft requires at least one wire or start/end point`));let o=P(),s=n?o.makeVertex(...SO(n)):void 0,c=r?o.makeVertex(...SO(r)):void 0;try{let n=F(o.loftAdvanced(e.map(e=>e.wrapped),{solid:!a,ruled:t,tolerance:i,...s?{startVertex:s}:{},...c?{endVertex:c}:{}}));return IE(n)?L(n):(I(n),R(gD(`LOFT_NOT_3D`,`Loft did not produce a 3D shape`)))}catch(e){return R(H(`LOFT_FAILED`,`Loft operation failed`,e,void 0,`Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered.`))}}function ZN(e){if(e.length===0)return L([]);let t=P(),n=[],r=e.map(e=>{let r=e.startPoint?t.makeVertex(...SO(e.startPoint)):void 0,i=e.endPoint?t.makeVertex(...SO(e.endPoint)):void 0;return r&&n.push(r),i&&n.push(i),{wires:e.wires.map(e=>e.wrapped),solid:!0,ruled:e.ruled??!0,tolerance:e.tolerance??1e-6,startVertex:r,endVertex:i}});try{let e=t.loftBatch?.(r)??r.map(e=>t.loftAdvanced(e.wires,{solid:e.solid,ruled:e.ruled,tolerance:e.tolerance,startVertex:e.startVertex,endVertex:e.endVertex})),n=[];for(let t of e){let e=F(t);if(!IE(e))return I(e),R(gD(`LOFT_ALL_NOT_3D`,`Batch loft entry did not produce a 3D shape`));n.push(e)}return L(n)}catch(e){return R(H(`LOFT_ALL_FAILED`,`Batch loft operation failed`,e))}finally{for(let e of n)t.dispose(e)}}var QN=new WeakMap;function $N(e,t){return QN.get(e)?.get(t)}function eP(e,t,n){let r=QN.get(e);r||(r=new Map,QN.set(e,r)),r.set(t,n)}function tP(e){return P().isNull(e.wrapped)}function nP(e){return R(U(V.NULL_SHAPE_INPUT,`${e}: shape is a null shape`))}function rP(e){let t=$N(e.wrapped,`volume`);if(t)return L(t);if(tP(e))return nP(`measureVolumeProps`);let n=P(),r=n.shapeType(e.wrapped);if(r!==`solid`&&r!==`compsolid`&&r!==`compound`){let t={mass:0,volume:0,centerOfMass:[0,0,0]};return eP(e.wrapped,`volume`,t),L(t)}let i=n.volume(e.wrapped),a=ND(()=>n.centerOfMass(e.wrapped),V.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!a.ok)return a;let o={mass:i,volume:i,centerOfMass:a.value};return eP(e.wrapped,`volume`,o),L(o)}function iP(e){let t=$N(e.wrapped,`surface`);if(t)return L(t);if(tP(e))return nP(`measureSurfaceProps`);let n=P(),r=n.area(e.wrapped),i=ND(()=>n.centerOfMass(e.wrapped),V.CENTER_OF_MASS_FAILED,`Failed to compute center of mass`);if(!i.ok)return i;let a={mass:r,area:r,centerOfMass:i.value};return eP(e.wrapped,`surface`,a),L(a)}function aP(e){let t=$N(e.wrapped,`linear`);if(t)return L(t);if(tP(e))return nP(`measureLinearProps`);let n=P(),r=n.length(e.wrapped),i={mass:r,length:r,centerOfMass:n.linearCenterOfMass(e.wrapped)};return eP(e.wrapped,`linear`,i),L(i)}function oP(e){let t=rP(e);return t.ok?L(t.value.mass):t}function sP(e){let t=iP(e);return t.ok?L(t.value.mass):t}function cP(e){let t=aP(e);return t.ok?L(t.value.mass):t}function lP(e,t){return tP(e)||tP(t)?nP(`measureDistance`):L(P().distance(e.wrapped,t.wrapped).value)}function uP(e,t){if(tP(e)||tP(t))return nP(`measureDistanceProps`);let n=P().distance(e.wrapped,t.wrapped);return L({distance:n.value,point1:n.point1,point2:n.point2})}function dP(e){if(tP(e))return nP(`createDistanceQuery`);let t=P().createDistanceQuery(e.wrapped);return L({distanceTo(e){return tP(e)?nP(`createDistanceQuery.distanceTo`):L(t.distanceTo(e.wrapped).value)},dispose(){t.dispose()}})}function fP(e,t,n){if(tP(e))return nP(`measureCurvatureAt`);let r=P().surfaceCurvature(e.wrapped,t,n);return L({mean:r.mean,gaussian:r.gaussian,maxCurvature:r.max,minCurvature:r.min,maxDirection:r.maxDirection,minDirection:r.minDirection})}function pP(e){if(tP(e))return nP(`measureCurvatureAtMid`);let t=fk(e),n=(t.uMin+t.uMax)/2,r=(t.vMin+t.vMax)/2,i=P().surfaceCurvature(e.wrapped,n,r);return L({mean:i.mean,gaussian:i.gaussian,maxCurvature:i.max,minCurvature:i.min,maxDirection:i.maxDirection,minDirection:i.minDirection})}function mP(e,t){return e.map(e=>WE(e,t))}function hP(e,t){let n=P(),r=n.iterShapes(e,t),i=[],a=new Map;for(let e of r){let r=n.hashCode(e,W),o=a.get(r);if(o?.some(t=>n.isSame(t,e))){n.dispose(e);continue}let s=UE(e,t);i.push(s),o?o.push(s.wrapped):a.set(r,[s.wrapped])}return i}function gP(e){let t=P(),n=new Map;for(let r of e){let e=t.hashCode(r.wrapped,W),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function _P(e,t,n){let r=P();return e.get(n)?.find(e=>r.isSame(e.wrapped,t))}function vP(e){let t=VD(e);if(t.edgeToFaces)return t.edgeToFaces;let n=P(),r=GD(e),i=gP(WD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`edge`)){let r=n.hashCode(t,W),o=_P(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.edge,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({edge:o.wrapped,face:e.wrapped})}return t.edgeToFaces=a,a}function yP(e){let t=VD(e);if(t.vertexToFaces)return t.vertexToFaces;let n=P(),r=GD(e),i=gP(qD(e)),a=new Map;for(let e of r)for(let t of n.iterShapes(e.wrapped,`vertex`)){let r=n.hashCode(t,W),o=_P(i,t,r);if(n.dispose(t),!o)continue;let s=a.get(r);s||(s=[],a.set(r,s)),s.some(t=>n.isSame(t.vertex,o.wrapped)&&n.isSame(t.face,e.wrapped))||s.push({vertex:o.wrapped,face:e.wrapped})}return t.vertexToFaces=a,a}function bP(e,t){let n=P(),r=vP(e),i=n.hashCode(t.wrapped,W),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.edge,t.wrapped))continue;let r=n.hashCode(e.face,W),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return mP(o,`face`)}function xP(e,t){let n=P(),r=yP(e),i=n.hashCode(t.wrapped,W),a=r.get(i)??[],o=[],s=new Map;for(let e of a){if(!n.isSame(e.vertex,t.wrapped))continue;let r=n.hashCode(e.face,W),i=s.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),o.push(e.face)):(s.set(r,[e.face]),o.push(e.face))}return mP(o,`face`)}function SP(e){return hP(e.wrapped,`edge`)}function CP(e){return hP(e.wrapped,`vertex`)}function wP(e){return hP(e.wrapped,`wire`)}function TP(e){return hP(e.wrapped,`vertex`)}function EP(e,t){let n=P(),r=vP(e),i=hP(t.wrapped,`edge`),a=[],o=new Map;for(let e of i){let i=n.hashCode(e.wrapped,W),s=r.get(i)??[];for(let e of s){if(n.isSame(e.face,t.wrapped))continue;let r=n.hashCode(e.face,W),i=o.get(r);i?i.some(t=>n.isSame(t,e.face))||(i.push(e.face),a.push(e.face)):(o.set(r,[e.face]),a.push(e.face))}}for(let e of i)e[Symbol.dispose]();return mP(a,`face`)}var DP=new Map;function OP(e,t){let n=P(),r=PT()??``;if(DP.get(r)!==!1){let i;try{i=n.sharedEdges(e.wrapped,t.wrapped);let a=i.map(e=>UE(e,`edge`));return DP.set(r,!0),a}catch(e){if(i)for(let e of i)n.dispose(e);if(!l(e))throw e;DP.set(r,!1)}}return kP(e,t)}function kP(e,t){let n=P(),r=n.iterShapes(e.wrapped,`edge`),i=n.iterShapes(t.wrapped,`edge`),a=new Map;for(let e of i){let t=n.hashCode(e,W),r=a.get(t);r||(r=[],a.set(t,r)),r.push(e)}let o=[];for(let e of r)a.get(n.hashCode(e,2147483647))?.some(t=>n.isSame(e,t))?o.push(UE(e,`edge`)):n.dispose(e);for(let e of i)n.dispose(e);return o}var AP=new Map;function jP(e,t){let n=P(),r=PT()??``;if(AP.get(r)!==!1)try{let i=n.adjacentFaces(e.wrapped,t.wrapped);AP.set(r,!0);try{return i.map(e=>n.hashCode(e,W))}finally{for(let e of i)n.dispose(e)}}catch(e){if(!l(e))throw e;AP.set(r,!1)}return EP(e,t).map(e=>n.hashCode(e.wrapped,W))}function MP(e,t){let n=0,r=lk(t);if(e.surfaceType!==void 0){if(r===e.surfaceType)n+=1;else return-1/0}if(e.normal!==void 0){let r=gk(t),i=e.normal[0]*r[0]+e.normal[1]*r[1]+e.normal[2]*r[2];if(i<.707)return-1/0;n+=i}if(e.centroid!==void 0){let r=_k(t),i=e.centroid[0]-r[0],a=e.centroid[1]-r[1],o=e.centroid[2]-r[2],s=i*i+a*a+o*o;if(s>100)return-1/0;n-=s/100}if(e.area!==void 0&&e.area>0){let r=sP(t);if(r.ok&&r.value>0){let t=Math.abs(Math.log(e.area/r.value));t>1&&(n-=t)}}return n}function NP(e){let t=lk(e),n=gk(e),r=_k(e),i=sP(e);return{entityType:`face`,surfaceType:t,normal:n,centroid:r,area:i.ok?i.value:void 0}}var PP=.9;function FP(e){if(e[2]>PP)return`box:top`;if(e[2]<-.9)return`box:bottom`;if(e[1]>PP)return`box:back`;if(e[1]<-.9)return`box:front`;if(e[0]>PP)return`box:right`;if(e[0]<-.9)return`box:left`}function IP(e,t){if(lk(t)!==`PLANE`)return;let n=gk(t)[2];if(n>PP)return`${e}:top`;if(n<-.9)return`${e}:bottom`}function LP(e){return lk(e)===`CYLINDRE`?`cylinder:lateral`:IP(`cylinder`,e)}function RP(e){return lk(e)===`CONE`?`cone:lateral`:IP(`cone`,e)}function zP(e){return lk(e)===`SPHERE`?`sphere:surface`:void 0}var BP={box:e=>FP(gk(e)),cylinder:LP,cone:RP,sphere:zP};function VP(e,t){let n=new Map,r=BP[t],i=P(),a=0;for(let o of i.iterShapes(e.wrapped,`face`)){let e=HE(o,`face`);try{let i=r?.(e),o=i!==void 0&&!n.has(i)?i:`${t}:face_${a}`;n.set(o,[Gj(e)]),a++}finally{VE(e,o)}}return n}function HP(e,t,n){return{origin:e,role:t,hint:NP(n)}}function UP(e,t){let n=[];for(let r of e){if(t.deleted.has(r))continue;let e=t.modified.get(r),i=e&&e.length>0?e:[r];for(let e of i)n.includes(e)||n.push(e)}return n}function WP(e,t,n){let r=e.get(t);if(!r)return e;let i=new Map;for(let[e,t]of r){let r=UP(t,n);r.length>0&&i.set(e,r)}let a=new Map;for(let[n,r]of e)a.set(n,n===t?i:r);return a}var GP=.1,KP=.5;function qP(e,t,n){let r=-1/0,i,a=-1/0,o=[];for(let s of t){let t=n(e,s);t>KP&&o.push([s,t]),t>r?(a=r,r=t,i=s):t>a&&(a=t)}return i!==void 0&&r>KP?r-a<GP&&o.length>1?{kind:`ambiguous`,candidates:o.filter(([,e])=>e>=r-GP).map(([e])=>e)}:{kind:`match`,face:i}:{kind:`none`}}function JP(e,t,n,r){let i=GD(n),a=r??MP,o=t.get(e.origin)?.get(e.role);if(o!==void 0&&o.length>0){let t=i.filter(e=>o.includes(Gj(e)));if(t.length===1){let[e]=t;if(e!==void 0)return{face:e,confidence:`exact`}}else if(t.length===0)return{ref:e,reason:`deleted`};else{let n=qP(e.hint,t,a);if(n.kind===`match`)return{face:n.face,confidence:`geometric-fallback`};if(n.kind===`ambiguous`)return{ref:e,reason:`ambiguous`,candidates:n.candidates}}}let s=qP(e.hint,i,a);return s.kind===`match`?{face:s.face,confidence:`geometric-fallback`}:s.kind===`ambiguous`?{ref:e,reason:`ambiguous`,candidates:s.candidates}:{ref:e,reason:`not-found`}}function YP(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function XP(e){if(e.length===0)return;let t=0,n=0,r=0;for(let i of e){let e=lO(i);t+=e[0],n+=e[1],r+=e[2]}let i=e.length;return[t/i,n/i,r/i]}function ZP(e,t,n){let r=n.get(t);if(!r)return;let i=Gj(e);for(let[e,t]of r)if(t.includes(i))return e}function QP(e,t,n,r){let i=r.get(t)?.get(n);return i===void 0||i.length===0?[]:GD(e).filter(e=>i.includes(Gj(e)))}function $P(e){let t=cP(e);return{entityType:`edge`,length:t.ok?t.value:void 0,midpoint:XP(TP(e))}}function eF(e){let t=new Set,n=[];for(let r of e){let e=Gj(r);t.has(e)||(t.add(e),n.push(r))}return n}var tF=1e-6;function nF(e,t){if(t.length===void 0&&t.midpoint===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=0;if(t.length!==void 0){let n=cP(a);n.ok&&(e+=Math.abs(n.value-t.length))}if(t.midpoint!==void 0){let n=XP(TP(a));n!==void 0&&(e+=YP(t.midpoint,n))}e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<tF))return n}function rF(e,t,n,r){let[i,a]=bP(n,t);if(i===void 0||a===void 0)return;let o=ZP(i,e,r),s=ZP(a,e,r);if(o!==void 0&&s!==void 0)return{origin:e,faceRoles:[o,s],hint:$P(t)}}function iF(e,t,n){let[r,i]=e.faceRoles,a=QP(n,e.origin,r,t),o=QP(n,e.origin,i,t);if(a.length===0||o.length===0)return{ref:e,reason:`not-found`};let s=[];for(let e of a)for(let t of o)s.push(...OP(e,t));let c=eF(s);if(c.length===1){let[e]=c;if(e!==void 0)return{edge:e,confidence:`exact`}}if(c.length>1){let t=nF(c,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:c}:{edge:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var aF=3,oF=1e-6;function sF(e,t){let n=new Set;for(let r of e)for(let e of CP(r)){let r=Gj(e);n.add(r),t.has(r)||t.set(r,e)}return n}function cF(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function lF(e){let t=new Map,n;for(let r of e){let e=sF(r,t);n=n===void 0?e:cF(n,e)}if(n===void 0)return[];let r=[];for(let e of n){let n=t.get(e);n!==void 0&&r.push(n)}return r}function uF(e,t){if(t.position===void 0)return;let n,r=1/0,i=1/0;for(let a of e){let e=YP(lO(a),t.position);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<oF))return n}function dF(e,t,n,r){let i=xP(n,t);if(i.length<aF)return;let a=new Set;for(let t of i){let n=ZP(t,e,r);n!==void 0&&a.add(n)}if(!(a.size<aF))return{origin:e,faceRoles:[...a].sort(),hint:{entityType:`vertex`,position:lO(t)}}}function fF(e,t,n){let r=[];for(let i of e.faceRoles){let a=QP(n,e.origin,i,t);if(a.length===0)return{ref:e,reason:`not-found`};r.push(a)}let i=lF(r);if(i.length===1){let[e]=i;if(e!==void 0)return{vertex:e,confidence:`exact`}}if(i.length>1){let t=uF(i,e.hint);return t===void 0?{ref:e,reason:`ambiguous`,candidates:i}:{vertex:t,confidence:`geometric-fallback`}}return{ref:e,reason:`not-found`}}var pF=.99,mF=.1,hF=1e-6;function gF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function _F(e,t){return GD(e).filter(e=>gF(gk(e),t)>pF)}function vF(e,t,n){let r=new Set([...t,...n].map(Gj)),i=new Set;for(let n of t)for(let t of jP(e,n))i.add(t);let a=[],o=new Set;for(let t of n)for(let n of jP(e,t))r.has(n)||o.has(n)||!i.has(n)||(o.add(n),a.push(n));if(a.length===0)return[];let s=new Map(GD(e).map(e=>[Gj(e),e]));return a.map(e=>s.get(e)).filter(e=>e!==void 0)}function yF(e,t){let n,r=1/0,i=1/0;for(let a of e){let e=YP(_k(a),t);e<r?(i=r,r=e,n=a):e<i&&(i=e)}if(!(n===void 0||i-r<hF))return n}function bF(e,t,n,r,i){let[a,o]=bP(r,n);if(a===void 0||o===void 0)return;let s=ZP(a,e,i),c=ZP(o,e,i);if(s!==void 0&&c!==void 0)return{origin:e,op:t,betweenRoles:[s,c],hint:{entityType:`derived-face`,normalA:gk(a),normalB:gk(o),edgeMidpoint:XP(TP(n))}}}function xF(e,t,n){let r=QP(n,e.origin,e.betweenRoles[0],t);r.length===0&&(r=_F(n,e.hint.normalA));let i=QP(n,e.origin,e.betweenRoles[1],t);if(i.length===0&&(i=_F(n,e.hint.normalB)),r.length===0||i.length===0)return{ref:e,reason:`not-found`};let a=vF(n,r,i).filter(t=>gF(gk(t),e.hint.normalA)>mF&&gF(gk(t),e.hint.normalB)>mF);if(a.length===1){let[e]=a;if(e!==void 0)return{face:e,confidence:`geometric-fallback`}}if(a.length>1){let t=e.hint.edgeMidpoint&&yF(a,e.hint.edgeMidpoint);return t?{face:t,confidence:`geometric-fallback`}:{ref:e,reason:`ambiguous`,candidates:a}}return{ref:e,reason:`not-found`}}function SF(e){return typeof e==`object`&&!!e&&`origin`in e}function CF(e){return SF(e)&&`betweenRoles`in e&&`op`in e}function wF(e){return SF(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length===2}function TF(e){return SF(e)&&Array.isArray(e.faceRoles)&&e.faceRoles.length>=3}function EF(e){return SF(e)&&typeof e.role==`string`}function DF(e){return EF(e)||wF(e)||TF(e)||CF(e)}function OF(e,t){return t===void 0?{ok:!1,reason:e}:{ok:!1,reason:e,candidates:t}}function kF(e,t,n){if(CF(e)){let r=xF(e,t,n);return`face`in r?{ok:!0,entity:r.face}:OF(r.reason,r.candidates)}if(wF(e)){let r=iF(e,t,n);return`edge`in r?{ok:!0,entity:r.edge}:OF(r.reason,r.candidates)}if(TF(e)){let r=fF(e,t,n);return`vertex`in r?{ok:!0,entity:r.vertex}:OF(r.reason,r.candidates)}let r=JP(e,t,n);return`face`in r?{ok:!0,entity:r.face}:OF(r.reason,r.candidates)}function AF(e,t,n){let r=n.get(e.origin);if(r!==void 0)return r;let i=new Map([[e.origin,VP(t,e.origin)]]);return n.set(e.origin,i),i}function jF(e,t){return kF(e,AF(e,t,new Map),t)}function MF(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t!==Object.prototype&&t!==null?!1:!(`wrapped`in e)}function NF(e,t){let n=new Map,r=e=>{if(DF(e)){let r=kF(e,AF(e,t,n),t);return r.ok?r.entity:e}if(Array.isArray(e))return e.map(r);if(MF(e)){let t={};for(let[n,i]of Object.entries(e))t[n]=r(i);return t}return e},i={...e};for(let[t,n]of Object.entries(e))i[t]=r(n);return i}function PF(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(Number(e)^crypto.getRandomValues(new Uint8Array(1))[0]&15>>Number(e)/4).toString(16))}function FF(e=[]){let t=e.map(({shape:e,name:t,color:n,alpha:r})=>{let i=n??`#f00`;i.indexOf(`#`)===0&&(i=i.slice(1)),i.length===3&&(i=i.replace(/([0-9a-f])/gi,`$1$1`));let a=parseInt(i.substring(0,2),16),o=parseInt(i.substring(2,4),16),s=parseInt(i.substring(4,6),16),c=Math.round((r??1)*255);return{shape:e.wrapped,name:t??PF(),color:[a,o,s,c]}});return iE(P().createXCAFDocument(t))}function IF(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function LF(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function RF(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function zF(e){return RF(LF(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function BF(e,t){let[n,r,i,a]=e,o=2*(i*t[2]-a*t[1]),s=2*(a*t[0]-r*t[2]),c=2*(r*t[1]-i*t[0]);return[t[0]+n*o+(i*c-a*s),t[1]+n*s+(a*o-r*c),t[2]+n*c+(r*s-i*o)]}function VF(e,t){let n=t/2,r=Math.sin(n),i=RF(e);return[Math.cos(n),i[0]*r,i[1]*r,i[2]*r]}function HF(e,t){let n=RF(e),r=RF(t),i=IF(n,r);if(i>=1-1e-9)return[1,0,0,0];if(i<=-1+1e-9)return VF(zF(n),Math.PI);let a=LF(n,r),o=Math.hypot(1+i,a[0],a[1],a[2])||1;return[(1+i)/o,a[0]/o,a[1]/o,a[2]/o]}function UF(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;return[n*o-r*s-i*c-a*l,n*s+r*o+i*l-a*c,n*c-r*l+i*o+a*s,n*l+r*c-i*s+a*o]}function WF(e,t,n,r,i){if(n<1)return R(U(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_DIRECTION`,`Pattern direction cannot be zero`));let a=FO(t),o=P().linearPattern(e.wrapped,[...a],r,n).map(e=>F(e));try{return MA(o,{optimisation:`sameFace`,...i,unsafe:!0})}finally{for(let e of o)e[Symbol.dispose]()}}function GF(e,t,n,r=360,i=[0,0,0],a){if(n<1)return R(U(`PATTERN_INVALID_COUNT`,`Pattern count must be at least 1`));if(n===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_AXIS`,`Pattern axis cannot be zero`));let o=r/n,s=P().circularPattern(e.wrapped,[...i],[...t],o,n).map(e=>F(e));try{return MA(s,{optimisation:`sameFace`,...a,unsafe:!0})}finally{for(let e of s)e[Symbol.dispose]()}}function KF(e,t,n,r,i,a,o,s){if(r<1||i<1)return R(U(`PATTERN_INVALID_COUNT`,`Grid pattern counts must be at least 1`));if(r===1&&i===1)return L(e);if(LO(t))return R(U(`PATTERN_ZERO_DIRECTION`,`Grid directionX cannot be zero`));if(LO(n))return R(U(`PATTERN_ZERO_DIRECTION`,`Grid directionY cannot be zero`));let c=P(),l=FO(t),u=FO(n);if(typeof c.gridPattern==`function`)return L(F(c.gridPattern(e.wrapped,[...l],[...u],a,o,r,i)));let d=WF(e,t,r,a,s);if(!d.ok)return d;let f=d.value,p=WF(f,n,i,o,s),m=p.ok&&p.value===f;return f!==e&&!m&&f[Symbol.dispose](),p}function qF(e=[],{unit:t,modelUnit:n}={}){let r=e=>{let t=e;return t.indexOf(`#`)===0&&(t=t.slice(1)),t.length===3&&(t=t.replace(/([0-9a-f])/gi,`$1$1`)),[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},i=P(),a=e.map(({shape:e,name:t,color:n,alpha:i})=>{let[a,o,s]=r(n??`#f00`);return{shape:e.wrapped,name:t??PF(),color:[a,o,s,Math.round((i??1)*255)]}}),o=i.createXCAFDocument(a);try{let e=i.writeXCAFToSTEP(o,{unit:t,modelUnit:n});return e?L(new Blob([e],{type:`application/STEP`})):R(bD(`STEP_EXPORT_FAILED`,`Failed to write STEP file`))}finally{o.delete()}}function JF(e,t={}){return{name:e,children:[],...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function YF(e,t){return{...e,children:[...e.children,t]}}function XF(e,t){let n=e.children.findIndex(e=>e.name===t);if(n===-1)return e;let r=[...e.children];return r.splice(n,1),{...e,children:r}}function ZF(e,t){return{...e,...t.shape===void 0?{}:{shape:t.shape},...t.translate===void 0?{}:{translate:t.translate},...t.rotate===void 0?{}:{rotate:t.rotate},...t.metadata===void 0?{}:{metadata:t.metadata}}}function QF(e,t){if(e.name===t)return e;for(let n of e.children){let e=QF(n,t);if(e)return e}}function $F(e,t,n=0){t(e,n);for(let r of e.children)$F(r,t,n+1)}function eI(e){let t=1;for(let n of e.children)t+=eI(n);return t}function tI(e){let t=[];return $F(e,e=>{e.shape&&t.push(e.shape)}),t}var nI=Math.PI/180;function rI(e,t,n){return Math.min(n,Math.max(t,e))}function iI(e){let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]}function aI(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function oI(e){return iI(aI(e,Math.abs(e[0])<.9?[1,0,0]:[0,1,0]))}function sI(e,t,n,r,i){let a=n.min??r,o=n.max??i,s=Math.min(a,o),c=Math.max(a,o);return{kind:e,axis:iI(t),min:s,max:c,value:rI(n.value??0,s,c)}}function cI(e,t,n,r,i){let a=i[0]??{kind:`rotation`,axis:[0,0,1],min:0,max:0,value:0};return{type:e,parent:t,child:n,axis:{origin:r.origin,direction:iI(r.direction)},min:a.min,max:a.max,value:a.value,dofs:i}}function lI(e,t,n,r={}){return cI(`revolute`,e,t,n,[sI(`rotation`,n.direction,r,-180,180)])}function uI(e,t,n,r={}){return cI(`prismatic`,e,t,n,[sI(`translation`,n.direction,r,0,100)])}function dI(e,t,n,r={}){return cI(`cylindrical`,e,t,n,[sI(`rotation`,n.direction,r.rotation??{},-180,180),sI(`translation`,n.direction,r.translation??{},0,100)])}function fI(e,t,n,r={}){let i=iI(n.direction),a;if(r.uDirection){let e=r.uDirection,t=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],n=[e[0]-t*i[0],e[1]-t*i[1],e[2]-t*i[2]];a=Math.hypot(n[0],n[1],n[2])<1e-9?oI(i):iI(n)}else a=oI(i);let o=iI(aI(i,a));return cI(`planar`,e,t,{origin:n.origin,direction:i},[sI(`translation`,a,r.u??{},-100,100),sI(`translation`,o,r.v??{},-100,100),sI(`rotation`,i,r.rotation??{},-180,180)])}function pI(e,t,n,r={}){return cI(`spherical`,e,t,{origin:n,direction:[0,0,1]},[sI(`rotation`,[1,0,0],r.x??{},-180,180),sI(`rotation`,[0,1,0],r.y??{},-180,180),sI(`rotation`,[0,0,1],r.z??{},-180,180)])}function mI(e,t){let n=e.dofs.map((e,n)=>{let r=t[n];return r===void 0?e:{...e,value:rI(r,e.min,e.max)}}),r=n[0];return r?{...e,dofs:n,value:r.value}:{...e,dofs:n}}function hI(e,t){return mI(e,[t])}function gI(e,t,n){if(t.kind===`translation`)return{position:[t.axis[0]*n,t.axis[1]*n,t.axis[2]*n],rotation:[1,0,0,0]};let r=VF(t.axis,n*nI),i=BF(r,e);return{position:[e[0]-i[0],e[1]-i[1],e[2]-i[2]],rotation:r}}function _I(e,t=e.value){let n=Array.isArray(t)?t:void 0,r=n?void 0:t,i=e.axis.origin,a=yI;for(let t=0;t<e.dofs.length;t++){let o=e.dofs[t];if(!o)continue;let s=n?n[t]??o.value:t===0?r??o.value:o.value;a=bI(a,gI(i,o,rI(s,o.min,o.max)))}return a}function vI(e,t){let n=e.joints??[];return{...e,joints:[...n,t]}}var yI={position:[0,0,0],rotation:[1,0,0,0]};function bI(e,t){let n=BF(e.rotation,t.position);return{position:[e.position[0]+n[0],e.position[1]+n[1],e.position[2]+n[2]],rotation:UF(e.rotation,t.rotation)}}function xI(e){let t=[];return $F(e,e=>{e.joints&&t.push(...e.joints)}),t}function SI(e,t={}){let n=[],r=new Set;$F(e,e=>{r.add(e.name),e.joints&&n.push(...e.joints)});let i=new Map;for(let e of n)i.set(e.child,e),r.add(e.parent),r.add(e.child);let a=new Map;for(let e of r)i.has(e)||a.set(e,yI);let o=[...n],s=!0;for(;s&&o.length>0;){s=!1;for(let e=o.length-1;e>=0;e--){let n=o[e];if(!n)continue;let r=a.get(n.parent);if(!r||(o.splice(e,1),s=!0,a.has(n.child)))continue;let i=t[n.child]??n.value,c=n.offset?bI(_I(n,i),n.offset):_I(n,i);a.set(n.child,bI(r,c))}}for(let e of o)a.has(e.child)||a.set(e.child,yI);return a}function CI(e){return xI(e).reduce((e,t)=>e+t.dofs.length,0)}var wI={position:[0,0,0],rotation:[1,0,0,0]};function TI(e,t){let n=BF(e.rotation,t);return[n[0]+e.position[0],n[1]+e.position[1],n[2]+e.position[2]]}function EI(e){return[e[0],-e[1],-e[2],-e[3]]}function DI(e,t){let[n,r,i,a]=UF(t,EI(e)),o=Math.hypot(n,r,i,a)||1;n/=o,r/=o,i/=o,a/=o,n<0&&(n=-n,r=-r,i=-i,a=-a);let s=Math.hypot(r,i,a);if(s<1e-12)return[0,0,0];let c=2*Math.atan2(s,n)/s;return[r*c,i*c,a*c]}function OI(e,t){let n=[];$F(e,e=>{e.joints&&n.push(...e.joints)});let r=new Map;for(let e of n)r.set(e.child,e);let i=[],a=new Set,o=t;for(;o&&r.has(o)&&!a.has(o);){a.add(o);let e=r.get(o);if(!e)break;i.push(e),o=e.parent}return i.reverse()}function kI(e,t){return e[t]??0}function AI(e,t,n){let r=n+1,i=new Float64Array(n*r);for(let a=0;a<n;a++){for(let t=0;t<n;t++)i[a*r+t]=kI(e,a*n+t);i[a*r+n]=kI(t,a)}for(let e=0;e<n;e++){let t=e;for(let a=e+1;a<n;a++)Math.abs(kI(i,a*r+e))>Math.abs(kI(i,t*r+e))&&(t=a);if(Math.abs(kI(i,t*r+e))<1e-12)return null;if(t!==e)for(let n=e;n<r;n++){let a=kI(i,e*r+n);i[e*r+n]=kI(i,t*r+n),i[t*r+n]=a}let a=kI(i,e*r+e);for(let t=e;t<r;t++)i[e*r+t]=kI(i,e*r+t)/a;for(let t=0;t<n;t++){if(t===e)continue;let n=kI(i,t*r+e);if(n!==0)for(let a=e;a<r;a++)i[t*r+a]=kI(i,t*r+a)-n*kI(i,e*r+a)}}let a=new Float64Array(n);for(let e=0;e<n;e++)a[e]=kI(i,e*r+n);return a}function jI(e,t){let n=[],r=[],i=[],a=[];for(let o of e){let e=t?.[o.child];n.push({child:o.child,count:o.dofs.length}),o.dofs.forEach((t,n)=>{let o=(Array.isArray(e)?e[n]:n===0?e:void 0)??t.value;r.push(Math.min(t.max,Math.max(t.min,o))),i.push(t.min),a.push(t.max)})}return{segments:n,q:Float64Array.from(r),lo:Float64Array.from(i),hi:Float64Array.from(a)}}function MI(e,t){let n={},r=0;for(let i of e){let e=[];for(let n=0;n<i.count;n++)e.push(kI(t,r++));n[i.child]=e}return n}function NI(e,t,n,r,i){let a=TI(t,r);if(e[0]=n.position[0]-a[0],e[1]=n.position[1]-a[1],e[2]=n.position[2]-a[2],i===6&&n.rotation){let r=DI(t.rotation,n.rotation);e[3]=r[0],e[4]=r[1],e[5]=r[2]}let o=0;for(let t=0;t<i;t++)o+=kI(e,t)**2;return Math.sqrt(o)}function PI(e,t,n,r,i,a,o,s,c,l){let u=TI(o,s);for(let d=0;d<n;d++){let f=kI(t,d),p=f+c>kI(a,d)&&f-c>=kI(i,d)?-c:c;t[d]=f+p;let m=l(t);t[d]=f;let h=TI(m,s);if(e[d]=(h[0]-u[0])/p,e[n+d]=(h[1]-u[1])/p,e[2*n+d]=(h[2]-u[2])/p,r===6){let t=DI(o.rotation,m.rotation);e[3*n+d]=t[0]/p,e[4*n+d]=t[1]/p,e[5*n+d]=t[2]/p}}}function FI(e,t,n,r,i){let a=new Float64Array(r*r),o=i*i;for(let t=0;t<r;t++)for(let i=0;i<r;i++){let s=0;for(let r=0;r<n;r++)s+=kI(e,t*n+r)*kI(e,i*n+r);a[t*r+i]=s+(t===i?o:0)}let s=AI(a,t,r);if(!s)return null;let c=new Float64Array(n);for(let t=0;t<n;t++){let i=0;for(let a=0;a<r;a++)i+=kI(e,a*n+t)*kI(s,a);c[t]=i}return c}function II(e,t,n,r={}){let i=r.maxIterations??200,a=r.tolerance??1e-5,o=r.damping??.05,s=r.tip??[0,0,0],c=n.rotation===void 0?3:6,{segments:l,q:u,lo:d,hi:f}=jI(OI(e,t),r.seed),p=u.length,m=n=>SI(e,MI(l,n)).get(t)??wI,h=new Float64Array(c),g=new Float64Array(c*p),_=m(u),v=NI(h,_,n,s,c),y=0;for(;y<i&&p>0&&v>a;y++){PI(g,u,p,c,d,f,_,s,1e-6,m);let e=FI(g,h,p,c,o);if(!e)break;for(let t=0;t<p;t++){let n=kI(u,t)+kI(e,t);u[t]=Math.min(kI(f,t),Math.max(kI(d,t),n))}_=m(u),v=NI(h,_,n,s,c)}return{values:MI(l,u),converged:v<=a,iterations:y,error:v}}function LI(e,t){return e.dofs.map((e,n)=>{let r=(Array.isArray(t)?t[n]:n===0?t:void 0)??e.value;return Math.min(e.max,Math.max(e.min,r))})}function RI(e,t,n,r){let i=[];$F(e,e=>{e.joints&&i.push(...e.joints)});let a=i.map(e=>({child:e.child,a:LI(e,t[e.child]),b:LI(e,n[e.child])})),o=Math.max(1,Math.floor(r)),s=[];for(let t=0;t<=o;t++){let n=t/o,r={};for(let e of a)r[e.child]=e.a.map((t,r)=>t+((e.b[r]??t)-t)*n);s.push({t:n,values:r,poses:SI(e,r)})}return s}var zI=Math.PI/180;function BI(e,t,n,r){let i=e*zI,a=r*zI,o=UF(VF([0,0,1],i),VF([1,0,0],a));return{position:[n*Math.cos(i),n*Math.sin(i),t],rotation:o}}function VI(e,t={}){let n=t.base??`base`,r=e.map((e,t)=>e.name??`link${t+1}`);return e.map((e,t)=>{let i=t===0?n:r[t-1]??`link${t}`,a=r[t]??`link${t+1}`,o=BI(e.theta,e.d,e.a,e.alpha),s={origin:[0,0,0],direction:[0,0,1]},c={...e.min===void 0?{}:{min:e.min},...e.max===void 0?{}:{max:e.max},...e.value===void 0?{}:{value:e.value}};return{...e.type===`prismatic`?uI(i,a,s,c):lI(i,a,s,c),offset:o}})}var HI=Math.PI/180,UI=180/Math.PI;function WI(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function GI(e){return String(e===0?0:e)}function KI(e){return`${GI(e[0])} ${GI(e[1])} ${GI(e[2])}`}function qI(e,t={}){let n=t.name??`robot`,r=t.effort??0,i=t.velocity??0,a=t.meshes??{},o=[],s=[];$F(e,e=>{o.push(e.name),e.joints&&s.push(...e.joints)});for(let e of s){if(e.type!==`revolute`&&e.type!==`prismatic`)return R(U(V.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' is '${e.type}'; URDF supports only revolute and prismatic joints`));if(e.offset)return R(U(V.VALIDATION_FAILED,`exportURDF: joint '${e.parent}->${e.child}' carries a fixed offset (e.g. a DH link) that URDF cannot represent as a single joint`))}let c=[`<?xml version="1.0"?>`,`<robot name="${WI(n)}">`];for(let e of o){let t=a[e];t?c.push(` <link name="${WI(e)}">`,` <visual><geometry><mesh filename="${WI(t)}"/></geometry></visual>`,` </link>`):c.push(` <link name="${WI(e)}"/>`)}for(let e of s){let t=e.type===`revolute`,n=t?e.min*HI:e.min,a=t?e.max*HI:e.max,o=e.type===`prismatic`?[0,0,0]:e.axis.origin;c.push(` <joint name="${WI(`${e.parent}_to_${e.child}`)}" type="${e.type}">`,` <parent link="${WI(e.parent)}"/>`,` <child link="${WI(e.child)}"/>`,` <origin xyz="${KI(o)}" rpy="0 0 0"/>`,` <axis xyz="${KI(e.axis.direction)}"/>`,` <limit lower="${GI(n)}" upper="${GI(a)}" effort="${GI(r)}" velocity="${GI(i)}"/>`,` </joint>`)}return c.push(`</robot>`,``),L(c.join(`
|
|
16
16
|
`))}function JI(e,t){return RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`).exec(e)?.[1]}function YI(e,t){if(!e)return t;let n=e.trim().split(/\s+/).map(Number);return[n[0]??0,n[1]??0,n[2]??0]}function XI(e,t){return BF(UF(UF(VF([0,0,1],t[2]),VF([0,1,0],t[1])),VF([1,0,0],t[0])),e)}function ZI(e){let t=/<robot\b([^>]*)>/.exec(e);if(!t)return R(U(V.VALIDATION_FAILED,`importURDF: no <robot> element found`));let n=JI(t[1]??``,`name`)??`robot`,r=[],i=/<link\b([^>]*?)(?:\/>|>)/g;for(let t=i.exec(e);t;t=i.exec(e)){let e=JI(t[1]??``,`name`);e&&r.push(e)}let a=[],o=/<joint\b([^>]*)>([\s\S]*?)<\/joint>/g;for(let t=o.exec(e);t;t=o.exec(e)){let e=t[1]??``,n=t[2]??``,r=JI(e,`type`)??`fixed`;if(r===`fixed`||r===`floating`||r===`planar`)continue;let i=/<parent\b([^>]*?)\/?>/.exec(n),o=/<child\b([^>]*?)\/?>/.exec(n),s=JI(i?.[1]??``,`link`),c=JI(o?.[1]??``,`link`);if(!s||!c)return R(U(V.VALIDATION_FAILED,`importURDF: joint missing parent/child link (${JI(e,`name`)??`unnamed`})`));let l=/<origin\b([^>]*?)\/?>/.exec(n),u=/<axis\b([^>]*?)\/?>/.exec(n),d=/<limit\b([^>]*?)\/?>/.exec(n),f=YI(JI(l?.[1]??``,`xyz`),[0,0,0]),p=YI(JI(l?.[1]??``,`rpy`),[0,0,0]),m=XI(YI(JI(u?.[1]??``,`xyz`),[1,0,0]),p),h=Number(JI(d?.[1]??``,`lower`)??NaN),g=Number(JI(d?.[1]??``,`upper`)??NaN);if(r===`prismatic`){let e=Number.isFinite(h)&&Number.isFinite(g)?{min:h,max:g}:{};a.push(uI(s,c,{origin:f,direction:m},e))}else if(r===`revolute`||r===`continuous`){let e=r===`continuous`||!Number.isFinite(h)||!Number.isFinite(g)?{min:-180,max:180}:{min:h*UI,max:g*UI};a.push(lI(s,c,{origin:f,direction:m},e))}else return R(U(V.VALIDATION_FAILED,`importURDF: joint '${JI(e,`name`)??`unnamed`}' has unrecognized type '${r}'`))}return L({name:n,links:r,joints:a})}function QI(){return{steps:[],shapes:new Map}}function $I(e,t,n){let r={...t,timestamp:Date.now()},i=new Map(e.shapes);return i.set(t.outputId,n),{steps:[...e.steps,r],shapes:i}}function eL(e){if(e.steps.length===0)return e;let t=e.steps.slice(0,-1),n=new Set;for(let e of t){n.add(e.outputId);for(let t of e.inputIds)n.add(t)}let r=new Map;for(let[t,i]of e.shapes)n.has(t)&&r.set(t,i);return{steps:t,shapes:r}}function tL(e,t){return e.steps.find(e=>e.id===t)}function nL(e,t){return e.shapes.get(t)}function rL(e){return e.steps.length}function iL(e,t){let n=e.steps.findIndex(e=>e.id===t);return n===-1?[]:e.steps.slice(n)}function aL(e,t,n){let r=new Map(e.shapes);return r.set(t,n),{...e,shapes:r}}function oL(){return{operations:new Map}}function sL(e,t,n){let r=new Map(e.operations);return r.set(t,n),{operations:r}}function cL(e,t){let[n,r]=t;return n!==void 0&&r===void 0&&IE(n)?NF(e,n):{...e}}function lL(e,t){let n=new Set(e.steps.map(e=>e.outputId)),r={steps:[],shapes:new Map};for(let[t,i]of e.shapes)n.has(t)||(r=aL(r,t,i));for(let n of e.steps){let e=t.operations.get(n.type);if(!e)return R(yD(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${n.type}`));let i=[];for(let e of n.inputIds){let t=r.shapes.get(e);if(!t)return R(yD(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${n.id}`));i.push(t)}try{let t=e(i,cL(n.parameters,i));r=$I(r,{id:n.id,type:n.type,parameters:n.parameters,inputIds:n.inputIds,outputId:n.outputId},t)}catch(e){return R(yD(`REPLAY_STEP_FAILED`,`Step ${n.id} (${n.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return L(r)}function uL(e,t,n){let r=e.steps.findIndex(e=>e.id===t);if(r===-1)return R(yD(`REPLAY_STEP_NOT_FOUND`,`Step not found: ${t}`));let i=new Map(e.shapes);for(let t=r;t<e.steps.length;t++){let n=e.steps[t];n&&i.delete(n.outputId)}let a={steps:e.steps.slice(0,r),shapes:i};for(let t=r;t<e.steps.length;t++){let r=e.steps[t];if(!r)continue;let i=n.operations.get(r.type);if(!i)return R(yD(`REPLAY_UNKNOWN_OP`,`Unknown operation type: ${r.type}`));let o=[];for(let e of r.inputIds){let t=a.shapes.get(e);if(!t)return R(yD(`REPLAY_MISSING_INPUT`,`Missing input shape: ${e} for step ${r.id}`));o.push(t)}try{let e=i(o,cL(r.parameters,o));a=$I(a,{id:r.id,type:r.type,parameters:r.parameters,inputIds:r.inputIds,outputId:r.outputId},e)}catch(e){return R(yD(`REPLAY_STEP_FAILED`,`Step ${r.id} (${r.type}) failed: ${e instanceof Error?e.message:String(e)}`))}}return L(a)}function dL(e,t,n,r){return e.steps.findIndex(e=>e.id===t)===-1?R(yD(`MODIFY_STEP_NOT_FOUND`,`Step not found: ${t}`)):uL({steps:e.steps.map(e=>e.id===t?{...e,parameters:n}:e),shapes:e.shapes},t,r)}function fL(e){let t={};for(let[n,r]of e.shapes){let e=Wj(r);if(!e.ok)return R(yD(`SERIALIZE_SHAPE_FAILED`,`Failed to serialize shape "${n}": ${e.error.message}`));t[n]=e.value}return L({steps:e.steps,shapes:t})}function pL(e){let t=new Map;for(let[n,r]of Object.entries(e.shapes))try{let e=ok(r);if(!e.ok)return R(yD(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e.error.message}`));t.set(n,e.value)}catch(e){return R(yD(`DESERIALIZE_SHAPE_FAILED`,`Failed to deserialize shape "${n}": ${e instanceof Error?e.message:String(e)}`))}return L({steps:e.steps,shapes:t})}function mL(e){try{var t=GT();let{radius:n,pitch:r,height:i,depth:a=.6*r,toothHalfWidth:o=.42*r,crest:s=0,sectionsPerTurn:c=20,lefthand:l=!1,inward:u=!1}=e;if(!(n>0))return R(U(`THREAD_INVALID_RADIUS`,`radius must be > 0`));if(!(r>0))return R(U(`THREAD_INVALID_PITCH`,`pitch must be > 0`));if(!(i>0))return R(U(`THREAD_INVALID_HEIGHT`,`height must be > 0`));if(!(a>0))return R(U(`THREAD_INVALID_DEPTH`,`depth must be > 0`));if(s<0||s>=o)return R(U(`THREAD_INVALID_CREST`,`crest must be >= 0 and < toothHalfWidth`));if(c<3)return R(U(`THREAD_TOO_FEW_SECTIONS`,`sectionsPerTurn must be >= 3`));let d=i/r,f=Math.max(2,Math.round(d*c)),p=l?-1:1,m=u?-a:a,h=u?.3:-.3,g=o,_=t.u(new aE),v=[];for(let e=0;e<=f;e++){let t=p*e*2*Math.PI/c,i=r*Math.abs(t)/(2*Math.PI),a=n*Math.cos(t),o=n*Math.sin(t),l=Math.cos(t),u=Math.sin(t),d=(e,t)=>[a+e*l,o+e*u,i+t],f=s>0?[d(h,-g),d(m,-s),d(m,s),d(h,g)]:[d(h,-g),d(m,0),d(h,g)],y=jj(f.map((e,t)=>_.register(Sj(e,f[(t+1)%f.length]))));if(!KE(y))return y;v.push(_.register(y.value))}return XN(v,{ruled:!0})}catch(e){t.e=e}finally{t.d()}}var hL=1e-9,gL=1e-8,_L=1e-6,vL=([e,t],[n,r],i=_L)=>Math.abs(e-n)<=i&&Math.abs(t-r)<=i,yL=([e,t],[n,r])=>[e+n,t+r],bL=([e,t],[n,r])=>[e-n,t-r],xL=([e,t],n)=>[e*n,t*n],SL=([e,t],[n,r]=[0,0])=>Math.sqrt((e-n)**2+(t-r)**2),CL=([e,t],[n,r]=[0,0])=>(e-n)**2+(t-r)**2;function wL([e,t],[n,r]){return e*r-t*n}var TL=([e,t],[n,r]=[0,0])=>Math.atan2(r*e-t*n,e*n+t*r),EL=([e,t],[n,r]=[0,0])=>Math.atan2(r-t,n-e),DL=(e,t,n=[0,0])=>{let[r,i]=e,[a,o]=n,s=r-a,c=i-o,l=Math.sin(t),u=Math.cos(t),d=s*u-c*l,f=s*l+c*u;return[d+a,f+o]};function OL([e,t]){let n=Math.sqrt(e*e+t*t);return n<1e-12?[0,0]:[e/n,t/n]}var kL=(e,t)=>[Math.cos(t)*e,Math.sin(t)*e],AL=([e,t])=>[Math.sqrt(e*e+t*t),Math.atan2(t,e)];function jL(e,t){let n,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(t(a)){if(r++,r===1)n=a;else break}}return r===1?L(n):R(xD(`FINDER_NOT_UNIQUE`,`Finder expected a unique match but found ${r===0?0:`2+`} element(s)`))}function ML(e,t,n,r){let i=e=>n([...t,e]),a=e=>t.every(t=>t(e));function o(t){switch(e){case`edge`:return WD(t);case`face`:return GD(t);case`wire`:return KD(t);case`vertex`:return qD(t)}}let s=e=>{let n=o(e);return t.length===0?n.slice():n.filter(a)},c=()=>ML(e,[],n,r),l={_filters:t,_topoKind:e,when:e=>i(e),inList:e=>{let t=new Map;for(let n of e){let e=Gj(n),r=t.get(e);r?r.push(n):t.set(e,[n])}return i(e=>{let n=t.get(Gj(e));return!!n&&n.some(t=>qj(t,e))})},not:e=>{let t=e(c());return i(e=>!t.shouldKeep(e))},either:e=>{let t=e.map(e=>e(c()));return i(e=>t.some(t=>t.shouldKeep(e)))},findAll:e=>s(e),findUnique:e=>jL(o(e),a),shouldKeep:a,and:e=>i(t=>e.shouldKeep(t)),or:e=>{let t=a;return n([n=>t(n)||e.shouldKeep(n)])},negate:()=>{let e=a;return n([t=>!e(t)])}},u=r(l,i);return{...l,...u}}var NL={X:[1,0,0],Y:[0,1,0],Z:[0,0,1]};function PL(e){return typeof e==`string`?NL[e]??[0,0,1]:e}function FL(e,t,n){let r=P(),i=r.makeVertex(t[0],t[1],t[2]);return t=>{let a=r.distance(i,t.wrapped).value;return Math.abs(a-e)<n}}function IL(e,t){let n=FO(PL(e));return e=>{let r=P(),[i,a]=r.curveParameters(e.wrapped),o=(i+a)/2,{tangent:s}=r.curveTangent(e.wrapped,o),c=FO(s),l=Math.acos(Math.min(1,Math.abs(AO(c,n))));return Math.abs(l-wD*t)<1e-6}}function LL(e){return ML(`edge`,e,LL,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(IL(e,t)),ofLength:(e,t=.001)=>n(n=>Math.abs(tM(n)-e)<t),ofCurveType:e=>n(t=>Xj(t)===e),parallelTo:(t=`Z`)=>LL(e).inDirection(t,0),atDistance:(e,t=[0,0,0])=>n(FL(e,t,1e-6))}))}function RL(){return LL([])}function zL(e,t){let n=FO(PL(e));return e=>{let r=gk(e),i=Math.acos(Math.min(1,Math.abs(AO(FO(r),n))));return Math.abs(i-wD*t)<1e-6}}function BL(e){return ML(`face`,e,BL,(t,n)=>({inDirection:(e=`Z`,t=0)=>n(zL(e,t)),parallelTo:(t=`Z`)=>BL(e).inDirection(t,0),ofSurfaceType:e=>n(t=>{let n=ck(t);return KE(n)&&n.value===e}),ofArea:(e,t=.001)=>n(n=>{let r=sP(n);return KE(r)&&Math.abs(r.value-e)<t}),atDistance:(e,t=[0,0,0])=>n(FL(e,t,1e-6))}))}function VL(){return BL([])}function HL(e){return ML(`wire`,e,HL,(e,t)=>({isClosed:()=>t(e=>rM(e)),isOpen:()=>t(e=>!rM(e)),ofEdgeCount:e=>t(t=>WD(t).length===e)}))}function UL(){return HL([])}function WL(e,t){return typeof e==`object`&&`_topoKind`in e?e.findUnique(t):typeof e!=`function`&&ME(e)?L(e):e(VL()).findUnique(t)}function GL(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`}function KL(e,t){let n=10**t,r=t<0?e:.01/n+e;return Math.round(r*n)/n}function qL(e){return Math.round(e*100)/100}function JL(e){return Math.round(e*1e5)/1e5}var YL=([e,t])=>`(${qL(e)},${qL(t)})`,XL=(e,t=1e-9)=>{let n=e;return Math.abs(e)<t&&(n=0),n.toFixed(-Math.log10(t))},ZL=(e,t=1e-9)=>Array.from(new Map(e.map(([e,n])=>[`[${XL(e,t)},${XL(n,t)}]`,[e,n]])).values()),QL=class{_wrapped;_deleted=!1;constructor(e){this._wrapped=e??NT().createBoundingBox2d(),sE(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,cE(this._wrapped),typeof this._wrapped.delete==`function`&&this._wrapped.delete())}[Symbol.dispose](){this.delete()}get repr(){let[e,t]=this.bounds;return`${YL(e)} - ${YL(t)}`}get bounds(){let{xMin:e,yMin:t,xMax:n,yMax:r}=NT().getBBox2dBounds(this.wrapped);return[[e,t],[n,r]]}get center(){let[[e,t],[n,r]]=this.bounds;return[e+(n-e)/2,t+(r-t)/2]}get width(){let[[e],[t]]=this.bounds;return Math.abs(t-e)}get height(){let[[,e],[,t]]=this.bounds;return Math.abs(t-e)}outsidePoint(e=1){let[t,n]=this.bounds,r=n[0]-t[0],i=n[1]-t[1];return[n[0]+r/100*e,n[1]+i/100*e*.9]}add(e){NT().mergeBBox2d(this.wrapped,e.wrapped)}isOut(e){return NT().isBBox2dOut(this.wrapped,e.wrapped)}containsPoint(e){return!NT().isBBox2dOutPoint(this.wrapped,e[0],e[1])}},$L=([e,t])=>{let n=OL([e,t]);return n[0]===0&&n[1]===0&&i(`normalize2d`,`Cannot normalize zero-length vector`),n};function eR(e){return new tR(P().deserializeCurve2d(e))}var tR=class e{_wrapped;_deleted=!1;_boundingBox;_firstPoint=null;_lastPoint=null;_firstParameter=null;_lastParameter=null;constructor(e){this._wrapped=P().wrapCurve2dHandle(e),this._boundingBox=null,typeof this._wrapped.delete==`function`&&sE(this,this._wrapped)}get wrapped(){if(this._deleted)throw Error(`This object has been deleted`);return this._wrapped}delete(){this._deleted||(this._deleted=!0,this._boundingBox&&=(this._boundingBox.delete(),null),typeof this._wrapped.delete==`function`&&(cE(this._wrapped),this._wrapped.delete()))}[Symbol.dispose](){this.delete()}get boundingBox(){if(this._boundingBox)return this._boundingBox;let e=P(),t=e.createBoundingBox2d();return e.addCurveToBBox2d(t,this.wrapped,1e-6),this._boundingBox=new QL(t),this._boundingBox}get repr(){return`${this.geomType} ${YL(this.firstPoint)} - ${YL(this.lastPoint)}`}serialize(){return P().serializeCurve2d(this.wrapped)}value(e){return P().evaluateCurve2d(this.wrapped,e)}get firstPoint(){return this._firstPoint===null&&(this._firstPoint=this.value(this.firstParameter)),this._firstPoint}get lastPoint(){return this._lastPoint===null&&(this._lastPoint=this.value(this.lastParameter)),this._lastPoint}get firstParameter(){return this._firstParameter===null&&(this._firstParameter=P().getCurve2dBounds(this.wrapped).first),this._firstParameter}get lastParameter(){return this._lastParameter===null&&(this._lastParameter=P().getCurve2dBounds(this.wrapped).last),this._lastParameter}get geomType(){return P().getCurve2dType(this.wrapped)}clone(){let t=new e(P().copyCurve2d(this.wrapped));return t._firstPoint=this._firstPoint,t._lastPoint=this._lastPoint,t._firstParameter=this._firstParameter,t._lastParameter=this._lastParameter,t}reverse(){P().reverseCurve2d(this.wrapped);let e=this._firstPoint;this._firstPoint=this._lastPoint,this._lastPoint=e;let t=this._firstParameter;this._firstParameter=this._lastParameter,this._lastParameter=t}distanceFromPoint(e){let t=P().projectPointOnCurve2d(this.wrapped,e[0],e[1]),n=t?t.distance:1/0;return Math.min(n,SL(e,this.firstPoint),SL(e,this.lastPoint))}distanceFromCurve(e){let t;try{t=P().distanceBetweenCurves2d(this.wrapped,e.wrapped,this.firstParameter,this.lastParameter,e.firstParameter,e.lastParameter)}catch{t=1/0}return Math.min(t,this.distanceFromPoint(e.firstPoint),this.distanceFromPoint(e.lastPoint),e.distanceFromPoint(this.firstPoint),e.distanceFromPoint(this.lastPoint))}distanceFrom(e){return GL(e)?this.distanceFromPoint(e):this.distanceFromCurve(e)}isOnCurve(e){return this.distanceFromPoint(e)<1e-9}parameter(e,t=1e-9){let n,r,i=!1;try{let t=P().projectPointOnCurve2d(this.wrapped,e[0],e[1]);t?(n=t.distance,r=t.param):i=!0}catch{i=!0}return i?vL(e,this.firstPoint,t)?L(this.firstParameter):vL(e,this.lastPoint,t)?L(this.lastParameter):R(yD(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n===void 0||r===void 0?R(yD(`PARAMETER_NOT_FOUND`,`Failed to find parameter`)):n>t?R(yD(`POINT_NOT_ON_CURVE`,`Point ${YL(e)} not on curve ${this.repr}, ${n.toFixed(9)}`)):L(r)}tangentAt(e){let t;if(Array.isArray(e))t=B(this.parameter(e));else{let n=P().getCurve2dBounds(this.wrapped);t=(n.last-n.first)*e+n.first}return P().evaluateCurve2dD1(this.wrapped,t).tangent}splitAt(n,r=1e-9){let i=n.map(e=>GL(e)?B(this.parameter(e,r)):e);i=Array.from(new Map(i.map(e=>[KL(e,-Math.log10(r)),e])).values()).sort((e,t)=>e-t);let a=this.firstParameter,o=this.lastParameter;return a>o&&i.reverse(),Math.abs(t(i,0)-a)<r*100&&(i=i.slice(1)),!i.length||(Math.abs(t(i,i.length-1)-o)<r*100&&(i=i.slice(0,-1)),!i.length)?[this]:P().splitCurve2d(this.wrapped,i).map(t=>new e(t))}},nR=(e,t=1e-4,n=`C0`,r=200)=>new tR(NT().approximateCurve2dAsBSpline(e.wrapped,t,n,r)),rR=e=>(e.geomType!==`BSPLINE_CURVE`&&i(`BSplineToBezier`,`You can only convert a Bspline`),NT().decomposeBSpline2dToBeziers(e.wrapped).map(e=>new tR(e)));function iR(e,t={tolerance:1e-4,continuity:`C0`,maxSegments:300}){let n=NT();return e.flatMap(e=>{let r=e.geomType;if(r===`ELLIPSE`||r===`CIRCLE`&&vL(e.firstPoint,e.lastPoint))return e.splitAt([(e.firstParameter+e.lastParameter)/2]);if([`LINE`,`ELLIPSE`,`CIRCLE`].includes(r))return e;if(r===`BEZIER_CURVE`){let t=n.getCurve2dBezierDegree(e.wrapped);if(t!==null&&[1,2,3].includes(t))return e}return iR(rR(r===`BSPLINE_CURVE`?e:nR(e,t.tolerance,t.continuity,t.maxSegments)),t)})}var aR=(e,t)=>{let n=new tR(P().makeLine2d(e[0],e[1],t[0],t[1]));return vL(n.firstPoint,e)||n.reverse(),n},oR=(e,t,n)=>{let r=new tR(P().makeArc2dThreePoints(e[0],e[1],t[0],t[1],n[0],n[1]));if(!vL(r.firstPoint,e)){let e=P().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new tR(e)}return r},sR=(e,t,n)=>{let r=new tR(P().makeArc2dTangent(e[0],e[1],t[0],t[1],n[0],n[1]));if(!vL(r.firstPoint,e)){let e=P().trimCurve2d(r.wrapped,r.lastParameter,r.firstParameter);r.delete(),r=new tR(e)}return r},cR=(e,t=[0,0])=>new tR(P().makeCircle2d(t[0],t[1],e,!0)),lR=(e,t,n=[1,0],r=[0,0],i=!0)=>new tR(P().makeEllipse2d(r[0],r[1],e,t,n[0],n[1],i)),uR=(e,t,n,r,i=[0,0],a,o=!0)=>new tR(P().makeEllipseArc2d(i[0],i[1],e,t,n,r,a[0],a[1],o)),dR=(e,t,n)=>{let r=[[e[0],e[1]],...t.map(e=>[e[0],e[1]]),[n[0],n[1]]];return new tR(P().makeBezier2d(r))};function fR(e,{tolerance:t=.001,smoothing:n=null,degMax:r=3,degMin:i=1}={}){try{let a=e.map(e=>[e[0],e[1]]);return L(new tR(P().makeBSpline2d(a,{tolerance:t,smoothing:n,degMax:r,degMin:i,continuity:`C2`})))}catch(e){return R(yD(`BSPLINE_2D_FAILED`,`B-spline approximation failed`,e))}}var pR=(e,t,n,r=!1)=>{let i=xL(yL(e,t),.5),a=SL(n,e)*(r?-1:1);return oR(e,yL(xL($L(bL(i,n)),a),n),t)};function mR(e,t){let n=Math.cos(t),r=Math.sin(t);return[n*e[0]+r*e[1],-r*e[0]+n*e[1]]}function hR(e,t,n,r,i,a){let o=r,s=i,c=mR(e,a),l=mR(t,a),u=mR(n,a),d=(c[0]-l[0])/2,f=(c[1]-l[1])/2,p=d*d/(o*o)+f*f/(s*s);if(p<1e-18)return null;if(p>1){let e=Math.sqrt(p);o*=e,s*=e}let m=o*o*s*s-o*o*f*f-s*s*d*d,h=o*o*f*f+s*s*d*d;if(h===0)return null;let g=Math.sqrt(Math.max(0,m/h)),_=(c[0]+l[0])/2,v=(c[1]+l[1])/2,y=[[_+g*o*f/s,v-g*s*d/o],[_-g*o*f/s,v+g*s*d/o]],b=e=>{let t=(u[0]-e[0])/o,n=(u[1]-e[1])/s;return Math.abs(t*t+n*n-1)},x=b(y[0])<=b(y[1])?y[0]:y[1],S=e=>Math.atan2((e[1]-x[1])/s,(e[0]-x[0])/o),C=2*Math.PI,w=S(c),ee=((S(u)-w)%C+C)%C,te=((S(l)-w)%C+C)%C,ne=ee<te;return{largeArc:(ne?te:C-te)>Math.PI,ccw:ne}}var gR=(e,t)=>{let n=(t-e)%(2*Math.PI);return n<0&&(n+=2*Math.PI),n};function _R(e,t,n,r){let a=NT(),o=a.getCurve2dCircleData(e.wrapped);o||i(`adaptedCurveToPathElem`,`Expected circle data`);let{radius:s,isDirect:c}=o,[l,u]=e.firstPoint;if(vL([l,u],[t,n]))return`A ${s} ${s} 0 1 ${c?`1`:`0`} ${JL(t)} ${JL(n+1e-4)}`;let d=a.getCurve2dBounds(e.wrapped),[f,p]=e.value((d.first+d.last)/2),m=2*(l*(p-n)+f*(n-u)+t*(u-p));if(Math.abs(m)<Math.hypot(t-l,n-u)*1e-6)return`L ${r}`;let h=l*l+u*u,g=f*f+p*p,_=t*t+n*n,v=(h*(p-n)+g*(n-u)+_*(u-p))/m,y=(h*(t-f)+g*(l-t)+_*(f-l))/m,b=Math.atan2(u-y,l-v),x=Math.atan2(p-y,f-v),S=Math.atan2(n-y,t-v),C=gR(b,x)<=gR(b,S);return`A ${s} ${s} 0 ${(C?gR(b,S):gR(S,b))>Math.PI?`1`:`0`} ${C?`1`:`0`} ${r}`}var vR=(e,n)=>{let r=NT(),a=e.geomType,[o,s]=n,c=`${JL(o)} ${JL(s)}`;if(a===`LINE`)return`L ${c}`;if(a===`BEZIER_CURVE`){let n=r.getCurve2dBezierPoles(e.wrapped);n||i(`adaptedCurveToPathElem`,`Expected Bezier poles`);let a=n.length-1;if(a===1)return`L ${c}`;if(a===2){let[e,r]=t(n,1);return`Q ${qL(e)} ${qL(r)} ${c}`}if(a===3){let[e,r]=t(n,1),[i,a]=t(n,2);return`C ${qL(e)} ${qL(r)} ${qL(i)} ${qL(a)} ${c}`}}if(a===`CIRCLE`)return _R(e,o,s,c);if(a===`ELLIPSE`){let t=r.getCurve2dEllipseData(e.wrapped);t||i(`adaptedCurveToPathElem`,`Expected ellipse data`);let{majorRadius:n,minorRadius:a,xAxisAngle:l,isDirect:u}=t,d=180-l*TD,[f,p]=e.firstPoint;if(vL([f,p],[o,s]))return`A ${JL(n)} ${JL(a)} ${JL(d)} 1 ${u?`1`:`0`} ${JL(o)} ${JL(s+1e-4)}`;let m=r.getCurve2dBounds(e.wrapped),[h,g]=e.value((m.first+m.last)/2),_=hR([f,p],[o,s],[h,g],n,a,l);return _?`A ${JL(n)} ${JL(a)} ${JL(d)} ${_.largeArc?`1`:`0`} ${_.ccw?`1`:`0`} ${c}`:`L ${c}`}i(`adaptedCurveToPathElem`,`Unsupported curve type: ${a}`)},yR=e=>{let t=P(),n=t.createBoundingBox2d();return e.forEach(e=>{t.addCurveToBBox2d(n,e.wrapped,1e-6)}),new QL(n)};function bR(e,t){let n=P();return e.map(e=>SE(n.liftCurve2dToPlane(e.wrapped,[...t.origin],[...t.zDir],[...t.xDir])))}var xR=(e,t)=>{let n=P();return e.map(e=>SE(n.buildEdgeOnSurface(e.wrapped,t)))},SR=(e,t)=>{let n=P();return e.map(e=>t?new tR(n.transformCurve2dGeneral(e.wrapped,t)):e.clone())},CR=(e,t,n=[0,0])=>P().createAffinityGTrsf2d(n[0],n[1],-t[1],t[0],e),wR=e=>P().createTranslationGTrsf2d(e[0],e[1]),TR=(e,t=[0,0],n=`center`)=>n===`center`?P().createMirrorGTrsf2d(e[0],e[1],`point`):P().createMirrorGTrsf2d(0,0,`axis`,t[0],t[1],e[0],e[1]),ER=(e,t=[0,0])=>P().createRotationGTrsf2d(e,t[0],t[1]),DR=(e,t=[0,0])=>P().createScaleGTrsf2d(e,t[0],t[1]);function OR(e,t,n=`original`){let r=P(),i=r.extractSurfaceFromFace(t.wrapped),a=fk(t),o=null;if(n===`original`&&lk(t)!==`PLANE`){if(lk(t)!==`CYLINDRE`)return R(U(`UNSUPPORTED_FACE_TYPE`,`Only planar and cylindrical faces can be unwrapped for sketching`));let e=r.getSurfaceCylinderData(i);if(!e)return R(U(`UNSUPPORTED_FACE_TYPE`,`Could not extract cylinder data from face surface`));e.isDirect||(i=r.reverseSurfaceU(i)),o=CR(1/e.radius,[1,0])}if(n===`bounds`){o=r.createIdentityGTrsf2d();try{r.setGTrsf2dTranslationPart(o,0,0);let e=r.createAffinityGTrsf2d(0,0,0,1,a.uMax-a.uMin);if(r.multiplyGTrsf2d(o,e),e.delete(),a.uMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,-a.uMin,0),r.multiplyGTrsf2d(o,e),e.delete()}let t=r.createAffinityGTrsf2d(0,0,1,0,a.vMax-a.vMin);if(r.multiplyGTrsf2d(o,t),t.delete(),a.vMin!==0){let e=r.createIdentityGTrsf2d();r.setGTrsf2dTranslationPart(e,0,-a.vMin),r.multiplyGTrsf2d(o,e),e.delete()}}catch(e){throw o.delete(),e}}let s=xR(SR(e,o),i);return o&&o.delete(),L(s)}function kR(e,t){let n=P(),r=new tR(n.extractCurve2dFromEdge(e.wrapped,t.wrapped));return oM(e)===`backward`&&n.reverseCurve2d(r.wrapped),r}var AR=(e,t=1)=>`${e.bounds[0][0]-t} ${-e.bounds[1][1]-t} ${e.width+2*t} ${e.height+2*t}`,jR=(e,t,n=1)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${AR(t,n)}" fill="none" stroke="black" stroke-width="0.6%" vector-effect="non-scaling-stroke">
|
|
17
17
|
${e}
|
|
18
18
|
</svg>`;function MR(e){let t=e.map(e=>e.wrapped);return CE(P().makeWire(t))}var NR=class e{curves;_boundingBox;_orientation;_guessedOrientation;constructor(e){e.length===0&&i(`Blueprint`,`requires at least one curve — use createBlueprint() for Result-based validation`),this.curves=e,this._boundingBox=null,this._orientation=null,this._guessedOrientation=null}delete(){this.curves.forEach(e=>{e.delete()}),this._boundingBox&&=(this._boundingBox.delete(),null)}[Symbol.dispose](){this.delete()}clone(){return new e(this.curves.map(e=>e.clone()))}get repr(){return[`Blueprint`,...this.curves.map(e=>e.repr)].join(`
|