2 lines
7 KiB
JavaScript
2 lines
7 KiB
JavaScript
|
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 C={exports:{}};C.exports=k;C.exports.default=k;function k(e,r,n){n=n||2;var t=r&&r.length,x=t?r[0]*n:e.length,u=B(e,0,x,n,!0),f=[];if(!u||u.next===u.prev)return f;var i,v,o,c,p,l,Z;if(t&&(u=Q(e,r,u,n)),e.length>80*n){i=o=e[0],v=c=e[1];for(var h=n;h<x;h+=n)p=e[h],l=e[h+1],p<i&&(i=p),l<v&&(v=l),p>o&&(o=p),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 B(e,r,n,t,x){var u,f;if(x===j(e,r,n,t)>0)for(u=r;u<n;u+=t)f=$(u,e[u],e[u+1],f);else for(u=n-t;u>=r;u-=t)f=$(u,e[u],e[u+1],f);return f&&z(f,f.next)&&(a(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&&(z(n,n.next)||g(n.prev,n,n.next)===0)){if(a(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?V(e,t,x,u):R(e)){r.push(v.i/n|0),r.push(e.i/n|0),r.push(o.i/n|0),a(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 R(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=x<u?x<f?x:f:u<f?u:f,p=i<v?i<o?i:o:v<o?v:o,l=x>u?x>f?x:f:u>f?u:f,Z=i>v?i>o?i:o:v>o?v:o,h=t.next;h!==r;){if(h.x>=c&&h.x<=l&&h.y>=p&&h.y<=Z&&F(x,i,u,v,f,o,h.x,h.y)&&g(h.prev,h,h.next)>=0)return!1;h=h.next}return!0}function V(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,p=u.y,l=f.y,Z=i<v?i<o?i:o:v<o?v:o,h=c<p?c<l?c:l:p<l?p:l,M=i>v?i>o?i:o:v>o?v:o,O=c>p?c>l?c:l:p>l?p:l,D=E(Z,h,r,n,t),T=E(M,O,r,n,t),s=e.prevZ,y=e.nextZ;s&&s.z>=D&&y&&y.z<=T;){if(s.x>=Z&&s.x<=M&&s.y>=h&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,p,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0||(s=s.prevZ,y.x>=Z&&y.x<=M&&y.y>=h&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,p,o,l,y.x,y.y)&&g(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;s&&s.z>=D;){if(s.x>=Z&&s.x<=M&&s.y>=h&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,p,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0)return!1;s=s.prevZ}for(;y&&y.z<=T;){if(y.x>=Z&&y.x<=M&&y.y>=h&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,p,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;!z(x,u)&&G(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),a(t),a(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=N(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<f;u++)i=r[u]*t,v=u<f-1?r[u+1]*t:e.length,o=B(e,i,v,t,!1),o===o.next&&(o.steiner=!0),x.push(b(o));for(x.sort(U),u=0;u<x.length;u++)n=W(x[u],n);return n}function U(e,r){return e.x-r.x}function W(e,r){var n=I(e,r);if(!n)return r;var t=N(n,e);return w(t,t.next),w(n,n.next)}function I(e,r){var n=r,t=e.x,x=e.y,u=-1/0,f;do{if(x<=n.y&&x>=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.next.x?n:n.next,i===t))return f}n=n.next}while(n!==r);if(!f)return null;var v=f,o=f.x,c=f.y,p=1/0,l;n=f;do t>=n.x&&n.x>=o&&t!==n.x&&F(x<c?t:u,x,o,c,x<c?u:t,x,n.x,n.y)&&(l=Math.abs(x-n.y)/(t-n.x),P(n,e)&&(l<p||l===p&&(n.x>f.x||n.x===f.x&&S(f,n)))&&(f=n,p=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=E(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
|