Update rbush to 2.0.1

This commit is contained in:
tsauerwein
2016-07-01 12:01:48 +02:00
parent c56432cf2e
commit 749660dd22
4 changed files with 54 additions and 22 deletions

View File

@@ -44,7 +44,7 @@
"nomnom": "1.8.1", "nomnom": "1.8.1",
"pbf": "2.0.1", "pbf": "2.0.1",
"pixelworks": "1.1.0", "pixelworks": "1.1.0",
"rbush": "1.4.3", "rbush": "2.0.1",
"temp": "0.8.3", "temp": "0.8.3",
"vector-tile": "1.2.1", "vector-tile": "1.2.1",
"walk": "2.3.9" "walk": "2.3.9"
@@ -86,7 +86,10 @@
} }
}, },
"ext": [ "ext": [
"rbush", {
"module": "rbush",
"browserify": true
},
{ {
"module": "pbf", "module": "pbf",
"browserify": true "browserify": true

View File

@@ -26,7 +26,7 @@ ol.structs.RBush = function(opt_maxEntries) {
* A mapping between the objects added to this rbush wrapper * A mapping between the objects added to this rbush wrapper
* and the objects that are actually added to the internal rbush. * and the objects that are actually added to the internal rbush.
* @private * @private
* @type {Object.<number, Object>} * @type {Object.<number, ol.RBushEntry>}
*/ */
this.items_ = {}; this.items_ = {};
@@ -49,13 +49,15 @@ ol.structs.RBush.prototype.insert = function(extent, value) {
if (goog.DEBUG && this.readers_) { if (goog.DEBUG && this.readers_) {
throw new Error('Can not insert value while reading'); throw new Error('Can not insert value while reading');
} }
var item = [ /** @type {ol.RBushEntry} */
extent[0], var item = {
extent[1], minX: extent[0],
extent[2], minY: extent[1],
extent[3], maxX: extent[2],
value maxY: extent[3],
]; value: value
};
this.rbush_.insert(item); this.rbush_.insert(item);
// remember the object that was added to the internal rbush // remember the object that was added to the internal rbush
goog.asserts.assert(!(goog.getUid(value) in this.items_), goog.asserts.assert(!(goog.getUid(value) in this.items_),
@@ -82,13 +84,14 @@ ol.structs.RBush.prototype.load = function(extents, values) {
var extent = extents[i]; var extent = extents[i];
var value = values[i]; var value = values[i];
var item = [ /** @type {ol.RBushEntry} */
extent[0], var item = {
extent[1], minX: extent[0],
extent[2], minY: extent[1],
extent[3], maxX: extent[2],
value maxY: extent[3],
]; value: value
};
items[i] = item; items[i] = item;
goog.asserts.assert(!(goog.getUid(value) in this.items_), goog.asserts.assert(!(goog.getUid(value) in this.items_),
'uid (%s) of value (%s) already exists', goog.getUid(value), value); 'uid (%s) of value (%s) already exists', goog.getUid(value), value);
@@ -130,7 +133,8 @@ ol.structs.RBush.prototype.update = function(extent, value) {
'uid (%s) of value (%s) does not exist', uid, value); 'uid (%s) of value (%s) does not exist', uid, value);
var item = this.items_[uid]; var item = this.items_[uid];
if (!ol.extent.equals(item.slice(0, 4), extent)) { var bbox = [item.minX, item.minY, item.maxX, item.maxY];
if (!ol.extent.equals(bbox, extent)) {
if (goog.DEBUG && this.readers_) { if (goog.DEBUG && this.readers_) {
throw new Error('Can not update extent while reading'); throw new Error('Can not update extent while reading');
} }
@@ -147,7 +151,7 @@ ol.structs.RBush.prototype.update = function(extent, value) {
ol.structs.RBush.prototype.getAll = function() { ol.structs.RBush.prototype.getAll = function() {
var items = this.rbush_.all(); var items = this.rbush_.all();
return items.map(function(item) { return items.map(function(item) {
return item[4]; return item.value;
}); });
}; };
@@ -158,9 +162,16 @@ ol.structs.RBush.prototype.getAll = function() {
* @return {Array.<T>} All in extent. * @return {Array.<T>} All in extent.
*/ */
ol.structs.RBush.prototype.getInExtent = function(extent) { ol.structs.RBush.prototype.getInExtent = function(extent) {
var items = this.rbush_.search(extent); /** @type {ol.RBushEntry} */
var bbox = {
minX: extent[0],
minY: extent[1],
maxX: extent[2],
maxY: extent[3]
};
var items = this.rbush_.search(bbox);
return items.map(function(item) { return items.map(function(item) {
return item[4]; return item.value;
}); });
}; };
@@ -253,5 +264,6 @@ ol.structs.RBush.prototype.clear = function() {
*/ */
ol.structs.RBush.prototype.getExtent = function(opt_extent) { ol.structs.RBush.prototype.getExtent = function(opt_extent) {
// FIXME add getExtent() to rbush // FIXME add getExtent() to rbush
return this.rbush_.data.bbox; var data = this.rbush_.data;
return [data.minX, data.minY, data.maxX, data.maxY];
}; };

View File

@@ -686,3 +686,10 @@ ol.XmlParser;
* @typedef {function(Node, *, Array.<*>)} * @typedef {function(Node, *, Array.<*>)}
*/ */
ol.XmlSerializer; ol.XmlSerializer;
/**
* @typedef {{minX: number, minY: number, maxX: number, maxY: number,
* value: (Object|undefined)}}
*/
ol.RBushEntry;

View File

@@ -362,6 +362,16 @@ describe('ol.structs.RBush', function() {
}); });
describe('#getExtent', function() {
it('gets the extent', function() {
var obj = {};
rBush.insert([0, 0, 1, 1], obj);
expect(rBush.getExtent()).to.eql([0, 0, 1, 1]);
});
});
}); });
goog.require('ol.structs.RBush'); goog.require('ol.structs.RBush');