From 23383c9979e7fbc066912ec99c9296338123e663 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 11 Jun 2014 10:30:04 +0200 Subject: [PATCH 1/2] Add more tests for ol.structs.RBush#forEach --- test/spec/ol/structs/rbush.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/spec/ol/structs/rbush.test.js b/test/spec/ol/structs/rbush.test.js index c63535b50a..c7653295c3 100644 --- a/test/spec/ol/structs/rbush.test.js +++ b/test/spec/ol/structs/rbush.test.js @@ -64,6 +64,27 @@ describe('ol.structs.RBush', function() { rBush.insert([-3, -3, -2, -2], objs[10]); }); + describe('#forEach', function() { + + it('called for all the objects', function() { + var i = 0; + rBush.forEach(function() { + ++i; + }); + expect(i).to.be(objs.length); + }); + + it('stops when the function returns true', function() { + var i = 0; + var result = rBush.forEach(function() { + return ++i >= 4; + }); + expect(i).to.be(4); + expect(result).to.be(true); + }); + + }); + describe('#getInExtent', function() { it('returns the expected objects', function() { From e9e62bcf98066603d2def3499ed9607ef38ed676 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 11 Jun 2014 12:50:55 +0200 Subject: [PATCH 2/2] Better ol.structs.RBush#forEach documentation --- src/ol/structs/rbush.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 4012576c4b..7e0250327a 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -395,6 +395,8 @@ ol.structs.RBush.prototype.condense_ = function(path) { /** * Calls a callback function with each node in the tree. Inside the callback, * no tree modifications (insert, update, remove) can be made. + * If the callback returns a truthy value, this value is returned without + * checking the rest of the tree. * @param {function(this: S, T): *} callback Callback. * @param {S=} opt_this The object to use as `this` in `callback`. * @return {*} Callback return value.