// https://github.com/vasturiano/d3-octree v1.0.2 !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";function i(t,i,n,s,e){if(isNaN(i)||isNaN(n)||isNaN(s))return t;var r,h,o,a,l,u,_,f,c,y,x,d,p=t._root,w={data:e},z=t._x0,N=t._y0,v=t._z0,g=t._x1,A=t._y1,b=t._z1;if(!p)return t._root=w,t;for(;p.length;)if((f=i>=(h=(z+g)/2))?z=h:g=h,(c=n>=(o=(N+A)/2))?N=o:A=o,(y=s>=(a=(v+b)/2))?v=a:b=a,r=p,!(p=p[x=y<<2|c<<1|f]))return r[x]=w,t;if(l=+t._x.call(null,p.data),u=+t._y.call(null,p.data),_=+t._z.call(null,p.data),i===l&&n===u&&s===_)return w.next=p,r?r[x]=w:t._root=w,t;do{r=r?r[x]=new Array(8):t._root=new Array(8),(f=i>=(h=(z+g)/2))?z=h:g=h,(c=n>=(o=(N+A)/2))?N=o:A=o,(y=s>=(a=(v+b)/2))?v=a:b=a}while((x=y<<2|c<<1|f)==(d=(_>=a)<<2|(u>=o)<<1|l>=h));return r[d]=p,r[x]=w,t}function n(t,i,n,s,e,r,h){this.node=t,this.x0=i,this.y0=n,this.z0=s,this.x1=e,this.y1=r,this.z1=h}function s(t){return t[0]}function e(t){return t[1]}function r(t){return t[2]}function h(t,i,n,h){var a=new o(null==i?s:i,null==n?e:n,null==h?r:h,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?a:a.addAll(t)}function o(t,i,n,s,e,r,h,o,a){this._x=t,this._y=i,this._z=n,this._x0=s,this._y0=e,this._z0=r,this._x1=h,this._y1=o,this._z1=a,this._root=void 0}function a(t){for(var i={data:t.data},n=i;t=t.next;)n=n.next={data:t.data};return i}var l=h.prototype=o.prototype;l.copy=function(){var t,i,n=new o(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),s=this._root;if(!s)return n;if(!s.length)return n._root=a(s),n;for(t=[{source:s,target:n._root=new Array(8)}];s=t.pop();)for(var e=0;e<8;++e)(i=s.source[e])&&(i.length?t.push({source:i,target:s.target[e]=new Array(8)}):s.target[e]=a(i));return n},l.add=function(t){const n=+this._x.call(null,t),s=+this._y.call(null,t),e=+this._z.call(null,t);return i(this.cover(n,s,e),n,s,e,t)},l.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const n=t.length,s=new Float64Array(n),e=new Float64Array(n),r=new Float64Array(n);let h=1/0,o=1/0,a=1/0,l=-1/0,u=-1/0,_=-1/0;for(let i,f,c,y,x=0;xl&&(l=f),cu&&(u=c),y_&&(_=y));if(h>l||o>u||a>_)return this;this.cover(h,o,a).cover(l,u,_);for(let h=0;ht||t>=h||e>i||i>=o||r>n||n>=a;)switch(u=(np||(o=f.y0)>w||(a=f.z0)>z||(l=f.x1)=b)<<2|(i>=A)<<1|t>=g)&&(f=N[N.length-1],N[N.length-1]=N[N.length-1-c],N[N.length-1-c]=f)}else{var k=t-+this._x.call(null,v.data),m=i-+this._y.call(null,v.data),M=s-+this._z.call(null,v.data),F=k*k+m*m+M*M;if(F=(a=(p+N)/2))?p=a:N=a,(f=h>=(l=(w+v)/2))?w=l:v=l,(c=o>=(u=(z+g)/2))?z=u:g=u,i=d,!(d=d[y=c<<2|f<<1|_]))return this;if(!d.length)break;(i[y+1&7]||i[y+2&7]||i[y+3&7]||i[y+4&7]||i[y+5&7]||i[y+6&7]||i[y+7&7])&&(n=i,x=y)}for(;d.data!==t;)if(s=d,!(d=d.next))return this;return(e=d.next)&&delete d.next,s?(e?s.next=e:delete s.next,this):i?(e?i[y]=e:delete i[y],(d=i[0]||i[1]||i[2]||i[3]||i[4]||i[5]||i[6]||i[7])&&d===(i[7]||i[6]||i[5]||i[4]||i[3]||i[2]||i[1]||i[0])&&!d.length&&(n?n[x]=d:this._root=d),this):(this._root=e,this)},l.removeAll=function(t){for(var i=0,n=t.length;i