Skip to content

Commit f5a24e2

Browse files
committed
fixed bug in quad tree where bounds not matching tree max depth caused bad subdivision
1 parent 2274ead commit f5a24e2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

js/quadtree.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var DIR_OPPOSITES = [
2727
[ LL, LR ] // + y
2828
];
2929

30-
var MAX_LEVELS = 6;
30+
var MAX_LEVELS = 8;
3131

3232

3333
var Cell = function(bounds) {
@@ -339,10 +339,11 @@ QuadTree.createFromCSGFields = function(fields, maxLevel) {
339339
upperLeftMaterial != lowerRightMaterial ||
340340
lowerLeftMaterial != upperRightMaterial) {
341341

342-
console.log('adding cell at (' + x + ', ' + y + ')');
342+
// add cell at max level
343+
var xx = (cellBounds.left / bounds.width()) * tree.maxVal;
344+
var yy = (cellBounds.bottom / bounds.height()) * tree.maxVal;
343345

344-
// add cell at max level
345-
tree.addCellAtDepth(cellBounds.left, cellBounds.bottom, maxLevel);
346+
tree.addCellAtDepth(xx, yy, maxLevel);
346347
}
347348
}
348349
}

0 commit comments

Comments
 (0)