From 286284b0c4a8af8529f6796969eb1b81f7e4a2a1 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 6 Feb 2014 01:21:22 +0100 Subject: [PATCH] Move remove from ol.structs.RBush to ol.structs.RBushNode --- src/ol/structs/rbush.js | 80 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 0c805e7327..aa01db816b 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -135,6 +135,41 @@ ol.structs.RBushNode.prototype.getChildrenExtent = }; +/** + * @param {ol.Extent} extent Extent. + * @param {T} value Value. + * @param {Array.>} path Path. + * @return {boolean} Removed. + */ +ol.structs.RBushNode.prototype.remove = function(extent, value, path) { + var children = this.children; + var ii = children.length; + var child, i; + if (this.height == 1) { + for (i = 0; i < ii; ++i) { + child = children[i]; + if (child.value === value) { + goog.array.removeAt(children, i); + return true; + } + } + } else { + goog.asserts.assert(this.height > 1); + for (i = 0; i < ii; ++i) { + child = children[i]; + if (ol.extent.containsExtent(child.extent, extent)) { + path.push(child); + if (child.remove(extent, value, path)) { + return true; + } + path.pop(); + } + } + } + return false; +}; + + /** * FIXME empty description for jsdoc */ @@ -618,56 +653,19 @@ ol.structs.RBush.prototype.remove = function(value) { * @return {boolean} Removed. */ ol.structs.RBush.prototype.remove_ = function(extent, value) { - var path = [this.root_]; - var removed = this.removeRecursive_(this.root_, extent, value, path); + var root = this.root_; + var path = [root]; + var removed = root.remove(extent, value, path); if (removed) { this.condense_(path); } else { goog.asserts.assert(path.length == 1); - goog.asserts.assert(path[0] === this.root_); + goog.asserts.assert(path[0] === root); } return removed; }; -/** - * @param {ol.structs.RBushNode.} node Node. - * @param {ol.Extent} extent Extent. - * @param {T} value Value. - * @param {Array.>} path Path. - * @private - * @return {boolean} Removed. - */ -ol.structs.RBush.prototype.removeRecursive_ = - function(node, extent, value, path) { - var children = node.children; - var ii = children.length; - var child, i; - if (node.height == 1) { - for (i = 0; i < ii; ++i) { - child = children[i]; - if (child.value === value) { - goog.array.removeAt(children, i); - return true; - } - } - } else { - goog.asserts.assert(node.height > 1); - for (i = 0; i < ii; ++i) { - child = children[i]; - if (ol.extent.containsExtent(child.extent, extent)) { - path.push(child); - if (this.removeRecursive_(child, extent, value, path)) { - return true; - } - path.pop(); - } - } - } - return false; -}; - - /** * @param {Array.>} path Path. * @param {number} level Level.