2 lines
7.7 KiB
JavaScript
Raw Normal View History

2026-05-31 13:21:13 +02:00
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).Delaunator=s()}(this,function(){"use strict";const t=11102230246251565e-32,s=134217729,i=(3+8*t)*t;function e(t,s,i,e,n){let h,r,l,o,a=s[0],f=e[0],c=0,u=0;f>a==f>-a?(h=a,a=s[++c]):(h=f,f=e[++u]);let _=0;if(c<t&&u<i)for(f>a==f>-a?(r=a+h,l=h-(r-a),a=s[++c]):(r=f+h,l=h-(r-f),f=e[++u]),h=r,0!==l&&(n[_++]=l);c<t&&u<i;)f>a==f>-a?(r=h+a,o=r-h,l=h-(r-o)+(a-o),a=s[++c]):(r=h+f,o=r-h,l=h-(r-o)+(f-o),f=e[++u]),h=r,0!==l&&(n[_++]=l);for(;c<t;)r=h+a,o=r-h,l=h-(r-o)+(a-o),a=s[++c],h=r,0!==l&&(n[_++]=l);for(;u<i;)r=h+f,o=r-h,l=h-(r-o)+(f-o),f=e[++u],h=r,0!==l&&(n[_++]=l);return 0===h&&0!==_||(n[_++]=h),_}function n(t){return new Float64Array(t)}const h=n(4),r=n(8),l=n(12),o=n(16),a=n(4);function f(t,n,f,c,u,_){const d=(n-_)*(f-u),g=(t-u)*(c-_),y=d-g,w=Math.abs(d+g);return Math.abs(y)>=33306690738754716e-32*w?y:-function(t,n,f,c,u,_,d){let g,y,w,b,A,k,x,M,S,p,T,z,U,m,K,L,v,F;const I=t-u,P=f-u,E=n-_,H=c-_;m=I*H,k=s*I,x=k-(k-I),M=I-x,k=s*H,S=k-(k-H),p=H-S,K=M*p-(m-x*S-M*S-x*p),L=E*P,k=s*E,x=k-(k-E),M=E-x,k=s*P,S=k-(k-P),p=P-S,v=M*p-(L-x*S-M*S-x*p),T=K-v,A=K-T,h[0]=K-(T+A)+(A-v),z=m+T,A=z-m,U=m-(z-A)+(T-A),T=U-L,A=U-T,h[1]=U-(T+A)+(A-L),F=z+T,A=F-z,h[2]=z-(F-A)+(T-A),h[3]=F;let N=function(t,s){let i=s[0];for(let e=1;e<t;e++)i+=s[e];return i}(4,h),j=22204460492503146e-32*d;if(N>=j||-N>=j)return N;if(A=t-I,g=t-(I+A)+(A-u),A=f-P,w=f-(P+A)+(A-u),A=n-E,y=n-(E+A)+(A-_),A=c-H,b=c-(H+A)+(A-_),0===g&&0===y&&0===w&&0===b)return N;if(j=11093356479670487e-47*d+i*Math.abs(N),N+=I*b+H*g-(E*w+P*y),N>=j||-N>=j)return N;m=g*H,k=s*g,x=k-(k-g),M=g-x,k=s*H,S=k-(k-H),p=H-S,K=M*p-(m-x*S-M*S-x*p),L=y*P,k=s*y,x=k-(k-y),M=y-x,k=s*P,S=k-(k-P),p=P-S,v=M*p-(L-x*S-M*S-x*p),T=K-v,A=K-T,a[0]=K-(T+A)+(A-v),z=m+T,A=z-m,U=m-(z-A)+(T-A),T=U-L,A=U-T,a[1]=U-(T+A)+(A-L),F=z+T,A=F-z,a[2]=z-(F-A)+(T-A),a[3]=F;const q=e(4,h,4,a,r);m=I*b,k=s*I,x=k-(k-I),M=I-x,k=s*b,S=k-(k-b),p=b-S,K=M*p-(m-x*S-M*S-x*p),L=E*w,k=s*E,x=k-(k-E),M=E-x,k=s*w,S=k-(k-w),p=w-S,v=M*p-(L-x*S-M*S-x*p),T=K-v,A=K-T,a[0]=K-(T+A)+(A-v),z=m+T,A=z-m,U=m-(z-A)+(T-A),T=U-L,A=U-T,a[1]=U-(T+A)+(A-L),F=z+T,A=F-z,a[2]=z-(F-A)+(T-A),a[3]=F;const D=e(q,r,4,a,l);m=g*b,k=s*g,x=k-(k-g),M=g-x,k=s*b,S=k-(k-b),p=b-S,K=M*p-(m-x*S-M*S-x*p),L=y*w,k=s*y,x=k-(k-y),M=y-x,k=s*w,S=k-(k-w),p=w-S,v=M*p-(L-x*S-M*S-x*p),T=K-v,A=K-T,a[0]=K-(T+A)+(A-v),z=m+T,A=z-m,U=m-(z-A)+(T-A),T=U-L,A=U-T,a[1]=U-(T+A)+(A-L),F=z+T,A=F-z,a[2]=z-(F-A)+(T-A),a[3]=F;const B=e(D,l,4,a,o);return o[B-1]}(t,n,f,c,u,_,w)}const c=Math.pow(2,-52),u=new Uint32Array(512);class _{static from(t,s=A,i=k){const e=t.length,n=new Float64Array(2*e);for(let h=0;h<e;h++){const e=t[h];n[2*h]=s(e),n[2*h+1]=i(e)}return new _(n)}constructor(t){const s=t.length>>1;if(s>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const i=Math.max(2*s-5,0);this._triangles=new Uint32Array(3*i),this._halfedges=new Int32Array(3*i),this._hashSize=Math.ceil(Math.sqrt(s)),this._hullPrev=new Uint32Array(s),this._hullNext=new Uint32Array(s),this._hullTri=new Uint32Array(s),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(s),this._dists=new Float64Array(s),this.trianglesLen=0,this._cx=0,this._cy=0,this._hullStart=0,this.hull=this._triangles,this.triangles=this._triangles,this.halfedges=this._halfedges,this.update()}update(){const{coords:t,_hullPrev:s,_hullNext:i,_hullTri:e,_hullHash:n}=this,h=t.length>>1;let r=1/0,l=1/0,o=-1/0,a=-1/0;for(let s=0;s<h;s++){const i=t[2*s],e=t[2*s+1];i<r&&(r=i),e<l&&(l=e),i>o&&(o=i),e>a&&(a=e),this._ids[s]=s}const u=(r+o)/2,_=(l+a)/2;let g=0,b=0,A=0;for(let s=0,i=1/0;s<h;s++){const e=d(u,_,t[2*s],t[2*s+1]);e<i&&(g=s,i=e)}const k=t[2*g],x=t[2*g+1];for(let s=0,i=1/0;s<h;s++){if(s===g)continue;const e=d(k,x,t[2*s],t[2*s+1]);e<i&&e>0&&(b=s,i=e)}let M=t[2*b],S=t[2*b+1],p=1/0;for(let s=0;s<h;s++){if(s===g||s===b)continue;const i=y(k,x,M,S,t[2*s],t[2*s+1]);i<p&&(A=s,p=i)}let T=t[2*A],z=t[2*A+1];if(p===1/0){for(let s=0;s<h;s++)this