1 line
6.9 KiB
JavaScript
1 line
6.9 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 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;p<x;p+=n)h=e[p],l=e[p+1],h<i&&(i=h),l<v&&(v=l),h>o&&(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<n;u+=t)f=T(u,e[u],e[u+1],f);else for(u=n-t;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=x<u?x<f?x:f:u<f?u:f,h=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,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=i<v?i<o?i:o:v<o?v:o,p=c<h?c<l?c:l:h<l?h:l,M=i>v?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<f;u++)i=r[u]*t,v=u<f-1?r[u+1]*t:e.length,o=G(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=R(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,h=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<h||l===h&&(n.x>f.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;r<o&&(i++,t=t.nextZ,!!t);r++);for(v=o;i>0||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<n.x||r.x===n.x&&r.y<n.y)&&(n=r),r=r.next;while(r!==e);return n}function F(e,r,n,t,x,u,f,i){return(x-f)*(r-i)>=(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;i<v;i++){var o=r[i]*n,c=i<v-1?r[i+1]*n:e.length;f-=Math.abs(j(e,o,c,n))}var h=0;for(i=0;i<t.length;i+=3){var l=t[i]*n,Z=t[i+1]*n,p=t[i+2]*n;h+=Math.abs((e[l]-e[p])*(e[Z+1]-e[l+1])-(e[l]-e[Z])*(e[p+1]-e[l+1]))}return f===0&&h===0?0:Math.abs((h-f)/f)};function j(e,r,n,t){for(var x=0,u=r,f=n-t;u<n;u+=t)x+=(e[f]-e[u])*(e[u+1]+e[f+1]),f=u;return x}z.flatten=function(e){for(var r=e[0][0].length,n={vertices:[],holes:[],dimensions:r},t=0,x=0;x<e.length;x++){for(var u=0;u<e[x].length;u++)for(var f=0;f<r;f++)n.vertices.push(e[x][u][f]);x>0&&(t+=e[x-1].length,n.holes.push(t))}return n};export{ne as a,ee as c,re as g};
|