This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
/
d3-quadtree.v0.4.min.js
1 lines (1 loc) · 3.24 KB
/
d3-quadtree.v0.4.min.js
1
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(t.d3_quadtree=t.d3_quadtree||{})}(this,function(t){"use strict";function i(t){if(isNaN(n=+t.x)||isNaN(s=+t.y))return this;var i,e,n,s,h,r,o,_,u,p,x,a,y=this._root,f=this._x0,w=this._y0,d=this._x1,c=this._y1;if(t.next&&delete t.next,!y)return this._root={point:t},this._x0=this._x1=n,this._y0=this._y1=s,this;if(f>n||n>d||w>s||s>c){switch(h=f===d?Math.max(Math.abs(f-n),Math.abs(w-s)):2*(d-f),x=((w+c)/2>s)<<1|(f+d)/2>n){case 0:do i=new Array(4),i[x]=y,y=i,d=f+h,c=w+h,h*=2;while(n>d||s>c);break;case 1:do i=new Array(4),i[x]=y,y=i,f=d-h,c=w+h,h*=2;while(f>n||s>c);break;case 2:do i=new Array(4),i[x]=y,y=i,d=f+h,w=c-h,h*=2;while(n>d||w>s);break;case 3:do i=new Array(4),i[x]=y,y=i,f=d-h,w=c-h,h*=2;while(f>n||w>s)}this._root=y,this._x0=f,this._x1=d,this._y0=w,this._y1=c}for(;!(e=y.point);)if((u=n>=(h=(f+d)/2))?f=h:d=h,(p=s>=(r=(w+c)/2))?w=r:c=r,i=y,!(y=y[x=p<<1|u]))return i[x]={point:t},this;if(o=e.x,_=e.y,n===o&&s===_)return y={point:t,next:y},i?i[x]=y:this._root=y,this;do i=i[x]=new Array(4),(u=n>=(h=(f+d)/2))?f=h:d=h,(p=s>=(r=(w+c)/2))?w=r:c=r;while((x=p<<1|u)===(a=(_>=r)<<1|o>=h));return i[x]={point:t},i[a]=y,this}function e(t,i,e,n,s){this.node=t,this.x0=i,this.y0=e,this.x1=n,this.y1=s}function n(t){var i,n,s,h,r,o,_=[],u=this._root;for(u&&_.push(new e(u,this._x0,this._y0,this._x1,this._y1));i=_.pop();)if(!t(u=i.node,s=i.x0,h=i.y0,r=i.x1,o=i.y1)){var p=(s+r)/2,x=(h+o)/2;(n=u[3])&&_.push(new e(n,p,x,r,o)),(n=u[2])&&_.push(new e(n,s,x,p,o)),(n=u[1])&&_.push(new e(n,p,h,r,x)),(n=u[0])&&_.push(new e(n,s,h,p,x))}return this}function s(t){var i,n=[],s=[];for(this._root&&n.push(new e(this._root,this._x0,this._y0,this._x1,this._y1));i=n.pop();){var h,r=i.node,o=i.x0,_=i.y0,u=i.x1,p=i.y1,x=(o+u)/2,a=(_+p)/2;(h=r[0])&&n.push(new e(h,o,_,x,a)),(h=r[1])&&n.push(new e(h,x,_,u,a)),(h=r[2])&&n.push(new e(h,o,a,x,p)),(h=r[3])&&n.push(new e(h,x,a,u,p)),s.push(i)}for(;i=s.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function h(t,i){var n,s,h,r,o,_,u,p=1/0,x=this._x0,a=this._y0,y=this._x1,f=this._y1,w=[],d=this._root;for(d&&w.push(new e(d,x,a,y,f));_=w.pop();)if(d=_.node,s=_.x0,h=_.y0,r=_.x1,o=_.y1,!(!d||s>y||h>f||x>r||a>o)){if(d.point){var c=t-d.point.x,v=i-d.point.y,l=c*c+v*v;if(p>l){var N=Math.sqrt(p=l);x=t-N,a=i-N,y=t+N,f=i+N,n=d.point}}var A=(s+r)/2,b=(h+o)/2;w.push(new e(d[3],A,b,r,o),new e(d[2],s,b,A,o),new e(d[1],A,h,r,b),new e(d[0],s,h,A,b)),(u=(i>=b)<<1|t>=A)&&(_=w[w.length-1],w[w.length-1]=w[w.length-1-u],w[w.length-1-u]=_)}return n}function r(t){var i,e,n,s,h,r,o,_=this._root,u=+t.x,p=+t.y,x=this._x0,a=this._y0,y=this._x1,f=this._y1;if(!_)return!1;for(;!_.point;)if((h=u>=(n=(x+y)/2))?x=n:y=n,(r=p>=(s=(a+f)/2))?a=s:f=s,i=_,!(_=_[o=r<<1|h]))return!1;for(;_.point!==t;)if(e=_,!(_=_.next))return!1;return e?e.next=_.next:i?i[o]=_.next:this._root=_.next,!0}function o(t,i,e,n){return 2===arguments.length&&(e=t,n=i,t=i=0),new _(t,i,e,n)}function _(t,i,e,n){var s=(e=+e)-(t=+t),h=(n=+n)-(i=+i);h>s?e=(t-=(h-s)/2)+h:n=(i-=(s-h)/2)+s,this._x0=t,this._y0=i,this._x1=e,this._y1=n,this._root=isNaN(s)||isNaN(h)?void 0:new Array(4)}var u="0.4.0",p=_.prototype=o.prototype;p.add=i,p.visit=n,p.visitAfter=s,p.find=h,p.remove=r,t.version=u,t.quadtree=o});