2 lines
6.9 KiB
JavaScript
2 lines
6.9 KiB
JavaScript
|
|
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.rbush=t()}}(function(){return function t(i,n,e){function r(h,o){if(!n[h]){if(!i[h]){var s="function"==typeof require&&require;if(!o&&s)return s(h,!0);if(a)return a(h,!0);var l=new Error("Cannot find module '"+h+"'");throw l.code="MODULE_NOT_FOUND",l}var f=n[h]={exports:{}};i[h][0].call(f.exports,function(t){var n=i[h][1][t];return r(n?n:t)},f,f.exports,t,i,n,e)}return n[h].exports}for(var a="function"==typeof require&&require,h=0;h<e.length;h++)r(e[h]);return r}({1:[function(t,i,n){"use strict";function e(t,i){return this instanceof e?(this._maxEntries=Math.max(4,t||9),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),i&&this._initFormat(i),void this.clear()):new e(t,i)}function r(t,i,n){if(!n)return i.indexOf(t);for(var e=0;e<i.length;e++)if(n(t,i[e]))return e;return-1}function a(t,i){h(t,0,t.children.length,i,t)}function h(t,i,n,e,r){r||(r=p(null)),r.minX=1/0,r.minY=1/0,r.maxX=-(1/0),r.maxY=-(1/0);for(var a,h=i;h<n;h++)a=t.children[h],o(r,t.leaf?e(a):a);return r}function o(t,i){return t.minX=Math.min(t.minX,i.minX),t.minY=Math.min(t.minY,i.minY),t.maxX=Math.max(t.maxX,i.maxX),t.maxY=Math.max(t.maxY,i.maxY),t}function s(t,i){return t.minX-i.minX}function l(t,i){return t.minY-i.minY}function f(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function u(t){return t.maxX-t.minX+(t.maxY-t.minY)}function c(t,i){return(Math.max(i.maxX,t.maxX)-Math.min(i.minX,t.minX))*(Math.max(i.maxY,t.maxY)-Math.min(i.minY,t.minY))}function m(t,i){var n=Math.max(t.minX,i.minX),e=Math.max(t.minY,i.minY),r=Math.min(t.maxX,i.maxX),a=Math.min(t.maxY,i.maxY);return Math.max(0,r-n)*Math.max(0,a-e)}function d(t,i){return t.minX<=i.minX&&t.minY<=i.minY&&i.maxX<=t.maxX&&i.maxY<=t.maxY}function x(t,i){return i.minX<=t.maxX&&i.minY<=t.maxY&&i.maxX>=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(t,i,n,e,r){for(var a,h=[i,n];h.length;)n=h.pop(),i=h.pop(),n-i<=e||(a=i+Math.ceil((n-i)/e/2)*e,g(t,a,i,n,r),h.push(i,a,a,n))}i.exports=e;var g=t("quickselect");e.prototype={all:function(){return this._all(this.data,[])},search:function(t){var i=this.data,n=[],e=this.toBBox;if(!x(t,i))return n;for(var r,a,h,o,s=[];i;){for(r=0,a=i.children.length;r<a;r++)h=i.children[r],o=i.leaf?e(h):h,x(t,o)&&(i.leaf?n.push(h):d(t,o)?this._all(h,n):s.push(h));i=s.pop()}return n},collides:function(t){var i=this.data,n=this.toBBox;if(!x(t,i))return!1;for(var e,r,a,h,o=[];i;){for(e=0,r=i.children.length;e<r;e++)if(a=i.children[e],h=i.leaf?n(a):a,x(t,h)){if(i.leaf||d(t,h))return!0;o.push(a)}i=o.pop()}return!1},load:function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var i=0,n=t.length;i<n;i++)this.insert(t[i]);return this}var e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){var r=this.data;this.data=e,e=r}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this},insert:function(t){return t&&this._insert(t,this.data.height-1),this},clear:function(){return this.data=p([]),this},remove:function(t,i){if(!t)return this;for(var n,e,a,h,o=this.data,s=this.toBBox(t),l=[],f=[];o||l.length;){if(o||(o=l.pop(),e=l[l.length-1],n=f.pop(),h=!0),o.leaf&&(a=r(t,o.children,i),a!==-1))return o.children.splice(a,1),l.push(o),this._condense(l),this;h||o.leaf||!d(o,s)?e?(n++,o=e.children[n],h=!1):o=null:(l.push(o),f.push(n),n=0,e=o,o=o.children[0])}return this},toBBox:function(t){return t},compareMinX:s,compareMinY:l,toJSON:function(){return this.data},fromJSON:function(t){return this.data=t,this},_all:function(t,i){for(var n=[];t;)t.leaf?i.push.apply(i,t.children):n.push.apply(n,t.children),t=n.pop();return i},_build:function(t,i,n,e){var r,h=n-i+1,o=this._maxEntries;if(h<=o)return r=p(t.slice(i,n+1)),a(r,this
|