diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 549c3be3da..e0bdc81819 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -574,6 +574,14 @@ ol.structs.RBush.prototype.insert_ = function(extent, value, level) { }; +/** + * @return {boolean} Is empty. + */ +ol.structs.RBush.prototype.isEmpty = function() { + return this.root_.children.length === 0; +}; + + /** * @param {T} value Value. */ diff --git a/test/spec/ol/structs/rbush.test.js b/test/spec/ol/structs/rbush.test.js index cdf6b7167d..250aa374b5 100644 --- a/test/spec/ol/structs/rbush.test.js +++ b/test/spec/ol/structs/rbush.test.js @@ -18,6 +18,14 @@ describe('ol.structs.RBush', function() { }); + describe('#isEmpty', function() { + + it('returns true', function() { + expect(rBush.isEmpty()).to.be(true); + }); + + }); + }); describe('with a few objects', function() { @@ -76,6 +84,14 @@ describe('ol.structs.RBush', function() { }); }); + describe('#isEmpty', function() { + + it('returns false', function() { + expect(rBush.isEmpty()).to.be(false); + }); + + }); + describe('#remove', function() { it('can remove each object', function() { @@ -155,6 +171,14 @@ describe('ol.structs.RBush', function() { }); + describe('#isEmpty', function() { + + it('returns false', function() { + expect(rBush.isEmpty()).to.be(false); + }); + + }); + describe('#remove', function() { it('can remove each object in turn', function() { @@ -165,6 +189,7 @@ describe('ol.structs.RBush', function() { expect(rBush.getAllInExtent(extents[i])).to.be.empty(); } expect(rBush.getAll()).to.be.empty(); + expect(rBush.isEmpty()).to.be(true); }); it('can remove objects in random order', function() { @@ -183,6 +208,7 @@ describe('ol.structs.RBush', function() { expect(rBush.getAllInExtent(extents[index])).to.be.empty(); } expect(rBush.getAll()).to.be.empty(); + expect(rBush.isEmpty()).to.be(true); }); }); @@ -260,6 +286,14 @@ describe('ol.structs.RBush', function() { }); + describe('#isEmpty', function() { + + it('returns false', function() { + expect(rBush.isEmpty()).to.be(false); + }); + + }); + }); });