function t(t,n,h,r,a){i(t,n,h||0,r||t.length-1,a||e)}function i(t,e,h,r,a){for(;r>h;){if(r-h>600){var s=r-h+1,o=e-h+1,l=Math.log(s),c=.5*Math.exp(2*l/3),m=.5*Math.sqrt(l*c*(s-c)/s)*(o-s/2<0?-1:1);i(t,e,Math.max(h,Math.floor(e-o*c/s+m)),Math.min(r,Math.floor(e+(s-o)*c/s+m)),a)}var f=t[e],u=h,x=r;for(n(t,h,e),a(t[r],f)>0&&n(t,h,r);u0;)x--}0===a(t[h],f)?n(t,h,x):n(t,++x,r),x<=e&&(h=x+1),e<=x&&(r=x-1)}}function n(t,i,n){var e=t[i];t[i]=t[n],t[n]=e}function e(t,i){return ti?1:0}class h{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let i=this.data;const n=[];if(!d(t,i))return n;const e=this.toBBox,h=[];for(;i;){for(let r=0;r=0&&h[i].children.length>this._maxEntries;)this._split(h,i),i--;this._adjustParentBBoxes(e,h,i)}_split(t,i){const n=t[i],e=n.children.length,h=this._minEntries;this._chooseSplitAxis(n,h,e);const r=this._chooseSplitIndex(n,h,e),s=p(n.children.splice(r,n.children.length-r));s.height=n.height,s.leaf=n.leaf,a(n,this.toBBox),a(s,this.toBBox),i?t[i-1].children.push(s):this._splitRoot(n,s)}_splitRoot(t,i){this.data=p([t,i]),this.data.height=t.height+1,this.data.leaf=!1,a(this.data,this.toBBox)}_chooseSplitIndex(t,i,n){let e,h=1/0,r=1/0;for(let a=i;a<=n-i;a++){const i=s(t,0,a,this.toBBox),o=s(t,a,n,this.toBBox),l=u(i,o),c=m(i)+m(o);l=i;s--){const i=t.children[s];o(a,t.leaf?h(i):i),l+=f(a)}return l}_adjustParentBBoxes(t,i,n){for(let e=n;e>=0;e--)o(i[e],t)}_condense(t){for(let i,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():a(t[n],this.toBBox)}}function r(t,i,n){if(!n)return i.indexOf(t);for(let e=0;e=t.minX&&i.maxY>=t.minY}function p(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(i,n,e,h,r){const a=[n,e];for(;a.length;){if((e=a.pop())-(n=a.pop())<=h)continue;const s=n+Math.ceil((e-n)/h/2)*h;t(i,s,n,e,r),a.push(n,s,s,e)}}export{h as R};