Merge pull request #5543 from tsauerwein/update-rbush-2

Update rbush to 2.0.1
This commit is contained in:
Tobias Sauerwein
2016-07-01 13:13:20 +02:00
committed by GitHub
4 changed files with 54 additions and 22 deletions

View File

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

View File

@@ -26,7 +26,7 @@ ol.structs.RBush = function(opt_maxEntries) {
* A mapping between the objects added to this rbush wrapper
* and the objects that are actually added to the internal rbush.
* @private
* @type {Object.<number, Object>}
* @type {Object.<number, ol.RBushEntry>}
*/
this.items_ = {};
@@ -49,13 +49,15 @@ ol.structs.RBush.prototype.insert = function(extent, value) {
if (goog.DEBUG && this.readers_) {
throw new Error('Can not insert value while reading');
}
var item = [
extent[0],
extent[1],
extent[2],
extent[3],
value
];
/** @type {ol.RBushEntry} */
var item = {
minX: extent[0],
minY: extent[1],
maxX: extent[2],
maxY: extent[3],
value: value
};
this.rbush_.insert(item);
// remember the object that was added to the internal rbush
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 value = values[i];
var item = [
extent[0],
extent[1],
extent[2],
extent[3],
value
];
/** @type {ol.RBushEntry} */
var item = {
minX: extent[0],
minY: extent[1],
maxX: extent[2],
maxY: extent[3],
value: value
};
items[i] = item;
goog.asserts.assert(!(goog.getUid(value) in this.items_),
'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);
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_) {
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() {
var items = this.rbush_.all();
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.
*/
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 item[4];
return item.value;
});
};
@@ -253,5 +264,6 @@ ol.structs.RBush.prototype.clear = function() {
*/
ol.structs.RBush.prototype.getExtent = function(opt_extent) {
// 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.<*>)}
*/
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');