Merge pull request #1559 from twpayne/rbush-update-reuse-extent

Reuse extent in ol.structs.RBush#update
This commit is contained in:
Tom Payne
2014-01-20 23:47:46 -08:00
2 changed files with 20 additions and 3 deletions

View File

@@ -555,6 +555,7 @@ ol.structs.RBush.prototype.insert = function(extent, value) {
var key = this.getKey_(value);
goog.asserts.assert(!this.valueExtent_.hasOwnProperty(key));
this.insert_(extent, value, this.root_.height - 1);
this.valueExtent_[key] = ol.extent.clone(extent);
};
@@ -582,8 +583,6 @@ ol.structs.RBush.prototype.insert_ = function(extent, value, level) {
for (; i >= 0; --i) {
ol.extent.extend(path[i].extent, extent);
}
var key = this.getKey_(value);
this.valueExtent_[key] = ol.extent.clone(extent);
return node;
};
@@ -715,6 +714,6 @@ ol.structs.RBush.prototype.update = function(extent, value) {
if (!ol.extent.equals(currentExtent, extent)) {
this.remove_(currentExtent, value);
this.insert_(extent, value, this.root_.height - 1);
ol.extent.clone(extent, currentExtent);
this.valueExtent_[key] = ol.extent.clone(extent, currentExtent);
}
};

View File

@@ -28,6 +28,24 @@ describe('ol.structs.RBush', function() {
});
describe('with a single object', function() {
var obj;
beforeEach(function() {
obj = {};
rBush.insert([0, 0, 1, 1], obj);
});
it('can update the object', function() {
expect(rBush.getAllInExtent([0, 0, 1, 1])).to.eql([obj]);
rBush.update([2, 2, 3, 3], obj);
expect(rBush.getAllInExtent([0, 0, 1, 1])).to.be.empty();
expect(rBush.getAll()).to.eql([obj]);
expect(rBush.getAllInExtent([2, 2, 3, 3])).to.eql([obj]);
});
});
describe('with a few objects', function() {
var objs;