clipper2-ts 2.0.1-13 → 2.0.1-15

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.
@@ -1,7 +1,7 @@
1
- var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};let n=function(e){return e[e.NoClip=0]=`NoClip`,e[e.Intersection=1]=`Intersection`,e[e.Union=2]=`Union`,e[e.Difference=3]=`Difference`,e[e.Xor=4]=`Xor`,e}({}),r=function(e){return e[e.Subject=0]=`Subject`,e[e.Clip=1]=`Clip`,e}({}),i=function(e){return e[e.EvenOdd=0]=`EvenOdd`,e[e.NonZero=1]=`NonZero`,e[e.Positive=2]=`Positive`,e[e.Negative=3]=`Negative`,e}({}),a=function(e){return e[e.IsOn=0]=`IsOn`,e[e.IsInside=1]=`IsInside`,e[e.IsOutside=2]=`IsOutside`,e}({});const o=2**53-1,s=Math.floor(Math.sqrt(o));function c(e,t){return!Number.isSafeInteger(e)||!Number.isSafeInteger(t)?!1:e===0||t===0?!0:Math.abs(e)<=o/Math.abs(t)}function l(e,t){return Math.abs(e)+Math.abs(t)<=o}function u(e,t,n,r){if(c(e,t)&&c(n,r)){let i=e*t,a=n*r;if(l(i,a))return i-a}return Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(e)*BigInt(t)-BigInt(n)*BigInt(r)):e*t-n*r}function d(e,t,n,r){if(c(e,t)&&c(n,r)){let i=e*t,a=n*r;if(l(i,a))return i+a}return Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(e)*BigInt(t)+BigInt(n)*BigInt(r)):e*t+n*r}const f=BigInt(0),p=BigInt(2),m=BigInt(4),h=BigInt(64),g=BigInt(`0xFFFFFFFFFFFFFFFF`),_=BigInt(`9223372036854775807`),v=Number(_/m),y=Number(_),b=1e-12,x=Math.floor(s/2),ee=Math.floor(Math.sqrt(Math.sqrt(o/4)));function te(e){if(!Number.isFinite(e))throw RangeError(`Scale must be a finite number`);let t=Math.abs(e);return t===0?1/0:o/t}function ne(e,t,n){if(!Number.isFinite(e)||Math.abs(e)>t)throw RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function re(e,t){if(!Number.isFinite(e)||Math.abs(e)>o)throw RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${t}`)}function ie(e,t,n){let r=t.x-e.x,i=n.y-t.y,a=t.y-e.y,o=n.x-t.x;return Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s?r*i-a*o:u(r,i,a,o)}function S(e,t,n){let r=t.x-e.x,i=n.y-t.y,a=t.y-e.y,o=n.x-t.x;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*i,t=a*o;return e>t?1:e<t?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)){let e=r*i,t=a*o;return e>t?1:e<t?-1:0}let c=BigInt(r)*BigInt(i),l=BigInt(a)*BigInt(o);return c===l?0:c>l?1:-1}function ae(e){if(e<-8||e>8)throw Error(`Error: Precision is out of range.`)}function oe(e){return Math.abs(e)<=b}function se(e){return e<0?-1:e>0?1:0}function ce(e,t){let n=BigInt(e)*BigInt(t);return{lo64:n&g,hi64:n>>h}}function le(e,t,n,r){let i=Math.abs(e),a=Math.abs(t),o=Math.abs(n),c=Math.abs(r);if(i<s&&a<s&&o<s&&c<s)return e*t===n*r;let l=(e<0?-1:e>0?1:0)*(t<0?-1:t>0?1:0);if(l!==(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0))return!1;if(l===0)return!0;if(!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)||!Number.isSafeInteger(c))return e*t===n*r;let u=BigInt(i),d=BigInt(a),f=BigInt(o),p=BigInt(c);return u*d===f*p}function ue(e,t,n){return le(t.x-e.x,n.y-t.y,t.y-e.y,n.x-t.x)}function de(e,t,n){let r=t.x-e.x,i=n.x-t.x,a=t.y-e.y,o=n.y-t.y;return Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s?r*i+a*o:d(r,i,a,o)}function fe(e,t,n){let r=t.x-e.x,i=n.x-t.x,a=t.y-e.y,o=n.y-t.y;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*i+a*o;return e>0?1:e<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)){let e=r*i+a*o;return e>0?1:e<0?-1:0}let c=BigInt(r)*BigInt(i)+BigInt(a)*BigInt(o);return c===f?0:c>f?1:-1}function pe(e){let t=e.length;if(t<3)return 0;let n=!0;for(let r=0;r<t&&n;r++){let t=e[r];(Math.abs(t.x)>=x||Math.abs(t.y)>=x)&&(n=!1)}let r=e[t-1];if(n){let t=0;for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5}let i=f;for(let t of e){let e=r.y+t.y,n=r.x-t.x;if(Number.isSafeInteger(e)&&Number.isSafeInteger(n))i+=BigInt(e)*BigInt(n);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(t.x)){let e=BigInt(r.y)+BigInt(t.y),n=BigInt(r.x)-BigInt(t.x);i+=e*n}else i+=BigInt(Math.round(e*n));r=t}return Number(i)*.5}function me(e,t){return e.y*t.x-t.y*e.x}function he(e,t){return e.x*t.x+e.y*t.y}function ge(e){let t=Math.round(e);return e===t-.5&&t&1?t-1:t}function _e(e){return e>=v||e<=-v?y:Math.round(e)}function ve(e,t,n,r){let i=t.y-e.y,a=t.x-e.x,o=r.y-n.y,s=r.x-n.x,c=u(i,s,o,a);if(c===0)return null;let l=u(e.x-n.x,o,e.y-n.y,s)/c;return l<=0?{x:e.x,y:e.y,z:e.z||0}:l>=1?{x:t.x,y:t.y,z:t.z||0}:{x:Math.trunc(e.x+l*a),y:Math.trunc(e.y+l*i),z:0}}function ye(e,t,n,r){let i=t.y-e.y,a=t.x-e.x,o=r.y-n.y,s=r.x-n.x,c=i*s-o*a;if(c===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((e.x-n.x)*o-(e.y-n.y)*s)/c,u;return u=l<=0?{...e,z:0}:l>=1?{...t,z:0}:{x:e.x+l*a,y:e.y+l*i,z:0},{success:!0,ip:u}}function be(e,t,n,r,i=!1){if(!i){let i=S(e,n,r),a=S(t,n,r),o=S(n,e,t),s=S(r,e,t);return i!==0&&a!==0&&i!==a&&o!==0&&s!==0&&o!==s}let a=S(e,n,r),o=S(t,n,r);if(a!==0&&a===o)return!1;let s=S(n,e,t),c=S(r,e,t);return s!==0&&s===c?!1:a!==0||o!==0||s!==0||c!==0}function xe(e){if(e.length===0)return{left:0,top:0,right:0,bottom:0};let t={left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)};for(let n of e)n.x<t.left&&(t.left=n.x),n.x>t.right&&(t.right=n.x),n.y<t.top&&(t.top=n.y),n.y>t.bottom&&(t.bottom=n.y);return t.left===2**53-1?{left:0,top:0,right:0,bottom:0}:t}function Se(e,t,n){if(t.x===n.x&&t.y===n.y)return{x:t.x,y:t.y,z:0};let r=n.x-t.x,i=n.y-t.y,a=d(e.x-t.x,r,e.y-t.y,i)/d(r,r,i,i),o=a<0?0:a>1?1:a;return{x:Math.round(t.x+o*r),y:Math.round(t.y+o*i),z:0}}function Ce(e,t){let n=t.length,r=0;if(n<3)return a.IsOutside;for(;r<n&&t[r].y===e.y;)r++;if(r===n)return a.IsOutside;let i=t[r].y<e.y,o=i,s=0,c=r+1,l=n;for(;;){if(c===l){if(l===0||r===0)break;l=r,c=0}if(i)for(;c<l&&t[c].y<e.y;)c++;else for(;c<l&&t[c].y>e.y;)c++;if(c===l)continue;let o=t[c],u=c>0?t[c-1]:t[n-1];if(o.y===e.y){if(o.x===e.x||o.y===u.y&&e.x<u.x!=e.x<o.x)return a.IsOn;if(c++,c===r)break;continue}if(!(e.x<o.x&&e.x<u.x))if(e.x>u.x&&e.x>o.x)s=1-s;else{let t=S(u,o,e);if(t===0)return a.IsOn;t<0===i&&(s=1-s)}i=!i,c++}if(i===o)return s===0?a.IsOutside:a.IsInside;c===n&&(c=0);let u=c===0?S(t[n-1],t[0],e):S(t[c-1],t[c],e);return u===0?a.IsOn:(u<0===i&&(s=1-s),s===0?a.IsOutside:a.IsInside)}function we(e,t){let n=a.IsOn;for(let r of e)switch(Ce(r,t)){case a.IsOutside:if(n===a.IsOutside)return!1;n=a.IsOutside;break;case a.IsInside:if(n===a.IsInside)return!0;n=a.IsInside;break;default:break}let r=xe(e),i,o;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>2**53-1?(i=Number((BigInt(r.left)+BigInt(r.right))/p),o=Number((BigInt(r.top)+BigInt(r.bottom))/p)):(i=Math.round((r.left+r.right)/2),o=Math.round((r.top+r.bottom)/2)),Ce({x:i,y:o},t)!==a.IsOutside}const C={MaxInt64:_,MaxCoord:v,max_coord:v,min_coord:-v,Invalid64:y,floatingPointTolerance:b,defaultMinimumEdgeLength:.1,maxCoordForSafeAreaProduct:x,maxCoordForSafeCrossSq:ee,maxSafeCoordinateForScale:te,checkSafeScaleValue:ne,ensureSafeInteger:re,crossProduct:ie,crossProductSign:S,checkPrecision:ae,isAlmostZero:oe,triSign:se,multiplyUInt64:ce,productsAreEqual:le,isCollinear:ue,dotProduct:de,dotProductSign:fe,area:pe,crossProductD:me,dotProductD:he,roundToEven:ge,checkCastInt64:_e,getLineIntersectPt:ve,getLineIntersectPtD:ye,segsIntersect:be,getBounds:xe,getClosestPtOnSegment:Se,pointInPolygon:Ce,path2ContainsPath1:we},w={create(e=0,t=0,n=0){return{x:Math.round(e),y:Math.round(t),z:n}},fromPointD(e){return C.ensureSafeInteger(e.x,`Point64Utils.fromPointD`),C.ensureSafeInteger(e.y,`Point64Utils.fromPointD`),{x:Math.round(e.x),y:Math.round(e.y),z:e.z||0}},scale(e,t){return{x:Math.round(e.x*t),y:Math.round(e.y*t),z:e.z||0}},equals(e,t){return e.x===t.x&&e.y===t.y},add(e,t){if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.y)){let n=e.x+t.x,r=e.y+t.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(e.x)+BigInt(t.x)),y:Number(BigInt(e.y)+BigInt(t.y)),z:0}}return{x:e.x+t.x,y:e.y+t.y,z:0}},subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:0}},toString(e){return e.z!==void 0&&e.z!==0?`${e.x},${e.y},${e.z} `:`${e.x},${e.y} `}},T={create(e=0,t=0,n=0){return{x:e,y:t,z:n}},fromPoint64(e){return{x:e.x,y:e.y,z:e.z||0}},scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z||0}},equals(e,t){return C.isAlmostZero(e.x-t.x)&&C.isAlmostZero(e.y-t.y)},negate(e){e.x=-e.x,e.y=-e.y},toString(e,t=2){return e.z!==void 0&&e.z!==0?`${e.x.toFixed(t)},${e.y.toFixed(t)},${e.z}`:`${e.x.toFixed(t)},${e.y.toFixed(t)}`}},E={create(e=0,t=0,n=0,r=0){return{left:e,top:t,right:n,bottom:r}},createInvalid(){return{left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)}},width(e){return e.right-e.left},height(e){return e.bottom-e.top},isEmpty(e){return e.bottom<=e.top||e.right<=e.left},isValid(e){return e.left<2**53-1},midPoint(e){return Number.isSafeInteger(e.left)&&Number.isSafeInteger(e.right)&&Math.abs(e.left)+Math.abs(e.right)>2**53-1?{x:Number((BigInt(e.left)+BigInt(e.right))/p),y:Number((BigInt(e.top)+BigInt(e.bottom))/p)}:{x:Math.round((e.left+e.right)/2),y:Math.round((e.top+e.bottom)/2)}},contains(e,t){return t.x>e.left&&t.x<e.right&&t.y>e.top&&t.y<e.bottom},containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom},intersects(e,t){return Math.max(e.left,t.left)<=Math.min(e.right,t.right)&&Math.max(e.top,t.top)<=Math.min(e.bottom,t.bottom)},asPath(e){return[{x:e.left,y:e.top,z:0},{x:e.right,y:e.top,z:0},{x:e.right,y:e.bottom,z:0},{x:e.left,y:e.bottom,z:0}]}},D={create(e=0,t=0,n=0,r=0){return{left:e,top:t,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(e){return e.right-e.left},height(e){return e.bottom-e.top},isEmpty(e){return e.bottom<=e.top||e.right<=e.left},midPoint(e){return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}},contains(e,t){return t.x>e.left&&t.x<e.right&&t.y>e.top&&t.y<e.bottom},containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom},intersects(e,t){return Math.max(e.left,t.left)<Math.min(e.right,t.right)&&Math.max(e.top,t.top)<Math.min(e.bottom,t.bottom)},asPath(e){return[{x:e.left,y:e.top,z:0},{x:e.right,y:e.top,z:0},{x:e.right,y:e.bottom,z:0},{x:e.left,y:e.bottom,z:0}]}},O={toString64(e){let t=``;for(let n of e)t+=w.toString(n);return t+`
2
- `},toStringD(e,t=2){let n=``;for(let r of e)n+=T.toString(r,t)+`, `;return n!==``&&(n=n.slice(0,-2)),n},reverse64(e){return[...e].reverse()},reverseD(e){return[...e].reverse()}},Te={toString64(e){let t=``;for(let n of e)t+=O.toString64(n);return t},toStringD(e,t=2){let n=``;for(let r of e)n+=O.toStringD(r,t)+`
3
- `;return n},reverse64(e){return e.map(e=>O.reverse64(e))},reverseD(e){return e.map(e=>O.reverseD(e))}},Ee=Object.freeze(E.createInvalid()),De=Object.freeze(D.createInvalid()),Oe=BigInt(0),ke=BigInt(2),Ae=BigInt(4);let k=function(e){return e[e.None=0]=`None`,e[e.OpenStart=1]=`OpenStart`,e[e.OpenEnd=2]=`OpenEnd`,e[e.LocalMax=4]=`LocalMax`,e[e.LocalMin=8]=`LocalMin`,e}({});var je=class{data=[];push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],t=this.data.pop();return this.data.length>0&&(this.data[0]=t,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let t=this.data[e];for(;e>0;){let n=e-1>>1;if(this.data[n]>=t)break;this.data[e]=this.data[n],e=n}this.data[e]=t}siftDown(e){let t=this.data.length,n=this.data[e];for(;;){let r=(e<<1)+1;if(r>=t)break;let i=r+1,a=r;if(i<t&&this.data[i]>this.data[r]&&(a=i),this.data[a]<=n)break;this.data[e]=this.data[a],e=a}this.data[e]=n}},Me=class{pt;next=null;prev=null;flags;constructor(e,t,n){this.pt=e,this.flags=t,this.prev=n}},Ne=class{vertex;polytype;isOpen;constructor(e,t,n=!1){this.vertex=e,this.polytype=t,this.isOpen=n}equals(e){return e!==null&&this.vertex===e.vertex}};function Pe(e,t,n=!1){return new Ne(e,t,n)}function Fe(e,t,n){return{pt:e,edge1:t,edge2:n}}var A=class{pt;next;prev;outrec;horz;constructor(e,t){this.pt=e,this.outrec=t,this.next=this,this.prev=this,this.horz=null}};let j=function(e){return e[e.None=0]=`None`,e[e.Left=1]=`Left`,e[e.Right=2]=`Right`,e}({}),Ie=function(e){return e[e.Bottom=0]=`Bottom`,e[e.Middle=1]=`Middle`,e[e.Top=2]=`Top`,e}({});var Le=class{idx=0;owner=null;frontEdge=null;backEdge=null;pts=null;polypath=null;bounds={left:0,top:0,right:0,bottom:0};path=[];isOpen=!1;splits=null;recursiveSplit=null},Re=class{leftOp;rightOp;leftToRight;constructor(e){this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},ze=class{op1;op2;constructor(e,t){this.op1=e,this.op2=t}},Be=class{bot={x:0,y:0};top={x:0,y:0};curX=0;dx=0;windDx=0;windCount=0;windCount2=0;outrec=null;prevInAEL=null;nextInAEL=null;prevInSEL=null;nextInSEL=null;jump=null;vertexTop=null;localMin=null;isLeftBound=!1;joinWith=j.None};const M={addLocMin(e,t,n,r){if((e.flags&k.LocalMin)!==k.None)return;e.flags|=k.LocalMin;let i=new Ne(e,t,n);r.push(i)},addPathsToVertexList(e,t,n,r,i){for(let a=0,o=e.length;a<o;a++){let o=e[a],s=null,c=null;for(let e=0,t=o.length;e<t;e++){let t=o[e];if(s===null)s=new Me(t,k.None,null),i.push(s),c=s;else if(!(c.pt.x===t.x&&c.pt.y===t.y)){let e=new Me(t,k.None,c);i.push(e),c.next=e,c=e}}if(c?.prev==null||(!n&&c.pt.x===s.pt.x&&c.pt.y===s.pt.y&&(c=c.prev),c.next=s,s.prev=c,!n&&c.next===c))continue;let l;if(n){let e=s.next;for(;e!==s&&e.pt.y===s.pt.y;)e=e.next;l=e.pt.y<=s.pt.y,l?(s.flags=k.OpenStart,M.addLocMin(s,t,!0,r)):s.flags=k.OpenStart|k.LocalMax}else{for(c=s.prev;c!==s&&c.pt.y===s.pt.y;)c=c.prev;if(c===s)continue;l=c.pt.y>s.pt.y}let u=l;c=s;let d=s.next;for(;d!==s;)d.pt.y>c.pt.y&&l?(c.flags|=k.LocalMax,l=!1):d.pt.y<c.pt.y&&!l&&(l=!0,M.addLocMin(c,t,n,r)),c=d,d=d.next;n?(c.flags|=k.OpenEnd,l?c.flags|=k.LocalMax:M.addLocMin(c,t,n,r)):l!==u&&(u?M.addLocMin(c,t,!1,r):c.flags|=k.LocalMax)}}};var Ve=class{minimaList;vertexList;constructor(){this.minimaList=[],this.vertexList=[]}clear(){this.minimaList.length=0,this.vertexList.length=0}addPaths(e,t,n){M.addPathsToVertexList(e,t,n,this.minimaList,this.vertexList)}},He=class{parent;children=[];constructor(e=null){this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,t=this.parent;for(;t!==null;)++e,t=t.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)==0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,t){let n=``,r=` `.repeat(t),i=this.children.length===1?``:`s`;t&1?n+=`${r}+- polygon (${e}) contains ${this.children.length} hole${i}.\n`:n+=`${r}+- hole (${e}) contains ${this.children.length} nested polygon${i}.\n`;for(let e=0;e<this.count;e++)this.children[e].count>0&&(n+=this.children[e].toStringInternal(e,t+1));return n}toString(){if(this.level>0)return``;let e=this.children.length===1?``:`s`,t=`Polytree with ${this.children.length} polygon${e}.\n`;for(let e=0;e<this.count;e++)this.children[e].count>0&&(t+=this.children[e].toStringInternal(e,1));return t+`
4
- `}},Ue=class e extends He{polygon=null;constructor(e=null){super(e)}get poly(){return this.polygon}addChild(t){let n=new e(this);return n.polygon=t,this.children.push(n),n}child(e){if(e<0||e>=this.children.length)throw Error(`Index out of range`);return this.children[e]}area(){let e=this.polygon===null?0:F.area(this.polygon);for(let t of this.children)e+=t.area();return e}},We=class e extends He{scale=1;polygon=null;constructor(e=null){super(e)}get poly(){return this.polygon}addChild(t){let n=new e(this);return n.scale=this.scale,n.polygon=F.scalePathD(t,1/this.scale),this.children.push(n),n}addChildD(t){let n=new e(this);return n.scale=this.scale,n.polygon=t,this.children.push(n),n}child(e){if(e<0||e>=this.children.length)throw Error(`Index out of range`);return this.children[e]}area(){let e=this.polygon===null?0:F.areaD(this.polygon);for(let t of this.children)e+=t.area();return e}},Ge=class extends Ue{},Ke=class extends We{get scaleValue(){return this.scale}},N=class e{static openPathsEnabled=!0;cliptype=n.NoClip;fillrule=i.EvenOdd;actives=null;sel=null;minimaList=[];intersectList=[];vertexList=[];outrecList=[];scanlineHeap=new je;scanlineSet=new Set;scanlineArr=[];useScanlineArray=!1;horzSegList=[];horzJoinList=[];currentLocMin=0;currentBotY=0;isSortedMinimaList=!1;hasOpenPaths=!1;usingPolytree=!1;succeeded=!1;zCallbackInternal=void 0;preserveCollinear=!0;reverseSolution=!1;constructor(){}getZCallback(){}xyEqual(e,t){return e.x===t.x&&e.y===t.y}setZ(t,n,i){let a=this.zCallbackInternal;a&&(e.getPolyType(t)===r.Subject?(this.xyEqual(i,t.bot)?i.z=t.bot.z??0:this.xyEqual(i,t.top)?i.z=t.top.z??0:this.xyEqual(i,n.bot)?i.z=n.bot.z??0:this.xyEqual(i,n.top)?i.z=n.top.z??0:i.z=0,a(t.bot,t.top,n.bot,n.top,i)):(this.xyEqual(i,n.bot)?i.z=n.bot.z??0:this.xyEqual(i,n.top)?i.z=n.top.z??0:this.xyEqual(i,t.bot)?i.z=t.bot.z??0:this.xyEqual(i,t.top)?i.z=t.top.z??0:i.z=0,a(n.bot,n.top,t.bot,t.top,i)))}static isOdd(e){return(e&1)!=0}static isHotEdge(e){return e.outrec!=null}static isOpen(t){return e.openPathsEnabled&&t.localMin.isOpen}static isOpenEnd(t){return e.openPathsEnabled&&t.localMin.isOpen&&e.isOpenEndVertex(t.vertexTop)}static isOpenEndVertex(e){return(e.flags&(k.OpenStart|k.OpenEnd))!==k.None}static getPrevHotEdge(t){let n=t.prevInAEL;if(!e.openPathsEnabled){for(;n!==null&&!e.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!e.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,t){let n=t.y-e.y;return n===0?t.x>e.x?-1/0:1/0:(t.x-e.x)/n}static topX(e,t){return t===e.top.y||e.top.x===e.bot.x?e.top.x:t===e.bot.y?e.bot.x:C.roundToEven(e.bot.x+e.dx*(t-e.bot.y))}static isHorizontal(e){return e.top.y===e.bot.y}static isHeadingRightHorz(e){return e.dx===-1/0}static isHeadingLeftHorz(e){return e.dx===1/0}static swapActives(e,t){return[t,e]}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,t){return e.localMin.polytype===t.localMin.polytype}static setDx(t){t.dx=e.getDx(t.bot,t.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaxima(t){return`flags`in t?(t.flags&k.LocalMax)!==k.None:e.isMaxima(t.vertexTop)}static getMaximaPair(e){let t=e.nextInAEL;for(;t!==null;){if(t.vertexTop===e.vertexTop)return t;t=t.nextInAEL}return null}boundingBoxesOverlap(e,t,n,r){let i=Math.min(e.x,t.x),a=Math.max(e.x,t.x),o=Math.min(e.y,t.y),s=Math.max(e.y,t.y),c=Math.min(n.x,r.x),l=Math.max(n.x,r.x),u=Math.min(n.y,r.y),d=Math.max(n.y,r.y);return!(a<c||l<i||s<u||d<o)}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||=(this.minimaList.sort((e,t)=>t.vertex.pt.y-e.vertex.pt.y),!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let t=0,n=e.length;t<n;t++){let n=e[t];this.scanlineSet.add(n),this.scanlineHeap.push(n)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let t=this.scanlineArr;for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return;t.push(e),t.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let e=this.scanlineArr,t=e.length;if(t===0)return null;let n=0,r=e[0];for(let i=1;i<t;i++){let t=e[i];t>r&&(r=t,n=i)}return e[n]=e[t-1],e.pop(),r}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,t,n=!1){let r=[e];this.addPaths(r,t,n)}addPaths(e,t,n=!1){n&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,M.addPathsToVertexList(e,t,n,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let t of e.minimaList)this.minimaList.push(new Ne(t.vertex,t.polytype,t.isOpen)),t.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let t=e.prevInAEL,n=e.nextInAEL;t===null&&n===null&&e!==this.actives||(t===null?this.actives=n:t.nextInAEL=n,n!==null&&(n.prevInAEL=t))}getBounds(){let e={left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)};for(let t of this.vertexList){let n=t;do n.pt.x<e.left&&(e.left=n.pt.x),n.pt.x>e.right&&(e.right=n.pt.x),n.pt.y<e.top&&(e.top=n.pt.y),n.pt.y>e.bottom&&(e.bottom=n.pt.y),n=n.next;while(n!==t)}return E.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(t,r){if(t===n.NoClip)return;e.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=r,this.cliptype=t,this.reset();let i=this.popScanline();if(i!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(i);let e;for(;(e=this.popHorz())!==null;)this.doHorizontal(e);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=i;let t=this.popScanline();if(t===null)break;for(i=t,this.doIntersections(i),this.doTopOfScanbeam(i);(e=this.popHorz())!==null;)this.doHorizontal(e)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(t){for(;this.hasLocMinAtY(t);){let t=this.popLocalMinima(),n;(t.vertex.flags&k.OpenStart)===k.None?(n=new Be,n.bot=t.vertex.pt,n.curX=t.vertex.pt.x,n.windDx=-1,n.vertexTop=t.vertex.prev,n.top=t.vertex.prev.pt,n.outrec=null,n.localMin=t,e.setDx(n)):n=null;let r;(t.vertex.flags&k.OpenEnd)===k.None?(r=new Be,r.bot=t.vertex.pt,r.curX=t.vertex.pt.x,r.windDx=1,r.vertexTop=t.vertex.next,r.top=t.vertex.next.pt,r.outrec=null,r.localMin=t,e.setDx(r)):r=null,n!==null&&r!==null?e.isHorizontal(n)?e.isHeadingRightHorz(n)&&([n,r]=e.swapActives(n,r)):e.isHorizontal(r)?e.isHeadingLeftHorz(r)&&([n,r]=e.swapActives(n,r)):n.dx<r.dx&&([n,r]=e.swapActives(n,r)):n===null&&(n=r,r=null);let i;if(n.isLeftBound=!0,this.insertLeftEdge(n),e.openPathsEnabled&&e.isOpen(n)?(this.setWindCountForOpenPathEdge(n),i=this.isContributingOpen(n)):(this.setWindCountForClosedPathEdge(n),i=this.isContributingClosed(n)),r!==null){for(r.windCount=n.windCount,r.windCount2=n.windCount2,this.insertRightEdge(n,r),i&&(this.addLocalMinPoly(n,r,n.bot,!0),e.isHorizontal(n)||this.checkJoinLeft(n,n.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);e.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else i&&e.openPathsEnabled&&this.startOpenPath(n,n.bot);e.isHorizontal(n)?this.pushHorz(n):this.insertScanline(n.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(t){if(!e.openPathsEnabled){this.doHorizontalClosed(t);return}let n=e.isOpen(t),r=t.bot.y,i=n?this.getCurrYMaximaVertexOpen(t):this.getCurrYMaximaVertex(t),{isLeftToRight:a,leftX:o,rightX:s}=this.resetHorzDirection(t,i),c=o,l=s;if(e.isHotEdge(t)){let e=this.addOutPt(t,{x:t.curX,y:r});this.addToHorzSegList(e)}for(;;){let o=a?t.nextInAEL:t.prevInAEL;for(;o!==null;){if(o.vertexTop===i){if(e.isHotEdge(t)&&this.isJoined(o)&&this.split(o,o.top),e.isHotEdge(t)){for(;t.vertexTop!==i;)this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);a?this.addLocalMaxPoly(t,o,t.top):this.addLocalMaxPoly(o,t,t.top)}this.deleteFromAEL(o),this.deleteFromAEL(t);return}if(i!==t.vertexTop||e.isOpenEnd(t)){if(a&&o.curX>l||!a&&o.curX<c)break;if(o.curX===t.top.x&&!e.isHorizontal(o)){let n=e.nextVertex(t).pt;if(e.isOpen(o)&&!e.isSamePolyType(o,t)&&!e.isHotEdge(o)){if(a&&e.topX(o,n.y)>n.x||!a&&e.topX(o,n.y)<n.x)break}else if(a&&e.topX(o,n.y)>=n.x||!a&&e.topX(o,n.y)<=n.x)break}}let n={x:o.curX,y:r};a?(this.intersectEdges(t,o,n),this.swapPositionsInAEL(t,o),this.checkJoinLeft(o,n),t.curX=o.curX,o=t.nextInAEL):(this.intersectEdges(o,t,n),this.swapPositionsInAEL(o,t),this.checkJoinRight(o,n),t.curX=o.curX,o=t.prevInAEL),e.isHotEdge(t)&&this.addToHorzSegList(this.getLastOp(t))}if(n&&e.isOpenEnd(t)){e.isHotEdge(t)&&(this.addOutPt(t,t.top),e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null),this.deleteFromAEL(t);return}if(e.nextVertex(t).pt.y!==t.top.y)break;e.isHotEdge(t)&&this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);let s=this.resetHorzDirection(t,i);c=s.leftX,l=s.rightX}if(e.isHotEdge(t)){let e=this.addOutPt(t,t.top);this.addToHorzSegList(e)}this.updateEdgeIntoAEL(t)}doHorizontalClosed(t){let n=t.bot.y,r=this.getCurrYMaximaVertex(t),{isLeftToRight:i,leftX:a,rightX:o}=this.resetHorzDirection(t,r),s=a,c=o;if(e.isHotEdge(t)){let e=this.addOutPt(t,{x:t.curX,y:n});this.addToHorzSegList(e)}for(;;){let a=i?t.nextInAEL:t.prevInAEL;for(;a!==null;){if(a.vertexTop===r){if(e.isHotEdge(t)&&this.isJoined(a)&&this.split(a,a.top),e.isHotEdge(t)){for(;t.vertexTop!==r;)this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);i?this.addLocalMaxPoly(t,a,t.top):this.addLocalMaxPoly(a,t,t.top)}this.deleteFromAEL(a),this.deleteFromAEL(t);return}if(r!==t.vertexTop){if(i&&a.curX>c||!i&&a.curX<s)break;if(a.curX===t.top.x&&!e.isHorizontal(a)){let n=e.nextVertex(t).pt,r=e.topX(a,n.y);if(i&&r>=n.x||!i&&r<=n.x)break}}let o={x:a.curX,y:n};i?(this.intersectEdges(t,a,o),this.swapPositionsInAEL(t,a),this.checkJoinLeft(a,o),t.curX=a.curX,a=t.nextInAEL):(this.intersectEdges(a,t,o),this.swapPositionsInAEL(a,t),this.checkJoinRight(a,o),t.curX=a.curX,a=t.prevInAEL),e.isHotEdge(t)&&this.addToHorzSegList(this.getLastOp(t))}if(e.nextVertex(t).pt.y!==t.top.y)break;e.isHotEdge(t)&&this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);let o=this.resetHorzDirection(t,r);s=o.leftX,c=o.rightX}if(e.isHotEdge(t)){let e=this.addOutPt(t,t.top);this.addToHorzSegList(e)}this.updateEdgeIntoAEL(t)}convertHorzSegsToJoins(){let e=0;for(let t of this.horzSegList)this.updateHorzSegment(t)&&e++;if(!(e<2)){this.horzSegList.sort((e,t)=>this.horzSegSort(e,t));for(let t=0;t<e-1;t++){let n=this.horzSegList[t];for(let r=t+1;r<e;r++){let e=this.horzSegList[r];if(e.leftOp.pt.x>=n.rightOp.pt.x||e.leftToRight===n.leftToRight||e.rightOp.pt.x<=n.leftOp.pt.x)continue;let t=n.leftOp.pt.y;if(n.leftToRight){for(;n.leftOp.next.pt.y===t&&n.leftOp.next.pt.x<=e.leftOp.pt.x;)n.leftOp=n.leftOp.next;for(;e.leftOp.prev.pt.y===t&&e.leftOp.prev.pt.x<=n.leftOp.pt.x;)e.leftOp=e.leftOp.prev;let r=new ze(this.duplicateOp(n.leftOp,!0),this.duplicateOp(e.leftOp,!1));this.horzJoinList.push(r)}else{for(;n.leftOp.prev.pt.y===t&&n.leftOp.prev.pt.x<=e.leftOp.pt.x;)n.leftOp=n.leftOp.prev;for(;e.leftOp.next.pt.y===t&&e.leftOp.next.pt.x<=n.leftOp.pt.x;)e.leftOp=e.leftOp.next;let r=new ze(this.duplicateOp(e.leftOp,!0),this.duplicateOp(n.leftOp,!1));this.horzJoinList.push(r)}}}}}updateHorzSegment(e){let t=e.leftOp,n=this.getRealOutRec(t.outrec),r=n.frontEdge!==null,i=t.pt.y,a=t,o=t;if(r){let e=n.pts,t=e.next;for(;a!==t&&a.prev.pt.y===i;)a=a.prev;for(;o!==e&&o.next.pt.y===i;)o=o.next}else{for(;a.prev!==o&&a.prev.pt.y===i;)a=a.prev;for(;o.next!==a&&o.next.pt.y===i;)o=o.next}let s=this.setHorzSegHeadingForward(e,a,o)&&e.leftOp.horz===null;return s?e.leftOp.horz=e:e.rightOp=null,s}setHorzSegHeadingForward(e,t,n){return t.pt.x===n.pt.x?!1:(t.pt.x<n.pt.x?(e.leftOp=t,e.rightOp=n,e.leftToRight=!0):(e.leftOp=n,e.rightOp=t,e.leftToRight=!1),!0)}horzSegSort(e,t){return e.rightOp===null?t.rightOp===null?0:1:t.rightOp===null?-1:e.leftOp.pt.x-t.leftOp.pt.x}duplicateOp(e,t){let n=new A(e.pt,e.outrec);return t?(n.next=e.next,n.next.prev=n,n.prev=e,e.next=n):(n.prev=e.prev,n.prev.next=n,n.next=e,e.prev=n),n}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(t){this.sel=null;let n=this.actives;for(;n!==null;){if(n.top.y===t)if(n.curX=n.top.x,e.isMaxima(n)){n=this.doMaxima(n);continue}else e.isHotEdge(n)&&this.addOutPt(n,n.top),this.updateEdgeIntoAEL(n),e.isHorizontal(n)&&this.pushHorz(n);else n.curX=e.topX(n,t);n=n.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let t=this.getRealOutRec(e.op1.outrec),n=this.getRealOutRec(e.op2.outrec),r=e.op1.next,i=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=i,i.next=r,t===n){let n=this.newOutRec();n.pts=r,this.fixOutRecPts(n),t.pts.outrec===n&&(t.pts=e.op1,t.pts.outrec=t),this.usingPolytree?(this.path1InsidePath2(t.pts,n.pts)?([n.pts,t.pts]=[t.pts,n.pts],this.fixOutRecPts(t),this.fixOutRecPts(n),n.owner=t):this.path1InsidePath2(n.pts,t.pts)?n.owner=t:n.owner=t.owner,t.splits===null&&(t.splits=[]),t.splits.push(n.idx)):n.owner=t}else n.pts=null,this.usingPolytree?(this.setOwner(n,t),this.moveSplits(n,t)):n.owner=t}}fixOutRecPts(e){let t=e.pts;do t.outrec=e,t=t.next;while(t!==e.pts)}path1InsidePath2(e,t){let n=a.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,t)){case a.IsOutside:if(n===a.IsOutside)return!1;n=a.IsOutside;break;case a.IsInside:if(n===a.IsInside)return!0;n=a.IsInside;break;default:break}r=r.next}while(r!==e);return C.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(t))}pointInOpPolygon(e,t){if(t===t.next||t.prev===t.next)return a.IsOutside;let n=t;do{if(t.pt.y!==e.y)break;t=t.next}while(t!==n);if(t.pt.y===e.y)return a.IsOutside;let r=t.pt.y<e.y,i=r,o=0;for(n=t.next;n!==t;){if(r)for(;n!==t&&n.pt.y<e.y;)n=n.next;else for(;n!==t&&n.pt.y>e.y;)n=n.next;if(n===t)break;if(n.pt.y===e.y){if(n.pt.x===e.x||n.pt.y===n.prev.pt.y&&e.x<n.prev.pt.x!=e.x<n.pt.x)return a.IsOn;if(n=n.next,n===t)break;continue}if(n.pt.x<=e.x||n.prev.pt.x<=e.x)if(n.prev.pt.x<e.x&&n.pt.x<e.x)o=1-o;else{let t=C.crossProductSign(n.prev.pt,n.pt,e);if(t===0)return a.IsOn;t<0===r&&(o=1-o)}r=!r,n=n.next}if(r===i)return o===0?a.IsOutside:a.IsInside;{let t=C.crossProductSign(n.prev.pt,n.pt,e);if(t===0)return a.IsOn;t<0===r&&(o=1-o)}return o===0?a.IsOutside:a.IsInside}getCleanPath(e){let t=[],n=e;for(;n.next!==e&&(n.pt.x===n.next.pt.x&&n.pt.x===n.prev.pt.x||n.pt.y===n.next.pt.y&&n.pt.y===n.prev.pt.y);)n=n.next;t.push(n.pt);let r=n;for(n=n.next;n!==e;)(n.pt.x!==n.next.pt.x||n.pt.x!==r.pt.x)&&(n.pt.y!==n.next.pt.y||n.pt.y!==r.pt.y)&&(t.push(n.pt),r=n),n=n.next;return t}moveSplits(e,t){if(e.splits!==null){t.splits===null&&(t.splits=[]);for(let n of e.splits)n!==t.idx&&t.splits.push(n);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;this.adjustCurrXAndCopyToSEL(e);let t=this.sel;for(;t!==null&&t.jump!==null;){let n=null;for(;t!==null&&t.jump!==null;){let r=t,i=t.jump,a=i,o=i?.jump||null;for(t.jump=o;t!==a&&i!==o;)if(i.curX<t.curX){let s=i.prevInSEL;for(;this.addNewIntersectNode(s,i,e),s!==t;)s=s.prevInSEL;if(s=i,i=this.extractFromSEL(s),a=i,t!==null&&this.insert1Before2InSEL(s,t),t!==r)continue;r=s,r.jump=o,n===null?this.sel=r:n.jump=r}else t=t.nextInSEL;n=r,t=o}t=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort((e,t)=>e.pt.y===t.pt.y?e.pt.x===t.pt.x?e.edge1.curX===t.edge1.curX?e.edge2.curX<t.edge2.curX?-1:e.edge2.curX>t.edge2.curX?1:0:e.edge1.curX<t.edge1.curX?-1:1:e.pt.x<t.pt.x?-1:1:e.pt.y>t.pt.y?-1:1);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let t=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[t]);)t++;[this.intersectList[t],this.intersectList[e]]=[this.intersectList[e],this.intersectList[t]]}let t=this.intersectList[e];this.intersectEdges(t.edge1,t.edge2,t.pt),this.swapPositionsInAEL(t.edge1,t.edge2),t.edge1.curX=t.pt.x,t.edge2.curX=t.pt.x,this.checkJoinLeft(t.edge2,t.pt,!0),this.checkJoinRight(t.edge1,t.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(t){let n=this.actives;for(this.sel=n;n!==null;)n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL,n.curX=e.topX(n,t),n=n.nextInAEL}doMaxima(t){let n=t.prevInAEL,r=t.nextInAEL;if(e.isOpenEnd(t))return e.isHotEdge(t)&&this.addOutPt(t,t.top),e.isHorizontal(t)?r:(e.isHotEdge(t)&&(e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null),this.deleteFromAEL(t),r);let i=e.getMaximaPair(t);if(i===null)return r;for(this.isJoined(t)&&this.split(t,t.top),this.isJoined(i)&&this.split(i,i.top);r!==i;)this.intersectEdges(t,r,t.top),this.swapPositionsInAEL(t,r),r=t.nextInAEL;return e.isOpen(t)?(e.isHotEdge(t)&&this.addLocalMaxPoly(t,i,t.top),this.deleteFromAEL(i),this.deleteFromAEL(t),n===null?this.actives:n.nextInAEL):(e.isHotEdge(t)&&this.addLocalMaxPoly(t,i,t.top),this.deleteFromAEL(t),this.deleteFromAEL(i),n===null?this.actives:n.nextInAEL)}updateEdgeIntoAEL(t){if(t.bot=t.top,t.vertexTop=e.nextVertex(t),t.top=t.vertexTop.pt,t.curX=t.bot.x,e.setDx(t),this.isJoined(t)&&this.split(t,t.bot),e.isHorizontal(t)){e.openPathsEnabled&&e.isOpen(t)||this.trimHorz(t,this.preserveCollinear);return}this.insertScanline(t.top.y),this.checkJoinLeft(t,t.bot),this.checkJoinRight(t,t.bot,!0)}trimHorz(t,n){let r=!1,i=e.nextVertex(t).pt;for(;i.y===t.top.y&&!(n&&i.x<t.top.x!=t.bot.x<t.top.x||(t.vertexTop=e.nextVertex(t),t.top=i,r=!0,e.isMaxima(t)));)i=e.nextVertex(t).pt;r&&e.setDx(t)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new Re(e))}addNewIntersectNode(t,n,r){let i=C.getLineIntersectPt(t.bot,t.top,n.bot,n.top);if(i===null&&(i={x:t.curX,y:r}),i.y>this.currentBotY||i.y<r){let a=Math.abs(t.dx),o=Math.abs(n.dx);a>100&&o>100?i=a>o?C.getClosestPtOnSegment(i,t.bot,t.top):C.getClosestPtOnSegment(i,n.bot,n.top):a>100?i=C.getClosestPtOnSegment(i,t.bot,t.top):o>100?i=C.getClosestPtOnSegment(i,n.bot,n.top):(i.y<r?i.y=r:i.y=this.currentBotY,a<o?i.x=e.topX(t,i.y):i.x=e.topX(n,i.y))}let a=Fe(i,t,n);this.intersectList.push(a)}extractFromSEL(e){let t=e.nextInSEL;return t!==null&&(t.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=t,t}insert1Before2InSEL(e,t){e.prevInSEL=t.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=t,t.prevInSEL=e}getCurrYMaximaVertexOpen(t){let n=t.vertexTop;if(t.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(k.OpenEnd|k.LocalMax))===k.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(k.OpenEnd|k.LocalMax))===k.None;)n=n.prev;return e.isMaxima(n)||(n=null),n}getCurrYMaximaVertex(t){let n=t.vertexTop;if(t.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return e.isMaxima(n)||(n=null),n}resetHorzDirection(e,t){if(e.bot.x===e.top.x){let n=e.curX,r=e.curX,i=e.nextInAEL;for(;i!==null&&i.vertexTop!==t;)i=i.nextInAEL;return{isLeftToRight:i!==null,leftX:n,rightX:r}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let t=e.outrec;return e===t.frontEdge?t.pts:t.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let t=this.actives;for(;t.nextInAEL!==null&&this.isValidAelOrder(t.nextInAEL,e);)t=t.nextInAEL;t.joinWith===j.Right&&(t=t.nextInAEL),e.nextInAEL=t.nextInAEL,t.nextInAEL!==null&&(t.nextInAEL.prevInAEL=e),e.prevInAEL=t,t.nextInAEL=e}}insertRightEdge(e,t){t.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=t),t.prevInAEL=e,e.nextInAEL=t}setWindCountForOpenPathEdge(t){let n=this.actives;if(this.fillrule===i.EvenOdd){let i=0,a=0;for(;n!==t;)e.getPolyType(n)===r.Clip?a++:e.isOpen(n)||i++,n=n.nextInAEL;t.windCount=e.isOdd(i)?1:0,t.windCount2=e.isOdd(a)?1:0}else for(;n!==t;)e.getPolyType(n)===r.Clip?t.windCount2+=n.windDx:e.isOpen(n)||(t.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(t){let n=t.prevInAEL,r=e.getPolyType(t);if(!e.openPathsEnabled){for(;n!==null&&e.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(t.windCount=t.windDx,n=this.actives):this.fillrule===i.EvenOdd?(t.windCount=t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx:t.windCount=t.windDx:n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===i.EvenOdd)for(;n!==t;)e.getPolyType(n)!==r&&(t.windCount2=t.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==t;)e.getPolyType(n)!==r&&(t.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(e.getPolyType(n)!==r||e.isOpen(n));)n=n.prevInAEL;if(n===null?(t.windCount=t.windDx,n=this.actives):this.fillrule===i.EvenOdd?(t.windCount=t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx:t.windCount=e.isOpen(t)?1:t.windDx:n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===i.EvenOdd)for(;n!==t;)e.getPolyType(n)!==r&&!e.isOpen(n)&&(t.windCount2=t.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==t;)e.getPolyType(n)!==r&&!e.isOpen(n)&&(t.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let t,r;switch(this.fillrule){case i.Positive:r=e.windCount>0,t=e.windCount2>0;break;case i.Negative:r=e.windCount<0,t=e.windCount2<0;break;default:r=e.windCount!==0,t=e.windCount2!==0;break}switch(this.cliptype){case n.Intersection:return t;case n.Union:return!r&&!t;default:return!t}}isContributingClosed(t){switch(this.fillrule){case i.Positive:if(t.windCount!==1)return!1;break;case i.Negative:if(t.windCount!==-1)return!1;break;case i.NonZero:if(Math.abs(t.windCount)!==1)return!1;break}switch(this.cliptype){case n.Intersection:return this.fillrule===i.Positive?t.windCount2>0:this.fillrule===i.Negative?t.windCount2<0:t.windCount2!==0;case n.Union:return this.fillrule===i.Positive?t.windCount2<=0:this.fillrule===i.Negative?t.windCount2>=0:t.windCount2===0;case n.Difference:{let n=this.fillrule===i.Positive?t.windCount2<=0:this.fillrule===i.Negative?t.windCount2>=0:t.windCount2===0;return e.getPolyType(t)===r.Subject?n:!n}case n.Xor:return!0;default:return!1}}addLocalMinPoly(t,n,r,i=!1){let a=this.newOutRec();if(t.outrec=a,n.outrec=a,e.isOpen(t))a.owner=null,a.isOpen=!0,t.windDx>0?this.setSides(a,t,n):this.setSides(a,n,t);else{a.isOpen=!1;let r=e.getPrevHotEdge(t);r===null?(a.owner=null,i?this.setSides(a,t,n):this.setSides(a,n,t)):(this.usingPolytree&&this.setOwner(a,r.outrec),a.owner=r.outrec,this.outrecIsAscending(r)===i?this.setSides(a,n,t):this.setSides(a,t,n))}let o=new A(r,a);return a.pts=o,o}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new Le;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,t){let n=this.newOutRec();n.isOpen=!0,e.windDx>0?(n.frontEdge=e,n.backEdge=null):(n.frontEdge=null,n.backEdge=e),e.outrec=n;let r=new A(t,n);return n.pts=r,r}checkJoinLeft(t,n,r=!1){let i=t.prevInAEL;if(!(i===null||!e.isHotEdge(t)||!e.isHotEdge(i)||e.isHorizontal(t)||e.isHorizontal(i)||e.isOpen(t)||e.isOpen(i))&&!((n.y<t.top.y+2||n.y<i.top.y+2)&&(t.bot.y>n.y||i.bot.y>n.y))){if(r){if(this.perpendicDistFromLineSqrdGreaterThanQuarter(n,i.bot,i.top))return}else if(t.curX!==i.curX)return;C.isCollinear(t.top,n,i.top)&&(t.outrec.idx===i.outrec.idx?this.addLocalMaxPoly(i,t,n):t.outrec.idx<i.outrec.idx?this.joinOutrecPaths(t,i):this.joinOutrecPaths(i,t),i.joinWith=j.Right,t.joinWith=j.Left)}}checkJoinRight(t,n,r=!1){let i=t.nextInAEL;if(!(i===null||!e.isHotEdge(t)||!e.isHotEdge(i)||e.isHorizontal(t)||e.isHorizontal(i)||e.isOpen(t)||e.isOpen(i))&&!((n.y<t.top.y+2||n.y<i.top.y+2)&&(t.bot.y>n.y||i.bot.y>n.y))){if(r){if(this.perpendicDistFromLineSqrdGreaterThanQuarter(n,i.bot,i.top))return}else if(t.curX!==i.curX)return;C.isCollinear(t.top,n,i.top)&&(t.outrec.idx===i.outrec.idx?this.addLocalMaxPoly(t,i,n):t.outrec.idx<i.outrec.idx?this.joinOutrecPaths(t,i):this.joinOutrecPaths(i,t),t.joinWith=j.Right,i.joinWith=j.Left)}}perpendicDistFromLineSqrdGreaterThanQuarter(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;if(a===0&&o===0)return!1;let s=C.maxCoordForSafeCrossSq;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*o-a*i;return e*e/(a*a+o*o)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(i)&&Number.isSafeInteger(a)&&Number.isSafeInteger(o)){let e=BigInt(r)*BigInt(o)-BigInt(a)*BigInt(i),t=e*e,n=BigInt(a)*BigInt(a)+BigInt(o)*BigInt(o);return Ae*t>n}let c=r*o-a*i;return c*c/(a*a+o*o)>.25}intersectEdges(t,a,o){let s;if(this.hasOpenPaths&&(e.isOpen(t)||e.isOpen(a))){if(e.isOpen(t)&&e.isOpen(a))return;if(e.isOpen(a)&&([t,a]=e.swapActives(t,a)),this.isJoined(a)&&this.split(a,o),this.cliptype===n.Union){if(!e.isHotEdge(a))return}else if(a.localMin.polytype===r.Subject)return;switch(this.fillrule){case i.Positive:if(a.windCount!==1)return;break;case i.Negative:if(a.windCount!==-1)return;break;default:if(Math.abs(a.windCount)!==1)return;break}if(e.isHotEdge(t))s=this.addOutPt(t,o),this.setZ(t,a,s.pt),e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null;else if(o.x===t.localMin.vertex.pt.x&&o.y===t.localMin.vertex.pt.y&&!e.isOpenEndVertex(t.localMin.vertex)){let n=this.findEdgeWithMatchingLocMin(t);if(n!==null&&e.isHotEdge(n)){t.outrec=n.outrec,t.windDx>0?this.setSides(n.outrec,t,n):this.setSides(n.outrec,n,t);return}s=this.startOpenPath(t,o)}else s=this.startOpenPath(t,o);this.setZ(t,a,s.pt);return}this.isJoined(t)&&this.split(t,o),this.isJoined(a)&&this.split(a,o);let c,l;switch(t.localMin.polytype===a.localMin.polytype?this.fillrule===i.EvenOdd?(c=t.windCount,t.windCount=a.windCount,a.windCount=c):(t.windCount+a.windDx===0?t.windCount=-t.windCount:t.windCount+=a.windDx,a.windCount-t.windDx===0?a.windCount=-a.windCount:a.windCount-=t.windDx):(this.fillrule===i.EvenOdd?t.windCount2=t.windCount2===0?1:0:t.windCount2+=a.windDx,this.fillrule===i.EvenOdd?a.windCount2=a.windCount2===0?1:0:a.windCount2-=t.windDx),this.fillrule){case i.Positive:c=t.windCount,l=a.windCount;break;case i.Negative:c=-t.windCount,l=-a.windCount;break;default:c=Math.abs(t.windCount),l=Math.abs(a.windCount);break}let u=c===0||c===1,d=l===0||l===1;if(!(!e.isHotEdge(t)&&!u||!e.isHotEdge(a)&&!d))if(e.isHotEdge(t)&&e.isHotEdge(a))if(c!==0&&c!==1||l!==0&&l!==1||t.localMin.polytype!==a.localMin.polytype&&this.cliptype!==n.Xor)s=this.addLocalMaxPoly(t,a,o),s&&this.setZ(t,a,s.pt);else if(e.isFront(t)||t.outrec===a.outrec){s=this.addLocalMaxPoly(t,a,o),s&&this.setZ(t,a,s.pt);let e=this.addLocalMinPoly(t,a,o);this.setZ(t,a,e.pt)}else{s=this.addOutPt(t,o),this.setZ(t,a,s.pt);let e=this.addOutPt(a,o);this.setZ(t,a,e.pt),this.swapOutrecs(t,a)}else if(e.isHotEdge(t))s=this.addOutPt(t,o),this.setZ(t,a,s.pt),this.swapOutrecs(t,a);else if(e.isHotEdge(a))s=this.addOutPt(a,o),this.setZ(t,a,s.pt),this.swapOutrecs(t,a);else{let u,d;switch(this.fillrule){case i.Positive:u=t.windCount2,d=a.windCount2;break;case i.Negative:u=-t.windCount2,d=-a.windCount2;break;default:u=Math.abs(t.windCount2),d=Math.abs(a.windCount2);break}if(!e.isSamePolyType(t,a))s=this.addLocalMinPoly(t,a,o),this.setZ(t,a,s.pt);else if(c===1&&l===1){switch(s=null,this.cliptype){case n.Union:if(u>0&&d>0)return;s=this.addLocalMinPoly(t,a,o);break;case n.Difference:(e.getPolyType(t)===r.Clip&&u>0&&d>0||e.getPolyType(t)===r.Subject&&u<=0&&d<=0)&&(s=this.addLocalMinPoly(t,a,o));break;case n.Xor:s=this.addLocalMinPoly(t,a,o);break;default:if(u<=0||d<=0)return;s=this.addLocalMinPoly(t,a,o);break}s&&this.setZ(t,a,s.pt)}}}swapPositionsInAEL(e,t){let n=t.nextInAEL;n!==null&&(n.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=t),t.prevInAEL=r,t.nextInAEL=e,e.prevInAEL=t,e.nextInAEL=n,t.prevInAEL===null&&(this.actives=t)}isValidAelOrder(t,n){if(n.curX!==t.curX)return n.curX>t.curX;let r=C.crossProductSign(t.top,n.bot,n.top);if(r!==0)return r<0;if(!e.isMaxima(t)&&t.top.y>n.top.y)return C.crossProductSign(n.bot,t.top,e.nextVertex(t).pt)<=0;if(!e.isMaxima(n)&&n.top.y>t.top.y)return C.crossProductSign(n.bot,n.top,e.nextVertex(n).pt)>=0;let i=n.bot.y,a=n.isLeftBound;return t.bot.y!==i||t.localMin.vertex.pt.y!==i?n.isLeftBound:t.isLeftBound===a?C.isCollinear(e.prevPrevVertex(t).pt,t.bot,t.top)?!0:C.crossProductSign(e.prevPrevVertex(t).pt,n.bot,e.prevPrevVertex(n).pt)>0===a:a}isJoined(e){return e.joinWith!==j.None}split(e,t){e.joinWith===j.Right?(e.joinWith=j.None,e.nextInAEL.joinWith=j.None,this.addLocalMinPoly(e,e.nextInAEL,t,!0)):(e.joinWith=j.None,e.prevInAEL.joinWith=j.None,this.addLocalMinPoly(e.prevInAEL,e,t,!0))}setSides(e,t,n){e.frontEdge=t,e.backEdge=n}findEdgeWithMatchingLocMin(t){let n=t.nextInAEL;for(;n!==null;){if(n.localMin?.equals(t.localMin))return n;n=!e.isHorizontal(n)&&!(t.bot.x===n.bot.x&&t.bot.y===n.bot.y)?null:n.nextInAEL}for(n=t.prevInAEL;n!==null;){if(n.localMin?.equals(t.localMin))return n;if(!e.isHorizontal(n)&&!(t.bot.x===n.bot.x&&t.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(t,n){let r=t.outrec,i=e.isFront(t),a=r.pts,o=a.next;if(i&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!i&&n.x===o.pt.x&&n.y===o.pt.y)return o;let s=new A(n,r);return o.prev=s,s.prev=a,s.next=o,a.next=s,i&&(r.pts=s),s}addLocalMaxPoly(t,n,r){if(this.isJoined(t)&&this.split(t,r),this.isJoined(n)&&this.split(n,r),e.isFront(t)===e.isFront(n))if(e.isOpenEnd(t))this.swapFrontBackSides(t.outrec);else if(e.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let i=this.addOutPt(t,r);if(t.outrec===n.outrec){let n=t.outrec;if(n.pts=i,this.usingPolytree){let r=e.getPrevHotEdge(t);r===null?n.owner=null:this.setOwner(n,r.outrec)}this.uncoupleOutRec(t)}else e.isOpen(t)?t.windDx<0?this.joinOutrecPaths(t,n):this.joinOutrecPaths(n,t):t.outrec.idx<n.outrec.idx?this.joinOutrecPaths(t,n):this.joinOutrecPaths(n,t);return i}swapFrontBackSides(e){let t=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=t,e.pts=e.pts.next}setOwner(e,t){for(;t.owner!==null&&t.owner.pts===null;)t.owner=t.owner.owner;let n=t;for(;n!==null&&n!==e;)n=n.owner;n!==null&&(t.owner=e.owner),e.owner=t}uncoupleOutRec(e){let t=e.outrec;t!==null&&(t.frontEdge.outrec=null,t.backEdge.outrec=null,t.frontEdge=null,t.backEdge=null)}joinOutrecPaths(t,n){let r=t.outrec.pts,i=n.outrec.pts,a=r.next,o=i.next;e.isFront(t)?(o.prev=r,r.next=o,i.next=a,a.prev=i,t.outrec.pts=i,t.outrec.frontEdge=n.outrec.frontEdge,t.outrec.frontEdge!==null&&(t.outrec.frontEdge.outrec=t.outrec)):(a.prev=i,i.next=a,r.next=o,o.prev=r,t.outrec.backEdge=n.outrec.backEdge,t.outrec.backEdge!==null&&(t.outrec.backEdge.outrec=t.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,t.outrec),e.isOpenEnd(t)&&(n.outrec.pts=t.outrec.pts,t.outrec.pts=null),t.outrec=null,n.outrec=null}swapOutrecs(e,t){let n=e.outrec,r=t.outrec;if(n===r){let e=n.frontEdge;n.frontEdge=n.backEdge,n.backEdge=e;return}n!==null&&(e===n.frontEdge?n.frontEdge=t:n.backEdge=t),r!==null&&(t===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,t.outrec=n}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,t){return Math.abs(e.x-t.x)<2&&Math.abs(e.y-t.y)<2}static isVerySmallTriangle(t){return t.next.next===t.prev&&(e.ptsReallyClose(t.prev.pt,t.next.pt)||e.ptsReallyClose(t.pt,t.next.pt)||e.ptsReallyClose(t.pt,t.prev.pt))}static buildPath(t,n,r,i){if(t===null||t.next===t||!r&&t.next===t.prev)return!1;i.length=0;let a,o;for(n?(a=t.pt,o=t.prev):(t=t.next,a=t.pt,o=t.next),i.push(a);o!==t;)o.pt.x===a.x&&o.pt.y===a.y||(a=o.pt,i.push(a)),o=n?o.prev:o.next;return i.length!==3||r||!e.isVerySmallTriangle(o)}buildPaths(t,n){t.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let i=this.outrecList[r++];if(i.pts===null)continue;let a=[];i.isOpen?e.buildPath(i.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(i),e.buildPath(i.pts,this.reverseSolution,!1,a)&&t.push(a))}return!0}buildTree(t,n){t.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let i=this.outrecList[r++];if(i.pts!==null){if(i.isOpen){let t=[];e.buildPath(i.pts,this.reverseSolution,!0,t)&&n.push(t);continue}this.checkBounds(i)&&this.recursiveCheckOwners(i,t)}}}checkBounds(t){return t.pts===null?!1:E.isEmpty(t.bounds)?(this.cleanCollinear(t),t.pts===null||!e.buildPath(t.pts,this.reverseSolution,!1,t.path)?!1:(t.bounds=C.getBounds(t.path),!0)):!0}recursiveCheckOwners(e,t){if(!(e.polypath!==null||E.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner===null?e.polypath=t.addChild(e.path):(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,t),e.polypath=e.owner.polypath.addChild(e.path))}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let t=e.pts,n=t,r=!1;for(;;){if(n!==null&&C.isCollinear(n.prev.pt,n.pt,n.next.pt)&&(n.pt.x===n.prev.pt.x&&n.pt.y===n.prev.pt.y||n.pt.x===n.next.pt.x&&n.pt.y===n.next.pt.y||!this.preserveCollinear||C.dotProductSign(n.prev.pt,n.pt,n.next.pt)<0)){if(n===e.pts&&(e.pts=n.prev),n=this.disposeOutPt(n),r=!0,!this.isValidClosedPath(n)){e.pts=null;return}t=n;continue}if(n===null||(n=n.next,n===t))break}r&&this.fixSelfIntersects(e)}isValidClosedPath(t){return t!==null&&t.next!==t&&(t.next!==t.prev||!e.isVerySmallTriangle(t))}disposeOutPt(e){let t=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,t}fixSelfIntersects(e){let t=e.pts;if(t.prev!==t.next.next)for(;;){if(t.next&&t.next.next&&this.boundingBoxesOverlap(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)&&C.segsIntersect(t.prev.pt,t.pt,t.next.pt,t.next.next.pt))if(t.next.next.next&&this.boundingBoxesOverlap(t.prev.pt,t.pt,t.next.next.pt,t.next.next.next.pt)&&C.segsIntersect(t.prev.pt,t.pt,t.next.next.pt,t.next.next.next.pt))t=this.duplicateOp(t,!1),t.pt=t.next.next.next.pt,t=t.next;else{if((t===e.pts||t.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,t),e.pts===null)return;if(t=e.pts,t.prev===t.next.next)break;continue}if(t=t.next,t===e.pts)break}}doSplitOp(t,n){let r=n.prev,i=n.next.next;t.pts=r;let a=C.getLineIntersectPt(r.pt,n.pt,n.next.pt,i.pt),o=e.areaOutPt(r),s=o<Oe?-o:o;if(s<Ae){t.pts=null;return}let c=this.areaTriangle(a,n.pt,n.next.pt),l=c<Oe?-c:c;if(a.x===r.pt.x&&a.y===r.pt.y||a.x===i.pt.x&&a.y===i.pt.y)i.prev=r,r.next=i;else{let e=new A(a,t);e.prev=r,e.next=i,i.prev=e,r.next=e}if(!(l>ke)||!(l>s)&&c>Oe!=o>Oe)return;let u=this.newOutRec();u.owner=t.owner,n.outrec=u,n.next.outrec=u;let d=new A(a,u);d.prev=n.next,d.next=n,u.pts=d,n.prev=d,n.next.next=d,this.usingPolytree&&(this.path1InsidePath2(r,d)?(u.splits===null&&(u.splits=[]),u.splits.push(t.idx)):(t.splits===null&&(t.splits=[]),t.splits.push(u.idx)))}static areaOutPt(e){let t=C.maxCoordForSafeAreaProduct,n=0,r=!0,i=e;do{let e=i.prev,a=i.pt;if(Math.abs(e.pt.x)>=t||Math.abs(e.pt.y)>=t||Math.abs(a.x)>=t||Math.abs(a.y)>=t){r=!1;break}n+=(e.pt.y+a.y)*(e.pt.x-a.x),i=i.next}while(i!==e);if(r)return BigInt(Math.round(n));let a=Oe;i=e;do{let e=i.prev;if(Number.isSafeInteger(e.pt.y)&&Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(e.pt.x)&&Number.isSafeInteger(i.pt.x)){let t=BigInt(e.pt.y)+BigInt(i.pt.y),n=BigInt(e.pt.x)-BigInt(i.pt.x);a+=t*n}else{let t=e.pt.y+i.pt.y,n=e.pt.x-i.pt.x;a+=BigInt(Math.round(t*n))}i=i.next}while(i!==e);return a}areaTriangle(e,t,n){let r=C.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(t.x)<r&&Math.abs(t.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r){let r=(n.y+e.y)*(n.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+n.y)*(t.x-n.x);return BigInt(Math.round(r))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)){let r=(BigInt(n.y)+BigInt(e.y))*(BigInt(n.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(t.y))*(BigInt(e.x)-BigInt(t.x)),a=(BigInt(t.y)+BigInt(n.y))*(BigInt(t.x)-BigInt(n.x));return r+i+a}let i=(n.y+e.y)*(n.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+n.y)*(t.x-n.x);return BigInt(Math.round(i))}isValidOwner(e,t){for(;t!==null&&t!==e;)t=t.owner;return t===null}containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom}checkSplitOwner(e,t){for(let n=0;n<t.length;n++){let r=this.outrecList[t[n]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}},P=class extends N{zCallback;getZCallback(){return this.zCallback}addPath(e,t,n=!1){super.addPath(e,t,n)}addReuseableData(e){super.addReuseableData(e)}addPaths(e,t,n=!1){super.addPaths(e,t,n)}addSubject(e){this.addPaths(e,r.Subject)}addOpenSubject(e){this.addPaths(e,r.Subject,!0)}addClip(e){this.addPaths(e,r.Clip)}execute(e,t,n,r){if(Array.isArray(n)){let i=n,a=r;i.length=0,a&&(a.length=0);try{this.executeInternal(e,t),this.buildPaths(i,a||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let i=n,a=r;i.clear(),a&&(a.length=0),this.usingPolytree=!0;try{this.executeInternal(e,t),this.buildTree(i,a||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}},qe=class extends N{zCallback;scale;invScale;constructor(e=2){super(),C.checkPrecision(e),this.scale=10**e,this.invScale=1/this.scale}getZCallback(){return this.zCallback}scalePathDFromInt(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t,z:r.z||0});return n}buildPathsD(e,t){e.length=0,t.length=0;let n=0;for(;n<this.outrecList.length;){let r=this.outrecList[n++];if(r.pts===null)continue;let i=[];r.isOpen?N.buildPath(r.pts,this.reverseSolution,!0,i)&&t.push(this.scalePathDFromInt(i,this.invScale)):(this.cleanCollinear(r),N.buildPath(r.pts,this.reverseSolution,!1,i)&&e.push(this.scalePathDFromInt(i,this.invScale)))}return!0}buildTreeD(e,t){e.clear(),t.length=0;let n=0;for(;n<this.outrecList.length;){let r=this.outrecList[n++];if(r.pts!==null){if(r.isOpen){let e=[];N.buildPath(r.pts,this.reverseSolution,!0,e)&&t.push(this.scalePathDFromInt(e,this.invScale));continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}addPath(e,t,n=!1){super.addPath(F.scalePath64(e,this.scale),t,n)}addPaths(e,t,n=!1){super.addPaths(F.scalePaths64(e,this.scale),t,n)}addSubject(e){this.addPath(e,r.Subject)}addOpenSubject(e){this.addPath(e,r.Subject,!0)}addClip(e){this.addPath(e,r.Clip)}addSubjectPaths(e){this.addPaths(e,r.Subject)}addOpenSubjectPaths(e){this.addPaths(e,r.Subject,!0)}addClipPaths(e){this.addPaths(e,r.Clip)}execute(e,t,n,r){if(Array.isArray(n)){let i=n,a=r,o=[],s=[];i.length=0,a&&(a.length=0);let c=!0;try{this.executeInternal(e,t),this.buildPaths(o,s)}catch{c=!1}if(this.clearSolutionOnly(),!c)return!1;for(let e of o)i.push(this.scalePathDFromInt(e,this.invScale));if(a)for(let e of s)a.push(this.scalePathDFromInt(e,this.invScale));return!0}else{let i=n,a=r;i.clear(),a&&(a.length=0),this.usingPolytree=!0,i.scale=this.scale;let o=!0;try{this.executeInternal(e,t),this.buildTreeD(i,a||[])}catch{o=!1}return this.clearSolutionOnly(),o}}};const F={area(e){return C.area(e)},areaD(e){let t=0,n=e.length;if(n<3)return 0;let r=e[n-1];for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5},scalePath64(e,t){let n=C.maxSafeCoordinateForScale(t),r=[];for(let i of e)C.checkSafeScaleValue(i.x,n,`scalePath64`),C.checkSafeScaleValue(i.y,n,`scalePath64`),r.push({x:Math.round(i.x*t),y:Math.round(i.y*t)});return r},scalePaths64(e,t){let n=[];for(let r of e)n.push(F.scalePath64(r,t));return n},scalePathD(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t});return n},scalePathsD(e,t){let n=[];for(let r of e)n.push(F.scalePathD(r,t));return n}};let I=function(e){return e[e.Miter=0]=`Miter`,e[e.Square=1]=`Square`,e[e.Bevel=2]=`Bevel`,e[e.Round=3]=`Round`,e}({}),L=function(e){return e[e.Polygon=0]=`Polygon`,e[e.Joined=1]=`Joined`,e[e.Butt=2]=`Butt`,e[e.Square=3]=`Square`,e[e.Round=4]=`Round`,e}({});var Je=class{inPaths;joinType;endType;pathsReversed;lowestPathIdx;constructor(e,t,n=L.Polygon){this.joinType=t,this.endType=n;let r=n===L.Polygon||n===L.Joined;this.inPaths=[];for(let t of e)this.inPaths.push(Ye.stripDuplicates(t,r));if(n===L.Polygon){let e=Ye.getLowestPathInfo(this.inPaths);this.lowestPathIdx=e.idx,this.pathsReversed=this.lowestPathIdx>=0&&e.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},Ye=class e{static Tolerance=1e-12;static arc_const=.002;groupList=[];pathOut=[];normals=[];solution=[];solutionTree=null;groupDelta=0;delta=0;mitLimSqr=0;stepsPerRad=0;stepSin=0;stepCos=0;joinType=I.Bevel;endType=L.Polygon;arcTolerance=0;mergeGroups=!0;miterLimit=2;preserveCollinear=!1;reverseSolution=!1;zCallback;deltaCallback=null;constructor(e=2,t=0,n=!1,r=!1){this.miterLimit=e,this.arcTolerance=t,this.mergeGroups=!0,this.preserveCollinear=n,this.reverseSolution=r}clear(){this.groupList.length=0}ZCB=(e,t,n,r,i)=>{(e.z||0)!==0&&(e.z===n.z||e.z===r.z)?i.z=e.z:(n.z||0)!==0&&n.z===t.z?i.z=n.z:(t.z||0)!==0&&t.z===r.z?i.z=t.z:this.zCallback&&this.zCallback(e,t,n,r,i)};addPath(e,t,n){if(e.length===0)return;let r=[e];this.addPaths(r,t,n)}addPaths(e,t,n){e.length!==0&&this.groupList.push(new Je(e,t,n))}calcSolutionCapacity(){let e=0;for(let t of this.groupList)e+=t.endType===L.Joined?t.inPaths.length*2:t.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let t of this.groupList)if(t.endType===L.Polygon){e=t.pathsReversed;break}return e}executeInternal(t){if(this.groupList.length===0)return;if(Math.abs(t)<.5){for(let e of this.groupList)for(let t of e.inPaths)this.solution.push(t);return}this.delta=t,this.mitLimSqr=this.miterLimit<=1?2:2/e.sqr(this.miterLimit);for(let e of this.groupList)this.doGroupOffset(e);if(this.groupList.length===0)return;let r=this.checkPathsReversed(),a=r?i.Negative:i.Positive,o=new P;o.preserveCollinear=this.preserveCollinear,o.reverseSolution=this.reverseSolution!==r,o.zCallback=this.ZCB,o.addSubject(this.solution),this.solutionTree===null?o.execute(n.Union,a,this.solution):o.execute(n.Union,a,this.solutionTree)}execute(e,t){if(Array.isArray(t)){let n=t;n.length=0,this.solution=n,this.executeInternal(e)}else{let n=t;n.clear(),this.solutionTree=n,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,t){this.deltaCallback=e,this.execute(1,t)}static getUnitNormal(e,t){let n=t.x-e.x,r=t.y-e.y;if(n===0&&r===0)return{x:0,y:0};let i=1/Math.sqrt(n*n+r*r);return{x:r*i,y:-n*i}}static getLowestPathInfo(t){let n=-1,r=!1,i={x:2**53-1,y:-(2**53-1)};for(let a=0;a<t.length;++a){let o=Number.MAX_VALUE;for(let s of t[a])if(!(s.y<i.y||s.y===i.y&&s.x>=i.x)){if(o===Number.MAX_VALUE){if(o=e.area(t[a]),o===0)break;r=o<0}n=a,i.x=s.x,i.y=s.y}}return{idx:n,isNegArea:r}}static translatePoint(e,t,n){return{x:e.x+t,y:e.y+n,z:e.z}}static reflectPoint(e,t){return{x:t.x+(t.x-e.x),y:t.y+(t.y-e.y),z:e.z}}static almostZero(e,t=.001){return Math.abs(e)<t}static hypotenuse(e,t){return Math.sqrt(e*e+t*t)}static normalizeVector(t){let n=e.hypotenuse(t.x,t.y);if(e.almostZero(n))return{x:0,y:0};let r=1/n;return{x:t.x*r,y:t.y*r}}static getAvgUnitVector(t,n){return e.normalizeVector({x:t.x+n.x,y:t.y+n.y})}static intersectPoint(e,t,n,r){if(C.isAlmostZero(e.x-t.x)){if(C.isAlmostZero(n.x-r.x))return{x:0,y:0};let t=(r.y-n.y)/(r.x-n.x),i=n.y-t*n.x;return{x:e.x,y:t*e.x+i}}if(C.isAlmostZero(n.x-r.x)){let r=(t.y-e.y)/(t.x-e.x),i=e.y-r*e.x;return{x:n.x,y:r*n.x+i}}else{let i=(t.y-e.y)/(t.x-e.x),a=e.y-i*e.x,o=(r.y-n.y)/(r.x-n.x),s=n.y-o*n.x;if(C.isAlmostZero(i-o))return{x:0,y:0};let c=(s-a)/(i-o);return{x:c,y:i*c+a}}}getPerpendic(e,t){return{x:Math.round(e.x+t.x*this.groupDelta),y:Math.round(e.y+t.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,t){return{x:e.x+t.x*this.groupDelta,y:e.y+t.y*this.groupDelta,z:e.z||0}}doBevel(e,t,n){let r,i,a=e[t].z||0;if(t===n){let n=Math.abs(this.groupDelta);r={x:Math.round(e[t].x-n*this.normals[t].x),y:Math.round(e[t].y-n*this.normals[t].y),z:a},i={x:Math.round(e[t].x+n*this.normals[t].x),y:Math.round(e[t].y+n*this.normals[t].y),z:a}}else r={x:Math.round(e[t].x+this.groupDelta*this.normals[n].x),y:Math.round(e[t].y+this.groupDelta*this.normals[n].y),z:a},i={x:Math.round(e[t].x+this.groupDelta*this.normals[t].x),y:Math.round(e[t].y+this.groupDelta*this.normals[t].y),z:a};this.pathOut.push(r),this.pathOut.push(i)}doSquare(t,n,r){let i;i=n===r?{x:this.normals[n].y,y:-this.normals[n].x}:e.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),o={x:t[n].x,y:t[n].y,z:t[n].z||0};o=e.translatePoint(o,a*i.x,a*i.y);let s=e.translatePoint(o,this.groupDelta*i.y,this.groupDelta*-i.x),c=e.translatePoint(o,this.groupDelta*-i.y,this.groupDelta*i.x),l=this.getPerpendicD(t[r],this.normals[r]);if(n===r){let t={x:l.x+i.x*this.groupDelta,y:l.y+i.y*this.groupDelta},n=e.intersectPoint(s,c,l,t);n.z=o.z,this.pathOut.push(w.fromPointD(e.reflectPoint(n,o))),this.pathOut.push(w.fromPointD(n))}else{let i=this.getPerpendicD(t[n],this.normals[r]),a=e.intersectPoint(s,c,l,i);a.z=o.z,this.pathOut.push(w.fromPointD(a)),this.pathOut.push(w.fromPointD(e.reflectPoint(a,o)))}}doMiter(e,t,n,r){let i=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[t].x+(this.normals[n].x+this.normals[t].x)*i),y:Math.round(e[t].y+(this.normals[n].y+this.normals[t].y)*i),z:e[t].z||0})}doRound(t,n,r,i){if(this.deltaCallback!==null){let t=Math.abs(this.groupDelta),n=this.arcTolerance>.01?this.arcTolerance:t*e.arc_const,r=Math.PI/Math.acos(1-n/t);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}let a=t[n],o=a.z||0,s={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&T.negate(s),this.pathOut.push({x:Math.round(a.x+s.x),y:Math.round(a.y+s.y),z:o});let c=Math.ceil(this.stepsPerRad*Math.abs(i));for(let e=1;e<c;e++)s={x:s.x*this.stepCos-this.stepSin*s.y,y:s.x*this.stepSin+s.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+s.x),y:Math.round(a.y+s.y),z:o});this.pathOut.push(this.getPerpendic(t[n],this.normals[n]))}buildNormals(t){let n=t.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(e.getUnitNormal(t[r],t[r+1]));this.normals.push(e.getUnitNormal(t[n-1],t[0]))}}offsetPoint(t,n,r,i){if(w.equals(n[r],n[i]))return;let a=C.crossProductD(this.normals[r],this.normals[i]),o=C.dotProductD(this.normals[r],this.normals[i]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,i),t.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<e.Tolerance){this.pathOut.push(n[r]);return}if(o>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[i])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(o>.999&&this.joinType!==I.Round)this.doMiter(n,r,i,o);else switch(this.joinType){case I.Miter:o>this.mitLimSqr-1?this.doMiter(n,r,i,o):this.doSquare(n,r,i);break;case I.Round:this.doRound(n,r,i,Math.atan2(a,o));break;case I.Bevel:this.doBevel(n,r,i);break;default:this.doSquare(n,r,i);break}}offsetPolygon(e,t){this.pathOut=[];let n=t.length,r=n-1;for(let i=0;i<n;i++)this.offsetPoint(e,t,i,r),r=i;this.solution.push(this.pathOut)}offsetOpenJoined(e,t){this.offsetPolygon(e,t);let n=[...t].reverse();this.buildNormals(n),this.offsetPolygon(e,n)}offsetOpenPath(t,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<e.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case L.Butt:this.doBevel(n,0,0);break;case L.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let e=1,i=0;e<r;e++)this.offsetPoint(t,n,e,i),i=e;for(let e=r;e>0;e--)this.normals[e]={x:-this.normals[e-1].x,y:-this.normals[e-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<e.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case L.Butt:this.doBevel(n,r,r);break;case L.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let e=r-1,i=r;e>0;e--)this.offsetPoint(t,n,e,i),i=e;this.solution.push(this.pathOut)}doGroupOffset(t){t.endType===L.Polygon?(t.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=t.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=t.joinType,this.endType=t.endType,t.joinType===I.Round||t.endType===L.Round){let t=this.arcTolerance>.01?this.arcTolerance:n*e.arc_const,r=Math.PI/Math.acos(1-t/n);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}for(let n of t.inPaths){this.pathOut=[];let r=n.length;if(r===1){let r=n[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0),t.pathsReversed&&(this.groupDelta=-this.groupDelta));let i=r.z||0;if(t.endType===L.Round){let t=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=e.ellipse(r,Math.abs(this.groupDelta),Math.abs(this.groupDelta),t),i!==0)for(let e=0;e<this.pathOut.length;e++)this.pathOut[e].z=i}else{let e=Math.ceil(Math.abs(this.groupDelta)),t={left:r.x-e,top:r.y-e,right:r.x+e,bottom:r.y+e};this.pathOut=[{x:t.left,y:t.top,z:i},{x:t.right,y:t.top,z:i},{x:t.right,y:t.bottom,z:i},{x:t.left,y:t.bottom,z:i}]}this.solution.push(this.pathOut);continue}switch(r===2&&t.endType===L.Joined&&(this.endType=t.joinType===I.Round?L.Round:L.Square),this.buildNormals(n),this.endType){case L.Polygon:this.offsetPolygon(t,n);break;case L.Joined:this.offsetOpenJoined(t,n);break;default:this.offsetOpenPath(t,n);break}}}static stripDuplicates(e,t){let n=e.length,r=[];if(n===0)return r;let i=e[0];r.push(i);for(let t=1;t<n;t++)w.equals(i,e[t])||(i=e[t],r.push(i));return t&&w.equals(i,r[0])&&r.pop(),r}static area(e){return C.area(e)}static sqr(e){return e*e}static ellipse(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:Math.round(e.x+t),y:e.y}];for(let l=1;l<r;++l){c.push({x:Math.round(e.x+t*o),y:Math.round(e.y+n*s)});let r=o*a-s*i;s=s*a+o*i,o=r}return c}},Xe=class{next=null;prev=null;pt;ownerIdx=0;edge=null;constructor(e){this.pt=e}},R=function(e){return e[e.left=0]=`left`,e[e.top=1]=`top`,e[e.right=2]=`right`,e[e.bottom=3]=`bottom`,e[e.inside=4]=`inside`,e}(R||{}),z=class e{rect;mp;rectPath;pathBounds={left:0,top:0,right:0,bottom:0};results=[];edges=[];currIdx=-1;constructor(e){this.currIdx=-1,this.rect=e,this.mp=E.midPoint(e),this.rectPath=E.asPath(this.rect),this.results=[],this.edges=[];for(let e=0;e<8;e++)this.edges[e]=[]}add(e,t=!1){let n=this.results.length,r;if(n===0||t)r=new Xe(e),this.results.push(r),r.ownerIdx=n,r.prev=r,r.next=r;else{n--;let t=this.results[n];if(t&&w.equals(t.pt,e))return t;r=new Xe(e),r.ownerIdx=n,r.next=t.next,t.next.prev=r,t.next=r,r.prev=t,this.results[n]=r}return r}static path1ContainsPath2(e,t){let n=0;for(let r of t){switch(C.pointInPolygon(r,e)){case a.IsInside:n--;break;case a.IsOutside:n++;break}if(Math.abs(n)>1)break}return n<=0}static isClockwise(t,n,r,i,a){return e.areOpposites(t,n)?C.crossProductSign(r,a,i)<0:e.headingClockwise(t,n)}static areOpposites(e,t){return Math.abs(e-t)===2}static headingClockwise(e,t){return(e+1)%4===t}static getAdjacentLocation(e,t){return(e+(t?1:3))%4}static unlinkOp(e){return e.next===e?null:(e.prev.next=e.next,e.next.prev=e.prev,e.next)}static unlinkOpBack(e){return e.next===e?null:(e.prev.next=e.next,e.next.prev=e.prev,e.prev)}static getEdgesForPt(e,t){let n=0;return e.x===t.left?n=1:e.x===t.right&&(n=4),e.y===t.top?n+=2:e.y===t.bottom&&(n+=8),n}static isHeadingClockwise(e,t,n){switch(n){case 0:return t.y<e.y;case 1:return t.x>e.x;case 2:return t.y>e.y;default:return t.x<e.x}}static hasHorzOverlap(e,t,n,r){return e.x<r.x&&t.x>n.x}static hasVertOverlap(e,t,n,r){return e.y<r.y&&t.y>n.y}static addToEdge(e,t){t.edge===null&&(t.edge=e,e.push(t))}static uncoupleEdge(e){if(e.edge!==null){for(let t=0;t<e.edge.length;t++)if(e.edge[t]===e){e.edge[t]=null;break}e.edge=null}}static setNewOwner(e,t){e.ownerIdx=t;let n=e.next;for(;n!==e;)n.ownerIdx=t,n=n.next}addCorner(t,n){this.add(e.headingClockwise(t,n)?this.rectPath[t]:this.rectPath[n])}addCornerWithDirection(t,n){if(n)return this.add(this.rectPath[t]),e.getAdjacentLocation(t,!0);{let n=e.getAdjacentLocation(t,!1);return this.add(this.rectPath[n]),n}}static getLocation(e,t){if(t.x===e.left&&t.y>=e.top&&t.y<=e.bottom)return{location:R.left,isOnRect:!0};if(t.x===e.right&&t.y>=e.top&&t.y<=e.bottom)return{location:R.right,isOnRect:!0};if(t.y===e.top&&t.x>=e.left&&t.x<=e.right)return{location:R.top,isOnRect:!0};if(t.y===e.bottom&&t.x>=e.left&&t.x<=e.right)return{location:R.bottom,isOnRect:!0};let n;return n=t.x<e.left?R.left:t.x>e.right?R.right:t.y<e.top?R.top:t.y>e.bottom?R.bottom:R.inside,{location:n,isOnRect:!1}}static isHorizontal(e,t){return e.y===t.y}static getSegmentIntersection(t,n,r,i){let a=C.crossProductSign(t,r,i),o=C.crossProductSign(n,r,i);if(a===0)return o===0?null:w.equals(t,r)||w.equals(t,i)?t:e.isHorizontal(r,i)?t.x>r.x==t.x<i.x?t:null:t.y>r.y==t.y<i.y?t:null;if(o===0)return w.equals(n,r)||w.equals(n,i)?n:e.isHorizontal(r,i)?n.x>r.x==n.x<i.x?n:null:n.y>r.y==n.y<i.y?n:null;if(a===o)return null;let s=C.crossProductSign(r,t,n),c=C.crossProductSign(i,t,n);return s===0?w.equals(r,t)||w.equals(r,n)?r:e.isHorizontal(t,n)?r.x>t.x==r.x<n.x?r:null:r.y>t.y==r.y<n.y?r:null:c===0?w.equals(i,t)||w.equals(i,n)?i:e.isHorizontal(t,n)?i.x>t.x==i.x<n.x?i:null:i.y>t.y==i.y<n.y?i:null:s===c?null:C.getLineIntersectPt(t,n,r,i)}static _intResult={intersects:!1,point:{x:0,y:0},newLocation:R.inside};static getIntersection(t,n,r,i){let a=e._intResult,o;switch(a.newLocation=i,i){case R.left:return o=e.getSegmentIntersection(n,r,t[0],t[3]),o===null?n.y<t[0].y&&(o=e.getSegmentIntersection(n,r,t[0],t[1]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=R.top,a):(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=R.bottom,a)):(a.intersects=!0,a.point=o,a);case R.right:return o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?n.y<t[0].y&&(o=e.getSegmentIntersection(n,r,t[0],t[1]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=R.top,a):(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=R.bottom,a)):(a.intersects=!0,a.point=o,a);case R.top:return o=e.getSegmentIntersection(n,r,t[0],t[1]),o===null?n.x<t[0].x&&(o=e.getSegmentIntersection(n,r,t[0],t[3]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=R.left,a):n.x<=t[1].x?(a.intersects=!1,a):(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=R.right,a)):(a.intersects=!0,a.point=o,a);case R.bottom:return o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?n.x<t[3].x&&(o=e.getSegmentIntersection(n,r,t[0],t[3]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=R.left,a):n.x<=t[2].x?(a.intersects=!1,a):(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=R.right,a)):(a.intersects=!0,a.point=o,a);default:return o=e.getSegmentIntersection(n,r,t[0],t[3]),o===null?(o=e.getSegmentIntersection(n,r,t[0],t[1]),o===null?(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=R.bottom,a)):(a.intersects=!0,a.point=o,a.newLocation=R.right,a)):(a.intersects=!0,a.point=o,a.newLocation=R.top,a)):(a.intersects=!0,a.point=o,a.newLocation=R.left,a)}}getNextLocation(e,t,n,r){let i=n,a=t;switch(t){case R.left:for(;i<=r&&e[i].x<=this.rect.left;)i++;if(i>r)break;a=e[i].x>=this.rect.right?R.right:e[i].y<=this.rect.top?R.top:e[i].y>=this.rect.bottom?R.bottom:R.inside;break;case R.top:for(;i<=r&&e[i].y<=this.rect.top;)i++;if(i>r)break;a=e[i].y>=this.rect.bottom?R.bottom:e[i].x<=this.rect.left?R.left:e[i].x>=this.rect.right?R.right:R.inside;break;case R.right:for(;i<=r&&e[i].x>=this.rect.right;)i++;if(i>r)break;a=e[i].x<=this.rect.left?R.left:e[i].y<=this.rect.top?R.top:e[i].y>=this.rect.bottom?R.bottom:R.inside;break;case R.bottom:for(;i<=r&&e[i].y>=this.rect.bottom;)i++;if(i>r)break;a=e[i].y<=this.rect.top?R.top:e[i].x<=this.rect.left?R.left:e[i].x>=this.rect.right?R.right:R.inside;break;case R.inside:for(;i<=r;){if(e[i].x<this.rect.left)a=R.left;else if(e[i].x>this.rect.right)a=R.right;else if(e[i].y>this.rect.bottom)a=R.bottom;else if(e[i].y<this.rect.top)a=R.top;else{this.add(e[i]),i++;continue}break}break}return{location:a,index:i}}static startLocsAreClockwise(e){let t=0;for(let n=1;n<e.length;n++)switch(e[n]-e[n-1]){case-1:--t;break;case 1:t+=1;break;case-3:t+=1;break;case 3:--t;break}return t>0}executeInternal(t){if(t.length<3||E.isEmpty(this.rect))return;let n=[],r=R.inside,i=r,a=r,o=t.length-1,s=e.getLocation(this.rect,t[o]),c=s.location;if(s.isOnRect){let n=o-1;for(;n>=0;){let r=e.getLocation(this.rect,t[n]);if(!r.isOnRect){a=r.location;break}n--}if(n<0){for(let e of t)this.add(e);return}a===R.inside&&(c=R.inside)}let l=c,u=0;for(;u<=o;){a=c;let s=i,l=this.getNextLocation(t,c,u,o);if(c=l.location,u=l.index,u>o)break;let d=u===0?t[o]:t[u-1];i=c;let f=e.getIntersection(this.rectPath,t[u],d,i);if(!f.intersects){if(s===R.inside){let r=e.isClockwise(a,c,d,t[u],this.mp);do n.push(a),a=e.getAdjacentLocation(a,r);while(a!==c);i=s}else if(a!==R.inside&&a!==c){let n=e.isClockwise(a,c,d,t[u],this.mp);do a=this.addCornerWithDirection(a,n);while(a!==c)}++u;continue}let p=f.point;if(i=f.newLocation,c===R.inside){if(r===R.inside)r=i,n.push(a);else if(a!==i){let n=e.isClockwise(a,i,d,t[u],this.mp);do a=this.addCornerWithDirection(a,n);while(a!==i)}}else if(a!==R.inside){c=a;let o=e.getIntersection(this.rectPath,d,t[u],c).point;if(s!==R.inside&&s!==c&&this.addCorner(s,c),r===R.inside&&(r=c,n.push(a)),c=i,this.add(o),w.equals(p,o)){c=e.getLocation(this.rect,t[u]).location,this.addCorner(i,c),i=c;continue}}else c=i,r===R.inside&&(r=i);this.add(p)}if(r===R.inside){if(l===R.inside||!E.containsRect(this.pathBounds,this.rect)||!e.path1ContainsPath2(t,this.rectPath))return;let r=e.startLocsAreClockwise(n);for(let t=0;t<4;t++){let n=r?t:3-t;this.add(this.rectPath[n]),e.addToEdge(this.edges[n*2],this.results[0])}}else if(c!==R.inside&&(c!==r||n.length>2)){if(n.length>0){a=c;for(let t of n)a!==t&&(this.addCornerWithDirection(a,e.headingClockwise(a,t)),a=t);c=a}c!==r&&this.addCornerWithDirection(c,e.headingClockwise(c,r))}}execute(e){let t=[];if(E.isEmpty(this.rect))return t;for(let n of e)if(!(n.length<3)&&(this.pathBounds=C.getBounds(n),E.intersects(this.rect,this.pathBounds))){if(E.containsRect(this.rect,this.pathBounds)){t.push(n);continue}this.executeInternal(n),this.checkEdges();for(let e=0;e<4;++e)this.tidyEdgePair(e,this.edges[e*2],this.edges[e*2+1]);for(let e of this.results){let n=this.getPath(e);n.length>0&&t.push(n)}this.results.length=0;for(let e=0;e<8;e++)this.edges[e].length=0}return t}checkEdges(){for(let t=0;t<this.results.length;t++){let n=this.results[t],r=n;if(n===null)continue;do if(C.isCollinear(r.prev.pt,r.pt,r.next.pt)){if(r===n){if(r=e.unlinkOpBack(r),r===null)break;n=r.prev}else if(r=e.unlinkOpBack(r),r===null)break}else r=r.next;while(r!==n);if(r===null){this.results[t]=null;continue}this.results[t]=r;let i=e.getEdgesForPt(n.prev.pt,this.rect);r=n;do{let t=e.getEdgesForPt(r.pt,this.rect);if(t!==0&&r.edge===null){let n=i&t;for(let t=0;t<4;++t)n&1<<t&&(e.isHeadingClockwise(r.prev.pt,r.pt,t)?e.addToEdge(this.edges[t*2],r):e.addToEdge(this.edges[t*2+1],r))}i=t,r=r.next}while(r!==n)}}tidyEdgePair(t,n,r){if(r.length===0)return;let i=t===1||t===3,a=t===1||t===2,o=0,s=0;for(;o<n.length;){let t=n[o];if(t===null||t.next===t.prev){n[o++]=null,s=0;continue}let c=r.length;for(;s<c&&(r[s]===null||r[s].next===r[s].prev);)++s;if(s===c){++o,s=0;continue}let l,u,d;if(a?(t=n[o].prev,u=n[o],l=r[s],d=r[s].prev):(t=n[o],u=n[o].prev,l=r[s].prev,d=r[s]),i&&!e.hasHorzOverlap(t.pt,u.pt,l.pt,d.pt)||!i&&!e.hasVertOverlap(t.pt,u.pt,l.pt,d.pt)){++s;continue}let f=n[o].ownerIdx!==r[s].ownerIdx;if(f&&(this.results[l.ownerIdx]=null,e.setNewOwner(l,t.ownerIdx)),a?(t.next=l,l.prev=t,u.prev=d,d.next=u):(t.prev=l,l.next=t,u.next=d,d.prev=u),!f){let t=this.results.length;this.results.push(u),e.setNewOwner(u,t)}let p,m;a?(p=l,m=u):(p=t,m=d),this.results[p.ownerIdx]=p,this.results[m.ownerIdx]=m;let h,g;i?(h=p.pt.x>p.prev.pt.x,g=m.pt.x>m.prev.pt.x):(h=p.pt.y>p.prev.pt.y,g=m.pt.y>m.prev.pt.y),p.next===p.prev||w.equals(p.pt,p.prev.pt)?g===a?(n[o]=m,r[s++]=null):(r[s]=m,n[o++]=null):m.next===m.prev||w.equals(m.pt,m.prev.pt)?h===a?(n[o]=p,r[s++]=null):(r[s]=p,n[o++]=null):h===g?h===a?(n[o]=p,e.uncoupleEdge(m),e.addToEdge(n,m),r[s++]=null):(n[o++]=null,r[s]=m,e.uncoupleEdge(p),e.addToEdge(r,p),s=0):(h===a?n[o]=p:r[s]=p,g===a?n[o]=m:r[s]=m)}}getPath(t){let n=[];if(t===null||t.prev===t.next)return n;let r=t.next;for(;r!==null&&r!==t;)C.isCollinear(r.prev.pt,r.pt,r.next.pt)?(t=r.prev,r=e.unlinkOp(r)):r=r.next;if(r===null)return[];for(n.push(t.pt),r=t.next;r!==t;)n.push(r.pt),r=r.next;return n}},Ze=class extends z{constructor(e){super(e)}execute(e){let t=[];if(E.isEmpty(this.rect))return t;for(let n of e)if(!(n.length<2)&&(this.pathBounds=C.getBounds(n),E.intersects(this.rect,this.pathBounds))){this.executeInternalLines(n);for(let e of this.results){let n=this.getPathLines(e);n.length>0&&t.push(n)}this.results.length=0;for(let e=0;e<8;e++)this.edges[e].length=0}return t}getPathLines(e){let t=[];if(e===null||e===e.next)return t;e=e.next,t.push(e.pt);let n=e.next;for(;n!==e;)t.push(n.pt),n=n.next;return t}executeInternalLines(e){if(this.results.length=0,e.length<2||E.isEmpty(this.rect))return;let t=R.inside,n=1,r=e.length-1,i=z.getLocation(this.rect,e[0]),a=i.location;if(i.isOnRect){for(;n<=r;){let r=z.getLocation(this.rect,e[n]);if(!r.isOnRect){t=r.location;break}n++}if(n>r){for(let t of e)this.add(t);return}t===R.inside&&(a=R.inside),n=1}for(a===R.inside&&this.add(e[0]);n<=r;){t=a;let i=this.getNextLocation(e,a,n,r);if(a=i.location,n=i.index,n>r)break;let o=e[n-1],s=a,c=z.getIntersection(this.rectPath,e[n],o,s);if(!c.intersects){++n;continue}let l=c.point;if(a===R.inside)this.add(l,!0);else if(t!==R.inside){s=t;let r=z.getIntersection(this.rectPath,o,e[n],s).point;this.add(r,!0),this.add(l)}else this.add(l)}}};function Qe(e,t,n,r){let i=r?0:1,a=e.length,o=t.length,s=[];for(let r of t){let t=[];if(n)for(let n of e)t.push(w.add(r,n));else for(let n of e)t.push(w.subtract(r,n));s.push(t)}let c=[],l=r?o-1:0,u=a-1;for(let e=i;e<o;e++){for(let t=0;t<a;t++){let n=[s[l][u],s[e][u],s[e][t],s[l][t]];$e(n)?c.push(n):c.push(et(n)),u=t}l=e}return c}function $e(e){return C.area(e)>=0}function et(e){return[...e].reverse()}function tt(e,t){let n=C.maxSafeCoordinateForScale(t),r=[];for(let i of e)C.checkSafeScaleValue(i.x,n,`Minkowski.scalePath64`),C.checkSafeScaleValue(i.y,n,`Minkowski.scalePath64`),r.push({x:C.roundToEven(i.x*t),y:C.roundToEven(i.y*t)});return r}function nt(e,t){let n=[];for(let r of e){let e=[];for(let n of r)e.push({x:n.x*t,y:n.y*t});n.push(e)}return n}function rt(e,t){let i=[],a=new P;return a.addPaths(e,r.Subject),a.execute(n.Union,t,i),i}const it={sum(e,t,n){return rt(Qe(e,t,!0,n),i.NonZero)},sumD(e,t,n,r=2){let a=10**r;return nt(rt(Qe(tt(e,a),tt(t,a),!0,n),i.NonZero),1/a)},diff(e,t,n){return rt(Qe(e,t,!1,n),i.NonZero)},diffD(e,t,n,r=2){let a=10**r;return nt(rt(Qe(tt(e,a),tt(t,a),!1,n),i.NonZero),1/a)}},B=BigInt(0);let V=function(e){return e[e.success=0]=`success`,e[e.fail=1]=`fail`,e[e.noPolygons=2]=`noPolygons`,e[e.pathsIntersect=3]=`pathsIntersect`,e}({});var H=function(e){return e[e.loose=0]=`loose`,e[e.ascend=1]=`ascend`,e[e.descend=2]=`descend`,e}(H||{}),U=function(e){return e[e.none=0]=`none`,e[e.collinear=1]=`collinear`,e[e.intersect=2]=`intersect`,e}(U||{}),W=function(e){return e[e.neither=0]=`neither`,e[e.left=1]=`left`,e[e.right=2]=`right`,e}(W||{}),at=class{pt;edges=[];innerLM=!1;constructor(e){this.pt=e}},ot=class{vL=null;vR=null;vB=null;vT=null;kind=H.loose;triA=null;triB=null;isActive=!1;pendingDelaunay=!1;nextE=null;prevE=null},st=class{edges=[,,,];constructor(e,t,n){this.edges[0]=e,this.edges[1]=t,this.edges[2]=n}},ct=class e{allVertices=[];allEdges=[];allTriangles=[];pendingDelaunayStack=[];horzEdgeStack=[];locMinStack=[];useDelaunay;firstActive=null;lowermostVertex=null;fastMath=!1;constructor(e=!0){this.useDelaunay=e}updateFastMath(t){let n=!1,r=0,i=0,a=0,o=0,s=!0;for(let e of t){for(let t of e){if(!Number.isSafeInteger(t.x)||!Number.isSafeInteger(t.y)){s=!1;break}n?(t.x<r&&(r=t.x),t.x>i&&(i=t.x),t.y<a&&(a=t.y),t.y>o&&(o=t.y)):(n=!0,r=t.x,i=t.x,a=t.y,o=t.y)}if(!s)break}if(!s||!n){this.fastMath=!1;return}let c=i-r,l=o-a;this.fastMath=Math.max(c,l)<=e.maxSafeDelta}addPath(t){let n=t.length;if(n===0)return;let r=0,i,a,o=e.findLocMinIdx(t,n,r);if(!o.found)return;for(r=o.idx,i=e.prev(r,n);t[i].x===t[r].x&&t[i].y===t[r].y;)i=e.prev(i,n);a=e.next(r,n);let s=r;for(;this.crossProductSign(t[i],t[s],t[a])===0;){let r=e.findLocMinIdx(t,n,s);if(!r.found)return;for(s=r.idx,i=e.prev(s,n);t[i].x===t[s].x&&t[i].y===t[s].y;)i=e.prev(i,n);a=e.next(s,n)}let c=this.allVertices.length,l=new at(t[s]);this.allVertices.push(l),this.leftTurning(t[i],t[s],t[a])&&(l.innerLM=!0);let u=l;for(s=a;;){if(this.locMinStack.push(u),(this.lowermostVertex===null||u.pt.y>this.lowermostVertex.pt.y||u.pt.y===this.lowermostVertex.pt.y&&u.pt.x<this.lowermostVertex.pt.x)&&(this.lowermostVertex=u),a=e.next(s,n),this.crossProductSign(u.pt,t[s],t[a])===0){s=a;continue}for(;t[s].y<=u.pt.y;){let r=new at(t[s]);for(this.allVertices.push(r),this.createEdge(u,r,H.ascend),u=r,s=a,a=e.next(s,n);this.crossProductSign(u.pt,t[s],t[a])===0;)s=a,a=e.next(s,n)}let i=u;for(;s!==r&&t[s].y>=u.pt.y;){let r=new at(t[s]);for(this.allVertices.push(r),this.createEdge(r,u,H.descend),u=r,s=a,a=e.next(s,n);this.crossProductSign(u.pt,t[s],t[a])===0;)s=a,a=e.next(s,n)}if(s===r)break;this.leftTurning(i.pt,u.pt,t[s])&&(u.innerLM=!0)}this.createEdge(l,u,H.descend);let d=this.allVertices.length-c,f=c;if(d<3||d===3&&(this.distSqr(this.allVertices[f].pt,this.allVertices[f+1].pt)<=1||this.distSqr(this.allVertices[f+1].pt,this.allVertices[f+2].pt)<=1||this.distSqr(this.allVertices[f+2].pt,this.allVertices[f].pt)<=1))for(let e=c;e<this.allVertices.length;++e)this.allVertices[e].edges=[]}addPaths(e){let t=0;for(let n of e)t+=n.length;if(t===0)return!1;for(let t of e)this.addPath(t);return this.allVertices.length>2}cleanUp(){this.allVertices.length=0,this.allEdges.length=0,this.allTriangles.length=0,this.pendingDelaunayStack.length=0,this.horzEdgeStack.length=0,this.locMinStack.length=0,this.firstActive=null,this.lowermostVertex=null}fixupEdgeIntersects(){for(let e=0;e<this.allEdges.length;++e){let t=this.allEdges[e],n=t.vR.pt.x,r=t.vB.pt.y,i=t.vT.pt.y;for(let a=e+1;a<this.allEdges.length;++a){let e=this.allEdges[a];if(e.vL.pt.x>=n)break;if(e.vT.pt.y<r&&e.vB.pt.y>i&&this.segsIntersect(e.vL.pt,e.vR.pt,t.vL.pt,t.vR.pt)===U.intersect&&!this.removeIntersection(e,t))return!1}}return!0}mergeDupOrCollinearVertices(){if(this.allVertices.length<2)return;let t=0;for(let n=1;n<this.allVertices.length;++n){let r=this.allVertices[t],i=this.allVertices[n];if(!(r.pt.x===i.pt.x&&r.pt.y===i.pt.y)){t=n;continue}(!r.innerLM||!i.innerLM)&&(r.innerLM=!1);for(let e of i.edges)e.vB===i?e.vB=r:e.vT=r,e.vL===i?e.vL=r:e.vR=r;r.edges.push(...i.edges),i.edges=[];for(let t=0;t<r.edges.length;++t){let n=r.edges[t];if(!(e.isHorizontal(n)||n.vB!==r))for(let e=t+1;e<r.edges.length;++e){let t=r.edges[e];if(!(t.vB!==r||n.vT.pt.y===t.vT.pt.y||this.crossProductSign(n.vT.pt,r.pt,t.vT.pt)!==0)){n.vT.pt.y<t.vT.pt.y?this.splitEdge(n,t):this.splitEdge(t,n);break}}}}}splitEdge(t,n){let r=t.vT,i=n.vT;e.removeEdgeFromVertex(r,t),t.vT=i,t.vL===r?t.vL=i:t.vR=i,i.edges.push(t),this.createEdge(i,r,t.kind)}removeIntersection(t,n){let r=t.vL,i=n,a=this.shortestDistFromSegment(t.vL.pt,n.vL.pt,n.vR.pt),o=this.shortestDistFromSegment(t.vR.pt,n.vL.pt,n.vR.pt);if(o<a&&(a=o,r=t.vR),o=this.shortestDistFromSegment(n.vL.pt,t.vL.pt,t.vR.pt),o<a&&(a=o,i=t,r=n.vL),o=this.shortestDistFromSegment(n.vR.pt,t.vL.pt,t.vR.pt),o<a&&(a=o,i=t,r=n.vR),a>1)return!1;let s=i.vT;return e.removeEdgeFromVertex(s,i),i.vL===s?i.vL=r:i.vR=r,i.vT=r,r.edges.push(i),r.innerLM=!1,i.vB.innerLM&&e.getLocMinAngle(i.vB)<=0&&(i.vB.innerLM=!1),this.createEdge(r,s,i.kind),!0}createEdge(e,t,n){let r=new ot;return this.allEdges.push(r),e.pt.y===t.pt.y?(r.vB=e,r.vT=t):e.pt.y<t.pt.y?(r.vB=t,r.vT=e):(r.vB=e,r.vT=t),e.pt.x<=t.pt.x?(r.vL=e,r.vR=t):(r.vL=t,r.vR=e),r.kind=n,e.edges.push(r),t.edges.push(r),n===H.loose&&(this.queuePendingDelaunay(r),this.addEdgeToActives(r)),r}createTriangle(t,n,r){let i=new st(t,n,r);this.allTriangles.push(i);for(let t=0;t<3;++t){let n=i.edges[t];n.triA===null?(n.triA=i,e.isLooseEdge(n)||this.removeEdgeFromActives(n)):(n.triB=i,this.removeEdgeFromActives(n))}return i}forceLegal(t){if(t.triA===null||t.triB===null)return;let n=null,r=null,i=[null,null,null],a=[null,null,null];for(let r=0;r<3;++r){if(t.triA.edges[r]===t)continue;let o=t.triA.edges[r],s=e.edgeContains(o,t.vL);s===W.left?(i[1]=o,n=o.vR):s===W.right?(i[1]=o,n=o.vL):a[1]=o}for(let n=0;n<3;++n){if(t.triB.edges[n]===t)continue;let o=t.triB.edges[n],s=e.edgeContains(o,t.vL);s===W.left?(i[2]=o,r=o.vR):s===W.right?(i[2]=o,r=o.vL):a[2]=o}if(n===null||r===null)return;let o=this.crossProductSign(n.pt,t.vL.pt,t.vR.pt);if(o===0)return;let s=this.crossProductSign(r.pt,t.vL.pt,t.vR.pt);if(s===0||o===s)return;let c=this.inCircleTest(n.pt,t.vL.pt,t.vR.pt,r.pt);if(!(c===0||this.rightTurning(n.pt,t.vL.pt,t.vR.pt)===c<0)){t.vL=n,t.vR=r,t.triA.edges[0]=t;for(let n=1;n<3;++n){let r=i[n];if(t.triA.edges[n]=r,e.isLooseEdge(r)&&this.queuePendingDelaunay(r),!(r.triA===t.triA||r.triB===t.triA))if(r.triA===t.triB)r.triA=t.triA;else if(r.triB===t.triB)r.triB=t.triA;else throw Error(`Triangulation internal error`)}t.triB.edges[0]=t;for(let n=1;n<3;++n){let r=a[n];if(t.triB.edges[n]=r,e.isLooseEdge(r)&&this.queuePendingDelaunay(r),!(r.triA===t.triB||r.triB===t.triB))if(r.triA===t.triA)r.triA=t.triB;else if(r.triB===t.triA)r.triB=t.triB;else throw Error(`Triangulation internal error`)}}}createInnerLocMinLooseEdge(e){if(this.firstActive===null)return null;let t=e.pt.x,n=e.pt.y,r=this.firstActive,i=null,a=-1;for(;r!==null;){if(r.vL.pt.x<=t&&r.vR.pt.x>=t&&r.vB.pt.y>=n&&r.vB!==e&&r.vT!==e&&!this.leftTurning(r.vL.pt,e.pt,r.vR.pt)){let t=this.shortestDistFromSegment(e.pt,r.vL.pt,r.vR.pt);(i===null||t<a)&&(i=r,a=t)}r=r.nextE}if(i===null)return null;let o=i.vT.pt.y<=n?i.vB:i.vT,s=!0;for(;s;)for(s=!1,r=this.firstActive;r!==null;){if(r.vB!==o&&r.vT!==o&&r.vB!==e&&r.vT!==e&&this.segsIntersect(r.vB.pt,r.vT.pt,o.pt,e.pt)===U.intersect){o=r.vT.pt.y>n?r.vT:r.vB,s=!0;break}r=r.nextE}return this.createEdge(o,e,H.loose)}doTriangulateLeft(t,n,r){let i=null,a=null,o=t.vB===n?t.vT:t.vB;for(let e of n.edges){if(e===t||!e.isActive)continue;let r=e.vT===n?e.vB:e.vT;if(r===o)continue;let s=this.crossProductSign(o.pt,n.pt,r.pt);if(s===0){if(o.pt.x>n.pt.x==n.pt.x>r.pt.x)continue}else if(s>0||i!==null&&!this.leftTurning(r.pt,n.pt,i.pt))continue;i=r,a=e}if(i===null||i.pt.y<r||a===null)return;if(i.pt.y<n.pt.y){if(e.isLeftEdge(a))return}else if(i.pt.y>n.pt.y&&e.isRightEdge(a))return;let s=e.findLinkingEdge(i,o,i.pt.y<o.pt.y);s===null&&(s=this.createEdge(i,o,H.loose)),this.createTriangle(t,a,s),e.edgeCompleted(s)||this.doTriangulateLeft(s,i,r)}doTriangulateRight(t,n,r){let i=null,a=null,o=t.vB===n?t.vT:t.vB;for(let e of n.edges){if(e===t||!e.isActive)continue;let r=e.vT===n?e.vB:e.vT;if(r===o)continue;let s=this.crossProductSign(o.pt,n.pt,r.pt);if(s===0){if(o.pt.x>n.pt.x==n.pt.x>r.pt.x)continue}else if(s<0||i!==null&&!this.rightTurning(r.pt,n.pt,i.pt))continue;i=r,a=e}if(i===null||i.pt.y<r||a===null)return;if(i.pt.y<n.pt.y){if(e.isRightEdge(a))return}else if(i.pt.y>n.pt.y&&e.isLeftEdge(a))return;let s=e.findLinkingEdge(i,o,i.pt.y>o.pt.y);s===null&&(s=this.createEdge(i,o,H.loose)),this.createTriangle(t,s,a),e.edgeCompleted(s)||this.doTriangulateRight(s,i,r)}addEdgeToActives(e){e.isActive||(e.prevE=null,e.nextE=this.firstActive,e.isActive=!0,this.firstActive!==null&&(this.firstActive.prevE=e),this.firstActive=e)}queuePendingDelaunay(e){e.pendingDelaunay||(e.pendingDelaunay=!0,this.pendingDelaunayStack.push(e))}removeEdgeFromActives(t){e.removeEdgeFromVertex(t.vB,t),e.removeEdgeFromVertex(t.vT,t);let n=t.prevE,r=t.nextE;r!==null&&(r.prevE=n),n!==null&&(n.nextE=r),t.isActive=!1,this.firstActive===t&&(this.firstActive=r)}execute(t){let n=[];if(this.updateFastMath(t),!this.addPaths(t))return{result:V.noPolygons,solution:n};if(this.lowermostVertex.innerLM){for(;this.locMinStack.length>0;){let e=this.locMinStack.pop();e.innerLM=!e.innerLM}for(let e of this.allEdges)e.kind===H.ascend?e.kind=H.descend:e.kind===H.descend&&(e.kind=H.ascend)}else this.locMinStack.length=0;if(this.allEdges.sort((e,t)=>e.vL.pt.x<t.vL.pt.x?-1:e.vL.pt.x>t.vL.pt.x?1:0),!this.fixupEdgeIntersects())return this.cleanUp(),{result:V.pathsIntersect,solution:n};this.allVertices.sort((e,t)=>e.pt.y===t.pt.y?e.pt.x<t.pt.x?-1:e.pt.x>t.pt.x?1:0:t.pt.y<e.pt.y?-1:1),this.mergeDupOrCollinearVertices();let r=this.allVertices[0].pt.y;for(let t of this.allVertices)if(t.edges.length!==0){if(t.pt.y!==r){for(;this.locMinStack.length>0;){let t=this.locMinStack.pop(),i=this.createInnerLocMinLooseEdge(t);if(i===null)return this.cleanUp(),{result:V.fail,solution:n};e.isHorizontal(i)?i.vL===i.vB?this.doTriangulateLeft(i,i.vB,r):this.doTriangulateRight(i,i.vB,r):(this.doTriangulateLeft(i,i.vB,r),e.edgeCompleted(i)||this.doTriangulateRight(i,i.vB,r)),this.addEdgeToActives(t.edges[0]),this.addEdgeToActives(t.edges[1])}for(;this.horzEdgeStack.length>0;){let t=this.horzEdgeStack.pop();e.edgeCompleted(t)||(t.vB===t.vL?e.isLeftEdge(t)&&this.doTriangulateLeft(t,t.vB,r):e.isRightEdge(t)&&this.doTriangulateRight(t,t.vB,r))}r=t.pt.y}for(let n=t.edges.length-1;n>=0;--n){if(n>=t.edges.length)continue;let r=t.edges[n];e.edgeCompleted(r)||e.isLooseEdge(r)||(t===r.vB?(e.isHorizontal(r)&&this.horzEdgeStack.push(r),t.innerLM||this.addEdgeToActives(r)):e.isHorizontal(r)?this.horzEdgeStack.push(r):e.isLeftEdge(r)?this.doTriangulateLeft(r,r.vB,t.pt.y):this.doTriangulateRight(r,r.vB,t.pt.y))}t.innerLM&&this.locMinStack.push(t)}for(;this.horzEdgeStack.length>0;){let t=this.horzEdgeStack.pop();!e.edgeCompleted(t)&&t.vB===t.vL&&this.doTriangulateLeft(t,t.vB,r)}if(this.useDelaunay)for(;this.pendingDelaunayStack.length>0;){let e=this.pendingDelaunayStack.pop();e.pendingDelaunay=!1,this.forceLegal(e)}for(let t of this.allTriangles){let r=e.pathFromTriangle(t),i=this.crossProductSign(r[0],r[1],r[2]);i!==0&&(i<0&&r.reverse(),n.push(r))}return this.cleanUp(),{result:V.success,solution:n}}crossProductSign(e,t,n){if(!this.fastMath)return C.crossProductSign(e,t,n);let r=t.x-e.x,i=n.y-t.y,a=t.y-e.y,o=n.x-t.x,s=r*i,c=a*o;return s>c?1:s<c?-1:0}distSqr(e,t){return this.distanceSqr(e,t)}distanceSqr(t,n){if(!this.fastMath)return e.distanceSqr(t,n);let r=t.x-n.x,i=t.y-n.y;return r*r+i*i}shortestDistFromSegment(t,n,r){if(!this.fastMath)return e.shortestDistFromSegment(t,n,r);let i=r.x-n.x,a=r.y-n.y,o=t.x-n.x,s=t.y-n.y,c=o*i+s*a,l=i*i+a*a;if(c<0)return this.distanceSqr(t,n);if(c>l)return this.distanceSqr(t,r);let u=o*a-i*s;return u*u/l}segsIntersect(t,n,r,i){if(!this.fastMath)return e.segsIntersect(t,n,r,i);if(t.x===r.x&&t.y===r.y||t.x===i.x&&t.y===i.y||n.x===i.x&&n.y===i.y)return U.none;let a=n.y-t.y,o=n.x-t.x,s=i.y-r.y,c=i.x-r.x,l=t.x-r.x,u=t.y-r.y,d=a*c-s*o;if(d===0)return U.collinear;let f=l*s-u*c;if(f>=0){if(d<0||f>=d)return U.none}else if(d>0||f<=d)return U.none;if(f=l*a-u*o,f>=0){if(d>0&&f<d)return U.intersect}else if(d<0&&f>d)return U.intersect;return U.none}inCircleTest(t,n,r,i){if(!this.fastMath)return e.inCircleTest(t,n,r,i);let a=t.x-i.x,o=t.y-i.y,s=n.x-i.x,c=n.y-i.y,l=r.x-i.x,u=r.y-i.y,d=a*c-s*o,f=s*u-l*c,p=l*o-a*u,m=a*a+o*o,h=s*s+c*c,g=l*l+u*u,_=m*f+h*p+g*d,v=Math.abs(m*f)+Math.abs(h*p)+Math.abs(g*d),y=2**-52,b=(10+96*y)*y*v;if(_>b)return 1;if(-_>b)return-1;let x=BigInt(t.x)-BigInt(i.x),ee=BigInt(t.y)-BigInt(i.y),te=BigInt(n.x)-BigInt(i.x),ne=BigInt(n.y)-BigInt(i.y),re=BigInt(r.x)-BigInt(i.x),ie=BigInt(r.y)-BigInt(i.y),S=x*ne-te*ee,ae=te*ie-re*ne,oe=re*ee-x*ie,se=x*x+ee*ee,ce=te*te+ne*ne,le=re*re+ie*ie,ue=se*ae+ce*oe+le*S;return ue>B?1:ue<B?-1:0}static isLooseEdge(e){return e.kind===H.loose}static isLeftEdge(e){return e.kind===H.ascend}static isRightEdge(e){return e.kind===H.descend}static isHorizontal(e){return e.vB.pt.y===e.vT.pt.y}leftTurning(e,t,n){return this.crossProductSign(e,t,n)<0}rightTurning(e,t,n){return this.crossProductSign(e,t,n)>0}static edgeCompleted(e){return e.triA===null?!1:e.triB===null?e.kind!==H.loose:!0}static edgeContains(e,t){return e.vL===t?W.left:e.vR===t?W.right:W.neither}static getAngle(e,t,n){let r=Number(t.x-e.x),i=Number(t.y-e.y),a=Number(t.x-n.x),o=Number(t.y-n.y),s=r*a+i*o,c=r*o-i*a;return Math.atan2(c,s)}static getLocMinAngle(t){let n,r;return t.edges[0].kind===H.ascend?(n=0,r=1):(r=0,n=1),e.getAngle(t.edges[r].vT.pt,t.pt,t.edges[n].vT.pt)}static removeEdgeFromVertex(e,t){let n=e.edges.indexOf(t);if(n<0)throw Error(`Edge not found in vertex`);let r=e.edges.length-1;n!==r&&(e.edges[n]=e.edges[r]),e.edges.pop()}static findLocMinIdx(e,t,n){if(t<3)return{found:!1,idx:n};let r=n,i=(n+1)%t;for(;e[i].y<=e[n].y;)if(n=i,i=(i+1)%t,n===r)return{found:!1,idx:n};for(;e[i].y>=e[n].y;)n=i,i=(i+1)%t;return{found:!0,idx:n}}static prev(e,t){return e===0?t-1:e-1}static next(e,t){return(e+1)%t}static findLinkingEdge(e,t,n){let r=null;for(let i of e.edges)if(i.vL===t||i.vR===t){if(i.kind===H.loose||i.kind===H.ascend===n)return i;r=i}return r}static pathFromTriangle(e){let t=[e.edges[0].vL.pt,e.edges[0].vR.pt],n=e.edges[1];return n.vL.pt.x===t[0].x&&n.vL.pt.y===t[0].y||n.vL.pt.x===t[1].x&&n.vL.pt.y===t[1].y?t.push(n.vR.pt):t.push(n.vL.pt),t}static areSafePoints(...e){for(let t of e)if(!Number.isSafeInteger(t.x)||!Number.isSafeInteger(t.y))return!1;return!0}static maxSafeDelta=Math.floor(Math.sqrt((2**53-1)/2));static areSafeDeltas(...t){for(let n of t)if(Math.abs(n)>e.maxSafeDelta)return!1;return!0}static inCircleTest(t,n,r,i){let a=t.x-i.x,o=t.y-i.y,s=n.x-i.x,c=n.y-i.y,l=r.x-i.x,u=r.y-i.y,d=a*c-s*o,f=s*u-l*c,p=l*o-a*u,m=a*a+o*o,h=s*s+c*c,g=l*l+u*u,_=m*f+h*p+g*d,v=Math.abs(m*f)+Math.abs(h*p)+Math.abs(g*d),y=2**-52,b=(10+96*y)*y*v;if(_>b)return 1;if(-_>b)return-1;if(e.areSafePoints(t,n,r,i)){let e=BigInt(t.x)-BigInt(i.x),a=BigInt(t.y)-BigInt(i.y),o=BigInt(n.x)-BigInt(i.x),s=BigInt(n.y)-BigInt(i.y),c=BigInt(r.x)-BigInt(i.x),l=BigInt(r.y)-BigInt(i.y),u=e*s-o*a,d=o*l-c*s,f=c*a-e*l,p=e*e+a*a,m=o*o+s*s,h=c*c+l*l,g=p*d+m*f+h*u;return g>B?1:g<B?-1:0}return _>0?1:_<0?-1:0}static shortestDistFromSegment(t,n,r){let i=r.x-n.x,a=r.y-n.y,o=t.x-n.x,s=t.y-n.y,c=o*i+s*a,l=i*i+a*a;if(e.areSafeDeltas(i,a,o,s))return c<0?e.distanceSqr(t,n):c>l?e.distanceSqr(t,r):(o*a-i*s)*(o*a-i*s)/l;if(e.areSafePoints(t,n,r)){let i=BigInt(r.x)-BigInt(n.x),a=BigInt(r.y)-BigInt(n.y),o=BigInt(t.x)-BigInt(n.x),s=BigInt(t.y)-BigInt(n.y),c=o*i+s*a,l=i*i+a*a;if(c<B)return e.distanceSqr(t,n);if(c>l)return e.distanceSqr(t,r);let u=o*a-i*s;return Number(u*u)/Number(l)}return c<0?e.distanceSqr(t,n):c>l?e.distanceSqr(t,r):(o*a-i*s)*(o*a-i*s)/l}static segsIntersect(t,n,r,i){if(t.x===r.x&&t.y===r.y||t.x===i.x&&t.y===i.y||n.x===i.x&&n.y===i.y)return U.none;let a=n.y-t.y,o=n.x-t.x,s=i.y-r.y,c=i.x-r.x,l=t.x-r.x,u=t.y-r.y;if(e.areSafeDeltas(a,o,s,c,l,u)){let e=a*c-s*o;if(e===0)return U.collinear;let t=l*s-u*c;if(t>=0){if(e<0||t>=e)return U.none}else if(e>0||t<=e)return U.none;if(t=l*a-u*o,t>=0){if(e>0&&t<e)return U.intersect}else if(e<0&&t>e)return U.intersect;return U.none}if(e.areSafePoints(t,n,r,i)){let e=BigInt(n.y)-BigInt(t.y),a=BigInt(n.x)-BigInt(t.x),o=BigInt(i.y)-BigInt(r.y),s=BigInt(i.x)-BigInt(r.x),c=e*s-o*a;if(c===B)return U.collinear;let l=(BigInt(t.x)-BigInt(r.x))*o-(BigInt(t.y)-BigInt(r.y))*s;if(l===B)return U.none;if(l>B){if(c<B||l>=c)return U.none}else if(c>B||l<=c)return U.none;if(l=(BigInt(t.x)-BigInt(r.x))*e-(BigInt(t.y)-BigInt(r.y))*a,l===B)return U.none;if(l>B){if(c>B&&l<c)return U.intersect}else if(c<B&&l>c)return U.intersect;return U.none}let d=a*c-s*o;if(d===0)return U.collinear;let f=l*s-u*c;if(f>=0){if(d<0||f>=d)return U.none}else if(d>0||f<=d)return U.none;if(f=l*a-u*o,f>=0){if(d>0&&f<d)return U.intersect}else if(d<0&&f>d)return U.intersect;return U.none}static distSqr(t,n){return e.distanceSqr(t,n)}static distanceSqr(t,n){let r=t.x-n.x,i=t.y-n.y;if(e.areSafeDeltas(r,i)){let e=r*r+i*i;if(e<=2**53-1)return e}if(e.areSafePoints(t,n)){let e=BigInt(t.x)-BigInt(n.x),r=BigInt(t.y)-BigInt(n.y);return Number(e*e+r*r)}return r*r+i*i}},lt=t({Clipper:()=>Kn,addPolyNodeToPathsD:()=>Tn,area:()=>jt,areaD:()=>Nt,areaPaths:()=>Mt,areaPathsD:()=>Pt,booleanOp:()=>G,booleanOpD:()=>K,booleanOpDWithPolyTree:()=>St,booleanOpWithPolyTree:()=>xt,difference:()=>_t,differenceD:()=>vt,distanceSqr:()=>hn,ellipse:()=>Hn,ellipseD:()=>Un,getBounds:()=>ln,getBoundsD:()=>dn,getBoundsPaths:()=>un,getBoundsPathsD:()=>fn,inflatePaths:()=>Ct,inflatePathsD:()=>wt,inflateRect:()=>vn,inflateRectD:()=>yn,intersect:()=>pt,intersectD:()=>mt,invalidRect64:()=>dt,invalidRectD:()=>ft,isPositive:()=>Ft,isPositiveD:()=>It,makePath:()=>pn,makePathD:()=>mn,midPoint:()=>gn,midPointD:()=>_n,minkowskiDiff:()=>kt,minkowskiDiffD:()=>At,minkowskiSum:()=>Dt,minkowskiSumD:()=>Ot,offsetPath:()=>Vt,path64FromD:()=>Xt,path64ToString:()=>Lt,pathD:()=>$t,pathDToString:()=>zt,paths64FromD:()=>Zt,paths64ToString:()=>Rt,pathsD:()=>Qt,pathsDToString:()=>Bt,perpendicDistFromLineSqrd:()=>Z,perpendicDistFromLineSqrd64:()=>Q,pointInPolygon:()=>Bn,pointInPolygonD:()=>Vn,pointsNearEqual:()=>bn,polyTreeToPaths64:()=>wn,polyTreeToPathsD:()=>En,ramerDouglasPeucker:()=>On,ramerDouglasPeuckerD:()=>jn,ramerDouglasPeuckerPaths:()=>kn,ramerDouglasPeuckerPathsD:()=>Mn,rectClip:()=>Tt,rectClipLines:()=>Et,reversePath:()=>an,reversePathD:()=>on,reversePaths:()=>sn,reversePathsD:()=>cn,scalePath:()=>Gt,scalePath64:()=>J,scalePathD:()=>qt,scalePathDFromInt:()=>Jt,scalePaths:()=>Kt,scalePaths64:()=>Y,scalePathsD:()=>q,scalePathsDFromInt:()=>Yt,scalePoint64:()=>Ht,scalePointD:()=>Ut,scaleRect:()=>Wt,simplifyPath:()=>Pn,simplifyPathD:()=>In,simplifyPaths:()=>Fn,simplifyPathsD:()=>Ln,sqr:()=>X,stripDuplicates:()=>Sn,stripNearDuplicates:()=>xn,translatePath:()=>en,translatePathD:()=>nn,translatePaths:()=>tn,translatePathsD:()=>rn,triangulate:()=>Wn,triangulateD:()=>Gn,trimCollinear:()=>Rn,trimCollinearD:()=>zn,union:()=>ht,unionD:()=>gt,xor:()=>yt,xorD:()=>bt});const ut=BigInt(2),dt=Ee,ft=De;function pt(e,t,r){return G(n.Intersection,e,t,r)}function mt(e,t,r,i=2){return K(n.Intersection,e,t,r,i)}function ht(e,t,r){return typeof t==`number`?G(n.Union,e,null,t):G(n.Union,e,t,r)}function gt(e,t,r,i){return typeof t==`number`?K(n.Union,e,null,t):K(n.Union,e,t,r,i||2)}function _t(e,t,r){return G(n.Difference,e,t,r)}function vt(e,t,r,i=2){return K(n.Difference,e,t,r,i)}function yt(e,t,r){return G(n.Xor,e,t,r)}function bt(e,t,r,i=2){return K(n.Xor,e,t,r,i)}function G(e,t,n,i){let a=[];if(t===null)return a;let o=new P;return o.addPaths(t,r.Subject),n!==null&&o.addPaths(n,r.Clip),o.execute(e,i,a),a}function xt(e,t,n,i,a){if(t===null)return;let o=new P;o.addPaths(t,r.Subject),n!==null&&o.addPaths(n,r.Clip),o.execute(e,a,i)}function K(e,t,n,r,i=2){let a=[],o=new qe(i);return o.addSubjectPaths(t),n!==null&&o.addClipPaths(n),o.execute(e,r,a),a}function St(e,t,n,r,i,a=2){if(t===null)return;let o=new qe(a);o.addSubjectPaths(t),n!==null&&o.addClipPaths(n),o.execute(e,i,r)}function Ct(e,t,n,r,i=2,a=0){let o=new Ye(i,a);o.addPaths(e,n,r);let s=[];return o.execute(t,s),s}function wt(e,t,n,r,i=2,a=2,o=0){C.checkPrecision(a);let s=10**a,c=Y(e,s),l=new Ye(i,s*o);l.addPaths(c,n,r);let u=[];return l.execute(t*s,u),q(u,1/s)}function Tt(e,t,n){if(`left`in e&&typeof e.left==`number`&&Number.isInteger(e.left)){let n=e;if(E.isEmpty(n))return[];if(Array.isArray(t[0])){let e=t;return e.length===0?[]:new z(n).execute(e)}else{let e=t;return e.length===0?[]:Tt(n,[e])}}else{let r=e,i=n||2;if(C.checkPrecision(i),D.isEmpty(r))return[];let a=10**i,o=Wt(r,a);if(Array.isArray(t[0])){let e=t;if(e.length===0)return[];let n=Y(e,a);return q(new z(o).execute(n),1/a)}else{let e=t;return e.length===0?[]:Tt(r,[e],i)}}}function Et(e,t,n){if(`left`in e&&typeof e.left==`number`&&Number.isInteger(e.left)){let n=e;if(E.isEmpty(n))return[];if(Array.isArray(t[0])){let e=t;return e.length===0?[]:new Ze(n).execute(e)}else{let e=t;return e.length===0?[]:Et(n,[e])}}else{let r=e,i=n||2;if(C.checkPrecision(i),D.isEmpty(r))return[];let a=10**i,o=Wt(r,a);if(Array.isArray(t[0])){let e=t;if(e.length===0)return[];let n=Y(e,a);return q(new Ze(o).execute(n),1/a)}else{let e=t;return e.length===0?[]:Et(r,[e],i)}}}function Dt(e,t,n){return it.sum(e,t,n)}function Ot(e,t,n){return it.sumD(e,t,n)}function kt(e,t,n){return it.diff(e,t,n)}function At(e,t,n){return it.diffD(e,t,n)}function jt(e){return C.area(e)}function Mt(e){let t=0;for(let n of e)t+=jt(n);return t}function Nt(e){let t=0,n=e.length;if(n<3)return 0;let r=e[n-1];for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5}function Pt(e){let t=0;for(let n of e)t+=Nt(n);return t}function Ft(e){return jt(e)>=0}function It(e){return Nt(e)>=0}function Lt(e){let t=``;for(let n of e)t+=w.toString(n);return t+`
5
- `}function Rt(e){let t=``;for(let n of e)t+=Lt(n);return t}function zt(e,t=2){let n=``;for(let r of e)n+=T.toString(r,t);return n+`
6
- `}function Bt(e,t=2){let n=``;for(let r of e)n+=zt(r,t);return n}function Vt(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function Ht(e,t){return{x:Math.round(e.x*t),y:Math.round(e.y*t)}}function Ut(e,t){return{x:e.x*t,y:e.y*t}}function Wt(e,t){let n=C.maxSafeCoordinateForScale(t);return C.checkSafeScaleValue(e.left,n,`scaleRect`),C.checkSafeScaleValue(e.top,n,`scaleRect`),C.checkSafeScaleValue(e.right,n,`scaleRect`),C.checkSafeScaleValue(e.bottom,n,`scaleRect`),{left:Math.round(e.left*t),top:Math.round(e.top*t),right:Math.round(e.right*t),bottom:Math.round(e.bottom*t)}}function Gt(e,t){if(C.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push({x:Math.round(r.x*t),y:Math.round(r.y*t)});return n}function Kt(e,t){if(C.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(Gt(r,t));return n}function qt(e,t){if(C.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(T.scale(r,t));return n}function q(e,t){if(C.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(qt(r,t));return n}function J(e,t){let n=C.maxSafeCoordinateForScale(t),r=[];for(let i of e)C.checkSafeScaleValue(i.x,n,`scalePath64`),C.checkSafeScaleValue(i.y,n,`scalePath64`),r.push({x:Math.round(i.x*t),y:Math.round(i.y*t)});return r}function Y(e,t){let n=[];for(let r of e)n.push(J(r,t));return n}function Jt(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t});return n}function Yt(e,t){let n=[];for(let r of e)n.push(Jt(r,t));return n}function Xt(e){let t=[];for(let n of e)t.push(w.fromPointD(n));return t}function Zt(e){let t=[];for(let n of e)t.push(Xt(n));return t}function Qt(e){let t=[];for(let n of e)t.push($t(n));return t}function $t(e){let t=[];for(let n of e)t.push(T.fromPoint64(n));return t}function en(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function tn(e,t,n){let r=[];for(let i of e)r.push(Vt(i,t,n));return r}function nn(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function rn(e,t,n){let r=[];for(let i of e)r.push(nn(i,t,n));return r}function an(e){return[...e].reverse()}function on(e){return[...e].reverse()}function sn(e){let t=[];for(let n of e)t.push(an(n));return t}function cn(e){let t=[];for(let n of e)t.push(on(n));return t}function ln(e){return C.getBounds(e)}function un(e){let t=E.createInvalid();for(let n of e)for(let e of n)e.x<t.left&&(t.left=e.x),e.x>t.right&&(t.right=e.x),e.y<t.top&&(t.top=e.y),e.y>t.bottom&&(t.bottom=e.y);return t.left===2**53-1?{left:0,top:0,right:0,bottom:0}:t}function dn(e){let t=D.createInvalid();for(let n of e)n.x<t.left&&(t.left=n.x),n.x>t.right&&(t.right=n.x),n.y<t.top&&(t.top=n.y),n.y>t.bottom&&(t.bottom=n.y);return Math.abs(t.left-Number.MAX_VALUE)<C.floatingPointTolerance?{left:0,top:0,right:0,bottom:0}:t}function fn(e){let t=D.createInvalid();for(let n of e)for(let e of n)e.x<t.left&&(t.left=e.x),e.x>t.right&&(t.right=e.x),e.y<t.top&&(t.top=e.y),e.y>t.bottom&&(t.bottom=e.y);return Math.abs(t.left-Number.MAX_VALUE)<C.floatingPointTolerance?{left:0,top:0,right:0,bottom:0}:t}function pn(e){let t=Math.floor(e.length/2),n=[];for(let r=0;r<t;r++)n.push({x:e[r*2],y:e[r*2+1],z:0});return n}function mn(e){let t=Math.floor(e.length/2),n=[];for(let r=0;r<t;r++)n.push({x:e[r*2],y:e[r*2+1],z:0});return n}function X(e){return e*e}function hn(e,t){let n=e.x-t.x,r=e.y-t.y;if(Number.isSafeInteger(n)&&Number.isSafeInteger(r)){let e=Math.abs(n),t=Math.abs(r),i=C.maxCoordForSafeAreaProduct*2;if(e<=i&&t<=i){let e=n*n+r*r;if(e<=2**53-1)return e}let a=BigInt(n)*BigInt(n),o=BigInt(r)*BigInt(r);return Number(a+o)}return X(n)+X(r)}function gn(e,t){return Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.y)&&(Math.abs(e.x)+Math.abs(t.x)>2**53-1||Math.abs(e.y)+Math.abs(t.y)>2**53-1)?{x:Number((BigInt(e.x)+BigInt(t.x))/ut),y:Number((BigInt(e.y)+BigInt(t.y))/ut)}:{x:Math.round((e.x+t.x)/2),y:Math.round((e.y+t.y)/2)}}function _n(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function vn(e,t,n){e.left-=t,e.right+=t,e.top-=n,e.bottom+=n}function yn(e,t,n){e.left-=t,e.right+=t,e.top-=n,e.bottom+=n}function bn(e,t,n){return X(e.x-t.x)+X(e.y-t.y)<n}function xn(e,t,n){let r=e.length,i=[];if(r===0)return i;let a=e[0];i.push(a);for(let n=1;n<r;n++)bn(a,e[n],t)||(a=e[n],i.push(a));return n&&bn(a,i[0],t)&&i.pop(),i}function Sn(e,t){let n=e.length,r=[];if(n===0)return r;let i=e[0];r.push(i);for(let t=1;t<n;t++)w.equals(i,e[t])||(i=e[t],r.push(i));return t&&w.equals(i,r[0])&&r.pop(),r}function Cn(e,t){e.poly&&e.poly.length>0&&t.push(e.poly);for(let n=0;n<e.count;n++)Cn(e.child(n),t)}function wn(e){let t=[];for(let n=0;n<e.count;n++)Cn(e.child(n),t);return t}function Tn(e,t){e.poly&&e.poly.length>0&&t.push(e.poly);for(let n=0;n<e.count;n++)Tn(e.child(n),t)}function En(e){let t=[];for(let n=0;n<e.count;n++)Tn(e.child(n),t);return t}function Z(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;return a===0&&o===0?0:X(r*o-a*i)/(a*a+o*o)}function Q(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;if(a===0&&o===0)return 0;if(Number.isSafeInteger(r)&&Number.isSafeInteger(i)&&Number.isSafeInteger(a)&&Number.isSafeInteger(o)){let e=BigInt(r)*BigInt(o)-BigInt(a)*BigInt(i),t=e*e,n=BigInt(a)*BigInt(a)+BigInt(o)*BigInt(o);return Number(t)/Number(n)}return X(C.crossProduct(t,e,n))/(a*a+o*o)}function Dn(e,t,n,r,i){for(;;){let a=0,o=0;for(;n>t&&w.equals(e[t],e[n]);)i[n--]=!1;for(let r=t+1;r<n;++r){let i=Q(e[r],e[t],e[n]);i<=o||(o=i,a=r)}if(o<=r)return;if(i[a]=!0,a>t+1&&Dn(e,t,a,r,i),a<n-1){t=a;continue}break}}function On(e,t){let n=e.length;if(n<5)return e;let r=Array(n).fill(!1);r[0]=!0,r[n-1]=!0,Dn(e,0,n-1,X(t),r);let i=[];for(let t=0;t<n;++t)r[t]&&i.push(e[t]);return i}function kn(e,t){let n=[];for(let r of e)n.push(On(r,t));return n}function An(e,t,n,r,i){for(;;){let a=0,o=0;for(;n>t&&T.equals(e[t],e[n]);)i[n--]=!1;for(let r=t+1;r<n;++r){let i=Z(e[r],e[t],e[n]);i<=o||(o=i,a=r)}if(o<=r)return;if(i[a]=!0,a>t+1&&An(e,t,a,r,i),a<n-1){t=a;continue}break}}function jn(e,t){let n=e.length;if(n<5)return e;let r=Array(n).fill(!1);r[0]=!0,r[n-1]=!0,An(e,0,n-1,X(t),r);let i=[];for(let t=0;t<n;++t)r[t]&&i.push(e[t]);return i}function Mn(e,t){let n=[];for(let r of e)n.push(jn(r,t));return n}function $(e,t,n){for(++e;e<=t&&n[e];)++e;if(e<=t)return e;for(e=0;n[e];)++e;return e}function Nn(e,t,n){for(e===0?e=t:--e;e>0&&n[e];)--e;if(!n[e])return e;for(e=t;n[e];)--e;return e}function Pn(e,t,n=!0){let r=e.length,i=r-1,a=X(t);if(r<4)return e;let o=Array(r).fill(!1),s=Array(r).fill(0),c=0;n?(s[0]=Q(e[0],e[i],e[1]),s[i]=Q(e[i],e[0],e[i-1])):(s[0]=Number.MAX_VALUE,s[i]=Number.MAX_VALUE);for(let t=1;t<i;++t)s[t]=Q(e[t],e[t-1],e[t+1]);for(;;){if(s[c]>a){let e=c;do c=$(c,i,o);while(c!==e&&s[c]>a);if(c===e)break}let t=Nn(c,i,o),r=$(c,i,o);if(r===t)break;let l;if(s[r]<s[c]){l=t;let a=c;c=r;let u=$(r,i,o);o[c]=!0,c=u;let d=$(u,i,o);(n||c!==i&&c!==0)&&(s[c]=Q(e[c],e[a],e[d])),(n||a!==0&&a!==i)&&(s[a]=Q(e[a],e[l],e[c]))}else{l=Nn(t,i,o),o[c]=!0,c=r;let a=$(r,i,o);(n||c!==i&&c!==0)&&(s[c]=Q(e[c],e[t],e[a])),(n||t!==0&&t!==i)&&(s[t]=Q(e[t],e[l],e[c]))}}let l=[];for(let t=0;t<r;t++)o[t]||l.push(e[t]);return l}function Fn(e,t,n=!0){let r=[];for(let i of e)r.push(Pn(i,t,n));return r}function In(e,t,n=!0){let r=e.length,i=r-1,a=X(t);if(r<4)return e;let o=Array(r).fill(!1),s=Array(r).fill(0),c=0;n?(s[0]=Z(e[0],e[i],e[1]),s[i]=Z(e[i],e[0],e[i-1])):(s[0]=Number.MAX_VALUE,s[i]=Number.MAX_VALUE);for(let t=1;t<i;++t)s[t]=Z(e[t],e[t-1],e[t+1]);for(;;){if(s[c]>a){let e=c;do c=$(c,i,o);while(c!==e&&s[c]>a);if(c===e)break}let t=Nn(c,i,o),r=$(c,i,o);if(r===t)break;let l;if(s[r]<s[c]){l=t;let a=c;c=r;let u=$(r,i,o);o[c]=!0,c=u;let d=$(u,i,o);(n||c!==i&&c!==0)&&(s[c]=Z(e[c],e[a],e[d])),(n||a!==0&&a!==i)&&(s[a]=Z(e[a],e[l],e[c]))}else{l=Nn(t,i,o),o[c]=!0,c=r;let a=$(r,i,o);(n||c!==i&&c!==0)&&(s[c]=Z(e[c],e[t],e[a])),(n||t!==0&&t!==i)&&(s[t]=Z(e[t],e[l],e[c]))}}let l=[];for(let t=0;t<r;t++)o[t]||l.push(e[t]);return l}function Ln(e,t,n=!0){let r=[];for(let i of e)r.push(In(i,t,n));return r}function Rn(e,t=!1){let n=e.length,r=0;if(!t){for(;r<n-1&&C.isCollinear(e[n-1],e[r],e[r+1]);)r++;for(;r<n-1&&C.isCollinear(e[n-2],e[n-1],e[r]);)n--}if(n-r<3)return!t||n<2||w.equals(e[0],e[1])?[]:e;let i=[],a=e[r];for(i.push(a),r++;r<n-1;r++)C.isCollinear(a,e[r],e[r+1])||(a=e[r],i.push(a));if(t)i.push(e[n-1]);else if(!C.isCollinear(a,e[n-1],i[0]))i.push(e[n-1]);else{for(;i.length>2&&C.isCollinear(i[i.length-1],i[i.length-2],i[0]);)i.pop();i.length<3&&(i.length=0)}return i}function zn(e,t,n=!1){C.checkPrecision(t);let r=10**t,i=J(e,r);return i=Rn(i,n),Jt(i,1/r)}function Bn(e,t){return C.pointInPolygon(e,t)}function Vn(e,t,n=2){C.checkPrecision(n);let r=10**n,i=C.maxSafeCoordinateForScale(r);C.checkSafeScaleValue(e.x,i,`pointInPolygonD`),C.checkSafeScaleValue(e.y,i,`pointInPolygonD`);let a=w.fromPointD(T.scale(e,r)),o=J(t,r);return C.pointInPolygon(a,o)}function Hn(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:Math.round(e.x+t),y:e.y}];for(let l=1;l<r;++l){c.push({x:Math.round(e.x+t*o),y:Math.round(e.y+n*s)});let r=o*a-s*i;s=s*a+o*i,o=r}return c}function Un(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:e.x+t,y:e.y}];for(let l=1;l<r;++l){c.push({x:e.x+t*o,y:e.y+n*s});let r=o*a-s*i;s=s*a+o*i,o=r}return c}function Wn(e,t=!0){return new ct(t).execute(e)}function Gn(e,t,n=!0){let r;r=t<=0?1:t>8?10**8:10**t;let i=Y(e,r),{result:a,solution:o}=new ct(n).execute(i),s;return s=a===V.success?q(o,1/r):[],{result:a,solution:s}}const Kn={invalidRect64:dt,invalidRectD:ft,intersect:pt,intersectD:mt,union:ht,unionD:gt,difference:_t,differenceD:vt,xor:yt,xorD:bt,booleanOp:G,booleanOpWithPolyTree:xt,booleanOpD:K,booleanOpDWithPolyTree:St,inflatePaths:Ct,inflatePathsD:wt,rectClip:Tt,rectClipLines:Et,minkowskiSum:Dt,minkowskiSumD:Ot,minkowskiDiff:kt,minkowskiDiffD:At,area:jt,areaPaths:Mt,areaD:Nt,areaPathsD:Pt,isPositive:Ft,isPositiveD:It,path64ToString:Lt,paths64ToString:Rt,pathDToString:zt,pathsDToString:Bt,offsetPath:Vt,scalePoint64:Ht,scalePointD:Ut,scaleRect:Wt,scalePath:Gt,scalePaths:Kt,scalePathD:qt,scalePathsD:q,scalePath64:J,scalePaths64:Y,scalePathDFromInt:Jt,scalePathsDFromInt:Yt,path64FromD:Xt,paths64FromD:Zt,pathsD:Qt,pathD:$t,translatePath:en,translatePaths:tn,translatePathD:nn,translatePathsD:rn,reversePath:an,reversePathD:on,reversePaths:sn,reversePathsD:cn,getBounds:ln,getBoundsPaths:un,getBoundsD:dn,getBoundsPathsD:fn,makePath:pn,makePathD:mn,sqr:X,distanceSqr:hn,midPoint:gn,midPointD:_n,inflateRect:vn,inflateRectD:yn,pointsNearEqual:bn,stripNearDuplicates:xn,stripDuplicates:Sn,polyTreeToPaths64:wn,addPolyNodeToPathsD:Tn,polyTreeToPathsD:En,perpendicDistFromLineSqrd:Z,perpendicDistFromLineSqrd64:Q,ramerDouglasPeucker:On,ramerDouglasPeuckerPaths:kn,ramerDouglasPeuckerD:jn,ramerDouglasPeuckerPathsD:Mn,simplifyPath:Pn,simplifyPaths:Fn,simplifyPathD:In,simplifyPathsD:Ln,trimCollinear:Rn,trimCollinearD:zn,pointInPolygon:Bn,pointInPolygonD:Vn,ellipse:Hn,ellipseD:Un,triangulate:Wn,triangulateD:Gn};export{Be as Active,n as ClipType,lt as Clipper,P as Clipper64,N as ClipperBase,qe as ClipperD,M as ClipperEngine,Ye as ClipperOffset,ct as Delaunay,L as EndType,i as FillRule,ze as HorzJoin,Ie as HorzPosition,Re as HorzSegment,C as InternalClipper,Ee as InvalidRect64,De as InvalidRectD,I as JoinType,j as JoinWith,Ne as LocalMinima,it as Minkowski,A as OutPt,Xe as OutPt2,Le as OutRec,r as PathType,O as PathUtils,Te as PathsUtils,w as Point64Utils,T as PointDUtils,a as PointInPolygonResult,Ue as PolyPath64,He as PolyPathBase,We as PolyPathD,Ge as PolyTree64,Ke as PolyTreeD,E as Rect64Utils,z as RectClip64,Ze as RectClipLines64,D as RectDUtils,Ve as ReuseableDataContainer64,V as TriangulateResult,Me as Vertex,k as VertexFlags,jt as area,Nt as areaD,Mt as areaPaths,Pt as areaPathsD,G as booleanOp,K as booleanOpD,St as booleanOpDWithPolyTree,xt as booleanOpWithPolyTree,Fe as createIntersectNode,Pe as createLocalMinima,_t as difference,vt as differenceD,Hn as ellipse,Un as ellipseD,ln as getBounds,dn as getBoundsD,un as getBoundsPaths,fn as getBoundsPathsD,Ct as inflatePaths,wt as inflatePathsD,pt as intersect,mt as intersectD,Ft as isPositive,It as isPositiveD,pn as makePath,mn as makePathD,kt as minkowskiDiff,At as minkowskiDiffD,Dt as minkowskiSum,Ot as minkowskiSumD,Bn as pointInPolygon,Vn as pointInPolygonD,wn as polyTreeToPaths64,En as polyTreeToPathsD,On as ramerDouglasPeucker,jn as ramerDouglasPeuckerD,kn as ramerDouglasPeuckerPaths,Mn as ramerDouglasPeuckerPathsD,Tt as rectClip,Et as rectClipLines,an as reversePath,on as reversePathD,sn as reversePaths,cn as reversePathsD,J as scalePath64,qt as scalePathD,Y as scalePaths64,q as scalePathsD,Pn as simplifyPath,In as simplifyPathD,Fn as simplifyPaths,Ln as simplifyPathsD,Sn as stripDuplicates,en as translatePath,nn as translatePathD,tn as translatePaths,rn as translatePathsD,Wn as triangulate,Gn as triangulateD,Rn as trimCollinear,zn as trimCollinearD,ht as union,gt as unionD,yt as xor,bt as xorD};
1
+ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};let n=function(e){return e[e.NoClip=0]=`NoClip`,e[e.Intersection=1]=`Intersection`,e[e.Union=2]=`Union`,e[e.Difference=3]=`Difference`,e[e.Xor=4]=`Xor`,e}({}),r=function(e){return e[e.Subject=0]=`Subject`,e[e.Clip=1]=`Clip`,e}({}),i=function(e){return e[e.EvenOdd=0]=`EvenOdd`,e[e.NonZero=1]=`NonZero`,e[e.Positive=2]=`Positive`,e[e.Negative=3]=`Negative`,e}({}),a=function(e){return e[e.IsOn=0]=`IsOn`,e[e.IsInside=1]=`IsInside`,e[e.IsOutside=2]=`IsOutside`,e}({});const o=2**53-1,s=Math.floor(Math.sqrt(o));function c(e,t){return!Number.isSafeInteger(e)||!Number.isSafeInteger(t)?!1:e===0||t===0?!0:Math.abs(e)<=o/Math.abs(t)}function l(e,t){return Math.abs(e)+Math.abs(t)<=o}function u(e,t,n,r){if(c(e,t)&&c(n,r)){let i=e*t,a=n*r;if(l(i,a))return i-a}return Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(e)*BigInt(t)-BigInt(n)*BigInt(r)):e*t-n*r}function d(e,t,n,r){if(c(e,t)&&c(n,r)){let i=e*t,a=n*r;if(l(i,a))return i+a}return Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)?Number(BigInt(e)*BigInt(t)+BigInt(n)*BigInt(r)):e*t+n*r}const f=BigInt(0),p=BigInt(2),m=BigInt(4),h=BigInt(64),g=BigInt(`0xFFFFFFFFFFFFFFFF`),_=BigInt(`9223372036854775807`),v=Number(_/m),y=Number(_),b=1e-12,x=Math.floor(s/2),S=Math.floor(Math.sqrt(Math.sqrt(o/4)));function C(e){if(!Number.isFinite(e))throw RangeError(`Scale must be a finite number`);let t=Math.abs(e);return t===0?1/0:o/t}function w(e,t,n){if(!Number.isFinite(e)||Math.abs(e)>t)throw RangeError(`Scaled coordinate exceeds Number.MAX_SAFE_INTEGER in ${n}`)}function T(e,t){if(!Number.isFinite(e)||Math.abs(e)>o)throw RangeError(`Coordinate exceeds Number.MAX_SAFE_INTEGER in ${t}`)}function E(e,t,n){let r=t.x-e.x,i=n.y-t.y,a=t.y-e.y,o=n.x-t.x;return Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s?r*i-a*o:u(r,i,a,o)}function D(e,t,n){let r=t.x-e.x,i=n.y-t.y,a=t.y-e.y,o=n.x-t.x;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*i,t=a*o;return e>t?1:e<t?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)){let e=r*i,t=a*o;return e>t?1:e<t?-1:0}let c=BigInt(r)*BigInt(i),l=BigInt(a)*BigInt(o);return c===l?0:c>l?1:-1}function O(e){if(e<-8||e>8)throw Error(`Error: Precision is out of range.`)}function k(e){return Math.abs(e)<=b}function ee(e){return e<0?-1:e>0?1:0}function te(e,t){let n=BigInt(e)*BigInt(t);return{lo64:n&g,hi64:n>>h}}function ne(e,t,n,r){let i=Math.abs(e),a=Math.abs(t),o=Math.abs(n),c=Math.abs(r);if(i<s&&a<s&&o<s&&c<s)return e*t===n*r;let l=(e<0?-1:e>0?1:0)*(t<0?-1:t>0?1:0);if(l!==(n<0?-1:n>0?1:0)*(r<0?-1:r>0?1:0))return!1;if(l===0)return!0;if(!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)||!Number.isSafeInteger(c))return e*t===n*r;let u=BigInt(i),d=BigInt(a),f=BigInt(o),p=BigInt(c);return u*d===f*p}function re(e,t,n){return ne(t.x-e.x,n.y-t.y,t.y-e.y,n.x-t.x)}function ie(e,t,n){let r=t.x-e.x,i=n.x-t.x,a=t.y-e.y,o=n.y-t.y;return Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s?r*i+a*o:d(r,i,a,o)}function ae(e,t,n){let r=t.x-e.x,i=n.x-t.x,a=t.y-e.y,o=n.y-t.y;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*i+a*o;return e>0?1:e<0?-1:0}if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||!Number.isSafeInteger(o)){let e=r*i+a*o;return e>0?1:e<0?-1:0}let c=BigInt(r)*BigInt(i)+BigInt(a)*BigInt(o);return c===f?0:c>f?1:-1}function oe(e){let t=e.length;if(t<3)return 0;let n=!0;for(let r=0;r<t&&n;r++){let t=e[r];(Math.abs(t.x)>=x||Math.abs(t.y)>=x)&&(n=!1)}let r=e[t-1];if(n){let t=0;for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5}let i=f;for(let t of e){let e=r.y+t.y,n=r.x-t.x;if(Number.isSafeInteger(e)&&Number.isSafeInteger(n))i+=BigInt(e)*BigInt(n);else if(Number.isSafeInteger(r.y)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(r.x)&&Number.isSafeInteger(t.x)){let e=BigInt(r.y)+BigInt(t.y),n=BigInt(r.x)-BigInt(t.x);i+=e*n}else i+=BigInt(Math.round(e*n));r=t}return Number(i)*.5}function se(e,t){return e.y*t.x-t.y*e.x}function A(e,t){return e.x*t.x+e.y*t.y}function j(e){let t=Math.round(e);return e===t-.5&&t&1?t-1:t}function M(e){return e>=v||e<=-v?y:Math.round(e)}function N(e,t,n,r){let i=t.y-e.y,a=t.x-e.x,o=r.y-n.y,s=r.x-n.x,c=u(i,s,o,a);if(c===0)return null;let l=u(e.x-n.x,o,e.y-n.y,s)/c;return l<=0?{x:e.x,y:e.y,z:e.z||0}:l>=1?{x:t.x,y:t.y,z:t.z||0}:{x:Math.trunc(e.x+l*a),y:Math.trunc(e.y+l*i),z:0}}function P(e,t,n,r){let i=t.y-e.y,a=t.x-e.x,o=r.y-n.y,s=r.x-n.x,c=i*s-o*a;if(c===0)return{success:!1,ip:{x:0,y:0,z:0}};let l=((e.x-n.x)*o-(e.y-n.y)*s)/c,u;return u=l<=0?{...e,z:0}:l>=1?{...t,z:0}:{x:e.x+l*a,y:e.y+l*i,z:0},{success:!0,ip:u}}function F(e,t,n,r,i=!1){if(!i){let i=D(e,n,r),a=D(t,n,r),o=D(n,e,t),s=D(r,e,t);return i!==0&&a!==0&&i!==a&&o!==0&&s!==0&&o!==s}let a=D(e,n,r),o=D(t,n,r);if(a!==0&&a===o)return!1;let s=D(n,e,t),c=D(r,e,t);return s!==0&&s===c?!1:a!==0||o!==0||s!==0||c!==0}function ce(e){if(e.length===0)return{left:0,top:0,right:0,bottom:0};let t={left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)};for(let n of e)n.x<t.left&&(t.left=n.x),n.x>t.right&&(t.right=n.x),n.y<t.top&&(t.top=n.y),n.y>t.bottom&&(t.bottom=n.y);return t.left===2**53-1?{left:0,top:0,right:0,bottom:0}:t}function le(e,t,n){if(t.x===n.x&&t.y===n.y)return{x:t.x,y:t.y,z:0};let r=n.x-t.x,i=n.y-t.y,a=d(e.x-t.x,r,e.y-t.y,i)/d(r,r,i,i),o=a<0?0:a>1?1:a;return{x:Math.round(t.x+o*r),y:Math.round(t.y+o*i),z:0}}function ue(e,t){let n=t.length,r=0;if(n<3)return a.IsOutside;for(;r<n&&t[r].y===e.y;)r++;if(r===n)return a.IsOutside;let i=t[r].y<e.y,o=i,s=0,c=r+1,l=n;for(;;){if(c===l){if(l===0||r===0)break;l=r,c=0}if(i)for(;c<l&&t[c].y<e.y;)c++;else for(;c<l&&t[c].y>e.y;)c++;if(c===l)continue;let o=t[c],u=c>0?t[c-1]:t[n-1];if(o.y===e.y){if(o.x===e.x||o.y===u.y&&e.x<u.x!=e.x<o.x)return a.IsOn;if(c++,c===r)break;continue}if(!(e.x<o.x&&e.x<u.x))if(e.x>u.x&&e.x>o.x)s=1-s;else{let t=D(u,o,e);if(t===0)return a.IsOn;t<0===i&&(s=1-s)}i=!i,c++}if(i===o)return s===0?a.IsOutside:a.IsInside;c===n&&(c=0);let u=c===0?D(t[n-1],t[0],e):D(t[c-1],t[c],e);return u===0?a.IsOn:(u<0===i&&(s=1-s),s===0?a.IsOutside:a.IsInside)}function de(e,t){let n=a.IsOn;for(let r of e)switch(ue(r,t)){case a.IsOutside:if(n===a.IsOutside)return!1;n=a.IsOutside;break;case a.IsInside:if(n===a.IsInside)return!0;n=a.IsInside;break;default:break}let r=ce(e),i,o;return Number.isSafeInteger(r.left)&&Number.isSafeInteger(r.right)&&Math.abs(r.left)+Math.abs(r.right)>2**53-1?(i=Number((BigInt(r.left)+BigInt(r.right))/p),o=Number((BigInt(r.top)+BigInt(r.bottom))/p)):(i=Math.round((r.left+r.right)/2),o=Math.round((r.top+r.bottom)/2)),ue({x:i,y:o},t)!==a.IsOutside}const I={MaxInt64:_,MaxCoord:v,max_coord:v,min_coord:-v,Invalid64:y,floatingPointTolerance:b,defaultMinimumEdgeLength:.1,maxCoordForSafeAreaProduct:x,maxCoordForSafeCrossSq:S,maxSafeCoordinateForScale:C,checkSafeScaleValue:w,ensureSafeInteger:T,crossProduct:E,crossProductSign:D,checkPrecision:O,isAlmostZero:k,triSign:ee,multiplyUInt64:te,productsAreEqual:ne,isCollinear:re,dotProduct:ie,dotProductSign:ae,area:oe,crossProductD:se,dotProductD:A,roundToEven:j,checkCastInt64:M,getLineIntersectPt:N,getLineIntersectPtD:P,segsIntersect:F,getBounds:ce,getClosestPtOnSegment:le,pointInPolygon:ue,path2ContainsPath1:de},L={create(e=0,t=0,n=0){return{x:Math.round(e),y:Math.round(t),z:n}},fromPointD(e){return I.ensureSafeInteger(e.x,`Point64Utils.fromPointD`),I.ensureSafeInteger(e.y,`Point64Utils.fromPointD`),{x:Math.round(e.x),y:Math.round(e.y),z:e.z||0}},scale(e,t){return{x:Math.round(e.x*t),y:Math.round(e.y*t),z:e.z||0}},equals(e,t){return e.x===t.x&&e.y===t.y},add(e,t){if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.y)){let n=e.x+t.x,r=e.y+t.y;return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?{x:n,y:r,z:0}:{x:Number(BigInt(e.x)+BigInt(t.x)),y:Number(BigInt(e.y)+BigInt(t.y)),z:0}}return{x:e.x+t.x,y:e.y+t.y,z:0}},subtract(e,t){return{x:e.x-t.x,y:e.y-t.y,z:0}},toString(e){return e.z!==void 0&&e.z!==0?`${e.x},${e.y},${e.z} `:`${e.x},${e.y} `}},fe={create(e=0,t=0,n=0){return{x:e,y:t,z:n}},fromPoint64(e){return{x:e.x,y:e.y,z:e.z||0}},scale(e,t){return{x:e.x*t,y:e.y*t,z:e.z||0}},equals(e,t){return I.isAlmostZero(e.x-t.x)&&I.isAlmostZero(e.y-t.y)},negate(e){e.x=-e.x,e.y=-e.y},toString(e,t=2){return e.z!==void 0&&e.z!==0?`${e.x.toFixed(t)},${e.y.toFixed(t)},${e.z}`:`${e.x.toFixed(t)},${e.y.toFixed(t)}`}},R={create(e=0,t=0,n=0,r=0){return{left:e,top:t,right:n,bottom:r}},createInvalid(){return{left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)}},width(e){return e.right-e.left},height(e){return e.bottom-e.top},isEmpty(e){return e.bottom<=e.top||e.right<=e.left},isValid(e){return e.left<2**53-1},midPoint(e){return Number.isSafeInteger(e.left)&&Number.isSafeInteger(e.right)&&Math.abs(e.left)+Math.abs(e.right)>2**53-1?{x:Number((BigInt(e.left)+BigInt(e.right))/p),y:Number((BigInt(e.top)+BigInt(e.bottom))/p)}:{x:Math.round((e.left+e.right)/2),y:Math.round((e.top+e.bottom)/2)}},contains(e,t){return t.x>e.left&&t.x<e.right&&t.y>e.top&&t.y<e.bottom},containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom},intersects(e,t){return Math.max(e.left,t.left)<=Math.min(e.right,t.right)&&Math.max(e.top,t.top)<=Math.min(e.bottom,t.bottom)},asPath(e){return[{x:e.left,y:e.top,z:0},{x:e.right,y:e.top,z:0},{x:e.right,y:e.bottom,z:0},{x:e.left,y:e.bottom,z:0}]}},pe={create(e=0,t=0,n=0,r=0){return{left:e,top:t,right:n,bottom:r}},createInvalid(){return{left:Number.MAX_VALUE,top:Number.MAX_VALUE,right:-Number.MAX_VALUE,bottom:-Number.MAX_VALUE}},width(e){return e.right-e.left},height(e){return e.bottom-e.top},isEmpty(e){return e.bottom<=e.top||e.right<=e.left},midPoint(e){return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}},contains(e,t){return t.x>e.left&&t.x<e.right&&t.y>e.top&&t.y<e.bottom},containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom},intersects(e,t){return Math.max(e.left,t.left)<Math.min(e.right,t.right)&&Math.max(e.top,t.top)<Math.min(e.bottom,t.bottom)},asPath(e){return[{x:e.left,y:e.top,z:0},{x:e.right,y:e.top,z:0},{x:e.right,y:e.bottom,z:0},{x:e.left,y:e.bottom,z:0}]}},me={toString64(e){let t=``;for(let n of e)t+=L.toString(n);return t+`
2
+ `},toStringD(e,t=2){let n=``;for(let r of e)n+=fe.toString(r,t)+`, `;return n!==``&&(n=n.slice(0,-2)),n},reverse64(e){return[...e].reverse()},reverseD(e){return[...e].reverse()}},he={toString64(e){let t=``;for(let n of e)t+=me.toString64(n);return t},toStringD(e,t=2){let n=``;for(let r of e)n+=me.toStringD(r,t)+`
3
+ `;return n},reverse64(e){return e.map(e=>me.reverse64(e))},reverseD(e){return e.map(e=>me.reverseD(e))}},ge=Object.freeze(R.createInvalid()),_e=Object.freeze(pe.createInvalid()),ve=BigInt(0),ye=BigInt(2),be=BigInt(4);let z=function(e){return e[e.None=0]=`None`,e[e.OpenStart=1]=`OpenStart`,e[e.OpenEnd=2]=`OpenEnd`,e[e.LocalMax=4]=`LocalMax`,e[e.LocalMin=8]=`LocalMin`,e}({});var xe=class{data=[];push(e){this.data.push(e),this.siftUp(this.data.length-1)}pop(){if(this.data.length===0)return null;let e=this.data[0],t=this.data.pop();return this.data.length>0&&(this.data[0]=t,this.siftDown(0)),e}clear(){this.data.length=0}siftUp(e){let t=this.data[e];for(;e>0;){let n=e-1>>1;if(this.data[n]>=t)break;this.data[e]=this.data[n],e=n}this.data[e]=t}siftDown(e){let t=this.data.length,n=this.data[e];for(;;){let r=(e<<1)+1;if(r>=t)break;let i=r+1,a=r;if(i<t&&this.data[i]>this.data[r]&&(a=i),this.data[a]<=n)break;this.data[e]=this.data[a],e=a}this.data[e]=n}},Se=class{pt;next=null;prev=null;flags;constructor(e,t,n){this.pt=e,this.flags=t,this.prev=n}},Ce=class{vertex;polytype;isOpen;constructor(e,t,n=!1){this.vertex=e,this.polytype=t,this.isOpen=n}equals(e){return e!==null&&this.vertex===e.vertex}};function we(e,t,n=!1){return new Ce(e,t,n)}function Te(e,t,n){return{pt:e,edge1:t,edge2:n}}var Ee=class{pt;next;prev;outrec;horz;constructor(e,t){this.pt=e,this.outrec=t,this.next=this,this.prev=this,this.horz=null}};let De=function(e){return e[e.None=0]=`None`,e[e.Left=1]=`Left`,e[e.Right=2]=`Right`,e}({}),Oe=function(e){return e[e.Bottom=0]=`Bottom`,e[e.Middle=1]=`Middle`,e[e.Top=2]=`Top`,e}({});var ke=class{idx=0;owner=null;frontEdge=null;backEdge=null;pts=null;polypath=null;bounds={left:0,top:0,right:0,bottom:0};path=[];isOpen=!1;splits=null;recursiveSplit=null},Ae=class{leftOp;rightOp;leftToRight;constructor(e){this.leftOp=e,this.rightOp=null,this.leftToRight=!0}},je=class{op1;op2;constructor(e,t){this.op1=e,this.op2=t}},Me=class{bot={x:0,y:0};top={x:0,y:0};curX=0;dx=0;windDx=0;windCount=0;windCount2=0;outrec=null;prevInAEL=null;nextInAEL=null;prevInSEL=null;nextInSEL=null;jump=null;vertexTop=null;localMin=null;isLeftBound=!1;joinWith=De.None};const Ne={addLocMin(e,t,n,r){if((e.flags&z.LocalMin)!==z.None)return;e.flags|=z.LocalMin;let i=new Ce(e,t,n);r.push(i)},addPathsToVertexList(e,t,n,r,i){for(let a=0,o=e.length;a<o;a++){let o=e[a],s=null,c=null;for(let e=0,t=o.length;e<t;e++){let t=o[e];if(s===null)s=new Se(t,z.None,null),i.push(s),c=s;else if(!(c.pt.x===t.x&&c.pt.y===t.y)){let e=new Se(t,z.None,c);i.push(e),c.next=e,c=e}}if(c?.prev==null||(!n&&c.pt.x===s.pt.x&&c.pt.y===s.pt.y&&(c=c.prev),c.next=s,s.prev=c,!n&&c.next===c))continue;let l;if(n){let e=s.next;for(;e!==s&&e.pt.y===s.pt.y;)e=e.next;l=e.pt.y<=s.pt.y,l?(s.flags=z.OpenStart,Ne.addLocMin(s,t,!0,r)):s.flags=z.OpenStart|z.LocalMax}else{for(c=s.prev;c!==s&&c.pt.y===s.pt.y;)c=c.prev;if(c===s)continue;l=c.pt.y>s.pt.y}let u=l;c=s;let d=s.next;for(;d!==s;)d.pt.y>c.pt.y&&l?(c.flags|=z.LocalMax,l=!1):d.pt.y<c.pt.y&&!l&&(l=!0,Ne.addLocMin(c,t,n,r)),c=d,d=d.next;n?(c.flags|=z.OpenEnd,l?c.flags|=z.LocalMax:Ne.addLocMin(c,t,n,r)):l!==u&&(u?Ne.addLocMin(c,t,!1,r):c.flags|=z.LocalMax)}}};var Pe=class{minimaList;vertexList;constructor(){this.minimaList=[],this.vertexList=[]}clear(){this.minimaList.length=0,this.vertexList.length=0}addPaths(e,t,n){Ne.addPathsToVertexList(e,t,n,this.minimaList,this.vertexList)}},Fe=class{parent;children=[];constructor(e=null){this.parent=e}get isHole(){return this.getIsHole()}getLevel(){let e=0,t=this.parent;for(;t!==null;)++e,t=t.parent;return e}get level(){return this.getLevel()}getIsHole(){let e=this.getLevel();return e!==0&&(e&1)==0}get count(){return this.children.length}clear(){this.children.length=0}toStringInternal(e,t){let n=``,r=` `.repeat(t),i=this.children.length===1?``:`s`;t&1?n+=`${r}+- polygon (${e}) contains ${this.children.length} hole${i}.\n`:n+=`${r}+- hole (${e}) contains ${this.children.length} nested polygon${i}.\n`;for(let e=0;e<this.count;e++)this.children[e].count>0&&(n+=this.children[e].toStringInternal(e,t+1));return n}toString(){if(this.level>0)return``;let e=this.children.length===1?``:`s`,t=`Polytree with ${this.children.length} polygon${e}.\n`;for(let e=0;e<this.count;e++)this.children[e].count>0&&(t+=this.children[e].toStringInternal(e,1));return t+`
4
+ `}},Ie=class e extends Fe{polygon=null;constructor(e=null){super(e)}get poly(){return this.polygon}addChild(t){let n=new e(this);return n.polygon=t,this.children.push(n),n}child(e){if(e<0||e>=this.children.length)throw Error(`Index out of range`);return this.children[e]}area(){let e=this.polygon===null?0:Ue.area(this.polygon);for(let t of this.children)e+=t.area();return e}},Le=class e extends Fe{scale=1;polygon=null;constructor(e=null){super(e)}get poly(){return this.polygon}addChild(t){let n=new e(this);return n.scale=this.scale,n.polygon=Ue.scalePathD(t,1/this.scale),this.children.push(n),n}addChildD(t){let n=new e(this);return n.scale=this.scale,n.polygon=t,this.children.push(n),n}child(e){if(e<0||e>=this.children.length)throw Error(`Index out of range`);return this.children[e]}area(){let e=this.polygon===null?0:Ue.areaD(this.polygon);for(let t of this.children)e+=t.area();return e}},Re=class extends Ie{},ze=class extends Le{get scaleValue(){return this.scale}},Be=class e{static openPathsEnabled=!0;cliptype=n.NoClip;fillrule=i.EvenOdd;actives=null;sel=null;minimaList=[];intersectList=[];vertexList=[];outrecList=[];scanlineHeap=new xe;scanlineSet=new Set;scanlineArr=[];useScanlineArray=!1;horzSegList=[];horzJoinList=[];currentLocMin=0;currentBotY=0;isSortedMinimaList=!1;hasOpenPaths=!1;usingPolytree=!1;succeeded=!1;zCallbackInternal=void 0;preserveCollinear=!0;reverseSolution=!1;constructor(){}getZCallback(){}xyEqual(e,t){return e.x===t.x&&e.y===t.y}setZ(t,n,i){let a=this.zCallbackInternal;a&&(e.getPolyType(t)===r.Subject?(this.xyEqual(i,t.bot)?i.z=t.bot.z??0:this.xyEqual(i,t.top)?i.z=t.top.z??0:this.xyEqual(i,n.bot)?i.z=n.bot.z??0:this.xyEqual(i,n.top)?i.z=n.top.z??0:i.z=0,a(t.bot,t.top,n.bot,n.top,i)):(this.xyEqual(i,n.bot)?i.z=n.bot.z??0:this.xyEqual(i,n.top)?i.z=n.top.z??0:this.xyEqual(i,t.bot)?i.z=t.bot.z??0:this.xyEqual(i,t.top)?i.z=t.top.z??0:i.z=0,a(n.bot,n.top,t.bot,t.top,i)))}static isOdd(e){return(e&1)!=0}static isHotEdge(e){return e.outrec!=null}static isOpen(t){return e.openPathsEnabled&&t.localMin.isOpen}static isOpenEnd(t){return e.openPathsEnabled&&t.localMin.isOpen&&e.isOpenEndVertex(t.vertexTop)}static isOpenEndVertex(e){return(e.flags&(z.OpenStart|z.OpenEnd))!==z.None}static getPrevHotEdge(t){let n=t.prevInAEL;if(!e.openPathsEnabled){for(;n!==null&&!e.isHotEdge(n);)n=n.prevInAEL;return n}for(;n!==null&&(n.localMin.isOpen||!e.isHotEdge(n));)n=n.prevInAEL;return n}static isFront(e){return e===e.outrec.frontEdge}static getDx(e,t){let n=t.y-e.y;return n===0?t.x>e.x?-1/0:1/0:(t.x-e.x)/n}static topX(e,t){return t===e.top.y||e.top.x===e.bot.x?e.top.x:t===e.bot.y?e.bot.x:I.roundToEven(e.bot.x+e.dx*(t-e.bot.y))}static isHorizontal(e){return e.top.y===e.bot.y}static isHeadingRightHorz(e){return e.dx===-1/0}static isHeadingLeftHorz(e){return e.dx===1/0}static swapActives(e,t){return[t,e]}static getPolyType(e){return e.localMin.polytype}static isSamePolyType(e,t){return e.localMin.polytype===t.localMin.polytype}static setDx(t){t.dx=e.getDx(t.bot,t.top)}static nextVertex(e){return e.windDx>0?e.vertexTop.next:e.vertexTop.prev}static prevPrevVertex(e){return e.windDx>0?e.vertexTop.prev.prev:e.vertexTop.next.next}static isMaxima(t){return`flags`in t?(t.flags&z.LocalMax)!==z.None:e.isMaxima(t.vertexTop)}static getMaximaPair(e){let t=e.nextInAEL;for(;t!==null;){if(t.vertexTop===e.vertexTop)return t;t=t.nextInAEL}return null}boundingBoxesOverlap(e,t,n,r){let i=Math.min(e.x,t.x),a=Math.max(e.x,t.x),o=Math.min(e.y,t.y),s=Math.max(e.y,t.y),c=Math.min(n.x,r.x),l=Math.max(n.x,r.x),u=Math.min(n.y,r.y),d=Math.max(n.y,r.y);return!(a<c||l<i||s<u||d<o)}clearSolutionOnly(){for(;this.actives!==null;)this.deleteFromAEL(this.actives);this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.disposeIntersectNodes(),this.outrecList.length=0,this.horzSegList.length=0,this.horzJoinList.length=0}clear(){this.clearSolutionOnly(),this.minimaList.length=0,this.vertexList.length=0,this.currentLocMin=0,this.isSortedMinimaList=!1,this.hasOpenPaths=!1}reset(){this.isSortedMinimaList||=(this.minimaList.sort((e,t)=>t.vertex.pt.y-e.vertex.pt.y),!0),this.scanlineHeap.clear(),this.scanlineSet.clear(),this.scanlineArr.length=0,this.useScanlineArray=this.minimaList.length<=16;for(let e=this.minimaList.length-1;e>=0;e--)this.insertScanline(this.minimaList[e].vertex.pt.y);this.currentBotY=0,this.currentLocMin=0,this.actives=null,this.sel=null,this.succeeded=!0}upgradeScanlineStructureFromArray(){let e=this.scanlineArr;for(let t=0,n=e.length;t<n;t++){let n=e[t];this.scanlineSet.add(n),this.scanlineHeap.push(n)}e.length=0,this.useScanlineArray=!1}insertScanline(e){if(this.useScanlineArray){let t=this.scanlineArr;for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return;t.push(e),t.length>64&&this.upgradeScanlineStructureFromArray();return}this.scanlineSet.has(e)||(this.scanlineSet.add(e),this.scanlineHeap.push(e))}popScanline(){if(this.useScanlineArray){let e=this.scanlineArr,t=e.length;if(t===0)return null;let n=0,r=e[0];for(let i=1;i<t;i++){let t=e[i];t>r&&(r=t,n=i)}return e[n]=e[t-1],e.pop(),r}let e=this.scanlineHeap.pop();return e===null?null:(this.scanlineSet.delete(e),e)}hasLocMinAtY(e){return this.currentLocMin<this.minimaList.length&&this.minimaList[this.currentLocMin].vertex.pt.y===e}popLocalMinima(){return this.minimaList[this.currentLocMin++]}addPath(e,t,n=!1){let r=[e];this.addPaths(r,t,n)}addPaths(e,t,n=!1){n&&(this.hasOpenPaths=!0),this.isSortedMinimaList=!1,Ne.addPathsToVertexList(e,t,n,this.minimaList,this.vertexList)}addReuseableData(e){if(e.minimaList.length!==0){this.isSortedMinimaList=!1;for(let t of e.minimaList)this.minimaList.push(new Ce(t.vertex,t.polytype,t.isOpen)),t.isOpen&&(this.hasOpenPaths=!0)}}deleteFromAEL(e){let t=e.prevInAEL,n=e.nextInAEL;t===null&&n===null&&e!==this.actives||(t===null?this.actives=n:t.nextInAEL=n,n!==null&&(n.prevInAEL=t))}getBounds(){let e={left:2**53-1,top:2**53-1,right:-(2**53-1),bottom:-(2**53-1)};for(let t of this.vertexList){let n=t;do n.pt.x<e.left&&(e.left=n.pt.x),n.pt.x>e.right&&(e.right=n.pt.x),n.pt.y<e.top&&(e.top=n.pt.y),n.pt.y>e.bottom&&(e.bottom=n.pt.y),n=n.next;while(n!==t)}return R.isEmpty(e)?{left:0,top:0,right:0,bottom:0}:e}executeInternal(t,r){if(t===n.NoClip)return;e.openPathsEnabled=this.hasOpenPaths,this.zCallbackInternal=this.getZCallback(),this.fillrule=r,this.cliptype=t,this.reset();let i=this.popScanline();if(i!==null){for(;this.succeeded;){this.insertLocalMinimaIntoAEL(i);let e;for(;(e=this.popHorz())!==null;)this.doHorizontal(e);this.horzSegList.length>0&&(this.convertHorzSegsToJoins(),this.horzSegList.length=0),this.currentBotY=i;let t=this.popScanline();if(t===null)break;for(i=t,this.doIntersections(i),this.doTopOfScanbeam(i);(e=this.popHorz())!==null;)this.doHorizontal(e)}this.succeeded&&this.processHorzJoins()}}insertLocalMinimaIntoAEL(t){for(;this.hasLocMinAtY(t);){let t=this.popLocalMinima(),n;(t.vertex.flags&z.OpenStart)===z.None?(n=new Me,n.bot=t.vertex.pt,n.curX=t.vertex.pt.x,n.windDx=-1,n.vertexTop=t.vertex.prev,n.top=t.vertex.prev.pt,n.outrec=null,n.localMin=t,e.setDx(n)):n=null;let r;(t.vertex.flags&z.OpenEnd)===z.None?(r=new Me,r.bot=t.vertex.pt,r.curX=t.vertex.pt.x,r.windDx=1,r.vertexTop=t.vertex.next,r.top=t.vertex.next.pt,r.outrec=null,r.localMin=t,e.setDx(r)):r=null,n!==null&&r!==null?e.isHorizontal(n)?e.isHeadingRightHorz(n)&&([n,r]=e.swapActives(n,r)):e.isHorizontal(r)?e.isHeadingLeftHorz(r)&&([n,r]=e.swapActives(n,r)):n.dx<r.dx&&([n,r]=e.swapActives(n,r)):n===null&&(n=r,r=null);let i;if(n.isLeftBound=!0,this.insertLeftEdge(n),e.openPathsEnabled&&e.isOpen(n)?(this.setWindCountForOpenPathEdge(n),i=this.isContributingOpen(n)):(this.setWindCountForClosedPathEdge(n),i=this.isContributingClosed(n)),r!==null){for(r.windCount=n.windCount,r.windCount2=n.windCount2,this.insertRightEdge(n,r),i&&(this.addLocalMinPoly(n,r,n.bot,!0),e.isHorizontal(n)||this.checkJoinLeft(n,n.bot));r.nextInAEL!==null&&this.isValidAelOrder(r.nextInAEL,r);)this.intersectEdges(r,r.nextInAEL,r.bot),this.swapPositionsInAEL(r,r.nextInAEL);e.isHorizontal(r)?this.pushHorz(r):(this.checkJoinRight(r,r.bot),this.insertScanline(r.top.y))}else i&&e.openPathsEnabled&&this.startOpenPath(n,n.bot);e.isHorizontal(n)?this.pushHorz(n):this.insertScanline(n.top.y)}}pushHorz(e){e.nextInSEL=this.sel,this.sel=e}popHorz(){let e=this.sel;return e===null?null:(this.sel=this.sel.nextInSEL,e)}doHorizontal(t){if(!e.openPathsEnabled){this.doHorizontalClosed(t);return}let n=e.isOpen(t),r=t.bot.y,i=n?this.getCurrYMaximaVertexOpen(t):this.getCurrYMaximaVertex(t),{isLeftToRight:a,leftX:o,rightX:s}=this.resetHorzDirection(t,i),c=o,l=s;if(e.isHotEdge(t)){let e=this.addOutPt(t,{x:t.curX,y:r});this.addToHorzSegList(e)}for(;;){let o=a?t.nextInAEL:t.prevInAEL;for(;o!==null;){if(o.vertexTop===i){if(e.isHotEdge(t)&&this.isJoined(o)&&this.split(o,o.top),e.isHotEdge(t)){for(;t.vertexTop!==i;)this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);a?this.addLocalMaxPoly(t,o,t.top):this.addLocalMaxPoly(o,t,t.top)}this.deleteFromAEL(o),this.deleteFromAEL(t);return}if(i!==t.vertexTop||e.isOpenEnd(t)){if(a&&o.curX>l||!a&&o.curX<c)break;if(o.curX===t.top.x&&!e.isHorizontal(o)){let n=e.nextVertex(t).pt;if(e.isOpen(o)&&!e.isSamePolyType(o,t)&&!e.isHotEdge(o)){if(a&&e.topX(o,n.y)>n.x||!a&&e.topX(o,n.y)<n.x)break}else if(a&&e.topX(o,n.y)>=n.x||!a&&e.topX(o,n.y)<=n.x)break}}let n={x:o.curX,y:r};a?(this.intersectEdges(t,o,n),this.swapPositionsInAEL(t,o),this.checkJoinLeft(o,n),t.curX=o.curX,o=t.nextInAEL):(this.intersectEdges(o,t,n),this.swapPositionsInAEL(o,t),this.checkJoinRight(o,n),t.curX=o.curX,o=t.prevInAEL),e.isHotEdge(t)&&this.addToHorzSegList(this.getLastOp(t))}if(n&&e.isOpenEnd(t)){e.isHotEdge(t)&&(this.addOutPt(t,t.top),e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null),this.deleteFromAEL(t);return}if(e.nextVertex(t).pt.y!==t.top.y)break;e.isHotEdge(t)&&this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);let s=this.resetHorzDirection(t,i);c=s.leftX,l=s.rightX}if(e.isHotEdge(t)){let e=this.addOutPt(t,t.top);this.addToHorzSegList(e)}this.updateEdgeIntoAEL(t)}doHorizontalClosed(t){let n=t.bot.y,r=this.getCurrYMaximaVertex(t),{isLeftToRight:i,leftX:a,rightX:o}=this.resetHorzDirection(t,r),s=a,c=o;if(e.isHotEdge(t)){let e=this.addOutPt(t,{x:t.curX,y:n});this.addToHorzSegList(e)}for(;;){let a=i?t.nextInAEL:t.prevInAEL;for(;a!==null;){if(a.vertexTop===r){if(e.isHotEdge(t)&&this.isJoined(a)&&this.split(a,a.top),e.isHotEdge(t)){for(;t.vertexTop!==r;)this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);i?this.addLocalMaxPoly(t,a,t.top):this.addLocalMaxPoly(a,t,t.top)}this.deleteFromAEL(a),this.deleteFromAEL(t);return}if(r!==t.vertexTop){if(i&&a.curX>c||!i&&a.curX<s)break;if(a.curX===t.top.x&&!e.isHorizontal(a)){let n=e.nextVertex(t).pt,r=e.topX(a,n.y);if(i&&r>=n.x||!i&&r<=n.x)break}}let o={x:a.curX,y:n};i?(this.intersectEdges(t,a,o),this.swapPositionsInAEL(t,a),this.checkJoinLeft(a,o),t.curX=a.curX,a=t.nextInAEL):(this.intersectEdges(a,t,o),this.swapPositionsInAEL(a,t),this.checkJoinRight(a,o),t.curX=a.curX,a=t.prevInAEL),e.isHotEdge(t)&&this.addToHorzSegList(this.getLastOp(t))}if(e.nextVertex(t).pt.y!==t.top.y)break;e.isHotEdge(t)&&this.addOutPt(t,t.top),this.updateEdgeIntoAEL(t);let o=this.resetHorzDirection(t,r);s=o.leftX,c=o.rightX}if(e.isHotEdge(t)){let e=this.addOutPt(t,t.top);this.addToHorzSegList(e)}this.updateEdgeIntoAEL(t)}convertHorzSegsToJoins(){let e=0;for(let t of this.horzSegList)this.updateHorzSegment(t)&&e++;if(!(e<2)){this.horzSegList.sort((e,t)=>this.horzSegSort(e,t));for(let t=0;t<e-1;t++){let n=this.horzSegList[t];for(let r=t+1;r<e;r++){let e=this.horzSegList[r];if(e.leftOp.pt.x>=n.rightOp.pt.x||e.leftToRight===n.leftToRight||e.rightOp.pt.x<=n.leftOp.pt.x)continue;let t=n.leftOp.pt.y;if(n.leftToRight){for(;n.leftOp.next.pt.y===t&&n.leftOp.next.pt.x<=e.leftOp.pt.x;)n.leftOp=n.leftOp.next;for(;e.leftOp.prev.pt.y===t&&e.leftOp.prev.pt.x<=n.leftOp.pt.x;)e.leftOp=e.leftOp.prev;let r=new je(this.duplicateOp(n.leftOp,!0),this.duplicateOp(e.leftOp,!1));this.horzJoinList.push(r)}else{for(;n.leftOp.prev.pt.y===t&&n.leftOp.prev.pt.x<=e.leftOp.pt.x;)n.leftOp=n.leftOp.prev;for(;e.leftOp.next.pt.y===t&&e.leftOp.next.pt.x<=n.leftOp.pt.x;)e.leftOp=e.leftOp.next;let r=new je(this.duplicateOp(e.leftOp,!0),this.duplicateOp(n.leftOp,!1));this.horzJoinList.push(r)}}}}}updateHorzSegment(e){let t=e.leftOp,n=this.getRealOutRec(t.outrec),r=n.frontEdge!==null,i=t.pt.y,a=t,o=t;if(r){let e=n.pts,t=e.next;for(;a!==t&&a.prev.pt.y===i;)a=a.prev;for(;o!==e&&o.next.pt.y===i;)o=o.next}else{for(;a.prev!==o&&a.prev.pt.y===i;)a=a.prev;for(;o.next!==a&&o.next.pt.y===i;)o=o.next}let s=this.setHorzSegHeadingForward(e,a,o)&&e.leftOp.horz===null;return s?e.leftOp.horz=e:e.rightOp=null,s}setHorzSegHeadingForward(e,t,n){return t.pt.x===n.pt.x?!1:(t.pt.x<n.pt.x?(e.leftOp=t,e.rightOp=n,e.leftToRight=!0):(e.leftOp=n,e.rightOp=t,e.leftToRight=!1),!0)}horzSegSort(e,t){return e.rightOp===null?t.rightOp===null?0:1:t.rightOp===null?-1:e.leftOp.pt.x-t.leftOp.pt.x}duplicateOp(e,t){let n=new Ee(e.pt,e.outrec);return t?(n.next=e.next,n.next.prev=n,n.prev=e,e.next=n):(n.prev=e.prev,n.prev.next=n,n.next=e,e.prev=n),n}getRealOutRec(e){for(;e!==null&&e.pts===null;)e=e.owner;return e}doIntersections(e){this.buildIntersectList(e)&&(this.processIntersectList(),this.disposeIntersectNodes())}doTopOfScanbeam(t){this.sel=null;let n=this.actives;for(;n!==null;){if(n.top.y===t)if(n.curX=n.top.x,e.isMaxima(n)){n=this.doMaxima(n);continue}else e.isHotEdge(n)&&this.addOutPt(n,n.top),this.updateEdgeIntoAEL(n),e.isHorizontal(n)&&this.pushHorz(n);else n.curX=e.topX(n,t);n=n.nextInAEL}}processHorzJoins(){for(let e of this.horzJoinList){let t=this.getRealOutRec(e.op1.outrec),n=this.getRealOutRec(e.op2.outrec),r=e.op1.next,i=e.op2.prev;if(e.op1.next=e.op2,e.op2.prev=e.op1,r.prev=i,i.next=r,t===n){let n=this.newOutRec();n.pts=r,this.fixOutRecPts(n),t.pts.outrec===n&&(t.pts=e.op1,t.pts.outrec=t),this.usingPolytree?(this.path1InsidePath2(t.pts,n.pts)?([n.pts,t.pts]=[t.pts,n.pts],this.fixOutRecPts(t),this.fixOutRecPts(n),n.owner=t):this.path1InsidePath2(n.pts,t.pts)?n.owner=t:n.owner=t.owner,t.splits===null&&(t.splits=[]),t.splits.push(n.idx)):n.owner=t}else n.pts=null,this.usingPolytree?(this.setOwner(n,t),this.moveSplits(n,t)):n.owner=t}}fixOutRecPts(e){let t=e.pts;do t.outrec=e,t=t.next;while(t!==e.pts)}path1InsidePath2(e,t){let n=a.IsOn,r=e;do{switch(this.pointInOpPolygon(r.pt,t)){case a.IsOutside:if(n===a.IsOutside)return!1;n=a.IsOutside;break;case a.IsInside:if(n===a.IsInside)return!0;n=a.IsInside;break;default:break}r=r.next}while(r!==e);return I.path2ContainsPath1(this.getCleanPath(e),this.getCleanPath(t))}pointInOpPolygon(e,t){if(t===t.next||t.prev===t.next)return a.IsOutside;let n=t;do{if(t.pt.y!==e.y)break;t=t.next}while(t!==n);if(t.pt.y===e.y)return a.IsOutside;let r=t.pt.y<e.y,i=r,o=0;for(n=t.next;n!==t;){if(r)for(;n!==t&&n.pt.y<e.y;)n=n.next;else for(;n!==t&&n.pt.y>e.y;)n=n.next;if(n===t)break;if(n.pt.y===e.y){if(n.pt.x===e.x||n.pt.y===n.prev.pt.y&&e.x<n.prev.pt.x!=e.x<n.pt.x)return a.IsOn;if(n=n.next,n===t)break;continue}if(n.pt.x<=e.x||n.prev.pt.x<=e.x)if(n.prev.pt.x<e.x&&n.pt.x<e.x)o=1-o;else{let t=I.crossProductSign(n.prev.pt,n.pt,e);if(t===0)return a.IsOn;t<0===r&&(o=1-o)}r=!r,n=n.next}if(r===i)return o===0?a.IsOutside:a.IsInside;{let t=I.crossProductSign(n.prev.pt,n.pt,e);if(t===0)return a.IsOn;t<0===r&&(o=1-o)}return o===0?a.IsOutside:a.IsInside}getCleanPath(e){let t=[],n=e;for(;n.next!==e&&(n.pt.x===n.next.pt.x&&n.pt.x===n.prev.pt.x||n.pt.y===n.next.pt.y&&n.pt.y===n.prev.pt.y);)n=n.next;t.push(n.pt);let r=n;for(n=n.next;n!==e;)(n.pt.x!==n.next.pt.x||n.pt.x!==r.pt.x)&&(n.pt.y!==n.next.pt.y||n.pt.y!==r.pt.y)&&(t.push(n.pt),r=n),n=n.next;return t}moveSplits(e,t){if(e.splits!==null){t.splits===null&&(t.splits=[]);for(let n of e.splits)n!==t.idx&&t.splits.push(n);e.splits=null}}buildIntersectList(e){if(this.actives?.nextInAEL===null)return!1;this.adjustCurrXAndCopyToSEL(e);let t=this.sel;for(;t!==null&&t.jump!==null;){let n=null;for(;t!==null&&t.jump!==null;){let r=t,i=t.jump,a=i,o=i?.jump||null;for(t.jump=o;t!==a&&i!==o;)if(i.curX<t.curX){let s=i.prevInSEL;for(;this.addNewIntersectNode(s,i,e),s!==t;)s=s.prevInSEL;if(s=i,i=this.extractFromSEL(s),a=i,t!==null&&this.insert1Before2InSEL(s,t),t!==r)continue;r=s,r.jump=o,n===null?this.sel=r:n.jump=r}else t=t.nextInSEL;n=r,t=o}t=this.sel}return this.intersectList.length>0}processIntersectList(){this.intersectList.sort((e,t)=>e.pt.y===t.pt.y?e.pt.x===t.pt.x?e.edge1.curX===t.edge1.curX?e.edge2.curX<t.edge2.curX?-1:e.edge2.curX>t.edge2.curX?1:0:e.edge1.curX<t.edge1.curX?-1:1:e.pt.x<t.pt.x?-1:1:e.pt.y>t.pt.y?-1:1);for(let e=0;e<this.intersectList.length;++e){if(!this.edgesAdjacentInAEL(this.intersectList[e])){let t=e+1;for(;!this.edgesAdjacentInAEL(this.intersectList[t]);)t++;[this.intersectList[t],this.intersectList[e]]=[this.intersectList[e],this.intersectList[t]]}let t=this.intersectList[e];this.intersectEdges(t.edge1,t.edge2,t.pt),this.swapPositionsInAEL(t.edge1,t.edge2),t.edge1.curX=t.pt.x,t.edge2.curX=t.pt.x,this.checkJoinLeft(t.edge2,t.pt,!0),this.checkJoinRight(t.edge1,t.pt,!0)}}edgesAdjacentInAEL(e){return e.edge1.nextInAEL===e.edge2||e.edge1.prevInAEL===e.edge2}adjustCurrXAndCopyToSEL(t){let n=this.actives;for(this.sel=n;n!==null;)n.prevInSEL=n.prevInAEL,n.nextInSEL=n.nextInAEL,n.jump=n.nextInSEL,n.curX=e.topX(n,t),n=n.nextInAEL}doMaxima(t){let n=t.prevInAEL,r=t.nextInAEL;if(e.isOpenEnd(t))return e.isHotEdge(t)&&this.addOutPt(t,t.top),e.isHorizontal(t)?r:(e.isHotEdge(t)&&(e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null),this.deleteFromAEL(t),r);let i=e.getMaximaPair(t);if(i===null)return r;for(this.isJoined(t)&&this.split(t,t.top),this.isJoined(i)&&this.split(i,i.top);r!==i;)this.intersectEdges(t,r,t.top),this.swapPositionsInAEL(t,r),r=t.nextInAEL;return e.isOpen(t)?(e.isHotEdge(t)&&this.addLocalMaxPoly(t,i,t.top),this.deleteFromAEL(i),this.deleteFromAEL(t),n===null?this.actives:n.nextInAEL):(e.isHotEdge(t)&&this.addLocalMaxPoly(t,i,t.top),this.deleteFromAEL(t),this.deleteFromAEL(i),n===null?this.actives:n.nextInAEL)}updateEdgeIntoAEL(t){if(t.bot=t.top,t.vertexTop=e.nextVertex(t),t.top=t.vertexTop.pt,t.curX=t.bot.x,e.setDx(t),this.isJoined(t)&&this.split(t,t.bot),e.isHorizontal(t)){e.openPathsEnabled&&e.isOpen(t)||this.trimHorz(t,this.preserveCollinear);return}this.insertScanline(t.top.y),this.checkJoinLeft(t,t.bot),this.checkJoinRight(t,t.bot,!0)}trimHorz(t,n){let r=!1,i=e.nextVertex(t).pt;for(;i.y===t.top.y&&!(n&&i.x<t.top.x!=t.bot.x<t.top.x||(t.vertexTop=e.nextVertex(t),t.top=i,r=!0,e.isMaxima(t)));)i=e.nextVertex(t).pt;r&&e.setDx(t)}addToHorzSegList(e){e.outrec.isOpen||this.horzSegList.push(new Ae(e))}addNewIntersectNode(t,n,r){let i=I.getLineIntersectPt(t.bot,t.top,n.bot,n.top);if(i===null&&(i={x:t.curX,y:r}),i.y>this.currentBotY||i.y<r){let a=Math.abs(t.dx),o=Math.abs(n.dx);a>100&&o>100?i=a>o?I.getClosestPtOnSegment(i,t.bot,t.top):I.getClosestPtOnSegment(i,n.bot,n.top):a>100?i=I.getClosestPtOnSegment(i,t.bot,t.top):o>100?i=I.getClosestPtOnSegment(i,n.bot,n.top):(i.y<r?i.y=r:i.y=this.currentBotY,a<o?i.x=e.topX(t,i.y):i.x=e.topX(n,i.y))}let a=Te(i,t,n);this.intersectList.push(a)}extractFromSEL(e){let t=e.nextInSEL;return t!==null&&(t.prevInSEL=e.prevInSEL),e.prevInSEL.nextInSEL=t,t}insert1Before2InSEL(e,t){e.prevInSEL=t.prevInSEL,e.prevInSEL!==null&&(e.prevInSEL.nextInSEL=e),e.nextInSEL=t,t.prevInSEL=e}getCurrYMaximaVertexOpen(t){let n=t.vertexTop;if(t.windDx>0)for(;n.next.pt.y===n.pt.y&&(n.flags&(z.OpenEnd|z.LocalMax))===z.None;)n=n.next;else for(;n.prev.pt.y===n.pt.y&&(n.flags&(z.OpenEnd|z.LocalMax))===z.None;)n=n.prev;return e.isMaxima(n)||(n=null),n}getCurrYMaximaVertex(t){let n=t.vertexTop;if(t.windDx>0)for(;n.next.pt.y===n.pt.y;)n=n.next;else for(;n.prev.pt.y===n.pt.y;)n=n.prev;return e.isMaxima(n)||(n=null),n}resetHorzDirection(e,t){if(e.bot.x===e.top.x){let n=e.curX,r=e.curX,i=e.nextInAEL;for(;i!==null&&i.vertexTop!==t;)i=i.nextInAEL;return{isLeftToRight:i!==null,leftX:n,rightX:r}}return e.curX<e.top.x?{isLeftToRight:!0,leftX:e.curX,rightX:e.top.x}:{isLeftToRight:!1,leftX:e.top.x,rightX:e.curX}}getLastOp(e){let t=e.outrec;return e===t.frontEdge?t.pts:t.pts.next}insertLeftEdge(e){if(this.actives===null)e.prevInAEL=null,e.nextInAEL=null,this.actives=e;else if(!this.isValidAelOrder(this.actives,e))e.prevInAEL=null,e.nextInAEL=this.actives,this.actives.prevInAEL=e,this.actives=e;else{let t=this.actives;for(;t.nextInAEL!==null&&this.isValidAelOrder(t.nextInAEL,e);)t=t.nextInAEL;t.joinWith===De.Right&&(t=t.nextInAEL),e.nextInAEL=t.nextInAEL,t.nextInAEL!==null&&(t.nextInAEL.prevInAEL=e),e.prevInAEL=t,t.nextInAEL=e}}insertRightEdge(e,t){t.nextInAEL=e.nextInAEL,e.nextInAEL!==null&&(e.nextInAEL.prevInAEL=t),t.prevInAEL=e,e.nextInAEL=t}setWindCountForOpenPathEdge(t){let n=this.actives;if(this.fillrule===i.EvenOdd){let i=0,a=0;for(;n!==t;)e.getPolyType(n)===r.Clip?a++:e.isOpen(n)||i++,n=n.nextInAEL;t.windCount=e.isOdd(i)?1:0,t.windCount2=e.isOdd(a)?1:0}else for(;n!==t;)e.getPolyType(n)===r.Clip?t.windCount2+=n.windDx:e.isOpen(n)||(t.windCount+=n.windDx),n=n.nextInAEL}setWindCountForClosedPathEdge(t){let n=t.prevInAEL,r=e.getPolyType(t);if(!e.openPathsEnabled){for(;n!==null&&e.getPolyType(n)!==r;)n=n.prevInAEL;if(n===null?(t.windCount=t.windDx,n=this.actives):this.fillrule===i.EvenOdd?(t.windCount=t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx:t.windCount=t.windDx:n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===i.EvenOdd)for(;n!==t;)e.getPolyType(n)!==r&&(t.windCount2=t.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==t;)e.getPolyType(n)!==r&&(t.windCount2+=n.windDx),n=n.nextInAEL;return}for(;n!==null&&(e.getPolyType(n)!==r||e.isOpen(n));)n=n.prevInAEL;if(n===null?(t.windCount=t.windDx,n=this.actives):this.fillrule===i.EvenOdd?(t.windCount=t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL):(n.windCount*n.windDx<0?Math.abs(n.windCount)>1?n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx:t.windCount=e.isOpen(t)?1:t.windDx:n.windDx*t.windDx<0?t.windCount=n.windCount:t.windCount=n.windCount+t.windDx,t.windCount2=n.windCount2,n=n.nextInAEL),this.fillrule===i.EvenOdd)for(;n!==t;)e.getPolyType(n)!==r&&!e.isOpen(n)&&(t.windCount2=t.windCount2===0?1:0),n=n.nextInAEL;else for(;n!==t;)e.getPolyType(n)!==r&&!e.isOpen(n)&&(t.windCount2+=n.windDx),n=n.nextInAEL}isContributingOpen(e){let t,r;switch(this.fillrule){case i.Positive:r=e.windCount>0,t=e.windCount2>0;break;case i.Negative:r=e.windCount<0,t=e.windCount2<0;break;default:r=e.windCount!==0,t=e.windCount2!==0;break}switch(this.cliptype){case n.Intersection:return t;case n.Union:return!r&&!t;default:return!t}}isContributingClosed(t){switch(this.fillrule){case i.Positive:if(t.windCount!==1)return!1;break;case i.Negative:if(t.windCount!==-1)return!1;break;case i.NonZero:if(Math.abs(t.windCount)!==1)return!1;break}switch(this.cliptype){case n.Intersection:return this.fillrule===i.Positive?t.windCount2>0:this.fillrule===i.Negative?t.windCount2<0:t.windCount2!==0;case n.Union:return this.fillrule===i.Positive?t.windCount2<=0:this.fillrule===i.Negative?t.windCount2>=0:t.windCount2===0;case n.Difference:{let n=this.fillrule===i.Positive?t.windCount2<=0:this.fillrule===i.Negative?t.windCount2>=0:t.windCount2===0;return e.getPolyType(t)===r.Subject?n:!n}case n.Xor:return!0;default:return!1}}addLocalMinPoly(t,n,r,i=!1){let a=this.newOutRec();if(t.outrec=a,n.outrec=a,e.isOpen(t))a.owner=null,a.isOpen=!0,t.windDx>0?this.setSides(a,t,n):this.setSides(a,n,t);else{a.isOpen=!1;let r=e.getPrevHotEdge(t);r===null?(a.owner=null,i?this.setSides(a,t,n):this.setSides(a,n,t)):(this.usingPolytree&&this.setOwner(a,r.outrec),a.owner=r.outrec,this.outrecIsAscending(r)===i?this.setSides(a,n,t):this.setSides(a,t,n))}let o=new Ee(r,a);return a.pts=o,o}outrecIsAscending(e){return e===e.outrec.frontEdge}newOutRec(){let e=new ke;return e.idx=this.outrecList.length,this.outrecList.push(e),e}startOpenPath(e,t){let n=this.newOutRec();n.isOpen=!0,e.windDx>0?(n.frontEdge=e,n.backEdge=null):(n.frontEdge=null,n.backEdge=e),e.outrec=n;let r=new Ee(t,n);return n.pts=r,r}checkJoinLeft(t,n,r=!1){let i=t.prevInAEL;if(!(i===null||!e.isHotEdge(t)||!e.isHotEdge(i)||e.isHorizontal(t)||e.isHorizontal(i)||e.isOpen(t)||e.isOpen(i))&&!((n.y<t.top.y+2||n.y<i.top.y+2)&&(t.bot.y>n.y||i.bot.y>n.y))){if(r){if(this.perpendicDistFromLineSqrdGreaterThanQuarter(n,i.bot,i.top))return}else if(t.curX!==i.curX)return;I.isCollinear(t.top,n,i.top)&&(t.outrec.idx===i.outrec.idx?this.addLocalMaxPoly(i,t,n):t.outrec.idx<i.outrec.idx?this.joinOutrecPaths(t,i):this.joinOutrecPaths(i,t),i.joinWith=De.Right,t.joinWith=De.Left)}}checkJoinRight(t,n,r=!1){let i=t.nextInAEL;if(!(i===null||!e.isHotEdge(t)||!e.isHotEdge(i)||e.isHorizontal(t)||e.isHorizontal(i)||e.isOpen(t)||e.isOpen(i))&&!((n.y<t.top.y+2||n.y<i.top.y+2)&&(t.bot.y>n.y||i.bot.y>n.y))){if(r){if(this.perpendicDistFromLineSqrdGreaterThanQuarter(n,i.bot,i.top))return}else if(t.curX!==i.curX)return;I.isCollinear(t.top,n,i.top)&&(t.outrec.idx===i.outrec.idx?this.addLocalMaxPoly(t,i,n):t.outrec.idx<i.outrec.idx?this.joinOutrecPaths(t,i):this.joinOutrecPaths(i,t),t.joinWith=De.Right,i.joinWith=De.Left)}}perpendicDistFromLineSqrdGreaterThanQuarter(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;if(a===0&&o===0)return!1;let s=I.maxCoordForSafeCrossSq;if(Math.abs(r)<s&&Math.abs(i)<s&&Math.abs(a)<s&&Math.abs(o)<s){let e=r*o-a*i;return e*e/(a*a+o*o)>.25}if(Number.isSafeInteger(r)&&Number.isSafeInteger(i)&&Number.isSafeInteger(a)&&Number.isSafeInteger(o)){let e=BigInt(r)*BigInt(o)-BigInt(a)*BigInt(i),t=e*e,n=BigInt(a)*BigInt(a)+BigInt(o)*BigInt(o);return be*t>n}let c=r*o-a*i;return c*c/(a*a+o*o)>.25}intersectEdges(t,a,o){let s;if(this.hasOpenPaths&&(e.isOpen(t)||e.isOpen(a))){if(e.isOpen(t)&&e.isOpen(a))return;if(e.isOpen(a)&&([t,a]=e.swapActives(t,a)),this.isJoined(a)&&this.split(a,o),this.cliptype===n.Union){if(!e.isHotEdge(a))return}else if(a.localMin.polytype===r.Subject)return;switch(this.fillrule){case i.Positive:if(a.windCount!==1)return;break;case i.Negative:if(a.windCount!==-1)return;break;default:if(Math.abs(a.windCount)!==1)return;break}if(e.isHotEdge(t))s=this.addOutPt(t,o),this.setZ(t,a,s.pt),e.isFront(t)?t.outrec.frontEdge=null:t.outrec.backEdge=null,t.outrec=null;else if(o.x===t.localMin.vertex.pt.x&&o.y===t.localMin.vertex.pt.y&&!e.isOpenEndVertex(t.localMin.vertex)){let n=this.findEdgeWithMatchingLocMin(t);if(n!==null&&e.isHotEdge(n)){t.outrec=n.outrec,t.windDx>0?this.setSides(n.outrec,t,n):this.setSides(n.outrec,n,t);return}s=this.startOpenPath(t,o)}else s=this.startOpenPath(t,o);this.setZ(t,a,s.pt);return}this.isJoined(t)&&this.split(t,o),this.isJoined(a)&&this.split(a,o);let c,l;switch(t.localMin.polytype===a.localMin.polytype?this.fillrule===i.EvenOdd?(c=t.windCount,t.windCount=a.windCount,a.windCount=c):(t.windCount+a.windDx===0?t.windCount=-t.windCount:t.windCount+=a.windDx,a.windCount-t.windDx===0?a.windCount=-a.windCount:a.windCount-=t.windDx):(this.fillrule===i.EvenOdd?t.windCount2=t.windCount2===0?1:0:t.windCount2+=a.windDx,this.fillrule===i.EvenOdd?a.windCount2=a.windCount2===0?1:0:a.windCount2-=t.windDx),this.fillrule){case i.Positive:c=t.windCount,l=a.windCount;break;case i.Negative:c=-t.windCount,l=-a.windCount;break;default:c=Math.abs(t.windCount),l=Math.abs(a.windCount);break}let u=c===0||c===1,d=l===0||l===1;if(!(!e.isHotEdge(t)&&!u||!e.isHotEdge(a)&&!d))if(e.isHotEdge(t)&&e.isHotEdge(a))if(c!==0&&c!==1||l!==0&&l!==1||t.localMin.polytype!==a.localMin.polytype&&this.cliptype!==n.Xor)s=this.addLocalMaxPoly(t,a,o),s&&this.setZ(t,a,s.pt);else if(e.isFront(t)||t.outrec===a.outrec){s=this.addLocalMaxPoly(t,a,o),s&&this.setZ(t,a,s.pt);let e=this.addLocalMinPoly(t,a,o);this.setZ(t,a,e.pt)}else{s=this.addOutPt(t,o),this.setZ(t,a,s.pt);let e=this.addOutPt(a,o);this.setZ(t,a,e.pt),this.swapOutrecs(t,a)}else if(e.isHotEdge(t))s=this.addOutPt(t,o),this.setZ(t,a,s.pt),this.swapOutrecs(t,a);else if(e.isHotEdge(a))s=this.addOutPt(a,o),this.setZ(t,a,s.pt),this.swapOutrecs(t,a);else{let u,d;switch(this.fillrule){case i.Positive:u=t.windCount2,d=a.windCount2;break;case i.Negative:u=-t.windCount2,d=-a.windCount2;break;default:u=Math.abs(t.windCount2),d=Math.abs(a.windCount2);break}if(!e.isSamePolyType(t,a))s=this.addLocalMinPoly(t,a,o),this.setZ(t,a,s.pt);else if(c===1&&l===1){switch(s=null,this.cliptype){case n.Union:if(u>0&&d>0)return;s=this.addLocalMinPoly(t,a,o);break;case n.Difference:(e.getPolyType(t)===r.Clip&&u>0&&d>0||e.getPolyType(t)===r.Subject&&u<=0&&d<=0)&&(s=this.addLocalMinPoly(t,a,o));break;case n.Xor:s=this.addLocalMinPoly(t,a,o);break;default:if(u<=0||d<=0)return;s=this.addLocalMinPoly(t,a,o);break}s&&this.setZ(t,a,s.pt)}}}swapPositionsInAEL(e,t){let n=t.nextInAEL;n!==null&&(n.prevInAEL=e);let r=e.prevInAEL;r!==null&&(r.nextInAEL=t),t.prevInAEL=r,t.nextInAEL=e,e.prevInAEL=t,e.nextInAEL=n,t.prevInAEL===null&&(this.actives=t)}isValidAelOrder(t,n){if(n.curX!==t.curX)return n.curX>t.curX;let r=I.crossProductSign(t.top,n.bot,n.top);if(r!==0)return r<0;if(!e.isMaxima(t)&&t.top.y>n.top.y)return I.crossProductSign(n.bot,t.top,e.nextVertex(t).pt)<=0;if(!e.isMaxima(n)&&n.top.y>t.top.y)return I.crossProductSign(n.bot,n.top,e.nextVertex(n).pt)>=0;let i=n.bot.y,a=n.isLeftBound;return t.bot.y!==i||t.localMin.vertex.pt.y!==i?n.isLeftBound:t.isLeftBound===a?I.isCollinear(e.prevPrevVertex(t).pt,t.bot,t.top)?!0:I.crossProductSign(e.prevPrevVertex(t).pt,n.bot,e.prevPrevVertex(n).pt)>0===a:a}isJoined(e){return e.joinWith!==De.None}split(e,t){e.joinWith===De.Right?(e.joinWith=De.None,e.nextInAEL.joinWith=De.None,this.addLocalMinPoly(e,e.nextInAEL,t,!0)):(e.joinWith=De.None,e.prevInAEL.joinWith=De.None,this.addLocalMinPoly(e.prevInAEL,e,t,!0))}setSides(e,t,n){e.frontEdge=t,e.backEdge=n}findEdgeWithMatchingLocMin(t){let n=t.nextInAEL;for(;n!==null;){if(n.localMin?.equals(t.localMin))return n;n=!e.isHorizontal(n)&&!(t.bot.x===n.bot.x&&t.bot.y===n.bot.y)?null:n.nextInAEL}for(n=t.prevInAEL;n!==null;){if(n.localMin?.equals(t.localMin))return n;if(!e.isHorizontal(n)&&!(t.bot.x===n.bot.x&&t.bot.y===n.bot.y))return null;n=n.prevInAEL}return n}addOutPt(t,n){let r=t.outrec,i=e.isFront(t),a=r.pts,o=a.next;if(i&&n.x===a.pt.x&&n.y===a.pt.y)return a;if(!i&&n.x===o.pt.x&&n.y===o.pt.y)return o;let s=new Ee(n,r);return o.prev=s,s.prev=a,s.next=o,a.next=s,i&&(r.pts=s),s}addLocalMaxPoly(t,n,r){if(this.isJoined(t)&&this.split(t,r),this.isJoined(n)&&this.split(n,r),e.isFront(t)===e.isFront(n))if(e.isOpenEnd(t))this.swapFrontBackSides(t.outrec);else if(e.isOpenEnd(n))this.swapFrontBackSides(n.outrec);else return this.succeeded=!1,null;let i=this.addOutPt(t,r);if(t.outrec===n.outrec){let n=t.outrec;if(n.pts=i,this.usingPolytree){let r=e.getPrevHotEdge(t);r===null?n.owner=null:this.setOwner(n,r.outrec)}this.uncoupleOutRec(t)}else e.isOpen(t)?t.windDx<0?this.joinOutrecPaths(t,n):this.joinOutrecPaths(n,t):t.outrec.idx<n.outrec.idx?this.joinOutrecPaths(t,n):this.joinOutrecPaths(n,t);return i}swapFrontBackSides(e){let t=e.frontEdge;e.frontEdge=e.backEdge,e.backEdge=t,e.pts=e.pts.next}setOwner(e,t){for(;t.owner!==null&&t.owner.pts===null;)t.owner=t.owner.owner;let n=t;for(;n!==null&&n!==e;)n=n.owner;n!==null&&(t.owner=e.owner),e.owner=t}uncoupleOutRec(e){let t=e.outrec;t!==null&&(t.frontEdge.outrec=null,t.backEdge.outrec=null,t.frontEdge=null,t.backEdge=null)}joinOutrecPaths(t,n){let r=t.outrec.pts,i=n.outrec.pts,a=r.next,o=i.next;e.isFront(t)?(o.prev=r,r.next=o,i.next=a,a.prev=i,t.outrec.pts=i,t.outrec.frontEdge=n.outrec.frontEdge,t.outrec.frontEdge!==null&&(t.outrec.frontEdge.outrec=t.outrec)):(a.prev=i,i.next=a,r.next=o,o.prev=r,t.outrec.backEdge=n.outrec.backEdge,t.outrec.backEdge!==null&&(t.outrec.backEdge.outrec=t.outrec)),n.outrec.frontEdge=null,n.outrec.backEdge=null,n.outrec.pts=null,this.setOwner(n.outrec,t.outrec),e.isOpenEnd(t)&&(n.outrec.pts=t.outrec.pts,t.outrec.pts=null),t.outrec=null,n.outrec=null}swapOutrecs(e,t){let n=e.outrec,r=t.outrec;if(n===r){let e=n.frontEdge;n.frontEdge=n.backEdge,n.backEdge=e;return}n!==null&&(e===n.frontEdge?n.frontEdge=t:n.backEdge=t),r!==null&&(t===r.frontEdge?r.frontEdge=e:r.backEdge=e),e.outrec=r,t.outrec=n}disposeIntersectNodes(){this.intersectList.length=0}static ptsReallyClose(e,t){return Math.abs(e.x-t.x)<2&&Math.abs(e.y-t.y)<2}static isVerySmallTriangle(t){return t.next.next===t.prev&&(e.ptsReallyClose(t.prev.pt,t.next.pt)||e.ptsReallyClose(t.pt,t.next.pt)||e.ptsReallyClose(t.pt,t.prev.pt))}static buildPath(t,n,r,i){if(t===null||t.next===t||!r&&t.next===t.prev)return!1;i.length=0;let a,o;for(n?(a=t.pt,o=t.prev):(t=t.next,a=t.pt,o=t.next),i.push(a);o!==t;)o.pt.x===a.x&&o.pt.y===a.y||(a=o.pt,i.push(a)),o=n?o.prev:o.next;return i.length!==3||r||!e.isVerySmallTriangle(o)}buildPaths(t,n){t.length=0,n.length=0;let r=0;for(;r<this.outrecList.length;){let i=this.outrecList[r++];if(i.pts===null)continue;let a=[];i.isOpen?e.buildPath(i.pts,this.reverseSolution,!0,a)&&n.push(a):(this.cleanCollinear(i),e.buildPath(i.pts,this.reverseSolution,!1,a)&&t.push(a))}return!0}buildTree(t,n){t.clear(),n.length=0;let r=0;for(;r<this.outrecList.length;){let i=this.outrecList[r++];if(i.pts!==null){if(i.isOpen){let t=[];e.buildPath(i.pts,this.reverseSolution,!0,t)&&n.push(t);continue}this.checkBounds(i)&&this.recursiveCheckOwners(i,t)}}}checkBounds(t){return t.pts===null?!1:R.isEmpty(t.bounds)?(this.cleanCollinear(t),t.pts===null||!e.buildPath(t.pts,this.reverseSolution,!1,t.path)?!1:(t.bounds=I.getBounds(t.path),!0)):!0}recursiveCheckOwners(e,t){if(!(e.polypath!==null||R.isEmpty(e.bounds))){for(;e.owner!==null&&!(e.owner.splits!==null&&this.checkSplitOwner(e,e.owner.splits)||e.owner.pts!==null&&this.checkBounds(e.owner)&&this.containsRect(e.owner.bounds,e.bounds)&&this.path1InsidePath2(e.pts,e.owner.pts));)e.owner=e.owner.owner;e.owner===null?e.polypath=t.addChild(e.path):(e.owner.polypath===null&&this.recursiveCheckOwners(e.owner,t),e.polypath=e.owner.polypath.addChild(e.path))}}cleanCollinear(e){if(e=this.getRealOutRec(e),e===null||e.isOpen)return;if(!this.isValidClosedPath(e.pts)){e.pts=null;return}let t=e.pts,n=t;for(;;){if(n!==null&&I.isCollinear(n.prev.pt,n.pt,n.next.pt)&&(n.pt.x===n.prev.pt.x&&n.pt.y===n.prev.pt.y||n.pt.x===n.next.pt.x&&n.pt.y===n.next.pt.y||!this.preserveCollinear||I.dotProductSign(n.prev.pt,n.pt,n.next.pt)<0)){if(n===e.pts&&(e.pts=n.prev),n=this.disposeOutPt(n),!this.isValidClosedPath(n)){e.pts=null;return}t=n;continue}if(n===null||(n=n.next,n===t))break}this.fixSelfIntersects(e)}isValidClosedPath(t){return t!==null&&t.next!==t&&(t.next!==t.prev||!e.isVerySmallTriangle(t))}disposeOutPt(e){let t=e.next===e?null:e.next;return e.prev.next=e.next,e.next.prev=e.prev,t}fixSelfIntersects(e){let t=e.pts;if(t.prev!==t.next.next)for(;;){if(t.next&&t.next.next&&this.boundingBoxesOverlap(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)&&I.segsIntersect(t.prev.pt,t.pt,t.next.pt,t.next.next.pt)){if((t===e.pts||t.next===e.pts)&&(e.pts=e.pts.prev),this.doSplitOp(e,t),e.pts===null)return;if(t=e.pts,t.prev===t.next.next)break;continue}if(t=t.next,t===e.pts)break}}doSplitOp(t,n){let r=n.prev,i=n.next.next;t.pts=r;let a=I.getLineIntersectPt(r.pt,n.pt,n.next.pt,i.pt),o=e.areaOutPt(r),s=o<ve?-o:o;if(s<be){t.pts=null;return}let c=this.areaTriangle(a,n.pt,n.next.pt),l=c<ve?-c:c;if(a.x===r.pt.x&&a.y===r.pt.y||a.x===i.pt.x&&a.y===i.pt.y)i.prev=r,r.next=i;else{let e=new Ee(a,t);e.prev=r,e.next=i,i.prev=e,r.next=e}if(!(l>ye)||!(l>s)&&c>ve!=o>ve)return;let u=this.newOutRec();u.owner=t.owner,n.outrec=u,n.next.outrec=u;let d=new Ee(a,u);d.prev=n.next,d.next=n,u.pts=d,n.prev=d,n.next.next=d,this.usingPolytree&&(this.path1InsidePath2(r,d)?(u.splits===null&&(u.splits=[]),u.splits.push(t.idx)):(t.splits===null&&(t.splits=[]),t.splits.push(u.idx)))}static areaOutPt(e){let t=I.maxCoordForSafeAreaProduct,n=0,r=!0,i=e;do{let e=i.prev,a=i.pt;if(Math.abs(e.pt.x)>=t||Math.abs(e.pt.y)>=t||Math.abs(a.x)>=t||Math.abs(a.y)>=t){r=!1;break}n+=(e.pt.y+a.y)*(e.pt.x-a.x),i=i.next}while(i!==e);if(r)return BigInt(Math.round(n));let a=ve;i=e;do{let e=i.prev;if(Number.isSafeInteger(e.pt.y)&&Number.isSafeInteger(i.pt.y)&&Number.isSafeInteger(e.pt.x)&&Number.isSafeInteger(i.pt.x)){let t=BigInt(e.pt.y)+BigInt(i.pt.y),n=BigInt(e.pt.x)-BigInt(i.pt.x);a+=t*n}else{let t=e.pt.y+i.pt.y,n=e.pt.x-i.pt.x;a+=BigInt(Math.round(t*n))}i=i.next}while(i!==e);return a}areaTriangle(e,t,n){let r=I.maxCoordForSafeAreaProduct;if(Math.abs(e.x)<r&&Math.abs(e.y)<r&&Math.abs(t.x)<r&&Math.abs(t.y)<r&&Math.abs(n.x)<r&&Math.abs(n.y)<r){let r=(n.y+e.y)*(n.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+n.y)*(t.x-n.x);return BigInt(Math.round(r))}if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(t.y)&&Number.isSafeInteger(n.x)&&Number.isSafeInteger(n.y)){let r=(BigInt(n.y)+BigInt(e.y))*(BigInt(n.x)-BigInt(e.x)),i=(BigInt(e.y)+BigInt(t.y))*(BigInt(e.x)-BigInt(t.x)),a=(BigInt(t.y)+BigInt(n.y))*(BigInt(t.x)-BigInt(n.x));return r+i+a}let i=(n.y+e.y)*(n.x-e.x)+(e.y+t.y)*(e.x-t.x)+(t.y+n.y)*(t.x-n.x);return BigInt(Math.round(i))}isValidOwner(e,t){for(;t!==null&&t!==e;)t=t.owner;return t===null}containsRect(e,t){return t.left>=e.left&&t.right<=e.right&&t.top>=e.top&&t.bottom<=e.bottom}checkSplitOwner(e,t){for(let n=0;n<t.length;n++){let r=this.outrecList[t[n]];if(r.pts===null&&r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(r=this.getRealOutRec(r),!(r===null||r===e||r.recursiveSplit===e)){if(r.recursiveSplit=e,r.splits!==null&&this.checkSplitOwner(e,r.splits))return!0;if(!(!this.checkBounds(r)||!this.containsRect(r.bounds,e.bounds)||!this.path1InsidePath2(e.pts,r.pts)))return this.isValidOwner(e,r)||(r.owner=e.owner),e.owner=r,!0}}return!1}},Ve=class extends Be{zCallback;getZCallback(){return this.zCallback}addPath(e,t,n=!1){super.addPath(e,t,n)}addReuseableData(e){super.addReuseableData(e)}addPaths(e,t,n=!1){super.addPaths(e,t,n)}addSubject(e){this.addPaths(e,r.Subject)}addOpenSubject(e){this.addPaths(e,r.Subject,!0)}addClip(e){this.addPaths(e,r.Clip)}execute(e,t,n,r){if(Array.isArray(n)){let i=n,a=r;i.length=0,a&&(a.length=0);try{this.executeInternal(e,t),this.buildPaths(i,a||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}else{let i=n,a=r;i.clear(),a&&(a.length=0),this.usingPolytree=!0;try{this.executeInternal(e,t),this.buildTree(i,a||[])}catch{this.succeeded=!1}return this.clearSolutionOnly(),this.succeeded}}},He=class extends Be{zCallback;scale;invScale;constructor(e=2){super(),I.checkPrecision(e),this.scale=10**e,this.invScale=1/this.scale}getZCallback(){return this.zCallback}scalePathDFromInt(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t,z:r.z||0});return n}buildPathsD(e,t){e.length=0,t.length=0;let n=0;for(;n<this.outrecList.length;){let r=this.outrecList[n++];if(r.pts===null)continue;let i=[];r.isOpen?Be.buildPath(r.pts,this.reverseSolution,!0,i)&&t.push(this.scalePathDFromInt(i,this.invScale)):(this.cleanCollinear(r),Be.buildPath(r.pts,this.reverseSolution,!1,i)&&e.push(this.scalePathDFromInt(i,this.invScale)))}return!0}buildTreeD(e,t){e.clear(),t.length=0;let n=0;for(;n<this.outrecList.length;){let r=this.outrecList[n++];if(r.pts!==null){if(r.isOpen){let e=[];Be.buildPath(r.pts,this.reverseSolution,!0,e)&&t.push(this.scalePathDFromInt(e,this.invScale));continue}this.checkBounds(r)&&this.recursiveCheckOwners(r,e)}}}addPath(e,t,n=!1){let r=[e];this.addPaths(r,t,n)}addPaths(e,t,n=!1){super.addPaths(Ue.scalePaths64(e,this.scale),t,n)}addSubject(e){this.addPath(e,r.Subject)}addOpenSubject(e){this.addPath(e,r.Subject,!0)}addClip(e){this.addPath(e,r.Clip)}addSubjectPaths(e){this.addPaths(e,r.Subject)}addOpenSubjectPaths(e){this.addPaths(e,r.Subject,!0)}addClipPaths(e){this.addPaths(e,r.Clip)}execute(e,t,n,r){if(Array.isArray(n)){let i=n,a=r,o=[],s=[];i.length=0,a&&(a.length=0);let c=!0;try{this.executeInternal(e,t),this.buildPaths(o,s)}catch{c=!1}if(this.clearSolutionOnly(),!c)return!1;for(let e of o)i.push(this.scalePathDFromInt(e,this.invScale));if(a)for(let e of s)a.push(this.scalePathDFromInt(e,this.invScale));return!0}else{let i=n,a=r;i.clear(),a&&(a.length=0),this.usingPolytree=!0,i.scale=this.scale;let o=!0;try{this.executeInternal(e,t),this.buildTreeD(i,a||[])}catch{o=!1}return this.clearSolutionOnly(),o}}};const Ue={area(e){return I.area(e)},areaD(e){let t=0,n=e.length;if(n<3)return 0;let r=e[n-1];for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5},scalePath64(e,t){let n=I.maxSafeCoordinateForScale(t),r=[];for(let i of e)I.checkSafeScaleValue(i.x,n,`scalePath64`),I.checkSafeScaleValue(i.y,n,`scalePath64`),r.push({x:Math.round(i.x*t),y:Math.round(i.y*t)});return r},scalePaths64(e,t){let n=[];for(let r of e)n.push(Ue.scalePath64(r,t));return n},scalePathD(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t});return n},scalePathsD(e,t){let n=[];for(let r of e)n.push(Ue.scalePathD(r,t));return n}};let We=function(e){return e[e.Miter=0]=`Miter`,e[e.Square=1]=`Square`,e[e.Bevel=2]=`Bevel`,e[e.Round=3]=`Round`,e}({}),B=function(e){return e[e.Polygon=0]=`Polygon`,e[e.Joined=1]=`Joined`,e[e.Butt=2]=`Butt`,e[e.Square=3]=`Square`,e[e.Round=4]=`Round`,e}({});var Ge=class{inPaths;joinType;endType;pathsReversed;lowestPathIdx;constructor(e,t,n=B.Polygon){this.joinType=t,this.endType=n;let r=n===B.Polygon||n===B.Joined;this.inPaths=[];for(let t of e)this.inPaths.push(Ke.stripDuplicates(t,r));if(n===B.Polygon){let e=Ke.getLowestPathInfo(this.inPaths);this.lowestPathIdx=e.idx,this.pathsReversed=this.lowestPathIdx>=0&&e.isNegArea}else this.lowestPathIdx=-1,this.pathsReversed=!1}},Ke=class e{static Tolerance=1e-12;static arc_const=.002;groupList=[];pathOut=[];normals=[];solution=[];solutionTree=null;groupDelta=0;delta=0;mitLimSqr=0;stepsPerRad=0;stepSin=0;stepCos=0;joinType=We.Bevel;endType=B.Polygon;arcTolerance=0;mergeGroups=!0;miterLimit=2;preserveCollinear=!1;reverseSolution=!1;zCallback;deltaCallback=null;constructor(e=2,t=0,n=!1,r=!1){this.miterLimit=e,this.arcTolerance=t,this.mergeGroups=!0,this.preserveCollinear=n,this.reverseSolution=r}clear(){this.groupList.length=0}ZCB=(e,t,n,r,i)=>{(e.z||0)!==0&&(e.z===n.z||e.z===r.z)?i.z=e.z:(n.z||0)!==0&&n.z===t.z?i.z=n.z:(t.z||0)!==0&&t.z===r.z?i.z=t.z:this.zCallback&&this.zCallback(e,t,n,r,i)};addPath(e,t,n){if(e.length===0)return;let r=[e];this.addPaths(r,t,n)}addPaths(e,t,n){e.length!==0&&this.groupList.push(new Ge(e,t,n))}calcSolutionCapacity(){let e=0;for(let t of this.groupList)e+=t.endType===B.Joined?t.inPaths.length*2:t.inPaths.length;return e}checkPathsReversed(){let e=!1;for(let t of this.groupList)if(t.endType===B.Polygon){e=t.pathsReversed;break}return e}executeInternal(t){if(this.groupList.length===0)return;if(Math.abs(t)<.5){for(let e of this.groupList)for(let t of e.inPaths)this.solution.push(t);return}this.delta=t,this.mitLimSqr=this.miterLimit<=1?2:2/e.sqr(this.miterLimit);for(let e of this.groupList)this.doGroupOffset(e);if(this.groupList.length===0)return;let r=this.checkPathsReversed(),a=r?i.Negative:i.Positive,o=new Ve;o.preserveCollinear=this.preserveCollinear,o.reverseSolution=this.reverseSolution!==r,o.zCallback=this.ZCB,o.addSubject(this.solution),this.solutionTree===null?o.execute(n.Union,a,this.solution):o.execute(n.Union,a,this.solutionTree)}execute(e,t){if(Array.isArray(t)){let n=t;n.length=0,this.solution=n,this.executeInternal(e)}else{let n=t;n.clear(),this.solutionTree=n,this.solution=[],this.executeInternal(e)}}executeWithCallback(e,t){this.deltaCallback=e,this.execute(1,t)}static getUnitNormal(e,t){let n=t.x-e.x,r=t.y-e.y;if(n===0&&r===0)return{x:0,y:0};let i=1/Math.sqrt(n*n+r*r);return{x:r*i,y:-n*i}}static getLowestPathInfo(t){let n=-1,r=!1,i={x:2**53-1,y:-(2**53-1)};for(let a=0;a<t.length;++a){let o=Number.MAX_VALUE;for(let s of t[a])if(!(s.y<i.y||s.y===i.y&&s.x>=i.x)){if(o===Number.MAX_VALUE){if(o=e.area(t[a]),o===0)break;r=o<0}n=a,i.x=s.x,i.y=s.y}}return{idx:n,isNegArea:r}}static translatePoint(e,t,n){return{x:e.x+t,y:e.y+n,z:e.z}}static reflectPoint(e,t){return{x:t.x+(t.x-e.x),y:t.y+(t.y-e.y),z:e.z}}static almostZero(e,t=.001){return Math.abs(e)<t}static hypotenuse(e,t){return Math.sqrt(e*e+t*t)}static normalizeVector(t){let n=e.hypotenuse(t.x,t.y);if(e.almostZero(n))return{x:0,y:0};let r=1/n;return{x:t.x*r,y:t.y*r}}static getAvgUnitVector(t,n){return e.normalizeVector({x:t.x+n.x,y:t.y+n.y})}static intersectPoint(e,t,n,r){if(I.isAlmostZero(e.x-t.x)){if(I.isAlmostZero(n.x-r.x))return{x:0,y:0};let t=(r.y-n.y)/(r.x-n.x),i=n.y-t*n.x;return{x:e.x,y:t*e.x+i}}if(I.isAlmostZero(n.x-r.x)){let r=(t.y-e.y)/(t.x-e.x),i=e.y-r*e.x;return{x:n.x,y:r*n.x+i}}else{let i=(t.y-e.y)/(t.x-e.x),a=e.y-i*e.x,o=(r.y-n.y)/(r.x-n.x),s=n.y-o*n.x;if(I.isAlmostZero(i-o))return{x:0,y:0};let c=(s-a)/(i-o);return{x:c,y:i*c+a}}}getPerpendic(e,t){return{x:Math.round(e.x+t.x*this.groupDelta),y:Math.round(e.y+t.y*this.groupDelta),z:e.z||0}}getPerpendicD(e,t){return{x:e.x+t.x*this.groupDelta,y:e.y+t.y*this.groupDelta,z:e.z||0}}doBevel(e,t,n){let r,i,a=e[t].z||0;if(t===n){let n=Math.abs(this.groupDelta);r={x:Math.round(e[t].x-n*this.normals[t].x),y:Math.round(e[t].y-n*this.normals[t].y),z:a},i={x:Math.round(e[t].x+n*this.normals[t].x),y:Math.round(e[t].y+n*this.normals[t].y),z:a}}else r={x:Math.round(e[t].x+this.groupDelta*this.normals[n].x),y:Math.round(e[t].y+this.groupDelta*this.normals[n].y),z:a},i={x:Math.round(e[t].x+this.groupDelta*this.normals[t].x),y:Math.round(e[t].y+this.groupDelta*this.normals[t].y),z:a};this.pathOut.push(r),this.pathOut.push(i)}doSquare(t,n,r){let i;i=n===r?{x:this.normals[n].y,y:-this.normals[n].x}:e.getAvgUnitVector({x:-this.normals[r].y,y:this.normals[r].x},{x:this.normals[n].y,y:-this.normals[n].x});let a=Math.abs(this.groupDelta),o={x:t[n].x,y:t[n].y,z:t[n].z||0};o=e.translatePoint(o,a*i.x,a*i.y);let s=e.translatePoint(o,this.groupDelta*i.y,this.groupDelta*-i.x),c=e.translatePoint(o,this.groupDelta*-i.y,this.groupDelta*i.x),l=this.getPerpendicD(t[r],this.normals[r]);if(n===r){let t={x:l.x+i.x*this.groupDelta,y:l.y+i.y*this.groupDelta},n=e.intersectPoint(s,c,l,t);n.z=o.z,this.pathOut.push(L.fromPointD(e.reflectPoint(n,o))),this.pathOut.push(L.fromPointD(n))}else{let i=this.getPerpendicD(t[n],this.normals[r]),a=e.intersectPoint(s,c,l,i);a.z=o.z,this.pathOut.push(L.fromPointD(a)),this.pathOut.push(L.fromPointD(e.reflectPoint(a,o)))}}doMiter(e,t,n,r){let i=this.groupDelta/(r+1);this.pathOut.push({x:Math.round(e[t].x+(this.normals[n].x+this.normals[t].x)*i),y:Math.round(e[t].y+(this.normals[n].y+this.normals[t].y)*i),z:e[t].z||0})}doRound(t,n,r,i){if(this.deltaCallback!==null){let t=Math.abs(this.groupDelta),n=this.arcTolerance>.01?this.arcTolerance:t*e.arc_const,r=Math.PI/Math.acos(1-n/t);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}let a=t[n],o=a.z||0,s={x:this.normals[r].x*this.groupDelta,y:this.normals[r].y*this.groupDelta};n===r&&fe.negate(s),this.pathOut.push({x:Math.round(a.x+s.x),y:Math.round(a.y+s.y),z:o});let c=Math.ceil(this.stepsPerRad*Math.abs(i));for(let e=1;e<c;e++)s={x:s.x*this.stepCos-this.stepSin*s.y,y:s.x*this.stepSin+s.y*this.stepCos},this.pathOut.push({x:Math.round(a.x+s.x),y:Math.round(a.y+s.y),z:o});this.pathOut.push(this.getPerpendic(t[n],this.normals[n]))}buildNormals(t){let n=t.length;if(this.normals.length=0,n!==0){for(let r=0;r<n-1;r++)this.normals.push(e.getUnitNormal(t[r],t[r+1]));this.normals.push(e.getUnitNormal(t[n-1],t[0]))}}offsetPoint(t,n,r,i){if(L.equals(n[r],n[i]))return;let a=I.crossProductD(this.normals[r],this.normals[i]),o=I.dotProductD(this.normals[r],this.normals[i]);if(a>1?a=1:a<-1&&(a=-1),this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,i),t.pathsReversed&&(this.groupDelta=-this.groupDelta)),Math.abs(this.groupDelta)<e.Tolerance){this.pathOut.push(n[r]);return}if(o>-.999&&a*this.groupDelta<0)this.pathOut.push(this.getPerpendic(n[r],this.normals[i])),this.pathOut.push(n[r]),this.pathOut.push(this.getPerpendic(n[r],this.normals[r]));else if(o>.999&&this.joinType!==We.Round)this.doMiter(n,r,i,o);else switch(this.joinType){case We.Miter:o>this.mitLimSqr-1?this.doMiter(n,r,i,o):this.doSquare(n,r,i);break;case We.Round:this.doRound(n,r,i,Math.atan2(a,o));break;case We.Bevel:this.doBevel(n,r,i);break;default:this.doSquare(n,r,i);break}}offsetPolygon(e,t){this.pathOut=[];let n=t.length,r=n-1;for(let i=0;i<n;i++)this.offsetPoint(e,t,i,r),r=i;this.solution.push(this.pathOut)}offsetOpenJoined(e,t){this.offsetPolygon(e,t);let n=[...t].reverse();this.buildNormals(n),this.offsetPolygon(e,n)}offsetOpenPath(t,n){this.pathOut=[];let r=n.length-1;if(this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0)),Math.abs(this.groupDelta)<e.Tolerance)this.pathOut.push(n[0]);else switch(this.endType){case B.Butt:this.doBevel(n,0,0);break;case B.Round:this.doRound(n,0,0,Math.PI);break;default:this.doSquare(n,0,0);break}for(let e=1,i=0;e<r;e++)this.offsetPoint(t,n,e,i),i=e;for(let e=r;e>0;e--)this.normals[e]={x:-this.normals[e-1].x,y:-this.normals[e-1].y};if(this.normals[0]=this.normals[r],this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,r,r)),Math.abs(this.groupDelta)<e.Tolerance)this.pathOut.push(n[r]);else switch(this.endType){case B.Butt:this.doBevel(n,r,r);break;case B.Round:this.doRound(n,r,r,Math.PI);break;default:this.doSquare(n,r,r);break}for(let e=r-1,i=r;e>0;e--)this.offsetPoint(t,n,e,i),i=e;this.solution.push(this.pathOut)}doGroupOffset(t){t.endType===B.Polygon?(t.lowestPathIdx<0&&(this.delta=Math.abs(this.delta)),this.groupDelta=t.pathsReversed?-this.delta:this.delta):this.groupDelta=Math.abs(this.delta);let n=Math.abs(this.groupDelta);if(this.joinType=t.joinType,this.endType=t.endType,t.joinType===We.Round||t.endType===B.Round){let t=this.arcTolerance>.01?this.arcTolerance:n*e.arc_const,r=Math.PI/Math.acos(1-t/n);this.stepSin=Math.sin(2*Math.PI/r),this.stepCos=Math.cos(2*Math.PI/r),this.groupDelta<0&&(this.stepSin=-this.stepSin),this.stepsPerRad=r/(2*Math.PI)}for(let n of t.inPaths){this.pathOut=[];let r=n.length;if(r===1){let r=n[0];this.deltaCallback!==null&&(this.groupDelta=this.deltaCallback(n,this.normals,0,0),t.pathsReversed&&(this.groupDelta=-this.groupDelta));let i=r.z||0;if(t.endType===B.Round){let t=Math.ceil(this.stepsPerRad*2*Math.PI);if(this.pathOut=e.ellipse(r,Math.abs(this.groupDelta),Math.abs(this.groupDelta),t),i!==0)for(let e=0;e<this.pathOut.length;e++)this.pathOut[e].z=i}else{let e=Math.ceil(Math.abs(this.groupDelta)),t={left:r.x-e,top:r.y-e,right:r.x+e,bottom:r.y+e};this.pathOut=[{x:t.left,y:t.top,z:i},{x:t.right,y:t.top,z:i},{x:t.right,y:t.bottom,z:i},{x:t.left,y:t.bottom,z:i}]}this.solution.push(this.pathOut);continue}switch(r===2&&t.endType===B.Joined&&(this.endType=t.joinType===We.Round?B.Round:B.Square),this.buildNormals(n),this.endType){case B.Polygon:this.offsetPolygon(t,n);break;case B.Joined:this.offsetOpenJoined(t,n);break;default:this.offsetOpenPath(t,n);break}}}static stripDuplicates(e,t){let n=e.length,r=[];if(n===0)return r;let i=e[0];r.push(i);for(let t=1;t<n;t++)L.equals(i,e[t])||(i=e[t],r.push(i));return t&&L.equals(i,r[0])&&r.pop(),r}static area(e){return I.area(e)}static sqr(e){return e*e}static ellipse(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:Math.round(e.x+t),y:e.y}];for(let l=1;l<r;++l){c.push({x:Math.round(e.x+t*o),y:Math.round(e.y+n*s)});let r=o*a-s*i;s=s*a+o*i,o=r}return c}},qe=class{next=null;prev=null;pt;ownerIdx=0;edge=null;constructor(e){this.pt=e}},V=function(e){return e[e.left=0]=`left`,e[e.top=1]=`top`,e[e.right=2]=`right`,e[e.bottom=3]=`bottom`,e[e.inside=4]=`inside`,e}(V||{}),Je=class e{rect;mp;rectPath;pathBounds={left:0,top:0,right:0,bottom:0};results=[];edges=[];currIdx=-1;constructor(e){this.currIdx=-1,this.rect=e,this.mp=R.midPoint(e),this.rectPath=R.asPath(this.rect),this.results=[],this.edges=[];for(let e=0;e<8;e++)this.edges[e]=[]}add(e,t=!1){let n=this.results.length,r;if(n===0||t)r=new qe(e),this.results.push(r),r.ownerIdx=n,r.prev=r,r.next=r;else{n--;let t=this.results[n];if(t&&L.equals(t.pt,e))return t;r=new qe(e),r.ownerIdx=n,r.next=t.next,t.next.prev=r,t.next=r,r.prev=t,this.results[n]=r}return r}static path1ContainsPath2(e,t){let n=0;for(let r of t){switch(I.pointInPolygon(r,e)){case a.IsInside:n--;break;case a.IsOutside:n++;break}if(Math.abs(n)>1)break}return n<=0}static isClockwise(t,n,r,i,a){return e.areOpposites(t,n)?I.crossProductSign(r,a,i)<0:e.headingClockwise(t,n)}static areOpposites(e,t){return Math.abs(e-t)===2}static headingClockwise(e,t){return(e+1)%4===t}static getAdjacentLocation(e,t){return(e+(t?1:3))%4}static unlinkOp(e){return e.next===e?null:(e.prev.next=e.next,e.next.prev=e.prev,e.next)}static unlinkOpBack(e){return e.next===e?null:(e.prev.next=e.next,e.next.prev=e.prev,e.prev)}static getEdgesForPt(e,t){let n=0;return e.x===t.left?n=1:e.x===t.right&&(n=4),e.y===t.top?n+=2:e.y===t.bottom&&(n+=8),n}static isHeadingClockwise(e,t,n){switch(n){case 0:return t.y<e.y;case 1:return t.x>e.x;case 2:return t.y>e.y;default:return t.x<e.x}}static hasHorzOverlap(e,t,n,r){return e.x<r.x&&t.x>n.x}static hasVertOverlap(e,t,n,r){return e.y<r.y&&t.y>n.y}static addToEdge(e,t){t.edge===null&&(t.edge=e,e.push(t))}static uncoupleEdge(e){if(e.edge!==null){for(let t=0;t<e.edge.length;t++)if(e.edge[t]===e){e.edge[t]=null;break}e.edge=null}}static setNewOwner(e,t){e.ownerIdx=t;let n=e.next;for(;n!==e;)n.ownerIdx=t,n=n.next}addCorner(t,n){this.add(e.headingClockwise(t,n)?this.rectPath[t]:this.rectPath[n])}addCornerWithDirection(t,n){if(n)return this.add(this.rectPath[t]),e.getAdjacentLocation(t,!0);{let n=e.getAdjacentLocation(t,!1);return this.add(this.rectPath[n]),n}}static getLocation(e,t){if(t.x===e.left&&t.y>=e.top&&t.y<=e.bottom)return{location:V.left,isOnRect:!0};if(t.x===e.right&&t.y>=e.top&&t.y<=e.bottom)return{location:V.right,isOnRect:!0};if(t.y===e.top&&t.x>=e.left&&t.x<=e.right)return{location:V.top,isOnRect:!0};if(t.y===e.bottom&&t.x>=e.left&&t.x<=e.right)return{location:V.bottom,isOnRect:!0};let n;return n=t.x<e.left?V.left:t.x>e.right?V.right:t.y<e.top?V.top:t.y>e.bottom?V.bottom:V.inside,{location:n,isOnRect:!1}}static isHorizontal(e,t){return e.y===t.y}static getSegmentIntersection(t,n,r,i){let a=I.crossProductSign(t,r,i),o=I.crossProductSign(n,r,i);if(a===0)return o===0?null:L.equals(t,r)||L.equals(t,i)?t:e.isHorizontal(r,i)?t.x>r.x==t.x<i.x?t:null:t.y>r.y==t.y<i.y?t:null;if(o===0)return L.equals(n,r)||L.equals(n,i)?n:e.isHorizontal(r,i)?n.x>r.x==n.x<i.x?n:null:n.y>r.y==n.y<i.y?n:null;if(a===o)return null;let s=I.crossProductSign(r,t,n),c=I.crossProductSign(i,t,n);return s===0?L.equals(r,t)||L.equals(r,n)?r:e.isHorizontal(t,n)?r.x>t.x==r.x<n.x?r:null:r.y>t.y==r.y<n.y?r:null:c===0?L.equals(i,t)||L.equals(i,n)?i:e.isHorizontal(t,n)?i.x>t.x==i.x<n.x?i:null:i.y>t.y==i.y<n.y?i:null:s===c?null:I.getLineIntersectPt(t,n,r,i)}static _intResult={intersects:!1,point:{x:0,y:0},newLocation:V.inside};static getIntersection(t,n,r,i){let a=e._intResult,o;switch(a.newLocation=i,i){case V.left:return o=e.getSegmentIntersection(n,r,t[0],t[3]),o===null?n.y<t[0].y&&(o=e.getSegmentIntersection(n,r,t[0],t[1]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=V.top,a):(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=V.bottom,a)):(a.intersects=!0,a.point=o,a);case V.right:return o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?n.y<t[0].y&&(o=e.getSegmentIntersection(n,r,t[0],t[1]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=V.top,a):(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=V.bottom,a)):(a.intersects=!0,a.point=o,a);case V.top:return o=e.getSegmentIntersection(n,r,t[0],t[1]),o===null?n.x<t[0].x&&(o=e.getSegmentIntersection(n,r,t[0],t[3]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=V.left,a):n.x<=t[1].x?(a.intersects=!1,a):(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=V.right,a)):(a.intersects=!0,a.point=o,a);case V.bottom:return o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?n.x<t[3].x&&(o=e.getSegmentIntersection(n,r,t[0],t[3]),o!==null)?(a.intersects=!0,a.point=o,a.newLocation=V.left,a):n.x<=t[2].x?(a.intersects=!1,a):(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=V.right,a)):(a.intersects=!0,a.point=o,a);default:return o=e.getSegmentIntersection(n,r,t[0],t[3]),o===null?(o=e.getSegmentIntersection(n,r,t[0],t[1]),o===null?(o=e.getSegmentIntersection(n,r,t[1],t[2]),o===null?(o=e.getSegmentIntersection(n,r,t[2],t[3]),o===null?(a.intersects=!1,a):(a.intersects=!0,a.point=o,a.newLocation=V.bottom,a)):(a.intersects=!0,a.point=o,a.newLocation=V.right,a)):(a.intersects=!0,a.point=o,a.newLocation=V.top,a)):(a.intersects=!0,a.point=o,a.newLocation=V.left,a)}}getNextLocation(e,t,n,r){let i=n,a=t;switch(t){case V.left:for(;i<=r&&e[i].x<=this.rect.left;)i++;if(i>r)break;a=e[i].x>=this.rect.right?V.right:e[i].y<=this.rect.top?V.top:e[i].y>=this.rect.bottom?V.bottom:V.inside;break;case V.top:for(;i<=r&&e[i].y<=this.rect.top;)i++;if(i>r)break;a=e[i].y>=this.rect.bottom?V.bottom:e[i].x<=this.rect.left?V.left:e[i].x>=this.rect.right?V.right:V.inside;break;case V.right:for(;i<=r&&e[i].x>=this.rect.right;)i++;if(i>r)break;a=e[i].x<=this.rect.left?V.left:e[i].y<=this.rect.top?V.top:e[i].y>=this.rect.bottom?V.bottom:V.inside;break;case V.bottom:for(;i<=r&&e[i].y>=this.rect.bottom;)i++;if(i>r)break;a=e[i].y<=this.rect.top?V.top:e[i].x<=this.rect.left?V.left:e[i].x>=this.rect.right?V.right:V.inside;break;case V.inside:for(;i<=r;){if(e[i].x<this.rect.left)a=V.left;else if(e[i].x>this.rect.right)a=V.right;else if(e[i].y>this.rect.bottom)a=V.bottom;else if(e[i].y<this.rect.top)a=V.top;else{this.add(e[i]),i++;continue}break}break}return{location:a,index:i}}static startLocsAreClockwise(e){let t=0;for(let n=1;n<e.length;n++)switch(e[n]-e[n-1]){case-1:--t;break;case 1:t+=1;break;case-3:t+=1;break;case 3:--t;break}return t>0}executeInternal(t){if(t.length<3||R.isEmpty(this.rect))return;let n=[],r=V.inside,i=r,a=r,o=t.length-1,s=e.getLocation(this.rect,t[o]),c=s.location;if(s.isOnRect){let n=o-1;for(;n>=0;){let r=e.getLocation(this.rect,t[n]);if(!r.isOnRect){a=r.location;break}n--}if(n<0){for(let e of t)this.add(e);return}a===V.inside&&(c=V.inside)}let l=c,u=0;for(;u<=o;){a=c;let s=i,l=this.getNextLocation(t,c,u,o);if(c=l.location,u=l.index,u>o)break;let d=u===0?t[o]:t[u-1];i=c;let f=e.getIntersection(this.rectPath,t[u],d,i);if(!f.intersects){if(s===V.inside){let r=e.isClockwise(a,c,d,t[u],this.mp);do n.push(a),a=e.getAdjacentLocation(a,r);while(a!==c);i=s}else if(a!==V.inside&&a!==c){let n=e.isClockwise(a,c,d,t[u],this.mp);do a=this.addCornerWithDirection(a,n);while(a!==c)}++u;continue}let p=f.point;if(i=f.newLocation,c===V.inside){if(r===V.inside)r=i,n.push(a);else if(a!==i){let n=e.isClockwise(a,i,d,t[u],this.mp);do a=this.addCornerWithDirection(a,n);while(a!==i)}}else if(a!==V.inside){c=a;let o=e.getIntersection(this.rectPath,d,t[u],c).point;if(s!==V.inside&&s!==c&&this.addCorner(s,c),r===V.inside&&(r=c,n.push(a)),c=i,this.add(o),L.equals(p,o)){c=e.getLocation(this.rect,t[u]).location,this.addCorner(i,c),i=c;continue}}else c=i,r===V.inside&&(r=i);this.add(p)}if(r===V.inside){if(l===V.inside||!R.containsRect(this.pathBounds,this.rect)||!e.path1ContainsPath2(t,this.rectPath))return;let r=e.startLocsAreClockwise(n);for(let t=0;t<4;t++){let n=r?t:3-t;this.add(this.rectPath[n]),e.addToEdge(this.edges[n*2],this.results[0])}}else if(c!==V.inside&&(c!==r||n.length>2)){if(n.length>0){a=c;for(let t of n)a!==t&&(this.addCornerWithDirection(a,e.headingClockwise(a,t)),a=t);c=a}c!==r&&this.addCornerWithDirection(c,e.headingClockwise(c,r))}}execute(e){let t=[];if(R.isEmpty(this.rect))return t;for(let n of e)if(!(n.length<3)&&(this.pathBounds=I.getBounds(n),R.intersects(this.rect,this.pathBounds))){if(R.containsRect(this.rect,this.pathBounds)){t.push(n);continue}this.executeInternal(n),this.checkEdges();for(let e=0;e<4;++e)this.tidyEdgePair(e,this.edges[e*2],this.edges[e*2+1]);for(let e of this.results){let n=this.getPath(e);n.length>0&&t.push(n)}this.results.length=0;for(let e=0;e<8;e++)this.edges[e].length=0}return t}checkEdges(){for(let t=0;t<this.results.length;t++){let n=this.results[t],r=n;if(n===null)continue;do if(I.isCollinear(r.prev.pt,r.pt,r.next.pt)){if(r===n){if(r=e.unlinkOpBack(r),r===null)break;n=r.prev}else if(r=e.unlinkOpBack(r),r===null)break}else r=r.next;while(r!==n);if(r===null){this.results[t]=null;continue}this.results[t]=r;let i=e.getEdgesForPt(n.prev.pt,this.rect);r=n;do{let t=e.getEdgesForPt(r.pt,this.rect);if(t!==0&&r.edge===null){let n=i&t;for(let t=0;t<4;++t)n&1<<t&&(e.isHeadingClockwise(r.prev.pt,r.pt,t)?e.addToEdge(this.edges[t*2],r):e.addToEdge(this.edges[t*2+1],r))}i=t,r=r.next}while(r!==n)}}tidyEdgePair(t,n,r){if(r.length===0)return;let i=t===1||t===3,a=t===1||t===2,o=0,s=0;for(;o<n.length;){let t=n[o];if(t===null||t.next===t.prev){n[o++]=null,s=0;continue}let c=r.length;for(;s<c&&(r[s]===null||r[s].next===r[s].prev);)++s;if(s===c){++o,s=0;continue}let l,u,d;if(a?(t=n[o].prev,u=n[o],l=r[s],d=r[s].prev):(t=n[o],u=n[o].prev,l=r[s].prev,d=r[s]),i&&!e.hasHorzOverlap(t.pt,u.pt,l.pt,d.pt)||!i&&!e.hasVertOverlap(t.pt,u.pt,l.pt,d.pt)){++s;continue}let f=n[o].ownerIdx!==r[s].ownerIdx;if(f&&(this.results[l.ownerIdx]=null,e.setNewOwner(l,t.ownerIdx)),a?(t.next=l,l.prev=t,u.prev=d,d.next=u):(t.prev=l,l.next=t,u.next=d,d.prev=u),!f){let t=this.results.length;this.results.push(u),e.setNewOwner(u,t)}let p,m;a?(p=l,m=u):(p=t,m=d),this.results[p.ownerIdx]=p,this.results[m.ownerIdx]=m;let h,g;i?(h=p.pt.x>p.prev.pt.x,g=m.pt.x>m.prev.pt.x):(h=p.pt.y>p.prev.pt.y,g=m.pt.y>m.prev.pt.y),p.next===p.prev||L.equals(p.pt,p.prev.pt)?g===a?(n[o]=m,r[s++]=null):(r[s]=m,n[o++]=null):m.next===m.prev||L.equals(m.pt,m.prev.pt)?h===a?(n[o]=p,r[s++]=null):(r[s]=p,n[o++]=null):h===g?h===a?(n[o]=p,e.uncoupleEdge(m),e.addToEdge(n,m),r[s++]=null):(n[o++]=null,r[s]=m,e.uncoupleEdge(p),e.addToEdge(r,p),s=0):(h===a?n[o]=p:r[s]=p,g===a?n[o]=m:r[s]=m)}}getPath(t){let n=[];if(t===null||t.prev===t.next)return n;let r=t.next;for(;r!==null&&r!==t;)I.isCollinear(r.prev.pt,r.pt,r.next.pt)?(t=r.prev,r=e.unlinkOp(r)):r=r.next;if(r===null)return[];for(n.push(t.pt),r=t.next;r!==t;)n.push(r.pt),r=r.next;return n}},Ye=class extends Je{constructor(e){super(e)}execute(e){let t=[];if(R.isEmpty(this.rect))return t;for(let n of e)if(!(n.length<2)&&(this.pathBounds=I.getBounds(n),R.intersects(this.rect,this.pathBounds))){this.executeInternalLines(n);for(let e of this.results){let n=this.getPathLines(e);n.length>0&&t.push(n)}this.results.length=0;for(let e=0;e<8;e++)this.edges[e].length=0}return t}getPathLines(e){let t=[];if(e===null||e===e.next)return t;e=e.next,t.push(e.pt);let n=e.next;for(;n!==e;)t.push(n.pt),n=n.next;return t}executeInternalLines(e){if(this.results.length=0,e.length<2||R.isEmpty(this.rect))return;let t=V.inside,n=1,r=e.length-1,i=Je.getLocation(this.rect,e[0]),a=i.location;if(i.isOnRect){for(;n<=r;){let r=Je.getLocation(this.rect,e[n]);if(!r.isOnRect){t=r.location;break}n++}if(n>r){for(let t of e)this.add(t);return}t===V.inside&&(a=V.inside),n=1}for(a===V.inside&&this.add(e[0]);n<=r;){t=a;let i=this.getNextLocation(e,a,n,r);if(a=i.location,n=i.index,n>r)break;let o=e[n-1],s=a,c=Je.getIntersection(this.rectPath,e[n],o,s);if(!c.intersects){++n;continue}let l=c.point;if(a===V.inside)this.add(l,!0);else if(t!==V.inside){s=t;let r=Je.getIntersection(this.rectPath,o,e[n],s).point;this.add(r,!0),this.add(l)}else this.add(l)}}};function Xe(e,t,n,r){let i=r?0:1,a=e.length,o=t.length,s=[];for(let r of t){let t=[];if(n)for(let n of e)t.push(L.add(r,n));else for(let n of e)t.push(L.subtract(r,n));s.push(t)}let c=[],l=r?o-1:0,u=a-1;for(let e=i;e<o;e++){for(let t=0;t<a;t++){let n=[s[l][u],s[e][u],s[e][t],s[l][t]];Ze(n)?c.push(n):c.push(Qe(n)),u=t}l=e}return c}function Ze(e){return I.area(e)>=0}function Qe(e){return[...e].reverse()}function $e(e,t){let n=I.maxSafeCoordinateForScale(t),r=[];for(let i of e)I.checkSafeScaleValue(i.x,n,`Minkowski.scalePath64`),I.checkSafeScaleValue(i.y,n,`Minkowski.scalePath64`),r.push({x:I.roundToEven(i.x*t),y:I.roundToEven(i.y*t)});return r}function et(e,t){let n=[];for(let r of e){let e=[];for(let n of r)e.push({x:n.x*t,y:n.y*t});n.push(e)}return n}function tt(e,t){let i=[],a=new Ve;return a.addPaths(e,r.Subject),a.execute(n.Union,t,i),i}const nt={sum(e,t,n){return tt(Xe(e,t,!0,n),i.NonZero)},sumD(e,t,n,r=2){let a=10**r;return et(tt(Xe($e(e,a),$e(t,a),!0,n),i.NonZero),1/a)},diff(e,t,n){return tt(Xe(e,t,!1,n),i.NonZero)},diffD(e,t,n,r=2){let a=10**r;return et(tt(Xe($e(e,a),$e(t,a),!1,n),i.NonZero),1/a)}},H=11102230246251565e-32,U=134217729,rt=(3+8*H)*H;(3+16*H)*H,(2+12*H)*H,(9+64*H)*H*H,(10+96*H)*H,(4+48*H)*H,(44+576*H)*H*H;const it=new Float64Array(4),at=new Float64Array(8),ot=new Float64Array(12),st=new Float64Array(16),ct=new Float64Array(4),lt=new Float64Array(4),ut=new Float64Array(4),dt=new Float64Array(4),ft=new Float64Array(4),pt=new Float64Array(4),mt=new Float64Array(4),ht=new Float64Array(4),gt=new Float64Array(8),_t=new Float64Array(8),vt=new Float64Array(8),yt=new Float64Array(8),bt=new Float64Array(8),xt=new Float64Array(8),St=new Float64Array(8),Ct=new Float64Array(8),wt=new Float64Array(8),Tt=new Float64Array(4),Et=new Float64Array(4),Dt=new Float64Array(4),W=new Float64Array(8),G=new Float64Array(16),K=new Float64Array(16),q=new Float64Array(16),J=new Float64Array(32),Ot=new Float64Array(32),Y=new Float64Array(48),kt=new Float64Array(64),At=new Float64Array(4);let jt=new Float64Array(1152),Mt=new Float64Array(1152);function X(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function Z(e,t,n,r){let i,a,o,s,c,l,u,d,f,p,m;u=U*n,p=u-(u-n),m=n-p;let h=t[0];i=h*n,u=U*h,d=u-(u-h),f=h-d,o=f*m-(i-d*p-f*p-d*m);let g=0;o!==0&&(r[g++]=o);for(let _=1;_<e;_++)h=t[_],s=h*n,u=U*h,d=u-(u-h),f=h-d,c=f*m-(s-d*p-f*p-d*m),a=i+c,l=a-i,o=i-(a-l)+(c-l),o!==0&&(r[g++]=o),i=s+a,o=a-(i-s),o!==0&&(r[g++]=o);return(i!==0||g===0)&&(r[g++]=i),g}function Nt(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function Pt(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=e-i,E=n-i,D=t-a,O=r-a;g=T*O,c=U*T,l=c-(c-T),u=T-l,c=U*O,d=c-(c-O),f=O-d,_=u*f-(g-l*d-u*d-l*f),v=D*E,c=U*D,l=c-(c-D),u=D-l,c=U*E,d=c-(c-E),f=E-d,y=u*f-(v-l*d-u*d-l*f),p=_-y,s=_-p,it[0]=_-(p+s)+(s-y),m=g+p,s=m-g,h=g-(m-s)+(p-s),p=h-v,s=h-p,it[1]=h-(p+s)+(s-v),b=m+p,s=b-m,it[2]=m-(b-s)+(p-s),it[3]=b;let k=Nt(4,it),ee=22204460492503146e-32*o;if(k>=ee||-k>=ee||(s=e-T,x=e-(T+s)+(s-i),s=n-E,C=n-(E+s)+(s-i),s=t-D,S=t-(D+s)+(s-a),s=r-O,w=r-(O+s)+(s-a),x===0&&S===0&&C===0&&w===0)||(ee=11093356479670487e-47*o+rt*Math.abs(k),k+=T*w+O*x-(D*C+E*S),k>=ee||-k>=ee))return k;g=x*O,c=U*x,l=c-(c-x),u=x-l,c=U*O,d=c-(c-O),f=O-d,_=u*f-(g-l*d-u*d-l*f),v=S*E,c=U*S,l=c-(c-S),u=S-l,c=U*E,d=c-(c-E),f=E-d,y=u*f-(v-l*d-u*d-l*f),p=_-y,s=_-p,ct[0]=_-(p+s)+(s-y),m=g+p,s=m-g,h=g-(m-s)+(p-s),p=h-v,s=h-p,ct[1]=h-(p+s)+(s-v),b=m+p,s=b-m,ct[2]=m-(b-s)+(p-s),ct[3]=b;let te=X(4,it,4,ct,at);g=T*w,c=U*T,l=c-(c-T),u=T-l,c=U*w,d=c-(c-w),f=w-d,_=u*f-(g-l*d-u*d-l*f),v=D*C,c=U*D,l=c-(c-D),u=D-l,c=U*C,d=c-(c-C),f=C-d,y=u*f-(v-l*d-u*d-l*f),p=_-y,s=_-p,ct[0]=_-(p+s)+(s-y),m=g+p,s=m-g,h=g-(m-s)+(p-s),p=h-v,s=h-p,ct[1]=h-(p+s)+(s-v),b=m+p,s=b-m,ct[2]=m-(b-s)+(p-s),ct[3]=b;let ne=X(te,at,4,ct,ot);return g=x*w,c=U*x,l=c-(c-x),u=x-l,c=U*w,d=c-(c-w),f=w-d,_=u*f-(g-l*d-u*d-l*f),v=S*C,c=U*S,l=c-(c-S),u=S-l,c=U*C,d=c-(c-C),f=C-d,y=u*f-(v-l*d-u*d-l*f),p=_-y,s=_-p,ct[0]=_-(p+s)+(s-y),m=g+p,s=m-g,h=g-(m-s)+(p-s),p=h-v,s=h-p,ct[1]=h-(p+s)+(s-v),b=m+p,s=b-m,ct[2]=m-(b-s)+(p-s),ct[3]=b,st[X(ne,ot,4,ct,st)-1]}function Ft(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s;if(o>0){if(s<=0)return c>0?1:c<0?-1:0}else if(o<0){if(s>=0)return c>0?1:c<0?-1:0}else return c>0?1:c<0?-1:0;let l=o>0?o+s:-o-s,u=33306690738754716e-32*l;if(c>=u||-c>=u)return c>0?1:-1;let d=Pt(e,t,n,r,i,a,l);return d>0?1:d<0?-1:0}function Q(e,t,n){e=X(e,jt,t,n,Mt);let r=jt;return jt=Mt,Mt=r,e}function It(e,t,n,r,i,a,o,s,c){let l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,ee=0,te=0,ne=0,re=0,ie=0,ae=0,oe,se,A=e-o,j=n-o,M=i-o,N=t-s,P=r-s,F=a-s;v=j*F,u=U*j,d=u-(u-j),f=j-d,u=U*F,p=u-(u-F),m=F-p,y=f*m-(v-d*p-f*p-d*m),b=M*P,u=U*M,d=u-(u-M),f=M-d,u=U*P,p=u-(u-P),m=P-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,lt[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,lt[1]=_-(h+l)+(l-b),S=g+h,l=S-g,lt[2]=g-(S-l)+(h-l),lt[3]=S,v=M*N,u=U*M,d=u-(u-M),f=M-d,u=U*N,p=u-(u-N),m=N-p,y=f*m-(v-d*p-f*p-d*m),b=A*F,u=U*A,d=u-(u-A),f=A-d,u=U*F,p=u-(u-F),m=F-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,ut[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,ut[1]=_-(h+l)+(l-b),S=g+h,l=S-g,ut[2]=g-(S-l)+(h-l),ut[3]=S,v=A*P,u=U*A,d=u-(u-A),f=A-d,u=U*P,p=u-(u-P),m=P-p,y=f*m-(v-d*p-f*p-d*m),b=j*N,u=U*j,d=u-(u-j),f=j-d,u=U*N,p=u-(u-N),m=N-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,dt[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,dt[1]=_-(h+l)+(l-b),S=g+h,l=S-g,dt[2]=g-(S-l)+(h-l),dt[3]=S,C=X(X(X(Z(Z(4,lt,A,W),W,A,G),G,Z(Z(4,lt,N,W),W,N,K),K,J),J,X(Z(Z(4,ut,j,W),W,j,G),G,Z(Z(4,ut,P,W),W,P,K),K,Ot),Ot,kt),kt,X(Z(Z(4,dt,M,W),W,M,G),G,Z(Z(4,dt,F,W),W,F,K),K,J),J,jt);let ce=Nt(C,jt),le=4440892098500632e-31*c;if(ce>=le||-ce>=le||(l=e-A,w=e-(A+l)+(l-o),l=t-N,D=t-(N+l)+(l-s),l=n-j,T=n-(j+l)+(l-o),l=r-P,O=r-(P+l)+(l-s),l=i-M,E=i-(M+l)+(l-o),l=a-F,k=a-(F+l)+(l-s),w===0&&T===0&&E===0&&D===0&&O===0&&k===0)||(le=5423418723394464e-46*c+rt*Math.abs(ce),ce+=(A*A+N*N)*(j*k+F*T-(P*E+M*O))+2*(A*w+N*D)*(j*F-P*M)+((j*j+P*P)*(M*D+N*E-(F*w+A*k))+2*(j*T+P*O)*(M*N-F*A))+((M*M+F*F)*(A*O+P*w-(N*T+j*D))+2*(M*E+F*k)*(A*P-N*j)),ce>=le||-ce>=le))return ce;(T!==0||O!==0||E!==0||k!==0)&&(v=A*A,u=U*A,d=u-(u-A),f=A-d,y=f*f-(v-d*d-(d+d)*f),b=N*N,u=U*N,d=u-(u-N),f=N-d,x=f*f-(b-d*d-(d+d)*f),h=y+x,l=h-y,ft[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,ft[1]=_-(h-l)+(b-l),S=g+h,l=S-g,ft[2]=g-(S-l)+(h-l),ft[3]=S),(E!==0||k!==0||w!==0||D!==0)&&(v=j*j,u=U*j,d=u-(u-j),f=j-d,y=f*f-(v-d*d-(d+d)*f),b=P*P,u=U*P,d=u-(u-P),f=P-d,x=f*f-(b-d*d-(d+d)*f),h=y+x,l=h-y,pt[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,pt[1]=_-(h-l)+(b-l),S=g+h,l=S-g,pt[2]=g-(S-l)+(h-l),pt[3]=S),(w!==0||D!==0||T!==0||O!==0)&&(v=M*M,u=U*M,d=u-(u-M),f=M-d,y=f*f-(v-d*d-(d+d)*f),b=F*F,u=U*F,d=u-(u-F),f=F-d,x=f*f-(b-d*d-(d+d)*f),h=y+x,l=h-y,mt[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,mt[1]=_-(h-l)+(b-l),S=g+h,l=S-g,mt[2]=g-(S-l)+(h-l),mt[3]=S);let ue=(e,t,n,r,i,a)=>X(X(e,t,n,r,J),J,i,a,Y);w!==0&&(ee=Z(4,lt,w,gt),C=Q(C,ue(Z(ee,gt,2*A,G),G,Z(Z(4,mt,w,W),W,P,K),K,Z(Z(4,pt,w,W),W,-F,q),q),Y)),D!==0&&(te=Z(4,lt,D,_t),C=Q(C,ue(Z(te,_t,2*N,G),G,Z(Z(4,pt,D,W),W,M,K),K,Z(Z(4,mt,D,W),W,-j,q),q),Y)),T!==0&&(ne=Z(4,ut,T,vt),C=Q(C,ue(Z(ne,vt,2*j,G),G,Z(Z(4,ft,T,W),W,F,K),K,Z(Z(4,mt,T,W),W,-N,q),q),Y)),O!==0&&(re=Z(4,ut,O,yt),C=Q(C,ue(Z(re,yt,2*P,G),G,Z(Z(4,mt,O,W),W,A,K),K,Z(Z(4,ft,O,W),W,-M,q),q),Y)),E!==0&&(ie=Z(4,dt,E,bt),C=Q(C,ue(Z(ie,bt,2*M,G),G,Z(Z(4,pt,E,W),W,N,K),K,Z(Z(4,ft,E,W),W,-P,q),q),Y)),k!==0&&(ae=Z(4,dt,k,xt),C=Q(C,ue(Z(ae,xt,2*F,G),G,Z(Z(4,ft,k,W),W,j,K),K,Z(Z(4,pt,k,W),W,-A,q),q),Y));let de,I,L,fe,R,pe;if(w!==0||D!==0){if(T!==0||O!==0||E!==0||k!==0?(v=T*F,u=U*T,d=u-(u-T),f=T-d,u=U*F,p=u-(u-F),m=F-p,y=f*m-(v-d*p-f*p-d*m),b=j*k,u=U*j,d=u-(u-j),f=j-d,u=U*k,p=u-(u-k),m=k-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,ht[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,ht[1]=_-(h-l)+(b-l),S=g+h,l=S-g,ht[2]=g-(S-l)+(h-l),ht[3]=S,oe=-P,se=-O,v=E*oe,u=U*E,d=u-(u-E),f=E-d,u=U*oe,p=u-(u-oe),m=oe-p,y=f*m-(v-d*p-f*p-d*m),b=M*se,u=U*M,d=u-(u-M),f=M-d,u=U*se,p=u-(u-se),m=se-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,At[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,At[1]=_-(h-l)+(b-l),S=g+h,l=S-g,At[2]=g-(S-l)+(h-l),At[3]=S,de=X(4,ht,4,At,Ct),v=T*k,u=U*T,d=u-(u-T),f=T-d,u=U*k,p=u-(u-k),m=k-p,y=f*m-(v-d*p-f*p-d*m),b=E*O,u=U*E,d=u-(u-E),f=E-d,u=U*O,p=u-(u-O),m=O-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,Et[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,Et[1]=_-(h+l)+(l-b),S=g+h,l=S-g,Et[2]=g-(S-l)+(h-l),Et[3]=S,fe=4):(Ct[0]=0,de=1,Et[0]=0,fe=1),w!==0){let e=Z(de,Ct,w,q);C=Q(C,X(Z(ee,gt,w,G),G,Z(e,q,2*A,J),J,Y),Y);let t=Z(fe,Et,w,W),n=X(Z(t,W,2*A,G),G,Z(t,W,w,K),K,Ot);C=Q(C,X(Z(e,q,w,J),J,n,Ot,kt),kt),O!==0&&(C=Q(C,Z(Z(4,mt,w,W),W,O,G),G)),k!==0&&(C=Q(C,Z(Z(4,pt,-w,W),W,k,G),G))}if(D!==0){let e=Z(de,Ct,D,q);C=Q(C,X(Z(te,_t,D,G),G,Z(e,q,2*N,J),J,Y),Y);let t=Z(fe,Et,D,W),n=X(Z(t,W,2*N,G),G,Z(t,W,D,K),K,Ot);C=Q(C,X(Z(e,q,D,J),J,n,Ot,kt),kt)}}if(T!==0||O!==0){if(E!==0||k!==0||w!==0||D!==0?(v=E*N,u=U*E,d=u-(u-E),f=E-d,u=U*N,p=u-(u-N),m=N-p,y=f*m-(v-d*p-f*p-d*m),b=M*D,u=U*M,d=u-(u-M),f=M-d,u=U*D,p=u-(u-D),m=D-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,ht[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,ht[1]=_-(h-l)+(b-l),S=g+h,l=S-g,ht[2]=g-(S-l)+(h-l),ht[3]=S,oe=-F,se=-k,v=w*oe,u=U*w,d=u-(u-w),f=w-d,u=U*oe,p=u-(u-oe),m=oe-p,y=f*m-(v-d*p-f*p-d*m),b=A*se,u=U*A,d=u-(u-A),f=A-d,u=U*se,p=u-(u-se),m=se-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,At[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,At[1]=_-(h-l)+(b-l),S=g+h,l=S-g,At[2]=g-(S-l)+(h-l),At[3]=S,I=X(4,ht,4,At,wt),v=E*D,u=U*E,d=u-(u-E),f=E-d,u=U*D,p=u-(u-D),m=D-p,y=f*m-(v-d*p-f*p-d*m),b=w*k,u=U*w,d=u-(u-w),f=w-d,u=U*k,p=u-(u-k),m=k-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,Dt[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,Dt[1]=_-(h+l)+(l-b),S=g+h,l=S-g,Dt[2]=g-(S-l)+(h-l),Dt[3]=S,R=4):(wt[0]=0,I=1,Dt[0]=0,R=1),T!==0){let e=Z(I,wt,T,q);C=Q(C,X(Z(ne,vt,T,G),G,Z(e,q,2*j,J),J,Y),Y);let t=Z(R,Dt,T,W),n=X(Z(t,W,2*j,G),G,Z(t,W,T,K),K,Ot);C=Q(C,X(Z(e,q,T,J),J,n,Ot,kt),kt),k!==0&&(C=Q(C,Z(Z(4,ft,T,W),W,k,G),G)),D!==0&&(C=Q(C,Z(Z(4,mt,-T,W),W,D,G),G))}if(O!==0){let e=Z(I,wt,O,q);C=Q(C,X(Z(re,yt,O,G),G,Z(e,q,2*P,J),J,Y),Y);let t=Z(R,Dt,O,W),n=X(Z(t,W,2*P,G),G,Z(t,W,O,K),K,Ot);C=Q(C,X(Z(e,q,O,J),J,n,Ot,kt),kt)}}if(E!==0||k!==0){if(w!==0||D!==0||T!==0||O!==0?(v=w*P,u=U*w,d=u-(u-w),f=w-d,u=U*P,p=u-(u-P),m=P-p,y=f*m-(v-d*p-f*p-d*m),b=A*O,u=U*A,d=u-(u-A),f=A-d,u=U*O,p=u-(u-O),m=O-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,ht[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,ht[1]=_-(h-l)+(b-l),S=g+h,l=S-g,ht[2]=g-(S-l)+(h-l),ht[3]=S,oe=-N,se=-D,v=T*oe,u=U*T,d=u-(u-T),f=T-d,u=U*oe,p=u-(u-oe),m=oe-p,y=f*m-(v-d*p-f*p-d*m),b=j*se,u=U*j,d=u-(u-j),f=j-d,u=U*se,p=u-(u-se),m=se-p,x=f*m-(b-d*p-f*p-d*m),h=y+x,l=h-y,At[0]=y-(h-l)+(x-l),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_+b,l=h-_,At[1]=_-(h-l)+(b-l),S=g+h,l=S-g,At[2]=g-(S-l)+(h-l),At[3]=S,L=X(4,ht,4,At,St),v=w*O,u=U*w,d=u-(u-w),f=w-d,u=U*O,p=u-(u-O),m=O-p,y=f*m-(v-d*p-f*p-d*m),b=T*D,u=U*T,d=u-(u-T),f=T-d,u=U*D,p=u-(u-D),m=D-p,x=f*m-(b-d*p-f*p-d*m),h=y-x,l=y-h,Tt[0]=y-(h+l)+(l-x),g=v+h,l=g-v,_=v-(g-l)+(h-l),h=_-b,l=_-h,Tt[1]=_-(h+l)+(l-b),S=g+h,l=S-g,Tt[2]=g-(S-l)+(h-l),Tt[3]=S,pe=4):(St[0]=0,L=1,Tt[0]=0,pe=1),E!==0){let e=Z(L,St,E,q);C=Q(C,X(Z(ie,bt,E,G),G,Z(e,q,2*M,J),J,Y),Y);let t=Z(pe,Tt,E,W),n=X(Z(t,W,2*M,G),G,Z(t,W,E,K),K,Ot);C=Q(C,X(Z(e,q,E,J),J,n,Ot,kt),kt),D!==0&&(C=Q(C,Z(Z(4,pt,E,W),W,D,G),G)),O!==0&&(C=Q(C,Z(Z(4,ft,-E,W),W,O,G),G))}if(k!==0){let e=Z(L,St,k,q);C=Q(C,X(Z(ae,xt,k,G),G,Z(e,q,2*F,J),J,Y),Y);let t=Z(pe,Tt,k,W),n=X(Z(t,W,2*F,G),G,Z(t,W,k,K),K,Ot);C=Q(C,X(Z(e,q,k,J),J,n,Ot,kt),kt)}}return jt[C-1]}function Lt(e,t,n,r,i,a,o,s){let c=e-o,l=n-o,u=i-o,d=t-s,f=r-s,p=a-s,m=l*p,h=u*f,g=c*c+d*d,_=u*d,v=c*p,y=l*l+f*f,b=c*f,x=l*d,S=u*u+p*p,C=g*(m-h)+y*(_-v)+S*(b-x),w=(Math.abs(m)+Math.abs(h))*g+(Math.abs(_)+Math.abs(v))*y+(Math.abs(b)+Math.abs(x))*S,T=11102230246251577e-31*w;if(C>T||-C>T)return C>0?1:-1;let E=It(e,t,n,r,i,a,o,s,w);return E>0?1:E<0?-1:0}let Rt=function(e){return e[e.success=0]=`success`,e[e.fail=1]=`fail`,e[e.noPolygons=2]=`noPolygons`,e[e.pathsIntersect=3]=`pathsIntersect`,e}({});var $=function(e){return e[e.loose=0]=`loose`,e[e.ascend=1]=`ascend`,e[e.descend=2]=`descend`,e}($||{}),zt=function(e){return e[e.none=0]=`none`,e[e.collinear=1]=`collinear`,e[e.intersect=2]=`intersect`,e}(zt||{}),Bt=function(e){return e[e.neither=0]=`neither`,e[e.left=1]=`left`,e[e.right=2]=`right`,e}(Bt||{}),Vt=class{pt;edges=[];innerLM=!1;constructor(e){this.pt=e}},Ht=class{vL=null;vR=null;vB=null;vT=null;kind=$.loose;triA=null;triB=null;isActive=!1;pendingDelaunay=!1;nextE=null;prevE=null},Ut=class{edges=[,,,];constructor(e,t,n){this.edges[0]=e,this.edges[1]=t,this.edges[2]=n}},Wt=class e{allVertices=[];allEdges=[];allTriangles=[];pendingDelaunayStack=[];horzEdgeStack=[];locMinStack=[];useDelaunay;firstActive=null;lowermostVertex=null;fastMath=!1;_edgesA=[null,null,null];_edgesB=[null,null,null];constructor(e=!0){this.useDelaunay=e}updateFastMath(t){let n=!1,r=0,i=0,a=0,o=0,s=!0;for(let e of t){for(let t of e){if(!Number.isSafeInteger(t.x)||!Number.isSafeInteger(t.y)){s=!1;break}n?(t.x<r&&(r=t.x),t.x>i&&(i=t.x),t.y<a&&(a=t.y),t.y>o&&(o=t.y)):(n=!0,r=t.x,i=t.x,a=t.y,o=t.y)}if(!s)break}if(!s||!n){this.fastMath=!1;return}let c=i-r,l=o-a;this.fastMath=Math.max(c,l)<=e.maxSafeDelta}addPath(t){let n=t.length;if(n===0)return;let r=0,i,a;if(r=e.findLocMinIdx(t,n,r),r<0)return;for(i=e.prev(r,n);t[i].x===t[r].x&&t[i].y===t[r].y;)i=e.prev(i,n);a=e.next(r,n);let o=r;for(;this.crossProductSign(t[i],t[o],t[a])===0;){if(o=e.findLocMinIdx(t,n,o),o<0)return;for(i=e.prev(o,n);t[i].x===t[o].x&&t[i].y===t[o].y;)i=e.prev(i,n);a=e.next(o,n)}let s=this.allVertices.length,c=new Vt(t[o]);this.allVertices.push(c),this.leftTurning(t[i],t[o],t[a])&&(c.innerLM=!0);let l=c;for(o=a;;){if(a=e.next(o,n),this.crossProductSign(l.pt,t[o],t[a])===0){o=a;continue}for(this.locMinStack.push(l),(this.lowermostVertex===null||l.pt.y>this.lowermostVertex.pt.y||l.pt.y===this.lowermostVertex.pt.y&&l.pt.x<this.lowermostVertex.pt.x)&&(this.lowermostVertex=l);t[o].y<=l.pt.y;){let r=new Vt(t[o]);for(this.allVertices.push(r),this.createEdge(l,r,$.ascend),l=r,o=a,a=e.next(o,n);this.crossProductSign(l.pt,t[o],t[a])===0;)o=a,a=e.next(o,n)}let i=l;for(;o!==r&&t[o].y>=l.pt.y;){let r=new Vt(t[o]);for(this.allVertices.push(r),this.createEdge(r,l,$.descend),l=r,o=a,a=e.next(o,n);this.crossProductSign(l.pt,t[o],t[a])===0;)o=a,a=e.next(o,n)}if(o===r)break;this.leftTurning(i.pt,l.pt,t[o])&&(l.innerLM=!0)}this.createEdge(c,l,$.descend);let u=this.allVertices.length-s,d=s;if(u<3||u===3&&(this.distanceSqr(this.allVertices[d].pt,this.allVertices[d+1].pt)<=1||this.distanceSqr(this.allVertices[d+1].pt,this.allVertices[d+2].pt)<=1||this.distanceSqr(this.allVertices[d+2].pt,this.allVertices[d].pt)<=1))for(let e=s;e<this.allVertices.length;++e)this.allVertices[e].edges=[]}addPaths(e){let t=0;for(let n of e)t+=n.length;if(t===0)return!1;for(let t of e)this.addPath(t);return this.allVertices.length>2}cleanUp(){this.allVertices.length=0,this.allEdges.length=0,this.allTriangles.length=0,this.pendingDelaunayStack.length=0,this.horzEdgeStack.length=0,this.locMinStack.length=0,this.firstActive=null,this.lowermostVertex=null}fixupEdgeIntersects(){for(let e=0;e<this.allEdges.length;++e){let t=this.allEdges[e],n=t.vR.pt.x,r=t.vB.pt.y,i=t.vT.pt.y;for(let a=e+1;a<this.allEdges.length;++a){let e=this.allEdges[a];if(e.vL.pt.x>=n)break;if(e.vT.pt.y<r&&e.vB.pt.y>i&&this.segsIntersect(e.vL.pt,e.vR.pt,t.vL.pt,t.vR.pt)===zt.intersect&&!this.removeIntersection(e,t))return!1}}return!0}mergeDupOrCollinearVertices(){if(this.allVertices.length<2)return;let t=0;for(let n=1;n<this.allVertices.length;++n){let r=this.allVertices[t],i=this.allVertices[n];if(!(r.pt.x===i.pt.x&&r.pt.y===i.pt.y)){t=n;continue}(!r.innerLM||!i.innerLM)&&(r.innerLM=!1);for(let e of i.edges)e.vB===i?e.vB=r:e.vT=r,e.vL===i?e.vL=r:e.vR=r;r.edges.push(...i.edges),i.edges=[];for(let t=0;t<r.edges.length;++t){let n=r.edges[t];if(!(e.isHorizontal(n)||n.vB!==r))for(let e=t+1;e<r.edges.length;++e){let t=r.edges[e];if(!(t.vB!==r||n.vT.pt.y===t.vT.pt.y||this.crossProductSign(n.vT.pt,r.pt,t.vT.pt)!==0)){n.vT.pt.y<t.vT.pt.y?this.splitEdge(n,t):this.splitEdge(t,n);break}}}}}splitEdge(t,n){let r=t.vT,i=n.vT;e.removeEdgeFromVertex(r,t),t.vT=i,t.vL===r?t.vL=i:t.vR=i,i.edges.push(t),this.createEdge(i,r,t.kind)}removeIntersection(t,n){let r=t.vL,i=n,a=this.shortestDistFromSegment(t.vL.pt,n.vL.pt,n.vR.pt),o=this.shortestDistFromSegment(t.vR.pt,n.vL.pt,n.vR.pt);if(o<a&&(a=o,r=t.vR),o=this.shortestDistFromSegment(n.vL.pt,t.vL.pt,t.vR.pt),o<a&&(a=o,i=t,r=n.vL),o=this.shortestDistFromSegment(n.vR.pt,t.vL.pt,t.vR.pt),o<a&&(a=o,i=t,r=n.vR),a>1)return!1;let s=i.vT;return e.removeEdgeFromVertex(s,i),i.vL===s?i.vL=r:i.vR=r,i.vT=r,r.edges.push(i),r.innerLM=!1,i.vB.innerLM&&e.getLocMinAngle(i.vB)<=0&&(i.vB.innerLM=!1),this.createEdge(r,s,i.kind),!0}createEdge(e,t,n){let r=new Ht;return this.allEdges.push(r),e.pt.y===t.pt.y?(r.vB=e,r.vT=t):e.pt.y<t.pt.y?(r.vB=t,r.vT=e):(r.vB=e,r.vT=t),e.pt.x<=t.pt.x?(r.vL=e,r.vR=t):(r.vL=t,r.vR=e),r.kind=n,e.edges.push(r),t.edges.push(r),n===$.loose&&(this.queuePendingDelaunay(r),this.addEdgeToActives(r)),r}createTriangle(t,n,r){let i=new Ut(t,n,r);this.allTriangles.push(i);for(let t=0;t<3;++t){let n=i.edges[t];n.triA===null?(n.triA=i,e.isLooseEdge(n)||this.removeEdgeFromActives(n)):(n.triB=i,this.removeEdgeFromActives(n))}return i}forceLegal(t){if(t.triA===null||t.triB===null)return;let n=null,r=null,i=this._edgesA,a=this._edgesB;i[0]=i[1]=i[2]=null,a[0]=a[1]=a[2]=null;for(let r=0;r<3;++r){if(t.triA.edges[r]===t)continue;let o=t.triA.edges[r],s=e.edgeContains(o,t.vL);s===Bt.left?(i[1]=o,n=o.vR):s===Bt.right?(i[1]=o,n=o.vL):a[1]=o}for(let n=0;n<3;++n){if(t.triB.edges[n]===t)continue;let o=t.triB.edges[n],s=e.edgeContains(o,t.vL);s===Bt.left?(i[2]=o,r=o.vR):s===Bt.right?(i[2]=o,r=o.vL):a[2]=o}if(n===null||r===null)return;let o=this.crossProductSign(n.pt,t.vL.pt,t.vR.pt);if(o===0)return;let s=this.crossProductSign(r.pt,t.vL.pt,t.vR.pt);if(s===0||o===s)return;let c=this.inCircleTest(n.pt,t.vL.pt,t.vR.pt,r.pt);if(!(c===0||this.rightTurning(n.pt,t.vL.pt,t.vR.pt)===c<0)){t.vL=n,t.vR=r,t.triA.edges[0]=t;for(let n=1;n<3;++n){let r=i[n];if(t.triA.edges[n]=r,e.isLooseEdge(r)&&this.queuePendingDelaunay(r),!(r.triA===t.triA||r.triB===t.triA))if(r.triA===t.triB)r.triA=t.triA;else if(r.triB===t.triB)r.triB=t.triA;else throw Error(`Triangulation internal error`)}t.triB.edges[0]=t;for(let n=1;n<3;++n){let r=a[n];if(t.triB.edges[n]=r,e.isLooseEdge(r)&&this.queuePendingDelaunay(r),!(r.triA===t.triB||r.triB===t.triB))if(r.triA===t.triA)r.triA=t.triB;else if(r.triB===t.triA)r.triB=t.triB;else throw Error(`Triangulation internal error`)}}}createInnerLocMinLooseEdge(e){if(this.firstActive===null)return null;let t=e.pt.x,n=e.pt.y,r=this.firstActive,i=null,a=-1;for(;r!==null;){if(r.vL.pt.x<=t&&r.vR.pt.x>=t&&r.vB.pt.y>=n&&r.vB!==e&&r.vT!==e&&!this.leftTurning(r.vL.pt,e.pt,r.vR.pt)){let t=this.shortestDistFromSegment(e.pt,r.vL.pt,r.vR.pt);(i===null||t<a)&&(i=r,a=t)}r=r.nextE}if(i===null)return null;let o=i.vT.pt.y<=n?i.vB:i.vT,s=!0;for(;s;)for(s=!1,r=this.firstActive;r!==null;){if(r.vB!==o&&r.vT!==o&&r.vB!==e&&r.vT!==e&&this.segsIntersect(r.vB.pt,r.vT.pt,o.pt,e.pt)===zt.intersect){o=r.vT.pt.y>n?r.vT:r.vB,s=!0;break}r=r.nextE}return this.createEdge(o,e,$.loose)}doTriangulateLeft(t,n,r,i=!1){let a=null,o=null,s=t.vB===n?t.vT:t.vB;for(let e of n.edges){if(e===t||!e.isActive)continue;let r=e.vT===n?e.vB:e.vT;if(r===s)continue;let i=this.crossProductSign(s.pt,n.pt,r.pt);if(i===0){if(s.pt.x>n.pt.x==n.pt.x>r.pt.x)continue}else if(i>0||a!==null&&!this.leftTurning(r.pt,n.pt,a.pt))continue;a=r,o=e}if(a===null||a.pt.y<r||o===null)return;if(i){let e=s.pt.x-n.pt.x,t=s.pt.y-n.pt.y,r=a.pt.x-n.pt.x,i=a.pt.y-n.pt.y;if(e*r+t*i<0)return}if(a.pt.y<n.pt.y){if(e.isLeftEdge(o))return}else if(a.pt.y>n.pt.y&&e.isRightEdge(o))return;let c=e.findLinkingEdge(a,s,a.pt.y<s.pt.y);c===null&&(c=this.createEdge(a,s,$.loose)),this.createTriangle(t,o,c),e.edgeCompleted(c)||this.doTriangulateLeft(c,a,r,!0)}doTriangulateRight(t,n,r,i=!1){let a=null,o=null,s=t.vB===n?t.vT:t.vB;for(let e of n.edges){if(e===t||!e.isActive)continue;let r=e.vT===n?e.vB:e.vT;if(r===s)continue;let i=this.crossProductSign(s.pt,n.pt,r.pt);if(i===0){if(s.pt.x>n.pt.x==n.pt.x>r.pt.x)continue}else if(i<0||a!==null&&!this.rightTurning(r.pt,n.pt,a.pt))continue;a=r,o=e}if(a===null||a.pt.y<r||o===null)return;if(i){let e=s.pt.x-n.pt.x,t=s.pt.y-n.pt.y,r=a.pt.x-n.pt.x,i=a.pt.y-n.pt.y;if(e*r+t*i<0)return}if(a.pt.y<n.pt.y){if(e.isRightEdge(o))return}else if(a.pt.y>n.pt.y&&e.isLeftEdge(o))return;let c=e.findLinkingEdge(a,s,a.pt.y>s.pt.y);c===null&&(c=this.createEdge(a,s,$.loose)),this.createTriangle(t,c,o),e.edgeCompleted(c)||this.doTriangulateRight(c,a,r,!0)}addEdgeToActives(e){e.isActive||(e.prevE=null,e.nextE=this.firstActive,e.isActive=!0,this.firstActive!==null&&(this.firstActive.prevE=e),this.firstActive=e)}queuePendingDelaunay(e){e.pendingDelaunay||(e.pendingDelaunay=!0,this.pendingDelaunayStack.push(e))}removeEdgeFromActives(t){e.removeEdgeFromVertex(t.vB,t),e.removeEdgeFromVertex(t.vT,t);let n=t.prevE,r=t.nextE;r!==null&&(r.prevE=n),n!==null&&(n.nextE=r),t.isActive=!1,this.firstActive===t&&(this.firstActive=r)}execute(t){let n=[];if(this.updateFastMath(t),!this.addPaths(t))return{result:Rt.noPolygons,solution:n};if(this.lowermostVertex.innerLM){for(;this.locMinStack.length>0;){let e=this.locMinStack.pop();e.innerLM=!e.innerLM}for(let e of this.allEdges)e.kind===$.ascend?e.kind=$.descend:e.kind===$.descend&&(e.kind=$.ascend)}else this.locMinStack.length=0;if(this.allEdges.sort((e,t)=>e.vL.pt.x<t.vL.pt.x?-1:e.vL.pt.x>t.vL.pt.x?1:0),!this.fixupEdgeIntersects())return this.cleanUp(),{result:Rt.pathsIntersect,solution:n};this.allVertices.sort((e,t)=>e.pt.y===t.pt.y?e.pt.x<t.pt.x?-1:e.pt.x>t.pt.x?1:0:t.pt.y<e.pt.y?-1:1),this.mergeDupOrCollinearVertices();let r=this.allVertices[0].pt.y;for(let t of this.allVertices)if(t.edges.length!==0){if(t.pt.y!==r){for(;this.locMinStack.length>0;){let t=this.locMinStack.pop(),i=this.createInnerLocMinLooseEdge(t);if(i===null)return this.cleanUp(),{result:Rt.fail,solution:n};e.isHorizontal(i)?i.vL===i.vB?this.doTriangulateLeft(i,i.vB,r):this.doTriangulateRight(i,i.vB,r):(this.doTriangulateLeft(i,i.vB,r),e.edgeCompleted(i)||this.doTriangulateRight(i,i.vB,r)),this.addEdgeToActives(t.edges[0]),this.addEdgeToActives(t.edges[1])}for(;this.horzEdgeStack.length>0;){let t=this.horzEdgeStack.pop();e.edgeCompleted(t)||(t.vB===t.vL?e.isLeftEdge(t)&&this.doTriangulateLeft(t,t.vB,r):e.isRightEdge(t)&&this.doTriangulateRight(t,t.vB,r))}r=t.pt.y}for(let n=t.edges.length-1;n>=0;--n){if(n>=t.edges.length)continue;let r=t.edges[n];e.edgeCompleted(r)||e.isLooseEdge(r)||(t===r.vB?(e.isHorizontal(r)&&this.horzEdgeStack.push(r),t.innerLM||this.addEdgeToActives(r)):e.isHorizontal(r)?this.horzEdgeStack.push(r):e.isLeftEdge(r)?this.doTriangulateLeft(r,r.vB,t.pt.y):this.doTriangulateRight(r,r.vB,t.pt.y))}t.innerLM&&this.locMinStack.push(t)}for(;this.horzEdgeStack.length>0;){let t=this.horzEdgeStack.pop();!e.edgeCompleted(t)&&t.vB===t.vL&&this.doTriangulateLeft(t,t.vB,r)}if(this.useDelaunay)for(;this.pendingDelaunayStack.length>0;){let e=this.pendingDelaunayStack.pop();e.pendingDelaunay=!1,this.forceLegal(e)}for(let t of this.allTriangles){let r=e.pathFromTriangle(t),i=this.crossProductSign(r[0],r[1],r[2]);i!==0&&(i<0&&r.reverse(),n.push(r))}return this.cleanUp(),{result:Rt.success,solution:n}}crossProductSign(e,t,n){if(this.fastMath){let r=(t.x-e.x)*(n.y-t.y),i=(t.y-e.y)*(n.x-t.x);return r>i?1:r<i?-1:0}return-Ft(e.x,e.y,t.x,t.y,n.x,n.y)}distanceSqr(t,n){if(!this.fastMath)return e.distanceSqr(t,n);let r=t.x-n.x,i=t.y-n.y;return r*r+i*i}shortestDistFromSegment(t,n,r){if(!this.fastMath)return e.shortestDistFromSegment(t,n,r);let i=r.x-n.x,a=r.y-n.y,o=t.x-n.x,s=t.y-n.y,c=o*i+s*a,l=i*i+a*a;if(c<0)return this.distanceSqr(t,n);if(c>l)return this.distanceSqr(t,r);let u=o*a-i*s;return u*u/l}segsIntersect(t,n,r,i){if(!this.fastMath)return e.segsIntersect(t,n,r,i);if(t.x===r.x&&t.y===r.y||t.x===i.x&&t.y===i.y||n.x===i.x&&n.y===i.y)return zt.none;let a=n.y-t.y,o=n.x-t.x,s=i.y-r.y,c=i.x-r.x,l=t.x-r.x,u=t.y-r.y,d=a*c-s*o;if(d===0)return zt.collinear;let f=l*s-u*c;if(f>=0){if(d<0||f>=d)return zt.none}else if(d>0||f<=d)return zt.none;if(f=l*a-u*o,f>=0){if(d>0&&f<d)return zt.intersect}else if(d<0&&f>d)return zt.intersect;return zt.none}inCircleTest(e,t,n,r){if(this.fastMath){let i=e.x-r.x,a=e.y-r.y,o=t.x-r.x,s=t.y-r.y,c=n.x-r.x,l=n.y-r.y,u=(i*i+a*a)*(o*l-c*s)+(o*o+s*s)*(c*a-i*l)+(c*c+l*l)*(i*s-o*a);return u>0?1:u<0?-1:0}return Lt(e.x,e.y,t.x,t.y,n.x,n.y,r.x,r.y)}static isLooseEdge(e){return e.kind===$.loose}static isLeftEdge(e){return e.kind===$.ascend}static isRightEdge(e){return e.kind===$.descend}static isHorizontal(e){return e.vB.pt.y===e.vT.pt.y}leftTurning(e,t,n){return this.crossProductSign(e,t,n)<0}rightTurning(e,t,n){return this.crossProductSign(e,t,n)>0}static edgeCompleted(e){return e.triA===null?!1:e.triB===null?e.kind!==$.loose:!0}static edgeContains(e,t){return e.vL===t?Bt.left:e.vR===t?Bt.right:Bt.neither}static getAngle(e,t,n){let r=Number(t.x-e.x),i=Number(t.y-e.y),a=Number(t.x-n.x),o=Number(t.y-n.y),s=r*a+i*o,c=r*o-i*a;return Math.atan2(c,s)}static getLocMinAngle(t){let n,r;return t.edges[0].kind===$.ascend?(n=0,r=1):(r=0,n=1),e.getAngle(t.edges[r].vT.pt,t.pt,t.edges[n].vT.pt)}static removeEdgeFromVertex(e,t){let n=e.edges.indexOf(t);if(n<0)throw Error(`Edge not found in vertex`);let r=e.edges.length-1;n!==r&&(e.edges[n]=e.edges[r]),e.edges.pop()}static findLocMinIdx(e,t,n){if(t<3)return-1;let r=n,i=(n+1)%t;for(;e[i].y<=e[n].y;)if(n=i,i=(i+1)%t,n===r)return-1;for(;e[i].y>=e[n].y;)n=i,i=(i+1)%t;return n}static prev(e,t){return e===0?t-1:e-1}static next(e,t){return(e+1)%t}static findLinkingEdge(e,t,n){let r=null;for(let i of e.edges)if(i.vL===t||i.vR===t){if(i.kind===$.loose||i.kind===$.ascend===n)return i;r=i}return r}static pathFromTriangle(e){let t=[e.edges[0].vL.pt,e.edges[0].vR.pt],n=e.edges[1];return n.vL.pt.x===t[0].x&&n.vL.pt.y===t[0].y||n.vL.pt.x===t[1].x&&n.vL.pt.y===t[1].y?t.push(n.vR.pt):t.push(n.vL.pt),t}static maxSafeDelta=Math.floor(Math.sqrt((2**53-1)/2));static shortestDistFromSegment(t,n,r){let i=r.x-n.x,a=r.y-n.y,o=t.x-n.x,s=t.y-n.y,c=e.maxSafeDelta;if(Math.abs(i)<=c&&Math.abs(a)<=c&&Math.abs(o)<=c&&Math.abs(s)<=c){let c=o*i+s*a,l=i*i+a*a;return c<0?e.distanceSqr(t,n):c>l?e.distanceSqr(t,r):(o*a-i*s)*(o*a-i*s)/l}let l=BigInt(r.x)-BigInt(n.x),u=BigInt(r.y)-BigInt(n.y),d=BigInt(t.x)-BigInt(n.x),f=BigInt(t.y)-BigInt(n.y),p=d*l+f*u,m=l*l+u*u;if(p<BigInt(0))return e.distanceSqr(t,n);if(p>m)return e.distanceSqr(t,r);let h=d*u-l*f;return Number(h*h)/Number(m)}static segsIntersect(e,t,n,r){if(e.x===n.x&&e.y===n.y||e.x===r.x&&e.y===r.y||t.x===r.x&&t.y===r.y)return zt.none;let i=Ft(n.x,n.y,r.x,r.y,e.x,e.y),a=Ft(n.x,n.y,r.x,r.y,t.x,t.y);if(i===0&&a===0)return zt.collinear;if(i===0||a===0||i===a)return zt.none;let o=Ft(e.x,e.y,t.x,t.y,n.x,n.y),s=Ft(e.x,e.y,t.x,t.y,r.x,r.y);return o===0||s===0||o===s?zt.none:zt.intersect}static distanceSqr(t,n){let r=t.x-n.x,i=t.y-n.y,a=e.maxSafeDelta;if(Math.abs(r)<=a&&Math.abs(i)<=a){let e=r*r+i*i;if(e<=2**53-1)return e}let o=BigInt(t.x)-BigInt(n.x),s=BigInt(t.y)-BigInt(n.y);return Number(o*o+s*s)}},Gt=t({Clipper:()=>Lr,addPolyNodeToPathsD:()=>pr,area:()=>gn,areaD:()=>vn,areaPaths:()=>_n,areaPathsD:()=>yn,booleanOp:()=>rn,booleanOpD:()=>on,booleanOpDWithPolyTree:()=>sn,booleanOpWithPolyTree:()=>an,difference:()=>$t,differenceD:()=>en,distanceSqr:()=>rr,ellipse:()=>Nr,ellipseD:()=>Pr,getBounds:()=>Xn,getBoundsD:()=>Qn,getBoundsPaths:()=>Zn,getBoundsPathsD:()=>$n,inflatePaths:()=>cn,inflatePathsD:()=>ln,inflateRect:()=>or,inflateRectD:()=>sr,intersect:()=>Yt,intersectD:()=>Xt,invalidRect64:()=>qt,invalidRectD:()=>Jt,isPositive:()=>bn,isPositiveD:()=>xn,makePath:()=>er,makePathD:()=>tr,midPoint:()=>ir,midPointD:()=>ar,minkowskiDiff:()=>mn,minkowskiDiffD:()=>hn,minkowskiSum:()=>fn,minkowskiSumD:()=>pn,offsetPath:()=>En,path64FromD:()=>Rn,path64ToString:()=>Sn,pathD:()=>Vn,pathDToString:()=>wn,paths64FromD:()=>zn,paths64ToString:()=>Cn,pathsD:()=>Bn,pathsDToString:()=>Tn,perpendicDistFromLineSqrd:()=>hr,perpendicDistFromLineSqrd64:()=>gr,pointInPolygon:()=>jr,pointInPolygonD:()=>Mr,pointsNearEqual:()=>cr,polyTreeToPaths64:()=>fr,polyTreeToPathsD:()=>mr,ramerDouglasPeucker:()=>vr,ramerDouglasPeuckerD:()=>xr,ramerDouglasPeuckerPaths:()=>yr,ramerDouglasPeuckerPathsD:()=>Sr,rectClip:()=>un,rectClipLines:()=>dn,reversePath:()=>Kn,reversePathD:()=>qn,reversePaths:()=>Jn,reversePathsD:()=>Yn,scalePath:()=>An,scalePath64:()=>Pn,scalePathD:()=>Mn,scalePathDFromInt:()=>In,scalePaths:()=>jn,scalePaths64:()=>Fn,scalePathsD:()=>Nn,scalePathsDFromInt:()=>Ln,scalePoint64:()=>Dn,scalePointD:()=>On,scaleRect:()=>kn,simplifyPath:()=>Tr,simplifyPathD:()=>Dr,simplifyPaths:()=>Er,simplifyPathsD:()=>Or,sqr:()=>nr,stripDuplicates:()=>ur,stripNearDuplicates:()=>lr,translatePath:()=>Hn,translatePathD:()=>Wn,translatePaths:()=>Un,translatePathsD:()=>Gn,triangulate:()=>Fr,triangulateD:()=>Ir,trimCollinear:()=>kr,trimCollinearD:()=>Ar,union:()=>Zt,unionD:()=>Qt,xor:()=>tn,xorD:()=>nn});const Kt=BigInt(2),qt=ge,Jt=_e;function Yt(e,t,r){return rn(n.Intersection,e,t,r)}function Xt(e,t,r,i=2){return on(n.Intersection,e,t,r,i)}function Zt(e,t,r){return typeof t==`number`?rn(n.Union,e,null,t):rn(n.Union,e,t,r)}function Qt(e,t,r,i){return typeof t==`number`?on(n.Union,e,null,t):on(n.Union,e,t,r,i||2)}function $t(e,t,r){return rn(n.Difference,e,t,r)}function en(e,t,r,i=2){return on(n.Difference,e,t,r,i)}function tn(e,t,r){return rn(n.Xor,e,t,r)}function nn(e,t,r,i=2){return on(n.Xor,e,t,r,i)}function rn(e,t,n,i){let a=[];if(t===null)return a;let o=new Ve;return o.addPaths(t,r.Subject),n!==null&&o.addPaths(n,r.Clip),o.execute(e,i,a),a}function an(e,t,n,i,a){if(t===null)return;let o=new Ve;o.addPaths(t,r.Subject),n!==null&&o.addPaths(n,r.Clip),o.execute(e,a,i)}function on(e,t,n,r,i=2){let a=[],o=new He(i);return o.addSubjectPaths(t),n!==null&&o.addClipPaths(n),o.execute(e,r,a),a}function sn(e,t,n,r,i,a=2){if(t===null)return;let o=new He(a);o.addSubjectPaths(t),n!==null&&o.addClipPaths(n),o.execute(e,i,r)}function cn(e,t,n,r,i=2,a=0){let o=new Ke(i,a);o.addPaths(e,n,r);let s=[];return o.execute(t,s),s}function ln(e,t,n,r,i=2,a=2,o=0){I.checkPrecision(a);let s=10**a,c=Fn(e,s),l=new Ke(i,s*o);l.addPaths(c,n,r);let u=[];return l.execute(t*s,u),Nn(u,1/s)}function un(e,t,n){if(`left`in e&&typeof e.left==`number`&&Number.isInteger(e.left)){let n=e;if(R.isEmpty(n))return[];if(Array.isArray(t[0])){let e=t;return e.length===0?[]:new Je(n).execute(e)}else{let e=t;return e.length===0?[]:un(n,[e])}}else{let r=e,i=n||2;if(I.checkPrecision(i),pe.isEmpty(r))return[];let a=10**i,o=kn(r,a);if(Array.isArray(t[0])){let e=t;if(e.length===0)return[];let n=Fn(e,a);return Nn(new Je(o).execute(n),1/a)}else{let e=t;return e.length===0?[]:un(r,[e],i)}}}function dn(e,t,n){if(`left`in e&&typeof e.left==`number`&&Number.isInteger(e.left)){let n=e;if(R.isEmpty(n))return[];if(Array.isArray(t[0])){let e=t;return e.length===0?[]:new Ye(n).execute(e)}else{let e=t;return e.length===0?[]:dn(n,[e])}}else{let r=e,i=n||2;if(I.checkPrecision(i),pe.isEmpty(r))return[];let a=10**i,o=kn(r,a);if(Array.isArray(t[0])){let e=t;if(e.length===0)return[];let n=Fn(e,a);return Nn(new Ye(o).execute(n),1/a)}else{let e=t;return e.length===0?[]:dn(r,[e],i)}}}function fn(e,t,n){return nt.sum(e,t,n)}function pn(e,t,n){return nt.sumD(e,t,n)}function mn(e,t,n){return nt.diff(e,t,n)}function hn(e,t,n){return nt.diffD(e,t,n)}function gn(e){return I.area(e)}function _n(e){let t=0;for(let n of e)t+=gn(n);return t}function vn(e){let t=0,n=e.length;if(n<3)return 0;let r=e[n-1];for(let n of e)t+=(r.y+n.y)*(r.x-n.x),r=n;return t*.5}function yn(e){let t=0;for(let n of e)t+=vn(n);return t}function bn(e){return gn(e)>=0}function xn(e){return vn(e)>=0}function Sn(e){let t=``;for(let n of e)t+=L.toString(n);return t+`
5
+ `}function Cn(e){let t=``;for(let n of e)t+=Sn(n);return t}function wn(e,t=2){let n=``;for(let r of e)n+=fe.toString(r,t);return n+`
6
+ `}function Tn(e,t=2){let n=``;for(let r of e)n+=wn(r,t);return n}function En(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function Dn(e,t){return{x:Math.round(e.x*t),y:Math.round(e.y*t)}}function On(e,t){return{x:e.x*t,y:e.y*t}}function kn(e,t){let n=I.maxSafeCoordinateForScale(t);return I.checkSafeScaleValue(e.left,n,`scaleRect`),I.checkSafeScaleValue(e.top,n,`scaleRect`),I.checkSafeScaleValue(e.right,n,`scaleRect`),I.checkSafeScaleValue(e.bottom,n,`scaleRect`),{left:Math.round(e.left*t),top:Math.round(e.top*t),right:Math.round(e.right*t),bottom:Math.round(e.bottom*t)}}function An(e,t){if(I.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push({x:Math.round(r.x*t),y:Math.round(r.y*t)});return n}function jn(e,t){if(I.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(An(r,t));return n}function Mn(e,t){if(I.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(fe.scale(r,t));return n}function Nn(e,t){if(I.isAlmostZero(t-1))return e;let n=[];for(let r of e)n.push(Mn(r,t));return n}function Pn(e,t){let n=I.maxSafeCoordinateForScale(t),r=[];for(let i of e)I.checkSafeScaleValue(i.x,n,`scalePath64`),I.checkSafeScaleValue(i.y,n,`scalePath64`),r.push({x:Math.round(i.x*t),y:Math.round(i.y*t)});return r}function Fn(e,t){let n=[];for(let r of e)n.push(Pn(r,t));return n}function In(e,t){let n=[];for(let r of e)n.push({x:r.x*t,y:r.y*t});return n}function Ln(e,t){let n=[];for(let r of e)n.push(In(r,t));return n}function Rn(e){let t=[];for(let n of e)t.push(L.fromPointD(n));return t}function zn(e){let t=[];for(let n of e)t.push(Rn(n));return t}function Bn(e){let t=[];for(let n of e)t.push(Vn(n));return t}function Vn(e){let t=[];for(let n of e)t.push(fe.fromPoint64(n));return t}function Hn(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function Un(e,t,n){let r=[];for(let i of e)r.push(En(i,t,n));return r}function Wn(e,t,n){let r=[];for(let i of e)r.push({x:i.x+t,y:i.y+n});return r}function Gn(e,t,n){let r=[];for(let i of e)r.push(Wn(i,t,n));return r}function Kn(e){return[...e].reverse()}function qn(e){return[...e].reverse()}function Jn(e){let t=[];for(let n of e)t.push(Kn(n));return t}function Yn(e){let t=[];for(let n of e)t.push(qn(n));return t}function Xn(e){return I.getBounds(e)}function Zn(e){let t=R.createInvalid();for(let n of e)for(let e of n)e.x<t.left&&(t.left=e.x),e.x>t.right&&(t.right=e.x),e.y<t.top&&(t.top=e.y),e.y>t.bottom&&(t.bottom=e.y);return t.left===2**53-1?{left:0,top:0,right:0,bottom:0}:t}function Qn(e){let t=pe.createInvalid();for(let n of e)n.x<t.left&&(t.left=n.x),n.x>t.right&&(t.right=n.x),n.y<t.top&&(t.top=n.y),n.y>t.bottom&&(t.bottom=n.y);return Math.abs(t.left-Number.MAX_VALUE)<I.floatingPointTolerance?{left:0,top:0,right:0,bottom:0}:t}function $n(e){let t=pe.createInvalid();for(let n of e)for(let e of n)e.x<t.left&&(t.left=e.x),e.x>t.right&&(t.right=e.x),e.y<t.top&&(t.top=e.y),e.y>t.bottom&&(t.bottom=e.y);return Math.abs(t.left-Number.MAX_VALUE)<I.floatingPointTolerance?{left:0,top:0,right:0,bottom:0}:t}function er(e){let t=Math.floor(e.length/2),n=[];for(let r=0;r<t;r++)n.push({x:e[r*2],y:e[r*2+1],z:0});return n}function tr(e){let t=Math.floor(e.length/2),n=[];for(let r=0;r<t;r++)n.push({x:e[r*2],y:e[r*2+1],z:0});return n}function nr(e){return e*e}function rr(e,t){let n=e.x-t.x,r=e.y-t.y;if(Number.isSafeInteger(n)&&Number.isSafeInteger(r)){let e=Math.abs(n),t=Math.abs(r),i=I.maxCoordForSafeAreaProduct*2;if(e<=i&&t<=i){let e=n*n+r*r;if(e<=2**53-1)return e}let a=BigInt(n)*BigInt(n),o=BigInt(r)*BigInt(r);return Number(a+o)}return nr(n)+nr(r)}function ir(e,t){return Number.isSafeInteger(e.x)&&Number.isSafeInteger(t.x)&&Number.isSafeInteger(e.y)&&Number.isSafeInteger(t.y)&&(Math.abs(e.x)+Math.abs(t.x)>2**53-1||Math.abs(e.y)+Math.abs(t.y)>2**53-1)?{x:Number((BigInt(e.x)+BigInt(t.x))/Kt),y:Number((BigInt(e.y)+BigInt(t.y))/Kt)}:{x:Math.round((e.x+t.x)/2),y:Math.round((e.y+t.y)/2)}}function ar(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function or(e,t,n){e.left-=t,e.right+=t,e.top-=n,e.bottom+=n}function sr(e,t,n){e.left-=t,e.right+=t,e.top-=n,e.bottom+=n}function cr(e,t,n){return nr(e.x-t.x)+nr(e.y-t.y)<n}function lr(e,t,n){let r=e.length,i=[];if(r===0)return i;let a=e[0];i.push(a);for(let n=1;n<r;n++)cr(a,e[n],t)||(a=e[n],i.push(a));return n&&cr(a,i[0],t)&&i.pop(),i}function ur(e,t){let n=e.length,r=[];if(n===0)return r;let i=e[0];r.push(i);for(let t=1;t<n;t++)L.equals(i,e[t])||(i=e[t],r.push(i));return t&&L.equals(i,r[0])&&r.pop(),r}function dr(e,t){e.poly&&e.poly.length>0&&t.push(e.poly);for(let n=0;n<e.count;n++)dr(e.child(n),t)}function fr(e){let t=[];for(let n=0;n<e.count;n++)dr(e.child(n),t);return t}function pr(e,t){e.poly&&e.poly.length>0&&t.push(e.poly);for(let n=0;n<e.count;n++)pr(e.child(n),t)}function mr(e){let t=[];for(let n=0;n<e.count;n++)pr(e.child(n),t);return t}function hr(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;return a===0&&o===0?0:nr(r*o-a*i)/(a*a+o*o)}function gr(e,t,n){let r=e.x-t.x,i=e.y-t.y,a=n.x-t.x,o=n.y-t.y;if(a===0&&o===0)return 0;if(Number.isSafeInteger(r)&&Number.isSafeInteger(i)&&Number.isSafeInteger(a)&&Number.isSafeInteger(o)){let e=BigInt(r)*BigInt(o)-BigInt(a)*BigInt(i),t=e*e,n=BigInt(a)*BigInt(a)+BigInt(o)*BigInt(o);return Number(t)/Number(n)}return nr(I.crossProduct(t,e,n))/(a*a+o*o)}function _r(e,t,n,r,i){for(;;){let a=0,o=0;for(;n>t&&L.equals(e[t],e[n]);)i[n--]=!1;for(let r=t+1;r<n;++r){let i=gr(e[r],e[t],e[n]);i<=o||(o=i,a=r)}if(o<=r)return;if(i[a]=!0,a>t+1&&_r(e,t,a,r,i),a<n-1){t=a;continue}break}}function vr(e,t){let n=e.length;if(n<5)return e;let r=Array(n).fill(!1);r[0]=!0,r[n-1]=!0,_r(e,0,n-1,nr(t),r);let i=[];for(let t=0;t<n;++t)r[t]&&i.push(e[t]);return i}function yr(e,t){let n=[];for(let r of e)n.push(vr(r,t));return n}function br(e,t,n,r,i){for(;;){let a=0,o=0;for(;n>t&&fe.equals(e[t],e[n]);)i[n--]=!1;for(let r=t+1;r<n;++r){let i=hr(e[r],e[t],e[n]);i<=o||(o=i,a=r)}if(o<=r)return;if(i[a]=!0,a>t+1&&br(e,t,a,r,i),a<n-1){t=a;continue}break}}function xr(e,t){let n=e.length;if(n<5)return e;let r=Array(n).fill(!1);r[0]=!0,r[n-1]=!0,br(e,0,n-1,nr(t),r);let i=[];for(let t=0;t<n;++t)r[t]&&i.push(e[t]);return i}function Sr(e,t){let n=[];for(let r of e)n.push(xr(r,t));return n}function Cr(e,t,n){for(++e;e<=t&&n[e];)++e;if(e<=t)return e;for(e=0;n[e];)++e;return e}function wr(e,t,n){for(e===0?e=t:--e;e>0&&n[e];)--e;if(!n[e])return e;for(e=t;n[e];)--e;return e}function Tr(e,t,n=!0){let r=e.length,i=r-1,a=nr(t);if(r<4)return e;let o=Array(r).fill(!1),s=Array(r).fill(0),c=0;n?(s[0]=gr(e[0],e[i],e[1]),s[i]=gr(e[i],e[0],e[i-1])):(s[0]=Number.MAX_VALUE,s[i]=Number.MAX_VALUE);for(let t=1;t<i;++t)s[t]=gr(e[t],e[t-1],e[t+1]);for(;;){if(s[c]>a){let e=c;do c=Cr(c,i,o);while(c!==e&&s[c]>a);if(c===e)break}let t=wr(c,i,o),r=Cr(c,i,o);if(r===t)break;let l;if(s[r]<s[c]){l=t;let a=c;c=r;let u=Cr(r,i,o);o[c]=!0,c=u;let d=Cr(u,i,o);(n||c!==i&&c!==0)&&(s[c]=gr(e[c],e[a],e[d])),(n||a!==0&&a!==i)&&(s[a]=gr(e[a],e[l],e[c]))}else{l=wr(t,i,o),o[c]=!0,c=r;let a=Cr(r,i,o);(n||c!==i&&c!==0)&&(s[c]=gr(e[c],e[t],e[a])),(n||t!==0&&t!==i)&&(s[t]=gr(e[t],e[l],e[c]))}}let l=[];for(let t=0;t<r;t++)o[t]||l.push(e[t]);return l}function Er(e,t,n=!0){let r=[];for(let i of e)r.push(Tr(i,t,n));return r}function Dr(e,t,n=!0){let r=e.length,i=r-1,a=nr(t);if(r<4)return e;let o=Array(r).fill(!1),s=Array(r).fill(0),c=0;n?(s[0]=hr(e[0],e[i],e[1]),s[i]=hr(e[i],e[0],e[i-1])):(s[0]=Number.MAX_VALUE,s[i]=Number.MAX_VALUE);for(let t=1;t<i;++t)s[t]=hr(e[t],e[t-1],e[t+1]);for(;;){if(s[c]>a){let e=c;do c=Cr(c,i,o);while(c!==e&&s[c]>a);if(c===e)break}let t=wr(c,i,o),r=Cr(c,i,o);if(r===t)break;let l;if(s[r]<s[c]){l=t;let a=c;c=r;let u=Cr(r,i,o);o[c]=!0,c=u;let d=Cr(u,i,o);(n||c!==i&&c!==0)&&(s[c]=hr(e[c],e[a],e[d])),(n||a!==0&&a!==i)&&(s[a]=hr(e[a],e[l],e[c]))}else{l=wr(t,i,o),o[c]=!0,c=r;let a=Cr(r,i,o);(n||c!==i&&c!==0)&&(s[c]=hr(e[c],e[t],e[a])),(n||t!==0&&t!==i)&&(s[t]=hr(e[t],e[l],e[c]))}}let l=[];for(let t=0;t<r;t++)o[t]||l.push(e[t]);return l}function Or(e,t,n=!0){let r=[];for(let i of e)r.push(Dr(i,t,n));return r}function kr(e,t=!1){let n=e.length,r=0;if(!t){for(;r<n-1&&I.isCollinear(e[n-1],e[r],e[r+1]);)r++;for(;r<n-1&&I.isCollinear(e[n-2],e[n-1],e[r]);)n--}if(n-r<3)return!t||n<2||L.equals(e[0],e[1])?[]:e;let i=[],a=e[r];for(i.push(a),r++;r<n-1;r++)I.isCollinear(a,e[r],e[r+1])||(a=e[r],i.push(a));if(t)i.push(e[n-1]);else if(!I.isCollinear(a,e[n-1],i[0]))i.push(e[n-1]);else{for(;i.length>2&&I.isCollinear(i[i.length-1],i[i.length-2],i[0]);)i.pop();i.length<3&&(i.length=0)}return i}function Ar(e,t,n=!1){I.checkPrecision(t);let r=10**t,i=Pn(e,r);return i=kr(i,n),In(i,1/r)}function jr(e,t){return I.pointInPolygon(e,t)}function Mr(e,t,n=2){I.checkPrecision(n);let r=10**n,i=I.maxSafeCoordinateForScale(r);I.checkSafeScaleValue(e.x,i,`pointInPolygonD`),I.checkSafeScaleValue(e.y,i,`pointInPolygonD`);let a=L.fromPointD(fe.scale(e,r)),o=Pn(t,r);return I.pointInPolygon(a,o)}function Nr(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:Math.round(e.x+t),y:e.y}];for(let l=1;l<r;++l){c.push({x:Math.round(e.x+t*o),y:Math.round(e.y+n*s)});let r=o*a-s*i;s=s*a+o*i,o=r}return c}function Pr(e,t,n=0,r=0){if(t<=0)return[];n<=0&&(n=t),r<=2&&(r=Math.ceil(Math.PI*Math.sqrt((t+n)/2)));let i=Math.sin(2*Math.PI/r),a=Math.cos(2*Math.PI/r),o=a,s=i,c=[{x:e.x+t,y:e.y}];for(let l=1;l<r;++l){c.push({x:e.x+t*o,y:e.y+n*s});let r=o*a-s*i;s=s*a+o*i,o=r}return c}function Fr(e,t=!0){return new Wt(t).execute(e)}function Ir(e,t,n=!0){let r;r=t<=0?1:t>8?10**8:10**t;let i=Fn(e,r),{result:a,solution:o}=new Wt(n).execute(i),s;return s=a===Rt.success?Nn(o,1/r):[],{result:a,solution:s}}const Lr={invalidRect64:qt,invalidRectD:Jt,intersect:Yt,intersectD:Xt,union:Zt,unionD:Qt,difference:$t,differenceD:en,xor:tn,xorD:nn,booleanOp:rn,booleanOpWithPolyTree:an,booleanOpD:on,booleanOpDWithPolyTree:sn,inflatePaths:cn,inflatePathsD:ln,rectClip:un,rectClipLines:dn,minkowskiSum:fn,minkowskiSumD:pn,minkowskiDiff:mn,minkowskiDiffD:hn,area:gn,areaPaths:_n,areaD:vn,areaPathsD:yn,isPositive:bn,isPositiveD:xn,path64ToString:Sn,paths64ToString:Cn,pathDToString:wn,pathsDToString:Tn,offsetPath:En,scalePoint64:Dn,scalePointD:On,scaleRect:kn,scalePath:An,scalePaths:jn,scalePathD:Mn,scalePathsD:Nn,scalePath64:Pn,scalePaths64:Fn,scalePathDFromInt:In,scalePathsDFromInt:Ln,path64FromD:Rn,paths64FromD:zn,pathsD:Bn,pathD:Vn,translatePath:Hn,translatePaths:Un,translatePathD:Wn,translatePathsD:Gn,reversePath:Kn,reversePathD:qn,reversePaths:Jn,reversePathsD:Yn,getBounds:Xn,getBoundsPaths:Zn,getBoundsD:Qn,getBoundsPathsD:$n,makePath:er,makePathD:tr,sqr:nr,distanceSqr:rr,midPoint:ir,midPointD:ar,inflateRect:or,inflateRectD:sr,pointsNearEqual:cr,stripNearDuplicates:lr,stripDuplicates:ur,polyTreeToPaths64:fr,addPolyNodeToPathsD:pr,polyTreeToPathsD:mr,perpendicDistFromLineSqrd:hr,perpendicDistFromLineSqrd64:gr,ramerDouglasPeucker:vr,ramerDouglasPeuckerPaths:yr,ramerDouglasPeuckerD:xr,ramerDouglasPeuckerPathsD:Sr,simplifyPath:Tr,simplifyPaths:Er,simplifyPathD:Dr,simplifyPathsD:Or,trimCollinear:kr,trimCollinearD:Ar,pointInPolygon:jr,pointInPolygonD:Mr,ellipse:Nr,ellipseD:Pr,triangulate:Fr,triangulateD:Ir};export{Me as Active,n as ClipType,Gt as Clipper,Ve as Clipper64,Be as ClipperBase,He as ClipperD,Ne as ClipperEngine,Ke as ClipperOffset,Wt as Delaunay,B as EndType,i as FillRule,je as HorzJoin,Oe as HorzPosition,Ae as HorzSegment,I as InternalClipper,ge as InvalidRect64,_e as InvalidRectD,We as JoinType,De as JoinWith,Ce as LocalMinima,nt as Minkowski,Ee as OutPt,qe as OutPt2,ke as OutRec,r as PathType,me as PathUtils,he as PathsUtils,L as Point64Utils,fe as PointDUtils,a as PointInPolygonResult,Ie as PolyPath64,Fe as PolyPathBase,Le as PolyPathD,Re as PolyTree64,ze as PolyTreeD,R as Rect64Utils,Je as RectClip64,Ye as RectClipLines64,pe as RectDUtils,Pe as ReuseableDataContainer64,Rt as TriangulateResult,Se as Vertex,z as VertexFlags,gn as area,vn as areaD,_n as areaPaths,yn as areaPathsD,rn as booleanOp,on as booleanOpD,sn as booleanOpDWithPolyTree,an as booleanOpWithPolyTree,Te as createIntersectNode,we as createLocalMinima,$t as difference,en as differenceD,Nr as ellipse,Pr as ellipseD,Xn as getBounds,Qn as getBoundsD,Zn as getBoundsPaths,$n as getBoundsPathsD,cn as inflatePaths,ln as inflatePathsD,Yt as intersect,Xt as intersectD,bn as isPositive,xn as isPositiveD,er as makePath,tr as makePathD,mn as minkowskiDiff,hn as minkowskiDiffD,fn as minkowskiSum,pn as minkowskiSumD,jr as pointInPolygon,Mr as pointInPolygonD,fr as polyTreeToPaths64,mr as polyTreeToPathsD,vr as ramerDouglasPeucker,xr as ramerDouglasPeuckerD,yr as ramerDouglasPeuckerPaths,Sr as ramerDouglasPeuckerPathsD,un as rectClip,dn as rectClipLines,Kn as reversePath,qn as reversePathD,Jn as reversePaths,Yn as reversePathsD,Pn as scalePath64,Mn as scalePathD,Fn as scalePaths64,Nn as scalePathsD,Tr as simplifyPath,Dr as simplifyPathD,Er as simplifyPaths,Or as simplifyPathsD,ur as stripDuplicates,Hn as translatePath,Wn as translatePathD,Un as translatePaths,Gn as translatePathsD,Fr as triangulate,Ir as triangulateD,kr as trimCollinear,Ar as trimCollinearD,Zt as union,Qt as unionD,tn as xor,nn as xorD};
7
7
  //# sourceMappingURL=clipper2.min.mjs.map