Skip to content

Commit a6ccb5e

Browse files
author
phishman3579
committed
Caught an error in the RectangleQuadTree
git-svn-id: https://java-algorithms-implementation.googlecode.com/svn/trunk@391 032fbc0f-8cab-eb90-e552-f08422b9a96a
1 parent b988537 commit a6ccb5e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/com/jwetherell/algorithms/data_structures/QuadTree.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,9 @@ protected boolean insert(AABB b) {
325325
return true;
326326
}
327327
return false;
328+
} else {
329+
return true;
328330
}
329-
330-
// Otherwise, the point cannot be inserted for some unknown reason (which should never happen)
331-
return false;
332331
}
333332

334333
private void subdivide() {
@@ -352,13 +351,12 @@ private void subdivide() {
352351
}
353352

354353
private boolean insertIntoChildren(AABB b) {
355-
//Try to insert into all children, it will fail on children which don't intersect box
356-
boolean successful = false;
357-
successful = northWest.insert(b);
358-
successful = (successful || northEast.insert(b));
359-
successful = (successful || southWest.insert(b));
360-
successful = (successful || southEast.insert(b));
361-
return successful;
354+
//Try to insert into all children
355+
if (northWest.insert(b)) return true;
356+
if (northEast.insert(b)) return true;
357+
if (southWest.insert(b)) return true;
358+
if (southEast.insert(b)) return true;
359+
return false;
362360
}
363361

364362
/**
@@ -369,16 +367,18 @@ protected void queryRange(AxisAlignedBoundingBox range, List<AABB> geometricObje
369367
// Automatically abort if the range does not collide with this quad
370368
if (!aabb.intersectsBox(range)) return;
371369

372-
// If leaf, check objects at this level
370+
// Check objects at this level
373371
for (AABB b : aabbs) {
374372
if (range.intersectsBox(b)) geometricObjectsInRange.add(b);
375373
}
376374

377-
// Otherwise, add the points from the children
378-
if (northWest!=null) northWest.queryRange(range,geometricObjectsInRange);
379-
if (northEast!=null) northEast.queryRange(range,geometricObjectsInRange);
380-
if (southWest!=null) southWest.queryRange(range,geometricObjectsInRange);
381-
if (southEast!=null) southEast.queryRange(range,geometricObjectsInRange);
375+
// Otherwise, add the objects from the children
376+
if (!isLeaf()) {
377+
northWest.queryRange(range,geometricObjectsInRange);
378+
northEast.queryRange(range,geometricObjectsInRange);
379+
southWest.queryRange(range,geometricObjectsInRange);
380+
southEast.queryRange(range,geometricObjectsInRange);
381+
}
382382
}
383383

384384
/**

0 commit comments

Comments
 (0)