Make minWidth and maxWidth private member variables
This commit is contained in:
+23
-14
@@ -43,17 +43,26 @@ ol.structs.RTreeNode;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number=} opt_width Width before a node is split. Default is 6.
|
* @param {number=} opt_maxWidth Width before a node is split. Default is 6.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
ol.structs.RTree = function(opt_width) {
|
ol.structs.RTree = function(opt_maxWidth) {
|
||||||
// Variables to control tree-dimensions
|
|
||||||
var minWidth = 3; // Minimum width of any node before a merge
|
/**
|
||||||
var maxWidth = 6; // Maximum width of any node before a split
|
* Maximum width of any node before a split.
|
||||||
if (goog.isDef(opt_width)) {
|
* @private
|
||||||
minWidth = Math.floor(opt_width / 2);
|
* @type {number}
|
||||||
maxWidth = opt_width;
|
*/
|
||||||
}
|
this.maxWidth_ = goog.isDef(opt_maxWidth) ? opt_maxWidth : 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum width of any node before a merge.
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.minWidth_ = Math.floor(this.maxWidth_ / 2);
|
||||||
|
|
||||||
|
var that = this; // FIXME remove
|
||||||
|
|
||||||
// Start with an empty root-tree
|
// Start with an empty root-tree
|
||||||
var rootTree = /** @type {ol.structs.RTreeNode} */
|
var rootTree = /** @type {ol.structs.RTreeNode} */
|
||||||
@@ -110,7 +119,7 @@ ol.structs.RTree = function(opt_width) {
|
|||||||
// Resize MBR down...
|
// Resize MBR down...
|
||||||
ol.structs.RTree.makeMBR_(tree.nodes, tree);
|
ol.structs.RTree.makeMBR_(tree.nodes, tree);
|
||||||
workingObject.target = undefined;
|
workingObject.target = undefined;
|
||||||
if (tree.nodes.length < minWidth) { // Underflow
|
if (tree.nodes.length < that.minWidth_) { // Underflow
|
||||||
workingObject.nodes = /** @type {Array} */
|
workingObject.nodes = /** @type {Array} */
|
||||||
(searchSubtree(tree, true, [], tree));
|
(searchSubtree(tree, true, [], tree));
|
||||||
}
|
}
|
||||||
@@ -145,7 +154,7 @@ ol.structs.RTree = function(opt_width) {
|
|||||||
tree.nodes.length = 0;
|
tree.nodes.length = 0;
|
||||||
hitStack.push(tree);
|
hitStack.push(tree);
|
||||||
countStack.push(1);
|
countStack.push(1);
|
||||||
} else if (hitStack.length > 0 && tree.nodes.length < minWidth) {
|
} else if (hitStack.length > 0 && tree.nodes.length < that.minWidth_) {
|
||||||
// Underflow..AGAIN!
|
// Underflow..AGAIN!
|
||||||
workingObject.nodes = /** @type {Array} */
|
workingObject.nodes = /** @type {Array} */
|
||||||
(searchSubtree(tree, true, workingObject.nodes, tree));
|
(searchSubtree(tree, true, workingObject.nodes, tree));
|
||||||
@@ -286,10 +295,10 @@ ol.structs.RTree = function(opt_width) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tempNode = nodes.splice(highAreaNode, 1)[0];
|
var tempNode = nodes.splice(highAreaNode, 1)[0];
|
||||||
if (a.nodes.length + nodes.length + 1 <= minWidth) {
|
if (a.nodes.length + nodes.length + 1 <= that.minWidth_) {
|
||||||
a.nodes.push(tempNode);
|
a.nodes.push(tempNode);
|
||||||
ol.extent.extend(a.extent, tempNode.extent);
|
ol.extent.extend(a.extent, tempNode.extent);
|
||||||
} else if (b.nodes.length + nodes.length + 1 <= minWidth) {
|
} else if (b.nodes.length + nodes.length + 1 <= that.minWidth_) {
|
||||||
b.nodes.push(tempNode);
|
b.nodes.push(tempNode);
|
||||||
ol.extent.extend(b.extent, tempNode.extent);
|
ol.extent.extend(b.extent, tempNode.extent);
|
||||||
}
|
}
|
||||||
@@ -468,7 +477,7 @@ ol.structs.RTree = function(opt_width) {
|
|||||||
bc.nodes.push(workingObject); // Do Insert
|
bc.nodes.push(workingObject); // Do Insert
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bc.nodes.length <= maxWidth) { // Start Resizeing Up the Tree
|
if (bc.nodes.length <= that.maxWidth_) { // Start Resizeing Up the Tree
|
||||||
workingObject = {extent: bc.extent.concat()};
|
workingObject = {extent: bc.extent.concat()};
|
||||||
} else { // Otherwise Split this Node
|
} else { // Otherwise Split this Node
|
||||||
// linearSplit() returns an array containing two new nodes
|
// linearSplit() returns an array containing two new nodes
|
||||||
|
|||||||
Reference in New Issue
Block a user