(()=>{var Di=Object.create;var Pe=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var Fi=Object.getOwnPropertyNames;var Ri=Object.getPrototypeOf,Wi=Object.prototype.hasOwnProperty;var Yt=(n,o)=>()=>(n&&(o=n(n=0)),o);var Zi=(n,o)=>()=>(o||n((o={exports:{}}).exports,o),o.exports);var Gi=(n,o,a,h)=>{if(o&&typeof o=="object"||typeof o=="function")for(let u of Fi(o))!Wi.call(n,u)&&u!==a&&Pe(n,u,{get:()=>o[u],enumerable:!(h=Bi(o,u))||h.enumerable});return n};var xe=(n,o,a)=>(a=n!=null?Di(Ri(n)):{},Gi(o||!n||!n.__esModule?Pe(a,"default",{value:n,enumerable:!0}):a,n));function b(n,o){return be+n+(o?ge+JSON.stringify(o):"")+ve}function qt(n){let o=[],a=0;for(;a<n.length;){let h=n.indexOf(be,a);if(h<0){o.push(n.slice(a));break}h>a&&o.push(n.slice(a,h));let u=n.indexOf(ve,h),p=n.slice(h+1,u<0?n.length:u),y=p.indexOf(ge);if(y<0)o.push({de:p});else{let x=JSON.parse(p.slice(y+1)),c={};for(let[P,v]of Object.entries(x))c[P]=typeof v=="number"?v:qt(String(v));o.push({de:p.slice(0,y),values:c})}a=u<0?n.length:u+1}return o}var be,ge,ve,Dt,vt=Yt(()=>{"use strict";be="",ge="",ve="";Dt="en-US"});var ee=Zi((Gr,Zt)=>{(function(){"use strict";var n={};n.version="6.4.2.2",n.use_lines=!0,n.use_xyz=!1;var o=!1;typeof Zt<"u"&&Zt.exports?(Zt.exports=n,o=!0):(typeof define=="function"&&define.amd&&define(n),typeof document<"u"?window.ClipperLib=n:self.ClipperLib=n);var a;if(o){var h="chrome";a="Netscape"}else{var h=navigator.userAgent.toString().toLowerCase();a=navigator.appName}var u={};h.indexOf("chrome")!=-1&&h.indexOf("chromium")==-1?u.chrome=1:u.chrome=0,h.indexOf("chromium")!=-1?u.chromium=1:u.chromium=0,h.indexOf("safari")!=-1&&h.indexOf("chrome")==-1&&h.indexOf("chromium")==-1?u.safari=1:u.safari=0,h.indexOf("firefox")!=-1?u.firefox=1:u.firefox=0,h.indexOf("firefox/17")!=-1?u.firefox17=1:u.firefox17=0,h.indexOf("firefox/15")!=-1?u.firefox15=1:u.firefox15=0,h.indexOf("firefox/3")!=-1?u.firefox3=1:u.firefox3=0,h.indexOf("opera")!=-1?u.opera=1:u.opera=0,h.indexOf("msie 10")!=-1?u.msie10=1:u.msie10=0,h.indexOf("msie 9")!=-1?u.msie9=1:u.msie9=0,h.indexOf("msie 8")!=-1?u.msie8=1:u.msie8=0,h.indexOf("msie 7")!=-1?u.msie7=1:u.msie7=0,h.indexOf("msie ")!=-1?u.msie=1:u.msie=0,n.biginteger_used=null;var p,y=0xdeadbeefcafe,x=(y&16777215)==15715070;function c(t,e,i){n.biginteger_used=1,t!=null&&(typeof t=="number"&&typeof e>"u"?this.fromInt(t):typeof t=="number"?this.fromNumber(t,e,i):e==null&&typeof t!="string"?this.fromString(t,256):this.fromString(t,e))}function P(){return new c(null,void 0,void 0)}function v(t,e,i,r,s,l){for(;--l>=0;){var f=e*this[t++]+i[r]+s;s=Math.floor(f/67108864),i[r++]=f&67108863}return s}function w(t,e,i,r,s,l){for(var f=e&32767,m=e>>15;--l>=0;){var d=this[t]&32767,g=this[t++]>>15,I=m*d+g*f;d=f*d+((I&32767)<<15)+i[r]+(s&1073741823),s=(d>>>30)+(I>>>15)+m*g+(s>>>30),i[r++]=d&1073741823}return s}function A(t,e,i,r,s,l){for(var f=e&16383,m=e>>14;--l>=0;){var d=this[t]&16383,g=this[t++]>>14,I=m*d+g*f;d=f*d+((I&16383)<<14)+i[r]+s,s=(d>>28)+(I>>14)+m*g,i[r++]=d&268435455}return s}x&&a=="Microsoft Internet Explorer"?(c.prototype.am=w,p=30):x&&a!="Netscape"?(c.prototype.am=v,p=26):(c.prototype.am=A,p=28),c.prototype.DB=p,c.prototype.DM=(1<<p)-1,c.prototype.DV=1<<p;var T=52;c.prototype.FV=Math.pow(2,T),c.prototype.F1=T-p,c.prototype.F2=2*p-T;var _="0123456789abcdefghijklmnopqrstuvwxyz",S=new Array,X,k;for(X=48,k=0;k<=9;++k)S[X++]=k;for(X=97,k=10;k<36;++k)S[X++]=k;for(X=65,k=10;k<36;++k)S[X++]=k;function j(t){return _.charAt(t)}function Y(t,e){var i=S[t.charCodeAt(e)];return i??-1}function K(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}function Z(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 D(t){var e=P();return e.fromInt(t),e}function $(t,e){var i;if(e==16)i=4;else if(e==8)i=3;else if(e==256)i=8;else if(e==2)i=1;else if(e==32)i=5;else if(e==4)i=2;else{this.fromRadix(t,e);return}this.t=0,this.s=0;for(var r=t.length,s=!1,l=0;--r>=0;){var f=i==8?t[r]&255:Y(t,r);if(f<0){t.charAt(r)=="-"&&(s=!0);continue}s=!1,l==0?this[this.t++]=f:l+i>this.DB?(this[this.t-1]|=(f&(1<<this.DB-l)-1)<<l,this[this.t++]=f>>this.DB-l):this[this.t-1]|=f<<l,l+=i,l>=this.DB&&(l-=this.DB)}i==8&&t[0]&128&&(this.s=-1,l>0&&(this[this.t-1]|=(1<<this.DB-l)-1<<l)),this.clamp(),s&&c.ZERO.subTo(this,this)}function H(){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 e;if(t==16)e=4;else if(t==8)e=3;else if(t==2)e=1;else if(t==32)e=5;else if(t==4)e=2;else return this.toRadix(t);var i=(1<<e)-1,r,s=!1,l="",f=this.t,m=this.DB-f*this.DB%e;if(f-- >0)for(m<this.DB&&(r=this[f]>>m)>0&&(s=!0,l=j(r));f>=0;)m<e?(r=(this[f]&(1<<m)-1)<<e-m,r|=this[--f]>>(m+=this.DB-e)):(r=this[f]>>(m-=e)&i,m<=0&&(m+=this.DB,--f)),r>0&&(s=!0),s&&(l+=j(r));return s?l:"0"}function R(){var t=P();return c.ZERO.subTo(this,t),t}function V(){return this.s<0?this.negate():this}function E(t){var e=this.s-t.s;if(e!=0)return e;var i=this.t;if(e=i-t.t,e!=0)return this.s<0?-e:e;for(;--i>=0;)if((e=this[i]-t[i])!=0)return e;return 0}function z(t){var e=1,i;return(i=t>>>16)!=0&&(t=i,e+=16),(i=t>>8)!=0&&(t=i,e+=8),(i=t>>4)!=0&&(t=i,e+=4),(i=t>>2)!=0&&(t=i,e+=2),(i=t>>1)!=0&&(t=i,e+=1),e}function rt(){return this.t<=0?0:this.DB*(this.t-1)+z(this[this.t-1]^this.s&this.DM)}function lt(t,e){var i;for(i=this.t-1;i>=0;--i)e[i+t]=this[i];for(i=t-1;i>=0;--i)e[i]=0;e.t=this.t+t,e.s=this.s}function L(t,e){for(var i=t;i<this.t;++i)e[i-t]=this[i];e.t=Math.max(this.t-t,0),e.s=this.s}function M(t,e){var i=t%this.DB,r=this.DB-i,s=(1<<r)-1,l=Math.floor(t/this.DB),f=this.s<<i&this.DM,m;for(m=this.t-1;m>=0;--m)e[m+l+1]=this[m]>>r|f,f=(this[m]&s)<<i;for(m=l-1;m>=0;--m)e[m]=0;e[l]=f,e.t=this.t+l+1,e.s=this.s,e.clamp()}function U(t,e){e.s=this.s;var i=Math.floor(t/this.DB);if(i>=this.t){e.t=0;return}var r=t%this.DB,s=this.DB-r,l=(1<<r)-1;e[0]=this[i]>>r;for(var f=i+1;f<this.t;++f)e[f-i-1]|=(this[f]&l)<<s,e[f-i]=this[f]>>r;r>0&&(e[this.t-i-1]|=(this.s&l)<<s),e.t=this.t-i,e.clamp()}function q(t,e){for(var i=0,r=0,s=Math.min(t.t,this.t);i<s;)r+=this[i]-t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r-=t[i],e[i++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[i++]=this.DV+r:r>0&&(e[i++]=r),e.t=i,e.clamp()}function G(t,e){var i=this.abs(),r=t.abs(),s=i.t;for(e.t=s+r.t;--s>=0;)e[s]=0;for(s=0;s<r.t;++s)e[s+i.t]=i.am(0,r[s],e,s,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&c.ZERO.subTo(e,e)}function tt(t){for(var e=this.abs(),i=t.t=2*e.t;--i>=0;)t[i]=0;for(i=0;i<e.t-1;++i){var r=e.am(i,e[i],t,2*i,0,1);(t[i+e.t]+=e.am(i+1,2*e[i],t,2*i+1,r,e.t-i-1))>=e.DV&&(t[i+e.t]-=e.DV,t[i+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(i,e[i],t,2*i,0,1)),t.s=0,t.clamp()}function mt(t,e,i){var r=t.abs();if(!(r.t<=0)){var s=this.abs();if(s.t<r.t){e?.fromInt(0),i!=null&&this.copyTo(i);return}i==null&&(i=P());var l=P(),f=this.s,m=t.s,d=this.DB-z(r[r.t-1]);d>0?(r.lShiftTo(d,l),s.lShiftTo(d,i)):(r.copyTo(l),s.copyTo(i));var g=l.t,I=l[g-1];if(I!=0){var C=I*(1<<this.F1)+(g>1?l[g-2]>>this.F2:0),N=this.FV/C,O=(1<<this.F1)/C,F=1<<this.F2,W=i.t,J=W-g,st=e??P();for(l.dlShiftTo(J,st),i.compareTo(st)>=0&&(i[i.t++]=1,i.subTo(st,i)),c.ONE.dlShiftTo(g,st),st.subTo(l,l);l.t<g;)l[l.t++]=0;for(;--J>=0;){var ht=i[--W]==I?this.DM:Math.floor(i[W]*N+(i[W-1]+F)*O);if((i[W]+=l.am(0,ht,i,J,0,g))<ht)for(l.dlShiftTo(J,st),i.subTo(st,i);i[W]<--ht;)i.subTo(st,i)}e!=null&&(i.drShiftTo(g,e),f!=m&&c.ZERO.subTo(e,e)),i.t=g,i.clamp(),d>0&&i.rShiftTo(d,i),f<0&&c.ZERO.subTo(i,i)}}}function pn(t){var e=P();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(c.ZERO)>0&&t.subTo(e,e),e}function bt(t){this.m=t}function cn(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function mn(t){return t}function dn(t){t.divRemTo(this.m,null,t)}function yn(t,e,i){t.multiplyTo(e,i),this.reduce(i)}function Pn(t,e){t.squareTo(e),this.reduce(e)}bt.prototype.convert=cn,bt.prototype.revert=mn,bt.prototype.reduce=dn,bt.prototype.mulTo=yn,bt.prototype.sqrTo=Pn;function xn(){if(this.t<1)return 0;var t=this[0];if(!(t&1))return 0;var e=t&3;return e=e*(2-(t&15)*e)&15,e=e*(2-(t&255)*e)&255,e=e*(2-((t&65535)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e}function gt(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 bn(t){var e=P();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(c.ZERO)>0&&this.m.subTo(e,e),e}function gn(t){var e=P();return t.copyTo(e),this.reduce(e),e}function vn(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var i=t[e]&32767,r=i*this.mpl+((i*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(i=e+this.m.t,t[i]+=this.m.am(0,r,t,e,0,this.m.t);t[i]>=t.DV;)t[i]-=t.DV,t[++i]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function Cn(t,e){t.squareTo(e),this.reduce(e)}function In(t,e,i){t.multiplyTo(e,i),this.reduce(i)}gt.prototype.convert=bn,gt.prototype.revert=gn,gt.prototype.reduce=vn,gt.prototype.mulTo=In,gt.prototype.sqrTo=Cn;function wn(){return(this.t>0?this[0]&1:this.s)==0}function _n(t,e){if(t>4294967295||t<1)return c.ONE;var i=P(),r=P(),s=e.convert(this),l=z(t)-1;for(s.copyTo(i);--l>=0;)if(e.sqrTo(i,r),(t&1<<l)>0)e.mulTo(r,s,i);else{var f=i;i=r,r=f}return e.revert(i)}function Tn(t,e){var i;return t<256||e.isEven()?i=new bt(e):i=new gt(e),this.exp(t,i)}c.prototype.copyTo=K,c.prototype.fromInt=Z,c.prototype.fromString=$,c.prototype.clamp=H,c.prototype.dlShiftTo=lt,c.prototype.drShiftTo=L,c.prototype.lShiftTo=M,c.prototype.rShiftTo=U,c.prototype.subTo=q,c.prototype.multiplyTo=G,c.prototype.squareTo=tt,c.prototype.divRemTo=mt,c.prototype.invDigit=xn,c.prototype.isEven=wn,c.prototype.exp=_n,c.prototype.toString=Q,c.prototype.negate=R,c.prototype.abs=V,c.prototype.compareTo=E,c.prototype.bitLength=rt,c.prototype.mod=pn,c.prototype.modPowInt=Tn,c.ZERO=D(0),c.ONE=D(1);function Sn(){var t=P();return this.copyTo(t),t}function Nn(){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 An(){return this.t==0?this.s:this[0]<<24>>24}function Ln(){return this.t==0?this.s:this[0]<<16>>16}function Xn(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function Mn(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function kn(t){if(t==null&&(t=10),this.signum()==0||t<2||t>36)return"0";var e=this.chunkSize(t),i=Math.pow(t,e),r=D(i),s=P(),l=P(),f="";for(this.divRemTo(r,s,l);s.signum()>0;)f=(i+l.intValue()).toString(t).substr(1)+f,s.divRemTo(r,s,l);return l.intValue().toString(t)+f}function On(t,e){this.fromInt(0),e==null&&(e=10);for(var i=this.chunkSize(e),r=Math.pow(e,i),s=!1,l=0,f=0,m=0;m<t.length;++m){var d=Y(t,m);if(d<0){t.charAt(m)=="-"&&this.signum()==0&&(s=!0);continue}f=e*f+d,++l>=i&&(this.dMultiply(r),this.dAddOffset(f,0),l=0,f=0)}l>0&&(this.dMultiply(Math.pow(e,l)),this.dAddOffset(f,0)),s&&c.ZERO.subTo(this,this)}function En(t,e,i){if(typeof e=="number")if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(c.ONE.shiftLeft(t-1),Ut,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(c.ONE.shiftLeft(t-1),this);else{var r=new Array,s=t&7;r.length=(t>>3)+1,e.nextBytes(r),s>0?r[0]&=(1<<s)-1:r[0]=0,this.fromString(r,256)}}function Yn(){var t=this.t,e=new Array;e[0]=this.s;var i=this.DB-t*this.DB%8,r,s=0;if(t-- >0)for(i<this.DB&&(r=this[t]>>i)!=(this.s&this.DM)>>i&&(e[s++]=r|this.s<<this.DB-i);t>=0;)i<8?(r=(this[t]&(1<<i)-1)<<8-i,r|=this[--t]>>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),r&128&&(r|=-256),s==0&&(this.s&128)!=(r&128)&&++s,(s>0||r!=this.s)&&(e[s++]=r);return e}function Dn(t){return this.compareTo(t)==0}function Bn(t){return this.compareTo(t)<0?this:t}function Fn(t){return this.compareTo(t)>0?this:t}function Rn(t,e,i){var r,s,l=Math.min(t.t,this.t);for(r=0;r<l;++r)i[r]=e(this[r],t[r]);if(t.t<this.t){for(s=t.s&this.DM,r=l;r<this.t;++r)i[r]=e(this[r],s);i.t=this.t}else{for(s=this.s&this.DM,r=l;r<t.t;++r)i[r]=e(s,t[r]);i.t=t.t}i.s=e(this.s,t.s),i.clamp()}function Wn(t,e){return t&e}function Zn(t){var e=P();return this.bitwiseTo(t,Wn,e),e}function Ut(t,e){return t|e}function Gn(t){var e=P();return this.bitwiseTo(t,Ut,e),e}function ce(t,e){return t^e}function Vn(t){var e=P();return this.bitwiseTo(t,ce,e),e}function me(t,e){return t&~e}function zn(t){var e=P();return this.bitwiseTo(t,me,e),e}function Un(){for(var t=P(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}function qn(t){var e=P();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function Hn(t){var e=P();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function Jn(t){if(t==0)return-1;var e=0;return t&65535||(t>>=16,e+=16),t&255||(t>>=8,e+=8),t&15||(t>>=4,e+=4),t&3||(t>>=2,e+=2),t&1||++e,e}function jn(){for(var t=0;t<this.t;++t)if(this[t]!=0)return t*this.DB+Jn(this[t]);return this.s<0?this.t*this.DB:-1}function Kn(t){for(var e=0;t!=0;)t&=t-1,++e;return e}function $n(){for(var t=0,e=this.s&this.DM,i=0;i<this.t;++i)t+=Kn(this[i]^e);return t}function Qn(t){var e=Math.floor(t/this.DB);return e>=this.t?this.s!=0:(this[e]&1<<t%this.DB)!=0}function ti(t,e){var i=c.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i}function ei(t){return this.changeBit(t,Ut)}function ni(t){return this.changeBit(t,me)}function ii(t){return this.changeBit(t,ce)}function ri(t,e){for(var i=0,r=0,s=Math.min(t.t,this.t);i<s;)r+=this[i]+t[i],e[i++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;i<this.t;)r+=this[i],e[i++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;i<t.t;)r+=t[i],e[i++]=r&this.DM,r>>=this.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[i++]=r:r<-1&&(e[i++]=this.DV+r),e.t=i,e.clamp()}function si(t){var e=P();return this.addTo(t,e),e}function oi(t){var e=P();return this.subTo(t,e),e}function li(t){var e=P();return this.multiplyTo(t,e),e}function ai(){var t=P();return this.squareTo(t),t}function ui(t){var e=P();return this.divRemTo(t,e,null),e}function fi(t){var e=P();return this.divRemTo(t,null,e),e}function hi(t){var e=P(),i=P();return this.divRemTo(t,e,i),new Array(e,i)}function pi(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function ci(t,e){if(t!=0){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}function At(){}function de(t){return t}function mi(t,e,i){t.multiplyTo(e,i)}function di(t,e){t.squareTo(e)}At.prototype.convert=de,At.prototype.revert=de,At.prototype.mulTo=mi,At.prototype.sqrTo=di;function yi(t){return this.exp(t,new At)}function Pi(t,e,i){var r=Math.min(this.t+t.t,e);for(i.s=0,i.t=r;r>0;)i[--r]=0;var s;for(s=i.t-this.t;r<s;++r)i[r+this.t]=this.am(0,t[r],i,r,0,this.t);for(s=Math.min(t.t,e);r<s;++r)this.am(0,t[r],i,r,0,e-r);i.clamp()}function xi(t,e,i){--e;var r=i.t=this.t+t.t-e;for(i.s=0;--r>=0;)i[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)i[this.t+r-e]=this.am(e-r,t[r],i,0,0,this.t+r-e);i.clamp(),i.drShiftTo(1,i)}function wt(t){this.r2=P(),this.q3=P(),c.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function bi(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 e=P();return t.copyTo(e),this.reduce(e),e}function gi(t){return t}function vi(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 Ci(t,e){t.squareTo(e),this.reduce(e)}function Ii(t,e,i){t.multiplyTo(e,i),this.reduce(i)}wt.prototype.convert=bi,wt.prototype.revert=gi,wt.prototype.reduce=vi,wt.prototype.mulTo=Ii,wt.prototype.sqrTo=Ci;function wi(t,e){var i=t.bitLength(),r,s=D(1),l;if(i<=0)return s;i<18?r=1:i<48?r=3:i<144?r=4:i<768?r=5:r=6,i<8?l=new bt(e):e.isEven()?l=new wt(e):l=new gt(e);var f=new Array,m=3,d=r-1,g=(1<<r)-1;if(f[1]=l.convert(this),r>1){var I=P();for(l.sqrTo(f[1],I);m<=g;)f[m]=P(),l.mulTo(I,f[m-2],f[m]),m+=2}var C=t.t-1,N,O=!0,F=P(),W;for(i=z(t[C])-1;C>=0;){for(i>=d?N=t[C]>>i-d&g:(N=(t[C]&(1<<i+1)-1)<<d-i,C>0&&(N|=t[C-1]>>this.DB+i-d)),m=r;!(N&1);)N>>=1,--m;if((i-=m)<0&&(i+=this.DB,--C),O)f[N].copyTo(s),O=!1;else{for(;m>1;)l.sqrTo(s,F),l.sqrTo(F,s),m-=2;m>0?l.sqrTo(s,F):(W=s,s=F,F=W),l.mulTo(F,f[N],s)}for(;C>=0&&!(t[C]&1<<i);)l.sqrTo(s,F),W=s,s=F,F=W,--i<0&&(i=this.DB-1,--C)}return l.revert(s)}function _i(t){var e=this.s<0?this.negate():this.clone(),i=t.s<0?t.negate():t.clone();if(e.compareTo(i)<0){var r=e;e=i,i=r}var s=e.getLowestSetBit(),l=i.getLowestSetBit();if(l<0)return e;for(s<l&&(l=s),l>0&&(e.rShiftTo(l,e),i.rShiftTo(l,i));e.signum()>0;)(s=e.getLowestSetBit())>0&&e.rShiftTo(s,e),(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),e.compareTo(i)>=0?(e.subTo(i,e),e.rShiftTo(1,e)):(i.subTo(e,i),i.rShiftTo(1,i));return l>0&&i.lShiftTo(l,i),i}function Ti(t){if(t<=0)return 0;var e=this.DV%t,i=this.s<0?t-1:0;if(this.t>0)if(e==0)i=this[0]%t;else for(var r=this.t-1;r>=0;--r)i=(e*i+this[r])%t;return i}function Si(t){var e=t.isEven();if(this.isEven()&&e||t.signum()==0)return c.ZERO;for(var i=t.clone(),r=this.clone(),s=D(1),l=D(0),f=D(0),m=D(1);i.signum()!=0;){for(;i.isEven();)i.rShiftTo(1,i),e?((!s.isEven()||!l.isEven())&&(s.addTo(this,s),l.subTo(t,l)),s.rShiftTo(1,s)):l.isEven()||l.subTo(t,l),l.rShiftTo(1,l);for(;r.isEven();)r.rShiftTo(1,r),e?((!f.isEven()||!m.isEven())&&(f.addTo(this,f),m.subTo(t,m)),f.rShiftTo(1,f)):m.isEven()||m.subTo(t,m),m.rShiftTo(1,m);i.compareTo(r)>=0?(i.subTo(r,i),e&&s.subTo(f,s),l.subTo(m,l)):(r.subTo(i,r),e&&f.subTo(s,f),m.subTo(l,m))}if(r.compareTo(c.ONE)!=0)return c.ZERO;if(m.compareTo(t)>=0)return m.subtract(t);if(m.signum()<0)m.addTo(t,m);else return m;return m.signum()<0?m.add(t):m}var nt=[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],Ni=(1<<26)/nt[nt.length-1];function Ai(t){var e,i=this.abs();if(i.t==1&&i[0]<=nt[nt.length-1]){for(e=0;e<nt.length;++e)if(i[0]==nt[e])return!0;return!1}if(i.isEven())return!1;for(e=1;e<nt.length;){for(var r=nt[e],s=e+1;s<nt.length&&r<Ni;)r*=nt[s++];for(r=i.modInt(r);e<s;)if(r%nt[e++]==0)return!1}return i.millerRabin(t)}function Li(t){var e=this.subtract(c.ONE),i=e.getLowestSetBit();if(i<=0)return!1;var r=e.shiftRight(i);t=t+1>>1,t>nt.length&&(t=nt.length);for(var s=P(),l=0;l<t;++l){s.fromInt(nt[Math.floor(Math.random()*nt.length)]);var f=s.modPow(r,this);if(f.compareTo(c.ONE)!=0&&f.compareTo(e)!=0){for(var m=1;m++<i&&f.compareTo(e)!=0;)if(f=f.modPowInt(2,this),f.compareTo(c.ONE)==0)return!1;if(f.compareTo(e)!=0)return!1}}return!0}c.prototype.chunkSize=Xn,c.prototype.toRadix=kn,c.prototype.fromRadix=On,c.prototype.fromNumber=En,c.prototype.bitwiseTo=Rn,c.prototype.changeBit=ti,c.prototype.addTo=ri,c.prototype.dMultiply=pi,c.prototype.dAddOffset=ci,c.prototype.multiplyLowerTo=Pi,c.prototype.multiplyUpperTo=xi,c.prototype.modInt=Ti,c.prototype.millerRabin=Li,c.prototype.clone=Sn,c.prototype.intValue=Nn,c.prototype.byteValue=An,c.prototype.shortValue=Ln,c.prototype.signum=Mn,c.prototype.toByteArray=Yn,c.prototype.equals=Dn,c.prototype.min=Bn,c.prototype.max=Fn,c.prototype.and=Zn,c.prototype.or=Gn,c.prototype.xor=Vn,c.prototype.andNot=zn,c.prototype.not=Un,c.prototype.shiftLeft=qn,c.prototype.shiftRight=Hn,c.prototype.getLowestSetBit=jn,c.prototype.bitCount=$n,c.prototype.testBit=Qn,c.prototype.setBit=ei,c.prototype.clearBit=ni,c.prototype.flipBit=ii,c.prototype.add=si,c.prototype.subtract=oi,c.prototype.multiply=li,c.prototype.divide=ui,c.prototype.remainder=fi,c.prototype.divideAndRemainder=hi,c.prototype.modPow=wi,c.prototype.modInverse=Si,c.prototype.pow=yi,c.prototype.gcd=_i,c.prototype.isProbablePrime=Ai,c.prototype.square=ai;var B=c;B.prototype.IsNegative=function(){return this.compareTo(B.ZERO)==-1},B.op_Equality=function(t,e){return t.compareTo(e)==0},B.op_Inequality=function(t,e){return t.compareTo(e)!=0},B.op_GreaterThan=function(t,e){return t.compareTo(e)>0},B.op_LessThan=function(t,e){return t.compareTo(e)<0},B.op_Addition=function(t,e){return new B(t,void 0,void 0).add(new B(e,void 0,void 0))},B.op_Subtraction=function(t,e){return new B(t,void 0,void 0).subtract(new B(e,void 0,void 0))},B.Int128Mul=function(t,e){return new B(t,void 0,void 0).multiply(new B(e,void 0,void 0))},B.op_Division=function(t,e){return t.divide(e)},B.prototype.ToDouble=function(){return parseFloat(this.toString())};var ye=function(t,e){var i;if(typeof Object.getOwnPropertyNames>"u"){for(i in e.prototype)(typeof t.prototype[i]>"u"||t.prototype[i]===Object.prototype[i])&&(t.prototype[i]=e.prototype[i]);for(i in e)typeof t[i]>"u"&&(t[i]=e[i]);t.$baseCtor=e}else{for(var r=Object.getOwnPropertyNames(e.prototype),s=0;s<r.length;s++)typeof Object.getOwnPropertyDescriptor(t.prototype,r[s])>"u"&&Object.defineProperty(t.prototype,r[s],Object.getOwnPropertyDescriptor(e.prototype,r[s]));for(i in e)typeof t[i]>"u"&&(t[i]=e[i]);t.$baseCtor=e}};n.Path=function(){return[]},n.Path.prototype.push=Array.prototype.push,n.Paths=function(){return[]},n.Paths.prototype.push=Array.prototype.push,n.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])},n.DoublePoint0=function(){this.X=0,this.Y=0},n.DoublePoint0.prototype=n.DoublePoint.prototype,n.DoublePoint1=function(t){this.X=t.X,this.Y=t.Y},n.DoublePoint1.prototype=n.DoublePoint.prototype,n.DoublePoint2=function(t,e){this.X=t,this.Y=e},n.DoublePoint2.prototype=n.DoublePoint.prototype,n.PolyNode=function(){this.m_Parent=null,this.m_polygon=new n.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},n.PolyNode.prototype.IsHoleNode=function(){for(var t=!0,e=this.m_Parent;e!==null;)t=!t,e=e.m_Parent;return t},n.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},n.PolyNode.prototype.Contour=function(){return this.m_polygon},n.PolyNode.prototype.AddChild=function(t){var e=this.m_Childs.length;this.m_Childs.push(t),t.m_Parent=this,t.m_Index=e},n.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},n.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]},n.PolyNode.prototype.Childs=function(){return this.m_Childs},n.PolyNode.prototype.Parent=function(){return this.m_Parent},n.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},n.PolyTree=function(){this.m_AllPolys=[],n.PolyNode.call(this)},n.PolyTree.prototype.Clear=function(){for(var t=0,e=this.m_AllPolys.length;t<e;t++)this.m_AllPolys[t]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},n.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},n.PolyTree.prototype.Total=function(){var t=this.m_AllPolys.length;return t>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&t--,t},ye(n.PolyTree,n.PolyNode),n.Math_Abs_Int64=n.Math_Abs_Int32=n.Math_Abs_Double=function(t){return Math.abs(t)},n.Math_Max_Int32_Int32=function(t,e){return Math.max(t,e)},u.msie||u.opera||u.safari?n.Cast_Int32=function(t){return t|0}:n.Cast_Int32=function(t){return~~t},typeof Number.toInteger>"u"&&(Number.toInteger=null),u.chrome?n.Cast_Int64=function(t){return t<-2147483648||t>2147483647?t<0?Math.ceil(t):Math.floor(t):~~t}:u.firefox&&typeof Number.toInteger=="function"?n.Cast_Int64=function(t){return Number.toInteger(t)}:u.msie7||u.msie8?n.Cast_Int64=function(t){return parseInt(t,10)}:u.msie?n.Cast_Int64=function(t){return t<-2147483648||t>2147483647?t<0?Math.ceil(t):Math.floor(t):t|0}:n.Cast_Int64=function(t){return t<0?Math.ceil(t):Math.floor(t)},n.Clear=function(t){t.length=0},n.PI=3.141592653589793,n.PI2=2*3.141592653589793,n.IntPoint=function(){var t=arguments,e=t.length;if(this.X=0,this.Y=0,n.use_xyz)if(this.Z=0,e===3)this.X=t[0],this.Y=t[1],this.Z=t[2];else if(e===2)this.X=t[0],this.Y=t[1],this.Z=0;else if(e===1)if(t[0]instanceof n.DoublePoint){var i=t[0];this.X=n.Clipper.Round(i.X),this.Y=n.Clipper.Round(i.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(e===2)this.X=t[0],this.Y=t[1];else if(e===1)if(t[0]instanceof n.DoublePoint){var i=t[0];this.X=n.Clipper.Round(i.X),this.Y=n.Clipper.Round(i.Y)}else{var r=t[0];this.X=r.X,this.Y=r.Y}else this.X=0,this.Y=0},n.IntPoint.op_Equality=function(t,e){return t.X===e.X&&t.Y===e.Y},n.IntPoint.op_Inequality=function(t,e){return t.X!==e.X||t.Y!==e.Y},n.IntPoint0=function(){this.X=0,this.Y=0,n.use_xyz&&(this.Z=0)},n.IntPoint0.prototype=n.IntPoint.prototype,n.IntPoint1=function(t){this.X=t.X,this.Y=t.Y,n.use_xyz&&(typeof t.Z>"u"?this.Z=0:this.Z=t.Z)},n.IntPoint1.prototype=n.IntPoint.prototype,n.IntPoint1dp=function(t){this.X=n.Clipper.Round(t.X),this.Y=n.Clipper.Round(t.Y),n.use_xyz&&(this.Z=0)},n.IntPoint1dp.prototype=n.IntPoint.prototype,n.IntPoint2=function(t,e,i){this.X=t,this.Y=e,n.use_xyz&&(typeof i>"u"?this.Z=0:this.Z=i)},n.IntPoint2.prototype=n.IntPoint.prototype,n.IntRect=function(){var t=arguments,e=t.length;if(e===4)this.left=t[0],this.top=t[1],this.right=t[2],this.bottom=t[3];else if(e===1){var i=t[0];this.left=i.left,this.top=i.top,this.right=i.right,this.bottom=i.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},n.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},n.IntRect0.prototype=n.IntRect.prototype,n.IntRect1=function(t){this.left=t.left,this.top=t.top,this.right=t.right,this.bottom=t.bottom},n.IntRect1.prototype=n.IntRect.prototype,n.IntRect4=function(t,e,i,r){this.left=t,this.top=e,this.right=i,this.bottom=r},n.IntRect4.prototype=n.IntRect.prototype,n.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},n.PolyType={ptSubject:0,ptClip:1},n.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},n.JoinType={jtSquare:0,jtRound:1,jtMiter:2},n.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},n.EdgeSide={esLeft:0,esRight:1},n.Direction={dRightToLeft:0,dLeftToRight:1},n.TEdge=function(){this.Bot=new n.IntPoint0,this.Curr=new n.IntPoint0,this.Top=new n.IntPoint0,this.Delta=new n.IntPoint0,this.Dx=0,this.PolyTyp=n.PolyType.ptSubject,this.Side=n.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},n.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new n.IntPoint0},n.MyIntersectNodeSort=function(){},n.MyIntersectNodeSort.Compare=function(t,e){var i=e.Pt.Y-t.Pt.Y;return i>0?1:i<0?-1:0},n.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},n.Scanbeam=function(){this.Y=0,this.Next=null},n.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},n.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},n.OutPt=function(){this.Idx=0,this.Pt=new n.IntPoint0,this.Next=null,this.Prev=null},n.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new n.IntPoint0},n.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},n.ClipperBase.horizontal=-9007199254740992,n.ClipperBase.Skip=-2,n.ClipperBase.Unassigned=-1,n.ClipperBase.tolerance=1e-20,n.ClipperBase.loRange=47453132,n.ClipperBase.hiRange=0xfffffffffffff,n.ClipperBase.near_zero=function(t){return t>-n.ClipperBase.tolerance&&t<n.ClipperBase.tolerance},n.ClipperBase.IsHorizontal=function(t){return t.Delta.Y===0},n.ClipperBase.prototype.PointIsVertex=function(t,e){var i=e;do{if(n.IntPoint.op_Equality(i.Pt,t))return!0;i=i.Next}while(i!==e);return!1},n.ClipperBase.prototype.PointOnLineSegment=function(t,e,i,r){return r?t.X===e.X&&t.Y===e.Y||t.X===i.X&&t.Y===i.Y||t.X>e.X==t.X<i.X&&t.Y>e.Y==t.Y<i.Y&&B.op_Equality(B.Int128Mul(t.X-e.X,i.Y-e.Y),B.Int128Mul(i.X-e.X,t.Y-e.Y)):t.X===e.X&&t.Y===e.Y||t.X===i.X&&t.Y===i.Y||t.X>e.X==t.X<i.X&&t.Y>e.Y==t.Y<i.Y&&(t.X-e.X)*(i.Y-e.Y)===(i.X-e.X)*(t.Y-e.Y)},n.ClipperBase.prototype.PointOnPolygon=function(t,e,i){for(var r=e;;){if(this.PointOnLineSegment(t,r.Pt,r.Next.Pt,i))return!0;if(r=r.Next,r===e)break}return!1},n.ClipperBase.prototype.SlopesEqual=n.ClipperBase.SlopesEqual=function(){var t=arguments,e=t.length,i,r,s,l,f,m,d;return e===3?(i=t[0],r=t[1],d=t[2],d?B.op_Equality(B.Int128Mul(i.Delta.Y,r.Delta.X),B.Int128Mul(i.Delta.X,r.Delta.Y)):n.Cast_Int64(i.Delta.Y*r.Delta.X)===n.Cast_Int64(i.Delta.X*r.Delta.Y)):e===4?(s=t[0],l=t[1],f=t[2],d=t[3],d?B.op_Equality(B.Int128Mul(s.Y-l.Y,l.X-f.X),B.Int128Mul(s.X-l.X,l.Y-f.Y)):n.Cast_Int64((s.Y-l.Y)*(l.X-f.X))-n.Cast_Int64((s.X-l.X)*(l.Y-f.Y))===0):(s=t[0],l=t[1],f=t[2],m=t[3],d=t[4],d?B.op_Equality(B.Int128Mul(s.Y-l.Y,f.X-m.X),B.Int128Mul(s.X-l.X,f.Y-m.Y)):n.Cast_Int64((s.Y-l.Y)*(f.X-m.X))-n.Cast_Int64((s.X-l.X)*(f.Y-m.Y))===0)},n.ClipperBase.SlopesEqual3=function(t,e,i){return i?B.op_Equality(B.Int128Mul(t.Delta.Y,e.Delta.X),B.Int128Mul(t.Delta.X,e.Delta.Y)):n.Cast_Int64(t.Delta.Y*e.Delta.X)===n.Cast_Int64(t.Delta.X*e.Delta.Y)},n.ClipperBase.SlopesEqual4=function(t,e,i,r){return r?B.op_Equality(B.Int128Mul(t.Y-e.Y,e.X-i.X),B.Int128Mul(t.X-e.X,e.Y-i.Y)):n.Cast_Int64((t.Y-e.Y)*(e.X-i.X))-n.Cast_Int64((t.X-e.X)*(e.Y-i.Y))===0},n.ClipperBase.SlopesEqual5=function(t,e,i,r,s){return s?B.op_Equality(B.Int128Mul(t.Y-e.Y,i.X-r.X),B.Int128Mul(t.X-e.X,i.Y-r.Y)):n.Cast_Int64((t.Y-e.Y)*(i.X-r.X))-n.Cast_Int64((t.X-e.X)*(i.Y-r.Y))===0},n.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var t=0,e=this.m_edges.length;t<e;++t){for(var i=0,r=this.m_edges[t].length;i<r;++i)this.m_edges[t][i]=null;n.Clear(this.m_edges[t])}n.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},n.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},n.ClipperBase.prototype.RangeTest=function(t,e){e.Value?(t.X>n.ClipperBase.hiRange||t.Y>n.ClipperBase.hiRange||-t.X>n.ClipperBase.hiRange||-t.Y>n.ClipperBase.hiRange)&&n.Error("Coordinate outside allowed range in RangeTest()."):(t.X>n.ClipperBase.loRange||t.Y>n.ClipperBase.loRange||-t.X>n.ClipperBase.loRange||-t.Y>n.ClipperBase.loRange)&&(e.Value=!0,this.RangeTest(t,e))},n.ClipperBase.prototype.InitEdge=function(t,e,i,r){t.Next=e,t.Prev=i,t.Curr.X=r.X,t.Curr.Y=r.Y,n.use_xyz&&(t.Curr.Z=r.Z),t.OutIdx=-1},n.ClipperBase.prototype.InitEdge2=function(t,e){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,n.use_xyz&&(t.Bot.Z=t.Curr.Z),t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y,n.use_xyz&&(t.Top.Z=t.Next.Curr.Z)):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,n.use_xyz&&(t.Top.Z=t.Curr.Z),t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y,n.use_xyz&&(t.Bot.Z=t.Next.Curr.Z)),this.SetDx(t),t.PolyTyp=e},n.ClipperBase.prototype.FindNextLocMin=function(t){for(var e;;){for(;n.IntPoint.op_Inequality(t.Bot,t.Prev.Bot)||n.IntPoint.op_Equality(t.Curr,t.Top);)t=t.Next;if(t.Dx!==n.ClipperBase.horizontal&&t.Prev.Dx!==n.ClipperBase.horizontal)break;for(;t.Prev.Dx===n.ClipperBase.horizontal;)t=t.Prev;for(e=t;t.Dx===n.ClipperBase.horizontal;)t=t.Next;if(t.Top.Y!==t.Prev.Bot.Y){e.Prev.Bot.X<t.Bot.X&&(t=e);break}}return t},n.ClipperBase.prototype.ProcessBound=function(t,e){var i,r=t,s;if(r.OutIdx===n.ClipperBase.Skip){if(t=r,e){for(;t.Top.Y===t.Next.Bot.Y;)t=t.Next;for(;t!==r&&t.Dx===n.ClipperBase.horizontal;)t=t.Prev}else{for(;t.Top.Y===t.Prev.Bot.Y;)t=t.Prev;for(;t!==r&&t.Dx===n.ClipperBase.horizontal;)t=t.Next}if(t===r)e?r=t.Next:r=t.Prev;else{e?t=r.Next:t=r.Prev;var l=new n.LocalMinima;l.Next=null,l.Y=t.Bot.Y,l.LeftBound=null,l.RightBound=t,t.WindDelta=0,r=this.ProcessBound(t,e),this.InsertLocalMinima(l)}return r}if(t.Dx===n.ClipperBase.horizontal&&(e?i=t.Prev:i=t.Next,i.Dx===n.ClipperBase.horizontal?i.Bot.X!==t.Bot.X&&i.Top.X!==t.Bot.X&&this.ReverseHorizontal(t):i.Bot.X!==t.Bot.X&&this.ReverseHorizontal(t)),i=t,e){for(;r.Top.Y===r.Next.Bot.Y&&r.Next.OutIdx!==n.ClipperBase.Skip;)r=r.Next;if(r.Dx===n.ClipperBase.horizontal&&r.Next.OutIdx!==n.ClipperBase.Skip){for(s=r;s.Prev.Dx===n.ClipperBase.horizontal;)s=s.Prev;s.Prev.Top.X>r.Next.Top.X&&(r=s.Prev)}for(;t!==r;)t.NextInLML=t.Next,t.Dx===n.ClipperBase.horizontal&&t!==i&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),t=t.Next;t.Dx===n.ClipperBase.horizontal&&t!==i&&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!==n.ClipperBase.Skip;)r=r.Prev;if(r.Dx===n.ClipperBase.horizontal&&r.Prev.OutIdx!==n.ClipperBase.Skip){for(s=r;s.Next.Dx===n.ClipperBase.horizontal;)s=s.Next;(s.Next.Top.X===r.Prev.Top.X||s.Next.Top.X>r.Prev.Top.X)&&(r=s.Next)}for(;t!==r;)t.NextInLML=t.Prev,t.Dx===n.ClipperBase.horizontal&&t!==i&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),t=t.Prev;t.Dx===n.ClipperBase.horizontal&&t!==i&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),r=r.Prev}return r},n.ClipperBase.prototype.AddPath=function(t,e,i){n.use_lines?!i&&e===n.PolyType.ptClip&&n.Error("AddPath: Open paths must be subject."):i||n.Error("AddPath: Open paths have been disabled.");var r=t.length-1;if(i)for(;r>0&&n.IntPoint.op_Equality(t[r],t[0]);)--r;for(;r>0&&n.IntPoint.op_Equality(t[r],t[r-1]);)--r;if(i&&r<2||!i&&r<1)return!1;for(var s=new Array,l=0;l<=r;l++)s.push(new n.TEdge);var f=!0;s[1].Curr.X=t[1].X,s[1].Curr.Y=t[1].Y,n.use_xyz&&(s[1].Curr.Z=t[1].Z);var m={Value:this.m_UseFullRange};this.RangeTest(t[0],m),this.m_UseFullRange=m.Value,m.Value=this.m_UseFullRange,this.RangeTest(t[r],m),this.m_UseFullRange=m.Value,this.InitEdge(s[0],s[1],s[r],t[0]),this.InitEdge(s[r],s[0],s[r-1],t[r]);for(var l=r-1;l>=1;--l)m.Value=this.m_UseFullRange,this.RangeTest(t[l],m),this.m_UseFullRange=m.Value,this.InitEdge(s[l],s[l+1],s[l-1],t[l]);for(var d=s[0],g=d,I=d;;){if(g.Curr===g.Next.Curr&&(i||g.Next!==d)){if(g===g.Next)break;g===d&&(d=g.Next),g=this.RemoveEdge(g),I=g;continue}if(g.Prev===g.Next)break;if(i&&n.ClipperBase.SlopesEqual4(g.Prev.Curr,g.Curr,g.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(g.Prev.Curr,g.Curr,g.Next.Curr))){g===d&&(d=g.Next),g=this.RemoveEdge(g),g=g.Prev,I=g;continue}if(g=g.Next,g===I||!i&&g.Next===d)break}if(!i&&g===g.Next||i&&g.Prev===g.Next)return!1;i||(this.m_HasOpenPaths=!0,d.Prev.OutIdx=n.ClipperBase.Skip),g=d;do this.InitEdge2(g,e),g=g.Next,f&&g.Curr.Y!==d.Curr.Y&&(f=!1);while(g!==d);if(f){if(i)return!1;g.Prev.OutIdx=n.ClipperBase.Skip;var C=new n.LocalMinima;for(C.Next=null,C.Y=g.Bot.Y,C.LeftBound=null,C.RightBound=g,C.RightBound.Side=n.EdgeSide.esRight,C.RightBound.WindDelta=0;g.Bot.X!==g.Prev.Top.X&&this.ReverseHorizontal(g),g.Next.OutIdx!==n.ClipperBase.Skip;)g.NextInLML=g.Next,g=g.Next;return this.InsertLocalMinima(C),this.m_edges.push(s),!0}this.m_edges.push(s);var N,O=null;for(n.IntPoint.op_Equality(g.Prev.Bot,g.Prev.Top)&&(g=g.Next);g=this.FindNextLocMin(g),g!==O;){O===null&&(O=g);var C=new n.LocalMinima;C.Next=null,C.Y=g.Bot.Y,g.Dx<g.Prev.Dx?(C.LeftBound=g.Prev,C.RightBound=g,N=!1):(C.LeftBound=g,C.RightBound=g.Prev,N=!0),C.LeftBound.Side=n.EdgeSide.esLeft,C.RightBound.Side=n.EdgeSide.esRight,i?C.LeftBound.Next===C.RightBound?C.LeftBound.WindDelta=-1:C.LeftBound.WindDelta=1:C.LeftBound.WindDelta=0,C.RightBound.WindDelta=-C.LeftBound.WindDelta,g=this.ProcessBound(C.LeftBound,N),g.OutIdx===n.ClipperBase.Skip&&(g=this.ProcessBound(g,N));var F=this.ProcessBound(C.RightBound,!N);F.OutIdx===n.ClipperBase.Skip&&(F=this.ProcessBound(F,!N)),C.LeftBound.OutIdx===n.ClipperBase.Skip?C.LeftBound=null:C.RightBound.OutIdx===n.ClipperBase.Skip&&(C.RightBound=null),this.InsertLocalMinima(C),N||(g=F)}return!0},n.ClipperBase.prototype.AddPaths=function(t,e,i){for(var r=!1,s=0,l=t.length;s<l;++s)this.AddPath(t[s],e,i)&&(r=!0);return r},n.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(t,e,i){return n.IntPoint.op_Equality(t,i)||n.IntPoint.op_Equality(t,e)||n.IntPoint.op_Equality(i,e)?!1:t.X!==i.X?e.X>t.X==e.X<i.X:e.Y>t.Y==e.Y<i.Y},n.ClipperBase.prototype.RemoveEdge=function(t){t.Prev.Next=t.Next,t.Next.Prev=t.Prev;var e=t.Next;return t.Prev=null,e},n.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=n.ClipperBase.horizontal:t.Dx=t.Delta.X/t.Delta.Y},n.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 e=this.m_MinimaList;e.Next!==null&&t.Y<e.Next.Y;)e=e.Next;t.Next=e.Next,e.Next=t}},n.ClipperBase.prototype.PopLocalMinima=function(t,e){return e.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===t?(this.m_CurrentLM=this.m_CurrentLM.Next,!0):!1},n.ClipperBase.prototype.ReverseHorizontal=function(t){var e=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=e,n.use_xyz&&(e=t.Top.Z,t.Top.Z=t.Bot.Z,t.Bot.Z=e)},n.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 e=t.LeftBound;e!==null&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,n.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=n.ClipperBase.Unassigned),e=t.RightBound,e!==null&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,n.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=n.ClipperBase.Unassigned),t=t.Next}this.m_ActiveEdges=null}},n.ClipperBase.prototype.InsertScanbeam=function(t){if(this.m_Scanbeam===null)this.m_Scanbeam=new n.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=t;else if(t>this.m_Scanbeam.Y){var e=new n.Scanbeam;e.Y=t,e.Next=this.m_Scanbeam,this.m_Scanbeam=e}else{for(var i=this.m_Scanbeam;i.Next!==null&&t<=i.Next.Y;)i=i.Next;if(t===i.Y)return;var r=new n.Scanbeam;r.Y=t,r.Next=i.Next,i.Next=r}},n.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)},n.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},n.ClipperBase.prototype.CreateOutRec=function(){var t=new n.OutRec;return t.Idx=n.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},n.ClipperBase.prototype.DisposeOutRec=function(t){var e=this.m_PolyOuts[t];e.Pts=null,e=null,this.m_PolyOuts[t]=null},n.ClipperBase.prototype.UpdateEdgeIntoAEL=function(t){t.NextInLML===null&&n.Error("UpdateEdgeIntoAEL: invalid call");var e=t.PrevInAEL,i=t.NextInAEL;return t.NextInLML.OutIdx=t.OutIdx,e!==null?e.NextInAEL=t.NextInLML:this.m_ActiveEdges=t.NextInLML,i!==null&&(i.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=e,t.NextInAEL=i,n.ClipperBase.IsHorizontal(t)||this.InsertScanbeam(t.Top.Y),t},n.ClipperBase.prototype.SwapPositionsInAEL=function(t,e){if(!(t.NextInAEL===t.PrevInAEL||e.NextInAEL===e.PrevInAEL)){if(t.NextInAEL===e){var i=e.NextInAEL;i!==null&&(i.PrevInAEL=t);var r=t.PrevInAEL;r!==null&&(r.NextInAEL=e),e.PrevInAEL=r,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else if(e.NextInAEL===t){var s=t.NextInAEL;s!==null&&(s.PrevInAEL=e);var l=e.PrevInAEL;l!==null&&(l.NextInAEL=t),t.PrevInAEL=l,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=s}else{var f=t.NextInAEL,m=t.PrevInAEL;t.NextInAEL=e.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=e.PrevInAEL,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t),e.NextInAEL=f,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=m,e.PrevInAEL!==null&&(e.PrevInAEL.NextInAEL=e)}t.PrevInAEL===null?this.m_ActiveEdges=t:e.PrevInAEL===null&&(this.m_ActiveEdges=e)}},n.ClipperBase.prototype.DeleteFromAEL=function(t){var e=t.PrevInAEL,i=t.NextInAEL;e===null&&i===null&&t!==this.m_ActiveEdges||(e!==null?e.NextInAEL=i:this.m_ActiveEdges=i,i!==null&&(i.PrevInAEL=e),t.NextInAEL=null,t.PrevInAEL=null)},n.Clipper=function(t){typeof t>"u"&&(t=0),this.m_PolyOuts=null,this.m_ClipType=n.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=n.PolyFillType.pftEvenOdd,this.m_SubjFillType=n.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,n.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=n.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,n.use_xyz&&(this.ZFillFunction=null)},n.Clipper.ioReverseSolution=1,n.Clipper.ioStrictlySimple=2,n.Clipper.ioPreserveCollinear=4,n.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),n.ClipperBase.prototype.Clear.call(this))},n.Clipper.prototype.InsertMaxima=function(t){var e=new n.Maxima;if(e.X=t,this.m_Maxima===null)this.m_Maxima=e,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(t<this.m_Maxima.X)e.Next=this.m_Maxima,e.Prev=null,this.m_Maxima=e;else{for(var i=this.m_Maxima;i.Next!==null&&t>=i.Next.X;)i=i.Next;if(t===i.X)return;e.Next=i.Next,e.Prev=i,i.Next!==null&&(i.Next.Prev=e),i.Next=e}},n.Clipper.prototype.Execute=function(){var t=arguments,e=t.length,i=t[1]instanceof n.PolyTree;if(e===4&&!i){var r=t[0],s=t[1],l=t[2],f=t[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&n.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,n.Clear(s),this.m_SubjFillType=l,this.m_ClipFillType=f,this.m_ClipType=r,this.m_UsingPolyTree=!1;try{var m=this.ExecuteInternal();m&&this.BuildResult(s)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return m}else if(e===4&&i){var r=t[0],d=t[1],l=t[2],f=t[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=l,this.m_ClipFillType=f,this.m_ClipType=r,this.m_UsingPolyTree=!0;try{var m=this.ExecuteInternal();m&&this.BuildResult2(d)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return m}else if(e===2&&!i){var r=t[0],s=t[1];return this.Execute(r,s,n.PolyFillType.pftEvenOdd,n.PolyFillType.pftEvenOdd)}else if(e===2&&i){var r=t[0],d=t[1];return this.Execute(r,d,n.PolyFillType.pftEvenOdd,n.PolyFillType.pftEvenOdd)}},n.Clipper.prototype.FixHoleLinkage=function(t){if(!(t.FirstLeft===null||t.IsHole!==t.FirstLeft.IsHole&&t.FirstLeft.Pts!==null)){for(var e=t.FirstLeft;e!==null&&(e.IsHole===t.IsHole||e.Pts===null);)e=e.FirstLeft;t.FirstLeft=e}},n.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var t={},e={};if(!this.PopScanbeam(t))return!1;for(this.InsertLocalMinimaIntoAEL(t.v);this.PopScanbeam(e)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(e.v))return!1;this.ProcessEdgesAtTopOfScanbeam(e.v),t.v=e.v,this.InsertLocalMinimaIntoAEL(t.v)}var i,r,s;for(r=0,s=this.m_PolyOuts.length;r<s;r++)i=this.m_PolyOuts[r],!(i.Pts===null||i.IsOpen)&&(i.IsHole^this.ReverseSolution)==this.Area$1(i)>0&&this.ReversePolyPtLinks(i.Pts);for(this.JoinCommonEdges(),r=0,s=this.m_PolyOuts.length;r<s;r++)i=this.m_PolyOuts[r],i.Pts!==null&&(i.IsOpen?this.FixupOutPolyline(i):this.FixupOutPolygon(i));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},n.Clipper.prototype.DisposeAllPolyPts=function(){for(var t=0,e=this.m_PolyOuts.length;t<e;++t)this.DisposeOutRec(t);n.Clear(this.m_PolyOuts)},n.Clipper.prototype.AddJoin=function(t,e,i){var r=new n.Join;r.OutPt1=t,r.OutPt2=e,r.OffPt.X=i.X,r.OffPt.Y=i.Y,n.use_xyz&&(r.OffPt.Z=i.Z),this.m_Joins.push(r)},n.Clipper.prototype.AddGhostJoin=function(t,e){var i=new n.Join;i.OutPt1=t,i.OffPt.X=e.X,i.OffPt.Y=e.Y,n.use_xyz&&(i.OffPt.Z=e.Z),this.m_GhostJoins.push(i)},n.Clipper.prototype.SetZ=function(t,e,i){if(this.ZFillFunction!==null){if(t.Z!==0||this.ZFillFunction===null)return;n.IntPoint.op_Equality(t,e.Bot)?t.Z=e.Bot.Z:n.IntPoint.op_Equality(t,e.Top)?t.Z=e.Top.Z:n.IntPoint.op_Equality(t,i.Bot)?t.Z=i.Bot.Z:n.IntPoint.op_Equality(t,i.Top)?t.Z=i.Top.Z:this.ZFillFunction(e.Bot,e.Top,i.Bot,i.Top,t)}},n.Clipper.prototype.InsertLocalMinimaIntoAEL=function(t){for(var e={},i,r;this.PopLocalMinima(t,e);){i=e.v.LeftBound,r=e.v.RightBound;var s=null;if(i===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(s=this.AddOutPt(r,r.Bot))):r===null?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(s=this.AddOutPt(i,i.Bot)),this.InsertScanbeam(i.Top.Y)):(this.InsertEdgeIntoAEL(i,null),this.InsertEdgeIntoAEL(r,i),this.SetWindingCount(i),r.WindCnt=i.WindCnt,r.WindCnt2=i.WindCnt2,this.IsContributing(i)&&(s=this.AddLocalMinPoly(i,r,i.Bot)),this.InsertScanbeam(i.Top.Y)),r!==null&&(n.ClipperBase.IsHorizontal(r)?(r.NextInLML!==null&&this.InsertScanbeam(r.NextInLML.Top.Y),this.AddEdgeToSEL(r)):this.InsertScanbeam(r.Top.Y)),!(i===null||r===null)){if(s!==null&&n.ClipperBase.IsHorizontal(r)&&this.m_GhostJoins.length>0&&r.WindDelta!==0)for(var l=0,f=this.m_GhostJoins.length;l<f;l++){var m=this.m_GhostJoins[l];this.HorzSegmentsOverlap(m.OutPt1.Pt.X,m.OffPt.X,r.Bot.X,r.Top.X)&&this.AddJoin(m.OutPt1,s,m.OffPt)}if(i.OutIdx>=0&&i.PrevInAEL!==null&&i.PrevInAEL.Curr.X===i.Bot.X&&i.PrevInAEL.OutIdx>=0&&n.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top,this.m_UseFullRange)&&i.WindDelta!==0&&i.PrevInAEL.WindDelta!==0){var d=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(s,d,i.Top)}if(i.NextInAEL!==r){if(r.OutIdx>=0&&r.PrevInAEL.OutIdx>=0&&n.ClipperBase.SlopesEqual5(r.PrevInAEL.Curr,r.PrevInAEL.Top,r.Curr,r.Top,this.m_UseFullRange)&&r.WindDelta!==0&&r.PrevInAEL.WindDelta!==0){var d=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(s,d,r.Top)}var g=i.NextInAEL;if(g!==null)for(;g!==r;)this.IntersectEdges(r,g,i.Curr),g=g.NextInAEL}}}},n.Clipper.prototype.InsertEdgeIntoAEL=function(t,e){if(this.m_ActiveEdges===null)t.PrevInAEL=null,t.NextInAEL=null,this.m_ActiveEdges=t;else if(e===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(e===null&&(e=this.m_ActiveEdges);e.NextInAEL!==null&&!this.E2InsertsBeforeE1(e.NextInAEL,t);)e=e.NextInAEL;t.NextInAEL=e.NextInAEL,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=t),t.PrevInAEL=e,e.NextInAEL=t}},n.Clipper.prototype.E2InsertsBeforeE1=function(t,e){return e.Curr.X===t.Curr.X?e.Top.Y>t.Top.Y?e.Top.X<n.Clipper.TopX(t,e.Top.Y):t.Top.X>n.Clipper.TopX(e,t.Top.Y):e.Curr.X<t.Curr.X},n.Clipper.prototype.IsEvenOddFillType=function(t){return t.PolyTyp===n.PolyType.ptSubject?this.m_SubjFillType===n.PolyFillType.pftEvenOdd:this.m_ClipFillType===n.PolyFillType.pftEvenOdd},n.Clipper.prototype.IsEvenOddAltFillType=function(t){return t.PolyTyp===n.PolyType.ptSubject?this.m_ClipFillType===n.PolyFillType.pftEvenOdd:this.m_SubjFillType===n.PolyFillType.pftEvenOdd},n.Clipper.prototype.IsContributing=function(t){var e,i;switch(t.PolyTyp===n.PolyType.ptSubject?(e=this.m_SubjFillType,i=this.m_ClipFillType):(e=this.m_ClipFillType,i=this.m_SubjFillType),e){case n.PolyFillType.pftEvenOdd:if(t.WindDelta===0&&t.WindCnt!==1)return!1;break;case n.PolyFillType.pftNonZero:if(Math.abs(t.WindCnt)!==1)return!1;break;case n.PolyFillType.pftPositive:if(t.WindCnt!==1)return!1;break;default:if(t.WindCnt!==-1)return!1;break}switch(this.m_ClipType){case n.ClipType.ctIntersection:switch(i){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return t.WindCnt2!==0;case n.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case n.ClipType.ctUnion:switch(i){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return t.WindCnt2===0;case n.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case n.ClipType.ctDifference:if(t.PolyTyp===n.PolyType.ptSubject)switch(i){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return t.WindCnt2===0;case n.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(i){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return t.WindCnt2!==0;case n.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case n.ClipType.ctXor:if(t.WindDelta===0)switch(i){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return t.WindCnt2===0;case n.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else return!0}return!0},n.Clipper.prototype.SetWindingCount=function(t){for(var e=t.PrevInAEL;e!==null&&(e.PolyTyp!==t.PolyTyp||e.WindDelta===0);)e=e.PrevInAEL;if(e===null){var i=t.PolyTyp===n.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;t.WindDelta===0?t.WindCnt=i===n.PolyFillType.pftNegative?-1:1:t.WindCnt=t.WindDelta,t.WindCnt2=0,e=this.m_ActiveEdges}else if(t.WindDelta===0&&this.m_ClipType!==n.ClipType.ctUnion)t.WindCnt=1,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;else if(this.IsEvenOddFillType(t)){if(t.WindDelta===0){for(var r=!0,s=e.PrevInAEL;s!==null;)s.PolyTyp===e.PolyTyp&&s.WindDelta!==0&&(r=!r),s=s.PrevInAEL;t.WindCnt=r?0:1}else t.WindCnt=t.WindDelta;t.WindCnt2=e.WindCnt2,e=e.NextInAEL}else e.WindCnt*e.WindDelta<0?Math.abs(e.WindCnt)>1?e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta:t.WindCnt=t.WindDelta===0?1:t.WindDelta:t.WindDelta===0?t.WindCnt=e.WindCnt<0?e.WindCnt-1:e.WindCnt+1:e.WindDelta*t.WindDelta<0?t.WindCnt=e.WindCnt:t.WindCnt=e.WindCnt+t.WindDelta,t.WindCnt2=e.WindCnt2,e=e.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;e!==t;)e.WindDelta!==0&&(t.WindCnt2=t.WindCnt2===0?1:0),e=e.NextInAEL;else for(;e!==t;)t.WindCnt2+=e.WindDelta,e=e.NextInAEL},n.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)},n.Clipper.prototype.PopEdgeFromSEL=function(t){if(t.v=this.m_SortedEdges,t.v===null)return!1;var e=t.v;return this.m_SortedEdges=t.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),e.NextInSEL=null,e.PrevInSEL=null,!0},n.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},n.Clipper.prototype.SwapPositionsInSEL=function(t,e){if(!(t.NextInSEL===null&&t.PrevInSEL===null)&&!(e.NextInSEL===null&&e.PrevInSEL===null)){if(t.NextInSEL===e){var i=e.NextInSEL;i!==null&&(i.PrevInSEL=t);var r=t.PrevInSEL;r!==null&&(r.NextInSEL=e),e.PrevInSEL=r,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=i}else if(e.NextInSEL===t){var i=t.NextInSEL;i!==null&&(i.PrevInSEL=e);var r=e.PrevInSEL;r!==null&&(r.NextInSEL=t),t.PrevInSEL=r,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=i}else{var i=t.NextInSEL,r=t.PrevInSEL;t.NextInSEL=e.NextInSEL,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=e.PrevInSEL,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t),e.NextInSEL=i,e.NextInSEL!==null&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=r,e.PrevInSEL!==null&&(e.PrevInSEL.NextInSEL=e)}t.PrevInSEL===null?this.m_SortedEdges=t:e.PrevInSEL===null&&(this.m_SortedEdges=e)}},n.Clipper.prototype.AddLocalMaxPoly=function(t,e,i){this.AddOutPt(t,i),e.WindDelta===0&&this.AddOutPt(e,i),t.OutIdx===e.OutIdx?(t.OutIdx=-1,e.OutIdx=-1):t.OutIdx<e.OutIdx?this.AppendPolygon(t,e):this.AppendPolygon(e,t)},n.Clipper.prototype.AddLocalMinPoly=function(t,e,i){var r,s,l;if(n.ClipperBase.IsHorizontal(e)||t.Dx>e.Dx?(r=this.AddOutPt(t,i),e.OutIdx=t.OutIdx,t.Side=n.EdgeSide.esLeft,e.Side=n.EdgeSide.esRight,s=t,s.PrevInAEL===e?l=e.PrevInAEL:l=s.PrevInAEL):(r=this.AddOutPt(e,i),t.OutIdx=e.OutIdx,t.Side=n.EdgeSide.esRight,e.Side=n.EdgeSide.esLeft,s=e,s.PrevInAEL===t?l=t.PrevInAEL:l=s.PrevInAEL),l!==null&&l.OutIdx>=0&&l.Top.Y<i.Y&&s.Top.Y<i.Y){var f=n.Clipper.TopX(l,i.Y),m=n.Clipper.TopX(s,i.Y);if(f===m&&s.WindDelta!==0&&l.WindDelta!==0&&n.ClipperBase.SlopesEqual5(new n.IntPoint2(f,i.Y),l.Top,new n.IntPoint2(m,i.Y),s.Top,this.m_UseFullRange)){var d=this.AddOutPt(l,i);this.AddJoin(r,d,s.Top)}}return r},n.Clipper.prototype.AddOutPt=function(t,e){if(t.OutIdx<0){var i=this.CreateOutRec();i.IsOpen=t.WindDelta===0;var r=new n.OutPt;return i.Pts=r,r.Idx=i.Idx,r.Pt.X=e.X,r.Pt.Y=e.Y,n.use_xyz&&(r.Pt.Z=e.Z),r.Next=r,r.Prev=r,i.IsOpen||this.SetHoleState(t,i),t.OutIdx=i.Idx,r}else{var i=this.m_PolyOuts[t.OutIdx],s=i.Pts,l=t.Side===n.EdgeSide.esLeft;if(l&&n.IntPoint.op_Equality(e,s.Pt))return s;if(!l&&n.IntPoint.op_Equality(e,s.Prev.Pt))return s.Prev;var r=new n.OutPt;return r.Idx=i.Idx,r.Pt.X=e.X,r.Pt.Y=e.Y,n.use_xyz&&(r.Pt.Z=e.Z),r.Next=s,r.Prev=s.Prev,r.Prev.Next=r,s.Prev=r,l&&(i.Pts=r),r}},n.Clipper.prototype.GetLastOutPt=function(t){var e=this.m_PolyOuts[t.OutIdx];return t.Side===n.EdgeSide.esLeft?e.Pts:e.Pts.Prev},n.Clipper.prototype.SwapPoints=function(t,e){var i=new n.IntPoint1(t.Value);t.Value.X=e.Value.X,t.Value.Y=e.Value.Y,n.use_xyz&&(t.Value.Z=e.Value.Z),e.Value.X=i.X,e.Value.Y=i.Y,n.use_xyz&&(e.Value.Z=i.Z)},n.Clipper.prototype.HorzSegmentsOverlap=function(t,e,i,r){var s;return t>e&&(s=t,t=e,e=s),i>r&&(s=i,i=r,r=s),t<r&&i<e},n.Clipper.prototype.SetHoleState=function(t,e){for(var i=t.PrevInAEL,r=null;i!==null;)i.OutIdx>=0&&i.WindDelta!==0&&(r===null?r=i:r.OutIdx===i.OutIdx&&(r=null)),i=i.PrevInAEL;r===null?(e.FirstLeft=null,e.IsHole=!1):(e.FirstLeft=this.m_PolyOuts[r.OutIdx],e.IsHole=!e.FirstLeft.IsHole)},n.Clipper.prototype.GetDx=function(t,e){return t.Y===e.Y?n.ClipperBase.horizontal:(e.X-t.X)/(e.Y-t.Y)},n.Clipper.prototype.FirstIsBottomPt=function(t,e){for(var i=t.Prev;n.IntPoint.op_Equality(i.Pt,t.Pt)&&i!==t;)i=i.Prev;var r=Math.abs(this.GetDx(t.Pt,i.Pt));for(i=t.Next;n.IntPoint.op_Equality(i.Pt,t.Pt)&&i!==t;)i=i.Next;var s=Math.abs(this.GetDx(t.Pt,i.Pt));for(i=e.Prev;n.IntPoint.op_Equality(i.Pt,e.Pt)&&i!==e;)i=i.Prev;var l=Math.abs(this.GetDx(e.Pt,i.Pt));for(i=e.Next;n.IntPoint.op_Equality(i.Pt,e.Pt)&&i!==e;)i=i.Next;var f=Math.abs(this.GetDx(e.Pt,i.Pt));return Math.max(r,s)===Math.max(l,f)&&Math.min(r,s)===Math.min(l,f)?this.Area(t)>0:r>=l&&r>=f||s>=l&&s>=f},n.Clipper.prototype.GetBottomPt=function(t){for(var e=null,i=t.Next;i!==t;)i.Pt.Y>t.Pt.Y?(t=i,e=null):i.Pt.Y===t.Pt.Y&&i.Pt.X<=t.Pt.X&&(i.Pt.X<t.Pt.X?(e=null,t=i):i.Next!==t&&i.Prev!==t&&(e=i)),i=i.Next;if(e!==null)for(;e!==i;)for(this.FirstIsBottomPt(i,e)||(t=e),e=e.Next;n.IntPoint.op_Inequality(e.Pt,t.Pt);)e=e.Next;return t},n.Clipper.prototype.GetLowermostRec=function(t,e){t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts)),e.BottomPt===null&&(e.BottomPt=this.GetBottomPt(e.Pts));var i=t.BottomPt,r=e.BottomPt;return i.Pt.Y>r.Pt.Y?t:i.Pt.Y<r.Pt.Y?e:i.Pt.X<r.Pt.X?t:i.Pt.X>r.Pt.X||i.Next===i?e:r.Next===r||this.FirstIsBottomPt(i,r)?t:e},n.Clipper.prototype.OutRec1RightOfOutRec2=function(t,e){do if(t=t.FirstLeft,t===e)return!0;while(t!==null);return!1},n.Clipper.prototype.GetOutRec=function(t){for(var e=this.m_PolyOuts[t];e!==this.m_PolyOuts[e.Idx];)e=this.m_PolyOuts[e.Idx];return e},n.Clipper.prototype.AppendPolygon=function(t,e){var i=this.m_PolyOuts[t.OutIdx],r=this.m_PolyOuts[e.OutIdx],s;this.OutRec1RightOfOutRec2(i,r)?s=r:this.OutRec1RightOfOutRec2(r,i)?s=i:s=this.GetLowermostRec(i,r);var l=i.Pts,f=l.Prev,m=r.Pts,d=m.Prev;t.Side===n.EdgeSide.esLeft?e.Side===n.EdgeSide.esLeft?(this.ReversePolyPtLinks(m),m.Next=l,l.Prev=m,f.Next=d,d.Prev=f,i.Pts=d):(d.Next=l,l.Prev=d,m.Prev=f,f.Next=m,i.Pts=m):e.Side===n.EdgeSide.esRight?(this.ReversePolyPtLinks(m),f.Next=d,d.Prev=f,m.Next=l,l.Prev=m):(f.Next=m,m.Prev=f,l.Prev=d,d.Next=l),i.BottomPt=null,s===r&&(r.FirstLeft!==i&&(i.FirstLeft=r.FirstLeft),i.IsHole=r.IsHole),r.Pts=null,r.BottomPt=null,r.FirstLeft=i;var g=t.OutIdx,I=e.OutIdx;t.OutIdx=-1,e.OutIdx=-1;for(var C=this.m_ActiveEdges;C!==null;){if(C.OutIdx===I){C.OutIdx=g,C.Side=t.Side;break}C=C.NextInAEL}r.Idx=i.Idx},n.Clipper.prototype.ReversePolyPtLinks=function(t){if(t!==null){var e,i;e=t;do i=e.Next,e.Next=e.Prev,e.Prev=i,e=i;while(e!==t)}},n.Clipper.SwapSides=function(t,e){var i=t.Side;t.Side=e.Side,e.Side=i},n.Clipper.SwapPolyIndexes=function(t,e){var i=t.OutIdx;t.OutIdx=e.OutIdx,e.OutIdx=i},n.Clipper.prototype.IntersectEdges=function(t,e,i){var r=t.OutIdx>=0,s=e.OutIdx>=0;if(n.use_xyz&&this.SetZ(i,t,e),n.use_lines&&(t.WindDelta===0||e.WindDelta===0)){if(t.WindDelta===0&&e.WindDelta===0)return;t.PolyTyp===e.PolyTyp&&t.WindDelta!==e.WindDelta&&this.m_ClipType===n.ClipType.ctUnion?t.WindDelta===0?s&&(this.AddOutPt(t,i),r&&(t.OutIdx=-1)):r&&(this.AddOutPt(e,i),s&&(e.OutIdx=-1)):t.PolyTyp!==e.PolyTyp&&(t.WindDelta===0&&Math.abs(e.WindCnt)===1&&(this.m_ClipType!==n.ClipType.ctUnion||e.WindCnt2===0)?(this.AddOutPt(t,i),r&&(t.OutIdx=-1)):e.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==n.ClipType.ctUnion||t.WindCnt2===0)&&(this.AddOutPt(e,i),s&&(e.OutIdx=-1)));return}if(t.PolyTyp===e.PolyTyp)if(this.IsEvenOddFillType(t)){var l=t.WindCnt;t.WindCnt=e.WindCnt,e.WindCnt=l}else t.WindCnt+e.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt+=e.WindDelta,e.WindCnt-t.WindDelta===0?e.WindCnt=-e.WindCnt:e.WindCnt-=t.WindDelta;else this.IsEvenOddFillType(e)?t.WindCnt2=t.WindCnt2===0?1:0:t.WindCnt2+=e.WindDelta,this.IsEvenOddFillType(t)?e.WindCnt2=e.WindCnt2===0?1:0:e.WindCnt2-=t.WindDelta;var f,m,d,g;t.PolyTyp===n.PolyType.ptSubject?(f=this.m_SubjFillType,d=this.m_ClipFillType):(f=this.m_ClipFillType,d=this.m_SubjFillType),e.PolyTyp===n.PolyType.ptSubject?(m=this.m_SubjFillType,g=this.m_ClipFillType):(m=this.m_ClipFillType,g=this.m_SubjFillType);var I,C;switch(f){case n.PolyFillType.pftPositive:I=t.WindCnt;break;case n.PolyFillType.pftNegative:I=-t.WindCnt;break;default:I=Math.abs(t.WindCnt);break}switch(m){case n.PolyFillType.pftPositive:C=e.WindCnt;break;case n.PolyFillType.pftNegative:C=-e.WindCnt;break;default:C=Math.abs(e.WindCnt);break}if(r&&s)I!==0&&I!==1||C!==0&&C!==1||t.PolyTyp!==e.PolyTyp&&this.m_ClipType!==n.ClipType.ctXor?this.AddLocalMaxPoly(t,e,i):(this.AddOutPt(t,i),this.AddOutPt(e,i),n.Clipper.SwapSides(t,e),n.Clipper.SwapPolyIndexes(t,e));else if(r)(C===0||C===1)&&(this.AddOutPt(t,i),n.Clipper.SwapSides(t,e),n.Clipper.SwapPolyIndexes(t,e));else if(s)(I===0||I===1)&&(this.AddOutPt(e,i),n.Clipper.SwapSides(t,e),n.Clipper.SwapPolyIndexes(t,e));else if((I===0||I===1)&&(C===0||C===1)){var N,O;switch(d){case n.PolyFillType.pftPositive:N=t.WindCnt2;break;case n.PolyFillType.pftNegative:N=-t.WindCnt2;break;default:N=Math.abs(t.WindCnt2);break}switch(g){case n.PolyFillType.pftPositive:O=e.WindCnt2;break;case n.PolyFillType.pftNegative:O=-e.WindCnt2;break;default:O=Math.abs(e.WindCnt2);break}if(t.PolyTyp!==e.PolyTyp)this.AddLocalMinPoly(t,e,i);else if(I===1&&C===1)switch(this.m_ClipType){case n.ClipType.ctIntersection:N>0&&O>0&&this.AddLocalMinPoly(t,e,i);break;case n.ClipType.ctUnion:N<=0&&O<=0&&this.AddLocalMinPoly(t,e,i);break;case n.ClipType.ctDifference:(t.PolyTyp===n.PolyType.ptClip&&N>0&&O>0||t.PolyTyp===n.PolyType.ptSubject&&N<=0&&O<=0)&&this.AddLocalMinPoly(t,e,i);break;case n.ClipType.ctXor:this.AddLocalMinPoly(t,e,i);break}else n.Clipper.SwapSides(t,e)}},n.Clipper.prototype.DeleteFromSEL=function(t){var e=t.PrevInSEL,i=t.NextInSEL;e===null&&i===null&&t!==this.m_SortedEdges||(e!==null?e.NextInSEL=i:this.m_SortedEdges=i,i!==null&&(i.PrevInSEL=e),t.NextInSEL=null,t.PrevInSEL=null)},n.Clipper.prototype.ProcessHorizontals=function(){for(var t={};this.PopEdgeFromSEL(t);)this.ProcessHorizontal(t.v)},n.Clipper.prototype.GetHorzDirection=function(t,e){t.Bot.X<t.Top.X?(e.Left=t.Bot.X,e.Right=t.Top.X,e.Dir=n.Direction.dLeftToRight):(e.Left=t.Top.X,e.Right=t.Bot.X,e.Dir=n.Direction.dRightToLeft)},n.Clipper.prototype.ProcessHorizontal=function(t){var e={Dir:null,Left:null,Right:null};this.GetHorzDirection(t,e);for(var i=e.Dir,r=e.Left,s=e.Right,l=t.WindDelta===0,f=t,m=null;f.NextInLML!==null&&n.ClipperBase.IsHorizontal(f.NextInLML);)f=f.NextInLML;f.NextInLML===null&&(m=this.GetMaximaPair(f));var d=this.m_Maxima;if(d!==null)if(i===n.Direction.dLeftToRight){for(;d!==null&&d.X<=t.Bot.X;)d=d.Next;d!==null&&d.X>=f.Top.X&&(d=null)}else{for(;d.Next!==null&&d.Next.X<t.Bot.X;)d=d.Next;d.X<=f.Top.X&&(d=null)}for(var g=null;;){for(var I=t===f,C=this.GetNextInAEL(t,i);C!==null;){if(d!==null)if(i===n.Direction.dLeftToRight)for(;d!==null&&d.X<C.Curr.X;)t.OutIdx>=0&&!l&&this.AddOutPt(t,new n.IntPoint2(d.X,t.Bot.Y)),d=d.Next;else for(;d!==null&&d.X>C.Curr.X;)t.OutIdx>=0&&!l&&this.AddOutPt(t,new n.IntPoint2(d.X,t.Bot.Y)),d=d.Prev;if(i===n.Direction.dLeftToRight&&C.Curr.X>s||i===n.Direction.dRightToLeft&&C.Curr.X<r||C.Curr.X===t.Top.X&&t.NextInLML!==null&&C.Dx<t.NextInLML.Dx)break;if(t.OutIdx>=0&&!l){n.use_xyz&&(i===n.Direction.dLeftToRight?this.SetZ(C.Curr,t,C):this.SetZ(C.Curr,C,t)),g=this.AddOutPt(t,C.Curr);for(var N=this.m_SortedEdges;N!==null;){if(N.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,N.Bot.X,N.Top.X)){var O=this.GetLastOutPt(N);this.AddJoin(O,g,N.Top)}N=N.NextInSEL}this.AddGhostJoin(g,t.Bot)}if(C===m&&I){t.OutIdx>=0&&this.AddLocalMaxPoly(t,m,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(m);return}if(i===n.Direction.dLeftToRight){var F=new n.IntPoint2(C.Curr.X,t.Curr.Y);this.IntersectEdges(t,C,F)}else{var F=new n.IntPoint2(C.Curr.X,t.Curr.Y);this.IntersectEdges(C,t,F)}var W=this.GetNextInAEL(C,i);this.SwapPositionsInAEL(t,C),C=W}if(t.NextInLML===null||!n.ClipperBase.IsHorizontal(t.NextInLML))break;t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),e={Dir:i,Left:r,Right:s},this.GetHorzDirection(t,e),i=e.Dir,r=e.Left,s=e.Right}if(t.OutIdx>=0&&g===null){g=this.GetLastOutPt(t);for(var N=this.m_SortedEdges;N!==null;){if(N.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,N.Bot.X,N.Top.X)){var O=this.GetLastOutPt(N);this.AddJoin(O,g,N.Top)}N=N.NextInSEL}this.AddGhostJoin(g,t.Top)}if(t.NextInLML!==null)if(t.OutIdx>=0){if(g=this.AddOutPt(t,t.Top),t=this.UpdateEdgeIntoAEL(t),t.WindDelta===0)return;var J=t.PrevInAEL,W=t.NextInAEL;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&&n.ClipperBase.SlopesEqual3(t,J,this.m_UseFullRange)){var O=this.AddOutPt(J,t.Bot);this.AddJoin(g,O,t.Top)}else if(W!==null&&W.Curr.X===t.Bot.X&&W.Curr.Y===t.Bot.Y&&W.WindDelta!==0&&W.OutIdx>=0&&W.Curr.Y>W.Top.Y&&n.ClipperBase.SlopesEqual3(t,W,this.m_UseFullRange)){var O=this.AddOutPt(W,t.Bot);this.AddJoin(g,O,t.Top)}}else t=this.UpdateEdgeIntoAEL(t);else t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t)},n.Clipper.prototype.GetNextInAEL=function(t,e){return e===n.Direction.dLeftToRight?t.NextInAEL:t.PrevInAEL},n.Clipper.prototype.IsMinima=function(t){return t!==null&&t.Prev.NextInLML!==t&&t.Next.NextInLML!==t},n.Clipper.prototype.IsMaxima=function(t,e){return t!==null&&t.Top.Y===e&&t.NextInLML===null},n.Clipper.prototype.IsIntermediate=function(t,e){return t.Top.Y===e&&t.NextInLML!==null},n.Clipper.prototype.GetMaximaPair=function(t){return n.IntPoint.op_Equality(t.Next.Top,t.Top)&&t.Next.NextInLML===null?t.Next:n.IntPoint.op_Equality(t.Prev.Top,t.Top)&&t.Prev.NextInLML===null?t.Prev:null},n.Clipper.prototype.GetMaximaPairEx=function(t){var e=this.GetMaximaPair(t);return e===null||e.OutIdx===n.ClipperBase.Skip||e.NextInAEL===e.PrevInAEL&&!n.ClipperBase.IsHorizontal(e)?null:e},n.Clipper.prototype.ProcessIntersections=function(t){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(t),this.m_IntersectList.length===0)return!0;if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,n.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0},n.Clipper.prototype.BuildIntersectList=function(t){if(this.m_ActiveEdges!==null){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;e!==null;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e.Curr.X=n.Clipper.TopX(e,t),e=e.NextInAEL;for(var i=!0;i&&this.m_SortedEdges!==null;){for(i=!1,e=this.m_SortedEdges;e.NextInSEL!==null;){var r=e.NextInSEL,s=new n.IntPoint0;if(e.Curr.X>r.Curr.X){this.IntersectPoint(e,r,s),s.Y<t&&(s=new n.IntPoint2(n.Clipper.TopX(e,t),t));var l=new n.IntersectNode;l.Edge1=e,l.Edge2=r,l.Pt.X=s.X,l.Pt.Y=s.Y,n.use_xyz&&(l.Pt.Z=s.Z),this.m_IntersectList.push(l),this.SwapPositionsInSEL(e,r),i=!0}else e=r}if(e.PrevInSEL!==null)e.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},n.Clipper.prototype.EdgesAdjacent=function(t){return t.Edge1.NextInSEL===t.Edge2||t.Edge1.PrevInSEL===t.Edge2},n.Clipper.IntersectNodeSort=function(t,e){return e.Pt.Y-t.Pt.Y},n.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var t=this.m_IntersectList.length,e=0;e<t;e++){if(!this.EdgesAdjacent(this.m_IntersectList[e])){for(var i=e+1;i<t&&!this.EdgesAdjacent(this.m_IntersectList[i]);)i++;if(i===t)return!1;var r=this.m_IntersectList[e];this.m_IntersectList[e]=this.m_IntersectList[i],this.m_IntersectList[i]=r}this.SwapPositionsInSEL(this.m_IntersectList[e].Edge1,this.m_IntersectList[e].Edge2)}return!0},n.Clipper.prototype.ProcessIntersectList=function(){for(var t=0,e=this.m_IntersectList.length;t<e;t++){var i=this.m_IntersectList[t];this.IntersectEdges(i.Edge1,i.Edge2,i.Pt),this.SwapPositionsInAEL(i.Edge1,i.Edge2)}this.m_IntersectList.length=0};var Xi=function(t){return t<0?Math.ceil(t-.5):Math.round(t)},Mi=function(t){return t<0?Math.ceil(t-.5):Math.floor(t+.5)},ki=function(t){return t<0?-Math.round(Math.abs(t)):Math.round(t)},Oi=function(t){return t<0?(t-=.5,t<-2147483648?Math.ceil(t):t|0):(t+=.5,t>2147483647?Math.floor(t):t|0)};u.msie?n.Clipper.Round=Xi:u.chromium?n.Clipper.Round=ki:u.safari?n.Clipper.Round=Oi:n.Clipper.Round=Mi,n.Clipper.TopX=function(t,e){return e===t.Top.Y?t.Top.X:t.Bot.X+n.Clipper.Round(t.Dx*(e-t.Bot.Y))},n.Clipper.prototype.IntersectPoint=function(t,e,i){i.X=0,i.Y=0;var r,s;if(t.Dx===e.Dx){i.Y=t.Curr.Y,i.X=n.Clipper.TopX(t,i.Y);return}if(t.Delta.X===0)i.X=t.Bot.X,n.ClipperBase.IsHorizontal(e)?i.Y=e.Bot.Y:(s=e.Bot.Y-e.Bot.X/e.Dx,i.Y=n.Clipper.Round(i.X/e.Dx+s));else if(e.Delta.X===0)i.X=e.Bot.X,n.ClipperBase.IsHorizontal(t)?i.Y=t.Bot.Y:(r=t.Bot.Y-t.Bot.X/t.Dx,i.Y=n.Clipper.Round(i.X/t.Dx+r));else{r=t.Bot.X-t.Bot.Y*t.Dx,s=e.Bot.X-e.Bot.Y*e.Dx;var l=(s-r)/(t.Dx-e.Dx);i.Y=n.Clipper.Round(l),Math.abs(t.Dx)<Math.abs(e.Dx)?i.X=n.Clipper.Round(t.Dx*l+r):i.X=n.Clipper.Round(e.Dx*l+s)}if(i.Y<t.Top.Y||i.Y<e.Top.Y){if(t.Top.Y>e.Top.Y)return i.Y=t.Top.Y,i.X=n.Clipper.TopX(e,t.Top.Y),i.X<t.Top.X;i.Y=e.Top.Y,Math.abs(t.Dx)<Math.abs(e.Dx)?i.X=n.Clipper.TopX(t,i.Y):i.X=n.Clipper.TopX(e,i.Y)}i.Y>t.Curr.Y&&(i.Y=t.Curr.Y,Math.abs(t.Dx)>Math.abs(e.Dx)?i.X=n.Clipper.TopX(e,i.Y):i.X=n.Clipper.TopX(t,i.Y))},n.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(t){for(var e=this.m_ActiveEdges;e!==null;){var i=this.IsMaxima(e,t);if(i){var r=this.GetMaximaPairEx(e);i=r===null||!n.ClipperBase.IsHorizontal(r)}if(i){this.StrictlySimple&&this.InsertMaxima(e.Top.X);var s=e.PrevInAEL;this.DoMaxima(e),s===null?e=this.m_ActiveEdges:e=s.NextInAEL}else{if(this.IsIntermediate(e,t)&&n.ClipperBase.IsHorizontal(e.NextInLML)?(e=this.UpdateEdgeIntoAEL(e),e.OutIdx>=0&&this.AddOutPt(e,e.Bot),this.AddEdgeToSEL(e)):(e.Curr.X=n.Clipper.TopX(e,t),e.Curr.Y=t),n.use_xyz&&(e.Top.Y===t?e.Curr.Z=e.Top.Z:e.Bot.Y===t?e.Curr.Z=e.Bot.Z:e.Curr.Z=0),this.StrictlySimple){var s=e.PrevInAEL;if(e.OutIdx>=0&&e.WindDelta!==0&&s!==null&&s.OutIdx>=0&&s.Curr.X===e.Curr.X&&s.WindDelta!==0){var l=new n.IntPoint1(e.Curr);n.use_xyz&&this.SetZ(l,s,e);var f=this.AddOutPt(s,l),m=this.AddOutPt(e,l);this.AddJoin(f,m,l)}}e=e.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,e=this.m_ActiveEdges;e!==null;){if(this.IsIntermediate(e,t)){var f=null;e.OutIdx>=0&&(f=this.AddOutPt(e,e.Top)),e=this.UpdateEdgeIntoAEL(e);var s=e.PrevInAEL,d=e.NextInAEL;if(s!==null&&s.Curr.X===e.Bot.X&&s.Curr.Y===e.Bot.Y&&f!==null&&s.OutIdx>=0&&s.Curr.Y===s.Top.Y&&n.ClipperBase.SlopesEqual5(e.Curr,e.Top,s.Curr,s.Top,this.m_UseFullRange)&&e.WindDelta!==0&&s.WindDelta!==0){var m=this.AddOutPt(ePrev2,e.Bot);this.AddJoin(f,m,e.Top)}else if(d!==null&&d.Curr.X===e.Bot.X&&d.Curr.Y===e.Bot.Y&&f!==null&&d.OutIdx>=0&&d.Curr.Y===d.Top.Y&&n.ClipperBase.SlopesEqual5(e.Curr,e.Top,d.Curr,d.Top,this.m_UseFullRange)&&e.WindDelta!==0&&d.WindDelta!==0){var m=this.AddOutPt(d,e.Bot);this.AddJoin(f,m,e.Top)}}e=e.NextInAEL}},n.Clipper.prototype.DoMaxima=function(t){var e=this.GetMaximaPairEx(t);if(e===null){t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t);return}for(var i=t.NextInAEL;i!==null&&i!==e;)this.IntersectEdges(t,i,t.Top),this.SwapPositionsInAEL(t,i),i=t.NextInAEL;t.OutIdx===-1&&e.OutIdx===-1?(this.DeleteFromAEL(t),this.DeleteFromAEL(e)):t.OutIdx>=0&&e.OutIdx>=0?(t.OutIdx>=0&&this.AddLocalMaxPoly(t,e,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(e)):n.use_lines&&t.WindDelta===0?(t.OutIdx>=0&&(this.AddOutPt(t,t.Top),t.OutIdx=n.ClipperBase.Unassigned),this.DeleteFromAEL(t),e.OutIdx>=0&&(this.AddOutPt(e,t.Top),e.OutIdx=n.ClipperBase.Unassigned),this.DeleteFromAEL(e)):n.Error("DoMaxima error")},n.Clipper.ReversePaths=function(t){for(var e=0,i=t.length;e<i;e++)t[e].reverse()},n.Clipper.Orientation=function(t){return n.Clipper.Area(t)>=0},n.Clipper.prototype.PointCount=function(t){if(t===null)return 0;var e=0,i=t;do e++,i=i.Next;while(i!==t);return e},n.Clipper.prototype.BuildResult=function(t){n.Clear(t);for(var e=0,i=this.m_PolyOuts.length;e<i;e++){var r=this.m_PolyOuts[e];if(r.Pts!==null){var s=r.Pts.Prev,l=this.PointCount(s);if(!(l<2)){for(var f=new Array(l),m=0;m<l;m++)f[m]=s.Pt,s=s.Prev;t.push(f)}}}},n.Clipper.prototype.BuildResult2=function(t){t.Clear();for(var e=0,i=this.m_PolyOuts.length;e<i;e++){var r=this.m_PolyOuts[e],s=this.PointCount(r.Pts);if(!(r.IsOpen&&s<2||!r.IsOpen&&s<3)){this.FixHoleLinkage(r);var l=new n.PolyNode;t.m_AllPolys.push(l),r.PolyNode=l,l.m_polygon.length=s;for(var f=r.Pts.Prev,m=0;m<s;m++)l.m_polygon[m]=f.Pt,f=f.Prev}}for(var e=0,i=this.m_PolyOuts.length;e<i;e++){var r=this.m_PolyOuts[e];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))}},n.Clipper.prototype.FixupOutPolyline=function(t){for(var e=t.Pts,i=e.Prev;e!==i;)if(e=e.Next,n.IntPoint.op_Equality(e.Pt,e.Prev.Pt)){e===i&&(i=e.Prev);var r=e.Prev;r.Next=e.Next,e.Next.Prev=r,e=r}e===e.Prev&&(t.Pts=null)},n.Clipper.prototype.FixupOutPolygon=function(t){var e=null;t.BottomPt=null;for(var i=t.Pts,r=this.PreserveCollinear||this.StrictlySimple;;){if(i.Prev===i||i.Prev===i.Next){t.Pts=null;return}if(n.IntPoint.op_Equality(i.Pt,i.Next.Pt)||n.IntPoint.op_Equality(i.Pt,i.Prev.Pt)||n.ClipperBase.SlopesEqual4(i.Prev.Pt,i.Pt,i.Next.Pt,this.m_UseFullRange)&&(!r||!this.Pt2IsBetweenPt1AndPt3(i.Prev.Pt,i.Pt,i.Next.Pt)))e=null,i.Prev.Next=i.Next,i.Next.Prev=i.Prev,i=i.Prev;else{if(i===e)break;e===null&&(e=i),i=i.Next}}t.Pts=i},n.Clipper.prototype.DupOutPt=function(t,e){var i=new n.OutPt;return i.Pt.X=t.Pt.X,i.Pt.Y=t.Pt.Y,n.use_xyz&&(i.Pt.Z=t.Pt.Z),i.Idx=t.Idx,e?(i.Next=t.Next,i.Prev=t,t.Next.Prev=i,t.Next=i):(i.Prev=t.Prev,i.Next=t,t.Prev.Next=i,t.Prev=i),i},n.Clipper.prototype.GetOverlap=function(t,e,i,r,s){return t<e?i<r?(s.Left=Math.max(t,i),s.Right=Math.min(e,r)):(s.Left=Math.max(t,r),s.Right=Math.min(e,i)):i<r?(s.Left=Math.max(e,i),s.Right=Math.min(t,r)):(s.Left=Math.max(e,r),s.Right=Math.min(t,i)),s.Left<s.Right},n.Clipper.prototype.JoinHorz=function(t,e,i,r,s,l){var f=t.Pt.X>e.Pt.X?n.Direction.dRightToLeft:n.Direction.dLeftToRight,m=i.Pt.X>r.Pt.X?n.Direction.dRightToLeft:n.Direction.dLeftToRight;if(f===m)return!1;if(f===n.Direction.dLeftToRight){for(;t.Next.Pt.X<=s.X&&t.Next.Pt.X>=t.Pt.X&&t.Next.Pt.Y===s.Y;)t=t.Next;l&&t.Pt.X!==s.X&&(t=t.Next),e=this.DupOutPt(t,!l),n.IntPoint.op_Inequality(e.Pt,s)&&(t=e,t.Pt.X=s.X,t.Pt.Y=s.Y,n.use_xyz&&(t.Pt.Z=s.Z),e=this.DupOutPt(t,!l))}else{for(;t.Next.Pt.X>=s.X&&t.Next.Pt.X<=t.Pt.X&&t.Next.Pt.Y===s.Y;)t=t.Next;!l&&t.Pt.X!==s.X&&(t=t.Next),e=this.DupOutPt(t,l),n.IntPoint.op_Inequality(e.Pt,s)&&(t=e,t.Pt.X=s.X,t.Pt.Y=s.Y,n.use_xyz&&(t.Pt.Z=s.Z),e=this.DupOutPt(t,l))}if(m===n.Direction.dLeftToRight){for(;i.Next.Pt.X<=s.X&&i.Next.Pt.X>=i.Pt.X&&i.Next.Pt.Y===s.Y;)i=i.Next;l&&i.Pt.X!==s.X&&(i=i.Next),r=this.DupOutPt(i,!l),n.IntPoint.op_Inequality(r.Pt,s)&&(i=r,i.Pt.X=s.X,i.Pt.Y=s.Y,n.use_xyz&&(i.Pt.Z=s.Z),r=this.DupOutPt(i,!l))}else{for(;i.Next.Pt.X>=s.X&&i.Next.Pt.X<=i.Pt.X&&i.Next.Pt.Y===s.Y;)i=i.Next;!l&&i.Pt.X!==s.X&&(i=i.Next),r=this.DupOutPt(i,l),n.IntPoint.op_Inequality(r.Pt,s)&&(i=r,i.Pt.X=s.X,i.Pt.Y=s.Y,n.use_xyz&&(i.Pt.Z=s.Z),r=this.DupOutPt(i,l))}return f===n.Direction.dLeftToRight===l?(t.Prev=i,i.Next=t,e.Next=r,r.Prev=e):(t.Next=i,i.Prev=t,e.Prev=r,r.Next=e),!0},n.Clipper.prototype.JoinPoints=function(t,e,i){var r=t.OutPt1,s=new n.OutPt,l=t.OutPt2,f=new n.OutPt,m=t.OutPt1.Pt.Y===t.OffPt.Y;if(m&&n.IntPoint.op_Equality(t.OffPt,t.OutPt1.Pt)&&n.IntPoint.op_Equality(t.OffPt,t.OutPt2.Pt)){if(e!==i)return!1;for(s=t.OutPt1.Next;s!==r&&n.IntPoint.op_Equality(s.Pt,t.OffPt);)s=s.Next;var d=s.Pt.Y>t.OffPt.Y;for(f=t.OutPt2.Next;f!==l&&n.IntPoint.op_Equality(f.Pt,t.OffPt);)f=f.Next;var g=f.Pt.Y>t.OffPt.Y;return d===g?!1:d?(s=this.DupOutPt(r,!1),f=this.DupOutPt(l,!0),r.Prev=l,l.Next=r,s.Next=f,f.Prev=s,t.OutPt1=r,t.OutPt2=s,!0):(s=this.DupOutPt(r,!0),f=this.DupOutPt(l,!1),r.Next=l,l.Prev=r,s.Prev=f,f.Next=s,t.OutPt1=r,t.OutPt2=s,!0)}else if(m){for(s=r;r.Prev.Pt.Y===r.Pt.Y&&r.Prev!==s&&r.Prev!==l;)r=r.Prev;for(;s.Next.Pt.Y===s.Pt.Y&&s.Next!==r&&s.Next!==l;)s=s.Next;if(s.Next===r||s.Next===l)return!1;for(f=l;l.Prev.Pt.Y===l.Pt.Y&&l.Prev!==f&&l.Prev!==s;)l=l.Prev;for(;f.Next.Pt.Y===f.Pt.Y&&f.Next!==l&&f.Next!==r;)f=f.Next;if(f.Next===l||f.Next===r)return!1;var I={Left:null,Right:null};if(!this.GetOverlap(r.Pt.X,s.Pt.X,l.Pt.X,f.Pt.X,I))return!1;var C=I.Left,N=I.Right,O=new n.IntPoint0,F;return r.Pt.X>=C&&r.Pt.X<=N?(O.X=r.Pt.X,O.Y=r.Pt.Y,n.use_xyz&&(O.Z=r.Pt.Z),F=r.Pt.X>s.Pt.X):l.Pt.X>=C&&l.Pt.X<=N?(O.X=l.Pt.X,O.Y=l.Pt.Y,n.use_xyz&&(O.Z=l.Pt.Z),F=l.Pt.X>f.Pt.X):s.Pt.X>=C&&s.Pt.X<=N?(O.X=s.Pt.X,O.Y=s.Pt.Y,n.use_xyz&&(O.Z=s.Pt.Z),F=s.Pt.X>r.Pt.X):(O.X=f.Pt.X,O.Y=f.Pt.Y,n.use_xyz&&(O.Z=f.Pt.Z),F=f.Pt.X>l.Pt.X),t.OutPt1=r,t.OutPt2=l,this.JoinHorz(r,s,l,f,O,F)}else{for(s=r.Next;n.IntPoint.op_Equality(s.Pt,r.Pt)&&s!==r;)s=s.Next;var W=s.Pt.Y>r.Pt.Y||!n.ClipperBase.SlopesEqual4(r.Pt,s.Pt,t.OffPt,this.m_UseFullRange);if(W){for(s=r.Prev;n.IntPoint.op_Equality(s.Pt,r.Pt)&&s!==r;)s=s.Prev;if(s.Pt.Y>r.Pt.Y||!n.ClipperBase.SlopesEqual4(r.Pt,s.Pt,t.OffPt,this.m_UseFullRange))return!1}for(f=l.Next;n.IntPoint.op_Equality(f.Pt,l.Pt)&&f!==l;)f=f.Next;var J=f.Pt.Y>l.Pt.Y||!n.ClipperBase.SlopesEqual4(l.Pt,f.Pt,t.OffPt,this.m_UseFullRange);if(J){for(f=l.Prev;n.IntPoint.op_Equality(f.Pt,l.Pt)&&f!==l;)f=f.Prev;if(f.Pt.Y>l.Pt.Y||!n.ClipperBase.SlopesEqual4(l.Pt,f.Pt,t.OffPt,this.m_UseFullRange))return!1}return s===r||f===l||s===f||e===i&&W===J?!1:W?(s=this.DupOutPt(r,!1),f=this.DupOutPt(l,!0),r.Prev=l,l.Next=r,s.Next=f,f.Prev=s,t.OutPt1=r,t.OutPt2=s,!0):(s=this.DupOutPt(r,!0),f=this.DupOutPt(l,!1),r.Next=l,l.Prev=r,s.Prev=f,f.Next=s,t.OutPt1=r,t.OutPt2=s,!0)}},n.Clipper.GetBounds=function(t){for(var e=0,i=t.length;e<i&&t[e].length===0;)e++;if(e===i)return new n.IntRect(0,0,0,0);var r=new n.IntRect;for(r.left=t[e][0].X,r.right=r.left,r.top=t[e][0].Y,r.bottom=r.top;e<i;e++)for(var s=0,l=t[e].length;s<l;s++)t[e][s].X<r.left?r.left=t[e][s].X:t[e][s].X>r.right&&(r.right=t[e][s].X),t[e][s].Y<r.top?r.top=t[e][s].Y:t[e][s].Y>r.bottom&&(r.bottom=t[e][s].Y);return r},n.Clipper.prototype.GetBounds2=function(t){var e=t,i=new n.IntRect;for(i.left=t.Pt.X,i.right=t.Pt.X,i.top=t.Pt.Y,i.bottom=t.Pt.Y,t=t.Next;t!==e;)t.Pt.X<i.left&&(i.left=t.Pt.X),t.Pt.X>i.right&&(i.right=t.Pt.X),t.Pt.Y<i.top&&(i.top=t.Pt.Y),t.Pt.Y>i.bottom&&(i.bottom=t.Pt.Y),t=t.Next;return i},n.Clipper.PointInPolygon=function(t,e){var i=0,r=e.length;if(r<3)return 0;for(var s=e[0],l=1;l<=r;++l){var f=l===r?e[0]:e[l];if(f.Y===t.Y&&(f.X===t.X||s.Y===t.Y&&f.X>t.X==s.X<t.X))return-1;if(s.Y<t.Y!=f.Y<t.Y){if(s.X>=t.X)if(f.X>t.X)i=1-i;else{var m=(s.X-t.X)*(f.Y-t.Y)-(f.X-t.X)*(s.Y-t.Y);if(m===0)return-1;m>0==f.Y>s.Y&&(i=1-i)}else if(f.X>t.X){var m=(s.X-t.X)*(f.Y-t.Y)-(f.X-t.X)*(s.Y-t.Y);if(m===0)return-1;m>0==f.Y>s.Y&&(i=1-i)}}s=f}return i},n.Clipper.prototype.PointInPolygon=function(t,e){var i=0,r=e,s=t.X,l=t.Y,f=e.Pt.X,m=e.Pt.Y;do{e=e.Next;var d=e.Pt.X,g=e.Pt.Y;if(g===l&&(d===s||m===l&&d>s==f<s))return-1;if(m<l!=g<l){if(f>=s)if(d>s)i=1-i;else{var I=(f-s)*(g-l)-(d-s)*(m-l);if(I===0)return-1;I>0==g>m&&(i=1-i)}else if(d>s){var I=(f-s)*(g-l)-(d-s)*(m-l);if(I===0)return-1;I>0==g>m&&(i=1-i)}}f=d,m=g}while(r!==e);return i},n.Clipper.prototype.Poly2ContainsPoly1=function(t,e){var i=t;do{var r=this.PointInPolygon(i.Pt,e);if(r>=0)return r>0;i=i.Next}while(i!==t);return!0},n.Clipper.prototype.FixupFirstLefts1=function(t,e){for(var i,r,s=0,l=this.m_PolyOuts.length;s<l;s++)i=this.m_PolyOuts[s],r=n.Clipper.ParseFirstLeft(i.FirstLeft),i.Pts!==null&&r===t&&this.Poly2ContainsPoly1(i.Pts,e.Pts)&&(i.FirstLeft=e)},n.Clipper.prototype.FixupFirstLefts2=function(t,e){for(var i=e.FirstLeft,r,s,l=0,f=this.m_PolyOuts.length;l<f;l++)r=this.m_PolyOuts[l],!(r.Pts===null||r===e||r===t)&&(s=n.Clipper.ParseFirstLeft(r.FirstLeft),!(s!==i&&s!==t&&s!==e)&&(this.Poly2ContainsPoly1(r.Pts,t.Pts)?r.FirstLeft=t:this.Poly2ContainsPoly1(r.Pts,e.Pts)?r.FirstLeft=e:(r.FirstLeft===t||r.FirstLeft===e)&&(r.FirstLeft=i)))},n.Clipper.prototype.FixupFirstLefts3=function(t,e){for(var i,r,s=0,l=this.m_PolyOuts.length;s<l;s++)i=this.m_PolyOuts[s],r=n.Clipper.ParseFirstLeft(i.FirstLeft),i.Pts!==null&&r===t&&(i.FirstLeft=e)},n.Clipper.ParseFirstLeft=function(t){for(;t!==null&&t.Pts===null;)t=t.FirstLeft;return t},n.Clipper.prototype.JoinCommonEdges=function(){for(var t=0,e=this.m_Joins.length;t<e;t++){var i=this.m_Joins[t],r=this.GetOutRec(i.OutPt1.Idx),s=this.GetOutRec(i.OutPt2.Idx);if(!(r.Pts===null||s.Pts===null)&&!(r.IsOpen||s.IsOpen)){var l;r===s?l=r:this.OutRec1RightOfOutRec2(r,s)?l=s:this.OutRec1RightOfOutRec2(s,r)?l=r:l=this.GetLowermostRec(r,s),this.JoinPoints(i,r,s)&&(r===s?(r.Pts=i.OutPt1,r.BottomPt=null,s=this.CreateOutRec(),s.Pts=i.OutPt2,this.UpdateOutPtIdxs(s),this.Poly2ContainsPoly1(s.Pts,r.Pts)?(s.IsHole=!r.IsHole,s.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(s,r),(s.IsHole^this.ReverseSolution)==this.Area$1(s)>0&&this.ReversePolyPtLinks(s.Pts)):this.Poly2ContainsPoly1(r.Pts,s.Pts)?(s.IsHole=r.IsHole,r.IsHole=!s.IsHole,s.FirstLeft=r.FirstLeft,r.FirstLeft=s,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,s),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(s.IsHole=r.IsHole,s.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,s))):(s.Pts=null,s.BottomPt=null,s.Idx=r.Idx,r.IsHole=l.IsHole,l===s&&(r.FirstLeft=s.FirstLeft),s.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(s,r)))}}},n.Clipper.prototype.UpdateOutPtIdxs=function(t){var e=t.Pts;do e.Idx=t.Idx,e=e.Prev;while(e!==t.Pts)},n.Clipper.prototype.DoSimplePolygons=function(){for(var t=0;t<this.m_PolyOuts.length;){var e=this.m_PolyOuts[t++],i=e.Pts;if(!(i===null||e.IsOpen))do{for(var r=i.Next;r!==e.Pts;){if(n.IntPoint.op_Equality(i.Pt,r.Pt)&&r.Next!==i&&r.Prev!==i){var s=i.Prev,l=r.Prev;i.Prev=l,l.Next=i,r.Prev=s,s.Next=r,e.Pts=i;var f=this.CreateOutRec();f.Pts=r,this.UpdateOutPtIdxs(f),this.Poly2ContainsPoly1(f.Pts,e.Pts)?(f.IsHole=!e.IsHole,f.FirstLeft=e,this.m_UsingPolyTree&&this.FixupFirstLefts2(f,e)):this.Poly2ContainsPoly1(e.Pts,f.Pts)?(f.IsHole=e.IsHole,e.IsHole=!f.IsHole,f.FirstLeft=e.FirstLeft,e.FirstLeft=f,this.m_UsingPolyTree&&this.FixupFirstLefts2(e,f)):(f.IsHole=e.IsHole,f.FirstLeft=e.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(e,f)),r=i}r=r.Next}i=i.Next}while(i!==e.Pts)}},n.Clipper.Area=function(t){if(!Array.isArray(t))return 0;var e=t.length;if(e<3)return 0;for(var i=0,r=0,s=e-1;r<e;++r)i+=(t[s].X+t[r].X)*(t[s].Y-t[r].Y),s=r;return-i*.5},n.Clipper.prototype.Area=function(t){var e=t;if(t===null)return 0;var i=0;do i=i+(t.Prev.Pt.X+t.Pt.X)*(t.Prev.Pt.Y-t.Pt.Y),t=t.Next;while(t!==e);return i*.5},n.Clipper.prototype.Area$1=function(t){return this.Area(t.Pts)},n.Clipper.SimplifyPolygon=function(t,e){var i=new Array,r=new n.Clipper(0);return r.StrictlySimple=!0,r.AddPath(t,n.PolyType.ptSubject,!0),r.Execute(n.ClipType.ctUnion,i,e,e),i},n.Clipper.SimplifyPolygons=function(t,e){typeof e>"u"&&(e=n.PolyFillType.pftEvenOdd);var i=new Array,r=new n.Clipper(0);return r.StrictlySimple=!0,r.AddPaths(t,n.PolyType.ptSubject,!0),r.Execute(n.ClipType.ctUnion,i,e,e),i},n.Clipper.DistanceSqrd=function(t,e){var i=t.X-e.X,r=t.Y-e.Y;return i*i+r*r},n.Clipper.DistanceFromLineSqrd=function(t,e,i){var r=e.Y-i.Y,s=i.X-e.X,l=r*e.X+s*e.Y;return l=r*t.X+s*t.Y-l,l*l/(r*r+s*s)},n.Clipper.SlopesNearCollinear=function(t,e,i,r){return Math.abs(t.X-e.X)>Math.abs(t.Y-e.Y)?t.X>e.X==t.X<i.X?n.Clipper.DistanceFromLineSqrd(t,e,i)<r:e.X>t.X==e.X<i.X?n.Clipper.DistanceFromLineSqrd(e,t,i)<r:n.Clipper.DistanceFromLineSqrd(i,t,e)<r:t.Y>e.Y==t.Y<i.Y?n.Clipper.DistanceFromLineSqrd(t,e,i)<r:e.Y>t.Y==e.Y<i.Y?n.Clipper.DistanceFromLineSqrd(e,t,i)<r:n.Clipper.DistanceFromLineSqrd(i,t,e)<r},n.Clipper.PointsAreClose=function(t,e,i){var r=t.X-e.X,s=t.Y-e.Y;return r*r+s*s<=i},n.Clipper.ExcludeOp=function(t){var e=t.Prev;return e.Next=t.Next,t.Next.Prev=e,e.Idx=0,e},n.Clipper.CleanPolygon=function(t,e){typeof e>"u"&&(e=1.415);var i=t.length;if(i===0)return new Array;for(var r=new Array(i),s=0;s<i;++s)r[s]=new n.OutPt;for(var s=0;s<i;++s)r[s].Pt=t[s],r[s].Next=r[(s+1)%i],r[s].Next.Prev=r[s],r[s].Idx=0;for(var l=e*e,f=r[0];f.Idx===0&&f.Next!==f.Prev;)n.Clipper.PointsAreClose(f.Pt,f.Prev.Pt,l)?(f=n.Clipper.ExcludeOp(f),i--):n.Clipper.PointsAreClose(f.Prev.Pt,f.Next.Pt,l)?(n.Clipper.ExcludeOp(f.Next),f=n.Clipper.ExcludeOp(f),i-=2):n.Clipper.SlopesNearCollinear(f.Prev.Pt,f.Pt,f.Next.Pt,l)?(f=n.Clipper.ExcludeOp(f),i--):(f.Idx=1,f=f.Next);i<3&&(i=0);for(var m=new Array(i),s=0;s<i;++s)m[s]=new n.IntPoint1(f.Pt),f=f.Next;return r=null,m},n.Clipper.CleanPolygons=function(t,e){for(var i=new Array(t.length),r=0,s=t.length;r<s;r++)i[r]=n.Clipper.CleanPolygon(t[r],e);return i},n.Clipper.Minkowski=function(t,e,i,r){var s=r?1:0,l=t.length,f=e.length,m=new Array;if(i)for(var d=0;d<f;d++){for(var g=new Array(l),I=0,C=t.length,N=t[I];I<C;I++,N=t[I])g[I]=new n.IntPoint2(e[d].X+N.X,e[d].Y+N.Y);m.push(g)}else for(var d=0;d<f;d++){for(var g=new Array(l),I=0,C=t.length,N=t[I];I<C;I++,N=t[I])g[I]=new n.IntPoint2(e[d].X-N.X,e[d].Y-N.Y);m.push(g)}for(var O=new Array,d=0;d<f-1+s;d++)for(var I=0;I<l;I++){var F=new Array;F.push(m[d%f][I%l]),F.push(m[(d+1)%f][I%l]),F.push(m[(d+1)%f][(I+1)%l]),F.push(m[d%f][(I+1)%l]),n.Clipper.Orientation(F)||F.reverse(),O.push(F)}return O},n.Clipper.MinkowskiSum=function(t,e,i){if(e[0]instanceof Array){for(var s=e,f=new n.Paths,l=new n.Clipper,m=0;m<s.length;++m){var d=n.Clipper.Minkowski(t,s[m],!0,i);if(l.AddPaths(d,n.PolyType.ptSubject,!0),i){var r=n.Clipper.TranslatePath(s[m],t[0]);l.AddPath(r,n.PolyType.ptClip,!0)}}return l.Execute(n.ClipType.ctUnion,f,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),f}else{var r=e,s=n.Clipper.Minkowski(t,r,!0,i),l=new n.Clipper;return l.AddPaths(s,n.PolyType.ptSubject,!0),l.Execute(n.ClipType.ctUnion,s,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),s}},n.Clipper.TranslatePath=function(t,e){for(var i=new n.Path,r=0;r<t.length;r++)i.push(new n.IntPoint2(t[r].X+e.X,t[r].Y+e.Y));return i},n.Clipper.MinkowskiDiff=function(t,e){var i=n.Clipper.Minkowski(t,e,!1,!0),r=new n.Clipper;return r.AddPaths(i,n.PolyType.ptSubject,!0),r.Execute(n.ClipType.ctUnion,i,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),i},n.Clipper.PolyTreeToPaths=function(t){var e=new Array;return n.Clipper.AddPolyNodeToPaths(t,n.Clipper.NodeType.ntAny,e),e},n.Clipper.AddPolyNodeToPaths=function(t,e,i){var r=!0;switch(e){case n.Clipper.NodeType.ntOpen:return;case n.Clipper.NodeType.ntClosed:r=!t.IsOpen;break;default:break}t.m_polygon.length>0&&r&&i.push(t.m_polygon);for(var s=0,l=t.Childs(),f=l.length,m=l[s];s<f;s++,m=l[s])n.Clipper.AddPolyNodeToPaths(m,e,i)},n.Clipper.OpenPathsFromPolyTree=function(t){for(var e=new n.Paths,i=0,r=t.ChildCount();i<r;i++)t.Childs()[i].IsOpen&&e.push(t.Childs()[i].m_polygon);return e},n.Clipper.ClosedPathsFromPolyTree=function(t){var e=new n.Paths;return n.Clipper.AddPolyNodeToPaths(t,n.Clipper.NodeType.ntClosed,e),e},ye(n.Clipper,n.ClipperBase),n.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},n.ClipperOffset=function(t,e){typeof t>"u"&&(t=2),typeof e>"u"&&(e=n.ClipperOffset.def_arc_tolerance),this.m_destPolys=new n.Paths,this.m_srcPoly=new n.Path,this.m_destPoly=new n.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 n.IntPoint0,this.m_polyNodes=new n.PolyNode,this.MiterLimit=t,this.ArcTolerance=e,this.m_lowest.X=-1},n.ClipperOffset.two_pi=6.28318530717959,n.ClipperOffset.def_arc_tolerance=.25,n.ClipperOffset.prototype.Clear=function(){n.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},n.ClipperOffset.Round=n.Clipper.Round,n.ClipperOffset.prototype.AddPath=function(t,e,i){var r=t.length-1;if(!(r<0)){var s=new n.PolyNode;if(s.m_jointype=e,s.m_endtype=i,i===n.EndType.etClosedLine||i===n.EndType.etClosedPolygon)for(;r>0&&n.IntPoint.op_Equality(t[0],t[r]);)r--;s.m_polygon.push(t[0]);for(var l=0,f=0,m=1;m<=r;m++)n.IntPoint.op_Inequality(s.m_polygon[l],t[m])&&(l++,s.m_polygon.push(t[m]),(t[m].Y>s.m_polygon[f].Y||t[m].Y===s.m_polygon[f].Y&&t[m].X<s.m_polygon[f].X)&&(f=l));if(!(i===n.EndType.etClosedPolygon&&l<2)&&(this.m_polyNodes.AddChild(s),i===n.EndType.etClosedPolygon))if(this.m_lowest.X<0)this.m_lowest=new n.IntPoint2(this.m_polyNodes.ChildCount()-1,f);else{var d=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(s.m_polygon[f].Y>d.Y||s.m_polygon[f].Y===d.Y&&s.m_polygon[f].X<d.X)&&(this.m_lowest=new n.IntPoint2(this.m_polyNodes.ChildCount()-1,f))}}},n.ClipperOffset.prototype.AddPaths=function(t,e,i){for(var r=0,s=t.length;r<s;r++)this.AddPath(t[r],e,i)},n.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!n.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var t=0;t<this.m_polyNodes.ChildCount();t++){var e=this.m_polyNodes.Childs()[t];(e.m_endtype===n.EndType.etClosedPolygon||e.m_endtype===n.EndType.etClosedLine&&n.Clipper.Orientation(e.m_polygon))&&e.m_polygon.reverse()}else for(var t=0;t<this.m_polyNodes.ChildCount();t++){var e=this.m_polyNodes.Childs()[t];e.m_endtype===n.EndType.etClosedLine&&!n.Clipper.Orientation(e.m_polygon)&&e.m_polygon.reverse()}},n.ClipperOffset.GetUnitNormal=function(t,e){var i=e.X-t.X,r=e.Y-t.Y;if(i===0&&r===0)return new n.DoublePoint2(0,0);var s=1/Math.sqrt(i*i+r*r);return i*=s,r*=s,new n.DoublePoint2(r,-i)},n.ClipperOffset.prototype.DoOffset=function(t){if(this.m_destPolys=new Array,this.m_delta=t,n.ClipperBase.near_zero(t)){for(var e=0;e<this.m_polyNodes.ChildCount();e++){var i=this.m_polyNodes.Childs()[e];i.m_endtype===n.EndType.etClosedPolygon&&this.m_destPolys.push(i.m_polygon)}return}this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5;var r;this.ArcTolerance<=0?r=n.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(t)*n.ClipperOffset.def_arc_tolerance?r=Math.abs(t)*n.ClipperOffset.def_arc_tolerance:r=this.ArcTolerance;var s=3.14159265358979/Math.acos(1-r/Math.abs(t));this.m_sin=Math.sin(n.ClipperOffset.two_pi/s),this.m_cos=Math.cos(n.ClipperOffset.two_pi/s),this.m_StepsPerRad=s/n.ClipperOffset.two_pi,t<0&&(this.m_sin=-this.m_sin);for(var e=0;e<this.m_polyNodes.ChildCount();e++){var i=this.m_polyNodes.Childs()[e];this.m_srcPoly=i.m_polygon;var l=this.m_srcPoly.length;if(!(l===0||t<=0&&(l<3||i.m_endtype!==n.EndType.etClosedPolygon))){if(this.m_destPoly=new Array,l===1){if(i.m_jointype===n.JoinType.jtRound)for(var f=1,m=0,d=1;d<=s;d++){this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+f*t),n.ClipperOffset.Round(this.m_srcPoly[0].Y+m*t)));var g=f;f=f*this.m_cos-this.m_sin*m,m=g*this.m_sin+m*this.m_cos}else for(var f=-1,m=-1,d=0;d<4;++d)this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+f*t),n.ClipperOffset.Round(this.m_srcPoly[0].Y+m*t))),f<0?f=1:m<0?m=1:f=-1;this.m_destPolys.push(this.m_destPoly);continue}this.m_normals.length=0;for(var d=0;d<l-1;d++)this.m_normals.push(n.ClipperOffset.GetUnitNormal(this.m_srcPoly[d],this.m_srcPoly[d+1]));if(i.m_endtype===n.EndType.etClosedLine||i.m_endtype===n.EndType.etClosedPolygon?this.m_normals.push(n.ClipperOffset.GetUnitNormal(this.m_srcPoly[l-1],this.m_srcPoly[0])):this.m_normals.push(new n.DoublePoint1(this.m_normals[l-2])),i.m_endtype===n.EndType.etClosedPolygon){for(var I=l-1,d=0;d<l;d++)I=this.OffsetPoint(d,I,i.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(i.m_endtype===n.EndType.etClosedLine){for(var I=l-1,d=0;d<l;d++)I=this.OffsetPoint(d,I,i.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;for(var C=this.m_normals[l-1],d=l-1;d>0;d--)this.m_normals[d]=new n.DoublePoint2(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new n.DoublePoint2(-C.X,-C.Y),I=0;for(var d=l-1;d>=0;d--)I=this.OffsetPoint(d,I,i.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var I=0,d=1;d<l-1;++d)I=this.OffsetPoint(d,I,i.m_jointype);var N;if(i.m_endtype===n.EndType.etOpenButt){var d=l-1;N=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[d].X+this.m_normals[d].X*t),n.ClipperOffset.Round(this.m_srcPoly[d].Y+this.m_normals[d].Y*t)),this.m_destPoly.push(N),N=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[d].X-this.m_normals[d].X*t),n.ClipperOffset.Round(this.m_srcPoly[d].Y-this.m_normals[d].Y*t)),this.m_destPoly.push(N)}else{var d=l-1;I=l-2,this.m_sinA=0,this.m_normals[d]=new n.DoublePoint2(-this.m_normals[d].X,-this.m_normals[d].Y),i.m_endtype===n.EndType.etOpenSquare?this.DoSquare(d,I):this.DoRound(d,I)}for(var d=l-1;d>0;d--)this.m_normals[d]=new n.DoublePoint2(-this.m_normals[d-1].X,-this.m_normals[d-1].Y);this.m_normals[0]=new n.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),I=l-1;for(var d=I-1;d>0;--d)I=this.OffsetPoint(d,I,i.m_jointype);i.m_endtype===n.EndType.etOpenButt?(N=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*t),n.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*t)),this.m_destPoly.push(N),N=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*t),n.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*t)),this.m_destPoly.push(N)):(I=1,this.m_sinA=0,i.m_endtype===n.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}},n.ClipperOffset.prototype.Execute=function(){var t=arguments,e=t[0]instanceof n.PolyTree;if(e){var i=t[0],r=t[1];i.Clear(),this.FixOrientations(),this.DoOffset(r);var s=new n.Clipper(0);if(s.AddPaths(this.m_destPolys,n.PolyType.ptSubject,!0),r>0)s.Execute(n.ClipType.ctUnion,i,n.PolyFillType.pftPositive,n.PolyFillType.pftPositive);else{var l=n.Clipper.GetBounds(this.m_destPolys),f=new n.Path;if(f.push(new n.IntPoint2(l.left-10,l.bottom+10)),f.push(new n.IntPoint2(l.right+10,l.bottom+10)),f.push(new n.IntPoint2(l.right+10,l.top-10)),f.push(new n.IntPoint2(l.left-10,l.top-10)),s.AddPath(f,n.PolyType.ptSubject,!0),s.ReverseSolution=!0,s.Execute(n.ClipType.ctUnion,i,n.PolyFillType.pftNegative,n.PolyFillType.pftNegative),i.ChildCount()===1&&i.Childs()[0].ChildCount()>0){var m=i.Childs()[0];i.Childs()[0]=m.Childs()[0],i.Childs()[0].m_Parent=i;for(var d=1;d<m.ChildCount();d++)i.AddChild(m.Childs()[d])}else i.Clear()}}else{var i=t[0],r=t[1];n.Clear(i),this.FixOrientations(),this.DoOffset(r);var s=new n.Clipper(0);if(s.AddPaths(this.m_destPolys,n.PolyType.ptSubject,!0),r>0)s.Execute(n.ClipType.ctUnion,i,n.PolyFillType.pftPositive,n.PolyFillType.pftPositive);else{var l=n.Clipper.GetBounds(this.m_destPolys),f=new n.Path;f.push(new n.IntPoint2(l.left-10,l.bottom+10)),f.push(new n.IntPoint2(l.right+10,l.bottom+10)),f.push(new n.IntPoint2(l.right+10,l.top-10)),f.push(new n.IntPoint2(l.left-10,l.top-10)),s.AddPath(f,n.PolyType.ptSubject,!0),s.ReverseSolution=!0,s.Execute(n.ClipType.ctUnion,i,n.PolyFillType.pftNegative,n.PolyFillType.pftNegative),i.length>0&&i.splice(0,1)}}},n.ClipperOffset.prototype.OffsetPoint=function(t,e,i){if(this.m_sinA=this.m_normals[e].X*this.m_normals[t].Y-this.m_normals[t].X*this.m_normals[e].Y,Math.abs(this.m_sinA*this.m_delta)<1){var r=this.m_normals[e].X*this.m_normals[t].X+this.m_normals[t].Y*this.m_normals[e].Y;if(r>0)return this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[e].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[e].Y*this.m_delta))),e}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 n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[e].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[e].Y*this.m_delta))),this.m_destPoly.push(new n.IntPoint1(this.m_srcPoly[t])),this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)));else switch(i){case n.JoinType.jtMiter:{var s=1+(this.m_normals[t].X*this.m_normals[e].X+this.m_normals[t].Y*this.m_normals[e].Y);s>=this.m_miterLim?this.DoMiter(t,e,s):this.DoSquare(t,e);break}case n.JoinType.jtSquare:this.DoSquare(t,e);break;case n.JoinType.jtRound:this.DoRound(t,e);break}return e=t,e},n.ClipperOffset.prototype.DoSquare=function(t,e){var i=Math.tan(Math.atan2(this.m_sinA,this.m_normals[e].X*this.m_normals[t].X+this.m_normals[e].Y*this.m_normals[t].Y)/4);this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[e].X-this.m_normals[e].Y*i)),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[e].Y+this.m_normals[e].X*i)))),this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[t].X+this.m_normals[t].Y*i)),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[t].Y-this.m_normals[t].X*i))))},n.ClipperOffset.prototype.DoMiter=function(t,e,i){var r=this.m_delta/i;this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+(this.m_normals[e].X+this.m_normals[t].X)*r),n.ClipperOffset.Round(this.m_srcPoly[t].Y+(this.m_normals[e].Y+this.m_normals[t].Y)*r)))},n.ClipperOffset.prototype.DoRound=function(t,e){for(var i=Math.atan2(this.m_sinA,this.m_normals[e].X*this.m_normals[t].X+this.m_normals[e].Y*this.m_normals[t].Y),r=Math.max(n.Cast_Int32(n.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(i))),1),s=this.m_normals[e].X,l=this.m_normals[e].Y,f,m=0;m<r;++m)this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+s*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[t].Y+l*this.m_delta))),f=s,s=s*this.m_cos-this.m_sin*l,l=f*this.m_sin+l*this.m_cos;this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)))},n.Error=function(t){try{throw new Error(t)}catch(e){alert(e.message)}},n.JS={},n.JS.AreaOfPolygon=function(t,e){return e||(e=1),n.Clipper.Area(t)/(e*e)},n.JS.AreaOfPolygons=function(t,e){e||(e=1);for(var i=0,r=0;r<t.length;r++)i+=n.Clipper.Area(t[r]);return i/(e*e)},n.JS.BoundsOfPath=function(t,e){return n.JS.BoundsOfPaths([t],e)},n.JS.BoundsOfPaths=function(t,e){e||(e=1);var i=n.Clipper.GetBounds(t);return i.left/=e,i.bottom/=e,i.right/=e,i.top/=e,i},n.JS.Clean=function(r,e){if(!(r instanceof Array))return[];var i=r[0]instanceof Array,r=n.JS.Clone(r);if(typeof e!="number"||e===null)return n.Error("Delta is not a number in Clean()."),r;if(r.length===0||r.length===1&&r[0].length===0||e<0)return r;i||(r=[r]);for(var s=r.length,l,f,m,d,g,I,C,N=[],O=0;O<s;O++)if(f=r[O],l=f.length,l!==0){if(l<3){m=f,N.push(m);continue}for(m=f,d=e*e,g=f[0],I=1,C=1;C<l;C++)(f[C].X-g.X)*(f[C].X-g.X)+(f[C].Y-g.Y)*(f[C].Y-g.Y)<=d||(m[I]=f[C],g=f[C],I++);g=f[I-1],(f[0].X-g.X)*(f[0].X-g.X)+(f[0].Y-g.Y)*(f[0].Y-g.Y)<=d&&I--,I<l&&m.splice(I,l-I),m.length&&N.push(m)}return!i&&N.length?N=N[0]:!i&&N.length===0?N=[]:i&&N.length===0&&(N=[[]]),N},n.JS.Clone=function(t){if(!(t instanceof Array))return[];if(t.length===0)return[];if(t.length===1&&t[0].length===0)return[[]];var e=t[0]instanceof Array;e||(t=[t]);var i=t.length,r,s,l,f,m=new Array(i);for(s=0;s<i;s++){for(r=t[s].length,f=new Array(r),l=0;l<r;l++)f[l]={X:t[s][l].X,Y:t[s][l].Y};m[s]=f}return e||(m=m[0]),m},n.JS.Lighten=function(t,e){if(!(t instanceof Array))return[];if(typeof e!="number"||e===null)return n.Error("Tolerance is not a number in Lighten()."),n.JS.Clone(t);if(t.length===0||t.length===1&&t[0].length===0||e<0)return n.JS.Clone(t);var i=t[0]instanceof Array;i||(t=[t]);var r,s,l,f,m,d,g,I,C,N,O,F,W,J,st,ht,_t,Ei=t.length,Yi=e*e,Tt=[];for(r=0;r<Ei;r++)if(l=t[r],d=l.length,d!==0){for(f=0;f<1e6;f++){for(m=[],d=l.length,l[d-1].X!==l[0].X||l[d-1].Y!==l[0].Y?(F=1,l.push({X:l[0].X,Y:l[0].Y}),d=l.length):F=0,O=[],s=0;s<d-2;s++)g=l[s],C=l[s+1],I=l[s+2],ht=g.X,_t=g.Y,W=I.X-ht,J=I.Y-_t,(W!==0||J!==0)&&(st=((C.X-ht)*W+(C.Y-_t)*J)/(W*W+J*J),st>1?(ht=I.X,_t=I.Y):st>0&&(ht+=W*st,_t+=J*st)),W=C.X-ht,J=C.Y-_t,N=W*W+J*J,N<=Yi&&(O[s+1]=1,s++);for(m.push({X:l[0].X,Y:l[0].Y}),s=1;s<d-1;s++)O[s]||m.push({X:l[s].X,Y:l[s].Y});if(m.push({X:l[d-1].X,Y:l[d-1].Y}),F&&l.pop(),O.length)l=m;else break}d=m.length,m[d-1].X===m[0].X&&m[d-1].Y===m[0].Y&&m.pop(),m.length>2&&Tt.push(m)}return i||(Tt=Tt[0]),typeof Tt>"u"&&(Tt=[]),Tt},n.JS.PerimeterOfPath=function(t,e,i){if(typeof t>"u")return 0;var r=Math.sqrt,s=0,l,f,m=0,d=0,g=0,I=0,C=t.length;if(C<2)return 0;for(e&&(t[C]=t[0],C++);--C;)l=t[C],m=l.X,d=l.Y,f=t[C-1],g=f.X,I=f.Y,s+=r((m-g)*(m-g)+(d-I)*(d-I));return e&&t.pop(),s/i},n.JS.PerimeterOfPaths=function(t,e,i){i||(i=1);for(var r=0,s=0;s<t.length;s++)r+=n.JS.PerimeterOfPath(t[s],e,i);return r},n.JS.ScaleDownPath=function(t,e){var i,r;for(e||(e=1),i=t.length;i--;)r=t[i],r.X=r.X/e,r.Y=r.Y/e},n.JS.ScaleDownPaths=function(t,e){var i,r,s;for(e||(e=1),i=t.length;i--;)for(r=t[i].length;r--;)s=t[i][r],s.X=s.X/e,s.Y=s.Y/e},n.JS.ScaleUpPath=function(t,e){var i,r,s=Math.round;for(e||(e=1),i=t.length;i--;)r=t[i],r.X=s(r.X*e),r.Y=s(r.Y*e)},n.JS.ScaleUpPaths=function(t,e){var i,r,s,l=Math.round;for(e||(e=1),i=t.length;i--;)for(r=t[i].length;r--;)s=t[i][r],s.X=l(s.X*e),s.Y=l(s.Y*e)},n.ExPolygons=function(){return[]},n.ExPolygon=function(){this.outer=null,this.holes=null},n.JS.AddOuterPolyNodeToExPolygons=function(t,e){var i=new n.ExPolygon;i.outer=t.Contour();var r=t.Childs(),s=r.length;i.holes=new Array(s);var l,f,m,d,g,I;for(m=0;m<s;m++)for(l=r[m],i.holes[m]=l.Contour(),d=0,g=l.Childs(),I=g.length;d<I;d++)f=g[d],n.JS.AddOuterPolyNodeToExPolygons(f,e);e.push(i)},n.JS.ExPolygonsToPaths=function(t){var e,i,r,s,l=new n.Paths;for(e=0,r=t.length;e<r;e++)for(l.push(t[e].outer),i=0,s=t[e].holes.length;i<s;i++)l.push(t[e].holes[i]);return l},n.JS.PolyTreeToExPolygons=function(t){var e=new n.ExPolygons,i,r,s,l;for(r=0,s=t.Childs(),l=s.length;r<l;r++)i=s[r],n.JS.AddOuterPolyNodeToExPolygons(i,e);return e}})()});function Et(n){let o=new Uint8Array(128);for(let p=0;p<64;p++)o[hr.charCodeAt(p)]=p;let a=n.replace(/=+$/,"").length,h=new Uint8ClampedArray(Math.floor(a*3/4)),u=0;for(let p=0;p<a;p+=4){let y=o[n.charCodeAt(p)]<<18|o[n.charCodeAt(p+1)]<<12|(p+2<a?o[n.charCodeAt(p+2)]:0)<<6|(p+3<a?o[n.charCodeAt(p+3)]:0);h[u++]=y>>16,u<h.length&&(h[u++]=y>>8&255),u<h.length&&(h[u++]=y&255)}return h}var hr,Vt=Yt(()=>{"use strict";hr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"});function Qe(n){if(!n.startsWith("kzm1:"))return"format";let o=Et(n.slice(5));if(o.length<8)return"damaged";let a=new DataView(o.buffer,o.byteOffset,o.byteLength),h=a.getUint32(0,!0),u=a.getUint32(4,!0);if(8+h*12+u*12!==o.length)return"damaged";let p=new Float32Array(h*3),y=new Uint32Array(u*3),x=8;for(let c=0;c<p.length;c++,x+=4)p[c]=a.getFloat32(x,!0);for(let c=0;c<y.length;c++,x+=4)y[c]=a.getUint32(x,!0);return y.some(c=>c>=h)?"damaged":{pos:p,tri:y}}var tn=Yt(()=>{"use strict";Vt()});function en(n){let o=Qe(n);if(o==="format")throw new zt(b("Unbekanntes Modellformat."));if(o==="damaged")throw new zt(b("Die Modelldaten sind besch\xE4digt."));return o}var zt,nn=Yt(()=>{"use strict";vt();Vt();tn();zt=class extends Error{}});vt();function Ct(n,o){if(!Number.isFinite(n)||!Number.isFinite(o)||n<=0||o<=0)throw new Error("finger-length-invalid");let a=Math.floor(n/o),h=Math.max(3,a%2?a:a-1);if(h>5001)throw new Error("too-many-fingers");return h}function Ht(n,o){if(!Number.isFinite(n)||!Number.isFinite(o)||n<=0||o<=0)throw new Error("finger-length-invalid");let a=Math.floor(n/o),h=Math.max(1,a%2?a:a-1);if(h>5001)throw new Error("too-many-fingers");return h}function Bt(n,o,a,h,u=!1){let p=u?Ct(n,o):Ht(n,o),y=n/p;return Array.from({length:p},(x,c)=>({from:c*y,to:(c+1)*y,offset:c%2===0===h?a:0}))}function Ce(n,o,a,h,u){let p=n-a*(h?2:1),y=Ct(p,o),x=p/y;return Array.from({length:y},(c,P)=>({from:P===0?u?0:a:a+P*x,to:P===y-1?h&&!u?n-a:n:a+(P+1)*x,offset:P%2===0===u?a:0}))}function dt(n,o,a,h=!1,u=0,p=0){let y=o.map(c=>({...c}));for(let c=0;c+1<y.length;c++){let P=y[c].offset===p?-u/4:u/4;y[c].to+=P,y[c+1].from+=P}if(y.some(c=>c.to-c.from<=1e-7))throw new Error("clearance-too-large");let x=y.flatMap(c=>[a(c.from,c.offset),a(c.to,c.offset)]);n.push(...h?x.reverse():x)}function Vi(n){let o=[];for(let a of n)(!o.length||Math.hypot(a.x-o[o.length-1].x,a.y-o[o.length-1].y)>1e-7)&&o.push(a);return o.length>1&&Math.hypot(o[0].x-o[o.length-1].x,o[0].y-o[o.length-1].y)<=1e-7&&o.pop(),o}function Ie(n){let{width:o,depth:a,height:h,thickness:u,finger:p}=n;if(![o,a,h,u,p].every(Z=>Number.isFinite(Z)&&Z>0)||o<=2*u||a<=2*u||h<=2*u)throw new Error("outer-size-invalid");let y=n.clearance??0;if(!Number.isFinite(y))throw new Error("clearance-invalid");let x=n.jointLayout==="legacy",c=Bt(o-2*u,p,u,!x,x),P=Bt(a-2*u,p,u,!x,x),v=x?Bt(h,p,u,!0,!0):Ce(h,p,u,n.top==="closed",!0),w=x?Bt(h,p,u,!1,!0):Ce(h,p,u,n.top==="closed",!1),A=[];dt(A,c,(Z,D)=>({x:u+Z,y:u-D}),!1,y,u),x||A.push({x:o-u,y:u}),dt(A,P,(Z,D)=>({x:o-u+D,y:u+Z}),!1,y,u),x||A.push({x:o-u,y:a-u}),dt(A,c,(Z,D)=>({x:u+Z,y:a-u+D}),!0,y,u),x||A.push({x:u,y:a-u}),dt(A,P,(Z,D)=>({x:u-D,y:u+Z}),!0,y,u),x||A.push({x:u,y:u});function T(Z,D,$){let H=[];dt(H,D,(R,V)=>({x:u+R,y:V}),!1,y,0);let Q=!x&&$[0].offset===u;return Q&&H.push({x:Z-u,y:0}),dt(H,$,(R,V)=>({x:Z-u+V,y:R}),!1,y,u),n.top==="closed"?(Q&&H.push({x:Z-u,y:h}),dt(H,D,(R,V)=>({x:u+R,y:h-V}),!0,y,0),Q&&H.push({x:u,y:h})):H.push({x:u,y:h}),dt(H,$,(R,V)=>({x:u-V,y:R}),!0,y,u),Q&&H.push({x:u,y:0}),H}let _=T(o,c,v),S=T(a,P,w),X=10,k=(Z,D,$,H,Q,R)=>({key:Z,at:Q,subs:[{closed:!0,nodes:Vi(D).map(V=>({x:V.x-$/2,y:R?H/2-V.y:V.y-H/2}))}]});if(x&&n.top!=="closed")return[k("bottom",A,o,a,{x:o/2,y:a/2},!1),k("front",_,o,h,{x:o+X+o/2,y:h/2},!0),k("back",_,o,h,{x:2*(o+X)+o/2,y:h/2},!0),k("left",S,a,h,{x:a/2,y:a+X+h/2},!0),k("right",S,a,h,{x:a+X+a/2,y:a+X+h/2},!0)];let j=[[{key:"bottom",points:A,a:o,b:a,wall:!1},{key:"front",points:_,a:o,b:h,wall:!0},{key:"back",points:_,a:o,b:h,wall:!0}],[...n.top==="closed"?[{key:"top",points:A,a:o,b:a,wall:!1}]:[],{key:"left",points:S,a,b:h,wall:!0},{key:"right",points:S,a,b:h,wall:!0}]],Y=j.map(Z=>Math.max(...Z.map(D=>D.b))),K=Y[0]+X+Y[1];return j.flatMap((Z,D)=>{let H=-(Z.reduce((R,V)=>R+V.a,0)+X*(Z.length-1))/2,Q=-K/2+(D===0?0:Y[0]+X);return Z.map(R=>{let V=k(R.key,R.points,R.a,R.b,{x:H+R.a/2,y:Q+R.b/2},R.wall);return H+=R.a+X,V})})}var it=n=>{throw new Error(n)};function we(n){let o=0,a=n.replace(/\s+/g,"").toLowerCase(),h=c=>a[o]===c?(o++,!0):!1;function u(){if(h("+"))return u();if(h("-")){let w=u();return{...w,value:-w.value}}if(h("(")){let w=y();return h(")")||it("expr-bracket"),w}let c=/^(?:\d+(?:[.,]\d*)?|[.,]\d+)/.exec(a.slice(o));if(!c)return it("expr-invalid");o+=c[0].length;let P=Number(c[0].replace(",",".")),v=0;return a.slice(o,o+2)==="mm"&&(o+=2,v=1),{value:P,dimension:v}}function p(){let c=u();for(;a[o]==="*"||a[o]==="/";){let P=a[o++],v=u();P==="/"&&v.value===0&&it("expr-div-zero");let w=P==="*"?c.dimension+v.dimension:c.dimension-v.dimension;w!==0&&w!==1&&it("expr-units"),c={value:P==="*"?c.value*v.value:c.value/v.value,dimension:w}}return c}function y(){let c=p();for(;a[o]==="+"||a[o]==="-";){let P=a[o++],v=p(),w=c.dimension===1||v.dimension===1?1:0;c={value:P==="+"?c.value+v.value:c.value-v.value,dimension:w}}return c}let x=y();return o!==a.length&&it("expr-invalid"),(!Number.isFinite(x.value)||x.value<=0)&&it("ratio-not-positive"),x}function Lt(n){return(!Number.isInteger(n)||n<1||n>100)&&it("compartments-range"),Array(n).fill("1").join(":")}function _e(n,o){return(o.trim()||Lt(n)).split(":").map(a=>we(a).dimension===1?a.trim():null)}function ot(n,o,a,h){let u=Lt(a);(!Number.isFinite(n)||!Number.isFinite(o)||n<=0||o<=0)&&it("size-invalid"),h.length>2e3&&it("input-too-long");let p=n-2*o-(a-1)*o;p<=0&&it("no-space");let y=(h.trim()?h:u).split(":");y.length!==a&&it("ratio-count");let x=y.map(we),c=x.reduce((S,X)=>S+(X.dimension===1?X.value:0),0),P=x.reduce((S,X)=>S+(X.dimension===0?X.value:0),0);(!Number.isFinite(c)||!Number.isFinite(P))&&it("ratio-too-large");let v=p-c,w=1e-9*Math.max(1,p);P>0&&v<=0&&it("fixed-no-space"),P===0&&Math.abs(v)>w&&it("fixed-mismatch");let A=x.map(S=>S.dimension===1?S.value:v*(S.value/P));A.some(S=>!Number.isFinite(S)||S<=0)&&it("gap-not-positive");let T=[],_=o;for(let S=0;S<A.length-1;S++)_+=A[S],T.push(_+o/2),_+=o;return{gaps:A,centres:T}}function Te(n,o,a){if(!n||!Number.isInteger(o)||!Number.isInteger(a)||a<1||a>20)return null;let h=n.split(":");if(h.length!==o||h.some(y=>!y.trim()))return null;let u=h.slice(a).filter(y=>y.trim()!=="1"),p=h.slice(0,a);for(;p.length<a;)p.push("1");return{text:p.join(":"),removed:u}}vt();vt();var zi={ne:["planOp","none"]},Le=[{key:"planOp",type:"enum",label:b("Fachwerkzeug"),def:"none",resetOnNew:!0,options:[["none",b("Aus")],["split",b("Ein Fach gleichm\xE4\xDFig unterteilen")],["reserve",b("Ma\xDFfach einf\xFCgen")],["center",b("Eine Trennwand zentrieren")],["shift",b("Trennwandreihe verschieben")],["mirror",b("Fachfolge spiegeln")],["copy",b("Verteilung auf die andere Achse \xFCbertragen")],["gradient",b("Fachweiten stufenweise \xE4ndern")]]},{key:"planAxis",type:"enum",label:b("Arbeitsachse"),def:"X",showIf:zi,options:[["X",b("Breite (X)")],["Y",b("Tiefe (Y)")]]},{key:"planGap",type:"int",label:b("Fachnummer"),title:b("Ab links (X) oder vorne (Y) z\xE4hlen. Das Fach kann auch in der Draufsicht gew\xE4hlt werden."),def:1,min:1,max:20,showIf:{in:["planOp",["split","reserve"]]}},{key:"planDivider",type:"int",label:b("Trennwandnummer"),def:1,min:1,max:19,showIf:{eq:["planOp","center"]}},{key:"planPieces",type:"int",label:b("Teilf\xE4cher"),def:2,min:2,max:20,showIf:{eq:["planOp","split"]}},{key:"planWidth",type:"length",label:b("Freies Ma\xDF des neuen Fachs"),def:25,min:.01,max:3e3,showIf:{eq:["planOp","reserve"]}},{key:"planEnd",type:"enum",label:b("Kante im Fach"),def:"first",showIf:{eq:["planOp","reserve"]},options:[["first",b("Links / vorne")],["last",b("Rechts / hinten")]]},{key:"planShift",type:"length",label:b("Verschiebung der Reihe"),def:5,min:-3e3,max:3e3,showIf:{eq:["planOp","shift"]}},{key:"planStep",type:"length",label:b("Differenz je freiem Fach"),def:5,min:-3e3,max:3e3,showIf:{eq:["planOp","gradient"]}}],Jt=n=>Number(n.toFixed(9)),Mt=class extends Error{},yt=n=>{throw new Mt(n)},jt=()=>yt(b("Kein freier Platz f\xFCr die F\xE4cher.")),Xt=()=>yt(b("Ein festes Fachma\xDF verhindert diese \xC4nderung. Die Verteilung in mm pr\xFCfen.")),Se=n=>n.reduce((o,a)=>o+a,0);function Ft(n){return n.planAxis==="Y"?"Y":"X"}function Ne(n,o,a){let h=Number(o==="X"?n.width:n.depth),u=Number(n.thickness),p=Number(n["compartments"+o]),y=String(n["ratios"+o]??""),{gaps:x}=ot(h,u,p,y);return{axis:o,length:h,thickness:u,gaps:x,locks:_e(p,y),ids:a.slice()}}function Ae(n,o,a){let h=new Set(n),u=Math.max(0,...n)+1,p=[];for(;p.length<a;)u>=1e9&&(u=1),h.has(u)||(p.push(u),h.add(u)),u++;n.splice(o,0,...p)}function Xe(n,o){let a=Ft(n),h=Ne(n,a,o(a)),{gaps:u,locks:p,ids:y,thickness:x}=h,c=n.planOp;if(c==="split"||c==="reserve"){let v=Number(n.planGap)-1;(!Number.isInteger(v)||v<0||v>=u.length)&&yt(b("Eine vorhandene Fachnummer w\xE4hlen.")),p[v]&&Xt();let w=c==="reserve"?2:Number(n.planPieces);(!Number.isInteger(w)||w<2||u.length+w-1>20)&&yt(b("Maximal 20 F\xE4cher pro Richtung."));let A=u[v]-(w-1)*x,T=Array(w).fill(A/w),_=Array(w).fill(null);if(c==="reserve"){let S=n.planEnd==="last"?1:0;T[S]=Number(n.planWidth),T[1-S]=A-T[S],_[S]=Jt(T[S])+"mm"}u.splice(v,1,...T),p.splice(v,1,..._),Ae(y,v,w-1)}else if(c==="center"){let v=Number(n.planDivider)-1;(!Number.isInteger(v)||v<0||v>=y.length)&&yt(b("Eine vorhandene Trennwandnummer w\xE4hlen.")),(p[v]||p[v+1])&&Math.abs(u[v]-u[v+1])>1e-8&&Xt(),u[v]=u[v+1]=(u[v]+u[v+1])/2}else if(c==="shift"){y.length||yt(b("Eine vorhandene Trennwandnummer w\xE4hlen."));let v=Number(n.planShift),w=u.length-1;Number.isFinite(v)||jt(),v&&(p[0]||p[w])&&Xt(),u[0]+=v,u[w]-=v}else if(c==="mirror"){u.reverse(),p.reverse(),y.reverse();let v=String(n["ratios"+a]??"").trim();return{["ratios"+a]:v?v.split(":").reverse().join(":"):"",["dividerIds"+a]:y.join(",")}}else if(c==="copy"){let v=a==="X"?"Y":"X";h=Ne(n,v,o(v)),h.gaps.length!==u.length&&h.locks.some(Boolean)&&Xt();let w=h.length-(u.length+1)*x;w<=0&&jt();let A=w/Se(u),T=u.map(_=>_*A);h.locks.some((_,S)=>_&&Math.abs(T[S]-h.gaps[S])>1e-7)&&Xt(),h.gaps=T,h.locks=T.map((_,S)=>h.locks[S]??null),h.ids.length<y.length?Ae(h.ids,h.ids.length,y.length-h.ids.length):h.ids.length=y.length}else if(c==="gradient"){let v=u.map((T,_)=>_).filter(T=>!p[T]);v.length<2&&yt(b("Mindestens zwei ver\xE4nderliche F\xE4cher w\xE4hlen."));let w=Number(n.planStep),A=Se(v.map(T=>u[T]))/v.length-w*(v.length-1)/2;v.forEach((T,_)=>{u[T]=A+_*w})}else yt(b("Fachwerkzeug w\xE4hlen."));h.gaps.some(v=>!Number.isFinite(v)||Jt(v)<=0)&&jt();let P=h.gaps.map((v,w)=>h.locks[w]??String(Jt(v))).join(":");return ot(h.length,x,h.gaps.length,P),{["compartments"+h.axis]:h.gaps.length,["ratios"+h.axis]:P,["dividerIds"+h.axis]:h.ids.join(",")}}var Me=["X","Y"],Kt=(n,o)=>Number(o==="X"?n.width:n.depth),Oe=n=>Number(n.toFixed(6));function pt(n,o){let a=Math.max(0,Math.min(19,Number(n[`compartments${o}`])-1)),h=String(n[`dividerIds${o}`]??"").split(",").slice(0,a).map(Number),u=h.every(y=>Number.isSafeInteger(y)&&y>0&&y<1e9)&&new Set(h).size===h.length?h:[],p=Math.max(0,...u)+1;for(;u.length<a;)u.push(p++);return u}function It(n,o){let a=Number(n["compartments"+o]);return ot(Kt(n,o),Number(n.thickness),a,String(n["ratios"+o]??""))}function kt(n,o){if(!n.length)return"";let a=o;return[...n.map(u=>{let p=Oe(u-o/2-a);return a=u+o/2,p+"mm"}),"1"].join(":")}function Rt(n,o){let a=typeof n=="object"&&n&&"key"in n?n.key:n;if(typeof a!="string")return null;let h=/^([XY])-(\d+)$/.exec(a);if(!h)return null;let u=h[1],p=pt(o,u),y=p.indexOf(Number(h[2]));return y<0?null:{axis:u,ids:p,index:y,key:a}}function ke(n,o){let{axis:a,ids:h,index:u}=o,{centres:p}=It(n,a);return p.splice(u,1),h.splice(u,1),{state:null,patch:{["compartments"+a]:p.length+1,["ratios"+a]:kt(p,Number(n.thickness)),["dividerIds"+a]:h.join(",")}}}var Ee={surface:{views:[{id:"top",label:b("Draufsicht")}],height:180,help:b("Trennwand anklicken oder mit Enter ausw\xE4hlen. Zum Verschieben ziehen oder die Position in mm eingeben. Entf entfernt die Auswahl.")},actions:[{id:"addX",label:b("L\xE4ngstrennwand hinzuf\xFCgen")},{id:"addY",label:b("Quertrennwand hinzuf\xFCgen")},{id:"remove",label:b("Gew\xE4hlte Trennwand entfernen")},{id:"equalX",label:b("Fachbreiten ausgleichen")},{id:"equalY",label:b("Fachtiefen ausgleichen")},{id:"hold",label:b("Trennwandpositionen beim \xC4ndern der Ma\xDFe halten")},{id:"arrange",label:b("Fachwerkzeug anwenden"),showIf:{ne:["planOp","none"]}}],onEvent(n,o){if(n.action==="arrange")try{return{patch:Xe(o,a=>pt(o,a)),state:null,message:b("Fachverteilung angewendet.")}}catch(a){return{message:a instanceof Mt?a.message:b("Zuerst die Fachma\xDFe korrigieren.")}}if(n.action==="equalX"||n.action==="equalY")return{patch:{["ratios"+n.action.slice(-1)]:""}};try{if(n.action==="hold")return{patch:{ratiosX:kt(It(o,"X").centres,Number(o.thickness)),ratiosY:kt(It(o,"Y").centres,Number(o.thickness))}};if(n.action==="remove"){let w=Rt(n.surface?.state,o);return w?ke(o,w):{message:b("Zuerst eine Trennwand in der Draufsicht w\xE4hlen.")}}if(n.action!=="addX"&&n.action!=="addY")return;let a=n.action==="addX"?"X":"Y",h=pt(o,a);if(h.length>=19)return{message:b("Maximal 20 F\xE4cher pro Richtung.")};let{centres:u,gaps:p}=It(o,a),y=Number(o.thickness),x=!String(o["ratios"+a]??"").trim(),c=x?h.length:p.indexOf(Math.max(...p));if((x?Kt(o,a)-(p.length+2)*y:p[c]-y)<=0)return{message:b("Kein freier Platz f\xFCr die F\xE4cher.")};let P=Math.max(0,...h)+1;h.splice(c,0,P);let v=c===0?y:u[c-1]+y/2;return u.splice(c,0,v+p[c]/2),{state:a+"-"+P,patch:{["compartments"+a]:h.length+1,["dividerIds"+a]:h.join(","),["ratios"+a]:x?"":kt(u,y)}}}catch{return{message:b("Zuerst die Fachma\xDFe korrigieren.")}}},draw(n,o){let a=Number(o.width),h=Number(o.depth),u=Number(o.thickness),p={frame:{x0:0,y0:0,x1:a,y1:h},items:[{type:"line",pts:[[0,0],[a,0],[a,h],[0,h]],closed:!0},{type:"line",pts:[[u,u],[a-u,u],[a-u,h-u],[u,h-u]],closed:!0,style:"muted"}]},y=Rt(n.state,o),x=typeof n.state=="object"&&n.state&&"dragPos"in n.state?Number(n.state.dragPos):NaN;for(let c of Me){let P;try{P=It(o,c).centres}catch{continue}let v=pt(o,c),w=c===Ft(o);if(w&&(o.planOp==="split"||o.planOp==="reserve")){let A=Number(o.planGap)-1,T=c==="X";if(Number.isInteger(A)&&A>=0&&A<=P.length){let _=A?P[A-1]+u/2:u,S=A<P.length?P[A]-u/2:(T?a:h)-u,X=T?_:u,k=T?S:a-u,j=T?u:_,Y=T?h-u:S;p.items.push({type:"line",pts:[[X,j],[k,j],[k,Y],[X,Y]],closed:!0,style:"accent",dash:!0}),p.items.push({type:"text",x:(X+k)/2,y:(j+Y)/2,text:b("Fach {n}",{n:A+1}),style:"accent",align:"center",bubble:!0})}}P.forEach((A,T)=>{let _=c+"-"+v[T],S=c==="X",X=y?.key===_,k=X&&Number.isFinite(x)?x:A,j=X||w&&o.planOp==="center"&&T+1===Number(o.planDivider);p.items.push({type:"line",id:_,pts:S?[[k,u],[k,h-u]]:[[u,k],[a-u,k]],style:j?"accent":"normal",width:j?4:2}),X&&(p.fields=[{id:_,label:S?b("Mitte ab linker Innenwand"):b("Mitte ab vorderer Innenwand"),value:Oe(k-u)}])})}return p},onSurface(n,o,a){if(n.type==="down"){let _=Rt(n.hit,a);if(a.planOp==="center"&&_)return{patch:{planAxis:_.axis,planDivider:_.index+1},state:_.key,message:""};if(!_&&(a.planOp==="split"||a.planOp==="reserve")){let S=Number(a.thickness),X=Ft(a);if(n.x>S&&n.x<Number(a.width)-S&&n.y>S&&n.y<Number(a.depth)-S)try{let k=X==="X"?n.x:n.y;return{patch:{planGap:1+It(a,X).centres.filter(Y=>Y<k).length},state:null,message:""}}catch{return{message:b("Zuerst die Fachma\xDFe korrigieren.")}}}return{state:_?.key??null,message:""}}let h=Rt(o.state,a);if(n.type==="key"&&n.key==="Enter"){let _=Me.flatMap(X=>pt(a,X).map(k=>X+"-"+k));if(!_.length)return;let S=h?_.indexOf(h.key):n.shift?0:-1;return{state:_[(S+(n.shift?-1:1)+_.length)%_.length],message:""}}if(!h)return;if(n.type==="key"&&(n.key==="Delete"||n.key==="Backspace"))try{return ke(a,h)}catch{return{message:b("Zuerst die Fachma\xDFe korrigieren.")}}let u=n.type==="field"&&n.field===h.key;if(!u&&!(n.type==="move"&&n.drag)&&!(n.type==="up"&&n.from))return;let{axis:p,index:y}=h,x=Number(a.thickness),c=p==="X"?"x":"y";if(!u&&!n.from)return;let P;try{P=It(a,p).centres}catch{return{message:b("Zuerst die Fachma\xDFe korrigieren.")}}let v=n.from?n[c]-n.from[c]:0;if(!u&&Math.abs(v)<1e-4)return{state:h.key,message:""};let w=u?Number(n.value)+x:Math.round((P[y]+v)*10)/10,A=y?P[y-1]+x:1.5*x,T=y<P.length-1?P[y+1]-x:Kt(a,p)-1.5*x;return!Number.isFinite(w)||w<=A||w>=T?{state:h.key,message:b("Die Trennwand ben\xF6tigt auf beiden Seiten freien Platz.")}:n.type==="move"?{state:{key:h.key,dragPos:w},message:""}:Math.abs(P[y]-w)<1e-7?{state:h.key,message:""}:(P[y]=w,{patch:{["ratios"+p]:kt(P,x)},state:h.key,message:""})}};function Ye(n){let o=[];for(let a of n)(!o.length||Math.hypot(a.x-o[o.length-1].x,a.y-o[o.length-1].y)>1e-7)&&o.push(a);return o.length>1&&Math.hypot(o[0].x-o[o.length-1].x,o[0].y-o[o.length-1].y)<1e-7&&o.pop(),o}function De(n,o,a,h){return{closed:!0,nodes:Ye(n).map(u=>({x:u.x-o/2,y:h?a/2-u.y:u.y-a/2}))}}function $t(n,o,a,h,u,p,y){return De([{x:n,y:a},{x:o,y:a},{x:o,y:h},{x:n,y:h}],u,p,y)}function Ui(n,o,a,h,u,p){let y=[],x=n;for(let P of a){let v=P-h/2,w=P+h/2;if(v<=x||w>=o)throw new Error("dividers-overlap");y.push({a:x,b:v}),x=w}y.push({a:x,b:o});let c=[];for(let P of y){let v=P.b-P.a;if(a.length&&v<3*h-1e-9){p.push("narrow-no-bottom-fingers");continue}let w=Ct(v,u),A=v/w;for(let T=1;T<w;T+=2)c.push({a:P.a+T*A,b:P.a+(T+1)*A})}return c}function qi(n,o,a,h,u,p,y=u){let x=h.map(v=>({a:v-y/2,b:v+y/2})),c=[n,o,...a.flatMap(v=>[v.a,v.b]),...x.flatMap(v=>[v.a,v.b])].sort((v,w)=>v-w),P=[];for(let v=0;v<c.length-1;v++){let w=c[v],A=c[v+1];if(A-w<1e-9)continue;let T=(w+A)/2,_=x.some(S=>T>S.a&&T<S.b)?p:a.some(S=>T>S.a&&T<S.b)?0:u;P.push({x:w,y:_},{x:A,y:_})}return Ye(P)}function Hi(n,o,a,h,u,p=h){let y=[{x:o,y:u}];for(let x of[...a].reverse())y.push({x:x+p/2,y:u},{x:x+p/2,y:u/2},{x:x-p/2,y:u/2},{x:x-p/2,y:u});return y.push({x:n,y:u}),y}function Qt(n){let{width:o,depth:a,height:h,thickness:u,finger:p,dividerHeight:y}=n;if(![o,a,h,u,p,y].every(Y=>Number.isFinite(Y)&&Y>0)||y>h||y<=2*u)throw new Error("divider-height-invalid");if(n.top==="closed"&&y>h-u+1e-9)throw new Error("divider-into-lid");let x=n.dividerClearance??n.clearance??0,c=n.slotClearance??x,P=u+c;if(!Number.isFinite(x)||!Number.isFinite(c)||P<=0)throw new Error("clearance-invalid");let v=ot(o,u,n.compartmentsX,n.ratiosX),w=ot(a,u,n.compartmentsY,n.ratiosY),A=v.centres,T=w.centres,_=Ct(y,p),S=y/_;if(S<=u+1e-9)throw new Error("divider-fingers-short");let X={dividers:[],holes:{bottom:[],front:[],back:[],left:[],right:[]},gapsX:v.gaps,gapsY:w.gaps,warnings:[]},k=[];for(let Y=1;Y<_;Y+=2)k.push({a:Y*S,b:(Y+1)*S});function j(Y,K,Z){let D=Y==="x"?a:o,$=Y==="x"?T:A,H=Ui(u,D-u,$,u,p,X.warnings),Q=H.map(({a:E,b:z})=>({a:E+x/2,b:z-x/2})),R=k.map(({a:E,b:z})=>({a:E+x/2,b:z-x/2}));if([...Q,...R].some(({a:E,b:z})=>z-E<=1e-7))throw new Error("clearance-too-large");for(let E of $)if(Q.some(({a:z,b:rt})=>z<E+P/2&&rt>E-P/2))throw new Error("clearance-overlap");let V=qi(u,D-u,Q,Y==="y"?$:[],u,y/2,P);for(let E=0;E<_;E++){let z=E%2?u:0,rt=E===0?u:E%2?R[(E-1)/2].a:k[E/2-1].b-x/2,lt=E%2?R[(E-1)/2].b:E===_-1?y:k[E/2].a+x/2;V.push({x:D-u+z,y:rt},{x:D-u+z,y:lt})}V.push(...Hi(u,D-u,Y==="x"?$:[],u,y,P));for(let E=_-1;E>=0;E--){let z=E%2?u:0,rt=E===0?u:E%2?R[(E-1)/2].a:k[E/2-1].b-x/2,lt=E%2?R[(E-1)/2].b:E===_-1?y:k[E/2].a+x/2;V.push({x:u-z,y:lt},{x:u-z,y:rt})}X.dividers.push({key:`div${Y}-${Z}`,outline:De(V,D,y,!0)});for(let E of H)X.holes.bottom.push(Y==="x"?$t(K-P/2,K+P/2,E.a,E.b,o,a,!1):$t(E.a,E.b,K-P/2,K+P/2,o,a,!1));for(let E of k){let z=$t(K-P/2,K+P/2,E.a,E.b,Y==="x"?o:a,h,!0);Y==="x"?(X.holes.front.push(z),X.holes.back.push(structuredClone(z))):(X.holes.left.push(z),X.holes.right.push(structuredClone(z)))}}return A.forEach((Y,K)=>j("x",Y,n.idsX?.[K]??K+1)),T.forEach((Y,K)=>j("y",Y,n.idsY?.[K]??K+1)),X}vt();function Be(n){let o=h=>({x:-h.x,y:h.y}),a=n.closed?n.nodes.length?[n.nodes[0],...n.nodes.slice(1).reverse()]:[]:[...n.nodes].reverse();return{...n,nodes:a.map(h=>{let{cin:u,cout:p,...y}=h;return{...y,...o(h),...p?{cin:o(p)}:{},...u?{cout:o(u)}:{}}})}}function ji(n){let o=1/0,a=1/0,h=-1/0,u=-1/0;for(let p of n)for(let y of p.nodes)o=Math.min(o,y.x),a=Math.min(a,y.y),h=Math.max(h,y.x),u=Math.max(u,y.y);return{x0:o,y0:a,x1:h,y1:u,w:h-o,h:u-a}}function te(n,o){let a=n.map(T=>({...T,b:ji(T.subs)})),h=a.reduce((T,_)=>T+(_.b.w+o)*(_.b.h+o),0),u=Math.max(Math.sqrt(h)*1.3,...a.map(T=>T.b.w)),p=[...a].sort((T,_)=>_.b.h-T.b.h||_.b.w-T.b.w),y=[],x=0,c=0,P=0,v=0;for(let T of p)x>0&&x+T.b.w>u&&(c+=P+o,x=0,P=0),y.push({key:T.key,subs:T.subs,at:{x:x-T.b.x0,y:c-T.b.y0}}),x+=T.b.w+o,P=Math.max(P,T.b.h),v=Math.max(v,x-o);let w=c+P,A=new Map(y.map(T=>[T.key,T]));return n.map(T=>{let _=A.get(T.key);return{..._,at:{x:_.at.x-v/2,y:_.at.y-w/2}}})}function Ki(n,o){if(n.length<2)return te(n,o);let a=globalThis.host.nest({parts:n.map(h=>({key:h.key,subs:h.subs})),gap:o});return n.map((h,u)=>({key:h.key,subs:h.subs,at:{x:a[u][0],y:a[u][1]}}))}function Wt(n,o,a){if(a==="rows")return n;let h=a==="packed"?te(n,o):Ki(n,o);return n.map((u,p)=>({...u,at:h[p].at}))}var at=[1,0,0],ut=[0,1,0],Pt=[0,0,1],St=n=>[-n[0],-n[1],-n[2]],ft=(n,o,a,h)=>({o:n,u:o,v:a,n:h});var ie=xe(ee(),1);var Fe=xe(ee(),1);var ne=1e3;var{Clipper:Qr,ClipType:ts,PolyType:es,PolyFillType:ns}=Fe.default;var $i=Math.PI/2,rs=Math.PI/12;var Qi=1e-9,ss=Math.PI*2;var tr=(n,o,a,h)=>({x:n+a*Math.cos(h),y:o+a*Math.sin(h)});function Re(n,o,a,h,u){if(![n,o,a,h,u].every(Number.isFinite)||!(a>0))return[];if(Math.abs(u)<Qi)return[tr(n,o,a,h)];let p=Math.max(1,Math.ceil(Math.abs(u)/$i)),y=u/p,x=4/3*Math.tan(y/4)*a,c=[];for(let P=0;P<=p;P++){let v=P===p?h+u:h+P*y,w=n+a*Math.cos(v),A=o+a*Math.sin(v),T=-Math.sin(v),_=Math.cos(v);c.push({x:w,y:A,...P>0&&P<p?{smooth:!0}:{},...P>0?{cin:{x:w-T*x,y:A-_*x}}:{},...P<p?{cout:{x:w+T*x,y:A+_*x}}:{}})}return c}function We(n,o,a){let h=x=>({X:Math.round(x.x*ne),Y:Math.round(x.y*ne)}),u=n.map(x=>x.closed?x.nodes.map(h):[]),p=o?.flatMap(x=>x.nodes)??[],y=o!==void 0&&!o.some(x=>x.closed);return n.map((x,c)=>{if(!x.closed||x.nodes.length<3)return x;let P=u[c],v=Math.sign(ie.default.Clipper.Area(P)),w=u.filter((_,S)=>S!==c&&_.length>2&&ie.default.Clipper.PointInPolygon(P[0],_)===1).length,A=y||w%2===1,T=x.nodes.flatMap((_,S)=>{let X=x.nodes[(S-1+x.nodes.length)%x.nodes.length],k=x.nodes[(S+1)%x.nodes.length];if(X.cout||_.cin||_.cout||k.cin||p.some(E=>Math.hypot(_.x-E.x,_.y-E.y)<1e-6))return[_];let j=X.x-_.x,Y=X.y-_.y,K=k.x-_.x,Z=k.y-_.y,D=j*Z-Y*K;if(D*v*(A?-1:1)<1e-8)return[_];let $=Math.min(a,Math.hypot(j,Y)/3,Math.hypot(K,Z)/3);if($<.001)return[_];let H=Math.atan2(Y,j),Q=Math.atan2(Z,K),R=Math.atan2(D,j*K+Y*Z),V=Re(_.x,_.y,$,H,R-Math.sign(R)*Math.PI*2);return V[V.length-1].x=_.x+$*Math.cos(Q),V[V.length-1].y=_.y+$*Math.sin(Q),V});return{...x,nodes:T}})}function Nt(n,o){let a=Math.floor(n/o);return Math.max(1,a%2?a:a-1)}function er(n,o,a,h,u,p){let y=Nt(n-2*o,u);a.pattern==="flat"&&(p=0);let x=(n-2*o)/y,c=[{s0:0,s1:o,full:h,corner:!0}];for(let v=0;v<y;v++){let w=a.pattern==="flat"?!0:a.pattern==="A"?v%2===0:v%2===1;c.push({s0:o+v*x,s1:o+(v+1)*x,full:w,corner:!1})}c.push({s0:n-o,s1:n,full:h,corner:!0});let P=[];for(let v of c){let w=P[P.length-1];w&&w.full===v.full?(w.s1=v.s1,w.corner||(w.corner=v.corner)):P.push({...v})}for(let v=0;v+1<P.length;v++){let w=P[v].full?-p/4:p/4;P[v].s1+=w,P[v+1].s0+=w}return P}function nr(n,o,a,h){let{a:u,b:p}=n,y=[{x:0,y:0},{x:u,y:0},{x:u,y:p},{x:0,y:p}],x=[{x:1,y:0},{x:0,y:1},{x:-1,y:0},{x:0,y:-1}],c=[x[1],x[2],x[3],x[0]],P=[u,p,u,p],v=(L,M,U)=>({x:y[L].x+x[L].x*M+c[L].x*U,y:y[L].y+x[L].y*M+c[L].y*U}),w=[];n.edges.forEach((L,M)=>{let U=er(P[M],o,L,n.corners,a,h);if(h<0&&!n.corners&&L.pattern==="A")for(let q of[0,P[M]-o]){let G=v(M,q,0),tt=v(M,q+o,o);w.push({x0:Math.min(G.x,tt.x),x1:Math.max(G.x,tt.x),y0:Math.min(G.y,tt.y),y1:Math.max(G.y,tt.y)})}for(let q of U){if(q.full)continue;let G=v(M,q.s0,0),tt=v(M,q.s1,o);w.push({x0:Math.min(G.x,tt.x),x1:Math.max(G.x,tt.x),y0:Math.min(G.y,tt.y),y1:Math.max(G.y,tt.y)})}});let A=L=>{let M=[];for(let U of L.sort((q,G)=>q-G))(!M.length||U-M[M.length-1]>1e-9)&&M.push(U);return M},T=A([0,u,...w.flatMap(L=>[L.x0,L.x1])].map(L=>Math.min(u,Math.max(0,L)))),_=A([0,p,...w.flatMap(L=>[L.y0,L.y1])].map(L=>Math.min(p,Math.max(0,L)))),S=T.length-1,X=_.length-1,k=T.slice(1).map((L,M)=>(T[M]+L)/2),j=_.slice(1).map((L,M)=>(_[M]+L)/2),Y=(L,M)=>{let U=0,q=L.length;for(;U<q;){let G=U+q>>1;L[G]>M?q=G:U=G+1}return U},K=(L,M)=>{let U=0,q=L.length;for(;U<q;){let G=U+q>>1;L[G]<M?U=G+1:q=G}return U},Z=new Uint8Array(S*X);for(let L of w){let M=Y(k,L.x0),U=K(k,L.x1),q=Y(j,L.y0),G=K(j,L.y1);for(let tt=M;tt<U;tt++)for(let mt=q;mt<G;mt++)Z[tt*X+mt]=1}let D=(L,M)=>L>=0&&M>=0&&L<S&&M<X&&!Z[L*X+M],$=new Map,H=(L,M)=>`${L},${M}`,Q=(L,M,U,q)=>{let G=H(L,M);$.has(G)||$.set(G,[]),$.get(G).push([U,q])},R=0;for(let L=0;L<S;L++)for(let M=0;M<X;M++)D(L,M)&&(D(L,M-1)||(Q(L,M,L+1,M),R++),D(L+1,M)||(Q(L+1,M,L+1,M+1),R++),D(L,M+1)||(Q(L+1,M+1,L,M+1),R++),D(L-1,M)||(Q(L,M+1,L,M),R++));let V=[...$.keys()].sort((L,M)=>{let[U,q]=L.split(",").map(Number),[G,tt]=M.split(",").map(Number);return q-tt||U-G})[0],E=[],[z,rt]=V.split(",").map(Number),lt=[0,-1];for(let L=0;L<=R;L++){let M=$.get(H(z,rt));if(!M?.length)break;let U=G=>{let tt=G[0]-z,mt=G[1]-rt;return tt===-lt[1]&&mt===lt[0]?0:tt===lt[0]&&mt===lt[1]?1:2};M.sort((G,tt)=>U(G)-U(tt));let q=M.shift();if(E.push({x:T[z],y:_[rt]}),lt=[q[0]-z,q[1]-rt],[z,rt]=q,H(z,rt)===V&&!$.get(V).length)break}return Ze(E)}function Ze(n){let o=n.filter((h,u)=>{let p=n[(u+n.length-1)%n.length];return Math.hypot(h.x-p.x,h.y-p.y)>1e-9}),a=!0;for(;a&&o.length>3;){a=!1;for(let h=0;h<o.length;h++){let u=o[(h+o.length-1)%o.length],p=o[h],y=o[(h+1)%o.length],x=(p.x-u.x)*(y.y-p.y)-(p.y-u.y)*(y.x-p.x);if(Math.abs(x)<1e-9||Math.hypot(p.x-y.x,p.y-y.y)<1e-9){o.splice(h,1),a=!0;break}}}return o}function Gt(n,o){if(!o)return n;let a=0;for(let p=0;p<n.length;p++){let y=n[p],x=n[(p+1)%n.length];a+=y.x*x.y-x.x*y.y}let h=a>0?1:-1,u=(p,y)=>{let x=Math.hypot(y.x-p.x,y.y-p.y)||1;return{x:h*(y.y-p.y)/x,y:-h*(y.x-p.x)/x}};return n.map((p,y)=>{let x=n[(y+n.length-1)%n.length],c=n[(y+1)%n.length],P=u(x,p),v=u(p,c);return{x:p.x+(P.x+v.x)*o,y:p.y+(P.y+v.y)*o}})}function ir(n,o,a,h,u){return Gt(nr(n,o,a,h),u/2).map(p=>({x:p.x-n.a/2,y:p.y-n.b/2}))}function Ge(n,o,a,h,u,p=0){let y={closed:!0,nodes:ir(n,o,a,h,u)};return p>0&&Number.isFinite(p)?We([y],void 0,p/2)[0]:y}function Ve(n,o,a,h,u){return globalThis.host.joints({op:"panel",v:2,width:n.a,height:n.b,thickness:o,finger:a,clearance:h,kerf:u,edges:n.edges.map(y=>y.pattern),corners:n.corners}).outline.nodes}function Ot(n){let o=2*n.thickness;return n.sizeMode==="outer"?{W:n.width,D:n.depth,H:n.height}:{W:n.width+o,D:n.depth+o,H:n.height+Ue(n)}}var Ue=n=>(n.top==="lift"?3:n.top==="closed"?2:1)*n.thickness,re=n=>n,ct=(n,o=1)=>(Math.round(n*10**o)/10**o).toLocaleString(Dt,{maximumFractionDigits:o});function qe(n){let{W:o,D:a,H:h}=Ot(n),u=n.top==="closed"?"B":"flat",p=P=>({pattern:P}),y=(P,v,w,A)=>({key:P,a:v,b:n.top==="lift"?h-n.thickness:h,corners:A,edges:[p(u),p(w),p("B"),p(w)]}),x=P=>({key:P,a:o,b:a,corners:!1,edges:[p("A"),p("A"),p("A"),p("A")]}),c=[x("bottom"),y("front",o,"A",!0),y("back",o,"A",!0),y("left",a,"B",!1),y("right",a,"B",!1)];if(n.top==="closed"&&c.splice(1,0,x("top")),n.top==="lift"){let P=2*n.thickness+(n.lidPlay??.4),v=(w,A,T)=>({key:w,a:A,b:T,corners:!0,edges:[p("flat"),p("flat"),p("flat"),p("flat")]});c.push(v("top",o,a),v("lid-locator",o-P,a-P))}return c}function He(n){return qe(n).map(o=>({key:o.key,a:o.a,b:o.b,pts:Ve(o,n.thickness,n.finger,n.clearance,n.kerf)}))}function rr(n,o){return Ge(o,n.thickness,n.finger,n.clearance,n.kerf,n.dogboneToolDiameter)}var sr={key:"dogboneToolDiameter",type:"length",label:b("Werkzeugdurchmesser f\xFCr Dogbones"),min:0,max:100,def:0,advanced:!0,title:b("Entlastet innere Zinkenecken mit dem halben Werkzeugdurchmesser. Kurze Kanten begrenzen den Radius. 0 schaltet die Entlastung aus.")},ze={bottom:()=>b("Boden"),top:()=>b("Deckel"),"lid-locator":()=>b("Zentrierplatte f\xFCr den Deckel"),front:()=>b("Vorderwand"),back:()=>b("R\xFCckwand"),left:()=>b("Seitenwand links"),right:()=>b("Seitenwand rechts")},se=n=>n&&Object.prototype.hasOwnProperty.call(ze,n)?ze[n]():void 0,Je=["top","back","left"];function oe(n,o=!1){let{W:a,D:h,H:u}=Ot(n),p=n.thickness,y=St(Pt),x=P=>o?P:St(P),c=(n.top==="lift"?u-p:u)/2;return{bottom:ft([a/2,h/2,0],at,ut,Pt),top:ft([a/2,h/2,u-p],x(at),ut,Pt),...n.top==="lift"?{"lid-locator":ft([a/2,h/2,u-2*p],at,ut,Pt)}:{},front:ft([a/2,0,c],at,y,ut),back:ft([a/2,h-p,c],x(at),y,ut),left:ft([0,h/2,c],x(ut),y,at),right:ft([a-p,h/2,c],ut,y,at)}}var gs={id:"box",version:3,kind:"assembly",name:b("Box"),icon:"box",poses:n=>({poses:oe({...n,kerf:0})}),fit:{kind:"pair",play:"clearance",total:!0},assemblyCheck:!0,tile:{group:"box",before:"lidhinge",text:n=>({name:n("Box mit Fingerzinken"),desc:n("Kiste aus Platten mit Fingerzinken, mit oder ohne Deckel, als Baugruppe."),keys:n("Kiste Kasten Geh\xE4use Schachtel Fingerzinken Deckel|Suchw\xF6rter"),action:n("Box mit Fingerzinken erstellen (Baugruppe, Parameter bleiben erhalten)")})},schema:[{key:"panelMaterial",type:"text",label:b("Material"),def:""},{key:"partLayout",type:"data",label:"",def:"nest",resetOnNew:!0},{key:"sizeMode",type:"enum",label:b("Ma\xDFe"),def:"outer",options:[["outer",b("Au\xDFenma\xDF")],["inner",b("Innenma\xDF")]]},{key:"width",type:"length",label:b("Breite"),min:5,max:3e3,def:100},{key:"depth",type:"length",label:b("Tiefe"),min:5,max:3e3,def:80},{key:"height",type:"length",label:b("H\xF6he"),min:5,max:3e3,def:50},{key:"thickness",type:"length",label:b("Materialdicke"),min:.3,max:50,def:3},{key:"top",type:"enum",label:b("Oben"),def:"open",options:[["open",b("Offen")],["closed",b("Geschlossen (Deckel mit Zinken)")],["lift",b("Abnehmbarer Deckel")]]},{key:"lidPlay",type:"length",label:b("Gesamtspiel der Zentrierplatte"),min:0,max:5,def:.4,showIf:{eq:["top","lift"]}},{key:"finger",type:"length",label:b("Zinkenbreite"),min:.5,max:500,def:10,title:b("Mindestbreite der Zinken; jede Kante bekommt eine ungerade Zahl gleich breiter Zinken")},{key:"clearance",type:"length",label:b("Steckspiel gesamt"),min:-2,max:4,def:0,playTotal:!0,title:b("Gesamtspiel der Zinken: L\xFCcke minus Zinke, auf beide Seiten verteilt; negativ = Presspassung")},{key:"kerf",type:"length",label:b("Schnittfuge (Kerf)"),min:0,max:2,def:.15,title:b("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt, damit die Teile die Sollma\xDFe haben. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},sr],migrate(n,o){return{...n,...o<2?{partLayout:"rows"}:{},...o<3?{clearance:2*Number(n.clearance??0)}:{}}},validate(n){let o=re(n),a=[],{W:h,D:u,H:p}=Ot(o),y=o.thickness,x=Math.min(h,u,o.top==="lift"?p-y:p);return o.top==="lift"&&Math.min(h,u)<=2*y+(o.lidPlay??.4)&&a.push({key:"lidPlay",level:"error",msg:b("F\xFCr dieses Deckelspiel ist die \xD6ffnung zu klein.")}),x<=4*y&&a.push({key:"thickness",level:"error",msg:b("Die Platten sind zu dick f\xFCr diese Ma\xDFe (jede Seite braucht mehr als die vierfache Materialdicke).")}),o.finger<y&&a.push({key:"finger",level:"warn",msg:b("Zinken schmaler als die Materialdicke brechen leicht.")}),Math.abs(o.clearance)>=o.finger/2&&a.push({key:"clearance",level:"error",msg:b("Das Steckspiel ist zu gro\xDF f\xFCr diese Zinkenbreite.")}),x-2*y<o.finger&&a.push({key:"finger",level:"warn",msg:b("Die Zinken sind breiter als die k\xFCrzeste Kante: Dort gibt es nur eine Zinke.")}),a},generate(n){let o=re(n),a=o.thickness,h=qe(o),u=5+o.kerf,p=[h.filter(S=>["bottom","front","back"].includes(S.key)),h.filter(S=>["top","lid-locator","left","right"].includes(S.key))],y=p.map(S=>S.reduce((X,k)=>X+k.a,0)+u*(S.length-1)),x=p.map(S=>Math.max(0,...S.map(X=>X.b))),c=x[0]+u+x[1],P=[];p.forEach((S,X)=>{let k=-y[X]/2,j=-c/2+(X?x[0]+u:0);for(let Y of S){let K=rr(o,Y);P.push({key:Y.key,subs:[K],at:{x:k+Y.a/2,y:j+Y.b/2}}),k+=Y.a+u}}),P=Wt(P,u,n.partLayout);let v=String(n.panelMaterial??"").trim();if(v)for(let S of P)S.stock={material:v,thickness:a};let{W:w,D:A,H:T}=Ot(o),_={W:w-2*a,D:A-2*a,H:T-Ue(o)};return{parts:P,info:[[b("Au\xDFenma\xDF"),`${ct(w)} \xD7 ${ct(A)} \xD7 ${ct(T)} mm`],[b("Innenma\xDF"),`${ct(_.W)} \xD7 ${ct(_.D)} \xD7 ${ct(_.H)} mm`],[b("Felder je Kante (B / T / H)"),`${Nt(w-2*a,o.finger)} / ${Nt(A-2*a,o.finger)} / ${Nt(T-2*a,o.finger)}`],[b("Teile"),String(P.length)],...o.top==="lift"?[[b("Montage"),b("Zentrierplatte mittig auf die Unterseite des Deckels kleben.")]]:[]]}},label(n,o){let a=re(n),{W:h,D:u,H:p}=Ot(a),y=b("Box {w}\xD7{d}\xD7{h}",{w:ct(h),d:ct(u),h:ct(p)}),x=se(o);return x?`${y}: ${x}`:y}};var le=n=>{let o=String(n.dividerClearance??"");return{...n,clearance:Number(n.clearance??0),kerf:Number(n.kerf??0),dividerClearance:o===""?void 0:Number(o)}};function or(n){let o=/^(divx|divy)-(\d+)$/.exec(n??"");return o?o[1]==="divx"?b("Trennwand Breite {n}",{n:o[2]}):b("Trennwand Tiefe {n}",{n:o[2]}):se(n)}var fe={"clearance-invalid":()=>b("Ung\xFCltiges Steckspiel."),"clearance-too-large":()=>b("Das Steckspiel ist f\xFCr einen Zinkenabschnitt zu gro\xDF."),"clearance-overlap":()=>b("Steckspiel f\xFChrt zu \xFCberlappenden Schlitzen und Zinken."),"kerf-contour-invalid":()=>b("Ung\xFCltige Kontur f\xFCr die Schnittfuge."),"kerf-too-large":()=>b("Schnittfuge ist f\xFCr eine Kontur oder einen Schlitz zu gro\xDF."),"kerf-splits-contour":()=>b("Schnittfuge erzeugt eine ung\xFCltige oder geteilte Kontur."),"too-many-contours":()=>b("Zu viele Konturen f\xFCr die sichere Pr\xFCfung."),"slot-outside":()=>b("Ein Schlitz liegt auf oder au\xDFerhalb der Au\xDFenkontur."),"slots-overlap":()=>b("Schlitze \xFCberlappen oder ber\xFChren sich."),"compartments-range":()=>b("Fachzahl muss zwischen 1 und 100 liegen."),"size-invalid":()=>b("Ung\xFCltige Ma\xDFe."),"input-too-long":()=>b("Eingabe ist zu lang."),"no-space":()=>b("Kein freier Platz f\xFCr die F\xE4cher."),"ratio-count":()=>b("Die Anzahl der Werte muss der Fachzahl entsprechen."),"expr-invalid":()=>b("Ung\xFCltiger Ausdruck."),"expr-bracket":()=>b("Klammer nicht geschlossen."),"expr-div-zero":()=>b("Division durch null."),"expr-units":()=>b("Ung\xFCltige Einheitenkombination."),"ratio-not-positive":()=>b("Jeder Wert muss gr\xF6\xDFer als null sein."),"ratio-too-large":()=>b("Werte sind zu gro\xDF."),"fixed-no-space":()=>b("Die festen Millimeterma\xDFe lassen keinen Platz f\xFCr die \xFCbrigen F\xE4cher."),"fixed-mismatch":()=>b("Die festen Millimeterma\xDFe m\xFCssen zusammen genau dem freien Platz entsprechen."),"gap-not-positive":()=>b("Alle F\xE4cher m\xFCssen einen positiven freien Abstand haben."),"divider-height-invalid":()=>b("Ung\xFCltige Trennwandh\xF6he oder Ma\xDFe."),"divider-into-lid":()=>b("Trennw\xE4nde reichen in den Deckel."),"divider-fingers-short":()=>b("Zinkenabschnitte der Trennwand sind zu kurz f\xFCr die Materialdicke."),"dividers-overlap":()=>b("Trennw\xE4nde \xFCberlappen oder liegen au\xDFerhalb des Innenraums."),"narrow-no-bottom-fingers":()=>b("Schmales Fach ohne Bodenzinken."),"too-many-fingers":()=>b("Zu viele Zinken f\xFCr diese Kante."),"finger-length-invalid":()=>"L\xE4nge und Zinkenbreite m\xFCssen positiv sein.","outer-size-invalid":()=>"Ung\xFCltige Ma\xDFe: positive Werte und jede Au\xDFenabmessung gr\xF6\xDFer als die doppelte Materialdicke erforderlich."},lr=n=>{let o=n instanceof Error?n.message:String(n);return fe[o]?.()??o},ae=(n,o,a)=>{let h=n instanceof Error?n.message:String(n);return{...a?{key:a}:{},level:o,msg:lr(n),...fe[h]?{code:h}:{}}},je=n=>({...n,dividerHeight:n.height-n.dividerDrop,idsX:pt(n,"X"),idsY:pt(n,"Y")}),ue=n=>n.compartmentsX>1||n.compartmentsY>1,xt=n=>(Math.round(n*1e3)/1e3).toLocaleString(Dt,{maximumFractionDigits:3});function ar(n){let a=n.filter((h,u)=>{let p=n[(u+1)%n.length];return Math.hypot(h.x-p.x,h.y-p.y)>1e-9});for(let h=!0;h;){h=!1;let u=a.filter((p,y)=>{let x=a[(y+a.length-1)%a.length],c=a[(y+1)%a.length],P=Math.abs((p.x-x.x)*(c.y-p.y)-(p.y-x.y)*(c.x-p.x))>1e-9;return P||(h=!0),P});if(h&&u.length>=3)a=u;else if(h)break}return a}function ur(n){let o=Ie(n);if(n.jointLayout!=="legacy"){let a=He({sizeMode:"outer",width:n.width,depth:n.depth,height:n.height,thickness:n.thickness,finger:n.finger,top:n.top==="closed"?"closed":"open",clearance:n.clearance,kerf:0});for(let h of o)if(h.key==="bottom"||h.key==="top"){let u=a.find(p=>p.key===h.key);if(!u)throw new Error(`Missing Box plate: ${h.key}`);h.subs[0]={closed:!0,nodes:u.pts}}}if(ue(n)){let a=Qt(je(n));for(let y of o)y.key in a.holes&&y.subs.push(...a.holes[y.key]);let h=1/0,u=-1/0;for(let y of o)for(let x of y.subs)for(let c of x.nodes)h=Math.min(h,c.x+y.at.x),u=Math.max(u,c.y+y.at.y);let p=u+10+(n.height-n.dividerDrop)/2;for(let y of a.dividers){let x=y.key.startsWith("divx-")?n.depth:n.width;o.push({key:y.key,subs:[y.outline],at:{x:h+x/2,y:p}}),h+=x+10}}if(n.kerf)for(let a of o)a.subs=a.subs.map((h,u)=>({...h,nodes:Gt(ar(h.nodes),u===0?n.kerf/2:-n.kerf/2)}));if(n.faces!=="legacy")for(let a of o)Je.includes(a.key)&&(a.subs=a.subs.map(Be));return Wt(o,5+n.kerf,n.partLayout)}function fr(n){try{let o=n,a=oe({sizeMode:"outer",width:o.width,depth:o.depth,height:o.height,thickness:o.thickness,top:o.top==="closed"?"closed":"open",finger:Number(o.finger),clearance:0,kerf:0},o.faces==="legacy"),h=ot(o.width,o.thickness,o.compartmentsX,o.ratiosX).centres,u=ot(o.depth,o.thickness,o.compartmentsY,o.ratiosY).centres,p=o.height-o.dividerDrop,y=pt(o,"X"),x=pt(o,"Y");return h.forEach((c,P)=>{a[`divx-${y[P]}`]=ft([c-o.thickness/2,o.depth/2,p/2],ut,St(Pt),at)}),u.forEach((c,P)=>{a[`divy-${x[P]}`]=ft([o.width/2,c-o.thickness/2,p/2],at,St(Pt),ut)}),{poses:a}}catch{return null}}var Ke={id:"box-divided",version:6,kind:"assembly",icon:"boxDivided",...Ee,preview:{center:!0},onChange(n,o,a){let h=n==="compartmentsX"?"ratiosX":n==="compartmentsY"?"ratiosY":"",u=Number(a[n]);if(!h||!Number.isInteger(u)||u<1||u>20||u===Number(o))return;let p=Te(String(a[h]??""),Number(o),u);if(!p)return;let y={[h]:p.text};return p.removed.length?{ask:{question:b("Diese Fachwerte werden entfernt: {values}. Fortfahren?",{values:p.removed.join(" : ")}),options:[{label:b("OK"),patch:y}]}}:{patch:y}},view:n=>({autoText:{ratiosX:Lt(Number(n.compartmentsX)),ratiosY:Lt(Number(n.compartmentsY))}}),texts:fe,poses:n=>fr(n),tile:{group:"box",before:"lidhinge",text:n=>({name:n("Box mit Fingerzinken und Trennw\xE4nden"),desc:n("Box mit parametrischen Trennw\xE4nden."),keys:n("Box F\xE4cher Trennw\xE4nde Fingerzinken|Suchw\xF6rter"),action:n("Box mit Fingerzinken und Trennw\xE4nden")})},name:b("Box mit Fingerzinken und Trennw\xE4nden"),schema:[{key:"panelMaterial",type:"text",label:b("Material"),def:""},{key:"dividerIdsX",type:"data",label:"",def:""},{key:"dividerIdsY",type:"data",label:"",def:""},{key:"jointLayout",type:"data",label:"",def:"current",resetOnNew:!0},{key:"partLayout",type:"data",label:"",def:"nest",resetOnNew:!0},{key:"dividerClearance",type:"data",label:"",def:"",resetOnNew:!0},{key:"faces",type:"data",label:"",def:"out",resetOnNew:!0},{key:"width",type:"length",label:b("Breite"),min:5,max:3e3,def:100},{key:"depth",type:"length",label:b("Tiefe"),min:5,max:3e3,def:80},{key:"height",type:"length",label:b("H\xF6he"),min:5,max:3e3,def:50},{key:"thickness",type:"length",label:b("Materialdicke"),min:.3,max:50,def:3},{key:"top",type:"enum",label:b("Oben"),def:"open",options:[["open",b("Offen")],["closed",b("Geschlossen (Deckel mit Zinken)")]]},{key:"compartmentsX",type:"int",label:b("F\xE4cher in Breitenrichtung"),min:1,max:20,def:1},{key:"ratiosX",type:"text",label:b("Verteilung in Breitenrichtung"),def:"",title:b("Freie Fachbreiten als Verh\xE4ltnis oder mm, getrennt mit Doppelpunkt, z. B. 50mm:1:2. Rechenzeichen + - * / und Klammern sind m\xF6glich.")},{key:"compartmentsY",type:"int",label:b("F\xE4cher in Tiefenrichtung"),min:1,max:20,def:1},{key:"ratiosY",type:"text",label:b("Verteilung in Tiefenrichtung"),def:"",title:b("Freie Fachbreiten als Verh\xE4ltnis oder mm, getrennt mit Doppelpunkt, z. B. 50mm:1:2. Rechenzeichen + - * / und Klammern sind m\xF6glich.")},...Le,{key:"dividerDrop",type:"length",label:b("Trennw\xE4nde niedriger als Box"),min:0,max:3e3,def:10,showIf:{or:[{gt:["compartmentsX",1]},{gt:["compartmentsY",1]}]}},{key:"kerf",type:"length",label:b("Schnittfuge (Kerf)"),min:0,max:2,def:0,title:b("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt, damit die Teile die Sollma\xDFe haben. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},{key:"finger",type:"length",label:b("Zinkenbreite"),min:.5,max:500,def:10,advanced:!0},{key:"clearance",type:"length",label:b("Steckspiel gesamt"),min:-2,max:4,def:0,playTotal:!0,advanced:!0,title:b("Gesamtspiel der Zinken: L\xFCcke minus Zinke, auf beide Seiten verteilt; negativ = Presspassung")}],validate(n){let o=le(n),a=[];if(o.jointLayout==="legacy"&&o.top!=="closed"&&o.height>o.depth+10&&a.push({level:"warn",msg:b("Bei dieser H\xF6he k\xF6nnen sich Teile in der 2D-Anordnung \xFCberlappen; Lage pr\xFCfen.")}),Math.min(o.width,o.depth,o.height)<=2*o.thickness)return a.push({key:"thickness",level:"error",msg:b("Alle Au\xDFenma\xDFe m\xFCssen gr\xF6\xDFer als die doppelte Materialdicke sein.")}),a;Math.abs(o.clearance)>=o.finger/2&&a.push({key:"clearance",level:"error",msg:b("Das Steckspiel ist zu gro\xDF f\xFCr diese Zinkenbreite.")});let h=o.jointLayout==="legacy",u=[o.width-2*o.thickness,o.depth-2*o.thickness,h?o.height:o.height-o.thickness*(o.top==="closed"?2:1)];try{let p=u.map((y,x)=>y/(h||x===2?Ct(y,o.finger):Ht(y,o.finger)));Math.min(...p)<=o.thickness&&a.push({key:"finger",level:"warn",msg:b("Ein Zinkenabschnitt ist h\xF6chstens so breit wie die Materialdicke; die Geometrie kann ungeeignet sein.")})}catch{a.push({key:"finger",level:"error",msg:b("Zu viele Zinken f\xFCr diese Kante.")})}for(let[p,y,x,c]of[["ratiosX",o.width,o.compartmentsX,o.ratiosX],["ratiosY",o.depth,o.compartmentsY,o.ratiosY]])try{ot(y,o.thickness,x,c)}catch(P){a.push(ae(P,"error",p))}if(a.some(p=>p.level==="error"))return a;if(ue(o)&&(o.compartmentsX-1)*(Math.ceil(o.depth/o.finger)+3*o.compartmentsY+Math.ceil(o.height/o.finger))+(o.compartmentsY-1)*(Math.ceil(o.width/o.finger)+3*o.compartmentsX+Math.ceil(o.height/o.finger))>2e4)return a.push({level:"error",msg:b("Zu viele Zinken und Schlitze f\xFCr diese Vorschau. Weniger F\xE4cher oder gr\xF6\xDFere Zinken w\xE4hlen.")}),a;if(ue(o))try{for(let p of new Set(Qt(je(o)).warnings))a.push(ae(p,"warn"))}catch(p){a.push(ae(p,"error"))}return a},migrate(n,o){let a=Number(n.clearance??0);return{...n,...o<2?{jointLayout:"legacy"}:{},...o<3?{partLayout:"rows"}:{},...o<4?{clearance:2*a,dividerClearance:String(a)}:{},...o<5?{faces:"legacy"}:{}}},generate(n){let o=le(n),a=ur(o),h=String(n.panelMaterial??"").trim();if(h)for(let x of a)x.stock={material:h,thickness:o.thickness};let u=ot(o.width,o.thickness,o.compartmentsX,o.ratiosX).gaps,p=ot(o.depth,o.thickness,o.compartmentsY,o.ratiosY).gaps,y=o.thickness;return{parts:a,info:[[b("Au\xDFenma\xDF"),`${xt(o.width)} \xD7 ${xt(o.depth)} \xD7 ${xt(o.height)} mm`],[b("Innenma\xDF"),`${xt(o.width-2*y)} \xD7 ${xt(o.depth-2*y)} \xD7 ${xt(o.height-(o.top==="closed"?2:1)*y)} mm`],[b("Freie Fachbreiten"),`${u.map(xt).join(" : ")} mm`],[b("Freie Fachtiefen"),`${p.map(xt).join(" : ")} mm`],[b("Teile"),String(a.length)]]}},label(n,o){let a=le(n),h=b("Box mit Trennw\xE4nden {w}\xD7{d}\xD7{h}",{w:a.width,d:a.depth,h:a.height}),u=or(o);return u?`${h}: ${u}`:h}};Vt();var Rs={callMs:{validate:1e4,generate:3e4,view:2e3,onChange:2e3,onEvent:1e4,resource:2e4,draw:3e4,onSurface:5e3,open:3e4,close:2e3,apply:3e4,migrate:2e3},askOptions:3,memoryBytes:512*1024*1024,codeBytes:8*1024*1024,outputBytes:32*1024*1024,parts:2e3,nodes:5e5,issues:200,info:40,text:400,range:1e5,items:2e4,points:1e6,tris:2e6,layers:4,sideFields:8,highlight:64,regionCells:4e6,stateBytes:1024*1024,imagePixels:16e6,imageSide:8e3,objects:5e3};vt();function $e(n){let o=2166136261;for(let a=0;a<n.length;a++)o^=n.charCodeAt(a),o=Math.imul(o,16777619)>>>0;return"t"+o.toString(16).padStart(8,"0")}nn();var rn=new Map;function on(n,o){if(rn.has(n))return!0;try{rn.set(n,{data:o,mesh:en(o)})}catch{return!1}return dr(n,o),!0}var cr=n=>`mesh:${n}`,sn=null;function mr(){return sn??(sn=new Promise((n,o)=>{if(typeof indexedDB>"u")return o(new Error("no indexedDB"));let a=indexedDB.open("laserwerk",1);a.onupgradeneeded=()=>a.result.createObjectStore("assets"),a.onsuccess=()=>n(a.result),a.onerror=()=>o(a.error)})),sn}function dr(n,o){mr().then(a=>a.transaction("assets","readwrite").objectStore("assets").put(o,cr(n))).catch(()=>{})}var he=n=>({width:n.width,height:n.height,data:Et(n.data)});function yr(n){let o={};return n.selection&&(o.selection=n.selection),n.image&&(o.image={...he(n.image),name:String(n.image.name??"")}),n.camera&&(o.camera={...he(n.camera),bed:n.camera.bed,...n.camera.empty?{empty:he(n.camera.empty)}:{}}),o}var ln=n=>{if(typeof n=="string")return n;let o={code:$e(n.de)};return n.values&&(o.values=Object.fromEntries(Object.entries(n.values).map(([a,h])=>[a,typeof h=="number"?h:fn(h)]))),o},fn=n=>n.length===1?ln(n[0]):n.map(ln),et=n=>fn(qt(n)),pe=globalThis;pe.structuredClone??(pe.structuredClone=n=>JSON.parse(JSON.stringify(n)));function an(n){return!n||n instanceof Promise?null:{...n.patch?{patch:n.patch}:{},...n.message!==void 0?{message:et(n.message)}:{},...n.state!==void 0?{state:n.state}:{},...n.view!==void 0?{view:n.view}:{},...n.select?{select:n.select}:{}}}var un=n=>n.type==="text"?{...n,text:et(n.text)}:n;function hn(n){globalThis.plugin={...n.schema.some(o=>o.type==="data"&&o.resource)?{resource(o){if(o.kind==="model3d"&&!on(o.id,o.data))throw new Error("bad-model");return null}}:{},validate(o){return n.validate(o).map(a=>{let h=a.code?{code:a.code}:et(a.msg),u=typeof h=="object"&&!Array.isArray(h)?h:{code:"plugin-text",values:{text:h}};return{...a.key?{key:a.key}:{},level:a.level,...u}})},generate(o){let a=n.generate(o),h=n.poses?.(o,Number(o.thickness)||3)??null,u={};if(n.kind==="assembly")for(let p of a.parts)u[p.key]=et(n.label(o,p.key));return{parts:a.parts,info:a.info.map(([p,y])=>[et(p),et(y)]),label:et(n.label(o)),...a.distribute?{distribute:a.distribute}:{},...a.plan?{plan:{title:et(a.plan.title),lines:a.plan.lines,labels:a.plan.labels.map(p=>({...p,text:et(p.text)})),steps:a.plan.steps.map(et)}}:{},...n.kind==="assembly"?{labels:u}:{},...h?{poses:h}:{}}},...n.migrate?{migrate(o){return n.migrate(o.params,o.from)}}:{},...n.view?{view(o){let a=n.view(o);return{...a.autoText?{autoText:Object.fromEntries(Object.entries(a.autoText).map(([h,u])=>[h,et(u)]))}:{},...a.rows?{rows:Object.fromEntries(Object.entries(a.rows).map(([h,u])=>[h,u.map(et)]))}:{},...a.rowAuto?{rowAuto:Object.fromEntries(Object.entries(a.rowAuto).map(([h,u])=>[h,u.map(et)]))}:{}}}}:{},...n.onEvent?{onEvent(o){let a={action:o.action,inputs:yr(o.inputs??{})};return o.row!==void 0&&(a.row=o.row),o.surface&&(a.surface=o.surface),an(n.onEvent(a,o.params))}}:{},...n.draw?{draw(o){let{params:a,...h}=o,u=n.draw(h,a);return u instanceof Promise?null:{...u,items:u.items.map(un),...u.fields?{fields:u.fields.map(p=>({...p,label:et(p.label),...p.title?{title:et(p.title)}:{}}))}:{},...u.layers?{layers:u.layers.map(p=>p.items?{...p,items:p.items.map(un)}:p)}:{}}}}:{},...n.onSurface?{onSurface(o){return an(n.onSurface(o.event,o.surface,o.params))}}:{},...n.onChange?{onChange(o){let a=n.onChange(o.key,o.old,o.params);return!a||a instanceof Promise?null:{...a.patch?{patch:a.patch}:{},...a.ask?{ask:{question:et(a.ask.question),options:a.ask.options.map(h=>({label:et(h.label),patch:h.patch}))}}:{}}}}:{}}}hn(Ke);})();
