d3-geo-voronoi
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,6 +0,6 @@ | ||
// https://github.com/Fil/d3-geo-voronoi Version 0.0.3. Copyright 2017 Philippe Riviere. | ||
// https://github.com/Fil/d3-geo-voronoi Version 0.0.4. Copyright 2017 Philippe Riviere. | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-collection'), require('d3-geo'), require('d3-voronoi')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-geo', 'd3-voronoi'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3)); | ||
(factory((global.d3 = {}),global.d3,global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Array,d3Collection,d3Geo,d3Voronoi) { 'use strict'; | ||
@@ -7,0 +7,0 @@ |
@@ -1,2 +0,1 @@ | ||
// https://github.com/Fil/d3-geo-voronoi Version 0.0.3. Copyright 2017 Philippe Riviere. | ||
(function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-array"),require("d3-collection"),require("d3-geo"),require("d3-voronoi")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-collection","d3-geo","d3-voronoi"],e):e(r.d3=r.d3||{},r.d3,r.d3,r.d3,r.d3)})(this,function(r,e,o,n,t){"use strict";function s(r,e){for(var o=0,n=0;n<3;n++)o+=r[n]*e[n];return o}function i(r,e){for(var o=new Array(3),n=0;n<3;n++){var t=n+1;t>=3&&(t-=3);var s=n+2;s>=3&&(s-=3),o[n]=r[t]*e[s]-r[s]*e[t]}return o}function a(r,e,o){return s(i(r,e),o)}function v(r,e){for(var o=0,n=0,t=0;t<3;t++){var s=e[t]-r[t];o+=s*s;var i=e[t]+r[t];n+=i*i}return Math.sqrt(o)-Math.sqrt(n)}function u(r){for(var e,o=new Array(3),n=0,t=0;t<3;t++){var s=r[t];n+=s*s}e=n>0?1/Math.sqrt(n):0;for(var t=0;t<3;t++)o[t]=e*r[t];return o}function f(r,e,o){return i(r[e],r[o])}function l(r,e,o,n){return a(r[e],r[o],r[n])}function p(r,e,o){return v(r[e],r[o])}function g(){for(var r=new Array(3),e=0;e<3;e++)r[e]=0;return r}function d(r){for(var e=new Array(3),o=0;o<3;o++)e[o]=r[o];return e}function h(r,e){for(var o=0;o<3;o++)r[o]+=e[o]}function c(r,e){for(var o=0;o<3;o++)r[o]*=e}function y(r,e){for(var o=g(),n=0;n<3;n++)o[n]=r[n]-e[n];return o}function _(r){return void 0===r}function b(r,e){if(_(r))return!1;if(_(e))return!1;for(var o=0;o<3;o++)if(r.verts[o]!=e.verts[o])return!1;return!0}function I(r,e){if(_(r))return!1;if(_(e))return!1;for(var o=0;o<2;o++)if(r.verts[o]!=e.verts[o])return!1;return!0}function x(r,e){return e>r?e:r}function w(r,e){this.verts=e,this.edges=new Array(3),this.dirs=new Array(3);for(var o=0;o<3;o++){var n=o+1;n>=3&&(n-=3);var t=o+2;t>=3&&(t-=3),this.dirs[o]=f(r,e[n],e[t])}this.vol=l(r,e[0],e[1],e[2]);for(var o=0;o<3;o++)c(this.dirs[o],1/this.vol);for(var s=g(),o=0;o<3;o++)h(s,this.dirs[o]);this.ccdir=u(s);for(var i=0,o=0;o<3;o++)i+=v(this.ccdir,r[e[o]]);i/=3,this.ccdsq=i}function m(r){this.verts=r,this.polys=new Array(2)}function k(r,e){this.verts=e,this.pdst=p(r,e[0],e[1]),this.direc=u(f(r,e[0],e[1]));var o=g();h(o,r[e[0]]),h(o,r[e[1]]),this.midpnt=u(o)}function V(r,e){for(var o=0;o<r.length;o++)if(e==r[o])return;r.push(e)}function A(r,e){for(var o=0;o<r.length;o++)if(I(r[o],e))return;r.push(e)}function P(r,e){for(var o=[],n=0;n<r.length;n++)for(var t=r[n],s=0;s<e.length;s++){var i=e[s];if(t==i){o.push(t);break}}return o}function q(r,e){for(var o=[],n=0;n<r.length;n++)for(var t=r[n],s=0;s<e.length;s++){var i=e[s];if(I(t,i)){o.push(t);break}}return o}function C(r,e){if(0!=e.length){for(var o=[],n=0;n<r.length;n++){for(var t=r[n],s=!0,i=0;i<e.length;i++){if(e[i]==t){s=!1;break}}s&&o.push(t)}r.splice(0,r.length);for(var a=0;a<o.length;a++)r.push(o[a])}}function O(r,e){if(0!=e.length){for(var o=[],n=0;n<r.length;n++){for(var t=r[n],s=!0,i=0;i<e.length;i++){if(I(t,e[i])){s=!1;break}}s&&o.push(t)}r.splice(0,r.length);for(var a=0;a<o.length;a++)r.push(o[a])}}function M(r,e){for(var o=r.positions,n=o[e],t=r.triangles.length,s=0;s<t;s++){var i=r.triangles[s];if(i.IsPointInside(n)){for(var a=i.edges,v=[],u=0;u<3;u++)v.push(a[u].PolyIndexIn(i));for(var f=Array(3),l=Array(3),u=0;u<3;u++){var p=u+1;p>=3&&(p-=3),f[u]=new w(o,[i.verts[u],i.verts[p],e]),l[u]=new m([i.verts[u],e])}for(var u=0;u<3;u++){var p=u+1;p>=3&&(p-=3),f[u].edges[0]=l[p],f[u].edges[1]=l[u],l[u].polys[0]=f[u],l[p].polys[1]=f[u]}for(var u=0;u<3;u++)for(var g=a[u],d=v[u],h=0;h<3;h++)for(var c=f[h],y=0,_=0;_<2;_++)if(c.IsVertex(g.verts[_])&&y++,2==y){g.polys[d]=c,c.edges[2]=g;break}r.triangles[s]=f[0];for(var u=1;u<3;u++)r.triangles.push(f[u]);for(var u=0;u<3;u++)r.edges.push(l[u]);return!0}}return!1}function j(r){for(var e=r.positions,o=new Array(4),n=0;n<100;n++){for(var t=0,s=0;s<r.edges.length;s++){var i=r.edges[s],a=i.polys;if(!_(a[0])&&!_(a[1])){for(var v=0;v<3;v++){var u=a[0].verts[v];if(!i.IsVertex(u))break}var f=v+1;f>=3&&(f-=3);var l=v+2;l>=3&&(l-=3),o[0]=u,o[1]=a[0].verts[f],o[3]=a[0].verts[l];for(var v=0;v<3;v++){var u=a[1].verts[v];if(!i.IsVertex(u))break}o[2]=u;var p=a[0].IsPointInCircumcircle(e[o[2]]),g=a[1].IsPointInCircumcircle(e[o[0]]);if(p||g){var d=new w(e,[o[0],o[1],o[2]]);if(d.IsVertexOrderCorrect()){var h=new w(e,[o[0],o[2],o[3]]);if(h.IsVertexOrderCorrect()){t++;for(var v=0;v<3;v++){var c=a[0].edges[v];if(!I(c,i)&&c.IsVertex(o[3])){var y=c,b=v;break}}for(var v=0;v<3;v++){var c=a[1].edges[v];if(!I(c,i)&&c.IsVertex(o[1])){var x=c,m=v;break}}var k=y.PolyIndexIn(a[0]),V=x.PolyIndexIn(a[1]);y.polys[k]=a[1],x.polys[V]=a[0],a[0].edges[b]=x,a[1].edges[m]=y,a[0].copy_vert_info(d),a[1].copy_vert_info(h),i.verts=[o[0],o[2]]}}}}}if(0==t)break}}function F(r){for(var e=new Object,o=-1,n=0;n<r.edges.length;n++){var t=r.edges[n];if(_(t.polys[0])){if(_(t.polys[1]))continue;var s=t.polys[1]}else{if(!_(t.polys[1]))continue;var s=t.polys[0]}var i=t.verts[0],a=t.verts[1],v=s.VertexIndexIn(a)-s.VertexIndexIn(i);if(v<0&&(v+=3),1!=v){var u=i;i=a,a=u}e[i]=a,o=i}if(o>=0){for(var f=o,l=[f];;){var p=e[f];if(p==o)break;l.push(p),f=p}r.hull=l}}function D(r){if(1!=r.triangles.length){if(0!=r.triangles.length){for(var e=0;e<r.triangles.length;e++){var o=r.triangles[e];o.index=e,r.vor_positions.push(o.ccdir)}for(var e=0;e<r.edges.length;e++){var n=r.edges[e];if(!_(n.polys[0])&&!_(n.polys[1])){var t=[n.polys[0].index,n.polys[1].index];r.vor_edges.push(t)}}for(var e=0;e<r.indices.length;e++){var s=r.indices[e];r.vor_polygons[s]=new Object;var a=r.vor_polygons[s];a.edges=[],a.triangles=[],a.boundary=[]}for(var e=0;e<r.edges.length;e++)for(var n=r.edges[e],f=0;f<2;f++)r.vor_polygons[n.verts[f]].edges.push(n);for(var e=0;e<r.triangles.length;e++)for(var o=r.triangles[e],f=0;f<3;f++)r.vor_polygons[o.verts[f]].triangles.push(o);for(var e=0;e<r.indices.length;e++){var s=r.indices[e],a=r.vor_polygons[s],l=a.triangles[0],o=l;a.boundary.push(o.index);for(var f=0;f<3;f++){var n=o.edges[f];if(n.IsVertex(s))break}for(var p=n,x=!1;;){var m=n.PolyIndexIn(o);if(o=n.polys[1-m],_(o))break;if(b(o,l)){x=!0;break}a.boundary.push(o.index);for(var f=0;f<3;f++){var k=o.edges[f];if(!I(k,n)&&k.IsVertex(s)){n=k;break}}}if(!x){a.boundary.reverse(),o=l;for(var f=0;f<3&&(n=o.edges[f],I(n,p)||!n.IsVertex(s));f++);for(;;){var m=n.PolyIndexIn(o);if(o=n.polys[1-m],_(o))break;a.boundary.push(o.index);for(var f=0;f<3;f++){var k=o.edges[f];if(!I(k,n)&&k.IsVertex(s)){n=k;break}}}}x||(a.boundary.reverse(),a.boundary.push(-1),a.boundary.reverse(),a.boundary.push(-1))}if(r.hull.length>=3){for(var V=new Array,A=r.positions,C=r.hull.length,f=0;f<C;f++){var s=r.hull[f],O=f+1;O>=C&&(O=0);var M=r.hull[O],j=r.vor_polygons[s].edges,F=r.vor_polygons[M].edges,D=q(j,F),n=D[0],E=n.polys[0].index,S=A[s],z=A[M],L=y(z,S),T=[E,r.vor_positions[E],s,S,M,z,L];V.push(T)}for(;V.length>3;){for(var B=V.length,G=new Array,H=new Array,J=0;J<B;J++)H.push(new Array);for(var J=0;J<B;J++){var K=J+1;K>=B&&(K=0);var N=u(i(V[J][6],V[K][6]));c(N,-1),H[J].push(G.length),H[K].push(G.length),G.push(N)}for(var J=0;J<B;J++){var Q=H[J];if(Q.length>=2){for(var R=new Array,U=0;U<Q.length;U++)R.push(v(G[Q[U]],V[J][1]));for(var W=0,X=R[W],Y=0;Y<R.length;Y++){var Z=R[Y];Z<X&&(W=Y,X=Z)}var $=Q[W]}else if(1==Q.length)var $=Q[0];else var $=-1;H[J]=$}for(var rr=new Array,J=0;J<B;J++){var K=J+1;K>=B&&(K=0);var er=J-1;er<0&&(er=B-1);var or,nr=0,Q=H[J];if(-1!=Q){var tr=H[er];Q==tr?nr=2:(or=H[K],Q==or&&(nr=1))}if(0==nr)rr.push(V[J]);else if(1==nr){var sr=V[J],ir=V[K],N=G[J],ar=sr[0],vr=ir[0],ur=vr!=ar;if(ur){for(var fr=r.vor_positions.length,lr=sr[2],S=sr[3],pr=ir[4],z=ir[5],gr=void 0,dr=void 0,hr=0;hr<B;hr++){for(var cr=v(V[hr][3],N),yr=hr-J;yr<0;)yr+=B;for(;yr>=B;)yr-=B;yr<=2?void 0==gr?gr=cr:cr<gr&&(gr=cr):void 0==dr?dr=cr:cr<dr&&(dr=cr)}ur=gr<dr}if(ur){var L=y(z,S),T=[fr,N,lr,S,pr,z,L];rr.push(T),r.vor_positions.push(N);var _r=sr[4];r.vor_edges.push([ar,fr]),r.vor_edges.push([vr,fr]),r.vor_polygons[_r].boundary.shift();var br=r.vor_polygons[_r].boundary.length;r.vor_polygons[_r].boundary[br-1]=fr,r.vor_polygons[lr].boundary[1]==ar?(r.vor_polygons[lr].boundary.unshift(-1),r.vor_polygons[lr].boundary[1]=fr):(br=r.vor_polygons[lr].boundary.length,r.vor_polygons[lr].boundary[br-2]==ar&&(r.vor_polygons[lr].boundary.push(-1),br=r.vor_polygons[lr].boundary.length,r.vor_polygons[lr].boundary[br-2]=fr)),r.vor_polygons[pr].boundary[1]==vr?(r.vor_polygons[pr].boundary.unshift(-1),r.vor_polygons[pr].boundary[1]=fr):(br=r.vor_polygons[pr].boundary.length,r.vor_polygons[pr].boundary[br-2]==vr&&(r.vor_polygons[pr].boundary.push(-1),br=r.vor_polygons[pr].boundary.length,r.vor_polygons[pr].boundary[br-2]=fr))}else rr.push(sr),rr.push(ir)}}if(rr.length==V.length)break;V=rr}if(2==V.length){if(V[0][0]!=V[1][0]){for(var Ir=[],J=0;J<2;J++){var K=V[J][0];Ir.push(K),K=V[J][2],r.vor_polygons[K].boundary.shift(),r.vor_polygons[K].boundary.pop()}r.vor_edges.push(Ir)}}else if(3==V.length){var xr=V[0][0],wr=V[1][0],mr=V[2][0];if(xr!=wr&&xr!=mr&&wr!=mr){var fr=r.vor_positions.length,kr=V[0][3],Vr=V[1][3],Ar=V[2][3],N=g();h(N,i(kr,Vr)),h(N,i(Vr,Ar)),h(N,i(Ar,kr)),N=u(N),c(N,-1),r.vor_positions.push(N);for(var J=0;J<3;J++){var T=V[J];r.vor_edges.push([T[0],fr]);var s=T[2];r.vor_polygons[s].boundary.shift();var br=r.vor_polygons[s].boundary.length;r.vor_polygons[s].boundary[br-1]=fr}}}}for(var J=0;J<r.vor_polygons.length;J++)a=r.vor_polygons[J],a.boundary.length>=3&&a.boundary[0]>=0&&(o=new w(r.vor_positions,a.boundary.slice(0,3)),o.IsVertexOrderCorrect()||a.boundary.reverse())}else if(2==r.hull.length){var kr=r.positions[r.hull[0]],Vr=r.positions[r.hull[1]],S=g();h(S,kr),h(S,Vr),S=u(S),r.vor_positions.push(S);var z=u(i(kr,Vr));r.vor_positions.push(z);var Pr=d(S);c(Pr,-1),r.vor_positions.push(Pr);var qr=d(z);c(qr,-1),r.vor_positions.push(qr),r.vor_edges.push([0,1,2,3,0]),n=r.edges[0];for(var J=0;J<2;J++){var s=r.hull[J];r.vor_polygons[s]=new Object;var a=r.vor_polygons[s];a.edges=[n],a.triangles=[0],0==J?a.boundary=[0,1,2,3]:1==J&&(a.boundary=[0,3,2,1])}}}else if(3==r.hull.length){var o=r.triangles[0];r.vor_positions.push(o.ccdir);for(var J=0;J<3;J++){var K=J+1;K>=3&&(K=0);var er=J-1;er<0&&(er=2);var Vr=r.positions[r.hull[J]],Ar=r.positions[r.hull[K]],Cr=y(Ar,Vr);r.vor_positions.push(u(i(Cr,o.ccdir))),r.vor_edges.push([0,J+1,4]);var s=r.hull[J];r.vor_polygons[s]=new Object;for(var a=r.vor_polygons[s],Or=r.hull[er],Mr=0;Mr<3;Mr++){var n=r.edges[Mr],jr=P([Or,s],n.verts);if(2==jr.length)break}a.edges=[n],a.triangles=[o],a.boundary=[0,er+1,4,J+1]}var Fr=d(o.ccdir);c(Fr,-1),r.vor_positions.push(Fr)}}function E(r,e){var o=new Object;if(o.positions=r,o.indices=e,o.triangles=[],o.edges=[],o.hull=[],o.vor_positions=[],o.vor_edges=[],o.vor_polygons=new Object,e.length<3)return 2==e.length&&(o.edges.push(new m(e)),o.hull=e),D(o),o;var n=new w(r,e.slice(0,3));n.IsVertexOrderCorrect()||(n=new w(r,[e[0],e[2],e[1]])),o.triangles.push(n);for(var t=new Array(3),s=0;s<3;s++){var i=s+1;i>=3&&(i-=3);var a=e[s],v=e[i],u=[a,v],f=new m(u),l=new k(r,u);l.edge=f,t[s]=l,n.edges[s]=f,f.polys[0]=n,o.edges.push(f)}for(var p=e.slice(0,3),g=t,d=Object,s=0;s<3;s++){var i=s+2;i>=3&&(i-=3);var a=e[s];d[a]=[t[s],t[s+1]]}for(var h=3;h<e.length;h++){var a=e[h];if(!M(o,a)){d[a]=[];for(var c=[],y=[],b=[],I=0;I<p.length;I++){for(var v=p[I],x=new k(r,[a,v]),P=!1,E=0;E<g.length;E++){var S=g[E];if(P=x.intersects(r,S))break}if(!P){var f=new m(x.verts);x.edge=f,A(c,x),A(d[a],x),V(y,a),A(d[v],x),V(y,v)}}V(p,a);for(var I=0;I<g.length;I++){for(var x=g[I],z=[],L=0;L<2;L++){var T=q(d[a],d[x.verts[L]]);0!=T.length&&z.push(T[0])}if(!(z.length<2)){for(var B=-1,L=0;L<2;L++)if(_(x.edge.polys[L])){B=L;break}if(!(B<0)){var G=x.edge.polys[1-B],H=x.verts[0],J=G.VertexIndexIn(H),K=x.verts[1],N=G.VertexIndexIn(K),Q=N-J;if(Q<0&&(Q+=3),1==Q)var R=[a,K,H];else if(2==Q)var R=[a,H,K];var n=new w(r,R);if(n.IsVertexOrderCorrect()){o.triangles.push(n),x.edge.polys[B]=n,n.edges[0]=x.edge,n.edges[1]=z[0].edge,n.edges[2]=z[1].edge,A(b,x);for(var L=0;L<2;L++){var U=z[L];_(U.edge.polys[0])?(U.edge.polys[0]=n,o.edges.push(U.edge)):(U.edge.polys[1]=n,A(b,U))}}}}}for(var I=0;I<c.length;I++)A(g,c[I]);O(g,b);for(var W=[],I=0;I<y.length;I++){var X=y[I];O(d[X],b),0==d[X].length&&W.push(X)}C(p,W)}}return j(o),F(o),D(o),o}function S(r){for(var e=new Array(r.length),o=0;o<e.length;o++)e[o]=o;return E(r,e)}w.prototype.copy_vert_info=function(r){this.verts=r.verts,this.dirs=r.dirs,this.vol=r.vol,this.ccdir=r.ccdir,this.ccdsq=r.ccdsq},w.prototype.IsVertexOrderCorrect=function(){return this.vol>=0},w.prototype.IsPointInside=function(r){for(var e=0;e<3;e++)if(s(r,this.dirs[e])<0)return!1;return!0},w.prototype.IsPointInCircumcircle=function(r){return v(this.ccdir,r)<this.ccdsq},w.prototype.IsVertex=function(r){for(var e=0;e<3;e++)if(r==this.verts[e])return!0;return!1},w.prototype.VertexIndexIn=function(r){for(var e=0;e<3;e++)if(r==this.verts[e])return e;return-1},w.prototype.EdgeIndexIn=function(r){for(var e=0;e<3;e++)if(I(this.edges[e],r))return e;return-1},m.prototype.IsVertex=function(r){for(var e=0;e<2;e++)if(r==this.verts[e])return!0;return!1},m.prototype.VertexIndexIn=function(r){for(var e=0;e<2;e++)if(r==this.verts[e])return e;return-1},m.prototype.PolyIndexIn=function(r){for(var e=0;e<2;e++)if(b(this.polys[e],r))return e;return-1},k.prototype.intersects=function(r,e){for(var o=0;o<2;o++)for(var n=0;n<2;n++)if(this.verts[o]==e.verts[n])return!1;var t=u(i(this.direc,e.direc)),a=s(t,this.midpnt)>0;if(s(t,e.midpnt)>0!=a)return!1;for(var f=[],o=0;o<2;o++){var l=v(t,r[this.verts[o]]);f.push(l)}for(var p=[],o=0;o<2;o++){var l=v(t,r[e.verts[o]]);p.push(l)}var g=x(f[0],f[1]),d=x(p[0],p[1]);if(g<=this.pdst&&d<=e.pdst&&a)return!0;c(t,-1),a=!a;for(var o=0;o<2;o++)f[o]=-f[o],p[o]=-p[o];return g=x(f[0],f[1]),d=x(p[0],p[1]),!!(g<=this.pdst&&d<=e.pdst&&a)};var z=function(){var r=Math.PI/180,s=function(e){var o=e[0]*r,n=e[1]*r,t=Math.cos(n);return[t*Math.cos(o),t*Math.sin(o),Math.sin(n)]},i=function(e){var o=Math.sqrt(e[0]*e[0]+e[1]*e[1]),n=Math.atan2(e[2],o);return[Math.atan2(e[1],e[0])/r,n/r]},a=function(r,e){return e.map(function(e){return i(r[e])})},v=t.voronoi()([]),u=v.DT=null,f=v.sites=[],l=v.pos=[],p=function(r){return"object"==typeof r&&"type"in r?n.geoCentroid(r)[0]:0 in r?r[0]:void 0},g=function(r){return"object"==typeof r&&"type"in r?n.geoCentroid(r)[1]:0 in r?r[1]:void 0},d=function(r){return v._hull=v._polygons=v._links=v._triangles=null,"object"==typeof r&&"FeatureCollection"==r.type&&(r=r.features),f=r.map(function(r,e){return r.index=e,r}),l=r.map(function(r){return[p(r),g(r)]}),u=S(l.map(s)),v};return v.links=d.links=function(r){if(r&&d(r),v._links)return v._links;var t=o.map(),s=u.edges.map(function(r,o){t.set(e.extent(r.verts),o);var s={source:f[r.verts[0]],target:f[r.verts[1]],urquhart:!0,length:n.geoDistance(l[r.verts[0]],l[r.verts[1]])};return{type:"Feature",geometry:{type:"LineString",coordinates:[i(u.positions[r.verts[0]]),i(u.positions[r.verts[1]])]},properties:s}});return u.triangles.forEach(function(r){for(var o,n,i=0,a=0,v=0;v<3;v++){n=e.extent([r.verts[v],r.verts[(v+1)%3]]);var u=t.get(n);a=s[u].properties.length,a>i&&(i=a,o=u)}s[o].properties.urquhart=!1}),v._links={type:"FeatureCollection",features:s}},v.triangles=d.triangles=function(r){if(r&&d(r),v._triangles)return v._triangles;var e=u.triangles.map(function(r){return r.spherical=r.verts.map(function(r){return u.positions[r]}).map(i),r.ccdsq<0&&(r.spherical=r.spherical.reverse(),r.ccdsq*=-1),r}).map(function(r){return{type:"Feature",geometry:{type:"Polygon",coordinates:[r.spherical.concat([r.spherical[0]])]},properties:{sites:r.verts.map(function(r){return f[r]}),area:r.vol,circumcenter:i(r.ccdir)}}});return v._triangles={type:"FeatureCollection",features:e}},v.polygons=d.polygons=function(r){if(r&&d(r),v._polygons)return v._polygons;var e=u.indices.map(function(r,e){var o=u.vor_polygons[u.indices[r]],t={};if(void 0==o)t.type="Sphere";else{var s=a(u.vor_positions,o.boundary.concat([o.boundary[0]])),i={type:"Polygon",coordinates:[[l[r],s[0],s[1],l[r]]]};n.geoArea(i)>2*Math.PI+1e-10&&(s=s.reverse()),t.type="Polygon",t.coordinates=[s]}return{type:"Feature",geometry:t,properties:{site:f[r],sitecoordinates:l[r],neighbours:o.edges.map(function(e){return e.verts.filter(function(e){return e!==r})[0]})}}});return v._polygons={type:"FeatureCollection",features:e}},v.hull=d.hull=function(r){if(r&&d(r),v._hull)return v._hull;if(!u.hull.length)return null;var e=u.hull.reverse();return v._hull={type:"Feature",geometry:{type:"Polygon",coordinates:[e.concat([e[0]]).map(function(r){return l[r]})]},properties:{sites:e.map(function(r){return f[r]})}}},v.find=function(r,e,o){var t,s=v.polygons().features,i=v.find.found||0,a=s[i]||s[i=0],u=n.geoDistance([r,e],a.properties.sitecoordinates);do{a=s[t=i],i=null,a.properties.neighbours.forEach(function(o){var t=n.geoDistance([r,e],s[o].properties.sitecoordinates);if(t<u)return u=t,void(i=o)})}while(null!==i);if(v.find.found=t,!o||u<o*o)return a.properties.site},d.x=function(r){return r?(p=r,d):p},d.y=function(r){return r?(g=r,d):g},d.extent=function(r){return r?d:null},d.size=function(r){return r?d:null},d};r.geoVoronoi=z,Object.defineProperty(r,"__esModule",{value:!0})}); | ||
(function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-array"),require("d3-collection"),require("d3-geo"),require("d3-voronoi")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-collection","d3-geo","d3-voronoi"],e):e(r.d3={},r.d3,r.d3,r.d3,r.d3)})(this,function(r,e,o,n,t){"use strict";function s(r,e){for(var o=0,n=0;n<3;n++)o+=r[n]*e[n];return o}function i(r,e){for(var o=new Array(3),n=0;n<3;n++){var t=n+1;t>=3&&(t-=3);var s=n+2;s>=3&&(s-=3),o[n]=r[t]*e[s]-r[s]*e[t]}return o}function u(r,e,o){return s(i(r,e),o)}function a(r,e){for(var o=0,n=0,t=0;t<3;t++){var s=e[t]-r[t];o+=s*s;var i=e[t]+r[t];n+=i*i}return Math.sqrt(o)-Math.sqrt(n)}function l(r){for(var e,o=new Array(3),n=0,t=0;t<3;t++){var s=r[t];n+=s*s}e=n>0?1/Math.sqrt(n):0;for(t=0;t<3;t++)o[t]=e*r[t];return o}function f(r,e,o){return i(r[e],r[o])}function v(r,e,o,n){return u(r[e],r[o],r[n])}function p(r,e,o){return a(r[e],r[o])}function g(){for(var r=new Array(3),e=0;e<3;e++)r[e]=0;return r}function d(r){for(var e=new Array(3),o=0;o<3;o++)e[o]=r[o];return e}function h(r,e){for(var o=0;o<3;o++)r[o]+=e[o]}function c(r,e){for(var o=0;o<3;o++)r[o]*=e}function y(r,e){for(var o=g(),n=0;n<3;n++)o[n]=r[n]-e[n];return o}function _(r){return void 0===r}function b(r,e){if(_(r))return!1;if(_(e))return!1;for(var o=0;o<3;o++)if(r.verts[o]!=e.verts[o])return!1;return!0}function I(r,e){if(_(r))return!1;if(_(e))return!1;for(var o=0;o<2;o++)if(r.verts[o]!=e.verts[o])return!1;return!0}function x(r,e){return e>r?e:r}function w(r,e){this.verts=e,this.edges=new Array(3),this.dirs=new Array(3);for(s=0;s<3;s++){var o=s+1;o>=3&&(o-=3);var n=s+2;n>=3&&(n-=3),this.dirs[s]=f(r,e[o],e[n])}this.vol=v(r,e[0],e[1],e[2]);for(s=0;s<3;s++)c(this.dirs[s],1/this.vol);for(var t=g(),s=0;s<3;s++)h(t,this.dirs[s]);this.ccdir=l(t);for(var i=0,s=0;s<3;s++)i+=a(this.ccdir,r[e[s]]);i/=3,this.ccdsq=i}function m(r){this.verts=r,this.polys=new Array(2)}function k(r,e){this.verts=e,this.pdst=p(r,e[0],e[1]),this.direc=l(f(r,e[0],e[1]));var o=g();h(o,r[e[0]]),h(o,r[e[1]]),this.midpnt=l(o)}function V(r,e){for(var o=0;o<r.length;o++)if(e==r[o])return;r.push(e)}function A(r,e){for(var o=0;o<r.length;o++)if(I(r[o],e))return;r.push(e)}function P(r,e){for(var o=[],n=0;n<r.length;n++)for(var t=r[n],s=0;s<e.length;s++)if(t==e[s]){o.push(t);break}return o}function q(r,e){for(var o=[],n=0;n<r.length;n++)for(var t=r[n],s=0;s<e.length;s++)if(I(t,e[s])){o.push(t);break}return o}function C(r,e){if(0!=e.length){for(var o=[],n=0;n<r.length;n++){for(var t=r[n],s=!0,i=0;i<e.length;i++)if(e[i]==t){s=!1;break}s&&o.push(t)}r.splice(0,r.length);for(var u=0;u<o.length;u++)r.push(o[u])}}function O(r,e){if(0!=e.length){for(var o=[],n=0;n<r.length;n++){for(var t=r[n],s=!0,i=0;i<e.length;i++)if(I(t,e[i])){s=!1;break}s&&o.push(t)}r.splice(0,r.length);for(var u=0;u<o.length;u++)r.push(o[u])}}function M(r,e){for(var o=r.positions,n=o[e],t=r.triangles.length,s=0;s<t;s++){var i=r.triangles[s];if(i.IsPointInside(n)){for(var u=i.edges,a=[],l=0;l<3;l++)a.push(u[l].PolyIndexIn(i));for(var f=Array(3),v=Array(3),l=0;l<3;l++)(p=l+1)>=3&&(p-=3),f[l]=new w(o,[i.verts[l],i.verts[p],e]),v[l]=new m([i.verts[l],e]);for(l=0;l<3;l++){var p=l+1;p>=3&&(p-=3),f[l].edges[0]=v[p],f[l].edges[1]=v[l],v[l].polys[0]=f[l],v[p].polys[1]=f[l]}for(l=0;l<3;l++)for(var g=u[l],d=a[l],h=0;h<3;h++)for(var c=f[h],y=0,_=0;_<2;_++)if(c.IsVertex(g.verts[_])&&y++,2==y){g.polys[d]=c,c.edges[2]=g;break}r.triangles[s]=f[0];for(l=1;l<3;l++)r.triangles.push(f[l]);for(l=0;l<3;l++)r.edges.push(v[l]);return!0}}return!1}function j(r){for(var e=r.positions,o=new Array(4),n=0;n<100;n++){for(var t=0,s=0;s<r.edges.length;s++){var i=r.edges[s],u=i.polys;if(!_(u[0])&&!_(u[1])){for(y=0;y<3;y++){f=u[0].verts[y];if(!i.IsVertex(f))break}var a=y+1;a>=3&&(a-=3);var l=y+2;l>=3&&(l-=3),o[0]=f,o[1]=u[0].verts[a],o[3]=u[0].verts[l];for(y=0;y<3;y++){var f=u[1].verts[y];if(!i.IsVertex(f))break}o[2]=f;var v=u[0].IsPointInCircumcircle(e[o[2]]),p=u[1].IsPointInCircumcircle(e[o[0]]);if(v||p){var g=new w(e,[o[0],o[1],o[2]]);if(g.IsVertexOrderCorrect()){var d=new w(e,[o[0],o[2],o[3]]);if(d.IsVertexOrderCorrect()){t++;for(y=0;y<3;y++)if(!I(b=u[0].edges[y],i)&&b.IsVertex(o[3])){var h=b,c=y;break}for(var y=0;y<3;y++){var b=u[1].edges[y];if(!I(b,i)&&b.IsVertex(o[1])){var x=b,m=y;break}}var k=h.PolyIndexIn(u[0]),V=x.PolyIndexIn(u[1]);h.polys[k]=u[1],x.polys[V]=u[0],u[0].edges[c]=x,u[1].edges[m]=h,u[0].copy_vert_info(g),u[1].copy_vert_info(d),i.verts=[o[0],o[2]]}}}}}if(0==t)break}}function F(r){for(var e=new Object,o=-1,n=0;n<r.edges.length;n++){var t=r.edges[n];if(_(t.polys[0])){if(_(t.polys[1]))continue;s=t.polys[1]}else{if(!_(t.polys[1]))continue;var s=t.polys[0]}var i=t.verts[0],u=t.verts[1],a=s.VertexIndexIn(u)-s.VertexIndexIn(i);if(a<0&&(a+=3),1!=a){var l=i;i=u,u=l}e[i]=u,o=i}if(o>=0){for(var f=o,v=[f];;){var p=e[f];if(p==o)break;v.push(p),f=p}r.hull=v}}function D(r){if(1!=r.triangles.length){if(0!=r.triangles.length){for(s=0;s<r.triangles.length;s++)(t=r.triangles[s]).index=s,r.vor_positions.push(t.ccdir);for(s=0;s<r.edges.length;s++)if(!_((o=r.edges[s]).polys[0])&&!_(o.polys[1])){var e=[o.polys[0].index,o.polys[1].index];r.vor_edges.push(e)}for(s=0;s<r.indices.length;s++){u=r.indices[s];r.vor_polygons[u]=new Object,(kr=r.vor_polygons[u]).edges=[],kr.triangles=[],kr.boundary=[]}for(s=0;s<r.edges.length;s++)for(var o=r.edges[s],n=0;n<2;n++)r.vor_polygons[o.verts[n]].edges.push(o);for(s=0;s<r.triangles.length;s++)for(var t=r.triangles[s],n=0;n<3;n++)r.vor_polygons[t.verts[n]].triangles.push(t);for(var s=0;s<r.indices.length;s++){var u=r.indices[s],f=(kr=r.vor_polygons[u]).triangles[0],t=f;kr.boundary.push(t.index);for(n=0;n<3&&!(o=t.edges[n]).IsVertex(u);n++);for(var v=o,p=!1;;){x=o.PolyIndexIn(t);if(t=o.polys[1-x],_(t))break;if(b(t,f)){p=!0;break}kr.boundary.push(t.index);for(n=0;n<3;n++)if(!I(m=t.edges[n],o)&&m.IsVertex(u)){o=m;break}}if(!p){kr.boundary.reverse(),t=f;for(n=0;n<3&&(o=t.edges[n],I(o,v)||!o.IsVertex(u));n++);for(;;){var x=o.PolyIndexIn(t);if(t=o.polys[1-x],_(t))break;kr.boundary.push(t.index);for(n=0;n<3;n++){var m=t.edges[n];if(!I(m,o)&&m.IsVertex(u)){o=m;break}}}}p||(kr.boundary.reverse(),kr.boundary.push(-1),kr.boundary.reverse(),kr.boundary.push(-1))}if(r.hull.length>=3){for(var k=new Array,V=r.positions,A=r.hull.length,n=0;n<A;n++){var u=r.hull[n],C=n+1;C>=A&&(C=0);var O=r.hull[C],M=(o=q(r.vor_polygons[u].edges,r.vor_polygons[O].edges)[0]).polys[0].index,j=V[u],F=y(sr=V[O],j),D=[M,r.vor_positions[M],u,j,O,sr,F];k.push(D)}for(;k.length>3;){for(var E=k.length,S=new Array,z=new Array,L=0;L<E;L++)z.push(new Array);for(L=0;L<E;L++)(gr=L+1)>=E&&(gr=0),c(Z=l(i(k[L][6],k[gr][6])),-1),z[L].push(S.length),z[gr].push(S.length),S.push(Z);for(L=0;L<E;L++){if((W=z[L]).length>=2){for(var T=new Array,B=0;B<W.length;B++)T.push(a(S[W[B]],k[L][1]));for(var G=0,H=T[G],J=0;J<T.length;J++){var K=T[J];K<H&&(G=J,H=K)}N=W[G]}else if(1==W.length)N=W[0];else var N=-1;z[L]=N}for(var Q=new Array,L=0;L<E;L++){(gr=L+1)>=E&&(gr=0);var R=L-1;R<0&&(R=E-1);var U=0,W=z[L];if(-1!=W&&(W==z[R]?U=2:W==z[gr]&&(U=1)),0==U)Q.push(k[L]);else if(1==U){var X=k[L],Y=k[gr],Z=S[L],$=X[0],rr=Y[0],er=rr!=$;if(er){for(var or=r.vor_positions.length,nr=X[2],j=X[3],tr=Y[4],sr=Y[5],ir=void 0,ur=void 0,ar=0;ar<E;ar++){for(var lr=a(k[ar][3],Z),fr=ar-L;fr<0;)fr+=E;for(;fr>=E;)fr-=E;fr<=2?void 0==ir?ir=lr:lr<ir&&(ir=lr):void 0==ur?ur=lr:lr<ur&&(ur=lr)}er=ir<ur}if(er){D=[or,Z,nr,j,tr,sr,F=y(sr,j)];Q.push(D),r.vor_positions.push(Z);var vr=X[4];r.vor_edges.push([$,or]),r.vor_edges.push([rr,or]),r.vor_polygons[vr].boundary.shift();Ir=r.vor_polygons[vr].boundary.length;r.vor_polygons[vr].boundary[Ir-1]=or,r.vor_polygons[nr].boundary[1]==$?(r.vor_polygons[nr].boundary.unshift(-1),r.vor_polygons[nr].boundary[1]=or):(Ir=r.vor_polygons[nr].boundary.length,r.vor_polygons[nr].boundary[Ir-2]==$&&(r.vor_polygons[nr].boundary.push(-1),Ir=r.vor_polygons[nr].boundary.length,r.vor_polygons[nr].boundary[Ir-2]=or)),r.vor_polygons[tr].boundary[1]==rr?(r.vor_polygons[tr].boundary.unshift(-1),r.vor_polygons[tr].boundary[1]=or):(Ir=r.vor_polygons[tr].boundary.length,r.vor_polygons[tr].boundary[Ir-2]==rr&&(r.vor_polygons[tr].boundary.push(-1),Ir=r.vor_polygons[tr].boundary.length,r.vor_polygons[tr].boundary[Ir-2]=or))}else Q.push(X),Q.push(Y)}}if(Q.length==k.length)break;k=Q}if(2==k.length){if(k[0][0]!=k[1][0]){for(var pr=[],L=0;L<2;L++){var gr=k[L][0];pr.push(gr),gr=k[L][2],r.vor_polygons[gr].boundary.shift(),r.vor_polygons[gr].boundary.pop()}r.vor_edges.push(pr)}}else if(3==k.length){var dr=k[0][0],hr=k[1][0],cr=k[2][0];if(dr!=hr&&dr!=cr&&hr!=cr){var or=r.vor_positions.length,yr=k[0][3],_r=k[1][3],br=k[2][3];h(Z=g(),i(yr,_r)),h(Z,i(_r,br)),h(Z,i(br,yr)),c(Z=l(Z),-1),r.vor_positions.push(Z);for(L=0;L<3;L++){D=k[L];r.vor_edges.push([D[0],or]);u=D[2];r.vor_polygons[u].boundary.shift();var Ir=r.vor_polygons[u].boundary.length;r.vor_polygons[u].boundary[Ir-1]=or}}}}for(L=0;L<r.vor_polygons.length;L++)(kr=r.vor_polygons[L]).boundary.length>=3&&kr.boundary[0]>=0&&((t=new w(r.vor_positions,kr.boundary.slice(0,3))).IsVertexOrderCorrect()||kr.boundary.reverse())}else if(2==r.hull.length){var yr=r.positions[r.hull[0]],_r=r.positions[r.hull[1]];h(j=g(),yr),h(j,_r),j=l(j),r.vor_positions.push(j);sr=l(i(yr,_r));r.vor_positions.push(sr);var xr=d(j);c(xr,-1),r.vor_positions.push(xr);var wr=d(sr);c(wr,-1),r.vor_positions.push(wr),r.vor_edges.push([0,1,2,3,0]),o=r.edges[0];for(L=0;L<2;L++){u=r.hull[L];r.vor_polygons[u]=new Object,(kr=r.vor_polygons[u]).edges=[o],kr.triangles=[0],0==L?kr.boundary=[0,1,2,3]:1==L&&(kr.boundary=[0,3,2,1])}}}else if(3==r.hull.length){t=r.triangles[0];r.vor_positions.push(t.ccdir);for(L=0;L<3;L++){(gr=L+1)>=3&&(gr=0),(R=L-1)<0&&(R=2);var _r=r.positions[r.hull[L]],mr=y(br=r.positions[r.hull[gr]],_r);r.vor_positions.push(l(i(mr,t.ccdir))),r.vor_edges.push([0,L+1,4]);u=r.hull[L];r.vor_polygons[u]=new Object;for(var kr=r.vor_polygons[u],Vr=r.hull[R],Ar=0;Ar<3&&2!=P([Vr,u],(o=r.edges[Ar]).verts).length;Ar++);kr.edges=[o],kr.triangles=[t],kr.boundary=[0,R+1,4,L+1]}var Pr=d(t.ccdir);c(Pr,-1),r.vor_positions.push(Pr)}}function E(r,e){var o=new Object;if(o.positions=r,o.indices=e,o.triangles=[],o.edges=[],o.hull=[],o.vor_positions=[],o.vor_edges=[],o.vor_polygons=new Object,e.length<3)return 2==e.length&&(o.edges.push(new m(e)),o.hull=e),D(o),o;var n=new w(r,e.slice(0,3));n.IsVertexOrderCorrect()||(n=new w(r,[e[0],e[2],e[1]])),o.triangles.push(n);for(var t=new Array(3),s=0;s<3;s++){(p=s+1)>=3&&(p-=3);var i=[d=e[s],I=e[p]],u=new m(i),a=new k(r,i);a.edge=u,t[s]=a,n.edges[s]=u,u.polys[0]=n,o.edges.push(u)}for(var l=e.slice(0,3),f=t,v=Object,s=0;s<3;s++){var p=s+2;p>=3&&(p-=3),v[d=e[s]]=[t[s],t[s+1]]}for(var g=3;g<e.length;g++){var d=e[g];if(!M(o,d)){v[d]=[];for(var h=[],c=[],y=[],b=0;b<l.length;b++){for(var I=l[b],x=new k(r,[d,I]),P=!1,E=0;E<f.length;E++){var S=f[E];if(P=x.intersects(r,S))break}if(!P){u=new m(x.verts);x.edge=u,A(h,x),A(v[d],x),V(c,d),A(v[I],x),V(c,I)}}V(l,d);for(b=0;b<f.length;b++){for(var x=f[b],z=[],L=0;L<2;L++){var T=q(v[d],v[x.verts[L]]);0!=T.length&&z.push(T[0])}if(!(z.length<2)){for(var B=-1,L=0;L<2;L++)if(_(x.edge.polys[L])){B=L;break}if(!(B<0)){var G=x.edge.polys[1-B],H=x.verts[0],J=G.VertexIndexIn(H),K=x.verts[1],N=G.VertexIndexIn(K)-J;if(N<0&&(N+=3),1==N)Q=[d,K,H];else if(2==N)var Q=[d,H,K];if((n=new w(r,Q)).IsVertexOrderCorrect()){o.triangles.push(n),x.edge.polys[B]=n,n.edges[0]=x.edge,n.edges[1]=z[0].edge,n.edges[2]=z[1].edge,A(y,x);for(L=0;L<2;L++){var R=z[L];_(R.edge.polys[0])?(R.edge.polys[0]=n,o.edges.push(R.edge)):(R.edge.polys[1]=n,A(y,R))}}}}}for(b=0;b<h.length;b++)A(f,h[b]);O(f,y);for(var U=[],b=0;b<c.length;b++){var W=c[b];O(v[W],y),0==v[W].length&&U.push(W)}C(l,U)}}return j(o),F(o),D(o),o}function S(r){for(var e=new Array(r.length),o=0;o<e.length;o++)e[o]=o;return E(r,e)}w.prototype.copy_vert_info=function(r){this.verts=r.verts,this.dirs=r.dirs,this.vol=r.vol,this.ccdir=r.ccdir,this.ccdsq=r.ccdsq},w.prototype.IsVertexOrderCorrect=function(){return this.vol>=0},w.prototype.IsPointInside=function(r){for(var e=0;e<3;e++)if(s(r,this.dirs[e])<0)return!1;return!0},w.prototype.IsPointInCircumcircle=function(r){return a(this.ccdir,r)<this.ccdsq},w.prototype.IsVertex=function(r){for(var e=0;e<3;e++)if(r==this.verts[e])return!0;return!1},w.prototype.VertexIndexIn=function(r){for(var e=0;e<3;e++)if(r==this.verts[e])return e;return-1},w.prototype.EdgeIndexIn=function(r){for(var e=0;e<3;e++)if(I(this.edges[e],r))return e;return-1},m.prototype.IsVertex=function(r){for(var e=0;e<2;e++)if(r==this.verts[e])return!0;return!1},m.prototype.VertexIndexIn=function(r){for(var e=0;e<2;e++)if(r==this.verts[e])return e;return-1},m.prototype.PolyIndexIn=function(r){for(var e=0;e<2;e++)if(b(this.polys[e],r))return e;return-1},k.prototype.intersects=function(r,e){for(f=0;f<2;f++)for(var o=0;o<2;o++)if(this.verts[f]==e.verts[o])return!1;var n=l(i(this.direc,e.direc)),t=s(n,this.midpnt)>0;if(s(n,e.midpnt)>0!=t)return!1;for(var u=[],f=0;f<2;f++){p=a(n,r[this.verts[f]]);u.push(p)}for(var v=[],f=0;f<2;f++){var p=a(n,r[e.verts[f]]);v.push(p)}var g=x(u[0],u[1]),d=x(v[0],v[1]);if(g<=this.pdst&&d<=e.pdst&&t)return!0;c(n,-1),t=!t;for(f=0;f<2;f++)u[f]=-u[f],v[f]=-v[f];return g=x(u[0],u[1]),d=x(v[0],v[1]),!!(g<=this.pdst&&d<=e.pdst&&t)};r.geoVoronoi=function(){var r=Math.PI/180,s=function(e){var o=e[0]*r,n=e[1]*r,t=Math.cos(n);return[t*Math.cos(o),t*Math.sin(o),Math.sin(n)]},i=function(e){var o=Math.sqrt(e[0]*e[0]+e[1]*e[1]),n=Math.atan2(e[2],o);return[Math.atan2(e[1],e[0])/r,n/r]},u=function(r,e){return e.map(function(e){return i(r[e])})},a=t.voronoi()([]),l=a.DT=null,f=a.sites=[],v=a.pos=[],p=function(r){return"object"==typeof r&&"type"in r?n.geoCentroid(r)[0]:0 in r?r[0]:void 0},g=function(r){return"object"==typeof r&&"type"in r?n.geoCentroid(r)[1]:0 in r?r[1]:void 0},d=function(r){return a._hull=a._polygons=a._links=a._triangles=null,"object"==typeof r&&"FeatureCollection"==r.type&&(r=r.features),f=r.map(function(r,e){return r.index=e,r}),v=r.map(function(r){return[p(r),g(r)]}),l=S(v.map(s)),a};return a.links=d.links=function(r){if(r&&d(r),a._links)return a._links;var t=o.map(),s=l.edges.map(function(r,o){t.set(e.extent(r.verts),o);var s={source:f[r.verts[0]],target:f[r.verts[1]],urquhart:!0,length:n.geoDistance(v[r.verts[0]],v[r.verts[1]])};return{type:"Feature",geometry:{type:"LineString",coordinates:[i(l.positions[r.verts[0]]),i(l.positions[r.verts[1]])]},properties:s}});return l.triangles.forEach(function(r){for(var o,n,i=0,u=0,a=0;a<3;a++){n=e.extent([r.verts[a],r.verts[(a+1)%3]]);var l=t.get(n);(u=s[l].properties.length)>i&&(i=u,o=l)}s[o].properties.urquhart=!1}),a._links={type:"FeatureCollection",features:s}},a.triangles=d.triangles=function(r){if(r&&d(r),a._triangles)return a._triangles;var e=l.triangles.map(function(r){return r.spherical=r.verts.map(function(r){return l.positions[r]}).map(i),r.ccdsq<0&&(r.spherical=r.spherical.reverse(),r.ccdsq*=-1),r}).map(function(r){return{type:"Feature",geometry:{type:"Polygon",coordinates:[r.spherical.concat([r.spherical[0]])]},properties:{sites:r.verts.map(function(r){return f[r]}),area:r.vol,circumcenter:i(r.ccdir)}}});return a._triangles={type:"FeatureCollection",features:e}},a.polygons=d.polygons=function(r){if(r&&d(r),a._polygons)return a._polygons;var e=l.indices.map(function(r,e){var o=l.vor_polygons[l.indices[r]],t={};if(void 0==o)t.type="Sphere";else{var s=u(l.vor_positions,o.boundary.concat([o.boundary[0]])),i={type:"Polygon",coordinates:[[v[r],s[0],s[1],v[r]]]};n.geoArea(i)>2*Math.PI+1e-10&&(s=s.reverse()),t.type="Polygon",t.coordinates=[s]}return{type:"Feature",geometry:t,properties:{site:f[r],sitecoordinates:v[r],neighbours:o.edges.map(function(e){return e.verts.filter(function(e){return e!==r})[0]})}}});return a._polygons={type:"FeatureCollection",features:e}},a.hull=d.hull=function(r){if(r&&d(r),a._hull)return a._hull;if(!l.hull.length)return null;var e=l.hull.reverse();return a._hull={type:"Feature",geometry:{type:"Polygon",coordinates:[e.concat([e[0]]).map(function(r){return v[r]})]},properties:{sites:e.map(function(r){return f[r]})}}},a.find=function(r,e,o){var t,s=a.polygons().features,i=a.find.found||0,u=s[i]||s[i=0],l=n.geoDistance([r,e],u.properties.sitecoordinates);do{u=s[t=i],i=null,u.properties.neighbours.forEach(function(o){var t=n.geoDistance([r,e],s[o].properties.sitecoordinates);if(t<l)return l=t,void(i=o)})}while(null!==i);if(a.find.found=t,!o||l<o*o)return u.properties.site},d.x=function(r){return r?(p=r,d):p},d.y=function(r){return r?(g=r,d):g},d.extent=function(r){return r?d:null},d.size=function(r){return r?d:null},d},Object.defineProperty(r,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-geo-voronoi", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Spherical Voronoi Diagram and Delaunay Triangulation", | ||
@@ -13,2 +13,4 @@ "keywords": [ | ||
"main": "build/d3-geo-voronoi.js", | ||
"unpkg": "build/d3-geo-voronoi.js", | ||
"jsdelivr": "build/d3-geo-voronoi.js", | ||
"module": "index", | ||
@@ -34,3 +36,3 @@ "jsnext:main": "index", | ||
"test": "tape 'test/**/*-test.js'", | ||
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-geo-voronoi.js -c negate_iife=false -m -o build/d3-geo-voronoi.min.js", | ||
"prepublishOnly": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-geo-voronoi.js -c negate_iife=false -m -o build/d3-geo-voronoi.min.js", | ||
"postpublish": "zip -j build/d3-geo-voronoi.zip -- LICENSE README.md build/d3-geo-voronoi.js build/d3-geo-voronoi.min.js" | ||
@@ -46,6 +48,6 @@ }, | ||
"package-preamble": "0.1", | ||
"rollup": "0.41", | ||
"tape": "^4", | ||
"uglify-js": "^2" | ||
"rollup": "0.49", | ||
"tape": "4", | ||
"uglify-js": "32" | ||
} | ||
} |
@@ -8,3 +8,3 @@ // | ||
import { ascending, extent } from "d3-array"; | ||
import { extent } from "d3-array"; | ||
import { map } from "d3-collection"; | ||
@@ -11,0 +11,0 @@ import { geoArea, geoCentroid, geoDistance } from "d3-geo"; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9420830
17040