You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
9.1 KiB
2 lines
9.1 KiB
5 years ago
|
// https://d3js.org/d3-voronoi/ Version 1.1.2. Copyright 2017 Mike Bostock.
|
||
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.d3=e.d3||{})}(this,function(e){"use strict";function t(e){return e[0]}function n(e){return e[1]}function r(){this._=null}function i(e){e.U=e.C=e.L=e.R=e.P=e.N=null}function f(e,t){var n=t,r=t.R,i=n.U;i?i.L===n?i.L=r:i.R=r:e._=r,r.U=i,n.U=r,n.R=r.L,n.R&&(n.R.U=n),r.L=n}function u(e,t){var n=t,r=t.L,i=n.U;i?i.L===n?i.L=r:i.R=r:e._=r,r.U=i,n.U=r,n.L=r.R,n.L&&(n.L.U=n),r.R=n}function s(e){for(;e.L;)e=e.L;return e}function l(e,t,n,r){var i=[null,null],f=D.push(i)-1;return i.left=e,i.right=t,n&&o(i,e,t,n),r&&o(i,t,e,r),O[e.index].halfedges.push(f),O[t.index].halfedges.push(f),i}function a(e,t,n){var r=[t,n];return r.left=e,r}function o(e,t,n,r){e[0]||e[1]?e.left===n?e[1]=r:e[0]=r:(e[0]=r,e.left=t,e.right=n)}function h(e,t,n,r,i){var f,u=e[0],s=e[1],l=u[0],a=u[1],o=s[0],h=s[1],c=0,d=1,v=o-l,g=h-a;if(f=t-l,v||!(f>0)){if(f/=v,v<0){if(f<c)return;f<d&&(d=f)}else if(v>0){if(f>d)return;f>c&&(c=f)}if(f=r-l,v||!(f<0)){if(f/=v,v<0){if(f>d)return;f>c&&(c=f)}else if(v>0){if(f<c)return;f<d&&(d=f)}if(f=n-a,g||!(f>0)){if(f/=g,g<0){if(f<c)return;f<d&&(d=f)}else if(g>0){if(f>d)return;f>c&&(c=f)}if(f=i-a,g||!(f<0)){if(f/=g,g<0){if(f>d)return;f>c&&(c=f)}else if(g>0){if(f<c)return;f<d&&(d=f)}return!(c>0||d<1)||(c>0&&(e[0]=[l+c*v,a+c*g]),d<1&&(e[1]=[l+d*v,a+d*g]),!0)}}}}}function c(e,t,n,r,i){var f=e[1];if(f)return!0;var u,s,l=e[0],a=e.left,o=e.right,h=a[0],c=a[1],d=o[0],v=o[1],g=(h+d)/2,C=(c+v)/2;if(v===c){if(g<t||g>=r)return;if(h>d){if(l){if(l[1]>=i)return}else l=[g,n];f=[g,i]}else{if(l){if(l[1]<n)return}else l=[g,i];f=[g,n]}}else if(u=(h-d)/(v-c),s=C-u*g,u<-1||u>1)if(h>d){if(l){if(l[1]>=i)return}else l=[(n-s)/u,n];f=[(i-s)/u,i]}else{if(l){if(l[1]<n)return}else l=[(i-s)/u,i];f=[(n-s)/u,n]}else if(c<v){if(l){if(l[0]>=r)return}else l=[t,u*t+s];f=[r,u*r+s]}else{if(l){if(l[0]<t)return}else l=[r,u*r+s];f=[t,u*t+s]}return e[0]=l,e[1]=f,!0}function d(e,t,n,r){for(var i,f=D.length;f--;)c(i=D[f],e,t,n,r)&&h(i,e,t,n,r)&&(Math.abs(i[0][0]-i[1][0])>H||Math.abs(i[0][1]-i[1][1])>H)||delete D[f]}function v(e){return O[e.index]={site:e,halfedges:[]}}function g(e,t){var n=e.site,r=t.left,i=t.right;return n===i&&(i=r,r=n),i?Math.atan2(i[1]-r[1],i[0]-r[0]):(n===r?(r=t[1],i=t[0]):(r=t[0],i=t[1]),Math.atan2(r[0]-i[0],i[1]-r[1]))}function C(e,t){return t[+(t.left!==e.site)]}function p(e,t){return t[+(t.left===e.site)]}function L(){for(var e,t,n,r,i=0,f=O.length;i<f;++i)if((e=O[i])&&(r=(t=e.halfedges).length)){var u=new Array(r),s=new Array(r);for(n=0;n<r;++n)u[n]=n,s[n]=g(e,D[t[n]]);for(u.sort(function(e,t){return s[t]-s[e]}),n=0;n<r;++n)s[n]=t[u[n]];for(n=0;n<r;++n)t[n]=s[n]}}function R(e,t,n,r){var i,f,u,s,l,o,h,c,d,v,g,L,R=O.length,y=!0;for(i=0;i<R;++i)if(f=O[i]){for(u=f.site,l=f.halfedges,s=l.length;s--;)D[l[s]]||l.splice(s,1);for(s=0,o=l.length;s<o;)v=p(f,D[l[s]]),g=v[0],L=v[1],h=C(f,D[l[++s%o]]),c=h[0],d=h[1],(Math.abs(g-c)>H||Math.abs(L-d)>H)&&(l.splice(s,0,D.push(a(u,v,Math.abs(g-e)<H&&r-L>H?[e,Math.abs(c-e)<H?d:r]:Math.abs(L-r)<H&&n-g>H?[Math.abs(d-r)<H?c:n,r]:Math.abs(g-n)<H&&L-t>H?[n,Math.abs(c-n)<H?d:t]:Math.abs(L-t)<H&&g-e>H?[Math.abs(d-t)<H?c:e,t]:null))-1),++o);o&&(y=!1)}if(y){var b,M,U,x=1/0;for(i=0,y=null;i<R;++i)(f=O[i])&&(u=f.site,b=u[0]-e,M=u[1]-t,(U=b*b+M*M)<x&&(x=U,y=f));if(y){var N=[e,t],P=[e,r],_=[n,r],k=[n,t];y.halfedges.push(D.push(a(u=y.site,N,P))-1,D.push(a(u,P,_))-1,D.push(a(u,_,k))-1,D.push(a(u,k,N))-1)}}for(i=0;i<R;++i)(f=O[i])&&(f.halfedges.length||delete O[i])}function y(){i(this),this.x=this.y=this.arc=this.site=this.cy=null}function b(e){var t=e.P,n=e.N;if(t&&n){var r=t.site,i=e.site,f=n.site;if(r!==f){var u=i[0],s=i[1],l=r[0]-u,a=r[1]-s,o=f[0]-u,h=f[1]-s,c=2*(l*h-a*o);if(!(c>=-I)){var d=l*l+a*a,v=o*o+h*h,g=(h*d-a*v)/c,C=(l*v-o*d)/c,p=F.pop()||new y;p.arc=e,p.site=i,p.x=g+u,p.y=(p.cy=C+s)+Math.sqrt(g*g+C*C),e.circle=p;for(var L=null,R=B._;R;)if(p.y<R.y||p.y===R.y&&p.x<=R.x){if(!R.L){L=R.P;break}R=R.L}else{if(!R.R){L=R;break}R=R.R}B.insert(L,p),L||(E=p)}}}}function M(e){var t=e.circle;t&&(t.P
|