markuno_lib 1.1.21 → 1.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/markcad.js CHANGED
@@ -1 +1 @@
1
- class Matrix3D{constructor(){this.m=new Float32Array(16),this.st=[],this.init()}init(){return this.m.fill(0),this.m[0]=this.m[5]=this.m[10]=this.m[15]=1,this}atranslate(x,y,z){return this.m[12]+=x,this.m[13]+=y,this.m[14]+=z,this}translate(x,y,z){return x??=0,y??=0,z??=0,this.m[12]+=x*this.m[0]+y*this.m[4]+z*this.m[8],this.m[13]+=x*this.m[1]+y*this.m[5]+z*this.m[9],this.m[14]+=x*this.m[2]+y*this.m[6]+z*this.m[10],this.m[15]+=x*this.m[3]+y*this.m[7]+z*this.m[11],this}rotateX(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateY(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[8]*s,this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[8]=a[0]*-s+a[8]*c,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateZ(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[4]*s,this.m[1]=a[1]*c+a[5]*s,this.m[2]=a[2]*c+a[6]*s,this.m[3]=a[3]*c+a[7]*s,this.m[4]=a[0]*-s+a[4]*c,this.m[5]=a[1]*-s+a[5]*c,this.m[6]=a[2]*-s+a[6]*c,this.m[7]=a[3]*-s+a[7]*c}return this}getdati(){return Array.from(this.m)}setdati(d){if(d&&16===d.length){for(let i=0;i<16;i++)this.m[i]=Number(d[i])||0;return this}this.init()}push(){return this.st.push(new Float32Array(this.m)),this}pop(){return this.st.length>0&&(this.m=this.st.pop()),this}transform(x,y,z=0){return{x:x*this.m[0]+y*this.m[4]+z*this.m[8]+this.m[12],y:x*this.m[1]+y*this.m[5]+z*this.m[9]+this.m[13],z:x*this.m[2]+y*this.m[6]+z*this.m[10]+this.m[14]}}invert(){const m=this.m,inv=new Matrix3D,det=this.determinant();return Math.abs(det)<1e-8?null:(inv.m[0]=(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])/det,inv.m[1]=(m[1]*m[14]*m[11]+m[9]*m[2]*m[15]+m[13]*m[10]*m[3]-m[1]*m[10]*m[15]-m[9]*m[14]*m[3]-m[13]*m[2]*m[11])/det,inv.m[2]=(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])/det,inv.m[3]=(m[1]*m[10]*m[7]+m[5]*m[2]*m[11]+m[9]*m[6]*m[3]-m[1]*m[6]*m[11]-m[5]*m[10]*m[3]-m[9]*m[2]*m[7])/det,inv.m[4]=(m[4]*m[14]*m[11]+m[8]*m[6]*m[15]+m[12]*m[10]*m[7]-m[4]*m[10]*m[15]-m[8]*m[14]*m[7]-m[12]*m[6]*m[11])/det,inv.m[5]=(m[0]*m[10]*m[15]+m[8]*m[14]*m[3]+m[12]*m[2]*m[11]-m[0]*m[14]*m[11]-m[8]*m[2]*m[15]-m[12]*m[10]*m[3])/det,inv.m[6]=(m[0]*m[14]*m[7]+m[4]*m[2]*m[15]+m[12]*m[6]*m[3]-m[0]*m[6]*m[15]-m[4]*m[14]*m[3]-m[12]*m[2]*m[7])/det,inv.m[7]=(m[0]*m[6]*m[11]+m[4]*m[10]*m[3]+m[8]*m[2]*m[7]-m[0]*m[10]*m[7]-m[4]*m[2]*m[11]-m[8]*m[6]*m[3])/det,inv.m[8]=(m[4]*m[9]*m[15]+m[8]*m[13]*m[7]+m[12]*m[5]*m[11]-m[4]*m[13]*m[11]-m[8]*m[5]*m[15]-m[12]*m[9]*m[7])/det,inv.m[9]=(m[0]*m[13]*m[11]+m[8]*m[1]*m[15]+m[12]*m[9]*m[3]-m[0]*m[9]*m[15]-m[8]*m[13]*m[3]-m[12]*m[1]*m[11])/det,inv.m[10]=(m[0]*m[5]*m[15]+m[4]*m[13]*m[3]+m[12]*m[1]*m[7]-m[0]*m[13]*m[7]-m[4]*m[1]*m[15]-m[12]*m[5]*m[3])/det,inv.m[11]=(m[0]*m[9]*m[7]+m[4]*m[1]*m[11]+m[8]*m[5]*m[3]-m[0]*m[5]*m[11]-m[4]*m[9]*m[3]-m[8]*m[1]*m[7])/det,inv.m[12]=(m[4]*m[13]*m[10]+m[8]*m[5]*m[14]+m[12]*m[9]*m[6]-m[4]*m[9]*m[14]-m[8]*m[13]*m[6]-m[12]*m[5]*m[10])/det,inv.m[13]=(m[0]*m[9]*m[14]+m[8]*m[13]*m[2]+m[12]*m[1]*m[10]-m[0]*m[13]*m[10]-m[8]*m[1]*m[14]-m[12]*m[9]*m[2])/det,inv.m[14]=(m[0]*m[13]*m[6]+m[4]*m[1]*m[14]+m[12]*m[5]*m[2]-m[0]*m[5]*m[14]-m[4]*m[13]*m[2]-m[12]*m[1]*m[6])/det,inv.m[15]=(m[0]*m[5]*m[10]+m[4]*m[9]*m[2]+m[8]*m[1]*m[6]-m[0]*m[9]*m[6]-m[4]*m[1]*m[10]-m[8]*m[5]*m[2])/det,inv)}determinant(){const m=this.m;return m[0]*(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])-m[4]*(m[1]*m[10]*m[15]+m[9]*m[14]*m[3]+m[13]*m[2]*m[11]-m[1]*m[14]*m[11]-m[9]*m[2]*m[15]-m[13]*m[10]*m[3])+m[8]*(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])-m[12]*(m[1]*m[6]*m[11]+m[5]*m[10]*m[3]+m[9]*m[2]*m[7]-m[1]*m[10]*m[7]-m[5]*m[2]*m[11]-m[9]*m[6]*m[3])}multiply(matrix){const a=[...this.m],b=matrix.m;return this.m[0]=a[0]*b[0]+a[4]*b[1]+a[8]*b[2]+a[12]*b[3],this.m[1]=a[1]*b[0]+a[5]*b[1]+a[9]*b[2]+a[13]*b[3],this.m[2]=a[2]*b[0]+a[6]*b[1]+a[10]*b[2]+a[14]*b[3],this.m[3]=a[3]*b[0]+a[7]*b[1]+a[11]*b[2]+a[15]*b[3],this.m[4]=a[0]*b[4]+a[4]*b[5]+a[8]*b[6]+a[12]*b[7],this.m[5]=a[1]*b[4]+a[5]*b[5]+a[9]*b[6]+a[13]*b[7],this.m[6]=a[2]*b[4]+a[6]*b[5]+a[10]*b[6]+a[14]*b[7],this.m[7]=a[3]*b[4]+a[7]*b[5]+a[11]*b[6]+a[15]*b[7],this.m[8]=a[0]*b[8]+a[4]*b[9]+a[8]*b[10]+a[12]*b[11],this.m[9]=a[1]*b[8]+a[5]*b[9]+a[9]*b[10]+a[13]*b[11],this.m[10]=a[2]*b[8]+a[6]*b[9]+a[10]*b[10]+a[14]*b[11],this.m[11]=a[3]*b[8]+a[7]*b[9]+a[11]*b[10]+a[15]*b[11],this.m[12]=a[0]*b[12]+a[4]*b[13]+a[8]*b[14]+a[12]*b[15],this.m[13]=a[1]*b[12]+a[5]*b[13]+a[9]*b[14]+a[13]*b[15],this.m[14]=a[2]*b[12]+a[6]*b[13]+a[10]*b[14]+a[14]*b[15],this.m[15]=a[3]*b[12]+a[7]*b[13]+a[11]*b[14]+a[15]*b[15],this}}class Punto2{constructor(x,y){Array.isArray(x)?(this.x=x[0]||0,this.y=x[1]||0):x&&"object"==typeof x?(this.x=x.x||0,this.y=x.y||0):(this.x=x||0,this.y=y||0)}get dump(){return`{${this.x.toFixed(1)},${this.y.toFixed(1)}}`}get len2(){return this.x*this.x+this.y*this.y}get len(){return Math.sqrt(this.len2)}get angle(){return Math.atan2(this.y,this.x)}dir(){let l=this.len;return l?new Punto2(this.x/l,this.y/l):this}}class Linea2{constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&null!==x2&&null!==y2?(this.p1=new Punto2({x:p1,y:p2}),this.p2=new Punto2({x:x2,y:y2})):p1&&p2?(this.p1=new Punto2(p1),this.p2=new Punto2(p2)):(this.p1=new Punto2(0,0),this.p2=new Punto2(1,0))}get dump(){return`${this.p1.dump}-${this.p2.dump}`}get dx(){return this.p2.x-this.p1.x}get dy(){return this.p2.y-this.p1.y}get len2(){let{dx:dx,dy:dy}=this;return dx*dx+dy*dy}get len(){return Math.sqrt(this.len2)}estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.intersection(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}get direzione(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(dx/len,dy/len):new Punto2(0,0)}get normale(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(-dy/len,dx/len):new Punto2(0,1)}ruotata(angle=Math.PI/2,length=0,fine=!1){const{p1:p1,p2:p2,direzione:direzione,len:len}=this;length=length||len;const sx=(direzione.x*Math.cos(angle)-direzione.y*Math.sin(angle))*length,sy=(direzione.x*Math.sin(angle)+direzione.y*Math.cos(angle))*length;return fine?new Linea2(p1,new Punto2(p1.x+sx,p1.y+sy)):new Linea2(p2,new Punto2(p2.x+sx,p2.y+sy))}puntosudirezione(p1,lunghezza){let{direzione:direzione}=this;return new Punto2(p1.x+direzione.x*lunghezza,p1.y+direzione.y*lunghezza)}parallela(p1,lunghezza){let{direzione:direzione}=this;return new Linea2(p1,this.puntosudirezione(p1,lunghezza))}intersezione(line2){const{p1:p1_1,p2:p2_1}=this,{p1:p1_2,p2:p2_2}=line2,det=(p2_1.x-p1_1.x)*(p2_2.y-p1_2.y)-(p2_1.y-p1_1.y)*(p2_2.x-p1_2.x);if(Math.abs(det)<.001)return null;const t=((p1_2.x-p1_1.x)*(p2_2.y-p1_2.y)-(p1_2.y-p1_1.y)*(p2_2.x-p1_2.x))/det;return new Punto2(p1_1.x+t*(p2_1.x-p1_1.x),p1_1.y+t*(p2_1.y-p1_1.y))}onsegment(p,eps=1e-9){const{p1:p1,p2:p2}=this,minX=Math.min(p1.x,p2.x)-eps,maxX=Math.max(p1.x,p2.x)+eps,minY=Math.min(p1.y,p2.y)-eps,maxY=Math.max(p1.y,p2.y)+eps;return p.x>=minX&&p.x<=maxX&&p.y>=minY&&p.y<=maxY}isparallela(line2){const det=this.dx*line2.dy-this.dy*line2.dx;return Math.abs(det)<.001}infoquad(line2){if(!this.isparallela(line2))return;const{p1:p1,p2:p2,normale:normale}=this;let{p1:p3,p2:p4}=line2;function wrapToPi(theta){return theta>Math.PI?theta-=2*Math.PI:theta<-Math.PI&&(theta+=2*Math.PI),theta}function getangle(a,b){return Math.atan2(b.y-a.y,b.x-a.x)}(p2.x-p1.x)*(p3.y-p2.y)-(p2.y-p1.y)*(p3.x-p2.x)<0&&([p3,p4]=[p4,p3]);const baseAng=getangle(p1,p2),afin=wrapToPi(getangle(p2,p3)-baseAng),aini=wrapToPi(getangle(p1,p4)-baseAng),l=this.len,dx=p3.x-p1.x,dy=p3.y-p1.y;return{angle:baseAng,aini:aini,afin:afin,l:l,distanza:Math.abs(dx*normale.x+dy*normale.y)}}isperpendicolare(line2){const dotProduct=this.dx*line2.dx+this.dy*line2.dy;return Math.abs(dotProduct)<.001}offset(delta){const normale=this.normale,p1_offset=new Punto2(this.p1.x+normale.x*delta,this.p1.y+normale.y*delta),p2_offset=new Punto2(this.p2.x+normale.x*delta,this.p2.y+normale.y*delta);return new Linea2(p1_offset,p2_offset)}angolo(line2){const{dx:dx1,dy:dy1}=this,{dx:dx2,dy:dy2}=line2,a1=Math.atan2(dy1,dx1);let delta=Math.atan2(dy2,dx2)-a1;return delta>Math.PI?delta-=2*Math.PI:delta<-Math.PI&&(delta+=2*Math.PI),delta}ortopt(l){let{p1:p1,dx:dx,dy:dy}=this;const len=Math.hypot(dx,dy);if(len<.001)return;const ux=-dy/len,uy=dx/len;return{x:p1.x+ux*l,y:p1.y+uy*l}}offsetline(l){let{p1:p1,p2:p2,dx:dx,dy:dy}=this;const len=Math.hypot(dx,dy);if(len<.001)return;const ux=-dy/len,uy=dx/len;return new Linea2({x:p1.x+ux*l,y:p1.y+uy*l},{x:p2.x+ux*l,y:p2.y+uy*l})}distanzaSegmentiParalleli(line2){if(!this.isparallela(line2))return 1e9;const{p1:p1,normale:normale}=this,dx=line2.p1.x-p1.x,dy=line2.p1.y-p1.y,distanza=Math.abs(dx*normale.x+dy*normale.y);return Math.abs(distanza)<.001?0:distanza}isCollineare(line2,checkpunticomune=!1){if(!this.isparallela(line2))return!1;const distanza=this.distanzaSegmentiParalleli(line2);if(Math.abs(distanza)>.001)return!1;if(checkpunticomune){const isPointBetween=(p,a,b)=>Math.min(a.x,b.x)<=p.x&&p.x<=Math.max(a.x,b.x)&&Math.min(a.y,b.y)<=p.y&&p.y<=Math.max(a.y,b.y),{p1:p1,p2:p2}=this,{p1:p1_2,p2:p2_2}=line2;return isPointBetween(p1_2,p1,p2)||isPointBetween(p2_2,p1,p2)||isPointBetween(p1,p1_2,p2_2)||isPointBetween(p2,p1_2,p2_2)}return!0}}function getptsoffset(pt,pt2,delta){let k1,k2,a1,a2,i1=-1,i2=-1,n=pt.length,np=pt2.length,offpt=[],l1a=new Linea2(pt[0],pt[1]),l2a=new Linea2(pt[n-2],pt[n-1]),l1=l1a.offset(delta),l2=l2a.offset(delta);for(var i=0;i<np;i++){let l=new Linea2(pt2[i%np],pt2[(i+1)%np]);l1.isparallela(l)&&l1.isCollineare(l,!0)&&(i1=i),l2.isparallela(l)&&l2.isCollineare(l,!0)&&(i2=i)}if(i1>=0&&i2>=0){i1>i2?(k1=i1-i2+2,k2=i2+np-i1+2,k1<k2?(a1=i2,a2=i1+1):(a1=i1,a2=i2+np+1)):(k1=i2-i1+2,k2=i1+np-i2+2,k1<k2?(a1=i1,a2=i2+1):(a1=i2,a2=i1+np+1));for(let i=a1;i<=a2;i++)offpt.push(pt2[i%np])}return offpt}function hash(obj){let str="";if("string"==typeof obj||"number"==typeof obj)str=obj+"";else if("object"==typeof obj&&obj){const chiaviOrdinati=Object.keys(obj).sort(),separatore="\0";str=chiaviOrdinati.map((key=>`${key}${separatore}${String(obj[key])}`)).join(separatore)}let h1=2166136261,h2=2218511855;for(let i=0;i<str.length;i++){const char=str.charCodeAt(i);h1^=char,h1+=h1<<5^2779096485,h2^=h1,h2=((h2<<3)+char^2134516169)>>>0}return h1>>>=0,h1.toString(16)+h2.toString(16)}function clamp(n,min=-1/0,max=1/0){return(n=Number(n)||0)<min&&(n=min),n>max&&(n=max),n}function getSqSegDist(p,p1,p2){var x=p1.x,y=p1.y,dx=p2.x-x,dy=p2.y-y;if(0!==dx||0!==dy){var t=((p.x-x)*dx+(p.y-y)*dy)/(dx*dx+dy*dy);t>1?(x=p2.x,y=p2.y):t>0&&(x+=dx*t,y+=dy*t)}return(dx=p.x-x)*dx+(dy=p.y-y)*dy}function simplifyDPStep(points,first,last,sqTolerance,simplified){for(var index,maxSqDist=sqTolerance,i=first+1;i<last;i++){var sqDist=getSqSegDist(points[i],points[first],points[last]);sqDist>maxSqDist&&(index=i,maxSqDist=sqDist)}maxSqDist>sqTolerance&&(index-first>1&&simplifyDPStep(points,first,index,sqTolerance,simplified),simplified.push(points[index]),last-index>1&&simplifyDPStep(points,index,last,sqTolerance,simplified))}function simplifyDouglasPeucker(points,sqTolerance){var last=points.length-1,simplified=[points[0]];return simplifyDPStep(points,0,last,sqTolerance,simplified),simplified.push(points[last]),simplified}new class Errori{constructor(){this.azzera()}azzera(){this.err=[]}add(msg,row){this.err.push({msg:msg,row:row})}get(){return this.err}get length(){return this.err.length}toString(){var cl=[];for(var e of this.err){let m="object"==typeof e.msg?JSON.stringify(e.msg):e.msg||"";cl.push(`${e.row?e.row+":":""}${m}`)}return cl.join("\n")}},Date.prototype.toInt||(Date.prototype.toInt=function(){return this.getDate()+100*(this.getMonth()+1)+1e4*this.getFullYear()}),Date.prototype.toFloat||(Date.prototype.toFloat=function(){return Math.floor(1e4*this.getDate()+1e6*(this.getMonth()+1)+1e8*this.getFullYear()+100*this.getHours()+this.getMinutes()+.5)/1e4});const PIF=Math.PI/180;function raccordabezier(a1,a2,b1,b2,subdivisions=10){const intersection=function getIntersection(p1,p2,p3,p4){const denom=(p1.x-p2.x)*(p3.y-p4.y)-(p1.y-p2.y)*(p3.x-p4.x);return 0===denom?null:{x:((p1.x*p2.y-p1.y*p2.x)*(p3.x-p4.x)-(p1.x-p2.x)*(p3.x*p4.y-p3.y*p4.x))/denom,y:((p1.x*p2.y-p1.y*p2.x)*(p3.y-p4.y)-(p1.y-p2.y)*(p3.x*p4.y-p3.y*p4.x))/denom}}(a1,a2,b1,b2);if(!intersection)return[{x:a2.x,y:a2.y},{x:b1.x,y:b1.y}];const control=intersection;if(0===subdivisions)return[{x:a2.x,y:a2.y},{x:b1.x,y:b1.y}];const curvePoints=[];for(let i=0;i<=subdivisions;i++){const t=i/subdivisions,oneMinusT=1-t,x=oneMinusT*oneMinusT*a2.x+2*oneMinusT*t*control.x+t*t*b1.x,y=oneMinusT*oneMinusT*a2.y+2*oneMinusT*t*control.y+t*t*b1.y;curvePoints.push({x:x,y:y})}return curvePoints}function raccordabezier3(a1,a2,a3,d,subdivisions=10){const v1_x=a2.x-a1.x,v1_y=a2.y-a1.y,v2_x=a3.x-a2.x,v2_y=a3.y-a2.y,len1=Math.sqrt(v1_x*v1_x+v1_y*v1_y),len2=Math.sqrt(v2_x*v2_x+v2_y*v2_y);if(d>len1||d>len2)return[a1,a2,a3];d!=len1&&d!=len2||(d-=.01);const t1=(len1-d)/len1,t2=d/len2;return raccordabezier(a1,{x:a1.x+v1_x*t1,y:a1.y+v1_y*t1},{x:a2.x+v2_x*t2,y:a2.y+v2_y*t2},a3,subdivisions)}function normal2(p1,p2){const dx=p2.x-p1.x;let nx=-(p2.y-p1.y),ny=dx;const length=Math.sqrt(nx*nx+ny*ny);return 0===length?{nx:0,ny:0}:{nx:nx/length,ny:ny/length}}function angle3point(p1,p2,p3){const u_x=p2.x-p1.x,u_y=p2.y-p1.y,v_x=p3.x-p2.x,v_y=p3.y-p2.y,dot=u_x*v_x+u_y*v_y,cross=u_x*v_y-u_y*v_x,magU=Math.sqrt(u_x**2+u_y**2),magV=Math.sqrt(v_x**2+v_y**2);return magU&&magV?Math.atan2(cross,dot):0}function angle2vec(v1,v2){const dot=v1.x*v2.x+v1.y*v2.y,mag1=Math.sqrt(v1.x*v1.x+v1.y*v1.y),mag2=Math.sqrt(v2.x*v2.x+v2.y*v2.y);if(0===mag1||0===mag2)return 0;let cosTheta=dot/(mag1*mag2);cosTheta=Math.max(-1,Math.min(1,cosTheta));return Math.acos(cosTheta)/PIF}function removeduplicate(path,delta=.005){if(!Array.isArray(path)||0===path.length)return[];const deltaSq=delta*delta,cleanedPath=[],n=path.length;for(let i=0;i<n;i++){const current=path[i],next=path[(i+1)%n];cleanedPath.push({x:current.x,y:current.y});const dx=next.x-current.x,dy=next.y-current.y;dx*dx+dy*dy<=deltaSq&&i++}if(cleanedPath.length>1){const first=cleanedPath[0],last=cleanedPath[cleanedPath.length-1],dx=first.x-last.x,dy=first.y-last.y;dx*dx+dy*dy<=deltaSq&&cleanedPath.pop()}return cleanedPath}function getshape(){let pt=[];function orientation(){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.x*next.y-next.x*current.y}return area>0?1:area<0?-1:0}function tovec(){let vv=[];for(let p of pt)vv.push(p.x),vv.push(p.y);return vv}function _addvec(aa){for(let i=0;i<aa.length;i+=2)pt.push({x:aa[i],y:aa[i+1]})}function dims(pts){let{p1:p1,p2:p2}=pts.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}),isrect=!1;if(4==pts.length){const TOLL=.001;function findpunto(x,y){return!!pts.find((p=>Math.abs(p.x-x)<TOLL&&Math.abs(p.y-y)<TOLL))}findpunto(p1.x,p1.y)&&findpunto(p1.x,p2.y)&&findpunto(p2.x,p1.y)&&findpunto(p2.x,p2.y)&&(isrect=!0)}return{p1:p1,p2:p2,isrect:isrect,width:p2.x-p1.x,height:p2.y-p1.y}}return{get key(){return hash(tovec().join("\t"))},orienta:function orienta(p0,p1){if(!p0||!p1)return null;const dx=p1.x-p0.x,dy=p1.y-p0.y,angolo=180*Math.atan2(dy,dx)/Math.PI,matrix=new Matrix3D;matrix.rotateZ(-angolo),matrix.translate(-p0.x,-p0.y,0);const ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y)));let mm=ptTrasformati.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)});return{shape:getshape().frompt(ptTrasformati),origine:new Punto2(p0.x,p0.y),angolo:angolo,mm:mm,width:mm.p2.x-mm.p1.x,height:mm.p2.y-mm.p1.y}},rebase:function rebase(angolo,forceorigin=!1,ox=0,oy=0){const matrix=new Matrix3D;matrix.rotateZ(-angolo);let ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y))),{p1:p1,p2:p2,width:width,height:height}=dims(ptTrasformati);return forceorigin||(ox=p1.x,oy=p1.y),ptTrasformati=ptTrasformati.map((p=>new Punto2(p.x-ox,p.y-oy))),{shape:getshape().frompt(ptTrasformati),origine:new Punto2(ox,oy),angolo:angolo,width:width,height:height}},get pt(){return pt},get vec(){return tovec()},toJSON:()=>({vec:tovec(),orient:orientation()}),get orient(){return orientation()},clone:()=>getshape().frompt(pt),dims:()=>dims(pt),rotate(deg){if(!deg)return this;const r=deg*Math.PI/180,cosTheta=Math.cos(r),sinTheta=Math.sin(r);for(let p of pt){const xNew=p.x*cosTheta-p.y*sinTheta,yNew=p.x*sinTheta+p.y*cosTheta;p.x=xNew,p.y=yNew}return this},selezionaprimo:function selezionaprimo(idprimopunto){return(idprimopunto%=pt.length)>0&&(pt=[...pt.slice(idprimopunto),...pt.slice(0,idprimopunto)]),this},segment(i,inverse=!1){let n=pt.length;return new Linea2(pt[i%n],pt[(i+(inverse?-1:1))%n])},lineoffset(i1,i2,offset){if((i1=(i1||0)%pt.length)!=(i2=(i2||0)%pt.length)){let l2=new Linea2(pt[i1],pt[i2]);if(l2){return l2=l2.offsetline(-offset),this.intersectline(l2)}}},move(x=0,y=0){for(let p of pt)p.x+=x,p.y+=y;return this},mirrorx(value=0){for(let p of pt)p.x=2*value-p.x;return this},mirrory(value=0){for(let p of pt)p.y=2*value-p.y;return this},simplify(tolerance,hq){return pt=function simplify(points,tolerance,highestQuality){if(points.length<=2)return points;var sqTolerance=void 0!==tolerance?tolerance*tolerance:1;return simplifyDouglasPeucker(points=highestQuality?points:function simplifyRadialDist(points,sqTolerance){for(var point,p1,p2,dx,dy,prevPoint=points[0],newPoints=[prevPoint],i=1,len=points.length;i<len;i++)p2=prevPoint,dx=void 0,dy=void 0,(dx=(p1=point=points[i]).x-p2.x)*dx+(dy=p1.y-p2.y)*dy>sqTolerance&&(newPoints.push(point),prevPoint=point);return prevPoint!==point&&newPoints.push(point),newPoints}(points,sqTolerance),sqTolerance)}(pt,tolerance,hq),this},fromclip(vv){pt=[];for(let p of vv)pt.push({x:p.x/1e3,y:p.y/1e3});return this},infosegmento(i,open=!1){const n=pt.length;function clampIndex(idx){return(idx+n)%n}function angle(p1,p2){return Math.atan2(p2.y-p1.y,p2.x-p1.x)}function angleDiff(a,b){let diff=a-b;for(;diff>Math.PI;)diff-=2*Math.PI;for(;diff<-Math.PI;)diff+=2*Math.PI;return diff}const p1=pt[i];let p0,p2,p3;if(open)if(0===i){const dx=pt[1].x-pt[0].x,dy=pt[1].y-pt[0].y;p0={x:pt[0].x-dx,y:pt[0].y-dy},p2=pt[1],p3=pt[2]}else if(i===n-1){const dx=pt[n-1].x-pt[n-2].x,dy=pt[n-1].y-pt[n-2].y;p0=pt[n-2],p2={x:pt[n-1].x+dx,y:pt[n-1].y+dy},p3={x:p2.x+dx,y:p2.y+dy}}else p0=pt[i-1],p2=pt[i+1],p3=i+2<n?pt[i+2]:{x:pt[i+1].x+(pt[i+1].x-pt[i].x),y:pt[i+1].y+(pt[i+1].y-pt[i].y)};else{const i0=clampIndex(i-1),i2=clampIndex(i+1),i3=clampIndex(i+2);p0=pt[i0],p2=pt[i2],p3=pt[i3]}const ang12=angle(p1,p2),ang01=angle(p0,p1),ang23=angle(p2,p3);return{x:p1.x,y:p1.y,l:function length(p1,p2){const dx=p2.x-p1.x,dy=p2.y-p1.y;return Math.sqrt(dx*dx+dy*dy)}(p1,p2),ang:ang12/PIF,a1:angleDiff(ang12,ang01)/PIF,a2:angleDiff(ang23,ang12)/PIF}},fromvec(aa){return pt=[],_addvec(aa),this},addvec(vec){return _addvec(vec),this},frompt(pts){return pt=[...pts],pt=removeduplicate(pt),this},fromstr(str){return pt=removeduplicate(function processTokens(tokens){const points=[];for(let i=0;i<tokens.length;i++){const token=tokens[i];if("point"===token.type)points.push(token.point);else if("command"===token.type)switch(token.cmd){case"b":{if(points.length<2)continue;const npt=parseInt(token.params[0])||5,p1=points[points.length-2],p2=points[points.length-1];let p3="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p4="point"===tokens[i+2]?.type?tokens[i+2].point:void 0;p3?p4||(p4=points[0]):(p3=points[0],p4=points[1]);const raccordo=raccordabezier(p1,p2,p3,p4,npt);points.push(...raccordo),i+=1;break}case"r":{if(points.length<1)continue;const dist=parseFloat(token.params[0])||5,npt=parseInt(token.params[1])||10,p1=points[points.length-1];let p2="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p3="point"===tokens[i+2]?.type?tokens[i+2].point:"point"===tokens[i+3]?.type?tokens[i+3].point:void 0;p2?p3||(p3=points[0]):(p2=points[0],p3=points[1],points.splice(0,1));const raccordo=raccordabezier3(p1,p2,p3,dist,npt);points.push(...raccordo),i+=1;break}case"c":{const radius=parseFloat(token.params[0])||50,segments=parseInt(token.params[1])||12,center="point"===tokens[i+1]?.type?tokens[i+1].point:new Punto2(0,0);for(let j=0;j<segments;j++)points.push(new Punto2(center.x+radius*Math.cos(j/segments*Math.PI*2),center.y+radius*Math.sin(j/segments*Math.PI*2)));i+=1;break}case"a":{let npt,p1="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p2="point"===tokens[i+2]?.type?tokens[i+2].point:void 0,p3="point"===tokens[i+3]?.type?tokens[i+3].point:void 0;if(!p1||!p3)continue;if(p2)if(token.params[0])npt=clamp(parseInt(token.params[0]),1,24);else{const chord=Math.hypot(p3.x-p1.x,p3.y-p1.y),sagitta=Math.abs((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))/(2*chord);npt=Math.round(chord*Math.sqrt(sagitta/(chord+.1))*10),npt=clamp(npt,1,24),npt=1}else p2=p3,npt=0;const arcoPoints=arcfrom3point(npt,p1,p2,p3);points.push(...arcoPoints),i+=3;break}}}return points}(function tokenize(str){const tokens=[],values=str.toLowerCase().replace(/[\n\s]+/gm," ").split(/[\,\;]/).map((s=>s.trim()));for(let i=0;i<values.length;){const current=values[i];["b","r","c","a"].includes(current[0])?(tokens.push({type:"command",cmd:current[0],params:current.slice(1).split(":")}),i++):/[a-zA-Z]/.test(current[0])||(i<values.length-1?(tokens.push({type:"point",point:new Punto2(parseFloat(values[i]),parseFloat(values[i+1]))}),i+=2):i++)}return tokens}(str))),this},intersectline:l=>function _intersectline(shape,p3,p4){let n=shape.length,l=new Linea2(p3,p4);const intersezioni=[];for(let i=0;i<shape.length;i++){let l2=new Linea2(shape[i],shape[(i+1)%n]),p=l2.intersezione(l);p&&l2.onsegment(p)&&intersezioni.push(p)}if(intersezioni.length<2)return null;const{dx:dx,dy:dy}=l;intersezioni.sort(((a,b)=>(a.x-p3.x)*dx+(a.y-p3.y)*dy-((b.x-p3.x)*dx+(b.y-p3.y)*dy)));let pstart=new Punto2(intersezioni[0].x,intersezioni[0].y),pend=new Punto2(intersezioni[intersezioni.length-1].x,intersezioni[intersezioni.length-1].y);const vx1=pend.x-pstart.x,vy1=pend.y-pstart.y;return vx1*dx+vy1*dy<0&&([pstart,pend]=[pend,pstart]),new Linea2(pstart,pend)}(pt,l.p1,l.p2),addpt(pts){return pts?(Array.isArray(pts)||(pts=[pts]),pt=removeduplicate([...pt,...pts]),this):this},addracc(v1,v2,suddivisioni=2,addv1v2=!0){if(Array.isArray(v1)&&(v2={x:v1[2]||0,y:v1[3]||0},v1={x:v1[0]||0,y:v1[1]||0}),pt.length>=2){let tm=raccordabezier(pt[pt.length-2],pt[pt.length-1],v1,v2,suddivisioni);pt=[...pt,...tm],addv1v2&&(pt.push(v1),pt.push(v2))}return pt=removeduplicate(pt),this},setorient(mode){let p=orientation();return(1==p&&-1==mode||-1==p&&1==mode)&&pt.reverse(),this},reverse(){return pt.reverse(),this},pointinshape:p=>function isPointInPolygon(P){let x=P.x,y=P.y,inside=!1;for(let i=0,j=pt.length-1;i<pt.length;j=i++){let xi=pt[i].x,yi=pt[i].y,xj=pt[j].x,yj=pt[j].y;yi>y!=yj>y&&x<(xj-xi)*(y-yi)/(yj-yi)+xi&&(inside=!inside)}return inside}(p),azzera(){return pt=[],this},removeduplicate(delta=.005){return pt=removeduplicate(pt,delta),this},to3d(u0,alt=0,coeffa=0,coeffb=0,open=!1){pt=removeduplicate(pt);let tm=function genuvnormal(path,options){let{currentU:currentU=0,c:c=0,a:a=0,b:b=0,anglemin:anglemin=30,open:open=!1}=options;const pointsWithNormals=[],n=path.length;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],current=path[i],next=path[(i+1)%n],vPrev={x:current.x-prev.x,y:current.y-prev.y},vNext={x:next.x-current.x,y:next.y-current.y},normalPrev=normal2(prev,current),normalNext=normal2(current,next),angle=angle2vec(vPrev,vNext);let z=a*current.x+b*current.y+c;Math.abs(angle-180)<=anglemin?(normalPrev.nx,normalNext.nx,normalPrev.ny,normalNext.ny,pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z})):(pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}),pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}));const dx=next.x-current.x,dy=next.y-current.y;currentU+=Math.sqrt(dx*dx+dy*dy)}if(!open){let p=pointsWithNormals[0],pf=pointsWithNormals[pointsWithNormals.length-1];p.x==pf.x&&p.y==pf.y||pointsWithNormals.push({x:p.x,y:p.y,z:p.z,nx:p.nx,ny:p.ny,nz:p.nz,u:currentU,v:p.z})}return pointsWithNormals}(pt,{open:open,currentU:u0,c:alt,a:coeffa,b:coeffb,anglemin:30});return tm},getboundbox:()=>pt.length?pt.reduce(((box,p)=>(box.p1.x=Math.min(box.p1.x,p.x),box.p1.y=Math.min(box.p1.y,p.y),box.p2.x=Math.max(box.p2.x,p.x),box.p2.y=Math.max(box.p2.y,p.y),box)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}):{p1:new Punto2(0,0),p2:new Punto2(0,0)},fittobox(p1,p2){if(!pt.length)return this;const currentBox=this.getboundbox(),currentWidth=currentBox.p2.x-currentBox.p1.x,currentHeight=currentBox.p2.y-currentBox.p1.y,targetWidth=p2.x-p1.x,targetHeight=p2.y-p1.y,scale=Math.min(targetWidth/(currentWidth||1),targetHeight/(currentHeight||1));for(let p of pt)p.x=(p.x-currentBox.p1.x)*scale,p.y=(p.y-currentBox.p1.y)*scale,p.x+=p1.x,p.y+=p1.y;return this}}}function arcfrom3point(segments,p1,p2,p3){if(segments<=0)return[p1,p3];if(1===segments)return[p1,p2,p3];const center=function findCircleCenter(p1,p2,p3){const temp=p2.x*p2.x+p2.y*p2.y,bc=(p1.x*p1.x+p1.y*p1.y-temp)/2,cd=(temp-p3.x*p3.x-p3.y*p3.y)/2,det=(p1.x-p2.x)*(p2.y-p3.y)-(p2.x-p3.x)*(p1.y-p2.y);return Math.abs(det)<1e-10?null:new Punto2((bc*(p2.y-p3.y)-cd*(p1.y-p2.y))/det,((p1.x-p2.x)*cd-(p2.x-p3.x)*bc)/det)}(p1,p2,p3);if(!center){const points=[];for(let i=0;i<segments+1;i++){const t=i/segments;points.push(new Punto2(p1.x+(p3.x-p1.x)*t,p1.y+(p3.y-p1.y)*t))}return points}let normalizeAngle=angle=>(angle+2*Math.PI)%(2*Math.PI),start=normalizeAngle(Math.atan2(p1.y-center.y,p1.x-center.x)),mid=normalizeAngle(Math.atan2(p2.y-center.y,p2.x-center.x)),end=normalizeAngle(Math.atan2(p3.y-center.y,p3.x-center.x));mid>start&&(mid-=2*Math.PI),end>mid&&(end-=2*Math.PI);const delta=(end-start)/segments,radius=Math.hypot(p1.x-center.x,p1.y-center.y),points=[];for(let i=0;i<=segments;i++){const angle=start+delta*i;points.push(new Punto2(center.x+radius*Math.cos(angle),center.y+radius*Math.sin(angle)))}return points}function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x.default:x}var module,clipper={exports:{}};module=clipper,function(){var navigator_appName,ClipperLib={version:"6.4.2.2",use_lines:!0,use_xyz:!1},isNode=!1;if(module.exports?(module.exports=ClipperLib,isNode=!0):"undefined"!=typeof document?window.ClipperLib=ClipperLib:self.ClipperLib=ClipperLib,isNode)nav="chrome",navigator_appName="Netscape";else{var nav=navigator.userAgent.toString().toLowerCase();navigator_appName=navigator.appName}var dbits,browser={};function BigInteger(a,b,c){ClipperLib.biginteger_used=1,null!=a&&("number"==typeof a&&void 0===b?this.fromInt(a):"number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function nbi(){return new BigInteger(null,void 0,void 0)}-1!=nav.indexOf("chrome")&&-1==nav.indexOf("chromium")?browser.chrome=1:browser.chrome=0,-1!=nav.indexOf("chromium")?browser.chromium=1:browser.chromium=0,-1!=nav.indexOf("safari")&&-1==nav.indexOf("chrome")&&-1==nav.indexOf("chromium")?browser.safari=1:browser.safari=0,-1!=nav.indexOf("firefox")?browser.firefox=1:browser.firefox=0,-1!=nav.indexOf("firefox/17")?browser.firefox17=1:browser.firefox17=0,-1!=nav.indexOf("firefox/15")?browser.firefox15=1:browser.firefox15=0,-1!=nav.indexOf("firefox/3")?browser.firefox3=1:browser.firefox3=0,-1!=nav.indexOf("opera")?browser.opera=1:browser.opera=0,-1!=nav.indexOf("msie 10")?browser.msie10=1:browser.msie10=0,-1!=nav.indexOf("msie 9")?browser.msie9=1:browser.msie9=0,-1!=nav.indexOf("msie 8")?browser.msie8=1:browser.msie8=0,-1!=nav.indexOf("msie 7")?browser.msie7=1:browser.msie7=0,-1!=nav.indexOf("msie ")?browser.msie=1:browser.msie=0,ClipperLib.biginteger_used=null,"Microsoft Internet Explorer"==navigator_appName?(BigInteger.prototype.am=function am2(i,x,w,j,c,n){for(var xl=32767&x,xh=x>>15;--n>=0;){var l=32767&this[i],h=this[i++]>>15,m=xh*l+h*xl;c=((l=xl*l+((32767&m)<<15)+w[j]+(1073741823&c))>>>30)+(m>>>15)+xh*h+(c>>>30),w[j++]=1073741823&l}return c},dbits=30):"Netscape"!=navigator_appName?(BigInteger.prototype.am=function am1(i,x,w,j,c,n){for(;--n>=0;){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864),w[j++]=67108863&v}return c},dbits=26):(BigInteger.prototype.am=function am3(i,x,w,j,c,n){for(var xl=16383&x,xh=x>>14;--n>=0;){var l=16383&this[i],h=this[i++]>>14,m=xh*l+h*xl;c=((l=xl*l+((16383&m)<<14)+w[j]+c)>>28)+(m>>14)+xh*h,w[j++]=268435455&l}return c},dbits=28),BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1,BigInteger.prototype.DV=1<<dbits,BigInteger.prototype.FV=Math.pow(2,52),BigInteger.prototype.F1=52-dbits,BigInteger.prototype.F2=2*dbits-52;var rr,vv,BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(n){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(n)}function intAt(s,i){var c=BI_RC[s.charCodeAt(i)];return null==c?-1:c}function nbv(i){var r=nbi();return r.fromInt(i),r}function nbits(x){var t,r=1;return 0!=(t=x>>>16)&&(x=t,r+=16),0!=(t=x>>8)&&(x=t,r+=8),0!=(t=x>>4)&&(x=t,r+=4),0!=(t=x>>2)&&(x=t,r+=2),0!=(t=x>>1)&&(x=t,r+=1),r}function Classic(m){this.m=m}function Montgomery(m){this.m=m,this.mp=m.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<m.DB-15)-1,this.mt2=2*m.t}function op_and(x,y){return x&y}function op_or(x,y){return x|y}function op_xor(x,y){return x^y}function op_andnot(x,y){return x&~y}function lbit(x){if(0==x)return-1;var r=0;return 65535&x||(x>>=16,r+=16),255&x||(x>>=8,r+=8),15&x||(x>>=4,r+=4),3&x||(x>>=2,r+=2),1&x||++r,r}function cbit(x){for(var r=0;0!=x;)x&=x-1,++r;return r}function NullExp(){}function nNop(x){return x}function Barrett(m){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*m.t,this.r2),this.mu=this.r2.divide(m),this.m=m}Classic.prototype.convert=function cConvert(x){return x.s<0||x.compareTo(this.m)>=0?x.mod(this.m):x},Classic.prototype.revert=function cRevert(x){return x},Classic.prototype.reduce=function cReduce(x){x.divRemTo(this.m,null,x)},Classic.prototype.mulTo=function cMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Classic.prototype.sqrTo=function cSqrTo(x,r){x.squareTo(r),this.reduce(r)},Montgomery.prototype.convert=function montConvert(x){var r=nbi();return x.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),x.s<0&&r.compareTo(BigInteger.ZERO)>0&&this.m.subTo(r,r),r},Montgomery.prototype.revert=function montRevert(x){var r=nbi();return x.copyTo(r),this.reduce(r),r},Montgomery.prototype.reduce=function montReduce(x){for(;x.t<=this.mt2;)x[x.t++]=0;for(var i=0;i<this.m.t;++i){var j=32767&x[i],u0=j*this.mpl+((j*this.mph+(x[i]>>15)*this.mpl&this.um)<<15)&x.DM;for(x[j=i+this.m.t]+=this.m.am(0,u0,x,i,0,this.m.t);x[j]>=x.DV;)x[j]-=x.DV,x[++j]++}x.clamp(),x.drShiftTo(this.m.t,x),x.compareTo(this.m)>=0&&x.subTo(this.m,x)},Montgomery.prototype.mulTo=function montMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Montgomery.prototype.sqrTo=function montSqrTo(x,r){x.squareTo(r),this.reduce(r)},BigInteger.prototype.copyTo=function bnpCopyTo(r){for(var i=this.t-1;i>=0;--i)r[i]=this[i];r.t=this.t,r.s=this.s},BigInteger.prototype.fromInt=function bnpFromInt(x){this.t=1,this.s=x<0?-1:0,x>0?this[0]=x:x<-1?this[0]=x+this.DV:this.t=0},BigInteger.prototype.fromString=function bnpFromString(s,b){var k;if(16==b)k=4;else if(8==b)k=3;else if(256==b)k=8;else if(2==b)k=1;else if(32==b)k=5;else{if(4!=b)return void this.fromRadix(s,b);k=2}this.t=0,this.s=0;for(var i=s.length,mi=!1,sh=0;--i>=0;){var x=8==k?255&s[i]:intAt(s,i);x<0?"-"==s.charAt(i)&&(mi=!0):(mi=!1,0==sh?this[this.t++]=x:sh+k>this.DB?(this[this.t-1]|=(x&(1<<this.DB-sh)-1)<<sh,this[this.t++]=x>>this.DB-sh):this[this.t-1]|=x<<sh,(sh+=k)>=this.DB&&(sh-=this.DB))}8==k&&128&s[0]&&(this.s=-1,sh>0&&(this[this.t-1]|=(1<<this.DB-sh)-1<<sh)),this.clamp(),mi&&BigInteger.ZERO.subTo(this,this)},BigInteger.prototype.clamp=function bnpClamp(){for(var c=this.s&this.DM;this.t>0&&this[this.t-1]==c;)--this.t},BigInteger.prototype.dlShiftTo=function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n,r.s=this.s},BigInteger.prototype.drShiftTo=function bnpDRShiftTo(n,r){for(var i=n;i<this.t;++i)r[i-n]=this[i];r.t=Math.max(this.t-n,0),r.s=this.s},BigInteger.prototype.lShiftTo=function bnpLShiftTo(n,r){var i,bs=n%this.DB,cbs=this.DB-bs,bm=(1<<cbs)-1,ds=Math.floor(n/this.DB),c=this.s<<bs&this.DM;for(i=this.t-1;i>=0;--i)r[i+ds+1]=this[i]>>cbs|c,c=(this[i]&bm)<<bs;for(i=ds-1;i>=0;--i)r[i]=0;r[ds]=c,r.t=this.t+ds+1,r.s=this.s,r.clamp()},BigInteger.prototype.rShiftTo=function bnpRShiftTo(n,r){r.s=this.s;var ds=Math.floor(n/this.DB);if(ds>=this.t)r.t=0;else{var bs=n%this.DB,cbs=this.DB-bs,bm=(1<<bs)-1;r[0]=this[ds]>>bs;for(var i=ds+1;i<this.t;++i)r[i-ds-1]|=(this[i]&bm)<<cbs,r[i-ds]=this[i]>>bs;bs>0&&(r[this.t-ds-1]|=(this.s&bm)<<cbs),r.t=this.t-ds,r.clamp()}},BigInteger.prototype.subTo=function bnpSubTo(a,r){for(var i=0,c=0,m=Math.min(a.t,this.t);i<m;)c+=this[i]-a[i],r[i++]=c&this.DM,c>>=this.DB;if(a.t<this.t){for(c-=a.s;i<this.t;)c+=this[i],r[i++]=c&this.DM,c>>=this.DB;c+=this.s}else{for(c+=this.s;i<a.t;)c-=a[i],r[i++]=c&this.DM,c>>=this.DB;c-=a.s}r.s=c<0?-1:0,c<-1?r[i++]=this.DV+c:c>0&&(r[i++]=c),r.t=i,r.clamp()},BigInteger.prototype.multiplyTo=function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs(),i=x.t;for(r.t=i+y.t;--i>=0;)r[i]=0;for(i=0;i<y.t;++i)r[i+x.t]=x.am(0,y[i],r,i,0,x.t);r.s=0,r.clamp(),this.s!=a.s&&BigInteger.ZERO.subTo(r,r)},BigInteger.prototype.squareTo=function bnpSquareTo(r){for(var x=this.abs(),i=r.t=2*x.t;--i>=0;)r[i]=0;for(i=0;i<x.t-1;++i){var c=x.am(i,x[i],r,2*i,0,1);(r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1))>=x.DV&&(r[i+x.t]-=x.DV,r[i+x.t+1]=1)}r.t>0&&(r[r.t-1]+=x.am(i,x[i],r,2*i,0,1)),r.s=0,r.clamp()},BigInteger.prototype.divRemTo=function bnpDivRemTo(m,q,r){var pm=m.abs();if(!(pm.t<=0)){var pt=this.abs();if(pt.t<pm.t)return null!=q&&q.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=nbi());var y=nbi(),ts=this.s,ms=m.s,nsh=this.DB-nbits(pm[pm.t-1]);nsh>0?(pm.lShiftTo(nsh,y),pt.lShiftTo(nsh,r)):(pm.copyTo(y),pt.copyTo(r));var ys=y.t,y0=y[ys-1];if(0!=y0){var yt=y0*(1<<this.F1)+(ys>1?y[ys-2]>>this.F2:0),d1=this.FV/yt,d2=(1<<this.F1)/yt,e=1<<this.F2,i=r.t,j=i-ys,t=null==q?nbi():q;for(y.dlShiftTo(j,t),r.compareTo(t)>=0&&(r[r.t++]=1,r.subTo(t,r)),BigInteger.ONE.dlShiftTo(ys,t),t.subTo(y,y);y.t<ys;)y[y.t++]=0;for(;--j>=0;){var qd=r[--i]==y0?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))<qd)for(y.dlShiftTo(j,t),r.subTo(t,r);r[i]<--qd;)r.subTo(t,r)}null!=q&&(r.drShiftTo(ys,q),ts!=ms&&BigInteger.ZERO.subTo(q,q)),r.t=ys,r.clamp(),nsh>0&&r.rShiftTo(nsh,r),ts<0&&BigInteger.ZERO.subTo(r,r)}}},BigInteger.prototype.invDigit=function bnpInvDigit(){if(this.t<1)return 0;var x=this[0];if(!(1&x))return 0;var y=3&x;return(y=(y=(y=(y=y*(2-(15&x)*y)&15)*(2-(255&x)*y)&255)*(2-((65535&x)*y&65535))&65535)*(2-x*y%this.DV)%this.DV)>0?this.DV-y:-y},BigInteger.prototype.isEven=function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)},BigInteger.prototype.exp=function bnpExp(e,z){if(e>4294967295||e<1)return BigInteger.ONE;var r=nbi(),r2=nbi(),g=z.convert(this),i=nbits(e)-1;for(g.copyTo(r);--i>=0;)if(z.sqrTo(r,r2),(e&1<<i)>0)z.mulTo(r2,g,r);else{var t=r;r=r2,r2=t}return z.revert(r)},BigInteger.prototype.toString=function bnToString(b){if(this.s<0)return"-"+this.negate().toString(b);var k;if(16==b)k=4;else if(8==b)k=3;else if(2==b)k=1;else if(32==b)k=5;else{if(4!=b)return this.toRadix(b);k=2}var d,km=(1<<k)-1,m=!1,r="",i=this.t,p=this.DB-i*this.DB%k;if(i-- >0)for(p<this.DB&&(d=this[i]>>p)>0&&(m=!0,r=int2char(d));i>=0;)p<k?(d=(this[i]&(1<<p)-1)<<k-p,d|=this[--i]>>(p+=this.DB-k)):(d=this[i]>>(p-=k)&km,p<=0&&(p+=this.DB,--i)),d>0&&(m=!0),m&&(r+=int2char(d));return m?r:"0"},BigInteger.prototype.negate=function bnNegate(){var r=nbi();return BigInteger.ZERO.subTo(this,r),r},BigInteger.prototype.abs=function bnAbs(){return this.s<0?this.negate():this},BigInteger.prototype.compareTo=function bnCompareTo(a){var r=this.s-a.s;if(0!=r)return r;var i=this.t;if(0!=(r=i-a.t))return this.s<0?-r:r;for(;--i>=0;)if(0!=(r=this[i]-a[i]))return r;return 0},BigInteger.prototype.bitLength=function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)},BigInteger.prototype.mod=function bnMod(a){var r=nbi();return this.abs().divRemTo(a,null,r),this.s<0&&r.compareTo(BigInteger.ZERO)>0&&a.subTo(r,r),r},BigInteger.prototype.modPowInt=function bnModPowInt(e,m){var z;return z=e<256||m.isEven()?new Classic(m):new Montgomery(m),this.exp(e,z)},BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=function nMulTo(x,y,r){x.multiplyTo(y,r)},NullExp.prototype.sqrTo=function nSqrTo(x,r){x.squareTo(r)},Barrett.prototype.convert=function barrettConvert(x){if(x.s<0||x.t>2*this.m.t)return x.mod(this.m);if(x.compareTo(this.m)<0)return x;var r=nbi();return x.copyTo(r),this.reduce(r),r},Barrett.prototype.revert=function barrettRevert(x){return x},Barrett.prototype.reduce=function barrettReduce(x){for(x.drShiftTo(this.m.t-1,this.r2),x.t>this.m.t+1&&(x.t=this.m.t+1,x.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);x.compareTo(this.r2)<0;)x.dAddOffset(1,this.m.t+1);for(x.subTo(this.r2,x);x.compareTo(this.m)>=0;)x.subTo(this.m,x)},Barrett.prototype.mulTo=function barrettMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Barrett.prototype.sqrTo=function barrettSqrTo(x,r){x.squareTo(r),this.reduce(r)};var lowprimes=[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],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=function bnpChunkSize(r){return Math.floor(Math.LN2*this.DB/Math.log(r))},BigInteger.prototype.toRadix=function bnpToRadix(b){if(null==b&&(b=10),0==this.signum()||b<2||b>36)return"0";var cs=this.chunkSize(b),a=Math.pow(b,cs),d=nbv(a),y=nbi(),z=nbi(),r="";for(this.divRemTo(d,y,z);y.signum()>0;)r=(a+z.intValue()).toString(b).substr(1)+r,y.divRemTo(d,y,z);return z.intValue().toString(b)+r},BigInteger.prototype.fromRadix=function bnpFromRadix(s,b){this.fromInt(0),null==b&&(b=10);for(var cs=this.chunkSize(b),d=Math.pow(b,cs),mi=!1,j=0,w=0,i=0;i<s.length;++i){var x=intAt(s,i);x<0?"-"==s.charAt(i)&&0==this.signum()&&(mi=!0):(w=b*w+x,++j>=cs&&(this.dMultiply(d),this.dAddOffset(w,0),j=0,w=0))}j>0&&(this.dMultiply(Math.pow(b,j)),this.dAddOffset(w,0)),mi&&BigInteger.ZERO.subTo(this,this)},BigInteger.prototype.fromNumber=function bnpFromNumber(a,b,c){if("number"==typeof b)if(a<2)this.fromInt(1);else for(this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(BigInteger.ONE.shiftLeft(a-1),this);else{var x=new Array,t=7&a;x.length=1+(a>>3),b.nextBytes(x),t>0?x[0]&=(1<<t)-1:x[0]=0,this.fromString(x,256)}},BigInteger.prototype.bitwiseTo=function bnpBitwiseTo(a,op,r){var i,f,m=Math.min(a.t,this.t);for(i=0;i<m;++i)r[i]=op(this[i],a[i]);if(a.t<this.t){for(f=a.s&this.DM,i=m;i<this.t;++i)r[i]=op(this[i],f);r.t=this.t}else{for(f=this.s&this.DM,i=m;i<a.t;++i)r[i]=op(f,a[i]);r.t=a.t}r.s=op(this.s,a.s),r.clamp()},BigInteger.prototype.changeBit=function bnpChangeBit(n,op){var r=BigInteger.ONE.shiftLeft(n);return this.bitwiseTo(r,op,r),r},BigInteger.prototype.addTo=function bnpAddTo(a,r){for(var i=0,c=0,m=Math.min(a.t,this.t);i<m;)c+=this[i]+a[i],r[i++]=c&this.DM,c>>=this.DB;if(a.t<this.t){for(c+=a.s;i<this.t;)c+=this[i],r[i++]=c&this.DM,c>>=this.DB;c+=this.s}else{for(c+=this.s;i<a.t;)c+=a[i],r[i++]=c&this.DM,c>>=this.DB;c+=a.s}r.s=c<0?-1:0,c>0?r[i++]=c:c<-1&&(r[i++]=this.DV+c),r.t=i,r.clamp()},BigInteger.prototype.dMultiply=function bnpDMultiply(n){this[this.t]=this.am(0,n-1,this,0,0,this.t),++this.t,this.clamp()},BigInteger.prototype.dAddOffset=function bnpDAddOffset(n,w){if(0!=n){for(;this.t<=w;)this[this.t++]=0;for(this[w]+=n;this[w]>=this.DV;)this[w]-=this.DV,++w>=this.t&&(this[this.t++]=0),++this[w]}},BigInteger.prototype.multiplyLowerTo=function bnpMultiplyLowerTo(a,n,r){var j,i=Math.min(this.t+a.t,n);for(r.s=0,r.t=i;i>0;)r[--i]=0;for(j=r.t-this.t;i<j;++i)r[i+this.t]=this.am(0,a[i],r,i,0,this.t);for(j=Math.min(a.t,n);i<j;++i)this.am(0,a[i],r,i,0,n-i);r.clamp()},BigInteger.prototype.multiplyUpperTo=function bnpMultiplyUpperTo(a,n,r){--n;var i=r.t=this.t+a.t-n;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(n-this.t,0);i<a.t;++i)r[this.t+i-n]=this.am(n-i,a[i],r,0,0,this.t+i-n);r.clamp(),r.drShiftTo(1,r)},BigInteger.prototype.modInt=function bnpModInt(n){if(n<=0)return 0;var d=this.DV%n,r=this.s<0?n-1:0;if(this.t>0)if(0==d)r=this[0]%n;else for(var i=this.t-1;i>=0;--i)r=(d*r+this[i])%n;return r},BigInteger.prototype.millerRabin=function bnpMillerRabin(t){var n1=this.subtract(BigInteger.ONE),k=n1.getLowestSetBit();if(k<=0)return!1;var r=n1.shiftRight(k);(t=t+1>>1)>lowprimes.length&&(t=lowprimes.length);for(var a=nbi(),i=0;i<t;++i){a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var y=a.modPow(r,this);if(0!=y.compareTo(BigInteger.ONE)&&0!=y.compareTo(n1)){for(var j=1;j++<k&&0!=y.compareTo(n1);)if(0==(y=y.modPowInt(2,this)).compareTo(BigInteger.ONE))return!1;if(0!=y.compareTo(n1))return!1}}return!0},BigInteger.prototype.clone=function bnClone(){var r=nbi();return this.copyTo(r),r},BigInteger.prototype.intValue=function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},BigInteger.prototype.byteValue=function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24},BigInteger.prototype.shortValue=function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16},BigInteger.prototype.signum=function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},BigInteger.prototype.toByteArray=function bnToByteArray(){var i=this.t,r=new Array;r[0]=this.s;var d,p=this.DB-i*this.DB%8,k=0;if(i-- >0)for(p<this.DB&&(d=this[i]>>p)!=(this.s&this.DM)>>p&&(r[k++]=d|this.s<<this.DB-p);i>=0;)p<8?(d=(this[i]&(1<<p)-1)<<8-p,d|=this[--i]>>(p+=this.DB-8)):(d=this[i]>>(p-=8)&255,p<=0&&(p+=this.DB,--i)),128&d&&(d|=-256),0==k&&(128&this.s)!=(128&d)&&++k,(k>0||d!=this.s)&&(r[k++]=d);return r},BigInteger.prototype.equals=function bnEquals(a){return 0==this.compareTo(a)},BigInteger.prototype.min=function bnMin(a){return this.compareTo(a)<0?this:a},BigInteger.prototype.max=function bnMax(a){return this.compareTo(a)>0?this:a},BigInteger.prototype.and=function bnAnd(a){var r=nbi();return this.bitwiseTo(a,op_and,r),r},BigInteger.prototype.or=function bnOr(a){var r=nbi();return this.bitwiseTo(a,op_or,r),r},BigInteger.prototype.xor=function bnXor(a){var r=nbi();return this.bitwiseTo(a,op_xor,r),r},BigInteger.prototype.andNot=function bnAndNot(a){var r=nbi();return this.bitwiseTo(a,op_andnot,r),r},BigInteger.prototype.not=function bnNot(){for(var r=nbi(),i=0;i<this.t;++i)r[i]=this.DM&~this[i];return r.t=this.t,r.s=~this.s,r},BigInteger.prototype.shiftLeft=function bnShiftLeft(n){var r=nbi();return n<0?this.rShiftTo(-n,r):this.lShiftTo(n,r),r},BigInteger.prototype.shiftRight=function bnShiftRight(n){var r=nbi();return n<0?this.lShiftTo(-n,r):this.rShiftTo(n,r),r},BigInteger.prototype.getLowestSetBit=function bnGetLowestSetBit(){for(var i=0;i<this.t;++i)if(0!=this[i])return i*this.DB+lbit(this[i]);return this.s<0?this.t*this.DB:-1},BigInteger.prototype.bitCount=function bnBitCount(){for(var r=0,x=this.s&this.DM,i=0;i<this.t;++i)r+=cbit(this[i]^x);return r},BigInteger.prototype.testBit=function bnTestBit(n){var j=Math.floor(n/this.DB);return j>=this.t?0!=this.s:!!(this[j]&1<<n%this.DB)},BigInteger.prototype.setBit=function bnSetBit(n){return this.changeBit(n,op_or)},BigInteger.prototype.clearBit=function bnClearBit(n){return this.changeBit(n,op_andnot)},BigInteger.prototype.flipBit=function bnFlipBit(n){return this.changeBit(n,op_xor)},BigInteger.prototype.add=function bnAdd(a){var r=nbi();return this.addTo(a,r),r},BigInteger.prototype.subtract=function bnSubtract(a){var r=nbi();return this.subTo(a,r),r},BigInteger.prototype.multiply=function bnMultiply(a){var r=nbi();return this.multiplyTo(a,r),r},BigInteger.prototype.divide=function bnDivide(a){var r=nbi();return this.divRemTo(a,r,null),r},BigInteger.prototype.remainder=function bnRemainder(a){var r=nbi();return this.divRemTo(a,null,r),r},BigInteger.prototype.divideAndRemainder=function bnDivideAndRemainder(a){var q=nbi(),r=nbi();return this.divRemTo(a,q,r),new Array(q,r)},BigInteger.prototype.modPow=function bnModPow(e,m){var k,z,i=e.bitLength(),r=nbv(1);if(i<=0)return r;k=i<18?1:i<48?3:i<144?4:i<768?5:6,z=i<8?new Classic(m):m.isEven()?new Barrett(m):new Montgomery(m);var g=new Array,n=3,k1=k-1,km=(1<<k)-1;if(g[1]=z.convert(this),k>1){var g2=nbi();for(z.sqrTo(g[1],g2);n<=km;)g[n]=nbi(),z.mulTo(g2,g[n-2],g[n]),n+=2}var w,t,j=e.t-1,is1=!0,r2=nbi();for(i=nbits(e[j])-1;j>=0;){for(i>=k1?w=e[j]>>i-k1&km:(w=(e[j]&(1<<i+1)-1)<<k1-i,j>0&&(w|=e[j-1]>>this.DB+i-k1)),n=k;!(1&w);)w>>=1,--n;if((i-=n)<0&&(i+=this.DB,--j),is1)g[w].copyTo(r),is1=!1;else{for(;n>1;)z.sqrTo(r,r2),z.sqrTo(r2,r),n-=2;n>0?z.sqrTo(r,r2):(t=r,r=r2,r2=t),z.mulTo(r2,g[w],r)}for(;j>=0&&!(e[j]&1<<i);)z.sqrTo(r,r2),t=r,r=r2,r2=t,--i<0&&(i=this.DB-1,--j)}return z.revert(r)},BigInteger.prototype.modInverse=function bnModInverse(m){var ac=m.isEven();if(this.isEven()&&ac||0==m.signum())return BigInteger.ZERO;for(var u=m.clone(),v=this.clone(),a=nbv(1),b=nbv(0),c=nbv(0),d=nbv(1);0!=u.signum();){for(;u.isEven();)u.rShiftTo(1,u),ac?(a.isEven()&&b.isEven()||(a.addTo(this,a),b.subTo(m,b)),a.rShiftTo(1,a)):b.isEven()||b.subTo(m,b),b.rShiftTo(1,b);for(;v.isEven();)v.rShiftTo(1,v),ac?(c.isEven()&&d.isEven()||(c.addTo(this,c),d.subTo(m,d)),c.rShiftTo(1,c)):d.isEven()||d.subTo(m,d),d.rShiftTo(1,d);u.compareTo(v)>=0?(u.subTo(v,u),ac&&a.subTo(c,a),b.subTo(d,b)):(v.subTo(u,v),ac&&c.subTo(a,c),d.subTo(b,d))}return 0!=v.compareTo(BigInteger.ONE)?BigInteger.ZERO:d.compareTo(m)>=0?d.subtract(m):d.signum()<0?(d.addTo(m,d),d.signum()<0?d.add(m):d):d},BigInteger.prototype.pow=function bnPow(e){return this.exp(e,new NullExp)},BigInteger.prototype.gcd=function bnGCD(a){var x=this.s<0?this.negate():this.clone(),y=a.s<0?a.negate():a.clone();if(x.compareTo(y)<0){var t=x;x=y,y=t}var i=x.getLowestSetBit(),g=y.getLowestSetBit();if(g<0)return x;for(i<g&&(g=i),g>0&&(x.rShiftTo(g,x),y.rShiftTo(g,y));x.signum()>0;)(i=x.getLowestSetBit())>0&&x.rShiftTo(i,x),(i=y.getLowestSetBit())>0&&y.rShiftTo(i,y),x.compareTo(y)>=0?(x.subTo(y,x),x.rShiftTo(1,x)):(y.subTo(x,y),y.rShiftTo(1,y));return g>0&&y.lShiftTo(g,y),y},BigInteger.prototype.isProbablePrime=function bnIsProbablePrime(t){var i,x=this.abs();if(1==x.t&&x[0]<=lowprimes[lowprimes.length-1]){for(i=0;i<lowprimes.length;++i)if(x[0]==lowprimes[i])return!0;return!1}if(x.isEven())return!1;for(i=1;i<lowprimes.length;){for(var m=lowprimes[i],j=i+1;j<lowprimes.length&&m<lplim;)m*=lowprimes[j++];for(m=x.modInt(m);i<j;)if(m%lowprimes[i++]==0)return!1}return x.millerRabin(t)},BigInteger.prototype.square=function bnSquare(){var r=nbi();return this.squareTo(r),r};var Int128=BigInteger;Int128.prototype.IsNegative=function(){return-1==this.compareTo(Int128.ZERO)},Int128.op_Equality=function(val1,val2){return 0==val1.compareTo(val2)},Int128.op_Inequality=function(val1,val2){return 0!=val1.compareTo(val2)},Int128.op_GreaterThan=function(val1,val2){return val1.compareTo(val2)>0},Int128.op_LessThan=function(val1,val2){return val1.compareTo(val2)<0},Int128.op_Addition=function(lhs,rhs){return new Int128(lhs,void 0,void 0).add(new Int128(rhs,void 0,void 0))},Int128.op_Subtraction=function(lhs,rhs){return new Int128(lhs,void 0,void 0).subtract(new Int128(rhs,void 0,void 0))},Int128.Int128Mul=function(lhs,rhs){return new Int128(lhs,void 0,void 0).multiply(new Int128(rhs,void 0,void 0))},Int128.op_Division=function(lhs,rhs){return lhs.divide(rhs)},Int128.prototype.ToDouble=function(){return parseFloat(this.toString())};var Inherit=function(ce,ce2){var p;if(void 0===Object.getOwnPropertyNames){for(p in ce2.prototype)void 0!==ce.prototype[p]&&ce.prototype[p]!==Object.prototype[p]||(ce.prototype[p]=ce2.prototype[p]);for(p in ce2)void 0===ce[p]&&(ce[p]=ce2[p]);ce.$baseCtor=ce2}else{for(var props=Object.getOwnPropertyNames(ce2.prototype),i=0;i<props.length;i++)void 0===Object.getOwnPropertyDescriptor(ce.prototype,props[i])&&Object.defineProperty(ce.prototype,props[i],Object.getOwnPropertyDescriptor(ce2.prototype,props[i]));for(p in ce2)void 0===ce[p]&&(ce[p]=ce2[p]);ce.$baseCtor=ce2}};ClipperLib.Path=function(){return[]},ClipperLib.Path.prototype.push=Array.prototype.push,ClipperLib.Paths=function(){return[]},ClipperLib.Paths.prototype.push=Array.prototype.push,ClipperLib.DoublePoint=function(){var a=arguments;this.X=0,this.Y=0,1===a.length?(this.X=a[0].X,this.Y=a[0].Y):2===a.length&&(this.X=a[0],this.Y=a[1])},ClipperLib.DoublePoint0=function(){this.X=0,this.Y=0},ClipperLib.DoublePoint0.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.DoublePoint1=function(dp){this.X=dp.X,this.Y=dp.Y},ClipperLib.DoublePoint1.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.DoublePoint2=function(x,y){this.X=x,this.Y=y},ClipperLib.DoublePoint2.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.PolyNode=function(){this.m_Parent=null,this.m_polygon=new ClipperLib.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},ClipperLib.PolyNode.prototype.IsHoleNode=function(){for(var result=!0,node=this.m_Parent;null!==node;)result=!result,node=node.m_Parent;return result},ClipperLib.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},ClipperLib.PolyNode.prototype.Contour=function(){return this.m_polygon},ClipperLib.PolyNode.prototype.AddChild=function(Child){var cnt=this.m_Childs.length;this.m_Childs.push(Child),Child.m_Parent=this,Child.m_Index=cnt},ClipperLib.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},ClipperLib.PolyNode.prototype.GetNextSiblingUp=function(){return null===this.m_Parent?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},ClipperLib.PolyNode.prototype.Childs=function(){return this.m_Childs},ClipperLib.PolyNode.prototype.Parent=function(){return this.m_Parent},ClipperLib.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},ClipperLib.PolyTree=function(){this.m_AllPolys=[],ClipperLib.PolyNode.call(this)},ClipperLib.PolyTree.prototype.Clear=function(){for(var i=0,ilen=this.m_AllPolys.length;i<ilen;i++)this.m_AllPolys[i]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},ClipperLib.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},ClipperLib.PolyTree.prototype.Total=function(){var result=this.m_AllPolys.length;return result>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&result--,result},Inherit(ClipperLib.PolyTree,ClipperLib.PolyNode),ClipperLib.Math_Abs_Int64=ClipperLib.Math_Abs_Int32=ClipperLib.Math_Abs_Double=function(a){return Math.abs(a)},ClipperLib.Math_Max_Int32_Int32=function(a,b){return Math.max(a,b)},browser.msie||browser.opera||browser.safari?ClipperLib.Cast_Int32=function(a){return 0|a}:ClipperLib.Cast_Int32=function(a){return~~a},void 0===Number.toInteger&&(Number.toInteger=null),browser.chrome?ClipperLib.Cast_Int64=function(a){return a<-2147483648||a>2147483647?a<0?Math.ceil(a):Math.floor(a):~~a}:browser.firefox&&"function"==typeof Number.toInteger?ClipperLib.Cast_Int64=function(a){return Number.toInteger(a)}:browser.msie7||browser.msie8?ClipperLib.Cast_Int64=function(a){return parseInt(a,10)}:browser.msie?ClipperLib.Cast_Int64=function(a){return a<-2147483648||a>2147483647?a<0?Math.ceil(a):Math.floor(a):0|a}:ClipperLib.Cast_Int64=function(a){return a<0?Math.ceil(a):Math.floor(a)},ClipperLib.Clear=function(a){a.length=0},ClipperLib.PI=3.141592653589793,ClipperLib.PI2=6.283185307179586,ClipperLib.IntPoint=function(){var a=arguments,alen=a.length;if(this.X=0,this.Y=0,ClipperLib.use_xyz)if(this.Z=0,3===alen)this.X=a[0],this.Y=a[1],this.Z=a[2];else if(2===alen)this.X=a[0],this.Y=a[1],this.Z=0;else if(1===alen)if(a[0]instanceof ClipperLib.DoublePoint){var dp=a[0];this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y),this.Z=0}else void 0===(pt=a[0]).Z&&(pt.Z=0),this.X=pt.X,this.Y=pt.Y,this.Z=pt.Z;else this.X=0,this.Y=0,this.Z=0;else if(2===alen)this.X=a[0],this.Y=a[1];else if(1===alen)if(a[0]instanceof ClipperLib.DoublePoint)dp=a[0],this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y);else{var pt=a[0];this.X=pt.X,this.Y=pt.Y}else this.X=0,this.Y=0},ClipperLib.IntPoint.op_Equality=function(a,b){return a.X===b.X&&a.Y===b.Y},ClipperLib.IntPoint.op_Inequality=function(a,b){return a.X!==b.X||a.Y!==b.Y},ClipperLib.IntPoint0=function(){this.X=0,this.Y=0,ClipperLib.use_xyz&&(this.Z=0)},ClipperLib.IntPoint0.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint1=function(pt){this.X=pt.X,this.Y=pt.Y,ClipperLib.use_xyz&&(void 0===pt.Z?this.Z=0:this.Z=pt.Z)},ClipperLib.IntPoint1.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint1dp=function(dp){this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y),ClipperLib.use_xyz&&(this.Z=0)},ClipperLib.IntPoint1dp.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint2=function(x,y,z){this.X=x,this.Y=y,ClipperLib.use_xyz&&(this.Z=void 0===z?0:z)},ClipperLib.IntPoint2.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntRect=function(){var a=arguments,alen=a.length;if(4===alen)this.left=a[0],this.top=a[1],this.right=a[2],this.bottom=a[3];else if(1===alen){var ir=a[0];this.left=ir.left,this.top=ir.top,this.right=ir.right,this.bottom=ir.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},ClipperLib.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},ClipperLib.IntRect0.prototype=ClipperLib.IntRect.prototype,ClipperLib.IntRect1=function(ir){this.left=ir.left,this.top=ir.top,this.right=ir.right,this.bottom=ir.bottom},ClipperLib.IntRect1.prototype=ClipperLib.IntRect.prototype,ClipperLib.IntRect4=function(l,t,r,b){this.left=l,this.top=t,this.right=r,this.bottom=b},ClipperLib.IntRect4.prototype=ClipperLib.IntRect.prototype,ClipperLib.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},ClipperLib.PolyType={ptSubject:0,ptClip:1},ClipperLib.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},ClipperLib.JoinType={jtSquare:0,jtRound:1,jtMiter:2},ClipperLib.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},ClipperLib.EdgeSide={esLeft:0,esRight:1},ClipperLib.Direction={dRightToLeft:0,dLeftToRight:1},ClipperLib.TEdge=function(){this.Bot=new ClipperLib.IntPoint0,this.Curr=new ClipperLib.IntPoint0,this.Top=new ClipperLib.IntPoint0,this.Delta=new ClipperLib.IntPoint0,this.Dx=0,this.PolyTyp=ClipperLib.PolyType.ptSubject,this.Side=ClipperLib.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},ClipperLib.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new ClipperLib.IntPoint0},ClipperLib.MyIntersectNodeSort=function(){},ClipperLib.MyIntersectNodeSort.Compare=function(node1,node2){var i=node2.Pt.Y-node1.Pt.Y;return i>0?1:i<0?-1:0},ClipperLib.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},ClipperLib.Scanbeam=function(){this.Y=0,this.Next=null},ClipperLib.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},ClipperLib.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},ClipperLib.OutPt=function(){this.Idx=0,this.Pt=new ClipperLib.IntPoint0,this.Next=null,this.Prev=null},ClipperLib.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new ClipperLib.IntPoint0},ClipperLib.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},ClipperLib.ClipperBase.horizontal=-9007199254740992,ClipperLib.ClipperBase.Skip=-2,ClipperLib.ClipperBase.Unassigned=-1,ClipperLib.ClipperBase.tolerance=1e-20,ClipperLib.ClipperBase.loRange=47453132,ClipperLib.ClipperBase.hiRange=0xfffffffffffff,ClipperLib.ClipperBase.near_zero=function(val){return val>-ClipperLib.ClipperBase.tolerance&&val<ClipperLib.ClipperBase.tolerance},ClipperLib.ClipperBase.IsHorizontal=function(e){return 0===e.Delta.Y},ClipperLib.ClipperBase.prototype.PointIsVertex=function(pt,pp){var pp2=pp;do{if(ClipperLib.IntPoint.op_Equality(pp2.Pt,pt))return!0;pp2=pp2.Next}while(pp2!==pp);return!1},ClipperLib.ClipperBase.prototype.PointOnLineSegment=function(pt,linePt1,linePt2,UseFullRange){return UseFullRange?pt.X===linePt1.X&&pt.Y===linePt1.Y||pt.X===linePt2.X&&pt.Y===linePt2.Y||pt.X>linePt1.X==pt.X<linePt2.X&&pt.Y>linePt1.Y==pt.Y<linePt2.Y&&Int128.op_Equality(Int128.Int128Mul(pt.X-linePt1.X,linePt2.Y-linePt1.Y),Int128.Int128Mul(linePt2.X-linePt1.X,pt.Y-linePt1.Y)):pt.X===linePt1.X&&pt.Y===linePt1.Y||pt.X===linePt2.X&&pt.Y===linePt2.Y||pt.X>linePt1.X==pt.X<linePt2.X&&pt.Y>linePt1.Y==pt.Y<linePt2.Y&&(pt.X-linePt1.X)*(linePt2.Y-linePt1.Y)==(linePt2.X-linePt1.X)*(pt.Y-linePt1.Y)},ClipperLib.ClipperBase.prototype.PointOnPolygon=function(pt,pp,UseFullRange){for(var pp2=pp;;){if(this.PointOnLineSegment(pt,pp2.Pt,pp2.Next.Pt,UseFullRange))return!0;if((pp2=pp2.Next)===pp)break}return!1},ClipperLib.ClipperBase.prototype.SlopesEqual=ClipperLib.ClipperBase.SlopesEqual=function(){var e1,e2,pt1,pt2,pt3,pt4,a=arguments,alen=a.length;return 3===alen?(e1=a[0],e2=a[1],a[2]?Int128.op_Equality(Int128.Int128Mul(e1.Delta.Y,e2.Delta.X),Int128.Int128Mul(e1.Delta.X,e2.Delta.Y)):ClipperLib.Cast_Int64(e1.Delta.Y*e2.Delta.X)===ClipperLib.Cast_Int64(e1.Delta.X*e2.Delta.Y)):4===alen?(pt1=a[0],pt2=a[1],pt3=a[2],a[3]?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt2.X-pt3.X),Int128.Int128Mul(pt1.X-pt2.X,pt2.Y-pt3.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt2.X-pt3.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt2.Y-pt3.Y))==0):(pt1=a[0],pt2=a[1],pt3=a[2],pt4=a[3],a[4]?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt3.X-pt4.X),Int128.Int128Mul(pt1.X-pt2.X,pt3.Y-pt4.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt3.X-pt4.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt3.Y-pt4.Y))==0)},ClipperLib.ClipperBase.SlopesEqual3=function(e1,e2,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(e1.Delta.Y,e2.Delta.X),Int128.Int128Mul(e1.Delta.X,e2.Delta.Y)):ClipperLib.Cast_Int64(e1.Delta.Y*e2.Delta.X)===ClipperLib.Cast_Int64(e1.Delta.X*e2.Delta.Y)},ClipperLib.ClipperBase.SlopesEqual4=function(pt1,pt2,pt3,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt2.X-pt3.X),Int128.Int128Mul(pt1.X-pt2.X,pt2.Y-pt3.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt2.X-pt3.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt2.Y-pt3.Y))==0},ClipperLib.ClipperBase.SlopesEqual5=function(pt1,pt2,pt3,pt4,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt3.X-pt4.X),Int128.Int128Mul(pt1.X-pt2.X,pt3.Y-pt4.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt3.X-pt4.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt3.Y-pt4.Y))==0},ClipperLib.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var i=0,ilen=this.m_edges.length;i<ilen;++i){for(var j=0,jlen=this.m_edges[i].length;j<jlen;++j)this.m_edges[i][j]=null;ClipperLib.Clear(this.m_edges[i])}ClipperLib.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},ClipperLib.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;null!==this.m_MinimaList;){var tmpLm=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=tmpLm}this.m_CurrentLM=null},ClipperLib.ClipperBase.prototype.RangeTest=function(Pt,useFullRange){useFullRange.Value?(Pt.X>ClipperLib.ClipperBase.hiRange||Pt.Y>ClipperLib.ClipperBase.hiRange||-Pt.X>ClipperLib.ClipperBase.hiRange||-Pt.Y>ClipperLib.ClipperBase.hiRange)&&ClipperLib.Error("Coordinate outside allowed range in RangeTest()."):(Pt.X>ClipperLib.ClipperBase.loRange||Pt.Y>ClipperLib.ClipperBase.loRange||-Pt.X>ClipperLib.ClipperBase.loRange||-Pt.Y>ClipperLib.ClipperBase.loRange)&&(useFullRange.Value=!0,this.RangeTest(Pt,useFullRange))},ClipperLib.ClipperBase.prototype.InitEdge=function(e,eNext,ePrev,pt){e.Next=eNext,e.Prev=ePrev,e.Curr.X=pt.X,e.Curr.Y=pt.Y,ClipperLib.use_xyz&&(e.Curr.Z=pt.Z),e.OutIdx=-1},ClipperLib.ClipperBase.prototype.InitEdge2=function(e,polyType){e.Curr.Y>=e.Next.Curr.Y?(e.Bot.X=e.Curr.X,e.Bot.Y=e.Curr.Y,ClipperLib.use_xyz&&(e.Bot.Z=e.Curr.Z),e.Top.X=e.Next.Curr.X,e.Top.Y=e.Next.Curr.Y,ClipperLib.use_xyz&&(e.Top.Z=e.Next.Curr.Z)):(e.Top.X=e.Curr.X,e.Top.Y=e.Curr.Y,ClipperLib.use_xyz&&(e.Top.Z=e.Curr.Z),e.Bot.X=e.Next.Curr.X,e.Bot.Y=e.Next.Curr.Y,ClipperLib.use_xyz&&(e.Bot.Z=e.Next.Curr.Z)),this.SetDx(e),e.PolyTyp=polyType},ClipperLib.ClipperBase.prototype.FindNextLocMin=function(E){for(var E2;;){for(;ClipperLib.IntPoint.op_Inequality(E.Bot,E.Prev.Bot)||ClipperLib.IntPoint.op_Equality(E.Curr,E.Top);)E=E.Next;if(E.Dx!==ClipperLib.ClipperBase.horizontal&&E.Prev.Dx!==ClipperLib.ClipperBase.horizontal)break;for(;E.Prev.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Prev;for(E2=E;E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Next;if(E.Top.Y!==E.Prev.Bot.Y){E2.Prev.Bot.X<E.Bot.X&&(E=E2);break}}return E},ClipperLib.ClipperBase.prototype.ProcessBound=function(E,LeftBoundIsForward){var EStart,Horz,Result=E;if(Result.OutIdx===ClipperLib.ClipperBase.Skip){if(E=Result,LeftBoundIsForward){for(;E.Top.Y===E.Next.Bot.Y;)E=E.Next;for(;E!==Result&&E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Prev}else{for(;E.Top.Y===E.Prev.Bot.Y;)E=E.Prev;for(;E!==Result&&E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Next}if(E===Result)Result=LeftBoundIsForward?E.Next:E.Prev;else{E=LeftBoundIsForward?Result.Next:Result.Prev;var locMin=new ClipperLib.LocalMinima;locMin.Next=null,locMin.Y=E.Bot.Y,locMin.LeftBound=null,locMin.RightBound=E,E.WindDelta=0,Result=this.ProcessBound(E,LeftBoundIsForward),this.InsertLocalMinima(locMin)}return Result}if(E.Dx===ClipperLib.ClipperBase.horizontal&&((EStart=LeftBoundIsForward?E.Prev:E.Next).Dx===ClipperLib.ClipperBase.horizontal?EStart.Bot.X!==E.Bot.X&&EStart.Top.X!==E.Bot.X&&this.ReverseHorizontal(E):EStart.Bot.X!==E.Bot.X&&this.ReverseHorizontal(E)),EStart=E,LeftBoundIsForward){for(;Result.Top.Y===Result.Next.Bot.Y&&Result.Next.OutIdx!==ClipperLib.ClipperBase.Skip;)Result=Result.Next;if(Result.Dx===ClipperLib.ClipperBase.horizontal&&Result.Next.OutIdx!==ClipperLib.ClipperBase.Skip){for(Horz=Result;Horz.Prev.Dx===ClipperLib.ClipperBase.horizontal;)Horz=Horz.Prev;Horz.Prev.Top.X>Result.Next.Top.X&&(Result=Horz.Prev)}for(;E!==Result;)E.NextInLML=E.Next,E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),E=E.Next;E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),Result=Result.Next}else{for(;Result.Top.Y===Result.Prev.Bot.Y&&Result.Prev.OutIdx!==ClipperLib.ClipperBase.Skip;)Result=Result.Prev;if(Result.Dx===ClipperLib.ClipperBase.horizontal&&Result.Prev.OutIdx!==ClipperLib.ClipperBase.Skip){for(Horz=Result;Horz.Next.Dx===ClipperLib.ClipperBase.horizontal;)Horz=Horz.Next;(Horz.Next.Top.X===Result.Prev.Top.X||Horz.Next.Top.X>Result.Prev.Top.X)&&(Result=Horz.Next)}for(;E!==Result;)E.NextInLML=E.Prev,E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Next.Top.X&&this.ReverseHorizontal(E),E=E.Prev;E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Next.Top.X&&this.ReverseHorizontal(E),Result=Result.Prev}return Result},ClipperLib.ClipperBase.prototype.AddPath=function(pg,polyType,Closed){ClipperLib.use_lines?Closed||polyType!==ClipperLib.PolyType.ptClip||ClipperLib.Error("AddPath: Open paths must be subject."):Closed||ClipperLib.Error("AddPath: Open paths have been disabled.");var highI=pg.length-1;if(Closed)for(;highI>0&&ClipperLib.IntPoint.op_Equality(pg[highI],pg[0]);)--highI;for(;highI>0&&ClipperLib.IntPoint.op_Equality(pg[highI],pg[highI-1]);)--highI;if(Closed&&highI<2||!Closed&&highI<1)return!1;for(var edges=new Array,i=0;i<=highI;i++)edges.push(new ClipperLib.TEdge);var IsFlat=!0;edges[1].Curr.X=pg[1].X,edges[1].Curr.Y=pg[1].Y,ClipperLib.use_xyz&&(edges[1].Curr.Z=pg[1].Z);var $1={Value:this.m_UseFullRange};for(this.RangeTest(pg[0],$1),this.m_UseFullRange=$1.Value,$1.Value=this.m_UseFullRange,this.RangeTest(pg[highI],$1),this.m_UseFullRange=$1.Value,this.InitEdge(edges[0],edges[1],edges[highI],pg[0]),this.InitEdge(edges[highI],edges[0],edges[highI-1],pg[highI]),i=highI-1;i>=1;--i)$1.Value=this.m_UseFullRange,this.RangeTest(pg[i],$1),this.m_UseFullRange=$1.Value,this.InitEdge(edges[i],edges[i+1],edges[i-1],pg[i]);for(var leftBoundIsForward,eStart=edges[0],E=eStart,eLoopStop=eStart;;)if(E.Curr!==E.Next.Curr||!Closed&&E.Next===eStart){if(E.Prev===E.Next)break;if(!Closed||!ClipperLib.ClipperBase.SlopesEqual4(E.Prev.Curr,E.Curr,E.Next.Curr,this.m_UseFullRange)||this.PreserveCollinear&&this.Pt2IsBetweenPt1AndPt3(E.Prev.Curr,E.Curr,E.Next.Curr)){if((E=E.Next)===eLoopStop||!Closed&&E.Next===eStart)break}else E===eStart&&(eStart=E.Next),eLoopStop=E=(E=this.RemoveEdge(E)).Prev}else{if(E===E.Next)break;E===eStart&&(eStart=E.Next),eLoopStop=E=this.RemoveEdge(E)}if(!Closed&&E===E.Next||Closed&&E.Prev===E.Next)return!1;Closed||(this.m_HasOpenPaths=!0,eStart.Prev.OutIdx=ClipperLib.ClipperBase.Skip),E=eStart;do{this.InitEdge2(E,polyType),E=E.Next,IsFlat&&E.Curr.Y!==eStart.Curr.Y&&(IsFlat=!1)}while(E!==eStart);if(IsFlat){if(Closed)return!1;for(E.Prev.OutIdx=ClipperLib.ClipperBase.Skip,(locMin=new ClipperLib.LocalMinima).Next=null,locMin.Y=E.Bot.Y,locMin.LeftBound=null,locMin.RightBound=E,locMin.RightBound.Side=ClipperLib.EdgeSide.esRight,locMin.RightBound.WindDelta=0;E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),E.Next.OutIdx!==ClipperLib.ClipperBase.Skip;)E.NextInLML=E.Next,E=E.Next;return this.InsertLocalMinima(locMin),this.m_edges.push(edges),!0}this.m_edges.push(edges);var EMin=null;for(ClipperLib.IntPoint.op_Equality(E.Prev.Bot,E.Prev.Top)&&(E=E.Next);(E=this.FindNextLocMin(E))!==EMin;){var locMin;null===EMin&&(EMin=E),(locMin=new ClipperLib.LocalMinima).Next=null,locMin.Y=E.Bot.Y,E.Dx<E.Prev.Dx?(locMin.LeftBound=E.Prev,locMin.RightBound=E,leftBoundIsForward=!1):(locMin.LeftBound=E,locMin.RightBound=E.Prev,leftBoundIsForward=!0),locMin.LeftBound.Side=ClipperLib.EdgeSide.esLeft,locMin.RightBound.Side=ClipperLib.EdgeSide.esRight,Closed?locMin.LeftBound.Next===locMin.RightBound?locMin.LeftBound.WindDelta=-1:locMin.LeftBound.WindDelta=1:locMin.LeftBound.WindDelta=0,locMin.RightBound.WindDelta=-locMin.LeftBound.WindDelta,(E=this.ProcessBound(locMin.LeftBound,leftBoundIsForward)).OutIdx===ClipperLib.ClipperBase.Skip&&(E=this.ProcessBound(E,leftBoundIsForward));var E2=this.ProcessBound(locMin.RightBound,!leftBoundIsForward);E2.OutIdx===ClipperLib.ClipperBase.Skip&&(E2=this.ProcessBound(E2,!leftBoundIsForward)),locMin.LeftBound.OutIdx===ClipperLib.ClipperBase.Skip?locMin.LeftBound=null:locMin.RightBound.OutIdx===ClipperLib.ClipperBase.Skip&&(locMin.RightBound=null),this.InsertLocalMinima(locMin),leftBoundIsForward||(E=E2)}return!0},ClipperLib.ClipperBase.prototype.AddPaths=function(ppg,polyType,closed){for(var result=!1,i=0,ilen=ppg.length;i<ilen;++i)this.AddPath(ppg[i],polyType,closed)&&(result=!0);return result},ClipperLib.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(pt1,pt2,pt3){return!(ClipperLib.IntPoint.op_Equality(pt1,pt3)||ClipperLib.IntPoint.op_Equality(pt1,pt2)||ClipperLib.IntPoint.op_Equality(pt3,pt2))&&(pt1.X!==pt3.X?pt2.X>pt1.X==pt2.X<pt3.X:pt2.Y>pt1.Y==pt2.Y<pt3.Y)},ClipperLib.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var result=e.Next;return e.Prev=null,result},ClipperLib.ClipperBase.prototype.SetDx=function(e){e.Delta.X=e.Top.X-e.Bot.X,e.Delta.Y=e.Top.Y-e.Bot.Y,0===e.Delta.Y?e.Dx=ClipperLib.ClipperBase.horizontal:e.Dx=e.Delta.X/e.Delta.Y},ClipperLib.ClipperBase.prototype.InsertLocalMinima=function(newLm){if(null===this.m_MinimaList)this.m_MinimaList=newLm;else if(newLm.Y>=this.m_MinimaList.Y)newLm.Next=this.m_MinimaList,this.m_MinimaList=newLm;else{for(var tmpLm=this.m_MinimaList;null!==tmpLm.Next&&newLm.Y<tmpLm.Next.Y;)tmpLm=tmpLm.Next;newLm.Next=tmpLm.Next,tmpLm.Next=newLm}},ClipperLib.ClipperBase.prototype.PopLocalMinima=function(Y,current){return current.v=this.m_CurrentLM,null!==this.m_CurrentLM&&this.m_CurrentLM.Y===Y&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)},ClipperLib.ClipperBase.prototype.ReverseHorizontal=function(e){var tmp=e.Top.X;e.Top.X=e.Bot.X,e.Bot.X=tmp,ClipperLib.use_xyz&&(tmp=e.Top.Z,e.Top.Z=e.Bot.Z,e.Bot.Z=tmp)},ClipperLib.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,null!==this.m_CurrentLM){this.m_Scanbeam=null;for(var lm=this.m_MinimaList;null!==lm;){this.InsertScanbeam(lm.Y);var e=lm.LeftBound;null!==e&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,ClipperLib.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=ClipperLib.ClipperBase.Unassigned),null!==(e=lm.RightBound)&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,ClipperLib.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=ClipperLib.ClipperBase.Unassigned),lm=lm.Next}this.m_ActiveEdges=null}},ClipperLib.ClipperBase.prototype.InsertScanbeam=function(Y){if(null===this.m_Scanbeam)this.m_Scanbeam=new ClipperLib.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=Y;else if(Y>this.m_Scanbeam.Y){var newSb=new ClipperLib.Scanbeam;newSb.Y=Y,newSb.Next=this.m_Scanbeam,this.m_Scanbeam=newSb}else{for(var sb2=this.m_Scanbeam;null!==sb2.Next&&Y<=sb2.Next.Y;)sb2=sb2.Next;if(Y===sb2.Y)return;var newSb1=new ClipperLib.Scanbeam;newSb1.Y=Y,newSb1.Next=sb2.Next,sb2.Next=newSb1}},ClipperLib.ClipperBase.prototype.PopScanbeam=function(Y){return null===this.m_Scanbeam?(Y.v=0,!1):(Y.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},ClipperLib.ClipperBase.prototype.LocalMinimaPending=function(){return null!==this.m_CurrentLM},ClipperLib.ClipperBase.prototype.CreateOutRec=function(){var result=new ClipperLib.OutRec;return result.Idx=ClipperLib.ClipperBase.Unassigned,result.IsHole=!1,result.IsOpen=!1,result.FirstLeft=null,result.Pts=null,result.BottomPt=null,result.PolyNode=null,this.m_PolyOuts.push(result),result.Idx=this.m_PolyOuts.length-1,result},ClipperLib.ClipperBase.prototype.DisposeOutRec=function(index){var outRec=this.m_PolyOuts[index];outRec.Pts=null,outRec=null,this.m_PolyOuts[index]=null},ClipperLib.ClipperBase.prototype.UpdateEdgeIntoAEL=function(e){null===e.NextInLML&&ClipperLib.Error("UpdateEdgeIntoAEL: invalid call");var AelPrev=e.PrevInAEL,AelNext=e.NextInAEL;return e.NextInLML.OutIdx=e.OutIdx,null!==AelPrev?AelPrev.NextInAEL=e.NextInLML:this.m_ActiveEdges=e.NextInLML,null!==AelNext&&(AelNext.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).Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,e.PrevInAEL=AelPrev,e.NextInAEL=AelNext,ClipperLib.ClipperBase.IsHorizontal(e)||this.InsertScanbeam(e.Top.Y),e},ClipperLib.ClipperBase.prototype.SwapPositionsInAEL=function(edge1,edge2){if(edge1.NextInAEL!==edge1.PrevInAEL&&edge2.NextInAEL!==edge2.PrevInAEL){if(edge1.NextInAEL===edge2){var next=edge2.NextInAEL;null!==next&&(next.PrevInAEL=edge1);var prev=edge1.PrevInAEL;null!==prev&&(prev.NextInAEL=edge2),edge2.PrevInAEL=prev,edge2.NextInAEL=edge1,edge1.PrevInAEL=edge2,edge1.NextInAEL=next}else if(edge2.NextInAEL===edge1){var next1=edge1.NextInAEL;null!==next1&&(next1.PrevInAEL=edge2);var prev1=edge2.PrevInAEL;null!==prev1&&(prev1.NextInAEL=edge1),edge1.PrevInAEL=prev1,edge1.NextInAEL=edge2,edge2.PrevInAEL=edge1,edge2.NextInAEL=next1}else{var next2=edge1.NextInAEL,prev2=edge1.PrevInAEL;edge1.NextInAEL=edge2.NextInAEL,null!==edge1.NextInAEL&&(edge1.NextInAEL.PrevInAEL=edge1),edge1.PrevInAEL=edge2.PrevInAEL,null!==edge1.PrevInAEL&&(edge1.PrevInAEL.NextInAEL=edge1),edge2.NextInAEL=next2,null!==edge2.NextInAEL&&(edge2.NextInAEL.PrevInAEL=edge2),edge2.PrevInAEL=prev2,null!==edge2.PrevInAEL&&(edge2.PrevInAEL.NextInAEL=edge2)}null===edge1.PrevInAEL?this.m_ActiveEdges=edge1:null===edge2.PrevInAEL&&(this.m_ActiveEdges=edge2)}},ClipperLib.ClipperBase.prototype.DeleteFromAEL=function(e){var AelPrev=e.PrevInAEL,AelNext=e.NextInAEL;null===AelPrev&&null===AelNext&&e!==this.m_ActiveEdges||(null!==AelPrev?AelPrev.NextInAEL=AelNext:this.m_ActiveEdges=AelNext,null!==AelNext&&(AelNext.PrevInAEL=AelPrev),e.NextInAEL=null,e.PrevInAEL=null)},ClipperLib.Clipper=function(InitOptions){void 0===InitOptions&&(InitOptions=0),this.m_PolyOuts=null,this.m_ClipType=ClipperLib.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=ClipperLib.PolyFillType.pftEvenOdd,this.m_SubjFillType=ClipperLib.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,ClipperLib.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=ClipperLib.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&InitOptions),this.StrictlySimple=!!(2&InitOptions),this.PreserveCollinear=!!(4&InitOptions),ClipperLib.use_xyz&&(this.ZFillFunction=null)},ClipperLib.Clipper.ioReverseSolution=1,ClipperLib.Clipper.ioStrictlySimple=2,ClipperLib.Clipper.ioPreserveCollinear=4,ClipperLib.Clipper.prototype.Clear=function(){0!==this.m_edges.length&&(this.DisposeAllPolyPts(),ClipperLib.ClipperBase.prototype.Clear.call(this))},ClipperLib.Clipper.prototype.InsertMaxima=function(X){var newMax=new ClipperLib.Maxima;if(newMax.X=X,null===this.m_Maxima)this.m_Maxima=newMax,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(X<this.m_Maxima.X)newMax.Next=this.m_Maxima,newMax.Prev=null,this.m_Maxima=newMax;else{for(var m=this.m_Maxima;null!==m.Next&&X>=m.Next.X;)m=m.Next;if(X===m.X)return;newMax.Next=m.Next,newMax.Prev=m,null!==m.Next&&(m.Next.Prev=newMax),m.Next=newMax}},ClipperLib.Clipper.prototype.Execute=function(){var a=arguments,alen=a.length,ispolytree=a[1]instanceof ClipperLib.PolyTree;if(4===alen&&!ispolytree){var clipType=a[0],solution=a[1],subjFillType=a[2],clipFillType=a[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&ClipperLib.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,ClipperLib.Clear(solution),this.m_SubjFillType=subjFillType,this.m_ClipFillType=clipFillType,this.m_ClipType=clipType,this.m_UsingPolyTree=!1;try{(succeeded=this.ExecuteInternal())&&this.BuildResult(solution)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return succeeded}if(4===alen&&ispolytree){clipType=a[0];var polytree=a[1];if(subjFillType=a[2],clipFillType=a[3],this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=subjFillType,this.m_ClipFillType=clipFillType,this.m_ClipType=clipType,this.m_UsingPolyTree=!0;try{var succeeded;(succeeded=this.ExecuteInternal())&&this.BuildResult2(polytree)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return succeeded}return 2!==alen||ispolytree?2===alen&&ispolytree?(clipType=a[0],polytree=a[1],this.Execute(clipType,polytree,ClipperLib.PolyFillType.pftEvenOdd,ClipperLib.PolyFillType.pftEvenOdd)):void 0:(clipType=a[0],solution=a[1],this.Execute(clipType,solution,ClipperLib.PolyFillType.pftEvenOdd,ClipperLib.PolyFillType.pftEvenOdd))},ClipperLib.Clipper.prototype.FixHoleLinkage=function(outRec){if(null!==outRec.FirstLeft&&(outRec.IsHole===outRec.FirstLeft.IsHole||null===outRec.FirstLeft.Pts)){for(var orfl=outRec.FirstLeft;null!==orfl&&(orfl.IsHole===outRec.IsHole||null===orfl.Pts);)orfl=orfl.FirstLeft;outRec.FirstLeft=orfl}},ClipperLib.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var outRec,i,ilen,botY={},topY={};if(!this.PopScanbeam(botY))return!1;for(this.InsertLocalMinimaIntoAEL(botY.v);this.PopScanbeam(topY)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(topY.v))return!1;this.ProcessEdgesAtTopOfScanbeam(topY.v),botY.v=topY.v,this.InsertLocalMinimaIntoAEL(botY.v)}for(i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null===(outRec=this.m_PolyOuts[i]).Pts||outRec.IsOpen||(outRec.IsHole^this.ReverseSolution)==this.Area$1(outRec)>0&&this.ReversePolyPtLinks(outRec.Pts);for(this.JoinCommonEdges(),i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).Pts&&(outRec.IsOpen?this.FixupOutPolyline(outRec):this.FixupOutPolygon(outRec));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},ClipperLib.Clipper.prototype.DisposeAllPolyPts=function(){for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;++i)this.DisposeOutRec(i);ClipperLib.Clear(this.m_PolyOuts)},ClipperLib.Clipper.prototype.AddJoin=function(Op1,Op2,OffPt){var j=new ClipperLib.Join;j.OutPt1=Op1,j.OutPt2=Op2,j.OffPt.X=OffPt.X,j.OffPt.Y=OffPt.Y,ClipperLib.use_xyz&&(j.OffPt.Z=OffPt.Z),this.m_Joins.push(j)},ClipperLib.Clipper.prototype.AddGhostJoin=function(Op,OffPt){var j=new ClipperLib.Join;j.OutPt1=Op,j.OffPt.X=OffPt.X,j.OffPt.Y=OffPt.Y,ClipperLib.use_xyz&&(j.OffPt.Z=OffPt.Z),this.m_GhostJoins.push(j)},ClipperLib.Clipper.prototype.SetZ=function(pt,e1,e2){if(null!==this.ZFillFunction){if(0!==pt.Z||null===this.ZFillFunction)return;ClipperLib.IntPoint.op_Equality(pt,e1.Bot)?pt.Z=e1.Bot.Z:ClipperLib.IntPoint.op_Equality(pt,e1.Top)?pt.Z=e1.Top.Z:ClipperLib.IntPoint.op_Equality(pt,e2.Bot)?pt.Z=e2.Bot.Z:ClipperLib.IntPoint.op_Equality(pt,e2.Top)?pt.Z=e2.Top.Z:this.ZFillFunction(e1.Bot,e1.Top,e2.Bot,e2.Top,pt)}},ClipperLib.Clipper.prototype.InsertLocalMinimaIntoAEL=function(botY){for(var lb,rb,lm={};this.PopLocalMinima(botY,lm);){lb=lm.v.LeftBound,rb=lm.v.RightBound;var Op1=null;if(null===lb?(this.InsertEdgeIntoAEL(rb,null),this.SetWindingCount(rb),this.IsContributing(rb)&&(Op1=this.AddOutPt(rb,rb.Bot))):null===rb?(this.InsertEdgeIntoAEL(lb,null),this.SetWindingCount(lb),this.IsContributing(lb)&&(Op1=this.AddOutPt(lb,lb.Bot)),this.InsertScanbeam(lb.Top.Y)):(this.InsertEdgeIntoAEL(lb,null),this.InsertEdgeIntoAEL(rb,lb),this.SetWindingCount(lb),rb.WindCnt=lb.WindCnt,rb.WindCnt2=lb.WindCnt2,this.IsContributing(lb)&&(Op1=this.AddLocalMinPoly(lb,rb,lb.Bot)),this.InsertScanbeam(lb.Top.Y)),null!==rb&&(ClipperLib.ClipperBase.IsHorizontal(rb)?(null!==rb.NextInLML&&this.InsertScanbeam(rb.NextInLML.Top.Y),this.AddEdgeToSEL(rb)):this.InsertScanbeam(rb.Top.Y)),null!==lb&&null!==rb){if(null!==Op1&&ClipperLib.ClipperBase.IsHorizontal(rb)&&this.m_GhostJoins.length>0&&0!==rb.WindDelta)for(var i=0,ilen=this.m_GhostJoins.length;i<ilen;i++){var j=this.m_GhostJoins[i];this.HorzSegmentsOverlap(j.OutPt1.Pt.X,j.OffPt.X,rb.Bot.X,rb.Top.X)&&this.AddJoin(j.OutPt1,Op1,j.OffPt)}if(lb.OutIdx>=0&&null!==lb.PrevInAEL&&lb.PrevInAEL.Curr.X===lb.Bot.X&&lb.PrevInAEL.OutIdx>=0&&ClipperLib.ClipperBase.SlopesEqual5(lb.PrevInAEL.Curr,lb.PrevInAEL.Top,lb.Curr,lb.Top,this.m_UseFullRange)&&0!==lb.WindDelta&&0!==lb.PrevInAEL.WindDelta){var Op2=this.AddOutPt(lb.PrevInAEL,lb.Bot);this.AddJoin(Op1,Op2,lb.Top)}if(lb.NextInAEL!==rb){rb.OutIdx>=0&&rb.PrevInAEL.OutIdx>=0&&ClipperLib.ClipperBase.SlopesEqual5(rb.PrevInAEL.Curr,rb.PrevInAEL.Top,rb.Curr,rb.Top,this.m_UseFullRange)&&0!==rb.WindDelta&&0!==rb.PrevInAEL.WindDelta&&(Op2=this.AddOutPt(rb.PrevInAEL,rb.Bot),this.AddJoin(Op1,Op2,rb.Top));var e=lb.NextInAEL;if(null!==e)for(;e!==rb;)this.IntersectEdges(rb,e,lb.Curr),e=e.NextInAEL}}}},ClipperLib.Clipper.prototype.InsertEdgeIntoAEL=function(edge,startEdge){if(null===this.m_ActiveEdges)edge.PrevInAEL=null,edge.NextInAEL=null,this.m_ActiveEdges=edge;else if(null===startEdge&&this.E2InsertsBeforeE1(this.m_ActiveEdges,edge))edge.PrevInAEL=null,edge.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=edge,this.m_ActiveEdges=edge;else{for(null===startEdge&&(startEdge=this.m_ActiveEdges);null!==startEdge.NextInAEL&&!this.E2InsertsBeforeE1(startEdge.NextInAEL,edge);)startEdge=startEdge.NextInAEL;edge.NextInAEL=startEdge.NextInAEL,null!==startEdge.NextInAEL&&(startEdge.NextInAEL.PrevInAEL=edge),edge.PrevInAEL=startEdge,startEdge.NextInAEL=edge}},ClipperLib.Clipper.prototype.E2InsertsBeforeE1=function(e1,e2){return e2.Curr.X===e1.Curr.X?e2.Top.Y>e1.Top.Y?e2.Top.X<ClipperLib.Clipper.TopX(e1,e2.Top.Y):e1.Top.X>ClipperLib.Clipper.TopX(e2,e1.Top.Y):e2.Curr.X<e1.Curr.X},ClipperLib.Clipper.prototype.IsEvenOddFillType=function(edge){return edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_SubjFillType===ClipperLib.PolyFillType.pftEvenOdd:this.m_ClipFillType===ClipperLib.PolyFillType.pftEvenOdd},ClipperLib.Clipper.prototype.IsEvenOddAltFillType=function(edge){return edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_ClipFillType===ClipperLib.PolyFillType.pftEvenOdd:this.m_SubjFillType===ClipperLib.PolyFillType.pftEvenOdd},ClipperLib.Clipper.prototype.IsContributing=function(edge){var pft,pft2;switch(edge.PolyTyp===ClipperLib.PolyType.ptSubject?(pft=this.m_SubjFillType,pft2=this.m_ClipFillType):(pft=this.m_ClipFillType,pft2=this.m_SubjFillType),pft){case ClipperLib.PolyFillType.pftEvenOdd:if(0===edge.WindDelta&&1!==edge.WindCnt)return!1;break;case ClipperLib.PolyFillType.pftNonZero:if(1!==Math.abs(edge.WindCnt))return!1;break;case ClipperLib.PolyFillType.pftPositive:if(1!==edge.WindCnt)return!1;break;default:if(-1!==edge.WindCnt)return!1}switch(this.m_ClipType){case ClipperLib.ClipType.ctIntersection:switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0!==edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2>0;default:return edge.WindCnt2<0}case ClipperLib.ClipType.ctUnion:switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}case ClipperLib.ClipType.ctDifference:if(edge.PolyTyp===ClipperLib.PolyType.ptSubject)switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}else switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0!==edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2>0;default:return edge.WindCnt2<0}case ClipperLib.ClipType.ctXor:if(0!==edge.WindDelta)return!0;switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}}return!0},ClipperLib.Clipper.prototype.SetWindingCount=function(edge){for(var e=edge.PrevInAEL;null!==e&&(e.PolyTyp!==edge.PolyTyp||0===e.WindDelta);)e=e.PrevInAEL;if(null===e){var pft=edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;0===edge.WindDelta?edge.WindCnt=pft===ClipperLib.PolyFillType.pftNegative?-1:1:edge.WindCnt=edge.WindDelta,edge.WindCnt2=0,e=this.m_ActiveEdges}else if(0===edge.WindDelta&&this.m_ClipType!==ClipperLib.ClipType.ctUnion)edge.WindCnt=1,edge.WindCnt2=e.WindCnt2,e=e.NextInAEL;else if(this.IsEvenOddFillType(edge)){if(0===edge.WindDelta){for(var Inside=!0,e2=e.PrevInAEL;null!==e2;)e2.PolyTyp===e.PolyTyp&&0!==e2.WindDelta&&(Inside=!Inside),e2=e2.PrevInAEL;edge.WindCnt=Inside?0:1}else edge.WindCnt=edge.WindDelta;edge.WindCnt2=e.WindCnt2,e=e.NextInAEL}else e.WindCnt*e.WindDelta<0?Math.abs(e.WindCnt)>1?e.WindDelta*edge.WindDelta<0?edge.WindCnt=e.WindCnt:edge.WindCnt=e.WindCnt+edge.WindDelta:edge.WindCnt=0===edge.WindDelta?1:edge.WindDelta:0===edge.WindDelta?edge.WindCnt=e.WindCnt<0?e.WindCnt-1:e.WindCnt+1:e.WindDelta*edge.WindDelta<0?edge.WindCnt=e.WindCnt:edge.WindCnt=e.WindCnt+edge.WindDelta,edge.WindCnt2=e.WindCnt2,e=e.NextInAEL;if(this.IsEvenOddAltFillType(edge))for(;e!==edge;)0!==e.WindDelta&&(edge.WindCnt2=0===edge.WindCnt2?1:0),e=e.NextInAEL;else for(;e!==edge;)edge.WindCnt2+=e.WindDelta,e=e.NextInAEL},ClipperLib.Clipper.prototype.AddEdgeToSEL=function(edge){null===this.m_SortedEdges?(this.m_SortedEdges=edge,edge.PrevInSEL=null,edge.NextInSEL=null):(edge.NextInSEL=this.m_SortedEdges,edge.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=edge,this.m_SortedEdges=edge)},ClipperLib.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,null===e.v)return!1;var oldE=e.v;return this.m_SortedEdges=e.v.NextInSEL,null!==this.m_SortedEdges&&(this.m_SortedEdges.PrevInSEL=null),oldE.NextInSEL=null,oldE.PrevInSEL=null,!0},ClipperLib.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;null!==e;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},ClipperLib.Clipper.prototype.SwapPositionsInSEL=function(edge1,edge2){if(!(null===edge1.NextInSEL&&null===edge1.PrevInSEL||null===edge2.NextInSEL&&null===edge2.PrevInSEL)){if(edge1.NextInSEL===edge2)null!==(next=edge2.NextInSEL)&&(next.PrevInSEL=edge1),null!==(prev=edge1.PrevInSEL)&&(prev.NextInSEL=edge2),edge2.PrevInSEL=prev,edge2.NextInSEL=edge1,edge1.PrevInSEL=edge2,edge1.NextInSEL=next;else if(edge2.NextInSEL===edge1)null!==(next=edge1.NextInSEL)&&(next.PrevInSEL=edge2),null!==(prev=edge2.PrevInSEL)&&(prev.NextInSEL=edge1),edge1.PrevInSEL=prev,edge1.NextInSEL=edge2,edge2.PrevInSEL=edge1,edge2.NextInSEL=next;else{var next=edge1.NextInSEL,prev=edge1.PrevInSEL;edge1.NextInSEL=edge2.NextInSEL,null!==edge1.NextInSEL&&(edge1.NextInSEL.PrevInSEL=edge1),edge1.PrevInSEL=edge2.PrevInSEL,null!==edge1.PrevInSEL&&(edge1.PrevInSEL.NextInSEL=edge1),edge2.NextInSEL=next,null!==edge2.NextInSEL&&(edge2.NextInSEL.PrevInSEL=edge2),edge2.PrevInSEL=prev,null!==edge2.PrevInSEL&&(edge2.PrevInSEL.NextInSEL=edge2)}null===edge1.PrevInSEL?this.m_SortedEdges=edge1:null===edge2.PrevInSEL&&(this.m_SortedEdges=edge2)}},ClipperLib.Clipper.prototype.AddLocalMaxPoly=function(e1,e2,pt){this.AddOutPt(e1,pt),0===e2.WindDelta&&this.AddOutPt(e2,pt),e1.OutIdx===e2.OutIdx?(e1.OutIdx=-1,e2.OutIdx=-1):e1.OutIdx<e2.OutIdx?this.AppendPolygon(e1,e2):this.AppendPolygon(e2,e1)},ClipperLib.Clipper.prototype.AddLocalMinPoly=function(e1,e2,pt){var result,e,prevE;if(ClipperLib.ClipperBase.IsHorizontal(e2)||e1.Dx>e2.Dx?(result=this.AddOutPt(e1,pt),e2.OutIdx=e1.OutIdx,e1.Side=ClipperLib.EdgeSide.esLeft,e2.Side=ClipperLib.EdgeSide.esRight,prevE=(e=e1).PrevInAEL===e2?e2.PrevInAEL:e.PrevInAEL):(result=this.AddOutPt(e2,pt),e1.OutIdx=e2.OutIdx,e1.Side=ClipperLib.EdgeSide.esRight,e2.Side=ClipperLib.EdgeSide.esLeft,prevE=(e=e2).PrevInAEL===e1?e1.PrevInAEL:e.PrevInAEL),null!==prevE&&prevE.OutIdx>=0&&prevE.Top.Y<pt.Y&&e.Top.Y<pt.Y){var xPrev=ClipperLib.Clipper.TopX(prevE,pt.Y),xE=ClipperLib.Clipper.TopX(e,pt.Y);if(xPrev===xE&&0!==e.WindDelta&&0!==prevE.WindDelta&&ClipperLib.ClipperBase.SlopesEqual5(new ClipperLib.IntPoint2(xPrev,pt.Y),prevE.Top,new ClipperLib.IntPoint2(xE,pt.Y),e.Top,this.m_UseFullRange)){var outPt=this.AddOutPt(prevE,pt);this.AddJoin(result,outPt,e.Top)}}return result},ClipperLib.Clipper.prototype.AddOutPt=function(e,pt){if(e.OutIdx<0){(outRec=this.CreateOutRec()).IsOpen=0===e.WindDelta;var newOp=new ClipperLib.OutPt;return outRec.Pts=newOp,newOp.Idx=outRec.Idx,newOp.Pt.X=pt.X,newOp.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newOp.Pt.Z=pt.Z),newOp.Next=newOp,newOp.Prev=newOp,outRec.IsOpen||this.SetHoleState(e,outRec),e.OutIdx=outRec.Idx,newOp}var outRec,op=(outRec=this.m_PolyOuts[e.OutIdx]).Pts,ToFront=e.Side===ClipperLib.EdgeSide.esLeft;return ToFront&&ClipperLib.IntPoint.op_Equality(pt,op.Pt)?op:!ToFront&&ClipperLib.IntPoint.op_Equality(pt,op.Prev.Pt)?op.Prev:((newOp=new ClipperLib.OutPt).Idx=outRec.Idx,newOp.Pt.X=pt.X,newOp.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newOp.Pt.Z=pt.Z),newOp.Next=op,newOp.Prev=op.Prev,newOp.Prev.Next=newOp,op.Prev=newOp,ToFront&&(outRec.Pts=newOp),newOp)},ClipperLib.Clipper.prototype.GetLastOutPt=function(e){var outRec=this.m_PolyOuts[e.OutIdx];return e.Side===ClipperLib.EdgeSide.esLeft?outRec.Pts:outRec.Pts.Prev},ClipperLib.Clipper.prototype.SwapPoints=function(pt1,pt2){var tmp=new ClipperLib.IntPoint1(pt1.Value);pt1.Value.X=pt2.Value.X,pt1.Value.Y=pt2.Value.Y,ClipperLib.use_xyz&&(pt1.Value.Z=pt2.Value.Z),pt2.Value.X=tmp.X,pt2.Value.Y=tmp.Y,ClipperLib.use_xyz&&(pt2.Value.Z=tmp.Z)},ClipperLib.Clipper.prototype.HorzSegmentsOverlap=function(seg1a,seg1b,seg2a,seg2b){var tmp;return seg1a>seg1b&&(tmp=seg1a,seg1a=seg1b,seg1b=tmp),seg2a>seg2b&&(tmp=seg2a,seg2a=seg2b,seg2b=tmp),seg1a<seg2b&&seg2a<seg1b},ClipperLib.Clipper.prototype.SetHoleState=function(e,outRec){for(var e2=e.PrevInAEL,eTmp=null;null!==e2;)e2.OutIdx>=0&&0!==e2.WindDelta&&(null===eTmp?eTmp=e2:eTmp.OutIdx===e2.OutIdx&&(eTmp=null)),e2=e2.PrevInAEL;null===eTmp?(outRec.FirstLeft=null,outRec.IsHole=!1):(outRec.FirstLeft=this.m_PolyOuts[eTmp.OutIdx],outRec.IsHole=!outRec.FirstLeft.IsHole)},ClipperLib.Clipper.prototype.GetDx=function(pt1,pt2){return pt1.Y===pt2.Y?ClipperLib.ClipperBase.horizontal:(pt2.X-pt1.X)/(pt2.Y-pt1.Y)},ClipperLib.Clipper.prototype.FirstIsBottomPt=function(btmPt1,btmPt2){for(var p=btmPt1.Prev;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt1.Pt)&&p!==btmPt1;)p=p.Prev;var dx1p=Math.abs(this.GetDx(btmPt1.Pt,p.Pt));for(p=btmPt1.Next;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt1.Pt)&&p!==btmPt1;)p=p.Next;var dx1n=Math.abs(this.GetDx(btmPt1.Pt,p.Pt));for(p=btmPt2.Prev;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt2.Pt)&&p!==btmPt2;)p=p.Prev;var dx2p=Math.abs(this.GetDx(btmPt2.Pt,p.Pt));for(p=btmPt2.Next;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt2.Pt)&&p!==btmPt2;)p=p.Next;var dx2n=Math.abs(this.GetDx(btmPt2.Pt,p.Pt));return Math.max(dx1p,dx1n)===Math.max(dx2p,dx2n)&&Math.min(dx1p,dx1n)===Math.min(dx2p,dx2n)?this.Area(btmPt1)>0:dx1p>=dx2p&&dx1p>=dx2n||dx1n>=dx2p&&dx1n>=dx2n},ClipperLib.Clipper.prototype.GetBottomPt=function(pp){for(var dups=null,p=pp.Next;p!==pp;)p.Pt.Y>pp.Pt.Y?(pp=p,dups=null):p.Pt.Y===pp.Pt.Y&&p.Pt.X<=pp.Pt.X&&(p.Pt.X<pp.Pt.X?(dups=null,pp=p):p.Next!==pp&&p.Prev!==pp&&(dups=p)),p=p.Next;if(null!==dups)for(;dups!==p;)for(this.FirstIsBottomPt(p,dups)||(pp=dups),dups=dups.Next;ClipperLib.IntPoint.op_Inequality(dups.Pt,pp.Pt);)dups=dups.Next;return pp},ClipperLib.Clipper.prototype.GetLowermostRec=function(outRec1,outRec2){null===outRec1.BottomPt&&(outRec1.BottomPt=this.GetBottomPt(outRec1.Pts)),null===outRec2.BottomPt&&(outRec2.BottomPt=this.GetBottomPt(outRec2.Pts));var bPt1=outRec1.BottomPt,bPt2=outRec2.BottomPt;return bPt1.Pt.Y>bPt2.Pt.Y?outRec1:bPt1.Pt.Y<bPt2.Pt.Y?outRec2:bPt1.Pt.X<bPt2.Pt.X?outRec1:bPt1.Pt.X>bPt2.Pt.X||bPt1.Next===bPt1?outRec2:bPt2.Next===bPt2||this.FirstIsBottomPt(bPt1,bPt2)?outRec1:outRec2},ClipperLib.Clipper.prototype.OutRec1RightOfOutRec2=function(outRec1,outRec2){do{if((outRec1=outRec1.FirstLeft)===outRec2)return!0}while(null!==outRec1);return!1},ClipperLib.Clipper.prototype.GetOutRec=function(idx){for(var outrec=this.m_PolyOuts[idx];outrec!==this.m_PolyOuts[outrec.Idx];)outrec=this.m_PolyOuts[outrec.Idx];return outrec},ClipperLib.Clipper.prototype.AppendPolygon=function(e1,e2){var holeStateRec,outRec1=this.m_PolyOuts[e1.OutIdx],outRec2=this.m_PolyOuts[e2.OutIdx];holeStateRec=this.OutRec1RightOfOutRec2(outRec1,outRec2)?outRec2:this.OutRec1RightOfOutRec2(outRec2,outRec1)?outRec1:this.GetLowermostRec(outRec1,outRec2);var p1_lft=outRec1.Pts,p1_rt=p1_lft.Prev,p2_lft=outRec2.Pts,p2_rt=p2_lft.Prev;e1.Side===ClipperLib.EdgeSide.esLeft?e2.Side===ClipperLib.EdgeSide.esLeft?(this.ReversePolyPtLinks(p2_lft),p2_lft.Next=p1_lft,p1_lft.Prev=p2_lft,p1_rt.Next=p2_rt,p2_rt.Prev=p1_rt,outRec1.Pts=p2_rt):(p2_rt.Next=p1_lft,p1_lft.Prev=p2_rt,p2_lft.Prev=p1_rt,p1_rt.Next=p2_lft,outRec1.Pts=p2_lft):e2.Side===ClipperLib.EdgeSide.esRight?(this.ReversePolyPtLinks(p2_lft),p1_rt.Next=p2_rt,p2_rt.Prev=p1_rt,p2_lft.Next=p1_lft,p1_lft.Prev=p2_lft):(p1_rt.Next=p2_lft,p2_lft.Prev=p1_rt,p1_lft.Prev=p2_rt,p2_rt.Next=p1_lft),outRec1.BottomPt=null,holeStateRec===outRec2&&(outRec2.FirstLeft!==outRec1&&(outRec1.FirstLeft=outRec2.FirstLeft),outRec1.IsHole=outRec2.IsHole),outRec2.Pts=null,outRec2.BottomPt=null,outRec2.FirstLeft=outRec1;var OKIdx=e1.OutIdx,ObsoleteIdx=e2.OutIdx;e1.OutIdx=-1,e2.OutIdx=-1;for(var e=this.m_ActiveEdges;null!==e;){if(e.OutIdx===ObsoleteIdx){e.OutIdx=OKIdx,e.Side=e1.Side;break}e=e.NextInAEL}outRec2.Idx=outRec1.Idx},ClipperLib.Clipper.prototype.ReversePolyPtLinks=function(pp){if(null!==pp){var pp1,pp2;pp1=pp;do{pp2=pp1.Next,pp1.Next=pp1.Prev,pp1.Prev=pp2,pp1=pp2}while(pp1!==pp)}},ClipperLib.Clipper.SwapSides=function(edge1,edge2){var side=edge1.Side;edge1.Side=edge2.Side,edge2.Side=side},ClipperLib.Clipper.SwapPolyIndexes=function(edge1,edge2){var outIdx=edge1.OutIdx;edge1.OutIdx=edge2.OutIdx,edge2.OutIdx=outIdx},ClipperLib.Clipper.prototype.IntersectEdges=function(e1,e2,pt){var e1Contributing=e1.OutIdx>=0,e2Contributing=e2.OutIdx>=0;if(ClipperLib.use_xyz&&this.SetZ(pt,e1,e2),!ClipperLib.use_lines||0!==e1.WindDelta&&0!==e2.WindDelta){if(e1.PolyTyp===e2.PolyTyp)if(this.IsEvenOddFillType(e1)){var oldE1WindCnt=e1.WindCnt;e1.WindCnt=e2.WindCnt,e2.WindCnt=oldE1WindCnt}else e1.WindCnt+e2.WindDelta===0?e1.WindCnt=-e1.WindCnt:e1.WindCnt+=e2.WindDelta,e2.WindCnt-e1.WindDelta==0?e2.WindCnt=-e2.WindCnt:e2.WindCnt-=e1.WindDelta;else this.IsEvenOddFillType(e2)?e1.WindCnt2=0===e1.WindCnt2?1:0:e1.WindCnt2+=e2.WindDelta,this.IsEvenOddFillType(e1)?e2.WindCnt2=0===e2.WindCnt2?1:0:e2.WindCnt2-=e1.WindDelta;var e1FillType,e2FillType,e1FillType2,e2FillType2,e1Wc,e2Wc;switch(e1.PolyTyp===ClipperLib.PolyType.ptSubject?(e1FillType=this.m_SubjFillType,e1FillType2=this.m_ClipFillType):(e1FillType=this.m_ClipFillType,e1FillType2=this.m_SubjFillType),e2.PolyTyp===ClipperLib.PolyType.ptSubject?(e2FillType=this.m_SubjFillType,e2FillType2=this.m_ClipFillType):(e2FillType=this.m_ClipFillType,e2FillType2=this.m_SubjFillType),e1FillType){case ClipperLib.PolyFillType.pftPositive:e1Wc=e1.WindCnt;break;case ClipperLib.PolyFillType.pftNegative:e1Wc=-e1.WindCnt;break;default:e1Wc=Math.abs(e1.WindCnt)}switch(e2FillType){case ClipperLib.PolyFillType.pftPositive:e2Wc=e2.WindCnt;break;case ClipperLib.PolyFillType.pftNegative:e2Wc=-e2.WindCnt;break;default:e2Wc=Math.abs(e2.WindCnt)}if(e1Contributing&&e2Contributing)0!==e1Wc&&1!==e1Wc||0!==e2Wc&&1!==e2Wc||e1.PolyTyp!==e2.PolyTyp&&this.m_ClipType!==ClipperLib.ClipType.ctXor?this.AddLocalMaxPoly(e1,e2,pt):(this.AddOutPt(e1,pt),this.AddOutPt(e2,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(e1Contributing)0!==e2Wc&&1!==e2Wc||(this.AddOutPt(e1,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(e2Contributing)0!==e1Wc&&1!==e1Wc||(this.AddOutPt(e2,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(!(0!==e1Wc&&1!==e1Wc||0!==e2Wc&&1!==e2Wc)){var e1Wc2,e2Wc2;switch(e1FillType2){case ClipperLib.PolyFillType.pftPositive:e1Wc2=e1.WindCnt2;break;case ClipperLib.PolyFillType.pftNegative:e1Wc2=-e1.WindCnt2;break;default:e1Wc2=Math.abs(e1.WindCnt2)}switch(e2FillType2){case ClipperLib.PolyFillType.pftPositive:e2Wc2=e2.WindCnt2;break;case ClipperLib.PolyFillType.pftNegative:e2Wc2=-e2.WindCnt2;break;default:e2Wc2=Math.abs(e2.WindCnt2)}if(e1.PolyTyp!==e2.PolyTyp)this.AddLocalMinPoly(e1,e2,pt);else if(1===e1Wc&&1===e2Wc)switch(this.m_ClipType){case ClipperLib.ClipType.ctIntersection:e1Wc2>0&&e2Wc2>0&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctUnion:e1Wc2<=0&&e2Wc2<=0&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctDifference:(e1.PolyTyp===ClipperLib.PolyType.ptClip&&e1Wc2>0&&e2Wc2>0||e1.PolyTyp===ClipperLib.PolyType.ptSubject&&e1Wc2<=0&&e2Wc2<=0)&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctXor:this.AddLocalMinPoly(e1,e2,pt)}else ClipperLib.Clipper.SwapSides(e1,e2)}}else{if(0===e1.WindDelta&&0===e2.WindDelta)return;e1.PolyTyp===e2.PolyTyp&&e1.WindDelta!==e2.WindDelta&&this.m_ClipType===ClipperLib.ClipType.ctUnion?0===e1.WindDelta?e2Contributing&&(this.AddOutPt(e1,pt),e1Contributing&&(e1.OutIdx=-1)):e1Contributing&&(this.AddOutPt(e2,pt),e2Contributing&&(e2.OutIdx=-1)):e1.PolyTyp!==e2.PolyTyp&&(0!==e1.WindDelta||1!==Math.abs(e2.WindCnt)||this.m_ClipType===ClipperLib.ClipType.ctUnion&&0!==e2.WindCnt2?0!==e2.WindDelta||1!==Math.abs(e1.WindCnt)||this.m_ClipType===ClipperLib.ClipType.ctUnion&&0!==e1.WindCnt2||(this.AddOutPt(e2,pt),e2Contributing&&(e2.OutIdx=-1)):(this.AddOutPt(e1,pt),e1Contributing&&(e1.OutIdx=-1)))}},ClipperLib.Clipper.prototype.DeleteFromSEL=function(e){var SelPrev=e.PrevInSEL,SelNext=e.NextInSEL;null===SelPrev&&null===SelNext&&e!==this.m_SortedEdges||(null!==SelPrev?SelPrev.NextInSEL=SelNext:this.m_SortedEdges=SelNext,null!==SelNext&&(SelNext.PrevInSEL=SelPrev),e.NextInSEL=null,e.PrevInSEL=null)},ClipperLib.Clipper.prototype.ProcessHorizontals=function(){for(var horzEdge={};this.PopEdgeFromSEL(horzEdge);)this.ProcessHorizontal(horzEdge.v)},ClipperLib.Clipper.prototype.GetHorzDirection=function(HorzEdge,$var){HorzEdge.Bot.X<HorzEdge.Top.X?($var.Left=HorzEdge.Bot.X,$var.Right=HorzEdge.Top.X,$var.Dir=ClipperLib.Direction.dLeftToRight):($var.Left=HorzEdge.Top.X,$var.Right=HorzEdge.Bot.X,$var.Dir=ClipperLib.Direction.dRightToLeft)},ClipperLib.Clipper.prototype.ProcessHorizontal=function(horzEdge){var $var={Dir:null,Left:null,Right:null};this.GetHorzDirection(horzEdge,$var);for(var dir=$var.Dir,horzLeft=$var.Left,horzRight=$var.Right,IsOpen=0===horzEdge.WindDelta,eLastHorz=horzEdge,eMaxPair=null;null!==eLastHorz.NextInLML&&ClipperLib.ClipperBase.IsHorizontal(eLastHorz.NextInLML);)eLastHorz=eLastHorz.NextInLML;null===eLastHorz.NextInLML&&(eMaxPair=this.GetMaximaPair(eLastHorz));var currMax=this.m_Maxima;if(null!==currMax)if(dir===ClipperLib.Direction.dLeftToRight){for(;null!==currMax&&currMax.X<=horzEdge.Bot.X;)currMax=currMax.Next;null!==currMax&&currMax.X>=eLastHorz.Top.X&&(currMax=null)}else{for(;null!==currMax.Next&&currMax.Next.X<horzEdge.Bot.X;)currMax=currMax.Next;currMax.X<=eLastHorz.Top.X&&(currMax=null)}for(var op1=null;;){for(var IsLastHorz=horzEdge===eLastHorz,e=this.GetNextInAEL(horzEdge,dir);null!==e;){if(null!==currMax)if(dir===ClipperLib.Direction.dLeftToRight)for(;null!==currMax&&currMax.X<e.Curr.X;)horzEdge.OutIdx>=0&&!IsOpen&&this.AddOutPt(horzEdge,new ClipperLib.IntPoint2(currMax.X,horzEdge.Bot.Y)),currMax=currMax.Next;else for(;null!==currMax&&currMax.X>e.Curr.X;)horzEdge.OutIdx>=0&&!IsOpen&&this.AddOutPt(horzEdge,new ClipperLib.IntPoint2(currMax.X,horzEdge.Bot.Y)),currMax=currMax.Prev;if(dir===ClipperLib.Direction.dLeftToRight&&e.Curr.X>horzRight||dir===ClipperLib.Direction.dRightToLeft&&e.Curr.X<horzLeft)break;if(e.Curr.X===horzEdge.Top.X&&null!==horzEdge.NextInLML&&e.Dx<horzEdge.NextInLML.Dx)break;if(horzEdge.OutIdx>=0&&!IsOpen){ClipperLib.use_xyz&&(dir===ClipperLib.Direction.dLeftToRight?this.SetZ(e.Curr,horzEdge,e):this.SetZ(e.Curr,e,horzEdge)),op1=this.AddOutPt(horzEdge,e.Curr);for(var eNextHorz=this.m_SortedEdges;null!==eNextHorz;){if(eNextHorz.OutIdx>=0&&this.HorzSegmentsOverlap(horzEdge.Bot.X,horzEdge.Top.X,eNextHorz.Bot.X,eNextHorz.Top.X)){var op2=this.GetLastOutPt(eNextHorz);this.AddJoin(op2,op1,eNextHorz.Top)}eNextHorz=eNextHorz.NextInSEL}this.AddGhostJoin(op1,horzEdge.Bot)}if(e===eMaxPair&&IsLastHorz)return horzEdge.OutIdx>=0&&this.AddLocalMaxPoly(horzEdge,eMaxPair,horzEdge.Top),this.DeleteFromAEL(horzEdge),void this.DeleteFromAEL(eMaxPair);if(dir===ClipperLib.Direction.dLeftToRight){var Pt=new ClipperLib.IntPoint2(e.Curr.X,horzEdge.Curr.Y);this.IntersectEdges(horzEdge,e,Pt)}else Pt=new ClipperLib.IntPoint2(e.Curr.X,horzEdge.Curr.Y),this.IntersectEdges(e,horzEdge,Pt);var eNext=this.GetNextInAEL(e,dir);this.SwapPositionsInAEL(horzEdge,e),e=eNext}if(null===horzEdge.NextInLML||!ClipperLib.ClipperBase.IsHorizontal(horzEdge.NextInLML))break;(horzEdge=this.UpdateEdgeIntoAEL(horzEdge)).OutIdx>=0&&this.AddOutPt(horzEdge,horzEdge.Bot),$var={Dir:dir,Left:horzLeft,Right:horzRight},this.GetHorzDirection(horzEdge,$var),dir=$var.Dir,horzLeft=$var.Left,horzRight=$var.Right}if(horzEdge.OutIdx>=0&&null===op1){for(op1=this.GetLastOutPt(horzEdge),eNextHorz=this.m_SortedEdges;null!==eNextHorz;)eNextHorz.OutIdx>=0&&this.HorzSegmentsOverlap(horzEdge.Bot.X,horzEdge.Top.X,eNextHorz.Bot.X,eNextHorz.Top.X)&&(op2=this.GetLastOutPt(eNextHorz),this.AddJoin(op2,op1,eNextHorz.Top)),eNextHorz=eNextHorz.NextInSEL;this.AddGhostJoin(op1,horzEdge.Top)}if(null!==horzEdge.NextInLML)if(horzEdge.OutIdx>=0){if(op1=this.AddOutPt(horzEdge,horzEdge.Top),0===(horzEdge=this.UpdateEdgeIntoAEL(horzEdge)).WindDelta)return;var ePrev=horzEdge.PrevInAEL;eNext=horzEdge.NextInAEL,null!==ePrev&&ePrev.Curr.X===horzEdge.Bot.X&&ePrev.Curr.Y===horzEdge.Bot.Y&&0===ePrev.WindDelta&&ePrev.OutIdx>=0&&ePrev.Curr.Y>ePrev.Top.Y&&ClipperLib.ClipperBase.SlopesEqual3(horzEdge,ePrev,this.m_UseFullRange)?(op2=this.AddOutPt(ePrev,horzEdge.Bot),this.AddJoin(op1,op2,horzEdge.Top)):null!==eNext&&eNext.Curr.X===horzEdge.Bot.X&&eNext.Curr.Y===horzEdge.Bot.Y&&0!==eNext.WindDelta&&eNext.OutIdx>=0&&eNext.Curr.Y>eNext.Top.Y&&ClipperLib.ClipperBase.SlopesEqual3(horzEdge,eNext,this.m_UseFullRange)&&(op2=this.AddOutPt(eNext,horzEdge.Bot),this.AddJoin(op1,op2,horzEdge.Top))}else horzEdge=this.UpdateEdgeIntoAEL(horzEdge);else horzEdge.OutIdx>=0&&this.AddOutPt(horzEdge,horzEdge.Top),this.DeleteFromAEL(horzEdge)},ClipperLib.Clipper.prototype.GetNextInAEL=function(e,Direction){return Direction===ClipperLib.Direction.dLeftToRight?e.NextInAEL:e.PrevInAEL},ClipperLib.Clipper.prototype.IsMinima=function(e){return null!==e&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},ClipperLib.Clipper.prototype.IsMaxima=function(e,Y){return null!==e&&e.Top.Y===Y&&null===e.NextInLML},ClipperLib.Clipper.prototype.IsIntermediate=function(e,Y){return e.Top.Y===Y&&null!==e.NextInLML},ClipperLib.Clipper.prototype.GetMaximaPair=function(e){return ClipperLib.IntPoint.op_Equality(e.Next.Top,e.Top)&&null===e.Next.NextInLML?e.Next:ClipperLib.IntPoint.op_Equality(e.Prev.Top,e.Top)&&null===e.Prev.NextInLML?e.Prev:null},ClipperLib.Clipper.prototype.GetMaximaPairEx=function(e){var result=this.GetMaximaPair(e);return null===result||result.OutIdx===ClipperLib.ClipperBase.Skip||result.NextInAEL===result.PrevInAEL&&!ClipperLib.ClipperBase.IsHorizontal(result)?null:result},ClipperLib.Clipper.prototype.ProcessIntersections=function(topY){if(null===this.m_ActiveEdges)return!0;try{if(this.BuildIntersectList(topY),0===this.m_IntersectList.length)return!0;if(1!==this.m_IntersectList.length&&!this.FixupIntersectionOrder())return!1;this.ProcessIntersectList()}catch($$e2){this.m_SortedEdges=null,this.m_IntersectList.length=0,ClipperLib.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0},ClipperLib.Clipper.prototype.BuildIntersectList=function(topY){if(null!==this.m_ActiveEdges){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;null!==e;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e.Curr.X=ClipperLib.Clipper.TopX(e,topY),e=e.NextInAEL;for(var isModified=!0;isModified&&null!==this.m_SortedEdges;){for(isModified=!1,e=this.m_SortedEdges;null!==e.NextInSEL;){var eNext=e.NextInSEL,pt=new ClipperLib.IntPoint0;if(e.Curr.X>eNext.Curr.X){this.IntersectPoint(e,eNext,pt),pt.Y<topY&&(pt=new ClipperLib.IntPoint2(ClipperLib.Clipper.TopX(e,topY),topY));var newNode=new ClipperLib.IntersectNode;newNode.Edge1=e,newNode.Edge2=eNext,newNode.Pt.X=pt.X,newNode.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newNode.Pt.Z=pt.Z),this.m_IntersectList.push(newNode),this.SwapPositionsInSEL(e,eNext),isModified=!0}else e=eNext}if(null===e.PrevInSEL)break;e.PrevInSEL.NextInSEL=null}this.m_SortedEdges=null}},ClipperLib.Clipper.prototype.EdgesAdjacent=function(inode){return inode.Edge1.NextInSEL===inode.Edge2||inode.Edge1.PrevInSEL===inode.Edge2},ClipperLib.Clipper.IntersectNodeSort=function(node1,node2){return node2.Pt.Y-node1.Pt.Y},ClipperLib.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var cnt=this.m_IntersectList.length,i=0;i<cnt;i++){if(!this.EdgesAdjacent(this.m_IntersectList[i])){for(var j=i+1;j<cnt&&!this.EdgesAdjacent(this.m_IntersectList[j]);)j++;if(j===cnt)return!1;var tmp=this.m_IntersectList[i];this.m_IntersectList[i]=this.m_IntersectList[j],this.m_IntersectList[j]=tmp}this.SwapPositionsInSEL(this.m_IntersectList[i].Edge1,this.m_IntersectList[i].Edge2)}return!0},ClipperLib.Clipper.prototype.ProcessIntersectList=function(){for(var i=0,ilen=this.m_IntersectList.length;i<ilen;i++){var iNode=this.m_IntersectList[i];this.IntersectEdges(iNode.Edge1,iNode.Edge2,iNode.Pt),this.SwapPositionsInAEL(iNode.Edge1,iNode.Edge2)}this.m_IntersectList.length=0},browser.msie?ClipperLib.Clipper.Round=function(a){return a<0?Math.ceil(a-.5):Math.round(a)}:browser.chromium?ClipperLib.Clipper.Round=function(a){return a<0?-Math.round(Math.abs(a)):Math.round(a)}:browser.safari?ClipperLib.Clipper.Round=function(a){return a<0?(a-=.5)<-2147483648?Math.ceil(a):0|a:(a+=.5)>2147483647?Math.floor(a):0|a}:ClipperLib.Clipper.Round=function(a){return a<0?Math.ceil(a-.5):Math.floor(a+.5)},ClipperLib.Clipper.TopX=function(edge,currentY){return currentY===edge.Top.Y?edge.Top.X:edge.Bot.X+ClipperLib.Clipper.Round(edge.Dx*(currentY-edge.Bot.Y))},ClipperLib.Clipper.prototype.IntersectPoint=function(edge1,edge2,ip){var b1,b2;if(ip.X=0,ip.Y=0,edge1.Dx===edge2.Dx)return ip.Y=edge1.Curr.Y,void(ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y));if(0===edge1.Delta.X)ip.X=edge1.Bot.X,ClipperLib.ClipperBase.IsHorizontal(edge2)?ip.Y=edge2.Bot.Y:(b2=edge2.Bot.Y-edge2.Bot.X/edge2.Dx,ip.Y=ClipperLib.Clipper.Round(ip.X/edge2.Dx+b2));else if(0===edge2.Delta.X)ip.X=edge2.Bot.X,ClipperLib.ClipperBase.IsHorizontal(edge1)?ip.Y=edge1.Bot.Y:(b1=edge1.Bot.Y-edge1.Bot.X/edge1.Dx,ip.Y=ClipperLib.Clipper.Round(ip.X/edge1.Dx+b1));else{b1=edge1.Bot.X-edge1.Bot.Y*edge1.Dx;var q=((b2=edge2.Bot.X-edge2.Bot.Y*edge2.Dx)-b1)/(edge1.Dx-edge2.Dx);ip.Y=ClipperLib.Clipper.Round(q),Math.abs(edge1.Dx)<Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.Round(edge1.Dx*q+b1):ip.X=ClipperLib.Clipper.Round(edge2.Dx*q+b2)}if(ip.Y<edge1.Top.Y||ip.Y<edge2.Top.Y){if(edge1.Top.Y>edge2.Top.Y)return ip.Y=edge1.Top.Y,ip.X=ClipperLib.Clipper.TopX(edge2,edge1.Top.Y),ip.X<edge1.Top.X;ip.Y=edge2.Top.Y,Math.abs(edge1.Dx)<Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y):ip.X=ClipperLib.Clipper.TopX(edge2,ip.Y)}ip.Y>edge1.Curr.Y&&(ip.Y=edge1.Curr.Y,Math.abs(edge1.Dx)>Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.TopX(edge2,ip.Y):ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y))},ClipperLib.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(topY){for(var e=this.m_ActiveEdges;null!==e;){var IsMaximaEdge=this.IsMaxima(e,topY);if(IsMaximaEdge){var eMaxPair=this.GetMaximaPairEx(e);IsMaximaEdge=null===eMaxPair||!ClipperLib.ClipperBase.IsHorizontal(eMaxPair)}if(IsMaximaEdge){this.StrictlySimple&&this.InsertMaxima(e.Top.X);var ePrev=e.PrevInAEL;this.DoMaxima(e),e=null===ePrev?this.m_ActiveEdges:ePrev.NextInAEL}else{if(this.IsIntermediate(e,topY)&&ClipperLib.ClipperBase.IsHorizontal(e.NextInLML)?((e=this.UpdateEdgeIntoAEL(e)).OutIdx>=0&&this.AddOutPt(e,e.Bot),this.AddEdgeToSEL(e)):(e.Curr.X=ClipperLib.Clipper.TopX(e,topY),e.Curr.Y=topY),ClipperLib.use_xyz&&(e.Top.Y===topY?e.Curr.Z=e.Top.Z:e.Bot.Y===topY?e.Curr.Z=e.Bot.Z:e.Curr.Z=0),this.StrictlySimple&&(ePrev=e.PrevInAEL,e.OutIdx>=0&&0!==e.WindDelta&&null!==ePrev&&ePrev.OutIdx>=0&&ePrev.Curr.X===e.Curr.X&&0!==ePrev.WindDelta)){var ip=new ClipperLib.IntPoint1(e.Curr);ClipperLib.use_xyz&&this.SetZ(ip,ePrev,e);var op=this.AddOutPt(ePrev,ip),op2=this.AddOutPt(e,ip);this.AddJoin(op,op2,ip)}e=e.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,e=this.m_ActiveEdges;null!==e;){if(this.IsIntermediate(e,topY)){op=null,e.OutIdx>=0&&(op=this.AddOutPt(e,e.Top)),ePrev=(e=this.UpdateEdgeIntoAEL(e)).PrevInAEL;var eNext=e.NextInAEL;null!==ePrev&&ePrev.Curr.X===e.Bot.X&&ePrev.Curr.Y===e.Bot.Y&&null!==op&&ePrev.OutIdx>=0&&ePrev.Curr.Y===ePrev.Top.Y&&ClipperLib.ClipperBase.SlopesEqual5(e.Curr,e.Top,ePrev.Curr,ePrev.Top,this.m_UseFullRange)&&0!==e.WindDelta&&0!==ePrev.WindDelta?(op2=this.AddOutPt(ePrev2,e.Bot),this.AddJoin(op,op2,e.Top)):null!==eNext&&eNext.Curr.X===e.Bot.X&&eNext.Curr.Y===e.Bot.Y&&null!==op&&eNext.OutIdx>=0&&eNext.Curr.Y===eNext.Top.Y&&ClipperLib.ClipperBase.SlopesEqual5(e.Curr,e.Top,eNext.Curr,eNext.Top,this.m_UseFullRange)&&0!==e.WindDelta&&0!==eNext.WindDelta&&(op2=this.AddOutPt(eNext,e.Bot),this.AddJoin(op,op2,e.Top))}e=e.NextInAEL}},ClipperLib.Clipper.prototype.DoMaxima=function(e){var eMaxPair=this.GetMaximaPairEx(e);if(null===eMaxPair)return e.OutIdx>=0&&this.AddOutPt(e,e.Top),void this.DeleteFromAEL(e);for(var eNext=e.NextInAEL;null!==eNext&&eNext!==eMaxPair;)this.IntersectEdges(e,eNext,e.Top),this.SwapPositionsInAEL(e,eNext),eNext=e.NextInAEL;-1===e.OutIdx&&-1===eMaxPair.OutIdx?(this.DeleteFromAEL(e),this.DeleteFromAEL(eMaxPair)):e.OutIdx>=0&&eMaxPair.OutIdx>=0?(e.OutIdx>=0&&this.AddLocalMaxPoly(e,eMaxPair,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(eMaxPair)):ClipperLib.use_lines&&0===e.WindDelta?(e.OutIdx>=0&&(this.AddOutPt(e,e.Top),e.OutIdx=ClipperLib.ClipperBase.Unassigned),this.DeleteFromAEL(e),eMaxPair.OutIdx>=0&&(this.AddOutPt(eMaxPair,e.Top),eMaxPair.OutIdx=ClipperLib.ClipperBase.Unassigned),this.DeleteFromAEL(eMaxPair)):ClipperLib.Error("DoMaxima error")},ClipperLib.Clipper.ReversePaths=function(polys){for(var i=0,len=polys.length;i<len;i++)polys[i].reverse()},ClipperLib.Clipper.Orientation=function(poly){return ClipperLib.Clipper.Area(poly)>=0},ClipperLib.Clipper.prototype.PointCount=function(pts){if(null===pts)return 0;var result=0,p=pts;do{result++,p=p.Next}while(p!==pts);return result},ClipperLib.Clipper.prototype.BuildResult=function(polyg){ClipperLib.Clear(polyg);for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;i++){var outRec=this.m_PolyOuts[i];if(null!==outRec.Pts){var p=outRec.Pts.Prev,cnt=this.PointCount(p);if(!(cnt<2)){for(var pg=new Array(cnt),j=0;j<cnt;j++)pg[j]=p.Pt,p=p.Prev;polyg.push(pg)}}}},ClipperLib.Clipper.prototype.BuildResult2=function(polytree){polytree.Clear();for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;i++){var outRec=this.m_PolyOuts[i],cnt=this.PointCount(outRec.Pts);if(!(outRec.IsOpen&&cnt<2||!outRec.IsOpen&&cnt<3)){this.FixHoleLinkage(outRec);var pn=new ClipperLib.PolyNode;polytree.m_AllPolys.push(pn),outRec.PolyNode=pn,pn.m_polygon.length=cnt;for(var op=outRec.Pts.Prev,j=0;j<cnt;j++)pn.m_polygon[j]=op.Pt,op=op.Prev}}for(i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).PolyNode&&(outRec.IsOpen?(outRec.PolyNode.IsOpen=!0,polytree.AddChild(outRec.PolyNode)):null!==outRec.FirstLeft&&null!==outRec.FirstLeft.PolyNode?outRec.FirstLeft.PolyNode.AddChild(outRec.PolyNode):polytree.AddChild(outRec.PolyNode))},ClipperLib.Clipper.prototype.FixupOutPolyline=function(outRec){for(var pp=outRec.Pts,lastPP=pp.Prev;pp!==lastPP;)if(pp=pp.Next,ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Prev.Pt)){pp===lastPP&&(lastPP=pp.Prev);var tmpPP=pp.Prev;tmpPP.Next=pp.Next,pp.Next.Prev=tmpPP,pp=tmpPP}pp===pp.Prev&&(outRec.Pts=null)},ClipperLib.Clipper.prototype.FixupOutPolygon=function(outRec){var lastOK=null;outRec.BottomPt=null;for(var pp=outRec.Pts,preserveCol=this.PreserveCollinear||this.StrictlySimple;;){if(pp.Prev===pp||pp.Prev===pp.Next)return void(outRec.Pts=null);if(ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Next.Pt)||ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Prev.Pt)||ClipperLib.ClipperBase.SlopesEqual4(pp.Prev.Pt,pp.Pt,pp.Next.Pt,this.m_UseFullRange)&&(!preserveCol||!this.Pt2IsBetweenPt1AndPt3(pp.Prev.Pt,pp.Pt,pp.Next.Pt)))lastOK=null,pp.Prev.Next=pp.Next,pp.Next.Prev=pp.Prev,pp=pp.Prev;else{if(pp===lastOK)break;null===lastOK&&(lastOK=pp),pp=pp.Next}}outRec.Pts=pp},ClipperLib.Clipper.prototype.DupOutPt=function(outPt,InsertAfter){var result=new ClipperLib.OutPt;return result.Pt.X=outPt.Pt.X,result.Pt.Y=outPt.Pt.Y,ClipperLib.use_xyz&&(result.Pt.Z=outPt.Pt.Z),result.Idx=outPt.Idx,InsertAfter?(result.Next=outPt.Next,result.Prev=outPt,outPt.Next.Prev=result,outPt.Next=result):(result.Prev=outPt.Prev,result.Next=outPt,outPt.Prev.Next=result,outPt.Prev=result),result},ClipperLib.Clipper.prototype.GetOverlap=function(a1,a2,b1,b2,$val){return a1<a2?b1<b2?($val.Left=Math.max(a1,b1),$val.Right=Math.min(a2,b2)):($val.Left=Math.max(a1,b2),$val.Right=Math.min(a2,b1)):b1<b2?($val.Left=Math.max(a2,b1),$val.Right=Math.min(a1,b2)):($val.Left=Math.max(a2,b2),$val.Right=Math.min(a1,b1)),$val.Left<$val.Right},ClipperLib.Clipper.prototype.JoinHorz=function(op1,op1b,op2,op2b,Pt,DiscardLeft){var Dir1=op1.Pt.X>op1b.Pt.X?ClipperLib.Direction.dRightToLeft:ClipperLib.Direction.dLeftToRight,Dir2=op2.Pt.X>op2b.Pt.X?ClipperLib.Direction.dRightToLeft:ClipperLib.Direction.dLeftToRight;if(Dir1===Dir2)return!1;if(Dir1===ClipperLib.Direction.dLeftToRight){for(;op1.Next.Pt.X<=Pt.X&&op1.Next.Pt.X>=op1.Pt.X&&op1.Next.Pt.Y===Pt.Y;)op1=op1.Next;DiscardLeft&&op1.Pt.X!==Pt.X&&(op1=op1.Next),op1b=this.DupOutPt(op1,!DiscardLeft),ClipperLib.IntPoint.op_Inequality(op1b.Pt,Pt)&&((op1=op1b).Pt.X=Pt.X,op1.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op1.Pt.Z=Pt.Z),op1b=this.DupOutPt(op1,!DiscardLeft))}else{for(;op1.Next.Pt.X>=Pt.X&&op1.Next.Pt.X<=op1.Pt.X&&op1.Next.Pt.Y===Pt.Y;)op1=op1.Next;DiscardLeft||op1.Pt.X===Pt.X||(op1=op1.Next),op1b=this.DupOutPt(op1,DiscardLeft),ClipperLib.IntPoint.op_Inequality(op1b.Pt,Pt)&&((op1=op1b).Pt.X=Pt.X,op1.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op1.Pt.Z=Pt.Z),op1b=this.DupOutPt(op1,DiscardLeft))}if(Dir2===ClipperLib.Direction.dLeftToRight){for(;op2.Next.Pt.X<=Pt.X&&op2.Next.Pt.X>=op2.Pt.X&&op2.Next.Pt.Y===Pt.Y;)op2=op2.Next;DiscardLeft&&op2.Pt.X!==Pt.X&&(op2=op2.Next),op2b=this.DupOutPt(op2,!DiscardLeft),ClipperLib.IntPoint.op_Inequality(op2b.Pt,Pt)&&((op2=op2b).Pt.X=Pt.X,op2.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op2.Pt.Z=Pt.Z),op2b=this.DupOutPt(op2,!DiscardLeft))}else{for(;op2.Next.Pt.X>=Pt.X&&op2.Next.Pt.X<=op2.Pt.X&&op2.Next.Pt.Y===Pt.Y;)op2=op2.Next;DiscardLeft||op2.Pt.X===Pt.X||(op2=op2.Next),op2b=this.DupOutPt(op2,DiscardLeft),ClipperLib.IntPoint.op_Inequality(op2b.Pt,Pt)&&((op2=op2b).Pt.X=Pt.X,op2.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op2.Pt.Z=Pt.Z),op2b=this.DupOutPt(op2,DiscardLeft))}return Dir1===ClipperLib.Direction.dLeftToRight===DiscardLeft?(op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b):(op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b),!0},ClipperLib.Clipper.prototype.JoinPoints=function(j,outRec1,outRec2){var op1=j.OutPt1,op1b=new ClipperLib.OutPt,op2=j.OutPt2,op2b=new ClipperLib.OutPt,isHorizontal=j.OutPt1.Pt.Y===j.OffPt.Y;if(isHorizontal&&ClipperLib.IntPoint.op_Equality(j.OffPt,j.OutPt1.Pt)&&ClipperLib.IntPoint.op_Equality(j.OffPt,j.OutPt2.Pt)){if(outRec1!==outRec2)return!1;for(op1b=j.OutPt1.Next;op1b!==op1&&ClipperLib.IntPoint.op_Equality(op1b.Pt,j.OffPt);)op1b=op1b.Next;var reverse1=op1b.Pt.Y>j.OffPt.Y;for(op2b=j.OutPt2.Next;op2b!==op2&&ClipperLib.IntPoint.op_Equality(op2b.Pt,j.OffPt);)op2b=op2b.Next;return reverse1!==op2b.Pt.Y>j.OffPt.Y&&(reverse1?(op1b=this.DupOutPt(op1,!1),op2b=this.DupOutPt(op2,!0),op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b,j.OutPt1=op1,j.OutPt2=op1b,!0):(op1b=this.DupOutPt(op1,!0),op2b=this.DupOutPt(op2,!1),op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b,j.OutPt1=op1,j.OutPt2=op1b,!0))}if(isHorizontal){for(op1b=op1;op1.Prev.Pt.Y===op1.Pt.Y&&op1.Prev!==op1b&&op1.Prev!==op2;)op1=op1.Prev;for(;op1b.Next.Pt.Y===op1b.Pt.Y&&op1b.Next!==op1&&op1b.Next!==op2;)op1b=op1b.Next;if(op1b.Next===op1||op1b.Next===op2)return!1;for(op2b=op2;op2.Prev.Pt.Y===op2.Pt.Y&&op2.Prev!==op2b&&op2.Prev!==op1b;)op2=op2.Prev;for(;op2b.Next.Pt.Y===op2b.Pt.Y&&op2b.Next!==op2&&op2b.Next!==op1;)op2b=op2b.Next;if(op2b.Next===op2||op2b.Next===op1)return!1;var $val={Left:null,Right:null};if(!this.GetOverlap(op1.Pt.X,op1b.Pt.X,op2.Pt.X,op2b.Pt.X,$val))return!1;var DiscardLeftSide,Left=$val.Left,Right=$val.Right,Pt=new ClipperLib.IntPoint0;return op1.Pt.X>=Left&&op1.Pt.X<=Right?(Pt.X=op1.Pt.X,Pt.Y=op1.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op1.Pt.Z),DiscardLeftSide=op1.Pt.X>op1b.Pt.X):op2.Pt.X>=Left&&op2.Pt.X<=Right?(Pt.X=op2.Pt.X,Pt.Y=op2.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op2.Pt.Z),DiscardLeftSide=op2.Pt.X>op2b.Pt.X):op1b.Pt.X>=Left&&op1b.Pt.X<=Right?(Pt.X=op1b.Pt.X,Pt.Y=op1b.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op1b.Pt.Z),DiscardLeftSide=op1b.Pt.X>op1.Pt.X):(Pt.X=op2b.Pt.X,Pt.Y=op2b.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op2b.Pt.Z),DiscardLeftSide=op2b.Pt.X>op2.Pt.X),j.OutPt1=op1,j.OutPt2=op2,this.JoinHorz(op1,op1b,op2,op2b,Pt,DiscardLeftSide)}for(op1b=op1.Next;ClipperLib.IntPoint.op_Equality(op1b.Pt,op1.Pt)&&op1b!==op1;)op1b=op1b.Next;var Reverse1=op1b.Pt.Y>op1.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op1.Pt,op1b.Pt,j.OffPt,this.m_UseFullRange);if(Reverse1){for(op1b=op1.Prev;ClipperLib.IntPoint.op_Equality(op1b.Pt,op1.Pt)&&op1b!==op1;)op1b=op1b.Prev;if(op1b.Pt.Y>op1.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op1.Pt,op1b.Pt,j.OffPt,this.m_UseFullRange))return!1}for(op2b=op2.Next;ClipperLib.IntPoint.op_Equality(op2b.Pt,op2.Pt)&&op2b!==op2;)op2b=op2b.Next;var Reverse2=op2b.Pt.Y>op2.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op2.Pt,op2b.Pt,j.OffPt,this.m_UseFullRange);if(Reverse2){for(op2b=op2.Prev;ClipperLib.IntPoint.op_Equality(op2b.Pt,op2.Pt)&&op2b!==op2;)op2b=op2b.Prev;if(op2b.Pt.Y>op2.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op2.Pt,op2b.Pt,j.OffPt,this.m_UseFullRange))return!1}return!(op1b===op1||op2b===op2||op1b===op2b||outRec1===outRec2&&Reverse1===Reverse2||(Reverse1?(op1b=this.DupOutPt(op1,!1),op2b=this.DupOutPt(op2,!0),op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b,j.OutPt1=op1,j.OutPt2=op1b,0):(op1b=this.DupOutPt(op1,!0),op2b=this.DupOutPt(op2,!1),op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b,j.OutPt1=op1,j.OutPt2=op1b,0)))},ClipperLib.Clipper.GetBounds=function(paths){for(var i=0,cnt=paths.length;i<cnt&&0===paths[i].length;)i++;if(i===cnt)return new ClipperLib.IntRect(0,0,0,0);var result=new ClipperLib.IntRect;for(result.left=paths[i][0].X,result.right=result.left,result.top=paths[i][0].Y,result.bottom=result.top;i<cnt;i++)for(var j=0,jlen=paths[i].length;j<jlen;j++)paths[i][j].X<result.left?result.left=paths[i][j].X:paths[i][j].X>result.right&&(result.right=paths[i][j].X),paths[i][j].Y<result.top?result.top=paths[i][j].Y:paths[i][j].Y>result.bottom&&(result.bottom=paths[i][j].Y);return result},ClipperLib.Clipper.prototype.GetBounds2=function(ops){var opStart=ops,result=new ClipperLib.IntRect;for(result.left=ops.Pt.X,result.right=ops.Pt.X,result.top=ops.Pt.Y,result.bottom=ops.Pt.Y,ops=ops.Next;ops!==opStart;)ops.Pt.X<result.left&&(result.left=ops.Pt.X),ops.Pt.X>result.right&&(result.right=ops.Pt.X),ops.Pt.Y<result.top&&(result.top=ops.Pt.Y),ops.Pt.Y>result.bottom&&(result.bottom=ops.Pt.Y),ops=ops.Next;return result},ClipperLib.Clipper.PointInPolygon=function(pt,path){var result=0,cnt=path.length;if(cnt<3)return 0;for(var ip=path[0],i=1;i<=cnt;++i){var ipNext=i===cnt?path[0]:path[i];if(ipNext.Y===pt.Y&&(ipNext.X===pt.X||ip.Y===pt.Y&&ipNext.X>pt.X==ip.X<pt.X))return-1;if(ip.Y<pt.Y!=ipNext.Y<pt.Y)if(ip.X>=pt.X)if(ipNext.X>pt.X)result=1-result;else{if(0==(d=(ip.X-pt.X)*(ipNext.Y-pt.Y)-(ipNext.X-pt.X)*(ip.Y-pt.Y)))return-1;d>0==ipNext.Y>ip.Y&&(result=1-result)}else if(ipNext.X>pt.X){var d;if(0==(d=(ip.X-pt.X)*(ipNext.Y-pt.Y)-(ipNext.X-pt.X)*(ip.Y-pt.Y)))return-1;d>0==ipNext.Y>ip.Y&&(result=1-result)}ip=ipNext}return result},ClipperLib.Clipper.prototype.PointInPolygon=function(pt,op){var result=0,startOp=op,ptx=pt.X,pty=pt.Y,poly0x=op.Pt.X,poly0y=op.Pt.Y;do{var poly1x=(op=op.Next).Pt.X,poly1y=op.Pt.Y;if(poly1y===pty&&(poly1x===ptx||poly0y===pty&&poly1x>ptx==poly0x<ptx))return-1;if(poly0y<pty!=poly1y<pty)if(poly0x>=ptx)if(poly1x>ptx)result=1-result;else{if(0==(d=(poly0x-ptx)*(poly1y-pty)-(poly1x-ptx)*(poly0y-pty)))return-1;d>0==poly1y>poly0y&&(result=1-result)}else if(poly1x>ptx){var d;if(0==(d=(poly0x-ptx)*(poly1y-pty)-(poly1x-ptx)*(poly0y-pty)))return-1;d>0==poly1y>poly0y&&(result=1-result)}poly0x=poly1x,poly0y=poly1y}while(startOp!==op);return result},ClipperLib.Clipper.prototype.Poly2ContainsPoly1=function(outPt1,outPt2){var op=outPt1;do{var res=this.PointInPolygon(op.Pt,outPt2);if(res>=0)return res>0;op=op.Next}while(op!==outPt1);return!0},ClipperLib.Clipper.prototype.FixupFirstLefts1=function(OldOutRec,NewOutRec){for(var outRec,firstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)outRec=this.m_PolyOuts[i],firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft),null!==outRec.Pts&&firstLeft===OldOutRec&&this.Poly2ContainsPoly1(outRec.Pts,NewOutRec.Pts)&&(outRec.FirstLeft=NewOutRec)},ClipperLib.Clipper.prototype.FixupFirstLefts2=function(innerOutRec,outerOutRec){for(var outRec,firstLeft,orfl=outerOutRec.FirstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).Pts&&outRec!==outerOutRec&&outRec!==innerOutRec&&((firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft))!==orfl&&firstLeft!==innerOutRec&&firstLeft!==outerOutRec||(this.Poly2ContainsPoly1(outRec.Pts,innerOutRec.Pts)?outRec.FirstLeft=innerOutRec:this.Poly2ContainsPoly1(outRec.Pts,outerOutRec.Pts)?outRec.FirstLeft=outerOutRec:outRec.FirstLeft!==innerOutRec&&outRec.FirstLeft!==outerOutRec||(outRec.FirstLeft=orfl)))},ClipperLib.Clipper.prototype.FixupFirstLefts3=function(OldOutRec,NewOutRec){for(var outRec,firstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)outRec=this.m_PolyOuts[i],firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft),null!==outRec.Pts&&firstLeft===OldOutRec&&(outRec.FirstLeft=NewOutRec)},ClipperLib.Clipper.ParseFirstLeft=function(FirstLeft){for(;null!==FirstLeft&&null===FirstLeft.Pts;)FirstLeft=FirstLeft.FirstLeft;return FirstLeft},ClipperLib.Clipper.prototype.JoinCommonEdges=function(){for(var i=0,ilen=this.m_Joins.length;i<ilen;i++){var holeStateRec,join=this.m_Joins[i],outRec1=this.GetOutRec(join.OutPt1.Idx),outRec2=this.GetOutRec(join.OutPt2.Idx);null!==outRec1.Pts&&null!==outRec2.Pts&&(outRec1.IsOpen||outRec2.IsOpen||(holeStateRec=outRec1===outRec2?outRec1:this.OutRec1RightOfOutRec2(outRec1,outRec2)?outRec2:this.OutRec1RightOfOutRec2(outRec2,outRec1)?outRec1:this.GetLowermostRec(outRec1,outRec2),this.JoinPoints(join,outRec1,outRec2)&&(outRec1===outRec2?(outRec1.Pts=join.OutPt1,outRec1.BottomPt=null,(outRec2=this.CreateOutRec()).Pts=join.OutPt2,this.UpdateOutPtIdxs(outRec2),this.Poly2ContainsPoly1(outRec2.Pts,outRec1.Pts)?(outRec2.IsHole=!outRec1.IsHole,outRec2.FirstLeft=outRec1,this.m_UsingPolyTree&&this.FixupFirstLefts2(outRec2,outRec1),(outRec2.IsHole^this.ReverseSolution)==this.Area$1(outRec2)>0&&this.ReversePolyPtLinks(outRec2.Pts)):this.Poly2ContainsPoly1(outRec1.Pts,outRec2.Pts)?(outRec2.IsHole=outRec1.IsHole,outRec1.IsHole=!outRec2.IsHole,outRec2.FirstLeft=outRec1.FirstLeft,outRec1.FirstLeft=outRec2,this.m_UsingPolyTree&&this.FixupFirstLefts2(outRec1,outRec2),(outRec1.IsHole^this.ReverseSolution)==this.Area$1(outRec1)>0&&this.ReversePolyPtLinks(outRec1.Pts)):(outRec2.IsHole=outRec1.IsHole,outRec2.FirstLeft=outRec1.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(outRec1,outRec2))):(outRec2.Pts=null,outRec2.BottomPt=null,outRec2.Idx=outRec1.Idx,outRec1.IsHole=holeStateRec.IsHole,holeStateRec===outRec2&&(outRec1.FirstLeft=outRec2.FirstLeft),outRec2.FirstLeft=outRec1,this.m_UsingPolyTree&&this.FixupFirstLefts3(outRec2,outRec1)))))}},ClipperLib.Clipper.prototype.UpdateOutPtIdxs=function(outrec){var op=outrec.Pts;do{op.Idx=outrec.Idx,op=op.Prev}while(op!==outrec.Pts)},ClipperLib.Clipper.prototype.DoSimplePolygons=function(){for(var i=0;i<this.m_PolyOuts.length;){var outrec=this.m_PolyOuts[i++],op=outrec.Pts;if(null!==op&&!outrec.IsOpen)do{for(var op2=op.Next;op2!==outrec.Pts;){if(ClipperLib.IntPoint.op_Equality(op.Pt,op2.Pt)&&op2.Next!==op&&op2.Prev!==op){var op3=op.Prev,op4=op2.Prev;op.Prev=op4,op4.Next=op,op2.Prev=op3,op3.Next=op2,outrec.Pts=op;var outrec2=this.CreateOutRec();outrec2.Pts=op2,this.UpdateOutPtIdxs(outrec2),this.Poly2ContainsPoly1(outrec2.Pts,outrec.Pts)?(outrec2.IsHole=!outrec.IsHole,outrec2.FirstLeft=outrec,this.m_UsingPolyTree&&this.FixupFirstLefts2(outrec2,outrec)):this.Poly2ContainsPoly1(outrec.Pts,outrec2.Pts)?(outrec2.IsHole=outrec.IsHole,outrec.IsHole=!outrec2.IsHole,outrec2.FirstLeft=outrec.FirstLeft,outrec.FirstLeft=outrec2,this.m_UsingPolyTree&&this.FixupFirstLefts2(outrec,outrec2)):(outrec2.IsHole=outrec.IsHole,outrec2.FirstLeft=outrec.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(outrec,outrec2)),op2=op}op2=op2.Next}op=op.Next}while(op!==outrec.Pts)}},ClipperLib.Clipper.Area=function(poly){if(!Array.isArray(poly))return 0;var cnt=poly.length;if(cnt<3)return 0;for(var a=0,i=0,j=cnt-1;i<cnt;++i)a+=(poly[j].X+poly[i].X)*(poly[j].Y-poly[i].Y),j=i;return.5*-a},ClipperLib.Clipper.prototype.Area=function(op){var opFirst=op;if(null===op)return 0;var a=0;do{a+=(op.Prev.Pt.X+op.Pt.X)*(op.Prev.Pt.Y-op.Pt.Y),op=op.Next}while(op!==opFirst);return.5*a},ClipperLib.Clipper.prototype.Area$1=function(outRec){return this.Area(outRec.Pts)},ClipperLib.Clipper.SimplifyPolygon=function(poly,fillType){var result=new Array,c=new ClipperLib.Clipper(0);return c.StrictlySimple=!0,c.AddPath(poly,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,result,fillType,fillType),result},ClipperLib.Clipper.SimplifyPolygons=function(polys,fillType){void 0===fillType&&(fillType=ClipperLib.PolyFillType.pftEvenOdd);var result=new Array,c=new ClipperLib.Clipper(0);return c.StrictlySimple=!0,c.AddPaths(polys,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,result,fillType,fillType),result},ClipperLib.Clipper.DistanceSqrd=function(pt1,pt2){var dx=pt1.X-pt2.X,dy=pt1.Y-pt2.Y;return dx*dx+dy*dy},ClipperLib.Clipper.DistanceFromLineSqrd=function(pt,ln1,ln2){var A=ln1.Y-ln2.Y,B=ln2.X-ln1.X,C=A*ln1.X+B*ln1.Y;return(C=A*pt.X+B*pt.Y-C)*C/(A*A+B*B)},ClipperLib.Clipper.SlopesNearCollinear=function(pt1,pt2,pt3,distSqrd){return Math.abs(pt1.X-pt2.X)>Math.abs(pt1.Y-pt2.Y)?pt1.X>pt2.X==pt1.X<pt3.X?ClipperLib.Clipper.DistanceFromLineSqrd(pt1,pt2,pt3)<distSqrd:pt2.X>pt1.X==pt2.X<pt3.X?ClipperLib.Clipper.DistanceFromLineSqrd(pt2,pt1,pt3)<distSqrd:ClipperLib.Clipper.DistanceFromLineSqrd(pt3,pt1,pt2)<distSqrd:pt1.Y>pt2.Y==pt1.Y<pt3.Y?ClipperLib.Clipper.DistanceFromLineSqrd(pt1,pt2,pt3)<distSqrd:pt2.Y>pt1.Y==pt2.Y<pt3.Y?ClipperLib.Clipper.DistanceFromLineSqrd(pt2,pt1,pt3)<distSqrd:ClipperLib.Clipper.DistanceFromLineSqrd(pt3,pt1,pt2)<distSqrd},ClipperLib.Clipper.PointsAreClose=function(pt1,pt2,distSqrd){var dx=pt1.X-pt2.X,dy=pt1.Y-pt2.Y;return dx*dx+dy*dy<=distSqrd},ClipperLib.Clipper.ExcludeOp=function(op){var result=op.Prev;return result.Next=op.Next,op.Next.Prev=result,result.Idx=0,result},ClipperLib.Clipper.CleanPolygon=function(path,distance){void 0===distance&&(distance=1.415);var cnt=path.length;if(0===cnt)return new Array;for(var outPts=new Array(cnt),i=0;i<cnt;++i)outPts[i]=new ClipperLib.OutPt;for(i=0;i<cnt;++i)outPts[i].Pt=path[i],outPts[i].Next=outPts[(i+1)%cnt],outPts[i].Next.Prev=outPts[i],outPts[i].Idx=0;for(var distSqrd=distance*distance,op=outPts[0];0===op.Idx&&op.Next!==op.Prev;)ClipperLib.Clipper.PointsAreClose(op.Pt,op.Prev.Pt,distSqrd)?(op=ClipperLib.Clipper.ExcludeOp(op),cnt--):ClipperLib.Clipper.PointsAreClose(op.Prev.Pt,op.Next.Pt,distSqrd)?(ClipperLib.Clipper.ExcludeOp(op.Next),op=ClipperLib.Clipper.ExcludeOp(op),cnt-=2):ClipperLib.Clipper.SlopesNearCollinear(op.Prev.Pt,op.Pt,op.Next.Pt,distSqrd)?(op=ClipperLib.Clipper.ExcludeOp(op),cnt--):(op.Idx=1,op=op.Next);cnt<3&&(cnt=0);var result=new Array(cnt);for(i=0;i<cnt;++i)result[i]=new ClipperLib.IntPoint1(op.Pt),op=op.Next;return outPts=null,result},ClipperLib.Clipper.CleanPolygons=function(polys,distance){for(var result=new Array(polys.length),i=0,ilen=polys.length;i<ilen;i++)result[i]=ClipperLib.Clipper.CleanPolygon(polys[i],distance);return result},ClipperLib.Clipper.Minkowski=function(pattern,path,IsSum,IsClosed){var delta=IsClosed?1:0,polyCnt=pattern.length,pathCnt=path.length,result=new Array;if(IsSum)for(var i=0;i<pathCnt;i++){for(var p=new Array(polyCnt),j=0,jlen=pattern.length,ip=pattern[j];j<jlen;ip=pattern[++j])p[j]=new ClipperLib.IntPoint2(path[i].X+ip.X,path[i].Y+ip.Y);result.push(p)}else for(i=0;i<pathCnt;i++){for(p=new Array(polyCnt),j=0,jlen=pattern.length,ip=pattern[j];j<jlen;ip=pattern[++j])p[j]=new ClipperLib.IntPoint2(path[i].X-ip.X,path[i].Y-ip.Y);result.push(p)}var quads=new Array;for(i=0;i<pathCnt-1+delta;i++)for(j=0;j<polyCnt;j++){var quad=new Array;quad.push(result[i%pathCnt][j%polyCnt]),quad.push(result[(i+1)%pathCnt][j%polyCnt]),quad.push(result[(i+1)%pathCnt][(j+1)%polyCnt]),quad.push(result[i%pathCnt][(j+1)%polyCnt]),ClipperLib.Clipper.Orientation(quad)||quad.reverse(),quads.push(quad)}return quads},ClipperLib.Clipper.MinkowskiSum=function(pattern,path_or_paths,pathIsClosed){if(path_or_paths[0]instanceof Array){paths=path_or_paths;for(var solution=new ClipperLib.Paths,i=(c=new ClipperLib.Clipper,0);i<paths.length;++i){var tmp=ClipperLib.Clipper.Minkowski(pattern,paths[i],!0,pathIsClosed);c.AddPaths(tmp,ClipperLib.PolyType.ptSubject,!0),pathIsClosed&&(path=ClipperLib.Clipper.TranslatePath(paths[i],pattern[0]),c.AddPath(path,ClipperLib.PolyType.ptClip,!0))}return c.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),solution}var c,path=path_or_paths,paths=ClipperLib.Clipper.Minkowski(pattern,path,!0,pathIsClosed);return(c=new ClipperLib.Clipper).AddPaths(paths,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,paths,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),paths},ClipperLib.Clipper.TranslatePath=function(path,delta){for(var outPath=new ClipperLib.Path,i=0;i<path.length;i++)outPath.push(new ClipperLib.IntPoint2(path[i].X+delta.X,path[i].Y+delta.Y));return outPath},ClipperLib.Clipper.MinkowskiDiff=function(poly1,poly2){var paths=ClipperLib.Clipper.Minkowski(poly1,poly2,!1,!0),c=new ClipperLib.Clipper;return c.AddPaths(paths,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,paths,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),paths},ClipperLib.Clipper.PolyTreeToPaths=function(polytree){var result=new Array;return ClipperLib.Clipper.AddPolyNodeToPaths(polytree,ClipperLib.Clipper.NodeType.ntAny,result),result},ClipperLib.Clipper.AddPolyNodeToPaths=function(polynode,nt,paths){var match=!0;switch(nt){case ClipperLib.Clipper.NodeType.ntOpen:return;case ClipperLib.Clipper.NodeType.ntClosed:match=!polynode.IsOpen}polynode.m_polygon.length>0&&match&&paths.push(polynode.m_polygon);for(var $i3=0,$t3=polynode.Childs(),$l3=$t3.length,pn=$t3[$i3];$i3<$l3;pn=$t3[++$i3])ClipperLib.Clipper.AddPolyNodeToPaths(pn,nt,paths)},ClipperLib.Clipper.OpenPathsFromPolyTree=function(polytree){for(var result=new ClipperLib.Paths,i=0,ilen=polytree.ChildCount();i<ilen;i++)polytree.Childs()[i].IsOpen&&result.push(polytree.Childs()[i].m_polygon);return result},ClipperLib.Clipper.ClosedPathsFromPolyTree=function(polytree){var result=new ClipperLib.Paths;return ClipperLib.Clipper.AddPolyNodeToPaths(polytree,ClipperLib.Clipper.NodeType.ntClosed,result),result},Inherit(ClipperLib.Clipper,ClipperLib.ClipperBase),ClipperLib.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},ClipperLib.ClipperOffset=function(miterLimit,arcTolerance){void 0===miterLimit&&(miterLimit=2),void 0===arcTolerance&&(arcTolerance=ClipperLib.ClipperOffset.def_arc_tolerance),this.m_destPolys=new ClipperLib.Paths,this.m_srcPoly=new ClipperLib.Path,this.m_destPoly=new ClipperLib.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 ClipperLib.IntPoint0,this.m_polyNodes=new ClipperLib.PolyNode,this.MiterLimit=miterLimit,this.ArcTolerance=arcTolerance,this.m_lowest.X=-1},ClipperLib.ClipperOffset.two_pi=6.28318530717959,ClipperLib.ClipperOffset.def_arc_tolerance=.25,ClipperLib.ClipperOffset.prototype.Clear=function(){ClipperLib.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},ClipperLib.ClipperOffset.Round=ClipperLib.Clipper.Round,ClipperLib.ClipperOffset.prototype.AddPath=function(path,joinType,endType){var highI=path.length-1;if(!(highI<0)){var newNode=new ClipperLib.PolyNode;if(newNode.m_jointype=joinType,newNode.m_endtype=endType,endType===ClipperLib.EndType.etClosedLine||endType===ClipperLib.EndType.etClosedPolygon)for(;highI>0&&ClipperLib.IntPoint.op_Equality(path[0],path[highI]);)highI--;newNode.m_polygon.push(path[0]);for(var j=0,k=0,i=1;i<=highI;i++)ClipperLib.IntPoint.op_Inequality(newNode.m_polygon[j],path[i])&&(j++,newNode.m_polygon.push(path[i]),(path[i].Y>newNode.m_polygon[k].Y||path[i].Y===newNode.m_polygon[k].Y&&path[i].X<newNode.m_polygon[k].X)&&(k=j));if(!(endType===ClipperLib.EndType.etClosedPolygon&&j<2)&&(this.m_polyNodes.AddChild(newNode),endType===ClipperLib.EndType.etClosedPolygon))if(this.m_lowest.X<0)this.m_lowest=new ClipperLib.IntPoint2(this.m_polyNodes.ChildCount()-1,k);else{var ip=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(newNode.m_polygon[k].Y>ip.Y||newNode.m_polygon[k].Y===ip.Y&&newNode.m_polygon[k].X<ip.X)&&(this.m_lowest=new ClipperLib.IntPoint2(this.m_polyNodes.ChildCount()-1,k))}}},ClipperLib.ClipperOffset.prototype.AddPaths=function(paths,joinType,endType){for(var i=0,ilen=paths.length;i<ilen;i++)this.AddPath(paths[i],joinType,endType)},ClipperLib.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!ClipperLib.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var i=0;i<this.m_polyNodes.ChildCount();i++)((node=this.m_polyNodes.Childs()[i]).m_endtype===ClipperLib.EndType.etClosedPolygon||node.m_endtype===ClipperLib.EndType.etClosedLine&&ClipperLib.Clipper.Orientation(node.m_polygon))&&node.m_polygon.reverse();else for(i=0;i<this.m_polyNodes.ChildCount();i++){var node;(node=this.m_polyNodes.Childs()[i]).m_endtype!==ClipperLib.EndType.etClosedLine||ClipperLib.Clipper.Orientation(node.m_polygon)||node.m_polygon.reverse()}},ClipperLib.ClipperOffset.GetUnitNormal=function(pt1,pt2){var dx=pt2.X-pt1.X,dy=pt2.Y-pt1.Y;if(0===dx&&0===dy)return new ClipperLib.DoublePoint2(0,0);var f=1/Math.sqrt(dx*dx+dy*dy);return dx*=f,dy*=f,new ClipperLib.DoublePoint2(dy,-dx)},ClipperLib.ClipperOffset.prototype.DoOffset=function(delta){if(this.m_destPolys=new Array,this.m_delta=delta,ClipperLib.ClipperBase.near_zero(delta))for(var i=0;i<this.m_polyNodes.ChildCount();i++)(node=this.m_polyNodes.Childs()[i]).m_endtype===ClipperLib.EndType.etClosedPolygon&&this.m_destPolys.push(node.m_polygon);else{var y;this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5,y=this.ArcTolerance<=0?ClipperLib.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(delta)*ClipperLib.ClipperOffset.def_arc_tolerance?Math.abs(delta)*ClipperLib.ClipperOffset.def_arc_tolerance:this.ArcTolerance;var steps=3.14159265358979/Math.acos(1-y/Math.abs(delta));for(this.m_sin=Math.sin(ClipperLib.ClipperOffset.two_pi/steps),this.m_cos=Math.cos(ClipperLib.ClipperOffset.two_pi/steps),this.m_StepsPerRad=steps/ClipperLib.ClipperOffset.two_pi,delta<0&&(this.m_sin=-this.m_sin),i=0;i<this.m_polyNodes.ChildCount();i++){var node=this.m_polyNodes.Childs()[i];this.m_srcPoly=node.m_polygon;var len=this.m_srcPoly.length;if(!(0===len||delta<=0&&(len<3||node.m_endtype!==ClipperLib.EndType.etClosedPolygon)))if(this.m_destPoly=new Array,1!==len){for(this.m_normals.length=0,j=0;j<len-1;j++)this.m_normals.push(ClipperLib.ClipperOffset.GetUnitNormal(this.m_srcPoly[j],this.m_srcPoly[j+1]));if(node.m_endtype===ClipperLib.EndType.etClosedLine||node.m_endtype===ClipperLib.EndType.etClosedPolygon?this.m_normals.push(ClipperLib.ClipperOffset.GetUnitNormal(this.m_srcPoly[len-1],this.m_srcPoly[0])):this.m_normals.push(new ClipperLib.DoublePoint1(this.m_normals[len-2])),node.m_endtype===ClipperLib.EndType.etClosedPolygon){var k=len-1;for(j=0;j<len;j++)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(node.m_endtype===ClipperLib.EndType.etClosedLine){for(k=len-1,j=0;j<len;j++)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;var n=this.m_normals[len-1];for(j=len-1;j>0;j--)this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j-1].X,-this.m_normals[j-1].Y);for(this.m_normals[0]=new ClipperLib.DoublePoint2(-n.X,-n.Y),k=0,j=len-1;j>=0;j--)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{var pt1;for(k=0,j=1;j<len-1;++j)k=this.OffsetPoint(j,k,node.m_jointype);for(node.m_endtype===ClipperLib.EndType.etOpenButt?(j=len-1,pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*delta)),this.m_destPoly.push(pt1),pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X-this.m_normals[j].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y-this.m_normals[j].Y*delta)),this.m_destPoly.push(pt1)):(j=len-1,k=len-2,this.m_sinA=0,this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j].X,-this.m_normals[j].Y),node.m_endtype===ClipperLib.EndType.etOpenSquare?this.DoSquare(j,k):this.DoRound(j,k)),j=len-1;j>0;j--)this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j-1].X,-this.m_normals[j-1].Y);for(this.m_normals[0]=new ClipperLib.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),j=(k=len-1)-1;j>0;--j)k=this.OffsetPoint(j,k,node.m_jointype);node.m_endtype===ClipperLib.EndType.etOpenButt?(pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*delta)),this.m_destPoly.push(pt1),pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*delta)),this.m_destPoly.push(pt1)):(k=1,this.m_sinA=0,node.m_endtype===ClipperLib.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}else{if(node.m_jointype===ClipperLib.JoinType.jtRound)for(var X=1,Y=0,j=1;j<=steps;j++){this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+Y*delta)));var X2=X;X=X*this.m_cos-this.m_sin*Y,Y=X2*this.m_sin+Y*this.m_cos}else{X=-1,Y=-1;for(var j=0;j<4;++j)this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+Y*delta))),X<0?X=1:Y<0?Y=1:X=-1}this.m_destPolys.push(this.m_destPoly)}}}},ClipperLib.ClipperOffset.prototype.Execute=function(){var a=arguments;if(a[0]instanceof ClipperLib.PolyTree)if(delta=a[1],(solution=a[0]).Clear(),this.FixOrientations(),this.DoOffset(delta),(clpr=new ClipperLib.Clipper(0)).AddPaths(this.m_destPolys,ClipperLib.PolyType.ptSubject,!0),delta>0)clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftPositive,ClipperLib.PolyFillType.pftPositive);else if(r=ClipperLib.Clipper.GetBounds(this.m_destPolys),(outer=new ClipperLib.Path).push(new ClipperLib.IntPoint2(r.left-10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.top-10)),outer.push(new ClipperLib.IntPoint2(r.left-10,r.top-10)),clpr.AddPath(outer,ClipperLib.PolyType.ptSubject,!0),clpr.ReverseSolution=!0,clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNegative,ClipperLib.PolyFillType.pftNegative),1===solution.ChildCount()&&solution.Childs()[0].ChildCount()>0){var outerNode=solution.Childs()[0];solution.Childs()[0]=outerNode.Childs()[0],solution.Childs()[0].m_Parent=solution;for(var i=1;i<outerNode.ChildCount();i++)solution.AddChild(outerNode.Childs()[i])}else solution.Clear();else{var clpr,solution=a[0],delta=a[1];if(ClipperLib.Clear(solution),this.FixOrientations(),this.DoOffset(delta),(clpr=new ClipperLib.Clipper(0)).AddPaths(this.m_destPolys,ClipperLib.PolyType.ptSubject,!0),delta>0)clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftPositive,ClipperLib.PolyFillType.pftPositive);else{var outer,r=ClipperLib.Clipper.GetBounds(this.m_destPolys);(outer=new ClipperLib.Path).push(new ClipperLib.IntPoint2(r.left-10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.top-10)),outer.push(new ClipperLib.IntPoint2(r.left-10,r.top-10)),clpr.AddPath(outer,ClipperLib.PolyType.ptSubject,!0),clpr.ReverseSolution=!0,clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNegative,ClipperLib.PolyFillType.pftNegative),solution.length>0&&solution.splice(0,1)}}},ClipperLib.ClipperOffset.prototype.OffsetPoint=function(j,k,jointype){if(this.m_sinA=this.m_normals[k].X*this.m_normals[j].Y-this.m_normals[j].X*this.m_normals[k].Y,Math.abs(this.m_sinA*this.m_delta)<1){if(this.m_normals[k].X*this.m_normals[j].X+this.m_normals[j].Y*this.m_normals[k].Y>0)return this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[k].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[k].Y*this.m_delta))),k}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 ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[k].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[k].Y*this.m_delta))),this.m_destPoly.push(new ClipperLib.IntPoint1(this.m_srcPoly[j])),this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*this.m_delta)));else switch(jointype){case ClipperLib.JoinType.jtMiter:var r=this.m_normals[j].X*this.m_normals[k].X+this.m_normals[j].Y*this.m_normals[k].Y+1;r>=this.m_miterLim?this.DoMiter(j,k,r):this.DoSquare(j,k);break;case ClipperLib.JoinType.jtSquare:this.DoSquare(j,k);break;case ClipperLib.JoinType.jtRound:this.DoRound(j,k)}return k=j},ClipperLib.ClipperOffset.prototype.DoSquare=function(j,k){var dx=Math.tan(Math.atan2(this.m_sinA,this.m_normals[k].X*this.m_normals[j].X+this.m_normals[k].Y*this.m_normals[j].Y)/4);this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_delta*(this.m_normals[k].X-this.m_normals[k].Y*dx)),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_delta*(this.m_normals[k].Y+this.m_normals[k].X*dx)))),this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_delta*(this.m_normals[j].X+this.m_normals[j].Y*dx)),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_delta*(this.m_normals[j].Y-this.m_normals[j].X*dx))))},ClipperLib.ClipperOffset.prototype.DoMiter=function(j,k,r){var q=this.m_delta/r;this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+(this.m_normals[k].X+this.m_normals[j].X)*q),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+(this.m_normals[k].Y+this.m_normals[j].Y)*q)))},ClipperLib.ClipperOffset.prototype.DoRound=function(j,k){for(var X2,a=Math.atan2(this.m_sinA,this.m_normals[k].X*this.m_normals[j].X+this.m_normals[k].Y*this.m_normals[j].Y),steps=Math.max(ClipperLib.Cast_Int32(ClipperLib.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(a))),1),X=this.m_normals[k].X,Y=this.m_normals[k].Y,i=0;i<steps;++i)this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+Y*this.m_delta))),X2=X,X=X*this.m_cos-this.m_sin*Y,Y=X2*this.m_sin+Y*this.m_cos;this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*this.m_delta)))},ClipperLib.Error=function(message){try{throw new Error(message)}catch(err){alert(err.message)}},ClipperLib.JS={},ClipperLib.JS.AreaOfPolygon=function(poly,scale){return scale||(scale=1),ClipperLib.Clipper.Area(poly)/(scale*scale)},ClipperLib.JS.AreaOfPolygons=function(poly,scale){scale||(scale=1);for(var area=0,i=0;i<poly.length;i++)area+=ClipperLib.Clipper.Area(poly[i]);return area/(scale*scale)},ClipperLib.JS.BoundsOfPath=function(path,scale){return ClipperLib.JS.BoundsOfPaths([path],scale)},ClipperLib.JS.BoundsOfPaths=function(paths,scale){scale||(scale=1);var bounds=ClipperLib.Clipper.GetBounds(paths);return bounds.left/=scale,bounds.bottom/=scale,bounds.right/=scale,bounds.top/=scale,bounds},ClipperLib.JS.Clean=function(polygon,delta){if(!(polygon instanceof Array))return[];var isPolygons=polygon[0]instanceof Array;if(polygon=ClipperLib.JS.Clone(polygon),"number"!=typeof delta||null===delta)return ClipperLib.Error("Delta is not a number in Clean()."),polygon;if(0===polygon.length||1===polygon.length&&0===polygon[0].length||delta<0)return polygon;isPolygons||(polygon=[polygon]);for(var len,poly,result,d,p,j,i,k_length=polygon.length,results=[],k=0;k<k_length;k++)if(0!==(len=(poly=polygon[k]).length))if(len<3)result=poly,results.push(result);else{for(result=poly,d=delta*delta,p=poly[0],j=1,i=1;i<len;i++)(poly[i].X-p.X)*(poly[i].X-p.X)+(poly[i].Y-p.Y)*(poly[i].Y-p.Y)<=d||(result[j]=poly[i],p=poly[i],j++);p=poly[j-1],(poly[0].X-p.X)*(poly[0].X-p.X)+(poly[0].Y-p.Y)*(poly[0].Y-p.Y)<=d&&j--,j<len&&result.splice(j,len-j),result.length&&results.push(result)}return!isPolygons&&results.length?results=results[0]:isPolygons||0!==results.length?isPolygons&&0===results.length&&(results=[[]]):results=[],results},ClipperLib.JS.Clone=function(polygon){if(!(polygon instanceof Array))return[];if(0===polygon.length)return[];if(1===polygon.length&&0===polygon[0].length)return[[]];var isPolygons=polygon[0]instanceof Array;isPolygons||(polygon=[polygon]);var plen,i,j,result,len=polygon.length,results=new Array(len);for(i=0;i<len;i++){for(plen=polygon[i].length,result=new Array(plen),j=0;j<plen;j++)result[j]={X:polygon[i][j].X,Y:polygon[i][j].Y};results[i]=result}return isPolygons||(results=results[0]),results},ClipperLib.JS.Lighten=function(polygon,tolerance){if(!(polygon instanceof Array))return[];if("number"!=typeof tolerance||null===tolerance)return ClipperLib.Error("Tolerance is not a number in Lighten()."),ClipperLib.JS.Clone(polygon);if(0===polygon.length||1===polygon.length&&0===polygon[0].length||tolerance<0)return ClipperLib.JS.Clone(polygon);var i,j,poly,k,poly2,plen,A,B,P,rem,addlast,bxax,byay,l,ax,ay,isPolygons=polygon[0]instanceof Array;isPolygons||(polygon=[polygon]);var len=polygon.length,toleranceSq=tolerance*tolerance,results=[];for(i=0;i<len;i++)if(0!==(plen=(poly=polygon[i]).length)){for(k=0;k<1e6;k++){for(poly2=[],poly[(plen=poly.length)-1].X!==poly[0].X||poly[plen-1].Y!==poly[0].Y?(addlast=1,poly.push({X:poly[0].X,Y:poly[0].Y}),plen=poly.length):addlast=0,rem=[],j=0;j<plen-2;j++)A=poly[j],P=poly[j+1],B=poly[j+2],ax=A.X,ay=A.Y,bxax=B.X-ax,byay=B.Y-ay,0===bxax&&0===byay||((l=((P.X-ax)*bxax+(P.Y-ay)*byay)/(bxax*bxax+byay*byay))>1?(ax=B.X,ay=B.Y):l>0&&(ax+=bxax*l,ay+=byay*l)),(bxax=P.X-ax)*bxax+(byay=P.Y-ay)*byay<=toleranceSq&&(rem[j+1]=1,j++);for(poly2.push({X:poly[0].X,Y:poly[0].Y}),j=1;j<plen-1;j++)rem[j]||poly2.push({X:poly[j].X,Y:poly[j].Y});if(poly2.push({X:poly[plen-1].X,Y:poly[plen-1].Y}),addlast&&poly.pop(),!rem.length)break;poly=poly2}poly2[(plen=poly2.length)-1].X===poly2[0].X&&poly2[plen-1].Y===poly2[0].Y&&poly2.pop(),poly2.length>2&&results.push(poly2)}return isPolygons||(results=results[0]),void 0===results&&(results=[]),results},ClipperLib.JS.PerimeterOfPath=function(path,closed,scale){if(void 0===path)return 0;var p1,p2,sqrt=Math.sqrt,perimeter=0,p1x=0,p1y=0,p2x=0,p2y=0,j=path.length;if(j<2)return 0;for(closed&&(path[j]=path[0],j++);--j;)p1x=(p1=path[j]).X,p1y=p1.Y,perimeter+=sqrt((p1x-(p2x=(p2=path[j-1]).X))*(p1x-p2x)+(p1y-(p2y=p2.Y))*(p1y-p2y));return closed&&path.pop(),perimeter/scale},ClipperLib.JS.PerimeterOfPaths=function(paths,closed,scale){scale||(scale=1);for(var perimeter=0,i=0;i<paths.length;i++)perimeter+=ClipperLib.JS.PerimeterOfPath(paths[i],closed,scale);return perimeter},ClipperLib.JS.ScaleDownPath=function(path,scale){var i,p;for(scale||(scale=1),i=path.length;i--;)(p=path[i]).X=p.X/scale,p.Y=p.Y/scale},ClipperLib.JS.ScaleDownPaths=function(paths,scale){var i,j,p;for(scale||(scale=1),i=paths.length;i--;)for(j=paths[i].length;j--;)(p=paths[i][j]).X=p.X/scale,p.Y=p.Y/scale},ClipperLib.JS.ScaleUpPath=function(path,scale){var i,p,round=Math.round;for(scale||(scale=1),i=path.length;i--;)(p=path[i]).X=round(p.X*scale),p.Y=round(p.Y*scale)},ClipperLib.JS.ScaleUpPaths=function(paths,scale){var i,j,p,round=Math.round;for(scale||(scale=1),i=paths.length;i--;)for(j=paths[i].length;j--;)(p=paths[i][j]).X=round(p.X*scale),p.Y=round(p.Y*scale)},ClipperLib.ExPolygons=function(){return[]},ClipperLib.ExPolygon=function(){this.outer=null,this.holes=null},ClipperLib.JS.AddOuterPolyNodeToExPolygons=function(polynode,expolygons){var ep=new ClipperLib.ExPolygon;ep.outer=polynode.Contour();var node,n,i,j,childs2,jlen,childs=polynode.Childs(),ilen=childs.length;for(ep.holes=new Array(ilen),i=0;i<ilen;i++)for(node=childs[i],ep.holes[i]=node.Contour(),j=0,jlen=(childs2=node.Childs()).length;j<jlen;j++)n=childs2[j],ClipperLib.JS.AddOuterPolyNodeToExPolygons(n,expolygons);expolygons.push(ep)},ClipperLib.JS.ExPolygonsToPaths=function(expolygons){var a,i,alen,ilen,paths=new ClipperLib.Paths;for(a=0,alen=expolygons.length;a<alen;a++)for(paths.push(expolygons[a].outer),i=0,ilen=expolygons[a].holes.length;i<ilen;i++)paths.push(expolygons[a].holes[i]);return paths},ClipperLib.JS.PolyTreeToExPolygons=function(polytree){var node,i,childs,ilen,expolygons=new ClipperLib.ExPolygons;for(i=0,ilen=(childs=polytree.Childs()).length;i<ilen;i++)node=childs[i],ClipperLib.JS.AddOuterPolyNodeToExPolygons(node,expolygons);return expolygons}}();var ClipperLib=getDefaultExportFromCjs(clipper.exports);function shapeclip(){function toclipformat(pts){let tm=pts.map((e=>({X:Math.round(1e4*e.x),Y:Math.round(1e4*e.y)})));return ensureOrientation(tm)}function fromclipformat(pts){return pts.map((e=>({x:e.X/1e4,y:e.Y/1e4})))}const ensureOrientation=poly=>ClipperLib.Clipper.Orientation(poly)?poly:poly.slice().reverse();function orientation(pt){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.X*next.Y-next.X*current.Y}return area>0?1:area<0?-1:0}const _inflate=(pt,delta,cut=!1)=>{const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.AddPath(pt,ClipperLib.JoinType.jtMiter,cut||2==pt.length?ClipperLib.EndType.etOpenButt:ClipperLib.EndType.etClosedPolygon);const solution=new ClipperLib.Paths;return co.Execute(solution,delta),solution};return{offset(shape,delta,full=!1){const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.ArcTolerance=.25;const DD=1e4*Math.abs(delta),pshape=toclipformat(shape.pt);co.AddPath(pshape,ClipperLib.JoinType.jtMiter,ClipperLib.EndType.etOpenButt);const solution=new ClipperLib.Paths;co.Execute(solution,DD);let tm=fromclipformat(solution[0]);return full?getshape().frompt(tm):getshape().frompt(getptsoffset(shape.pt,tm,delta))},inflate(shape,delta=2,mantainorder=!1){let pshape=toclipformat(shape.pt),tm=_inflate(pshape,1e4*delta);let p2=getshape().frompt(fromclipformat(tm[0]));if(mantainorder&&shape.pt.length==p2.pt.length){p2.orient!=shape.orient&&p2.reverse();let p3=function alignByMinDist(sag1,sag2){const N=sag1.length;let bestOffset=0,minSum=1/0;for(let k=0;k<N;k++){let sum=0;for(let i=0;i<N;i++){const p=sag1[i],q=sag2[(i+k)%N],dx=p.x-q.x,dy=p.y-q.y;sum+=dx*dx+dy*dy}sum<minSum&&(minSum=sum,bestOffset=k)}return[...sag2.slice(bestOffset),...sag2.slice(0,bestOffset)]}(shape.pt,p2.pt);p2.frompt(p3)}return p2},intersecasplitter(areabase,forma1){const clipper=new ClipperLib.Clipper,pt1=[toclipformat(forma1.pt)],pt2=[toclipformat(areabase.pt)];clipper.AddPaths(pt1,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(pt2,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;let res;if(clipper.Execute(ClipperLib.ClipType.ctIntersection,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)&&solution.length>0){const path=solution[0];if(1===orientation(path)){res=getshape().frompt(fromclipformat(path)),res.orient!=forma1.orient&&res.reverse();for(let iu=0;iu<forma1.pt.length;iu++){let p2=forma1.pt[iu],id=res.pt.findIndex((p=>Math.abs(p.x-p2.x)<.01&&Math.abs(p.y-p2.y)<.01));if(id>0){id-=iu,0!=id&&res.selezionaprimo(id);break}}}}return res},offsetpts(pts,delta=.01){const DELTA=1e4*delta;let tm=_inflate(toclipformat(pts),DELTA);if(tm&&tm.length)return fromclipformat(tm[0])},areesplitter(shapept,clipspt,useInflatedClipping=!0){if(!Array.isArray(shapept)||shapept.length<3)return;if(!clipspt||0==clipspt.length)return[shapept];const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;let shape_in=useInflatedClipping?_inflate(toclipformat(shapept),-100):[toclipformat(shapept)],clips_in=useInflatedClipping?clipspt.flatMap((c=>_inflate(toclipformat(c),100))):clipspt.map((c=>toclipformat(c)));for(let s of shape_in)subj.push(s);for(let c of clips_in)clip.push(c);const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(!clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero))return;let res=[];for(let x of solution)if(useInflatedClipping){const restored=_inflate(x,100);for(const r of restored)1===orientation(r)&&res.push(fromclipformat(r))}else if(x.length>4&&1==orientation(x)){const cleaned=_inflate(x,-100);if(cleaned.length>0)for(let cc of cleaned){const restored=_inflate(cc,100);for(const rr of restored)1===orientation(rr)&&res.push(fromclipformat(rr))}}else 1==orientation(x)&&res.push(fromclipformat(x));return res},unisci(shapes,holes,cuts){const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;for(var hh of shapes){let h2=[toclipformat(hh.pt)];for(var h of h2)subj.push(h)}if(holes&&holes.length)for(var hh of holes){let h1=toclipformat(hh.pt);clip.push(h1)}if(cuts&&cuts.length)for(var hh of cuts){let h1=toclipformat(hh.pt),h2=_inflate(h1,1,!0);for(var h of h2)clip.push(h)}const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)){let res=[],holes=[];for(var x of solution)if(1==orientation(x)){let yy=[x];for(var y of yy)res.push({shape:getshape().frompt(fromclipformat(y)),holes:[]})}else holes.push(getshape().frompt(fromclipformat(x)));for(var h of holes)for(var s of res)if(s.shape.pointinshape(h.pt[0])){s.holes.push(h);break}return res}return[]}}}class Vis2d{constructor(name,p1,p2){this.name=name,this.clear(p1,p2)}clear(p1,p2){return this.vec=[],this.xp1=p1||new Punto2(-10,-10),this.xp2=p2||new Punto2(100,100),this}randomcolor(transp="100%"){return`hsl(${Math.floor(360*Math.random())}, 50%, 40%,${transp})`}addpoint(p,id=-1,color=void 0,spessore=1){return this.vec.push({type:"point",p:p,id:id,color:color,spessore:spessore}),this}addline(l,id=-1,color=void 0,spessore=1){return this.vec.push({type:"line",l:l,id:id,color:color,spessore:spessore}),this}addrect(l,id=-1,color=void 0,spessore=1){return this.vec.push({type:"rect",l:l,id:id,color:color,spessore:spessore}),this}addrecta(l,id=-1,color=void 0){return this.vec.push({type:"recta",l:l,id:id,color:color,spessore:spessore}),this}addshape(s,color=void 0,spessore=1){return this.vec.push({type:"shape",s:s,color:color||this.randomcolor(),spessore:spessore}),this}addshapelin(s,color=void 0,spessore=1){return this.vec.push({type:"shapelin",s:s,color:color||this.randomcolor(),spessore:spessore}),this}addarea(s,color=void 0){return this.vec.push({type:"area",s:s,color:color||this.randomcolor()}),this}addoffset(x,y){return this.vec.push({type:"offset",x:x||0,y:y||0}),this}}function generatesegments(t1,t2,interna=!1,allbreak=!1){let t3=[];if(t1?.length>2){if(allbreak){let tm=[];for(let t of t1)tm.push({a:t.a,b:t.a}),t.a!=t.b&&tm.push({a:t.b,b:t.b});t1=tm}if(t1=t1.sort(((a,b)=>a.a-b.a)),t2?.length){let j=0;for(let i=1;i<t1.length;i++){const ε=1e-6;t2.find((e=>e>t1[i-1].b+ε&&e<t1[i].a-ε))&&(i-1>j&&(interna?t3.push({a:t1[j].b,b:t1[i-1].a}):t3.push({a:t1[j].a,b:t1[i-1].b})),j=i)}j<t1.length-1&&(interna?t3.push({a:t1[j].b,b:t1[t1.length-1].a}):t3.push({a:t1[j].a,b:t1[t1.length-1].b}))}else t3.push({a:t1[0].b,b:t1[t1.length-1].a})}return t3}function bordi(ff){function getbordo(b1,b2){let b=b1??b2??{s:0};return"number"==typeof b?{s:b}:"number"==typeof b?.s?b:{s:0}}let bt,bb,bl,br;return"a"==ff.tipo?bt=bb=bl=br=getbordo(ff.bordo,ff.bordo):(bt=getbordo(ff.bt,ff.bordo),bb=getbordo(ff.bb,ff.bordo),bl=getbordo(ff.bl,ff.bordo),br=getbordo(ff.br,ff.bordo)),{bt:bt,bb:bb,bl:bl,br:br}}function internalshape(ff,shape){let shape2,CLP=shapeclip(),{bt:bt,bb:bb,bl:bl,br:br}=bordi(ff);if(bt==br&&bb==br&&bl==br||"a"==ff.tipo)shape2=CLP.inflate(shape,-bt.s,!0);else{let n=shape.pt.length,ll=[];for(let i=0;i<n;i++){let ofs=0==i?bl.s:i==n-2?br.s:i==n-1?bb.s:bt.s;ll.push(shape.segment(i).offset(-ofs))}let pts=[];for(let i=0;i<n;i++){let j=(i+n-1)%n,p=ll[i].intersezione(ll[j]);p||(p=shape.pt[i]),pts.push(p)}shape2=getshape().frompt(pts)}return shape2}const tipi={i:"inclinato",a:"arco",d:"diagonali",s:"smussato",x:"normale"},priorita={v:"verticale",h:"orizzontale"},tagli={d:"diagonale",v:"verticale",h:"orizzontale"};function ordinabase(hh,dd,minvano,b1,b2){let d1=[];if(hh){for(var h of hh){let x=0;switch(h.tipo){case"d-":x=dd-h.p;break;case"p":x=dd*h.p/100;break;case"p-":x=dd*(100-h.p)/100;break;default:x=h.p}let sp=h.sps||0;if(sp&&"c"==h.align?x-=sp/2:sp&&"r"==h.align&&(x-=sp),x=Math.round(10*x)/10,x>b1&&x<dd-b2){let cuts=[];h.cuttings&&h.cuttings.forEach((c=>{cuts.push(c<0?dd+c:c)})),d1.push({id:h.id,x:x,sp:sp,cuts:cuts,des:h.des})}}d1.sort(((a,b)=>a.x-b.x))}let d2=[],p0=b1;for(let i=0;i<d1.length;i++){let d=d1[i];d.x>=p0+minvano&&d.x+d.sp<=dd-b2-minvano&&(d.min=p0+minvano,d.max=dd-b2-minvano,d2.length>0&&(d2[d2.length-1].max=d.x-minvano),d2.push(d),p0=d.x+d.sp)}let d3=[];d3.push({a:b1,b:b1});for(let d of d2)d3.push({a:d.x,b:d.x+d.sp});return d3.push({a:dd-b2,b:dd-b2}),{dati:d2,punti:d3}}const tipocut={d:"dist. positiva","d-":"dist. negativa",p:"perc. positiva","p-":"perc negativa"},tipoalign={l:"left",c:"center",r:"right"};function newcount(ff){return ff.countid++,ff.countid}function addtaglio(ff,dir,tipodim,dim,sps,des,align="c",cuts=[]){return{dir:dir,id:newcount(ff),tipo:tipocut[tipodim]?tipodim:"d",align:tipoalign[align]?align:"c",p:dim,sps:sps,des:des,cuttings:cuts||[]}}function pushlineare(ff,type,des,l0,l1,id=-1,shapecontorno=void 0,areas){let tm;if(id<0&&(id=newcount(ff)),"l"==type)Array.isArray(areas)&&areas.push([l0.p1,l0.p2]);else{let ptx=[l0.p1,l0.p2,l1.p2,l1.p1];Array.isArray(areas)&&areas.push(ptx);let s1=getshape().frompt(ptx);if(shapecontorno?.pt&&"x"!=ff.tipo&&(s1=shapeclip().intersecasplitter(shapecontorno,s1)),s1){let info=l0.infoquad(l1);info&&info.distanza&&(tm={id:id,type:type,des:des,shape:s1.pt,info:info},ff.dati.push(tm))}}return tm}function pushshape(ff,type,des,shape,info,id=-1){let tm;return id<0&&(id=newcount(ff)),info||(info={}),info={isshape:!0},shape?.pt&&(tm={id:id,type:type,des:des,shape:shape.pt,info:info},ff.dati.push(tm)),tm}function creabordi(ff,shape,shape2){let l1,n=shape.pt.length,draws=[];function addlineare(type,des,l0,l1){let tm=pushlineare(ff,type,des,l0,l1);tm?.shape&&draws.push({pt:tm.shape,type:type})}if("a"!=ff.tipo)for(let i=1;i<n-2;i++)addlineare("bt","sopra",shape.segment(i),shape2.segment(i));else{let p1=[...shape.pt].slice(1,-1),p2=[...shape2.pt].slice(1,-1).reverse(),sa=getshape().frompt([...p1,...p2]);pushshape(ff,"bt","sopra",sa,{isarco:!0}),draws.push({pt:sa.pt,type:"bs"})}switch(ff.taglio){case"h":{let p1=shape2.segment(n-1).intersezione(shape.segment(0)),p2=shape2.segment(n-1).intersezione(shape.segment(n-2));l1=new Linea2(p1,shape.pt[1]),addlineare("bl","sx",l1,shape2.segment(0)),l1=new Linea2(shape.pt[n-2],p2),addlineare("br","dx",l1,shape2.segment(n-2)),l1=new Linea2(p2,p1),addlineare("bb","sotto",shape.segment(n-1),l1);break}case"v":{let p1=shape2.segment(0).intersezione(shape.segment(n-1)),p2=shape2.segment(n-2).intersezione(shape.segment(n-1));l1=new Linea2(p1,shape2.pt[1]),addlineare("bl","sx",shape.segment(0),l1),l1=new Linea2(shape2.pt[n-2],p2),addlineare("br","sx",shape.segment(n-2),l1),l1=new Linea2(p2,p1),addlineare("bb","sotto",l1,shape2.segment(n-1));break}default:addlineare("bl","sx",shape.segment(0),shape2.segment(0)),addlineare("br","dx",shape.segment(n-2),shape2.segment(n-2)),addlineare("bb","sotto",shape.segment(n-1),shape2.segment(n-1))}return draws}var splitter=Object.freeze({__proto__:null,addhoriz:function addhoriz(ff,tipodim,dim,sps,des,align,cuts){let tm=addtaglio(ff,"h",tipodim,dim,sps,des,cuts,align);ff.horiz.push(tm)},addvert:function addvert(ff,tipodim,dim,sps,des,align,cuts){let tm=addtaglio(ff,"v",tipodim,dim,sps,des,align,cuts);ff.vert.push(tm)},bordi:bordi,calcoladivisioni:function calcoladivisioni(ff,shape,shape2){let draws=creabordi(ff,shape,shape2)||[],areas=[],{x:dx,y:dy,horiz:horiz,vert:vert,tipo:tipo,priority:priority,minvano:minvano,minvanox:minvanox,minvanoy:minvanoy}=ff,{bl:bl,br:br,bt:bt,bb:bb}=bordi(ff);minvanox=minvanox||minvano||50,minvanoy=minvanoy||minvano||50;let{dati:h1,punti:ph}=ordinabase(horiz,dy,minvanoy,bb.s,bt.s),{dati:v1,punti:pv}=ordinabase(vert,dx,minvanox,bl.s,br.s);function adddatilin(type,des,l0,l1,id){let tm=pushlineare(ff,type,des,l0,l1,id,shape2,areas);tm?.shape&&draws.push({pt:tm.shape,type:type})}function isinseg(segs,v){return!!segs.find((e=>e.a<=v&&e.b>=v))}for(var h of(v1.forEach(((v,i)=>{v.segs=generatesegments(ph,v.cuts,!0),v.segs.forEach(((s,j)=>{let l0=new Linea2({x:v.x,y:s.a},{x:v.x,y:s.b}),l1=new Linea2({x:v.x+v.sp,y:s.a},{x:v.x+v.sp,y:s.b});adddatilin(v.sp?"v":"l","vert",l0,l1,v.id)}))})),h1)){let cuts=[...h.cuts],pv1=[...pv];for(var v of v1)pv1.push({a:v.x,b:v.x+v.sp}),isinseg(v.segs,h.x+h.sp/2)&&cuts.push(v.x+v.sp/2);h.segs=generatesegments(pv1,cuts,!0,!0);for(let s of h.segs){let l0=new Linea2({x:s.a,y:h.x+h.sp},{x:s.b,y:h.x+h.sp}),l1=new Linea2({x:s.a,y:h.x},{x:s.b,y:h.x});adddatilin(h.sp?"h":"l","oriz",l0,l1,h.id)}}let res=shapeclip().areesplitter(shape2.pt,areas);for(let d of res){let s=getshape().frompt(d),{p1:p1,width:width,height:height,isrect:isrect}=s.dims(),ix=s.pt.findIndex((p=>Math.abs(p.x-p1.x)<.001&&Math.abs(p.y-p1.y)<.001));ix>0&&s.selezionaprimo(ix),ff.dati.push({id:-1,type:"a",des:"area",shape:isrect?null:s.pt,info:{isrect:isrect,p1:p1,width:width,height:height}}),draws.push({pt:s.pt,type:isrect?"a":"as"})}return{ff:ff,h1:h1,ph:ph,v1:v1,pv:pv,draws:draws,areas:areas}},creabordi:creabordi,create:function create(x,y,bordo,options){options||(options={});let{minvano:minvano,priority:priority,taglio:taglio,tipo:tipo,h1:h1,h2:h2,d1:d1,d2:d2,l1:l1,l2:l2,x1:x1,x2:x2,y1:y1,y2:y2}=options;minvano||(minvano=50);let ff={x:x||1e3,y:y||1e3,bordo:bordo||0,minvano:minvano||50,priority:priorita[priority]?priority:"v",taglio:tagli[taglio]?taglio:"d",tipo:tipi[tipo]?tipo:"x",h1:h1||y1||0,h2:h2||y2||0,l1:l1||d1||x1||0,l2:l2||d2||x2||0,vert:[],horiz:[],dati:[],countid:1e3};return delete options.x1,delete options.x2,delete options.d1,delete options.d2,delete options.y1,delete options.y2,ff={...options,...ff},ff},findid:function findid(ff,id){let f=ff.vert.find((e=>e.id==id));return f||(f=ff.horiz.find((e=>e.id==id))),{f:f}},generatesegments:generatesegments,internalshape:internalshape,makeshape:function makeshape(ff){let shape,{x:x,y:y,tipo:tipo,h1:h1,h2:h2,l1:l1,l2:l2}=ff;if(x>0&&y>0){let pts=[0,0];switch(tipo){case"i":pts.push(0,h1>0&&h1<y?y-h1:y),pts.push(x,h2>0&&h2<y&&h2!=h1?y-h2:y),pts.push(x,0),shape=getshape().fromvec(pts);break;case"a":if(h2=h2||h1||0,y-h1>=y-x/2&&y-h1<=y&&y-h2>=y-x/2&&y-h2<=y){let str=`0;0;a30;0;${y-h1};${x/2};${y};${x};${y-h2};${x};0`.replaceAll(",",".");shape=getshape().fromstr(str)}else pts.push(x,y,0,y),shape=getshape().fromvec(pts);break;case"s":case"d":l1=l1||0,l2=l2||0,l1&&l1<x&&h1>0&&h1<y?pts.push(0,y-h1,l1,y):pts.push(0,y),l2&&l2+l1<x&&h2>0&&h2<y?pts.push(x-l2,y,x,y-h2):0==l2&&l1>0&&l1<x&&h2>0&&h2<y?pts.push(x,y-h2):(l2=0,pts.push(x,y)),pts.push(x,0),shape=getshape().fromvec(pts);break;default:pts.push(0,y,x,y,x,0),shape=getshape().fromvec(pts)}}return ff.dati=[],{shape:shape,internalshape:internalshape(ff,shape)}},priorita:priorita,pushlineare:pushlineare,pushshape:pushshape,tagli:tagli,tipi:tipi,tipoalign:tipoalign,tipocut:tipocut});async function valutagrafica(amb,startmacro,rulespec,progetto,fnreload){let{getcolonne:getcolonne,muCalc:muCalc,muEval:muEval,tipifree:tipifree}=amb.muvalutatore;for(var x of(rulespec||(rulespec={}),["l","a","p"])){!amb.vari.var(x)&&startmacro.dims&&amb.vari.add(x,String(startmacro.dims[x].val||100))}let fnlist=new Set;const PARSGLOBAL=["sl","sa","sp","ul","ua","up","ax","ay","az","scx","scy","scz","scale"];let isfnreload=!1,oo=await muEval(amb,startmacro,startmacro.codice,{leveleval:0,checkheader:async op=>{let{variante:variante}=op;if(Array.isArray(startmacro.head)){let ff=startmacro.head.find((e=>e.cod==variante));isfnreload=!!ff}},grafica:async _op=>{let p2,cadv,iscad,des,fatti,{id:id,pars:pars,parametri:parametri,macro:macro,options:options,vari:vari}=_op,isheader=!!(macro&&macro.head&&macro.head.length),sv={l:amb.vari.var("l"),a:amb.vari.var("a"),p:amb.vari.var("p")};const varcad=["l","a","p","#d",...PARSGLOBAL];for(var x of varcad){let tm=amb.vari.dictionary[x];tm&&(sv[x]=tm)}async function _parsepars(x,head){let k,v,r9=/^\#(d|des|descrizione)\s*=\s*(.*)\s*$/im.exec(x);if(r9)k="#d",v=await amb.vari.valuta(r9[2]);else{let result=await vari.parametrokeyval(x);k=result.k,v=result.v}k&&!fatti[k]&&(fatti[k]=!0,varcad.includes(k)?"#d"==k?des=v:("string"==typeof v&&(v=muCalc(v)),["l","a","p"].includes(k)&&amb.vari.add(k,String(v)),cadv[k]=v,iscad=!0):"string"==typeof v?head&&tipifree.includes(head.t)?p2.push(`${k}=${v}`):p2.push(`${k}=${v.split(",")[0]}`):amb.vari.add(k,v))}if(p2=[],cadv={},iscad=!1,des="",fatti={},progetto&&progetto.keys&&progetto.keys[id]){let px=progetto.keys[id].pars;if(px)for(let t in px){let t1=amb.vari.dictionary[t];t1&&(sv[t]=t1),await _parsepars(`${t}=${px[t]}`)}}if(pars&&pars.length)for(const par of pars)await _parsepars(par);if(parametri&&parametri.length)for(const param of parametri)await _parsepars(param);if(macro&&macro.head&&macro.head.length){let tm=macro.head.filter((e=>!["g"].includes(e.t)));for(const h of tm)await _parsepars(h.cod,h)}let out={iscad:iscad,isheader:isheader,name:macro.name,des:des,leveleval:options.leveleval};isheader&&id&&(out.id=id),iscad&&(cadv.l?amb.vari.add("l",String(cadv.l)):cadv.l=muCalc(amb.vari.var("l")),cadv.a?amb.vari.add("a",String(cadv.a)):cadv.a=muCalc(amb.vari.var("a")),cadv.p?amb.vari.add("p",String(cadv.p)):cadv.p=muCalc(amb.vari.var("p")),out.cadv=cadv),await macro.impostaparametri(parametri,p2,!0);let ruleid=rulespec[id];if(id&&isheader&&ruleid&&ruleid.pars&&(out.pars=ruleid.pars,options.leveleval++,await macro.setparametri(ruleid.pars)),out.rows=await muEval(amb,macro,macro.codice,options),id&&isheader&&(out.spars=macro.getparametri()),iscad)for(var x in sv)amb.vari.dictionary[x]=sv[x];return out},parsefnpunto:async _op=>{let{dati:dati,vari:vari,id:id,output:output}=_op;dati=dati.trim();let q=dati.indexOf(" "),q2=dati.indexOf(",");q2>0&&q>0&&q2<q&&(q=q2);let fn,pp,pars={},p2={};for(var p of(q>1?(fn=dati.slice(1,q),pp=getcolonne(dati.slice(q+1))):(fn=dati.slice(1),pp=[]),fnlist.has(fn)||fnlist.add(fn),pp)){let{k:k,v:v}=await vari.parametrokeyval(p);k&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)&&v&&(pars[k]=v)}for(var l of["l","a","p"])pars[l]||(pars[l]=vari.var(l));let tm=Object.keys(pars);for(var l of PARSGLOBAL)tm.includes(l)&&(p2[l]=muCalc(pars[l]),delete pars[l]);output.push({t:"fn",fn:fn,id:id,pars:pars,p2:p2})}});return isfnreload&&"function"==typeof fnreload&&await fnreload(),{oo:oo,vari:amb.vari.dump(!0),fnlist:[...fnlist]}}function ismacro(row){return"object"==typeof row&&row?.name&&row.rows}function isfn(row){return"object"==typeof row&&"fn"==row?.t}function getnodebyid(id,nodocorrente){let res;return nodocorrente&&nodocorrente.rows&&function _getnode(rows){for(var x of rows){if(ismacro(x)){if(x.id==id)return void(res=x);x.rows&&_getnode(x.rows)}if(res)return}}(nodocorrente.rows),res}function getsubrules(nodocorrente){let res=[];return res.push({id:"",level:0,name:"home"}),function _xfiltrati(rr,level){if(rr.rows&&rr.rows.length)for(var x of rr.rows)ismacro(x)&&(x.id&&x.isheader?(res.push({id:x.id,name:x.name,des:x.des||"",spec:x.pars?1:0,level:level}),_xfiltrati(x,level+1)):_xfiltrati(x,level))}(nodocorrente,1),res}function getprojectkeys(project){return project.keys={},function _getkeys(node){if(node.rows&&node.rows.length)for(var x of node.rows)ismacro(x)&&(x.id&&x.isheader&&x.pars&&(project.keys[x.id]={name:x.name,des:x.des||"",pars:x.pars}),_getkeys(x))}(project),project}function getdumpmacro(nodo){let cl=[];return function _dumpnodo(node){if(node.rows&&node.rows.length)for(var x of node.rows)if(ismacro(x)){x.name;let c=[];if(x.iscad&&x.cadv)for(var k in x.cadv){let t=x.cadv[k];"number"==typeof t&&t&&c.push(`${k}=${t}`)}if(x.pars)for(var k in x.pars){let t=x.pars[k];c.push(`${k}=${t}`)}c.length&&cl.push(`--\x3e ${x.name} ${c.join(",")}`),_dumpnodo(x),c.length&&cl.push("<--")}else isfn(x)?cl.push(`FN: ${x.fn} ${JSON.stringify(x.pars)}`):"string"==typeof x&&x.length&&cl.push(x)}(nodo),cl.join("\n")}export{Linea2,Matrix3D,PIF,Punto2,splitter as SP,Vis2d,angle2vec,angle3point,clamp,getdumpmacro,getnodebyid,getprojectkeys,getptsoffset,getshape,getsubrules,hash,isfn,ismacro,normal2,raccordabezier,shapeclip,valutagrafica};
1
+ class Matrix3D{constructor(){this.m=new Float32Array(16),this.st=[],this.init()}init(){return this.m.fill(0),this.m[0]=this.m[5]=this.m[10]=this.m[15]=1,this}atranslate(x,y,z){return this.m[12]+=x,this.m[13]+=y,this.m[14]+=z,this}translate(x,y,z){return x??=0,y??=0,z??=0,this.m[12]+=x*this.m[0]+y*this.m[4]+z*this.m[8],this.m[13]+=x*this.m[1]+y*this.m[5]+z*this.m[9],this.m[14]+=x*this.m[2]+y*this.m[6]+z*this.m[10],this.m[15]+=x*this.m[3]+y*this.m[7]+z*this.m[11],this}rotateX(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateY(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[8]*s,this.m[1]=a[1]*c+a[9]*s,this.m[2]=a[2]*c+a[10]*s,this.m[3]=a[3]*c+a[11]*s,this.m[8]=a[0]*-s+a[8]*c,this.m[9]=a[1]*-s+a[9]*c,this.m[10]=a[2]*-s+a[10]*c,this.m[11]=a[3]*-s+a[11]*c}return this}rotateZ(angolo){if(angolo){const rad=(angolo||0)*Math.PI/180,s=Math.sin(rad),c=Math.cos(rad),a=[...this.m];this.m[0]=a[0]*c+a[4]*s,this.m[1]=a[1]*c+a[5]*s,this.m[2]=a[2]*c+a[6]*s,this.m[3]=a[3]*c+a[7]*s,this.m[4]=a[0]*-s+a[4]*c,this.m[5]=a[1]*-s+a[5]*c,this.m[6]=a[2]*-s+a[6]*c,this.m[7]=a[3]*-s+a[7]*c}return this}getdati(){return Array.from(this.m)}setdati(d){if(d&&16===d.length){for(let i=0;i<16;i++)this.m[i]=Number(d[i])||0;return this}this.init()}push(){return this.st.push(new Float32Array(this.m)),this}pop(){return this.st.length>0&&(this.m=this.st.pop()),this}transform(x,y,z=0){return{x:x*this.m[0]+y*this.m[4]+z*this.m[8]+this.m[12],y:x*this.m[1]+y*this.m[5]+z*this.m[9]+this.m[13],z:x*this.m[2]+y*this.m[6]+z*this.m[10]+this.m[14]}}invert(){const m=this.m,inv=new Matrix3D,det=this.determinant();return Math.abs(det)<1e-8?null:(inv.m[0]=(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])/det,inv.m[1]=(m[1]*m[14]*m[11]+m[9]*m[2]*m[15]+m[13]*m[10]*m[3]-m[1]*m[10]*m[15]-m[9]*m[14]*m[3]-m[13]*m[2]*m[11])/det,inv.m[2]=(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])/det,inv.m[3]=(m[1]*m[10]*m[7]+m[5]*m[2]*m[11]+m[9]*m[6]*m[3]-m[1]*m[6]*m[11]-m[5]*m[10]*m[3]-m[9]*m[2]*m[7])/det,inv.m[4]=(m[4]*m[14]*m[11]+m[8]*m[6]*m[15]+m[12]*m[10]*m[7]-m[4]*m[10]*m[15]-m[8]*m[14]*m[7]-m[12]*m[6]*m[11])/det,inv.m[5]=(m[0]*m[10]*m[15]+m[8]*m[14]*m[3]+m[12]*m[2]*m[11]-m[0]*m[14]*m[11]-m[8]*m[2]*m[15]-m[12]*m[10]*m[3])/det,inv.m[6]=(m[0]*m[14]*m[7]+m[4]*m[2]*m[15]+m[12]*m[6]*m[3]-m[0]*m[6]*m[15]-m[4]*m[14]*m[3]-m[12]*m[2]*m[7])/det,inv.m[7]=(m[0]*m[6]*m[11]+m[4]*m[10]*m[3]+m[8]*m[2]*m[7]-m[0]*m[10]*m[7]-m[4]*m[2]*m[11]-m[8]*m[6]*m[3])/det,inv.m[8]=(m[4]*m[9]*m[15]+m[8]*m[13]*m[7]+m[12]*m[5]*m[11]-m[4]*m[13]*m[11]-m[8]*m[5]*m[15]-m[12]*m[9]*m[7])/det,inv.m[9]=(m[0]*m[13]*m[11]+m[8]*m[1]*m[15]+m[12]*m[9]*m[3]-m[0]*m[9]*m[15]-m[8]*m[13]*m[3]-m[12]*m[1]*m[11])/det,inv.m[10]=(m[0]*m[5]*m[15]+m[4]*m[13]*m[3]+m[12]*m[1]*m[7]-m[0]*m[13]*m[7]-m[4]*m[1]*m[15]-m[12]*m[5]*m[3])/det,inv.m[11]=(m[0]*m[9]*m[7]+m[4]*m[1]*m[11]+m[8]*m[5]*m[3]-m[0]*m[5]*m[11]-m[4]*m[9]*m[3]-m[8]*m[1]*m[7])/det,inv.m[12]=(m[4]*m[13]*m[10]+m[8]*m[5]*m[14]+m[12]*m[9]*m[6]-m[4]*m[9]*m[14]-m[8]*m[13]*m[6]-m[12]*m[5]*m[10])/det,inv.m[13]=(m[0]*m[9]*m[14]+m[8]*m[13]*m[2]+m[12]*m[1]*m[10]-m[0]*m[13]*m[10]-m[8]*m[1]*m[14]-m[12]*m[9]*m[2])/det,inv.m[14]=(m[0]*m[13]*m[6]+m[4]*m[1]*m[14]+m[12]*m[5]*m[2]-m[0]*m[5]*m[14]-m[4]*m[13]*m[2]-m[12]*m[1]*m[6])/det,inv.m[15]=(m[0]*m[5]*m[10]+m[4]*m[9]*m[2]+m[8]*m[1]*m[6]-m[0]*m[9]*m[6]-m[4]*m[1]*m[10]-m[8]*m[5]*m[2])/det,inv)}determinant(){const m=this.m;return m[0]*(m[5]*m[10]*m[15]+m[9]*m[14]*m[7]+m[13]*m[6]*m[11]-m[5]*m[14]*m[11]-m[9]*m[6]*m[15]-m[13]*m[10]*m[7])-m[4]*(m[1]*m[10]*m[15]+m[9]*m[14]*m[3]+m[13]*m[2]*m[11]-m[1]*m[14]*m[11]-m[9]*m[2]*m[15]-m[13]*m[10]*m[3])+m[8]*(m[1]*m[6]*m[15]+m[5]*m[14]*m[3]+m[13]*m[2]*m[7]-m[1]*m[14]*m[7]-m[5]*m[2]*m[15]-m[13]*m[6]*m[3])-m[12]*(m[1]*m[6]*m[11]+m[5]*m[10]*m[3]+m[9]*m[2]*m[7]-m[1]*m[10]*m[7]-m[5]*m[2]*m[11]-m[9]*m[6]*m[3])}multiply(matrix){const a=[...this.m],b=matrix.m;return this.m[0]=a[0]*b[0]+a[4]*b[1]+a[8]*b[2]+a[12]*b[3],this.m[1]=a[1]*b[0]+a[5]*b[1]+a[9]*b[2]+a[13]*b[3],this.m[2]=a[2]*b[0]+a[6]*b[1]+a[10]*b[2]+a[14]*b[3],this.m[3]=a[3]*b[0]+a[7]*b[1]+a[11]*b[2]+a[15]*b[3],this.m[4]=a[0]*b[4]+a[4]*b[5]+a[8]*b[6]+a[12]*b[7],this.m[5]=a[1]*b[4]+a[5]*b[5]+a[9]*b[6]+a[13]*b[7],this.m[6]=a[2]*b[4]+a[6]*b[5]+a[10]*b[6]+a[14]*b[7],this.m[7]=a[3]*b[4]+a[7]*b[5]+a[11]*b[6]+a[15]*b[7],this.m[8]=a[0]*b[8]+a[4]*b[9]+a[8]*b[10]+a[12]*b[11],this.m[9]=a[1]*b[8]+a[5]*b[9]+a[9]*b[10]+a[13]*b[11],this.m[10]=a[2]*b[8]+a[6]*b[9]+a[10]*b[10]+a[14]*b[11],this.m[11]=a[3]*b[8]+a[7]*b[9]+a[11]*b[10]+a[15]*b[11],this.m[12]=a[0]*b[12]+a[4]*b[13]+a[8]*b[14]+a[12]*b[15],this.m[13]=a[1]*b[12]+a[5]*b[13]+a[9]*b[14]+a[13]*b[15],this.m[14]=a[2]*b[12]+a[6]*b[13]+a[10]*b[14]+a[14]*b[15],this.m[15]=a[3]*b[12]+a[7]*b[13]+a[11]*b[14]+a[15]*b[15],this}}class Punto2{constructor(x,y){Array.isArray(x)?(this.x=x[0]||0,this.y=x[1]||0):x&&"object"==typeof x?(this.x=x.x||0,this.y=x.y||0):(this.x=x||0,this.y=y||0)}get dump(){return`{${this.x.toFixed(1)},${this.y.toFixed(1)}}`}get len2(){return this.x*this.x+this.y*this.y}get len(){return Math.sqrt(this.len2)}get angle(){return Math.atan2(this.y,this.x)}dir(){let l=this.len;return l?new Punto2(this.x/l,this.y/l):this}}class Linea2{constructor(p1,p2,x2=null,y2=null){"number"==typeof p1&&"number"==typeof p2&&null!==x2&&null!==y2?(this.p1=new Punto2({x:p1,y:p2}),this.p2=new Punto2({x:x2,y:y2})):p1&&p2?(this.p1=new Punto2(p1),this.p2=new Punto2(p2)):(this.p1=new Punto2(0,0),this.p2=new Punto2(1,0))}get dump(){return`${this.p1.dump}-${this.p2.dump}`}get dx(){return this.p2.x-this.p1.x}get dy(){return this.p2.y-this.p1.y}get len2(){let{dx:dx,dy:dy}=this;return dx*dx+dy*dy}get len(){return Math.sqrt(this.len2)}estendi(l){if("number"==typeof l){if(!l)return this;let{p1:p1,p2:p2,dx:dx,dy:dy,len:len}=this;return len?(dx/=len,dy/=len,l>0?new Linea2(p1,new Punto2(p2.x+dx*l,p2.y+dy*l)):new Linea2(new Punto2(p1.x+dx*l,p1.y+dy*l),p2)):this}if(l instanceof Linea2){const intersectionPoint=this.intersection(l);if(!intersectionPoint)return this;return(intersectionPoint.x-this.p1.x)**2+(intersectionPoint.y-this.p1.y)**2<(intersectionPoint.x-this.p2.x)**2+(intersectionPoint.y-this.p2.y)**2?new Linea2(intersectionPoint,this.p2):new Linea2(this.p1,intersectionPoint)}}get direzione(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(dx/len,dy/len):new Punto2(0,0)}get normale(){let{dx:dx,dy:dy,len:len}=this;return len?new Punto2(-dy/len,dx/len):new Punto2(0,1)}ruotata(angle=Math.PI/2,length=0,fine=!1){const{p1:p1,p2:p2,direzione:direzione,len:len}=this;length=length||len;const sx=(direzione.x*Math.cos(angle)-direzione.y*Math.sin(angle))*length,sy=(direzione.x*Math.sin(angle)+direzione.y*Math.cos(angle))*length;return fine?new Linea2(p1,new Punto2(p1.x+sx,p1.y+sy)):new Linea2(p2,new Punto2(p2.x+sx,p2.y+sy))}puntosudirezione(p1,lunghezza){let{direzione:direzione}=this;return new Punto2(p1.x+direzione.x*lunghezza,p1.y+direzione.y*lunghezza)}parallela(p1,lunghezza){let{direzione:direzione}=this;return new Linea2(p1,this.puntosudirezione(p1,lunghezza))}intersezione(line2){const{p1:p1_1,p2:p2_1}=this,{p1:p1_2,p2:p2_2}=line2,det=(p2_1.x-p1_1.x)*(p2_2.y-p1_2.y)-(p2_1.y-p1_1.y)*(p2_2.x-p1_2.x);if(Math.abs(det)<.001)return null;const t=((p1_2.x-p1_1.x)*(p2_2.y-p1_2.y)-(p1_2.y-p1_1.y)*(p2_2.x-p1_2.x))/det;return new Punto2(p1_1.x+t*(p2_1.x-p1_1.x),p1_1.y+t*(p2_1.y-p1_1.y))}onsegment(p,eps=1e-9){const{p1:p1,p2:p2}=this,minX=Math.min(p1.x,p2.x)-eps,maxX=Math.max(p1.x,p2.x)+eps,minY=Math.min(p1.y,p2.y)-eps,maxY=Math.max(p1.y,p2.y)+eps;return p.x>=minX&&p.x<=maxX&&p.y>=minY&&p.y<=maxY}isparallela(line2){const det=this.dx*line2.dy-this.dy*line2.dx;return Math.abs(det)<.001}infoquad(line2){if(!this.isparallela(line2))return;const{p1:p1,p2:p2,normale:normale}=this;let{p1:p3,p2:p4}=line2;function wrapToPi(theta){return theta>Math.PI?theta-=2*Math.PI:theta<-Math.PI&&(theta+=2*Math.PI),theta}function getangle(a,b){return Math.atan2(b.y-a.y,b.x-a.x)}(p2.x-p1.x)*(p3.y-p2.y)-(p2.y-p1.y)*(p3.x-p2.x)<0&&([p3,p4]=[p4,p3]);const baseAng=getangle(p1,p2),afin=wrapToPi(getangle(p2,p3)-baseAng),aini=wrapToPi(getangle(p1,p4)-baseAng),l=this.len,dx=p3.x-p1.x,dy=p3.y-p1.y;return{angle:baseAng,aini:aini,afin:afin,l:l,distanza:Math.abs(dx*normale.x+dy*normale.y)}}isperpendicolare(line2){const dotProduct=this.dx*line2.dx+this.dy*line2.dy;return Math.abs(dotProduct)<.001}offset(delta){const normale=this.normale,p1_offset=new Punto2(this.p1.x+normale.x*delta,this.p1.y+normale.y*delta),p2_offset=new Punto2(this.p2.x+normale.x*delta,this.p2.y+normale.y*delta);return new Linea2(p1_offset,p2_offset)}angolo(line2){const{dx:dx1,dy:dy1}=this,{dx:dx2,dy:dy2}=line2,a1=Math.atan2(dy1,dx1);let delta=Math.atan2(dy2,dx2)-a1;return delta>Math.PI?delta-=2*Math.PI:delta<-Math.PI&&(delta+=2*Math.PI),delta}ortopt(l){let{p1:p1,dx:dx,dy:dy}=this;const len=Math.hypot(dx,dy);if(len<.001)return;const ux=-dy/len,uy=dx/len;return{x:p1.x+ux*l,y:p1.y+uy*l}}offsetline(l){let{p1:p1,p2:p2,dx:dx,dy:dy}=this;const len=Math.hypot(dx,dy);if(len<.001)return;const ux=-dy/len,uy=dx/len;return new Linea2({x:p1.x+ux*l,y:p1.y+uy*l},{x:p2.x+ux*l,y:p2.y+uy*l})}distanzaSegmentiParalleli(line2){if(!this.isparallela(line2))return 1e9;const{p1:p1,normale:normale}=this,dx=line2.p1.x-p1.x,dy=line2.p1.y-p1.y,distanza=Math.abs(dx*normale.x+dy*normale.y);return Math.abs(distanza)<.001?0:distanza}isCollineare(line2,checkpunticomune=!1){if(!this.isparallela(line2))return!1;const distanza=this.distanzaSegmentiParalleli(line2);if(Math.abs(distanza)>.001)return!1;if(checkpunticomune){const isPointBetween=(p,a,b)=>Math.min(a.x,b.x)<=p.x&&p.x<=Math.max(a.x,b.x)&&Math.min(a.y,b.y)<=p.y&&p.y<=Math.max(a.y,b.y),{p1:p1,p2:p2}=this,{p1:p1_2,p2:p2_2}=line2;return isPointBetween(p1_2,p1,p2)||isPointBetween(p2_2,p1,p2)||isPointBetween(p1,p1_2,p2_2)||isPointBetween(p2,p1_2,p2_2)}return!0}}function getptsoffset(pt,pt2,delta){let k1,k2,a1,a2,i1=-1,i2=-1,n=pt.length,np=pt2.length,offpt=[],l1a=new Linea2(pt[0],pt[1]),l2a=new Linea2(pt[n-2],pt[n-1]),l1=l1a.offset(delta),l2=l2a.offset(delta);for(var i=0;i<np;i++){let l=new Linea2(pt2[i%np],pt2[(i+1)%np]);l1.isparallela(l)&&l1.isCollineare(l,!0)&&(i1=i),l2.isparallela(l)&&l2.isCollineare(l,!0)&&(i2=i)}if(i1>=0&&i2>=0){i1>i2?(k1=i1-i2+2,k2=i2+np-i1+2,k1<k2?(a1=i2,a2=i1+1):(a1=i1,a2=i2+np+1)):(k1=i2-i1+2,k2=i1+np-i2+2,k1<k2?(a1=i1,a2=i2+1):(a1=i2,a2=i1+np+1));for(let i=a1;i<=a2;i++)offpt.push(pt2[i%np])}return offpt}function hash(obj){let str="";if("string"==typeof obj||"number"==typeof obj)str=obj+"";else if("object"==typeof obj&&obj){const chiaviOrdinati=Object.keys(obj).sort(),separatore="\0";str=chiaviOrdinati.map((key=>`${key}${separatore}${String(obj[key])}`)).join(separatore)}let h1=2166136261,h2=2218511855;for(let i=0;i<str.length;i++){const char=str.charCodeAt(i);h1^=char,h1+=h1<<5^2779096485,h2^=h1,h2=((h2<<3)+char^2134516169)>>>0}return h1>>>=0,h1.toString(16)+h2.toString(16)}function clamp(n,min=-1/0,max=1/0){return(n=Number(n)||0)<min&&(n=min),n>max&&(n=max),n}function getSqSegDist(p,p1,p2){var x=p1.x,y=p1.y,dx=p2.x-x,dy=p2.y-y;if(0!==dx||0!==dy){var t=((p.x-x)*dx+(p.y-y)*dy)/(dx*dx+dy*dy);t>1?(x=p2.x,y=p2.y):t>0&&(x+=dx*t,y+=dy*t)}return(dx=p.x-x)*dx+(dy=p.y-y)*dy}function simplifyDPStep(points,first,last,sqTolerance,simplified){for(var index,maxSqDist=sqTolerance,i=first+1;i<last;i++){var sqDist=getSqSegDist(points[i],points[first],points[last]);sqDist>maxSqDist&&(index=i,maxSqDist=sqDist)}maxSqDist>sqTolerance&&(index-first>1&&simplifyDPStep(points,first,index,sqTolerance,simplified),simplified.push(points[index]),last-index>1&&simplifyDPStep(points,index,last,sqTolerance,simplified))}function simplifyDouglasPeucker(points,sqTolerance){var last=points.length-1,simplified=[points[0]];return simplifyDPStep(points,0,last,sqTolerance,simplified),simplified.push(points[last]),simplified}new class Errori{constructor(){this.azzera()}azzera(){this.err=[]}add(msg,row){this.err.push({msg:msg,row:row})}get(){return this.err}get length(){return this.err.length}toString(){var cl=[];for(var e of this.err){let m="object"==typeof e.msg?JSON.stringify(e.msg):e.msg||"";cl.push(`${e.row?e.row+":":""}${m}`)}return cl.join("\n")}},Date.prototype.toInt||(Date.prototype.toInt=function(){return this.getDate()+100*(this.getMonth()+1)+1e4*this.getFullYear()}),Date.prototype.toFloat||(Date.prototype.toFloat=function(){return Math.floor(1e4*this.getDate()+1e6*(this.getMonth()+1)+1e8*this.getFullYear()+100*this.getHours()+this.getMinutes()+.5)/1e4});const PIF=Math.PI/180;function raccordabezier(a1,a2,b1,b2,subdivisions=10){const intersection=function getIntersection(p1,p2,p3,p4){const denom=(p1.x-p2.x)*(p3.y-p4.y)-(p1.y-p2.y)*(p3.x-p4.x);return 0===denom?null:{x:((p1.x*p2.y-p1.y*p2.x)*(p3.x-p4.x)-(p1.x-p2.x)*(p3.x*p4.y-p3.y*p4.x))/denom,y:((p1.x*p2.y-p1.y*p2.x)*(p3.y-p4.y)-(p1.y-p2.y)*(p3.x*p4.y-p3.y*p4.x))/denom}}(a1,a2,b1,b2);if(!intersection)return[{x:a2.x,y:a2.y},{x:b1.x,y:b1.y}];const control=intersection;if(0===subdivisions)return[{x:a2.x,y:a2.y},{x:b1.x,y:b1.y}];const curvePoints=[];for(let i=0;i<=subdivisions;i++){const t=i/subdivisions,oneMinusT=1-t,x=oneMinusT*oneMinusT*a2.x+2*oneMinusT*t*control.x+t*t*b1.x,y=oneMinusT*oneMinusT*a2.y+2*oneMinusT*t*control.y+t*t*b1.y;curvePoints.push({x:x,y:y})}return curvePoints}function raccordabezier3(a1,a2,a3,d,subdivisions=10){const v1_x=a2.x-a1.x,v1_y=a2.y-a1.y,v2_x=a3.x-a2.x,v2_y=a3.y-a2.y,len1=Math.sqrt(v1_x*v1_x+v1_y*v1_y),len2=Math.sqrt(v2_x*v2_x+v2_y*v2_y);if(d>len1||d>len2)return[a1,a2,a3];d!=len1&&d!=len2||(d-=.01);const t1=(len1-d)/len1,t2=d/len2;return raccordabezier(a1,{x:a1.x+v1_x*t1,y:a1.y+v1_y*t1},{x:a2.x+v2_x*t2,y:a2.y+v2_y*t2},a3,subdivisions)}function normal2(p1,p2){const dx=p2.x-p1.x;let nx=-(p2.y-p1.y),ny=dx;const length=Math.sqrt(nx*nx+ny*ny);return 0===length?{nx:0,ny:0}:{nx:nx/length,ny:ny/length}}function angle3point(p1,p2,p3){const u_x=p2.x-p1.x,u_y=p2.y-p1.y,v_x=p3.x-p2.x,v_y=p3.y-p2.y,dot=u_x*v_x+u_y*v_y,cross=u_x*v_y-u_y*v_x,magU=Math.sqrt(u_x**2+u_y**2),magV=Math.sqrt(v_x**2+v_y**2);return magU&&magV?Math.atan2(cross,dot):0}function angle2vec(v1,v2){const dot=v1.x*v2.x+v1.y*v2.y,mag1=Math.sqrt(v1.x*v1.x+v1.y*v1.y),mag2=Math.sqrt(v2.x*v2.x+v2.y*v2.y);if(0===mag1||0===mag2)return 0;let cosTheta=dot/(mag1*mag2);cosTheta=Math.max(-1,Math.min(1,cosTheta));return Math.acos(cosTheta)/PIF}function removeduplicate(path,delta=.005){if(!Array.isArray(path)||0===path.length)return[];const deltaSq=delta*delta,cleanedPath=[],n=path.length;for(let i=0;i<n;i++){const current=path[i],next=path[(i+1)%n];cleanedPath.push({x:current.x,y:current.y});const dx=next.x-current.x,dy=next.y-current.y;dx*dx+dy*dy<=deltaSq&&i++}if(cleanedPath.length>1){const first=cleanedPath[0],last=cleanedPath[cleanedPath.length-1],dx=first.x-last.x,dy=first.y-last.y;dx*dx+dy*dy<=deltaSq&&cleanedPath.pop()}return cleanedPath}function getshape(){let pt=[];function orientation(){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.x*next.y-next.x*current.y}return area>0?1:area<0?-1:0}function tovec(){let vv=[];for(let p of pt)vv.push(p.x),vv.push(p.y);return vv}function _addvec(aa){for(let i=0;i<aa.length;i+=2)pt.push({x:aa[i],y:aa[i+1]})}function dims(pts){let{p1:p1,p2:p2}=pts.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}),isrect=!1;if(4==pts.length){const TOLL=.001;function findpunto(x,y){return!!pts.find((p=>Math.abs(p.x-x)<TOLL&&Math.abs(p.y-y)<TOLL))}findpunto(p1.x,p1.y)&&findpunto(p1.x,p2.y)&&findpunto(p2.x,p1.y)&&findpunto(p2.x,p2.y)&&(isrect=!0)}return{p1:p1,p2:p2,isrect:isrect,width:p2.x-p1.x,height:p2.y-p1.y}}return{get key(){return hash(tovec().join("\t"))},orienta:function orienta(p0,p1){if(!p0||!p1)return null;const dx=p1.x-p0.x,dy=p1.y-p0.y,angolo=180*Math.atan2(dy,dx)/Math.PI,matrix=new Matrix3D;matrix.rotateZ(-angolo),matrix.translate(-p0.x,-p0.y,0);const ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y)));let mm=ptTrasformati.reduce(((m,p)=>(m.p1.x=Math.min(m.p1.x,p.x),m.p2.x=Math.max(m.p2.x,p.x),m.p1.y=Math.min(m.p1.y,p.y),m.p2.y=Math.max(m.p2.y,p.y),m)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)});return{shape:getshape().frompt(ptTrasformati),origine:new Punto2(p0.x,p0.y),angolo:angolo,mm:mm,width:mm.p2.x-mm.p1.x,height:mm.p2.y-mm.p1.y}},rebase:function rebase(angolo,forceorigin=!1,ox=0,oy=0){const matrix=new Matrix3D;matrix.rotateZ(-angolo);let ptTrasformati=pt.map((p=>matrix.transform(p.x,p.y))),{p1:p1,p2:p2,width:width,height:height}=dims(ptTrasformati);return forceorigin||(ox=p1.x,oy=p1.y),ptTrasformati=ptTrasformati.map((p=>new Punto2(p.x-ox,p.y-oy))),{shape:getshape().frompt(ptTrasformati),origine:new Punto2(ox,oy),angolo:angolo,width:width,height:height}},get pt(){return pt},get vec(){return tovec()},toJSON:()=>({vec:tovec(),orient:orientation()}),get orient(){return orientation()},clone:()=>getshape().frompt(pt),dims:()=>dims(pt),rotate(deg){if(!deg)return this;const r=deg*Math.PI/180,cosTheta=Math.cos(r),sinTheta=Math.sin(r);for(let p of pt){const xNew=p.x*cosTheta-p.y*sinTheta,yNew=p.x*sinTheta+p.y*cosTheta;p.x=xNew,p.y=yNew}return this},selezionaprimo:function selezionaprimo(idprimopunto){return(idprimopunto%=pt.length)>0&&(pt=[...pt.slice(idprimopunto),...pt.slice(0,idprimopunto)]),this},segment(i,inverse=!1){let n=pt.length;return new Linea2(pt[i%n],pt[(i+(inverse?-1:1))%n])},lineoffset(i1,i2,offset){if((i1=(i1||0)%pt.length)!=(i2=(i2||0)%pt.length)){let l2=new Linea2(pt[i1],pt[i2]);if(l2){return l2=l2.offsetline(-offset),this.intersectline(l2)}}},move(x=0,y=0){for(let p of pt)p.x+=x,p.y+=y;return this},mirrorx(value=0){for(let p of pt)p.x=2*value-p.x;return this},mirrory(value=0){for(let p of pt)p.y=2*value-p.y;return this},simplify(tolerance,hq){return pt=function simplify(points,tolerance,highestQuality){if(points.length<=2)return points;var sqTolerance=void 0!==tolerance?tolerance*tolerance:1;return simplifyDouglasPeucker(points=highestQuality?points:function simplifyRadialDist(points,sqTolerance){for(var point,p1,p2,dx,dy,prevPoint=points[0],newPoints=[prevPoint],i=1,len=points.length;i<len;i++)p2=prevPoint,dx=void 0,dy=void 0,(dx=(p1=point=points[i]).x-p2.x)*dx+(dy=p1.y-p2.y)*dy>sqTolerance&&(newPoints.push(point),prevPoint=point);return prevPoint!==point&&newPoints.push(point),newPoints}(points,sqTolerance),sqTolerance)}(pt,tolerance,hq),this},fromclip(vv){pt=[];for(let p of vv)pt.push({x:p.x/1e3,y:p.y/1e3});return this},infosegmento(i,open=!1){const n=pt.length;function clampIndex(idx){return(idx+n)%n}function angle(p1,p2){return Math.atan2(p2.y-p1.y,p2.x-p1.x)}function angleDiff(a,b){let diff=a-b;for(;diff>Math.PI;)diff-=2*Math.PI;for(;diff<-Math.PI;)diff+=2*Math.PI;return diff}const p1=pt[i];let p0,p2,p3;if(open)if(0===i){const dx=pt[1].x-pt[0].x,dy=pt[1].y-pt[0].y;p0={x:pt[0].x-dx,y:pt[0].y-dy},p2=pt[1],p3=pt[2]}else if(i===n-1){const dx=pt[n-1].x-pt[n-2].x,dy=pt[n-1].y-pt[n-2].y;p0=pt[n-2],p2={x:pt[n-1].x+dx,y:pt[n-1].y+dy},p3={x:p2.x+dx,y:p2.y+dy}}else p0=pt[i-1],p2=pt[i+1],p3=i+2<n?pt[i+2]:{x:pt[i+1].x+(pt[i+1].x-pt[i].x),y:pt[i+1].y+(pt[i+1].y-pt[i].y)};else{const i0=clampIndex(i-1),i2=clampIndex(i+1),i3=clampIndex(i+2);p0=pt[i0],p2=pt[i2],p3=pt[i3]}const ang12=angle(p1,p2),ang01=angle(p0,p1),ang23=angle(p2,p3);return{x:p1.x,y:p1.y,l:function length(p1,p2){const dx=p2.x-p1.x,dy=p2.y-p1.y;return Math.sqrt(dx*dx+dy*dy)}(p1,p2),ang:ang12/PIF,a1:angleDiff(ang12,ang01)/PIF,a2:angleDiff(ang23,ang12)/PIF}},fromvec(aa){return pt=[],_addvec(aa),this},addvec(vec){return _addvec(vec),this},frompt(pts){return pt=[...pts],pt=removeduplicate(pt),this},fromstr(str){return pt=removeduplicate(function processTokens(tokens){const points=[];for(let i=0;i<tokens.length;i++){const token=tokens[i];if("point"===token.type)points.push(token.point);else if("command"===token.type)switch(token.cmd){case"b":{if(points.length<2)continue;const npt=parseInt(token.params[0])||5,p1=points[points.length-2],p2=points[points.length-1];let p3="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p4="point"===tokens[i+2]?.type?tokens[i+2].point:void 0;p3?p4||(p4=points[0]):(p3=points[0],p4=points[1]);const raccordo=raccordabezier(p1,p2,p3,p4,npt);points.push(...raccordo),i+=1;break}case"r":{if(points.length<1)continue;const dist=parseFloat(token.params[0])||5,npt=parseInt(token.params[1])||10,p1=points[points.length-1];let p2="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p3="point"===tokens[i+2]?.type?tokens[i+2].point:"point"===tokens[i+3]?.type?tokens[i+3].point:void 0;p2?p3||(p3=points[0]):(p2=points[0],p3=points[1],points.splice(0,1));const raccordo=raccordabezier3(p1,p2,p3,dist,npt);points.push(...raccordo),i+=1;break}case"c":{const radius=parseFloat(token.params[0])||50,segments=parseInt(token.params[1])||12,center="point"===tokens[i+1]?.type?tokens[i+1].point:new Punto2(0,0);for(let j=0;j<segments;j++)points.push(new Punto2(center.x+radius*Math.cos(j/segments*Math.PI*2),center.y+radius*Math.sin(j/segments*Math.PI*2)));i+=1;break}case"a":{let npt,p1="point"===tokens[i+1]?.type?tokens[i+1].point:void 0,p2="point"===tokens[i+2]?.type?tokens[i+2].point:void 0,p3="point"===tokens[i+3]?.type?tokens[i+3].point:void 0;if(!p1||!p3)continue;if(p2)if(token.params[0])npt=clamp(parseInt(token.params[0]),1,24);else{const chord=Math.hypot(p3.x-p1.x,p3.y-p1.y),sagitta=Math.abs((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))/(2*chord);npt=Math.round(chord*Math.sqrt(sagitta/(chord+.1))*10),npt=clamp(npt,1,24),npt=1}else p2=p3,npt=0;const arcoPoints=arcfrom3point(npt,p1,p2,p3);points.push(...arcoPoints),i+=3;break}}}return points}(function tokenize(str){const tokens=[],values=str.toLowerCase().replace(/[\n\s]+/gm," ").split(/[\,\;]/).map((s=>s.trim()));for(let i=0;i<values.length;){const current=values[i];["b","r","c","a"].includes(current[0])?(tokens.push({type:"command",cmd:current[0],params:current.slice(1).split(":")}),i++):/[a-zA-Z]/.test(current[0])||(i<values.length-1?(tokens.push({type:"point",point:new Punto2(parseFloat(values[i]),parseFloat(values[i+1]))}),i+=2):i++)}return tokens}(str))),this},intersectline:l=>function _intersectline(shape,p3,p4){let n=shape.length,l=new Linea2(p3,p4);const intersezioni=[];for(let i=0;i<shape.length;i++){let l2=new Linea2(shape[i],shape[(i+1)%n]),p=l2.intersezione(l);p&&l2.onsegment(p)&&intersezioni.push(p)}if(intersezioni.length<2)return null;const{dx:dx,dy:dy}=l;intersezioni.sort(((a,b)=>(a.x-p3.x)*dx+(a.y-p3.y)*dy-((b.x-p3.x)*dx+(b.y-p3.y)*dy)));let pstart=new Punto2(intersezioni[0].x,intersezioni[0].y),pend=new Punto2(intersezioni[intersezioni.length-1].x,intersezioni[intersezioni.length-1].y);const vx1=pend.x-pstart.x,vy1=pend.y-pstart.y;return vx1*dx+vy1*dy<0&&([pstart,pend]=[pend,pstart]),new Linea2(pstart,pend)}(pt,l.p1,l.p2),addpt(pts){return pts?(Array.isArray(pts)||(pts=[pts]),pt=removeduplicate([...pt,...pts]),this):this},addracc(v1,v2,suddivisioni=2,addv1v2=!0){if(Array.isArray(v1)&&(v2={x:v1[2]||0,y:v1[3]||0},v1={x:v1[0]||0,y:v1[1]||0}),pt.length>=2){let tm=raccordabezier(pt[pt.length-2],pt[pt.length-1],v1,v2,suddivisioni);pt=[...pt,...tm],addv1v2&&(pt.push(v1),pt.push(v2))}return pt=removeduplicate(pt),this},setorient(mode){let p=orientation();return(1==p&&-1==mode||-1==p&&1==mode)&&pt.reverse(),this},reverse(){return pt.reverse(),this},pointinshape:p=>function isPointInPolygon(P){let x=P.x,y=P.y,inside=!1;for(let i=0,j=pt.length-1;i<pt.length;j=i++){let xi=pt[i].x,yi=pt[i].y,xj=pt[j].x,yj=pt[j].y;yi>y!=yj>y&&x<(xj-xi)*(y-yi)/(yj-yi)+xi&&(inside=!inside)}return inside}(p),azzera(){return pt=[],this},removeduplicate(delta=.005){return pt=removeduplicate(pt,delta),this},to3d(u0,alt=0,coeffa=0,coeffb=0,open=!1){pt=removeduplicate(pt);let tm=function genuvnormal(path,options){let{currentU:currentU=0,c:c=0,a:a=0,b:b=0,anglemin:anglemin=30,open:open=!1}=options;const pointsWithNormals=[],n=path.length;for(let i=0;i<n;i++){const prev=path[(i-1+n)%n],current=path[i],next=path[(i+1)%n],vPrev={x:current.x-prev.x,y:current.y-prev.y},vNext={x:next.x-current.x,y:next.y-current.y},normalPrev=normal2(prev,current),normalNext=normal2(current,next),angle=angle2vec(vPrev,vNext);let z=a*current.x+b*current.y+c;Math.abs(angle-180)<=anglemin?(normalPrev.nx,normalNext.nx,normalPrev.ny,normalNext.ny,pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z})):(pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}),pointsWithNormals.push({x:current.x,y:-current.y,z:z,u:currentU,v:z}));const dx=next.x-current.x,dy=next.y-current.y;currentU+=Math.sqrt(dx*dx+dy*dy)}if(!open){let p=pointsWithNormals[0],pf=pointsWithNormals[pointsWithNormals.length-1];p.x==pf.x&&p.y==pf.y||pointsWithNormals.push({x:p.x,y:p.y,z:p.z,nx:p.nx,ny:p.ny,nz:p.nz,u:currentU,v:p.z})}return pointsWithNormals}(pt,{open:open,currentU:u0,c:alt,a:coeffa,b:coeffb,anglemin:30});return tm},getboundbox:()=>pt.length?pt.reduce(((box,p)=>(box.p1.x=Math.min(box.p1.x,p.x),box.p1.y=Math.min(box.p1.y,p.y),box.p2.x=Math.max(box.p2.x,p.x),box.p2.y=Math.max(box.p2.y,p.y),box)),{p1:new Punto2(1/0,1/0),p2:new Punto2(-1/0,-1/0)}):{p1:new Punto2(0,0),p2:new Punto2(0,0)},fittobox(p1,p2){if(!pt.length)return this;const currentBox=this.getboundbox(),currentWidth=currentBox.p2.x-currentBox.p1.x,currentHeight=currentBox.p2.y-currentBox.p1.y,targetWidth=p2.x-p1.x,targetHeight=p2.y-p1.y,scale=Math.min(targetWidth/(currentWidth||1),targetHeight/(currentHeight||1));for(let p of pt)p.x=(p.x-currentBox.p1.x)*scale,p.y=(p.y-currentBox.p1.y)*scale,p.x+=p1.x,p.y+=p1.y;return this}}}function arcfrom3point(segments,p1,p2,p3){if(segments<=0)return[p1,p3];if(1===segments)return[p1,p2,p3];const center=function findCircleCenter(p1,p2,p3){const temp=p2.x*p2.x+p2.y*p2.y,bc=(p1.x*p1.x+p1.y*p1.y-temp)/2,cd=(temp-p3.x*p3.x-p3.y*p3.y)/2,det=(p1.x-p2.x)*(p2.y-p3.y)-(p2.x-p3.x)*(p1.y-p2.y);return Math.abs(det)<1e-10?null:new Punto2((bc*(p2.y-p3.y)-cd*(p1.y-p2.y))/det,((p1.x-p2.x)*cd-(p2.x-p3.x)*bc)/det)}(p1,p2,p3);if(!center){const points=[];for(let i=0;i<segments+1;i++){const t=i/segments;points.push(new Punto2(p1.x+(p3.x-p1.x)*t,p1.y+(p3.y-p1.y)*t))}return points}let normalizeAngle=angle=>(angle+2*Math.PI)%(2*Math.PI),start=normalizeAngle(Math.atan2(p1.y-center.y,p1.x-center.x)),mid=normalizeAngle(Math.atan2(p2.y-center.y,p2.x-center.x)),end=normalizeAngle(Math.atan2(p3.y-center.y,p3.x-center.x));mid>start&&(mid-=2*Math.PI),end>mid&&(end-=2*Math.PI);const delta=(end-start)/segments,radius=Math.hypot(p1.x-center.x,p1.y-center.y),points=[];for(let i=0;i<=segments;i++){const angle=start+delta*i;points.push(new Punto2(center.x+radius*Math.cos(angle),center.y+radius*Math.sin(angle)))}return points}function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x.default:x}var module,clipper={exports:{}};module=clipper,function(){var navigator_appName,ClipperLib={version:"6.4.2.2",use_lines:!0,use_xyz:!1},isNode=!1;if(module.exports?(module.exports=ClipperLib,isNode=!0):"undefined"!=typeof document?window.ClipperLib=ClipperLib:self.ClipperLib=ClipperLib,isNode)nav="chrome",navigator_appName="Netscape";else{var nav=navigator.userAgent.toString().toLowerCase();navigator_appName=navigator.appName}var dbits,browser={};function BigInteger(a,b,c){ClipperLib.biginteger_used=1,null!=a&&("number"==typeof a&&void 0===b?this.fromInt(a):"number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function nbi(){return new BigInteger(null,void 0,void 0)}-1!=nav.indexOf("chrome")&&-1==nav.indexOf("chromium")?browser.chrome=1:browser.chrome=0,-1!=nav.indexOf("chromium")?browser.chromium=1:browser.chromium=0,-1!=nav.indexOf("safari")&&-1==nav.indexOf("chrome")&&-1==nav.indexOf("chromium")?browser.safari=1:browser.safari=0,-1!=nav.indexOf("firefox")?browser.firefox=1:browser.firefox=0,-1!=nav.indexOf("firefox/17")?browser.firefox17=1:browser.firefox17=0,-1!=nav.indexOf("firefox/15")?browser.firefox15=1:browser.firefox15=0,-1!=nav.indexOf("firefox/3")?browser.firefox3=1:browser.firefox3=0,-1!=nav.indexOf("opera")?browser.opera=1:browser.opera=0,-1!=nav.indexOf("msie 10")?browser.msie10=1:browser.msie10=0,-1!=nav.indexOf("msie 9")?browser.msie9=1:browser.msie9=0,-1!=nav.indexOf("msie 8")?browser.msie8=1:browser.msie8=0,-1!=nav.indexOf("msie 7")?browser.msie7=1:browser.msie7=0,-1!=nav.indexOf("msie ")?browser.msie=1:browser.msie=0,ClipperLib.biginteger_used=null,"Microsoft Internet Explorer"==navigator_appName?(BigInteger.prototype.am=function am2(i,x,w,j,c,n){for(var xl=32767&x,xh=x>>15;--n>=0;){var l=32767&this[i],h=this[i++]>>15,m=xh*l+h*xl;c=((l=xl*l+((32767&m)<<15)+w[j]+(1073741823&c))>>>30)+(m>>>15)+xh*h+(c>>>30),w[j++]=1073741823&l}return c},dbits=30):"Netscape"!=navigator_appName?(BigInteger.prototype.am=function am1(i,x,w,j,c,n){for(;--n>=0;){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864),w[j++]=67108863&v}return c},dbits=26):(BigInteger.prototype.am=function am3(i,x,w,j,c,n){for(var xl=16383&x,xh=x>>14;--n>=0;){var l=16383&this[i],h=this[i++]>>14,m=xh*l+h*xl;c=((l=xl*l+((16383&m)<<14)+w[j]+c)>>28)+(m>>14)+xh*h,w[j++]=268435455&l}return c},dbits=28),BigInteger.prototype.DB=dbits,BigInteger.prototype.DM=(1<<dbits)-1,BigInteger.prototype.DV=1<<dbits,BigInteger.prototype.FV=Math.pow(2,52),BigInteger.prototype.F1=52-dbits,BigInteger.prototype.F2=2*dbits-52;var rr,vv,BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(n){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(n)}function intAt(s,i){var c=BI_RC[s.charCodeAt(i)];return null==c?-1:c}function nbv(i){var r=nbi();return r.fromInt(i),r}function nbits(x){var t,r=1;return 0!=(t=x>>>16)&&(x=t,r+=16),0!=(t=x>>8)&&(x=t,r+=8),0!=(t=x>>4)&&(x=t,r+=4),0!=(t=x>>2)&&(x=t,r+=2),0!=(t=x>>1)&&(x=t,r+=1),r}function Classic(m){this.m=m}function Montgomery(m){this.m=m,this.mp=m.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<m.DB-15)-1,this.mt2=2*m.t}function op_and(x,y){return x&y}function op_or(x,y){return x|y}function op_xor(x,y){return x^y}function op_andnot(x,y){return x&~y}function lbit(x){if(0==x)return-1;var r=0;return 65535&x||(x>>=16,r+=16),255&x||(x>>=8,r+=8),15&x||(x>>=4,r+=4),3&x||(x>>=2,r+=2),1&x||++r,r}function cbit(x){for(var r=0;0!=x;)x&=x-1,++r;return r}function NullExp(){}function nNop(x){return x}function Barrett(m){this.r2=nbi(),this.q3=nbi(),BigInteger.ONE.dlShiftTo(2*m.t,this.r2),this.mu=this.r2.divide(m),this.m=m}Classic.prototype.convert=function cConvert(x){return x.s<0||x.compareTo(this.m)>=0?x.mod(this.m):x},Classic.prototype.revert=function cRevert(x){return x},Classic.prototype.reduce=function cReduce(x){x.divRemTo(this.m,null,x)},Classic.prototype.mulTo=function cMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Classic.prototype.sqrTo=function cSqrTo(x,r){x.squareTo(r),this.reduce(r)},Montgomery.prototype.convert=function montConvert(x){var r=nbi();return x.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),x.s<0&&r.compareTo(BigInteger.ZERO)>0&&this.m.subTo(r,r),r},Montgomery.prototype.revert=function montRevert(x){var r=nbi();return x.copyTo(r),this.reduce(r),r},Montgomery.prototype.reduce=function montReduce(x){for(;x.t<=this.mt2;)x[x.t++]=0;for(var i=0;i<this.m.t;++i){var j=32767&x[i],u0=j*this.mpl+((j*this.mph+(x[i]>>15)*this.mpl&this.um)<<15)&x.DM;for(x[j=i+this.m.t]+=this.m.am(0,u0,x,i,0,this.m.t);x[j]>=x.DV;)x[j]-=x.DV,x[++j]++}x.clamp(),x.drShiftTo(this.m.t,x),x.compareTo(this.m)>=0&&x.subTo(this.m,x)},Montgomery.prototype.mulTo=function montMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Montgomery.prototype.sqrTo=function montSqrTo(x,r){x.squareTo(r),this.reduce(r)},BigInteger.prototype.copyTo=function bnpCopyTo(r){for(var i=this.t-1;i>=0;--i)r[i]=this[i];r.t=this.t,r.s=this.s},BigInteger.prototype.fromInt=function bnpFromInt(x){this.t=1,this.s=x<0?-1:0,x>0?this[0]=x:x<-1?this[0]=x+this.DV:this.t=0},BigInteger.prototype.fromString=function bnpFromString(s,b){var k;if(16==b)k=4;else if(8==b)k=3;else if(256==b)k=8;else if(2==b)k=1;else if(32==b)k=5;else{if(4!=b)return void this.fromRadix(s,b);k=2}this.t=0,this.s=0;for(var i=s.length,mi=!1,sh=0;--i>=0;){var x=8==k?255&s[i]:intAt(s,i);x<0?"-"==s.charAt(i)&&(mi=!0):(mi=!1,0==sh?this[this.t++]=x:sh+k>this.DB?(this[this.t-1]|=(x&(1<<this.DB-sh)-1)<<sh,this[this.t++]=x>>this.DB-sh):this[this.t-1]|=x<<sh,(sh+=k)>=this.DB&&(sh-=this.DB))}8==k&&128&s[0]&&(this.s=-1,sh>0&&(this[this.t-1]|=(1<<this.DB-sh)-1<<sh)),this.clamp(),mi&&BigInteger.ZERO.subTo(this,this)},BigInteger.prototype.clamp=function bnpClamp(){for(var c=this.s&this.DM;this.t>0&&this[this.t-1]==c;)--this.t},BigInteger.prototype.dlShiftTo=function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n,r.s=this.s},BigInteger.prototype.drShiftTo=function bnpDRShiftTo(n,r){for(var i=n;i<this.t;++i)r[i-n]=this[i];r.t=Math.max(this.t-n,0),r.s=this.s},BigInteger.prototype.lShiftTo=function bnpLShiftTo(n,r){var i,bs=n%this.DB,cbs=this.DB-bs,bm=(1<<cbs)-1,ds=Math.floor(n/this.DB),c=this.s<<bs&this.DM;for(i=this.t-1;i>=0;--i)r[i+ds+1]=this[i]>>cbs|c,c=(this[i]&bm)<<bs;for(i=ds-1;i>=0;--i)r[i]=0;r[ds]=c,r.t=this.t+ds+1,r.s=this.s,r.clamp()},BigInteger.prototype.rShiftTo=function bnpRShiftTo(n,r){r.s=this.s;var ds=Math.floor(n/this.DB);if(ds>=this.t)r.t=0;else{var bs=n%this.DB,cbs=this.DB-bs,bm=(1<<bs)-1;r[0]=this[ds]>>bs;for(var i=ds+1;i<this.t;++i)r[i-ds-1]|=(this[i]&bm)<<cbs,r[i-ds]=this[i]>>bs;bs>0&&(r[this.t-ds-1]|=(this.s&bm)<<cbs),r.t=this.t-ds,r.clamp()}},BigInteger.prototype.subTo=function bnpSubTo(a,r){for(var i=0,c=0,m=Math.min(a.t,this.t);i<m;)c+=this[i]-a[i],r[i++]=c&this.DM,c>>=this.DB;if(a.t<this.t){for(c-=a.s;i<this.t;)c+=this[i],r[i++]=c&this.DM,c>>=this.DB;c+=this.s}else{for(c+=this.s;i<a.t;)c-=a[i],r[i++]=c&this.DM,c>>=this.DB;c-=a.s}r.s=c<0?-1:0,c<-1?r[i++]=this.DV+c:c>0&&(r[i++]=c),r.t=i,r.clamp()},BigInteger.prototype.multiplyTo=function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs(),i=x.t;for(r.t=i+y.t;--i>=0;)r[i]=0;for(i=0;i<y.t;++i)r[i+x.t]=x.am(0,y[i],r,i,0,x.t);r.s=0,r.clamp(),this.s!=a.s&&BigInteger.ZERO.subTo(r,r)},BigInteger.prototype.squareTo=function bnpSquareTo(r){for(var x=this.abs(),i=r.t=2*x.t;--i>=0;)r[i]=0;for(i=0;i<x.t-1;++i){var c=x.am(i,x[i],r,2*i,0,1);(r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1))>=x.DV&&(r[i+x.t]-=x.DV,r[i+x.t+1]=1)}r.t>0&&(r[r.t-1]+=x.am(i,x[i],r,2*i,0,1)),r.s=0,r.clamp()},BigInteger.prototype.divRemTo=function bnpDivRemTo(m,q,r){var pm=m.abs();if(!(pm.t<=0)){var pt=this.abs();if(pt.t<pm.t)return null!=q&&q.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=nbi());var y=nbi(),ts=this.s,ms=m.s,nsh=this.DB-nbits(pm[pm.t-1]);nsh>0?(pm.lShiftTo(nsh,y),pt.lShiftTo(nsh,r)):(pm.copyTo(y),pt.copyTo(r));var ys=y.t,y0=y[ys-1];if(0!=y0){var yt=y0*(1<<this.F1)+(ys>1?y[ys-2]>>this.F2:0),d1=this.FV/yt,d2=(1<<this.F1)/yt,e=1<<this.F2,i=r.t,j=i-ys,t=null==q?nbi():q;for(y.dlShiftTo(j,t),r.compareTo(t)>=0&&(r[r.t++]=1,r.subTo(t,r)),BigInteger.ONE.dlShiftTo(ys,t),t.subTo(y,y);y.t<ys;)y[y.t++]=0;for(;--j>=0;){var qd=r[--i]==y0?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))<qd)for(y.dlShiftTo(j,t),r.subTo(t,r);r[i]<--qd;)r.subTo(t,r)}null!=q&&(r.drShiftTo(ys,q),ts!=ms&&BigInteger.ZERO.subTo(q,q)),r.t=ys,r.clamp(),nsh>0&&r.rShiftTo(nsh,r),ts<0&&BigInteger.ZERO.subTo(r,r)}}},BigInteger.prototype.invDigit=function bnpInvDigit(){if(this.t<1)return 0;var x=this[0];if(!(1&x))return 0;var y=3&x;return(y=(y=(y=(y=y*(2-(15&x)*y)&15)*(2-(255&x)*y)&255)*(2-((65535&x)*y&65535))&65535)*(2-x*y%this.DV)%this.DV)>0?this.DV-y:-y},BigInteger.prototype.isEven=function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)},BigInteger.prototype.exp=function bnpExp(e,z){if(e>4294967295||e<1)return BigInteger.ONE;var r=nbi(),r2=nbi(),g=z.convert(this),i=nbits(e)-1;for(g.copyTo(r);--i>=0;)if(z.sqrTo(r,r2),(e&1<<i)>0)z.mulTo(r2,g,r);else{var t=r;r=r2,r2=t}return z.revert(r)},BigInteger.prototype.toString=function bnToString(b){if(this.s<0)return"-"+this.negate().toString(b);var k;if(16==b)k=4;else if(8==b)k=3;else if(2==b)k=1;else if(32==b)k=5;else{if(4!=b)return this.toRadix(b);k=2}var d,km=(1<<k)-1,m=!1,r="",i=this.t,p=this.DB-i*this.DB%k;if(i-- >0)for(p<this.DB&&(d=this[i]>>p)>0&&(m=!0,r=int2char(d));i>=0;)p<k?(d=(this[i]&(1<<p)-1)<<k-p,d|=this[--i]>>(p+=this.DB-k)):(d=this[i]>>(p-=k)&km,p<=0&&(p+=this.DB,--i)),d>0&&(m=!0),m&&(r+=int2char(d));return m?r:"0"},BigInteger.prototype.negate=function bnNegate(){var r=nbi();return BigInteger.ZERO.subTo(this,r),r},BigInteger.prototype.abs=function bnAbs(){return this.s<0?this.negate():this},BigInteger.prototype.compareTo=function bnCompareTo(a){var r=this.s-a.s;if(0!=r)return r;var i=this.t;if(0!=(r=i-a.t))return this.s<0?-r:r;for(;--i>=0;)if(0!=(r=this[i]-a[i]))return r;return 0},BigInteger.prototype.bitLength=function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)},BigInteger.prototype.mod=function bnMod(a){var r=nbi();return this.abs().divRemTo(a,null,r),this.s<0&&r.compareTo(BigInteger.ZERO)>0&&a.subTo(r,r),r},BigInteger.prototype.modPowInt=function bnModPowInt(e,m){var z;return z=e<256||m.isEven()?new Classic(m):new Montgomery(m),this.exp(e,z)},BigInteger.ZERO=nbv(0),BigInteger.ONE=nbv(1),NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=function nMulTo(x,y,r){x.multiplyTo(y,r)},NullExp.prototype.sqrTo=function nSqrTo(x,r){x.squareTo(r)},Barrett.prototype.convert=function barrettConvert(x){if(x.s<0||x.t>2*this.m.t)return x.mod(this.m);if(x.compareTo(this.m)<0)return x;var r=nbi();return x.copyTo(r),this.reduce(r),r},Barrett.prototype.revert=function barrettRevert(x){return x},Barrett.prototype.reduce=function barrettReduce(x){for(x.drShiftTo(this.m.t-1,this.r2),x.t>this.m.t+1&&(x.t=this.m.t+1,x.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);x.compareTo(this.r2)<0;)x.dAddOffset(1,this.m.t+1);for(x.subTo(this.r2,x);x.compareTo(this.m)>=0;)x.subTo(this.m,x)},Barrett.prototype.mulTo=function barrettMulTo(x,y,r){x.multiplyTo(y,r),this.reduce(r)},Barrett.prototype.sqrTo=function barrettSqrTo(x,r){x.squareTo(r),this.reduce(r)};var lowprimes=[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],lplim=(1<<26)/lowprimes[lowprimes.length-1];BigInteger.prototype.chunkSize=function bnpChunkSize(r){return Math.floor(Math.LN2*this.DB/Math.log(r))},BigInteger.prototype.toRadix=function bnpToRadix(b){if(null==b&&(b=10),0==this.signum()||b<2||b>36)return"0";var cs=this.chunkSize(b),a=Math.pow(b,cs),d=nbv(a),y=nbi(),z=nbi(),r="";for(this.divRemTo(d,y,z);y.signum()>0;)r=(a+z.intValue()).toString(b).substr(1)+r,y.divRemTo(d,y,z);return z.intValue().toString(b)+r},BigInteger.prototype.fromRadix=function bnpFromRadix(s,b){this.fromInt(0),null==b&&(b=10);for(var cs=this.chunkSize(b),d=Math.pow(b,cs),mi=!1,j=0,w=0,i=0;i<s.length;++i){var x=intAt(s,i);x<0?"-"==s.charAt(i)&&0==this.signum()&&(mi=!0):(w=b*w+x,++j>=cs&&(this.dMultiply(d),this.dAddOffset(w,0),j=0,w=0))}j>0&&(this.dMultiply(Math.pow(b,j)),this.dAddOffset(w,0)),mi&&BigInteger.ZERO.subTo(this,this)},BigInteger.prototype.fromNumber=function bnpFromNumber(a,b,c){if("number"==typeof b)if(a<2)this.fromInt(1);else for(this.fromNumber(a,c),this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(BigInteger.ONE.shiftLeft(a-1),this);else{var x=new Array,t=7&a;x.length=1+(a>>3),b.nextBytes(x),t>0?x[0]&=(1<<t)-1:x[0]=0,this.fromString(x,256)}},BigInteger.prototype.bitwiseTo=function bnpBitwiseTo(a,op,r){var i,f,m=Math.min(a.t,this.t);for(i=0;i<m;++i)r[i]=op(this[i],a[i]);if(a.t<this.t){for(f=a.s&this.DM,i=m;i<this.t;++i)r[i]=op(this[i],f);r.t=this.t}else{for(f=this.s&this.DM,i=m;i<a.t;++i)r[i]=op(f,a[i]);r.t=a.t}r.s=op(this.s,a.s),r.clamp()},BigInteger.prototype.changeBit=function bnpChangeBit(n,op){var r=BigInteger.ONE.shiftLeft(n);return this.bitwiseTo(r,op,r),r},BigInteger.prototype.addTo=function bnpAddTo(a,r){for(var i=0,c=0,m=Math.min(a.t,this.t);i<m;)c+=this[i]+a[i],r[i++]=c&this.DM,c>>=this.DB;if(a.t<this.t){for(c+=a.s;i<this.t;)c+=this[i],r[i++]=c&this.DM,c>>=this.DB;c+=this.s}else{for(c+=this.s;i<a.t;)c+=a[i],r[i++]=c&this.DM,c>>=this.DB;c+=a.s}r.s=c<0?-1:0,c>0?r[i++]=c:c<-1&&(r[i++]=this.DV+c),r.t=i,r.clamp()},BigInteger.prototype.dMultiply=function bnpDMultiply(n){this[this.t]=this.am(0,n-1,this,0,0,this.t),++this.t,this.clamp()},BigInteger.prototype.dAddOffset=function bnpDAddOffset(n,w){if(0!=n){for(;this.t<=w;)this[this.t++]=0;for(this[w]+=n;this[w]>=this.DV;)this[w]-=this.DV,++w>=this.t&&(this[this.t++]=0),++this[w]}},BigInteger.prototype.multiplyLowerTo=function bnpMultiplyLowerTo(a,n,r){var j,i=Math.min(this.t+a.t,n);for(r.s=0,r.t=i;i>0;)r[--i]=0;for(j=r.t-this.t;i<j;++i)r[i+this.t]=this.am(0,a[i],r,i,0,this.t);for(j=Math.min(a.t,n);i<j;++i)this.am(0,a[i],r,i,0,n-i);r.clamp()},BigInteger.prototype.multiplyUpperTo=function bnpMultiplyUpperTo(a,n,r){--n;var i=r.t=this.t+a.t-n;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(n-this.t,0);i<a.t;++i)r[this.t+i-n]=this.am(n-i,a[i],r,0,0,this.t+i-n);r.clamp(),r.drShiftTo(1,r)},BigInteger.prototype.modInt=function bnpModInt(n){if(n<=0)return 0;var d=this.DV%n,r=this.s<0?n-1:0;if(this.t>0)if(0==d)r=this[0]%n;else for(var i=this.t-1;i>=0;--i)r=(d*r+this[i])%n;return r},BigInteger.prototype.millerRabin=function bnpMillerRabin(t){var n1=this.subtract(BigInteger.ONE),k=n1.getLowestSetBit();if(k<=0)return!1;var r=n1.shiftRight(k);(t=t+1>>1)>lowprimes.length&&(t=lowprimes.length);for(var a=nbi(),i=0;i<t;++i){a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var y=a.modPow(r,this);if(0!=y.compareTo(BigInteger.ONE)&&0!=y.compareTo(n1)){for(var j=1;j++<k&&0!=y.compareTo(n1);)if(0==(y=y.modPowInt(2,this)).compareTo(BigInteger.ONE))return!1;if(0!=y.compareTo(n1))return!1}}return!0},BigInteger.prototype.clone=function bnClone(){var r=nbi();return this.copyTo(r),r},BigInteger.prototype.intValue=function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},BigInteger.prototype.byteValue=function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24},BigInteger.prototype.shortValue=function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16},BigInteger.prototype.signum=function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},BigInteger.prototype.toByteArray=function bnToByteArray(){var i=this.t,r=new Array;r[0]=this.s;var d,p=this.DB-i*this.DB%8,k=0;if(i-- >0)for(p<this.DB&&(d=this[i]>>p)!=(this.s&this.DM)>>p&&(r[k++]=d|this.s<<this.DB-p);i>=0;)p<8?(d=(this[i]&(1<<p)-1)<<8-p,d|=this[--i]>>(p+=this.DB-8)):(d=this[i]>>(p-=8)&255,p<=0&&(p+=this.DB,--i)),128&d&&(d|=-256),0==k&&(128&this.s)!=(128&d)&&++k,(k>0||d!=this.s)&&(r[k++]=d);return r},BigInteger.prototype.equals=function bnEquals(a){return 0==this.compareTo(a)},BigInteger.prototype.min=function bnMin(a){return this.compareTo(a)<0?this:a},BigInteger.prototype.max=function bnMax(a){return this.compareTo(a)>0?this:a},BigInteger.prototype.and=function bnAnd(a){var r=nbi();return this.bitwiseTo(a,op_and,r),r},BigInteger.prototype.or=function bnOr(a){var r=nbi();return this.bitwiseTo(a,op_or,r),r},BigInteger.prototype.xor=function bnXor(a){var r=nbi();return this.bitwiseTo(a,op_xor,r),r},BigInteger.prototype.andNot=function bnAndNot(a){var r=nbi();return this.bitwiseTo(a,op_andnot,r),r},BigInteger.prototype.not=function bnNot(){for(var r=nbi(),i=0;i<this.t;++i)r[i]=this.DM&~this[i];return r.t=this.t,r.s=~this.s,r},BigInteger.prototype.shiftLeft=function bnShiftLeft(n){var r=nbi();return n<0?this.rShiftTo(-n,r):this.lShiftTo(n,r),r},BigInteger.prototype.shiftRight=function bnShiftRight(n){var r=nbi();return n<0?this.lShiftTo(-n,r):this.rShiftTo(n,r),r},BigInteger.prototype.getLowestSetBit=function bnGetLowestSetBit(){for(var i=0;i<this.t;++i)if(0!=this[i])return i*this.DB+lbit(this[i]);return this.s<0?this.t*this.DB:-1},BigInteger.prototype.bitCount=function bnBitCount(){for(var r=0,x=this.s&this.DM,i=0;i<this.t;++i)r+=cbit(this[i]^x);return r},BigInteger.prototype.testBit=function bnTestBit(n){var j=Math.floor(n/this.DB);return j>=this.t?0!=this.s:!!(this[j]&1<<n%this.DB)},BigInteger.prototype.setBit=function bnSetBit(n){return this.changeBit(n,op_or)},BigInteger.prototype.clearBit=function bnClearBit(n){return this.changeBit(n,op_andnot)},BigInteger.prototype.flipBit=function bnFlipBit(n){return this.changeBit(n,op_xor)},BigInteger.prototype.add=function bnAdd(a){var r=nbi();return this.addTo(a,r),r},BigInteger.prototype.subtract=function bnSubtract(a){var r=nbi();return this.subTo(a,r),r},BigInteger.prototype.multiply=function bnMultiply(a){var r=nbi();return this.multiplyTo(a,r),r},BigInteger.prototype.divide=function bnDivide(a){var r=nbi();return this.divRemTo(a,r,null),r},BigInteger.prototype.remainder=function bnRemainder(a){var r=nbi();return this.divRemTo(a,null,r),r},BigInteger.prototype.divideAndRemainder=function bnDivideAndRemainder(a){var q=nbi(),r=nbi();return this.divRemTo(a,q,r),new Array(q,r)},BigInteger.prototype.modPow=function bnModPow(e,m){var k,z,i=e.bitLength(),r=nbv(1);if(i<=0)return r;k=i<18?1:i<48?3:i<144?4:i<768?5:6,z=i<8?new Classic(m):m.isEven()?new Barrett(m):new Montgomery(m);var g=new Array,n=3,k1=k-1,km=(1<<k)-1;if(g[1]=z.convert(this),k>1){var g2=nbi();for(z.sqrTo(g[1],g2);n<=km;)g[n]=nbi(),z.mulTo(g2,g[n-2],g[n]),n+=2}var w,t,j=e.t-1,is1=!0,r2=nbi();for(i=nbits(e[j])-1;j>=0;){for(i>=k1?w=e[j]>>i-k1&km:(w=(e[j]&(1<<i+1)-1)<<k1-i,j>0&&(w|=e[j-1]>>this.DB+i-k1)),n=k;!(1&w);)w>>=1,--n;if((i-=n)<0&&(i+=this.DB,--j),is1)g[w].copyTo(r),is1=!1;else{for(;n>1;)z.sqrTo(r,r2),z.sqrTo(r2,r),n-=2;n>0?z.sqrTo(r,r2):(t=r,r=r2,r2=t),z.mulTo(r2,g[w],r)}for(;j>=0&&!(e[j]&1<<i);)z.sqrTo(r,r2),t=r,r=r2,r2=t,--i<0&&(i=this.DB-1,--j)}return z.revert(r)},BigInteger.prototype.modInverse=function bnModInverse(m){var ac=m.isEven();if(this.isEven()&&ac||0==m.signum())return BigInteger.ZERO;for(var u=m.clone(),v=this.clone(),a=nbv(1),b=nbv(0),c=nbv(0),d=nbv(1);0!=u.signum();){for(;u.isEven();)u.rShiftTo(1,u),ac?(a.isEven()&&b.isEven()||(a.addTo(this,a),b.subTo(m,b)),a.rShiftTo(1,a)):b.isEven()||b.subTo(m,b),b.rShiftTo(1,b);for(;v.isEven();)v.rShiftTo(1,v),ac?(c.isEven()&&d.isEven()||(c.addTo(this,c),d.subTo(m,d)),c.rShiftTo(1,c)):d.isEven()||d.subTo(m,d),d.rShiftTo(1,d);u.compareTo(v)>=0?(u.subTo(v,u),ac&&a.subTo(c,a),b.subTo(d,b)):(v.subTo(u,v),ac&&c.subTo(a,c),d.subTo(b,d))}return 0!=v.compareTo(BigInteger.ONE)?BigInteger.ZERO:d.compareTo(m)>=0?d.subtract(m):d.signum()<0?(d.addTo(m,d),d.signum()<0?d.add(m):d):d},BigInteger.prototype.pow=function bnPow(e){return this.exp(e,new NullExp)},BigInteger.prototype.gcd=function bnGCD(a){var x=this.s<0?this.negate():this.clone(),y=a.s<0?a.negate():a.clone();if(x.compareTo(y)<0){var t=x;x=y,y=t}var i=x.getLowestSetBit(),g=y.getLowestSetBit();if(g<0)return x;for(i<g&&(g=i),g>0&&(x.rShiftTo(g,x),y.rShiftTo(g,y));x.signum()>0;)(i=x.getLowestSetBit())>0&&x.rShiftTo(i,x),(i=y.getLowestSetBit())>0&&y.rShiftTo(i,y),x.compareTo(y)>=0?(x.subTo(y,x),x.rShiftTo(1,x)):(y.subTo(x,y),y.rShiftTo(1,y));return g>0&&y.lShiftTo(g,y),y},BigInteger.prototype.isProbablePrime=function bnIsProbablePrime(t){var i,x=this.abs();if(1==x.t&&x[0]<=lowprimes[lowprimes.length-1]){for(i=0;i<lowprimes.length;++i)if(x[0]==lowprimes[i])return!0;return!1}if(x.isEven())return!1;for(i=1;i<lowprimes.length;){for(var m=lowprimes[i],j=i+1;j<lowprimes.length&&m<lplim;)m*=lowprimes[j++];for(m=x.modInt(m);i<j;)if(m%lowprimes[i++]==0)return!1}return x.millerRabin(t)},BigInteger.prototype.square=function bnSquare(){var r=nbi();return this.squareTo(r),r};var Int128=BigInteger;Int128.prototype.IsNegative=function(){return-1==this.compareTo(Int128.ZERO)},Int128.op_Equality=function(val1,val2){return 0==val1.compareTo(val2)},Int128.op_Inequality=function(val1,val2){return 0!=val1.compareTo(val2)},Int128.op_GreaterThan=function(val1,val2){return val1.compareTo(val2)>0},Int128.op_LessThan=function(val1,val2){return val1.compareTo(val2)<0},Int128.op_Addition=function(lhs,rhs){return new Int128(lhs,void 0,void 0).add(new Int128(rhs,void 0,void 0))},Int128.op_Subtraction=function(lhs,rhs){return new Int128(lhs,void 0,void 0).subtract(new Int128(rhs,void 0,void 0))},Int128.Int128Mul=function(lhs,rhs){return new Int128(lhs,void 0,void 0).multiply(new Int128(rhs,void 0,void 0))},Int128.op_Division=function(lhs,rhs){return lhs.divide(rhs)},Int128.prototype.ToDouble=function(){return parseFloat(this.toString())};var Inherit=function(ce,ce2){var p;if(void 0===Object.getOwnPropertyNames){for(p in ce2.prototype)void 0!==ce.prototype[p]&&ce.prototype[p]!==Object.prototype[p]||(ce.prototype[p]=ce2.prototype[p]);for(p in ce2)void 0===ce[p]&&(ce[p]=ce2[p]);ce.$baseCtor=ce2}else{for(var props=Object.getOwnPropertyNames(ce2.prototype),i=0;i<props.length;i++)void 0===Object.getOwnPropertyDescriptor(ce.prototype,props[i])&&Object.defineProperty(ce.prototype,props[i],Object.getOwnPropertyDescriptor(ce2.prototype,props[i]));for(p in ce2)void 0===ce[p]&&(ce[p]=ce2[p]);ce.$baseCtor=ce2}};ClipperLib.Path=function(){return[]},ClipperLib.Path.prototype.push=Array.prototype.push,ClipperLib.Paths=function(){return[]},ClipperLib.Paths.prototype.push=Array.prototype.push,ClipperLib.DoublePoint=function(){var a=arguments;this.X=0,this.Y=0,1===a.length?(this.X=a[0].X,this.Y=a[0].Y):2===a.length&&(this.X=a[0],this.Y=a[1])},ClipperLib.DoublePoint0=function(){this.X=0,this.Y=0},ClipperLib.DoublePoint0.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.DoublePoint1=function(dp){this.X=dp.X,this.Y=dp.Y},ClipperLib.DoublePoint1.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.DoublePoint2=function(x,y){this.X=x,this.Y=y},ClipperLib.DoublePoint2.prototype=ClipperLib.DoublePoint.prototype,ClipperLib.PolyNode=function(){this.m_Parent=null,this.m_polygon=new ClipperLib.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},ClipperLib.PolyNode.prototype.IsHoleNode=function(){for(var result=!0,node=this.m_Parent;null!==node;)result=!result,node=node.m_Parent;return result},ClipperLib.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},ClipperLib.PolyNode.prototype.Contour=function(){return this.m_polygon},ClipperLib.PolyNode.prototype.AddChild=function(Child){var cnt=this.m_Childs.length;this.m_Childs.push(Child),Child.m_Parent=this,Child.m_Index=cnt},ClipperLib.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},ClipperLib.PolyNode.prototype.GetNextSiblingUp=function(){return null===this.m_Parent?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},ClipperLib.PolyNode.prototype.Childs=function(){return this.m_Childs},ClipperLib.PolyNode.prototype.Parent=function(){return this.m_Parent},ClipperLib.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},ClipperLib.PolyTree=function(){this.m_AllPolys=[],ClipperLib.PolyNode.call(this)},ClipperLib.PolyTree.prototype.Clear=function(){for(var i=0,ilen=this.m_AllPolys.length;i<ilen;i++)this.m_AllPolys[i]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},ClipperLib.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},ClipperLib.PolyTree.prototype.Total=function(){var result=this.m_AllPolys.length;return result>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&result--,result},Inherit(ClipperLib.PolyTree,ClipperLib.PolyNode),ClipperLib.Math_Abs_Int64=ClipperLib.Math_Abs_Int32=ClipperLib.Math_Abs_Double=function(a){return Math.abs(a)},ClipperLib.Math_Max_Int32_Int32=function(a,b){return Math.max(a,b)},browser.msie||browser.opera||browser.safari?ClipperLib.Cast_Int32=function(a){return 0|a}:ClipperLib.Cast_Int32=function(a){return~~a},void 0===Number.toInteger&&(Number.toInteger=null),browser.chrome?ClipperLib.Cast_Int64=function(a){return a<-2147483648||a>2147483647?a<0?Math.ceil(a):Math.floor(a):~~a}:browser.firefox&&"function"==typeof Number.toInteger?ClipperLib.Cast_Int64=function(a){return Number.toInteger(a)}:browser.msie7||browser.msie8?ClipperLib.Cast_Int64=function(a){return parseInt(a,10)}:browser.msie?ClipperLib.Cast_Int64=function(a){return a<-2147483648||a>2147483647?a<0?Math.ceil(a):Math.floor(a):0|a}:ClipperLib.Cast_Int64=function(a){return a<0?Math.ceil(a):Math.floor(a)},ClipperLib.Clear=function(a){a.length=0},ClipperLib.PI=3.141592653589793,ClipperLib.PI2=6.283185307179586,ClipperLib.IntPoint=function(){var a=arguments,alen=a.length;if(this.X=0,this.Y=0,ClipperLib.use_xyz)if(this.Z=0,3===alen)this.X=a[0],this.Y=a[1],this.Z=a[2];else if(2===alen)this.X=a[0],this.Y=a[1],this.Z=0;else if(1===alen)if(a[0]instanceof ClipperLib.DoublePoint){var dp=a[0];this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y),this.Z=0}else void 0===(pt=a[0]).Z&&(pt.Z=0),this.X=pt.X,this.Y=pt.Y,this.Z=pt.Z;else this.X=0,this.Y=0,this.Z=0;else if(2===alen)this.X=a[0],this.Y=a[1];else if(1===alen)if(a[0]instanceof ClipperLib.DoublePoint)dp=a[0],this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y);else{var pt=a[0];this.X=pt.X,this.Y=pt.Y}else this.X=0,this.Y=0},ClipperLib.IntPoint.op_Equality=function(a,b){return a.X===b.X&&a.Y===b.Y},ClipperLib.IntPoint.op_Inequality=function(a,b){return a.X!==b.X||a.Y!==b.Y},ClipperLib.IntPoint0=function(){this.X=0,this.Y=0,ClipperLib.use_xyz&&(this.Z=0)},ClipperLib.IntPoint0.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint1=function(pt){this.X=pt.X,this.Y=pt.Y,ClipperLib.use_xyz&&(void 0===pt.Z?this.Z=0:this.Z=pt.Z)},ClipperLib.IntPoint1.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint1dp=function(dp){this.X=ClipperLib.Clipper.Round(dp.X),this.Y=ClipperLib.Clipper.Round(dp.Y),ClipperLib.use_xyz&&(this.Z=0)},ClipperLib.IntPoint1dp.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntPoint2=function(x,y,z){this.X=x,this.Y=y,ClipperLib.use_xyz&&(this.Z=void 0===z?0:z)},ClipperLib.IntPoint2.prototype=ClipperLib.IntPoint.prototype,ClipperLib.IntRect=function(){var a=arguments,alen=a.length;if(4===alen)this.left=a[0],this.top=a[1],this.right=a[2],this.bottom=a[3];else if(1===alen){var ir=a[0];this.left=ir.left,this.top=ir.top,this.right=ir.right,this.bottom=ir.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},ClipperLib.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},ClipperLib.IntRect0.prototype=ClipperLib.IntRect.prototype,ClipperLib.IntRect1=function(ir){this.left=ir.left,this.top=ir.top,this.right=ir.right,this.bottom=ir.bottom},ClipperLib.IntRect1.prototype=ClipperLib.IntRect.prototype,ClipperLib.IntRect4=function(l,t,r,b){this.left=l,this.top=t,this.right=r,this.bottom=b},ClipperLib.IntRect4.prototype=ClipperLib.IntRect.prototype,ClipperLib.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},ClipperLib.PolyType={ptSubject:0,ptClip:1},ClipperLib.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},ClipperLib.JoinType={jtSquare:0,jtRound:1,jtMiter:2},ClipperLib.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},ClipperLib.EdgeSide={esLeft:0,esRight:1},ClipperLib.Direction={dRightToLeft:0,dLeftToRight:1},ClipperLib.TEdge=function(){this.Bot=new ClipperLib.IntPoint0,this.Curr=new ClipperLib.IntPoint0,this.Top=new ClipperLib.IntPoint0,this.Delta=new ClipperLib.IntPoint0,this.Dx=0,this.PolyTyp=ClipperLib.PolyType.ptSubject,this.Side=ClipperLib.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},ClipperLib.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new ClipperLib.IntPoint0},ClipperLib.MyIntersectNodeSort=function(){},ClipperLib.MyIntersectNodeSort.Compare=function(node1,node2){var i=node2.Pt.Y-node1.Pt.Y;return i>0?1:i<0?-1:0},ClipperLib.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},ClipperLib.Scanbeam=function(){this.Y=0,this.Next=null},ClipperLib.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},ClipperLib.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},ClipperLib.OutPt=function(){this.Idx=0,this.Pt=new ClipperLib.IntPoint0,this.Next=null,this.Prev=null},ClipperLib.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new ClipperLib.IntPoint0},ClipperLib.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},ClipperLib.ClipperBase.horizontal=-9007199254740992,ClipperLib.ClipperBase.Skip=-2,ClipperLib.ClipperBase.Unassigned=-1,ClipperLib.ClipperBase.tolerance=1e-20,ClipperLib.ClipperBase.loRange=47453132,ClipperLib.ClipperBase.hiRange=0xfffffffffffff,ClipperLib.ClipperBase.near_zero=function(val){return val>-ClipperLib.ClipperBase.tolerance&&val<ClipperLib.ClipperBase.tolerance},ClipperLib.ClipperBase.IsHorizontal=function(e){return 0===e.Delta.Y},ClipperLib.ClipperBase.prototype.PointIsVertex=function(pt,pp){var pp2=pp;do{if(ClipperLib.IntPoint.op_Equality(pp2.Pt,pt))return!0;pp2=pp2.Next}while(pp2!==pp);return!1},ClipperLib.ClipperBase.prototype.PointOnLineSegment=function(pt,linePt1,linePt2,UseFullRange){return UseFullRange?pt.X===linePt1.X&&pt.Y===linePt1.Y||pt.X===linePt2.X&&pt.Y===linePt2.Y||pt.X>linePt1.X==pt.X<linePt2.X&&pt.Y>linePt1.Y==pt.Y<linePt2.Y&&Int128.op_Equality(Int128.Int128Mul(pt.X-linePt1.X,linePt2.Y-linePt1.Y),Int128.Int128Mul(linePt2.X-linePt1.X,pt.Y-linePt1.Y)):pt.X===linePt1.X&&pt.Y===linePt1.Y||pt.X===linePt2.X&&pt.Y===linePt2.Y||pt.X>linePt1.X==pt.X<linePt2.X&&pt.Y>linePt1.Y==pt.Y<linePt2.Y&&(pt.X-linePt1.X)*(linePt2.Y-linePt1.Y)==(linePt2.X-linePt1.X)*(pt.Y-linePt1.Y)},ClipperLib.ClipperBase.prototype.PointOnPolygon=function(pt,pp,UseFullRange){for(var pp2=pp;;){if(this.PointOnLineSegment(pt,pp2.Pt,pp2.Next.Pt,UseFullRange))return!0;if((pp2=pp2.Next)===pp)break}return!1},ClipperLib.ClipperBase.prototype.SlopesEqual=ClipperLib.ClipperBase.SlopesEqual=function(){var e1,e2,pt1,pt2,pt3,pt4,a=arguments,alen=a.length;return 3===alen?(e1=a[0],e2=a[1],a[2]?Int128.op_Equality(Int128.Int128Mul(e1.Delta.Y,e2.Delta.X),Int128.Int128Mul(e1.Delta.X,e2.Delta.Y)):ClipperLib.Cast_Int64(e1.Delta.Y*e2.Delta.X)===ClipperLib.Cast_Int64(e1.Delta.X*e2.Delta.Y)):4===alen?(pt1=a[0],pt2=a[1],pt3=a[2],a[3]?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt2.X-pt3.X),Int128.Int128Mul(pt1.X-pt2.X,pt2.Y-pt3.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt2.X-pt3.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt2.Y-pt3.Y))==0):(pt1=a[0],pt2=a[1],pt3=a[2],pt4=a[3],a[4]?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt3.X-pt4.X),Int128.Int128Mul(pt1.X-pt2.X,pt3.Y-pt4.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt3.X-pt4.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt3.Y-pt4.Y))==0)},ClipperLib.ClipperBase.SlopesEqual3=function(e1,e2,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(e1.Delta.Y,e2.Delta.X),Int128.Int128Mul(e1.Delta.X,e2.Delta.Y)):ClipperLib.Cast_Int64(e1.Delta.Y*e2.Delta.X)===ClipperLib.Cast_Int64(e1.Delta.X*e2.Delta.Y)},ClipperLib.ClipperBase.SlopesEqual4=function(pt1,pt2,pt3,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt2.X-pt3.X),Int128.Int128Mul(pt1.X-pt2.X,pt2.Y-pt3.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt2.X-pt3.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt2.Y-pt3.Y))==0},ClipperLib.ClipperBase.SlopesEqual5=function(pt1,pt2,pt3,pt4,UseFullRange){return UseFullRange?Int128.op_Equality(Int128.Int128Mul(pt1.Y-pt2.Y,pt3.X-pt4.X),Int128.Int128Mul(pt1.X-pt2.X,pt3.Y-pt4.Y)):ClipperLib.Cast_Int64((pt1.Y-pt2.Y)*(pt3.X-pt4.X))-ClipperLib.Cast_Int64((pt1.X-pt2.X)*(pt3.Y-pt4.Y))==0},ClipperLib.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var i=0,ilen=this.m_edges.length;i<ilen;++i){for(var j=0,jlen=this.m_edges[i].length;j<jlen;++j)this.m_edges[i][j]=null;ClipperLib.Clear(this.m_edges[i])}ClipperLib.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},ClipperLib.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;null!==this.m_MinimaList;){var tmpLm=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=tmpLm}this.m_CurrentLM=null},ClipperLib.ClipperBase.prototype.RangeTest=function(Pt,useFullRange){useFullRange.Value?(Pt.X>ClipperLib.ClipperBase.hiRange||Pt.Y>ClipperLib.ClipperBase.hiRange||-Pt.X>ClipperLib.ClipperBase.hiRange||-Pt.Y>ClipperLib.ClipperBase.hiRange)&&ClipperLib.Error("Coordinate outside allowed range in RangeTest()."):(Pt.X>ClipperLib.ClipperBase.loRange||Pt.Y>ClipperLib.ClipperBase.loRange||-Pt.X>ClipperLib.ClipperBase.loRange||-Pt.Y>ClipperLib.ClipperBase.loRange)&&(useFullRange.Value=!0,this.RangeTest(Pt,useFullRange))},ClipperLib.ClipperBase.prototype.InitEdge=function(e,eNext,ePrev,pt){e.Next=eNext,e.Prev=ePrev,e.Curr.X=pt.X,e.Curr.Y=pt.Y,ClipperLib.use_xyz&&(e.Curr.Z=pt.Z),e.OutIdx=-1},ClipperLib.ClipperBase.prototype.InitEdge2=function(e,polyType){e.Curr.Y>=e.Next.Curr.Y?(e.Bot.X=e.Curr.X,e.Bot.Y=e.Curr.Y,ClipperLib.use_xyz&&(e.Bot.Z=e.Curr.Z),e.Top.X=e.Next.Curr.X,e.Top.Y=e.Next.Curr.Y,ClipperLib.use_xyz&&(e.Top.Z=e.Next.Curr.Z)):(e.Top.X=e.Curr.X,e.Top.Y=e.Curr.Y,ClipperLib.use_xyz&&(e.Top.Z=e.Curr.Z),e.Bot.X=e.Next.Curr.X,e.Bot.Y=e.Next.Curr.Y,ClipperLib.use_xyz&&(e.Bot.Z=e.Next.Curr.Z)),this.SetDx(e),e.PolyTyp=polyType},ClipperLib.ClipperBase.prototype.FindNextLocMin=function(E){for(var E2;;){for(;ClipperLib.IntPoint.op_Inequality(E.Bot,E.Prev.Bot)||ClipperLib.IntPoint.op_Equality(E.Curr,E.Top);)E=E.Next;if(E.Dx!==ClipperLib.ClipperBase.horizontal&&E.Prev.Dx!==ClipperLib.ClipperBase.horizontal)break;for(;E.Prev.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Prev;for(E2=E;E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Next;if(E.Top.Y!==E.Prev.Bot.Y){E2.Prev.Bot.X<E.Bot.X&&(E=E2);break}}return E},ClipperLib.ClipperBase.prototype.ProcessBound=function(E,LeftBoundIsForward){var EStart,Horz,Result=E;if(Result.OutIdx===ClipperLib.ClipperBase.Skip){if(E=Result,LeftBoundIsForward){for(;E.Top.Y===E.Next.Bot.Y;)E=E.Next;for(;E!==Result&&E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Prev}else{for(;E.Top.Y===E.Prev.Bot.Y;)E=E.Prev;for(;E!==Result&&E.Dx===ClipperLib.ClipperBase.horizontal;)E=E.Next}if(E===Result)Result=LeftBoundIsForward?E.Next:E.Prev;else{E=LeftBoundIsForward?Result.Next:Result.Prev;var locMin=new ClipperLib.LocalMinima;locMin.Next=null,locMin.Y=E.Bot.Y,locMin.LeftBound=null,locMin.RightBound=E,E.WindDelta=0,Result=this.ProcessBound(E,LeftBoundIsForward),this.InsertLocalMinima(locMin)}return Result}if(E.Dx===ClipperLib.ClipperBase.horizontal&&((EStart=LeftBoundIsForward?E.Prev:E.Next).Dx===ClipperLib.ClipperBase.horizontal?EStart.Bot.X!==E.Bot.X&&EStart.Top.X!==E.Bot.X&&this.ReverseHorizontal(E):EStart.Bot.X!==E.Bot.X&&this.ReverseHorizontal(E)),EStart=E,LeftBoundIsForward){for(;Result.Top.Y===Result.Next.Bot.Y&&Result.Next.OutIdx!==ClipperLib.ClipperBase.Skip;)Result=Result.Next;if(Result.Dx===ClipperLib.ClipperBase.horizontal&&Result.Next.OutIdx!==ClipperLib.ClipperBase.Skip){for(Horz=Result;Horz.Prev.Dx===ClipperLib.ClipperBase.horizontal;)Horz=Horz.Prev;Horz.Prev.Top.X>Result.Next.Top.X&&(Result=Horz.Prev)}for(;E!==Result;)E.NextInLML=E.Next,E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),E=E.Next;E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),Result=Result.Next}else{for(;Result.Top.Y===Result.Prev.Bot.Y&&Result.Prev.OutIdx!==ClipperLib.ClipperBase.Skip;)Result=Result.Prev;if(Result.Dx===ClipperLib.ClipperBase.horizontal&&Result.Prev.OutIdx!==ClipperLib.ClipperBase.Skip){for(Horz=Result;Horz.Next.Dx===ClipperLib.ClipperBase.horizontal;)Horz=Horz.Next;(Horz.Next.Top.X===Result.Prev.Top.X||Horz.Next.Top.X>Result.Prev.Top.X)&&(Result=Horz.Next)}for(;E!==Result;)E.NextInLML=E.Prev,E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Next.Top.X&&this.ReverseHorizontal(E),E=E.Prev;E.Dx===ClipperLib.ClipperBase.horizontal&&E!==EStart&&E.Bot.X!==E.Next.Top.X&&this.ReverseHorizontal(E),Result=Result.Prev}return Result},ClipperLib.ClipperBase.prototype.AddPath=function(pg,polyType,Closed){ClipperLib.use_lines?Closed||polyType!==ClipperLib.PolyType.ptClip||ClipperLib.Error("AddPath: Open paths must be subject."):Closed||ClipperLib.Error("AddPath: Open paths have been disabled.");var highI=pg.length-1;if(Closed)for(;highI>0&&ClipperLib.IntPoint.op_Equality(pg[highI],pg[0]);)--highI;for(;highI>0&&ClipperLib.IntPoint.op_Equality(pg[highI],pg[highI-1]);)--highI;if(Closed&&highI<2||!Closed&&highI<1)return!1;for(var edges=new Array,i=0;i<=highI;i++)edges.push(new ClipperLib.TEdge);var IsFlat=!0;edges[1].Curr.X=pg[1].X,edges[1].Curr.Y=pg[1].Y,ClipperLib.use_xyz&&(edges[1].Curr.Z=pg[1].Z);var $1={Value:this.m_UseFullRange};for(this.RangeTest(pg[0],$1),this.m_UseFullRange=$1.Value,$1.Value=this.m_UseFullRange,this.RangeTest(pg[highI],$1),this.m_UseFullRange=$1.Value,this.InitEdge(edges[0],edges[1],edges[highI],pg[0]),this.InitEdge(edges[highI],edges[0],edges[highI-1],pg[highI]),i=highI-1;i>=1;--i)$1.Value=this.m_UseFullRange,this.RangeTest(pg[i],$1),this.m_UseFullRange=$1.Value,this.InitEdge(edges[i],edges[i+1],edges[i-1],pg[i]);for(var leftBoundIsForward,eStart=edges[0],E=eStart,eLoopStop=eStart;;)if(E.Curr!==E.Next.Curr||!Closed&&E.Next===eStart){if(E.Prev===E.Next)break;if(!Closed||!ClipperLib.ClipperBase.SlopesEqual4(E.Prev.Curr,E.Curr,E.Next.Curr,this.m_UseFullRange)||this.PreserveCollinear&&this.Pt2IsBetweenPt1AndPt3(E.Prev.Curr,E.Curr,E.Next.Curr)){if((E=E.Next)===eLoopStop||!Closed&&E.Next===eStart)break}else E===eStart&&(eStart=E.Next),eLoopStop=E=(E=this.RemoveEdge(E)).Prev}else{if(E===E.Next)break;E===eStart&&(eStart=E.Next),eLoopStop=E=this.RemoveEdge(E)}if(!Closed&&E===E.Next||Closed&&E.Prev===E.Next)return!1;Closed||(this.m_HasOpenPaths=!0,eStart.Prev.OutIdx=ClipperLib.ClipperBase.Skip),E=eStart;do{this.InitEdge2(E,polyType),E=E.Next,IsFlat&&E.Curr.Y!==eStart.Curr.Y&&(IsFlat=!1)}while(E!==eStart);if(IsFlat){if(Closed)return!1;for(E.Prev.OutIdx=ClipperLib.ClipperBase.Skip,(locMin=new ClipperLib.LocalMinima).Next=null,locMin.Y=E.Bot.Y,locMin.LeftBound=null,locMin.RightBound=E,locMin.RightBound.Side=ClipperLib.EdgeSide.esRight,locMin.RightBound.WindDelta=0;E.Bot.X!==E.Prev.Top.X&&this.ReverseHorizontal(E),E.Next.OutIdx!==ClipperLib.ClipperBase.Skip;)E.NextInLML=E.Next,E=E.Next;return this.InsertLocalMinima(locMin),this.m_edges.push(edges),!0}this.m_edges.push(edges);var EMin=null;for(ClipperLib.IntPoint.op_Equality(E.Prev.Bot,E.Prev.Top)&&(E=E.Next);(E=this.FindNextLocMin(E))!==EMin;){var locMin;null===EMin&&(EMin=E),(locMin=new ClipperLib.LocalMinima).Next=null,locMin.Y=E.Bot.Y,E.Dx<E.Prev.Dx?(locMin.LeftBound=E.Prev,locMin.RightBound=E,leftBoundIsForward=!1):(locMin.LeftBound=E,locMin.RightBound=E.Prev,leftBoundIsForward=!0),locMin.LeftBound.Side=ClipperLib.EdgeSide.esLeft,locMin.RightBound.Side=ClipperLib.EdgeSide.esRight,Closed?locMin.LeftBound.Next===locMin.RightBound?locMin.LeftBound.WindDelta=-1:locMin.LeftBound.WindDelta=1:locMin.LeftBound.WindDelta=0,locMin.RightBound.WindDelta=-locMin.LeftBound.WindDelta,(E=this.ProcessBound(locMin.LeftBound,leftBoundIsForward)).OutIdx===ClipperLib.ClipperBase.Skip&&(E=this.ProcessBound(E,leftBoundIsForward));var E2=this.ProcessBound(locMin.RightBound,!leftBoundIsForward);E2.OutIdx===ClipperLib.ClipperBase.Skip&&(E2=this.ProcessBound(E2,!leftBoundIsForward)),locMin.LeftBound.OutIdx===ClipperLib.ClipperBase.Skip?locMin.LeftBound=null:locMin.RightBound.OutIdx===ClipperLib.ClipperBase.Skip&&(locMin.RightBound=null),this.InsertLocalMinima(locMin),leftBoundIsForward||(E=E2)}return!0},ClipperLib.ClipperBase.prototype.AddPaths=function(ppg,polyType,closed){for(var result=!1,i=0,ilen=ppg.length;i<ilen;++i)this.AddPath(ppg[i],polyType,closed)&&(result=!0);return result},ClipperLib.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(pt1,pt2,pt3){return!(ClipperLib.IntPoint.op_Equality(pt1,pt3)||ClipperLib.IntPoint.op_Equality(pt1,pt2)||ClipperLib.IntPoint.op_Equality(pt3,pt2))&&(pt1.X!==pt3.X?pt2.X>pt1.X==pt2.X<pt3.X:pt2.Y>pt1.Y==pt2.Y<pt3.Y)},ClipperLib.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var result=e.Next;return e.Prev=null,result},ClipperLib.ClipperBase.prototype.SetDx=function(e){e.Delta.X=e.Top.X-e.Bot.X,e.Delta.Y=e.Top.Y-e.Bot.Y,0===e.Delta.Y?e.Dx=ClipperLib.ClipperBase.horizontal:e.Dx=e.Delta.X/e.Delta.Y},ClipperLib.ClipperBase.prototype.InsertLocalMinima=function(newLm){if(null===this.m_MinimaList)this.m_MinimaList=newLm;else if(newLm.Y>=this.m_MinimaList.Y)newLm.Next=this.m_MinimaList,this.m_MinimaList=newLm;else{for(var tmpLm=this.m_MinimaList;null!==tmpLm.Next&&newLm.Y<tmpLm.Next.Y;)tmpLm=tmpLm.Next;newLm.Next=tmpLm.Next,tmpLm.Next=newLm}},ClipperLib.ClipperBase.prototype.PopLocalMinima=function(Y,current){return current.v=this.m_CurrentLM,null!==this.m_CurrentLM&&this.m_CurrentLM.Y===Y&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)},ClipperLib.ClipperBase.prototype.ReverseHorizontal=function(e){var tmp=e.Top.X;e.Top.X=e.Bot.X,e.Bot.X=tmp,ClipperLib.use_xyz&&(tmp=e.Top.Z,e.Top.Z=e.Bot.Z,e.Bot.Z=tmp)},ClipperLib.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,null!==this.m_CurrentLM){this.m_Scanbeam=null;for(var lm=this.m_MinimaList;null!==lm;){this.InsertScanbeam(lm.Y);var e=lm.LeftBound;null!==e&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,ClipperLib.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=ClipperLib.ClipperBase.Unassigned),null!==(e=lm.RightBound)&&(e.Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,ClipperLib.use_xyz&&(e.Curr.Z=e.Bot.Z),e.OutIdx=ClipperLib.ClipperBase.Unassigned),lm=lm.Next}this.m_ActiveEdges=null}},ClipperLib.ClipperBase.prototype.InsertScanbeam=function(Y){if(null===this.m_Scanbeam)this.m_Scanbeam=new ClipperLib.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=Y;else if(Y>this.m_Scanbeam.Y){var newSb=new ClipperLib.Scanbeam;newSb.Y=Y,newSb.Next=this.m_Scanbeam,this.m_Scanbeam=newSb}else{for(var sb2=this.m_Scanbeam;null!==sb2.Next&&Y<=sb2.Next.Y;)sb2=sb2.Next;if(Y===sb2.Y)return;var newSb1=new ClipperLib.Scanbeam;newSb1.Y=Y,newSb1.Next=sb2.Next,sb2.Next=newSb1}},ClipperLib.ClipperBase.prototype.PopScanbeam=function(Y){return null===this.m_Scanbeam?(Y.v=0,!1):(Y.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},ClipperLib.ClipperBase.prototype.LocalMinimaPending=function(){return null!==this.m_CurrentLM},ClipperLib.ClipperBase.prototype.CreateOutRec=function(){var result=new ClipperLib.OutRec;return result.Idx=ClipperLib.ClipperBase.Unassigned,result.IsHole=!1,result.IsOpen=!1,result.FirstLeft=null,result.Pts=null,result.BottomPt=null,result.PolyNode=null,this.m_PolyOuts.push(result),result.Idx=this.m_PolyOuts.length-1,result},ClipperLib.ClipperBase.prototype.DisposeOutRec=function(index){var outRec=this.m_PolyOuts[index];outRec.Pts=null,outRec=null,this.m_PolyOuts[index]=null},ClipperLib.ClipperBase.prototype.UpdateEdgeIntoAEL=function(e){null===e.NextInLML&&ClipperLib.Error("UpdateEdgeIntoAEL: invalid call");var AelPrev=e.PrevInAEL,AelNext=e.NextInAEL;return e.NextInLML.OutIdx=e.OutIdx,null!==AelPrev?AelPrev.NextInAEL=e.NextInLML:this.m_ActiveEdges=e.NextInLML,null!==AelNext&&(AelNext.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).Curr.X=e.Bot.X,e.Curr.Y=e.Bot.Y,e.PrevInAEL=AelPrev,e.NextInAEL=AelNext,ClipperLib.ClipperBase.IsHorizontal(e)||this.InsertScanbeam(e.Top.Y),e},ClipperLib.ClipperBase.prototype.SwapPositionsInAEL=function(edge1,edge2){if(edge1.NextInAEL!==edge1.PrevInAEL&&edge2.NextInAEL!==edge2.PrevInAEL){if(edge1.NextInAEL===edge2){var next=edge2.NextInAEL;null!==next&&(next.PrevInAEL=edge1);var prev=edge1.PrevInAEL;null!==prev&&(prev.NextInAEL=edge2),edge2.PrevInAEL=prev,edge2.NextInAEL=edge1,edge1.PrevInAEL=edge2,edge1.NextInAEL=next}else if(edge2.NextInAEL===edge1){var next1=edge1.NextInAEL;null!==next1&&(next1.PrevInAEL=edge2);var prev1=edge2.PrevInAEL;null!==prev1&&(prev1.NextInAEL=edge1),edge1.PrevInAEL=prev1,edge1.NextInAEL=edge2,edge2.PrevInAEL=edge1,edge2.NextInAEL=next1}else{var next2=edge1.NextInAEL,prev2=edge1.PrevInAEL;edge1.NextInAEL=edge2.NextInAEL,null!==edge1.NextInAEL&&(edge1.NextInAEL.PrevInAEL=edge1),edge1.PrevInAEL=edge2.PrevInAEL,null!==edge1.PrevInAEL&&(edge1.PrevInAEL.NextInAEL=edge1),edge2.NextInAEL=next2,null!==edge2.NextInAEL&&(edge2.NextInAEL.PrevInAEL=edge2),edge2.PrevInAEL=prev2,null!==edge2.PrevInAEL&&(edge2.PrevInAEL.NextInAEL=edge2)}null===edge1.PrevInAEL?this.m_ActiveEdges=edge1:null===edge2.PrevInAEL&&(this.m_ActiveEdges=edge2)}},ClipperLib.ClipperBase.prototype.DeleteFromAEL=function(e){var AelPrev=e.PrevInAEL,AelNext=e.NextInAEL;null===AelPrev&&null===AelNext&&e!==this.m_ActiveEdges||(null!==AelPrev?AelPrev.NextInAEL=AelNext:this.m_ActiveEdges=AelNext,null!==AelNext&&(AelNext.PrevInAEL=AelPrev),e.NextInAEL=null,e.PrevInAEL=null)},ClipperLib.Clipper=function(InitOptions){void 0===InitOptions&&(InitOptions=0),this.m_PolyOuts=null,this.m_ClipType=ClipperLib.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=ClipperLib.PolyFillType.pftEvenOdd,this.m_SubjFillType=ClipperLib.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,ClipperLib.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=ClipperLib.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&InitOptions),this.StrictlySimple=!!(2&InitOptions),this.PreserveCollinear=!!(4&InitOptions),ClipperLib.use_xyz&&(this.ZFillFunction=null)},ClipperLib.Clipper.ioReverseSolution=1,ClipperLib.Clipper.ioStrictlySimple=2,ClipperLib.Clipper.ioPreserveCollinear=4,ClipperLib.Clipper.prototype.Clear=function(){0!==this.m_edges.length&&(this.DisposeAllPolyPts(),ClipperLib.ClipperBase.prototype.Clear.call(this))},ClipperLib.Clipper.prototype.InsertMaxima=function(X){var newMax=new ClipperLib.Maxima;if(newMax.X=X,null===this.m_Maxima)this.m_Maxima=newMax,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(X<this.m_Maxima.X)newMax.Next=this.m_Maxima,newMax.Prev=null,this.m_Maxima=newMax;else{for(var m=this.m_Maxima;null!==m.Next&&X>=m.Next.X;)m=m.Next;if(X===m.X)return;newMax.Next=m.Next,newMax.Prev=m,null!==m.Next&&(m.Next.Prev=newMax),m.Next=newMax}},ClipperLib.Clipper.prototype.Execute=function(){var a=arguments,alen=a.length,ispolytree=a[1]instanceof ClipperLib.PolyTree;if(4===alen&&!ispolytree){var clipType=a[0],solution=a[1],subjFillType=a[2],clipFillType=a[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&ClipperLib.Error("Error: PolyTree struct is needed for open path clipping."),this.m_ExecuteLocked=!0,ClipperLib.Clear(solution),this.m_SubjFillType=subjFillType,this.m_ClipFillType=clipFillType,this.m_ClipType=clipType,this.m_UsingPolyTree=!1;try{(succeeded=this.ExecuteInternal())&&this.BuildResult(solution)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return succeeded}if(4===alen&&ispolytree){clipType=a[0];var polytree=a[1];if(subjFillType=a[2],clipFillType=a[3],this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=subjFillType,this.m_ClipFillType=clipFillType,this.m_ClipType=clipType,this.m_UsingPolyTree=!0;try{var succeeded;(succeeded=this.ExecuteInternal())&&this.BuildResult2(polytree)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return succeeded}return 2!==alen||ispolytree?2===alen&&ispolytree?(clipType=a[0],polytree=a[1],this.Execute(clipType,polytree,ClipperLib.PolyFillType.pftEvenOdd,ClipperLib.PolyFillType.pftEvenOdd)):void 0:(clipType=a[0],solution=a[1],this.Execute(clipType,solution,ClipperLib.PolyFillType.pftEvenOdd,ClipperLib.PolyFillType.pftEvenOdd))},ClipperLib.Clipper.prototype.FixHoleLinkage=function(outRec){if(null!==outRec.FirstLeft&&(outRec.IsHole===outRec.FirstLeft.IsHole||null===outRec.FirstLeft.Pts)){for(var orfl=outRec.FirstLeft;null!==orfl&&(orfl.IsHole===outRec.IsHole||null===orfl.Pts);)orfl=orfl.FirstLeft;outRec.FirstLeft=orfl}},ClipperLib.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var outRec,i,ilen,botY={},topY={};if(!this.PopScanbeam(botY))return!1;for(this.InsertLocalMinimaIntoAEL(botY.v);this.PopScanbeam(topY)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(topY.v))return!1;this.ProcessEdgesAtTopOfScanbeam(topY.v),botY.v=topY.v,this.InsertLocalMinimaIntoAEL(botY.v)}for(i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null===(outRec=this.m_PolyOuts[i]).Pts||outRec.IsOpen||(outRec.IsHole^this.ReverseSolution)==this.Area$1(outRec)>0&&this.ReversePolyPtLinks(outRec.Pts);for(this.JoinCommonEdges(),i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).Pts&&(outRec.IsOpen?this.FixupOutPolyline(outRec):this.FixupOutPolygon(outRec));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},ClipperLib.Clipper.prototype.DisposeAllPolyPts=function(){for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;++i)this.DisposeOutRec(i);ClipperLib.Clear(this.m_PolyOuts)},ClipperLib.Clipper.prototype.AddJoin=function(Op1,Op2,OffPt){var j=new ClipperLib.Join;j.OutPt1=Op1,j.OutPt2=Op2,j.OffPt.X=OffPt.X,j.OffPt.Y=OffPt.Y,ClipperLib.use_xyz&&(j.OffPt.Z=OffPt.Z),this.m_Joins.push(j)},ClipperLib.Clipper.prototype.AddGhostJoin=function(Op,OffPt){var j=new ClipperLib.Join;j.OutPt1=Op,j.OffPt.X=OffPt.X,j.OffPt.Y=OffPt.Y,ClipperLib.use_xyz&&(j.OffPt.Z=OffPt.Z),this.m_GhostJoins.push(j)},ClipperLib.Clipper.prototype.SetZ=function(pt,e1,e2){if(null!==this.ZFillFunction){if(0!==pt.Z||null===this.ZFillFunction)return;ClipperLib.IntPoint.op_Equality(pt,e1.Bot)?pt.Z=e1.Bot.Z:ClipperLib.IntPoint.op_Equality(pt,e1.Top)?pt.Z=e1.Top.Z:ClipperLib.IntPoint.op_Equality(pt,e2.Bot)?pt.Z=e2.Bot.Z:ClipperLib.IntPoint.op_Equality(pt,e2.Top)?pt.Z=e2.Top.Z:this.ZFillFunction(e1.Bot,e1.Top,e2.Bot,e2.Top,pt)}},ClipperLib.Clipper.prototype.InsertLocalMinimaIntoAEL=function(botY){for(var lb,rb,lm={};this.PopLocalMinima(botY,lm);){lb=lm.v.LeftBound,rb=lm.v.RightBound;var Op1=null;if(null===lb?(this.InsertEdgeIntoAEL(rb,null),this.SetWindingCount(rb),this.IsContributing(rb)&&(Op1=this.AddOutPt(rb,rb.Bot))):null===rb?(this.InsertEdgeIntoAEL(lb,null),this.SetWindingCount(lb),this.IsContributing(lb)&&(Op1=this.AddOutPt(lb,lb.Bot)),this.InsertScanbeam(lb.Top.Y)):(this.InsertEdgeIntoAEL(lb,null),this.InsertEdgeIntoAEL(rb,lb),this.SetWindingCount(lb),rb.WindCnt=lb.WindCnt,rb.WindCnt2=lb.WindCnt2,this.IsContributing(lb)&&(Op1=this.AddLocalMinPoly(lb,rb,lb.Bot)),this.InsertScanbeam(lb.Top.Y)),null!==rb&&(ClipperLib.ClipperBase.IsHorizontal(rb)?(null!==rb.NextInLML&&this.InsertScanbeam(rb.NextInLML.Top.Y),this.AddEdgeToSEL(rb)):this.InsertScanbeam(rb.Top.Y)),null!==lb&&null!==rb){if(null!==Op1&&ClipperLib.ClipperBase.IsHorizontal(rb)&&this.m_GhostJoins.length>0&&0!==rb.WindDelta)for(var i=0,ilen=this.m_GhostJoins.length;i<ilen;i++){var j=this.m_GhostJoins[i];this.HorzSegmentsOverlap(j.OutPt1.Pt.X,j.OffPt.X,rb.Bot.X,rb.Top.X)&&this.AddJoin(j.OutPt1,Op1,j.OffPt)}if(lb.OutIdx>=0&&null!==lb.PrevInAEL&&lb.PrevInAEL.Curr.X===lb.Bot.X&&lb.PrevInAEL.OutIdx>=0&&ClipperLib.ClipperBase.SlopesEqual5(lb.PrevInAEL.Curr,lb.PrevInAEL.Top,lb.Curr,lb.Top,this.m_UseFullRange)&&0!==lb.WindDelta&&0!==lb.PrevInAEL.WindDelta){var Op2=this.AddOutPt(lb.PrevInAEL,lb.Bot);this.AddJoin(Op1,Op2,lb.Top)}if(lb.NextInAEL!==rb){rb.OutIdx>=0&&rb.PrevInAEL.OutIdx>=0&&ClipperLib.ClipperBase.SlopesEqual5(rb.PrevInAEL.Curr,rb.PrevInAEL.Top,rb.Curr,rb.Top,this.m_UseFullRange)&&0!==rb.WindDelta&&0!==rb.PrevInAEL.WindDelta&&(Op2=this.AddOutPt(rb.PrevInAEL,rb.Bot),this.AddJoin(Op1,Op2,rb.Top));var e=lb.NextInAEL;if(null!==e)for(;e!==rb;)this.IntersectEdges(rb,e,lb.Curr),e=e.NextInAEL}}}},ClipperLib.Clipper.prototype.InsertEdgeIntoAEL=function(edge,startEdge){if(null===this.m_ActiveEdges)edge.PrevInAEL=null,edge.NextInAEL=null,this.m_ActiveEdges=edge;else if(null===startEdge&&this.E2InsertsBeforeE1(this.m_ActiveEdges,edge))edge.PrevInAEL=null,edge.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=edge,this.m_ActiveEdges=edge;else{for(null===startEdge&&(startEdge=this.m_ActiveEdges);null!==startEdge.NextInAEL&&!this.E2InsertsBeforeE1(startEdge.NextInAEL,edge);)startEdge=startEdge.NextInAEL;edge.NextInAEL=startEdge.NextInAEL,null!==startEdge.NextInAEL&&(startEdge.NextInAEL.PrevInAEL=edge),edge.PrevInAEL=startEdge,startEdge.NextInAEL=edge}},ClipperLib.Clipper.prototype.E2InsertsBeforeE1=function(e1,e2){return e2.Curr.X===e1.Curr.X?e2.Top.Y>e1.Top.Y?e2.Top.X<ClipperLib.Clipper.TopX(e1,e2.Top.Y):e1.Top.X>ClipperLib.Clipper.TopX(e2,e1.Top.Y):e2.Curr.X<e1.Curr.X},ClipperLib.Clipper.prototype.IsEvenOddFillType=function(edge){return edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_SubjFillType===ClipperLib.PolyFillType.pftEvenOdd:this.m_ClipFillType===ClipperLib.PolyFillType.pftEvenOdd},ClipperLib.Clipper.prototype.IsEvenOddAltFillType=function(edge){return edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_ClipFillType===ClipperLib.PolyFillType.pftEvenOdd:this.m_SubjFillType===ClipperLib.PolyFillType.pftEvenOdd},ClipperLib.Clipper.prototype.IsContributing=function(edge){var pft,pft2;switch(edge.PolyTyp===ClipperLib.PolyType.ptSubject?(pft=this.m_SubjFillType,pft2=this.m_ClipFillType):(pft=this.m_ClipFillType,pft2=this.m_SubjFillType),pft){case ClipperLib.PolyFillType.pftEvenOdd:if(0===edge.WindDelta&&1!==edge.WindCnt)return!1;break;case ClipperLib.PolyFillType.pftNonZero:if(1!==Math.abs(edge.WindCnt))return!1;break;case ClipperLib.PolyFillType.pftPositive:if(1!==edge.WindCnt)return!1;break;default:if(-1!==edge.WindCnt)return!1}switch(this.m_ClipType){case ClipperLib.ClipType.ctIntersection:switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0!==edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2>0;default:return edge.WindCnt2<0}case ClipperLib.ClipType.ctUnion:switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}case ClipperLib.ClipType.ctDifference:if(edge.PolyTyp===ClipperLib.PolyType.ptSubject)switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}else switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0!==edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2>0;default:return edge.WindCnt2<0}case ClipperLib.ClipType.ctXor:if(0!==edge.WindDelta)return!0;switch(pft2){case ClipperLib.PolyFillType.pftEvenOdd:case ClipperLib.PolyFillType.pftNonZero:return 0===edge.WindCnt2;case ClipperLib.PolyFillType.pftPositive:return edge.WindCnt2<=0;default:return edge.WindCnt2>=0}}return!0},ClipperLib.Clipper.prototype.SetWindingCount=function(edge){for(var e=edge.PrevInAEL;null!==e&&(e.PolyTyp!==edge.PolyTyp||0===e.WindDelta);)e=e.PrevInAEL;if(null===e){var pft=edge.PolyTyp===ClipperLib.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;0===edge.WindDelta?edge.WindCnt=pft===ClipperLib.PolyFillType.pftNegative?-1:1:edge.WindCnt=edge.WindDelta,edge.WindCnt2=0,e=this.m_ActiveEdges}else if(0===edge.WindDelta&&this.m_ClipType!==ClipperLib.ClipType.ctUnion)edge.WindCnt=1,edge.WindCnt2=e.WindCnt2,e=e.NextInAEL;else if(this.IsEvenOddFillType(edge)){if(0===edge.WindDelta){for(var Inside=!0,e2=e.PrevInAEL;null!==e2;)e2.PolyTyp===e.PolyTyp&&0!==e2.WindDelta&&(Inside=!Inside),e2=e2.PrevInAEL;edge.WindCnt=Inside?0:1}else edge.WindCnt=edge.WindDelta;edge.WindCnt2=e.WindCnt2,e=e.NextInAEL}else e.WindCnt*e.WindDelta<0?Math.abs(e.WindCnt)>1?e.WindDelta*edge.WindDelta<0?edge.WindCnt=e.WindCnt:edge.WindCnt=e.WindCnt+edge.WindDelta:edge.WindCnt=0===edge.WindDelta?1:edge.WindDelta:0===edge.WindDelta?edge.WindCnt=e.WindCnt<0?e.WindCnt-1:e.WindCnt+1:e.WindDelta*edge.WindDelta<0?edge.WindCnt=e.WindCnt:edge.WindCnt=e.WindCnt+edge.WindDelta,edge.WindCnt2=e.WindCnt2,e=e.NextInAEL;if(this.IsEvenOddAltFillType(edge))for(;e!==edge;)0!==e.WindDelta&&(edge.WindCnt2=0===edge.WindCnt2?1:0),e=e.NextInAEL;else for(;e!==edge;)edge.WindCnt2+=e.WindDelta,e=e.NextInAEL},ClipperLib.Clipper.prototype.AddEdgeToSEL=function(edge){null===this.m_SortedEdges?(this.m_SortedEdges=edge,edge.PrevInSEL=null,edge.NextInSEL=null):(edge.NextInSEL=this.m_SortedEdges,edge.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=edge,this.m_SortedEdges=edge)},ClipperLib.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,null===e.v)return!1;var oldE=e.v;return this.m_SortedEdges=e.v.NextInSEL,null!==this.m_SortedEdges&&(this.m_SortedEdges.PrevInSEL=null),oldE.NextInSEL=null,oldE.PrevInSEL=null,!0},ClipperLib.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;null!==e;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},ClipperLib.Clipper.prototype.SwapPositionsInSEL=function(edge1,edge2){if(!(null===edge1.NextInSEL&&null===edge1.PrevInSEL||null===edge2.NextInSEL&&null===edge2.PrevInSEL)){if(edge1.NextInSEL===edge2)null!==(next=edge2.NextInSEL)&&(next.PrevInSEL=edge1),null!==(prev=edge1.PrevInSEL)&&(prev.NextInSEL=edge2),edge2.PrevInSEL=prev,edge2.NextInSEL=edge1,edge1.PrevInSEL=edge2,edge1.NextInSEL=next;else if(edge2.NextInSEL===edge1)null!==(next=edge1.NextInSEL)&&(next.PrevInSEL=edge2),null!==(prev=edge2.PrevInSEL)&&(prev.NextInSEL=edge1),edge1.PrevInSEL=prev,edge1.NextInSEL=edge2,edge2.PrevInSEL=edge1,edge2.NextInSEL=next;else{var next=edge1.NextInSEL,prev=edge1.PrevInSEL;edge1.NextInSEL=edge2.NextInSEL,null!==edge1.NextInSEL&&(edge1.NextInSEL.PrevInSEL=edge1),edge1.PrevInSEL=edge2.PrevInSEL,null!==edge1.PrevInSEL&&(edge1.PrevInSEL.NextInSEL=edge1),edge2.NextInSEL=next,null!==edge2.NextInSEL&&(edge2.NextInSEL.PrevInSEL=edge2),edge2.PrevInSEL=prev,null!==edge2.PrevInSEL&&(edge2.PrevInSEL.NextInSEL=edge2)}null===edge1.PrevInSEL?this.m_SortedEdges=edge1:null===edge2.PrevInSEL&&(this.m_SortedEdges=edge2)}},ClipperLib.Clipper.prototype.AddLocalMaxPoly=function(e1,e2,pt){this.AddOutPt(e1,pt),0===e2.WindDelta&&this.AddOutPt(e2,pt),e1.OutIdx===e2.OutIdx?(e1.OutIdx=-1,e2.OutIdx=-1):e1.OutIdx<e2.OutIdx?this.AppendPolygon(e1,e2):this.AppendPolygon(e2,e1)},ClipperLib.Clipper.prototype.AddLocalMinPoly=function(e1,e2,pt){var result,e,prevE;if(ClipperLib.ClipperBase.IsHorizontal(e2)||e1.Dx>e2.Dx?(result=this.AddOutPt(e1,pt),e2.OutIdx=e1.OutIdx,e1.Side=ClipperLib.EdgeSide.esLeft,e2.Side=ClipperLib.EdgeSide.esRight,prevE=(e=e1).PrevInAEL===e2?e2.PrevInAEL:e.PrevInAEL):(result=this.AddOutPt(e2,pt),e1.OutIdx=e2.OutIdx,e1.Side=ClipperLib.EdgeSide.esRight,e2.Side=ClipperLib.EdgeSide.esLeft,prevE=(e=e2).PrevInAEL===e1?e1.PrevInAEL:e.PrevInAEL),null!==prevE&&prevE.OutIdx>=0&&prevE.Top.Y<pt.Y&&e.Top.Y<pt.Y){var xPrev=ClipperLib.Clipper.TopX(prevE,pt.Y),xE=ClipperLib.Clipper.TopX(e,pt.Y);if(xPrev===xE&&0!==e.WindDelta&&0!==prevE.WindDelta&&ClipperLib.ClipperBase.SlopesEqual5(new ClipperLib.IntPoint2(xPrev,pt.Y),prevE.Top,new ClipperLib.IntPoint2(xE,pt.Y),e.Top,this.m_UseFullRange)){var outPt=this.AddOutPt(prevE,pt);this.AddJoin(result,outPt,e.Top)}}return result},ClipperLib.Clipper.prototype.AddOutPt=function(e,pt){if(e.OutIdx<0){(outRec=this.CreateOutRec()).IsOpen=0===e.WindDelta;var newOp=new ClipperLib.OutPt;return outRec.Pts=newOp,newOp.Idx=outRec.Idx,newOp.Pt.X=pt.X,newOp.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newOp.Pt.Z=pt.Z),newOp.Next=newOp,newOp.Prev=newOp,outRec.IsOpen||this.SetHoleState(e,outRec),e.OutIdx=outRec.Idx,newOp}var outRec,op=(outRec=this.m_PolyOuts[e.OutIdx]).Pts,ToFront=e.Side===ClipperLib.EdgeSide.esLeft;return ToFront&&ClipperLib.IntPoint.op_Equality(pt,op.Pt)?op:!ToFront&&ClipperLib.IntPoint.op_Equality(pt,op.Prev.Pt)?op.Prev:((newOp=new ClipperLib.OutPt).Idx=outRec.Idx,newOp.Pt.X=pt.X,newOp.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newOp.Pt.Z=pt.Z),newOp.Next=op,newOp.Prev=op.Prev,newOp.Prev.Next=newOp,op.Prev=newOp,ToFront&&(outRec.Pts=newOp),newOp)},ClipperLib.Clipper.prototype.GetLastOutPt=function(e){var outRec=this.m_PolyOuts[e.OutIdx];return e.Side===ClipperLib.EdgeSide.esLeft?outRec.Pts:outRec.Pts.Prev},ClipperLib.Clipper.prototype.SwapPoints=function(pt1,pt2){var tmp=new ClipperLib.IntPoint1(pt1.Value);pt1.Value.X=pt2.Value.X,pt1.Value.Y=pt2.Value.Y,ClipperLib.use_xyz&&(pt1.Value.Z=pt2.Value.Z),pt2.Value.X=tmp.X,pt2.Value.Y=tmp.Y,ClipperLib.use_xyz&&(pt2.Value.Z=tmp.Z)},ClipperLib.Clipper.prototype.HorzSegmentsOverlap=function(seg1a,seg1b,seg2a,seg2b){var tmp;return seg1a>seg1b&&(tmp=seg1a,seg1a=seg1b,seg1b=tmp),seg2a>seg2b&&(tmp=seg2a,seg2a=seg2b,seg2b=tmp),seg1a<seg2b&&seg2a<seg1b},ClipperLib.Clipper.prototype.SetHoleState=function(e,outRec){for(var e2=e.PrevInAEL,eTmp=null;null!==e2;)e2.OutIdx>=0&&0!==e2.WindDelta&&(null===eTmp?eTmp=e2:eTmp.OutIdx===e2.OutIdx&&(eTmp=null)),e2=e2.PrevInAEL;null===eTmp?(outRec.FirstLeft=null,outRec.IsHole=!1):(outRec.FirstLeft=this.m_PolyOuts[eTmp.OutIdx],outRec.IsHole=!outRec.FirstLeft.IsHole)},ClipperLib.Clipper.prototype.GetDx=function(pt1,pt2){return pt1.Y===pt2.Y?ClipperLib.ClipperBase.horizontal:(pt2.X-pt1.X)/(pt2.Y-pt1.Y)},ClipperLib.Clipper.prototype.FirstIsBottomPt=function(btmPt1,btmPt2){for(var p=btmPt1.Prev;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt1.Pt)&&p!==btmPt1;)p=p.Prev;var dx1p=Math.abs(this.GetDx(btmPt1.Pt,p.Pt));for(p=btmPt1.Next;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt1.Pt)&&p!==btmPt1;)p=p.Next;var dx1n=Math.abs(this.GetDx(btmPt1.Pt,p.Pt));for(p=btmPt2.Prev;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt2.Pt)&&p!==btmPt2;)p=p.Prev;var dx2p=Math.abs(this.GetDx(btmPt2.Pt,p.Pt));for(p=btmPt2.Next;ClipperLib.IntPoint.op_Equality(p.Pt,btmPt2.Pt)&&p!==btmPt2;)p=p.Next;var dx2n=Math.abs(this.GetDx(btmPt2.Pt,p.Pt));return Math.max(dx1p,dx1n)===Math.max(dx2p,dx2n)&&Math.min(dx1p,dx1n)===Math.min(dx2p,dx2n)?this.Area(btmPt1)>0:dx1p>=dx2p&&dx1p>=dx2n||dx1n>=dx2p&&dx1n>=dx2n},ClipperLib.Clipper.prototype.GetBottomPt=function(pp){for(var dups=null,p=pp.Next;p!==pp;)p.Pt.Y>pp.Pt.Y?(pp=p,dups=null):p.Pt.Y===pp.Pt.Y&&p.Pt.X<=pp.Pt.X&&(p.Pt.X<pp.Pt.X?(dups=null,pp=p):p.Next!==pp&&p.Prev!==pp&&(dups=p)),p=p.Next;if(null!==dups)for(;dups!==p;)for(this.FirstIsBottomPt(p,dups)||(pp=dups),dups=dups.Next;ClipperLib.IntPoint.op_Inequality(dups.Pt,pp.Pt);)dups=dups.Next;return pp},ClipperLib.Clipper.prototype.GetLowermostRec=function(outRec1,outRec2){null===outRec1.BottomPt&&(outRec1.BottomPt=this.GetBottomPt(outRec1.Pts)),null===outRec2.BottomPt&&(outRec2.BottomPt=this.GetBottomPt(outRec2.Pts));var bPt1=outRec1.BottomPt,bPt2=outRec2.BottomPt;return bPt1.Pt.Y>bPt2.Pt.Y?outRec1:bPt1.Pt.Y<bPt2.Pt.Y?outRec2:bPt1.Pt.X<bPt2.Pt.X?outRec1:bPt1.Pt.X>bPt2.Pt.X||bPt1.Next===bPt1?outRec2:bPt2.Next===bPt2||this.FirstIsBottomPt(bPt1,bPt2)?outRec1:outRec2},ClipperLib.Clipper.prototype.OutRec1RightOfOutRec2=function(outRec1,outRec2){do{if((outRec1=outRec1.FirstLeft)===outRec2)return!0}while(null!==outRec1);return!1},ClipperLib.Clipper.prototype.GetOutRec=function(idx){for(var outrec=this.m_PolyOuts[idx];outrec!==this.m_PolyOuts[outrec.Idx];)outrec=this.m_PolyOuts[outrec.Idx];return outrec},ClipperLib.Clipper.prototype.AppendPolygon=function(e1,e2){var holeStateRec,outRec1=this.m_PolyOuts[e1.OutIdx],outRec2=this.m_PolyOuts[e2.OutIdx];holeStateRec=this.OutRec1RightOfOutRec2(outRec1,outRec2)?outRec2:this.OutRec1RightOfOutRec2(outRec2,outRec1)?outRec1:this.GetLowermostRec(outRec1,outRec2);var p1_lft=outRec1.Pts,p1_rt=p1_lft.Prev,p2_lft=outRec2.Pts,p2_rt=p2_lft.Prev;e1.Side===ClipperLib.EdgeSide.esLeft?e2.Side===ClipperLib.EdgeSide.esLeft?(this.ReversePolyPtLinks(p2_lft),p2_lft.Next=p1_lft,p1_lft.Prev=p2_lft,p1_rt.Next=p2_rt,p2_rt.Prev=p1_rt,outRec1.Pts=p2_rt):(p2_rt.Next=p1_lft,p1_lft.Prev=p2_rt,p2_lft.Prev=p1_rt,p1_rt.Next=p2_lft,outRec1.Pts=p2_lft):e2.Side===ClipperLib.EdgeSide.esRight?(this.ReversePolyPtLinks(p2_lft),p1_rt.Next=p2_rt,p2_rt.Prev=p1_rt,p2_lft.Next=p1_lft,p1_lft.Prev=p2_lft):(p1_rt.Next=p2_lft,p2_lft.Prev=p1_rt,p1_lft.Prev=p2_rt,p2_rt.Next=p1_lft),outRec1.BottomPt=null,holeStateRec===outRec2&&(outRec2.FirstLeft!==outRec1&&(outRec1.FirstLeft=outRec2.FirstLeft),outRec1.IsHole=outRec2.IsHole),outRec2.Pts=null,outRec2.BottomPt=null,outRec2.FirstLeft=outRec1;var OKIdx=e1.OutIdx,ObsoleteIdx=e2.OutIdx;e1.OutIdx=-1,e2.OutIdx=-1;for(var e=this.m_ActiveEdges;null!==e;){if(e.OutIdx===ObsoleteIdx){e.OutIdx=OKIdx,e.Side=e1.Side;break}e=e.NextInAEL}outRec2.Idx=outRec1.Idx},ClipperLib.Clipper.prototype.ReversePolyPtLinks=function(pp){if(null!==pp){var pp1,pp2;pp1=pp;do{pp2=pp1.Next,pp1.Next=pp1.Prev,pp1.Prev=pp2,pp1=pp2}while(pp1!==pp)}},ClipperLib.Clipper.SwapSides=function(edge1,edge2){var side=edge1.Side;edge1.Side=edge2.Side,edge2.Side=side},ClipperLib.Clipper.SwapPolyIndexes=function(edge1,edge2){var outIdx=edge1.OutIdx;edge1.OutIdx=edge2.OutIdx,edge2.OutIdx=outIdx},ClipperLib.Clipper.prototype.IntersectEdges=function(e1,e2,pt){var e1Contributing=e1.OutIdx>=0,e2Contributing=e2.OutIdx>=0;if(ClipperLib.use_xyz&&this.SetZ(pt,e1,e2),!ClipperLib.use_lines||0!==e1.WindDelta&&0!==e2.WindDelta){if(e1.PolyTyp===e2.PolyTyp)if(this.IsEvenOddFillType(e1)){var oldE1WindCnt=e1.WindCnt;e1.WindCnt=e2.WindCnt,e2.WindCnt=oldE1WindCnt}else e1.WindCnt+e2.WindDelta===0?e1.WindCnt=-e1.WindCnt:e1.WindCnt+=e2.WindDelta,e2.WindCnt-e1.WindDelta==0?e2.WindCnt=-e2.WindCnt:e2.WindCnt-=e1.WindDelta;else this.IsEvenOddFillType(e2)?e1.WindCnt2=0===e1.WindCnt2?1:0:e1.WindCnt2+=e2.WindDelta,this.IsEvenOddFillType(e1)?e2.WindCnt2=0===e2.WindCnt2?1:0:e2.WindCnt2-=e1.WindDelta;var e1FillType,e2FillType,e1FillType2,e2FillType2,e1Wc,e2Wc;switch(e1.PolyTyp===ClipperLib.PolyType.ptSubject?(e1FillType=this.m_SubjFillType,e1FillType2=this.m_ClipFillType):(e1FillType=this.m_ClipFillType,e1FillType2=this.m_SubjFillType),e2.PolyTyp===ClipperLib.PolyType.ptSubject?(e2FillType=this.m_SubjFillType,e2FillType2=this.m_ClipFillType):(e2FillType=this.m_ClipFillType,e2FillType2=this.m_SubjFillType),e1FillType){case ClipperLib.PolyFillType.pftPositive:e1Wc=e1.WindCnt;break;case ClipperLib.PolyFillType.pftNegative:e1Wc=-e1.WindCnt;break;default:e1Wc=Math.abs(e1.WindCnt)}switch(e2FillType){case ClipperLib.PolyFillType.pftPositive:e2Wc=e2.WindCnt;break;case ClipperLib.PolyFillType.pftNegative:e2Wc=-e2.WindCnt;break;default:e2Wc=Math.abs(e2.WindCnt)}if(e1Contributing&&e2Contributing)0!==e1Wc&&1!==e1Wc||0!==e2Wc&&1!==e2Wc||e1.PolyTyp!==e2.PolyTyp&&this.m_ClipType!==ClipperLib.ClipType.ctXor?this.AddLocalMaxPoly(e1,e2,pt):(this.AddOutPt(e1,pt),this.AddOutPt(e2,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(e1Contributing)0!==e2Wc&&1!==e2Wc||(this.AddOutPt(e1,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(e2Contributing)0!==e1Wc&&1!==e1Wc||(this.AddOutPt(e2,pt),ClipperLib.Clipper.SwapSides(e1,e2),ClipperLib.Clipper.SwapPolyIndexes(e1,e2));else if(!(0!==e1Wc&&1!==e1Wc||0!==e2Wc&&1!==e2Wc)){var e1Wc2,e2Wc2;switch(e1FillType2){case ClipperLib.PolyFillType.pftPositive:e1Wc2=e1.WindCnt2;break;case ClipperLib.PolyFillType.pftNegative:e1Wc2=-e1.WindCnt2;break;default:e1Wc2=Math.abs(e1.WindCnt2)}switch(e2FillType2){case ClipperLib.PolyFillType.pftPositive:e2Wc2=e2.WindCnt2;break;case ClipperLib.PolyFillType.pftNegative:e2Wc2=-e2.WindCnt2;break;default:e2Wc2=Math.abs(e2.WindCnt2)}if(e1.PolyTyp!==e2.PolyTyp)this.AddLocalMinPoly(e1,e2,pt);else if(1===e1Wc&&1===e2Wc)switch(this.m_ClipType){case ClipperLib.ClipType.ctIntersection:e1Wc2>0&&e2Wc2>0&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctUnion:e1Wc2<=0&&e2Wc2<=0&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctDifference:(e1.PolyTyp===ClipperLib.PolyType.ptClip&&e1Wc2>0&&e2Wc2>0||e1.PolyTyp===ClipperLib.PolyType.ptSubject&&e1Wc2<=0&&e2Wc2<=0)&&this.AddLocalMinPoly(e1,e2,pt);break;case ClipperLib.ClipType.ctXor:this.AddLocalMinPoly(e1,e2,pt)}else ClipperLib.Clipper.SwapSides(e1,e2)}}else{if(0===e1.WindDelta&&0===e2.WindDelta)return;e1.PolyTyp===e2.PolyTyp&&e1.WindDelta!==e2.WindDelta&&this.m_ClipType===ClipperLib.ClipType.ctUnion?0===e1.WindDelta?e2Contributing&&(this.AddOutPt(e1,pt),e1Contributing&&(e1.OutIdx=-1)):e1Contributing&&(this.AddOutPt(e2,pt),e2Contributing&&(e2.OutIdx=-1)):e1.PolyTyp!==e2.PolyTyp&&(0!==e1.WindDelta||1!==Math.abs(e2.WindCnt)||this.m_ClipType===ClipperLib.ClipType.ctUnion&&0!==e2.WindCnt2?0!==e2.WindDelta||1!==Math.abs(e1.WindCnt)||this.m_ClipType===ClipperLib.ClipType.ctUnion&&0!==e1.WindCnt2||(this.AddOutPt(e2,pt),e2Contributing&&(e2.OutIdx=-1)):(this.AddOutPt(e1,pt),e1Contributing&&(e1.OutIdx=-1)))}},ClipperLib.Clipper.prototype.DeleteFromSEL=function(e){var SelPrev=e.PrevInSEL,SelNext=e.NextInSEL;null===SelPrev&&null===SelNext&&e!==this.m_SortedEdges||(null!==SelPrev?SelPrev.NextInSEL=SelNext:this.m_SortedEdges=SelNext,null!==SelNext&&(SelNext.PrevInSEL=SelPrev),e.NextInSEL=null,e.PrevInSEL=null)},ClipperLib.Clipper.prototype.ProcessHorizontals=function(){for(var horzEdge={};this.PopEdgeFromSEL(horzEdge);)this.ProcessHorizontal(horzEdge.v)},ClipperLib.Clipper.prototype.GetHorzDirection=function(HorzEdge,$var){HorzEdge.Bot.X<HorzEdge.Top.X?($var.Left=HorzEdge.Bot.X,$var.Right=HorzEdge.Top.X,$var.Dir=ClipperLib.Direction.dLeftToRight):($var.Left=HorzEdge.Top.X,$var.Right=HorzEdge.Bot.X,$var.Dir=ClipperLib.Direction.dRightToLeft)},ClipperLib.Clipper.prototype.ProcessHorizontal=function(horzEdge){var $var={Dir:null,Left:null,Right:null};this.GetHorzDirection(horzEdge,$var);for(var dir=$var.Dir,horzLeft=$var.Left,horzRight=$var.Right,IsOpen=0===horzEdge.WindDelta,eLastHorz=horzEdge,eMaxPair=null;null!==eLastHorz.NextInLML&&ClipperLib.ClipperBase.IsHorizontal(eLastHorz.NextInLML);)eLastHorz=eLastHorz.NextInLML;null===eLastHorz.NextInLML&&(eMaxPair=this.GetMaximaPair(eLastHorz));var currMax=this.m_Maxima;if(null!==currMax)if(dir===ClipperLib.Direction.dLeftToRight){for(;null!==currMax&&currMax.X<=horzEdge.Bot.X;)currMax=currMax.Next;null!==currMax&&currMax.X>=eLastHorz.Top.X&&(currMax=null)}else{for(;null!==currMax.Next&&currMax.Next.X<horzEdge.Bot.X;)currMax=currMax.Next;currMax.X<=eLastHorz.Top.X&&(currMax=null)}for(var op1=null;;){for(var IsLastHorz=horzEdge===eLastHorz,e=this.GetNextInAEL(horzEdge,dir);null!==e;){if(null!==currMax)if(dir===ClipperLib.Direction.dLeftToRight)for(;null!==currMax&&currMax.X<e.Curr.X;)horzEdge.OutIdx>=0&&!IsOpen&&this.AddOutPt(horzEdge,new ClipperLib.IntPoint2(currMax.X,horzEdge.Bot.Y)),currMax=currMax.Next;else for(;null!==currMax&&currMax.X>e.Curr.X;)horzEdge.OutIdx>=0&&!IsOpen&&this.AddOutPt(horzEdge,new ClipperLib.IntPoint2(currMax.X,horzEdge.Bot.Y)),currMax=currMax.Prev;if(dir===ClipperLib.Direction.dLeftToRight&&e.Curr.X>horzRight||dir===ClipperLib.Direction.dRightToLeft&&e.Curr.X<horzLeft)break;if(e.Curr.X===horzEdge.Top.X&&null!==horzEdge.NextInLML&&e.Dx<horzEdge.NextInLML.Dx)break;if(horzEdge.OutIdx>=0&&!IsOpen){ClipperLib.use_xyz&&(dir===ClipperLib.Direction.dLeftToRight?this.SetZ(e.Curr,horzEdge,e):this.SetZ(e.Curr,e,horzEdge)),op1=this.AddOutPt(horzEdge,e.Curr);for(var eNextHorz=this.m_SortedEdges;null!==eNextHorz;){if(eNextHorz.OutIdx>=0&&this.HorzSegmentsOverlap(horzEdge.Bot.X,horzEdge.Top.X,eNextHorz.Bot.X,eNextHorz.Top.X)){var op2=this.GetLastOutPt(eNextHorz);this.AddJoin(op2,op1,eNextHorz.Top)}eNextHorz=eNextHorz.NextInSEL}this.AddGhostJoin(op1,horzEdge.Bot)}if(e===eMaxPair&&IsLastHorz)return horzEdge.OutIdx>=0&&this.AddLocalMaxPoly(horzEdge,eMaxPair,horzEdge.Top),this.DeleteFromAEL(horzEdge),void this.DeleteFromAEL(eMaxPair);if(dir===ClipperLib.Direction.dLeftToRight){var Pt=new ClipperLib.IntPoint2(e.Curr.X,horzEdge.Curr.Y);this.IntersectEdges(horzEdge,e,Pt)}else Pt=new ClipperLib.IntPoint2(e.Curr.X,horzEdge.Curr.Y),this.IntersectEdges(e,horzEdge,Pt);var eNext=this.GetNextInAEL(e,dir);this.SwapPositionsInAEL(horzEdge,e),e=eNext}if(null===horzEdge.NextInLML||!ClipperLib.ClipperBase.IsHorizontal(horzEdge.NextInLML))break;(horzEdge=this.UpdateEdgeIntoAEL(horzEdge)).OutIdx>=0&&this.AddOutPt(horzEdge,horzEdge.Bot),$var={Dir:dir,Left:horzLeft,Right:horzRight},this.GetHorzDirection(horzEdge,$var),dir=$var.Dir,horzLeft=$var.Left,horzRight=$var.Right}if(horzEdge.OutIdx>=0&&null===op1){for(op1=this.GetLastOutPt(horzEdge),eNextHorz=this.m_SortedEdges;null!==eNextHorz;)eNextHorz.OutIdx>=0&&this.HorzSegmentsOverlap(horzEdge.Bot.X,horzEdge.Top.X,eNextHorz.Bot.X,eNextHorz.Top.X)&&(op2=this.GetLastOutPt(eNextHorz),this.AddJoin(op2,op1,eNextHorz.Top)),eNextHorz=eNextHorz.NextInSEL;this.AddGhostJoin(op1,horzEdge.Top)}if(null!==horzEdge.NextInLML)if(horzEdge.OutIdx>=0){if(op1=this.AddOutPt(horzEdge,horzEdge.Top),0===(horzEdge=this.UpdateEdgeIntoAEL(horzEdge)).WindDelta)return;var ePrev=horzEdge.PrevInAEL;eNext=horzEdge.NextInAEL,null!==ePrev&&ePrev.Curr.X===horzEdge.Bot.X&&ePrev.Curr.Y===horzEdge.Bot.Y&&0===ePrev.WindDelta&&ePrev.OutIdx>=0&&ePrev.Curr.Y>ePrev.Top.Y&&ClipperLib.ClipperBase.SlopesEqual3(horzEdge,ePrev,this.m_UseFullRange)?(op2=this.AddOutPt(ePrev,horzEdge.Bot),this.AddJoin(op1,op2,horzEdge.Top)):null!==eNext&&eNext.Curr.X===horzEdge.Bot.X&&eNext.Curr.Y===horzEdge.Bot.Y&&0!==eNext.WindDelta&&eNext.OutIdx>=0&&eNext.Curr.Y>eNext.Top.Y&&ClipperLib.ClipperBase.SlopesEqual3(horzEdge,eNext,this.m_UseFullRange)&&(op2=this.AddOutPt(eNext,horzEdge.Bot),this.AddJoin(op1,op2,horzEdge.Top))}else horzEdge=this.UpdateEdgeIntoAEL(horzEdge);else horzEdge.OutIdx>=0&&this.AddOutPt(horzEdge,horzEdge.Top),this.DeleteFromAEL(horzEdge)},ClipperLib.Clipper.prototype.GetNextInAEL=function(e,Direction){return Direction===ClipperLib.Direction.dLeftToRight?e.NextInAEL:e.PrevInAEL},ClipperLib.Clipper.prototype.IsMinima=function(e){return null!==e&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},ClipperLib.Clipper.prototype.IsMaxima=function(e,Y){return null!==e&&e.Top.Y===Y&&null===e.NextInLML},ClipperLib.Clipper.prototype.IsIntermediate=function(e,Y){return e.Top.Y===Y&&null!==e.NextInLML},ClipperLib.Clipper.prototype.GetMaximaPair=function(e){return ClipperLib.IntPoint.op_Equality(e.Next.Top,e.Top)&&null===e.Next.NextInLML?e.Next:ClipperLib.IntPoint.op_Equality(e.Prev.Top,e.Top)&&null===e.Prev.NextInLML?e.Prev:null},ClipperLib.Clipper.prototype.GetMaximaPairEx=function(e){var result=this.GetMaximaPair(e);return null===result||result.OutIdx===ClipperLib.ClipperBase.Skip||result.NextInAEL===result.PrevInAEL&&!ClipperLib.ClipperBase.IsHorizontal(result)?null:result},ClipperLib.Clipper.prototype.ProcessIntersections=function(topY){if(null===this.m_ActiveEdges)return!0;try{if(this.BuildIntersectList(topY),0===this.m_IntersectList.length)return!0;if(1!==this.m_IntersectList.length&&!this.FixupIntersectionOrder())return!1;this.ProcessIntersectList()}catch($$e2){this.m_SortedEdges=null,this.m_IntersectList.length=0,ClipperLib.Error("ProcessIntersections error")}return this.m_SortedEdges=null,!0},ClipperLib.Clipper.prototype.BuildIntersectList=function(topY){if(null!==this.m_ActiveEdges){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;null!==e;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e.Curr.X=ClipperLib.Clipper.TopX(e,topY),e=e.NextInAEL;for(var isModified=!0;isModified&&null!==this.m_SortedEdges;){for(isModified=!1,e=this.m_SortedEdges;null!==e.NextInSEL;){var eNext=e.NextInSEL,pt=new ClipperLib.IntPoint0;if(e.Curr.X>eNext.Curr.X){this.IntersectPoint(e,eNext,pt),pt.Y<topY&&(pt=new ClipperLib.IntPoint2(ClipperLib.Clipper.TopX(e,topY),topY));var newNode=new ClipperLib.IntersectNode;newNode.Edge1=e,newNode.Edge2=eNext,newNode.Pt.X=pt.X,newNode.Pt.Y=pt.Y,ClipperLib.use_xyz&&(newNode.Pt.Z=pt.Z),this.m_IntersectList.push(newNode),this.SwapPositionsInSEL(e,eNext),isModified=!0}else e=eNext}if(null===e.PrevInSEL)break;e.PrevInSEL.NextInSEL=null}this.m_SortedEdges=null}},ClipperLib.Clipper.prototype.EdgesAdjacent=function(inode){return inode.Edge1.NextInSEL===inode.Edge2||inode.Edge1.PrevInSEL===inode.Edge2},ClipperLib.Clipper.IntersectNodeSort=function(node1,node2){return node2.Pt.Y-node1.Pt.Y},ClipperLib.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var cnt=this.m_IntersectList.length,i=0;i<cnt;i++){if(!this.EdgesAdjacent(this.m_IntersectList[i])){for(var j=i+1;j<cnt&&!this.EdgesAdjacent(this.m_IntersectList[j]);)j++;if(j===cnt)return!1;var tmp=this.m_IntersectList[i];this.m_IntersectList[i]=this.m_IntersectList[j],this.m_IntersectList[j]=tmp}this.SwapPositionsInSEL(this.m_IntersectList[i].Edge1,this.m_IntersectList[i].Edge2)}return!0},ClipperLib.Clipper.prototype.ProcessIntersectList=function(){for(var i=0,ilen=this.m_IntersectList.length;i<ilen;i++){var iNode=this.m_IntersectList[i];this.IntersectEdges(iNode.Edge1,iNode.Edge2,iNode.Pt),this.SwapPositionsInAEL(iNode.Edge1,iNode.Edge2)}this.m_IntersectList.length=0},browser.msie?ClipperLib.Clipper.Round=function(a){return a<0?Math.ceil(a-.5):Math.round(a)}:browser.chromium?ClipperLib.Clipper.Round=function(a){return a<0?-Math.round(Math.abs(a)):Math.round(a)}:browser.safari?ClipperLib.Clipper.Round=function(a){return a<0?(a-=.5)<-2147483648?Math.ceil(a):0|a:(a+=.5)>2147483647?Math.floor(a):0|a}:ClipperLib.Clipper.Round=function(a){return a<0?Math.ceil(a-.5):Math.floor(a+.5)},ClipperLib.Clipper.TopX=function(edge,currentY){return currentY===edge.Top.Y?edge.Top.X:edge.Bot.X+ClipperLib.Clipper.Round(edge.Dx*(currentY-edge.Bot.Y))},ClipperLib.Clipper.prototype.IntersectPoint=function(edge1,edge2,ip){var b1,b2;if(ip.X=0,ip.Y=0,edge1.Dx===edge2.Dx)return ip.Y=edge1.Curr.Y,void(ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y));if(0===edge1.Delta.X)ip.X=edge1.Bot.X,ClipperLib.ClipperBase.IsHorizontal(edge2)?ip.Y=edge2.Bot.Y:(b2=edge2.Bot.Y-edge2.Bot.X/edge2.Dx,ip.Y=ClipperLib.Clipper.Round(ip.X/edge2.Dx+b2));else if(0===edge2.Delta.X)ip.X=edge2.Bot.X,ClipperLib.ClipperBase.IsHorizontal(edge1)?ip.Y=edge1.Bot.Y:(b1=edge1.Bot.Y-edge1.Bot.X/edge1.Dx,ip.Y=ClipperLib.Clipper.Round(ip.X/edge1.Dx+b1));else{b1=edge1.Bot.X-edge1.Bot.Y*edge1.Dx;var q=((b2=edge2.Bot.X-edge2.Bot.Y*edge2.Dx)-b1)/(edge1.Dx-edge2.Dx);ip.Y=ClipperLib.Clipper.Round(q),Math.abs(edge1.Dx)<Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.Round(edge1.Dx*q+b1):ip.X=ClipperLib.Clipper.Round(edge2.Dx*q+b2)}if(ip.Y<edge1.Top.Y||ip.Y<edge2.Top.Y){if(edge1.Top.Y>edge2.Top.Y)return ip.Y=edge1.Top.Y,ip.X=ClipperLib.Clipper.TopX(edge2,edge1.Top.Y),ip.X<edge1.Top.X;ip.Y=edge2.Top.Y,Math.abs(edge1.Dx)<Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y):ip.X=ClipperLib.Clipper.TopX(edge2,ip.Y)}ip.Y>edge1.Curr.Y&&(ip.Y=edge1.Curr.Y,Math.abs(edge1.Dx)>Math.abs(edge2.Dx)?ip.X=ClipperLib.Clipper.TopX(edge2,ip.Y):ip.X=ClipperLib.Clipper.TopX(edge1,ip.Y))},ClipperLib.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(topY){for(var e=this.m_ActiveEdges;null!==e;){var IsMaximaEdge=this.IsMaxima(e,topY);if(IsMaximaEdge){var eMaxPair=this.GetMaximaPairEx(e);IsMaximaEdge=null===eMaxPair||!ClipperLib.ClipperBase.IsHorizontal(eMaxPair)}if(IsMaximaEdge){this.StrictlySimple&&this.InsertMaxima(e.Top.X);var ePrev=e.PrevInAEL;this.DoMaxima(e),e=null===ePrev?this.m_ActiveEdges:ePrev.NextInAEL}else{if(this.IsIntermediate(e,topY)&&ClipperLib.ClipperBase.IsHorizontal(e.NextInLML)?((e=this.UpdateEdgeIntoAEL(e)).OutIdx>=0&&this.AddOutPt(e,e.Bot),this.AddEdgeToSEL(e)):(e.Curr.X=ClipperLib.Clipper.TopX(e,topY),e.Curr.Y=topY),ClipperLib.use_xyz&&(e.Top.Y===topY?e.Curr.Z=e.Top.Z:e.Bot.Y===topY?e.Curr.Z=e.Bot.Z:e.Curr.Z=0),this.StrictlySimple&&(ePrev=e.PrevInAEL,e.OutIdx>=0&&0!==e.WindDelta&&null!==ePrev&&ePrev.OutIdx>=0&&ePrev.Curr.X===e.Curr.X&&0!==ePrev.WindDelta)){var ip=new ClipperLib.IntPoint1(e.Curr);ClipperLib.use_xyz&&this.SetZ(ip,ePrev,e);var op=this.AddOutPt(ePrev,ip),op2=this.AddOutPt(e,ip);this.AddJoin(op,op2,ip)}e=e.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,e=this.m_ActiveEdges;null!==e;){if(this.IsIntermediate(e,topY)){op=null,e.OutIdx>=0&&(op=this.AddOutPt(e,e.Top)),ePrev=(e=this.UpdateEdgeIntoAEL(e)).PrevInAEL;var eNext=e.NextInAEL;null!==ePrev&&ePrev.Curr.X===e.Bot.X&&ePrev.Curr.Y===e.Bot.Y&&null!==op&&ePrev.OutIdx>=0&&ePrev.Curr.Y===ePrev.Top.Y&&ClipperLib.ClipperBase.SlopesEqual5(e.Curr,e.Top,ePrev.Curr,ePrev.Top,this.m_UseFullRange)&&0!==e.WindDelta&&0!==ePrev.WindDelta?(op2=this.AddOutPt(ePrev2,e.Bot),this.AddJoin(op,op2,e.Top)):null!==eNext&&eNext.Curr.X===e.Bot.X&&eNext.Curr.Y===e.Bot.Y&&null!==op&&eNext.OutIdx>=0&&eNext.Curr.Y===eNext.Top.Y&&ClipperLib.ClipperBase.SlopesEqual5(e.Curr,e.Top,eNext.Curr,eNext.Top,this.m_UseFullRange)&&0!==e.WindDelta&&0!==eNext.WindDelta&&(op2=this.AddOutPt(eNext,e.Bot),this.AddJoin(op,op2,e.Top))}e=e.NextInAEL}},ClipperLib.Clipper.prototype.DoMaxima=function(e){var eMaxPair=this.GetMaximaPairEx(e);if(null===eMaxPair)return e.OutIdx>=0&&this.AddOutPt(e,e.Top),void this.DeleteFromAEL(e);for(var eNext=e.NextInAEL;null!==eNext&&eNext!==eMaxPair;)this.IntersectEdges(e,eNext,e.Top),this.SwapPositionsInAEL(e,eNext),eNext=e.NextInAEL;-1===e.OutIdx&&-1===eMaxPair.OutIdx?(this.DeleteFromAEL(e),this.DeleteFromAEL(eMaxPair)):e.OutIdx>=0&&eMaxPair.OutIdx>=0?(e.OutIdx>=0&&this.AddLocalMaxPoly(e,eMaxPair,e.Top),this.DeleteFromAEL(e),this.DeleteFromAEL(eMaxPair)):ClipperLib.use_lines&&0===e.WindDelta?(e.OutIdx>=0&&(this.AddOutPt(e,e.Top),e.OutIdx=ClipperLib.ClipperBase.Unassigned),this.DeleteFromAEL(e),eMaxPair.OutIdx>=0&&(this.AddOutPt(eMaxPair,e.Top),eMaxPair.OutIdx=ClipperLib.ClipperBase.Unassigned),this.DeleteFromAEL(eMaxPair)):ClipperLib.Error("DoMaxima error")},ClipperLib.Clipper.ReversePaths=function(polys){for(var i=0,len=polys.length;i<len;i++)polys[i].reverse()},ClipperLib.Clipper.Orientation=function(poly){return ClipperLib.Clipper.Area(poly)>=0},ClipperLib.Clipper.prototype.PointCount=function(pts){if(null===pts)return 0;var result=0,p=pts;do{result++,p=p.Next}while(p!==pts);return result},ClipperLib.Clipper.prototype.BuildResult=function(polyg){ClipperLib.Clear(polyg);for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;i++){var outRec=this.m_PolyOuts[i];if(null!==outRec.Pts){var p=outRec.Pts.Prev,cnt=this.PointCount(p);if(!(cnt<2)){for(var pg=new Array(cnt),j=0;j<cnt;j++)pg[j]=p.Pt,p=p.Prev;polyg.push(pg)}}}},ClipperLib.Clipper.prototype.BuildResult2=function(polytree){polytree.Clear();for(var i=0,ilen=this.m_PolyOuts.length;i<ilen;i++){var outRec=this.m_PolyOuts[i],cnt=this.PointCount(outRec.Pts);if(!(outRec.IsOpen&&cnt<2||!outRec.IsOpen&&cnt<3)){this.FixHoleLinkage(outRec);var pn=new ClipperLib.PolyNode;polytree.m_AllPolys.push(pn),outRec.PolyNode=pn,pn.m_polygon.length=cnt;for(var op=outRec.Pts.Prev,j=0;j<cnt;j++)pn.m_polygon[j]=op.Pt,op=op.Prev}}for(i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).PolyNode&&(outRec.IsOpen?(outRec.PolyNode.IsOpen=!0,polytree.AddChild(outRec.PolyNode)):null!==outRec.FirstLeft&&null!==outRec.FirstLeft.PolyNode?outRec.FirstLeft.PolyNode.AddChild(outRec.PolyNode):polytree.AddChild(outRec.PolyNode))},ClipperLib.Clipper.prototype.FixupOutPolyline=function(outRec){for(var pp=outRec.Pts,lastPP=pp.Prev;pp!==lastPP;)if(pp=pp.Next,ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Prev.Pt)){pp===lastPP&&(lastPP=pp.Prev);var tmpPP=pp.Prev;tmpPP.Next=pp.Next,pp.Next.Prev=tmpPP,pp=tmpPP}pp===pp.Prev&&(outRec.Pts=null)},ClipperLib.Clipper.prototype.FixupOutPolygon=function(outRec){var lastOK=null;outRec.BottomPt=null;for(var pp=outRec.Pts,preserveCol=this.PreserveCollinear||this.StrictlySimple;;){if(pp.Prev===pp||pp.Prev===pp.Next)return void(outRec.Pts=null);if(ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Next.Pt)||ClipperLib.IntPoint.op_Equality(pp.Pt,pp.Prev.Pt)||ClipperLib.ClipperBase.SlopesEqual4(pp.Prev.Pt,pp.Pt,pp.Next.Pt,this.m_UseFullRange)&&(!preserveCol||!this.Pt2IsBetweenPt1AndPt3(pp.Prev.Pt,pp.Pt,pp.Next.Pt)))lastOK=null,pp.Prev.Next=pp.Next,pp.Next.Prev=pp.Prev,pp=pp.Prev;else{if(pp===lastOK)break;null===lastOK&&(lastOK=pp),pp=pp.Next}}outRec.Pts=pp},ClipperLib.Clipper.prototype.DupOutPt=function(outPt,InsertAfter){var result=new ClipperLib.OutPt;return result.Pt.X=outPt.Pt.X,result.Pt.Y=outPt.Pt.Y,ClipperLib.use_xyz&&(result.Pt.Z=outPt.Pt.Z),result.Idx=outPt.Idx,InsertAfter?(result.Next=outPt.Next,result.Prev=outPt,outPt.Next.Prev=result,outPt.Next=result):(result.Prev=outPt.Prev,result.Next=outPt,outPt.Prev.Next=result,outPt.Prev=result),result},ClipperLib.Clipper.prototype.GetOverlap=function(a1,a2,b1,b2,$val){return a1<a2?b1<b2?($val.Left=Math.max(a1,b1),$val.Right=Math.min(a2,b2)):($val.Left=Math.max(a1,b2),$val.Right=Math.min(a2,b1)):b1<b2?($val.Left=Math.max(a2,b1),$val.Right=Math.min(a1,b2)):($val.Left=Math.max(a2,b2),$val.Right=Math.min(a1,b1)),$val.Left<$val.Right},ClipperLib.Clipper.prototype.JoinHorz=function(op1,op1b,op2,op2b,Pt,DiscardLeft){var Dir1=op1.Pt.X>op1b.Pt.X?ClipperLib.Direction.dRightToLeft:ClipperLib.Direction.dLeftToRight,Dir2=op2.Pt.X>op2b.Pt.X?ClipperLib.Direction.dRightToLeft:ClipperLib.Direction.dLeftToRight;if(Dir1===Dir2)return!1;if(Dir1===ClipperLib.Direction.dLeftToRight){for(;op1.Next.Pt.X<=Pt.X&&op1.Next.Pt.X>=op1.Pt.X&&op1.Next.Pt.Y===Pt.Y;)op1=op1.Next;DiscardLeft&&op1.Pt.X!==Pt.X&&(op1=op1.Next),op1b=this.DupOutPt(op1,!DiscardLeft),ClipperLib.IntPoint.op_Inequality(op1b.Pt,Pt)&&((op1=op1b).Pt.X=Pt.X,op1.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op1.Pt.Z=Pt.Z),op1b=this.DupOutPt(op1,!DiscardLeft))}else{for(;op1.Next.Pt.X>=Pt.X&&op1.Next.Pt.X<=op1.Pt.X&&op1.Next.Pt.Y===Pt.Y;)op1=op1.Next;DiscardLeft||op1.Pt.X===Pt.X||(op1=op1.Next),op1b=this.DupOutPt(op1,DiscardLeft),ClipperLib.IntPoint.op_Inequality(op1b.Pt,Pt)&&((op1=op1b).Pt.X=Pt.X,op1.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op1.Pt.Z=Pt.Z),op1b=this.DupOutPt(op1,DiscardLeft))}if(Dir2===ClipperLib.Direction.dLeftToRight){for(;op2.Next.Pt.X<=Pt.X&&op2.Next.Pt.X>=op2.Pt.X&&op2.Next.Pt.Y===Pt.Y;)op2=op2.Next;DiscardLeft&&op2.Pt.X!==Pt.X&&(op2=op2.Next),op2b=this.DupOutPt(op2,!DiscardLeft),ClipperLib.IntPoint.op_Inequality(op2b.Pt,Pt)&&((op2=op2b).Pt.X=Pt.X,op2.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op2.Pt.Z=Pt.Z),op2b=this.DupOutPt(op2,!DiscardLeft))}else{for(;op2.Next.Pt.X>=Pt.X&&op2.Next.Pt.X<=op2.Pt.X&&op2.Next.Pt.Y===Pt.Y;)op2=op2.Next;DiscardLeft||op2.Pt.X===Pt.X||(op2=op2.Next),op2b=this.DupOutPt(op2,DiscardLeft),ClipperLib.IntPoint.op_Inequality(op2b.Pt,Pt)&&((op2=op2b).Pt.X=Pt.X,op2.Pt.Y=Pt.Y,ClipperLib.use_xyz&&(op2.Pt.Z=Pt.Z),op2b=this.DupOutPt(op2,DiscardLeft))}return Dir1===ClipperLib.Direction.dLeftToRight===DiscardLeft?(op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b):(op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b),!0},ClipperLib.Clipper.prototype.JoinPoints=function(j,outRec1,outRec2){var op1=j.OutPt1,op1b=new ClipperLib.OutPt,op2=j.OutPt2,op2b=new ClipperLib.OutPt,isHorizontal=j.OutPt1.Pt.Y===j.OffPt.Y;if(isHorizontal&&ClipperLib.IntPoint.op_Equality(j.OffPt,j.OutPt1.Pt)&&ClipperLib.IntPoint.op_Equality(j.OffPt,j.OutPt2.Pt)){if(outRec1!==outRec2)return!1;for(op1b=j.OutPt1.Next;op1b!==op1&&ClipperLib.IntPoint.op_Equality(op1b.Pt,j.OffPt);)op1b=op1b.Next;var reverse1=op1b.Pt.Y>j.OffPt.Y;for(op2b=j.OutPt2.Next;op2b!==op2&&ClipperLib.IntPoint.op_Equality(op2b.Pt,j.OffPt);)op2b=op2b.Next;return reverse1!==op2b.Pt.Y>j.OffPt.Y&&(reverse1?(op1b=this.DupOutPt(op1,!1),op2b=this.DupOutPt(op2,!0),op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b,j.OutPt1=op1,j.OutPt2=op1b,!0):(op1b=this.DupOutPt(op1,!0),op2b=this.DupOutPt(op2,!1),op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b,j.OutPt1=op1,j.OutPt2=op1b,!0))}if(isHorizontal){for(op1b=op1;op1.Prev.Pt.Y===op1.Pt.Y&&op1.Prev!==op1b&&op1.Prev!==op2;)op1=op1.Prev;for(;op1b.Next.Pt.Y===op1b.Pt.Y&&op1b.Next!==op1&&op1b.Next!==op2;)op1b=op1b.Next;if(op1b.Next===op1||op1b.Next===op2)return!1;for(op2b=op2;op2.Prev.Pt.Y===op2.Pt.Y&&op2.Prev!==op2b&&op2.Prev!==op1b;)op2=op2.Prev;for(;op2b.Next.Pt.Y===op2b.Pt.Y&&op2b.Next!==op2&&op2b.Next!==op1;)op2b=op2b.Next;if(op2b.Next===op2||op2b.Next===op1)return!1;var $val={Left:null,Right:null};if(!this.GetOverlap(op1.Pt.X,op1b.Pt.X,op2.Pt.X,op2b.Pt.X,$val))return!1;var DiscardLeftSide,Left=$val.Left,Right=$val.Right,Pt=new ClipperLib.IntPoint0;return op1.Pt.X>=Left&&op1.Pt.X<=Right?(Pt.X=op1.Pt.X,Pt.Y=op1.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op1.Pt.Z),DiscardLeftSide=op1.Pt.X>op1b.Pt.X):op2.Pt.X>=Left&&op2.Pt.X<=Right?(Pt.X=op2.Pt.X,Pt.Y=op2.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op2.Pt.Z),DiscardLeftSide=op2.Pt.X>op2b.Pt.X):op1b.Pt.X>=Left&&op1b.Pt.X<=Right?(Pt.X=op1b.Pt.X,Pt.Y=op1b.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op1b.Pt.Z),DiscardLeftSide=op1b.Pt.X>op1.Pt.X):(Pt.X=op2b.Pt.X,Pt.Y=op2b.Pt.Y,ClipperLib.use_xyz&&(Pt.Z=op2b.Pt.Z),DiscardLeftSide=op2b.Pt.X>op2.Pt.X),j.OutPt1=op1,j.OutPt2=op2,this.JoinHorz(op1,op1b,op2,op2b,Pt,DiscardLeftSide)}for(op1b=op1.Next;ClipperLib.IntPoint.op_Equality(op1b.Pt,op1.Pt)&&op1b!==op1;)op1b=op1b.Next;var Reverse1=op1b.Pt.Y>op1.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op1.Pt,op1b.Pt,j.OffPt,this.m_UseFullRange);if(Reverse1){for(op1b=op1.Prev;ClipperLib.IntPoint.op_Equality(op1b.Pt,op1.Pt)&&op1b!==op1;)op1b=op1b.Prev;if(op1b.Pt.Y>op1.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op1.Pt,op1b.Pt,j.OffPt,this.m_UseFullRange))return!1}for(op2b=op2.Next;ClipperLib.IntPoint.op_Equality(op2b.Pt,op2.Pt)&&op2b!==op2;)op2b=op2b.Next;var Reverse2=op2b.Pt.Y>op2.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op2.Pt,op2b.Pt,j.OffPt,this.m_UseFullRange);if(Reverse2){for(op2b=op2.Prev;ClipperLib.IntPoint.op_Equality(op2b.Pt,op2.Pt)&&op2b!==op2;)op2b=op2b.Prev;if(op2b.Pt.Y>op2.Pt.Y||!ClipperLib.ClipperBase.SlopesEqual4(op2.Pt,op2b.Pt,j.OffPt,this.m_UseFullRange))return!1}return!(op1b===op1||op2b===op2||op1b===op2b||outRec1===outRec2&&Reverse1===Reverse2||(Reverse1?(op1b=this.DupOutPt(op1,!1),op2b=this.DupOutPt(op2,!0),op1.Prev=op2,op2.Next=op1,op1b.Next=op2b,op2b.Prev=op1b,j.OutPt1=op1,j.OutPt2=op1b,0):(op1b=this.DupOutPt(op1,!0),op2b=this.DupOutPt(op2,!1),op1.Next=op2,op2.Prev=op1,op1b.Prev=op2b,op2b.Next=op1b,j.OutPt1=op1,j.OutPt2=op1b,0)))},ClipperLib.Clipper.GetBounds=function(paths){for(var i=0,cnt=paths.length;i<cnt&&0===paths[i].length;)i++;if(i===cnt)return new ClipperLib.IntRect(0,0,0,0);var result=new ClipperLib.IntRect;for(result.left=paths[i][0].X,result.right=result.left,result.top=paths[i][0].Y,result.bottom=result.top;i<cnt;i++)for(var j=0,jlen=paths[i].length;j<jlen;j++)paths[i][j].X<result.left?result.left=paths[i][j].X:paths[i][j].X>result.right&&(result.right=paths[i][j].X),paths[i][j].Y<result.top?result.top=paths[i][j].Y:paths[i][j].Y>result.bottom&&(result.bottom=paths[i][j].Y);return result},ClipperLib.Clipper.prototype.GetBounds2=function(ops){var opStart=ops,result=new ClipperLib.IntRect;for(result.left=ops.Pt.X,result.right=ops.Pt.X,result.top=ops.Pt.Y,result.bottom=ops.Pt.Y,ops=ops.Next;ops!==opStart;)ops.Pt.X<result.left&&(result.left=ops.Pt.X),ops.Pt.X>result.right&&(result.right=ops.Pt.X),ops.Pt.Y<result.top&&(result.top=ops.Pt.Y),ops.Pt.Y>result.bottom&&(result.bottom=ops.Pt.Y),ops=ops.Next;return result},ClipperLib.Clipper.PointInPolygon=function(pt,path){var result=0,cnt=path.length;if(cnt<3)return 0;for(var ip=path[0],i=1;i<=cnt;++i){var ipNext=i===cnt?path[0]:path[i];if(ipNext.Y===pt.Y&&(ipNext.X===pt.X||ip.Y===pt.Y&&ipNext.X>pt.X==ip.X<pt.X))return-1;if(ip.Y<pt.Y!=ipNext.Y<pt.Y)if(ip.X>=pt.X)if(ipNext.X>pt.X)result=1-result;else{if(0==(d=(ip.X-pt.X)*(ipNext.Y-pt.Y)-(ipNext.X-pt.X)*(ip.Y-pt.Y)))return-1;d>0==ipNext.Y>ip.Y&&(result=1-result)}else if(ipNext.X>pt.X){var d;if(0==(d=(ip.X-pt.X)*(ipNext.Y-pt.Y)-(ipNext.X-pt.X)*(ip.Y-pt.Y)))return-1;d>0==ipNext.Y>ip.Y&&(result=1-result)}ip=ipNext}return result},ClipperLib.Clipper.prototype.PointInPolygon=function(pt,op){var result=0,startOp=op,ptx=pt.X,pty=pt.Y,poly0x=op.Pt.X,poly0y=op.Pt.Y;do{var poly1x=(op=op.Next).Pt.X,poly1y=op.Pt.Y;if(poly1y===pty&&(poly1x===ptx||poly0y===pty&&poly1x>ptx==poly0x<ptx))return-1;if(poly0y<pty!=poly1y<pty)if(poly0x>=ptx)if(poly1x>ptx)result=1-result;else{if(0==(d=(poly0x-ptx)*(poly1y-pty)-(poly1x-ptx)*(poly0y-pty)))return-1;d>0==poly1y>poly0y&&(result=1-result)}else if(poly1x>ptx){var d;if(0==(d=(poly0x-ptx)*(poly1y-pty)-(poly1x-ptx)*(poly0y-pty)))return-1;d>0==poly1y>poly0y&&(result=1-result)}poly0x=poly1x,poly0y=poly1y}while(startOp!==op);return result},ClipperLib.Clipper.prototype.Poly2ContainsPoly1=function(outPt1,outPt2){var op=outPt1;do{var res=this.PointInPolygon(op.Pt,outPt2);if(res>=0)return res>0;op=op.Next}while(op!==outPt1);return!0},ClipperLib.Clipper.prototype.FixupFirstLefts1=function(OldOutRec,NewOutRec){for(var outRec,firstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)outRec=this.m_PolyOuts[i],firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft),null!==outRec.Pts&&firstLeft===OldOutRec&&this.Poly2ContainsPoly1(outRec.Pts,NewOutRec.Pts)&&(outRec.FirstLeft=NewOutRec)},ClipperLib.Clipper.prototype.FixupFirstLefts2=function(innerOutRec,outerOutRec){for(var outRec,firstLeft,orfl=outerOutRec.FirstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)null!==(outRec=this.m_PolyOuts[i]).Pts&&outRec!==outerOutRec&&outRec!==innerOutRec&&((firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft))!==orfl&&firstLeft!==innerOutRec&&firstLeft!==outerOutRec||(this.Poly2ContainsPoly1(outRec.Pts,innerOutRec.Pts)?outRec.FirstLeft=innerOutRec:this.Poly2ContainsPoly1(outRec.Pts,outerOutRec.Pts)?outRec.FirstLeft=outerOutRec:outRec.FirstLeft!==innerOutRec&&outRec.FirstLeft!==outerOutRec||(outRec.FirstLeft=orfl)))},ClipperLib.Clipper.prototype.FixupFirstLefts3=function(OldOutRec,NewOutRec){for(var outRec,firstLeft,i=0,ilen=this.m_PolyOuts.length;i<ilen;i++)outRec=this.m_PolyOuts[i],firstLeft=ClipperLib.Clipper.ParseFirstLeft(outRec.FirstLeft),null!==outRec.Pts&&firstLeft===OldOutRec&&(outRec.FirstLeft=NewOutRec)},ClipperLib.Clipper.ParseFirstLeft=function(FirstLeft){for(;null!==FirstLeft&&null===FirstLeft.Pts;)FirstLeft=FirstLeft.FirstLeft;return FirstLeft},ClipperLib.Clipper.prototype.JoinCommonEdges=function(){for(var i=0,ilen=this.m_Joins.length;i<ilen;i++){var holeStateRec,join=this.m_Joins[i],outRec1=this.GetOutRec(join.OutPt1.Idx),outRec2=this.GetOutRec(join.OutPt2.Idx);null!==outRec1.Pts&&null!==outRec2.Pts&&(outRec1.IsOpen||outRec2.IsOpen||(holeStateRec=outRec1===outRec2?outRec1:this.OutRec1RightOfOutRec2(outRec1,outRec2)?outRec2:this.OutRec1RightOfOutRec2(outRec2,outRec1)?outRec1:this.GetLowermostRec(outRec1,outRec2),this.JoinPoints(join,outRec1,outRec2)&&(outRec1===outRec2?(outRec1.Pts=join.OutPt1,outRec1.BottomPt=null,(outRec2=this.CreateOutRec()).Pts=join.OutPt2,this.UpdateOutPtIdxs(outRec2),this.Poly2ContainsPoly1(outRec2.Pts,outRec1.Pts)?(outRec2.IsHole=!outRec1.IsHole,outRec2.FirstLeft=outRec1,this.m_UsingPolyTree&&this.FixupFirstLefts2(outRec2,outRec1),(outRec2.IsHole^this.ReverseSolution)==this.Area$1(outRec2)>0&&this.ReversePolyPtLinks(outRec2.Pts)):this.Poly2ContainsPoly1(outRec1.Pts,outRec2.Pts)?(outRec2.IsHole=outRec1.IsHole,outRec1.IsHole=!outRec2.IsHole,outRec2.FirstLeft=outRec1.FirstLeft,outRec1.FirstLeft=outRec2,this.m_UsingPolyTree&&this.FixupFirstLefts2(outRec1,outRec2),(outRec1.IsHole^this.ReverseSolution)==this.Area$1(outRec1)>0&&this.ReversePolyPtLinks(outRec1.Pts)):(outRec2.IsHole=outRec1.IsHole,outRec2.FirstLeft=outRec1.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(outRec1,outRec2))):(outRec2.Pts=null,outRec2.BottomPt=null,outRec2.Idx=outRec1.Idx,outRec1.IsHole=holeStateRec.IsHole,holeStateRec===outRec2&&(outRec1.FirstLeft=outRec2.FirstLeft),outRec2.FirstLeft=outRec1,this.m_UsingPolyTree&&this.FixupFirstLefts3(outRec2,outRec1)))))}},ClipperLib.Clipper.prototype.UpdateOutPtIdxs=function(outrec){var op=outrec.Pts;do{op.Idx=outrec.Idx,op=op.Prev}while(op!==outrec.Pts)},ClipperLib.Clipper.prototype.DoSimplePolygons=function(){for(var i=0;i<this.m_PolyOuts.length;){var outrec=this.m_PolyOuts[i++],op=outrec.Pts;if(null!==op&&!outrec.IsOpen)do{for(var op2=op.Next;op2!==outrec.Pts;){if(ClipperLib.IntPoint.op_Equality(op.Pt,op2.Pt)&&op2.Next!==op&&op2.Prev!==op){var op3=op.Prev,op4=op2.Prev;op.Prev=op4,op4.Next=op,op2.Prev=op3,op3.Next=op2,outrec.Pts=op;var outrec2=this.CreateOutRec();outrec2.Pts=op2,this.UpdateOutPtIdxs(outrec2),this.Poly2ContainsPoly1(outrec2.Pts,outrec.Pts)?(outrec2.IsHole=!outrec.IsHole,outrec2.FirstLeft=outrec,this.m_UsingPolyTree&&this.FixupFirstLefts2(outrec2,outrec)):this.Poly2ContainsPoly1(outrec.Pts,outrec2.Pts)?(outrec2.IsHole=outrec.IsHole,outrec.IsHole=!outrec2.IsHole,outrec2.FirstLeft=outrec.FirstLeft,outrec.FirstLeft=outrec2,this.m_UsingPolyTree&&this.FixupFirstLefts2(outrec,outrec2)):(outrec2.IsHole=outrec.IsHole,outrec2.FirstLeft=outrec.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(outrec,outrec2)),op2=op}op2=op2.Next}op=op.Next}while(op!==outrec.Pts)}},ClipperLib.Clipper.Area=function(poly){if(!Array.isArray(poly))return 0;var cnt=poly.length;if(cnt<3)return 0;for(var a=0,i=0,j=cnt-1;i<cnt;++i)a+=(poly[j].X+poly[i].X)*(poly[j].Y-poly[i].Y),j=i;return.5*-a},ClipperLib.Clipper.prototype.Area=function(op){var opFirst=op;if(null===op)return 0;var a=0;do{a+=(op.Prev.Pt.X+op.Pt.X)*(op.Prev.Pt.Y-op.Pt.Y),op=op.Next}while(op!==opFirst);return.5*a},ClipperLib.Clipper.prototype.Area$1=function(outRec){return this.Area(outRec.Pts)},ClipperLib.Clipper.SimplifyPolygon=function(poly,fillType){var result=new Array,c=new ClipperLib.Clipper(0);return c.StrictlySimple=!0,c.AddPath(poly,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,result,fillType,fillType),result},ClipperLib.Clipper.SimplifyPolygons=function(polys,fillType){void 0===fillType&&(fillType=ClipperLib.PolyFillType.pftEvenOdd);var result=new Array,c=new ClipperLib.Clipper(0);return c.StrictlySimple=!0,c.AddPaths(polys,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,result,fillType,fillType),result},ClipperLib.Clipper.DistanceSqrd=function(pt1,pt2){var dx=pt1.X-pt2.X,dy=pt1.Y-pt2.Y;return dx*dx+dy*dy},ClipperLib.Clipper.DistanceFromLineSqrd=function(pt,ln1,ln2){var A=ln1.Y-ln2.Y,B=ln2.X-ln1.X,C=A*ln1.X+B*ln1.Y;return(C=A*pt.X+B*pt.Y-C)*C/(A*A+B*B)},ClipperLib.Clipper.SlopesNearCollinear=function(pt1,pt2,pt3,distSqrd){return Math.abs(pt1.X-pt2.X)>Math.abs(pt1.Y-pt2.Y)?pt1.X>pt2.X==pt1.X<pt3.X?ClipperLib.Clipper.DistanceFromLineSqrd(pt1,pt2,pt3)<distSqrd:pt2.X>pt1.X==pt2.X<pt3.X?ClipperLib.Clipper.DistanceFromLineSqrd(pt2,pt1,pt3)<distSqrd:ClipperLib.Clipper.DistanceFromLineSqrd(pt3,pt1,pt2)<distSqrd:pt1.Y>pt2.Y==pt1.Y<pt3.Y?ClipperLib.Clipper.DistanceFromLineSqrd(pt1,pt2,pt3)<distSqrd:pt2.Y>pt1.Y==pt2.Y<pt3.Y?ClipperLib.Clipper.DistanceFromLineSqrd(pt2,pt1,pt3)<distSqrd:ClipperLib.Clipper.DistanceFromLineSqrd(pt3,pt1,pt2)<distSqrd},ClipperLib.Clipper.PointsAreClose=function(pt1,pt2,distSqrd){var dx=pt1.X-pt2.X,dy=pt1.Y-pt2.Y;return dx*dx+dy*dy<=distSqrd},ClipperLib.Clipper.ExcludeOp=function(op){var result=op.Prev;return result.Next=op.Next,op.Next.Prev=result,result.Idx=0,result},ClipperLib.Clipper.CleanPolygon=function(path,distance){void 0===distance&&(distance=1.415);var cnt=path.length;if(0===cnt)return new Array;for(var outPts=new Array(cnt),i=0;i<cnt;++i)outPts[i]=new ClipperLib.OutPt;for(i=0;i<cnt;++i)outPts[i].Pt=path[i],outPts[i].Next=outPts[(i+1)%cnt],outPts[i].Next.Prev=outPts[i],outPts[i].Idx=0;for(var distSqrd=distance*distance,op=outPts[0];0===op.Idx&&op.Next!==op.Prev;)ClipperLib.Clipper.PointsAreClose(op.Pt,op.Prev.Pt,distSqrd)?(op=ClipperLib.Clipper.ExcludeOp(op),cnt--):ClipperLib.Clipper.PointsAreClose(op.Prev.Pt,op.Next.Pt,distSqrd)?(ClipperLib.Clipper.ExcludeOp(op.Next),op=ClipperLib.Clipper.ExcludeOp(op),cnt-=2):ClipperLib.Clipper.SlopesNearCollinear(op.Prev.Pt,op.Pt,op.Next.Pt,distSqrd)?(op=ClipperLib.Clipper.ExcludeOp(op),cnt--):(op.Idx=1,op=op.Next);cnt<3&&(cnt=0);var result=new Array(cnt);for(i=0;i<cnt;++i)result[i]=new ClipperLib.IntPoint1(op.Pt),op=op.Next;return outPts=null,result},ClipperLib.Clipper.CleanPolygons=function(polys,distance){for(var result=new Array(polys.length),i=0,ilen=polys.length;i<ilen;i++)result[i]=ClipperLib.Clipper.CleanPolygon(polys[i],distance);return result},ClipperLib.Clipper.Minkowski=function(pattern,path,IsSum,IsClosed){var delta=IsClosed?1:0,polyCnt=pattern.length,pathCnt=path.length,result=new Array;if(IsSum)for(var i=0;i<pathCnt;i++){for(var p=new Array(polyCnt),j=0,jlen=pattern.length,ip=pattern[j];j<jlen;ip=pattern[++j])p[j]=new ClipperLib.IntPoint2(path[i].X+ip.X,path[i].Y+ip.Y);result.push(p)}else for(i=0;i<pathCnt;i++){for(p=new Array(polyCnt),j=0,jlen=pattern.length,ip=pattern[j];j<jlen;ip=pattern[++j])p[j]=new ClipperLib.IntPoint2(path[i].X-ip.X,path[i].Y-ip.Y);result.push(p)}var quads=new Array;for(i=0;i<pathCnt-1+delta;i++)for(j=0;j<polyCnt;j++){var quad=new Array;quad.push(result[i%pathCnt][j%polyCnt]),quad.push(result[(i+1)%pathCnt][j%polyCnt]),quad.push(result[(i+1)%pathCnt][(j+1)%polyCnt]),quad.push(result[i%pathCnt][(j+1)%polyCnt]),ClipperLib.Clipper.Orientation(quad)||quad.reverse(),quads.push(quad)}return quads},ClipperLib.Clipper.MinkowskiSum=function(pattern,path_or_paths,pathIsClosed){if(path_or_paths[0]instanceof Array){paths=path_or_paths;for(var solution=new ClipperLib.Paths,i=(c=new ClipperLib.Clipper,0);i<paths.length;++i){var tmp=ClipperLib.Clipper.Minkowski(pattern,paths[i],!0,pathIsClosed);c.AddPaths(tmp,ClipperLib.PolyType.ptSubject,!0),pathIsClosed&&(path=ClipperLib.Clipper.TranslatePath(paths[i],pattern[0]),c.AddPath(path,ClipperLib.PolyType.ptClip,!0))}return c.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),solution}var c,path=path_or_paths,paths=ClipperLib.Clipper.Minkowski(pattern,path,!0,pathIsClosed);return(c=new ClipperLib.Clipper).AddPaths(paths,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,paths,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),paths},ClipperLib.Clipper.TranslatePath=function(path,delta){for(var outPath=new ClipperLib.Path,i=0;i<path.length;i++)outPath.push(new ClipperLib.IntPoint2(path[i].X+delta.X,path[i].Y+delta.Y));return outPath},ClipperLib.Clipper.MinkowskiDiff=function(poly1,poly2){var paths=ClipperLib.Clipper.Minkowski(poly1,poly2,!1,!0),c=new ClipperLib.Clipper;return c.AddPaths(paths,ClipperLib.PolyType.ptSubject,!0),c.Execute(ClipperLib.ClipType.ctUnion,paths,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero),paths},ClipperLib.Clipper.PolyTreeToPaths=function(polytree){var result=new Array;return ClipperLib.Clipper.AddPolyNodeToPaths(polytree,ClipperLib.Clipper.NodeType.ntAny,result),result},ClipperLib.Clipper.AddPolyNodeToPaths=function(polynode,nt,paths){var match=!0;switch(nt){case ClipperLib.Clipper.NodeType.ntOpen:return;case ClipperLib.Clipper.NodeType.ntClosed:match=!polynode.IsOpen}polynode.m_polygon.length>0&&match&&paths.push(polynode.m_polygon);for(var $i3=0,$t3=polynode.Childs(),$l3=$t3.length,pn=$t3[$i3];$i3<$l3;pn=$t3[++$i3])ClipperLib.Clipper.AddPolyNodeToPaths(pn,nt,paths)},ClipperLib.Clipper.OpenPathsFromPolyTree=function(polytree){for(var result=new ClipperLib.Paths,i=0,ilen=polytree.ChildCount();i<ilen;i++)polytree.Childs()[i].IsOpen&&result.push(polytree.Childs()[i].m_polygon);return result},ClipperLib.Clipper.ClosedPathsFromPolyTree=function(polytree){var result=new ClipperLib.Paths;return ClipperLib.Clipper.AddPolyNodeToPaths(polytree,ClipperLib.Clipper.NodeType.ntClosed,result),result},Inherit(ClipperLib.Clipper,ClipperLib.ClipperBase),ClipperLib.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},ClipperLib.ClipperOffset=function(miterLimit,arcTolerance){void 0===miterLimit&&(miterLimit=2),void 0===arcTolerance&&(arcTolerance=ClipperLib.ClipperOffset.def_arc_tolerance),this.m_destPolys=new ClipperLib.Paths,this.m_srcPoly=new ClipperLib.Path,this.m_destPoly=new ClipperLib.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 ClipperLib.IntPoint0,this.m_polyNodes=new ClipperLib.PolyNode,this.MiterLimit=miterLimit,this.ArcTolerance=arcTolerance,this.m_lowest.X=-1},ClipperLib.ClipperOffset.two_pi=6.28318530717959,ClipperLib.ClipperOffset.def_arc_tolerance=.25,ClipperLib.ClipperOffset.prototype.Clear=function(){ClipperLib.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},ClipperLib.ClipperOffset.Round=ClipperLib.Clipper.Round,ClipperLib.ClipperOffset.prototype.AddPath=function(path,joinType,endType){var highI=path.length-1;if(!(highI<0)){var newNode=new ClipperLib.PolyNode;if(newNode.m_jointype=joinType,newNode.m_endtype=endType,endType===ClipperLib.EndType.etClosedLine||endType===ClipperLib.EndType.etClosedPolygon)for(;highI>0&&ClipperLib.IntPoint.op_Equality(path[0],path[highI]);)highI--;newNode.m_polygon.push(path[0]);for(var j=0,k=0,i=1;i<=highI;i++)ClipperLib.IntPoint.op_Inequality(newNode.m_polygon[j],path[i])&&(j++,newNode.m_polygon.push(path[i]),(path[i].Y>newNode.m_polygon[k].Y||path[i].Y===newNode.m_polygon[k].Y&&path[i].X<newNode.m_polygon[k].X)&&(k=j));if(!(endType===ClipperLib.EndType.etClosedPolygon&&j<2)&&(this.m_polyNodes.AddChild(newNode),endType===ClipperLib.EndType.etClosedPolygon))if(this.m_lowest.X<0)this.m_lowest=new ClipperLib.IntPoint2(this.m_polyNodes.ChildCount()-1,k);else{var ip=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(newNode.m_polygon[k].Y>ip.Y||newNode.m_polygon[k].Y===ip.Y&&newNode.m_polygon[k].X<ip.X)&&(this.m_lowest=new ClipperLib.IntPoint2(this.m_polyNodes.ChildCount()-1,k))}}},ClipperLib.ClipperOffset.prototype.AddPaths=function(paths,joinType,endType){for(var i=0,ilen=paths.length;i<ilen;i++)this.AddPath(paths[i],joinType,endType)},ClipperLib.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!ClipperLib.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var i=0;i<this.m_polyNodes.ChildCount();i++)((node=this.m_polyNodes.Childs()[i]).m_endtype===ClipperLib.EndType.etClosedPolygon||node.m_endtype===ClipperLib.EndType.etClosedLine&&ClipperLib.Clipper.Orientation(node.m_polygon))&&node.m_polygon.reverse();else for(i=0;i<this.m_polyNodes.ChildCount();i++){var node;(node=this.m_polyNodes.Childs()[i]).m_endtype!==ClipperLib.EndType.etClosedLine||ClipperLib.Clipper.Orientation(node.m_polygon)||node.m_polygon.reverse()}},ClipperLib.ClipperOffset.GetUnitNormal=function(pt1,pt2){var dx=pt2.X-pt1.X,dy=pt2.Y-pt1.Y;if(0===dx&&0===dy)return new ClipperLib.DoublePoint2(0,0);var f=1/Math.sqrt(dx*dx+dy*dy);return dx*=f,dy*=f,new ClipperLib.DoublePoint2(dy,-dx)},ClipperLib.ClipperOffset.prototype.DoOffset=function(delta){if(this.m_destPolys=new Array,this.m_delta=delta,ClipperLib.ClipperBase.near_zero(delta))for(var i=0;i<this.m_polyNodes.ChildCount();i++)(node=this.m_polyNodes.Childs()[i]).m_endtype===ClipperLib.EndType.etClosedPolygon&&this.m_destPolys.push(node.m_polygon);else{var y;this.MiterLimit>2?this.m_miterLim=2/(this.MiterLimit*this.MiterLimit):this.m_miterLim=.5,y=this.ArcTolerance<=0?ClipperLib.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(delta)*ClipperLib.ClipperOffset.def_arc_tolerance?Math.abs(delta)*ClipperLib.ClipperOffset.def_arc_tolerance:this.ArcTolerance;var steps=3.14159265358979/Math.acos(1-y/Math.abs(delta));for(this.m_sin=Math.sin(ClipperLib.ClipperOffset.two_pi/steps),this.m_cos=Math.cos(ClipperLib.ClipperOffset.two_pi/steps),this.m_StepsPerRad=steps/ClipperLib.ClipperOffset.two_pi,delta<0&&(this.m_sin=-this.m_sin),i=0;i<this.m_polyNodes.ChildCount();i++){var node=this.m_polyNodes.Childs()[i];this.m_srcPoly=node.m_polygon;var len=this.m_srcPoly.length;if(!(0===len||delta<=0&&(len<3||node.m_endtype!==ClipperLib.EndType.etClosedPolygon)))if(this.m_destPoly=new Array,1!==len){for(this.m_normals.length=0,j=0;j<len-1;j++)this.m_normals.push(ClipperLib.ClipperOffset.GetUnitNormal(this.m_srcPoly[j],this.m_srcPoly[j+1]));if(node.m_endtype===ClipperLib.EndType.etClosedLine||node.m_endtype===ClipperLib.EndType.etClosedPolygon?this.m_normals.push(ClipperLib.ClipperOffset.GetUnitNormal(this.m_srcPoly[len-1],this.m_srcPoly[0])):this.m_normals.push(new ClipperLib.DoublePoint1(this.m_normals[len-2])),node.m_endtype===ClipperLib.EndType.etClosedPolygon){var k=len-1;for(j=0;j<len;j++)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(node.m_endtype===ClipperLib.EndType.etClosedLine){for(k=len-1,j=0;j<len;j++)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=new Array;var n=this.m_normals[len-1];for(j=len-1;j>0;j--)this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j-1].X,-this.m_normals[j-1].Y);for(this.m_normals[0]=new ClipperLib.DoublePoint2(-n.X,-n.Y),k=0,j=len-1;j>=0;j--)k=this.OffsetPoint(j,k,node.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{var pt1;for(k=0,j=1;j<len-1;++j)k=this.OffsetPoint(j,k,node.m_jointype);for(node.m_endtype===ClipperLib.EndType.etOpenButt?(j=len-1,pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*delta)),this.m_destPoly.push(pt1),pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X-this.m_normals[j].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y-this.m_normals[j].Y*delta)),this.m_destPoly.push(pt1)):(j=len-1,k=len-2,this.m_sinA=0,this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j].X,-this.m_normals[j].Y),node.m_endtype===ClipperLib.EndType.etOpenSquare?this.DoSquare(j,k):this.DoRound(j,k)),j=len-1;j>0;j--)this.m_normals[j]=new ClipperLib.DoublePoint2(-this.m_normals[j-1].X,-this.m_normals[j-1].Y);for(this.m_normals[0]=new ClipperLib.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),j=(k=len-1)-1;j>0;--j)k=this.OffsetPoint(j,k,node.m_jointype);node.m_endtype===ClipperLib.EndType.etOpenButt?(pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*delta)),this.m_destPoly.push(pt1),pt1=new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*delta)),this.m_destPoly.push(pt1)):(k=1,this.m_sinA=0,node.m_endtype===ClipperLib.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}else{if(node.m_jointype===ClipperLib.JoinType.jtRound)for(var X=1,Y=0,j=1;j<=steps;j++){this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+Y*delta)));var X2=X;X=X*this.m_cos-this.m_sin*Y,Y=X2*this.m_sin+Y*this.m_cos}else{X=-1,Y=-1;for(var j=0;j<4;++j)this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].X+X*delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[0].Y+Y*delta))),X<0?X=1:Y<0?Y=1:X=-1}this.m_destPolys.push(this.m_destPoly)}}}},ClipperLib.ClipperOffset.prototype.Execute=function(){var a=arguments;if(a[0]instanceof ClipperLib.PolyTree)if(delta=a[1],(solution=a[0]).Clear(),this.FixOrientations(),this.DoOffset(delta),(clpr=new ClipperLib.Clipper(0)).AddPaths(this.m_destPolys,ClipperLib.PolyType.ptSubject,!0),delta>0)clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftPositive,ClipperLib.PolyFillType.pftPositive);else if(r=ClipperLib.Clipper.GetBounds(this.m_destPolys),(outer=new ClipperLib.Path).push(new ClipperLib.IntPoint2(r.left-10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.top-10)),outer.push(new ClipperLib.IntPoint2(r.left-10,r.top-10)),clpr.AddPath(outer,ClipperLib.PolyType.ptSubject,!0),clpr.ReverseSolution=!0,clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNegative,ClipperLib.PolyFillType.pftNegative),1===solution.ChildCount()&&solution.Childs()[0].ChildCount()>0){var outerNode=solution.Childs()[0];solution.Childs()[0]=outerNode.Childs()[0],solution.Childs()[0].m_Parent=solution;for(var i=1;i<outerNode.ChildCount();i++)solution.AddChild(outerNode.Childs()[i])}else solution.Clear();else{var clpr,solution=a[0],delta=a[1];if(ClipperLib.Clear(solution),this.FixOrientations(),this.DoOffset(delta),(clpr=new ClipperLib.Clipper(0)).AddPaths(this.m_destPolys,ClipperLib.PolyType.ptSubject,!0),delta>0)clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftPositive,ClipperLib.PolyFillType.pftPositive);else{var outer,r=ClipperLib.Clipper.GetBounds(this.m_destPolys);(outer=new ClipperLib.Path).push(new ClipperLib.IntPoint2(r.left-10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.bottom+10)),outer.push(new ClipperLib.IntPoint2(r.right+10,r.top-10)),outer.push(new ClipperLib.IntPoint2(r.left-10,r.top-10)),clpr.AddPath(outer,ClipperLib.PolyType.ptSubject,!0),clpr.ReverseSolution=!0,clpr.Execute(ClipperLib.ClipType.ctUnion,solution,ClipperLib.PolyFillType.pftNegative,ClipperLib.PolyFillType.pftNegative),solution.length>0&&solution.splice(0,1)}}},ClipperLib.ClipperOffset.prototype.OffsetPoint=function(j,k,jointype){if(this.m_sinA=this.m_normals[k].X*this.m_normals[j].Y-this.m_normals[j].X*this.m_normals[k].Y,Math.abs(this.m_sinA*this.m_delta)<1){if(this.m_normals[k].X*this.m_normals[j].X+this.m_normals[j].Y*this.m_normals[k].Y>0)return this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[k].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[k].Y*this.m_delta))),k}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 ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[k].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[k].Y*this.m_delta))),this.m_destPoly.push(new ClipperLib.IntPoint1(this.m_srcPoly[j])),this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*this.m_delta)));else switch(jointype){case ClipperLib.JoinType.jtMiter:var r=this.m_normals[j].X*this.m_normals[k].X+this.m_normals[j].Y*this.m_normals[k].Y+1;r>=this.m_miterLim?this.DoMiter(j,k,r):this.DoSquare(j,k);break;case ClipperLib.JoinType.jtSquare:this.DoSquare(j,k);break;case ClipperLib.JoinType.jtRound:this.DoRound(j,k)}return k=j},ClipperLib.ClipperOffset.prototype.DoSquare=function(j,k){var dx=Math.tan(Math.atan2(this.m_sinA,this.m_normals[k].X*this.m_normals[j].X+this.m_normals[k].Y*this.m_normals[j].Y)/4);this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_delta*(this.m_normals[k].X-this.m_normals[k].Y*dx)),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_delta*(this.m_normals[k].Y+this.m_normals[k].X*dx)))),this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_delta*(this.m_normals[j].X+this.m_normals[j].Y*dx)),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_delta*(this.m_normals[j].Y-this.m_normals[j].X*dx))))},ClipperLib.ClipperOffset.prototype.DoMiter=function(j,k,r){var q=this.m_delta/r;this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+(this.m_normals[k].X+this.m_normals[j].X)*q),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+(this.m_normals[k].Y+this.m_normals[j].Y)*q)))},ClipperLib.ClipperOffset.prototype.DoRound=function(j,k){for(var X2,a=Math.atan2(this.m_sinA,this.m_normals[k].X*this.m_normals[j].X+this.m_normals[k].Y*this.m_normals[j].Y),steps=Math.max(ClipperLib.Cast_Int32(ClipperLib.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(a))),1),X=this.m_normals[k].X,Y=this.m_normals[k].Y,i=0;i<steps;++i)this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+Y*this.m_delta))),X2=X,X=X*this.m_cos-this.m_sin*Y,Y=X2*this.m_sin+Y*this.m_cos;this.m_destPoly.push(new ClipperLib.IntPoint2(ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].X+this.m_normals[j].X*this.m_delta),ClipperLib.ClipperOffset.Round(this.m_srcPoly[j].Y+this.m_normals[j].Y*this.m_delta)))},ClipperLib.Error=function(message){try{throw new Error(message)}catch(err){alert(err.message)}},ClipperLib.JS={},ClipperLib.JS.AreaOfPolygon=function(poly,scale){return scale||(scale=1),ClipperLib.Clipper.Area(poly)/(scale*scale)},ClipperLib.JS.AreaOfPolygons=function(poly,scale){scale||(scale=1);for(var area=0,i=0;i<poly.length;i++)area+=ClipperLib.Clipper.Area(poly[i]);return area/(scale*scale)},ClipperLib.JS.BoundsOfPath=function(path,scale){return ClipperLib.JS.BoundsOfPaths([path],scale)},ClipperLib.JS.BoundsOfPaths=function(paths,scale){scale||(scale=1);var bounds=ClipperLib.Clipper.GetBounds(paths);return bounds.left/=scale,bounds.bottom/=scale,bounds.right/=scale,bounds.top/=scale,bounds},ClipperLib.JS.Clean=function(polygon,delta){if(!(polygon instanceof Array))return[];var isPolygons=polygon[0]instanceof Array;if(polygon=ClipperLib.JS.Clone(polygon),"number"!=typeof delta||null===delta)return ClipperLib.Error("Delta is not a number in Clean()."),polygon;if(0===polygon.length||1===polygon.length&&0===polygon[0].length||delta<0)return polygon;isPolygons||(polygon=[polygon]);for(var len,poly,result,d,p,j,i,k_length=polygon.length,results=[],k=0;k<k_length;k++)if(0!==(len=(poly=polygon[k]).length))if(len<3)result=poly,results.push(result);else{for(result=poly,d=delta*delta,p=poly[0],j=1,i=1;i<len;i++)(poly[i].X-p.X)*(poly[i].X-p.X)+(poly[i].Y-p.Y)*(poly[i].Y-p.Y)<=d||(result[j]=poly[i],p=poly[i],j++);p=poly[j-1],(poly[0].X-p.X)*(poly[0].X-p.X)+(poly[0].Y-p.Y)*(poly[0].Y-p.Y)<=d&&j--,j<len&&result.splice(j,len-j),result.length&&results.push(result)}return!isPolygons&&results.length?results=results[0]:isPolygons||0!==results.length?isPolygons&&0===results.length&&(results=[[]]):results=[],results},ClipperLib.JS.Clone=function(polygon){if(!(polygon instanceof Array))return[];if(0===polygon.length)return[];if(1===polygon.length&&0===polygon[0].length)return[[]];var isPolygons=polygon[0]instanceof Array;isPolygons||(polygon=[polygon]);var plen,i,j,result,len=polygon.length,results=new Array(len);for(i=0;i<len;i++){for(plen=polygon[i].length,result=new Array(plen),j=0;j<plen;j++)result[j]={X:polygon[i][j].X,Y:polygon[i][j].Y};results[i]=result}return isPolygons||(results=results[0]),results},ClipperLib.JS.Lighten=function(polygon,tolerance){if(!(polygon instanceof Array))return[];if("number"!=typeof tolerance||null===tolerance)return ClipperLib.Error("Tolerance is not a number in Lighten()."),ClipperLib.JS.Clone(polygon);if(0===polygon.length||1===polygon.length&&0===polygon[0].length||tolerance<0)return ClipperLib.JS.Clone(polygon);var i,j,poly,k,poly2,plen,A,B,P,rem,addlast,bxax,byay,l,ax,ay,isPolygons=polygon[0]instanceof Array;isPolygons||(polygon=[polygon]);var len=polygon.length,toleranceSq=tolerance*tolerance,results=[];for(i=0;i<len;i++)if(0!==(plen=(poly=polygon[i]).length)){for(k=0;k<1e6;k++){for(poly2=[],poly[(plen=poly.length)-1].X!==poly[0].X||poly[plen-1].Y!==poly[0].Y?(addlast=1,poly.push({X:poly[0].X,Y:poly[0].Y}),plen=poly.length):addlast=0,rem=[],j=0;j<plen-2;j++)A=poly[j],P=poly[j+1],B=poly[j+2],ax=A.X,ay=A.Y,bxax=B.X-ax,byay=B.Y-ay,0===bxax&&0===byay||((l=((P.X-ax)*bxax+(P.Y-ay)*byay)/(bxax*bxax+byay*byay))>1?(ax=B.X,ay=B.Y):l>0&&(ax+=bxax*l,ay+=byay*l)),(bxax=P.X-ax)*bxax+(byay=P.Y-ay)*byay<=toleranceSq&&(rem[j+1]=1,j++);for(poly2.push({X:poly[0].X,Y:poly[0].Y}),j=1;j<plen-1;j++)rem[j]||poly2.push({X:poly[j].X,Y:poly[j].Y});if(poly2.push({X:poly[plen-1].X,Y:poly[plen-1].Y}),addlast&&poly.pop(),!rem.length)break;poly=poly2}poly2[(plen=poly2.length)-1].X===poly2[0].X&&poly2[plen-1].Y===poly2[0].Y&&poly2.pop(),poly2.length>2&&results.push(poly2)}return isPolygons||(results=results[0]),void 0===results&&(results=[]),results},ClipperLib.JS.PerimeterOfPath=function(path,closed,scale){if(void 0===path)return 0;var p1,p2,sqrt=Math.sqrt,perimeter=0,p1x=0,p1y=0,p2x=0,p2y=0,j=path.length;if(j<2)return 0;for(closed&&(path[j]=path[0],j++);--j;)p1x=(p1=path[j]).X,p1y=p1.Y,perimeter+=sqrt((p1x-(p2x=(p2=path[j-1]).X))*(p1x-p2x)+(p1y-(p2y=p2.Y))*(p1y-p2y));return closed&&path.pop(),perimeter/scale},ClipperLib.JS.PerimeterOfPaths=function(paths,closed,scale){scale||(scale=1);for(var perimeter=0,i=0;i<paths.length;i++)perimeter+=ClipperLib.JS.PerimeterOfPath(paths[i],closed,scale);return perimeter},ClipperLib.JS.ScaleDownPath=function(path,scale){var i,p;for(scale||(scale=1),i=path.length;i--;)(p=path[i]).X=p.X/scale,p.Y=p.Y/scale},ClipperLib.JS.ScaleDownPaths=function(paths,scale){var i,j,p;for(scale||(scale=1),i=paths.length;i--;)for(j=paths[i].length;j--;)(p=paths[i][j]).X=p.X/scale,p.Y=p.Y/scale},ClipperLib.JS.ScaleUpPath=function(path,scale){var i,p,round=Math.round;for(scale||(scale=1),i=path.length;i--;)(p=path[i]).X=round(p.X*scale),p.Y=round(p.Y*scale)},ClipperLib.JS.ScaleUpPaths=function(paths,scale){var i,j,p,round=Math.round;for(scale||(scale=1),i=paths.length;i--;)for(j=paths[i].length;j--;)(p=paths[i][j]).X=round(p.X*scale),p.Y=round(p.Y*scale)},ClipperLib.ExPolygons=function(){return[]},ClipperLib.ExPolygon=function(){this.outer=null,this.holes=null},ClipperLib.JS.AddOuterPolyNodeToExPolygons=function(polynode,expolygons){var ep=new ClipperLib.ExPolygon;ep.outer=polynode.Contour();var node,n,i,j,childs2,jlen,childs=polynode.Childs(),ilen=childs.length;for(ep.holes=new Array(ilen),i=0;i<ilen;i++)for(node=childs[i],ep.holes[i]=node.Contour(),j=0,jlen=(childs2=node.Childs()).length;j<jlen;j++)n=childs2[j],ClipperLib.JS.AddOuterPolyNodeToExPolygons(n,expolygons);expolygons.push(ep)},ClipperLib.JS.ExPolygonsToPaths=function(expolygons){var a,i,alen,ilen,paths=new ClipperLib.Paths;for(a=0,alen=expolygons.length;a<alen;a++)for(paths.push(expolygons[a].outer),i=0,ilen=expolygons[a].holes.length;i<ilen;i++)paths.push(expolygons[a].holes[i]);return paths},ClipperLib.JS.PolyTreeToExPolygons=function(polytree){var node,i,childs,ilen,expolygons=new ClipperLib.ExPolygons;for(i=0,ilen=(childs=polytree.Childs()).length;i<ilen;i++)node=childs[i],ClipperLib.JS.AddOuterPolyNodeToExPolygons(node,expolygons);return expolygons}}();var ClipperLib=getDefaultExportFromCjs(clipper.exports);function shapeclip(){function toclipformat(pts){let tm=pts.map((e=>({X:Math.round(1e4*e.x),Y:Math.round(1e4*e.y)})));return ensureOrientation(tm)}function fromclipformat(pts){return pts.map((e=>({x:e.X/1e4,y:e.Y/1e4})))}const ensureOrientation=poly=>ClipperLib.Clipper.Orientation(poly)?poly:poly.slice().reverse();function orientation(pt){if(!pt.length)return 0;let area=0;const n=pt.length;for(let i=0;i<n;i++){const current=pt[i],next=pt[(i+1)%n];area+=current.X*next.Y-next.X*current.Y}return area>0?1:area<0?-1:0}const _inflate=(pt,delta,cut=!1)=>{const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.AddPath(pt,ClipperLib.JoinType.jtMiter,cut||2==pt.length?ClipperLib.EndType.etOpenButt:ClipperLib.EndType.etClosedPolygon);const solution=new ClipperLib.Paths;return co.Execute(solution,delta),solution};return{offset(shape,delta,full=!1){const co=new ClipperLib.ClipperOffset;co.MiterLimit=4,co.ArcTolerance=.25;const DD=1e4*Math.abs(delta),pshape=toclipformat(shape.pt);co.AddPath(pshape,ClipperLib.JoinType.jtMiter,ClipperLib.EndType.etOpenButt);const solution=new ClipperLib.Paths;co.Execute(solution,DD);let tm=fromclipformat(solution[0]);return full?getshape().frompt(tm):getshape().frompt(getptsoffset(shape.pt,tm,delta))},inflate(shape,delta=2,mantainorder=!1){let pshape=toclipformat(shape.pt),tm=_inflate(pshape,1e4*delta);let p2=getshape().frompt(fromclipformat(tm[0]));if(mantainorder&&shape.pt.length==p2.pt.length){p2.orient!=shape.orient&&p2.reverse();let p3=function alignByMinDist(sag1,sag2){const N=sag1.length;let bestOffset=0,minSum=1/0;for(let k=0;k<N;k++){let sum=0;for(let i=0;i<N;i++){const p=sag1[i],q=sag2[(i+k)%N],dx=p.x-q.x,dy=p.y-q.y;sum+=dx*dx+dy*dy}sum<minSum&&(minSum=sum,bestOffset=k)}return[...sag2.slice(bestOffset),...sag2.slice(0,bestOffset)]}(shape.pt,p2.pt);p2.frompt(p3)}return p2},intersecasplitter(areabase,forma1){const clipper=new ClipperLib.Clipper,pt1=[toclipformat(forma1.pt)],pt2=[toclipformat(areabase.pt)];clipper.AddPaths(pt1,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(pt2,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;let res;if(clipper.Execute(ClipperLib.ClipType.ctIntersection,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)&&solution.length>0){const path=solution[0];if(1===orientation(path)){res=getshape().frompt(fromclipformat(path)),res.orient!=forma1.orient&&res.reverse();for(let iu=0;iu<forma1.pt.length;iu++){let p2=forma1.pt[iu],id=res.pt.findIndex((p=>Math.abs(p.x-p2.x)<.01&&Math.abs(p.y-p2.y)<.01));if(id>0){id-=iu,0!=id&&res.selezionaprimo(id);break}}}}return res},offsetpts(pts,delta=.01){const DELTA=1e4*delta;let tm=_inflate(toclipformat(pts),DELTA);if(tm&&tm.length)return fromclipformat(tm[0])},areesplitter(shapept,clipspt,useInflatedClipping=!0){if(!Array.isArray(shapept)||shapept.length<3)return;if(!clipspt||0==clipspt.length)return[shapept];const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;let shape_in=useInflatedClipping?_inflate(toclipformat(shapept),-100):[toclipformat(shapept)],clips_in=useInflatedClipping?clipspt.flatMap((c=>_inflate(toclipformat(c),100))):clipspt.map((c=>toclipformat(c)));for(let s of shape_in)subj.push(s);for(let c of clips_in)clip.push(c);const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(!clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero))return;let res=[];for(let x of solution)if(useInflatedClipping){const restored=_inflate(x,100);for(const r of restored)1===orientation(r)&&res.push(fromclipformat(r))}else if(x.length>4&&1==orientation(x)){const cleaned=_inflate(x,-100);if(cleaned.length>0)for(let cc of cleaned){const restored=_inflate(cc,100);for(const rr of restored)1===orientation(rr)&&res.push(fromclipformat(rr))}}else 1==orientation(x)&&res.push(fromclipformat(x));return res},unisci(shapes,holes,cuts){const subj=new ClipperLib.Paths,clip=new ClipperLib.Paths;for(var hh of shapes){let h2=[toclipformat(hh.pt)];for(var h of h2)subj.push(h)}if(holes&&holes.length)for(var hh of holes){let h1=toclipformat(hh.pt);clip.push(h1)}if(cuts&&cuts.length)for(var hh of cuts){let h1=toclipformat(hh.pt),h2=_inflate(h1,1,!0);for(var h of h2)clip.push(h)}const clipper=new ClipperLib.Clipper;clipper.AddPaths(subj,ClipperLib.PolyType.ptSubject,!0),clipper.AddPaths(clip,ClipperLib.PolyType.ptClip,!0);const solution=new ClipperLib.Paths;if(clipper.Execute(ClipperLib.ClipType.ctDifference,solution,ClipperLib.PolyFillType.pftNonZero,ClipperLib.PolyFillType.pftNonZero)){let res=[],holes=[];for(var x of solution)if(1==orientation(x)){let yy=[x];for(var y of yy)res.push({shape:getshape().frompt(fromclipformat(y)),holes:[]})}else holes.push(getshape().frompt(fromclipformat(x)));for(var h of holes)for(var s of res)if(s.shape.pointinshape(h.pt[0])){s.holes.push(h);break}return res}return[]}}}class Vis2d{constructor(name,p1,p2){this.name=name,this.clear(p1,p2)}clear(p1,p2){return this.vec=[],this.xp1=p1||new Punto2(-10,-10),this.xp2=p2||new Punto2(100,100),this}randomcolor(transp="100%"){return`hsl(${Math.floor(360*Math.random())}, 50%, 40%,${transp})`}addpoint(p,id=-1,color=void 0,spessore=1){return this.vec.push({type:"point",p:p,id:id,color:color,spessore:spessore}),this}addline(l,id=-1,color=void 0,spessore=1){return this.vec.push({type:"line",l:l,id:id,color:color,spessore:spessore}),this}addrect(l,id=-1,color=void 0,spessore=1){return this.vec.push({type:"rect",l:l,id:id,color:color,spessore:spessore}),this}addrecta(l,id=-1,color=void 0){return this.vec.push({type:"recta",l:l,id:id,color:color,spessore:spessore}),this}addshape(s,color=void 0,spessore=1){return this.vec.push({type:"shape",s:s,color:color||this.randomcolor(),spessore:spessore}),this}addshapelin(s,color=void 0,spessore=1){return this.vec.push({type:"shapelin",s:s,color:color||this.randomcolor(),spessore:spessore}),this}addarea(s,color=void 0){return this.vec.push({type:"area",s:s,color:color||this.randomcolor()}),this}addoffset(x,y){return this.vec.push({type:"offset",x:x||0,y:y||0}),this}}function generatesegments(t1,t2,interna=!1,allbreak=!1){let t3=[];if(t1?.length>2){if(allbreak){let tm=[];for(let t of t1)tm.push({a:t.a,b:t.a}),t.a!=t.b&&tm.push({a:t.b,b:t.b});t1=tm}if(t1=t1.sort(((a,b)=>a.a-b.a)),t2?.length){let j=0;for(let i=1;i<t1.length;i++){const ε=1e-6;t2.find((e=>e>t1[i-1].b+ε&&e<t1[i].a-ε))&&(i-1>j&&(interna?t3.push({a:t1[j].b,b:t1[i-1].a}):t3.push({a:t1[j].a,b:t1[i-1].b})),j=i)}j<t1.length-1&&(interna?t3.push({a:t1[j].b,b:t1[t1.length-1].a}):t3.push({a:t1[j].a,b:t1[t1.length-1].b}))}else t3.push({a:t1[0].b,b:t1[t1.length-1].a})}return t3}function bordi(ff){function getbordo(b1,b2){let b=b1??b2??{s:0};return"number"==typeof b?{s:b}:"number"==typeof b?.s?b:{s:0}}let bt,bb,bl,br;return"a"==ff.tipo?bt=bb=bl=br=getbordo(ff.bordo,ff.bordo):(bt=getbordo(ff.bt,ff.bordo),bb=getbordo(ff.bb,ff.bordo),bl=getbordo(ff.bl,ff.bordo),br=getbordo(ff.br,ff.bordo)),{bt:bt,bb:bb,bl:bl,br:br}}function internalshape(ff,shape){let shape2,CLP=shapeclip(),{bt:bt,bb:bb,bl:bl,br:br}=bordi(ff);if(bt==br&&bb==br&&bl==br||"a"==ff.tipo)shape2=CLP.inflate(shape,-bt.s,!0);else{let n=shape.pt.length,ll=[];for(let i=0;i<n;i++){let ofs=0==i?bl.s:i==n-2?br.s:i==n-1?bb.s:bt.s;ll.push(shape.segment(i).offset(-ofs))}let pts=[];for(let i=0;i<n;i++){let j=(i+n-1)%n,p=ll[i].intersezione(ll[j]);p||(p=shape.pt[i]),pts.push(p)}shape2=getshape().frompt(pts)}return shape2}const tipi={i:"inclinato",a:"arco",d:"diagonali",s:"smussato",x:"normale"},priorita={v:"verticale",h:"orizzontale"},tagli={d:"diagonale",v:"verticale",h:"orizzontale"};function ordinabase(hh,dd,minvano,b1,b2){let d1=[];if(hh){for(var h of hh){let x=0;switch(h.tipo){case"d-":x=dd-h.p;break;case"p":x=dd*h.p/100;break;case"p-":x=dd*(100-h.p)/100;break;default:x=h.p}let sp=h.sps||0;if(sp&&"c"==h.align?x-=sp/2:sp&&"r"==h.align&&(x-=sp),x=Math.round(10*x)/10,x>b1&&x<dd-b2){let cuts=[];h.cuttings&&h.cuttings.forEach((c=>{cuts.push(c<0?dd+c:c)})),d1.push({id:h.id,x:x,sp:sp,cuts:cuts,des:h.des})}}d1.sort(((a,b)=>a.x-b.x))}let d2=[],p0=b1;for(let i=0;i<d1.length;i++){let d=d1[i];d.x>=p0+minvano&&d.x+d.sp<=dd-b2-minvano&&(d.min=p0+minvano,d.max=dd-b2-minvano,d2.length>0&&(d2[d2.length-1].max=d.x-minvano),d2.push(d),p0=d.x+d.sp)}let d3=[];d3.push({a:b1,b:b1});for(let d of d2)d3.push({a:d.x,b:d.x+d.sp});return d3.push({a:dd-b2,b:dd-b2}),{dati:d2,punti:d3}}const tipocut={d:"dist. positiva","d-":"dist. negativa",p:"perc. positiva","p-":"perc negativa"},tipoalign={l:"left",c:"center",r:"right"};function newcount(ff){return ff.countid++,ff.countid}function addtaglio(ff,dir,tipodim,dim,sps,des,align="c",cuts=[]){return{dir:dir,id:newcount(ff),tipo:tipocut[tipodim]?tipodim:"d",align:tipoalign[align]?align:"c",p:dim,sps:sps,des:des,cuttings:cuts||[]}}function pushlineare(ff,type,des,l0,l1,id=-1,shapecontorno=void 0,areas){let tm;if(id<0&&(id=newcount(ff)),"l"==type)Array.isArray(areas)&&areas.push([l0.p1,l0.p2]);else{let ptx=[l0.p1,l0.p2,l1.p2,l1.p1];Array.isArray(areas)&&areas.push(ptx);let s1=getshape().frompt(ptx);if(shapecontorno?.pt&&"x"!=ff.tipo&&(s1=shapeclip().intersecasplitter(shapecontorno,s1)),s1){let info=l0.infoquad(l1);info&&info.distanza&&(tm={id:id,type:type,des:des,shape:s1.pt,info:info},ff.dati.push(tm))}}return tm}function pushshape(ff,type,des,shape,info,id=-1){let tm;return id<0&&(id=newcount(ff)),info||(info={}),info={isshape:!0},shape?.pt&&(tm={id:id,type:type,des:des,shape:shape.pt,info:info},ff.dati.push(tm)),tm}function creabordi(ff,shape,shape2){let l1,n=shape.pt.length,draws=[];function addlineare(type,des,l0,l1){let tm=pushlineare(ff,type,des,l0,l1);tm?.shape&&draws.push({pt:tm.shape,type:type})}if("a"!=ff.tipo)for(let i=1;i<n-2;i++)addlineare("bt","sopra",shape.segment(i),shape2.segment(i));else{let p1=[...shape.pt].slice(1,-1),p2=[...shape2.pt].slice(1,-1).reverse(),sa=getshape().frompt([...p1,...p2]);pushshape(ff,"bt","sopra",sa,{isarco:!0}),draws.push({pt:sa.pt,type:"bs"})}switch(ff.taglio){case"h":{let p1=shape2.segment(n-1).intersezione(shape.segment(0)),p2=shape2.segment(n-1).intersezione(shape.segment(n-2));l1=new Linea2(p1,shape.pt[1]),addlineare("bl","sx",l1,shape2.segment(0)),l1=new Linea2(shape.pt[n-2],p2),addlineare("br","dx",l1,shape2.segment(n-2)),l1=new Linea2(p2,p1),addlineare("bb","sotto",shape.segment(n-1),l1);break}case"v":{let p1=shape2.segment(0).intersezione(shape.segment(n-1)),p2=shape2.segment(n-2).intersezione(shape.segment(n-1));l1=new Linea2(p1,shape2.pt[1]),addlineare("bl","sx",shape.segment(0),l1),l1=new Linea2(shape2.pt[n-2],p2),addlineare("br","sx",shape.segment(n-2),l1),l1=new Linea2(p2,p1),addlineare("bb","sotto",l1,shape2.segment(n-1));break}default:addlineare("bl","sx",shape.segment(0),shape2.segment(0)),addlineare("br","dx",shape.segment(n-2),shape2.segment(n-2)),addlineare("bb","sotto",shape.segment(n-1),shape2.segment(n-1))}return draws}var splitter=Object.freeze({__proto__:null,addhoriz:function addhoriz(ff,tipodim,dim,sps,des,align,cuts){let tm=addtaglio(ff,"h",tipodim,dim,sps,des,cuts,align);ff.horiz.push(tm)},addvert:function addvert(ff,tipodim,dim,sps,des,align,cuts){let tm=addtaglio(ff,"v",tipodim,dim,sps,des,align,cuts);ff.vert.push(tm)},bordi:bordi,calcoladivisioni:function calcoladivisioni(ff,shape,shape2){let draws=creabordi(ff,shape,shape2)||[],areas=[],{x:dx,y:dy,horiz:horiz,vert:vert,tipo:tipo,priority:priority,minvano:minvano,minvanox:minvanox,minvanoy:minvanoy}=ff,{bl:bl,br:br,bt:bt,bb:bb}=bordi(ff);minvanox=minvanox||minvano||50,minvanoy=minvanoy||minvano||50;let{dati:h1,punti:ph}=ordinabase(horiz,dy,minvanoy,bb.s,bt.s),{dati:v1,punti:pv}=ordinabase(vert,dx,minvanox,bl.s,br.s);function adddatilin(type,des,l0,l1,id){let tm=pushlineare(ff,type,des,l0,l1,id,shape2,areas);tm?.shape&&draws.push({pt:tm.shape,type:type})}function isinseg(segs,v){return!!segs.find((e=>e.a<=v&&e.b>=v))}for(var h of(v1.forEach(((v,i)=>{v.segs=generatesegments(ph,v.cuts,!0),v.segs.forEach(((s,j)=>{let l0=new Linea2({x:v.x,y:s.a},{x:v.x,y:s.b}),l1=new Linea2({x:v.x+v.sp,y:s.a},{x:v.x+v.sp,y:s.b});adddatilin(v.sp?"v":"l","vert",l0,l1,v.id)}))})),h1)){let cuts=[...h.cuts],pv1=[...pv];for(var v of v1)pv1.push({a:v.x,b:v.x+v.sp}),isinseg(v.segs,h.x+h.sp/2)&&cuts.push(v.x+v.sp/2);h.segs=generatesegments(pv1,cuts,!0,!0);for(let s of h.segs){let l0=new Linea2({x:s.a,y:h.x+h.sp},{x:s.b,y:h.x+h.sp}),l1=new Linea2({x:s.a,y:h.x},{x:s.b,y:h.x});adddatilin(h.sp?"h":"l","oriz",l0,l1,h.id)}}let res=shapeclip().areesplitter(shape2.pt,areas);for(let d of res){let s=getshape().frompt(d),{p1:p1,width:width,height:height,isrect:isrect}=s.dims(),ix=s.pt.findIndex((p=>Math.abs(p.x-p1.x)<.001&&Math.abs(p.y-p1.y)<.001));ix>0&&s.selezionaprimo(ix),ff.dati.push({id:-1,type:"a",des:"area",shape:isrect?null:s.pt,info:{isrect:isrect,p1:p1,width:width,height:height}}),draws.push({pt:s.pt,type:isrect?"a":"as"})}return{ff:ff,h1:h1,ph:ph,v1:v1,pv:pv,draws:draws,areas:areas}},creabordi:creabordi,create:function create(x,y,bordo,options){options||(options={});let{minvano:minvano,priority:priority,taglio:taglio,tipo:tipo,h1:h1,h2:h2,d1:d1,d2:d2,l1:l1,l2:l2,x1:x1,x2:x2,y1:y1,y2:y2}=options;minvano||(minvano=50);let ff={x:x||1e3,y:y||1e3,bordo:bordo||0,minvano:minvano||50,priority:priorita[priority]?priority:"v",taglio:tagli[taglio]?taglio:"d",tipo:tipi[tipo]?tipo:"x",h1:h1||y1||0,h2:h2||y2||0,l1:l1||d1||x1||0,l2:l2||d2||x2||0,vert:[],horiz:[],dati:[],countid:1e3};return delete options.x1,delete options.x2,delete options.d1,delete options.d2,delete options.y1,delete options.y2,ff={...options,...ff},ff},findid:function findid(ff,id){let f=ff.vert.find((e=>e.id==id));return f||(f=ff.horiz.find((e=>e.id==id))),{f:f}},generatesegments:generatesegments,internalshape:internalshape,makeshape:function makeshape(ff){let shape,{x:x,y:y,tipo:tipo,h1:h1,h2:h2,l1:l1,l2:l2}=ff;if(x>0&&y>0){let pts=[0,0];switch(tipo){case"i":pts.push(0,h1>0&&h1<y?y-h1:y),pts.push(x,h2>0&&h2<y&&h2!=h1?y-h2:y),pts.push(x,0),shape=getshape().fromvec(pts);break;case"a":if(h2=h2||h1||0,y-h1>=y-x/2&&y-h1<=y&&y-h2>=y-x/2&&y-h2<=y){let str=`0;0;a30;0;${y-h1};${x/2};${y};${x};${y-h2};${x};0`.replaceAll(",",".");shape=getshape().fromstr(str)}else pts.push(x,y,0,y),shape=getshape().fromvec(pts);break;case"s":case"d":l1=l1||0,l2=l2||0,l1&&l1<x&&h1>0&&h1<y?pts.push(0,y-h1,l1,y):pts.push(0,y),l2&&l2+l1<x&&h2>0&&h2<y?pts.push(x-l2,y,x,y-h2):0==l2&&l1>0&&l1<x&&h2>0&&h2<y?pts.push(x,y-h2):(l2=0,pts.push(x,y)),pts.push(x,0),shape=getshape().fromvec(pts);break;default:pts.push(0,y,x,y,x,0),shape=getshape().fromvec(pts)}}return ff.dati=[],{shape:shape,internalshape:internalshape(ff,shape)}},priorita:priorita,pushlineare:pushlineare,pushshape:pushshape,tagli:tagli,tipi:tipi,tipoalign:tipoalign,tipocut:tipocut});async function valutagrafica(amb,startmacro,rulespec,progetto,fnreload){let{getcolonne:getcolonne,muCalc:muCalc,muEval:muEval,tipifree:tipifree}=amb.muvalutatore;for(var x of(rulespec||(rulespec={}),["l","a","p"])){!amb.vari.var(x)&&startmacro.dims&&amb.vari.add(x,String(startmacro.dims[x].val||100))}let fnlist=new Set;const PARSGLOBAL=["sl","sa","sp","ul","ua","up","ax","ay","az","scx","scy","scz","scale"];let isfnreload=!1,oo=await muEval(amb,startmacro,startmacro.codice,{leveleval:0,checkheader:async op=>{let{variante:variante}=op;if(Array.isArray(startmacro.head)){let ff=startmacro.head.find((e=>e.cod==variante));isfnreload=!!ff}},grafica:async _op=>{let p2,cadv,iscad,des,fatti,{id:id,pars:pars,parametri:parametri,macro:macro,options:options,vari:vari}=_op,isheader=!!(macro&&macro.head&&macro.head.length),sv={l:amb.vari.var("l"),a:amb.vari.var("a"),p:amb.vari.var("p")};const varcad=["l","a","p","#d",...PARSGLOBAL];for(var x of varcad){let tm=amb.vari.dictionary[x];tm&&(sv[x]=tm)}async function _parsepars(x,head){let k,v,r9=/^\#(d|des|descrizione)\s*=\s*(.*)\s*$/im.exec(x);if(r9)k="#d",v=await amb.vari.valuta(r9[2]);else{let result=await vari.parametrokeyval(x);k=result.k,v=result.v}k&&!fatti[k]&&(fatti[k]=!0,varcad.includes(k)?"#d"==k?des=v:("string"==typeof v&&(v=muCalc(v)),["l","a","p"].includes(k)&&amb.vari.add(k,String(v)),cadv[k]=v,iscad=!0):"string"==typeof v?head&&tipifree.includes(head.t)?p2.push(`${k}=${v}`):p2.push(`${k}=${v.split(",")[0]}`):amb.vari.add(k,v))}if(p2=[],cadv={},iscad=!1,des="",fatti={},progetto&&progetto.keys&&progetto.keys[id]){let px=progetto.keys[id].pars;if(px)for(let t in px){let t1=amb.vari.dictionary[t];t1&&(sv[t]=t1),await _parsepars(`${t}=${px[t]}`)}}if(pars&&pars.length)for(const par of pars)await _parsepars(par);if(parametri&&parametri.length)for(const param of parametri)await _parsepars(param);if(macro&&macro.head&&macro.head.length){let tm=macro.head.filter((e=>!["g"].includes(e.t)));for(const h of tm)await _parsepars(h.cod,h)}let out={iscad:iscad,isheader:isheader,name:macro.name,des:des,leveleval:options.leveleval};isheader&&id&&(out.id=id),iscad&&(cadv.l?amb.vari.add("l",String(cadv.l)):cadv.l=muCalc(amb.vari.var("l")),cadv.a?amb.vari.add("a",String(cadv.a)):cadv.a=muCalc(amb.vari.var("a")),cadv.p?amb.vari.add("p",String(cadv.p)):cadv.p=muCalc(amb.vari.var("p")),out.cadv=cadv),await macro.impostaparametri(parametri,p2,!0);let ruleid=rulespec[id];if(id&&isheader&&ruleid&&ruleid.pars&&(out.pars=ruleid.pars,options.leveleval++,await macro.setparametri(ruleid.pars)),out.rows=await muEval(amb,macro,macro.codice,options),id&&isheader&&(out.spars=macro.getparametri()),iscad)for(var x in sv)amb.vari.dictionary[x]=sv[x];return out},parsefnpunto:async _op=>{let{dati:dati,vari:vari,id:id,output:output}=_op;dati=dati.trim();let q=dati.indexOf(" "),q2=dati.indexOf(",");q2>0&&q>0&&q2<q&&(q=q2);let fn,pp,pars={},p2={};for(var p of(q>1?(fn=dati.slice(1,q),pp=getcolonne(dati.slice(q+1))):(fn=dati.slice(1),pp=[]),fnlist.has(fn)||fnlist.add(fn),pp)){let{k:k,v:v}=await vari.parametrokeyval(p);k&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)&&v&&(pars[k]=v)}for(var l of["l","a","p"])pars[l]||(pars[l]=vari.var(l));let tm=Object.keys(pars);for(var l of PARSGLOBAL)tm.includes(l)&&(p2[l]=muCalc(pars[l]),delete pars[l]);output.push({t:"fn",fn:fn,id:id,pars:pars,p2:p2})}});return isfnreload&&"function"==typeof fnreload&&await fnreload(),{oo:oo,vari:amb.vari.dump(!0),fnlist:[...fnlist]}}function ismacro(row){return"object"==typeof row&&row?.name&&row.rows}function isfn(row){return"object"==typeof row&&"fn"==row?.t}function getnodebyid(id,nodocorrente){let res;return nodocorrente&&nodocorrente.rows&&function _getnode(rows){for(var x of rows){if(ismacro(x)){if(x.id==id)return void(res=x);x.rows&&_getnode(x.rows)}if(res)return}}(nodocorrente.rows),res}function getsubrules(nodocorrente){let res=[];return res.push({id:"",level:0,name:"home"}),function _xfiltrati(rr,level){if(rr.rows&&rr.rows.length)for(var x of rr.rows)ismacro(x)&&(x.id&&x.isheader?(res.push({id:x.id,name:x.name,des:x.des||"",spec:x.pars?1:0,level:level}),_xfiltrati(x,level+1)):_xfiltrati(x,level))}(nodocorrente,1),res}function getprojectkeys(project){return project.keys={},function _getkeys(node){if(node.rows&&node.rows.length)for(var x of node.rows)ismacro(x)&&(x.id&&x.isheader&&x.pars&&(project.keys[x.id]={name:x.name,des:x.des||"",pars:x.pars}),_getkeys(x))}(project),project}function getdumpmacro(nodo){let cl=[];return function _dumpnodo(node){if(node.rows&&node.rows.length)for(var x of node.rows)if(ismacro(x)){x.name;let c=[];if(x.iscad&&x.cadv)for(var k in x.cadv){let t=x.cadv[k];"number"==typeof t&&t&&c.push(`${k}=${t}`)}if(x.pars)for(var k in x.pars){let t=x.pars[k];c.push(`${k}=${t}`)}c.length&&cl.push(`--\x3e ${x.name} ${c.join(",")}`),_dumpnodo(x),c.length&&cl.push("<--")}else isfn(x)?cl.push(`FN: ${x.fn} ${JSON.stringify(x.pars)}`):"string"==typeof x&&x.length&&cl.push(x)}(nodo),cl.join("\n")}function clean(k,locase=!1){return locase?(k||"").trim().toLowerCase():(k||"").trim()}export{Linea2,Matrix3D,PIF,Punto2,splitter as SP,Vis2d,angle2vec,angle3point,clamp,clean,getdumpmacro,getnodebyid,getprojectkeys,getptsoffset,getshape,getsubrules,hash,isfn,ismacro,normal2,raccordabezier,shapeclip,valutagrafica};