// https://github.com/d3/d3-delaunay v5.2.0 Copyright 2020 Mike Bostock // https://github.com/mapbox/delaunator v4.0.1. Copyright 2019 Mapbox, Inc. !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).d3=t.d3||{})}(this,function(t){"use strict";const i=Math.pow(2,-52),e=new Uint32Array(512);class n{static from(t,i=u,e=_){const s=t.length,h=new Float64Array(2*s);for(let n=0;n>1;if(i>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const e=Math.max(2*i-5,0);this._triangles=new Uint32Array(3*e),this._halfedges=new Int32Array(3*e),this._hashSize=Math.ceil(Math.sqrt(i)),this._hullPrev=new Uint32Array(i),this._hullNext=new Uint32Array(i),this._hullTri=new Uint32Array(i),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(i),this._dists=new Float64Array(i),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:h,_hullHash:r}=this,c=t.length>>1;let u=1/0,_=1/0,f=-1/0,d=-1/0;for(let i=0;if&&(f=e),n>d&&(d=n),this._ids[i]=i}const g=(u+f)/2,y=(_+d)/2;let m,x,p,w=1/0;for(let i=0;i0&&(x=i,w=e)}let T=t[2*x],A=t[2*x+1],M=1/0;for(let i=0;in&&(i[e++]=s,n=this._dists[s])}return this.hull=i.subarray(0,e),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(l(v,b,T,A,k,$)){const t=x,i=T,e=A;x=p,T=k,A=$,p=t,k=i,$=e}const P=function(t,i,e,n,s,h){const l=e-t,r=n-i,o=s-t,a=h-i,c=l*l+r*r,u=o*o+a*a,_=.5/(l*a-r*o);return{x:t+(a*c-r*u)*_,y:i+(l*u-o*c)*_}}(v,b,T,A,k,$);this._cx=P.x,this._cy=P.y;for(let i=0;i0&&Math.abs(u-s)<=i&&Math.abs(_-o)<=i)continue;if(s=u,o=_,c===m||c===x||c===p)continue;let f=0;for(let t=0,i=this._hashKey(u,_);t0?3-e:1+e)/4}(t-this._cx,i-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:i,_halfedges:n,coords:s}=this;let h=0,l=0;for(;;){const o=n[t],a=t-t%3;if(l=a+(t+2)%3,-1===o){if(0===h)break;t=e[--h];continue}const c=o-o%3,u=a+(t+1)%3,_=c+(o+2)%3,f=i[l],d=i[t],g=i[u],y=i[_];if(r(s[2*f],s[2*f+1],s[2*d],s[2*d+1],s[2*g],s[2*g+1],s[2*y],s[2*y+1])){i[t]=y,i[o]=f;const s=n[_];if(-1===s){let i=this._hullStart;do{if(this._hullTri[i]===_){this._hullTri[i]=t;break}i=this._hullPrev[i]}while(i!==this._hullStart)}this._link(t,s),this._link(o,n[l]),this._link(l,_);const r=c+(o+1)%3;h=33306690738754716e-32*Math.abs(l+r)?l-r:0}function l(t,i,e,n,s,l){return(h(s,l,t,i,e,n)||h(t,i,e,n,s,l)||h(e,n,s,l,t,i))<0}function r(t,i,e,n,s,h,l,r){const o=t-l,a=i-r,c=e-l,u=n-r,_=s-l,f=h-r,d=c*c+u*u,g=_*_+f*f;return o*(u*g-d*f)-a*(c*g-d*_)+(o*o+a*a)*(c*f-u*_)<0}function o(t,i,e,n,s,h){const l=e-t,r=n-i,o=s-t,a=h-i,c=l*l+r*r,u=o*o+a*a,_=.5/(l*a-r*o),f=(a*c-r*u)*_,d=(l*u-o*c)*_;return f*f+d*d}function a(t,i,e,n){if(n-e<=20)for(let s=e+1;s<=n;s++){const n=t[s],h=i[n];let l=s-1;for(;l>=e&&i[t[l]]>h;)t[l+1]=t[l--];t[l+1]=n}else{let s=e+1,h=n;c(t,e+n>>1,s),i[t[e]]>i[t[n]]&&c(t,e,n),i[t[s]]>i[t[n]]&&c(t,s,n),i[t[e]]>i[t[s]]&&c(t,e,s);const l=t[s],r=i[l];for(;;){do{s++}while(i[t[s]]r);if(h=h-e?(a(t,i,s,n),a(t,i,e,h-1)):(a(t,i,e,h-1),a(t,i,s,n))}}function c(t,i,e){const n=t[i];t[i]=t[e],t[e]=n}function u(t){return t[0]}function _(t){return t[1]}const f=1e-6;class d{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+i}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,i){this._+=`L${this._x1=+t},${this._y1=+i}`}arc(t,i,e){const n=(t=+t)+(e=+e),s=i=+i;if(e<0)throw new Error("negative radius");null===this._x1?this._+=`M${n},${s}`:(Math.abs(this._x1-n)>f||Math.abs(this._y1-s)>f)&&(this._+="L"+n+","+s),e&&(this._+=`A${e},${e},0,1,1,${t-e},${i}A${e},${e},0,1,1,${this._x1=n},${this._y1=s}`)}rect(t,i,e,n){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+i}h${+e}v${+n}h${-e}Z`}value(){return this._||null}}class g{constructor(){this._=[]}moveTo(t,i){this._.push([t,i])}closePath(){this._.push(this._[0].slice())}lineTo(t,i){this._.push([t,i])}value(){return this._.length?this._:null}}class y{constructor(t,[i,e,n,s]=[0,0,960,500]){if(!((n=+n)>=(i=+i)&&(s=+s)>=(e=+e)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=n,this.xmin=i,this.ymax=s,this.ymin=e,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:i,triangles:e},vectors:n}=this,s=this.circumcenters=this._circumcenters.subarray(0,e.length/3*2);for(let i,n,h=0,l=0,r=e.length;h1;)s-=2;for(let t=2;t4)for(let t=0;t0){if(i>=this.ymax)return null;(s=(this.ymax-i)/n)0){if(t>=this.xmax)return null;(s=(this.xmax-t)/e)this.xmax?2:0)|(ithis.ymax?8:0)}}const m=2*Math.PI;function x(t){return t[0]}function p(t){return t[1]}function w(t,i,e){return[t+Math.sin(t+i)*e,i+Math.cos(t-i)*e]}class v{constructor(t){this._delaunator=new n(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,i=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:i,coords:e}=t;for(let t=0;t1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:i.length/2},(t,i)=>i).sort((t,e)=>i[2*t]-i[2*e]||i[2*t+1]-i[2*e+1]);const t=this.collinear[0],e=this.collinear[this.collinear.length-1],s=[i[2*t],i[2*t+1],i[2*e],i[2*e+1]],h=1e-8*Math.sqrt((s[3]-s[1])**2+(s[2]-s[0])**2);for(let t=0,e=i.length/2;t0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=s[0],this.triangles[1]=s[1],this.triangles[2]=s[1],l[s[0]]=1,2===s.length&&(l[s[1]]=0))}voronoi(t){return new y(this,t)}*neighbors(t){const{inedges:i,hull:e,_hullIndex:n,halfedges:s,triangles:h,collinear:l}=this;if(l){const i=l.indexOf(t);return i>0&&(yield l[i-1]),void(i=0&&s!==e&&s!==n;)e=s;return s}_step(t,i,e){const{inedges:n,hull:s,_hullIndex:h,halfedges:l,triangles:r,points:o}=this;if(-1===n[t]||!o.length)return(t+1)%(o.length>>1);let a=t,c=(i-o[2*t])**2+(e-o[2*t+1])**2;const u=n[t];let _=u;do{let n=r[_];const u=(i-o[2*n])**2+(e-o[2*n+1])**2;if(u