(()=>{var Qr=Object.create;var _t=Object.defineProperty;var ei=Object.getOwnPropertyDescriptor;var ti=Object.getOwnPropertyNames;var ni=Object.getPrototypeOf,ri=Object.prototype.hasOwnProperty;var Ze=(n,s)=>()=>(n&&(s=n(n=0)),s);var ii=(n,s)=>()=>(s||n((s={exports:{}}).exports,s),s.exports);var oi=(n,s,a,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let u of ti(s))!ri.call(n,u)&&u!==a&&_t(n,u,{get:()=>s[u],enumerable:!(c=ei(s,u))||c.enumerable});return n};var Je=(n,s,a)=>(a=n!=null?Qr(ni(n)):{},oi(s||!n||!n.__esModule?_t(a,"default",{value:n,enumerable:!0}):a,n));var De=ii((ao,He)=>{(function(){"use strict";var n={};n.version="6.4.2.2",n.use_lines=!0,n.use_xyz=!1;var s=!1;typeof He<"u"&&He.exports?(He.exports=n,s=!0):(typeof define=="function"&&define.amd&&define(n),typeof document<"u"?window.ClipperLib=n:self.ClipperLib=n);var a;if(s){var c="chrome";a="Netscape"}else{var c=navigator.userAgent.toString().toLowerCase();a=navigator.appName}var u={};c.indexOf("chrome")!=-1&&c.indexOf("chromium")==-1?u.chrome=1:u.chrome=0,c.indexOf("chromium")!=-1?u.chromium=1:u.chromium=0,c.indexOf("safari")!=-1&&c.indexOf("chrome")==-1&&c.indexOf("chromium")==-1?u.safari=1:u.safari=0,c.indexOf("firefox")!=-1?u.firefox=1:u.firefox=0,c.indexOf("firefox/17")!=-1?u.firefox17=1:u.firefox17=0,c.indexOf("firefox/15")!=-1?u.firefox15=1:u.firefox15=0,c.indexOf("firefox/3")!=-1?u.firefox3=1:u.firefox3=0,c.indexOf("opera")!=-1?u.opera=1:u.opera=0,c.indexOf("msie 10")!=-1?u.msie10=1:u.msie10=0,c.indexOf("msie 9")!=-1?u.msie9=1:u.msie9=0,c.indexOf("msie 8")!=-1?u.msie8=1:u.msie8=0,c.indexOf("msie 7")!=-1?u.msie7=1:u.msie7=0,c.indexOf("msie ")!=-1?u.msie=1:u.msie=0,n.biginteger_used=null;var h,m=0xdeadbeefcafe,b=(m&16777215)==15715070;function p(e,t,r){n.biginteger_used=1,e!=null&&(typeof e=="number"&&typeof t>"u"?this.fromInt(e):typeof e=="number"?this.fromNumber(e,t,r):t==null&&typeof e!="string"?this.fromString(e,256):this.fromString(e,t))}function g(){return new p(null,void 0,void 0)}function S(e,t,r,i,o,l){for(;--l>=0;){var f=t*this[e++]+r[i]+o;o=Math.floor(f/67108864),r[i++]=f&67108863}return o}function I(e,t,r,i,o,l){for(var f=t&32767,d=t>>15;--l>=0;){var y=this[e]&32767,v=this[e++]>>15,A=d*y+v*f;y=f*y+((A&32767)<<15)+r[i]+(o&1073741823),o=(y>>>30)+(A>>>15)+d*v+(o>>>30),r[i++]=y&1073741823}return o}function T(e,t,r,i,o,l){for(var f=t&16383,d=t>>14;--l>=0;){var y=this[e]&16383,v=this[e++]>>14,A=d*y+v*f;y=f*y+((A&16383)<<14)+r[i]+o,o=(y>>28)+(A>>14)+d*v,r[i++]=y&268435455}return o}b&&a=="Microsoft Internet Explorer"?(p.prototype.am=I,h=30):b&&a!="Netscape"?(p.prototype.am=S,h=26):(p.prototype.am=T,h=28),p.prototype.DB=h,p.prototype.DM=(1<<h)-1,p.prototype.DV=1<<h;var x=52;p.prototype.FV=Math.pow(2,x),p.prototype.F1=x-h,p.prototype.F2=2*h-x;var C="0123456789abcdefghijklmnopqrstuvwxyz",M=new Array,L,O;for(L=48,O=0;O<=9;++O)M[L++]=O;for(L=97,O=10;O<36;++O)M[L++]=O;for(L=65,O=10;O<36;++O)M[L++]=O;function R(e){return C.charAt(e)}function D(e,t){var r=M[e.charCodeAt(t)];return r??-1}function P(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function _(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0}function E(e){var t=g();return t.fromInt(e),t}function B(e,t){var r;if(t==16)r=4;else if(t==8)r=3;else if(t==256)r=8;else if(t==2)r=1;else if(t==32)r=5;else if(t==4)r=2;else{this.fromRadix(e,t);return}this.t=0,this.s=0;for(var i=e.length,o=!1,l=0;--i>=0;){var f=r==8?e[i]&255:D(e,i);if(f<0){e.charAt(i)=="-"&&(o=!0);continue}o=!1,l==0?this[this.t++]=f:l+r>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+=r,l>=this.DB&&(l-=this.DB)}r==8&&e[0]&128&&(this.s=-1,l>0&&(this[this.t-1]|=(1<<this.DB-l)-1<<l)),this.clamp(),o&&p.ZERO.subTo(this,this)}function N(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function Y(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(e==16)t=4;else if(e==8)t=3;else if(e==2)t=1;else if(e==32)t=5;else if(e==4)t=2;else return this.toRadix(e);var r=(1<<t)-1,i,o=!1,l="",f=this.t,d=this.DB-f*this.DB%t;if(f-- >0)for(d<this.DB&&(i=this[f]>>d)>0&&(o=!0,l=R(i));f>=0;)d<t?(i=(this[f]&(1<<d)-1)<<t-d,i|=this[--f]>>(d+=this.DB-t)):(i=this[f]>>(d-=t)&r,d<=0&&(d+=this.DB,--f)),i>0&&(o=!0),o&&(l+=R(i));return o?l:"0"}function F(){var e=g();return p.ZERO.subTo(this,e),e}function J(){return this.s<0?this.negate():this}function W(e){var t=this.s-e.s;if(t!=0)return t;var r=this.t;if(t=r-e.t,t!=0)return this.s<0?-t:t;for(;--r>=0;)if((t=this[r]-e[r])!=0)return t;return 0}function $(e){var t=1,r;return(r=e>>>16)!=0&&(e=r,t+=16),(r=e>>8)!=0&&(e=r,t+=8),(r=e>>4)!=0&&(e=r,t+=4),(r=e>>2)!=0&&(e=r,t+=2),(r=e>>1)!=0&&(e=r,t+=1),t}function Z(){return this.t<=0?0:this.DB*(this.t-1)+$(this[this.t-1]^this.s&this.DM)}function re(e,t){var r;for(r=this.t-1;r>=0;--r)t[r+e]=this[r];for(r=e-1;r>=0;--r)t[r]=0;t.t=this.t+e,t.s=this.s}function H(e,t){for(var r=e;r<this.t;++r)t[r-e]=this[r];t.t=Math.max(this.t-e,0),t.s=this.s}function ue(e,t){var r=e%this.DB,i=this.DB-r,o=(1<<i)-1,l=Math.floor(e/this.DB),f=this.s<<r&this.DM,d;for(d=this.t-1;d>=0;--d)t[d+l+1]=this[d]>>i|f,f=(this[d]&o)<<r;for(d=l-1;d>=0;--d)t[d]=0;t[l]=f,t.t=this.t+l+1,t.s=this.s,t.clamp()}function le(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t){t.t=0;return}var i=e%this.DB,o=this.DB-i,l=(1<<i)-1;t[0]=this[r]>>i;for(var f=r+1;f<this.t;++f)t[f-r-1]|=(this[f]&l)<<o,t[f-r]=this[f]>>i;i>0&&(t[this.t-r-1]|=(this.s&l)<<o),t.t=this.t-r,t.clamp()}function ge(e,t){for(var r=0,i=0,o=Math.min(e.t,this.t);r<o;)i+=this[r]-e[r],t[r++]=i&this.DM,i>>=this.DB;if(e.t<this.t){for(i-=e.s;r<this.t;)i+=this[r],t[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<e.t;)i-=e[r],t[r++]=i&this.DM,i>>=this.DB;i-=e.s}t.s=i<0?-1:0,i<-1?t[r++]=this.DV+i:i>0&&(t[r++]=i),t.t=r,t.clamp()}function Ie(e,t){var r=this.abs(),i=e.abs(),o=r.t;for(t.t=o+i.t;--o>=0;)t[o]=0;for(o=0;o<i.t;++o)t[o+r.t]=r.am(0,i[o],t,o,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&p.ZERO.subTo(t,t)}function Ve(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e[r]=0;for(r=0;r<t.t-1;++r){var i=t.am(r,t[r],e,2*r,0,1);(e[r+t.t]+=t.am(r+1,2*t[r],e,2*r+1,i,t.t-r-1))>=t.DV&&(e[r+t.t]-=t.DV,e[r+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(r,t[r],e,2*r,0,1)),e.s=0,e.clamp()}function ze(e,t,r){var i=e.abs();if(!(i.t<=0)){var o=this.abs();if(o.t<i.t){t?.fromInt(0),r!=null&&this.copyTo(r);return}r==null&&(r=g());var l=g(),f=this.s,d=e.s,y=this.DB-$(i[i.t-1]);y>0?(i.lShiftTo(y,l),o.lShiftTo(y,r)):(i.copyTo(l),o.copyTo(r));var v=l.t,A=l[v-1];if(A!=0){var k=A*(1<<this.F1)+(v>1?l[v-2]>>this.F2:0),X=this.FV/k,j=(1<<this.F1)/k,V=1<<this.F2,z=r.t,q=z-v,se=t??g();for(l.dlShiftTo(q,se),r.compareTo(se)>=0&&(r[r.t++]=1,r.subTo(se,r)),p.ONE.dlShiftTo(v,se),se.subTo(l,l);l.t<v;)l[l.t++]=0;for(;--q>=0;){var he=r[--z]==A?this.DM:Math.floor(r[z]*X+(r[z-1]+V)*j);if((r[z]+=l.am(0,he,r,q,0,v))<he)for(l.dlShiftTo(q,se),r.subTo(se,r);r[z]<--he;)r.subTo(se,r)}t!=null&&(r.drShiftTo(v,t),f!=d&&p.ZERO.subTo(t,t)),r.t=v,r.clamp(),y>0&&r.rShiftTo(y,r),f<0&&p.ZERO.subTo(r,r)}}}function Ue(e){var t=g();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(p.ZERO)>0&&e.subTo(t,t),t}function Pe(e){this.m=e}function An(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function Ln(e){return e}function _n(e){e.divRemTo(this.m,null,e)}function On(e,t,r){e.multiplyTo(t,r),this.reduce(r)}function Nn(e,t){e.squareTo(t),this.reduce(t)}Pe.prototype.convert=An,Pe.prototype.revert=Ln,Pe.prototype.reduce=_n,Pe.prototype.mulTo=On,Pe.prototype.sqrTo=Nn;function En(){if(this.t<1)return 0;var e=this[0];if(!(e&1))return 0;var t=e&3;return t=t*(2-(e&15)*t)&15,t=t*(2-(e&255)*t)&255,t=t*(2-((e&65535)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function xe(e){this.m=e,this.mp=e.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Xn(e){var t=g();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(p.ZERO)>0&&this.m.subTo(t,t),t}function Dn(e){var t=g();return e.copyTo(t),this.reduce(t),t}function Yn(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=e[t]&32767,i=r*this.mpl+((r*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(r=t+this.m.t,e[r]+=this.m.am(0,i,e,t,0,this.m.t);e[r]>=e.DV;)e[r]-=e.DV,e[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function Bn(e,t){e.squareTo(t),this.reduce(t)}function Fn(e,t,r){e.multiplyTo(t,r),this.reduce(r)}xe.prototype.convert=Xn,xe.prototype.revert=Dn,xe.prototype.reduce=Yn,xe.prototype.mulTo=Fn,xe.prototype.sqrTo=Bn;function Rn(){return(this.t>0?this[0]&1:this.s)==0}function jn(e,t){if(e>4294967295||e<1)return p.ONE;var r=g(),i=g(),o=t.convert(this),l=$(e)-1;for(o.copyTo(r);--l>=0;)if(t.sqrTo(r,i),(e&1<<l)>0)t.mulTo(i,o,r);else{var f=r;r=i,i=f}return t.revert(r)}function Wn(e,t){var r;return e<256||t.isEven()?r=new Pe(t):r=new xe(t),this.exp(e,r)}p.prototype.copyTo=P,p.prototype.fromInt=_,p.prototype.fromString=B,p.prototype.clamp=N,p.prototype.dlShiftTo=re,p.prototype.drShiftTo=H,p.prototype.lShiftTo=ue,p.prototype.rShiftTo=le,p.prototype.subTo=ge,p.prototype.multiplyTo=Ie,p.prototype.squareTo=Ve,p.prototype.divRemTo=ze,p.prototype.invDigit=En,p.prototype.isEven=Rn,p.prototype.exp=jn,p.prototype.toString=Y,p.prototype.negate=F,p.prototype.abs=J,p.prototype.compareTo=W,p.prototype.bitLength=Z,p.prototype.mod=Ue,p.prototype.modPowInt=Wn,p.ZERO=E(0),p.ONE=E(1);function Gn(){var e=g();return this.copyTo(e),e}function Vn(){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 zn(){return this.t==0?this.s:this[0]<<24>>24}function Un(){return this.t==0?this.s:this[0]<<16>>16}function Zn(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function Jn(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function Hn(e){if(e==null&&(e=10),this.signum()==0||e<2||e>36)return"0";var t=this.chunkSize(e),r=Math.pow(e,t),i=E(r),o=g(),l=g(),f="";for(this.divRemTo(i,o,l);o.signum()>0;)f=(r+l.intValue()).toString(e).substr(1)+f,o.divRemTo(i,o,l);return l.intValue().toString(e)+f}function qn(e,t){this.fromInt(0),t==null&&(t=10);for(var r=this.chunkSize(t),i=Math.pow(t,r),o=!1,l=0,f=0,d=0;d<e.length;++d){var y=D(e,d);if(y<0){e.charAt(d)=="-"&&this.signum()==0&&(o=!0);continue}f=t*f+y,++l>=r&&(this.dMultiply(i),this.dAddOffset(f,0),l=0,f=0)}l>0&&(this.dMultiply(Math.pow(t,l)),this.dAddOffset(f,0)),o&&p.ZERO.subTo(this,this)}function Kn(e,t,r){if(typeof t=="number")if(e<2)this.fromInt(1);else for(this.fromNumber(e,r),this.testBit(e-1)||this.bitwiseTo(p.ONE.shiftLeft(e-1),ct,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(p.ONE.shiftLeft(e-1),this);else{var i=new Array,o=e&7;i.length=(e>>3)+1,t.nextBytes(i),o>0?i[0]&=(1<<o)-1:i[0]=0,this.fromString(i,256)}}function $n(){var e=this.t,t=new Array;t[0]=this.s;var r=this.DB-e*this.DB%8,i,o=0;if(e-- >0)for(r<this.DB&&(i=this[e]>>r)!=(this.s&this.DM)>>r&&(t[o++]=i|this.s<<this.DB-r);e>=0;)r<8?(i=(this[e]&(1<<r)-1)<<8-r,i|=this[--e]>>(r+=this.DB-8)):(i=this[e]>>(r-=8)&255,r<=0&&(r+=this.DB,--e)),i&128&&(i|=-256),o==0&&(this.s&128)!=(i&128)&&++o,(o>0||i!=this.s)&&(t[o++]=i);return t}function Qn(e){return this.compareTo(e)==0}function er(e){return this.compareTo(e)<0?this:e}function tr(e){return this.compareTo(e)>0?this:e}function nr(e,t,r){var i,o,l=Math.min(e.t,this.t);for(i=0;i<l;++i)r[i]=t(this[i],e[i]);if(e.t<this.t){for(o=e.s&this.DM,i=l;i<this.t;++i)r[i]=t(this[i],o);r.t=this.t}else{for(o=this.s&this.DM,i=l;i<e.t;++i)r[i]=t(o,e[i]);r.t=e.t}r.s=t(this.s,e.s),r.clamp()}function rr(e,t){return e&t}function ir(e){var t=g();return this.bitwiseTo(e,rr,t),t}function ct(e,t){return e|t}function or(e){var t=g();return this.bitwiseTo(e,ct,t),t}function Tt(e,t){return e^t}function sr(e){var t=g();return this.bitwiseTo(e,Tt,t),t}function Mt(e,t){return e&~t}function ar(e){var t=g();return this.bitwiseTo(e,Mt,t),t}function lr(){for(var e=g(),t=0;t<this.t;++t)e[t]=this.DM&~this[t];return e.t=this.t,e.s=~this.s,e}function ur(e){var t=g();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function cr(e){var t=g();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function fr(e){if(e==0)return-1;var t=0;return e&65535||(e>>=16,t+=16),e&255||(e>>=8,t+=8),e&15||(e>>=4,t+=4),e&3||(e>>=2,t+=2),e&1||++t,t}function hr(){for(var e=0;e<this.t;++e)if(this[e]!=0)return e*this.DB+fr(this[e]);return this.s<0?this.t*this.DB:-1}function pr(e){for(var t=0;e!=0;)e&=e-1,++t;return t}function mr(){for(var e=0,t=this.s&this.DM,r=0;r<this.t;++r)e+=pr(this[r]^t);return e}function dr(e){var t=Math.floor(e/this.DB);return t>=this.t?this.s!=0:(this[t]&1<<e%this.DB)!=0}function yr(e,t){var r=p.ONE.shiftLeft(e);return this.bitwiseTo(r,t,r),r}function br(e){return this.changeBit(e,ct)}function gr(e){return this.changeBit(e,Mt)}function Pr(e){return this.changeBit(e,Tt)}function xr(e,t){for(var r=0,i=0,o=Math.min(e.t,this.t);r<o;)i+=this[r]+e[r],t[r++]=i&this.DM,i>>=this.DB;if(e.t<this.t){for(i+=e.s;r<this.t;)i+=this[r],t[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<e.t;)i+=e[r],t[r++]=i&this.DM,i>>=this.DB;i+=e.s}t.s=i<0?-1:0,i>0?t[r++]=i:i<-1&&(t[r++]=this.DV+i),t.t=r,t.clamp()}function vr(e){var t=g();return this.addTo(e,t),t}function Sr(e){var t=g();return this.subTo(e,t),t}function wr(e){var t=g();return this.multiplyTo(e,t),t}function Ir(){var e=g();return this.squareTo(e),e}function Cr(e){var t=g();return this.divRemTo(e,t,null),t}function kr(e){var t=g();return this.divRemTo(e,null,t),t}function Tr(e){var t=g(),r=g();return this.divRemTo(e,t,r),new Array(t,r)}function Mr(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function Ar(e,t){if(e!=0){for(;this.t<=t;)this[this.t++]=0;for(this[t]+=e;this[t]>=this.DV;)this[t]-=this.DV,++t>=this.t&&(this[this.t++]=0),++this[t]}}function Xe(){}function At(e){return e}function Lr(e,t,r){e.multiplyTo(t,r)}function _r(e,t){e.squareTo(t)}Xe.prototype.convert=At,Xe.prototype.revert=At,Xe.prototype.mulTo=Lr,Xe.prototype.sqrTo=_r;function Or(e){return this.exp(e,new Xe)}function Nr(e,t,r){var i=Math.min(this.t+e.t,t);for(r.s=0,r.t=i;i>0;)r[--i]=0;var o;for(o=r.t-this.t;i<o;++i)r[i+this.t]=this.am(0,e[i],r,i,0,this.t);for(o=Math.min(e.t,t);i<o;++i)this.am(0,e[i],r,i,0,t-i);r.clamp()}function Er(e,t,r){--t;var i=r.t=this.t+e.t-t;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(t-this.t,0);i<e.t;++i)r[this.t+i-t]=this.am(t-i,e[i],r,0,0,this.t+i-t);r.clamp(),r.drShiftTo(1,r)}function Ce(e){this.r2=g(),this.q3=g(),p.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function Xr(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=g();return e.copyTo(t),this.reduce(t),t}function Dr(e){return e}function Yr(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function Br(e,t){e.squareTo(t),this.reduce(t)}function Fr(e,t,r){e.multiplyTo(t,r),this.reduce(r)}Ce.prototype.convert=Xr,Ce.prototype.revert=Dr,Ce.prototype.reduce=Yr,Ce.prototype.mulTo=Fr,Ce.prototype.sqrTo=Br;function Rr(e,t){var r=e.bitLength(),i,o=E(1),l;if(r<=0)return o;r<18?i=1:r<48?i=3:r<144?i=4:r<768?i=5:i=6,r<8?l=new Pe(t):t.isEven()?l=new Ce(t):l=new xe(t);var f=new Array,d=3,y=i-1,v=(1<<i)-1;if(f[1]=l.convert(this),i>1){var A=g();for(l.sqrTo(f[1],A);d<=v;)f[d]=g(),l.mulTo(A,f[d-2],f[d]),d+=2}var k=e.t-1,X,j=!0,V=g(),z;for(r=$(e[k])-1;k>=0;){for(r>=y?X=e[k]>>r-y&v:(X=(e[k]&(1<<r+1)-1)<<y-r,k>0&&(X|=e[k-1]>>this.DB+r-y)),d=i;!(X&1);)X>>=1,--d;if((r-=d)<0&&(r+=this.DB,--k),j)f[X].copyTo(o),j=!1;else{for(;d>1;)l.sqrTo(o,V),l.sqrTo(V,o),d-=2;d>0?l.sqrTo(o,V):(z=o,o=V,V=z),l.mulTo(V,f[X],o)}for(;k>=0&&!(e[k]&1<<r);)l.sqrTo(o,V),z=o,o=V,V=z,--r<0&&(r=this.DB-1,--k)}return l.revert(o)}function jr(e){var t=this.s<0?this.negate():this.clone(),r=e.s<0?e.negate():e.clone();if(t.compareTo(r)<0){var i=t;t=r,r=i}var o=t.getLowestSetBit(),l=r.getLowestSetBit();if(l<0)return t;for(o<l&&(l=o),l>0&&(t.rShiftTo(l,t),r.rShiftTo(l,r));t.signum()>0;)(o=t.getLowestSetBit())>0&&t.rShiftTo(o,t),(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),t.compareTo(r)>=0?(t.subTo(r,t),t.rShiftTo(1,t)):(r.subTo(t,r),r.rShiftTo(1,r));return l>0&&r.lShiftTo(l,r),r}function Wr(e){if(e<=0)return 0;var t=this.DV%e,r=this.s<0?e-1:0;if(this.t>0)if(t==0)r=this[0]%e;else for(var i=this.t-1;i>=0;--i)r=(t*r+this[i])%e;return r}function Gr(e){var t=e.isEven();if(this.isEven()&&t||e.signum()==0)return p.ZERO;for(var r=e.clone(),i=this.clone(),o=E(1),l=E(0),f=E(0),d=E(1);r.signum()!=0;){for(;r.isEven();)r.rShiftTo(1,r),t?((!o.isEven()||!l.isEven())&&(o.addTo(this,o),l.subTo(e,l)),o.rShiftTo(1,o)):l.isEven()||l.subTo(e,l),l.rShiftTo(1,l);for(;i.isEven();)i.rShiftTo(1,i),t?((!f.isEven()||!d.isEven())&&(f.addTo(this,f),d.subTo(e,d)),f.rShiftTo(1,f)):d.isEven()||d.subTo(e,d),d.rShiftTo(1,d);r.compareTo(i)>=0?(r.subTo(i,r),t&&o.subTo(f,o),l.subTo(d,l)):(i.subTo(r,i),t&&f.subTo(o,f),d.subTo(l,d))}if(i.compareTo(p.ONE)!=0)return p.ZERO;if(d.compareTo(e)>=0)return d.subtract(e);if(d.signum()<0)d.addTo(e,d);else return d;return d.signum()<0?d.add(e):d}var oe=[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],Vr=(1<<26)/oe[oe.length-1];function zr(e){var t,r=this.abs();if(r.t==1&&r[0]<=oe[oe.length-1]){for(t=0;t<oe.length;++t)if(r[0]==oe[t])return!0;return!1}if(r.isEven())return!1;for(t=1;t<oe.length;){for(var i=oe[t],o=t+1;o<oe.length&&i<Vr;)i*=oe[o++];for(i=r.modInt(i);t<o;)if(i%oe[t++]==0)return!1}return r.millerRabin(e)}function Ur(e){var t=this.subtract(p.ONE),r=t.getLowestSetBit();if(r<=0)return!1;var i=t.shiftRight(r);e=e+1>>1,e>oe.length&&(e=oe.length);for(var o=g(),l=0;l<e;++l){o.fromInt(oe[Math.floor(Math.random()*oe.length)]);var f=o.modPow(i,this);if(f.compareTo(p.ONE)!=0&&f.compareTo(t)!=0){for(var d=1;d++<r&&f.compareTo(t)!=0;)if(f=f.modPowInt(2,this),f.compareTo(p.ONE)==0)return!1;if(f.compareTo(t)!=0)return!1}}return!0}p.prototype.chunkSize=Zn,p.prototype.toRadix=Hn,p.prototype.fromRadix=qn,p.prototype.fromNumber=Kn,p.prototype.bitwiseTo=nr,p.prototype.changeBit=yr,p.prototype.addTo=xr,p.prototype.dMultiply=Mr,p.prototype.dAddOffset=Ar,p.prototype.multiplyLowerTo=Nr,p.prototype.multiplyUpperTo=Er,p.prototype.modInt=Wr,p.prototype.millerRabin=Ur,p.prototype.clone=Gn,p.prototype.intValue=Vn,p.prototype.byteValue=zn,p.prototype.shortValue=Un,p.prototype.signum=Jn,p.prototype.toByteArray=$n,p.prototype.equals=Qn,p.prototype.min=er,p.prototype.max=tr,p.prototype.and=ir,p.prototype.or=or,p.prototype.xor=sr,p.prototype.andNot=ar,p.prototype.not=lr,p.prototype.shiftLeft=ur,p.prototype.shiftRight=cr,p.prototype.getLowestSetBit=hr,p.prototype.bitCount=mr,p.prototype.testBit=dr,p.prototype.setBit=br,p.prototype.clearBit=gr,p.prototype.flipBit=Pr,p.prototype.add=vr,p.prototype.subtract=Sr,p.prototype.multiply=wr,p.prototype.divide=Cr,p.prototype.remainder=kr,p.prototype.divideAndRemainder=Tr,p.prototype.modPow=Rr,p.prototype.modInverse=Gr,p.prototype.pow=Or,p.prototype.gcd=jr,p.prototype.isProbablePrime=zr,p.prototype.square=Ir;var G=p;G.prototype.IsNegative=function(){return this.compareTo(G.ZERO)==-1},G.op_Equality=function(e,t){return e.compareTo(t)==0},G.op_Inequality=function(e,t){return e.compareTo(t)!=0},G.op_GreaterThan=function(e,t){return e.compareTo(t)>0},G.op_LessThan=function(e,t){return e.compareTo(t)<0},G.op_Addition=function(e,t){return new G(e,void 0,void 0).add(new G(t,void 0,void 0))},G.op_Subtraction=function(e,t){return new G(e,void 0,void 0).subtract(new G(t,void 0,void 0))},G.Int128Mul=function(e,t){return new G(e,void 0,void 0).multiply(new G(t,void 0,void 0))},G.op_Division=function(e,t){return e.divide(t)},G.prototype.ToDouble=function(){return parseFloat(this.toString())};var Lt=function(e,t){var r;if(typeof Object.getOwnPropertyNames>"u"){for(r in t.prototype)(typeof e.prototype[r]>"u"||e.prototype[r]===Object.prototype[r])&&(e.prototype[r]=t.prototype[r]);for(r in t)typeof e[r]>"u"&&(e[r]=t[r]);e.$baseCtor=t}else{for(var i=Object.getOwnPropertyNames(t.prototype),o=0;o<i.length;o++)typeof Object.getOwnPropertyDescriptor(e.prototype,i[o])>"u"&&Object.defineProperty(e.prototype,i[o],Object.getOwnPropertyDescriptor(t.prototype,i[o]));for(r in t)typeof e[r]>"u"&&(e[r]=t[r]);e.$baseCtor=t}};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 e=arguments;this.X=0,this.Y=0,e.length===1?(this.X=e[0].X,this.Y=e[0].Y):e.length===2&&(this.X=e[0],this.Y=e[1])},n.DoublePoint0=function(){this.X=0,this.Y=0},n.DoublePoint0.prototype=n.DoublePoint.prototype,n.DoublePoint1=function(e){this.X=e.X,this.Y=e.Y},n.DoublePoint1.prototype=n.DoublePoint.prototype,n.DoublePoint2=function(e,t){this.X=e,this.Y=t},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 e=!0,t=this.m_Parent;t!==null;)e=!e,t=t.m_Parent;return e},n.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},n.PolyNode.prototype.Contour=function(){return this.m_polygon},n.PolyNode.prototype.AddChild=function(e){var t=this.m_Childs.length;this.m_Childs.push(e),e.m_Parent=this,e.m_Index=t},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 e=0,t=this.m_AllPolys.length;e<t;e++)this.m_AllPolys[e]=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 e=this.m_AllPolys.length;return e>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&e--,e},Lt(n.PolyTree,n.PolyNode),n.Math_Abs_Int64=n.Math_Abs_Int32=n.Math_Abs_Double=function(e){return Math.abs(e)},n.Math_Max_Int32_Int32=function(e,t){return Math.max(e,t)},u.msie||u.opera||u.safari?n.Cast_Int32=function(e){return e|0}:n.Cast_Int32=function(e){return~~e},typeof Number.toInteger>"u"&&(Number.toInteger=null),u.chrome?n.Cast_Int64=function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):~~e}:u.firefox&&typeof Number.toInteger=="function"?n.Cast_Int64=function(e){return Number.toInteger(e)}:u.msie7||u.msie8?n.Cast_Int64=function(e){return parseInt(e,10)}:u.msie?n.Cast_Int64=function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):e|0}:n.Cast_Int64=function(e){return e<0?Math.ceil(e):Math.floor(e)},n.Clear=function(e){e.length=0},n.PI=3.141592653589793,n.PI2=2*3.141592653589793,n.IntPoint=function(){var e=arguments,t=e.length;if(this.X=0,this.Y=0,n.use_xyz)if(this.Z=0,t===3)this.X=e[0],this.Y=e[1],this.Z=e[2];else if(t===2)this.X=e[0],this.Y=e[1],this.Z=0;else if(t===1)if(e[0]instanceof n.DoublePoint){var r=e[0];this.X=n.Clipper.Round(r.X),this.Y=n.Clipper.Round(r.Y),this.Z=0}else{var i=e[0];typeof i.Z>"u"&&(i.Z=0),this.X=i.X,this.Y=i.Y,this.Z=i.Z}else this.X=0,this.Y=0,this.Z=0;else if(t===2)this.X=e[0],this.Y=e[1];else if(t===1)if(e[0]instanceof n.DoublePoint){var r=e[0];this.X=n.Clipper.Round(r.X),this.Y=n.Clipper.Round(r.Y)}else{var i=e[0];this.X=i.X,this.Y=i.Y}else this.X=0,this.Y=0},n.IntPoint.op_Equality=function(e,t){return e.X===t.X&&e.Y===t.Y},n.IntPoint.op_Inequality=function(e,t){return e.X!==t.X||e.Y!==t.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(e){this.X=e.X,this.Y=e.Y,n.use_xyz&&(typeof e.Z>"u"?this.Z=0:this.Z=e.Z)},n.IntPoint1.prototype=n.IntPoint.prototype,n.IntPoint1dp=function(e){this.X=n.Clipper.Round(e.X),this.Y=n.Clipper.Round(e.Y),n.use_xyz&&(this.Z=0)},n.IntPoint1dp.prototype=n.IntPoint.prototype,n.IntPoint2=function(e,t,r){this.X=e,this.Y=t,n.use_xyz&&(typeof r>"u"?this.Z=0:this.Z=r)},n.IntPoint2.prototype=n.IntPoint.prototype,n.IntRect=function(){var e=arguments,t=e.length;if(t===4)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(t===1){var r=e[0];this.left=r.left,this.top=r.top,this.right=r.right,this.bottom=r.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(e){this.left=e.left,this.top=e.top,this.right=e.right,this.bottom=e.bottom},n.IntRect1.prototype=n.IntRect.prototype,n.IntRect4=function(e,t,r,i){this.left=e,this.top=t,this.right=r,this.bottom=i},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(e,t){var r=t.Pt.Y-e.Pt.Y;return r>0?1:r<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(e){return e>-n.ClipperBase.tolerance&&e<n.ClipperBase.tolerance},n.ClipperBase.IsHorizontal=function(e){return e.Delta.Y===0},n.ClipperBase.prototype.PointIsVertex=function(e,t){var r=t;do{if(n.IntPoint.op_Equality(r.Pt,e))return!0;r=r.Next}while(r!==t);return!1},n.ClipperBase.prototype.PointOnLineSegment=function(e,t,r,i){return i?e.X===t.X&&e.Y===t.Y||e.X===r.X&&e.Y===r.Y||e.X>t.X==e.X<r.X&&e.Y>t.Y==e.Y<r.Y&&G.op_Equality(G.Int128Mul(e.X-t.X,r.Y-t.Y),G.Int128Mul(r.X-t.X,e.Y-t.Y)):e.X===t.X&&e.Y===t.Y||e.X===r.X&&e.Y===r.Y||e.X>t.X==e.X<r.X&&e.Y>t.Y==e.Y<r.Y&&(e.X-t.X)*(r.Y-t.Y)===(r.X-t.X)*(e.Y-t.Y)},n.ClipperBase.prototype.PointOnPolygon=function(e,t,r){for(var i=t;;){if(this.PointOnLineSegment(e,i.Pt,i.Next.Pt,r))return!0;if(i=i.Next,i===t)break}return!1},n.ClipperBase.prototype.SlopesEqual=n.ClipperBase.SlopesEqual=function(){var e=arguments,t=e.length,r,i,o,l,f,d,y;return t===3?(r=e[0],i=e[1],y=e[2],y?G.op_Equality(G.Int128Mul(r.Delta.Y,i.Delta.X),G.Int128Mul(r.Delta.X,i.Delta.Y)):n.Cast_Int64(r.Delta.Y*i.Delta.X)===n.Cast_Int64(r.Delta.X*i.Delta.Y)):t===4?(o=e[0],l=e[1],f=e[2],y=e[3],y?G.op_Equality(G.Int128Mul(o.Y-l.Y,l.X-f.X),G.Int128Mul(o.X-l.X,l.Y-f.Y)):n.Cast_Int64((o.Y-l.Y)*(l.X-f.X))-n.Cast_Int64((o.X-l.X)*(l.Y-f.Y))===0):(o=e[0],l=e[1],f=e[2],d=e[3],y=e[4],y?G.op_Equality(G.Int128Mul(o.Y-l.Y,f.X-d.X),G.Int128Mul(o.X-l.X,f.Y-d.Y)):n.Cast_Int64((o.Y-l.Y)*(f.X-d.X))-n.Cast_Int64((o.X-l.X)*(f.Y-d.Y))===0)},n.ClipperBase.SlopesEqual3=function(e,t,r){return r?G.op_Equality(G.Int128Mul(e.Delta.Y,t.Delta.X),G.Int128Mul(e.Delta.X,t.Delta.Y)):n.Cast_Int64(e.Delta.Y*t.Delta.X)===n.Cast_Int64(e.Delta.X*t.Delta.Y)},n.ClipperBase.SlopesEqual4=function(e,t,r,i){return i?G.op_Equality(G.Int128Mul(e.Y-t.Y,t.X-r.X),G.Int128Mul(e.X-t.X,t.Y-r.Y)):n.Cast_Int64((e.Y-t.Y)*(t.X-r.X))-n.Cast_Int64((e.X-t.X)*(t.Y-r.Y))===0},n.ClipperBase.SlopesEqual5=function(e,t,r,i,o){return o?G.op_Equality(G.Int128Mul(e.Y-t.Y,r.X-i.X),G.Int128Mul(e.X-t.X,r.Y-i.Y)):n.Cast_Int64((e.Y-t.Y)*(r.X-i.X))-n.Cast_Int64((e.X-t.X)*(r.Y-i.Y))===0},n.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var e=0,t=this.m_edges.length;e<t;++e){for(var r=0,i=this.m_edges[e].length;r<i;++r)this.m_edges[e][r]=null;n.Clear(this.m_edges[e])}n.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},n.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;this.m_MinimaList!==null;){var e=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=e}this.m_CurrentLM=null},n.ClipperBase.prototype.RangeTest=function(e,t){t.Value?(e.X>n.ClipperBase.hiRange||e.Y>n.ClipperBase.hiRange||-e.X>n.ClipperBase.hiRange||-e.Y>n.ClipperBase.hiRange)&&n.Error("Coordinate outside allowed range in RangeTest()."):(e.X>n.ClipperBase.loRange||e.Y>n.ClipperBase.loRange||-e.X>n.ClipperBase.loRange||-e.Y>n.ClipperBase.loRange)&&(t.Value=!0,this.RangeTest(e,t))},n.ClipperBase.prototype.InitEdge=function(e,t,r,i){e.Next=t,e.Prev=r,e.Curr.X=i.X,e.Curr.Y=i.Y,n.use_xyz&&(e.Curr.Z=i.Z),e.OutIdx=-1},n.ClipperBase.prototype.InitEdge2=function(e,t){e.Curr.Y>=e.Next.Curr.Y?(e.Bot.X=e.Curr.X,e.Bot.Y=e.Curr.Y,n.use_xyz&&(e.Bot.Z=e.Curr.Z),e.Top.X=e.Next.Curr.X,e.Top.Y=e.Next.Curr.Y,n.use_xyz&&(e.Top.Z=e.Next.Curr.Z)):(e.Top.X=e.Curr.X,e.Top.Y=e.Curr.Y,n.use_xyz&&(e.Top.Z=e.Curr.Z),e.Bot.X=e.Next.Curr.X,e.Bot.Y=e.Next.Curr.Y,n.use_xyz&&(e.Bot.Z=e.Next.Curr.Z)),this.SetDx(e),e.PolyTyp=t},n.ClipperBase.prototype.FindNextLocMin=function(e){for(var t;;){for(;n.IntPoint.op_Inequality(e.Bot,e.Prev.Bot)||n.IntPoint.op_Equality(e.Curr,e.Top);)e=e.Next;if(e.Dx!==n.ClipperBase.horizontal&&e.Prev.Dx!==n.ClipperBase.horizontal)break;for(;e.Prev.Dx===n.ClipperBase.horizontal;)e=e.Prev;for(t=e;e.Dx===n.ClipperBase.horizontal;)e=e.Next;if(e.Top.Y!==e.Prev.Bot.Y){t.Prev.Bot.X<e.Bot.X&&(e=t);break}}return e},n.ClipperBase.prototype.ProcessBound=function(e,t){var r,i=e,o;if(i.OutIdx===n.ClipperBase.Skip){if(e=i,t){for(;e.Top.Y===e.Next.Bot.Y;)e=e.Next;for(;e!==i&&e.Dx===n.ClipperBase.horizontal;)e=e.Prev}else{for(;e.Top.Y===e.Prev.Bot.Y;)e=e.Prev;for(;e!==i&&e.Dx===n.ClipperBase.horizontal;)e=e.Next}if(e===i)t?i=e.Next:i=e.Prev;else{t?e=i.Next:e=i.Prev;var l=new n.LocalMinima;l.Next=null,l.Y=e.Bot.Y,l.LeftBound=null,l.RightBound=e,e.WindDelta=0,i=this.ProcessBound(e,t),this.InsertLocalMinima(l)}return i}if(e.Dx===n.ClipperBase.horizontal&&(t?r=e.Prev:r=e.Next,r.Dx===n.ClipperBase.horizontal?r.Bot.X!==e.Bot.X&&r.Top.X!==e.Bot.X&&this.ReverseHorizontal(e):r.Bot.X!==e.Bot.X&&this.ReverseHorizontal(e)),r=e,t){for(;i.Top.Y===i.Next.Bot.Y&&i.Next.OutIdx!==n.ClipperBase.Skip;)i=i.Next;if(i.Dx===n.ClipperBase.horizontal&&i.Next.OutIdx!==n.ClipperBase.Skip){for(o=i;o.Prev.Dx===n.ClipperBase.horizontal;)o=o.Prev;o.Prev.Top.X>i.Next.Top.X&&(i=o.Prev)}for(;e!==i;)e.NextInLML=e.Next,e.Dx===n.ClipperBase.horizontal&&e!==r&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),e=e.Next;e.Dx===n.ClipperBase.horizontal&&e!==r&&e.Bot.X!==e.Prev.Top.X&&this.ReverseHorizontal(e),i=i.Next}else{for(;i.Top.Y===i.Prev.Bot.Y&&i.Prev.OutIdx!==n.ClipperBase.Skip;)i=i.Prev;if(i.Dx===n.ClipperBase.horizontal&&i.Prev.OutIdx!==n.ClipperBase.Skip){for(o=i;o.Next.Dx===n.ClipperBase.horizontal;)o=o.Next;(o.Next.Top.X===i.Prev.Top.X||o.Next.Top.X>i.Prev.Top.X)&&(i=o.Next)}for(;e!==i;)e.NextInLML=e.Prev,e.Dx===n.ClipperBase.horizontal&&e!==r&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),e=e.Prev;e.Dx===n.ClipperBase.horizontal&&e!==r&&e.Bot.X!==e.Next.Top.X&&this.ReverseHorizontal(e),i=i.Prev}return i},n.ClipperBase.prototype.AddPath=function(e,t,r){n.use_lines?!r&&t===n.PolyType.ptClip&&n.Error("AddPath: Open paths must be subject."):r||n.Error("AddPath: Open paths have been disabled.");var i=e.length-1;if(r)for(;i>0&&n.IntPoint.op_Equality(e[i],e[0]);)--i;for(;i>0&&n.IntPoint.op_Equality(e[i],e[i-1]);)--i;if(r&&i<2||!r&&i<1)return!1;for(var o=new Array,l=0;l<=i;l++)o.push(new n.TEdge);var f=!0;o[1].Curr.X=e[1].X,o[1].Curr.Y=e[1].Y,n.use_xyz&&(o[1].Curr.Z=e[1].Z);var d={Value:this.m_UseFullRange};this.RangeTest(e[0],d),this.m_UseFullRange=d.Value,d.Value=this.m_UseFullRange,this.RangeTest(e[i],d),this.m_UseFullRange=d.Value,this.InitEdge(o[0],o[1],o[i],e[0]),this.InitEdge(o[i],o[0],o[i-1],e[i]);for(var l=i-1;l>=1;--l)d.Value=this.m_UseFullRange,this.RangeTest(e[l],d),this.m_UseFullRange=d.Value,this.InitEdge(o[l],o[l+1],o[l-1],e[l]);for(var y=o[0],v=y,A=y;;){if(v.Curr===v.Next.Curr&&(r||v.Next!==y)){if(v===v.Next)break;v===y&&(y=v.Next),v=this.RemoveEdge(v),A=v;continue}if(v.Prev===v.Next)break;if(r&&n.ClipperBase.SlopesEqual4(v.Prev.Curr,v.Curr,v.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(v.Prev.Curr,v.Curr,v.Next.Curr))){v===y&&(y=v.Next),v=this.RemoveEdge(v),v=v.Prev,A=v;continue}if(v=v.Next,v===A||!r&&v.Next===y)break}if(!r&&v===v.Next||r&&v.Prev===v.Next)return!1;r||(this.m_HasOpenPaths=!0,y.Prev.OutIdx=n.ClipperBase.Skip),v=y;do this.InitEdge2(v,t),v=v.Next,f&&v.Curr.Y!==y.Curr.Y&&(f=!1);while(v!==y);if(f){if(r)return!1;v.Prev.OutIdx=n.ClipperBase.Skip;var k=new n.LocalMinima;for(k.Next=null,k.Y=v.Bot.Y,k.LeftBound=null,k.RightBound=v,k.RightBound.Side=n.EdgeSide.esRight,k.RightBound.WindDelta=0;v.Bot.X!==v.Prev.Top.X&&this.ReverseHorizontal(v),v.Next.OutIdx!==n.ClipperBase.Skip;)v.NextInLML=v.Next,v=v.Next;return this.InsertLocalMinima(k),this.m_edges.push(o),!0}this.m_edges.push(o);var X,j=null;for(n.IntPoint.op_Equality(v.Prev.Bot,v.Prev.Top)&&(v=v.Next);v=this.FindNextLocMin(v),v!==j;){j===null&&(j=v);var k=new n.LocalMinima;k.Next=null,k.Y=v.Bot.Y,v.Dx<v.Prev.Dx?(k.LeftBound=v.Prev,k.RightBound=v,X=!1):(k.LeftBound=v,k.RightBound=v.Prev,X=!0),k.LeftBound.Side=n.EdgeSide.esLeft,k.RightBound.Side=n.EdgeSide.esRight,r?k.LeftBound.Next===k.RightBound?k.LeftBound.WindDelta=-1:k.LeftBound.WindDelta=1:k.LeftBound.WindDelta=0,k.RightBound.WindDelta=-k.LeftBound.WindDelta,v=this.ProcessBound(k.LeftBound,X),v.OutIdx===n.ClipperBase.Skip&&(v=this.ProcessBound(v,X));var V=this.ProcessBound(k.RightBound,!X);V.OutIdx===n.ClipperBase.Skip&&(V=this.ProcessBound(V,!X)),k.LeftBound.OutIdx===n.ClipperBase.Skip?k.LeftBound=null:k.RightBound.OutIdx===n.ClipperBase.Skip&&(k.RightBound=null),this.InsertLocalMinima(k),X||(v=V)}return!0},n.ClipperBase.prototype.AddPaths=function(e,t,r){for(var i=!1,o=0,l=e.length;o<l;++o)this.AddPath(e[o],t,r)&&(i=!0);return i},n.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(e,t,r){return n.IntPoint.op_Equality(e,r)||n.IntPoint.op_Equality(e,t)||n.IntPoint.op_Equality(r,t)?!1:e.X!==r.X?t.X>e.X==t.X<r.X:t.Y>e.Y==t.Y<r.Y},n.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var t=e.Next;return e.Prev=null,t},n.ClipperBase.prototype.SetDx=function(e){e.Delta.X=e.Top.X-e.Bot.X,e.Delta.Y=e.Top.Y-e.Bot.Y,e.Delta.Y===0?e.Dx=n.ClipperBase.horizontal:e.Dx=e.Delta.X/e.Delta.Y},n.ClipperBase.prototype.InsertLocalMinima=function(e){if(this.m_MinimaList===null)this.m_MinimaList=e;else if(e.Y>=this.m_MinimaList.Y)e.Next=this.m_MinimaList,this.m_MinimaList=e;else{for(var t=this.m_MinimaList;t.Next!==null&&e.Y<t.Next.Y;)t=t.Next;e.Next=t.Next,t.Next=e}},n.ClipperBase.prototype.PopLocalMinima=function(e,t){return t.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===e?(this.m_CurrentLM=this.m_CurrentLM.Next,!0):!1},n.ClipperBase.prototype.ReverseHorizontal=function(e){var t=e.Top.X;e.Top.X=e.Bot.X,e.Bot.X=t,n.use_xyz&&(t=e.Top.Z,e.Top.Z=e.Bot.Z,e.Bot.Z=t)},n.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,this.m_CurrentLM!==null){this.m_Scanbeam=null;for(var e=this.m_MinimaList;e!==null;){this.InsertScanbeam(e.Y);var t=e.LeftBound;t!==null&&(t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,n.use_xyz&&(t.Curr.Z=t.Bot.Z),t.OutIdx=n.ClipperBase.Unassigned),t=e.RightBound,t!==null&&(t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,n.use_xyz&&(t.Curr.Z=t.Bot.Z),t.OutIdx=n.ClipperBase.Unassigned),e=e.Next}this.m_ActiveEdges=null}},n.ClipperBase.prototype.InsertScanbeam=function(e){if(this.m_Scanbeam===null)this.m_Scanbeam=new n.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=e;else if(e>this.m_Scanbeam.Y){var t=new n.Scanbeam;t.Y=e,t.Next=this.m_Scanbeam,this.m_Scanbeam=t}else{for(var r=this.m_Scanbeam;r.Next!==null&&e<=r.Next.Y;)r=r.Next;if(e===r.Y)return;var i=new n.Scanbeam;i.Y=e,i.Next=r.Next,r.Next=i}},n.ClipperBase.prototype.PopScanbeam=function(e){return this.m_Scanbeam===null?(e.v=0,!1):(e.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 e=new n.OutRec;return e.Idx=n.ClipperBase.Unassigned,e.IsHole=!1,e.IsOpen=!1,e.FirstLeft=null,e.Pts=null,e.BottomPt=null,e.PolyNode=null,this.m_PolyOuts.push(e),e.Idx=this.m_PolyOuts.length-1,e},n.ClipperBase.prototype.DisposeOutRec=function(e){var t=this.m_PolyOuts[e];t.Pts=null,t=null,this.m_PolyOuts[e]=null},n.ClipperBase.prototype.UpdateEdgeIntoAEL=function(e){e.NextInLML===null&&n.Error("UpdateEdgeIntoAEL: invalid call");var t=e.PrevInAEL,r=e.NextInAEL;return e.NextInLML.OutIdx=e.OutIdx,t!==null?t.NextInAEL=e.NextInLML:this.m_ActiveEdges=e.NextInLML,r!==null&&(r.PrevInAEL=e.NextInLML),e.NextInLML.Side=e.Side,e.NextInLML.WindDelta=e.WindDelta,e.NextInLML.WindCnt=e.WindCnt,e.NextInLML.WindCnt2=e.WindCnt2,e=e.NextInLML,e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,e.PrevInAEL=t,e.NextInAEL=r,n.ClipperBase.IsHorizontal(e)||this.InsertScanbeam(e.Top.Y),e},n.ClipperBase.prototype.SwapPositionsInAEL=function(e,t){if(!(e.NextInAEL===e.PrevInAEL||t.NextInAEL===t.PrevInAEL)){if(e.NextInAEL===t){var r=t.NextInAEL;r!==null&&(r.PrevInAEL=e);var i=e.PrevInAEL;i!==null&&(i.NextInAEL=t),t.PrevInAEL=i,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=r}else if(t.NextInAEL===e){var o=e.NextInAEL;o!==null&&(o.PrevInAEL=t);var l=t.PrevInAEL;l!==null&&(l.NextInAEL=e),e.PrevInAEL=l,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=o}else{var f=e.NextInAEL,d=e.PrevInAEL;e.NextInAEL=t.NextInAEL,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=t.PrevInAEL,e.PrevInAEL!==null&&(e.PrevInAEL.NextInAEL=e),t.NextInAEL=f,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=d,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t)}e.PrevInAEL===null?this.m_ActiveEdges=e:t.PrevInAEL===null&&(this.m_ActiveEdges=t)}},n.ClipperBase.prototype.DeleteFromAEL=function(e){var t=e.PrevInAEL,r=e.NextInAEL;t===null&&r===null&&e!==this.m_ActiveEdges||(t!==null?t.NextInAEL=r:this.m_ActiveEdges=r,r!==null&&(r.PrevInAEL=t),e.NextInAEL=null,e.PrevInAEL=null)},n.Clipper=function(e){typeof e>"u"&&(e=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&e)!==0,this.StrictlySimple=(2&e)!==0,this.PreserveCollinear=(4&e)!==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(e){var t=new n.Maxima;if(t.X=e,this.m_Maxima===null)this.m_Maxima=t,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(e<this.m_Maxima.X)t.Next=this.m_Maxima,t.Prev=null,this.m_Maxima=t;else{for(var r=this.m_Maxima;r.Next!==null&&e>=r.Next.X;)r=r.Next;if(e===r.X)return;t.Next=r.Next,t.Prev=r,r.Next!==null&&(r.Next.Prev=t),r.Next=t}},n.Clipper.prototype.Execute=function(){var e=arguments,t=e.length,r=e[1]instanceof n.PolyTree;if(t===4&&!r){var i=e[0],o=e[1],l=e[2],f=e[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(o),this.m_SubjFillType=l,this.m_ClipFillType=f,this.m_ClipType=i,this.m_UsingPolyTree=!1;try{var d=this.ExecuteInternal();d&&this.BuildResult(o)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return d}else if(t===4&&r){var i=e[0],y=e[1],l=e[2],f=e[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=l,this.m_ClipFillType=f,this.m_ClipType=i,this.m_UsingPolyTree=!0;try{var d=this.ExecuteInternal();d&&this.BuildResult2(y)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return d}else if(t===2&&!r){var i=e[0],o=e[1];return this.Execute(i,o,n.PolyFillType.pftEvenOdd,n.PolyFillType.pftEvenOdd)}else if(t===2&&r){var i=e[0],y=e[1];return this.Execute(i,y,n.PolyFillType.pftEvenOdd,n.PolyFillType.pftEvenOdd)}},n.Clipper.prototype.FixHoleLinkage=function(e){if(!(e.FirstLeft===null||e.IsHole!==e.FirstLeft.IsHole&&e.FirstLeft.Pts!==null)){for(var t=e.FirstLeft;t!==null&&(t.IsHole===e.IsHole||t.Pts===null);)t=t.FirstLeft;e.FirstLeft=t}},n.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var e={},t={};if(!this.PopScanbeam(e))return!1;for(this.InsertLocalMinimaIntoAEL(e.v);this.PopScanbeam(t)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(t.v))return!1;this.ProcessEdgesAtTopOfScanbeam(t.v),e.v=t.v,this.InsertLocalMinimaIntoAEL(e.v)}var r,i,o;for(i=0,o=this.m_PolyOuts.length;i<o;i++)r=this.m_PolyOuts[i],!(r.Pts===null||r.IsOpen)&&(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts);for(this.JoinCommonEdges(),i=0,o=this.m_PolyOuts.length;i<o;i++)r=this.m_PolyOuts[i],r.Pts!==null&&(r.IsOpen?this.FixupOutPolyline(r):this.FixupOutPolygon(r));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},n.Clipper.prototype.DisposeAllPolyPts=function(){for(var e=0,t=this.m_PolyOuts.length;e<t;++e)this.DisposeOutRec(e);n.Clear(this.m_PolyOuts)},n.Clipper.prototype.AddJoin=function(e,t,r){var i=new n.Join;i.OutPt1=e,i.OutPt2=t,i.OffPt.X=r.X,i.OffPt.Y=r.Y,n.use_xyz&&(i.OffPt.Z=r.Z),this.m_Joins.push(i)},n.Clipper.prototype.AddGhostJoin=function(e,t){var r=new n.Join;r.OutPt1=e,r.OffPt.X=t.X,r.OffPt.Y=t.Y,n.use_xyz&&(r.OffPt.Z=t.Z),this.m_GhostJoins.push(r)},n.Clipper.prototype.SetZ=function(e,t,r){if(this.ZFillFunction!==null){if(e.Z!==0||this.ZFillFunction===null)return;n.IntPoint.op_Equality(e,t.Bot)?e.Z=t.Bot.Z:n.IntPoint.op_Equality(e,t.Top)?e.Z=t.Top.Z:n.IntPoint.op_Equality(e,r.Bot)?e.Z=r.Bot.Z:n.IntPoint.op_Equality(e,r.Top)?e.Z=r.Top.Z:this.ZFillFunction(t.Bot,t.Top,r.Bot,r.Top,e)}},n.Clipper.prototype.InsertLocalMinimaIntoAEL=function(e){for(var t={},r,i;this.PopLocalMinima(e,t);){r=t.v.LeftBound,i=t.v.RightBound;var o=null;if(r===null?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(o=this.AddOutPt(i,i.Bot))):i===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(o=this.AddOutPt(r,r.Bot)),this.InsertScanbeam(r.Top.Y)):(this.InsertEdgeIntoAEL(r,null),this.InsertEdgeIntoAEL(i,r),this.SetWindingCount(r),i.WindCnt=r.WindCnt,i.WindCnt2=r.WindCnt2,this.IsContributing(r)&&(o=this.AddLocalMinPoly(r,i,r.Bot)),this.InsertScanbeam(r.Top.Y)),i!==null&&(n.ClipperBase.IsHorizontal(i)?(i.NextInLML!==null&&this.InsertScanbeam(i.NextInLML.Top.Y),this.AddEdgeToSEL(i)):this.InsertScanbeam(i.Top.Y)),!(r===null||i===null)){if(o!==null&&n.ClipperBase.IsHorizontal(i)&&this.m_GhostJoins.length>0&&i.WindDelta!==0)for(var l=0,f=this.m_GhostJoins.length;l<f;l++){var d=this.m_GhostJoins[l];this.HorzSegmentsOverlap(d.OutPt1.Pt.X,d.OffPt.X,i.Bot.X,i.Top.X)&&this.AddJoin(d.OutPt1,o,d.OffPt)}if(r.OutIdx>=0&&r.PrevInAEL!==null&&r.PrevInAEL.Curr.X===r.Bot.X&&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 y=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(o,y,r.Top)}if(r.NextInAEL!==i){if(i.OutIdx>=0&&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 y=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(o,y,i.Top)}var v=r.NextInAEL;if(v!==null)for(;v!==i;)this.IntersectEdges(i,v,r.Curr),v=v.NextInAEL}}}},n.Clipper.prototype.InsertEdgeIntoAEL=function(e,t){if(this.m_ActiveEdges===null)e.PrevInAEL=null,e.NextInAEL=null,this.m_ActiveEdges=e;else if(t===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,e))e.PrevInAEL=null,e.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=e,this.m_ActiveEdges=e;else{for(t===null&&(t=this.m_ActiveEdges);t.NextInAEL!==null&&!this.E2InsertsBeforeE1(t.NextInAEL,e);)t=t.NextInAEL;e.NextInAEL=t.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=e),e.PrevInAEL=t,t.NextInAEL=e}},n.Clipper.prototype.E2InsertsBeforeE1=function(e,t){return t.Curr.X===e.Curr.X?t.Top.Y>e.Top.Y?t.Top.X<n.Clipper.TopX(e,t.Top.Y):e.Top.X>n.Clipper.TopX(t,e.Top.Y):t.Curr.X<e.Curr.X},n.Clipper.prototype.IsEvenOddFillType=function(e){return e.PolyTyp===n.PolyType.ptSubject?this.m_SubjFillType===n.PolyFillType.pftEvenOdd:this.m_ClipFillType===n.PolyFillType.pftEvenOdd},n.Clipper.prototype.IsEvenOddAltFillType=function(e){return e.PolyTyp===n.PolyType.ptSubject?this.m_ClipFillType===n.PolyFillType.pftEvenOdd:this.m_SubjFillType===n.PolyFillType.pftEvenOdd},n.Clipper.prototype.IsContributing=function(e){var t,r;switch(e.PolyTyp===n.PolyType.ptSubject?(t=this.m_SubjFillType,r=this.m_ClipFillType):(t=this.m_ClipFillType,r=this.m_SubjFillType),t){case n.PolyFillType.pftEvenOdd:if(e.WindDelta===0&&e.WindCnt!==1)return!1;break;case n.PolyFillType.pftNonZero:if(Math.abs(e.WindCnt)!==1)return!1;break;case n.PolyFillType.pftPositive:if(e.WindCnt!==1)return!1;break;default:if(e.WindCnt!==-1)return!1;break}switch(this.m_ClipType){case n.ClipType.ctIntersection:switch(r){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return e.WindCnt2!==0;case n.PolyFillType.pftPositive:return e.WindCnt2>0;default:return e.WindCnt2<0}case n.ClipType.ctUnion:switch(r){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return e.WindCnt2===0;case n.PolyFillType.pftPositive:return e.WindCnt2<=0;default:return e.WindCnt2>=0}case n.ClipType.ctDifference:if(e.PolyTyp===n.PolyType.ptSubject)switch(r){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return e.WindCnt2===0;case n.PolyFillType.pftPositive:return e.WindCnt2<=0;default:return e.WindCnt2>=0}else switch(r){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return e.WindCnt2!==0;case n.PolyFillType.pftPositive:return e.WindCnt2>0;default:return e.WindCnt2<0}case n.ClipType.ctXor:if(e.WindDelta===0)switch(r){case n.PolyFillType.pftEvenOdd:case n.PolyFillType.pftNonZero:return e.WindCnt2===0;case n.PolyFillType.pftPositive:return e.WindCnt2<=0;default:return e.WindCnt2>=0}else return!0}return!0},n.Clipper.prototype.SetWindingCount=function(e){for(var t=e.PrevInAEL;t!==null&&(t.PolyTyp!==e.PolyTyp||t.WindDelta===0);)t=t.PrevInAEL;if(t===null){var r=e.PolyTyp===n.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;e.WindDelta===0?e.WindCnt=r===n.PolyFillType.pftNegative?-1:1:e.WindCnt=e.WindDelta,e.WindCnt2=0,t=this.m_ActiveEdges}else if(e.WindDelta===0&&this.m_ClipType!==n.ClipType.ctUnion)e.WindCnt=1,e.WindCnt2=t.WindCnt2,t=t.NextInAEL;else if(this.IsEvenOddFillType(e)){if(e.WindDelta===0){for(var i=!0,o=t.PrevInAEL;o!==null;)o.PolyTyp===t.PolyTyp&&o.WindDelta!==0&&(i=!i),o=o.PrevInAEL;e.WindCnt=i?0:1}else e.WindCnt=e.WindDelta;e.WindCnt2=t.WindCnt2,t=t.NextInAEL}else t.WindCnt*t.WindDelta<0?Math.abs(t.WindCnt)>1?t.WindDelta*e.WindDelta<0?e.WindCnt=t.WindCnt:e.WindCnt=t.WindCnt+e.WindDelta:e.WindCnt=e.WindDelta===0?1:e.WindDelta:e.WindDelta===0?e.WindCnt=t.WindCnt<0?t.WindCnt-1:t.WindCnt+1:t.WindDelta*e.WindDelta<0?e.WindCnt=t.WindCnt:e.WindCnt=t.WindCnt+e.WindDelta,e.WindCnt2=t.WindCnt2,t=t.NextInAEL;if(this.IsEvenOddAltFillType(e))for(;t!==e;)t.WindDelta!==0&&(e.WindCnt2=e.WindCnt2===0?1:0),t=t.NextInAEL;else for(;t!==e;)e.WindCnt2+=t.WindDelta,t=t.NextInAEL},n.Clipper.prototype.AddEdgeToSEL=function(e){this.m_SortedEdges===null?(this.m_SortedEdges=e,e.PrevInSEL=null,e.NextInSEL=null):(e.NextInSEL=this.m_SortedEdges,e.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=e,this.m_SortedEdges=e)},n.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,e.v===null)return!1;var t=e.v;return this.m_SortedEdges=e.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),t.NextInSEL=null,t.PrevInSEL=null,!0},n.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;e!==null;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},n.Clipper.prototype.SwapPositionsInSEL=function(e,t){if(!(e.NextInSEL===null&&e.PrevInSEL===null)&&!(t.NextInSEL===null&&t.PrevInSEL===null)){if(e.NextInSEL===t){var r=t.NextInSEL;r!==null&&(r.PrevInSEL=e);var i=e.PrevInSEL;i!==null&&(i.NextInSEL=t),t.PrevInSEL=i,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=r}else if(t.NextInSEL===e){var r=e.NextInSEL;r!==null&&(r.PrevInSEL=t);var i=t.PrevInSEL;i!==null&&(i.NextInSEL=e),e.PrevInSEL=i,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=r}else{var r=e.NextInSEL,i=e.PrevInSEL;e.NextInSEL=t.NextInSEL,e.NextInSEL!==null&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=t.PrevInSEL,e.PrevInSEL!==null&&(e.PrevInSEL.NextInSEL=e),t.NextInSEL=r,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=i,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t)}e.PrevInSEL===null?this.m_SortedEdges=e:t.PrevInSEL===null&&(this.m_SortedEdges=t)}},n.Clipper.prototype.AddLocalMaxPoly=function(e,t,r){this.AddOutPt(e,r),t.WindDelta===0&&this.AddOutPt(t,r),e.OutIdx===t.OutIdx?(e.OutIdx=-1,t.OutIdx=-1):e.OutIdx<t.OutIdx?this.AppendPolygon(e,t):this.AppendPolygon(t,e)},n.Clipper.prototype.AddLocalMinPoly=function(e,t,r){var i,o,l;if(n.ClipperBase.IsHorizontal(t)||e.Dx>t.Dx?(i=this.AddOutPt(e,r),t.OutIdx=e.OutIdx,e.Side=n.EdgeSide.esLeft,t.Side=n.EdgeSide.esRight,o=e,o.PrevInAEL===t?l=t.PrevInAEL:l=o.PrevInAEL):(i=this.AddOutPt(t,r),e.OutIdx=t.OutIdx,e.Side=n.EdgeSide.esRight,t.Side=n.EdgeSide.esLeft,o=t,o.PrevInAEL===e?l=e.PrevInAEL:l=o.PrevInAEL),l!==null&&l.OutIdx>=0&&l.Top.Y<r.Y&&o.Top.Y<r.Y){var f=n.Clipper.TopX(l,r.Y),d=n.Clipper.TopX(o,r.Y);if(f===d&&o.WindDelta!==0&&l.WindDelta!==0&&n.ClipperBase.SlopesEqual5(new n.IntPoint2(f,r.Y),l.Top,new n.IntPoint2(d,r.Y),o.Top,this.m_UseFullRange)){var y=this.AddOutPt(l,r);this.AddJoin(i,y,o.Top)}}return i},n.Clipper.prototype.AddOutPt=function(e,t){if(e.OutIdx<0){var r=this.CreateOutRec();r.IsOpen=e.WindDelta===0;var i=new n.OutPt;return r.Pts=i,i.Idx=r.Idx,i.Pt.X=t.X,i.Pt.Y=t.Y,n.use_xyz&&(i.Pt.Z=t.Z),i.Next=i,i.Prev=i,r.IsOpen||this.SetHoleState(e,r),e.OutIdx=r.Idx,i}else{var r=this.m_PolyOuts[e.OutIdx],o=r.Pts,l=e.Side===n.EdgeSide.esLeft;if(l&&n.IntPoint.op_Equality(t,o.Pt))return o;if(!l&&n.IntPoint.op_Equality(t,o.Prev.Pt))return o.Prev;var i=new n.OutPt;return i.Idx=r.Idx,i.Pt.X=t.X,i.Pt.Y=t.Y,n.use_xyz&&(i.Pt.Z=t.Z),i.Next=o,i.Prev=o.Prev,i.Prev.Next=i,o.Prev=i,l&&(r.Pts=i),i}},n.Clipper.prototype.GetLastOutPt=function(e){var t=this.m_PolyOuts[e.OutIdx];return e.Side===n.EdgeSide.esLeft?t.Pts:t.Pts.Prev},n.Clipper.prototype.SwapPoints=function(e,t){var r=new n.IntPoint1(e.Value);e.Value.X=t.Value.X,e.Value.Y=t.Value.Y,n.use_xyz&&(e.Value.Z=t.Value.Z),t.Value.X=r.X,t.Value.Y=r.Y,n.use_xyz&&(t.Value.Z=r.Z)},n.Clipper.prototype.HorzSegmentsOverlap=function(e,t,r,i){var o;return e>t&&(o=e,e=t,t=o),r>i&&(o=r,r=i,i=o),e<i&&r<t},n.Clipper.prototype.SetHoleState=function(e,t){for(var r=e.PrevInAEL,i=null;r!==null;)r.OutIdx>=0&&r.WindDelta!==0&&(i===null?i=r:i.OutIdx===r.OutIdx&&(i=null)),r=r.PrevInAEL;i===null?(t.FirstLeft=null,t.IsHole=!1):(t.FirstLeft=this.m_PolyOuts[i.OutIdx],t.IsHole=!t.FirstLeft.IsHole)},n.Clipper.prototype.GetDx=function(e,t){return e.Y===t.Y?n.ClipperBase.horizontal:(t.X-e.X)/(t.Y-e.Y)},n.Clipper.prototype.FirstIsBottomPt=function(e,t){for(var r=e.Prev;n.IntPoint.op_Equality(r.Pt,e.Pt)&&r!==e;)r=r.Prev;var i=Math.abs(this.GetDx(e.Pt,r.Pt));for(r=e.Next;n.IntPoint.op_Equality(r.Pt,e.Pt)&&r!==e;)r=r.Next;var o=Math.abs(this.GetDx(e.Pt,r.Pt));for(r=t.Prev;n.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Prev;var l=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=t.Next;n.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Next;var f=Math.abs(this.GetDx(t.Pt,r.Pt));return Math.max(i,o)===Math.max(l,f)&&Math.min(i,o)===Math.min(l,f)?this.Area(e)>0:i>=l&&i>=f||o>=l&&o>=f},n.Clipper.prototype.GetBottomPt=function(e){for(var t=null,r=e.Next;r!==e;)r.Pt.Y>e.Pt.Y?(e=r,t=null):r.Pt.Y===e.Pt.Y&&r.Pt.X<=e.Pt.X&&(r.Pt.X<e.Pt.X?(t=null,e=r):r.Next!==e&&r.Prev!==e&&(t=r)),r=r.Next;if(t!==null)for(;t!==r;)for(this.FirstIsBottomPt(r,t)||(e=t),t=t.Next;n.IntPoint.op_Inequality(t.Pt,e.Pt);)t=t.Next;return e},n.Clipper.prototype.GetLowermostRec=function(e,t){e.BottomPt===null&&(e.BottomPt=this.GetBottomPt(e.Pts)),t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts));var r=e.BottomPt,i=t.BottomPt;return r.Pt.Y>i.Pt.Y?e:r.Pt.Y<i.Pt.Y?t:r.Pt.X<i.Pt.X?e:r.Pt.X>i.Pt.X||r.Next===r?t:i.Next===i||this.FirstIsBottomPt(r,i)?e:t},n.Clipper.prototype.OutRec1RightOfOutRec2=function(e,t){do if(e=e.FirstLeft,e===t)return!0;while(e!==null);return!1},n.Clipper.prototype.GetOutRec=function(e){for(var t=this.m_PolyOuts[e];t!==this.m_PolyOuts[t.Idx];)t=this.m_PolyOuts[t.Idx];return t},n.Clipper.prototype.AppendPolygon=function(e,t){var r=this.m_PolyOuts[e.OutIdx],i=this.m_PolyOuts[t.OutIdx],o;this.OutRec1RightOfOutRec2(r,i)?o=i:this.OutRec1RightOfOutRec2(i,r)?o=r:o=this.GetLowermostRec(r,i);var l=r.Pts,f=l.Prev,d=i.Pts,y=d.Prev;e.Side===n.EdgeSide.esLeft?t.Side===n.EdgeSide.esLeft?(this.ReversePolyPtLinks(d),d.Next=l,l.Prev=d,f.Next=y,y.Prev=f,r.Pts=y):(y.Next=l,l.Prev=y,d.Prev=f,f.Next=d,r.Pts=d):t.Side===n.EdgeSide.esRight?(this.ReversePolyPtLinks(d),f.Next=y,y.Prev=f,d.Next=l,l.Prev=d):(f.Next=d,d.Prev=f,l.Prev=y,y.Next=l),r.BottomPt=null,o===i&&(i.FirstLeft!==r&&(r.FirstLeft=i.FirstLeft),r.IsHole=i.IsHole),i.Pts=null,i.BottomPt=null,i.FirstLeft=r;var v=e.OutIdx,A=t.OutIdx;e.OutIdx=-1,t.OutIdx=-1;for(var k=this.m_ActiveEdges;k!==null;){if(k.OutIdx===A){k.OutIdx=v,k.Side=e.Side;break}k=k.NextInAEL}i.Idx=r.Idx},n.Clipper.prototype.ReversePolyPtLinks=function(e){if(e!==null){var t,r;t=e;do r=t.Next,t.Next=t.Prev,t.Prev=r,t=r;while(t!==e)}},n.Clipper.SwapSides=function(e,t){var r=e.Side;e.Side=t.Side,t.Side=r},n.Clipper.SwapPolyIndexes=function(e,t){var r=e.OutIdx;e.OutIdx=t.OutIdx,t.OutIdx=r},n.Clipper.prototype.IntersectEdges=function(e,t,r){var i=e.OutIdx>=0,o=t.OutIdx>=0;if(n.use_xyz&&this.SetZ(r,e,t),n.use_lines&&(e.WindDelta===0||t.WindDelta===0)){if(e.WindDelta===0&&t.WindDelta===0)return;e.PolyTyp===t.PolyTyp&&e.WindDelta!==t.WindDelta&&this.m_ClipType===n.ClipType.ctUnion?e.WindDelta===0?o&&(this.AddOutPt(e,r),i&&(e.OutIdx=-1)):i&&(this.AddOutPt(t,r),o&&(t.OutIdx=-1)):e.PolyTyp!==t.PolyTyp&&(e.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==n.ClipType.ctUnion||t.WindCnt2===0)?(this.AddOutPt(e,r),i&&(e.OutIdx=-1)):t.WindDelta===0&&Math.abs(e.WindCnt)===1&&(this.m_ClipType!==n.ClipType.ctUnion||e.WindCnt2===0)&&(this.AddOutPt(t,r),o&&(t.OutIdx=-1)));return}if(e.PolyTyp===t.PolyTyp)if(this.IsEvenOddFillType(e)){var l=e.WindCnt;e.WindCnt=t.WindCnt,t.WindCnt=l}else e.WindCnt+t.WindDelta===0?e.WindCnt=-e.WindCnt:e.WindCnt+=t.WindDelta,t.WindCnt-e.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt-=e.WindDelta;else this.IsEvenOddFillType(t)?e.WindCnt2=e.WindCnt2===0?1:0:e.WindCnt2+=t.WindDelta,this.IsEvenOddFillType(e)?t.WindCnt2=t.WindCnt2===0?1:0:t.WindCnt2-=e.WindDelta;var f,d,y,v;e.PolyTyp===n.PolyType.ptSubject?(f=this.m_SubjFillType,y=this.m_ClipFillType):(f=this.m_ClipFillType,y=this.m_SubjFillType),t.PolyTyp===n.PolyType.ptSubject?(d=this.m_SubjFillType,v=this.m_ClipFillType):(d=this.m_ClipFillType,v=this.m_SubjFillType);var A,k;switch(f){case n.PolyFillType.pftPositive:A=e.WindCnt;break;case n.PolyFillType.pftNegative:A=-e.WindCnt;break;default:A=Math.abs(e.WindCnt);break}switch(d){case n.PolyFillType.pftPositive:k=t.WindCnt;break;case n.PolyFillType.pftNegative:k=-t.WindCnt;break;default:k=Math.abs(t.WindCnt);break}if(i&&o)A!==0&&A!==1||k!==0&&k!==1||e.PolyTyp!==t.PolyTyp&&this.m_ClipType!==n.ClipType.ctXor?this.AddLocalMaxPoly(e,t,r):(this.AddOutPt(e,r),this.AddOutPt(t,r),n.Clipper.SwapSides(e,t),n.Clipper.SwapPolyIndexes(e,t));else if(i)(k===0||k===1)&&(this.AddOutPt(e,r),n.Clipper.SwapSides(e,t),n.Clipper.SwapPolyIndexes(e,t));else if(o)(A===0||A===1)&&(this.AddOutPt(t,r),n.Clipper.SwapSides(e,t),n.Clipper.SwapPolyIndexes(e,t));else if((A===0||A===1)&&(k===0||k===1)){var X,j;switch(y){case n.PolyFillType.pftPositive:X=e.WindCnt2;break;case n.PolyFillType.pftNegative:X=-e.WindCnt2;break;default:X=Math.abs(e.WindCnt2);break}switch(v){case n.PolyFillType.pftPositive:j=t.WindCnt2;break;case n.PolyFillType.pftNegative:j=-t.WindCnt2;break;default:j=Math.abs(t.WindCnt2);break}if(e.PolyTyp!==t.PolyTyp)this.AddLocalMinPoly(e,t,r);else if(A===1&&k===1)switch(this.m_ClipType){case n.ClipType.ctIntersection:X>0&&j>0&&this.AddLocalMinPoly(e,t,r);break;case n.ClipType.ctUnion:X<=0&&j<=0&&this.AddLocalMinPoly(e,t,r);break;case n.ClipType.ctDifference:(e.PolyTyp===n.PolyType.ptClip&&X>0&&j>0||e.PolyTyp===n.PolyType.ptSubject&&X<=0&&j<=0)&&this.AddLocalMinPoly(e,t,r);break;case n.ClipType.ctXor:this.AddLocalMinPoly(e,t,r);break}else n.Clipper.SwapSides(e,t)}},n.Clipper.prototype.DeleteFromSEL=function(e){var t=e.PrevInSEL,r=e.NextInSEL;t===null&&r===null&&e!==this.m_SortedEdges||(t!==null?t.NextInSEL=r:this.m_SortedEdges=r,r!==null&&(r.PrevInSEL=t),e.NextInSEL=null,e.PrevInSEL=null)},n.Clipper.prototype.ProcessHorizontals=function(){for(var e={};this.PopEdgeFromSEL(e);)this.ProcessHorizontal(e.v)},n.Clipper.prototype.GetHorzDirection=function(e,t){e.Bot.X<e.Top.X?(t.Left=e.Bot.X,t.Right=e.Top.X,t.Dir=n.Direction.dLeftToRight):(t.Left=e.Top.X,t.Right=e.Bot.X,t.Dir=n.Direction.dRightToLeft)},n.Clipper.prototype.ProcessHorizontal=function(e){var t={Dir:null,Left:null,Right:null};this.GetHorzDirection(e,t);for(var r=t.Dir,i=t.Left,o=t.Right,l=e.WindDelta===0,f=e,d=null;f.NextInLML!==null&&n.ClipperBase.IsHorizontal(f.NextInLML);)f=f.NextInLML;f.NextInLML===null&&(d=this.GetMaximaPair(f));var y=this.m_Maxima;if(y!==null)if(r===n.Direction.dLeftToRight){for(;y!==null&&y.X<=e.Bot.X;)y=y.Next;y!==null&&y.X>=f.Top.X&&(y=null)}else{for(;y.Next!==null&&y.Next.X<e.Bot.X;)y=y.Next;y.X<=f.Top.X&&(y=null)}for(var v=null;;){for(var A=e===f,k=this.GetNextInAEL(e,r);k!==null;){if(y!==null)if(r===n.Direction.dLeftToRight)for(;y!==null&&y.X<k.Curr.X;)e.OutIdx>=0&&!l&&this.AddOutPt(e,new n.IntPoint2(y.X,e.Bot.Y)),y=y.Next;else for(;y!==null&&y.X>k.Curr.X;)e.OutIdx>=0&&!l&&this.AddOutPt(e,new n.IntPoint2(y.X,e.Bot.Y)),y=y.Prev;if(r===n.Direction.dLeftToRight&&k.Curr.X>o||r===n.Direction.dRightToLeft&&k.Curr.X<i||k.Curr.X===e.Top.X&&e.NextInLML!==null&&k.Dx<e.NextInLML.Dx)break;if(e.OutIdx>=0&&!l){n.use_xyz&&(r===n.Direction.dLeftToRight?this.SetZ(k.Curr,e,k):this.SetZ(k.Curr,k,e)),v=this.AddOutPt(e,k.Curr);for(var X=this.m_SortedEdges;X!==null;){if(X.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,X.Bot.X,X.Top.X)){var j=this.GetLastOutPt(X);this.AddJoin(j,v,X.Top)}X=X.NextInSEL}this.AddGhostJoin(v,e.Bot)}if(k===d&&A){e.OutIdx>=0&&this.AddLocalMaxPoly(e,d,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(d);return}if(r===n.Direction.dLeftToRight){var V=new n.IntPoint2(k.Curr.X,e.Curr.Y);this.IntersectEdges(e,k,V)}else{var V=new n.IntPoint2(k.Curr.X,e.Curr.Y);this.IntersectEdges(k,e,V)}var z=this.GetNextInAEL(k,r);this.SwapPositionsInAEL(e,k),k=z}if(e.NextInLML===null||!n.ClipperBase.IsHorizontal(e.NextInLML))break;e=this.UpdateEdgeIntoAEL(e),e.OutIdx>=0&&this.AddOutPt(e,e.Bot),t={Dir:r,Left:i,Right:o},this.GetHorzDirection(e,t),r=t.Dir,i=t.Left,o=t.Right}if(e.OutIdx>=0&&v===null){v=this.GetLastOutPt(e);for(var X=this.m_SortedEdges;X!==null;){if(X.OutIdx>=0&&this.HorzSegmentsOverlap(e.Bot.X,e.Top.X,X.Bot.X,X.Top.X)){var j=this.GetLastOutPt(X);this.AddJoin(j,v,X.Top)}X=X.NextInSEL}this.AddGhostJoin(v,e.Top)}if(e.NextInLML!==null)if(e.OutIdx>=0){if(v=this.AddOutPt(e,e.Top),e=this.UpdateEdgeIntoAEL(e),e.WindDelta===0)return;var q=e.PrevInAEL,z=e.NextInAEL;if(q!==null&&q.Curr.X===e.Bot.X&&q.Curr.Y===e.Bot.Y&&q.WindDelta===0&&q.OutIdx>=0&&q.Curr.Y>q.Top.Y&&n.ClipperBase.SlopesEqual3(e,q,this.m_UseFullRange)){var j=this.AddOutPt(q,e.Bot);this.AddJoin(v,j,e.Top)}else if(z!==null&&z.Curr.X===e.Bot.X&&z.Curr.Y===e.Bot.Y&&z.WindDelta!==0&&z.OutIdx>=0&&z.Curr.Y>z.Top.Y&&n.ClipperBase.SlopesEqual3(e,z,this.m_UseFullRange)){var j=this.AddOutPt(z,e.Bot);this.AddJoin(v,j,e.Top)}}else e=this.UpdateEdgeIntoAEL(e);else e.OutIdx>=0&&this.AddOutPt(e,e.Top),this.DeleteFromAEL(e)},n.Clipper.prototype.GetNextInAEL=function(e,t){return t===n.Direction.dLeftToRight?e.NextInAEL:e.PrevInAEL},n.Clipper.prototype.IsMinima=function(e){return e!==null&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},n.Clipper.prototype.IsMaxima=function(e,t){return e!==null&&e.Top.Y===t&&e.NextInLML===null},n.Clipper.prototype.IsIntermediate=function(e,t){return e.Top.Y===t&&e.NextInLML!==null},n.Clipper.prototype.GetMaximaPair=function(e){return n.IntPoint.op_Equality(e.Next.Top,e.Top)&&e.Next.NextInLML===null?e.Next:n.IntPoint.op_Equality(e.Prev.Top,e.Top)&&e.Prev.NextInLML===null?e.Prev:null},n.Clipper.prototype.GetMaximaPairEx=function(e){var t=this.GetMaximaPair(e);return t===null||t.OutIdx===n.ClipperBase.Skip||t.NextInAEL===t.PrevInAEL&&!n.ClipperBase.IsHorizontal(t)?null:t},n.Clipper.prototype.ProcessIntersections=function(e){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(e),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(e){if(this.m_ActiveEdges!==null){var t=this.m_ActiveEdges;for(this.m_SortedEdges=t;t!==null;)t.PrevInSEL=t.PrevInAEL,t.NextInSEL=t.NextInAEL,t.Curr.X=n.Clipper.TopX(t,e),t=t.NextInAEL;for(var r=!0;r&&this.m_SortedEdges!==null;){for(r=!1,t=this.m_SortedEdges;t.NextInSEL!==null;){var i=t.NextInSEL,o=new n.IntPoint0;if(t.Curr.X>i.Curr.X){this.IntersectPoint(t,i,o),o.Y<e&&(o=new n.IntPoint2(n.Clipper.TopX(t,e),e));var l=new n.IntersectNode;l.Edge1=t,l.Edge2=i,l.Pt.X=o.X,l.Pt.Y=o.Y,n.use_xyz&&(l.Pt.Z=o.Z),this.m_IntersectList.push(l),this.SwapPositionsInSEL(t,i),r=!0}else t=i}if(t.PrevInSEL!==null)t.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},n.Clipper.prototype.EdgesAdjacent=function(e){return e.Edge1.NextInSEL===e.Edge2||e.Edge1.PrevInSEL===e.Edge2},n.Clipper.IntersectNodeSort=function(e,t){return t.Pt.Y-e.Pt.Y},n.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var e=this.m_IntersectList.length,t=0;t<e;t++){if(!this.EdgesAdjacent(this.m_IntersectList[t])){for(var r=t+1;r<e&&!this.EdgesAdjacent(this.m_IntersectList[r]);)r++;if(r===e)return!1;var i=this.m_IntersectList[t];this.m_IntersectList[t]=this.m_IntersectList[r],this.m_IntersectList[r]=i}this.SwapPositionsInSEL(this.m_IntersectList[t].Edge1,this.m_IntersectList[t].Edge2)}return!0},n.Clipper.prototype.ProcessIntersectList=function(){for(var e=0,t=this.m_IntersectList.length;e<t;e++){var r=this.m_IntersectList[e];this.IntersectEdges(r.Edge1,r.Edge2,r.Pt),this.SwapPositionsInAEL(r.Edge1,r.Edge2)}this.m_IntersectList.length=0};var Zr=function(e){return e<0?Math.ceil(e-.5):Math.round(e)},Jr=function(e){return e<0?Math.ceil(e-.5):Math.floor(e+.5)},Hr=function(e){return e<0?-Math.round(Math.abs(e)):Math.round(e)},qr=function(e){return e<0?(e-=.5,e<-2147483648?Math.ceil(e):e|0):(e+=.5,e>2147483647?Math.floor(e):e|0)};u.msie?n.Clipper.Round=Zr:u.chromium?n.Clipper.Round=Hr:u.safari?n.Clipper.Round=qr:n.Clipper.Round=Jr,n.Clipper.TopX=function(e,t){return t===e.Top.Y?e.Top.X:e.Bot.X+n.Clipper.Round(e.Dx*(t-e.Bot.Y))},n.Clipper.prototype.IntersectPoint=function(e,t,r){r.X=0,r.Y=0;var i,o;if(e.Dx===t.Dx){r.Y=e.Curr.Y,r.X=n.Clipper.TopX(e,r.Y);return}if(e.Delta.X===0)r.X=e.Bot.X,n.ClipperBase.IsHorizontal(t)?r.Y=t.Bot.Y:(o=t.Bot.Y-t.Bot.X/t.Dx,r.Y=n.Clipper.Round(r.X/t.Dx+o));else if(t.Delta.X===0)r.X=t.Bot.X,n.ClipperBase.IsHorizontal(e)?r.Y=e.Bot.Y:(i=e.Bot.Y-e.Bot.X/e.Dx,r.Y=n.Clipper.Round(r.X/e.Dx+i));else{i=e.Bot.X-e.Bot.Y*e.Dx,o=t.Bot.X-t.Bot.Y*t.Dx;var l=(o-i)/(e.Dx-t.Dx);r.Y=n.Clipper.Round(l),Math.abs(e.Dx)<Math.abs(t.Dx)?r.X=n.Clipper.Round(e.Dx*l+i):r.X=n.Clipper.Round(t.Dx*l+o)}if(r.Y<e.Top.Y||r.Y<t.Top.Y){if(e.Top.Y>t.Top.Y)return r.Y=e.Top.Y,r.X=n.Clipper.TopX(t,e.Top.Y),r.X<e.Top.X;r.Y=t.Top.Y,Math.abs(e.Dx)<Math.abs(t.Dx)?r.X=n.Clipper.TopX(e,r.Y):r.X=n.Clipper.TopX(t,r.Y)}r.Y>e.Curr.Y&&(r.Y=e.Curr.Y,Math.abs(e.Dx)>Math.abs(t.Dx)?r.X=n.Clipper.TopX(t,r.Y):r.X=n.Clipper.TopX(e,r.Y))},n.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(e){for(var t=this.m_ActiveEdges;t!==null;){var r=this.IsMaxima(t,e);if(r){var i=this.GetMaximaPairEx(t);r=i===null||!n.ClipperBase.IsHorizontal(i)}if(r){this.StrictlySimple&&this.InsertMaxima(t.Top.X);var o=t.PrevInAEL;this.DoMaxima(t),o===null?t=this.m_ActiveEdges:t=o.NextInAEL}else{if(this.IsIntermediate(t,e)&&n.ClipperBase.IsHorizontal(t.NextInLML)?(t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),this.AddEdgeToSEL(t)):(t.Curr.X=n.Clipper.TopX(t,e),t.Curr.Y=e),n.use_xyz&&(t.Top.Y===e?t.Curr.Z=t.Top.Z:t.Bot.Y===e?t.Curr.Z=t.Bot.Z:t.Curr.Z=0),this.StrictlySimple){var o=t.PrevInAEL;if(t.OutIdx>=0&&t.WindDelta!==0&&o!==null&&o.OutIdx>=0&&o.Curr.X===t.Curr.X&&o.WindDelta!==0){var l=new n.IntPoint1(t.Curr);n.use_xyz&&this.SetZ(l,o,t);var f=this.AddOutPt(o,l),d=this.AddOutPt(t,l);this.AddJoin(f,d,l)}}t=t.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,t=this.m_ActiveEdges;t!==null;){if(this.IsIntermediate(t,e)){var f=null;t.OutIdx>=0&&(f=this.AddOutPt(t,t.Top)),t=this.UpdateEdgeIntoAEL(t);var o=t.PrevInAEL,y=t.NextInAEL;if(o!==null&&o.Curr.X===t.Bot.X&&o.Curr.Y===t.Bot.Y&&f!==null&&o.OutIdx>=0&&o.Curr.Y===o.Top.Y&&n.ClipperBase.SlopesEqual5(t.Curr,t.Top,o.Curr,o.Top,this.m_UseFullRange)&&t.WindDelta!==0&&o.WindDelta!==0){var d=this.AddOutPt(ePrev2,t.Bot);this.AddJoin(f,d,t.Top)}else if(y!==null&&y.Curr.X===t.Bot.X&&y.Curr.Y===t.Bot.Y&&f!==null&&y.OutIdx>=0&&y.Curr.Y===y.Top.Y&&n.ClipperBase.SlopesEqual5(t.Curr,t.Top,y.Curr,y.Top,this.m_UseFullRange)&&t.WindDelta!==0&&y.WindDelta!==0){var d=this.AddOutPt(y,t.Bot);this.AddJoin(f,d,t.Top)}}t=t.NextInAEL}},n.Clipper.prototype.DoMaxima=function(e){var t=this.GetMaximaPairEx(e);if(t===null){e.OutIdx>=0&&this.AddOutPt(e,e.Top),this.DeleteFromAEL(e);return}for(var r=e.NextInAEL;r!==null&&r!==t;)this.IntersectEdges(e,r,e.Top),this.SwapPositionsInAEL(e,r),r=e.NextInAEL;e.OutIdx===-1&&t.OutIdx===-1?(this.DeleteFromAEL(e),this.DeleteFromAEL(t)):e.OutIdx>=0&&t.OutIdx>=0?(e.OutIdx>=0&&this.AddLocalMaxPoly(e,t,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(t)):n.use_lines&&e.WindDelta===0?(e.OutIdx>=0&&(this.AddOutPt(e,e.Top),e.OutIdx=n.ClipperBase.Unassigned),this.DeleteFromAEL(e),t.OutIdx>=0&&(this.AddOutPt(t,e.Top),t.OutIdx=n.ClipperBase.Unassigned),this.DeleteFromAEL(t)):n.Error("DoMaxima error")},n.Clipper.ReversePaths=function(e){for(var t=0,r=e.length;t<r;t++)e[t].reverse()},n.Clipper.Orientation=function(e){return n.Clipper.Area(e)>=0},n.Clipper.prototype.PointCount=function(e){if(e===null)return 0;var t=0,r=e;do t++,r=r.Next;while(r!==e);return t},n.Clipper.prototype.BuildResult=function(e){n.Clear(e);for(var t=0,r=this.m_PolyOuts.length;t<r;t++){var i=this.m_PolyOuts[t];if(i.Pts!==null){var o=i.Pts.Prev,l=this.PointCount(o);if(!(l<2)){for(var f=new Array(l),d=0;d<l;d++)f[d]=o.Pt,o=o.Prev;e.push(f)}}}},n.Clipper.prototype.BuildResult2=function(e){e.Clear();for(var t=0,r=this.m_PolyOuts.length;t<r;t++){var i=this.m_PolyOuts[t],o=this.PointCount(i.Pts);if(!(i.IsOpen&&o<2||!i.IsOpen&&o<3)){this.FixHoleLinkage(i);var l=new n.PolyNode;e.m_AllPolys.push(l),i.PolyNode=l,l.m_polygon.length=o;for(var f=i.Pts.Prev,d=0;d<o;d++)l.m_polygon[d]=f.Pt,f=f.Prev}}for(var t=0,r=this.m_PolyOuts.length;t<r;t++){var i=this.m_PolyOuts[t];i.PolyNode!==null&&(i.IsOpen?(i.PolyNode.IsOpen=!0,e.AddChild(i.PolyNode)):i.FirstLeft!==null&&i.FirstLeft.PolyNode!==null?i.FirstLeft.PolyNode.AddChild(i.PolyNode):e.AddChild(i.PolyNode))}},n.Clipper.prototype.FixupOutPolyline=function(e){for(var t=e.Pts,r=t.Prev;t!==r;)if(t=t.Next,n.IntPoint.op_Equality(t.Pt,t.Prev.Pt)){t===r&&(r=t.Prev);var i=t.Prev;i.Next=t.Next,t.Next.Prev=i,t=i}t===t.Prev&&(e.Pts=null)},n.Clipper.prototype.FixupOutPolygon=function(e){var t=null;e.BottomPt=null;for(var r=e.Pts,i=this.PreserveCollinear||this.StrictlySimple;;){if(r.Prev===r||r.Prev===r.Next){e.Pts=null;return}if(n.IntPoint.op_Equality(r.Pt,r.Next.Pt)||n.IntPoint.op_Equality(r.Pt,r.Prev.Pt)||n.ClipperBase.SlopesEqual4(r.Prev.Pt,r.Pt,r.Next.Pt,this.m_UseFullRange)&&(!i||!this.Pt2IsBetweenPt1AndPt3(r.Prev.Pt,r.Pt,r.Next.Pt)))t=null,r.Prev.Next=r.Next,r.Next.Prev=r.Prev,r=r.Prev;else{if(r===t)break;t===null&&(t=r),r=r.Next}}e.Pts=r},n.Clipper.prototype.DupOutPt=function(e,t){var r=new n.OutPt;return r.Pt.X=e.Pt.X,r.Pt.Y=e.Pt.Y,n.use_xyz&&(r.Pt.Z=e.Pt.Z),r.Idx=e.Idx,t?(r.Next=e.Next,r.Prev=e,e.Next.Prev=r,e.Next=r):(r.Prev=e.Prev,r.Next=e,e.Prev.Next=r,e.Prev=r),r},n.Clipper.prototype.GetOverlap=function(e,t,r,i,o){return e<t?r<i?(o.Left=Math.max(e,r),o.Right=Math.min(t,i)):(o.Left=Math.max(e,i),o.Right=Math.min(t,r)):r<i?(o.Left=Math.max(t,r),o.Right=Math.min(e,i)):(o.Left=Math.max(t,i),o.Right=Math.min(e,r)),o.Left<o.Right},n.Clipper.prototype.JoinHorz=function(e,t,r,i,o,l){var f=e.Pt.X>t.Pt.X?n.Direction.dRightToLeft:n.Direction.dLeftToRight,d=r.Pt.X>i.Pt.X?n.Direction.dRightToLeft:n.Direction.dLeftToRight;if(f===d)return!1;if(f===n.Direction.dLeftToRight){for(;e.Next.Pt.X<=o.X&&e.Next.Pt.X>=e.Pt.X&&e.Next.Pt.Y===o.Y;)e=e.Next;l&&e.Pt.X!==o.X&&(e=e.Next),t=this.DupOutPt(e,!l),n.IntPoint.op_Inequality(t.Pt,o)&&(e=t,e.Pt.X=o.X,e.Pt.Y=o.Y,n.use_xyz&&(e.Pt.Z=o.Z),t=this.DupOutPt(e,!l))}else{for(;e.Next.Pt.X>=o.X&&e.Next.Pt.X<=e.Pt.X&&e.Next.Pt.Y===o.Y;)e=e.Next;!l&&e.Pt.X!==o.X&&(e=e.Next),t=this.DupOutPt(e,l),n.IntPoint.op_Inequality(t.Pt,o)&&(e=t,e.Pt.X=o.X,e.Pt.Y=o.Y,n.use_xyz&&(e.Pt.Z=o.Z),t=this.DupOutPt(e,l))}if(d===n.Direction.dLeftToRight){for(;r.Next.Pt.X<=o.X&&r.Next.Pt.X>=r.Pt.X&&r.Next.Pt.Y===o.Y;)r=r.Next;l&&r.Pt.X!==o.X&&(r=r.Next),i=this.DupOutPt(r,!l),n.IntPoint.op_Inequality(i.Pt,o)&&(r=i,r.Pt.X=o.X,r.Pt.Y=o.Y,n.use_xyz&&(r.Pt.Z=o.Z),i=this.DupOutPt(r,!l))}else{for(;r.Next.Pt.X>=o.X&&r.Next.Pt.X<=r.Pt.X&&r.Next.Pt.Y===o.Y;)r=r.Next;!l&&r.Pt.X!==o.X&&(r=r.Next),i=this.DupOutPt(r,l),n.IntPoint.op_Inequality(i.Pt,o)&&(r=i,r.Pt.X=o.X,r.Pt.Y=o.Y,n.use_xyz&&(r.Pt.Z=o.Z),i=this.DupOutPt(r,l))}return f===n.Direction.dLeftToRight===l?(e.Prev=r,r.Next=e,t.Next=i,i.Prev=t):(e.Next=r,r.Prev=e,t.Prev=i,i.Next=t),!0},n.Clipper.prototype.JoinPoints=function(e,t,r){var i=e.OutPt1,o=new n.OutPt,l=e.OutPt2,f=new n.OutPt,d=e.OutPt1.Pt.Y===e.OffPt.Y;if(d&&n.IntPoint.op_Equality(e.OffPt,e.OutPt1.Pt)&&n.IntPoint.op_Equality(e.OffPt,e.OutPt2.Pt)){if(t!==r)return!1;for(o=e.OutPt1.Next;o!==i&&n.IntPoint.op_Equality(o.Pt,e.OffPt);)o=o.Next;var y=o.Pt.Y>e.OffPt.Y;for(f=e.OutPt2.Next;f!==l&&n.IntPoint.op_Equality(f.Pt,e.OffPt);)f=f.Next;var v=f.Pt.Y>e.OffPt.Y;return y===v?!1:y?(o=this.DupOutPt(i,!1),f=this.DupOutPt(l,!0),i.Prev=l,l.Next=i,o.Next=f,f.Prev=o,e.OutPt1=i,e.OutPt2=o,!0):(o=this.DupOutPt(i,!0),f=this.DupOutPt(l,!1),i.Next=l,l.Prev=i,o.Prev=f,f.Next=o,e.OutPt1=i,e.OutPt2=o,!0)}else if(d){for(o=i;i.Prev.Pt.Y===i.Pt.Y&&i.Prev!==o&&i.Prev!==l;)i=i.Prev;for(;o.Next.Pt.Y===o.Pt.Y&&o.Next!==i&&o.Next!==l;)o=o.Next;if(o.Next===i||o.Next===l)return!1;for(f=l;l.Prev.Pt.Y===l.Pt.Y&&l.Prev!==f&&l.Prev!==o;)l=l.Prev;for(;f.Next.Pt.Y===f.Pt.Y&&f.Next!==l&&f.Next!==i;)f=f.Next;if(f.Next===l||f.Next===i)return!1;var A={Left:null,Right:null};if(!this.GetOverlap(i.Pt.X,o.Pt.X,l.Pt.X,f.Pt.X,A))return!1;var k=A.Left,X=A.Right,j=new n.IntPoint0,V;return i.Pt.X>=k&&i.Pt.X<=X?(j.X=i.Pt.X,j.Y=i.Pt.Y,n.use_xyz&&(j.Z=i.Pt.Z),V=i.Pt.X>o.Pt.X):l.Pt.X>=k&&l.Pt.X<=X?(j.X=l.Pt.X,j.Y=l.Pt.Y,n.use_xyz&&(j.Z=l.Pt.Z),V=l.Pt.X>f.Pt.X):o.Pt.X>=k&&o.Pt.X<=X?(j.X=o.Pt.X,j.Y=o.Pt.Y,n.use_xyz&&(j.Z=o.Pt.Z),V=o.Pt.X>i.Pt.X):(j.X=f.Pt.X,j.Y=f.Pt.Y,n.use_xyz&&(j.Z=f.Pt.Z),V=f.Pt.X>l.Pt.X),e.OutPt1=i,e.OutPt2=l,this.JoinHorz(i,o,l,f,j,V)}else{for(o=i.Next;n.IntPoint.op_Equality(o.Pt,i.Pt)&&o!==i;)o=o.Next;var z=o.Pt.Y>i.Pt.Y||!n.ClipperBase.SlopesEqual4(i.Pt,o.Pt,e.OffPt,this.m_UseFullRange);if(z){for(o=i.Prev;n.IntPoint.op_Equality(o.Pt,i.Pt)&&o!==i;)o=o.Prev;if(o.Pt.Y>i.Pt.Y||!n.ClipperBase.SlopesEqual4(i.Pt,o.Pt,e.OffPt,this.m_UseFullRange))return!1}for(f=l.Next;n.IntPoint.op_Equality(f.Pt,l.Pt)&&f!==l;)f=f.Next;var q=f.Pt.Y>l.Pt.Y||!n.ClipperBase.SlopesEqual4(l.Pt,f.Pt,e.OffPt,this.m_UseFullRange);if(q){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,e.OffPt,this.m_UseFullRange))return!1}return o===i||f===l||o===f||t===r&&z===q?!1:z?(o=this.DupOutPt(i,!1),f=this.DupOutPt(l,!0),i.Prev=l,l.Next=i,o.Next=f,f.Prev=o,e.OutPt1=i,e.OutPt2=o,!0):(o=this.DupOutPt(i,!0),f=this.DupOutPt(l,!1),i.Next=l,l.Prev=i,o.Prev=f,f.Next=o,e.OutPt1=i,e.OutPt2=o,!0)}},n.Clipper.GetBounds=function(e){for(var t=0,r=e.length;t<r&&e[t].length===0;)t++;if(t===r)return new n.IntRect(0,0,0,0);var i=new n.IntRect;for(i.left=e[t][0].X,i.right=i.left,i.top=e[t][0].Y,i.bottom=i.top;t<r;t++)for(var o=0,l=e[t].length;o<l;o++)e[t][o].X<i.left?i.left=e[t][o].X:e[t][o].X>i.right&&(i.right=e[t][o].X),e[t][o].Y<i.top?i.top=e[t][o].Y:e[t][o].Y>i.bottom&&(i.bottom=e[t][o].Y);return i},n.Clipper.prototype.GetBounds2=function(e){var t=e,r=new n.IntRect;for(r.left=e.Pt.X,r.right=e.Pt.X,r.top=e.Pt.Y,r.bottom=e.Pt.Y,e=e.Next;e!==t;)e.Pt.X<r.left&&(r.left=e.Pt.X),e.Pt.X>r.right&&(r.right=e.Pt.X),e.Pt.Y<r.top&&(r.top=e.Pt.Y),e.Pt.Y>r.bottom&&(r.bottom=e.Pt.Y),e=e.Next;return r},n.Clipper.PointInPolygon=function(e,t){var r=0,i=t.length;if(i<3)return 0;for(var o=t[0],l=1;l<=i;++l){var f=l===i?t[0]:t[l];if(f.Y===e.Y&&(f.X===e.X||o.Y===e.Y&&f.X>e.X==o.X<e.X))return-1;if(o.Y<e.Y!=f.Y<e.Y){if(o.X>=e.X)if(f.X>e.X)r=1-r;else{var d=(o.X-e.X)*(f.Y-e.Y)-(f.X-e.X)*(o.Y-e.Y);if(d===0)return-1;d>0==f.Y>o.Y&&(r=1-r)}else if(f.X>e.X){var d=(o.X-e.X)*(f.Y-e.Y)-(f.X-e.X)*(o.Y-e.Y);if(d===0)return-1;d>0==f.Y>o.Y&&(r=1-r)}}o=f}return r},n.Clipper.prototype.PointInPolygon=function(e,t){var r=0,i=t,o=e.X,l=e.Y,f=t.Pt.X,d=t.Pt.Y;do{t=t.Next;var y=t.Pt.X,v=t.Pt.Y;if(v===l&&(y===o||d===l&&y>o==f<o))return-1;if(d<l!=v<l){if(f>=o)if(y>o)r=1-r;else{var A=(f-o)*(v-l)-(y-o)*(d-l);if(A===0)return-1;A>0==v>d&&(r=1-r)}else if(y>o){var A=(f-o)*(v-l)-(y-o)*(d-l);if(A===0)return-1;A>0==v>d&&(r=1-r)}}f=y,d=v}while(i!==t);return r},n.Clipper.prototype.Poly2ContainsPoly1=function(e,t){var r=e;do{var i=this.PointInPolygon(r.Pt,t);if(i>=0)return i>0;r=r.Next}while(r!==e);return!0},n.Clipper.prototype.FixupFirstLefts1=function(e,t){for(var r,i,o=0,l=this.m_PolyOuts.length;o<l;o++)r=this.m_PolyOuts[o],i=n.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===e&&this.Poly2ContainsPoly1(r.Pts,t.Pts)&&(r.FirstLeft=t)},n.Clipper.prototype.FixupFirstLefts2=function(e,t){for(var r=t.FirstLeft,i,o,l=0,f=this.m_PolyOuts.length;l<f;l++)i=this.m_PolyOuts[l],!(i.Pts===null||i===t||i===e)&&(o=n.Clipper.ParseFirstLeft(i.FirstLeft),!(o!==r&&o!==e&&o!==t)&&(this.Poly2ContainsPoly1(i.Pts,e.Pts)?i.FirstLeft=e:this.Poly2ContainsPoly1(i.Pts,t.Pts)?i.FirstLeft=t:(i.FirstLeft===e||i.FirstLeft===t)&&(i.FirstLeft=r)))},n.Clipper.prototype.FixupFirstLefts3=function(e,t){for(var r,i,o=0,l=this.m_PolyOuts.length;o<l;o++)r=this.m_PolyOuts[o],i=n.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===e&&(r.FirstLeft=t)},n.Clipper.ParseFirstLeft=function(e){for(;e!==null&&e.Pts===null;)e=e.FirstLeft;return e},n.Clipper.prototype.JoinCommonEdges=function(){for(var e=0,t=this.m_Joins.length;e<t;e++){var r=this.m_Joins[e],i=this.GetOutRec(r.OutPt1.Idx),o=this.GetOutRec(r.OutPt2.Idx);if(!(i.Pts===null||o.Pts===null)&&!(i.IsOpen||o.IsOpen)){var l;i===o?l=i:this.OutRec1RightOfOutRec2(i,o)?l=o:this.OutRec1RightOfOutRec2(o,i)?l=i:l=this.GetLowermostRec(i,o),this.JoinPoints(r,i,o)&&(i===o?(i.Pts=r.OutPt1,i.BottomPt=null,o=this.CreateOutRec(),o.Pts=r.OutPt2,this.UpdateOutPtIdxs(o),this.Poly2ContainsPoly1(o.Pts,i.Pts)?(o.IsHole=!i.IsHole,o.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(o,i),(o.IsHole^this.ReverseSolution)==this.Area$1(o)>0&&this.ReversePolyPtLinks(o.Pts)):this.Poly2ContainsPoly1(i.Pts,o.Pts)?(o.IsHole=i.IsHole,i.IsHole=!o.IsHole,o.FirstLeft=i.FirstLeft,i.FirstLeft=o,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,o),(i.IsHole^this.ReverseSolution)==this.Area$1(i)>0&&this.ReversePolyPtLinks(i.Pts)):(o.IsHole=i.IsHole,o.FirstLeft=i.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(i,o))):(o.Pts=null,o.BottomPt=null,o.Idx=i.Idx,i.IsHole=l.IsHole,l===o&&(i.FirstLeft=o.FirstLeft),o.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts3(o,i)))}}},n.Clipper.prototype.UpdateOutPtIdxs=function(e){var t=e.Pts;do t.Idx=e.Idx,t=t.Prev;while(t!==e.Pts)},n.Clipper.prototype.DoSimplePolygons=function(){for(var e=0;e<this.m_PolyOuts.length;){var t=this.m_PolyOuts[e++],r=t.Pts;if(!(r===null||t.IsOpen))do{for(var i=r.Next;i!==t.Pts;){if(n.IntPoint.op_Equality(r.Pt,i.Pt)&&i.Next!==r&&i.Prev!==r){var o=r.Prev,l=i.Prev;r.Prev=l,l.Next=r,i.Prev=o,o.Next=i,t.Pts=r;var f=this.CreateOutRec();f.Pts=i,this.UpdateOutPtIdxs(f),this.Poly2ContainsPoly1(f.Pts,t.Pts)?(f.IsHole=!t.IsHole,f.FirstLeft=t,this.m_UsingPolyTree&&this.FixupFirstLefts2(f,t)):this.Poly2ContainsPoly1(t.Pts,f.Pts)?(f.IsHole=t.IsHole,t.IsHole=!f.IsHole,f.FirstLeft=t.FirstLeft,t.FirstLeft=f,this.m_UsingPolyTree&&this.FixupFirstLefts2(t,f)):(f.IsHole=t.IsHole,f.FirstLeft=t.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(t,f)),i=r}i=i.Next}r=r.Next}while(r!==t.Pts)}},n.Clipper.Area=function(e){if(!Array.isArray(e))return 0;var t=e.length;if(t<3)return 0;for(var r=0,i=0,o=t-1;i<t;++i)r+=(e[o].X+e[i].X)*(e[o].Y-e[i].Y),o=i;return-r*.5},n.Clipper.prototype.Area=function(e){var t=e;if(e===null)return 0;var r=0;do r=r+(e.Prev.Pt.X+e.Pt.X)*(e.Prev.Pt.Y-e.Pt.Y),e=e.Next;while(e!==t);return r*.5},n.Clipper.prototype.Area$1=function(e){return this.Area(e.Pts)},n.Clipper.SimplifyPolygon=function(e,t){var r=new Array,i=new n.Clipper(0);return i.StrictlySimple=!0,i.AddPath(e,n.PolyType.ptSubject,!0),i.Execute(n.ClipType.ctUnion,r,t,t),r},n.Clipper.SimplifyPolygons=function(e,t){typeof t>"u"&&(t=n.PolyFillType.pftEvenOdd);var r=new Array,i=new n.Clipper(0);return i.StrictlySimple=!0,i.AddPaths(e,n.PolyType.ptSubject,!0),i.Execute(n.ClipType.ctUnion,r,t,t),r},n.Clipper.DistanceSqrd=function(e,t){var r=e.X-t.X,i=e.Y-t.Y;return r*r+i*i},n.Clipper.DistanceFromLineSqrd=function(e,t,r){var i=t.Y-r.Y,o=r.X-t.X,l=i*t.X+o*t.Y;return l=i*e.X+o*e.Y-l,l*l/(i*i+o*o)},n.Clipper.SlopesNearCollinear=function(e,t,r,i){return Math.abs(e.X-t.X)>Math.abs(e.Y-t.Y)?e.X>t.X==e.X<r.X?n.Clipper.DistanceFromLineSqrd(e,t,r)<i:t.X>e.X==t.X<r.X?n.Clipper.DistanceFromLineSqrd(t,e,r)<i:n.Clipper.DistanceFromLineSqrd(r,e,t)<i:e.Y>t.Y==e.Y<r.Y?n.Clipper.DistanceFromLineSqrd(e,t,r)<i:t.Y>e.Y==t.Y<r.Y?n.Clipper.DistanceFromLineSqrd(t,e,r)<i:n.Clipper.DistanceFromLineSqrd(r,e,t)<i},n.Clipper.PointsAreClose=function(e,t,r){var i=e.X-t.X,o=e.Y-t.Y;return i*i+o*o<=r},n.Clipper.ExcludeOp=function(e){var t=e.Prev;return t.Next=e.Next,e.Next.Prev=t,t.Idx=0,t},n.Clipper.CleanPolygon=function(e,t){typeof t>"u"&&(t=1.415);var r=e.length;if(r===0)return new Array;for(var i=new Array(r),o=0;o<r;++o)i[o]=new n.OutPt;for(var o=0;o<r;++o)i[o].Pt=e[o],i[o].Next=i[(o+1)%r],i[o].Next.Prev=i[o],i[o].Idx=0;for(var l=t*t,f=i[0];f.Idx===0&&f.Next!==f.Prev;)n.Clipper.PointsAreClose(f.Pt,f.Prev.Pt,l)?(f=n.Clipper.ExcludeOp(f),r--):n.Clipper.PointsAreClose(f.Prev.Pt,f.Next.Pt,l)?(n.Clipper.ExcludeOp(f.Next),f=n.Clipper.ExcludeOp(f),r-=2):n.Clipper.SlopesNearCollinear(f.Prev.Pt,f.Pt,f.Next.Pt,l)?(f=n.Clipper.ExcludeOp(f),r--):(f.Idx=1,f=f.Next);r<3&&(r=0);for(var d=new Array(r),o=0;o<r;++o)d[o]=new n.IntPoint1(f.Pt),f=f.Next;return i=null,d},n.Clipper.CleanPolygons=function(e,t){for(var r=new Array(e.length),i=0,o=e.length;i<o;i++)r[i]=n.Clipper.CleanPolygon(e[i],t);return r},n.Clipper.Minkowski=function(e,t,r,i){var o=i?1:0,l=e.length,f=t.length,d=new Array;if(r)for(var y=0;y<f;y++){for(var v=new Array(l),A=0,k=e.length,X=e[A];A<k;A++,X=e[A])v[A]=new n.IntPoint2(t[y].X+X.X,t[y].Y+X.Y);d.push(v)}else for(var y=0;y<f;y++){for(var v=new Array(l),A=0,k=e.length,X=e[A];A<k;A++,X=e[A])v[A]=new n.IntPoint2(t[y].X-X.X,t[y].Y-X.Y);d.push(v)}for(var j=new Array,y=0;y<f-1+o;y++)for(var A=0;A<l;A++){var V=new Array;V.push(d[y%f][A%l]),V.push(d[(y+1)%f][A%l]),V.push(d[(y+1)%f][(A+1)%l]),V.push(d[y%f][(A+1)%l]),n.Clipper.Orientation(V)||V.reverse(),j.push(V)}return j},n.Clipper.MinkowskiSum=function(e,t,r){if(t[0]instanceof Array){for(var o=t,f=new n.Paths,l=new n.Clipper,d=0;d<o.length;++d){var y=n.Clipper.Minkowski(e,o[d],!0,r);if(l.AddPaths(y,n.PolyType.ptSubject,!0),r){var i=n.Clipper.TranslatePath(o[d],e[0]);l.AddPath(i,n.PolyType.ptClip,!0)}}return l.Execute(n.ClipType.ctUnion,f,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),f}else{var i=t,o=n.Clipper.Minkowski(e,i,!0,r),l=new n.Clipper;return l.AddPaths(o,n.PolyType.ptSubject,!0),l.Execute(n.ClipType.ctUnion,o,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),o}},n.Clipper.TranslatePath=function(e,t){for(var r=new n.Path,i=0;i<e.length;i++)r.push(new n.IntPoint2(e[i].X+t.X,e[i].Y+t.Y));return r},n.Clipper.MinkowskiDiff=function(e,t){var r=n.Clipper.Minkowski(e,t,!1,!0),i=new n.Clipper;return i.AddPaths(r,n.PolyType.ptSubject,!0),i.Execute(n.ClipType.ctUnion,r,n.PolyFillType.pftNonZero,n.PolyFillType.pftNonZero),r},n.Clipper.PolyTreeToPaths=function(e){var t=new Array;return n.Clipper.AddPolyNodeToPaths(e,n.Clipper.NodeType.ntAny,t),t},n.Clipper.AddPolyNodeToPaths=function(e,t,r){var i=!0;switch(t){case n.Clipper.NodeType.ntOpen:return;case n.Clipper.NodeType.ntClosed:i=!e.IsOpen;break;default:break}e.m_polygon.length>0&&i&&r.push(e.m_polygon);for(var o=0,l=e.Childs(),f=l.length,d=l[o];o<f;o++,d=l[o])n.Clipper.AddPolyNodeToPaths(d,t,r)},n.Clipper.OpenPathsFromPolyTree=function(e){for(var t=new n.Paths,r=0,i=e.ChildCount();r<i;r++)e.Childs()[r].IsOpen&&t.push(e.Childs()[r].m_polygon);return t},n.Clipper.ClosedPathsFromPolyTree=function(e){var t=new n.Paths;return n.Clipper.AddPolyNodeToPaths(e,n.Clipper.NodeType.ntClosed,t),t},Lt(n.Clipper,n.ClipperBase),n.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},n.ClipperOffset=function(e,t){typeof e>"u"&&(e=2),typeof t>"u"&&(t=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=e,this.ArcTolerance=t,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(e,t,r){var i=e.length-1;if(!(i<0)){var o=new n.PolyNode;if(o.m_jointype=t,o.m_endtype=r,r===n.EndType.etClosedLine||r===n.EndType.etClosedPolygon)for(;i>0&&n.IntPoint.op_Equality(e[0],e[i]);)i--;o.m_polygon.push(e[0]);for(var l=0,f=0,d=1;d<=i;d++)n.IntPoint.op_Inequality(o.m_polygon[l],e[d])&&(l++,o.m_polygon.push(e[d]),(e[d].Y>o.m_polygon[f].Y||e[d].Y===o.m_polygon[f].Y&&e[d].X<o.m_polygon[f].X)&&(f=l));if(!(r===n.EndType.etClosedPolygon&&l<2)&&(this.m_polyNodes.AddChild(o),r===n.EndType.etClosedPolygon))if(this.m_lowest.X<0)this.m_lowest=new n.IntPoint2(this.m_polyNodes.ChildCount()-1,f);else{var y=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(o.m_polygon[f].Y>y.Y||o.m_polygon[f].Y===y.Y&&o.m_polygon[f].X<y.X)&&(this.m_lowest=new n.IntPoint2(this.m_polyNodes.ChildCount()-1,f))}}},n.ClipperOffset.prototype.AddPaths=function(e,t,r){for(var i=0,o=e.length;i<o;i++)this.AddPath(e[i],t,r)},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 e=0;e<this.m_polyNodes.ChildCount();e++){var t=this.m_polyNodes.Childs()[e];(t.m_endtype===n.EndType.etClosedPolygon||t.m_endtype===n.EndType.etClosedLine&&n.Clipper.Orientation(t.m_polygon))&&t.m_polygon.reverse()}else for(var e=0;e<this.m_polyNodes.ChildCount();e++){var t=this.m_polyNodes.Childs()[e];t.m_endtype===n.EndType.etClosedLine&&!n.Clipper.Orientation(t.m_polygon)&&t.m_polygon.reverse()}},n.ClipperOffset.GetUnitNormal=function(e,t){var r=t.X-e.X,i=t.Y-e.Y;if(r===0&&i===0)return new n.DoublePoint2(0,0);var o=1/Math.sqrt(r*r+i*i);return r*=o,i*=o,new n.DoublePoint2(i,-r)},n.ClipperOffset.prototype.DoOffset=function(e){if(this.m_destPolys=new Array,this.m_delta=e,n.ClipperBase.near_zero(e)){for(var t=0;t<this.m_polyNodes.ChildCount();t++){var r=this.m_polyNodes.Childs()[t];r.m_endtype===n.EndType.etClosedPolygon&&this.m_destPolys.push(r.m_polygon)}return}this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5;var i;this.ArcTolerance<=0?i=n.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(e)*n.ClipperOffset.def_arc_tolerance?i=Math.abs(e)*n.ClipperOffset.def_arc_tolerance:i=this.ArcTolerance;var o=3.14159265358979/Math.acos(1-i/Math.abs(e));this.m_sin=Math.sin(n.ClipperOffset.two_pi/o),this.m_cos=Math.cos(n.ClipperOffset.two_pi/o),this.m_StepsPerRad=o/n.ClipperOffset.two_pi,e<0&&(this.m_sin=-this.m_sin);for(var t=0;t<this.m_polyNodes.ChildCount();t++){var r=this.m_polyNodes.Childs()[t];this.m_srcPoly=r.m_polygon;var l=this.m_srcPoly.length;if(!(l===0||e<=0&&(l<3||r.m_endtype!==n.EndType.etClosedPolygon))){if(this.m_destPoly=new Array,l===1){if(r.m_jointype===n.JoinType.jtRound)for(var f=1,d=0,y=1;y<=o;y++){this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+f*e),n.ClipperOffset.Round(this.m_srcPoly[0].Y+d*e)));var v=f;f=f*this.m_cos-this.m_sin*d,d=v*this.m_sin+d*this.m_cos}else for(var f=-1,d=-1,y=0;y<4;++y)this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+f*e),n.ClipperOffset.Round(this.m_srcPoly[0].Y+d*e))),f<0?f=1:d<0?d=1:f=-1;this.m_destPolys.push(this.m_destPoly);continue}this.m_normals.length=0;for(var y=0;y<l-1;y++)this.m_normals.push(n.ClipperOffset.GetUnitNormal(this.m_srcPoly[y],this.m_srcPoly[y+1]));if(r.m_endtype===n.EndType.etClosedLine||r.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])),r.m_endtype===n.EndType.etClosedPolygon){for(var A=l-1,y=0;y<l;y++)A=this.OffsetPoint(y,A,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(r.m_endtype===n.EndType.etClosedLine){for(var A=l-1,y=0;y<l;y++)A=this.OffsetPoint(y,A,r.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;for(var k=this.m_normals[l-1],y=l-1;y>0;y--)this.m_normals[y]=new n.DoublePoint2(-this.m_normals[y-1].X,-this.m_normals[y-1].Y);this.m_normals[0]=new n.DoublePoint2(-k.X,-k.Y),A=0;for(var y=l-1;y>=0;y--)A=this.OffsetPoint(y,A,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var A=0,y=1;y<l-1;++y)A=this.OffsetPoint(y,A,r.m_jointype);var X;if(r.m_endtype===n.EndType.etOpenButt){var y=l-1;X=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[y].X+this.m_normals[y].X*e),n.ClipperOffset.Round(this.m_srcPoly[y].Y+this.m_normals[y].Y*e)),this.m_destPoly.push(X),X=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[y].X-this.m_normals[y].X*e),n.ClipperOffset.Round(this.m_srcPoly[y].Y-this.m_normals[y].Y*e)),this.m_destPoly.push(X)}else{var y=l-1;A=l-2,this.m_sinA=0,this.m_normals[y]=new n.DoublePoint2(-this.m_normals[y].X,-this.m_normals[y].Y),r.m_endtype===n.EndType.etOpenSquare?this.DoSquare(y,A):this.DoRound(y,A)}for(var y=l-1;y>0;y--)this.m_normals[y]=new n.DoublePoint2(-this.m_normals[y-1].X,-this.m_normals[y-1].Y);this.m_normals[0]=new n.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),A=l-1;for(var y=A-1;y>0;--y)A=this.OffsetPoint(y,A,r.m_jointype);r.m_endtype===n.EndType.etOpenButt?(X=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*e),n.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*e)),this.m_destPoly.push(X),X=new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*e),n.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*e)),this.m_destPoly.push(X)):(A=1,this.m_sinA=0,r.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 e=arguments,t=e[0]instanceof n.PolyTree;if(t){var r=e[0],i=e[1];r.Clear(),this.FixOrientations(),this.DoOffset(i);var o=new n.Clipper(0);if(o.AddPaths(this.m_destPolys,n.PolyType.ptSubject,!0),i>0)o.Execute(n.ClipType.ctUnion,r,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)),o.AddPath(f,n.PolyType.ptSubject,!0),o.ReverseSolution=!0,o.Execute(n.ClipType.ctUnion,r,n.PolyFillType.pftNegative,n.PolyFillType.pftNegative),r.ChildCount()===1&&r.Childs()[0].ChildCount()>0){var d=r.Childs()[0];r.Childs()[0]=d.Childs()[0],r.Childs()[0].m_Parent=r;for(var y=1;y<d.ChildCount();y++)r.AddChild(d.Childs()[y])}else r.Clear()}}else{var r=e[0],i=e[1];n.Clear(r),this.FixOrientations(),this.DoOffset(i);var o=new n.Clipper(0);if(o.AddPaths(this.m_destPolys,n.PolyType.ptSubject,!0),i>0)o.Execute(n.ClipType.ctUnion,r,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)),o.AddPath(f,n.PolyType.ptSubject,!0),o.ReverseSolution=!0,o.Execute(n.ClipType.ctUnion,r,n.PolyFillType.pftNegative,n.PolyFillType.pftNegative),r.length>0&&r.splice(0,1)}}},n.ClipperOffset.prototype.OffsetPoint=function(e,t,r){if(this.m_sinA=this.m_normals[t].X*this.m_normals[e].Y-this.m_normals[e].X*this.m_normals[t].Y,Math.abs(this.m_sinA*this.m_delta)<1){var i=this.m_normals[t].X*this.m_normals[e].X+this.m_normals[e].Y*this.m_normals[t].Y;if(i>0)return this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+this.m_normals[t].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_normals[t].Y*this.m_delta))),t}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[e].X+this.m_normals[t].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_normals[t].Y*this.m_delta))),this.m_destPoly.push(new n.IntPoint1(this.m_srcPoly[e])),this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+this.m_normals[e].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta)));else switch(r){case n.JoinType.jtMiter:{var o=1+(this.m_normals[e].X*this.m_normals[t].X+this.m_normals[e].Y*this.m_normals[t].Y);o>=this.m_miterLim?this.DoMiter(e,t,o):this.DoSquare(e,t);break}case n.JoinType.jtSquare:this.DoSquare(e,t);break;case n.JoinType.jtRound:this.DoRound(e,t);break}return t=e,t},n.ClipperOffset.prototype.DoSquare=function(e,t){var r=Math.tan(Math.atan2(this.m_sinA,this.m_normals[t].X*this.m_normals[e].X+this.m_normals[t].Y*this.m_normals[e].Y)/4);this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[t].X-this.m_normals[t].Y*r)),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[t].Y+this.m_normals[t].X*r)))),this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+this.m_delta*(this.m_normals[e].X+this.m_normals[e].Y*r)),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_delta*(this.m_normals[e].Y-this.m_normals[e].X*r))))},n.ClipperOffset.prototype.DoMiter=function(e,t,r){var i=this.m_delta/r;this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+(this.m_normals[t].X+this.m_normals[e].X)*i),n.ClipperOffset.Round(this.m_srcPoly[e].Y+(this.m_normals[t].Y+this.m_normals[e].Y)*i)))},n.ClipperOffset.prototype.DoRound=function(e,t){for(var r=Math.atan2(this.m_sinA,this.m_normals[t].X*this.m_normals[e].X+this.m_normals[t].Y*this.m_normals[e].Y),i=Math.max(n.Cast_Int32(n.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(r))),1),o=this.m_normals[t].X,l=this.m_normals[t].Y,f,d=0;d<i;++d)this.m_destPoly.push(new n.IntPoint2(n.ClipperOffset.Round(this.m_srcPoly[e].X+o*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[e].Y+l*this.m_delta))),f=o,o=o*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[e].X+this.m_normals[e].X*this.m_delta),n.ClipperOffset.Round(this.m_srcPoly[e].Y+this.m_normals[e].Y*this.m_delta)))},n.Error=function(e){try{throw new Error(e)}catch(t){alert(t.message)}},n.JS={},n.JS.AreaOfPolygon=function(e,t){return t||(t=1),n.Clipper.Area(e)/(t*t)},n.JS.AreaOfPolygons=function(e,t){t||(t=1);for(var r=0,i=0;i<e.length;i++)r+=n.Clipper.Area(e[i]);return r/(t*t)},n.JS.BoundsOfPath=function(e,t){return n.JS.BoundsOfPaths([e],t)},n.JS.BoundsOfPaths=function(e,t){t||(t=1);var r=n.Clipper.GetBounds(e);return r.left/=t,r.bottom/=t,r.right/=t,r.top/=t,r},n.JS.Clean=function(i,t){if(!(i instanceof Array))return[];var r=i[0]instanceof Array,i=n.JS.Clone(i);if(typeof t!="number"||t===null)return n.Error("Delta is not a number in Clean()."),i;if(i.length===0||i.length===1&&i[0].length===0||t<0)return i;r||(i=[i]);for(var o=i.length,l,f,d,y,v,A,k,X=[],j=0;j<o;j++)if(f=i[j],l=f.length,l!==0){if(l<3){d=f,X.push(d);continue}for(d=f,y=t*t,v=f[0],A=1,k=1;k<l;k++)(f[k].X-v.X)*(f[k].X-v.X)+(f[k].Y-v.Y)*(f[k].Y-v.Y)<=y||(d[A]=f[k],v=f[k],A++);v=f[A-1],(f[0].X-v.X)*(f[0].X-v.X)+(f[0].Y-v.Y)*(f[0].Y-v.Y)<=y&&A--,A<l&&d.splice(A,l-A),d.length&&X.push(d)}return!r&&X.length?X=X[0]:!r&&X.length===0?X=[]:r&&X.length===0&&(X=[[]]),X},n.JS.Clone=function(e){if(!(e instanceof Array))return[];if(e.length===0)return[];if(e.length===1&&e[0].length===0)return[[]];var t=e[0]instanceof Array;t||(e=[e]);var r=e.length,i,o,l,f,d=new Array(r);for(o=0;o<r;o++){for(i=e[o].length,f=new Array(i),l=0;l<i;l++)f[l]={X:e[o][l].X,Y:e[o][l].Y};d[o]=f}return t||(d=d[0]),d},n.JS.Lighten=function(e,t){if(!(e instanceof Array))return[];if(typeof t!="number"||t===null)return n.Error("Tolerance is not a number in Lighten()."),n.JS.Clone(e);if(e.length===0||e.length===1&&e[0].length===0||t<0)return n.JS.Clone(e);var r=e[0]instanceof Array;r||(e=[e]);var i,o,l,f,d,y,v,A,k,X,j,V,z,q,se,he,ke,Kr=e.length,$r=t*t,Te=[];for(i=0;i<Kr;i++)if(l=e[i],y=l.length,y!==0){for(f=0;f<1e6;f++){for(d=[],y=l.length,l[y-1].X!==l[0].X||l[y-1].Y!==l[0].Y?(V=1,l.push({X:l[0].X,Y:l[0].Y}),y=l.length):V=0,j=[],o=0;o<y-2;o++)v=l[o],k=l[o+1],A=l[o+2],he=v.X,ke=v.Y,z=A.X-he,q=A.Y-ke,(z!==0||q!==0)&&(se=((k.X-he)*z+(k.Y-ke)*q)/(z*z+q*q),se>1?(he=A.X,ke=A.Y):se>0&&(he+=z*se,ke+=q*se)),z=k.X-he,q=k.Y-ke,X=z*z+q*q,X<=$r&&(j[o+1]=1,o++);for(d.push({X:l[0].X,Y:l[0].Y}),o=1;o<y-1;o++)j[o]||d.push({X:l[o].X,Y:l[o].Y});if(d.push({X:l[y-1].X,Y:l[y-1].Y}),V&&l.pop(),j.length)l=d;else break}y=d.length,d[y-1].X===d[0].X&&d[y-1].Y===d[0].Y&&d.pop(),d.length>2&&Te.push(d)}return r||(Te=Te[0]),typeof Te>"u"&&(Te=[]),Te},n.JS.PerimeterOfPath=function(e,t,r){if(typeof e>"u")return 0;var i=Math.sqrt,o=0,l,f,d=0,y=0,v=0,A=0,k=e.length;if(k<2)return 0;for(t&&(e[k]=e[0],k++);--k;)l=e[k],d=l.X,y=l.Y,f=e[k-1],v=f.X,A=f.Y,o+=i((d-v)*(d-v)+(y-A)*(y-A));return t&&e.pop(),o/r},n.JS.PerimeterOfPaths=function(e,t,r){r||(r=1);for(var i=0,o=0;o<e.length;o++)i+=n.JS.PerimeterOfPath(e[o],t,r);return i},n.JS.ScaleDownPath=function(e,t){var r,i;for(t||(t=1),r=e.length;r--;)i=e[r],i.X=i.X/t,i.Y=i.Y/t},n.JS.ScaleDownPaths=function(e,t){var r,i,o;for(t||(t=1),r=e.length;r--;)for(i=e[r].length;i--;)o=e[r][i],o.X=o.X/t,o.Y=o.Y/t},n.JS.ScaleUpPath=function(e,t){var r,i,o=Math.round;for(t||(t=1),r=e.length;r--;)i=e[r],i.X=o(i.X*t),i.Y=o(i.Y*t)},n.JS.ScaleUpPaths=function(e,t){var r,i,o,l=Math.round;for(t||(t=1),r=e.length;r--;)for(i=e[r].length;i--;)o=e[r][i],o.X=l(o.X*t),o.Y=l(o.Y*t)},n.ExPolygons=function(){return[]},n.ExPolygon=function(){this.outer=null,this.holes=null},n.JS.AddOuterPolyNodeToExPolygons=function(e,t){var r=new n.ExPolygon;r.outer=e.Contour();var i=e.Childs(),o=i.length;r.holes=new Array(o);var l,f,d,y,v,A;for(d=0;d<o;d++)for(l=i[d],r.holes[d]=l.Contour(),y=0,v=l.Childs(),A=v.length;y<A;y++)f=v[y],n.JS.AddOuterPolyNodeToExPolygons(f,t);t.push(r)},n.JS.ExPolygonsToPaths=function(e){var t,r,i,o,l=new n.Paths;for(t=0,i=e.length;t<i;t++)for(l.push(e[t].outer),r=0,o=e[t].holes.length;r<o;r++)l.push(e[t].holes[r]);return l},n.JS.PolyTreeToExPolygons=function(e){var t=new n.ExPolygons,r,i,o,l;for(i=0,o=e.Childs(),l=o.length;i<l;i++)r=o[i],n.JS.AddOuterPolyNodeToExPolygons(r,t);return t}})()});function w(n,s){return Ot+n+(s?Nt+JSON.stringify(s):"")+Et}function ft(n){let s=[],a=0;for(;a<n.length;){let c=n.indexOf(Ot,a);if(c<0){s.push(n.slice(a));break}c>a&&s.push(n.slice(a,c));let u=n.indexOf(Et,c),h=n.slice(c+1,u<0?n.length:u),m=h.indexOf(Nt);if(m<0)s.push({de:h});else{let b=JSON.parse(h.slice(m+1)),p={};for(let[g,S]of Object.entries(b))p[g]=typeof S=="number"?S:ft(String(S));s.push({de:h.slice(0,m),values:p})}a=u<0?n.length:u+1}return s}var Ot,Nt,Et,ve,Ye,ye=Ze(()=>{"use strict";Ot="",Nt="",Et="";ve=(n,s,a,c)=>w(a===1?n:s,{n:a,...c}),Ye="en-US"});function Fe(n){let s=new Uint8Array(128);for(let h=0;h<64;h++)s[Ci.charCodeAt(h)]=h;let a=n.replace(/=+$/,"").length,c=new Uint8ClampedArray(Math.floor(a*3/4)),u=0;for(let h=0;h<a;h+=4){let m=s[n.charCodeAt(h)]<<18|s[n.charCodeAt(h+1)]<<12|(h+2<a?s[n.charCodeAt(h+2)]:0)<<6|(h+3<a?s[n.charCodeAt(h+3)]:0);c[u++]=m>>16,u<c.length&&(c[u++]=m>>8&255),u<c.length&&(c[u++]=m&255)}return c}var Ci,qe=Ze(()=>{"use strict";Ci="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"});function zt(n){if(!n.startsWith("kzm1:"))return"format";let s=Fe(n.slice(5));if(s.length<8)return"damaged";let a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=a.getUint32(0,!0),u=a.getUint32(4,!0);if(8+c*12+u*12!==s.length)return"damaged";let h=new Float32Array(c*3),m=new Uint32Array(u*3),b=8;for(let p=0;p<h.length;p++,b+=4)h[p]=a.getFloat32(b,!0);for(let p=0;p<m.length;p++,b+=4)m[p]=a.getUint32(b,!0);return m.some(p=>p>=c)?"damaged":{pos:h,tri:m}}var Ut=Ze(()=>{"use strict";qe()});function Zt(n){let s=zt(n);if(s==="format")throw new Ke(w("Unbekanntes Modellformat."));if(s==="damaged")throw new Ke(w("Die Modelldaten sind besch\xE4digt."));return s}var Ke,Jt=Ze(()=>{"use strict";ye();qe();Ut();Ke=class extends Error{}});var de=Je(De(),1);ye();var Rt=Je(De(),1);var Se=[1,0,0,1,0,0];function Be(n,s,a){return{x:n[0]*s+n[2]*a+n[4],y:n[1]*s+n[3]*a+n[5]}}function ht(n,s,a,c,u){let h=1-u;return{x:h*h*h*n.x+3*h*h*u*s.x+3*h*u*u*a.x+u*u*u*c.x,y:h*h*h*n.y+3*h*h*u*s.y+3*h*u*u*a.y+u*u*u*c.y}}function Xt(n){let s=[],a=n.nodes.length,c=n.closed?a:a-1;for(let u=0;u<c;u++){let h=n.nodes[u],m=n.nodes[(u+1)%a];s.push({a:h,b:m,c1:h.cout??h,c2:m.cin??m,curve:!!(h.cout||m.cin),ia:u,ib:(u+1)%a})}return s}var si=35,ai=1.5,li=.5,K=(n,s)=>({x:n.x-s.x,y:n.y-s.y}),ae=(n,s)=>({x:n.x+s.x,y:n.y+s.y}),Q=(n,s)=>({x:n.x*s,y:n.y*s}),fe=(n,s)=>n.x*s.x+n.y*s.y,Bt=n=>Math.hypot(n.x,n.y),we=(n,s)=>Math.hypot(n.x-s.x,n.y-s.y),ce=n=>{let s=Bt(n)||1;return{x:n.x/s,y:n.y/s}};function Me(n,s,a,c={}){let u=c.lineMin??ai,h=c.cornerDeg??si,m=[];for(let P of n)(!m.length||we(P,m[m.length-1])>1e-6)&&m.push({x:P.x,y:P.y});s&&m.length>1&&we(m[0],m[m.length-1])<1e-6&&m.pop();let b=m.length;if(b<3)return{closed:s,nodes:m.map(P=>({...P}))};let p=P=>m[(P%b+b)%b],g=s?b:b-1,S=P=>we(p(P),p(P+1)),I=[];for(let P=0;P<g;P++)I.push(S(P)>=u);let T=[],x=[];for(let P=0;P<b;P++){if(!s&&(P===0||P===b-1)){T.push(!0),x.push(!0);continue}let _=ce(K(p(P),p(P-1))),E=ce(K(p(P+1),p(P))),N=Math.acos(Math.max(-1,Math.min(1,fe(_,E))))*180/Math.PI>h;T.push(N);let Y=I[P]||I[(P-1+g)%g];x.push(N||Y)}let C=P=>{if(T[P]||I[P%g])return ce(K(p(P+1),p(P)));if(!s&&P===0)return ce(K(p(1),p(0)));let _=(P-1+g)%g;return I[_]?ce(K(p(P),p(P-1))):ce(K(p(P+1),p(P-1)))},M=P=>{let _=(P-1+g)%g;return T[P]||I[_]?ce(K(p(P-1),p(P))):I[P%g]?ce(K(p(P),p(P+1))):ce(K(p(P-1),p(P+1)))},L=[...Array(b).keys()].filter(P=>x[P]);L.length||(L=[0]);let O=[],R=s?L.length:L.length-1;for(let P=0;P<R;P++){let _=L[P],E=L[(P+1)%L.length];E<=_&&(E+=b);let B=[];for(let F=_;F<=E;F++)B.push(p(F));if(B.length===2&&I[_%g]){O.push({c:[B[0],B[0],B[1],B[1]],line:!0});continue}let N=ui(B),Y=[];pt(N,0,N.length-1,C(_%b),M(E%b),a*a,Y),Y.forEach(F=>O.push({c:F,line:ci(F,a)}))}let D=[];O.forEach(({c:P,line:_},E)=>{let B=E===0,N;B?(N={x:P[0].x,y:P[0].y},D.push(N)):N=D[D.length-1],_||(N.cout={...P[1]});let Y=E===O.length-1;if(s&&Y)_||(D[0].cin={...P[2]});else{let F={x:P[3].x,y:P[3].y};_||(F.cin={...P[2]}),D.push(F)}});for(let P of D){let _=P.cin?ce(K(P,P.cin)):null,E=P.cout?ce(K(P.cout,P)):null;_&&E&&fe(_,E)>.999&&(P.smooth=!0)}return{closed:s,nodes:D}}function ui(n){let s=[n[0]];for(let a=1;a<n.length;a++){let c=we(n[a-1],n[a]),u=Math.ceil(c/li);for(let h=1;h<u;h++)s.push(ae(n[a-1],Q(K(n[a],n[a-1]),h/u)));s.push(n[a])}return s}function ci(n,s){let a=K(n[3],n[0]),c=Bt(a);if(c<1e-9)return!1;let u=Q(a,1/c),h=b=>Math.abs((b.x-n[0].x)*u.y-(b.y-n[0].y)*u.x),m=b=>fe(K(b,n[0]),u);return h(n[1])<s&&h(n[2])<s&&m(n[1])>=-s&&m(n[2])<=c+s}function Ft(n,s){let a=1-s;return ae(ae(Q(n[0],a*a*a),Q(n[1],3*a*a*s)),ae(Q(n[2],3*a*s*s),Q(n[3],s*s*s)))}function fi(n,s){let a=1-s;return ae(ae(Q(K(n[1],n[0]),3*a*a),Q(K(n[2],n[1]),6*a*s)),Q(K(n[3],n[2]),3*s*s))}function hi(n,s){return ae(Q(ae(K(n[2],Q(n[1],2)),n[0]),6*(1-s)),Q(ae(K(n[3],Q(n[2],2)),n[1]),6*s))}function pt(n,s,a,c,u,h,m,b=0){if(a-s+1===2){let C=we(n[s],n[a])/3;m.push([n[s],ae(n[s],Q(c,C)),ae(n[a],Q(u,C)),n[a]]);return}let g=pi(n,s,a),S=Dt(n,s,a,g,c,u),[I,T]=Yt(n,s,a,S,g);if(I<h){m.push(S);return}if(I<h*16){for(let C=0;C<6;C++)if(g=mi(n,s,g,S),S=Dt(n,s,a,g,c,u),[I,T]=Yt(n,s,a,S,g),I<h){m.push(S);return}}if(b>40){m.push(S);return}T=Math.max(s+1,Math.min(a-1,T));let x=ce(K(n[T-1],n[T+1]));pt(n,s,T,c,x,h,m,b+1),pt(n,T,a,Q(x,-1),u,h,m,b+1)}function pi(n,s,a){let c=[0];for(let h=s+1;h<=a;h++)c.push(c[c.length-1]+we(n[h],n[h-1]));let u=c[c.length-1]||1;return c.map(h=>h/u)}function Dt(n,s,a,c,u,h){let m=n[s],b=n[a],p=[[0,0],[0,0]],g=[0,0];for(let M=0;M<c.length;M++){let L=c[M],O=1-L,R=3*L*O*O,D=3*L*L*O,P=Q(u,R),_=Q(h,D);p[0][0]+=fe(P,P),p[0][1]+=fe(P,_),p[1][1]+=fe(_,_);let E=K(n[s+M],ae(Q(m,O*O*O+R),Q(b,D+L*L*L)));g[0]+=fe(P,E),g[1]+=fe(_,E)}p[1][0]=p[0][1];let S=p[0][0]*p[1][1]-p[1][0]*p[0][1],I=S===0?0:(g[0]*p[1][1]-g[1]*p[0][1])/S,T=S===0?0:(p[0][0]*g[1]-p[1][0]*g[0])/S,x=we(m,b),C=1e-6*x;return(I<C||T<C||!isFinite(I)||!isFinite(T))&&(I=T=x/3),[m,ae(m,Q(u,I)),ae(b,Q(h,T)),b]}function mi(n,s,a,c){return a.map((u,h)=>{let m=n[s+h],b=Ft(c,u),p=fi(c,u),g=hi(c,u),S=fe(K(b,m),p),I=fe(p,p)+fe(K(b,m),g);return Math.abs(I)<1e-12?u:Math.max(0,Math.min(1,u-S/I))})}function Yt(n,s,a,c,u){let h=0,m=Math.floor((s+a)/2);for(let b=s+1;b<a;b++){let p=K(Ft(c,u[b-s]),n[b]),g=fe(p,p);g>=h&&(h=g,m=b)}return[h,m]}var ne=1e3,di=.01,yi=1;var{Clipper:yo,ClipType:bo,PolyType:go,PolyFillType:Po}=Rt.default;function mt(n,s,a){let c=[],u=(h,m)=>{let b=Be(s,h.x,h.y),p=Math.round(b.x*ne),g=Math.round(b.y*ne),S=c[c.length-1];(!S||S.X!==p||S.Y!==g)&&(c.push({X:p,Y:g}),a?.push(m))};n.nodes.length&&u(n.nodes[0],0);for(let[h,m]of Xt(n).entries()){if(!m.curve){u(m.b,h+1);continue}let b=[m.a,m.c1,m.c2,m.b].map(S=>Be(s,S.x,S.y)),p=Math.hypot(b[1].x-b[0].x,b[1].y-b[0].y)+Math.hypot(b[2].x-b[1].x,b[2].y-b[1].y)+Math.hypot(b[3].x-b[2].x,b[3].y-b[2].y),g=Math.max(4,Math.min(2048,Math.max(Math.ceil(Math.sqrt(p/di)*.6),Math.ceil(p/yi))));for(let S=1;S<=g;S++)u(ht(m.a,m.c1,m.c2,m.b,S/g),h+S/g)}if(n.closed&&c.length>1){let h=c[0],m=c[c.length-1];h.X===m.X&&h.Y===m.Y&&(c.pop(),a?.pop())}return c}ye();ye();var wo=Math.PI/180;ye();var bi={style:"burn",color:"#3a2210",alpha:.88},ee=n=>({contrast:.5,rough:.75,metal:0,clear:0,ior:1.5,edge:"#4a2e18",engrave:bi,tile:120,...n}),ko=[ee({id:"poplar",name:"Sperrholz Pappel",group:"wood",tex:"ply",color:"#e2cfa4",contrast:.35,edge:"#5a3b20"}),ee({id:"birch",name:"Sperrholz Birke",group:"wood",tex:"ply",color:"#ecd9b4",contrast:.3,edge:"#5e3f22",engrave:{style:"burn",color:"#3f2512",alpha:.85}}),ee({id:"beech",name:"Buche",group:"wood",tex:"wood",color:"#d9a878",contrast:.4,edge:"#4f2f18"}),ee({id:"oak",name:"Eiche",group:"wood",tex:"wood",color:"#c99a62",contrast:.65,edge:"#45291a"}),ee({id:"walnut",name:"Nussbaum",group:"wood",tex:"wood",color:"#7a5034",contrast:.55,edge:"#2c1a0f",engrave:{style:"burn",color:"#1e120a",alpha:.85}}),ee({id:"cherry",name:"Kirsche",group:"wood",tex:"wood",color:"#b8744a",contrast:.45,edge:"#3e2414",engrave:{style:"burn",color:"#2a170c",alpha:.85}}),ee({id:"bamboo",name:"Bambus",group:"wood",tex:"wood",color:"#d8b77a",contrast:.3,edge:"#5a3a1c",tile:60}),ee({id:"mdf",name:"MDF",group:"board",tex:"mdf",color:"#b98e5f",contrast:.2,edge:"#3a2414",engrave:{style:"burn",color:"#2e1a0c",alpha:.9}}),ee({id:"cardboard",name:"Karton",group:"board",tex:"paper",color:"#c49a6a",contrast:.3,edge:"#5a3a20",tile:80}),ee({id:"paper",name:"Papier",group:"board",tex:"paper",color:"#f3f0e8",contrast:.12,edge:"#8a7458",rough:.9,tile:80}),ee({id:"cork",name:"Kork",group:"board",tex:"cork",color:"#b98a5a",contrast:.7,edge:"#4a2f18",rough:.95,tile:60}),ee({id:"leather",name:"Leder",group:"other",tex:"leather",color:"#8a5a36",contrast:.45,edge:"#3a2416",rough:.6,engrave:{style:"burn",color:"#2a170c",alpha:.8},tile:60}),ee({id:"slate",name:"Schiefer",group:"stone",tex:"slate",color:"#3b3f44",contrast:.5,edge:null,rough:.85,engrave:{style:"light",color:"#c9ccc9",alpha:.9}}),ee({id:"granite",name:"Granit",group:"stone",tex:"granite",color:"#2b2b2d",contrast:.6,edge:null,rough:.35,engrave:{style:"light",color:"#d6d6d2",alpha:.85},tile:80}),ee({id:"acrylic",name:"Acryl klar",group:"plastic",tex:"plain",color:"#e8f2f2",contrast:0,edge:"#9dbcbc",rough:.04,clear:.95,ior:1.49,engrave:{style:"frost",color:"#eef2f3",alpha:.9}}),ee({id:"acrylic-color",name:"Acryl farbig",group:"plastic",tex:"plain",color:"#d8333a",contrast:0,rough:.05,clear:.6,ior:1.49,edge:"#a0242a",engrave:{style:"frost",color:"#f4dede",alpha:.8}}),ee({id:"acrylic-opaque",name:"Acryl deckend",group:"plastic",tex:"plain",color:"#1d1f22",contrast:0,edge:null,rough:.08,engrave:{style:"frost",color:"#e8e8e8",alpha:.8}}),ee({id:"glass",name:"Glas",group:"plastic",tex:"plain",color:"#e2f0e8",contrast:0,edge:"#8fb8a4",rough:.02,clear:.95,ior:1.52,engrave:{style:"frost",color:"#eef2f0",alpha:.9}}),ee({id:"anodized",name:"Aluminium eloxiert",group:"metal",tex:"brushed",color:"#222428",contrast:.25,edge:"#b8bcc2",rough:.35,metal:.9,engrave:{style:"light",color:"#e4e6e8",alpha:.92}}),ee({id:"steel",name:"Edelstahl",group:"metal",tex:"brushed",color:"#b9bdc2",contrast:.3,edge:null,rough:.3,metal:1,engrave:{style:"burn",color:"#202226",alpha:.85}}),ee({id:"plain",name:"Einfarbig",group:"other",tex:"plain",color:"#cfc6b8",contrast:0,edge:null,rough:.7,engrave:{style:"burn",color:"#2a2622",alpha:.85}})];var jt=Je(De(),1);var{Clipper:Mo,ClipperOffset:Ao,JoinType:Lo,EndType:_o,PolyFillType:Oo,ClipType:No,PolyType:Eo}=jt.default;ye();var jo=[["%#",w("Seriennummer")],["%4#",w("Seriennummer mit 4 Stellen (0042)")],["%0",w("CSV-Spalte 0 (%1, %2 \u2026 weitere Spalten)")],["%{Name}",w("CSV-Spalte nach \xDCberschrift")],["%d",w("Tag (01\u201331)")],["%m",w("Monat (01\u201312)")],["%b",w("Monatsname kurz")],["%B",w("Monatsname")],["%y",w("Jahr zweistellig")],["%Y",w("Jahr")],["%j",w("Tag im Jahr (001\u2013366)")],["%a",w("Wochentag kurz")],["%A",w("Wochentag")],["%H",w("Stunde (00\u201323)")],["%h",w("Stunde (01\u201312)")],["%p",w("AM/PM")],["%M",w("Minute")],["%S",w("Sekunde")],["%%",w("Prozentzeichen")]];var _s=[["threshold",w("Schwellwert")],["ordered",w("Geordnet")],["atkinson",w("Atkinson")],["floyd",w("Dither (Floyd-Steinberg)")],["stucki",w("Stucki")],["jarvis",w("Jarvis")],["newsprint",w("Zeitungsdruck (Newsprint)")],["halftone",w("Halbton")],["sketch",w("Skizze (Sketch)")],["grayscale",w("Graustufen")]];var vi=["mode","speed","power","minPower","passes","air","kerf","tabs","fillStyle","interval","angle","crossHatch","bidirectional","overscan","perf","lead","ramp","dwell","dedup","dedupTol","zOffset","zStep","sub","look","galvo","layerType","kerfAxes","fillGrouping"],Os=vi.filter(n=>n!=="air"&&n!=="look"&&n!=="sub"&&n!=="layerType");var Si=.5522847498;function Gt(n){let s=n/2,a=s*Si,c=[{x:s,y:0,cin:{x:s,y:-a},cout:{x:s,y:a},smooth:!0},{x:0,y:s,cin:{x:a,y:s},cout:{x:-a,y:s},smooth:!0},{x:-s,y:0,cin:{x:-s,y:a},cout:{x:-s,y:-a},smooth:!0},{x:0,y:-s,cin:{x:-a,y:-s},cout:{x:a,y:-s},smooth:!0}],u=s*1.4;return[{nodes:c,closed:!0},{nodes:[{x:-u,y:0},{x:u,y:0}],closed:!1},{nodes:[{x:0,y:-u},{x:0,y:u}],closed:!1}]}ye();function wi(n){let s=1/0,a=1/0,c=-1/0,u=-1/0;for(let h of n)for(let m of h.nodes)s=Math.min(s,m.x),a=Math.min(a,m.y),c=Math.max(c,m.x),u=Math.max(u,m.y);return{x0:s,y0:a,x1:c,y1:u,w:c-s,h:u-a}}function dt(n,s){let a=n.map(x=>({...x,b:wi(x.subs)})),c=a.reduce((x,C)=>x+(C.b.w+s)*(C.b.h+s),0),u=Math.max(Math.sqrt(c)*1.3,...a.map(x=>x.b.w)),h=[...a].sort((x,C)=>C.b.h-x.b.h||C.b.w-x.b.w),m=[],b=0,p=0,g=0,S=0;for(let x of h)b>0&&b+x.b.w>u&&(p+=g+s,b=0,g=0),m.push({key:x.key,subs:x.subs,at:{x:b-x.b.x0,y:p-x.b.y0}}),b+=x.b.w+s,g=Math.max(g,x.b.h),S=Math.max(S,b-s);let I=p+g,T=new Map(m.map(x=>[x.key,x]));return n.map(x=>{let C=T.get(x.key);return{...C,at:{x:C.at.x-S/2,y:C.at.y-I/2}}})}function Ii(n,s){if(n.length<2)return dt(n,s);let a=globalThis.host.nest({parts:n.map(c=>({key:c.key,subs:c.subs})),gap:s});return n.map((c,u)=>({key:c.key,subs:c.subs,at:{x:a[u][0],y:a[u][1]}}))}function Vt(n,s,a){let c=a==="packed"||a==="rows"?dt(n,s):Ii(n,s);return n.map((u,h)=>({...u,at:c[h].at}))}Jt();var yt=new Map;var bt=n=>yt.get(n)?.mesh??null;function qt(n,s){if(yt.has(n))return!0;try{yt.set(n,{data:s,mesh:Zt(s)})}catch{return!1}return Ai(n,s),!0}var Ti=n=>`mesh:${n}`,Ht=null;function Mi(){return Ht??(Ht=new Promise((n,s)=>{if(typeof indexedDB>"u")return s(new Error("no indexedDB"));let a=indexedDB.open("laserwerk",1);a.onupgradeneeded=()=>a.result.createObjectStore("assets"),a.onsuccess=()=>n(a.result),a.onerror=()=>s(a.error)})),Ht}function Ai(n,s){Mi().then(a=>a.transaction("assets","readwrite").objectStore("assets").put(s,Ti(n))).catch(()=>{})}function $e(n,s,a){let c=s==="y"?(g,S,I)=>[g,-I,S]:(g,S,I)=>[g,S,I],u=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0];for(let g=0;g<n.pos.length;g+=3){let S=c(n.pos[g],n.pos[g+1],n.pos[g+2]);for(let I=0;I<3;I++)u[I]=Math.min(u[I],S[I]),h[I]=Math.max(h[I],S[I])}let m=Math.max(h[0]-u[0],h[1]-u[1],h[2]-u[2])||1,b=a/m,p=[(u[0]+h[0])/2,(u[1]+h[1])/2,u[2]];return{world:(g,S,I)=>{let T=c(g,S,I);return[(T[0]-p[0])*b,(T[1]-p[1])*b,(T[2]-p[2])*b]},dims:[(h[0]-u[0])*b,(h[1]-u[1])*b,(h[2]-u[2])*b]}}var U=Je(De(),1);function Kt(n){let s=0;for(let a=0,c=n.length-1;a<n.length;c=a++)s+=n[c].x*n[a].y-n[a].x*n[c].y;return s/2}function Ae(n){let s=0;for(let a of n){let c=0;for(let u=0,h=a.length-1;u<a.length;h=u++)c+=a[h].x*a[u].y-a[u].x*a[h].y;s+=c/2}return Math.abs(s)}function $t(n,s){let a=!1;for(let c of n)for(let u=0,h=c.length-1;u<c.length;h=u++){let m=c[h],b=c[u];m.y>s.y!=b.y>s.y&&s.x<m.x+(s.y-m.y)*(b.x-m.x)/(b.y-m.y)&&(a=!a)}return a}function Li(n,s){let a=1/0;for(let c of n)for(let u=0,h=c.length-1;u<c.length;h=u++){let m=c[h],b=c[u],p=b.x-m.x,g=b.y-m.y,S=p*p+g*g,I=S?Math.max(0,Math.min(1,((s.x-m.x)*p+(s.y-m.y)*g)/S)):0;a=Math.min(a,Math.hypot(s.x-m.x-I*p,s.y-m.y-I*g))}return a}function Qe(n){let s=1/0,a=1/0,c=-1/0,u=-1/0;for(let S of n)for(let I of S)s=Math.min(s,I.x),a=Math.min(a,I.y),c=Math.max(c,I.x),u=Math.max(u,I.y);if(!isFinite(s))return null;let h=null,m=(s+c)/2,b=(a+u)/2,p=(c-s)/2,g=(u-a)/2;for(let S=0;S<3;S++){for(let T=0;T<=20;T++)for(let x=0;x<=20;x++){let C={x:m-p+2*p*T/20,y:b-g+2*g*x/20};if(!$t(n,C))continue;let M=Li(n,C);(!h||M>h.r+1e-9)&&(h={p:C,r:M})}if(!h)return null;m=h.p.x,b=h.p.y,p/=5,g/=5}return h}function et(n,s){let a=[];for(let u of n)for(let h=0,m=u.length-1;h<u.length;m=h++){let b=u[m],p=u[h];b.x>s!=p.x>s&&a.push(b.y+(s-b.x)*(p.y-b.y)/(p.x-b.x))}a.sort((u,h)=>u-h);let c=[];for(let u=0;u+1<a.length;u+=2)a[u+1]-a[u]>1e-9&&c.push([a[u],a[u+1]]);return c}var te=1e3,tt=1<<26;function _i(n,s,a){let c=n.pos.length/3,u=new Float64Array(c),h=new Float64Array(c),m=new Float64Array(c),b=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0],{u:g,v:S,w:I}=a;for(let L=0;L<c;L++){let O=s(n.pos[L*3],n.pos[L*3+1],n.pos[L*3+2]);u[L]=O[0]*g[0]+O[1]*g[1]+O[2]*g[2],h[L]=O[0]*S[0]+O[1]*S[1]+O[2]*S[2],m[L]=O[0]*I[0]+O[1]*I[1]+O[2]*I[2];let R=[u[L],h[L],m[L]];for(let D=0;D<3;D++)b[D]=Math.min(b[D],R[D]),p[D]=Math.max(p[D],R[D])}let T=n.tri.length/3,x=new Float64Array(T),C=new Float64Array(T);for(let L=0;L<T;L++){let O=m[n.tri[L*3]],R=m[n.tri[L*3+1]],D=m[n.tri[L*3+2]];x[L]=Math.min(O,R,D),C[L]=Math.max(O,R,D)}let M=Uint32Array.from({length:T},(L,O)=>O).sort((L,O)=>x[L]-x[O]);return{X:u,Y:h,Z:m,tri:n.tri,min:b,max:p,order:M,zlo:x,zhi:C}}var Qt=(n,s,a,c)=>_i(n,$e(n,s,a).world,c);function Oi(n,s){let a=0,c=n.order.length;for(;a<c;){let u=a+c>>1;n.zlo[n.order[u]]<=s?a=u+1:c=u}return a}function en(n,s,a=.5){let c=n.X.length,u=[],h=new Map,m=[],b=new Map,p=(P,_)=>{let E=P<_?P*c+_:_*c+P,B=h.get(E);if(B===void 0){let N=n.Z[P],Y=n.Z[_],F=(s-N)/(Y-N);B=u.length,u.push({x:n.X[P]+(n.X[_]-n.X[P])*F,y:n.Y[P]+(n.Y[_]-n.Y[P])*F}),m.push([]),h.set(E,B)}return B},g=Oi(n,s);for(let P=0;P<g;P++){let _=n.order[P];if(n.zhi[_]<s)continue;let E=n.tri[_*3],B=n.tri[_*3+1],N=n.tri[_*3+2],Y=n.Z[E]>=s,F=n.Z[B]>=s,J=n.Z[N]>=s;if(Y===F&&F===J)continue;let W=[];if(Y!==F&&W.push(p(E,B)),F!==J&&W.push(p(B,N)),J!==Y&&W.push(p(N,E)),W.length===2&&W[0]!==W[1]){m[W[0]].push(W[1]),m[W[1]].push(W[0]);let $=n.X[B]-n.X[E],Z=n.Y[B]-n.Y[E],re=n.Z[B]-n.Z[E],H=n.X[N]-n.X[E],ue=n.Y[N]-n.Y[E],le=n.Z[N]-n.Z[E],ge=Z*le-re*ue,Ie=re*H-$*le,Ve=u[W[0]],ze=u[W[1]],Ue=(ze.x-Ve.x)*-Ie+(ze.y-Ve.y)*ge;Math.abs(Ue)>1e-12&&b.set(Ue>0?W[0]*tt+W[1]:W[1]*tt+W[0],1)}}let S=new Uint8Array(u.length),I=[],T=[],x=P=>{let _=[P];S[P]=1;let E=-1,B=P;for(;;){let N=m[B].find(Y=>Y!==E&&!S[Y]);if(N===void 0)break;S[N]=1,_.push(N),E=B,B=N}return _};for(let P=0;P<u.length;P++)!S[P]&&m[P].length===1&&T.push(x(P));for(let P=0;P<u.length;P++)if(!S[P]&&m[P].length){let _=x(P),E=_[_.length-1];_.length>2&&m[E].includes(_[0])?I.push(_):T.push(_)}let C=T.filter(P=>P.length>1),M=(P,_)=>Math.hypot(u[P].x-u[_].x,u[P].y-u[_].y),L=0;for(;C.length;){let P=C.pop();for(;;){let _=P[P.length-1];if(M(_,P[0])<=a&&P.length>2){I.push(P);break}let E=-1,B=a,N=!1;if(C.forEach((F,J)=>{let W=M(F[0],_),$=M(F[F.length-1],_);W<=B&&(B=W,E=J,N=!1),$<=B&&(B=$,E=J,N=!0)}),E<0){L++;break}let Y=C.splice(E,1)[0];P.push(...N?Y.reverse():Y)}}let O=I.length>0,R=0,D=[];for(let P of I){let _=0,E=0;for(let N=0;N<P.length;N++){let Y=P[N],F=P[(N+1)%P.length];b.has(Y*tt+F)?(_++,E++):b.has(F*tt+Y)&&(_--,E++)}(!E||Math.abs(_)<.6*E)&&(O=!1);let B=(_<0?P.slice().reverse():P).map(N=>u[N]);R+=Kt(B),D.push(B)}return O&&R<0&&D.forEach(P=>P.reverse()),{loops:D,open:L,oriented:O}}var tn=n=>n.map(s=>({X:Math.round(s.x*te),Y:Math.round(s.y*te)}));function Re(n,s,a,c=U.default.PolyFillType.pftEvenOdd){let u=new U.default.Clipper;u.AddPaths(s,U.default.PolyType.ptSubject,!0),a.length&&u.AddPaths(a,U.default.PolyType.ptClip,!0);let h=[];return u.Execute(n,h,c,c),h}var be=n=>Re(U.default.ClipType.ctUnion,n.map(tn),[]),nn=n=>n.oriented?Re(U.default.ClipType.ctUnion,n.loops.map(tn),[],U.default.PolyFillType.pftNonZero):be(n.loops),rn=(n,s)=>Re(U.default.ClipType.ctUnion,n,s,U.default.PolyFillType.pftNonZero),Le=(n,s)=>Re(U.default.ClipType.ctIntersection,n,s,U.default.PolyFillType.pftNonZero);function _e(n,s){if(!n.length)return{polys:[],islands:0};let a=new U.default.Clipper;a.AddPaths(n,U.default.PolyType.ptSubject,!0);let c=new U.default.PolyTree;a.Execute(U.default.ClipType.ctUnion,c,U.default.PolyFillType.pftNonZero,U.default.PolyFillType.pftNonZero);let u=[],h=0,m=s*te*te,b=(p,g)=>{for(let S of p.Childs()){let I=S.Contour();if(Math.abs(U.default.Clipper.Area(I))<m)continue;let T=U.default.Clipper.CleanPolygon(I,.01*te);T.length<3||(u.push(T.map(x=>({x:x.X/te,y:x.Y/te}))),g%2===0&&h++,b(S,g+1))}};return b(c,0),{polys:u,islands:h}}function pe(n,s){if(!s)return n;let a=new U.default.ClipperOffset(2,.01*te);a.AddPaths(n,U.default.JoinType.jtRound,U.default.EndType.etClosedPolygon);let c=[];return a.Execute(c,s*te),c}var me=(n,s)=>s.length?Re(U.default.ClipType.ctDifference,n,s,U.default.PolyFillType.pftNonZero):n;function je(n,s){if(!n.length)return[];let a=new U.default.Clipper;a.AddPaths(n,U.default.PolyType.ptSubject,!0);let c=new U.default.PolyTree;a.Execute(U.default.ClipType.ctUnion,c,U.default.PolyFillType.pftNonZero,U.default.PolyFillType.pftNonZero);let u=s*te*te,h=[],m=p=>{if(Math.abs(U.default.Clipper.Area(p))<u)return null;let g=U.default.Clipper.CleanPolygon(p,.01*te);return g.length<3?null:g.map(S=>({x:S.X/te,y:S.Y/te}))},b=p=>{for(let g of p.Childs()){let S=m(g.Contour());if(!S)continue;let I=[S];for(let T of g.Childs()){let x=m(T.Contour());x&&I.push(x),b(T)}h.push(I)}};return b(c),h}var nt=n=>[n.map(s=>({X:Math.round(s.x*te),Y:Math.round(s.y*te)}))];function rt(n,s,a=32){let c=[];for(let u=0;u<a;u++)c.push({x:n.x+s*Math.cos(2*Math.PI*u/a),y:n.y+s*Math.sin(2*Math.PI*u/a)});return nt(c)}function on(n,s){let a=new U.default.ClipperOffset(2,.01*te);a.AddPath(n.map(u=>({X:Math.round(u.x*te),Y:Math.round(u.y*te)})),U.default.JoinType.jtRound,U.default.EndType.etOpenRound);let c=[];return a.Execute(c,s*te),c}var We=.08,sn=.03,Ni=[.5,.46,.54,.42,.58,.38,.62,.34,.66];function Oe(n){let s=1/0,a=1/0,c=-1/0,u=-1/0;for(let h of n)for(let m of h)s=Math.min(s,m.x),a=Math.min(a,m.y),c=Math.max(c,m.x),u=Math.max(u,m.y);return{x0:s,y0:a,x1:c,y1:u,width:c-s,height:u-a}}function gt(n,s){let{width:a,height:c}=Oe(n),u=s.width-sn,h=s.height-sn;return a<=u&&c<=h||a<=h&&c<=u}var an=n=>({x:n.y,y:-n.x}),ln=n=>({x:-n.y,y:n.x});function Ei(n,s,a,c){let[u,h]=a,m=(u+h)/2;for(let b of[-.25,.25,.5,.75,1,1.25]){let p=et(n,s+c*b).find(([g,S])=>g<m&&S>m);if(!p)return null;u=Math.max(u,p[0]),h=Math.min(h,p[1])}return h>u?[u,h]:null}function Xi(n,s,a,c,u){let{x0:h,y0:m,y1:b,width:p}=Oe(n),g=et(n,s);if(!g.length)return null;let S=5*a+2,I=Math.min(3,Math.max(.7,c/2));if(I<=a+We||u.some(D=>Math.abs(D.center.x-s)<D.radius+I+We))return null;let T=[{x:h-1,y:m-1},{x:s,y:m-1}],x=[],C=be(n);for(let D of g){let P=Ei(n,s,D,I);if(!P||P[1]-P[0]<S)return null;let _=(P[0]+P[1])/2,E=.18*(P[1]-P[0]),B=.3*(P[1]-P[0]),N=[{x:s,y:_-E},{x:s+I,y:_-B},{x:s+I,y:_+B},{x:s,y:_+E}];if(me(pe(nt(N),a+.25),C).length)return null;x.push({center:{x:s+I/2,y:_},radius:Math.hypot(I/2,B)+We}),T.push(...N)}T.push({x:s,y:b+1},{x:h-1,y:b+1});let M=nt(T),L=je(Le(C,pe(M,-We/2)),0),O=je(me(C,pe(M,We/2)),0);if(L.length!==1||O.length!==1||Math.max(Oe(L[0]).width,Oe(O[0]).width)>.9*p)return null;let R=[L[0],O[0]];return a>0&&R.some(D=>je(pe(be(D),-a/2),0).length!==1)?null:{parts:R,joins:x}}function un(n,s,a,c,u){let h=0;function m(p,g,S){if(gt(p,s))return[p];if(g>=6||h>=96)return null;let I=Oe(p),T=I.width>=I.height?[!1,!0]:[!0,!1];for(let x of T){let C=x?p.map(R=>R.map(an)):p,M=x?S.map(R=>({...R,center:an(R.center)})):S,{x0:L,width:O}=Oe(C);for(let R of Ni){if(++h>96)return null;let D=Xi(C,L+O*R,a,c,M);if(!D)continue;let[P,_]=x?D.parts.map(Y=>Y.map(F=>F.map(ln))):D.parts,E=S.concat(x?D.joins.map(Y=>({...Y,center:ln(Y.center)})):D.joins),B=m(P,g+1,E),N=B&&m(_,g+1,E);if(B&&N)return[...B,...N]}}return null}let b=[];for(let p of je(be(n),0)){let g=m(p,0,u);if(!g)return null;b.push(...g)}return b.length?b:null}var it=n=>n,Ne=(n,s=1)=>(Math.round(n*10**s)/10**s).toLocaleString(Ye,{maximumFractionDigits:s}),cn={z:{u:[1,0,0],v:[0,-1,0],w:[0,0,1]},y:{u:[1,0,0],v:[0,0,-1],w:[0,1,0]},x:{u:[0,1,0],v:[0,0,-1],w:[1,0,0]}};var Ge=new Map;function Pt(n){let s=it(n),a=[s.model,s.up,s.axis,s.size,s.thickness,s.sample,s.minArea,s.kerf,s.pinDiameter,s.pinWeb,s.hideTopPins,s.hollow,s.wall,s.splitLarge,s.splitWidth,s.splitHeight].join("|");if(Ge.has(a))return Ge.get(a);let c=s.model?bt(s.model):null;if(!c)return null;let{dims:u}=$e(c,s.up,s.size),h=cn[s.axis]??cn.z,m=Qt(c,s.up,s.size,h),b=m.min[2],p=m.max[2],g=s.thickness,S=Math.max(1,Math.round((p-b)/g)),I=Math.min(g*.02,.01),T=0,x=N=>{let Y=en(m,Math.min(p-I,Math.max(b+I,N)));return T+=Y.open,nn(Y)},C=[],M=[];for(let N=0;N<S&&S<=600;N++){let Y=b+N*g,F;s.sample==="outer"?F=rn(x(Y+I),x(Y+g-I)):s.sample==="inner"?F=Le(x(Y+I),x(Y+g-I)):F=x(Y+g/2);let{polys:J,islands:W}=_e(pe(F,s.kerf/2),s.minArea);if(!J.length){M.push(N+1);continue}C.push({key:`L${N+1}`,z0:Y,polys:J,islands:W})}let L=s.hideTopPins?C.slice(0,-1):C,O=!M.length&&C.length>1?Di(L,s):null,R=O?.centers??[],D=O?.cutters??[],P=0,_=0;for(let N of C){let Y=Ae(N.polys);if(O&&s.hideTopPins&&N===C.at(-1)||!s.hollow&&!D.length){_+=Y;continue}let F=be(N.polys),J=D.length?me(F,D):F,W=D.length?_e(J,0).polys:N.polys,$=D.length?Ae(W):Y;if(_+=$,s.hollow){let Z=Math.max(.2,s.wall??4),H=pe(F,-(Z+s.kerf+.04));if(O&&H.length)for(let ue of R){let le=Yi(ue,N.polys),ge=on([ue,le],O.collarRadius);H=me(H,ge.length?ge:rt(ue,O.collarRadius,64))}if(H=Le(H,be(_e(H,s.minArea).polys)),H.length){let ue=me(J,H),le=_e(ue,0);if(le.islands===N.islands&&Ae(le.polys)<$-.01){N.polys=le.polys,P++;continue}}}N.polys=W}let E=[];if(s.hollow&&s.splitLarge){let N={width:s.splitWidth??300,height:s.splitHeight??200};for(let Y of C){if(gt(Y.polys,N))continue;let F=s.hideTopPins&&Y===C.at(-1),J=O&&!F?R.map($=>({center:$,radius:O.collarRadius})):[],W=un(Y.polys,N,s.kerf,s.thickness,J);W?Y.pieces=W:E.push(Y.key)}}let B={frame:h,dims:u,layers:C,count:S,empty:M,open:T,pins:R,hollowed:P,solidArea:_,unsplit:E};return Ge.size>8&&Ge.clear(),Ge.set(a,B),B}function Di(n,s){if(!s.pinDiameter||s.pinDiameter<=s.kerf)return null;let a=(s.pinDiameter-s.kerf)/2,c=Math.max(.2,s.pinWeb??2)+s.kerf+.06,u=n.map(({polys:M})=>be(M)),h=u[0];for(let M of u.slice(1))if(h=Le(h,M),!h.length)return null;let m=a+c,b=pe(h,-m),p=s.hollow?me(b,pe(b,-Math.max(1,(s.wall??4)/2))):b,g=M=>Qe(_e(M,0).polys)?.p,S=g(p)??g(b);if(!S)return null;let I=rt(S,2*a+c,64),T=g(me(p,I))??g(me(b,I));if(!T)return null;let x=[S,T],C=x.flatMap(M=>rt(M,a,64));return{centers:x,cutters:C,collarRadius:m}}function Yi(n,s){let a=s[0][0],c=1/0;for(let u of s)for(let h=0;h<u.length;h++){let m=u[h],b=u[(h+1)%u.length],p=b.x-m.x,g=b.y-m.y,S=p*p+g*g;if(!S)continue;let I=Math.max(0,Math.min(1,((n.x-m.x)*p+(n.y-m.y)*g)/S)),T={x:m.x+I*p,y:m.y+I*g},x=(T.x-n.x)**2+(T.y-n.y)**2;x<c&&(a=T,c=x)}return a}var Bi={a:[0,0,1,0],b:[1,0,1,.5],c:[1,.5,1,1],d:[0,1,1,1],e:[0,.5,0,1],f:[0,0,0,.5],g:[0,.5,1,.5],p:[.4,1,.6,1]},Fi={0:"abcdef",1:"bc",2:"abged",3:"abgcd",4:"fgbc",5:"afgcd",6:"afgedc",7:"abc",8:"abcdefg",9:"abcdfg",".":"p"},ot=.55,fn=.3,hn=n=>n.length*ot+(n.length-1)*fn;function xt(n,s,a){let c=hn(n)*a,u=[];return[...n].forEach((h,m)=>{let b=s.x-c/2+m*(ot+fn)*a,p=s.y-a/2,g=[...Fi[h]??""].map(x=>Bi[x]),S=x=>[{x:b+x[0]*ot*a,y:p+x[1]*a},{x:b+x[2]*ot*a,y:p+x[3]*a}],I=g.map(S),T=(x,C)=>Math.hypot(x.x-C.x,x.y-C.y)<1e-9;for(;I.length;){let x=[...I.shift()];for(let M=!0;M;){M=!1;for(let L=0;L<I.length;L++){let[O,R]=I[L],D=x[x.length-1];if(T(D,O))x.push(R);else if(T(D,R))x.push(O);else if(T(x[0],R))x.unshift(O);else if(T(x[0],O))x.unshift(R);else continue;I.splice(L,1),M=!0;break}}let C=x.length>3&&T(x[0],x[x.length-1]);C&&x.pop(),u.push({closed:C,nodes:x.map(M=>({x:M.x,y:M.y}))})}}),u}function Ri(n,s,a){let c=Qe(n);if(!c)return null;let u=hn(s),h=Math.min(a,.85*c.r/Math.hypot(u/2,.5));return h<1.5?null:xt(s,c.p,h)}var La={id:"stack",version:2,kind:"assembly",name:w("Schichtmodell"),icon:"stack",poses:n=>{let s=ji(n);return s?{poses:s}:null},assemblyFromToolpaths:n=>n.hollow===!0&&n.splitLarge===!0,assemblyCheck:!0,inputs:[{kind:"model3d"}],fromInputs:n=>n.model?{model:n.model.id,name:n.model.name}:void 0,tile:{group:"model3d",before:"multilayer",since:"1.10.0",text:n=>({name:n("Schichtmodell"),desc:n("3D-Modell (STL, OBJ) in gestapelte Scheiben zerlegen, die verleimt wieder das Modell ergeben."),keys:n("3D STL OBJ Scheiben Schichten stapeln Slicer Skulptur Relief Kopf|Suchw\xF6rter"),action:n("Schichtmodell aus einem 3D-Modell (STL, OBJ) erstellen")})},schema:[{key:"partLayout",type:"data",label:"",def:"nest",resetOnNew:!0},{key:"model",type:"data",label:w("Modell"),def:"",resource:"model3d"},{key:"name",type:"data",label:w("Dateiname"),def:""},{key:"up",type:"enum",label:w("Oben im Modell"),def:"z",options:[["z",w("Z (meist STL)")],["y",w("Y (meist OBJ)")]],title:w("Welche Achse der Datei nach oben zeigt. Liegt das Modell in der 3D-Ansicht auf der Seite, hier umschalten.")},{key:"axis",type:"enum",label:w("Schichten"),def:"z",options:[["z",w("von unten nach oben")],["y",w("von vorne nach hinten")],["x",w("von links nach rechts")]],title:w("Richtung, in der die Scheiben gestapelt werden. Vorne nach hinten passt z. B. zu K\xF6pfen und Reliefs.")},{key:"size",type:"length",label:w("Gr\xF6\xDFe (l\xE4ngste Seite)"),min:5,max:3e3,def:150},{key:"thickness",type:"length",label:w("Materialdicke"),min:.3,max:30,def:3},{key:"sample",type:"enum",label:w("Querschnitt"),def:"mid",options:[["mid",w("Mitte der Schicht")],["outer",w("au\xDFen (zum Schleifen)")],["inner",w("innen (nichts steht \xFCber)")]],title:w("Mitte: Querschnitt in halber Schichth\xF6he. Au\xDFen: nichts vom Modell fehlt, Stufen stehen \xFCber und lassen sich abschleifen. Innen: keine Schicht steht \xFCber das Modell hinaus.")},{key:"numbers",type:"bool",label:w("Nummern gravieren"),def:!0,title:w("Jede Scheibe bekommt ihre Nummer (von unten gez\xE4hlt) als feine Gravur auf einem eigenen Layer.")},{key:"numberSize",type:"length",label:w("Gr\xF6\xDFte Schrifth\xF6he"),min:1.5,max:30,def:6,advanced:!0,showIf:{eq:["numbers",!0]}},{key:"minArea",type:"number",label:w("Kleinste Fl\xE4che (mm\xB2)"),min:0,max:1e4,def:4,advanced:!0,title:w("Inseln und L\xF6cher, die kleiner sind, werden weggelassen bzw. gef\xFCllt.")},{key:"kerf",type:"length",label:w("Schnittfuge (Kerf)"),min:0,max:2,def:.1,title:w("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},{key:"hollow",type:"bool",label:w("Schichten aush\xF6hlen"),def:!1},{key:"wall",type:"length",label:w("Mindestwandst\xE4rke"),min:.2,max:100,def:4,showIf:{eq:["hollow",!0]}},{key:"splitLarge",type:"bool",label:w("Zu gro\xDFe Schichten mit Steckverbindungen teilen"),def:!1,showIf:{eq:["hollow",!0]}},{key:"splitWidth",type:"length",label:w("Nutzbare Breite f\xFCr geteilte Schichten"),min:10,max:3e3,def:300,showIf:{and:[{eq:["hollow",!0]},{eq:["splitLarge",!0]}]}},{key:"splitHeight",type:"length",label:w("Nutzbare H\xF6he f\xFCr geteilte Schichten"),min:10,max:3e3,def:200,showIf:{and:[{eq:["hollow",!0]},{eq:["splitLarge",!0]}]}},{key:"pinDiameter",type:"length",label:w("Passstift-Durchmesser (0 = aus)"),min:0,max:50,def:0,advanced:!0,title:w("Zwei gemeinsame Bohrungen zur Ausrichtung aller Schichten. Durchmesser einschlie\xDFlich gew\xFCnschtem Spiel eingeben.")},{key:"pinWeb",type:"length",label:w("Mindeststeg an Passstiften"),min:.2,max:50,def:2,advanced:!0},{key:"hideTopPins",type:"bool",label:w("Oberste Schicht ohne Passstift-Bohrungen"),def:!1,advanced:!0}],migrate(n,s){return s<2?{...n,partLayout:"packed"}:n},validate(n){let s=it(n),a=[];if(!s.model||!bt(s.model))return a.push({level:"error",msg:w("Das 3D-Modell fehlt. Bitte \xFCber Datei \u2192 Importieren \u2026 neu einlesen.")}),a;let c=Pt(n);if(!c)return a;if(c.count>600)return[{key:"thickness",level:"error",msg:w("{n} Schichten sind zu viele: gr\xF6\xDFere Materialdicke oder kleineres Modell w\xE4hlen.",{n:c.count})}];c.count>150&&a.push({key:"thickness",level:"warn",msg:w("{n} Schichten: Das wird viel Arbeit beim Lasern und Verleimen.",{n:c.count})}),c.layers.length?c.empty.length&&a.push({key:"minArea",level:"warn",msg:w("Leere Schichten (L\xFCcke im Stapel): {list}",{list:c.empty.slice(0,12).join(", ")+(c.empty.length>12?" \u2026":"")})}):a.push({key:"size",level:"error",msg:w("Keine Schicht enth\xE4lt eine Fl\xE4che: Gr\xF6\xDFe oder kleinste Fl\xE4che pr\xFCfen.")}),c.open&&a.push({level:"warn",msg:ve("Das Modell hat L\xF6cher im Netz; an {n} Stelle fehlt ein St\xFCck Kontur. Am besten das Modell vorher reparieren (z. B. in Blender oder PrusaSlicer).","Das Modell hat L\xF6cher im Netz; an {n} Stellen fehlt ein St\xFCck Kontur. Am besten das Modell vorher reparieren (z. B. in Blender oder PrusaSlicer).",c.open)}),s.pinDiameter&&!c.pins.length&&a.push({key:"pinDiameter",level:"error",msg:w("Zwei gemeinsame Passstift-Bohrungen passen nicht in alle Schichten. Durchmesser, Steg, Gr\xF6\xDFe oder Stapelachse pr\xFCfen.")}),s.hollow&&!c.hollowed&&a.push({key:"wall",level:"error",msg:w("Keine Schicht kann mit der gew\xE4hlten Wandst\xE4rke ausgeh\xF6hlt werden.")});let u=s.hideTopPins&&c.pins.length?1:0;s.hollow&&c.hollowed&&c.hollowed<c.layers.length-u&&a.push({key:"wall",level:"warn",msg:w("Einige Schichten bleiben massiv, um die Wandst\xE4rke zu erhalten.")}),c.unsplit.length&&a.push({key:"splitWidth",level:"error",msg:w("Keine passende Teilung mit Steckverbindungen f\xFCr Schichten {list}. Arbeitsbereich, Wandst\xE4rke oder Passstifte pr\xFCfen.",{list:c.unsplit.slice(0,12).join(", ")+(c.unsplit.length>12?" \u2026":"")})});let h=c.layers.filter(m=>m.islands>1).length;return h&&a.push({level:"warn",msg:ve("{n} Schicht besteht aus mehreren St\xFCcken: Die St\xFCcke beim Verleimen nach der Schicht darunter ausrichten.","{n} Schichten bestehen aus mehreren St\xFCcken: Die St\xFCcke beim Verleimen nach der Schicht darunter ausrichten.",h)}),a},generate(n){let s=it(n),a=Pt(n);if(!a)return{parts:[],info:[]};let c=[],u=0;for(let{key:S,polys:I}of mn(a)){let T=pn(I),x=I.map(L=>L.map(O=>({x:O.x-T.x,y:O.y-T.y}))),C=x.map(L=>Me(L,!0,s.hollow?.01:.05));u+=Ae(I);let M=s.numbers?Ri(x,S.slice(1),s.numberSize):null;c.push(M?{key:S,subs:C,marks:M}:{key:S,subs:C})}let m=Vt(c,3+s.kerf,n.partLayout).map((S,I)=>c[I].marks?{...S,marks:c[I].marks}:S),[b,p,g]=a.dims;return{parts:m,distribute:s.hollow&&s.splitLarge?{rotate:!0}:void 0,info:[[w("Modell"),s.name||"\u2013"],[w("Ma\xDFe (B \xD7 T \xD7 H)"),`${Ne(b)} \xD7 ${Ne(p)} \xD7 ${Ne(g)} mm`],[w("Schichten"),String(a.layers.length)],[w("Fl\xE4che gesamt"),`${Ne(u/100,0)} cm\xB2`],...s.hollow?[[w("Fl\xE4che massiv / hohl"),`${Ne(a.solidArea/100)} / ${Ne(u/100)} cm\xB2`]]:[]]}},label(n,s){let a=it(n),c=w("Schichtmodell {name}",{name:a.name||""}).trim();return s?`${c}: ${w("Schicht {n}",{n:s.slice(1)})}`:c}};function pn(n){let s=1/0,a=1/0,c=-1/0,u=-1/0;for(let h of n)for(let m of h)s=Math.min(s,m.x),a=Math.min(a,m.y),c=Math.max(c,m.x),u=Math.max(u,m.y);return{x:(s+c)/2,y:(a+u)/2}}function ji(n){let s=Pt(n);if(!s)return null;let{u:a,v:c,w:u}=s.frame,h={};for(let{key:m,polys:b,z0:p}of mn(s)){let g=pn(b);h[m]={o:[a[0]*g.x+c[0]*g.y+u[0]*p,a[1]*g.x+c[1]*g.y+u[1]*p,a[2]*g.x+c[2]*g.y+u[2]*p],u:a,v:c,n:u}}return h}function mn(n){return n.layers.flatMap(s=>s.pieces?s.pieces.map((a,c)=>({key:`${s.key}.${c+1}`,z0:s.z0,polys:a})):[{key:s.key,z0:s.z0,polys:s.polys}])}var vt={sensitivity:50,minArea:100},Wi=1500;function dn(n){let s=0,a=0;for(let b=0;b<256;b++)s+=n[b],a+=b*n[b];if(!s)return 128;let c=0,u=0,h=-1,m=128;for(let b=0;b<256;b++){if(c+=n[b],!c)continue;let p=s-c;if(!p)break;u+=b*n[b];let g=u/c,S=(a-u)/p,I=c*p*(g-S)*(g-S);I>h&&(h=I,m=b+.5)}return m}function Gi(n,s,a){let{width:c,height:u,data:h}=n,m=c*u,b=new Uint8Array(m),p=new Float32Array(m),g=!!a&&a.width===c&&a.height===u;for(let C=0;C<m;C++){let M=C*4;if(!(h[M+3]<128||g&&a.data[M+3]<128))if(b[C]=1,g){let L=a.data;p[C]=Math.max(Math.abs(h[M]-L[M]),Math.abs(h[M+1]-L[M+1]),Math.abs(h[M+2]-L[M+2]))}else p[C]=.299*h[M]+.587*h[M+1]+.114*h[M+2]}let S=new Float64Array(256);for(let C=0;C<m;C++)b[C]&&S[Math.min(255,p[C]|0)]++;let I=(s.sensitivity-50)/50*40,T=new Uint8Array(m);if(g){let C=Math.max(8,Math.max(20,dn(S))-I);for(let M=0;M<m;M++)T[M]=b[M]&&p[M]>C?1:0}else{let C=dn(S),M=0,L=0;for(let D=0;D<u;D++)for(let P=0;P<c;P++){let _=D*c+P;!b[_]||!(P===0||D===0||P===c-1||D===u-1||!b[_-1]||!b[_+1]||!b[_-c]||!b[_+c])||(L++,p[_]<C&&M++)}let O=M*2>L,R=O?C-I:C+I;for(let D=0;D<m;D++)T[D]=b[D]&&(O?p[D]>R:p[D]<R)?1:0}let x=Math.max(1,Math.round(Math.min(c,u)/600));return st(st(st(st(T,c,u,x,!1),c,u,x,!0),c,u,x,!0),c,u,x,!1)}function st(n,s,a,c,u){let h=new Uint8Array(n.length),m=new Uint8Array(n.length),b=u?1:0;for(let p=0;p<a;p++){let g=p*s;for(let S=0;S<s;S++){let I=u?0:1;for(let T=Math.max(0,S-c),x=Math.min(s-1,S+c);T<=x;T++)if(n[g+T]===b){I=b;break}h[g+S]=I}}for(let p=0;p<s;p++)for(let g=0;g<a;g++){let S=u?0:1;for(let I=Math.max(0,g-c),T=Math.min(a-1,g+c);I<=T;I++)if(h[I*s+p]===b){S=b;break}m[g*s+p]=S}return m}function Vi(n,s,a,c,u,h,m,b,p,g){let S=Math.max(1,Math.ceil(g/Wi)),I=new Float32Array(Math.ceil(g/S)*2),T=0,x=0;for(let C=0;C<a;C++)for(let M=0;M<s;M++)n[C*s+M]&&(x++%S||(I[T++]=c+(M+.5)*h-b,I[T++]=u+(C+.5)*m-p));return I.subarray(0,T)}function zi(n,s,a,c,u,h,m){let b=0,p=0,g=0;for(let T=0;T<a;T++)for(let x=0;x<s;x++)n[T*s+x]&&(b+=x+.5,p+=T+.5,g++);if(!g)return null;let S=c+b/g*h,I=u+p/g*m;return{x0:c,y0:u,kx:h,ky:m,w:s,h:a,mask:n,cx:S,cy:I,area:g*h*m,pts:Vi(n,s,a,c,u,h,m,S,I,g)}}function Ui(n,s,a,c,u,h,m){let b=s+2,p=(x,C)=>x<1||C<1||x>s||C>a?0:n[(C-1)*s+(x-1)],g=new Map,S=x=>{let C=x>>1,M=C%b,L=(C-M)/b,O=x&1?M:M+.5,R=x&1?L+.5:L;return{x:c+(O-.5)*h,y:u+(R-.5)*m}};for(let x=0;x<=a;x++)for(let C=0;C<=s;C++){let M=p(C,x),L=p(C+1,x),O=p(C+1,x+1),R=p(C,x+1),D=M<<3|L<<2|O<<1|R;if(D===0||D===15)continue;let P=2*(x*b+C),_=2*((x+1)*b+C),E=2*(x*b+C)+1,B=2*(x*b+C+1)+1,N=(Y,F)=>g.set(Y,F);switch(D){case 1:N(E,_);break;case 2:N(_,B);break;case 3:N(E,B);break;case 4:N(B,P);break;case 5:N(E,P),N(B,_);break;case 6:N(_,P);break;case 7:N(E,P);break;case 8:N(P,E);break;case 9:N(P,_);break;case 10:N(P,B),N(_,E);break;case 11:N(P,B);break;case 12:N(B,E);break;case 13:N(B,_);break;case 14:N(_,E);break}}let I=[],T=new Set;for(let x of g.keys()){if(T.has(x))continue;let C=[],M=x;for(;M!==void 0&&!T.has(M);)T.add(M),C.push(S(M)),M=g.get(M);C.length>=3&&I.push(Zi(C,Math.min(h,m)*.6))}return I}function Zi(n,s){if(n.length<8)return n;let a=(h,m,b)=>{let p=-1,g=-1,S=n[h],I=n[m%n.length],T=I.x-S.x,x=I.y-S.y,C=Math.hypot(T,x)||1;for(let M=h+1;M<m;M++){let L=Math.abs((n[M].x-S.x)*x-(n[M].y-S.y)*T)/C;L>p&&(p=L,g=M)}p>s?(a(h,g,b),a(g,m,b)):b.push(S)},c=n.length>>1,u=[];return a(0,c,u),a(c,n.length,u),u}function St(n,s,a,c,u){let{width:h,height:m}=n,b=Gi(n,c,u),p=x=>n.data[x*4+3]>=128,g=new Int32Array(h*m),S=new Int32Array(h*m),I=[],T=0;for(let x=0;x<h*m;x++){if(!b[x]||g[x])continue;T++;let C=0,M=0,L=!1,O=h,R=m,D=-1,P=-1;for(S[C++]=x,g[x]=T;C;){let Y=S[--C];M++;let F=Y%h,J=(Y-F)/h;F<O&&(O=F),F>D&&(D=F),J<R&&(R=J),J>P&&(P=J),(F===0||J===0||F===h-1||J===m-1)&&(L=!0);let W=[F>0?Y-1:-1,F<h-1?Y+1:-1,J>0?Y-h:-1,J<m-1?Y+h:-1];for(let $ of W)$<0||(p($)?b[$]&&!g[$]&&(g[$]=T,S[C++]=$):L=!0)}if(M*s*a<c.minArea)continue;let _=D-O+1,E=P-R+1,B=new Uint8Array(_*E);for(let Y=0;Y<E;Y++)for(let F=0;F<_;F++)g[(Y+R)*h+F+O]===T&&(B[Y*_+F]=1);let N=zi(B,_,E,O*s,R*a,s,a);I.push({...N,outline:Ui(B,_,E,N.x0,N.y0,s,a),cut:L})}return Ji(I)}function Ji(n){if(n.length<2)return n;let s=n.map(h=>Math.sqrt(h.area)).sort((h,m)=>h-m),a=s[s.length>>1]/2,c=[...n].sort((h,m)=>h.cy-m.cy),u=[];for(let h of c){let m=u[u.length-1];m&&h.cy-m[0].cy<=a?m.push(h):u.push([h])}return u.flatMap(h=>h.sort((m,b)=>m.cx-b.cx))}var at=n=>n,ut=(n,s=1)=>(Math.round(n*10**s)/10**s).toLocaleString(Ye,{maximumFractionDigits:s}),Ee=n=>Math.round(n*1e3)/1e3;function lt(n){try{let s=JSON.parse(n||"[]");return Array.isArray(s)?s.filter(a=>a&&Array.isArray(a.s)&&a.s.length).map(a=>({n:String(a.n??""),c:Math.max(0,Math.min(500,Math.round(Number(a.c)||0))),r:Number(a.r)===90?90:0,s:a.s})):[]}catch{return[]}}function yn(n){let s=a=>({closed:!0,nodes:a.nodes.map(c=>{let u={x:Ee(c.x),y:Ee(c.y)};return c.cin&&(u.cin={x:Ee(c.cin.x),y:Ee(c.cin.y)}),c.cout&&(u.cout={x:Ee(c.cout.x),y:Ee(c.cout.y)}),u})});return JSON.stringify(n.map(a=>({n:a.n,c:a.c,r:a.r,s:a.s.map(s)})))}var Hi=n=>n.map(s=>({X:Math.round(s.x*ne),Y:Math.round(s.y*ne)})),qi=n=>n.map(s=>({x:s.X/ne,y:s.Y/ne}));function It(n){let s=new de.default.Clipper;s.AddPaths(n,de.default.PolyType.ptSubject,!0);let a=new de.default.PolyTree;return s.Execute(de.default.ClipType.ctUnion,a,de.default.PolyFillType.pftNonZero,de.default.PolyFillType.pftNonZero),a.Childs().map(c=>c.Contour()).filter(c=>c.length>=3)}function Pn(n,s=.02){let a=It(n.filter(S=>S.length>=3).map(Hi));if(!a.length)return[];let c=a.map(qi),u=1/0,h=1/0,m=-1/0,b=-1/0;for(let S of c)for(let I of S)u=Math.min(u,I.x),h=Math.min(h,I.y),m=Math.max(m,I.x),b=Math.max(b,I.y);let p=(u+m)/2,g=(h+b)/2;return c.map(S=>Me(S.map(I=>({x:I.x-p,y:I.y-g})),!0,s))}function Ki(n,s){let a=n.s.map(u=>mt(u,Se)).filter(u=>u.length>=3);n.r===90&&(a=a.map(u=>u.map(h=>({X:-h.Y,Y:h.X}))));let c=(s.clearance-s.kerf/2)*ne;if(c){let u=new de.default.ClipperOffset(2,.005*ne);u.AddPaths(a,de.default.JoinType.jtRound,de.default.EndType.etClosedPolygon);let h=[];u.Execute(h,c),a=h}if(a=It(a),s.notch!=="none"&&a.length){let u=xn(a),h=(u.y0+u.y1)/2*ne,m=-1/0,b=1/0;for(let x of a)for(let C=0,M=x.length-1;C<x.length;M=C++){let L=x[M],O=x[C];if(L.Y<=h==O.Y<=h)continue;let R=L.X+(h-L.Y)/(O.Y-L.Y)*(O.X-L.X);m=Math.max(m,R),b=Math.min(b,R)}let p={X:m,Y:h},g={X:b,Y:h},S=s.notchSize/2*ne,I=(x,C)=>Array.from({length:48},(M,L)=>({X:Math.round(x+S*Math.cos(L/48*2*Math.PI)),Y:Math.round(C+S*Math.sin(L/48*2*Math.PI))})),T=[I(p.X,p.Y)];s.notch==="two"&&T.push(I(g.X,g.Y)),a=It([...a,...T])}return a}function xn(n){let s=1/0,a=1/0,c=-1/0,u=-1/0;for(let h of n)for(let m of h)s=Math.min(s,m.X),a=Math.min(a,m.Y),c=Math.max(c,m.X),u=Math.max(u,m.Y);return{x0:s/ne,y0:a/ne,x1:c/ne,y1:u/ne}}var $i=n=>n.marks?Math.max(n.margin,n.markSize*1.4+3):n.margin;function wt(n,s=lt(n.shapes)){let a=$i(n),c=n.numbers?n.numberSize+1.5:0,u=s.map(Z=>{let re=Ki(Z,n),H=xn(re);return{polys:re,b:H,w:H.x1-H.x0,h:H.y1-H.y0}}),h=[];s.forEach((Z,re)=>{if(u[re].polys.length)for(let H=0;H<Z.c;H++)h.push({k:re})});let m=n.plate==="size",b=Z=>u[Z].w+n.gap,p=Z=>u[Z].h+c+n.gap,g=h.reduce((Z,re)=>Z+b(re.k)*p(re.k),0),S=Math.max(0,...h.map(Z=>b(Z.k))),I=m?n.width-2*a+n.gap:Math.max(Math.sqrt(g)*1.15,S),T=m?n.height-2*a+n.gap:1/0,x=[],C=0,M=0,L=0,O=0,R=0;for(let Z of h){if(C>0&&C+b(Z.k)>I+1e-6&&(M+=L,C=0,L=0),M+p(Z.k)>T+1e-6||b(Z.k)>I+1e-6){R++;continue}x.push({k:Z.k,x:C,y:M}),C+=b(Z.k),L=Math.max(L,p(Z.k)),O=Math.max(O,C)}let D=Math.max(0,O-n.gap),P=Math.max(0,M+L-n.gap),_=m?n.width:D+2*a,E=m?n.height:P+2*a,B=-_/2+a+(m?Math.max(0,(_-2*a-D)/2):0),N=-E/2+a+(m?Math.max(0,(E-2*a-P)/2):0),Y=[],F=[],J=[];x.forEach((Z,re)=>{let H=u[Z.k],ue=B+Z.x-H.b.x0,le=N+Z.y-H.b.y0;for(let ge of H.polys)Y.push(Me(ge.map(Ie=>({x:Ie.X/ne+ue,y:Ie.Y/ne+le})),!0,.02));J.push({nr:re+1,shape:Z.k,c:{x:ue,y:le},rot:s[Z.k].r}),n.numbers&&F.push(...xt(String(re+1),{x:B+Z.x+H.w/2,y:N+Z.y+H.h+1+n.numberSize/2},n.numberSize))});let W=a/2,$=n.marks?[{x:-_/2+W,y:-E/2+W},{x:_/2-W,y:-E/2+W},{x:-_/2+W,y:E/2-W}]:[];return{w:_,h:E,slots:J,overflow:R,holes:Y,numbers:F,markCenters:$}}function Qi(n,s,a,c){let u=n/2+c,h=s/2+c,m=Math.max(0,Math.min(a+c,u,h));if(m<1e-6)return{closed:!0,nodes:[{x:-u,y:-h},{x:u,y:-h},{x:u,y:h},{x:-u,y:h}]};let b=m*.5522847498;return{closed:!0,nodes:[{x:-u+m,y:-h,cin:{x:-u+m-b,y:-h}},{x:u-m,y:-h,cout:{x:u-m+b,y:-h}},{x:u,y:-h+m,cin:{x:u,y:-h+m-b}},{x:u,y:h-m,cout:{x:u,y:h-m+b}},{x:u-m,y:h,cin:{x:u-m+b,y:h}},{x:-u+m,y:h,cout:{x:-u+m-b,y:h}},{x:-u,y:h-m,cin:{x:-u,y:h-m+b}},{x:-u,y:-h+m,cout:{x:-u,y:-h+m-b}}]}}var bn=(n,s)=>n&&{x:n.x+s.x,y:n.y+s.y},eo=(n,s)=>({...n,nodes:n.nodes.map(a=>{let c={...a,x:a.x+s.x,y:a.y+s.y};return a.cin&&(c.cin=bn(a.cin,s)),a.cout&&(c.cout=bn(a.cout,s)),c})});function gn(n){return n.map(s=>({n:s.name,c:1,r:0,s:Pn(s.polys)})).filter(s=>s.s.length)}var vn=(n,s,a=1)=>({n:s,c:1,r:0,s:Pn(n.outline.map(c=>c.map(u=>({x:u.x*a,y:u.y*a}))),.15)}),to=n=>n.filter(s=>!s.cut).sort((s,a)=>a.area-s.area)[0]??n.sort((s,a)=>a.area-s.area)[0];function no(n,s){let a=to(St(n,1,1,{...vt,minArea:n.width*n.height/400}));if(!a)return null;let c=a.outline.flat(),u=Math.max(...c.map(h=>h.x))-Math.min(...c.map(h=>h.x));return vn(a,n.name,s/Math.max(1e-6,u))}function ro(n){let s=St(n,n.bed.w/n.width,n.bed.h/n.height,vt,n.empty??null).filter(c=>!c.cut),a=[];for(let c of s){let u=a.find(h=>Math.abs(h.pc.area-c.area)/h.pc.area<.08);u?u.n++:a.push({pc:c,n:1})}return{shapes:a.map(c=>({...vn(c.pc,""),c:c.n})),found:s.length}}function io(n){let s=1/0,a=-1/0,c=1/0,u=-1/0;for(let h of n.s)for(let m of mt(h,Se)){let b=m.X/ne,p=m.Y/ne;s=Math.min(s,b),a=Math.max(a,b),c=Math.min(c,p),u=Math.max(u,p)}return s<=a?`${ut(a-s)} \xD7 ${ut(u-c)} mm`:""}var Sn={id:"jig",version:1,kind:"assembly",name:w("Jig"),icon:"jig",inputs:[{kind:"selection"}],fromInputs:n=>n.selection?.length?{shapes:yn(gn(n.selection))}:void 0,lists:[{param:"shapes",label:w("Werkst\xFCcke"),empty:w("Noch kein Werkst\xFCck."),shape:{key:"s",rotate:"r"},columns:[{key:"n",type:"text",label:w("Name"),max:120,placeholder:w("Werkst\xFCck {n}")},{key:"c",type:"int",label:w("Anzahl"),min:0,max:500,title:w("Anzahl F\xE4cher f\xFCr dieses Werkst\xFCck")},{key:"r",type:"enum",label:w("Drehung"),options:[[0,"0\xB0"],[90,"90\xB0"]],title:w("Werkst\xFCck im Jig drehen")}],remove:!0,removeTitle:w("Werkst\xFCck entfernen")}],actions:[{id:"fromSelection",label:w("Aus Auswahl"),title:w("Gew\xE4hlte Objekte als Werkst\xFCcke \xFCbernehmen (Vektorgrafik, Formen, Text); je Objekt eine Art, L\xF6cher z\xE4hlen nicht"),inputs:["selection"]},{id:"fromImage",label:w("Aus Bild \u2026"),title:w("Foto oder Scan eines Werkst\xFCcks nachzeichnen; die Breite legt den Ma\xDFstab fest"),inputs:["image"],field:"imageWidth"},{id:"fromCamera",label:w("Aus Kamera"),title:w("Werkst\xFCcke auf dem Bett im Kamerabild erkennen; Ma\xDFe kommen aus der Kalibrierung"),inputs:["camera"]}],onEvent(n,s){let a=at(s),c=(u,h="")=>({patch:{shapes:yn([...lt(a.shapes),...u])},message:h});if(n.action==="fromSelection"){let u=gn(n.inputs.selection??[]);return u.length?c(u):{message:w("Erst auf der Arbeitsfl\xE4che die Werkst\xFCckform ausw\xE4hlen (z. B. eine importierte SVG-, DXF- oder PDF-Datei).")}}if(n.action==="fromImage"){if(!n.inputs.image)return{message:w("Das Bild lie\xDF sich nicht lesen.")};let u=no(n.inputs.image,a.imageWidth);return u?c([u]):{message:w("Im Bild wurde kein Werkst\xFCck erkannt. Am besten ein Foto von oben auf einfarbigem Hintergrund.")}}if(n.action==="fromCamera"){if(!n.inputs.camera)return{message:w("Kein Kamerabild. Im Fenster \u201EKamera\u201C verbinden und das Bild aktualisieren.")};let u=ro(n.inputs.camera);return u.found?c(u.shapes,ve("{n} Werkst\xFCck erkannt.","{n} Werkst\xFCcke erkannt.",u.found)):{message:w("Kein Werkst\xFCck im Kamerabild erkannt.")}}},view:n=>({rows:{shapes:lt(String(n.shapes??"[]")).map(io)}}),tile:{group:"arrange",before:"jigfill",since:"1.17.0",text:n=>({name:n("Jig"),desc:n("Halteplatte mit passgenauen Aussparungen f\xFCr Werkst\xFCcke aus Vektorgrafik, Bild oder Kamera, mit Nummern und Passermarken."),keys:n("Jig Halterung Vorrichtung Schablone Aussparung Serie Schl\xFCsselanh\xE4nger Rohlinge F\xE4cher|Suchw\xF6rter"),action:n("Jig: Halteplatte mit Aussparungen f\xFCr Werkst\xFCcke, Nummern und Passermarken")})},schema:[{key:"shapes",type:"data",label:w("Werkst\xFCcke"),def:"[]"},{key:"imageWidth",type:"length",label:w("Breite"),min:1,max:1e3,def:20,title:w("Echte Breite des Werkst\xFCcks im Bild, damit die Form die richtige Gr\xF6\xDFe bekommt")},{key:"plate",type:"enum",label:w("Platte"),def:"fit",options:[["fit",w("Passend zu den F\xE4chern")],["size",w("Feste Gr\xF6\xDFe")]],title:w("Passend: die Platte w\xE4chst mit der Zahl der F\xE4cher. Feste Gr\xF6\xDFe: so viele F\xE4cher wie angegeben, soweit sie passen.")},{key:"width",type:"length",label:w("Breite"),min:20,max:2e3,def:200,showIf:{eq:["plate","size"]}},{key:"height",type:"length",label:w("H\xF6he"),min:20,max:2e3,def:150,showIf:{eq:["plate","size"]}},{key:"gap",type:"length",label:w("Abstand der F\xE4cher"),min:1,max:100,def:5,title:w("Steg zwischen zwei Aussparungen (ohne Griffmulden)")},{key:"clearance",type:"length",label:w("Spiel je Seite"),min:0,max:3,def:.15,title:w("So viel gr\xF6\xDFer als das Werkst\xFCck wird die Aussparung auf jeder Seite.")},{key:"notch",type:"enum",label:w("Griffmulden"),def:"one",options:[["none",w("Keine")],["one",w("Eine Seite")],["two",w("Beide Seiten")]],title:w("Halbrunde Ausschnitte am Rand der Aussparung, um das Werkst\xFCck herauszunehmen")},{key:"notchSize",type:"length",label:w("Muldengr\xF6\xDFe"),min:4,max:40,def:12,showIf:{ne:["notch","none"]}},{key:"numbers",type:"bool",label:w("F\xE4cher nummerieren"),def:!0,title:w("Fachnummer als feine Gravur unter jeder Aussparung; sie passt zur Zeile der Serien-Tabelle.")},{key:"marks",type:"bool",label:w("Passermarken gravieren"),def:!0,title:w("Drei Marken in den Ecken, um den wieder eingelegten Jig mit Print and Cut einzumessen")},{key:"margin",type:"length",label:w("Rand"),min:2,max:100,def:10,advanced:!0},{key:"radius",type:"length",label:w("Eckenradius"),min:0,max:50,def:3,advanced:!0},{key:"kerf",type:"length",label:w("Schnittfuge"),min:0,max:1,def:.1,advanced:!0,title:w("Breite des Schnitts; wird beim Spiel ber\xFCcksichtigt")},{key:"thickness",type:"length",label:w("Materialdicke"),min:.5,max:50,def:3,advanced:!0,title:w("Dicke der Jig-Platte (f\xFCr die 3D-Ansicht)")},{key:"numberSize",type:"length",label:w("Schrifth\xF6he"),min:1.5,max:20,def:3,advanced:!0,showIf:{eq:["numbers",!0]}},{key:"markSize",type:"length",label:w("Markengr\xF6\xDFe"),min:3,max:20,def:6,advanced:!0,showIf:{eq:["marks",!0]}}],validate(n){let s=at(n),a=lt(s.shapes),c=[];if(a.length?a.some(u=>u.c>0)||c.push({level:"error",msg:w("Alle Werkst\xFCcke haben die Anzahl 0.")}):c.push({level:"error",msg:w("Noch kein Werkst\xFCck. Unten eine Form aus der Auswahl, einer Datei oder der Kamera hinzuf\xFCgen.")}),a.length&&s.plate==="size"){let u=wt(s,a).overflow;u&&c.push({key:"width",level:"warn",msg:ve("{n} Fach passt nicht auf die Platte.","{n} F\xE4cher passen nicht auf die Platte.",u)})}return c},generate(n){let s=at(n),a=wt(s),c=[Qi(a.w,a.h,s.radius,s.kerf/2),...a.holes],u=[...a.numbers,...a.markCenters.flatMap(b=>Gt(s.markSize).map(p=>eo(p,b)))],h={key:"plate",subs:c,at:{x:0,y:0},...u.length?{marks:u}:{}},m=[[w("Platte"),`${ut(a.w)} \xD7 ${ut(a.h)} mm`],[w("F\xE4cher"),String(a.slots.length)]];return a.overflow&&m.push([w("Passen nicht"),String(a.overflow)]),{parts:[h],info:m}},label(n){let s=wt(at(n));return ve("Jig {n} Fach","Jig {n} F\xE4cher",s.slots.length)}};qe();var Ga={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};ye();function wn(n){let s=2166136261;for(let a=0;a<n.length;a++)s^=n.charCodeAt(a),s=Math.imul(s,16777619)>>>0;return"t"+s.toString(16).padStart(8,"0")}var Ct=n=>({width:n.width,height:n.height,data:Fe(n.data)});function oo(n){let s={};return n.selection&&(s.selection=n.selection),n.image&&(s.image={...Ct(n.image),name:String(n.image.name??"")}),n.camera&&(s.camera={...Ct(n.camera),bed:n.camera.bed,...n.camera.empty?{empty:Ct(n.camera.empty)}:{}}),s}var In=n=>{if(typeof n=="string")return n;let s={code:wn(n.de)};return n.values&&(s.values=Object.fromEntries(Object.entries(n.values).map(([a,c])=>[a,typeof c=="number"?c:Tn(c)]))),s},Tn=n=>n.length===1?In(n[0]):n.map(In),ie=n=>Tn(ft(n)),kt=globalThis;kt.structuredClone??(kt.structuredClone=n=>JSON.parse(JSON.stringify(n)));function Cn(n){return!n||n instanceof Promise?null:{...n.patch?{patch:n.patch}:{},...n.message!==void 0?{message:ie(n.message)}:{},...n.state!==void 0?{state:n.state}:{},...n.view!==void 0?{view:n.view}:{},...n.select?{select:n.select}:{}}}var kn=n=>n.type==="text"?{...n,text:ie(n.text)}:n;function Mn(n){globalThis.plugin={...n.schema.some(s=>s.type==="data"&&s.resource)?{resource(s){if(s.kind==="model3d"&&!qt(s.id,s.data))throw new Error("bad-model");return null}}:{},validate(s){return n.validate(s).map(a=>{let c=a.code?{code:a.code}:ie(a.msg),u=typeof c=="object"&&!Array.isArray(c)?c:{code:"plugin-text",values:{text:c}};return{...a.key?{key:a.key}:{},level:a.level,...u}})},generate(s){let a=n.generate(s),c=n.poses?.(s,Number(s.thickness)||3)??null,u={};if(n.kind==="assembly")for(let h of a.parts)u[h.key]=ie(n.label(s,h.key));return{parts:a.parts,info:a.info.map(([h,m])=>[ie(h),ie(m)]),label:ie(n.label(s)),...a.distribute?{distribute:a.distribute}:{},...a.plan?{plan:{title:ie(a.plan.title),lines:a.plan.lines,labels:a.plan.labels.map(h=>({...h,text:ie(h.text)})),steps:a.plan.steps.map(ie)}}:{},...n.kind==="assembly"?{labels:u}:{},...c?{poses:c}:{}}},...n.migrate?{migrate(s){return n.migrate(s.params,s.from)}}:{},...n.view?{view(s){let a=n.view(s);return{...a.autoText?{autoText:Object.fromEntries(Object.entries(a.autoText).map(([c,u])=>[c,ie(u)]))}:{},...a.rows?{rows:Object.fromEntries(Object.entries(a.rows).map(([c,u])=>[c,u.map(ie)]))}:{},...a.rowAuto?{rowAuto:Object.fromEntries(Object.entries(a.rowAuto).map(([c,u])=>[c,u.map(ie)]))}:{}}}}:{},...n.onEvent?{onEvent(s){let a={action:s.action,inputs:oo(s.inputs??{})};return s.row!==void 0&&(a.row=s.row),s.surface&&(a.surface=s.surface),Cn(n.onEvent(a,s.params))}}:{},...n.draw?{draw(s){let{params:a,...c}=s,u=n.draw(c,a);return u instanceof Promise?null:{...u,items:u.items.map(kn),...u.fields?{fields:u.fields.map(h=>({...h,label:ie(h.label),...h.title?{title:ie(h.title)}:{}}))}:{},...u.layers?{layers:u.layers.map(h=>h.items?{...h,items:h.items.map(kn)}:h)}:{}}}}:{},...n.onSurface?{onSurface(s){return Cn(n.onSurface(s.event,s.surface,s.params))}}:{},...n.onChange?{onChange(s){let a=n.onChange(s.key,s.old,s.params);return!a||a instanceof Promise?null:{...a.patch?{patch:a.patch}:{},...a.ask?{ask:{question:ie(a.ask.question),options:a.ask.options.map(c=>({label:ie(c.label),patch:c.patch}))}}:{}}}}:{}}}Mn(Sn);})();
