var ee=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function ne(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function re(e){if(e.__esModule)return e;var r=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach(function(n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}),r}var B={exports:{}};B.exports=z;B.exports.default=z;function z(e,r,n){n=n||2;var t=r&&r.length,x=t?r[0]*n:e.length,u=G(e,0,x,n,!0),f=[];if(!u||u.next===u.prev)return f;var i,v,o,c,h,l,Z;if(t&&(u=Q(e,r,u,n)),e.length>80*n){i=o=e[0],v=c=e[1];for(var p=n;po&&(o=h),l>c&&(c=l);Z=Math.max(o-i,c-v),Z=Z!==0?32767/Z:0}return L(u,f,n,i,v,Z,0),f}function G(e,r,n,t,x){var u,f;if(x===j(e,r,n,t)>0)for(u=r;u=r;u-=t)f=T(u,e[u],e[u+1],f);return f&&E(f,f.next)&&(H(f),f=f.next),f}function w(e,r){if(!e)return e;r||(r=e);var n=e,t;do if(t=!1,!n.steiner&&(E(n,n.next)||g(n.prev,n,n.next)===0)){if(H(n),n=r=n.prev,n===n.next)break;t=!0}else n=n.next;while(t||n!==r);return r}function L(e,r,n,t,x,u,f){if(!!e){!f&&u&&X(e,t,x,u);for(var i=e,v,o;e.prev!==e.next;){if(v=e.prev,o=e.next,u?$(e,t,x,u):V(e)){r.push(v.i/n|0),r.push(e.i/n|0),r.push(o.i/n|0),H(e),e=o.next,i=o.next;continue}if(e=o,e===i){f?f===1?(e=J(w(e),r,n),L(e,r,n,t,x,u,2)):f===2&&K(e,r,n,t,x,u):L(w(e),r,n,t,x,u,1);break}}}}function V(e){var r=e.prev,n=e,t=e.next;if(g(r,n,t)>=0)return!1;for(var x=r.x,u=n.x,f=t.x,i=r.y,v=n.y,o=t.y,c=xu?x>f?x:f:u>f?u:f,Z=i>v?i>o?i:o:v>o?v:o,p=t.next;p!==r;){if(p.x>=c&&p.x<=l&&p.y>=h&&p.y<=Z&&F(x,i,u,v,f,o,p.x,p.y)&&g(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function $(e,r,n,t){var x=e.prev,u=e,f=e.next;if(g(x,u,f)>=0)return!1;for(var i=x.x,v=u.x,o=f.x,c=x.y,h=u.y,l=f.y,Z=iv?i>o?i:o:v>o?v:o,O=c>h?c>l?c:l:h>l?h:l,C=A(Z,p,r,n,t),D=A(M,O,r,n,t),s=e.prevZ,y=e.nextZ;s&&s.z>=C&&y&&y.z<=D;){if(s.x>=Z&&s.x<=M&&s.y>=p&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,h,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0||(s=s.prevZ,y.x>=Z&&y.x<=M&&y.y>=p&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,h,o,l,y.x,y.y)&&g(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;s&&s.z>=C;){if(s.x>=Z&&s.x<=M&&s.y>=p&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,h,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0)return!1;s=s.prevZ}for(;y&&y.z<=D;){if(y.x>=Z&&y.x<=M&&y.y>=p&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,h,o,l,y.x,y.y)&&g(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function J(e,r,n){var t=e;do{var x=t.prev,u=t.next.next;!E(x,u)&&N(x,t,t.next,u)&&P(x,u)&&P(u,x)&&(r.push(x.i/n|0),r.push(t.i/n|0),r.push(u.i/n|0),H(t),H(t.next),t=e=u),t=t.next}while(t!==e);return w(t)}function K(e,r,n,t,x,u){var f=e;do{for(var i=f.next.next;i!==f.prev;){if(f.i!==i.i&&q(f,i)){var v=R(f,i);f=w(f,f.next),v=w(v,v.next),L(f,r,n,t,x,u,0),L(v,r,n,t,x,u,0);return}i=i.next}f=f.next}while(f!==e)}function Q(e,r,n,t){var x=[],u,f,i,v,o;for(u=0,f=r.length;u=n.next.y&&n.next.y!==n.y){var i=n.x+(x-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(i<=t&&i>u&&(u=i,f=n.x=n.x&&n.x>=o&&t!==n.x&&F(xf.x||n.x===f.x&&S(f,n)))&&(f=n,h=l)),n=n.next;while(n!==v);return f}function S(e,r){return g(e.prev,e,r.prev)<0&&g(r.next,e,e.next)<0}function X(e,r,n,t){var x=e;do x.z===0&&(x.z=A(x.x,x.y,r,n,t)),x.prevZ=x.prev,x.nextZ=x.next,x=x.next;while(x!==e);x.prevZ.nextZ=null,x.prevZ=null,Y(x)}function Y(e){var r,n,t,x,u,f,i,v,o=1;do{for(n=e,e=null,u=null,f=0;n;){for(f++,t=n,i=0,r=0;r0||v>0&&t;)i!==0&&(v===0||!t||n.z<=t.z)?(x=n,n=n.nextZ,i--):(x=t,t=t.nextZ,v--),u?u.nextZ=x:e=x,x.prevZ=u,u=x;n=t}u.nextZ=null,o*=2}while(f>1);return e}function A(e,r,n,t,x){return e=(e-n)*x|0,r=(r-t)*x|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e|r<<1}function b(e){var r=e,n=e;do(r.x=(e-f)*(u-i)&&(e-f)*(t-i)>=(n-f)*(r-i)&&(n-f)*(u-i)>=(x-f)*(t-i)}function q(e,r){return e.next.i!==r.i&&e.prev.i!==r.i&&!m(e,r)&&(P(e,r)&&P(r,e)&&d(e,r)&&(g(e.prev,e,r.prev)||g(e,r.prev,r))||E(e,r)&&g(e.prev,e,e.next)>0&&g(r.prev,r,r.next)>0)}function g(e,r,n){return(r.y-e.y)*(n.x-r.x)-(r.x-e.x)*(n.y-r.y)}function E(e,r){return e.x===r.x&&e.y===r.y}function N(e,r,n,t){var x=k(g(e,r,n)),u=k(g(e,r,t)),f=k(g(n,t,e)),i=k(g(n,t,r));return!!(x!==u&&f!==i||x===0&&_(e,n,r)||u===0&&_(e,t,r)||f===0&&_(n,e,t)||i===0&&_(n,r,t))}function _(e,r,n){return r.x<=Math.max(e.x,n.x)&&r.x>=Math.min(e.x,n.x)&&r.y<=Math.max(e.y,n.y)&&r.y>=Math.min(e.y,n.y)}function k(e){return e>0?1:e<0?-1:0}function m(e,r){var n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==r.i&&n.next.i!==r.i&&N(n,n.next,e,r))return!0;n=n.next}while(n!==e);return!1}function P(e,r){return g(e.prev,e,e.next)<0?g(e,r,e.next)>=0&&g(e,e.prev,r)>=0:g(e,r,e.prev)<0||g(e,e.next,r)<0}function d(e,r){var n=e,t=!1,x=(e.x+r.x)/2,u=(e.y+r.y)/2;do n.y>u!=n.next.y>u&&n.next.y!==n.y&&x<(n.next.x-n.x)*(u-n.y)/(n.next.y-n.y)+n.x&&(t=!t),n=n.next;while(n!==e);return t}function R(e,r){var n=new a(e.i,e.x,e.y),t=new a(r.i,r.x,r.y),x=e.next,u=r.prev;return e.next=r,r.prev=e,n.next=x,x.prev=n,t.next=n,n.prev=t,u.next=t,t.prev=u,t}function T(e,r,n,t){var x=new a(e,r,n);return t?(x.next=t.next,x.prev=t,t.next.prev=x,t.next=x):(x.prev=x,x.next=x),x}function H(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function a(e,r,n){this.i=e,this.x=r,this.y=n,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}z.deviation=function(e,r,n,t){var x=r&&r.length,u=x?r[0]*n:e.length,f=Math.abs(j(e,0,u,n));if(x)for(var i=0,v=r.length;i0&&(t+=e[x-1].length,n.holes.push(t))}return n};export{ne as a,ee as c,re as g};