New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

d3-delaunay

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-delaunay - npm Package Compare versions

Comparing version 4.1.3 to 4.1.4

67

dist/d3-delaunay.js

@@ -1,3 +0,3 @@

// https://github.com/d3/d3-delaunay v4.1.3 Copyright 2018 Mike Bostock
// https://github.com/mapbox/delaunator v2.0.3. Copyright 2017 Mapbox, Inc.
// https://github.com/d3/d3-delaunay v4.1.4 Copyright 2018 Mike Bostock
// https://github.com/mapbox/delaunator v2.0.4. Copyright 2017 Mapbox, Inc.
(function (global, factory) {

@@ -64,2 +64,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

}
const i0x = coords[2 * i0];
const i0y = coords[2 * i0 + 1];

@@ -71,3 +73,3 @@ minDist = Infinity;

if (i === i0) continue;
const d = dist(coords[2 * i0], coords[2 * i0 + 1], coords[2 * i], coords[2 * i + 1]);
const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
if (d < minDist && d > 0) {

@@ -78,2 +80,4 @@ i1 = i;

}
let i1x = coords[2 * i1];
let i1y = coords[2 * i1 + 1];

@@ -85,8 +89,3 @@ let minRadius = Infinity;

if (i === i0 || i === i1) continue;
const r = circumradius(
coords[2 * i0], coords[2 * i0 + 1],
coords[2 * i1], coords[2 * i1 + 1],
coords[2 * i], coords[2 * i + 1]);
const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
if (r < minRadius) {

@@ -97,2 +96,4 @@ i2 = i;

}
let i2x = coords[2 * i2];
let i2y = coords[2 * i2 + 1];

@@ -104,18 +105,14 @@ if (minRadius === Infinity) {

// swap the order of the seed points for counter-clockwise orientation
if (area(coords[2 * i0], coords[2 * i0 + 1],
coords[2 * i1], coords[2 * i1 + 1],
coords[2 * i2], coords[2 * i2 + 1]) < 0) {
const tmp = i1;
if (orient(i0x, i0y, i1x, i1y, i2x, i2y)) {
const i = i1;
const x = i1x;
const y = i1y;
i1 = i2;
i2 = tmp;
i1x = i2x;
i1y = i2y;
i2 = i;
i2x = x;
i2y = y;
}
const i0x = coords[2 * i0];
const i0y = coords[2 * i0 + 1];
const i1x = coords[2 * i1];
const i1y = coords[2 * i1 + 1];
const i2x = coords[2 * i2];
const i2y = coords[2 * i2 + 1];
const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);

@@ -130,4 +127,3 @@ this._cx = center.x;

this._hashSize = Math.ceil(Math.sqrt(n));
this._hash = [];
for (let i = 0; i < this._hashSize; i++) this._hash[i] = null;
this._hash = new Array(this._hashSize);

@@ -153,4 +149,4 @@ // initialize a circular doubly-linked list that will hold an advancing convex hull

for (let k = 0, xp, yp; k < ids.length; k++) {
const i = ids[k];
let xp, yp;
for (const i of ids) {
const x = coords[2 * i];

@@ -165,5 +161,3 @@ const y = coords[2 * i + 1];

// skip seed triangle points
if ((x === i0x && y === i0y) ||
(x === i1x && y === i1y) ||
(x === i2x && y === i2y)) continue;
if (i === i0 || i === i1 || i === i2) continue;

@@ -181,8 +175,11 @@ // find a visible edge on the convex hull using edge hash

e = start;
while (area(x, y, e.x, e.y, e.next.x, e.next.y) >= 0) {
while (!orient(x, y, e.x, e.y, e.next.x, e.next.y)) {
e = e.next;
if (e === start) {
throw new Error('Something is wrong with the input points.');
e = null;
break;
}
}
// likely a near-duplicate point; skip it
if (!e) continue;

@@ -202,3 +199,3 @@ const walkBack = e === start;

let q = e.next;
while (area(x, y, q.x, q.y, q.next.x, q.next.y) < 0) {
while (orient(x, y, q.x, q.y, q.next.x, q.next.y)) {
t = this._addTriangle(q.i, i, q.next.i, q.prev.t, -1, q.t);

@@ -213,3 +210,3 @@ q.prev.t = this._legalize(t + 2);

q = e.prev;
while (area(x, y, q.prev.x, q.prev.y, q.x, q.y) < 0) {
while (orient(x, y, q.prev.x, q.prev.y, q.x, q.y)) {
t = this._addTriangle(q.prev.i, i, q.i, -1, q.t, q.prev.t);

@@ -346,4 +343,4 @@ this._legalize(t + 2);

function area(px, py, qx, qy, rx, ry) {
return (qy - py) * (rx - qx) - (qx - px) * (ry - qy);
function orient(px, py, qx, qy, rx, ry) {
return (qy - py) * (rx - qx) - (qx - px) * (ry - qy) < 0;
}

@@ -350,0 +347,0 @@

@@ -1,3 +0,3 @@

// https://github.com/d3/d3-delaunay v4.1.3 Copyright 2018 Mike Bostock
// https://github.com/mapbox/delaunator v2.0.3. Copyright 2017 Mapbox, Inc.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.d3=t.d3||{})}(this,function(t){"use strict";class e{static from(t,i,n){i||(i=a),n||(n=c);const s=t.length,h=new Float64Array(2*s);for(let e=0;e<s;e++){const s=t[e];h[2*e]=i(s),h[2*e+1]=n(s)}return new e(h)}constructor(t){let e=1/0,a=1/0,c=-1/0,u=-1/0;const f=t.length>>1,x=this.ids=new Uint32Array(f);if(f>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;for(let i=0;i<f;i++){const n=t[2*i],s=t[2*i+1];n<e&&(e=n),s<a&&(a=s),n>c&&(c=n),s>u&&(u=s),x[i]=i}const g=(e+c)/2,d=(a+u)/2;let _,y,m,p=1/0;for(let e=0;e<f;e++){const n=i(g,d,t[2*e],t[2*e+1]);n<p&&(_=e,p=n)}p=1/0;for(let e=0;e<f;e++){if(e===_)continue;const n=i(t[2*_],t[2*_+1],t[2*e],t[2*e+1]);n<p&&n>0&&(y=e,p=n)}let v=1/0;for(let e=0;e<f;e++){if(e===_||e===y)continue;const i=s(t[2*_],t[2*_+1],t[2*y],t[2*y+1],t[2*e],t[2*e+1]);i<v&&(m=e,v=i)}if(v===1/0)throw new Error("No Delaunay triangulation exists for this input.");if(n(t[2*_],t[2*_+1],t[2*y],t[2*y+1],t[2*m],t[2*m+1])<0){const t=y;y=m,m=t}const w=t[2*_],T=t[2*_+1],b=t[2*y],$=t[2*y+1],M=t[2*m],P=t[2*m+1],k=function(t,e,i,n,s,h){const r=i-t,l=n-e,o=s-t,a=h-e,c=r*r+l*l,u=o*o+a*a,f=r*a-l*o;return{x:t+.5*(a*c-l*u)/f,y:e+.5*(r*u-o*c)/f}}(w,T,b,$,M,P);this._cx=k.x,this._cy=k.y,function t(e,i,n,s,h,r){let a,c,u;if(s-n<=20)for(a=n+1;a<=s;a++){for(u=e[a],c=a-1;c>=n&&l(i,e[c],u,h,r)>0;)e[c+1]=e[c--];e[c+1]=u}else{const f=n+s>>1;for(c=s,o(e,f,a=n+1),l(i,e[n],e[s],h,r)>0&&o(e,n,s),l(i,e[a],e[s],h,r)>0&&o(e,a,s),l(i,e[n],e[a],h,r)>0&&o(e,n,a),u=e[a];;){do{a++}while(l(i,e[a],u,h,r)<0);do{c--}while(l(i,e[c],u,h,r)>0);if(c<a)break;o(e,a,c)}e[n+1]=e[c],e[c]=u,s-a+1>=c-n?(t(e,i,a,s,h,r),t(e,i,n,c-1,h,r)):(t(e,i,n,c-1,h,r),t(e,i,a,s,h,r))}}(x,t,0,x.length-1,k.x,k.y),this._hashSize=Math.ceil(Math.sqrt(f)),this._hash=[];for(let t=0;t<this._hashSize;t++)this._hash[t]=null;let A=this.hull=h(t,_);this._hashEdge(A),A.t=0,A=h(t,y,A),this._hashEdge(A),A.t=1,A=h(t,m,A),this._hashEdge(A),A.t=2;const E=2*f-5,S=this.triangles=new Uint32Array(3*E),z=this.halfedges=new Int32Array(3*E);this.trianglesLen=0,this._addTriangle(_,y,m,-1,-1,-1);for(let e,i,s=0;s<x.length;s++){const l=x[s],o=t[2*l],a=t[2*l+1];if(o===e&&a===i)continue;if(e=o,i=a,o===w&&a===T||o===b&&a===$||o===M&&a===P)continue;const c=this._hashKey(o,a);let u,f=c;do{u=this._hash[f],f=(f+1)%this._hashSize}while((!u||u.removed)&&f!==c);for(A=u=u.prev;n(o,a,A.x,A.y,A.next.x,A.next.y)>=0;)if((A=A.next)===u)throw new Error("Something is wrong with the input points.");const g=A===u;let d=this._addTriangle(A.i,l,A.next.i,-1,-1,A.t);A.t=d,(A=h(t,l,A)).t=this._legalize(d+2);let _=A.next;for(;n(o,a,_.x,_.y,_.next.x,_.next.y)<0;)d=this._addTriangle(_.i,l,_.next.i,_.prev.t,-1,_.t),_.prev.t=this._legalize(d+2),this.hull=r(_),_=_.next;if(g)for(_=A.prev;n(o,a,_.prev.x,_.prev.y,_.x,_.y)<0;)d=this._addTriangle(_.prev.i,l,_.i,-1,_.t,_.prev.t),this._legalize(d+2),_.prev.t=d,this.hull=r(_),_=_.prev;this._hashEdge(A),this._hashEdge(A.prev)}this.triangles=S.subarray(0,this.trianglesLen),this.halfedges=z.subarray(0,this.trianglesLen)}_hashEdge(t){this._hash[this._hashKey(t.x,t.y)]=t}_hashKey(t,e){return Math.floor(function(t,e){const i=t/(Math.abs(t)+Math.abs(e));return(e>0?3-i:1+i)/4}(t-this._cx,e-this._cy)*this._hashSize)}_legalize(t){const{triangles:e,coords:i,halfedges:n}=this,s=n[t],h=t-t%3,r=s-s%3,l=h+(t+1)%3,o=h+(t+2)%3,a=r+(s+2)%3;if(-1===s)return o;const c=e[o],u=e[t],f=e[l],x=e[a];if(function(t,e,i,n,s,h,r,l){const o=t-r,a=e-l,c=i-r,u=n-l,f=s-r,x=h-l,g=c*c+u*u,d=f*f+x*x;return o*(u*d-g*x)-a*(c*d-g*f)+(o*o+a*a)*(c*x-u*f)<0}(i[2*c],i[2*c+1],i[2*u],i[2*u+1],i[2*f],i[2*f+1],i[2*x],i[2*x+1])){e[t]=x,e[s]=c;const i=n[a];if(-1===i){let e=this.hull;do{if(e.t===a){e.t=t;break}e=e.next}while(e!==this.hull)}this._link(t,i),this._link(s,n[o]),this._link(o,a);const h=r+(s+1)%3;return this._legalize(t),this._legalize(h)}return o}_link(t,e){this.halfedges[t]=e,-1!==e&&(this.halfedges[e]=t)}_addTriangle(t,e,i,n,s,h){const r=this.trianglesLen;return this.triangles[r]=t,this.triangles[r+1]=e,this.triangles[r+2]=i,this._link(r,n),this._link(r+1,s),this._link(r+2,h),this.trianglesLen+=3,r}}function i(t,e,i,n){const s=t-i,h=e-n;return s*s+h*h}function n(t,e,i,n,s,h){return(n-e)*(s-i)-(i-t)*(h-n)}function s(t,e,i,n,s,h){const r=i-t,l=n-e,o=s-t,a=h-e,c=r*r+l*l,u=o*o+a*a,f=r*a-l*o,x=.5*(a*c-l*u)/f,g=.5*(r*u-o*c)/f;return c&&u&&f&&x*x+g*g||1/0}function h(t,e,i){const n={i:e,x:t[2*e],y:t[2*e+1],t:0,prev:null,next:null,removed:!1};return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function r(t){return t.prev.next=t.next,t.next.prev=t.prev,t.removed=!0,t.prev}function l(t,e,n,s,h){return i(t[2*e],t[2*e+1],s,h)-i(t[2*n],t[2*n+1],s,h)||t[2*e]-t[2*n]||t[2*e+1]-t[2*n+1]}function o(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}function a(t){return t[0]}function c(t){return t[1]}const u=1e-6;class f{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,i){const n=(t=+t)+(i=+i),s=e=+e;if(i<0)throw new Error("negative radius");null===this._x1?this._+=`M${n},${s}`:(Math.abs(this._x1-n)>u||Math.abs(this._y1-s)>u)&&(this._+="L"+n+","+s),i&&(this._+=`A${i},${i},0,1,1,${t-i},${e}A${i},${i},0,1,1,${this._x1=n},${this._y1=s}`)}rect(t,e,i,n){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+i}v${+n}h${-i}Z`}value(){return this._||null}}class x{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class g{constructor(t,[e,i,n,s]=[0,0,960,500]){if(!((n=+n)>=(e=+e)&&(s=+s)>=(i=+i)))throw new Error("invalid bounds");const{points:h,hull:r,triangles:l}=this.delaunay=t,o=this.circumcenters=new Float64Array(l.length/3*2),a=this.vectors=new Float64Array(2*h.length);this.xmax=n,this.xmin=e,this.ymax=s,this.ymin=i;for(let t=0,e=0,i=l.length;t<i;t+=3,e+=2){const i=2*l[t],n=2*l[t+1],s=2*l[t+2],r=h[i],a=h[i+1],c=h[n],u=h[n+1],f=h[s],x=h[s+1],g=r-c,d=r-f,_=a-u,y=a-x,m=r*r+a*a,p=m-c*c-u*u,v=m-f*f-x*x,w=2*(d*_-g*y);o[e]=(_*v-y*p)/w,o[e+1]=(d*p-g*v)/w}let c,u,f,x=r,g=4*x.i,d=x.x,_=x.y;do{c=g,u=d,f=_,g=4*(x=x.next).i,d=x.x,_=x.y,a[c+2]=a[g]=f-_,a[c+3]=a[g+1]=d-u}while(x!==r)}render(t){const e=null==t?t=new f:void 0,{delaunay:{halfedges:i,hull:n},circumcenters:s,vectors:h}=this;for(let e=0,n=i.length;e<n;++e){const n=i[e];if(n<e)continue;const h=2*Math.floor(e/3),r=2*Math.floor(n/3),l=s[h],o=s[h+1],a=s[r],c=s[r+1];this._renderSegment(l,o,a,c,t)}let r=n;do{r=r.next;const e=2*Math.floor(r.t/3),i=s[e],n=s[e+1],l=4*r.i,o=this._project(i,n,h[l+2],h[l+3]);o&&this._renderSegment(i,n,o[0],o[1],t)}while(r!==n);return e&&e.value()}renderBounds(t){const e=null==t?t=new f:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const i=null==e?e=new f:void 0,n=this._clip(t);if(null!==n){e.moveTo(n[0],n[1]);for(let t=2,i=n.length;t<i;t+=2)e.lineTo(n[t],n[t+1]);return e.closePath(),i&&i.value()}}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,i=t.length/2;e<i;++e){const t=this.cellPolygon(e);t&&(yield t)}}cellPolygon(t){const e=new x;return this.renderCell(t,e),e.value()}_renderSegment(t,e,i,n,s){let h;const r=this._regioncode(t,e),l=this._regioncode(i,n);0===r&&0===l?(s.moveTo(t,e),s.lineTo(i,n)):(h=this._clipSegment(t,e,i,n,r,l))&&(s.moveTo(h[0],h[1]),s.lineTo(h[2],h[3]))}contains(t,e,i){return(e=+e)==e&&(i=+i)==i&&this.delaunay._step(t,e,i)===t}_cell(t){const{circumcenters:e,delaunay:{inedges:i,halfedges:n,triangles:s}}=this,h=i[t];if(-1===h)return null;const r=[];let l=h;do{const i=Math.floor(l/3);if(r.push(e[2*i],e[2*i+1]),s[l=l%3==2?l-2:l+1]!==t)break;l=n[l]}while(l!==h&&-1!==l);return r}_clip(t){const e=this._cell(t);if(null===e)return null;const{vectors:i}=this,n=4*t;return i[n]||i[n+1]?this._clipInfinite(t,e,i[n],i[n+1],i[n+2],i[n+3]):this._clipFinite(t,e)}_clipFinite(t,e){const i=e.length;let n,s,h,r,l,o=null,a=e[i-2],c=e[i-1],u=this._regioncode(a,c);for(let f=0;f<i;f+=2)if(n=a,s=c,a=e[f],c=e[f+1],h=u,u=this._regioncode(a,c),0===h&&0===u)r=l,l=0,o?o.push(a,c):o=[a,c];else{let e,i,f,x,g;if(0===h){if(null===(e=this._clipSegment(n,s,a,c,h,u)))continue;[i,f,x,g]=e}else{if(null===(e=this._clipSegment(a,c,n,s,u,h)))continue;[x,g,i,f]=e,r=l,l=this._edgecode(i,f),r&&l&&this._edge(t,r,l,o,o.length),o?o.push(i,f):o=[i,f]}r=l,l=this._edgecode(x,g),r&&l&&this._edge(t,r,l,o,o.length),o?o.push(x,g):o=[x,g]}if(o)r=l,l=this._edgecode(o[0],o[1]),r&&l&&this._edge(t,r,l,o,o.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return o}_clipSegment(t,e,i,n,s,h){for(;;){if(0===s&&0===h)return[t,e,i,n];if(s&h)return null;let r,l,o=s||h;8&o?(r=t+(i-t)*(this.ymax-e)/(n-e),l=this.ymax):4&o?(r=t+(i-t)*(this.ymin-e)/(n-e),l=this.ymin):2&o?(l=e+(n-e)*(this.xmax-t)/(i-t),r=this.xmax):(l=e+(n-e)*(this.xmin-t)/(i-t),r=this.xmin),s?(t=r,e=l,s=this._regioncode(t,e)):(i=r,n=l,h=this._regioncode(i,n))}}_clipInfinite(t,e,i,n,s,h){let r,l=Array.from(e);if((r=this._project(l[0],l[1],i,n))&&l.unshift(r[0],r[1]),(r=this._project(l[l.length-2],l[l.length-1],s,h))&&l.push(r[0],r[1]),l=this._clipFinite(t,l))for(let e,i=0,n=l.length,s=this._edgecode(l[n-2],l[n-1]);i<n;i+=2)e=s,s=this._edgecode(l[i],l[i+1]),e&&s&&(i=this._edge(t,e,s,l,i),n=l.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(l=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return l}_edge(t,e,i,n,s){for(;e!==i;){let i,h;switch(e){case 5:e=4;continue;case 4:e=6,i=this.xmax,h=this.ymin;break;case 6:e=2;continue;case 2:e=10,i=this.xmax,h=this.ymax;break;case 10:e=8;continue;case 8:e=9,i=this.xmin,h=this.ymax;break;case 9:e=1;continue;case 1:e=5,i=this.xmin,h=this.ymin}n[s]===i&&n[s+1]===h||!this.contains(t,i,h)||(n.splice(s,0,i,h),s+=2)}return s}_project(t,e,i,n){let s,h,r,l=1/0;if(n<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/n)<l&&(r=this.ymin,h=t+(l=s)*i)}else if(n>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/n)<l&&(r=this.ymax,h=t+(l=s)*i)}if(i>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/i)<l&&(h=this.xmax,r=e+(l=s)*n)}else if(i<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/i)<l&&(h=this.xmin,r=e+(l=s)*n)}return[h,r]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const d=2*Math.PI;class _{constructor(t){const{halfedges:i,hull:n,triangles:s}=new e(t);this.points=t,this.halfedges=i,this.hull=n,this.triangles=s;const h=this.inedges=new Int32Array(t.length/2).fill(-1),r=this.outedges=new Int32Array(t.length/2).fill(-1);for(let t=0,e=i.length;t<e;++t)h[s[t%3==2?t-2:t+1]]=t;let l,o=n;do{l=o,h[(o=o.next).i]=l.t,r[l.i]=o.t}while(o!==n)}voronoi(t){return new g(this,t)}*neighbors(t){const{inedges:e,outedges:i,halfedges:n,triangles:s}=this,h=e[t];if(-1===h)return;let r=h;do{if(yield s[r],s[r=r%3==2?r-2:r+1]!==t)return;if(-1===(r=n[r]))return yield s[i[t]]}while(r!==h)}find(t,e,i=0){if((t=+t)!=t||(e=+e)!=e)return-1;let n;for(;(n=this._step(i,t,e))>=0&&n!==i;)i=n;return n}_step(t,e,i){const{inedges:n,points:s}=this;if(-1===n[t])return-1;let h=t,r=(e-s[2*t])**2+(i-s[2*t+1])**2;for(const n of this.neighbors(t)){const t=(e-s[2*n])**2+(i-s[2*n+1])**2;t<r&&(r=t,h=n)}return h}render(t){const e=null==t?t=new f:void 0,{points:i,halfedges:n,triangles:s}=this;for(let e=0,h=n.length;e<h;++e){const h=n[e];if(h<e)continue;const r=2*s[e],l=2*s[h];t.moveTo(i[r],i[r+1]),t.lineTo(i[l],i[l+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e=2){const i=null==t?t=new f:void 0,{points:n}=this;for(let i=0,s=n.length;i<s;i+=2){const s=n[i],h=n[i+1];t.moveTo(s+e,h),t.arc(s,h,e,0,d)}return i&&i.value()}renderHull(t){const e=null==t?t=new f:void 0,{hull:i}=this;let n=i;for(t.moveTo(n.x,n.y);(n=n.next)!==i;)t.lineTo(n.x,n.y);return t.closePath(),e&&e.value()}hullPolygon(){const t=new x;return this.renderHull(t),t.value()}renderTriangle(t,e){const i=null==e?e=new f:void 0,{points:n,triangles:s}=this,h=2*s[t*=3],r=2*s[t+1],l=2*s[t+2];return e.moveTo(n[h],n[h+1]),e.lineTo(n[r],n[r+1]),e.lineTo(n[l],n[l+1]),e.closePath(),i&&i.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,i=t.length/3;e<i;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new x;return this.renderTriangle(t,e),e.value()}}_.from=function(t,e=function(t){return t[0]},i=function(t){return t[1]},n){return new _("length"in t?function(t,e,i,n){const s=t.length,h=new Float64Array(2*s);for(let r=0;r<s;++r){const s=t[r];h[2*r]=e.call(n,s,r,t),h[2*r+1]=i.call(n,s,r,t)}return h}(t,e,i,n):Float64Array.from(function*(t,e,i,n){let s=0;for(const h of t)yield e.call(n,h,s,t),yield i.call(n,h,s,t),++s}(t,e,i,n)))},t.Delaunay=_,t.Voronoi=g,Object.defineProperty(t,"__esModule",{value:!0})});
// https://github.com/d3/d3-delaunay v4.1.4 Copyright 2018 Mike Bostock
// https://github.com/mapbox/delaunator v2.0.4. Copyright 2017 Mapbox, Inc.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.d3=t.d3||{})}(this,function(t){"use strict";class e{static from(t,i,n){i||(i=a),n||(n=c);const s=t.length,h=new Float64Array(2*s);for(let e=0;e<s;e++){const s=t[e];h[2*e]=i(s),h[2*e+1]=n(s)}return new e(h)}constructor(t){let e=1/0,a=1/0,c=-1/0,u=-1/0;const f=t.length>>1,x=this.ids=new Uint32Array(f);if(f>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;for(let i=0;i<f;i++){const n=t[2*i],s=t[2*i+1];n<e&&(e=n),s<a&&(a=s),n>c&&(c=n),s>u&&(u=s),x[i]=i}const d=(e+c)/2,_=(a+u)/2;let g,y,m,p=1/0;for(let e=0;e<f;e++){const n=i(d,_,t[2*e],t[2*e+1]);n<p&&(g=e,p=n)}const v=t[2*g],w=t[2*g+1];p=1/0;for(let e=0;e<f;e++){if(e===g)continue;const n=i(v,w,t[2*e],t[2*e+1]);n<p&&n>0&&(y=e,p=n)}let T=t[2*y],b=t[2*y+1],$=1/0;for(let e=0;e<f;e++){if(e===g||e===y)continue;const i=s(v,w,T,b,t[2*e],t[2*e+1]);i<$&&(m=e,$=i)}let M=t[2*m],P=t[2*m+1];if($===1/0)throw new Error("No Delaunay triangulation exists for this input.");if(n(v,w,T,b,M,P)){const t=y,e=T,i=b;y=m,T=M,b=P,m=t,M=e,P=i}const k=function(t,e,i,n,s,h){const r=i-t,l=n-e,o=s-t,a=h-e,c=r*r+l*l,u=o*o+a*a,f=r*a-l*o;return{x:t+.5*(a*c-l*u)/f,y:e+.5*(r*u-o*c)/f}}(v,w,T,b,M,P);this._cx=k.x,this._cy=k.y,function t(e,i,n,s,h,r){let a,c,u;if(s-n<=20)for(a=n+1;a<=s;a++){for(u=e[a],c=a-1;c>=n&&l(i,e[c],u,h,r)>0;)e[c+1]=e[c--];e[c+1]=u}else{const f=n+s>>1;for(c=s,o(e,f,a=n+1),l(i,e[n],e[s],h,r)>0&&o(e,n,s),l(i,e[a],e[s],h,r)>0&&o(e,a,s),l(i,e[n],e[a],h,r)>0&&o(e,n,a),u=e[a];;){do{a++}while(l(i,e[a],u,h,r)<0);do{c--}while(l(i,e[c],u,h,r)>0);if(c<a)break;o(e,a,c)}e[n+1]=e[c],e[c]=u,s-a+1>=c-n?(t(e,i,a,s,h,r),t(e,i,n,c-1,h,r)):(t(e,i,n,c-1,h,r),t(e,i,a,s,h,r))}}(x,t,0,x.length-1,k.x,k.y),this._hashSize=Math.ceil(Math.sqrt(f)),this._hash=new Array(this._hashSize);let A=this.hull=h(t,g);this._hashEdge(A),A.t=0,A=h(t,y,A),this._hashEdge(A),A.t=1,A=h(t,m,A),this._hashEdge(A),A.t=2;const E=2*f-5,S=this.triangles=new Uint32Array(3*E),z=this.halfedges=new Int32Array(3*E);let F,L;this.trianglesLen=0,this._addTriangle(g,y,m,-1,-1,-1);for(const e of x){const i=t[2*e],s=t[2*e+1];if(i===F&&s===L)continue;if(F=i,L=s,e===g||e===y||e===m)continue;const l=this._hashKey(i,s);let o,a=l;do{o=this._hash[a],a=(a+1)%this._hashSize}while((!o||o.removed)&&a!==l);for(A=o=o.prev;!n(i,s,A.x,A.y,A.next.x,A.next.y);)if((A=A.next)===o){A=null;break}if(!A)continue;const c=A===o;let u=this._addTriangle(A.i,e,A.next.i,-1,-1,A.t);A.t=u,(A=h(t,e,A)).t=this._legalize(u+2);let f=A.next;for(;n(i,s,f.x,f.y,f.next.x,f.next.y);)u=this._addTriangle(f.i,e,f.next.i,f.prev.t,-1,f.t),f.prev.t=this._legalize(u+2),this.hull=r(f),f=f.next;if(c)for(f=A.prev;n(i,s,f.prev.x,f.prev.y,f.x,f.y);)u=this._addTriangle(f.prev.i,e,f.i,-1,f.t,f.prev.t),this._legalize(u+2),f.prev.t=u,this.hull=r(f),f=f.prev;this._hashEdge(A),this._hashEdge(A.prev)}this.triangles=S.subarray(0,this.trianglesLen),this.halfedges=z.subarray(0,this.trianglesLen)}_hashEdge(t){this._hash[this._hashKey(t.x,t.y)]=t}_hashKey(t,e){return Math.floor(function(t,e){const i=t/(Math.abs(t)+Math.abs(e));return(e>0?3-i:1+i)/4}(t-this._cx,e-this._cy)*this._hashSize)}_legalize(t){const{triangles:e,coords:i,halfedges:n}=this,s=n[t],h=t-t%3,r=s-s%3,l=h+(t+1)%3,o=h+(t+2)%3,a=r+(s+2)%3;if(-1===s)return o;const c=e[o],u=e[t],f=e[l],x=e[a];if(function(t,e,i,n,s,h,r,l){const o=t-r,a=e-l,c=i-r,u=n-l,f=s-r,x=h-l,d=c*c+u*u,_=f*f+x*x;return o*(u*_-d*x)-a*(c*_-d*f)+(o*o+a*a)*(c*x-u*f)<0}(i[2*c],i[2*c+1],i[2*u],i[2*u+1],i[2*f],i[2*f+1],i[2*x],i[2*x+1])){e[t]=x,e[s]=c;const i=n[a];if(-1===i){let e=this.hull;do{if(e.t===a){e.t=t;break}e=e.next}while(e!==this.hull)}this._link(t,i),this._link(s,n[o]),this._link(o,a);const h=r+(s+1)%3;return this._legalize(t),this._legalize(h)}return o}_link(t,e){this.halfedges[t]=e,-1!==e&&(this.halfedges[e]=t)}_addTriangle(t,e,i,n,s,h){const r=this.trianglesLen;return this.triangles[r]=t,this.triangles[r+1]=e,this.triangles[r+2]=i,this._link(r,n),this._link(r+1,s),this._link(r+2,h),this.trianglesLen+=3,r}}function i(t,e,i,n){const s=t-i,h=e-n;return s*s+h*h}function n(t,e,i,n,s,h){return(n-e)*(s-i)-(i-t)*(h-n)<0}function s(t,e,i,n,s,h){const r=i-t,l=n-e,o=s-t,a=h-e,c=r*r+l*l,u=o*o+a*a,f=r*a-l*o,x=.5*(a*c-l*u)/f,d=.5*(r*u-o*c)/f;return c&&u&&f&&x*x+d*d||1/0}function h(t,e,i){const n={i:e,x:t[2*e],y:t[2*e+1],t:0,prev:null,next:null,removed:!1};return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function r(t){return t.prev.next=t.next,t.next.prev=t.prev,t.removed=!0,t.prev}function l(t,e,n,s,h){return i(t[2*e],t[2*e+1],s,h)-i(t[2*n],t[2*n+1],s,h)||t[2*e]-t[2*n]||t[2*e+1]-t[2*n+1]}function o(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}function a(t){return t[0]}function c(t){return t[1]}const u=1e-6;class f{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,i){const n=(t=+t)+(i=+i),s=e=+e;if(i<0)throw new Error("negative radius");null===this._x1?this._+=`M${n},${s}`:(Math.abs(this._x1-n)>u||Math.abs(this._y1-s)>u)&&(this._+="L"+n+","+s),i&&(this._+=`A${i},${i},0,1,1,${t-i},${e}A${i},${i},0,1,1,${this._x1=n},${this._y1=s}`)}rect(t,e,i,n){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+i}v${+n}h${-i}Z`}value(){return this._||null}}class x{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class d{constructor(t,[e,i,n,s]=[0,0,960,500]){if(!((n=+n)>=(e=+e)&&(s=+s)>=(i=+i)))throw new Error("invalid bounds");const{points:h,hull:r,triangles:l}=this.delaunay=t,o=this.circumcenters=new Float64Array(l.length/3*2),a=this.vectors=new Float64Array(2*h.length);this.xmax=n,this.xmin=e,this.ymax=s,this.ymin=i;for(let t=0,e=0,i=l.length;t<i;t+=3,e+=2){const i=2*l[t],n=2*l[t+1],s=2*l[t+2],r=h[i],a=h[i+1],c=h[n],u=h[n+1],f=h[s],x=h[s+1],d=r-c,_=r-f,g=a-u,y=a-x,m=r*r+a*a,p=m-c*c-u*u,v=m-f*f-x*x,w=2*(_*g-d*y);o[e]=(g*v-y*p)/w,o[e+1]=(_*p-d*v)/w}let c,u,f,x=r,d=4*x.i,_=x.x,g=x.y;do{c=d,u=_,f=g,d=4*(x=x.next).i,_=x.x,g=x.y,a[c+2]=a[d]=f-g,a[c+3]=a[d+1]=_-u}while(x!==r)}render(t){const e=null==t?t=new f:void 0,{delaunay:{halfedges:i,hull:n},circumcenters:s,vectors:h}=this;for(let e=0,n=i.length;e<n;++e){const n=i[e];if(n<e)continue;const h=2*Math.floor(e/3),r=2*Math.floor(n/3),l=s[h],o=s[h+1],a=s[r],c=s[r+1];this._renderSegment(l,o,a,c,t)}let r=n;do{r=r.next;const e=2*Math.floor(r.t/3),i=s[e],n=s[e+1],l=4*r.i,o=this._project(i,n,h[l+2],h[l+3]);o&&this._renderSegment(i,n,o[0],o[1],t)}while(r!==n);return e&&e.value()}renderBounds(t){const e=null==t?t=new f:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const i=null==e?e=new f:void 0,n=this._clip(t);if(null!==n){e.moveTo(n[0],n[1]);for(let t=2,i=n.length;t<i;t+=2)e.lineTo(n[t],n[t+1]);return e.closePath(),i&&i.value()}}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,i=t.length/2;e<i;++e){const t=this.cellPolygon(e);t&&(yield t)}}cellPolygon(t){const e=new x;return this.renderCell(t,e),e.value()}_renderSegment(t,e,i,n,s){let h;const r=this._regioncode(t,e),l=this._regioncode(i,n);0===r&&0===l?(s.moveTo(t,e),s.lineTo(i,n)):(h=this._clipSegment(t,e,i,n,r,l))&&(s.moveTo(h[0],h[1]),s.lineTo(h[2],h[3]))}contains(t,e,i){return(e=+e)==e&&(i=+i)==i&&this.delaunay._step(t,e,i)===t}_cell(t){const{circumcenters:e,delaunay:{inedges:i,halfedges:n,triangles:s}}=this,h=i[t];if(-1===h)return null;const r=[];let l=h;do{const i=Math.floor(l/3);if(r.push(e[2*i],e[2*i+1]),s[l=l%3==2?l-2:l+1]!==t)break;l=n[l]}while(l!==h&&-1!==l);return r}_clip(t){const e=this._cell(t);if(null===e)return null;const{vectors:i}=this,n=4*t;return i[n]||i[n+1]?this._clipInfinite(t,e,i[n],i[n+1],i[n+2],i[n+3]):this._clipFinite(t,e)}_clipFinite(t,e){const i=e.length;let n,s,h,r,l,o=null,a=e[i-2],c=e[i-1],u=this._regioncode(a,c);for(let f=0;f<i;f+=2)if(n=a,s=c,a=e[f],c=e[f+1],h=u,u=this._regioncode(a,c),0===h&&0===u)r=l,l=0,o?o.push(a,c):o=[a,c];else{let e,i,f,x,d;if(0===h){if(null===(e=this._clipSegment(n,s,a,c,h,u)))continue;[i,f,x,d]=e}else{if(null===(e=this._clipSegment(a,c,n,s,u,h)))continue;[x,d,i,f]=e,r=l,l=this._edgecode(i,f),r&&l&&this._edge(t,r,l,o,o.length),o?o.push(i,f):o=[i,f]}r=l,l=this._edgecode(x,d),r&&l&&this._edge(t,r,l,o,o.length),o?o.push(x,d):o=[x,d]}if(o)r=l,l=this._edgecode(o[0],o[1]),r&&l&&this._edge(t,r,l,o,o.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return o}_clipSegment(t,e,i,n,s,h){for(;;){if(0===s&&0===h)return[t,e,i,n];if(s&h)return null;let r,l,o=s||h;8&o?(r=t+(i-t)*(this.ymax-e)/(n-e),l=this.ymax):4&o?(r=t+(i-t)*(this.ymin-e)/(n-e),l=this.ymin):2&o?(l=e+(n-e)*(this.xmax-t)/(i-t),r=this.xmax):(l=e+(n-e)*(this.xmin-t)/(i-t),r=this.xmin),s?(t=r,e=l,s=this._regioncode(t,e)):(i=r,n=l,h=this._regioncode(i,n))}}_clipInfinite(t,e,i,n,s,h){let r,l=Array.from(e);if((r=this._project(l[0],l[1],i,n))&&l.unshift(r[0],r[1]),(r=this._project(l[l.length-2],l[l.length-1],s,h))&&l.push(r[0],r[1]),l=this._clipFinite(t,l))for(let e,i=0,n=l.length,s=this._edgecode(l[n-2],l[n-1]);i<n;i+=2)e=s,s=this._edgecode(l[i],l[i+1]),e&&s&&(i=this._edge(t,e,s,l,i),n=l.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(l=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return l}_edge(t,e,i,n,s){for(;e!==i;){let i,h;switch(e){case 5:e=4;continue;case 4:e=6,i=this.xmax,h=this.ymin;break;case 6:e=2;continue;case 2:e=10,i=this.xmax,h=this.ymax;break;case 10:e=8;continue;case 8:e=9,i=this.xmin,h=this.ymax;break;case 9:e=1;continue;case 1:e=5,i=this.xmin,h=this.ymin}n[s]===i&&n[s+1]===h||!this.contains(t,i,h)||(n.splice(s,0,i,h),s+=2)}return s}_project(t,e,i,n){let s,h,r,l=1/0;if(n<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/n)<l&&(r=this.ymin,h=t+(l=s)*i)}else if(n>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/n)<l&&(r=this.ymax,h=t+(l=s)*i)}if(i>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/i)<l&&(h=this.xmax,r=e+(l=s)*n)}else if(i<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/i)<l&&(h=this.xmin,r=e+(l=s)*n)}return[h,r]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const _=2*Math.PI;class g{constructor(t){const{halfedges:i,hull:n,triangles:s}=new e(t);this.points=t,this.halfedges=i,this.hull=n,this.triangles=s;const h=this.inedges=new Int32Array(t.length/2).fill(-1),r=this.outedges=new Int32Array(t.length/2).fill(-1);for(let t=0,e=i.length;t<e;++t)h[s[t%3==2?t-2:t+1]]=t;let l,o=n;do{l=o,h[(o=o.next).i]=l.t,r[l.i]=o.t}while(o!==n)}voronoi(t){return new d(this,t)}*neighbors(t){const{inedges:e,outedges:i,halfedges:n,triangles:s}=this,h=e[t];if(-1===h)return;let r=h;do{if(yield s[r],s[r=r%3==2?r-2:r+1]!==t)return;if(-1===(r=n[r]))return yield s[i[t]]}while(r!==h)}find(t,e,i=0){if((t=+t)!=t||(e=+e)!=e)return-1;let n;for(;(n=this._step(i,t,e))>=0&&n!==i;)i=n;return n}_step(t,e,i){const{inedges:n,points:s}=this;if(-1===n[t])return-1;let h=t,r=(e-s[2*t])**2+(i-s[2*t+1])**2;for(const n of this.neighbors(t)){const t=(e-s[2*n])**2+(i-s[2*n+1])**2;t<r&&(r=t,h=n)}return h}render(t){const e=null==t?t=new f:void 0,{points:i,halfedges:n,triangles:s}=this;for(let e=0,h=n.length;e<h;++e){const h=n[e];if(h<e)continue;const r=2*s[e],l=2*s[h];t.moveTo(i[r],i[r+1]),t.lineTo(i[l],i[l+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e=2){const i=null==t?t=new f:void 0,{points:n}=this;for(let i=0,s=n.length;i<s;i+=2){const s=n[i],h=n[i+1];t.moveTo(s+e,h),t.arc(s,h,e,0,_)}return i&&i.value()}renderHull(t){const e=null==t?t=new f:void 0,{hull:i}=this;let n=i;for(t.moveTo(n.x,n.y);(n=n.next)!==i;)t.lineTo(n.x,n.y);return t.closePath(),e&&e.value()}hullPolygon(){const t=new x;return this.renderHull(t),t.value()}renderTriangle(t,e){const i=null==e?e=new f:void 0,{points:n,triangles:s}=this,h=2*s[t*=3],r=2*s[t+1],l=2*s[t+2];return e.moveTo(n[h],n[h+1]),e.lineTo(n[r],n[r+1]),e.lineTo(n[l],n[l+1]),e.closePath(),i&&i.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,i=t.length/3;e<i;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new x;return this.renderTriangle(t,e),e.value()}}g.from=function(t,e=function(t){return t[0]},i=function(t){return t[1]},n){return new g("length"in t?function(t,e,i,n){const s=t.length,h=new Float64Array(2*s);for(let r=0;r<s;++r){const s=t[r];h[2*r]=e.call(n,s,r,t),h[2*r+1]=i.call(n,s,r,t)}return h}(t,e,i,n):Float64Array.from(function*(t,e,i,n){let s=0;for(const h of t)yield e.call(n,h,s,t),yield i.call(n,h,s,t),++s}(t,e,i,n)))},t.Delaunay=g,t.Voronoi=d,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3-delaunay",
"version": "4.1.3",
"version": "4.1.4",
"description": "Compute the Voronoi diagram of a set of two-dimensional points.",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc