1(function(){"use strict";function Xt(s,e){return s===0||s===e||s%100===0}function qe(s,e=()=>performance.now()){let l=-1/0,a=0,u="";return(h,c)=>{a=Math.max(a,Math.min(.99,Math.max(0,h)));const p=`${(c==null?void 0:c.side)??""}:${(c==null?void 0:c.stage)??""}`,m=e(),x=c!==void 0&&c.completed>=c.total;p===u&&!x&&m-l<75||(u=p,l=m,s(a,c))}}var ht=(s=>(s.VBit="vbit",s.Drill="drill",s.EndMill="endmill",s.BallNose="ballnose",s))(ht||{});const Ue=[ht.VBit,ht.EndMill,ht.BallNose],Pt=.5,Dt=(s,e,l)=>(e.x-s.x)*(l.y-s.y)-(e.y-s.y)*(l.x-s.x);function Ft(s,e,l){const a=l.x-e.x,u=l.y-e.y,h=a*a+u*u,c=h?Math.max(0,Math.min(1,((s.x-e.x)*a+(s.y-e.y)*u)/h)):0;return(s.x-e.x-c*a)**2+(s.y-e.y-c*u)**2}function He(s,e,l,a){return Math.max(s.x,e.x)>=Math.min(l.x,a.x)&&Math.max(l.x,a.x)>=Math.min(s.x,e.x)&&Math.max(s.y,e.y)>=Math.min(l.y,a.y)&&Math.max(l.y,a.y)>=Math.min(s.y,e.y)&&Dt(s,e,l)*Dt(s,e,a)<=0&&Dt(l,a,s)*Dt(l,a,e)<=0?0:Math.min(Ft(s,l,a),Ft(e,l,a),Ft(l,s,e),Ft(a,s,e))}function de(s){const e=new Map;for(const l of s)for(let a=0;a<l.length;a++){const u=l[a],h=l[(a+1)%l.length],c={a:u,b:h,minX:Math.min(u.x,h.x),maxX:Math.max(u.x,h.x),minY:Math.min(u.y,h.y),maxY:Math.max(u.y,h.y)};for(let p=Math.floor(Math.min(u.x,h.x)/Pt);p<=Math.floor(Math.max(u.x,h.x)/Pt);p++){let m=e.get(p);m||(m=new Map,e.set(p,m));for(let x=Math.floor(Math.min(u.y,h.y)/Pt);x<=Math.floor(Math.max(u.y,h.y)/Pt);x++){const C=m.get(x)??[];C.push(c),m.set(x,C)}}}return(l,a,u=0)=>{const h=Math.min(l.x,a.x)-u,c=Math.max(l.x,a.x)+u,p=Math.min(l.y,a.y)-u,m=Math.max(l.y,a.y)+u,x=Math.max(1e-16,u**2);for(let C=Math.floor((Math.min(l.x,a.x)-u)/Pt);C<=Math.floor((Math.max(l.x,a.x)+u)/Pt);C++){const v=e.get(C);if(v){for(let I=Math.floor((Math.min(l.y,a.y)-u)/Pt);I<=Math.floor((Math.max(l.y,a.y)+u)/Pt);I++)for(const _ of v.get(I)??[])if(!(_.maxX<h||_.minX>c||_.maxY<p||_.minY>m)&&He(l,a,_.a,_.b)<x)return!1}}return!0}}const Ge=.49;function Je(s,e){const l=e*Ge;if(!Number.isFinite(l)||l<=0)return()=>!1;const a=de(s);return u=>a(u,u,l)}const ct=11102230246251565e-32,nt=134217729,ze=(3+8*ct)*ct;function Jt(s,e,l,a,u){let h,c,p,m,x=e[0],C=a[0],v=0,I=0;C>x==C>-x?(h=x,x=e[++v]):(h=C,C=a[++I]);let _=0;if(v<s&&I<l)for(C>x==C>-x?(c=x+h,p=h-(c-x),x=e[++v]):(c=C+h,p=h-(c-C),C=a[++I]),h=c,p!==0&&(u[_++]=p);v<s&&I<l;)C>x==C>-x?(c=h+x,m=c-h,p=h-(c-m)+(x-m),x=e[++v]):(c=h+C,m=c-h,p=h-(c-m)+(C-m),C=a[++I]),h=c,p!==0&&(u[_++]=p);for(;v<s;)c=h+x,m=c-h,p=h-(c-m)+(x-m),x=e[++v],h=c,p!==0&&(u[_++]=p);for(;I<l;)c=h+C,m=c-h,p=h-(c-m)+(C-m),C=a[++I],h=c,p!==0&&(u[_++]=p);return(h!==0||_===0)&&(u[_++]=h),_}function Ve(s,e){let l=e[0];for(let a=1;a<s;a++)l+=e[a];return l}function At(s){return new Float64Array(s)}const $e=(3+16*ct)*ct,Ke=(2+12*ct)*ct,je=(9+64*ct)*ct*ct,Lt=At(4),me=At(8),ye=At(12),Pe=At(16),st=At(4);function Qe(s,e,l,a,u,h,c){let p,m,x,C,v,I,_,g,L,N,Y,O,F,k,R,q,$,Q;const T=s-u,M=l-u,A=e-h,b=a-h;k=T*b,I=nt*T,_=I-(I-T),g=T-_,I=nt*b,L=I-(I-b),N=b-L,R=g*N-(k-_*L-g*L-_*N),q=A*M,I=nt*A,_=I-(I-A),g=A-_,I=nt*M,L=I-(I-M),N=M-L,$=g*N-(q-_*L-g*L-_*N),Y=R-$,v=R-Y,Lt[0]=R-(Y+v)+(v-$),O=k+Y,v=O-k,F=k-(O-v)+(Y-v),Y=F-q,v=F-Y,Lt[1]=F-(Y+v)+(v-q),Q=O+Y,v=Q-O,Lt[2]=O-(Q-v)+(Y-v),Lt[3]=Q;let B=Ve(4,Lt),G=Ke*c;if(B>=G||-B>=G||(v=s-T,p=s-(T+v)+(v-u),v=l-M,x=l-(M+v)+(v-u),v=e-A,m=e-(A+v)+(v-h),v=a-b,C=a-(b+v)+(v-h),p===0&&m===0&&x===0&&C===0)||(G=je*c+ze*Math.abs(B),B+=T*C+b*p-(A*x+M*m),B>=G||-B>=G))return B;k=p*b,I=nt*p,_=I-(I-p),g=p-_,I=nt*b,L=I-(I-b),N=b-L,R=g*N-(k-_*L-g*L-_*N),q=m*M,I=nt*m,_=I-(I-m),g=m-_,I=nt*M,L=I-(I-M),N=M-L,$=g*N-(q-_*L-g*L-_*N),Y=R-$,v=R-Y,st[0]=R-(Y+v)+(v-$),O=k+Y,v=O-k,F=k-(O-v)+(Y-v),Y=F-q,v=F-Y,st[1]=F-(Y+v)+(v-q),Q=O+Y,v=Q-O,st[2]=O-(Q-v)+(Y-v),st[3]=Q;const z=Jt(4,Lt,4,st,me);k=T*C,I=nt*T,_=I-(I-T),g=T-_,I=nt*C,L=I-(I-C),N=C-L,R=g*N-(k-_*L-g*L-_*N),q=A*x,I=nt*A,_=I-(I-A),g=A-_,I=nt*x,L=I-(I-x),N=x-L,$=g*N-(q-_*L-g*L-_*N),Y=R-$,v=R-Y,st[0]=R-(Y+v)+(v-$),O=k+Y,v=O-k,F=k-(O-v)+(Y-v),Y=F-q,v=F-Y,st[1]=F-(Y+v)+(v-q),Q=O+Y,v=Q-O,st[2]=O-(Q-v)+(Y-v),st[3]=Q;const W=Jt(z,me,4,st,ye);k=p*C,I=nt*p,_=I-(I-p),g=p-_,I=nt*C,L=I-(I-C),N=C-L,R=g*N-(k-_*L-g*L-_*N),q=m*x,I=nt*m,_=I-(I-m),g=m-_,I=nt*x,L=I-(I-x),N=x-L,$=g*N-(q-_*L-g*L-_*N),Y=R-$,v=R-Y,st[0]=R-(Y+v)+(v-$),O=k+Y,v=O-k,F=k-(O-v)+(Y-v),Y=F-q,v=F-Y,st[1]=F-(Y+v)+(v-q),Q=O+Y,v=Q-O,st[2]=O-(Q-v)+(Y-v),st[3]=Q;const V=Jt(W,ye,4,st,Pe);return Pe[V-1]}
vendor: 5,219 bytes, line 1
1function Rt(s,e,l,a,u,h){const c=(e-h)*(l-u),p=(s-u)*(a-h),m=c-p,x=Math.abs(c+p);return Math.abs(m)>=$e*x?m:-Qe(s,e,l,a,u,h,x)}const ve=Math.pow(2,-52),Wt=new Uint32Array(512);class zt{static from(e,l=ri,a=si){const u=e.length,h=new Float64Array(u*2);for(let c=0;c<u;c++){const p=e[c];h[2*c]=l(p),h[2*c+1]=a(p)}return new zt(h)}constructor(e){const l=e.length>>1;if(l>0&&typeof e[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=e;const a=Math.max(2*l-5,0);this._triangles=new Uint32Array(a*3),this._halfedges=new Int32Array(a*3),this._hashSize=Math.ceil(Math.sqrt(l)),this._hullPrev=new Uint32Array(l),this._hullNext=new Uint32Array(l),this._hullTri=new Uint32Array(l),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(l),this._dists=new Float64Array(l),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:e,_hullPrev:l,_hullNext:a,_hullTri:u,_hullHash:h}=this,c=e.length>>1;let p=1/0,m=1/0,x=-1/0,C=-1/0;for(let T=0;T<c;T++){const M=e[2*T],A=e[2*T+1];M<p&&(p=M),A<m&&(m=A),M>x&&(x=M),A>C&&(C=A),this._ids[T]=T}const v=(p+x)/2,I=(m+C)/2;let _=0,g=0,L=0;for(let T=0,M=1/0;T<c;T++){const A=Vt(v,I,e[2*T],e[2*T+1]);A<M&&(_=T,M=A)}const N=e[2*_],Y=e[2*_+1];for(let T=0,M=1/0;T<c;T++){if(T===_)continue;const A=Vt(N,Y,e[2*T],e[2*T+1]);A<M&&A>0&&(g=T,M=A)}let O=e[2*g],F=e[2*g+1],k=1/0;for(let T=0;T<c;T++){if(T===_||T===g)continue;const M=ii(N,Y,O,F,e[2*T],e[2*T+1]);M<k&&(L=T,k=M)}let R=e[2*L],q=e[2*L+1];if(k===1/0){for(let A=0;A<c;A++)this._dists[A]=e[2*A]-e[0]||e[2*A+1]-e[1];gt(this._ids,this._dists,0,c-1);const T=new Uint32Array(c);let M=0;for(let A=0,b=-1/0;A<c;A++){const B=this._ids[A],G=this._dists[B];G>b&&(T[M++]=B,b=G)}this.hull=T.subarray(0,M),this.triangles=new Uint32Array(0),this.halfedges=new Int32Array(0);return}if(Rt(N,Y,O,F,R,q)<0){const T=g,M=O,A=F;g=L,O=R,F=q,L=T,R=M,q=A}const $=ni(N,Y,O,F,R,q);this._cx=$.x,this._cy=$.y;for(let T=0;T<c;T++)this._dists[T]=Vt(e[2*T],e[2*T+1],$.x,$.y);gt(this._ids,this._dists,0,c-1),this._hullStart=_;let Q=3;a[_]=l[L]=g,a[g]=l[_]=L,a[L]=l[g]=_,u[_]=0,u[g]=1,u[L]=2,h.fill(-1),h[this._hashKey(N,Y)]=_,h[this._hashKey(O,F)]=g,h[this._hashKey(R,q)]=L,this.trianglesLen=0,this._addTriangle(_,g,L,-1,-1,-1);for(let T=0,M=0,A=0;T<this._ids.length;T++){const b=this._ids[T],B=e[2*b],G=e[2*b+1];if(T>0&&Math.abs(B-M)<=ve&&Math.abs(G-A)<=ve||(M=B,A=G,b===_||b===g||b===L))continue;let z=0;for(let K=0,rt=this._hashKey(B,G);K<this._hashSize&&(z=h[(rt+K)%this._hashSize],!(z!==-1&&z!==a[z]));K++);z=l[z];let W=z,V;for(;V=a[W],Rt(B,G,e[2*W],e[2*W+1],e[2*V],e[2*V+1])>=0;)if(W=V,W===z){W=-1;break}if(W===-1)continue;let et=this._addTriangle(W,b,a[W],-1,-1,u[W]);u[b]=this._legalize(et+2),u[W]=et,Q++;let Z=a[W];for(;V=a[Z],Rt(B,G,e[2*Z],e[2*Z+1],e[2*V],e[2*V+1])<0;)et=this._addTriangle(Z,b,V,u[b],-1,u[Z]),u[b]=this._legalize(et+2),a[Z]=Z,Q--,Z=V;if(W===z)for(;V=l[W],Rt(B,G,e[2*V],e[2*V+1],e[2*W],e[2*W+1])<0;)et=this._addTriangle(V,b,W,-1,u[W],u[V]),this._legalize(et+2),u[V]=et,a[W]=W,Q--,W=V;this._hullStart=l[b]=W,a[W]=l[Z]=b,a[b]=Z,h[this._hashKey(B,G)]=b,h[this._hashKey(e[2*W],e[2*W+1])]=W}this.hull=new Uint32Array(Q);for(let T=0,M=this._hullStart;T<Q;T++)this.hull[T]=M,M=a[M];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(e,l){return Math.floor(ti(e-this._cx,l-this._cy)*this._hashSize)%this._hashSize}_legalize(e){const{_triangles:l,_halfedges:a,coords:u}=this;let h=0,c=0;for(;;){const p=a[e],m=e-e%3;if(c=m+(e+2)%3,p===-1){if(h===0)break;e=Wt[--h];continue}const x=p-p%3,C=m+(e+1)%3,v=x+(p+2)%3,I=l[c],_=l[e],g=l[C],L=l[v];if(ei(u[2*I],u[2*I+1],u[2*_],u[2*_+1],u[2*g],u[2*g+1],u[2*L],u[2*L+1])){l[e]=L,l[p]=I;const Y=a[v];if(Y===-1){let F=this._hullStart;do{if(this._hullTri[F]===v){this._hullTri[F]=e;break}F=this._hullPrev[F]}while(F!==this._hullStart)}this._link(e,Y),this._link(p,a[c]),this._link(c,v);const O=x+(p+1)%3;h<Wt.length&&(Wt[h++]=O)}else{if(h===0)break;e=Wt[--h]}}return c}_link(e,l){this._halfedges[e]=l,l!==-1&&(this._halfedges[l]=e)}_addTriangle(e,l,a,u,h,c){const p=this.trianglesLen;return this._triangles[p]=e,this._triangles[p+1]=l,this._triangles[p+2]=a,this._link(p,u),this._link(p+1,h),this._link(p+2,c),this.trianglesLen+=3,p}}function ti(s,e){const l=s/(Math.abs(s)+Math.abs(e));return(e>0?3-l:1+l)/4}function Vt(s,e,l,a){const u=s-l,h=e-a;return u*u+h*h}function ei(s,e,l,a,u,h,c,p){const m=s-c,x=e-p,C=l-c,v=a-p,I=u-c,_=h-p,g=m*m+x*x,L=C*C+v*v,N=I*I+_*_;return m*(v*N-L*_)-x*(C*N-L*I)+g*(C*_-v*I)<0}function ii(s,e,l,a,u,h){const c=l-s,p=a-e,m=u-s,x=h-e,C=c*c+p*p,v=m*m+x*x,I=.5/(c*x-p*m),_=(x*C-p*v)*I,g=(c*v-m*C)*I;return _*_+g*g}function ni(s,e,l,a,u,h){const c=l-s,p=a-e,m=u-s,x=h-e,C=c*c+p*p,v=m*m+x*x,I=.5/(c*x-p*m),_=s+(x*C-p*v)*I,g=e+(c*v-m*C)*I;return{x:_,y:g}}function gt(s,e,l,a){if(a-l<=20)for(let u=l+1;u<=a;u++){const h=s[u],c=e[h];let p=u-1;for(;p>=l&&e[s[p]]>c;)s[p+1]=s[p--];s[p+1]=h}else{const u=l+a>>1;let h=l+1,c=a;Et(s,u,h),e[s[l]]>e[s[a]]&&Et(s,l,a),e[s[h]]>e[s[a]]&&Et(s,h,a),e[s[l]]>e[s[h]]&&Et(s,l,h);const p=s[h],m=e[p];for(;;){do h++;
1while(e[s[h]]<m);do c--;while(e[s[c]]>m);if(c<h)break;Et(s,h,c)}s[l+1]=s[c],s[c]=p,a-h+1>=c-l?(gt(s,e,h,a),gt(s,e,l,c-1)):(gt(s,e,l,c-1),gt(s,e,h,a))}}function Et(s,e,l){const a=s[e];s[e]=s[l],s[l]=a}function ri(s){return s[0]}function si(s){return s[1]}function oi(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var $t={exports:{}},xe;function li(){return xe||(xe=1,(function(s){(function(){var e={};e.version="6.4.2.2",e.use_lines=!0,e.use_xyz=!1;var l=!1;s.exports?(s.exports=e,l=!0):typeof document<"u"?window.ClipperLib=e:self.ClipperLib=e;var a;if(l){var u="chrome";a="Netscape"}else{var u=navigator.userAgent.toString().toLowerCase();a=navigator.appName}var h={};u.indexOf("chrome")!=-1&&u.indexOf("chromium")==-1?h.chrome=1:h.chrome=0,u.indexOf("chromium")!=-1?h.chromium=1:h.chromium=0,u.indexOf("safari")!=-1&&u.indexOf("chrome")==-1&&u.indexOf("chromium")==-1?h.safari=1:h.safari=0,u.indexOf("firefox")!=-1?h.firefox=1:h.firefox=0,u.indexOf("firefox/17")!=-1?h.firefox17=1:h.firefox17=0,u.indexOf("firefox/15")!=-1?h.firefox15=1:h.firefox15=0,u.indexOf("firefox/3")!=-1?h.firefox3=1:h.firefox3=0,u.indexOf("opera")!=-1?h.opera=1:h.opera=0,u.indexOf("msie 10")!=-1?h.msie10=1:h.msie10=0,u.indexOf("msie 9")!=-1?h.msie9=1:h.msie9=0,u.indexOf("msie 8")!=-1?h.msie8=1:h.msie8=0,u.indexOf("msie 7")!=-1?h.msie7=1:h.msie7=0,u.indexOf("msie ")!=-1?h.msie=1:h.msie=0,e.biginteger_used=null;var c;function p(t,i,n){e.biginteger_used=1,t!=null&&(typeof t=="number"&&typeof i>"u"?this.fromInt(t):typeof t=="number"?this.fromNumber(t,i,n):i==null&&typeof t!="string"?this.fromString(t,256):this.fromString(t,i))}function m(){return new p(null,void 0,void 0)}function x(t,i,n,r,o,f){for(;--f>=0;){var d=i*this[t++]+n[r]+o;o=Math.floor(d/67108864),n[r++]=d&67108863}return o}function C(t,i,n,r,o,f){for(var d=i&32767,y=i>>15;--f>=0;){var P=this[t]&32767,X=this[t++]>>15,S=y*P+X*d;P=d*P+((S&32767)<<15)+n[r]+(o&1073741823),o=(P>>>30)+(S>>>15)+y*X+(o>>>30),n[r++]=P&1073741823}return o}function v(t,i,n,r,o,f){for(var d=i&16383,y=i>>14;--f>=0;){var P=this[t]&16383,X=this[t++]>>14,S=y*P+X*d;P=d*P+((S&16383)<<14)+n[r]+o,o=(P>>28)+(S>>14)+y*X,n[r++]=P&268435455}return o}a=="Microsoft Internet Explorer"?(p.prototype.am=C,c=30):a!="Netscape"?(p.prototype.am=x,c=26):(p.prototype.am=v,c=28),p.prototype.DB=c,p.prototype.DM=(1<<c)-1,p.prototype.DV=1<<c;var I=52;p.prototype.FV=Math.pow(2,I),p.prototype.F1=I-c,p.prototype.F2=2*c-I;var _="0123456789abcdefghijklmnopqrstuvwxyz",g=new Array,L,N;for(L=48,N=0;N<=9;++N)g[L++]=N;for(L=97,N=10;N<36;++N)g[L++]=N;for(L=65,N=10;N<36;++N)g[L++]=N;function Y(t){return _.charAt(t)}function O(t,i){var n=g[t.charCodeAt(i)];return n??-1}function F(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s}function k(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}function R(t){var i=m();return i.fromInt(t),i}function q(t,i){var n;if(i==16)n=4;else if(i==8)n=3;else if(i==256)n=8;else if(i==2)n=1;else if(i==32)n=5;else if(i==4)n=2;else{this.fromRadix(t,i);return}this.t=0,this.s=0;for(var r=t.length,o=!1,f=0;--r>=0;){var d=n==8?t[r]&255:O(t,r);
vendor: 16,222 bytes, line 1
1if(d<0){t.charAt(r)=="-"&&(o=!0);continue}o=!1,f==0?this[this.t++]=d:f+n>this.DB?(this[this.t-1]|=(d&(1<<this.DB-f)-1)<<f,this[this.t++]=d>>this.DB-f):this[this.t-1]|=d<<f,f+=n,f>=this.DB&&(f-=this.DB)}n==8&&(t[0]&128)!=0&&(this.s=-1,f>0&&(this[this.t-1]|=(1<<this.DB-f)-1<<f)),this.clamp(),o&&p.ZERO.subTo(this,this)}function $(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function Q(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(t==16)i=4;else if(t==8)i=3;else if(t==2)i=1;else if(t==32)i=5;else if(t==4)i=2;else return this.toRadix(t);var n=(1<<i)-1,r,o=!1,f="",d=this.t,y=this.DB-d*this.DB%i;if(d-- >0)for(y<this.DB&&(r=this[d]>>y)>0&&(o=!0,f=Y(r));d>=0;)y<i?(r=(this[d]&(1<<y)-1)<<i-y,r|=this[--d]>>(y+=this.DB-i)):(r=this[d]>>(y-=i)&n,y<=0&&(y+=this.DB,--d)),r>0&&(o=!0),o&&(f+=Y(r));return o?f:"0"}function T(){var t=m();return p.ZERO.subTo(this,t),t}function M(){return this.s<0?this.negate():this}function A(t){var i=this.s-t.s;if(i!=0)return i;var n=this.t;if(i=n-t.t,i!=0)return this.s<0?-i:i;for(;--n>=0;)if((i=this[n]-t[n])!=0)return i;return 0}function b(t){var i=1,n;return(n=t>>>16)!=0&&(t=n,i+=16),(n=t>>8)!=0&&(t=n,i+=8),(n=t>>4)!=0&&(t=n,i+=4),(n=t>>2)!=0&&(t=n,i+=2),(n=t>>1)!=0&&(t=n,i+=1),i}function B(){return this.t<=0?0:this.DB*(this.t-1)+b(this[this.t-1]^this.s&this.DM)}function G(t,i){var n;for(n=this.t-1;n>=0;--n)i[n+t]=this[n];for(n=t-1;n>=0;--n)i[n]=0;i.t=this.t+t,i.s=this.s}function z(t,i){for(var n=t;n<this.t;++n)i[n-t]=this[n];i.t=Math.max(this.t-t,0),i.s=this.s}function W(t,i){var n=t%this.DB,r=this.DB-n,o=(1<<r)-1,f=Math.floor(t/this.DB),d=this.s<<n&this.DM,y;for(y=this.t-1;y>=0;--y)i[y+f+1]=this[y]>>r|d,d=(this[y]&o)<<n;for(y=f-1;y>=0;--y)i[y]=0;i[f]=d,i.t=this.t+f+1,i.s=this.s,i.clamp()}function V(t,i){i.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t){i.t=0;return}var r=t%this.DB,o=this.DB-r,f=(1<<r)-1;i[0]=this[n]>>r;for(var d=n+1;d<this.t;++d)i[d-n-1]|=(this[d]&f)<<o,i[d-n]=this[d]>>r;r>0&&(i[this.t-n-1]|=(this.s&f)<<o),i.t=this.t-n,i.clamp()}function et(t,i){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]-t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],i[n++]=r&this.DM,r>>=this.DB;r-=t.s}i.s=r<0?-1:0,r<-1?i[n++]=this.DV+r:r>0&&(i[n++]=r),i.t=n,i.clamp()}function Z(t,i){var n=this.abs(),r=t.abs(),o=n.t;for(i.t=o+r.t;--o>=0;)i[o]=0;for(o=0;o<r.t;++o)i[o+n.t]=n.am(0,r[o],i,o,0,n.t);i.s=0,i.clamp(),this.s!=t.s&&p.ZERO.subTo(i,i)}function K(t){for(var i=this.abs(),n=t.t=2*i.t;--n>=0;)t[n]=0;for(n=0;n<i.t-1;++n){var r=i.am(n,i[n],t,2*n,0,1);(t[n+i.t]+=i.am(n+1,2*i[n],t,2*n+1,r,i.t-n-1))>=i.DV&&(t[n+i.t]-=i.DV,t[n+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(n,i[n],t,2*n,0,1)),t.s=0,t.clamp()}function rt(t,i,n){var r=t.abs();if(!(r.t<=0)){var o=this.abs();if(o.t<r.t){i!=null&&i.fromInt(0),n!=null&&this.copyTo(n);return}n==null&&(n=m());var f=m(),d=this.s,y=t.s,P=this.DB-b(r[r.t-1]);P>0?(r.lShiftTo(P,f),o.lShiftTo(P,n)):(r.copyTo(f),o.copyTo(n));var X=f.t,S=f[X-1];if(S!=0){var w=S*(1<<this.F1)+(X>1?f[X-2]>>this.F2:0),E=this.FV/w,D=(1<<this.F1)/w,H=1<<this.F2,J=n.t,tt=J-X,at=i??m();for(f.dlShiftTo(tt,at),n.compareTo(at)>=0&&(n[n.t++]=1,n.subTo(at,n)),p.ONE.dlShiftTo(X,at),at.subTo(f,f);f.t<X;)f[f.t++]=0;for(;--tt>=0;){var pt=n[--J]==S?this.DM:Math.floor(n[J]*E+(n[J-1]+H)*D);if((n[J]+=f.am(0,pt,n,tt,0,X))<pt)for(f.dlShiftTo(tt,at),n.subTo(at,n);n[J]<--pt;)n.subTo(at,n)}i!=null&&(n.drShiftTo(X,i),d!=y&&p.ZERO.subTo(i,i)),n.t=X,n.clamp(),P>0&&n.rShiftTo(P,n),d<0&&p.ZERO.subTo(n,n)}}}function It(t){var i=m();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(p.ZERO)>0&&t.subTo(i,i),i}function ft(t){this.m=t}function _t(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function lr(t){return t}function ar(t){t.divRemTo(this.m,null,t)}function ur(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function hr(t,i){t.squareTo(i),this.reduce(i)}ft.prototype.convert=_t,ft.prototype.revert=lr,ft.prototype.reduce=ar,ft.prototype.mulTo=ur,ft.prototype.sqrTo=hr;function fr(){if(this.t<1)return 0;var t=this[0];if((t&1)==0)return 0;var i=t&3;return i=i*(2-(t&15)*i)&15,i=i*(2-(t&255)*i)&255,i=i*(2-((t&65535)*i&65535))&65535,i=i*(2-t*i%this.DV)%this.DV,i>0?this.DV-i:-i}function Tt(t){this.m=t,this.mp=t.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function pr(t){var i=m();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(p.ZERO)>0&&this.m.subTo(i,i),i}function cr(t){var i=m();return t.copyTo(i),this.reduce(i),i}function dr(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var n=t[i]&32767,r=n*this.mpl+((n*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(n=i+this.m.t,t[n]+=this.m.am(0,r,t,i,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function mr(t,i){t.squareTo(i),this.reduce(i)}function yr(t,i,n){t.multiplyTo(i,n),this.reduce(n)}Tt.prototype.convert=pr,Tt.prototype.revert=cr,Tt.prototype.reduce=dr,Tt.prototype.mulTo=yr,Tt.prototype.sqrTo=mr;function Pr(){return(this.t>0?this[0]&1:this.s)==0}function vr(t,i){if(t>4294967295||t<1)return p.ONE;var n=m(),r=m(),o=i.convert(this),f=b(t)-1;for(o.copyTo(n);--f>=0;)if(i.sqrTo(n,r),(t&1<<f)>0)i.mulTo(r,o,n);else{var d=n;n=r,r=d}return i.revert(n)}function xr(t,i){var n;return t<256||i.isEven()?n=new ft(i):n=new Tt(i),this.exp(t,n)}p.prototype.copyTo=F,p.prototype.fromInt=k,p.prototype.fromString=q,p.prototype.clamp=$,p.prototype.dlShiftTo=G,p.prototype.drShiftTo=z,p.prototype.lShiftTo=W,p.prototype.rShiftTo=V,p.prototype.subTo=et,p.prototype.multiplyTo=Z,p.prototype.squareTo=K,p.prototype.divRemTo=rt,p.prototype.invDigit=fr,p.prototype.isEven=Pr,p.prototype.exp=vr,p.prototype.toString=Q,p.prototype.negate=T,p.prototype.abs=M,p.prototype.compareTo=A,p.prototype.bitLength=B,p.prototype.mod=It,p.prototype.modPowInt=xr,p.ZERO=R(0),p.ONE=R(1);function Cr(){var t=m();return this.copyTo(t),t}function Ir(){if(this.s<0){if(this.t==1)return this[0]-this.DV;if(this.t==0)return-1}else{if(this.t==1)return this[0];if(this.t==0)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function _r(){return this.t==0?this.s:this[0]<<24>>24}function Tr(){return this.t==0?this.s:this[0]<<16>>16}function Xr(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function Lr(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function gr(t){if(t==null&&(t=10),this.signum()==0||t<2||t>36)return"0";var i=this.chunkSize(t),n=Math.pow(t,i),r=R(n),o=m(),f=m(),d="";for(this.divRemTo(r,o,f);o.signum()>0;)d=(n+f.intValue()).toString(t).substr(1)+d,o.divRemTo(r,o,f);return f.intValue().toString(t)+d}function wr(t,i){this.fromInt(0),i==null&&(i=10);for(var n=this.chunkSize(i),r=Math.pow(i,n),o=!1,f=0,d=0,y=0;y<t.length;++y){var P=O(t,y);if(P<0){t.charAt(y)=="-"&&this.signum()==0&&(o=!0);continue}d=i*d+P,++f>=n&&(this.dMultiply(r),this.dAddOffset(d,0),f=0,d=0)}f>0&&(this.dMultiply(Math.pow(i,f)),this.dAddOffset(d,0)),o&&p.ZERO.subTo(this,this)}function Sr(t,i,n){if(typeof i=="number")if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(p.ONE.shiftLeft(t-1),ce,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(p.ONE.shiftLeft(t-1),this);else{var r=new Array,o=t&7;r.length=(t>>3)+1,i.nextBytes(r),o>0?r[0]&=(1<<o)-1:r[0]=0,this.fromString(r,256)}}function Nr(){var t=this.t,i=new Array;i[0]=this.s;var n=this.DB-t*this.DB%8,r,o=0;if(t-- >0)for(n<this.DB&&(r=this[t]>>n)!=(this.s&this.DM)>>n&&(i[o++]=r|this.s<<this.DB-n);t>=0;)n<8?(r=(this[t]&(1<<n)-1)<<8-n,r|=this[--t]>>(n+=this.DB-8)):(r=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),(r&128)!=0&&(r|=-256),o==0&&(this.s&128)!=(r&128)&&++o,(o>0||r!=this.s)&&(i[o++]=r);return i}function Yr(t){return this.compareTo(t)==0}function Mr(t){return this.compareTo(t)<0?this:t}function Or(t){return this.compareTo(t)>0?this:t}function Ar(t,i,n){var r,o,f=Math.min(t.t,this.t);for(r=0;r<f;++r)n[r]=i(this[r],t[r]);if(t.t<this.t){for(o=t.s&this.DM,r=f;r<this.t;++r)n[r]=i(this[r],o);n.t=this.t}else{for(o=this.s&this.DM,r=f;r<t.t;++r)n[r]=i(o,t[r]);n.t=t.t}n.s=i(this.s,t.s),n.clamp()}function Er(t,i){return t&i}function br(t){var i=m();return this.bitwiseTo(t,Er,i),i}function ce(t,i){return t|i}function Br(t){var i=m();return this.bitwiseTo(t,ce,i),i}function Re(t,i){return t^i}function Dr(t){var i=m();return this.bitwiseTo(t,Re,i),i}function We(t,i){return t&~i}function Fr(t){var i=m();return this.bitwiseTo(t,We,i),i}function Rr(){for(var t=m(),i=0;i<this.t;++i)t[i]=this.DM&~this[i];return t.t=this.t,t.s=~this.s,t}function Wr(t){var i=m();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function Zr(t){var i=m();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function kr(t){if(t==0)return-1;var i=0;return(t&65535)==0&&(t>>=16,i+=16),(t&255)==0&&(t>>=8,i+=8),(t&15)==0&&(t>>=4,i+=4),(t&3)==0&&(t>>=2,i+=2),(t&1)==0&&++i,i}function qr(){for(var t=0;t<this.t;++t)if(this[t]!=0)return t*this.DB+kr(this[t]);return this.s<0?this.t*this.DB:-1}function Ur(t){for(var i=0;t!=0;)t&=t-1,++i;return i}function Hr(){for(var t=0,i=this.s&this.DM,n=0;n<this.t;++n)t+=Ur(this[n]^i);return t}function Gr(t){var i=Math.floor(t/this.DB);return i>=this.t?this.s!=0:(this[i]&1<<t%this.DB)!=0}function Jr(t,i){var n=p.ONE.shiftLeft(t);return this.bitwiseTo(n,i,n),n}function zr(t){return this.changeBit(t,ce)}function Vr(t){return this.changeBit(t,We)}function $r(t){return this.changeBit(t,Re)}function Kr(t,i){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]+t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r+=t[n],i[n++]=r&this.DM,r>>=this.DB;r+=t.s}i.s=r<0?-1:0,r>0?i[n++]=r:r<-1&&(i[n++]=this.DV+r),i.t=n,i.clamp()}function jr(t){var i=m();return this.addTo(t,i),i}function Qr(t){var i=m();return this.subTo(t,i),i}function ts(t){var i=m();return this.multiplyTo(t,i),i}function es(){var t=m();return this.squareTo(t),t}function is(t){var i=m();return this.divRemTo(t,i,null),i}function ns(t){var i=m();return this.divRemTo(t,null,i),i}function rs(t){var i=m(),n=m();return this.divRemTo(t,i,n),new Array(i,n)}function ss(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function os(t,i){if(t!=0){for(;this.t<=i;)this[this.t++]=0;for(this[i]+=t;this[i]>=this.DV;)this[i]-=this.DV,++i>=this.t&&(this[this.t++]=0),++this[i]}}function Bt(){}function Ze(t){return t}function ls(t,i,n){t.multiplyTo(i,n)}function as(t,i){t.squareTo(i)}Bt.prototype.convert=Ze,Bt.prototype.revert=Ze,Bt.prototype.mulTo=ls,Bt.prototype.sqrTo=as;function us(t){return this.exp(t,new Bt)}function hs(t,i,n){var r=Math.min(this.t+t.t,i);for(n.s=0,n.t=r;r>0;)n[--r]=0;var o;for(o=n.t-this.t;r<o;++r)n[r+this.t]=this.am(0,t[r],n,r,0,this.t);for(o=Math.min(t.t,i);r<o;++r)this.am(0,t[r],n,r,0,i-r);n.clamp()}function fs(t,i,n){--i;var r=n.t=this.t+t.t-i;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(i-this.t,0);r<t.t;++r)n[this.t+r-i]=this.am(i-r,t[r],n,0,0,this.t+r-i);n.clamp(),n.drShiftTo(1,n)}function Yt(t){this.r2=m(),this.q3=m(),p.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function ps(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=m();return t.copyTo(i),this.reduce(i),i}function cs(t){return t}function ds(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function ms(t,i){t.squareTo(i),this.reduce(i)}function ys(t,i,n){t.multiplyTo(i,n),this.reduce(n)}Yt.prototype.convert=ps,Yt.prototype.revert=cs,Yt.prototype.reduce=ds,Yt.prototype.mulTo=ys,Yt.prototype.sqrTo=ms;function Ps(t,i){var n=t.bitLength(),r,o=R(1),f;if(n<=0)return o;n<18?r=1:n<48?r=3:n<144?r=4:n<768?r=5:r=6,n<8?f=new ft(i):i.isEven()?f=new Yt(i):f=new Tt(i);var d=new Array,y=3,P=r-1,X=(1<<r)-1;if(d[1]=f.convert(this),r>1){var S=m();for(f.sqrTo(d[1],S);y<=X;)d[y]=m(),f.mulTo(S,d[y-2],d[y]),y+=2}var w=t.t-1,E,D=!0,H=m(),J;for(n=b(t[w])-1;w>=0;){for(n>=P?E=t[w]>>n-P&X:(E=(t[w]&(1<<n+1)-1)<<P-n,w>0&&(E|=t[w-1]>>this.DB+n-P)),y=r;(E&1)==0;)E>>=1,--y;if((n-=y)<0&&(n+=this.DB,--w),D)d[E].copyTo(o),D=!1;else{for(;y>1;)f.sqrTo(o,H),f.sqrTo(H,o),y-=2;y>0?f.sqrTo(o,H):(J=o,o=H,H=J),f.mulTo(H,d[E],o)}for(;w>=0&&(t[w]&1<<n)==0;)f.sqrTo(o,H),J=o,o=H,H=J,--n<0&&(n=this.DB-1,--w)}return f.revert(o)}function vs(t){var i=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(i.compareTo(n)<0){var r=i;i=n,n=r}var o=i.getLowestSetBit(),f=n.getLowestSetBit();if(f<0)return i;for(o<f&&(f=o),f>0&&(i.rShiftTo(f,i),n.rShiftTo(f,n));i.signum()>0;)(o=i.getLowestSetBit())>0&&i.rShiftTo(o,i),(o=n.getLowestSetBit())>0&&n.rShiftTo(o,n),i.compareTo(n)>=0?(i.subTo(n,i),i.rShiftTo(1,i)):(n.subTo(i,n),n.rShiftTo(1,n));return f>0&&n.lShiftTo(f,n),n}function xs(t){if(t<=0)return 0;var i=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(i==0)n=this[0]%t;else for(var r=this.t-1;r>=0;--r)n=(i*n+this[r])%t;return n}function Cs(t){var i=t.isEven();if(this.isEven()&&i||t.signum()==0)return p.ZERO;for(var n=t.clone(),r=this.clone(),o=R(1),f=R(0),d=R(0),y=R(1);n.signum()!=0;){for(;n.isEven();)n.rShiftTo(1,n),i?((!o.isEven()||!f.isEven())&&(o.addTo(this,o),f.subTo(t,f)),o.rShiftTo(1,o)):f.isEven()||f.subTo(t,f),f.rShiftTo(1,f);for(;r.isEven();)r.rShiftTo(1,r),i?((!d.isEven()||!y.isEven())&&(d.addTo(this,d),y.subTo(t,y)),d.rShiftTo(1,d)):y.isEven()||y.subTo(t,y),y.rShiftTo(1,y);n.compareTo(r)>=0?(n.subTo(r,n),i&&o.subTo(d,o),f.subTo(y,f)):(r.subTo(n,r),i&&d.subTo(o,d),y.subTo(f,y))}if(r.compareTo(p.ONE)!=0)return p.ZERO;if(y.compareTo(t)>=0)return y.subtract(t);if(y.signum()<0)y.addTo(t,y);else return y;return y.signum()<0?y.add(t):y}var lt=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],Is=(1<<26)/lt[lt.length-1];function _s(t){var i,n=this.abs();if(n.t==1&&n[0]<=lt[lt.length-1]){for(i=0;i<lt.length;++i)if(n[0]==lt[i])return!0;return!1}if(n.isEven())return!1;for(i=1;i<lt.length;){for(var r=lt[i],o=i+1;o<lt.length&&r<Is;)r*=lt[o++];for(r=n.modInt(r);i<o;)if(r%lt[i++]==0)return!1}return n.millerRabin(t)}function Ts(t){var i=this.subtract(p.ONE),n=i.getLowestSetBit();if(n<=0)return!1;var r=i.shiftRight(n);t=t+1>>1,t>lt.length&&(t=lt.length);for(var o=m(),f=0;f<t;++f){o.fromInt(lt[Math.floor(Math.random()*lt.length)]);var d=o.modPow(r,this);if(d.compareTo(p.ONE)!=0&&d.compareTo(i)!=0){for(var y=1;y++<n&&d.compareTo(i)!=0;)if(d=d.modPowInt(2,this),d.compareTo(p.ONE)==0)return!1;if(d.compareTo(i)!=0)return!1}}return!0}p.prototype.chunkSize=Xr,p.prototype.toRadix=gr,p.prototype.fromRadix=wr,p.prototype.fromNumber=Sr,p.prototype.bitwiseTo=Ar,p.prototype.changeBit=Jr,p.prototype.addTo=Kr,p.prototype.dMultiply=ss,p.prototype.dAddOffset=os,p.prototype.multiplyLowerTo=hs,p.prototype.multiplyUpperTo=fs,p.prototype.modInt=xs,p.prototype.millerRabin=Ts,p.prototype.clone=Cr,p.prototype.intValue=Ir,p.prototype.byteValue=_r,p.prototype.shortValue=Tr,p.prototype.signum=Lr,p.prototype.toByteArray=Nr,p.prototype.equals=Yr,p.prototype.min=Mr,p.prototype.max=Or,p.prototype.and=br,p.prototype.or=Br,p.prototype.xor=Dr,p.prototype.andNot=Fr,p.prototype.not=Rr,p.prototype.shiftLeft=Wr,p.prototype.shiftRight=Zr,p.prototype.getLowestSetBit=qr,p.prototype.bitCount=Hr,p.prototype.testBit=Gr,p.prototype.setBit=zr,p.prototype.clearBit=Vr,p.prototype.flip
1Bit=$r,p.prototype.add=jr,p.prototype.subtract=Qr,p.prototype.multiply=ts,p.prototype.divide=is,p.prototype.remainder=ns,p.prototype.divideAndRemainder=rs,p.prototype.modPow=Ps,p.prototype.modInverse=Cs,p.prototype.pow=us,p.prototype.gcd=vs,p.prototype.isProbablePrime=_s,p.prototype.square=es;var U=p;U.prototype.IsNegative=function(){return this.compareTo(U.ZERO)==-1},U.op_Equality=function(t,i){return t.compareTo(i)==0},U.op_Inequality=function(t,i){return t.compareTo(i)!=0},U.op_GreaterThan=function(t,i){return t.compareTo(i)>0},U.op_LessThan=function(t,i){return t.compareTo(i)<0},U.op_Addition=function(t,i){return new U(t,void 0,void 0).add(new U(i,void 0,void 0))},U.op_Subtraction=function(t,i){return new U(t,void 0,void 0).subtract(new U(i,void 0,void 0))},U.Int128Mul=function(t,i){return new U(t,void 0,void 0).multiply(new U(i,void 0,void 0))},U.op_Division=function(t,i){return t.divide(i)},U.prototype.ToDouble=function(){return parseFloat(this.toString())};var ke=function(t,i){var n;if(typeof Object.getOwnPropertyNames>"u"){for(n in i.prototype)(typeof t.prototype[n]>"u"||t.prototype[n]===Object.prototype[n])&&(t.prototype[n]=i.prototype[n]);for(n in i)typeof t[n]>"u"&&(t[n]=i[n]);t.$baseCtor=i}else{for(var r=Object.getOwnPropertyNames(i.prototype),o=0;o<r.length;o++)typeof Object.getOwnPropertyDescriptor(t.prototype,r[o])>"u"&&Object.defineProperty(t.prototype,r[o],Object.getOwnPropertyDescriptor(i.prototype,r[o]));for(n in i)typeof t[n]>"u"&&(t[n]=i[n]);t.$baseCtor=i}};e.Path=function(){return[]},e.Path.prototype.push=Array.prototype.push,e.Paths=function(){return[]},e.Paths.prototype.push=Array.prototype.push,e.DoublePoint=function(){var t=arguments;this.X=0,this.Y=0,t.length===1?(this.X=t[0].X,this.Y=t[0].Y):t.length===2&&(this.X=t[0],this.Y=t[1])},e.DoublePoint0=function(){this.X=0,this.Y=0},e.DoublePoint0.prototype=e.DoublePoint.prototype,e.DoublePoint1=function(t){this.X=t.X,this.Y=t.Y},e.DoublePoint1.prototype=e.DoublePoint.prototype,e.DoublePoint2=function(t,i){this.X=t,this.Y=i},e.DoublePoint2.prototype=e.DoublePoint.prototype,e.PolyNode=function(){this.m_Parent=null,this.m_polygon=new e.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},e.PolyNode.prototype.IsHoleNode=function(){for(var t=!0,i=this.m_Parent;i!==null;)t=!t,i=i.m_Parent;return t},e.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},e.PolyNode.prototype.Contour=function(){return this.m_polygon},e.PolyNode.prototype.AddChild=function(t){var i=this.m_Childs.length;this.m_Childs.push(t),t.m_Parent=this,t.m_Index=i},e.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},e.PolyNode.prototype.GetNextSiblingUp=function(){return this.m_Parent===null?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},e.PolyNode.prototype.Childs=function(){return this.m_Childs},e.PolyNode.prototype.Parent=function(){return this.m_Parent},e.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},e.PolyTree=function(){this.m_AllPolys=[],e.PolyNode.call(this)},e.PolyTree.prototype.Clear=function(){for(var t=0,i=this.m_AllPolys.length;t<i;t++)this.m_AllPolys[t]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},e.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},e.PolyTree.prototype.Total=function(){var t=this.m_AllPolys.length;return t>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&t--,t},ke(e.PolyTree,e.PolyNode),e.Math_Abs_Int64=e.Math_Abs_Int32=e.Math_Abs_Double=function(t){return Math.abs(t)},e.Math_Max_Int32_Int32=function(t,i){return Math.max(t,i)},h.msie||h.opera||h.safari?e.Cast_Int32=function(t){return t|0}:e.Cast_Int32=function(t){return~~t},typeof Number.toInteger>"u"&&(Number.toInteger=null),h.chrome?e.Cast_Int64=function(t){return t<-2147483648||t>2147483647?t<0?Math.ceil(t):Math.floor(t):~~t}:h.firefox&&typeof Number.toInteger=="function"?e.Cast_Int64=function(t){return Number.toInteger(t)}:h.msie7||h.msie8?e.Cast_Int64=function(t){return parseInt(t,10)}:h.msie?e.Cast_Int64=function(t){return t<-2147483648||t>2147483647?t<0?Math.ceil(t):Math.floor(t):t|0}:e.Cast_Int64=function(t){return t<0?Math.ceil(t):Math.floor(t)},e.Clear=function(t){t.length=0},e.PI=3.141592653589793,e.PI2=2*3.141592653589793,e.IntPoint=function(){var t=arguments,i=t.length;if(this.X=0,this.Y=0,e.use_xyz)if(this.Z=0,i===3)this.X=t[0],this.Y=t[1],this.Z=t[2];else if(i===2)this.X=t[0],this.Y=t[1],this.Z=0;else if(i===1)if(t[0]instanceof e.DoublePoint){var n=t[0];this.X=e.Clipper.Round(n.X),this.Y=e.Clipper.Round(n.Y),this.Z=0}else{var r=t[0];typeof r.Z>"u"&&(r.Z=0),this.X=r.X,this.Y=r.Y,this.Z=r.Z}else this.X=0,this.Y=0,this.Z=0;else if(i===2)this.X=t[0],this.Y=t[1];else if(i===1)if(t[0]instanceof e.DoublePoint){var n=t[0];this.X=e.Clipper.Round(n.X),this.Y=e.Clipper.Round(n.Y)}else{var r=t[0];this.X=r.X,this.Y=r.Y}else this.X=0,this.Y=0},e.IntPoint.op_Equality=function(t,i){return t.X===i.X&&t.Y===i.Y},e.IntPoint.op_Inequality=function(t,i){return t.X!==i.X||t.Y!==i.Y},e.IntPoint0=function(){this.X=0,this.Y=0,e.use_xyz&&(this.Z=0)},e.IntPoint0.prototype=e.IntPoint.prototype,e.IntPoint1=function(t){this.X=t.X,this.Y=t.Y,e.use_xyz&&(typeof t.Z>"u"?this.Z=0:this.Z=t.Z)},e.IntPoint1.prototype=e.IntPoint.prototype,e.IntPoint1dp=function(t){this.X=e.Clipper.Round(t.X),this.Y=e.Clipper.Round(t.Y),e.use_xyz&&(this.Z=0)},e.IntPoint1dp.prototype=e.IntPoint.prototype,e.IntPoint2=function(t,i,n){this.X=t,this.Y=i,e.use_xyz&&(typeof n>"u"?this.Z=0:this.Z=n)},e.IntPoint2.prototype=e.IntPoint.prototype,e.IntRect=function(){var t=arguments,i=t.length;if(i===4)this.left=t[0],this.top=t[1],this.right=t[2],this.bottom=t[3];else if(i===1){var n=t[0];this.left=n.left,this.top=n.top,this.right=n.right,this.bottom=n.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0.prototype=e.IntRect.prototype,e.IntRect1=function(t){this.left=t.left,this.top=t.top,this.right=t.right,this.bottom=t.bottom},e.IntRect1.prototype=e.IntRect.prototype,e.IntRect4=function(t,i,n,r){this.left=t,this.top=i,this.right=n,this.bottom=r},e.IntRect4.prototype=e.IntRect.prototype,e.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3}
1,e.PolyType={ptSubject:0,ptClip:1},e.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},e.JoinType={jtSquare:0,jtRound:1,jtMiter:2},e.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},e.EdgeSide={esLeft:0,esRight:1},e.Direction={dRightToLeft:0,dLeftToRight:1},e.TEdge=function(){this.Bot=new e.IntPoint0,this.Curr=new e.IntPoint0,this.Top=new e.IntPoint0,this.Delta=new e.IntPoint0,this.Dx=0,this.PolyTyp=e.PolyType.ptSubject,this.Side=e.EdgeSide.esLeft,this.WindDelta=0,this.WindCnt=0,this.WindCnt2=0,this.OutIdx=0,this.Next=null,this.Prev=null,this.NextInLML=null,this.NextInAEL=null,this.PrevInAEL=null,this.NextInSEL=null,this.PrevInSEL=null},e.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new e.IntPoint0},e.MyIntersectNodeSort=function(){},e.MyIntersectNodeSort.Compare=function(t,i){var n=i.Pt.Y-t.Pt.Y;return n>0?1:n<0?-1:0},e.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},e.Scanbeam=function(){this.Y=0,this.Next=null},e.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},e.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},e.OutPt=function(){this.Idx=0,this.Pt=new e.IntPoint0,this.Next=null,this.Prev=null},e.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new e.IntPoint0},e.ClipperBase=function(){this.m_MinimaList=null,this.m_CurrentLM=null,this.m_edges=new Array,this.m_UseFullRange=!1,this.m_HasOpenPaths=!1,this.PreserveCollinear=!1,this.m_Scanbeam=null,this.m_PolyOuts=null,this.m_ActiveEdges=null},e.ClipperBase.horizontal=-9007199254740992,e.ClipperBase.Skip=-2,e.ClipperBase.Unassigned=-1,e.ClipperBase.tolerance=1e-20,e.ClipperBase.loRange=47453132,e.ClipperBase.hiRange=0xfffffffffffff,e.ClipperBase.near_zero=function(t){return t>-e.ClipperBase.tolerance&&t<e.ClipperBase.tolerance},e.ClipperBase.IsHorizontal=function(t){return t.Delta.Y===0},e.ClipperBase.prototype.PointIsVertex=function(t,i){var n=i;do{if(e.IntPoint.op_Equality(n.Pt,t))return!0;n=n.Next}while(n!==i);return!1},e.ClipperBase.prototype.PointOnLineSegment=function(t,i,n,r){return r?t.X===i.X&&t.Y===i.Y||t.X===n.X&&t.Y===n.Y||t.X>i.X==t.X<n.X&&t.Y>i.Y==t.Y<n.Y&&U.op_Equality(U.Int128Mul(t.X-i.X,n.Y-i.Y),U.Int128Mul(n.X-i.X,t.Y-i.Y)):t.X===i.X&&t.Y===i.Y||t.X===n.X&&t.Y===n.Y||t.X>i.X==t.X<n.X&&t.Y>i.Y==t.Y<n.Y&&(t.X-i.X)*(n.Y-i.Y)===(n.X-i.X)*(t.Y-i.Y)},e.ClipperBase.prototype.PointOnPolygon=function(t,i,n){for(var r=i;;){if(this.PointOnLineSegment(t,r.Pt,r.Next.Pt,n))return!0;if(r=r.Next,r===i)break}return!1},e.ClipperBase.prototype.SlopesEqual=e.ClipperBase.SlopesEqual=function(){var t=arguments,i=t.length,n,r,o,f,d,y,P;return i===3?(n=t[0],r=t[1],P=t[2],P?U.op_Equality(U.Int128Mul(n.Delta.Y,r.Delta.X),U.Int128Mul(n.Delta.X,r.Delta.Y)):e.Cast_Int64(n.Delta.Y*r.Delta.X)===e.Cast_Int64(n.Delta.X*r.Delta.Y)):i===4?(o=t[0],f=t[1],d=t[2],P=t[3],P?U.op_Equality(U.Int128Mul(o.Y-f.Y,f.X-d.X),U.Int128Mul(o.X-f.X,f.Y-d.Y)):e.Cast_Int64((o.Y-f.Y)*(f.X-d.X))-e.Cast_Int64((o.X-f.X)*(f.Y-d.Y))===0):(o=t[0],f=t[1],d=t[2],y=t[3],P=t[4],P?U.op_Equality(U.Int128Mul(o.Y-f.Y,d.X-y.X),U.Int128Mul(o.X-f.X,d.Y-y.Y)):e.Cast_Int64((o.Y-f.Y)*(d.X-y.X))-e.Cast_Int64((o.X-f.X)*(d.Y-y.Y))===0)},e.ClipperBase.SlopesEqual3=function(t,i,n){return n?U.op_Equality(U.Int128Mul(t.Delta.Y,i.Delta.X),U.Int128Mul(t.Delta.X,i.Delta.Y)):e.Cast_Int64(t.Delta.Y*i.Delta.X)===e.Cast_Int64(t.Delta.X*i.Delta.Y)},e.ClipperBase.SlopesEqual4=function(t,i,n,r){return r?U.op_Equality(U.Int128Mul(t.Y-i.Y,i.X-n.X),U.Int128Mul(t.X-i.X,i.Y-n.Y)):e.Cast_Int64((t.Y-i.Y)*(i.X-n.X))-e.Cast_Int64((t.X-i.X)*(i.Y-n.Y))===0},e.ClipperBase.SlopesEqual5=function(t,i,n,r,o){return o?U.op_Equality(U.Int128Mul(t.Y-i.Y,n.X-r.X),U.Int128Mul(t.X-i.X,n.Y-r.Y)):e.Cast_Int64((t.Y-i.Y)*(n.X-r.X))-e.Cast_Int64((t.X-i.X)*(n.Y-r.Y))===0},e.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var t=0,i=this.m_edges.length;t<i;++t){for(var n=0,r=this.m_edges[t].length;n<r;++n)this.m_edges[t][n]=null;e.Clear(this.m_edges[t])}e.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},e.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;this.m_MinimaList!==null;){var t=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=t}this.m_CurrentLM=null},e.ClipperBase.prototype.RangeTest=function(t,i){i.Value?(t.X>e.ClipperBase.hiRange||t.Y>e.ClipperBase.hiRange||-t.X>e.ClipperBase.hiRange||-t.Y>e.ClipperBase.hiRange)&&e.Error("Coordinate outside allowed range in RangeTest()."):(t.X>e.ClipperBase.loRange||t.Y>e.ClipperBase.loRange||-t.X>e.ClipperBase.loRange||-t.Y>e.ClipperBase.loRange)&&(i.Value=!0,this.RangeTest(t,i))},e.ClipperBase.prototype.InitEdge=function(t,i,n,r){t.Next=i,t.Prev=n,t.Curr.X=r.X,t.Curr.Y=r.Y,e.use_xyz&&(t.Curr.Z=r.Z),t.OutIdx=-1},e.ClipperBase.prototype.InitEdge2=function(t,i){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Curr.Z),t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y,e.use_xyz&&(t.Top.Z=t.Next.Curr.Z)):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,e.use_xyz&&(t.Top.Z=t.Curr.Z),t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Next.Curr.Z)),this.SetDx(t),t.PolyTyp=i},e.ClipperBase.prototype.FindNextLocMin=function(t){for(var i;;){for(;e.IntPoint.op_Inequality(t.Bot,t.Prev.Bot)||e.IntPoint.op_Equality(t.Curr,t.Top);)t=t.Next;if(t.Dx!==e.ClipperBase.horizontal&&t.Prev.Dx!==e.ClipperBase.horizontal)break;for(;t.Prev.Dx===e.ClipperBase.horizontal;)t=t.Prev;for(i=t;t.Dx===e.ClipperBase.horizontal;)t=t.Next;if(t.Top.Y!==t.Prev.Bot.Y){i.Prev.Bot.X<t.Bot.X&&(t=i);break}}return t},e.ClipperBase.prototype.ProcessBound=function(t,i){var n,r=t,o;if(r.OutIdx===e.ClipperBase.Skip){if(t=r,i){for(;t.Top.Y===t.Next.Bot.Y;)t=t.Next;for(;t!==r&&t.Dx===e.ClipperBase.horizontal;)t=t.Prev}else{for(;t.Top.Y===t.Prev.Bot.Y;)t=t.Prev;for(;t!==r&&t.Dx===e.ClipperBase.horizontal;)t=t.Next}if(t===r)i?r=t.Next:r=t.Prev;else{i?t=r.Next:t=r.Prev;var f=new e.LocalMinima;f.Next=null,f.Y=t.Bot.Y,f.LeftBound=null,f.RightBound=t,t.WindDelta=0,r=this.ProcessBound(t,i),this.InsertLocalMinima(f)}return r}if(t.Dx===e.ClipperBase.horizontal&&(i?n=t.Prev:n=t.Next,n.Dx===e.ClipperBase.horizontal?n.Bot.X!==t.Bot.X&&n.Top.X!==t.Bot.X&&this.ReverseHorizontal(t):n.Bot.X!==t.Bot.X&&this.ReverseHorizontal(t)),n=t,i){for(;r.Top.Y===r.Next.Bot.Y&&r.Next.OutIdx!==e.ClipperBase.Skip;)r=r.Next;if(r.Dx===e.ClipperBase.horizontal&&r.Next.OutIdx!==e.ClipperBase.Skip){for(o=r;o.Prev.Dx===e.ClipperBase.horizontal;)o=o.Prev;o.Prev.Top.X>r.Next.Top.X&&(r=o.Prev)}for(;t!==r;)t.NextInLML=t.Next,t.Dx===e.ClipperBase.horizontal&&t!==n&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),t=t.Next;t.Dx===e.ClipperBase.horizontal&&t!==n&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),r=r.Next}else{for(;r.Top.Y===r.Prev.Bot.Y&&r.Prev.OutIdx!==e.ClipperBase.Skip;)r=r.Prev;if(r.Dx===e.ClipperBase.horizontal&&r.Prev.OutIdx!==e.ClipperBase.Skip){for(o=r;o.Next.Dx===e.ClipperBase.horizontal;)o=o.Next;(o.Next.Top.X===r.Prev.Top.X||o.Next.Top.X>r.Prev.Top.X)&&(r=o.Next)}for(;t!==r;)t.NextInLML=t.Prev,t.Dx===e.ClipperBase.horizontal&&t!==n&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),t=t.Prev;t.Dx===e.ClipperBase.horizontal&&t!==n&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),r=r.Prev}return r},e.ClipperBase.prototype.AddPath=function(t,i,n){e.use_lines?!n&&i===e.PolyType.ptClip&&e.Error("AddPath: Open paths must be subject."):n||e.
1Error("AddPath: Open paths have been disabled.");var r=t.length-1;if(n)for(;r>0&&e.IntPoint.op_Equality(t[r],t[0]);)--r;for(;r>0&&e.IntPoint.op_Equality(t[r],t[r-1]);)--r;if(n&&r<2||!n&&r<1)return!1;for(var o=new Array,f=0;f<=r;f++)o.push(new e.TEdge);var d=!0;o[1].Curr.X=t[1].X,o[1].Curr.Y=t[1].Y,e.use_xyz&&(o[1].Curr.Z=t[1].Z);var y={Value:this.m_UseFullRange};this.RangeTest(t[0],y),this.m_UseFullRange=y.Value,y.Value=this.m_UseFullRange,this.RangeTest(t[r],y),this.m_UseFullRange=y.Value,this.InitEdge(o[0],o[1],o[r],t[0]),this.InitEdge(o[r],o[0],o[r-1],t[r]);for(var f=r-1;f>=1;--f)y.Value=this.m_UseFullRange,this.RangeTest(t[f],y),this.m_UseFullRange=y.Value,this.InitEdge(o[f],o[f+1],o[f-1],t[f]);for(var P=o[0],X=P,S=P;;){if(X.Curr===X.Next.Curr&&(n||X.Next!==P)){if(X===X.Next)break;X===P&&(P=X.Next),X=this.RemoveEdge(X),S=X;continue}if(X.Prev===X.Next)break;if(n&&e.ClipperBase.SlopesEqual4(X.Prev.Curr,X.Curr,X.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(X.Prev.Curr,X.Curr,X.Next.Curr))){X===P&&(P=X.Next),X=this.RemoveEdge(X),X=X.Prev,S=X;continue}if(X=X.Next,X===S||!n&&X.Next===P)break}if(!n&&X===X.Next||n&&X.Prev===X.Next)return!1;n||(this.m_HasOpenPaths=!0,P.Prev.OutIdx=e.ClipperBase.Skip),X=P;do this.InitEdge2(X,i),X=X.Next,d&&X.Curr.Y!==P.Curr.Y&&(d=!1);while(X!==P);if(d){if(n)return!1;X.Prev.OutIdx=e.ClipperBase.Skip;var w=new e.LocalMinima;for(w.Next=null,w.Y=X.Bot.Y,w.LeftBound=null,w.RightBound=X,w.RightBound.Side=e.EdgeSide.esRight,w.RightBound.WindDelta=0;X.Bot.X!==X.Prev.Top.X&&this.ReverseHorizontal(X),X.Next.OutIdx!==e.ClipperBase.Skip;)X.NextInLML=X.Next,X=X.Next;return this.InsertLocalMinima(w),this.m_edges.push(o),!0}this.m_edges.push(o);var E,D=null;for(e.IntPoint.op_Equality(X.Prev.Bot,X.Prev.Top)&&(X=X.Next);X=this.FindNextLocMin(X),X!==D;){D===null&&(D=X);var w=new e.LocalMinima;w.Next=null,w.Y=X.Bot.Y,X.Dx<X.Prev.Dx?(w.LeftBound=X.Prev,w.RightBound=X,E=!1):(w.LeftBound=X,w.RightBound=X.Prev,E=!0),w.LeftBound.Side=e.EdgeSide.esLeft,w.RightBound.Side=e.EdgeSide.esRight,n?w.LeftBound.Next===w.RightBound?w.LeftBound.WindDelta=-1:w.LeftBound.WindDelta=1:w.LeftBound.WindDelta=0,w.RightBound.WindDelta=-w.LeftBound.WindDelta,X=this.ProcessBound(w.LeftBound,E),X.OutIdx===e.ClipperBase.Skip&&(X=this.ProcessBound(X,E));var H=this.ProcessBound(w.RightBound,!E);H.OutIdx===e.ClipperBase.Skip&&(H=this.ProcessBound(H,!E)),w.LeftBound.OutIdx===e.ClipperBase.Skip?w.LeftBound=null:w.RightBound.OutIdx===e.ClipperBase.Skip&&(w.RightBound=null),this.InsertLocalMinima(w),E||(X=H)}return!0},e.ClipperBase.prototype.AddPaths=function(t,i,n){for(var r=!1,o=0,f=t.length;o<f;++o)this.AddPath(t[o],i,n)&&(r=!0);return r},e.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(t,i,n){return e.IntPoint.op_Equality(t,n)||e.IntPoint.op_Equality(t,i)||e.IntPoint.op_Equality(n,i)?!1:t.X!==n.X?i.X>t.X==i.X<n.X:i.Y>t.Y==i.Y<n.Y},e.ClipperBase.prototype.RemoveEdge=function(t){t.Prev.Next=t.Next,t.Next.Prev=t.Prev;var i=t.Next;return t.Prev=null,i},e.ClipperBase.prototype.SetDx=function(t){t.Delta.X=t.Top.X-t.Bot.X,t.Delta.Y=t.Top.Y-t.Bot.Y,t.Delta.Y===0?t.Dx=e.ClipperBase.horizontal:t.Dx=t.Delta.X/t.Delta.Y},e.ClipperBase.prototype.InsertLocalMinima=function(t){if(this.m_MinimaList===null)this.m_MinimaList=t;else if(t.Y>=this.m_MinimaList.Y)t.Next=this.m_MinimaList,this.m_MinimaList=t;else{for(var i=this.m_MinimaList;i.Next!==null&&t.Y<i.Next.Y;)i=i.Next;t.Next=i.Next,i.Next=t}},e.ClipperBase.prototype.PopLocalMinima=function(t,i){return i.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===t?(this.m_CurrentLM=this.m_CurrentLM.Next,!0):!1},e.ClipperBase.prototype.ReverseHorizontal=function(t){var i=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=i,e.use_xyz&&(i=t.Top.Z,t.Top.Z=t.Bot.Z,t.Bot.Z=i)},e.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,this.m_CurrentLM!==null){this.m_Scanbeam=null;for(var t=this.m_MinimaList;t!==null;){this.InsertScanbeam(t.Y);var i=t.LeftBound;i!==null&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,e.use_xyz&&(i.Curr.Z=i.Bot.Z),i.OutIdx=e.ClipperBase.Unassigned),i=t.RightBound,i!==null&&(i.Curr.X=i.Bot.X,i.Curr.Y=i.Bot.Y,e.use_xyz&&(i.Curr.Z=i.Bot.Z),i.OutIdx=e.ClipperBase.Unassigned),t=t.Next}this.m_ActiveEdges=null}},e.ClipperBase.prototype.InsertScanbeam=function(t){if(this.m_Scanbeam===null)this.m_Scanbeam=new e.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=t;else if(t>this.m_Scanbeam.Y){var i=new e.Scanbeam;i.Y=t,i.Next=this.m_Scanbeam,this.m_Scanbeam=i}else{for(var n=this.m_Scanbeam;n.Next!==null&&t<=n.Next.Y;)n=n.Next;if(t===n.Y)return;var r=new e.Scanbeam;r.Y=t,r.Next=n.Next,n.Next=r}},e.ClipperBase.prototype.PopScanbeam=function(t){return this.m_Scanbeam===null?(t.v=0,!1):(t.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},e.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},e.ClipperBase.prototype.CreateOutRec=function(){var t=new e.OutRec;return t.Idx=e.ClipperBase.Unassigned,t.IsHole=!1,t.IsOpen=!1,t.FirstLeft=null,t.Pts=null,t.BottomPt=null,t.PolyNode=null,this.m_PolyOuts.push(t),t.Idx=this.m_PolyOuts.length-1,t},e.ClipperBase.prototype.DisposeOutRec=function(t){var i=this.m_PolyOuts[t];
1i.Pts=null,i=null,this.m_PolyOuts[t]=null},e.ClipperBase.prototype.UpdateEdgeIntoAEL=function(t){t.NextInLML===null&&e.Error("UpdateEdgeIntoAEL: invalid call");var i=t.PrevInAEL,n=t.NextInAEL;return t.NextInLML.OutIdx=t.OutIdx,i!==null?i.NextInAEL=t.NextInLML:this.m_ActiveEdges=t.NextInLML,n!==null&&(n.PrevInAEL=t.NextInLML),t.NextInLML.Side=t.Side,t.NextInLML.WindDelta=t.WindDelta,t.NextInLML.WindCnt=t.WindCnt,t.NextInLML.WindCnt2=t.WindCnt2,t=t.NextInLML,t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,t.PrevInAEL=i,t.NextInAEL=n,e.ClipperBase.IsHorizontal(t)||this.InsertScanbeam(t.Top.Y),t},e.ClipperBase.prototype.SwapPositionsInAEL=function(t,i){if(!(t.NextInAEL===t.PrevInAEL||i.NextInAEL===i.PrevInAEL)){if(t.NextInAEL===i){var n=i.NextInAEL;n!==null&&(n.PrevInAEL=t);var r=t.PrevInAEL;r!==null&&(r.NextInAEL=i),i.PrevInAEL=r,i.NextInAEL=t,t.PrevInAEL=i,t.NextInAEL=n}else if(i.NextInAEL===t){var o=t.NextInAEL;o!==null&&(o.PrevInAEL=i);var f=i.PrevInAEL;f!==null&&(f.NextInAEL=t),t.PrevInAEL=f,t.NextInAEL=i,i.PrevInAEL=t,i.NextInAEL=o}else{var d=t.NextInAEL,y=t.PrevInAEL;t.NextInAEL=i.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=i.PrevInAEL,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t),i.NextInAEL=d,i.NextInAEL!==null&&(i.NextInAEL.PrevInAEL=i),i.PrevInAEL=y,i.PrevInAEL!==null&&(i.PrevInAEL.NextInAEL=i)}t.PrevInAEL===null?this.m_ActiveEdges=t:i.PrevInAEL===null&&(this.m_ActiveEdges=i)}},e.ClipperBase.prototype.DeleteFromAEL=function(t){var i=t.PrevInAEL,n=t.NextInAEL;i===null&&n===null&&t!==this.m_ActiveEdges||(i!==null?i.NextInAEL=n:this.m_ActiveEdges=n,n!==null&&(n.PrevInAEL=i),t.NextInAEL=null,t.PrevInAEL=null)},e.Clipper=function(t){typeof t>"u"&&(t=0),this.m_PolyOuts=null,this.m_ClipType=e.ClipType.ctIntersection,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=null,this.m_IntersectNodeComparer=null,this.m_ExecuteLocked=!1,this.m_ClipFillType=e.PolyFillType.pftEvenOdd,this.m_SubjFillType=e.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,e.ClipperBase.call(this),this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=new Array,this.m_IntersectNodeComparer=e.MyIntersectNodeSort.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=new Array,this.m_Joins=new Array,this.m_GhostJoins=new Array,this.ReverseSolution=(1&t)!==0,this.StrictlySimple=(2&t)!==0,this.PreserveCollinear=(4&t)!==0,e.use_xyz&&(this.ZFillFunction=null)},e.Clipper.ioReverseSolution=1,e.Clipper.ioStrictlySimple=2,e.Clipper.ioPreserveCollinear=4,e.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),e.ClipperBase.prototype.Clear.call(this))},e.Clipper.prototype.InsertMaxima=function(t){var i=new e.Maxima;if(i.X=t,this.m_Maxima===null)this.m_Maxima=i,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(t<this.m_Maxima.X)i.Next=this.m_Maxima,i.Prev=null,this.m_Maxima=i;else{for(var n=this.m_Maxima;n.Next!==null&&t>=n.Next.X;)n=n.Next;if(t===n.X)return;i.Next=n.Next,i.Prev=n,n.Next!==null&&(n.Next.Prev=i),n.Next=i}},e.Clipper.prototype.Execute=function(){var t=arguments,i=t.length,n=t[1]instanceof e.PolyTree;if(i===4&&!n){var r=t[0],o=t[1],f=t[2],d=t[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&e.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,e.Clear(o),this.m_SubjFillType=f,this.m_ClipFillType=d,this.m_ClipType=r,this.m_UsingPolyTree=!1;try{var y=this.ExecuteInternal();y&&this.BuildResult(o)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return y}else if(i===4&&n){var r=t[0],P=t[1],f=t[2],d=t[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=f,this.m_ClipFillType=d,this.m_ClipType=r,this.m_UsingPolyTree=!0;try{var y=this.ExecuteInternal();y&&this.BuildResult2(P)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return y}else if(i===2&&!n){var r=t[0],o=t[1];return this.Execute(r,o,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}else if(i===2&&n){var r=t[0],P=t[1];return this.Execute(r,P,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}},e.Clipper.prototype.FixHoleLinkage=function(t){if(!(t.FirstLeft===null||t.IsHole!==t.FirstLeft.IsHole&&t.FirstLeft.Pts!==null)){for(var i=t.FirstLeft;i!==null&&(i.IsHole===t.IsHole||i.Pts===null);)i=i.FirstLeft;t.FirstLeft=i}},e.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var t={},i={};if(!this.PopScanbeam(t))return!1;for(this.InsertLocalMinimaIntoAEL(t.v);this.PopScanbeam(i)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(i.v))return!1;this.ProcessEdgesAtTopOfScanbeam(i.v),t.v=i.v,this.InsertLocalMinimaIntoAEL(t.v)}var n,r,o;for(r=0,o=this.m_PolyOuts.length;r<o;r++)n=this.m_PolyOuts[r],!(n.Pts===null||n.IsOpen)&&(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts);for(this.JoinCommonEdges(),r=0,o=this.m_PolyOuts.length;r<o;r++)n=this.m_PolyOuts[r],n.Pts!==null&&(n.IsOpen?this.FixupOutPolyline(n):this.FixupOutPolygon(n));
1return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},e.Clipper.prototype.DisposeAllPolyPts=function(){for(var t=0,i=this.m_PolyOuts.length;t<i;++t)this.DisposeOutRec(t);e.Clear(this.m_PolyOuts)},e.Clipper.prototype.AddJoin=function(t,i,n){var r=new e.Join;r.OutPt1=t,r.OutPt2=i,r.OffPt.X=n.X,r.OffPt.Y=n.Y,e.use_xyz&&(r.OffPt.Z=n.Z),this.m_Joins.push(r)},e.Clipper.prototype.AddGhostJoin=function(t,i){var n=new e.Join;n.OutPt1=t,n.OffPt.X=i.X,n.OffPt.Y=i.Y,e.use_xyz&&(n.OffPt.Z=i.Z),this.m_GhostJoins.push(n)},e.Clipper.prototype.SetZ=function(t,i,n){if(this.ZFillFunction!==null){if(t.Z!==0||this.ZFillFunction===null)return;e.IntPoint.op_Equality(t,i.Bot)?t.Z=i.Bot.Z:e.IntPoint.op_Equality(t,i.Top)?t.Z=i.Top.Z:e.IntPoint.op_Equality(t,n.Bot)?t.Z=n.Bot.Z:e.IntPoint.op_Equality(t,n.Top)?t.Z=n.Top.Z:this.ZFillFunction(i.Bot,i.Top,n.Bot,n.Top,t)}},e.Clipper.prototype.InsertLocalMinimaIntoAEL=function(t){for(var i={},n,r;this.PopLocalMinima(t,i);){n=i.v.LeftBound,r=i.v.RightBound;var o=null;if(n===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(o=this.AddOutPt(r,r.Bot))):r===null?(this.InsertEdgeIntoAEL(n,null),this.SetWindingCount(n),this.IsContributing(n)&&(o=this.AddOutPt(n,n.Bot)),this.InsertScanbeam(n.Top.Y)):(this.InsertEdgeIntoAEL(n,null),this.InsertEdgeIntoAEL(r,n),this.SetWindingCount(n),r.WindCnt=n.WindCnt,r.WindCnt2=n.WindCnt2,this.IsContributing(n)&&(o=this.AddLocalMinPoly(n,r,n.Bot)),this.InsertScanbeam(n.Top.Y)),r!==null&&(e.ClipperBase.IsHorizontal(r)?(r.NextInLML!==null&&this.InsertScanbeam(r.NextInLML.Top.Y),this.AddEdgeToSEL(r)):this.InsertScanbeam(r.Top.Y)),!(n===null||r===null)){if(o!==null&&e.ClipperBase.IsHorizontal(r)&&this.m_GhostJoins.length>0&&r.WindDelta!==0)for(var f=0,d=this.m_GhostJoins.length;f<d;f++){var y=this.m_GhostJoins[f];this.HorzSegmentsOverlap(y.OutPt1.Pt.X,y.OffPt.X,r.Bot.X,r.Top.X)&&this.AddJoin(y.OutPt1,o,y.OffPt)}if(n.OutIdx>=0&&n.PrevInAEL!==null&&n.PrevInAEL.Curr.X===n.Bot.X&&n.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(n.PrevInAEL.Curr,n.PrevInAEL.Top,n.Curr,n.Top,this.m_UseFullRange)&&n.WindDelta!==0&&n.PrevInAEL.WindDelta!==0){var P=this.AddOutPt(n.PrevInAEL,n.Bot);this.AddJoin(o,P,n.Top)}if(n.NextInAEL!==r){if(r.OutIdx>=0&&r.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(r.PrevInAEL.Curr,r.PrevInAEL.Top,r.Curr,r.Top,this.m_UseFullRange)&&r.WindDelta!==0&&r.PrevInAEL.WindDelta!==0){var P=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(o,P,r.Top)}var X=n.NextInAEL;if(X!==null)for(;X!==r;)this.IntersectEdges(r,X,n.Curr),X=X.NextInAEL}}}},e.Clipper.prototype.InsertEdgeIntoAEL=function(t,i){if(this.m_ActiveEdges===null)t.PrevInAEL=null,t.NextInAEL=null,this.m_ActiveEdges=t;else if(i===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,t))t.PrevInAEL=null,t.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=t,this.m_ActiveEdges=t;else{for(i===null&&(i=this.m_ActiveEdges);i.NextInAEL!==null&&!this.E2InsertsBeforeE1(i.NextInAEL,t);)i=i.NextInAEL;t.NextInAEL=i.NextInAEL,i.NextInAEL!==null&&(i.NextInAEL.PrevInAEL=t),t.PrevInAEL=i,i.NextInAEL=t}},e.Clipper.prototype.E2InsertsBeforeE1=function(t,i){return i.Curr.X===t.Curr.X?i.Top.Y>t.Top.Y?i.Top.X<e.Clipper.TopX(t,i.Top.Y):t.Top.X>e.Clipper.TopX(i,t.Top.Y):i.Curr.X<t.Curr.X},e.Clipper.prototype.IsEvenOddFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType===e.PolyFillType.pftEvenOdd:this.m_ClipFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsEvenOddAltFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_ClipFillType===e.PolyFillType.pftEvenOdd:this.m_SubjFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsContributing=function(t){var i,n;switch(t.PolyTyp===e.PolyType.ptSubject?(i=this.m_SubjFillType,n=this.m_ClipFillType):(i=this.m_ClipFillType,n=this.m_SubjFillType),i){case e.PolyFillType.pftEvenOdd:if(t.WindDelta===0&&t.WindCnt!==1)return!1;break;case e.PolyFillType.pftNonZero:if(Math.abs(t.WindCnt)!==1)return!1;break;case e.PolyFillType.pftPositive:if(t.WindCnt!==1)return!1;break;default:if(t.WindCnt!==-1)return!1;break}switch(this.m_ClipType){case e.ClipType.ctIntersection:switch(n){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctUnion:switch(n){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}
1case e.ClipType.ctDifference:if(t.PolyTyp===e.PolyType.ptSubject)switch(n){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(n){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctXor:if(t.WindDelta===0)switch(n){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else return!0}return!0},e.Clipper.prototype.SetWindingCount=function(t){for(var i=t.PrevInAEL;i!==null&&(i.PolyTyp!==t.PolyTyp||i.WindDelta===0);)i=i.PrevInAEL;if(i===null){var n=t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;t.WindDelta===0?t.WindCnt=n===e.PolyFillType.pftNegative?-1:1:t.WindCnt=t.WindDelta,t.WindCnt2=0,i=this.m_ActiveEdges}else if(t.WindDelta===0&&this.m_ClipType!==e.ClipType.ctUnion)t.WindCnt=1,t.WindCnt2=i.WindCnt2,i=i.NextInAEL;else if(this.IsEvenOddFillType(t)){if(t.WindDelta===0){for(var r=!0,o=i.PrevInAEL;o!==null;)o.PolyTyp===i.PolyTyp&&o.WindDelta!==0&&(r=!r),o=o.PrevInAEL;t.WindCnt=r?0:1}else t.WindCnt=t.WindDelta;t.WindCnt2=i.WindCnt2,i=i.NextInAEL}else i.WindCnt*i.WindDelta<0?Math.abs(i.WindCnt)>1?i.WindDelta*t.WindDelta<0?t.WindCnt=i.WindCnt:t.WindCnt=i.WindCnt+t.WindDelta:t.WindCnt=t.WindDelta===0?1:t.WindDelta:t.WindDelta===0?t.WindCnt=i.WindCnt<0?i.WindCnt-1:i.WindCnt+1:i.WindDelta*t.WindDelta<0?t.WindCnt=i.WindCnt:t.WindCnt=i.WindCnt+t.WindDelta,t.WindCnt2=i.WindCnt2,i=i.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;i!==t;)i.WindDelta!==0&&(t.WindCnt2=t.WindCnt2===0?1:0),i=i.NextInAEL;else for(;i!==t;)t.WindCnt2+=i.WindDelta,i=i.NextInAEL},e.Clipper.prototype.AddEdgeToSEL=function(t){this.m_SortedEdges===null?(this.m_SortedEdges=t,t.PrevInSEL=null,t.NextInSEL=null):(t.NextInSEL=this.m_SortedEdges,t.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=t,this.m_SortedEdges=t)},e.Clipper.prototype.PopEdgeFromSEL=function(t){if(t.v=this.m_SortedEdges,t.v===null)return!1;var i=t.v;return this.m_SortedEdges=t.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),i.NextInSEL=null,i.PrevInSEL=null,!0},e.Clipper.prototype.CopyAELToSEL=function(){var t=this.m_ActiveEdges;for(this.m_SortedEdges=t;t!==null;)t.PrevInSEL=t.PrevInAEL,t.NextInSEL=t.NextInAEL,t=t.NextInAEL},e.Clipper.prototype.SwapPositionsInSEL=function(t,i){if(!(t.NextInSEL===null&&t.PrevInSEL===null)&&!(i.NextInSEL===null&&i.PrevInSEL===null)){if(t.NextInSEL===i){var n=i.NextInSEL;n!==null&&(n.PrevInSEL=t);var r=t.PrevInSEL;r!==null&&(r.NextInSEL=i),i.PrevInSEL=r,i.NextInSEL=t,t.PrevInSEL=i,t.NextInSEL=n}else if(i.NextInSEL===t){var n=t.NextInSEL;n!==null&&(n.PrevInSEL=i);var r=i.PrevInSEL;r!==null&&(r.NextInSEL=t),t.PrevInSEL=r,t.NextInSEL=i,i.PrevInSEL=t,i.NextInSEL=n}else{var n=t.NextInSEL,r=t.PrevInSEL;t.NextInSEL=i.NextInSEL,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=i.PrevInSEL,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t),i.NextInSEL=n,i.NextInSEL!==null&&(i.NextInSEL.PrevInSEL=i),i.PrevInSEL=r,i.PrevInSEL!==null&&(i.PrevInSEL.NextInSEL=i)}t.PrevInSEL===null?this.m_SortedEdges=t:i.PrevInSEL===null&&(this.m_SortedEdges=i)}},e.Clipper.prototype.AddLocalMaxPoly=function(t,i,n){this.AddOutPt(t,n),i.WindDelta===0&&this.AddOutPt(i,n),t.OutIdx===i.OutIdx?(t.OutIdx=-1,i.OutIdx=-1):t.OutIdx<i.OutIdx?this.AppendPolygon(t,i):this.AppendPolygon(i,t)},e.Clipper.prototype.AddLocalMinPoly=function(t,i,n){var r,o,f;if(e.ClipperBase.IsHorizontal(i)||t.Dx>i.Dx?(r=this.AddOutPt(t,n),i.OutIdx=t.OutIdx,t.Side=e.EdgeSide.esLeft,i.Side=e.EdgeSide.esRight,o=t,o.PrevInAEL===i?f=i.PrevInAEL:f=o.PrevInAEL):(r=this.AddOutPt(i,n),t.OutIdx=i.OutIdx,t.Side=e.EdgeSide.esRight,i.Side=e.EdgeSide.esLeft,o=i,o.PrevInAEL===t?f=t.PrevInAEL:f=o.PrevInAEL),f!==null&&f.OutIdx>=0&&f.Top.Y<n.Y&&o.Top.Y<n.Y){var d=e.Clipper.TopX(f,n.Y),y=e.Clipper.TopX(o,n.Y);if(d===y&&o.WindDelta!==0&&f.WindDelta!==0&&e.ClipperBase.SlopesEqual5(new e.IntPoint2(d,n.Y),f.Top,new e.IntPoint2(y,n.Y),o.Top,this.m_UseFullRange)){var P=this.AddOutPt(f,n);this.AddJoin(r,P,o.Top)}}return r},e.Clipper.prototype.AddOutPt=function(t,i){if(t.OutIdx<0){var n=this.CreateOutRec();n.IsOpen=t.WindDelta===0;var r=new e.OutPt;return n.Pts=r,r.Idx=n.Idx,r.Pt.X=i.X,r.Pt.Y=i.Y,e.use_xyz&&(r.Pt.Z=i.Z),r.Next=r,r.Prev=r,n.IsOpen||this.SetHoleState(t,n),t.OutIdx=n.Idx,r}else{var n=this.m_PolyOuts[t.OutIdx],o=n.Pts,f=t.Side===e.EdgeSide.esLeft;if(f&&e.IntPoint.op_Equality(i,o.Pt))return o;if(!f&&e.IntPoint.op_Equality(i,o.Prev.Pt))return o.Prev;var r=new e.OutPt;return r.Idx=n.Idx,r.Pt.X=i.X,r.Pt.Y=i.Y,e.use_xyz&&(r.Pt.Z=i.Z),r.Next=o,r.Prev=o.Prev,r.Prev.Next=r,o.Prev=r,f&&(n.Pts=r),r}},e.Clipper.prototype.GetLastOutPt=function(t){var i=this.m_PolyOuts[t.OutIdx];return t.Side===e.EdgeSide.esLeft?i.Pts:i.Pts.Prev},e.Clipper.prototype.SwapPoints=function(t,i){var n=new e.IntPoint1(t.Value);t.Value.X=i.Value.X,t.Value.Y=i.Value.Y,e.use_xyz&&(t.Value.Z=i.Value.Z),i.Value.X=n.X,i.Value.Y=n.Y,e.use_xyz&&(i.Value.Z=n.Z)},e.Clipper.prototype.HorzSegmentsOverlap=function(t,i,n,r){var o;return t>i&&(o=t,t=i,i=o),n>r&&(o=n,n=r,r=o),t<r&&n<i},e.Clipper.prototype.SetHoleState=function(t,i){for(var n=t.PrevInAEL,r=null;n!==null;)n.OutIdx>=0&&n.WindDelta!==0&&(r===null?r=n:r.OutIdx===n.OutIdx&&(r=null)),n=n.PrevInAEL;r===null?(i.FirstLeft=null,i.IsHole=!1):(i.FirstLeft=this.m_PolyOuts[r.OutIdx],i.IsHole=!i.FirstLeft.IsHole)},e.Clipper.prototype.GetDx=function(t,i){return t.Y===i.Y?e.ClipperBase.horizontal:(i.X-t.X)/(i.Y-t.Y)},e.Clipper.prototype.FirstIsBottomPt=function(t,i){for(var n=t.Prev;e.IntPoint.op_Equality(n.Pt,t.Pt)&&n!==t;)n=n.Prev;var r=Math.abs(this.GetDx(t.Pt,n.Pt));for(n=t.Next;e.IntPoint.op_Equality(n.Pt,t.Pt)&&n!==t;)n=n.Next;var o=Math.abs(this.GetDx(t.Pt,n.Pt));for(n=i.Prev;e.IntPoint.op_Equality(n.Pt,i.Pt)&&n!==i;)n=n.Prev;var f=Math.abs(this.GetDx(i.Pt,n.Pt));for(n=i.Next;e.IntPoint.op_Equality(n.Pt,i.Pt)&&n!==i;)n=n.Next;var d=Math.abs(this.GetDx(i.Pt,n.Pt));return Math.max(r,o)===Math.max(f,d)&&Math.min(r,o)===Math.min(f,d)?this.Area(t)>0:r>=f&&r>=d||o>=f&&o>=d},e.Clipper.prototype.GetBottomPt=function(t){for(var i=null,n=t.Next;n!==t;)n.Pt.Y>t.Pt.Y?(t=n,i=null):n.Pt.Y===t.Pt.Y&&n.Pt.X<=t.Pt.X&&(n.Pt.X<t.Pt.X?(i=null,t=n):n.Next!==t&&n.Prev!==t&&(i=n)),n=n.Next;if(i!==null)for(;i!==n;)for(this.FirstIsBottomPt(n,i)||(t=i),i=i.Next;e.IntPoint.op_Inequality(i.Pt,t.Pt);)i=i.Next;return t},e.Clipper.prototype.GetLowermostRec=function(t,i){t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts)),i.BottomPt===null&&(i.BottomPt=this.GetBottomPt(i.Pt
1s));var n=t.BottomPt,r=i.BottomPt;return n.Pt.Y>r.Pt.Y?t:n.Pt.Y<r.Pt.Y?i:n.Pt.X<r.Pt.X?t:n.Pt.X>r.Pt.X||n.Next===n?i:r.Next===r||this.FirstIsBottomPt(n,r)?t:i},e.Clipper.prototype.OutRec1RightOfOutRec2=function(t,i){do if(t=t.FirstLeft,t===i)return!0;while(t!==null);return!1},e.Clipper.prototype.GetOutRec=function(t){for(var i=this.m_PolyOuts[t];i!==this.m_PolyOuts[i.Idx];)i=this.m_PolyOuts[i.Idx];return i},e.Clipper.prototype.AppendPolygon=function(t,i){var n=this.m_PolyOuts[t.OutIdx],r=this.m_PolyOuts[i.OutIdx],o;this.OutRec1RightOfOutRec2(n,r)?o=r:this.OutRec1RightOfOutRec2(r,n)?o=n:o=this.GetLowermostRec(n,r);var f=n.Pts,d=f.Prev,y=r.Pts,P=y.Prev;t.Side===e.EdgeSide.esLeft?i.Side===e.EdgeSide.esLeft?(this.ReversePolyPtLinks(y),y.Next=f,f.Prev=y,d.Next=P,P.Prev=d,n.Pts=P):(P.Next=f,f.Prev=P,y.Prev=d,d.Next=y,n.Pts=y):i.Side===e.EdgeSide.esRight?(this.ReversePolyPtLinks(y),d.Next=P,P.Prev=d,y.Next=f,f.Prev=y):(d.Next=y,y.Prev=d,f.Prev=P,P.Next=f),n.BottomPt=null,o===r&&(r.FirstLeft!==n&&(n.FirstLeft=r.FirstLeft),n.IsHole=r.IsHole),r.Pts=null,r.BottomPt=null,r.FirstLeft=n;var X=t.OutIdx,S=i.OutIdx;t.OutIdx=-1,i.OutIdx=-1;for(var w=this.m_ActiveEdges;w!==null;){if(w.OutIdx===S){w.OutIdx=X,w.Side=t.Side;break}w=w.NextInAEL}r.Idx=n.Idx},e.Clipper.prototype.ReversePolyPtLinks=function(t){if(t!==null){var i,n;i=t;do n=i.Next,i.Next=i.Prev,i.Prev=n,i=n;while(i!==t)}},e.Clipper.SwapSides=function(t,i){var n=t.Side;t.Side=i.Side,i.Side=n},e.Clipper.SwapPolyIndexes=function(t,i){var n=t.OutIdx;t.OutIdx=i.OutIdx,i.OutIdx=n},e.Clipper.prototype.IntersectEdges=function(t,i,n){var r=t.OutIdx>=0,o=i.OutIdx>=0;if(e.use_xyz&&this.SetZ(n,t,i),e.use_lines&&(t.WindDelta===0||i.WindDelta===0)){if(t.WindDelta===0&&i.WindDelta===0)return;t.PolyTyp===i.PolyTyp&&t.WindDelta!==i.WindDelta&&this.m_ClipType===e.ClipType.ctUnion?t.WindDelta===0?o&&(this.AddOutPt(t,n),r&&(t.OutIdx=-1)):r&&(this.AddOutPt(i,n),o&&(i.OutIdx=-1)):t.PolyTyp!==i.PolyTyp&&(t.WindDelta===0&&Math.abs(i.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||i.WindCnt2===0)?(this.AddOutPt(t,n),r&&(t.OutIdx=-1)):i.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||t.WindCnt2===0)&&(this.AddOutPt(i,n),o&&(i.OutIdx=-1)));return}if(t.PolyTyp===i.PolyTyp)if(this.IsEvenOddFillType(t)){var f=t.WindCnt;t.WindCnt=i.WindCnt,i.WindCnt=f}else t.WindCnt+i.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt+=i.WindDelta,i.WindCnt-t.WindDelta===0?i.WindCnt=-i.WindCnt:i.WindCnt-=t.WindDelta;else this.IsEvenOddFillType(i)?t.WindCnt2=t.WindCnt2===0?1:0:t.WindCnt2+=i.WindDelta,this.IsEvenOddFillType(t)?i.WindCnt2=i.WindCnt2===0?1:0:i.WindCnt2-=t.WindDelta;var d,y,P,X;t.PolyTyp===e.PolyType.ptSubject?(d=this.m_SubjFillType,P=this.m_ClipFillType):(d=this.m_ClipFillType,P=this.m_SubjFillType),i.PolyTyp===e.PolyType.ptSubject?(y=this.m_SubjFillType,X=this.m_ClipFillType):(y=this.m_ClipFillType,X=this.m_SubjFillType);var S,w;switch(d){case e.PolyFillType.pftPositive:S=t.WindCnt;break;case e.PolyFillType.pftNegative:S=-t.WindCnt;break;default:S=Math.abs(t.WindCnt);break}switch(y){case e.PolyFillType.pftPositive:w=i.WindCnt;break;case e.PolyFillType.pftNegative:w=-i.WindCnt;break;default:w=Math.abs(i.WindCnt);break}if(r&&o)S!==0&&S!==1||w!==0&&w!==1||t.PolyTyp!==i.PolyTyp&&this.m_ClipType!==e.ClipType.ctXor?this.AddLocalMaxPoly(t,i,n):(this.AddOutPt(t,n),this.AddOutPt(i,n),e.Clipper.SwapSides(t,i),e.Clipper.SwapPolyIndexes(t,i));else if(r)(w===0||w===1)&&(this.AddOutPt(t,n),e.Clipper.SwapSides(t,i),e.Clipper.SwapPolyIndexes(t,i));else if(o)(S===0||S===1)&&(this.AddOutPt(i,n),e.Clipper.SwapSides(t,i),e.Clipper.SwapPolyIndexes(t,i));else if((S===0||S===1)&&(w===0||w===1)){var E,D;switch(P){case e.PolyFillType.pftPositive:E=t.WindCnt2;break;case e.PolyFillType.pftNegative:E=-t.WindCnt2;break;default:E=Math.abs(t.WindCnt2);break}switch(X){case e.PolyFillType.pftPositive:D=i.WindCnt2;break;case e.PolyFillType.pftNegative:D=-i.WindCnt2;break;default:D=Math.abs(i.WindCnt2);break}if(t.PolyTyp!==i.PolyTyp)this.AddLocalMinPoly(t,i,n);else if(S===1&&w===1)switch(this.m_ClipType){case e.ClipType.ctIntersection:E>0&&D>0&&this.AddLocalMinPoly(t,i,n);break;case e.ClipType.ctUnion:E<=0&&D<=0&&this.AddLocalMinPoly(t,i,n);break;case e.ClipType.ctDifference:(t.PolyTyp===e.PolyType.ptClip&&E>0&&D>0||t.PolyTyp===e.PolyType.ptSubject&&E<=0&&D<=0)&&this.AddLocalMinPoly(t,i,n);break;case e.ClipType.ctXor:this.AddLocalMinPoly(t,i,n);break}else e.Clipper.SwapSides(t,i)}},e.Clipper.prototype.DeleteFromSEL=function(t){var i=t.PrevInSEL,n=t.NextInSEL;i===null&&n===null&&t!==this.m_SortedEdges||(i!==null?i.NextInSEL=n:this.m_SortedEdges=n,n!==null&&(n.PrevInSEL=i),t.NextInSEL=null,t.PrevInSEL=null)},e.Clipper.prototype.ProcessHorizontals=function(){for(var t={};this.PopEdgeFromSEL(t);)this.ProcessHorizontal(t.v)},e.Clipper.prototype.GetHorzDirection=function(t,i){t.Bot.X<t.Top.X?(i.Left=t.Bot.X,i.Right=t.Top.X,i.Dir=e.Direction.dLeftToRight):(i.Left=t.Top.X,i.Right=t.Bot.X,i.Dir=e.Direction.dRightToLeft)},e.Clipper.prototype.ProcessHorizontal=function(t){var i={Dir:null,Left:null,Right:null};this.GetHorzDirection(t,i);for(var n=i.Dir,r=i.Left,o=i.Right,f=t.WindDelta===0,d=t,y=null;d.NextInLML!==null&&e.ClipperBase.IsHorizontal(d.NextInLML);)d=d.NextInLML;d.NextInLML===null&&(y=this.GetMaximaPair(d));var P=this.m_Maxima;if(P!==null)if(n===e.Direction.dLeftToRight){for(;P!==null&&P.X<=t.Bot.X;)P=P.Next;P!==null&&P.X>=d.Top.X&&(P=null)}else{for(;P.Next!==null&&P.Next.X<t.Bot.X;)P=P.Next;P.X<=d.Top.X&&(P=null)}for(var X=null;;){for(var S=t===d,w=this.GetNextInAEL(t,n);w!==null;){if(P!==null)if(n===e.Direction.dLeftToRight)for(;P!==null&&P.X<w.Curr.X;)t.OutIdx>=0&&!f&&this.AddOutPt(t,new e.IntPoint2(P.X,t.Bot.Y)),P=P.Next;else for(;P!==null&&P.X>w.Curr.X;)t.OutIdx>=0&&!f&&this.AddOutPt(t,new e.IntPoint2(P.X,t.Bot.Y)),P=P.Prev;if(n===e.Direction.dLeftToRight&&w.Curr.X>o||n===e.Direction.dRightToLeft&&w.Curr.X<r||w.Curr.X===t.Top.X&&t.NextInLML!==null&&w.Dx<t.NextInLML.Dx)break;if(t.OutIdx>=0&&!f){e.use_xyz&&(n===e.Direction.dLeftToRight?this.SetZ(w.Curr,t,w):this.SetZ(w.Curr,w,t)),X=this.AddOutPt(t,w.Curr);for(var E=this.m_SortedEdges;E!==null;){if(E.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,E.Bot.X,E.Top.X)){var D=this.GetLastOutPt(E);this.AddJoin(D,X,E.Top)}E=E.NextInSEL}this.AddGhostJoin(X,t.Bot)}if(w===y&&S){t.OutIdx>=0&&this.AddLocalMaxPoly(t,y,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(y);return}if(n===e.Direction.dLeftToRight){var H=new e.IntPoint2(w.Curr.X,t.Curr.Y);this.IntersectEdges(t,w,H)}else{var H=new e.IntPoint2(w.Curr.X,t.Curr.Y);this.IntersectEdges(w,t,H)}var J=this.GetNextInAEL(w,n);this.SwapPositionsInAEL(t,w),w=J}if(t.NextInLML===null||!e.ClipperBase.IsHorizontal(t.NextInLML))break;t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),i={Dir:n,Left:r,Right:o},this.GetHorzDirection(t,i),n=i.Dir,r=i.Left,o=i.Right}if(t.OutIdx>=0&&X===null){X=this.GetLastOutPt(t);for(var E=this.m_SortedEdges;E!==null;){if(E.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,E.Bot.X,E.Top.X)){var D=this.GetLastOutPt(E);this.AddJoin(D,X,E.Top)}E=E.NextInSEL}this.AddGhostJoin(X,t.Top)}if(t.NextInLML!==null)if(t.OutIdx>=0){if(X=this.AddOutPt(t,t.Top),t=this.UpdateEdgeIntoAEL(t),t.WindDelta===0)return;var tt=t.PrevInAEL,J=t.NextInAEL;if(tt!==null&&tt.Curr.X===t.Bot.X&&tt.Curr.Y===t.Bot.Y&&tt.WindDelta===0&&tt.OutIdx>=0&&tt.Curr.Y>tt.Top.Y&&e.ClipperBase.SlopesEqual3(t,tt,this.m_UseFullRange)){var D=this.AddOutPt(tt,t.Bot);this.AddJoin(X,D,t.Top)}else if(J!==null&&J.Curr.X===t.Bot.X&&J.Curr.Y===t.Bot.Y&&J.WindDelta!==0&&J.OutIdx>=0&&J.Curr.Y>J.Top.Y&&e.ClipperBase.SlopesEqual3(t,J,this.m_UseFullRange)){var D=this.AddOutPt(J,t.Bot);this.AddJoin(X,D,t.Top)}}else t=this.UpdateEdgeIntoAEL(t);else t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t)},e.Clipper.prototype.GetNextInAEL=function(t,i){return i===e.Direction.dLeftToRight?t.NextInAEL:t.PrevInAEL},e.Clipper.prototype.IsMinima=function(t){return t!==null&&t.Prev.NextInLML!==t&&t.Next.NextInLML!==t},e.Clipper.prototype.IsMaxima=function(t,i){return t!==null&&t.Top.Y===i&&t.NextInLML===null},e.Clipper.prototype.IsIntermediate=function(t,i){return t.Top.Y===i&&t.NextInLML!==null},e.Clipper.prototype.GetMaximaPair=function(t){return e.IntPoint.op_Equality(t.Next.Top,t.Top)&&t.Next.NextInLML===null?t.Next:e.IntPoint.op_Equality(t.Prev.Top,t.Top)&&t.Prev.NextInLML===null?t.Prev:null},e.Clipper.prototype.GetMaximaPairEx=function(t){var i=this.GetMaximaPair(t);return i===null||i.OutIdx===e.ClipperBase.Skip||i.NextInAEL===i.PrevInAEL&&!e.ClipperBase.IsHorizontal(i)?null:i},e.Clipper.prototype.ProcessIntersections=function(t){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(t),this.m_IntersectList.length===0)return!0;
1if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,e.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0},e.Clipper.prototype.BuildIntersectList=function(t){if(this.m_ActiveEdges!==null){var i=this.m_ActiveEdges;for(this.m_SortedEdges=i;i!==null;)i.PrevInSEL=i.PrevInAEL,i.NextInSEL=i.NextInAEL,i.Curr.X=e.Clipper.TopX(i,t),i=i.NextInAEL;for(var n=!0;n&&this.m_SortedEdges!==null;){for(n=!1,i=this.m_SortedEdges;i.NextInSEL!==null;){var r=i.NextInSEL,o=new e.IntPoint0;if(i.Curr.X>r.Curr.X){this.IntersectPoint(i,r,o),o.Y<t&&(o=new e.IntPoint2(e.Clipper.TopX(i,t),t));var f=new e.IntersectNode;f.Edge1=i,f.Edge2=r,f.Pt.X=o.X,f.Pt.Y=o.Y,e.use_xyz&&(f.Pt.Z=o.Z),this.m_IntersectList.push(f),this.SwapPositionsInSEL(i,r),n=!0}else i=r}if(i.PrevInSEL!==null)i.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},e.Clipper.prototype.EdgesAdjacent=function(t){return t.Edge1.NextInSEL===t.Edge2||t.Edge1.PrevInSEL===t.Edge2},e.Clipper.IntersectNodeSort=function(t,i){return i.Pt.Y-t.Pt.Y},e.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var t=this.m_IntersectList.length,i=0;i<t;i++){if(!this.EdgesAdjacent(this.m_IntersectList[i])){for(var n=i+1;n<t&&!this.EdgesAdjacent(this.m_IntersectList[n]);)n++;if(n===t)return!1;var r=this.m_IntersectList[i];this.m_IntersectList[i]=this.m_IntersectList[n],this.m_IntersectList[n]=r}this.SwapPositionsInSEL(this.m_IntersectList[i].Edge1,this.m_IntersectList[i].Edge2)}return!0},e.Clipper.prototype.ProcessIntersectList=function(){for(var t=0,i=this.m_IntersectList.length;t<i;t++){var n=this.m_IntersectList[t];this.IntersectEdges(n.Edge1,n.Edge2,n.Pt),this.SwapPositionsInAEL(n.Edge1,n.Edge2)}this.m_IntersectList.length=0};var Xs=function(t){return t<0?Math.ceil(t-.5):Math.round(t)},Ls=function(t){return t<0?Math.ceil(t-.5):Math.floor(t+.5)},gs=function(t){return t<0?-Math.round(Math.abs(t)):Math.round(t)},ws=function(t){return t<0?(t-=.5,t<-2147483648?Math.ceil(t):t|0):(t+=.5,t>2147483647?Math.floor(t):t|0)};h.msie?e.Clipper.Round=Xs:h.chromium?e.Clipper.Round=gs:h.safari?e.Clipper.Round=ws:e.Clipper.Round=Ls,e.Clipper.TopX=function(t,i){return i===t.Top.Y?t.Top.X:t.Bot.X+e.Clipper.Round(t.Dx*(i-t.Bot.Y))},e.Clipper.prototype.IntersectPoint=function(t,i,n){n.X=0,n.Y=0;var r,o;if(t.Dx===i.Dx){n.Y=t.Curr.Y,n.X=e.Clipper.TopX(t,n.Y);return}if(t.Delta.X===0)n.X=t.Bot.X,e.ClipperBase.IsHorizontal(i)?n.Y=i.Bot.Y:(o=i.Bot.Y-i.Bot.X/i.Dx,n.Y=e.Clipper.Round(n.X/i.Dx+o));else if(i.Delta.X===0)n.X=i.Bot.X,e.ClipperBase.IsHorizontal(t)?n.Y=t.Bot.Y:(r=t.Bot.Y-t.Bot.X/t.Dx,n.Y=e.Clipper.Round(n.X/t.Dx+r));else{r=t.Bot.X-t.Bot.Y*t.Dx,o=i.Bot.X-i.Bot.Y*i.Dx;var f=(o-r)/(t.Dx-i.Dx);n.Y=e.Clipper.Round(f),Math.abs(t.Dx)<Math.abs(i.Dx)?n.X=e.Clipper.Round(t.Dx*f+r):n.X=e.Clipper.Round(i.Dx*f+o)}if(n.Y<t.Top.Y||n.Y<i.Top.Y){if(t.Top.Y>i.Top.Y)return n.Y=t.Top.Y,n.X=e.Clipper.TopX(i,t.Top.Y),n.X<t.Top.X;n.Y=i.Top.Y,Math.abs(t.Dx)<Math.abs(i.Dx)?n.X=e.Clipper.TopX(t,n.Y):n.X=e.Clipper.TopX(i,n.Y)}n.Y>t.Curr.Y&&(n.Y=t.Curr.Y,Math.abs(t.Dx)>Math.abs(i.Dx)?n.X=e.Clipper.TopX(i,n.Y):n.X=e.Clipper.TopX(t,n.Y))},e.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(t){for(var i=this.m_ActiveEdges;i!==null;){var n=this.IsMaxima(i,t);if(n){var r=this.GetMaximaPairEx(i);n=r===null||!e.ClipperBase.IsHorizontal(r)}if(n){this.StrictlySimple&&this.InsertMaxima(i.Top.X);var o=i.PrevInAEL;this.DoMaxima(i),o===null?i=this.m_ActiveEdges:i=o.NextInAEL}else{if(this.IsIntermediate(i,t)&&e.ClipperBase.IsHorizontal(i.NextInLML)?(i=this.UpdateEdgeIntoAEL(i),i.OutIdx>=0&&this.AddOutPt(i,i.Bot),this.AddEdgeToSEL(i)):(i.Curr.X=e.Clipper.TopX(i,t),i.Curr.Y=t),e.use_xyz&&(i.Top.Y===t?i.Curr.Z=i.Top.Z:i.Bot.Y===t?i.Curr.Z=i.Bot.Z:i.Curr.Z=0),this.StrictlySimple){var o=i.PrevInAEL;if(i.OutIdx>=0&&i.WindDelta!==0&&o!==null&&o.OutIdx>=0&&o.Curr.X===i.Curr.X&&o.WindDelta!==0){var f=new e.IntPoint1(i.Curr);e.use_xyz&&this.SetZ(f,o,i);var d=this.AddOutPt(o,f),y=this.AddOutPt(i,f);this.AddJoin(d,y,f)}}i=i.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,i=this.m_ActiveEdges;i!==null;){if(this.IsIntermediate(i,t)){var d=null;i.OutIdx>=0&&(d=this.AddOutPt(i,i.Top)),i=this.UpdateEdgeIntoAEL(i);var o=i.PrevInAEL,P=i.NextInAEL;if(o!==null&&o.Curr.X===i.Bot.X&&o.Curr.Y===i.Bot.Y&&d!==null&&o.OutIdx>=0&&o.Curr.Y===o.Top.Y&&e.ClipperBase.SlopesEqual5(i.Curr,i.Top,o.Curr,o.Top,this.m_UseFullRange)&&i.WindDelta!==0&&o.WindDelta!==0){var y=this.AddOutPt(ePrev2,i.Bot);this.AddJoin(d,y,i.Top)}else if(P!==null&&P.Curr.X===i.Bot.X&&P.Curr.Y===i.Bot.Y&&d!==null&&P.OutIdx>=0&&P.Curr.Y===P.Top.Y&&e.ClipperBase.SlopesEqual5(i.Curr,i.Top,P.Curr,P.Top,this.m_UseFullRange)&&i.WindDelta!==0&&P.WindDelta!==0){var y=this.AddOutPt(P,i.Bot);this.AddJoin(d,y,i.Top)}}i=i.NextInAEL}},e.Clipper.prototype.DoMaxima=function(t){var i=this.GetMaximaPairEx(t);if(i===null){t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t);return}for(var n=t.NextInAEL;n!==null&&n!==i;)this.IntersectEdges(t,n,t.Top),this.SwapPositionsInAEL(t,n),n=t.NextInAEL;t.OutIdx===-1&&i.OutIdx===-1?(this.DeleteFromAEL(t),this.DeleteFromAEL(i)):t.OutIdx>=0&&i.OutIdx>=0?(t.OutIdx>=0&&this.AddLocalMaxPoly(t,i,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(i)):e.use_lines&&t.WindDelta===0?(t.OutIdx>=0&&(this.AddOutPt(t,t.Top),t.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(t),i.OutIdx>=0&&(this.AddOutPt(i,t.Top),i.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(i)):e.Error("DoMaxima error")},e.Clipper.ReversePaths=function(t){for(var i=0,n=t.length;i<n;i++)t[i].reverse()},e.Clipper.Orientation=function(t){return e.Clipper.Area(t)>=0},e.Clipper.prototype.PointCount=function(t){if(t===null)return 0;var i=0,n=t;do i++,n=n.Next;while(n!==t);return i},e.Clipper.prototype.BuildResult=function(t){e.Clear(t);for(var i=0,n=this.m_PolyOuts.length;i<n;i++){var r=this.m_PolyOuts[i];if(r.Pts!==null){var o=r.Pts.Prev,f=this.PointCount(o);if(!(f<2)){for(var d=new Array(f),y=0;y<f;y++)d[y]=o.Pt,o=o.Prev;t.push(d)}}}},e.Clipper.prototype.BuildResult2=function(t){t.Clear();for(var i=0,n=this.m_PolyOuts.length;i<n;i++){var r=this.m_PolyOuts[i],o=this.PointCount(r.Pts);if(!(r.IsOpen&&o<2||!r.IsOpen&&o<3)){this.FixHoleLinkage(r);var f=new e.PolyNode;t.m_AllPolys.push(f),r.PolyNode=f,f.m_polygon.length=o;for(var d=r.Pts.Prev,y=0;y<o;y++)f.m_polygon[y]=d.Pt,d=d.Prev}}for(var i=0,n=this.m_PolyOuts.length;i<n;i++){var r=this.m_PolyOuts[i];r.PolyNode!==null&&(r.IsOpen?(r.PolyNode.IsOpen=!0,t.AddChild(r.PolyNode)):r.FirstLeft!==null&&r.FirstLeft.PolyNode!==null?r.FirstLeft.PolyNode.AddChild(r.PolyNode):t.AddChild(r.PolyNode))}},e.Clipper.prototype.FixupOutPolyline=function(t){for(var i=t.Pts,n=i.Prev;i!==n;)if(i=i.Next,e.IntPoint.op_Equality(i.Pt,i.Prev.Pt)){i===n&&(n=i.Prev);var r=i.Prev;r.Next=i.Next,i.Next.Prev=r,i=r}i===i.Prev&&(t.Pts=null)},e.Clipper.prototype.FixupOutPolygon=function(t){var i=null;t.BottomPt=null;
1for(var n=t.Pts,r=this.PreserveCollinear||this.StrictlySimple;;){if(n.Prev===n||n.Prev===n.Next){t.Pts=null;return}if(e.IntPoint.op_Equality(n.Pt,n.Next.Pt)||e.IntPoint.op_Equality(n.Pt,n.Prev.Pt)||e.ClipperBase.SlopesEqual4(n.Prev.Pt,n.Pt,n.Next.Pt,this.m_UseFullRange)&&(!r||!this.Pt2IsBetweenPt1AndPt3(n.Prev.Pt,n.Pt,n.Next.Pt)))i=null,n.Prev.Next=n.Next,n.Next.Prev=n.Prev,n=n.Prev;else{if(n===i)break;i===null&&(i=n),n=n.Next}}t.Pts=n},e.Clipper.prototype.DupOutPt=function(t,i){var n=new e.OutPt;return n.Pt.X=t.Pt.X,n.Pt.Y=t.Pt.Y,e.use_xyz&&(n.Pt.Z=t.Pt.Z),n.Idx=t.Idx,i?(n.Next=t.Next,n.Prev=t,t.Next.Prev=n,t.Next=n):(n.Prev=t.Prev,n.Next=t,t.Prev.Next=n,t.Prev=n),n},e.Clipper.prototype.GetOverlap=function(t,i,n,r,o){return t<i?n<r?(o.Left=Math.max(t,n),o.Right=Math.min(i,r)):(o.Left=Math.max(t,r),o.Right=Math.min(i,n)):n<r?(o.Left=Math.max(i,n),o.Right=Math.min(t,r)):(o.Left=Math.max(i,r),o.Right=Math.min(t,n)),o.Left<o.Right},e.Clipper.prototype.JoinHorz=function(t,i,n,r,o,f){var d=t.Pt.X>i.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight,y=n.Pt.X>r.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight;if(d===y)return!1;if(d===e.Direction.dLeftToRight){for(;t.Next.Pt.X<=o.X&&t.Next.Pt.X>=t.Pt.X&&t.Next.Pt.Y===o.Y;)t=t.Next;f&&t.Pt.X!==o.X&&(t=t.Next),i=this.DupOutPt(t,!f),e.IntPoint.op_Inequality(i.Pt,o)&&(t=i,t.Pt.X=o.X,t.Pt.Y=o.Y,e.use_xyz&&(t.Pt.Z=o.Z),i=this.DupOutPt(t,!f))}else{for(;t.Next.Pt.X>=o.X&&t.Next.Pt.X<=t.Pt.X&&t.Next.Pt.Y===o.Y;)t=t.Next;!f&&t.Pt.X!==o.X&&(t=t.Next),i=this.DupOutPt(t,f),e.IntPoint.op_Inequality(i.Pt,o)&&(t=i,t.Pt.X=o.X,t.Pt.Y=o.Y,e.use_xyz&&(t.Pt.Z=o.Z),i=this.DupOutPt(t,f))}if(y===e.Direction.dLeftToRight){for(;n.Next.Pt.X<=o.X&&n.Next.Pt.X>=n.Pt.X&&n.Next.Pt.Y===o.Y;)n=n.Next;f&&n.Pt.X!==o.X&&(n=n.Next),r=this.DupOutPt(n,!f),e.IntPoint.op_Inequality(r.Pt,o)&&(n=r,n.Pt.X=o.X,n.Pt.Y=o.Y,e.use_xyz&&(n.Pt.Z=o.Z),r=this.DupOutPt(n,!f))}else{for(;n.Next.Pt.X>=o.X&&n.Next.Pt.X<=n.Pt.X&&n.Next.Pt.Y===o.Y;)n=n.Next;!f&&n.Pt.X!==o.X&&(n=n.Next),r=this.DupOutPt(n,f),e.IntPoint.op_Inequality(r.Pt,o)&&(n=r,n.Pt.X=o.X,n.Pt.Y=o.Y,e.use_xyz&&(n.Pt.Z=o.Z),r=this.DupOutPt(n,f))}return d===e.Direction.dLeftToRight===f?(t.Prev=n,n.Next=t,i.Next=r,r.Prev=i):(t.Next=n,n.Prev=t,i.Prev=r,r.Next=i),!0},e.Clipper.prototype.JoinPoints=function(t,i,n){var r=t.OutPt1,o=new e.OutPt,f=t.OutPt2,d=new e.OutPt,y=t.OutPt1.Pt.Y===t.OffPt.Y;if(y&&e.IntPoint.op_Equality(t.OffPt,t.OutPt1.Pt)&&e.IntPoint.op_Equality(t.OffPt,t.OutPt2.Pt)){if(i!==n)return!1;for(o=t.OutPt1.Next;o!==r&&e.IntPoint.op_Equality(o.Pt,t.OffPt);)o=o.Next;var P=o.Pt.Y>t.OffPt.Y;for(d=t.OutPt2.Next;d!==f&&e.IntPoint.op_Equality(d.Pt,t.OffPt);)d=d.Next;var X=d.Pt.Y>t.OffPt.Y;return P===X?!1:P?(o=this.DupOutPt(r,!1),d=this.DupOutPt(f,!0),r.Prev=f,f.Next=r,o.Next=d,d.Prev=o,t.OutPt1=r,t.OutPt2=o,!0):(o=this.DupOutPt(r,!0),d=this.DupOutPt(f,!1),r.Next=f,f.Prev=r,o.Prev=d,d.Next=o,t.OutPt1=r,t.OutPt2=o,!0)}else if(y){for(o=r;r.Prev.Pt.Y===r.Pt.Y&&r.Prev!==o&&r.Prev!==f;)r=r.Prev;for(;o.Next.Pt.Y===o.Pt.Y&&o.Next!==r&&o.Next!==f;)o=o.Next;if(o.Next===r||o.Next===f)return!1;for(d=f;f.Prev.Pt.Y===f.Pt.Y&&f.Prev!==d&&f.Prev!==o;)f=f.Prev;for(;d.Next.Pt.Y===d.Pt.Y&&d.Next!==f&&d.Next!==r;)d=d.Next;if(d.Next===f||d.Next===r)return!1;var S={Left:null,Right:null};if(!this.GetOverlap(r.Pt.X,o.Pt.X,f.Pt.X,d.Pt.X,S))return!1;var w=S.Left,E=S.Right,D=new e.IntPoint0,H;return r.Pt.X>=w&&r.Pt.X<=E?(D.X=r.Pt.X,D.Y=r.Pt.Y,e.use_xyz&&(D.Z=r.Pt.Z),H=r.Pt.X>o.Pt.X):f.Pt.X>=w&&f.Pt.X<=E?(D.X=f.Pt.X,D.Y=f.Pt.Y,e.use_xyz&&(D.Z=f.Pt.Z),H=f.Pt.X>d.Pt.X):o.Pt.X>=w&&o.Pt.X<=E?(D.X=o.Pt.X,D.Y=o.Pt.Y,e.use_xyz&&(D.Z=o.Pt.Z),H=o.Pt.X>r.Pt.X):(D.X=d.Pt.X,D.Y=d.Pt.Y,e.use_xyz&&(D.Z=d.Pt.Z),H=d.Pt.X>f.Pt.X),t.OutPt1=r,t.OutPt2=f,this.JoinHorz(r,o,f,d,D,H)}else{for(o=r.Next;e.IntPoint.op_Equality(o.Pt,r.Pt)&&o!==r;)o=o.Next;var J=o.Pt.Y>r.Pt.Y||!e.ClipperBase.SlopesEqual4(r.Pt,o.Pt,t.OffPt,this.m_UseFullRange);if(J){for(o=r.Prev;e.IntPoint.op_Equality(o.Pt,r.Pt)&&o!==r;)o=o.Prev;if(o.Pt.Y>r.Pt.Y||!e.ClipperBase.SlopesEqual4(r.Pt,o.Pt,t.OffPt,this.m_UseFullRange))return!1}for(d=f.Next;e.IntPoint.op_Equality(d.Pt,f.Pt)&&d!==f;)d=d.Next;var tt=d.Pt.Y>f.Pt.Y||!e.ClipperBase.SlopesEqual4(f.Pt,d.Pt,t.OffPt,this.m_UseFullRange);if(tt){for(d=f.Prev;e.IntPoint.op_Equality(d.Pt,f.Pt)&&d!==f;)d=d.Prev;if(d.Pt.Y>f.Pt.Y||!e.ClipperBase.SlopesEqual4(f.Pt,d.Pt,t.OffPt,this.m_UseFullRange))return!1}return o===r||d===f||o===d||i===n&&J===tt?!1:J?(o=this.DupOutPt(r,!1),d=this.DupOutPt(f,!0),r.Prev=f,f.Next=r,o.Next=d,d.Prev=o,t.OutPt1=r,t.OutPt2=o,!0):(o=this.DupOutPt(r,!0),d=this.DupOutPt(f,!1),r.Next=f,f.Prev=r,o.Prev=d,d.Next=o,t.OutPt1=r,t.OutPt2=o,!0)}},e.Clipper.GetBounds=function(t){for(var i=0,n=t.length;i<n&&t[i].length===0;)i++;if(i===n)return new e.IntRect(0,0,0,0);var r=new e.IntRect;for(r.left=t[i][0].X,r.right=r.left,r.top=t[i][0].Y,r.bottom=r.to
1p;i<n;i++)for(var o=0,f=t[i].length;o<f;o++)t[i][o].X<r.left?r.left=t[i][o].X:t[i][o].X>r.right&&(r.right=t[i][o].X),t[i][o].Y<r.top?r.top=t[i][o].Y:t[i][o].Y>r.bottom&&(r.bottom=t[i][o].Y);return r},e.Clipper.prototype.GetBounds2=function(t){var i=t,n=new e.IntRect;for(n.left=t.Pt.X,n.right=t.Pt.X,n.top=t.Pt.Y,n.bottom=t.Pt.Y,t=t.Next;t!==i;)t.Pt.X<n.left&&(n.left=t.Pt.X),t.Pt.X>n.right&&(n.right=t.Pt.X),t.Pt.Y<n.top&&(n.top=t.Pt.Y),t.Pt.Y>n.bottom&&(n.bottom=t.Pt.Y),t=t.Next;return n},e.Clipper.PointInPolygon=function(t,i){var n=0,r=i.length;if(r<3)return 0;for(var o=i[0],f=1;f<=r;++f){var d=f===r?i[0]:i[f];if(d.Y===t.Y&&(d.X===t.X||o.Y===t.Y&&d.X>t.X==o.X<t.X))return-1;if(o.Y<t.Y!=d.Y<t.Y){if(o.X>=t.X)if(d.X>t.X)n=1-n;else{var y=(o.X-t.X)*(d.Y-t.Y)-(d.X-t.X)*(o.Y-t.Y);if(y===0)return-1;y>0==d.Y>o.Y&&(n=1-n)}else if(d.X>t.X){var y=(o.X-t.X)*(d.Y-t.Y)-(d.X-t.X)*(o.Y-t.Y);if(y===0)return-1;y>0==d.Y>o.Y&&(n=1-n)}}o=d}return n},e.Clipper.prototype.PointInPolygon=function(t,i){var n=0,r=i,o=t.X,f=t.Y,d=i.Pt.X,y=i.Pt.Y;do{i=i.Next;var P=i.Pt.X,X=i.Pt.Y;if(X===f&&(P===o||y===f&&P>o==d<o))return-1;if(y<f!=X<f){if(d>=o)if(P>o)n=1-n;else{var S=(d-o)*(X-f)-(P-o)*(y-f);if(S===0)return-1;S>0==X>y&&(n=1-n)}else if(P>o){var S=(d-o)*(X-f)-(P-o)*(y-f);if(S===0)return-1;S>0==X>y&&(n=1-n)}}d=P,y=X}while(r!==i);return n},e.Clipper.prototype.Poly2ContainsPoly1=function(t,i){var n=t;do{var r=this.PointInPolygon(n.Pt,i);if(r>=0)return r>0;n=n.Next}while(n!==t);return!0},e.Clipper.prototype.FixupFirstLefts1=function(t,i){for(var n,r,o=0,f=this.m_PolyOuts.length;o<f;o++)n=this.m_PolyOuts[o],r=e.Clipper.ParseFirstLeft(n.FirstLeft),n.Pts!==null&&r===t&&this.Poly2ContainsPoly1(n.Pts,i.Pts)&&(n.FirstLeft=i)},e.Clipper.prototype.FixupFirstLefts2=function(t,i){for(var n=i.FirstLeft,r,o,f=0,d=this.m_PolyOuts.length;f<d;f++)r=this.m_PolyOuts[f],!(r.Pts===null||r===i||r===t)&&(o=e.Clipper.ParseFirstLeft(r.FirstLeft),!(o!==n&&o!==t&&o!==i)&&(this.Poly2ContainsPoly1(r.Pts,t.Pts)?r.FirstLeft=t:this.Poly2ContainsPoly1(r.Pts,i.Pts)?r.FirstLeft=i:(r.FirstLeft===t||r.FirstLeft===i)&&(r.FirstLeft=n)))},e.Clipper.prototype.FixupFirstLefts3=function(t,i){for(var n,r,o=0,f=this.m_PolyOuts.length;o<f;o++)n=this.m_PolyOuts[o],r=e.Clipper.ParseFirstLeft(n.FirstLeft),n.Pts!==null&&r===t&&(n.FirstLeft=i)},e.Clipper.ParseFirstLeft=function(t){for(;t!==null&&t.Pts===null;)t=t.FirstLeft;return t},e.Clipper.prototype.JoinCommonEdges=function(){for(var t=0,i=this.m_Joins.length;t<i;t++){var n=this.m_Joins[t],r=this.GetOutRec(n.OutPt1.Idx),o=this.GetOutRec(n.OutPt2.Idx);if(!(r.Pts===null||o.Pts===null)&&!(r.IsOpen||o.IsOpen)){var f;r===o?f=r:this.OutRec1RightOfOutRec2(r,o)?f=o:this.OutRec1RightOfOutRec2(o,r)?f=r:f=this.GetLowermostRec(r,o),this.JoinPoints(n,r,o)&&(r===o?(r.Pts=n.OutPt1,r.BottomPt=null,o=this.CreateOutRec(),o.Pts=n.OutPt2,this.UpdateOutPtIdxs(o),this.Poly2ContainsPoly1(o.Pts,r.Pts)?(o.IsHole=!r.IsHole,o.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(o,r),(o.IsHole^this.ReverseSolution)==this.Area$1(o)>0&&this.ReversePolyPtLinks(o.Pts)):this.Poly2ContainsPoly1(r.Pts,o.Pts)?(o.IsHole=r.IsHole,r.IsHole=!o.IsHole,o.FirstLeft=r.FirstLeft,r.FirstLeft=o,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,o),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(o.IsHole=r.IsHole,o.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,o))):(o.Pts=null,o.BottomPt=null,o.Idx=r.Idx,r.IsHole=f.IsHole,f===o&&(r.FirstLeft=o.FirstLeft),o.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(o,r)))}}},e.Clipper.prototype.UpdateOutPtIdxs=function(t){var i=t.Pts;do i.Idx=t.Idx,i=i.Prev;while(i!==t.Pts)},e.Clipper.prototype.DoSimplePolygons=function(){for(var t=0;t<this.m_PolyOuts.length;){var i=this.m_PolyOuts[t++],n=i.Pts;if(!(n===null||i.IsOpen))do{for(var r=n.Next;r!==i.Pts;){if(e.IntPoint.op_Equality(n.Pt,r.Pt)&&r.Next!==n&&r.Prev!==n){var o=n.Prev,f=r.Prev;n.Prev=f,f.Next=n,r.Prev=o,o.Next=r,i.Pts=n;var d=this.CreateOutRec();d.Pts=r,this.UpdateOutPtIdxs(d),this.Poly2ContainsPoly1(d.Pts,i.Pts)?(d.IsHole=!i.IsHole,d.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(d,i)):this.Poly2ContainsPoly1(i.Pts,d.Pts)?(d.IsHole=i.IsHole,i.IsHole=!d.IsHole,d.FirstLeft=i.FirstLeft,i.FirstLeft=d,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,d)):(d.IsHole=i.IsHole,d.FirstLeft=i.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(i,d)),r=n}r=r.Next}n=n.Next}while(n!==i.Pts)}},e.Clipper.Area=function(t){if(!Array.isArray(t))return 0;var i=t.length;if(i<3)return 0;for(var n=0,r=0,o=i-1;r<i;++r)n+=(t[o].X+t[r].X)*(t[o].Y-t[r].Y),o=r;return-n*.5},e.Clipper.prototype.Area=function(t){var i=t;if(t===null)return 0;var n=0;do n=n+(t.Prev.Pt.X+t.Pt.X)*(t.Prev.Pt.Y-t.Pt.Y),t=t.Next;while(t!==i);return n*.5},e.Clipper.prototype.Area$1=function(t){return this.Area(t.Pts)},e.Clipper.SimplifyPolygon=function(t,i){var n=new Array,r=new e.Clipper(0);
1return r.StrictlySimple=!0,r.AddPath(t,e.PolyType.ptSubject,!0),r.Execute(e.ClipType.ctUnion,n,i,i),n},e.Clipper.SimplifyPolygons=function(t,i){typeof i>"u"&&(i=e.PolyFillType.pftEvenOdd);var n=new Array,r=new e.Clipper(0);return r.StrictlySimple=!0,r.AddPaths(t,e.PolyType.ptSubject,!0),r.Execute(e.ClipType.ctUnion,n,i,i),n},e.Clipper.DistanceSqrd=function(t,i){var n=t.X-i.X,r=t.Y-i.Y;return n*n+r*r},e.Clipper.DistanceFromLineSqrd=function(t,i,n){var r=i.Y-n.Y,o=n.X-i.X,f=r*i.X+o*i.Y;return f=r*t.X+o*t.Y-f,f*f/(r*r+o*o)},e.Clipper.SlopesNearCollinear=function(t,i,n,r){return Math.abs(t.X-i.X)>Math.abs(t.Y-i.Y)?t.X>i.X==t.X<n.X?e.Clipper.DistanceFromLineSqrd(t,i,n)<r:i.X>t.X==i.X<n.X?e.Clipper.DistanceFromLineSqrd(i,t,n)<r:e.Clipper.DistanceFromLineSqrd(n,t,i)<r:t.Y>i.Y==t.Y<n.Y?e.Clipper.DistanceFromLineSqrd(t,i,n)<r:i.Y>t.Y==i.Y<n.Y?e.Clipper.DistanceFromLineSqrd(i,t,n)<r:e.Clipper.DistanceFromLineSqrd(n,t,i)<r},e.Clipper.PointsAreClose=function(t,i,n){var r=t.X-i.X,o=t.Y-i.Y;return r*r+o*o<=n},e.Clipper.ExcludeOp=function(t){var i=t.Prev;return i.Next=t.Next,t.Next.Prev=i,i.Idx=0,i},e.Clipper.CleanPolygon=function(t,i){typeof i>"u"&&(i=1.415);var n=t.length;if(n===0)return new Array;for(var r=new Array(n),o=0;o<n;++o)r[o]=new e.OutPt;for(var o=0;o<n;++o)r[o].Pt=t[o],r[o].Next=r[(o+1)%n],r[o].Next.Prev=r[o],r[o].Idx=0;for(var f=i*i,d=r[0];d.Idx===0&&d.Next!==d.Prev;)e.Clipper.PointsAreClose(d.Pt,d.Prev.Pt,f)?(d=e.Clipper.ExcludeOp(d),n--):e.Clipper.PointsAreClose(d.Prev.Pt,d.Next.Pt,f)?(e.Clipper.ExcludeOp(d.Next),d=e.Clipper.ExcludeOp(d),n-=2):e.Clipper.SlopesNearCollinear(d.Prev.Pt,d.Pt,d.Next.Pt,f)?(d=e.Clipper.ExcludeOp(d),n--):(d.Idx=1,d=d.Next);n<3&&(n=0);for(var y=new Array(n),o=0;o<n;++o)y[o]=new e.IntPoint1(d.Pt),d=d.Next;return r=null,y},e.Clipper.CleanPolygons=function(t,i){for(var n=new Array(t.length),r=0,o=t.length;r<o;r++)n[r]=e.Clipper.CleanPolygon(t[r],i);return n},e.Clipper.Minkowski=function(t,i,n,r){var o=r?1:0,f=t.length,d=i.length,y=new Array;if(n)for(var P=0;P<d;P++){for(var X=new Array(f),S=0,w=t.length,E=t[S];S<w;S++,E=t[S])X[S]=new e.IntPoint2(i[P].X+E.X,i[P].Y+E.Y);y.push(X)}else for(var P=0;P<d;P++){for(var X=new Array(f),S=0,w=t.length,E=t[S];S<w;S++,E=t[S])X[S]=new e.IntPoint2(i[P].X-E.X,i[P].Y-E.Y);y.push(X)}for(var D=new Array,P=0;P<d-1+o;P++)for(var S=0;S<f;S++){var H=new Array;H.push(y[P%d][S%f]),H.push(y[(P+1)%d][S%f]),H.push(y[(P+1)%d][(S+1)%f]),H.push(y[P%d][(S+1)%f]),e.Clipper.Orientation(H)||H.reverse(),D.push(H)}return D},e.Clipper.MinkowskiSum=function(t,i,n){if(i[0]instanceof Array){for(var o=i,d=new e.Paths,f=new e.Clipper,y=0;y<o.length;++y){var P=e.Clipper.Minkowski(t,o[y],!0,n);
1if(f.AddPaths(P,e.PolyType.ptSubject,!0),n){var r=e.Clipper.TranslatePath(o[y],t[0]);f.AddPath(r,e.PolyType.ptClip,!0)}}return f.Execute(e.ClipType.ctUnion,d,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),d}else{var r=i,o=e.Clipper.Minkowski(t,r,!0,n),f=new e.Clipper;return f.AddPaths(o,e.PolyType.ptSubject,!0),f.Execute(e.ClipType.ctUnion,o,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),o}},e.Clipper.TranslatePath=function(t,i){for(var n=new e.Path,r=0;r<t.length;r++)n.push(new e.IntPoint2(t[r].X+i.X,t[r].Y+i.Y));return n},e.Clipper.MinkowskiDiff=function(t,i){var n=e.Clipper.Minkowski(t,i,!1,!0),r=new e.Clipper;return r.AddPaths(n,e.PolyType.ptSubject,!0),r.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),n},e.Clipper.PolyTreeToPaths=function(t){var i=new Array;return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntAny,i),i},e.Clipper.AddPolyNodeToPaths=function(t,i,n){var r=!0;switch(i){case e.Clipper.NodeType.ntOpen:return;case e.Clipper.NodeType.ntClosed:r=!t.IsOpen;break}t.m_polygon.length>0&&r&&n.push(t.m_polygon);for(var o=0,f=t.Childs(),d=f.length,y=f[o];o<d;o++,y=f[o])e.Clipper.AddPolyNodeToPaths(y,i,n)},e.Clipper.OpenPathsFromPolyTree=function(t){for(var i=new e.Paths,n=0,r=t.ChildCount();n<r;n++)t.Childs()[n].IsOpen&&i.push(t.Childs()[n].m_polygon);return i},e.Clipper.ClosedPathsFromPolyTree=function(t){var i=new e.Paths;return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntClosed,i),i},ke(e.Clipper,e.ClipperBase),e.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},e.ClipperOffset=function(t,i){typeof t>"u"&&(t=2),typeof i>"u"&&(i=e.ClipperOffset.def_arc_tolerance),this.m_destPolys=new e.Paths,this.m_srcPoly=new e.Path,this.m_destPoly=new e.Path,this.m_normals=new Array,this.m_delta=0,this.m_sinA=0,this.m_sin=0,this.m_cos=0,this.m_miterLim=0,this.m_StepsPerRad=0,this.m_lowest=new e.IntPoint0,this.m_polyNodes=new e.PolyNode,this.MiterLimit=t,this.ArcTolerance=i,this.m_lowest.X=-1},e.ClipperOffset.two_pi=6.28318530717959,e.ClipperOffset.def_arc_tolerance=.25,e.ClipperOffset.prototype.Clear=function(){e.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},e.ClipperOffset.Round=e.Clipper.Round,e.ClipperOffset.prototype.AddPath=function(t,i,n){var r=t.length-1;if(!(r<0)){var o=new e.PolyNode;if(o.m_jointype=i,o.m_endtype=n,n===e.EndType.etClosedLine||n===e.EndType.etClosedPolygon)for(;r>0&&e.IntPoint.op_Equality(t[0],t[r]);)r--;o.m_polygon.push(t[0]);for(var f=0,d=0,y=1;y<=r;y++)e.IntPoint.op_Inequality(o.m_polygon[f],t[y])&&(f++,o.m_polygon.push(t[y]),(t[y].Y>o.m_polygon[d].Y||t[y].Y===o.m_polygon[d].Y&&t[y].X<o.m_polygon[d].X)&&(d=f));if(!(n===e.EndType.etClosedPolygon&&f<2)&&(this.m_polyNodes.AddChild(o),n===e.EndType.etClosedPolygon))if(this.m_lowest.X<0)this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,d);else{var P=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(o.m_polygon[d].Y>P.Y||o.m_polygon[d].Y===P.Y&&o.m_polygon[d].X<P.X)&&(this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,d))}}},e.ClipperOffset.prototype.AddPaths=function(t,i,n){for(var r=0,o=t.length;r<o;r++)this.AddPath(t[r],i,n)},e.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!e.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var t=0;t<this.m_polyNodes.ChildCount();t++){var i=this.m_polyNodes.Childs()[t];(i.m_endtype===e.EndType.etClosedPolygon||i.m_endtype===e.EndType.etClosedLine&&e.Clipper.Orientation(i.m_polygon))&&i.m_polygon.reverse()}else for(var t=0;t<this.m_polyNodes.ChildCount();t++){var i=this.m_polyNodes.Childs()[t];i.m_endtype===e.EndType.etClosedLine&&!e.Clipper.Orientation(i.m_polygon)&&i.m_polygon.reverse()}},e.ClipperOffset.GetUnitNormal=function(t,i){var n=i.X-t.X,r=i.Y-t.Y;if(n===0&&r===0)return new e.DoublePoint2(0,0);var o=1/Math.sqrt(n*n+r*r);return n*=o,r*=o,new e.DoublePoint2(r,-n)},e.ClipperOffset.prototype.DoOffset=function(t){if(this.m_destPolys=new Array,this.m_delta=t,e.ClipperBase.near_zero(t)){for(var i=0;i<this.m_polyNodes.ChildCount();i++){var n=this.m_polyNodes.Childs()[i];n.m_endtype===e.EndType.etClosedPolygon&&this.m_destPolys.push(n.m_polygon)}return}this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5;var r;this.ArcTolerance<=0?r=e.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(t)*e.ClipperOffset.def_arc_tolerance?r=Math.abs(t)*e.ClipperOffset.def_arc_tolerance:r=this.ArcTolerance;var o=3.14159265358979/Math.acos(1-r/Math.abs(t));this.m_sin=Math.sin(e.ClipperOffset.two_pi/o),this.m_cos=Math.cos(e.ClipperOffset.two_pi/o),this.m_StepsPerRad=o/e.ClipperOffset.two_pi,t<0&&(this.m_sin=-this.m_sin);for(var i=0;i<this.m_polyNodes.ChildCount();i++){var n=this.m_polyNodes.Childs()[i];this.m_srcPoly=n.m_polygon;var f=this.m_srcPoly.length;if(!(f===0||t<=0&&(f<3||n.m_endtype!==e.EndType.etClosedPolygon))){if(this.m_destPoly=new Array,f===1){if(n.m_jointype===e.JoinType.jtRound)for(var d=1,y=0,P=1;P<=o;P++){this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+d*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+y*t)));var X=d;d=d*this.m_cos-this.m_sin*y,y=X*this.m_sin+y*this.m_cos}else for(var d=-1,y=-1,P=0;P<4;++P)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+d*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+y*t))),d<0?d=1:y<0?y=1:d=-1;this.m_destPolys.push(this.m_destPoly);continue}this.m_normals.length=0;for(var P=0;P<f-1;P++)this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[P],this.m_srcPoly[P+1]));if(n.m_endtype===e.EndType.etClosedLine||n.m_endtype===e.EndType.etClosedPolygon?this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[f-1],this.m_srcPoly[0])):this.m_normals.push(new e.DoublePoint1(this.m_normals[f
1-2])),n.m_endtype===e.EndType.etClosedPolygon){for(var S=f-1,P=0;P<f;P++)S=this.OffsetPoint(P,S,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(n.m_endtype===e.EndType.etClosedLine){for(var S=f-1,P=0;P<f;P++)S=this.OffsetPoint(P,S,n.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;for(var w=this.m_normals[f-1],P=f-1;P>0;P--)this.m_normals[P]=new e.DoublePoint2(-this.m_normals[P-1].X,-this.m_normals[P-1].Y);this.m_normals[0]=new e.DoublePoint2(-w.X,-w.Y),S=0;for(var P=f-1;P>=0;P--)S=this.OffsetPoint(P,S,n.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var S=0,P=1;P<f-1;++P)S=this.OffsetPoint(P,S,n.m_jointype);var E;if(n.m_endtype===e.EndType.etOpenButt){var P=f-1;E=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[P].X+this.m_normals[P].X*t),e.ClipperOffset.Round(this.m_srcPoly[P].Y+this.m_normals[P].Y*t)),this.m_destPoly.push(E),E=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[P].X-this.m_normals[P].X*t),e.ClipperOffset.Round(this.m_srcPoly[P].Y-this.m_normals[P].Y*t)),this.m_destPoly.push(E)}else{var P=f-1;S=f-2,this.m_sinA=0,this.m_normals[P]=new e.DoublePoint2(-this.m_normals[P].X,-this.m_normals[P].Y),n.m_endtype===e.EndType.etOpenSquare?this.DoSquare(P,S):this.DoRound(P,S)}for(var P=f-1;P>0;P--)this.m_normals[P]=new e.DoublePoint2(-this.m_normals[P-1].X,-this.m_normals[P-1].Y);this.m_normals[0]=new e.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),S=f-1;for(var P=S-1;P>0;--P)S=this.OffsetPoint(P,S,n.m_jointype);n.m_endtype===e.EndType.etOpenButt?(E=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*t)),this.m_destPoly.push(E),E=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*t)),this.m_destPoly.push(E)):(S=1,this.m_sinA=0,n.m_endtype===e.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}},e.ClipperOffset.prototype.Execute=function(){var t=arguments,i=t[0]instanceof e.PolyTree;if(i){var n=t[0],r=t[1];n.Clear(),this.FixOrientations(),this.DoOffset(r);var o=new e.Clipper(0);if(o.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)o.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var f=e.Clipper.GetBounds(this.m_destPolys),d=new e.Path;if(d.push(new e.IntPoint2(f.left-10,f.bottom+10)),d.push(new e.IntPoint2(f.right+10,f.bottom+10)),d.push(new e.IntPoint2(f.right+10,f.top-10)),d.push(new e.IntPoint2(f.left-10,f.top-10)),o.AddPath(d,e.PolyType.ptSubject,!0),o.ReverseSolution=!0,o.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.ChildCount()===1&&n.Childs()[0].ChildCount()>0){var y=n.Childs()[0];n.Childs()[0]=y.Childs()[0],n.Childs()[0].m_Parent=n;for(var P=1;P<y.ChildCount();P++)n.AddChild(y.Childs()[P])}else n.Clear()}}else{var n=t[0],r=t[1];e.Clear(n),this.FixOrientations(),this.DoOffset(r);var o=new e.Clipper(0);if(o.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)o.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var f=e.Clipper.GetBounds(this.m_destPolys),d=new e.Path;d.push(new e.IntPoint2(f.left-10,f.bottom+10)),d.push(new e.IntPoint2(f.right+10,f.bottom+10)),d.push(new e.IntPoint2(f.right+10,f.top-10)),d.push(new e.IntPoint2(f.left-10,f.top-10)),o.AddPath(d,e.PolyType.ptSubject,!0),o.ReverseSolution=!0,o.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.length>0&&n.splice(0,1)}}},e.ClipperOffset.prototype.OffsetPoint=function(t,i,n){if(this.m_sinA=this.m_normals[i].X*this.m_normals[t].Y-this.m_normals[t].X*this.m_normals[i].Y,Math.abs(this.m_sinA*this.m_delta)<1){var r=this.m_normals[i].X*this.m_normals[t].X+this.m_normals[t].Y*this.m_normals[i].Y;if(r>0)return this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[i].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[i].Y*this.m_delta))),i}else this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1);if(this.m_sinA*this.m_delta<0)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[i].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[i].Y*this.m_delta))),this.m_destPoly.push(new e.IntPoint1(this.m_srcPoly[t])),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)));else switch(n){case e.JoinType.jtMiter:{var o=1+(this.m_normals[t].X*this.m_normals[i].X+this.m_normals[t].Y*this.m_normals[i].Y);o>=this.m_miterLim?this.DoMiter(t,i,o):this.DoSquare(t,i);break}case e.JoinType.jtSquare:this.DoSquare(t,i);break;case e.JoinType.jtRound:this.DoRound(t,i);break}return i=t,i},e.ClipperOffset.prototype.DoSquare=function(t,i){var n=Math.tan(Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[t].X+this.m_normals[i].Y*this.m_normals[t].Y)/4);this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[i].X-this.m_normals[i].Y*n)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[i].Y+this.m_normals[i].X*n)))),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[t].X+this.m_normals[t].Y*n)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[t].Y-this.m_normals[t].X*n))))},e.ClipperOffset.prototype.DoMiter=function(t,i,n){var r=this.m_delta/n;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+(this.m_normals[i].X+this.m_normals[t].X)*r),e.ClipperOffset.Round(this.m_srcPoly[t].Y+(this.m_normals[i].Y+this.m_normals[t].Y)*r)))},e.ClipperOffset.prototype.DoRound=function(t,i){for(var n=Math.atan2(this.m_sinA,this.m_normals[i].X*this.m_normals[t].X+this.m_normals[i].Y*this.m_normals[t].Y),r=Math.max(e.Cast_Int32(e.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(n))),1),o=this.m_normals[i].X,f=this.m_normals[i].Y,d,y=0;y<r;++y)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+o*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+f*this.m_delta))),d=o,o=o*this.m_cos-this.m_sin*f,f=d*this.m_sin+f*this.m_cos;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)))},e.Error=function(t){try{throw new Error(t)}catch(i){alert(i.message)}},e.JS={}
1,e.JS.AreaOfPolygon=function(t,i){return i||(i=1),e.Clipper.Area(t)/(i*i)},e.JS.AreaOfPolygons=function(t,i){i||(i=1);for(var n=0,r=0;r<t.length;r++)n+=e.Clipper.Area(t[r]);return n/(i*i)},e.JS.BoundsOfPath=function(t,i){return e.JS.BoundsOfPaths([t],i)},e.JS.BoundsOfPaths=function(t,i){i||(i=1);var n=e.Clipper.GetBounds(t);return n.left/=i,n.bottom/=i,n.right/=i,n.top/=i,n},e.JS.Clean=function(r,i){if(!(r instanceof Array))return[];var n=r[0]instanceof Array,r=e.JS.Clone(r);if(typeof i!="number"||i===null)return e.Error("Delta is not a number in Clean()."),r;if(r.length===0||r.length===1&&r[0].length===0||i<0)return r;n||(r=[r]);for(var o=r.length,f,d,y,P,X,S,w,E=[],D=0;D<o;D++)if(d=r[D],f=d.length,f!==0){if(f<3){y=d,E.push(y);continue}for(y=d,P=i*i,X=d[0],S=1,w=1;w<f;w++)(d[w].X-X.X)*(d[w].X-X.X)+(d[w].Y-X.Y)*(d[w].Y-X.Y)<=P||(y[S]=d[w],X=d[w],S++);X=d[S-1],(d[0].X-X.X)*(d[0].X-X.X)+(d[0].Y-X.Y)*(d[0].Y-X.Y)<=P&&S--,S<f&&y.splice(S,f-S),y.length&&E.push(y)}return!n&&E.length?E=E[0]:!n&&E.length===0?E=[]:n&&E.length===0&&(E=[[]]),E},e.JS.Clone=function(t){if(!(t instanceof Array))return[];if(t.length===0)return[];if(t.length===1&&t[0].length===0)return[[]];var i=t[0]instanceof Array;i||(t=[t]);var n=t.length,r,o,f,d,y=new Array(n);for(o=0;o<n;o++){for(r=t[o].length,d=new Array(r),f=0;f<r;f++)d[f]={X:t[o][f].X,Y:t[o][f].Y};y[o]=d}return i||(y=y[0]),y},e.JS.Lighten=function(t,i){if(!(t instanceof Array))return[];if(typeof i!="number"||i===null)return e.Error("Tolerance is not a number in Lighten()."),e.JS.Clone(t);if(t.length===0||t.length===1&&t[0].length===0||i<0)return e.JS.Clone(t);var n=t[0]instanceof Array;n||(t=[t]);var r,o,f,d,y,P,X,S,w,E,D,H,J,tt,at,pt,Mt,Ss=t.length,Ns=i*i,Ot=[];for(r=0;r<Ss;r++)if(f=t[r],P=f.length,P!==0){for(d=0;d<1e6;d++){for(y=[],P=f.length,f[P-1].X!==f[0].X||f[P-1].Y!==f[0].Y?(H=1,f.push({X:f[0].X,Y:f[0].Y}),P=f.length):H=0,D=[],o=0;o<P-2;o++)X=f[o],w=f[o+1],S=f[o+2],pt=X.X,Mt=X.Y,J=S.X-pt,tt=S.Y-Mt,(J!==0||tt!==0)&&(at=((w.X-pt)*J+(w.Y-Mt)*tt)/(J*J+tt*tt),at>1?(pt=S.X,Mt=S.Y):at>0&&(pt+=J*at,Mt+=tt*at)),J=w.X-pt,tt=w.Y-Mt,E=J*J+tt*tt,E<=Ns&&(D[o+1]=1,o++);for(y.push({X:f[0].X,Y:f[0].Y}),o=1;o<P-1;o++)D[o]||y.push({X:f[o].X,Y:f[o].Y});if(y.push({X:f[P-1].X,Y:f[P-1].Y}),H&&f.pop(),D.length)f=y;else break}P=y.length,y[P-1].X===y[0].X&&y[P-1].Y===y[0].Y&&y.pop(),y.length>2&&Ot.push(y)}return n||(Ot=Ot[0]),typeof Ot>"u"&&(Ot=[]),Ot},e.JS.PerimeterOfPath=function(t,i,n){if(typeof t>"u")return 0;var r=Math.sqrt,o=0,f,d,y=0,P=0,X=0,S=0,w=t.length;if(w<2)return 0;for(i&&(t[w]=t[0],w++);--w;)f=t[w],y=f.X,P=f.Y,d=t[w-1],X=d.X,S=d.Y,o+=r((y-X)*(y-X)+(P-S)*(P-S));return i&&t.pop(),o/n},e.JS.PerimeterOfPaths=function(t,i,n){n||(n=1);for(var r=0,o=0;o<t.length;o++)r+=e.JS.PerimeterOfPath(t[o],i,n);return r},e.JS.ScaleDownPath=function(t,i){var n,r;for(i||(i=1),n=t.length;n--;)r=t[n],r.X=r.X/i,r.Y=r.Y/i},e.JS.ScaleDownPaths=function(t,i){var n,r,o;for(i||(i=1),n=t.length;n--;)for(r=t[n].length;r--;)o=t[n][r],o.X=o.X/i,o.Y=o.Y/i},e.JS.ScaleUpPath=function(t,i){var n,r,o=Math.round;for(i||(i=1),n=t.length;n--;)r=t[n],r.X=o(r.X*i),r.Y=o(r.Y*i)},e.JS.ScaleUpPaths=function(t,i){var n,r,o,f=Math.round;for(i||(i=1),n=t.length;n--;)for(r=t[n].length;r--;)o=t[n][r],o.X=f(o.X*i),o.Y=f(o.Y*i)},e.ExPolygons=function(){return[]},e.ExPolygon=function(){this.outer=null,this.holes=null},e.JS.AddOuterPolyNodeToExPolygons=function(t,i){var n=new e.ExPolygon;n.outer=t.Contour();var r=t.Childs(),o=r.length;n.holes=new Array(o);var f,d,y,P,X,S;for(y=0;y<o;y++)for(f=r[y],n.holes[y]=f.Contour(),P=0,X=f.Childs(),S=X.length;P<S;P++)d=X[P],e.JS.AddOuterPolyNodeToExPolygons(d,i);i.push(n)},e.JS.ExPolygonsToPaths=function(t){var i,n,r,o,f=new e.Paths;for(i=0,r=t.length;i<r;i++)for(f.push(t[i].outer),n=0,o=t[i].holes.length;n<o;n++)f.push(t[i].holes[n]);return f},e.JS.PolyTreeToExPolygons=function(t){var i=new e.ExPolygons,n,r,o,f;for(r=0,o=t.Childs(),f=o.length;r<f;r++)n=o[r],e.JS.AddOuterPolyNodeToExPolygons(n,i);return i}})()})($t)),$t.exports}var ai=li(),j=oi(ai);const vt=1e5,ut=(s,e)=>Math.hypot(s.x-e.x,s.y-e.y);function Ct(s){const e=s.flat();if(!e.length)return{minX:0,minY:0,maxX:60,maxY:40,width:60,height:40};let l=1/0,a=1/0,u=-1/0,h=-1/0;for(const c of e)l=Math.min(l,c.x),a=Math.min(a,c.y),u=Math.max(u,c.x),h=Math.max(h,c.y);return{minX:l,minY:a,maxX:u,maxY:h,width:u-l,height:h-a}}function ui(s,e=0){const l=Ct(s);return{...l,minX:l.minX-e,minY:l.minY-e,maxX:l.maxX+e,maxY:l.maxY+e,width:l.width+e*2,height:l.height+e*2}}const wt=s=>s.map(e=>e.map(l=>({X:Math.round(l.x*vt),Y:Math.round(l.y*vt)}))),Kt=s=>s.map(e=>e.map(l=>({x:l.X/vt,y:l.Y/vt})));function ot(s,e=[],l="union",a=!1){const u=new j.Clipper;u.AddPaths(wt(s),j.PolyType.ptSubject,!0),u.AddPaths(wt(e),j.PolyType.ptClip,!0);const h=[];return u.Execute(l==="union"?j.ClipType.ctUnion:l==="difference"?j.ClipType.ctDifference:j.ClipType.ctIntersection,h,a?j.PolyFillType.pftEvenOdd:j.PolyFillType.pftNonZero,a?j.PolyFillType.pftEvenOdd:j.PolyFillType.pftNonZero),Kt(h)}function dt(s,e,l=!1){if(!s.length)return[];const a=new j.ClipperOffset(2,.002*vt);a.AddPaths(wt(s),j.JoinType.jtRound,l?j.EndType.etOpenRound:j.EndType.etClosedPolygon);const u=[];return a.Execute(u,e*vt),Kt(u)}function Zt(s,e){let l=0;for(const a of wt(e)){const u=j.Clipper.PointInPolygon({X:Math.round(s.x*vt),Y:Math.round(s.y*vt)},a);if(u===-1)return!0;u===1&&l++}return l%2===1}function jt(s,e){if(!s.length||!e.length)return[];const l=new j.Clipper;l.AddPaths(wt(s),j.PolyType.ptSubject,!1),l.AddPaths(wt(e),j.PolyType.ptClip,!0);const a=new j.PolyTree;return l.Execute(j.ClipType.ctIntersection,a,j.PolyFillType.pftNonZero,j.PolyFillType.pftNonZero),Kt(j.Clipper.OpenPathsFromPolyTree(a))}function hi(s,e,l){return!Zt(s,l)||!Zt(e,l)?!1:jt([[s,e]],l).reduce((h,c)=>h+c.slice(1).reduce((p,m,x)=>p+ut(c[x],m),0),0)>=ut(s,e)-1e-4}const mt=.05,fi=2e3;function pi(s,e){const l=e==="x"?"y":"x",a=[];for(const u of s)for(let h=0;h<u.length;h++){let c=u[h],p=u[(h+1)%u.length];c[e]!==p[e]&&(c[e]>p[e]&&([c,p]=[p,c]),a.push({low:c[e],high:p[e],origin:c[l],slope:(p[l]-c[l])/(p[e]-c[e])}))}return a.sort((u,h)=>u.low-h.low)}function Qt(s,e){const l=Ct(s),a=e==="x"?l.minX:l.minY,u=e==="x"?l.
1width:l.height,h=Math.max(mt,u/fi),c=[],p=pi(s,e);let m=[],x=0;for(let C=a+h/2;C<a+u;C+=h){for(;x<p.length&&p[x].low<=C;)m.push(p[x++]);m=m.filter(I=>I.high>C);const v=m.map(I=>I.origin+(C-I.low)*I.slope).sort((I,_)=>I-_);for(let I=0;I+1<v.length;I+=2){if(v[I+1]-v[I]<=1e-6)continue;const _=(v[I]+v[I+1])/2;c.push(e==="x"?{x:C,y:_}:{x:_,y:C})}}return c}function Ce(s,e){const l=Math.cos(e),a=Math.sin(e),u=s.map(h=>h.map(c=>({x:c.x*l+c.y*a,y:-c.x*a+c.y*l})));return Qt(u,"y").map(h=>({x:h.x*l-h.y*a,y:h.x*a+h.y*l}))}function ci(s,e){if(!e.length||!s.length)return{vertical:[],horizontal:[],diagonal45:[],diagonal135:[]};const l=ot(e,s,"difference");return{vertical:Qt(l,"x"),horizontal:Qt(l,"y"),diagonal45:Ce(l,Math.PI/4),diagonal135:Ce(l,3*Math.PI/4)}}const Ie=mt*3,_e=mt/2;function di(s){const e=new Map;for(const u of s){const h=`${Math.round(u.x/_e)},${Math.round(u.y/_e)}`;e.has(h)||e.set(h,u)}const l=[...e.values()],a=new Map;return l.forEach((u,h)=>{const c=Math.floor(u.x/Ie),p=Math.floor(u.y/Ie);let m=a.get(c);m||(m=new Map,a.set(c,m));const x=m.get(p)??[];x.push(h),m.set(p,x)}),{points:l,bins:a}}const te=mt*3,mi=5,yi=.15,Pi=mt*.35,vi=2.5;function xi(s,e){var c;const l=s.points[e],a=Math.floor(l.x/te),u=Math.floor(l.y/te),h=[];for(let p=-1;p<=1;p++)for(let m=-1;m<=1;m++)for(const x of((c=s.bins.get(a+p))==null?void 0:c.get(u+m))??[]){const C=s.points[x];x!==e&&(l.x-C.x)**2+(l.y-C.y)**2<=te**2&&h.push(x)}return h}function Ci(s,e){const l=xi(s,e);if(l.length<mi)return!1;const a=s.points[e];let u=0,h=0,c=0,p=0,m=0;for(const F of l){const k=s.points[F],R=k.x-a.x,q=k.y-a.y;u+=R,h+=q,c+=R*R,p+=R*q,m+=q*q}const x=l.length;u/=x,h/=x,c=c/x-u*u,p=p/x-u*h,m=m/x-h*h;const C=Math.hypot(c-m,2*p),v=(c+m+C)/2,I=Math.max(0,(c+m-C)/2);if(v<=0||I>v*yi)return!1;const _=Math.atan2(2*p,c-m)/2,g=Math.cos(_),L=Math.sin(_);if(Math.abs(u*L-h*g)<=Math.max(Pi,vi*Math.sqrt(I)))return!1;let Y=!1,O=!1;for(const F of l){const k=s.points[F],R=(k.x-a.x)*g+(k.y-a.y)*L;Y||(Y=R<-mt/2),O||(O=R>mt/2)}return Y&&O}function Ii(s){return Uint8Array.from(s.points,(e,l)=>Number(Ci(s,l)))}const ee=s=>s%3===2?s-2:s+1;function _i(s,e){const l=di(s),a=Ii(l),u=l.points.filter((p,m)=>!a[m]),h=u.map(()=>new Set);if(u.length<3)return{points:u,neighbors:h};const c=zt.from(u,p=>p.x,p=>p.y);for(let p=0;p<c.triangles.length;p++){const m=c.halfedges[p];if(m>=0&&m<p)continue;const x=c.triangles[p],C=c.triangles[ee(p)],v=u[x],I=u[C],_=g=>{const L=u[c.triangles[ee(ee(g))]];return(L.x-v.x)*(L.x-I.x)+(L.y-v.y)*(L.y-I.y)>=-1e-10};!_(p)||m>=0&&!_(m)||!e(v,I)||(h[x].add(C),h[C].add(x))}return{points:u,neighbors:h}}const St=.006,it=1e-5;class xt extends Error{}function Ti(s=2e6,e=900*1e3){let l=0;const a=performance.now()+e;return(u=1)=>{if(l+=u,l>s||performance.now()>a)throw new xt("Scan-line isolation exceeded its work/time limit. Use a larger tool or simplify the board.")}}function ie(s){if(!s.length)return[];const e=1e5,l=new j.Clipper,a=new j.PolyTree;l.AddPaths(s.map(p=>p.map(m=>({X:Math.round(m.x*e),Y:Math.round(m.y*e)}))),j.PolyType.ptSubject,!0),l.Execute(j.ClipType.ctUnion,a,j.PolyFillType.pftNonZero,j.PolyFillType.pftNonZero);const u=p=>p.Contour().map(m=>({x:m.X/e,y:m.Y/e})),h=[],c=p=>{p.Contour().length&&!p.IsHole()&&h.push([u(p),...p.Childs().filter(m=>m.IsHole()).map(u)]),p.Childs().forEach(c)};return c(a),h}function Xi(s,e,l){return!Zt(s,l)||!Zt(e,l)?!1:ut(s,e)<it?!0:jt([[s,e]],l).reduce((u,h)=>u+h.slice(1).reduce((c,p,m)=>c+ut(h[m],p),0),0)>=ut(s,e)-it}function Te(s,e,l){let a=[];for(let u=0;u<s.length;u+=128)l(),a=ot([...a,...dt(s.slice(u,u+128),e,!0)]);return a}function Li(s,e,l,a,u=()=>{},h=()=>{}){const c=Te(l,a/2+St/2,u);u(),h(1,4);const p=!ot(c,e,"intersection").length&&!ot(c,s,"difference").length,m=ie(e);if(!p)return{safe:!1,unresolved:[],componentCount:m.length};const x=Te(l,Math.max(it,a/2-St/2),u);h(2,4),u();const C=ie(ot(s,x,"difference")),v=m.map(Ct),I=[];for(let _=0;_<C.length;_++){const g=C[_],L=Ct(g);let N=0;for(let Y=0;Y<m.length;Y++){u();const O=v[Y];if(!(O.maxX<L.minX||O.minX>L.maxX||O.maxY<L.minY||O.minY>L.maxY)&&ot(g,m[Y],"intersection").length&&++N>1){I.push({x:(L.minX+L.maxX)/2,y:(L.minY+L.maxY)/2});break}}_+1<C.length&&Xt(_+1,C.length)&&h(2+2*(_+1)/C.length,4)}return h(4,4),{safe:!0,unresolved:I,componentCount:m.length}}function gi(s,e){let l=!1;for(let a=0,u=e.length-1;a<e.length;u=a++){const h=e[a],c=e[u];if(Math.abs((c.x-h.x)*(s.y-h.y)-(c.y-h.y)*(s.x-h.x))<1e-10&&s.x>=Math.min(h.x,c.x)&&s.x<=Math.max(h.x,c.x)&&s.y>=Math.min(h.y,c.y)&&s.y<=Math.max(h.y,c.y))return!0;h.y>s.y!=c.y>s.y&&s.x<(c.x-h.x)*(s.y-h.y)/(c.y-h.y)+h.x&&(l=!l)}return l}function wi(s){const e=[];
1s.forEach((l,a)=>{l.size<2&&e.push(a)});for(let l=0;l<e.length;l++){const a=e[l];for(const u of s[a])s[u].delete(a),s[u].size===1&&e.push(u);s[a].clear()}}function Si(s){const e=[],l=[],a=new Map;for(const u of[...s,s[0]]){const h=a.get(u);if(h!==void 0)for(l.length-h>2&&e.push(l.slice(h));l.length>h+1;)a.delete(l.pop());else a.set(u,l.length),l.push(u)}return e}function Ni(s){return s.reduce((e,l,a)=>{const u=s[(a+1)%s.length];return e+l.x*u.y-u.x*l.y},0)}function Xe(s,e){const{points:l,neighbors:a}=s;wi(a);const u=a.map((m,x)=>[...m].sort((C,v)=>Math.atan2(l[C].y-l[x].y,l[C].x-l[x].x)-Math.atan2(l[v].y-l[x].y,l[v].x-l[x].x))),h=ie(e).map(m=>m[0][0]),c=new Set,p=[];for(let m=0;m<l.length;m++)for(const x of u[m]){if(c.has(m*l.length+x))continue;let C=m,v=x;const I=[];for(;!c.has(C*l.length+v);){c.add(C*l.length+v),I.push(l[C]);const _=u[v],g=_[(_.indexOf(C)+_.length-1)%_.length];C=v,v=g}for(const _ of Si(I))Ni(_)<=1e-8||h.some(g=>gi(g,_))&&p.push([..._,_[0]])}return p}const Yi=mt*3;function Mi(s,e){const l=e.map(()=>[]);return s.points.forEach((a,u)=>{if(s.neighbors[u].size!==1)return;let h=Yi**2,c;e.forEach((p,m)=>{p.forEach((x,C)=>{const v=p[(C+1)%p.length],I=v.x-x.x,_=v.y-x.y,g=I*I+_*_;if(!g)return;const L=Math.max(0,Math.min(1,((a.x-x.x)*I+(a.y-x.y)*_)/g)),N={x:x.x+L*I,y:x.y+L*_},Y=(a.x-N.x)**2+(a.y-N.y)**2;Y>=h||(h=Y,c={ring:m,hit:{id:u,position:C+L,point:N}})})}),c&&l[c.ring].push(c.hit)}),l}function Oi(s,e){const l={points:[...s.points],neighbors:s.neighbors.map(h=>new Set(h))},a=(h,c)=>{l.neighbors[h].add(c),l.neighbors[c].add(h)},u=Mi(s,e);return e.forEach((h,c)=>{if(!u[c].length)return;const m=[...h.map((x,C)=>({id:-1,position:C,point:x})),...u[c]].sort((x,C)=>x.position-C.position).map(x=>{const C=l.points.length;return l.points.push(x.point),l.neighbors.push(new Set),x.id>=0&&a(x.id,C),C});m.forEach((x,C)=>a(x,m[(C+1)%m.length]))}),l}function Ai(s,e,l){const a=Oi(s,e);if(a.points.length===s.points.length)return[];const u=new Map(s.points.map((c,p)=>[c,p])),h=new Map;for(const c of Xe(a,l)){const p=c.slice(0,-1),m=p.findIndex(C=>!u.has(C));if(m<0)continue;let x=[];for(let C=1;C<=p.length;C++){const v=p[(m+C)%p.length];if(u.has(v)){x.push(v);continue}if(x.length>1){const I=u.get(x[0]),_=u.get(x[x.length-1]),g=`${Math.min(I,_)}:${Math.max(I,_)}`,L=x.slice(1).reduce((N,Y,O)=>N+ut(x[O],Y),0);(!h.has(g)||L<h.get(g).length)&&h.set(g,{path:x,length:L})}x=[]}}return[...h.values()].map(({path:c})=>c)}function Ei(s){const e=[],l=[],a=new Map,u=new Set,h=p=>{const m=`${p.x},${p.y}`,x=a.get(m);if(x!==void 0)return x;const C=e.length;return a.set(m,C),e.push(p),l.push(new Set),C},c=s.map(p=>p.map(h));for(const p of c){p.length>1&&p[0]!==p.at(-1)&&(u.add(p[0]),u.add(p.at(-1)));for(let m=1;m<p.length;m++){const x=p[m-1],C=p[m];x!==C&&(l[x].add(C),l[C].add(x))}}return l.forEach((p,m)=>{p.size!==2&&u.add(m)}),{points:e,neighbors:l,paths:c,junctions:u}}function Le(s,e,l,a){const u=[s];let h=s,c=e;for(;;){if(l[h].delete(c),l[c].delete(h),u.push(c),a.has(c)||!l[c].size)return u;h=c,c=l[c].values().next().value}}function bi(s){const e=s.neighbors.map(a=>new Set(a)),l=[];for(const a of s.junctions)for(;e[a].size;)l.push(Le(a,e[a].values().next().value,e,s.junctions));for(let a=0;a<e.length;a++)e[a].size&&l.push(Le(a,e[a].values().next().value,e,s.junctions));return l}const Bi=20,ge=.25;function Di(s,e){const l=[s[0]];let a=0,u=0;for(let h=1;h<s.length;h++)if(u+=Math.hypot(s[h].x-s[h-1].x,s[h].y-s[h-1].y),!(u<mt*2&&h<s.length-1)){if(e(s[a],s[h]))l.push(s[h]);else for(let c=a+1;c<=h;c++)l.push(s[c]);a=h,u=0}return l}function Fi(s,e,l=e,a=!1){if(s.length<2)return s.map(p=>({...p}));const u=Di(s,l),h=!a&&s.length>1&&s[0].x===s[s.length-1].x&&s[0].y===s[s.length-1].y,c=(h?u.slice(0,-1):u).map(p=>({...p}));for(let p=0;p<Bi;p++)for(let m=h?0:1;m<c.length-(h?0:1);m++){const x=c[(m+c.length-1)%c.length],C=c[m],v=c[(m+1)%c.length],I={x:C.x+ge*(x.x+v.x-2*C.x),y:C.y+ge*(x.y+v.y-2*C.y)};(I.x-C.x)**2+(I.y-C.y)**2<1e-12||e(x,I)&&e(I,v)&&(c[m]=I)}return h&&c.length?[...c,c[0]]:c}
1function Ri(s,e,l){const a=new Map;for(const u of bi(s)){const h=u.map(m=>s.points[m]),c=Fi(h,e,l,s.junctions.has(u[0])),p=[...c].reverse();for(let m=1;m<u.length;m++)a.set(`${u[m-1]}:${u[m]}`,c),a.set(`${u[m]}:${u[m-1]}`,p)}return a}function Wi(s,e){const l=[];for(let a=1;a<s.length;a++){const u=e.get(`${s[a-1]}:${s[a]}`);u&&u!==l.at(-1)&&l.push(u)}return l.length>1&&l[0]===l.at(-1)&&l.pop(),l.flatMap((a,u)=>u?a.slice(1):a)}function Zi(s,e,l=e){const a=Ei(s),u=Ri(a,e,l);return a.paths.map((h,c)=>h.length<2?s[c].map(p=>({...p})):Wi(h,u))}function ki(s,e,l,a){if(!Number.isFinite(l)||l<=0)return{status:"error",paths:[],diagnostics:["Invalid effective cut width."],unresolved:[]};a==null||a(0,{stage:"Sample virtual scan midpoints",completed:0,total:1});const u=ci(s,e),h=Je(s,l),c=Object.values(u).flat().filter(h);a==null||a(.5,{stage:"Connect nearby scan points",completed:0,total:1});const p=de([...s,...e]),m=_i(c,p),x=Ai(m,e,s),C=Xe(m,s);a==null||a(.8,{stage:"Round scan path corners",completed:0,total:1});const v=Zi([...C,...x],(I,_)=>p(I,_,l*.49),p);return a==null||a(1,{stage:"Scan paths ready",completed:1,total:1}),{status:"complete",paths:v,unresolved:[],diagnostics:["Scan paths are preview-only; cutter validation is required before export."]}}const ne=(s,e,l)=>s==="x"?{x:e,y:l}:{x:l,y:e};function we(s,e,l){const a=e==="x"?"y":"x",u=s.flatMap(p=>p.flatMap((m,x)=>{const C=p[(x+1)%p.length];return Math.abs(m[e]-C[e])<it/2?[]:[{a:m,b:C,low:Math.min(m[e],C[e]),high:Math.max(m[e],C[e])}]})).sort((p,m)=>p.low-m.low);let h=0,c=[];return p=>{for(;h<u.length&&u[h].low<=p;)c.push(u[h++]);c=c.filter(C=>C.high>p);const m=c.map(({a:C,b:v})=>(l(),C[a]+(p-C[e])*(v[a]-C[a])/(v[e]-C[e]))).sort((C,v)=>C-v),x=[];for(let C=0;C+1<m.length;C+=2)m[C+1]-m[C]>it&&x.push({low:m[C],high:m[C+1]});return x}}function qi(s,e,l,a=[]){const u=Math.ceil((e-s)/l);if(!Number.isFinite(u)||u>2e4)throw new xt("Scan-line count exceeds 20,000 per direction. Use a larger tool.");const h=Array.from({length:u},(p,m)=>s+(m+.5)*l).concat(a).filter(p=>p>s+it&&p<e-it).sort((p,m)=>p-m),c=h.filter((p,m)=>!m||p-h[m-1]>it);if(c.length>2e4)throw new xt("Refined scan-line count exceeds 20,000 per direction.");return c}function Ui(s,e,l,a,u,h){const c=we(s,l,u),p=we(e,l,u);let m=0;return h(0,a.length),a.map((x,C)=>{u();const v=c(x),I=p(x);let _=0;const g=I.map(L=>{for(;_<v.length&&v[_].high<L.low;)_++;const N=v[_],Y=N?(N.low+N.high)/2:NaN,O=Y>L.low+it&&Y<L.high-it?Y:(L.low+L.high)/2;if(++m>5e4)throw new xt("Scan-line samples exceed 50,000 per direction.");return{...L,point:ne(l,x,O)}});return Xt(C+1,a.length)&&h(C+1,a.length),{coordinate:x,samples:g}})}function Hi(s,e,l,a,u){const h=[];u(0,Math.max(0,s.length-1));for(let c=1;c<s.length;c++){const p=s[c-1],m=s[c];let x=0;for(const C of p.samples){for(;x<m.samples.length&&m.samples[x].high<C.low;)x++;for(let v=x;v<m.samples.length&&m.samples[v].low<=C.high;v++){a();const I=m.samples[v],_=Math.max(C.low,I.low),g=Math.min(C.high,I.high);if(!(g-_<=it)){if(l(C.point,I.point))h.push([C.point,I.point]);else{const L=(_+g)/2,N=[C.point,ne(e,p.coordinate,L),ne(e,m.coordinate,L),I.point];N.slice(1).every((Y,O)=>l(N[O],Y))&&h.push(N)}if(h.length>1e5)throw new xt("Isolation graph exceeds 100,000 connections.")}}}Xt(c,s.length-1)&&u(c,s.length-1)}return h}const kt=(s,e)=>s.x*e.y-s.y*e.x,qt=(s,e)=>({x:s.x-e.x,y:s.y-e.y}),Se=(s,e,l)=>({x:s.x+(e.x-s.x)*l,y:s.y+(e.y-s.y)*l});function Gi(s,e){const l=s.flatMap(v=>v.slice(1).flatMap((I,_)=>{const g=v[_];return ut(g,I)<=it?[]:[{a:g,b:I,cuts:[0,1],minX:Math.min(g.x,I.x),maxX:Math.max(g.x,I.x),minY:Math.min(g.y,I.y),maxY:Math.max(g.y,I.y)}]})).sort((v,I)=>v.minX-I.minX);let a=[];for(const v of l){a=a.filter(I=>I.maxX>=v.minX-it);for(const I of a){if(e(),I.maxY<v.minY-it||I.minY>v.maxY+it)continue;const _=qt(v.b,v.a),g=qt(I.b,I.a),L=qt(I.a,v.a),N=kt(_,g);if(Math.abs(N)>1e-12){const Y=kt(L,g)/N,O=kt(L,_)/N;Y>=0&&Y<=1&&O>=0&&O<=1&&(v.cuts.push(Y),I.cuts.push(O))}else if(Math.abs(kt(L,_))<it*Math.hypot(_.x,_.y))for(const[Y,O]of[[v,[I.a,I.b]],[I,[v.a,v.b]]]){const F=qt(Y.b,Y.a),k=F.x**2+F.y**2;for(const R of O){const q=((R.x-Y.a.x)*F.x+(R.y-Y.a.y)*F.y)/k;q>0&&q<1&&Y.cuts.push(q)}}}a.push(v)}const u=[],h=new Map,c=[],p=v=>{const I=`${Math.round(v.x/it)},${Math.round(v.y/it)}`;let _=h.get(I);return _===void 0&&(_=u.length,h.set(I,_),u.push(v),c.push(new Set)),_};for(const v of l){v.cuts.sort((I,_)=>I-_);for(let I=1;I<v.cuts.length;I++){e();const _=p(Se(v.a,v.b,v.cuts[I-1])),g=p(Se(v.a,v.b,v.cuts[I]));_!==g&&(c[_].add(g),c[g].add(_))}if(u.length>1e5)throw new xt("Isolation graph exceeds 100,000 vertices.")}const m=c.map(v=>v.size),x=[],C=(v,I)=>{const _=[u[v]];let g=v,L=I;for(;e(),c[g].delete(L),c[L].delete(g),_.push(u[L]),!(m[L]!==2||!c[L].size);)g=L,L=c[L].values().next().value;x.push(_)};for(let v=0;v<u.length;v++)if(m[v]!==2)for(const I of[...c[v]])c[v].has(I)&&C(v,I);for(let v=0;v<u.length;v++)c[v].size&&C(v,c[v].values().next().value);return x}function Ji(s,e,l,a={}){const u=Ti(a.maxWork,a.milliseconds);let h=0;const c=(p,m,x=0,C=1)=>{var v;h=Math.max(h,p),(v=a.onProgress)==null||v.call(a,h,{stage:m,completed:x,total:C})};try{if(c(0,"Prepare clearance geometry"),!Number.isFinite(l)||l<=St*2)throw new Error(`Effective tool diameter must exceed ${St*2} mm for scan-line tolerance.`);const p=[...s,...e].flat();if(p.some(O=>
1!Number.isFinite(O.x)||!Number.isFinite(O.y)||Math.abs(O.x)>1e6||Math.abs(O.y)>1e6))throw new Error("Invalid or out-of-range scan-line geometry.");if(p.length>2e5)throw new xt("Scan-line input exceeds 200,000 vertices.");const m=ot(e,[],"union",!0),x=ot(ot(s),m,"intersection");if(!m.length||!x.length)return{status:"empty",paths:[],diagnostics:["No board copper to isolate."],unresolved:[]};const C=ot(m,x,"difference"),v=ot(dt(m,-l/2-St),dt(x,l/2+St),"difference");if(!v.length)return{status:"incomplete",paths:[],diagnostics:["No room for the selected cutter and clearance tolerance."],unresolved:[]};u(),c(.1,"Prepare clearance geometry",1,1);const I=Ct(m),_=l/2;let g=[],L;for(let O=0;O<2;O++){const F=O?.75:.1,k=O?.23:.65,R=[];for(const[q,$]of["y","x"].entries()){const Q=O?v.flatMap(b=>b.flatMap(B=>[B[$]-_/4,B[$]+_/4])):[],T=qi($==="x"?I.minX:I.minY,$==="x"?I.maxX:I.maxY,_,Q),M=`${O?"Refine: ":""}${$==="y"?"Horizontal":"Vertical"} scanning`,A=Ui(C,v,$,T,u,(b,B)=>c(F+k*(q*.25+.15*b/Math.max(1,B)),M,b,B));R.push(...Hi(A,$,(b,B)=>(u(),Xi(b,B,v)),u,(b,B)=>c(F+k*(q*.25+.15+.1*b/Math.max(1,B)),"Connect adjacent intervals",b,B)))}if(c(F+k*.5,"Join crossings and extract paths"),g=Gi(R,u),c(F+k*.65,"Validate cutter clearance and residual bridges"),L=Li(m,x,g,l,u,(q,$)=>c(F+k*(.65+.35*q/$),"Validate cutter clearance and residual bridges",q,$)),!L.safe)throw new Error("Final cutter sweep failed clearance validation. No cutting paths were accepted.");if(!L.unresolved.length&&g.length)break}const N=(L==null?void 0:L.unresolved)??[],Y=!!g.length&&!N.length;return c(1,Y?"Isolation validated":"Isolation incomplete",1,1),{status:Y?"complete":"incomplete",paths:Y?g:[],unresolved:N,diagnostics:Y?(L==null?void 0:L.componentCount)===1?["One connected copper component: separation is vacuous; centerlines do not guarantee contour coverage."]:[]:[`Isolation incomplete: ${N.length?`${N.length} residual region(s) still connect separate copper components`:"no continuous cutting path"}. Try a smaller tool or the spiral strategy.${N.length?` Region centers: ${N.slice(0,8).map(O=>`(${O.x.toFixed(3)}, ${O.y.toFixed(3)})`).join(", ")} mm.`:""}`]}}catch(p){return{status:p instanceof xt?"limit":"error",paths:[],unresolved:[],diagnostics:[p instanceof Error?p.message:"Scan-line isolation failed."]}}}function zi(s,e,l,a,u,h=0,c){const p=[];c==null||c(0,{stage:"Offset isolation",completed:0,total:a});for(let m=0;m<a;m++){const x=dt(s,l/2+h+m*l*(1-u));p.push(...jt(x.map(C=>[...C,C[0]]),e)),Xt(m+1,a)&&(c==null||c((m+1)/a,{stage:"Offset isolation",completed:m+1,total:a}))}return p}var re=(s=>(s.X="x",s.Y="y",s))(re||{});const Ne=new DataView(new ArrayBuffer(8)),Ut=52n,Vi=(1n<<Ut)-1n,$i=0x7ffn,Ki=1023;function ji(s){Ne.setFloat64(0,s);const e=Ne.getBigUint64(0),l=Number(e>>Ut&$i),a=e&Vi,u=l?a|1n<<Ut:a;return{integer:e>>63n?-u:u,exponent:(l||1)-Ki-Number(Ut)}}function Qi(s,e){let l=s<0n?-s:s,a=e<0n?-e:e;for(;a;)[l,a]=[a,l%a];return l}function tn(s,e){if(!s)return"0";for(;!(s&1n);)s>>=1n,e++;return`${s}@${e}`}function en(s,e){if(s.x===e.x)return`x:${s.x}`;if(s.y===e.y)return`y:${s.y}`;const l=[s.x,s.y,e.x,e.y].map(ji),a=Math.min(...l.filter(_=>_.integer).map(_=>_.exponent)),[u,h,c,p]=l.map(({integer:_,exponent:g})=>_?_<<BigInt(g-a):0n),m=c-u,x=p-h,C=Qi(m,x)*(m<0n?-1n:1n),v=-x/C,I=m/C;return`${v}:${I}:${tn(v*u+I*h,a)}`}function nn(s,e){let l=s.length;for(s.push(e);l;){const a=l-1>>1;if(s[a].id<=e.id)break;s[l]=s[a],l=a}s[l]=e}function rn(s){const e=s.pop();if(!s.length)return;let l=0;for(;l*2+1<s.length;){let a=l*2+1;if(a+1<s.length&&s[a+1].id<s[a].id&&a++,e.id<=s[a].id)break;s[l]=s[a],l=a}s[l]=e}function sn(s){const e=s.start[s.axis]<s.end[s.axis];return[{point:e?s.start:s.end,coordinate:s.low,segment:s,starts:!0},{point:e?s.end:s.start,coordinate:s.high,segment:s,starts:!1}]}function on(s,e,l){const a=s.retained.at(-1);a&&a[1][s.axis]===e.coordinate?a[1]=l.point:s.retained.push([e.point,l.point])}function ln(s){if(s.length<2)return;const e=s.flatMap(sn).sort((u,h)=>u.coordinate-h.coordinate);for(const u of s)u.retained=[];const l=[];let a=0;for(;a<e.length;){const u=e[a];do{const h=e[a++];h.starts&&nn(l,h.segment)}while(a<e.length&&e[a].coordinate===u.coordinate);for(;l.length&&l[0].high<=u.coordinate;)rn(l);l.length&&a<e.length&&on(l[0],u,e[a])}}const yt=(s,e)=>s===e||s.x===e.x&&s.y===e.y;function an(s,e,l){const a=s.x===e.x?re.Y:re.X;return{id:l,start:s,end:e,axis:a,low:Math.min(s[a],e[a]),high:Math.max(s[a],e[a]),retained:[s[a]<=e[a]?[s,e]:[e,s]]}}function un(s,e){const{start:l,end:a}=e;if(yt(l,a)||![l.x,l.y,a.x,a.y].every(Number.isFinite))return;const u=en(l,a),h=s.get(u);h?h.push(e):s.set(u,[e])}function Ye(s){if(s.retained.length!==1)return!1;const[e,l]=s.retained[0];return yt(e,s.start)&&yt(l,s.end)||yt(l,s.start)&&yt(e,s.end)}function hn(s){return s.start[s.axis]<=s.end[s.axis]?s.retained:s.retained.slice().reverse().map(([e,l])=>[l,e])}function fn(s,[e,l]){if(yt(e,l))return;const a=s.at(-1);a&&yt(a.at(-1),e)?a.push(l):s.push([e,l])}function pn(s,e){if(e.every(Ye))return[s];const l=[];for(const h of e)for(const c of hn(h))fn(l,c);const a=l[0],u=l.at(-1);return l.length>1&&yt(s[0],s.at(-1))&&yt(u.at(-1),a[0])&&(l[0]=[...u,...a.slice(1)],l.pop()),l}function cn(s){const e=new Map;let l=0;const a=s.map(u=>u.slice(1).map((h,c)=>{const p=an(u[c],h,l++);return un(e,p),p}));for(const u of e.values())ln(u);return a.every(u=>u.every(Ye))?s:s.flatMap((u,h)=>pn(u,a[h]))}const Nt=s=>`${s.x},${s.y}`,Me=s=>s.length>1&&Nt(s[0])===Nt(s.at(-1));function dn(s){const e=new Set;for(const l of s)l.length<2||Me(l)||(e.add(Nt(l[0])),e.add(Nt(l.at(-1))));return e}function mn(s,e){const l=[0];for(let a=1;a<s.length-1;a++)e.has(Nt(s[a]))&&l.push(a);return l.length===1?[s]:(l.push(s.length-1),l.slice(1).map((a,u)=>s.slice(l[u],a+1)))}function yn(s,e){const l=[],a=s.length-1;for(let u=0;u<a;u++)e.has(Nt(s[u]))&&l.push(u);return!l.length||l.length===1&&l[0]===0?[s]:l.map((u,h)=>{const c=l[(h+1)%l.length];return c>u?s.slice(u,c+1):[...s.slice(u,a),...s.slice(0,c+1)]})}function Pn(s){const e=dn(s);return e.size?s.flatMap(l=>l.length<2?[l]:Me(l)?yn(l,e):mn(l,e)):s}function vn(s){let e=0;for(let l=1;l<s.length;l++)e+=Math.hypot(s[l].x-s[l-1].x,s[l].y-s[l-1].y);return e}function xn(s,e){const l=[];for(const a of s)for(const u of a.edges){if(u.from!==a||u.to===a||!s.has(u.to))continue;const h=vn(u.path);h<=e&&l.push({edge:u,length:h,order:l.length})}return l.sort((a,u)=>a.length-u.length||a.order-u.order)}function Cn(s){const e={from:s.to,to:s.from,path:s.path.slice().reverse(),used:!1};e.from.edges.push(e),e.to.edges.push(e)}function In(s,e){if(!(e>0))return;const l=new Set(s.filter(a=>a.edges.length%2));if(!(l.size<=2)){for(const{edge:a}of xn(l,e))if(!(!l.has(a.from)||!l.has(a.to))&&(Cn(a),l.delete(a.from),l.delete(a.to),l.size<=2))break}}function Oe(s,e){const l=`${e.x},${e.y}`;let a=s.get(l);return a||(a={edges:[],cursor:0},s.set(l,a)),a}function Ae(s,e,l){const a={from:s,to:e,path:l,used:!1};return s.edges.push(a),e.edges.push(a),a}function _n(s,e){const l=[s];e.add(s);for(let a=0;a<l.length;a++){const u=l[a];for(const h of u.edges){const c=h.from===u?h.to:h.from;e.has(c)||(e.add(c),l.push(c))}}return l}function Tn(s){for(;s.cursor<s.edges.length;){const e=s.edges[s.cursor++];if(!e.used)return e}}function Xn(s){const e=[{vertex:s}],l=[];for(;e.length;){const a=e.at(-1),u=Tn(a.vertex);if(u){u.used=!0;const h=u.from!==a.vertex;e.push({vertex:h?u.from:u.to,incoming:{edge:u,reversed:h}})}else e.pop(),a.incoming&&l.push(a.incoming)}return l.reverse()}function Ln(s,e){const l=e.edge.path,a=s.length?1:0;for(let u=a;u<l.length;u++)s.push(l[e.reversed?l.length-u-1:u])}function gn(s){const e=s.findIndex(u=>!u.edge.path),l=[];let a=[];for(let u=0;u<s.length;u++){const h=s[(e+1+u)%s.length];h.edge.path?Ln(a,h):a.length&&(l.push(a),a=[])}return a.length&&l.push(a),l}function wn(s,e){if(s.reduce((u,h)=>u+h.edges.length,0)===2)return[s[0].edges[0].path];In(s,e);const a=s.filter(u=>u.edges.length%2);for(let u=0;u<a.length;u+=2)Ae(a[u],a[u+1]);return gn(Xn(s[0]))}function Ee(s,e=0){const l=Pn(s),a=new Map,u=l.map(p=>p.length<2?void 0:Ae(Oe(a,p[0]),Oe(a,p.at(-1)),p)),h=new Set,c=[];for(const[p,m]of u.entries())m?h.has(m.from)||c.push(...wn(_n(m.from,h),e)):c.push(l[p]);return c.every((p,m)=>p===s[m])&&c.length===s.length?s:c}const Sn=8;function Nn(s){const e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,minimumId:1/0};for(const l of s)e.minX=Math.min(e.minX,l.minX),e.minY=Math.min(e.minY,l.minY),e.maxX=Math.max(e.maxX,l.maxX),e.maxY=Math.max(e.maxY,l.maxY),e.minimumId=Math.min(e.minimumId,l.id);return e}function se(s){const e=Nn(s);if(s.length<=Sn)return e.segments=s.sort((u,h)=>u.id-h.id),e;const l=e.maxX-e.minX>=e.maxY-e.minY;s.sort((u,h)=>(l?u.minX+u.maxX-h.minX-h.maxX:u.minY+u.maxY-h.minY-h.maxY)||u.id-h.id);const a=Math.floor(s.length/2);return e.left=se(s.slice(0,a)),e.right=se(s.slice(a)),e}function Yn(s){return s.length?se(s.slice()):void 0}function be(s,e){return s.minX<=e.maxX&&s.maxX>=e.minX&&s.minY<=e.maxY&&s.maxY>=e.minY}function Mn(s,e){const l=e+Number.EPSILON*16*Math.max(1,Math.abs(s.minX),Math.abs(s.maxX),Math.abs(s.minY),Math.abs(s.maxY));return{minX:s.minX-l,minY:s.minY-l,maxX:s.maxX+l,maxY:s.maxY+l}}function On(s,e,l,a){for(const u of s)if(u.id<l&&u.retained.length>0&&be(u,e)&&!a(u))return!1;return!0}function An(s,e){const{left:l,right:a}=e;l&&a?l.minimumId<=a.minimumId?s.push(a,l):s.push(l,a):l?s.push(l):a&&s.push(a)}function En(s,e,l,a){const u=s?[s]:[],h=Mn(e,l);for(;u.length;){const c=u.pop();if(!(c.minimumId>=e.id||!be(c,h))){if(c.segments&&!On(c.segments,h,e.id,a))return;An(u,c)}}}function bn(s,e,l){const a=s.end.x-s.start.x,u=s.end.y-s.start.y,h=Math.hypot(a,u),c=e.x-s.start.x,p=e.y-s.start.y,m=(c*u-p*a)/h;if(Math.abs(m)>l)return;const x=(c*a+p*u)/h,C=Math.sqrt(Math.max(0,l*l-m*m));return[Math.max(0,(x-C)/h),Math.min(1,(x+C)/h)]}function Bn(s,e,l,a){let[u,h]=l;for(const c of e){const p=bn(s,c,a);!p||p[1]<u||p[0]>h||(u=Math.min(u,p[0]),h=Math.max(h,p[1]))}return[u,h]}const Dn=Math.SQRT1_2,oe=Number.EPSILON*32;function Ht(s,e){return e===0?s.start:e===1?s.end:{x:s.start.x+(s.end.x-s.start.x)*e,y:s.start.y+(s.end.y-s.start.y)*e}}function Fn(s,e,l,a){const u=Ht(e,l[0]),h=Ht(e,l[1]),c=s.end.x-s.start.x,p=s.end.y-s.start.y,m=Math.hypot(h.x-u.x,h.y-u.
1y);if(!m)return;const x=(h.x-u.x)/m,C=(h.y-u.y)/m,v=(s.start.x-u.x)*x+(s.start.y-u.y)*C,I=c*x+p*C;if(Math.abs(I)<=Math.hypot(c,p)*Dn)return;const _=[-v/I,(m-v)/I],g=Math.max(0,Math.min(..._)),L=Math.min(1,Math.max(..._));if(L-g<=oe)return;const N=(s.start.x-u.x)*C-(s.start.y-u.y)*x,Y=c*C-p*x,O=Number.EPSILON*16*Math.max(1,Math.abs(v),m,Math.abs(u.x),Math.abs(u.y),Math.abs(h.x),Math.abs(h.y),Math.abs(s.minX),Math.abs(s.maxX),Math.abs(s.minY),Math.abs(s.maxY));if(!(Math.max(Math.abs(N+g*Y),Math.abs(N+L*Y))>a+O))return Bn(s,[u,h],[g,L],a+O)}function Rn(s,[e,l]){return s.flatMap(([a,u])=>{if(e>=u||l<=a)return[[a,u]];const h=[];return e-a>oe&&h.push([a,e]),u-l>oe&&h.push([l,u]),h})}const bt=(s,e)=>s.x===e.x&&s.y===e.y;function Wn(s,e,l){return{id:l,start:s,end:e,retained:[[0,1]],minX:Math.min(s.x,e.x),maxX:Math.max(s.x,e.x),minY:Math.min(s.y,e.y),maxY:Math.max(s.y,e.y)}}function Zn(s,e,l){En(e,s,l,a=>{for(const u of a.retained){const h=Fn(s,a,u,l);if(h&&(s.retained=Rn(s.retained,h)),!s.retained.length)return!1}return!0})}function Be(s){return s.retained.length===1&&s.retained[0][0]===0&&s.retained[0][1]===1}function kn(s,e){if(e.every(Be))return[s];const l=[];for(const h of e)for(const[c,p]of h.retained){const m=Ht(h,c),x=Ht(h,p);if(bt(m,x))continue;const C=l.at(-1);C&&bt(C.at(-1),m)?C.push(x):l.push([m,x])}const a=l[0],u=l.at(-1);return l.length>1&&bt(s[0],s.at(-1))&&bt(u.at(-1),a[0])&&(l[0]=[...u,...a.slice(1)],l.pop()),l}function qn(s,e){if(!(e>0)||!Number.isFinite(e))return s;let l=0;const a=s.map(c=>c.slice(1).map((p,m)=>Wn(c[m],p,l++))),u=a.flat().filter(c=>!bt(c.start,c.end)&&[c.minX,c.minY,c.maxX,c.maxY].every(Number.isFinite)),h=Yn(u);for(const c of u)Zn(c,h,e);return a.every(c=>c.every(Be))?s:s.flatMap((c,p)=>kn(c,a[p]))}const Un=.01;function De(s){return s.strategy==="spiral"&&s.overlap===0}function Hn(s){return Math.min(Un,s/4)}function Gn(s,e,l,a,u){if(a.strategy==="virtual-scans")return ki(s,e,l,u);if(a.strategy==="between-traces")return Ji(s,e,l,{onProgress:u});const h=zi(ot(s,e,"intersection"),dt(e,-l/2),l,a.passes,a.overlap,a.copperOffset??0,u);return{status:h.length?"complete":"empty",paths:h,diagnostics:[],unresolved:[]}}function Jn(s,e,l,a,u){const h=Gn(s,e,l,a,(m,x)=>u==null?void 0:u(m*.95,x));u==null||u(.95,{stage:"Remove repeated cuts",completed:0,total:1});const c=cn(h.paths),p=Ee(De(a)?qn(c,Hn(l)):c);return u==null||u(1,{stage:"Isolation paths ready",completed:1,total:1}),{...h,paths:p}}function zn(s){return!!s&&typeof s.id=="string"&&typeof s.name=="string"&&[s.width,s.height,s.zTravel,s.maxRpm,s.spindleMaxS,s.rapidFeed].every(e=>Number.isFinite(e)&&e>0)}const le=(s,e)=>(s.x-e.x)**2+(s.y-e.y)**2;function Vn(s){return s.flatMap((e,l)=>{const a={point:e[0],pathIndex:l,reversed:!1},u=e.at(-1);return le(a.point,u)===0?[a]:[a,{point:u,pathIndex:l,reversed:!0}]})}function ae(s,e,l="x",a){if(!s.length)return;s.sort((p,m)=>p.point[l]-m.point[l]);const u=Math.floor(s.length/2),h={...s[u],axis:l,parent:a,active:!0,remaining:s.length};e[h.pathIndex].push(h);const c=l==="x"?"y":"x";return h.left=ae(s.slice(0,u),e,c,h),h.right=ae(s.slice(u+1),e,c,h),h}function ue(s,e,l){if(!(s!=null&&s.remaining))return;const a=le(e,s.point);s.active&&(a<l.distance||a===l.distance&&(!l.node||s.pathIndex<l.node.pathIndex||s.pathIndex===l.node.pathIndex&&!s.reversed))&&(l.node=s,l.distance=a);const u=e[s.axis]-s.point[s.axis];ue(u<=0?s.left:s.right,e,l),u*u<=l.distance&&ue(u<=0?s.right:s.left,e,l)}function $n(s){for(const e of s){e.active=!1;let l=e;for(;l;)l.remaining--,l=l.parent}}function Fe(s,e){let l=e,a=0;for(const u of s)a+=Math.sqrt(le(l,u[0])),l=u.at(-1);return a}function he(s,e){const l=s.filter(p=>p.length>0),a=l.map(()=>[]),u=ae(Vn(l),a),h=[];let c=e;for(;u!=null&&u.remaining;){const p={distance:1/0};ue(u,c,p);const m=p.node,x=l[m.pathIndex],C=m.reversed?[...x].reverse():x;h.push(C),c=C.at(-1),$n(a[m.pathIndex])}return Fe(h,e)<Fe(l,e)?h:l}function Kn(s,e,l,a,u){const h=(l.safeZ+s)/l.machine.rapidFeed,c=(l.safeZ-e)/l.machine.rapidFeed,p=(e+s)/(a.plunge*u.plungeFactor*l.feedScale),m=a.feed*u.feedFactor*l.feedScale;return(h+c+p)*m}const jn=s=>s.toFixed(3),Qn=.5,tr=.1;function er(s,e){if(s.kind===ht.BallNose){const l=s.diameter/2,a=Math.max(0,Math.min(e,l));
1return 2*Math.sqrt(a*(s.diameter-a))}return s.kind===ht.VBit?Math.min(s.diameter,s.tip+2*e*Math.tan(s.angle*Math.PI/360)):s.diameter}function fe(s,e,l){const a={...s};return e==="bottom"&&(l.flipAxis==="y"?a.x=2*l.flipCoordinate-a.x:a.y=2*l.flipCoordinate-a.y),{x:a.x-l.origin.x,y:a.y-l.origin.y}}function ir(s,e,l){if(!s.end||ut(s,s.end)<.001)return[{x:s.x,y:s.y}];const a=Math.ceil(ut(s,s.end)/(e*(1-l)));if(a>1e4)throw new Error("Slot exceeds the supported drill-hit count.");return Array.from({length:a+1},(u,h)=>({x:s.x+(s.end.x-s.x)*h/a,y:s.y+(s.end.y-s.y)*h/a}))}function nr(s,e){let l={x:0,y:0,z:e},a=0,u=0;for(const h of s){const c=Math.hypot(h.x-l.x,h.y-l.y,h.z-l.z);a+=c/h.feed*60,u+=c,l=h}return{seconds:a,distance:u}}function rr(s,e,l,a,u){var Q;const h={operations:[],errors:[...s.errors],warnings:[...s.warnings]},c=a.find(T=>T.id===e.materialId);c||h.errors.push("Select a valid material."),([e.thickness,e.safeZ,e.travelZ,e.toolChangeZ,e.feedScale,e.drilling.peck,e.cutout.stepdown,e.cutout.tabWidth,e.cutout.tabHeight].some(T=>!Number.isFinite(T)||T<=0)||![e.origin.x,e.origin.y,e.flipCoordinate,e.drilling.breakthrough].every(Number.isFinite)||e.drilling.breakthrough<0||e.drilling.slotOverlap<0||e.drilling.slotOverlap>.8||!Number.isInteger(e.cutout.tabs)||e.cutout.tabs<0||e.cutout.tabs>20)&&h.errors.push("Setup contains invalid dimensions or rates."),(e.travelZ<e.safeZ||e.toolChangeZ<e.travelZ)&&h.errors.push("Outside travel height must be at least the PCB clearance; tool-change height must be at least outside travel height."),e.probe.enabled&&(![e.probe.plateHeight,e.probe.feed,e.probe.travel].every(T=>Number.isFinite(T)&&T>0)||![e.probe.x,e.probe.y].every(Number.isFinite)||e.probe.plateHeight+e.safeZ>=e.toolChangeZ)&&h.errors.push("Probe settings are invalid or probe approach height reaches tool-change height."),e.cutout.enabled&&e.cutout.tabs&&e.cutout.tabHeight>=e.thickness&&h.errors.push("Tab height must be smaller than board thickness.");let m=Ct(s.outline);if(e.cutout.enabled){const T=l.find(M=>M.id===e.cutout.toolId);T!=null&&T.diameter&&T.diameter>0&&(m=ui(s.outline,T.diameter/2))}if((m.width>e.machine.width||m.height>e.machine.height)&&h.errors.push(`Board exceeds the configured ${e.machine.width} à ${e.machine.height} mm machine area.`),s.copper.bottom.length&&e.isolation.bottom.enabled&&e.fiducials.length<2&&h.warnings.push("Double-sided setup has fewer than two alignment holes. Verify an alternative registration method."),e.fiducials.some(T=>![T.x,T.y,T.diameter].every(Number.isFinite)||T.diameter<=0)&&h.errors.push("Invalid alignment hole coordinates or diameter."),zn(e.machine)||h.errors.push("Machine limits must be positive metric values."),e.toolChangeZ+e.thickness+e.drilling.breakthrough>e.machine.zTravel&&h.errors.push(`Tool-change height plus cutting depth exceeds ${e.machine.name} Z travel (${e.machine.zTravel} mm). Reduce heights or correct the machine profile.`),h.errors.length||!c)return h;const x=["top","bottom"].filter(T=>e.isolation[T].enabled&&s.copper[T].length),C=Math.max(1,(e.fiducials.length?1:0)+x.length+(e.drilling.enabled?1:0)+(e.cutout.enabled?1:0));let v=0;const I=()=>{v++,u==null||u(Math.min(1,v/C))};u==null||u(0);const _=T=>fe(e.origin,T,{...e,origin:{x:0,y:0}}),g=(T,M)=>{const A=l.find(b=>b.id===T);if(!A||!M.includes(A.kind)||[A.feed,A.plunge,A.rpm,A.diameter,A.stepdown].some(b=>!Number.isFinite(b)||b<=0)||A.kind===ht.VBit&&(!A.tip||!A.angle||A.angle>=180)){h.errors.push(`Invalid or missing tool: ${T}`);return}return A},L=(T,M,A,b)=>({id:`${h.operations.length+1}-${A}-${M}`,name:T,kind:M,side:A,toolId:b.id,moves:[],seconds:0,distance:0}),N=(T,M,A,b,B,G=!1)=>{if(T.moves.length>1e6)throw new Error("Toolpath exceeds one million moves; simplify the job.");T.moves.push({...fe(M,T.side,e),z:A,rapid:b,feed:b?e.machine.rapidFeed:(G?B.plunge*c.plungeFactor:B.feed*c.feedFactor)*e.feedScale})},Y=T=>{T.moves.length&&(T.moves=or(T.moves,s,e,T.side),Object.assign(T,nr(T.moves,e.toolChangeZ)),h.operations.push(T))},O=Math.min(e.safeZ,Qn),F=(T,M,A,b)=>{if(!(M.length<3)){N(T,M[0],O,!0,b),N(T,M[0],A,!1,b,!0);for(const B of[...M.slice(1),M[0]])N(T,B,A,!1,b);N(T,M[0],e.safeZ,!0,b)}},k=(T,M)=>{var b;const A=new Map;for(const B of T){const G=jn(B.diameter),z=e.drilling.tools[G];if(z==="skip")continue;const W=g(z||((b=l.find(et=>et.kind===ht.Drill&&Math.abs(et.diameter-B.diameter)<.001))==null?void 0:b.id)||`drill Ã${B.diameter}`,[ht.Drill]);if(!W)continue;if(Math.abs(W.diameter-B.diameter)>.001){h.errors.push(`Hole Ã${B.diameter.toFixed(2)} needs an equal-diameter drill; oversized-hole milling is disabled.`);continue}const V=A.get(W.id)??{tool:W,holes:[]};V.holes.push(B),A.set(W.id,V)}for(const{tool:B,holes:G}of A.values()){const z=L(`${M==="fiducial"?"Alignment holes":"Drill"} · Ã${B.diameter.toFixed(1)} mm`,M,"top",B),W=he(G.map(Z=>ir(Z,B.diameter,e.drilling.slotOverlap)),_(z.side)).flat(),V=e.thickness+e.drilling.breakthrough,et=Math.min(e.drilling.peck,B.stepdown);if(V/et>1e3){h.errors.push("Drilling requires more than 1,000 pecks per hole.");continue}for(const Z of W){N(z,Z,O,!0,B);for(let K=Math.min(et,V);N(z,Z,-K,!1,B,!0),N(z,Z,K===V?e.safeZ:0,!0,B),K!==V;K=Math.min(K+et,V)){const rt=tr-K;rt<0&&N(z,Z,rt,!0,B)}}Y(z)}};e.fiducials.length&&(u==null||u(v/C,{stage:"Alignment drilling",completed:0,total:1}),k(e.fiducials,"fiducial"),I());
1for(const T of["top","bottom"]){const M=e.isolation[T];if(!M.enabled||!s.copper[T].length)continue;if(!Number.isFinite(M.depth)||M.depth<=0||M.depth>=e.thickness||M.strategy==="spiral"&&(!Number.isInteger(M.passes)||M.passes<1||M.passes>20||!Number.isFinite(M.overlap)||M.overlap<0||M.overlap>.8||!Number.isFinite(M.copperOffset??0)||(M.copperOffset??0)<0)){h.errors.push(`${T}: invalid isolation depth, pass count, overlap, or copper offset.`);continue}const A=g(M.toolId,Ue);if(!A)continue;const b=er(A,M.depth),B=ot(s.copper[T],s.outline,"intersection"),G=L(`${T==="top"?"Top":"Bottom"} copper isolation`,"isolation",T,A),z=(Z,K)=>u==null?void 0:u((v+Z*(M.rough?.8:1))/C,K?{...K,side:T}:void 0),W=Jn(s.copper[T],s.outline,b,M,(Z,K)=>z(Z*.95,K)),V=W.diagnostics.map(Z=>`${T}: ${Z}`);W.status!=="complete"&&W.status!=="empty"?h.errors.push(...V):h.warnings.push(...V);const et=he(Ee(W.paths.filter(Z=>Z.length>=2),De(M)?0:Kn(M.depth,O,e,A,c)),_(T));z(.95,{stage:"Emit isolation moves",completed:0,total:et.length});for(const[Z,K]of et.entries())if(!(K.length<2)){N(G,K[0],O,!0,A),N(G,K[0],-M.depth,!1,A,!0);for(const rt of K.slice(1))N(G,rt,-M.depth,!1,A);N(G,K.at(-1),e.safeZ,!0,A),Xt(Z+1,et.length)&&z(.95+.05*(Z+1)/et.length,{stage:"Emit isolation moves",completed:Z+1,total:et.length})}if(Y(G),M.rough){const Z=g(M.roughToolId,[ht.EndMill]);if(Z){const K=L(`${T==="top"?"Top":"Bottom"} copper clearing`,"roughing",T,Z);let rt=ot(dt(s.outline,-Z.diameter/2),dt(B,Z.diameter/2+.03),"difference"),It=0;const ft=[];for(u==null||u((v+.8)/C,{stage:"Copper clearing",completed:0,total:500,side:T});rt.length&&It++<500;){for(const _t of rt)_t.length>=3&&ft.push([..._t,_t[0]]);rt=dt(rt,-Z.diameter*.55),(!rt.length||Xt(It,500))&&(u==null||u((v+.8+.19*It/500)/C,{stage:"Copper clearing",completed:It,total:rt.length?500:It,side:T}))}rt.length&&h.errors.push("Copper clearing exceeded 500 passes.");for(const _t of he(ft,_(T)))F(K,_t.slice(0,-1),-M.depth,Z);Y(K)}}I()}if(e.drilling.enabled&&(u==null||u(v/C,{stage:"Drilling",completed:0,total:1}),k(s.holes,"drill"),I()),e.cutout.enabled){u==null||u(v/C,{stage:"Board cutout",completed:0,total:1});const T=g(e.cutout.toolId,[ht.EndMill]);if(T){const M=L("Board cutout","cutout",e.cutout.side,T),A=e.thickness+e.drilling.breakthrough,b=Math.min(e.cutout.stepdown,T.stepdown);if(A/b>1e3)return h.errors.push("Cutout requires more than 1,000 depth passes."),h;const B=dt(ot(s.outline,[],"union",!0),T.diameter/2);B.sort((G,z)=>+(pe(G)>0)-+(pe(z)>0)||Gt(G)-Gt(z));for(const G of B){const z=pe(G)>0?e.cutout.tabs:0,W=Gt(G);if(z&&z*(e.cutout.tabWidth+T.diameter)>=W){h.errors.push(`${z} tabs need ${(z*(e.cutout.tabWidth+T.diameter)).toFixed(2)} mm including tool clearance, but an exterior cutout is only ${W.toFixed(2)} mm long. Reduce tab count or width, or select a smaller cutout tool.`);continue}for(let V=b;V<A+b;V+=b){const et=-Math.min(V,A),Z=sr(G,et,e,T.diameter,z);N(M,Z[0],O,!0,T),N(M,Z[0],Z[0].z,!1,T,!0);for(const K of Z.slice(1))N(M,K,K.z,!1,T,((Q=M.moves.at(-1))==null?void 0:Q.z)!==K.z);N(M,Z.at(-1),e.safeZ,!0,T)}}Y(M),e.cutout.tabs||h.warnings.push("Cutout has no holding tabs; use a verified full-board workholding method.")}I()}u==null||u(1),h.operations.length||h.errors.push("No enabled operations produced toolpaths."),s.holes.some(T=>T.end)&&h.warnings.push("Overlapping drilling leaves scalloped slots and can side-load drills; inspect the slot preview."),h.warnings.push("Time estimates use commanded motion rates; acceleration, probing, spindle startup, flips, and manual tool changes add time.");const R=T=>T.kind==="fiducial"?0:T.kind==="cutout"?3:T.side==="top"?1:2;h.operations.sort((T,M)=>R(T)-R(M));const q=Ct([[{x:0,y:0},...e.probe.enabled?[{x:e.probe.x,y:e.probe.y}]:[],...h.operations.flatMap(T=>T.moves)]]);return(q.width>e.machine.width||q.height>e.machine.height)&&h.errors.push("Toolpaths, probe position, or alignment holes exceed the configured XY travel span."),l.filter(T=>h.operations.some(M=>M.toolId===T.id)&&T.rpm>e.machine.maxRpm).length&&h.warnings.push(`Requested spindle speeds are capped to ${e.machine.maxRpm} RPM by the selected machine profile.`),h.warnings.push("Verify work-offset placement within the actual travel limits. Profile checks compare travel spans, not measured machine position."),h.operations.forEach((T,M)=>T.id=`${String(M+1).padStart(2,"0")}-${T.side}-${T.kind}`),h}function Gt(s){return s.reduce((e,l,a)=>e+ut(l,s[(a+1)%s.length]),0)}function pe(s){return s.reduce((e,l,a)=>{const u=s[(a+1)%s.length];return e+l.x*u.y-u.x*l.y},0)/2}function sr(s,e,l,a,u=l.cutout.tabs){const h=Gt(s),c=(l.cutout.tabWidth+a)/2,p=Array.from({length:u},(_,g)=>h*(g+.5)/u),m=p.flatMap(_=>[_-c,_+c]),x=Math.max(e,-l.thickness+l.cutout.tabHeight),C=_=>p.some(g=>Math.abs(_-g)<c)?x:e,v=[{...s[0],z:C(0)}];let I=0;for(let _=0;_<s.length;_++){const g=s[_],L=s[(_+1)%s.length],N=ut(g,L);if(N){for(const Y of m.filter(O=>O>I&&O<=I+N)){const O={x:g.x+(L.x-g.x)*(Y-I)/N,y:g.y+(L.y-g.y)*(Y-I)/N};v.push({...O,z:C(Y-1e-6)},{...O,z:C(Y+1e-6)})}I+=N,v.push({...L,z:C(I+1e-6)})}}return v}function or(s,e,l,a){const u=e.outline.map(p=>p.map(m=>fe(m,a,l))),h=[];let c={x:0,y:0,z:l.toolChangeZ,rapid:!0,feed:l.machine.rapidFeed};for(const p of s){if(p.rapid&&ut(c,p)>1e-5){const m=hi(c,p,u)?l.safeZ:l.travelZ,x=Math.max(c.z,p.z,m);c.z!==x&&h.push({...c,z:x,rapid:!0,feed:l.machine.rapidFeed}),h.push({...p,z:x,rapid:!0,feed:l.machine.rapidFeed}),p.z!==x&&h.push({...p})}else h.push(p);c=p}return h.length&&h.push({...h.at(-1),z:l.toolChangeZ,rapid:!0,feed:l.machine.rapidFeed}),h}self.onmessage=s=>{try{const{board:e,settings:l,tools:a,materials:u,id:h}=s.data,c=qe((m,x)=>self.postMessage({id:h,progress:m,detail:x})),p=rr(e,l,a,u,c);self.postMessage({id:h,progress:1,job:p})}catch(e){self.postMessage({id:s.data.id,job:{operations:[],errors:[e instanceof Error?e.message:"Toolpath generation failed."],warnings:[]}})}}})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.