Merge pull request #1559 from twpayne/rbush-update-reuse-extent
Reuse extent in ol.structs.RBush#update
This commit is contained in:
@@ -555,6 +555,7 @@ ol.structs.RBush.prototype.insert = function(extent, value) {
|
|||||||
var key = this.getKey_(value);
|
var key = this.getKey_(value);
|
||||||
goog.asserts.assert(!this.valueExtent_.hasOwnProperty(key));
|
goog.asserts.assert(!this.valueExtent_.hasOwnProperty(key));
|
||||||
this.insert_(extent, value, this.root_.height - 1);
|
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) {
|
for (; i >= 0; --i) {
|
||||||
ol.extent.extend(path[i].extent, extent);
|
ol.extent.extend(path[i].extent, extent);
|
||||||
}
|
}
|
||||||
var key = this.getKey_(value);
|
|
||||||
this.valueExtent_[key] = ol.extent.clone(extent);
|
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -715,6 +714,6 @@ ol.structs.RBush.prototype.update = function(extent, value) {
|
|||||||
if (!ol.extent.equals(currentExtent, extent)) {
|
if (!ol.extent.equals(currentExtent, extent)) {
|
||||||
this.remove_(currentExtent, value);
|
this.remove_(currentExtent, value);
|
||||||
this.insert_(extent, value, this.root_.height - 1);
|
this.insert_(extent, value, this.root_.height - 1);
|
||||||
ol.extent.clone(extent, currentExtent);
|
this.valueExtent_[key] = ol.extent.clone(extent, currentExtent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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() {
|
describe('with a few objects', function() {
|
||||||
|
|
||||||
var objs;
|
var objs;
|
||||||
|
|||||||
Reference in New Issue
Block a user