// https://github.com/vasturiano/d3-octree v0.2.0 Copyright 2021 Vasco Asturiano !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,e,s){if(isNaN(i)||isNaN(n)||isNaN(e))return t;var h,r,o,a,l,u,_,f,c,y,x,d,p=t._root,w={data:s},z=t._x0,N=t._y0,v=t._z0,g=t._x1,b=t._y1,A=t._z1;if(!p)return t._root=w,t;for(;p.length;)if((f=i>=(r=(z+g)/2))?z=r:g=r,(c=n>=(o=(N+b)/2))?N=o:b=o,(y=e>=(a=(v+A)/2))?v=a:A=a,h=p,!(p=p[x=y<<2|c<<1|f]))return h[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&&e===_)return w.next=p,h?h[x]=w:t._root=w,t;do{h=h?h[x]=new Array(8):t._root=new Array(8),(f=i>=(r=(z+g)/2))?z=r:g=r,(c=n>=(o=(N+b)/2))?N=o:b=o,(y=e>=(a=(v+A)/2))?v=a:A=a}while((x=y<<2|c<<1|f)==(d=(_>=a)<<2|(u>=o)<<1|l>=r));return h[d]=p,h[x]=w,t}function n(t,i,n,e,s,h,r){this.node=t,this.x0=i,this.y0=n,this.z0=e,this.x1=s,this.y1=h,this.z1=r}function e(t){return t[0]}function s(t){return t[1]}function h(t){return t[2]}function r(t,i,n,r){var a=new o(null==i?e:i,null==n?s:n,null==r?h:r,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?a:a.addAll(t)}function o(t,i,n,e,s,h,r,o,a){this._x=t,this._y=i,this._z=n,this._x0=e,this._y0=s,this._z0=h,this._x1=r,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=r.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),e=this._root;if(!e)return n;if(!e.length)return n._root=a(e),n;for(t=[{source:e,target:n._root=new Array(8)}];e=t.pop();)for(var s=0;s<8;++s)(i=e.source[s])&&(i.length?t.push({source:i,target:e.target[s]=new Array(8)}):e.target[s]=a(i));return n},l.add=function(t){var n=+this._x.call(null,t),e=+this._y.call(null,t),s=+this._z.call(null,t);return i(this.cover(n,e,s),n,e,s,t)},l.addAll=function(t){var n,e,s,h,r,o=t.length,a=new Array(o),l=new Array(o),u=new Array(o),_=1/0,f=1/0,c=1/0,y=-1/0,x=-1/0,d=-1/0;for(e=0;ey&&(y=s),hx&&(x=h),rd&&(d=r));if(_>y||f>x||c>d)return this;for(this.cover(_,f,c).cover(y,x,d),e=0;et||t>=r||s>i||i>=o||h>n||n>=a;)switch(u=(np||(o=f.y0)>w||(a=f.z0)>z||(l=f.x1)=A)<<2|(i>=b)<<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=e-+this._z.call(null,v.data),j=k*k+m*m+M*M;if(j=(a=(p+N)/2))?p=a:N=a,(f=r>=(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(e=d,!(d=d.next))return this;return(s=d.next)&&delete d.next,e?(s?e.next=s:delete e.next,this):i?(s?i[y]=s: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=s,this)},l.removeAll=function(t){for(var i=0,n=t.length;i