d3-geo-voronoi
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -1,2 +0,2 @@ | ||
// https://github.com/Fil/d3-geo-voronoi Version 1.4.0. Copyright 2019 Philippe Rivière. | ||
// https://github.com/Fil/d3-geo-voronoi Version 1.4.1. Copyright 2019 Philippe Rivière. | ||
(function (global, factory) { | ||
@@ -34,6 +34,6 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-delaunay'), require('d3-geo'), require('d3-array')) : | ||
var sqrt = Math.sqrt; | ||
var tan = Math.tan; | ||
function asin(x) { | ||
@@ -73,3 +73,3 @@ return x > 1 ? halfPi : x < -1 ? -halfPi : Math.asin(x); | ||
// | ||
// (c) 2018 Philippe Riviere | ||
// (c) 2019 Philippe Riviere | ||
// | ||
@@ -104,3 +104,3 @@ // https://github.com/Fil/ | ||
const delaunay = geo_delaunay_from(points), | ||
triangles = geo_triangles(delaunay, points.length), | ||
triangles = geo_triangles(delaunay), | ||
edges = geo_edges(triangles, points), | ||
@@ -163,2 +163,7 @@ neighbors = geo_neighbors(triangles, points.length), | ||
function stereo(lambda, phi) { | ||
var r = tan(0.5 * (halfPi + phi)); | ||
return [cos(lambda) * r, -sin(lambda) * r]; | ||
} | ||
function geo_delaunay_from(points) { | ||
@@ -172,6 +177,6 @@ if (points.length < 2) return {}; | ||
const r = d3Geo.geoRotation(points[pivot]), | ||
projection = d3Geo.geoStereographic() | ||
projection = d3Geo.geoProjection(stereo) | ||
.translate([0, 0]) | ||
.scale(1) | ||
.rotate(r.invert([180, 0])); | ||
.rotate(r.invert([0, 90])); | ||
points = points.map(projection); | ||
@@ -183,3 +188,3 @@ | ||
let m = points[i][0] ** 2 + points[i][1] ** 2; | ||
if (!isFinite(m)) zeros.push(i); | ||
if (m > 1e32) zeros.push(i); | ||
else if (m > max2) max2 = m; | ||
@@ -201,2 +206,9 @@ } | ||
// clean up the triangulation | ||
const {triangles} = delaunay; | ||
for (let i = 0, l = triangles.length; i < l; i++) { | ||
if (triangles[i] > points.length - 4) | ||
triangles[i] = 0; | ||
} | ||
return delaunay; | ||
@@ -218,6 +230,6 @@ } | ||
function geo_triangles(delaunay, npoints) { | ||
if (!delaunay.triangles) return []; | ||
function geo_triangles(delaunay) { | ||
const {triangles} = delaunay; | ||
if (!triangles) return []; | ||
const triangles = delaunay.triangles.slice().map(d => (d >= npoints ? 0 : d)); | ||
const geo_triangles = []; | ||
@@ -224,0 +236,0 @@ for (let i = 0, n = triangles.length / 3; i < n; i++) { |
@@ -1,1 +0,1 @@ | ||
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-delaunay"),require("d3-geo"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-delaunay","d3-geo","d3-array"],t):t(e.d3=e.d3||{},e.d3,e.d3,e.d3)})(this,function(e,t,n,o){"use strict";var r=Math.PI,i=r/2,u=180/r,a=r/180,l=Math.atan2,s=Math.cos,c=Math.max,f=Math.min,p=Math.sin,d=Math.sign||function(e){return e>0?1:e<0?-1:0},h=Math.sqrt;function y(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function g(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function m(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function v(e){var t=h(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);return[e[0]/t,e[1]/t,e[2]/t]}function _(e){return[l(e[1],e[0])*u,(t=c(-1,f(1,e[2])),(t>1?i:t<-1?-i:Math.asin(t))*u)];var t}function b(e){var t=e[0]*a,n=e[1]*a,o=s(n);return[o*s(t),o*p(t),p(n)]}function j(e){return y((e=e.map(e=>b(e)))[0],g(e[2],e[1]))}function M(e){const i=function(e){if(e.length<2)return{};let o=0;for(;isNaN(e[o][0]+e[o][1])&&o++<e.length;);const i=n.geoRotation(e[o]),u=n.geoStereographic().translate([0,0]).scale(1).rotate(i.invert([180,0])),a=[];let l=1;for(let t=0,n=(e=e.map(u)).length;t<n;t++){let n=e[t][0]**2+e[t][1]**2;isFinite(n)?n>l&&(l=n):a.push(t)}const c=1e6*h(l);a.forEach(t=>e[t]=[c/2,t]);for(let t=0;t<4;t++)e.push([c*s(t/2*r),c*p(t/2*r)]);const f=t.Delaunay.from(e);return f.projection=u,f}(e),u=function(e,t){if(!e.triangles)return[];const n=e.triangles.slice().map(e=>e>=t?0:e),o=[];for(let e=0,t=n.length/3;e<t;e++){const t=n[3*e],r=n[3*e+1],i=n[3*e+2];t!==r&&r!==i&&i!==t&&o.push([t,i,r])}return o}(i,e.length),a=function(e,t){const n={};return 2===t.length?[[0,1]]:(e.forEach(e=>{if(!(j(e.map(e=>t[e]))<0))for(let t,r=0;r<3;r++)t=(r+1)%3,n[o.extent([e[r],e[t]]).join("-")]=!0}),Object.keys(n).map(e=>e.split("-").map(Number)))}(u,e),l=function(e,t){const n=[];return e.forEach((e,t)=>{for(let t=0;t<3;t++){const o=e[t],r=e[(t+1)%3];n[o]=n[o]||[],n[o].push(r)}}),0===e.length&&(2===t?(n[0]=[1],n[1]=[0]):1===t&&(n[0]=[])),n}(u,e.length),c=function(e,t){function n(e,t){let n=e[0]-t[0],o=e[1]-t[1],r=e[2]-t[2];return n*n+o*o+r*r}return function(o,r,i){void 0===i&&(i=0);let u,a,l=i;const s=b([o,r]);do{u=i,i=null,a=n(s,b(t[u])),e[u].forEach(e=>{let o=n(s,b(t[e]));if(o<a)return a=o,i=e,void(l=e)})}while(null!==i);return l}}(l,e),f=function(e,t){return e.map(e=>{const n=e.map(e=>t[e]).map(b);return _(v(m(m(g(n[1],n[0]),g(n[2],n[1])),g(n[0],n[2]))))})}(u,e),{polygons:d,centers:y}=function(e,t,n){const o=[],r=e.slice();if(0===t.length){if(n.length<2)return{polygons:o,centers:r};if(2===n.length){const e=b(n[0]),t=b(n[1]),u=v(m(e,t)),a=v(g(e,t)),l=g(u,a),s=[u,g(u,l),g(g(u,l),l),g(g(g(u,l),l),l)].map(_).map(i);return o.push(s),o.push(s.slice().reverse()),{polygons:o,centers:r}}}function i(e){let n=-1;return r.slice(t.length,1/0).forEach((o,r)=>{o[0]===e[0]&&o[1]===e[1]&&(n=r+t.length)}),n<0&&(n=r.length,r.push(e)),n}return t.forEach((e,t)=>{for(let n=0;n<3;n++){const r=e[n],i=e[(n+1)%3],u=e[(n+2)%3];o[r]=o[r]||[],o[r].push([i,u,t,[r,i,u]])}}),{polygons:o.map(e=>{const t=[e[0][2]];let o=e[0][1];for(let n=1;n<e.length;n++)for(let n=0;n<e.length;n++)if(e[n][0]==o){o=e[n][1],t.push(e[n][2]);break}if(t.length>2)return t;if(2==t.length){const o=x(n[e[0][3][0]],n[e[0][3][1]],r[t[0]]),u=x(n[e[0][3][2]],n[e[0][3][0]],r[t[0]]),a=i(o),l=i(u);return[t[0],l,t[1],a]}console&&console.warn({here:"unreachable",poly:e})}),centers:r}}(f,u,e),M=function(e){const t=[];return e.forEach(e=>{if(!e)return;let n=e[e.length-1];for(let o of e)o>n&&t.push([n,o]),n=o}),t}(d),E=function(e,t){const n={},o=[];e.map(e=>{if(!(j(e.map(e=>t[e>t.length?0:e]))<0))for(let t=0;t<3;t++){let o=[e[t],e[(t+1)%3]],r=`${o[1]}-${o[0]}`;n[r]?delete n[r]:n[o.join("-")]=!0}});const r={};let i;if(Object.keys(n).forEach(e=>{e=e.split("-").map(Number),r[e[0]]=e[1],i=e[0]}),void 0===i)return o;let u=i;do{o.push(u);let e=r[u];r[u]=-1,u=e}while(u>-1&&u!==i);return o}(u,e),F=function(e,t){return function(n){const r={},i={};return e.forEach((e,t)=>{const o=e.join("-");r[o]=n[t],i[o]=!0}),t.forEach(e=>{let t=0,n=-1;for(var u=0;u<3;u++){let i=o.extent([e[u],e[(u+1)%3]]).join("-");r[i]>t&&(t=r[i],n=i)}i[n]=!1}),e.map(e=>i[e.join("-")])}}(a,u);return{delaunay:i,edges:a,triangles:u,centers:y,neighbors:l,polygons:d,mesh:M,hull:E,urquhart:F,find:c}}function x(e,t,n){e=b(e),t=b(t),n=b(n);const o=d(y(g(t,e),n));return _(v(m(e,t)).map(e=>o*e))}e.geoDelaunay=M,e.geoVoronoi=function(e){const t=function(e){if(t.delaunay=null,t._data=e,"object"==typeof t._data&&"FeatureCollection"===t._data.type&&(t._data=t._data.features),"object"==typeof t._data){const e=t._data.map(e=>[t._vx(e),t._vy(e),e]).filter(e=>isFinite(e[0]+e[1]));t.points=e.map(e=>[e[0],e[1]]),t.valid=e.map(e=>e[2]),t.delaunay=M(t.points)}return t};return t._vx=function(e){return"object"==typeof e&&"type"in e?n.geoCentroid(e)[0]:0 in e?e[0]:void 0},t._vy=function(e){return"object"==typeof e&&"type"in e?n.geoCentroid(e)[1]:1 in e?e[1]:void 0},t.x=function(e){return e?(t._vx=e,t):t._vx},t.y=function(e){return e?(t._vy=e,t):t._vy},t.polygons=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const n={type:"FeatureCollection",features:[]};return 0===t.valid.length?n:(t.delaunay.polygons.forEach((e,o)=>n.features.push({type:"Feature",geometry:e?{type:"Polygon",coordinates:[[...e,e[0]].map(e=>t.delaunay.centers[e])]}:null,properties:{site:t.valid[o],sitecoordinates:t.points[o],neighbours:t.delaunay.neighbors[o]}})),1===t.valid.length&&n.features.push({type:"Feature",geometry:{type:"Sphere"},properties:{site:t.valid[0],sitecoordinates:t.points[0],neighbours:[]}}),n)},t.triangles=function(e){return void 0!==e&&t(e),!!t.delaunay&&{type:"FeatureCollection",features:t.delaunay.triangles.map((e,n)=>((e=e.map(e=>t.points[e])).center=t.delaunay.centers[n],e)).filter(e=>j(e)>0).map(e=>({type:"Feature",properties:{circumcenter:e.center},geometry:{type:"Polygon",coordinates:[[...e,e[0]]]}}))}},t.links=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const o=t.delaunay.edges.map(e=>n.geoDistance(t.points[e[0]],t.points[e[1]])),r=t.delaunay.urquhart(o);return{type:"FeatureCollection",features:t.delaunay.edges.map((e,n)=>({type:"Feature",properties:{source:t.valid[e[0]],target:t.valid[e[1]],length:o[n],urquhart:!!r[n]},geometry:{type:"LineString",coordinates:[t.points[e[0]],t.points[e[1]]]}}))}},t.mesh=function(e){return void 0!==e&&t(e),!!t.delaunay&&{type:"MultiLineString",coordinates:t.delaunay.edges.map(e=>[t.points[e[0]],t.points[e[1]]])}},t.cellMesh=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const{centers:n,polygons:o}=t.delaunay,r=[];for(const e of o)if(e)for(let t=e.length,o=e[t-1],i=e[0],u=0;u<t;o=i,i=e[++u])i>o&&r.push([n[o],n[i]]);return{type:"MultiLineString",coordinates:r}},t._found=void 0,t.find=function(e,o,r){if(t._found=t.delaunay.find(e,o,t._found),!r||n.geoDistance([e,o],t.points[t._found])<r)return t._found},t.hull=function(e){void 0!==e&&t(e);const n=t.delaunay.hull,o=t.points;return 0===n.length?null:{type:"Polygon",coordinates:[[...n.map(e=>o[e]),o[n[0]]]]}},e?t(e):t},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-delaunay"),require("d3-geo"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-delaunay","d3-geo","d3-array"],t):t(e.d3=e.d3||{},e.d3,e.d3,e.d3)})(this,function(e,t,n,o){"use strict";var r=Math.PI,u=r/2,i=180/r,a=r/180,l=Math.atan2,s=Math.cos,c=Math.max,f=Math.min,p=Math.sin,d=Math.sign||function(e){return e>0?1:e<0?-1:0},h=Math.sqrt,y=Math.tan;function g(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function m(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function v(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function _(e){var t=h(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);return[e[0]/t,e[1]/t,e[2]/t]}function b(e){return[l(e[1],e[0])*i,(t=c(-1,f(1,e[2])),(t>1?u:t<-1?-u:Math.asin(t))*i)];var t}function j(e){var t=e[0]*a,n=e[1]*a,o=s(n);return[o*s(t),o*p(t),p(n)]}function M(e){return g((e=e.map(e=>j(e)))[0],m(e[2],e[1]))}function x(e){const u=function(e){if(e.length<2)return{};let o=0;for(;isNaN(e[o][0]+e[o][1])&&o++<e.length;);const u=n.geoRotation(e[o]),i=n.geoProjection(E).translate([0,0]).scale(1).rotate(u.invert([0,90])),a=[];let l=1;for(let t=0,n=(e=e.map(i)).length;t<n;t++){let n=e[t][0]**2+e[t][1]**2;n>1e32?a.push(t):n>l&&(l=n)}const c=1e6*h(l);a.forEach(t=>e[t]=[c/2,t]);for(let t=0;t<4;t++)e.push([c*s(t/2*r),c*p(t/2*r)]);const f=t.Delaunay.from(e);f.projection=i;const{triangles:d}=f;for(let t=0,n=d.length;t<n;t++)d[t]>e.length-4&&(d[t]=0);return f}(e),i=function(e){const{triangles:t}=e;if(!t)return[];const n=[];for(let e=0,o=t.length/3;e<o;e++){const o=t[3*e],r=t[3*e+1],u=t[3*e+2];o!==r&&r!==u&&u!==o&&n.push([o,u,r])}return n}(u),a=function(e,t){const n={};return 2===t.length?[[0,1]]:(e.forEach(e=>{if(!(M(e.map(e=>t[e]))<0))for(let t,r=0;r<3;r++)t=(r+1)%3,n[o.extent([e[r],e[t]]).join("-")]=!0}),Object.keys(n).map(e=>e.split("-").map(Number)))}(i,e),l=function(e,t){const n=[];return e.forEach((e,t)=>{for(let t=0;t<3;t++){const o=e[t],r=e[(t+1)%3];n[o]=n[o]||[],n[o].push(r)}}),0===e.length&&(2===t?(n[0]=[1],n[1]=[0]):1===t&&(n[0]=[])),n}(i,e.length),c=function(e,t){function n(e,t){let n=e[0]-t[0],o=e[1]-t[1],r=e[2]-t[2];return n*n+o*o+r*r}return function(o,r,u){void 0===u&&(u=0);let i,a,l=u;const s=j([o,r]);do{i=u,u=null,a=n(s,j(t[i])),e[i].forEach(e=>{let o=n(s,j(t[e]));if(o<a)return a=o,u=e,void(l=e)})}while(null!==u);return l}}(l,e),f=function(e,t){return e.map(e=>{const n=e.map(e=>t[e]).map(j);return b(_(v(v(m(n[1],n[0]),m(n[2],n[1])),m(n[0],n[2]))))})}(i,e),{polygons:d,centers:y}=function(e,t,n){const o=[],r=e.slice();if(0===t.length){if(n.length<2)return{polygons:o,centers:r};if(2===n.length){const e=j(n[0]),t=j(n[1]),i=_(v(e,t)),a=_(m(e,t)),l=m(i,a),s=[i,m(i,l),m(m(i,l),l),m(m(m(i,l),l),l)].map(b).map(u);return o.push(s),o.push(s.slice().reverse()),{polygons:o,centers:r}}}function u(e){let n=-1;return r.slice(t.length,1/0).forEach((o,r)=>{o[0]===e[0]&&o[1]===e[1]&&(n=r+t.length)}),n<0&&(n=r.length,r.push(e)),n}return t.forEach((e,t)=>{for(let n=0;n<3;n++){const r=e[n],u=e[(n+1)%3],i=e[(n+2)%3];o[r]=o[r]||[],o[r].push([u,i,t,[r,u,i]])}}),{polygons:o.map(e=>{const t=[e[0][2]];let o=e[0][1];for(let n=1;n<e.length;n++)for(let n=0;n<e.length;n++)if(e[n][0]==o){o=e[n][1],t.push(e[n][2]);break}if(t.length>2)return t;if(2==t.length){const o=F(n[e[0][3][0]],n[e[0][3][1]],r[t[0]]),i=F(n[e[0][3][2]],n[e[0][3][0]],r[t[0]]),a=u(o),l=u(i);return[t[0],l,t[1],a]}console&&console.warn({here:"unreachable",poly:e})}),centers:r}}(f,i,e),g=function(e){const t=[];return e.forEach(e=>{if(!e)return;let n=e[e.length-1];for(let o of e)o>n&&t.push([n,o]),n=o}),t}(d),x=function(e,t){const n={},o=[];e.map(e=>{if(!(M(e.map(e=>t[e>t.length?0:e]))<0))for(let t=0;t<3;t++){let o=[e[t],e[(t+1)%3]],r=`${o[1]}-${o[0]}`;n[r]?delete n[r]:n[o.join("-")]=!0}});const r={};let u;if(Object.keys(n).forEach(e=>{e=e.split("-").map(Number),r[e[0]]=e[1],u=e[0]}),void 0===u)return o;let i=u;do{o.push(i);let e=r[i];r[i]=-1,i=e}while(i>-1&&i!==u);return o}(i,e),q=function(e,t){return function(n){const r={},u={};return e.forEach((e,t)=>{const o=e.join("-");r[o]=n[t],u[o]=!0}),t.forEach(e=>{let t=0,n=-1;for(var i=0;i<3;i++){let u=o.extent([e[i],e[(i+1)%3]]).join("-");r[u]>t&&(t=r[u],n=u)}u[n]=!1}),e.map(e=>u[e.join("-")])}}(a,i);return{delaunay:u,edges:a,triangles:i,centers:y,neighbors:l,polygons:d,mesh:g,hull:x,urquhart:q,find:c}}function E(e,t){var n=y(.5*(u+t));return[s(e)*n,-p(e)*n]}function F(e,t,n){e=j(e),t=j(t),n=j(n);const o=d(g(m(t,e),n));return b(_(v(e,t)).map(e=>o*e))}e.geoDelaunay=x,e.geoVoronoi=function(e){const t=function(e){if(t.delaunay=null,t._data=e,"object"==typeof t._data&&"FeatureCollection"===t._data.type&&(t._data=t._data.features),"object"==typeof t._data){const e=t._data.map(e=>[t._vx(e),t._vy(e),e]).filter(e=>isFinite(e[0]+e[1]));t.points=e.map(e=>[e[0],e[1]]),t.valid=e.map(e=>e[2]),t.delaunay=x(t.points)}return t};return t._vx=function(e){return"object"==typeof e&&"type"in e?n.geoCentroid(e)[0]:0 in e?e[0]:void 0},t._vy=function(e){return"object"==typeof e&&"type"in e?n.geoCentroid(e)[1]:1 in e?e[1]:void 0},t.x=function(e){return e?(t._vx=e,t):t._vx},t.y=function(e){return e?(t._vy=e,t):t._vy},t.polygons=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const n={type:"FeatureCollection",features:[]};return 0===t.valid.length?n:(t.delaunay.polygons.forEach((e,o)=>n.features.push({type:"Feature",geometry:e?{type:"Polygon",coordinates:[[...e,e[0]].map(e=>t.delaunay.centers[e])]}:null,properties:{site:t.valid[o],sitecoordinates:t.points[o],neighbours:t.delaunay.neighbors[o]}})),1===t.valid.length&&n.features.push({type:"Feature",geometry:{type:"Sphere"},properties:{site:t.valid[0],sitecoordinates:t.points[0],neighbours:[]}}),n)},t.triangles=function(e){return void 0!==e&&t(e),!!t.delaunay&&{type:"FeatureCollection",features:t.delaunay.triangles.map((e,n)=>((e=e.map(e=>t.points[e])).center=t.delaunay.centers[n],e)).filter(e=>M(e)>0).map(e=>({type:"Feature",properties:{circumcenter:e.center},geometry:{type:"Polygon",coordinates:[[...e,e[0]]]}}))}},t.links=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const o=t.delaunay.edges.map(e=>n.geoDistance(t.points[e[0]],t.points[e[1]])),r=t.delaunay.urquhart(o);return{type:"FeatureCollection",features:t.delaunay.edges.map((e,n)=>({type:"Feature",properties:{source:t.valid[e[0]],target:t.valid[e[1]],length:o[n],urquhart:!!r[n]},geometry:{type:"LineString",coordinates:[t.points[e[0]],t.points[e[1]]]}}))}},t.mesh=function(e){return void 0!==e&&t(e),!!t.delaunay&&{type:"MultiLineString",coordinates:t.delaunay.edges.map(e=>[t.points[e[0]],t.points[e[1]]])}},t.cellMesh=function(e){if(void 0!==e&&t(e),!t.delaunay)return!1;const{centers:n,polygons:o}=t.delaunay,r=[];for(const e of o)if(e)for(let t=e.length,o=e[t-1],u=e[0],i=0;i<t;o=u,u=e[++i])u>o&&r.push([n[o],n[u]]);return{type:"MultiLineString",coordinates:r}},t._found=void 0,t.find=function(e,o,r){if(t._found=t.delaunay.find(e,o,t._found),!r||n.geoDistance([e,o],t.points[t._found])<r)return t._found},t.hull=function(e){void 0!==e&&t(e);const n=t.delaunay.hull,o=t.points;return 0===n.length?null:{type:"Polygon",coordinates:[[...n.map(e=>o[e]),o[n[0]]]]}},e?t(e):t},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-geo-voronoi", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Spherical Voronoi Diagram and Delaunay Triangulation", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -154,3 +154,3 @@ # d3-geo-voronoi | ||
``` | ||
<script src="https://unpkg.com/d3-delaunay@4"></script> | ||
<script src="https://unpkg.com/d3-delaunay@5"></script> | ||
<script src="https://unpkg.com/d3-geo-voronoi@1"></script> | ||
@@ -157,0 +157,0 @@ ``` |
@@ -1,2 +0,2 @@ | ||
import { asin, atan2, cos, sin, sqrt } from "./math"; | ||
import { asin, atan2, cos, sin, sqrt } from "./math.js"; | ||
@@ -3,0 +3,0 @@ export function spherical(cartesian) { |
// | ||
// (c) 2018 Philippe Riviere | ||
// (c) 2019 Philippe Riviere | ||
// | ||
@@ -9,3 +9,3 @@ // https://github.com/Fil/ | ||
import { Delaunay } from "d3-delaunay"; | ||
import { geoRotation, geoStereographic } from "d3-geo"; | ||
import { geoRotation, geoProjection } from "d3-geo"; | ||
import { extent } from "d3-array"; | ||
@@ -17,2 +17,3 @@ import { | ||
degrees, | ||
halfPi, | ||
max, | ||
@@ -24,3 +25,4 @@ min, | ||
sin, | ||
sqrt | ||
sqrt, | ||
tan | ||
} from "./math.js"; | ||
@@ -58,3 +60,3 @@ import { | ||
const delaunay = geo_delaunay_from(points), | ||
triangles = geo_triangles(delaunay, points.length), | ||
triangles = geo_triangles(delaunay), | ||
edges = geo_edges(triangles, points), | ||
@@ -117,2 +119,7 @@ neighbors = geo_neighbors(triangles, points.length), | ||
function stereo(lambda, phi) { | ||
var r = tan(0.5 * (halfPi + phi)); | ||
return [cos(lambda) * r, -sin(lambda) * r]; | ||
} | ||
function geo_delaunay_from(points) { | ||
@@ -126,6 +133,6 @@ if (points.length < 2) return {}; | ||
const r = geoRotation(points[pivot]), | ||
projection = geoStereographic() | ||
projection = geoProjection(stereo) | ||
.translate([0, 0]) | ||
.scale(1) | ||
.rotate(r.invert([180, 0])); | ||
.rotate(r.invert([0, 90])); | ||
points = points.map(projection); | ||
@@ -137,3 +144,3 @@ | ||
let m = points[i][0] ** 2 + points[i][1] ** 2; | ||
if (!isFinite(m)) zeros.push(i); | ||
if (m > 1e32) zeros.push(i); | ||
else if (m > max2) max2 = m; | ||
@@ -155,2 +162,9 @@ } | ||
// clean up the triangulation | ||
const {triangles} = delaunay; | ||
for (let i = 0, l = triangles.length; i < l; i++) { | ||
if (triangles[i] > points.length - 4) | ||
triangles[i] = 0; | ||
} | ||
return delaunay; | ||
@@ -172,6 +186,6 @@ } | ||
function geo_triangles(delaunay, npoints) { | ||
if (!delaunay.triangles) return []; | ||
function geo_triangles(delaunay) { | ||
const {triangles} = delaunay; | ||
if (!triangles) return []; | ||
const triangles = delaunay.triangles.slice().map(d => (d >= npoints ? 0 : d)); | ||
const geo_triangles = []; | ||
@@ -178,0 +192,0 @@ for (let i = 0, n = triangles.length / 3; i < n; i++) { |
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
74515
1747