d3-quadtree
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -1,7 +0,7 @@ | ||
// https://d3js.org/d3-quadtree/ v1.0.6 Copyright 2019 Mike Bostock | ||
// https://d3js.org/d3-quadtree/ v1.0.7 Copyright 2019 Mike Bostock | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.d3 = global.d3 || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
(global = global || self, factory(global.d3 = global.d3 || {})); | ||
}(this, function (exports) { 'use strict'; | ||
@@ -419,2 +419,2 @@ function tree_add(d) { | ||
}))); | ||
})); |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-quadtree/ v1.0.6 Copyright 2019 Mike Bostock | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(t.d3=t.d3||{})}(this,function(t){"use strict";function i(t,i,r,n){if(isNaN(i)||isNaN(r))return t;var e,s,h,o,a,u,l,_,f,c=t._root,x={data:n},y=t._x0,d=t._y0,v=t._x1,p=t._y1;if(!c)return t._root=x,t;for(;c.length;)if((u=i>=(s=(y+v)/2))?y=s:v=s,(l=r>=(h=(d+p)/2))?d=h:p=h,e=c,!(c=c[_=l<<1|u]))return e[_]=x,t;if(o=+t._x.call(null,c.data),a=+t._y.call(null,c.data),i===o&&r===a)return x.next=c,e?e[_]=x:t._root=x,t;do{e=e?e[_]=new Array(4):t._root=new Array(4),(u=i>=(s=(y+v)/2))?y=s:v=s,(l=r>=(h=(d+p)/2))?d=h:p=h}while((_=l<<1|u)==(f=(a>=h)<<1|o>=s));return e[f]=c,e[_]=x,t}function r(t,i,r,n,e){this.node=t,this.x0=i,this.y0=r,this.x1=n,this.y1=e}function n(t){return t[0]}function e(t){return t[1]}function s(t,i,r){var s=new h(null==i?n:i,null==r?e:r,NaN,NaN,NaN,NaN);return null==t?s:s.addAll(t)}function h(t,i,r,n,e,s){this._x=t,this._y=i,this._x0=r,this._y0=n,this._x1=e,this._y1=s,this._root=void 0}function o(t){for(var i={data:t.data},r=i;t=t.next;)r=r.next={data:t.data};return i}var a=s.prototype=h.prototype;a.copy=function(){var t,i,r=new h(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=o(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var e=0;e<4;++e)(i=n.source[e])&&(i.length?t.push({source:i,target:n.target[e]=new Array(4)}):n.target[e]=o(i));return r},a.add=function(t){var r=+this._x.call(null,t),n=+this._y.call(null,t);return i(this.cover(r,n),r,n,t)},a.addAll=function(t){var r,n,e,s,h=t.length,o=new Array(h),a=new Array(h),u=1/0,l=1/0,_=-1/0,f=-1/0;for(n=0;n<h;++n)isNaN(e=+this._x.call(null,r=t[n]))||isNaN(s=+this._y.call(null,r))||(o[n]=e,a[n]=s,e<u&&(u=e),e>_&&(_=e),s<l&&(l=s),s>f&&(f=s));if(u>_||l>f)return this;for(this.cover(u,l).cover(_,f),n=0;n<h;++n)i(this,o[n],a[n],t[n]);return this},a.cover=function(t,i){if(isNaN(t=+t)||isNaN(i=+i))return this;var r=this._x0,n=this._y0,e=this._x1,s=this._y1;if(isNaN(r))e=(r=Math.floor(t))+1,s=(n=Math.floor(i))+1;else{for(var h,o,a=e-r,u=this._root;r>t||t>=e||n>i||i>=s;)switch(o=(i<n)<<1|t<r,(h=new Array(4))[o]=u,u=h,a*=2,o){case 0:e=r+a,s=n+a;break;case 1:r=e-a,s=n+a;break;case 2:e=r+a,n=s-a;break;case 3:r=e-a,n=s-a}this._root&&this._root.length&&(this._root=u)}return this._x0=r,this._y0=n,this._x1=e,this._y1=s,this},a.data=function(){var t=[];return this.visit(function(i){if(!i.length)do{t.push(i.data)}while(i=i.next)}),t},a.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},a.find=function(t,i,n){var e,s,h,o,a,u,l,_=this._x0,f=this._y0,c=this._x1,x=this._y1,y=[],d=this._root;for(d&&y.push(new r(d,_,f,c,x)),null==n?n=1/0:(_=t-n,f=i-n,c=t+n,x=i+n,n*=n);u=y.pop();)if(!(!(d=u.node)||(s=u.x0)>c||(h=u.y0)>x||(o=u.x1)<_||(a=u.y1)<f))if(d.length){var v=(s+o)/2,p=(h+a)/2;y.push(new r(d[3],v,p,o,a),new r(d[2],s,p,v,a),new r(d[1],v,h,o,p),new r(d[0],s,h,v,p)),(l=(i>=p)<<1|t>=v)&&(u=y[y.length-1],y[y.length-1]=y[y.length-1-l],y[y.length-1-l]=u)}else{var w=t-+this._x.call(null,d.data),N=i-+this._y.call(null,d.data),g=w*w+N*N;if(g<n){var A=Math.sqrt(n=g);_=t-A,f=i-A,c=t+A,x=i+A,e=d.data}}return e},a.remove=function(t){if(isNaN(s=+this._x.call(null,t))||isNaN(h=+this._y.call(null,t)))return this;var i,r,n,e,s,h,o,a,u,l,_,f,c=this._root,x=this._x0,y=this._y0,d=this._x1,v=this._y1;if(!c)return this;if(c.length)for(;;){if((u=s>=(o=(x+d)/2))?x=o:d=o,(l=h>=(a=(y+v)/2))?y=a:v=a,i=c,!(c=c[_=l<<1|u]))return this;if(!c.length)break;(i[_+1&3]||i[_+2&3]||i[_+3&3])&&(r=i,f=_)}for(;c.data!==t;)if(n=c,!(c=c.next))return this;return(e=c.next)&&delete c.next,n?(e?n.next=e:delete n.next,this):i?(e?i[_]=e:delete i[_],(c=i[0]||i[1]||i[2]||i[3])&&c===(i[3]||i[2]||i[1]||i[0])&&!c.length&&(r?r[f]=c:this._root=c),this):(this._root=e,this)},a.removeAll=function(t){for(var i=0,r=t.length;i<r;++i)this.remove(t[i]);return this},a.root=function(){return this._root},a.size=function(){var t=0;return this.visit(function(i){if(!i.length)do{++t}while(i=i.next)}),t},a.visit=function(t){var i,n,e,s,h,o,a=[],u=this._root;for(u&&a.push(new r(u,this._x0,this._y0,this._x1,this._y1));i=a.pop();)if(!t(u=i.node,e=i.x0,s=i.y0,h=i.x1,o=i.y1)&&u.length){var l=(e+h)/2,_=(s+o)/2;(n=u[3])&&a.push(new r(n,l,_,h,o)),(n=u[2])&&a.push(new r(n,e,_,l,o)),(n=u[1])&&a.push(new r(n,l,s,h,_)),(n=u[0])&&a.push(new r(n,e,s,l,_))}return this},a.visitAfter=function(t){var i,n=[],e=[];for(this._root&&n.push(new r(this._root,this._x0,this._y0,this._x1,this._y1));i=n.pop();){var s=i.node;if(s.length){var h,o=i.x0,a=i.y0,u=i.x1,l=i.y1,_=(o+u)/2,f=(a+l)/2;(h=s[0])&&n.push(new r(h,o,a,_,f)),(h=s[1])&&n.push(new r(h,_,a,u,f)),(h=s[2])&&n.push(new r(h,o,f,_,l)),(h=s[3])&&n.push(new r(h,_,f,u,l))}e.push(i)}for(;i=e.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this},a.x=function(t){return arguments.length?(this._x=t,this):this._x},a.y=function(t){return arguments.length?(this._y=t,this):this._y},t.quadtree=s,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-quadtree/ v1.0.7 Copyright 2019 Mike Bostock | ||
!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";function i(t,i,r,e){if(isNaN(i)||isNaN(r))return t;var n,s,h,o,a,u,l,_,f,c=t._root,x={data:e},y=t._x0,d=t._y0,v=t._x1,p=t._y1;if(!c)return t._root=x,t;for(;c.length;)if((u=i>=(s=(y+v)/2))?y=s:v=s,(l=r>=(h=(d+p)/2))?d=h:p=h,n=c,!(c=c[_=l<<1|u]))return n[_]=x,t;if(o=+t._x.call(null,c.data),a=+t._y.call(null,c.data),i===o&&r===a)return x.next=c,n?n[_]=x:t._root=x,t;do{n=n?n[_]=new Array(4):t._root=new Array(4),(u=i>=(s=(y+v)/2))?y=s:v=s,(l=r>=(h=(d+p)/2))?d=h:p=h}while((_=l<<1|u)==(f=(a>=h)<<1|o>=s));return n[f]=c,n[_]=x,t}function r(t,i,r,e,n){this.node=t,this.x0=i,this.y0=r,this.x1=e,this.y1=n}function e(t){return t[0]}function n(t){return t[1]}function s(t,i,r){var s=new h(null==i?e:i,null==r?n:r,NaN,NaN,NaN,NaN);return null==t?s:s.addAll(t)}function h(t,i,r,e,n,s){this._x=t,this._y=i,this._x0=r,this._y0=e,this._x1=n,this._y1=s,this._root=void 0}function o(t){for(var i={data:t.data},r=i;t=t.next;)r=r.next={data:t.data};return i}var a=s.prototype=h.prototype;a.copy=function(){var t,i,r=new h(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root;if(!e)return r;if(!e.length)return r._root=o(e),r;for(t=[{source:e,target:r._root=new Array(4)}];e=t.pop();)for(var n=0;n<4;++n)(i=e.source[n])&&(i.length?t.push({source:i,target:e.target[n]=new Array(4)}):e.target[n]=o(i));return r},a.add=function(t){var r=+this._x.call(null,t),e=+this._y.call(null,t);return i(this.cover(r,e),r,e,t)},a.addAll=function(t){var r,e,n,s,h=t.length,o=new Array(h),a=new Array(h),u=1/0,l=1/0,_=-1/0,f=-1/0;for(e=0;e<h;++e)isNaN(n=+this._x.call(null,r=t[e]))||isNaN(s=+this._y.call(null,r))||(o[e]=n,a[e]=s,n<u&&(u=n),n>_&&(_=n),s<l&&(l=s),s>f&&(f=s));if(u>_||l>f)return this;for(this.cover(u,l).cover(_,f),e=0;e<h;++e)i(this,o[e],a[e],t[e]);return this},a.cover=function(t,i){if(isNaN(t=+t)||isNaN(i=+i))return this;var r=this._x0,e=this._y0,n=this._x1,s=this._y1;if(isNaN(r))n=(r=Math.floor(t))+1,s=(e=Math.floor(i))+1;else{for(var h,o,a=n-r,u=this._root;r>t||t>=n||e>i||i>=s;)switch(o=(i<e)<<1|t<r,(h=new Array(4))[o]=u,u=h,a*=2,o){case 0:n=r+a,s=e+a;break;case 1:r=n-a,s=e+a;break;case 2:n=r+a,e=s-a;break;case 3:r=n-a,e=s-a}this._root&&this._root.length&&(this._root=u)}return this._x0=r,this._y0=e,this._x1=n,this._y1=s,this},a.data=function(){var t=[];return this.visit(function(i){if(!i.length)do{t.push(i.data)}while(i=i.next)}),t},a.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},a.find=function(t,i,e){var n,s,h,o,a,u,l,_=this._x0,f=this._y0,c=this._x1,x=this._y1,y=[],d=this._root;for(d&&y.push(new r(d,_,f,c,x)),null==e?e=1/0:(_=t-e,f=i-e,c=t+e,x=i+e,e*=e);u=y.pop();)if(!(!(d=u.node)||(s=u.x0)>c||(h=u.y0)>x||(o=u.x1)<_||(a=u.y1)<f))if(d.length){var v=(s+o)/2,p=(h+a)/2;y.push(new r(d[3],v,p,o,a),new r(d[2],s,p,v,a),new r(d[1],v,h,o,p),new r(d[0],s,h,v,p)),(l=(i>=p)<<1|t>=v)&&(u=y[y.length-1],y[y.length-1]=y[y.length-1-l],y[y.length-1-l]=u)}else{var w=t-+this._x.call(null,d.data),N=i-+this._y.call(null,d.data),g=w*w+N*N;if(g<e){var A=Math.sqrt(e=g);_=t-A,f=i-A,c=t+A,x=i+A,n=d.data}}return n},a.remove=function(t){if(isNaN(s=+this._x.call(null,t))||isNaN(h=+this._y.call(null,t)))return this;var i,r,e,n,s,h,o,a,u,l,_,f,c=this._root,x=this._x0,y=this._y0,d=this._x1,v=this._y1;if(!c)return this;if(c.length)for(;;){if((u=s>=(o=(x+d)/2))?x=o:d=o,(l=h>=(a=(y+v)/2))?y=a:v=a,i=c,!(c=c[_=l<<1|u]))return this;if(!c.length)break;(i[_+1&3]||i[_+2&3]||i[_+3&3])&&(r=i,f=_)}for(;c.data!==t;)if(e=c,!(c=c.next))return this;return(n=c.next)&&delete c.next,e?(n?e.next=n:delete e.next,this):i?(n?i[_]=n:delete i[_],(c=i[0]||i[1]||i[2]||i[3])&&c===(i[3]||i[2]||i[1]||i[0])&&!c.length&&(r?r[f]=c:this._root=c),this):(this._root=n,this)},a.removeAll=function(t){for(var i=0,r=t.length;i<r;++i)this.remove(t[i]);return this},a.root=function(){return this._root},a.size=function(){var t=0;return this.visit(function(i){if(!i.length)do{++t}while(i=i.next)}),t},a.visit=function(t){var i,e,n,s,h,o,a=[],u=this._root;for(u&&a.push(new r(u,this._x0,this._y0,this._x1,this._y1));i=a.pop();)if(!t(u=i.node,n=i.x0,s=i.y0,h=i.x1,o=i.y1)&&u.length){var l=(n+h)/2,_=(s+o)/2;(e=u[3])&&a.push(new r(e,l,_,h,o)),(e=u[2])&&a.push(new r(e,n,_,l,o)),(e=u[1])&&a.push(new r(e,l,s,h,_)),(e=u[0])&&a.push(new r(e,n,s,l,_))}return this},a.visitAfter=function(t){var i,e=[],n=[];for(this._root&&e.push(new r(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var s=i.node;if(s.length){var h,o=i.x0,a=i.y0,u=i.x1,l=i.y1,_=(o+u)/2,f=(a+l)/2;(h=s[0])&&e.push(new r(h,o,a,_,f)),(h=s[1])&&e.push(new r(h,_,a,u,f)),(h=s[2])&&e.push(new r(h,o,f,_,l)),(h=s[3])&&e.push(new r(h,_,f,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this},a.x=function(t){return arguments.length?(this._x=t,this):this._x},a.y=function(t){return arguments.length?(this._y=t,this):this._y},t.quadtree=s,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-quadtree", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Two-dimensional recursive spatial subdivision.", | ||
@@ -24,2 +24,6 @@ "keywords": [ | ||
}, | ||
"files": [ | ||
"dist/**/*.js", | ||
"src/**/*.js" | ||
], | ||
"scripts": { | ||
@@ -31,9 +35,10 @@ "pretest": "rollup -c", | ||
}, | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"d3-array": "1", | ||
"eslint": "5", | ||
"rollup": "0.64", | ||
"rollup-plugin-terser": "1", | ||
"d3-array": "1 - 2", | ||
"eslint": "6", | ||
"rollup": "1", | ||
"rollup-plugin-terser": "5", | ||
"tape": "4" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # d3-quadtree | ||
If you use NPM, `npm install d3-quadtree`. Otherwise, download the [latest release](https://github.com/d3/d3-quadtree/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-quadtree.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: | ||
If you use NPM, `npm install d3-quadtree`. Otherwise, download the [latest release](https://github.com/d3/d3-quadtree/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-quadtree.v1.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: | ||
@@ -22,8 +22,6 @@ ```html | ||
[Try d3-quadtree in your browser.](https://tonicdev.com/npm/d3-quadtree) | ||
## API Reference | ||
<a name="quadtree" href="#quadtree">#</a> d3.<b>quadtree</b>([<i>data</i>[, <i>x</i>, <i>y</i>]]) | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/quadtree.js#L14 "Source") | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/quadtree.js "Source") | ||
@@ -87,3 +85,3 @@ Creates a new, empty quadtree with an empty [extent](#quadtree_extent) and the default [*x*-](#quadtree_x) and [*y*-](#quadtree_y)accessors. If *data* is specified, [adds](#quadtree_addAll) the specified array of data to the quadtree. This is equivalent to: | ||
<a name="quadtree_addAll" href="#quadtree_addAll">#</a> <i>quadtree</i>.<b>addAll</b>(<i>data</i>) | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/add.js#L50 "Source") | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/add.js "Source") | ||
@@ -103,8 +101,8 @@ Adds the specified array of *data* to the quadtree, deriving each element’s coordinates ⟨*x*,*y*⟩ using the current [*x*-](#quadtree_x) and [*y*-](#quadtree_y)accessors, and return this quadtree. This is approximately equivalent to calling [*quadtree*.add](#quadtree_add) repeatedly: | ||
Removes the specified *datum* to the quadtree, deriving its coordinates ⟨*x*,*y*⟩ using the current [*x*-](#quadtree_x) and [*y*-](#quadtree_y)accessors, and returns the quadtree. If the specified *datum* does not exist in this quadtree, this method does nothing. | ||
Removes the specified *datum* from the quadtree, deriving its coordinates ⟨*x*,*y*⟩ using the current [*x*-](#quadtree_x) and [*y*-](#quadtree_y)accessors, and returns the quadtree. If the specified *datum* does not exist in this quadtree, this method does nothing. | ||
<a name="quadtree_removeAll" href="#quadtree_removeAll">#</a> <i>quadtree</i>.<b>removeAll</b>(<i>data</i>) | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/remove.js#L59 "Source") | ||
[<>](https://github.com/d3/d3-quadtree/blob/master/src/remove.js "Source") | ||
… | ||
Removes the specified *data* from the quadtree, deriving their coordinates ⟨*x*,*y*⟩ using the current [*x*-](#quadtree_x) and [*y*-](#quadtree_y)accessors, and returns the quadtree. If a specified datum does not exist in this quadtree, it is ignored. | ||
@@ -111,0 +109,0 @@ <a name="quadtree_copy" href="#quadtree_copy">#</a> <i>quadtree</i>.<b>copy</b>() |
@@ -1,2 +0,2 @@ | ||
import Quad from "./quad"; | ||
import Quad from "./quad.js"; | ||
@@ -3,0 +3,0 @@ export default function(x, y, radius) { |
@@ -1,1 +0,1 @@ | ||
export {default as quadtree} from "./quadtree"; | ||
export {default as quadtree} from "./quadtree.js"; |
@@ -1,13 +0,13 @@ | ||
import tree_add, {addAll as tree_addAll} from "./add"; | ||
import tree_cover from "./cover"; | ||
import tree_data from "./data"; | ||
import tree_extent from "./extent"; | ||
import tree_find from "./find"; | ||
import tree_remove, {removeAll as tree_removeAll} from "./remove"; | ||
import tree_root from "./root"; | ||
import tree_size from "./size"; | ||
import tree_visit from "./visit"; | ||
import tree_visitAfter from "./visitAfter"; | ||
import tree_x, {defaultX} from "./x"; | ||
import tree_y, {defaultY} from "./y"; | ||
import tree_add, {addAll as tree_addAll} from "./add.js"; | ||
import tree_cover from "./cover.js"; | ||
import tree_data from "./data.js"; | ||
import tree_extent from "./extent.js"; | ||
import tree_find from "./find.js"; | ||
import tree_remove, {removeAll as tree_removeAll} from "./remove.js"; | ||
import tree_root from "./root.js"; | ||
import tree_size from "./size.js"; | ||
import tree_visit from "./visit.js"; | ||
import tree_visitAfter from "./visitAfter.js"; | ||
import tree_x, {defaultX} from "./x.js"; | ||
import tree_y, {defaultY} from "./y.js"; | ||
@@ -14,0 +14,0 @@ export default function quadtree(nodes, x, y) { |
@@ -1,2 +0,2 @@ | ||
import Quad from "./quad"; | ||
import Quad from "./quad.js"; | ||
@@ -3,0 +3,0 @@ export default function(callback) { |
@@ -1,2 +0,2 @@ | ||
import Quad from "./quad"; | ||
import Quad from "./quad.js"; | ||
@@ -3,0 +3,0 @@ export default function(callback) { |
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
43314
20
738
164