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