Skip to content

Commit a3c8488

Browse files
author
phishman3579
committed
Caught another bug in the query of the RectangleQuadTree
git-svn-id: https://java-algorithms-implementation.googlecode.com/svn/trunk@392 032fbc0f-8cab-eb90-e552-f08422b9a96a
1 parent a6ccb5e commit a3c8488

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ protected PointQuadNode(AxisAlignedBoundingBox aabb) {
123123
super(aabb);
124124
}
125125

126+
/**
127+
* {@inheritDoc}
128+
*
129+
* returns True if inserted.
130+
* returns False if not in bounds of tree OR tree already contains point.
131+
*/
126132
@Override
127133
protected boolean insert(XY p) {
128134
// Ignore objects which do not belong in this quad tree
@@ -271,12 +277,12 @@ public void insert(float x, float y, float height, float width) {
271277
*/
272278
@Override
273279
public List<B> queryRange(float x, float y, float height, float width) {
274-
List<B> pointsInRange = new LinkedList<B>();
275-
if (root==null) return (List<B>)pointsInRange;
280+
List<B> geometricObjectsInRange = new LinkedList<B>();
281+
if (root==null) return (List<B>)geometricObjectsInRange;
276282
XYPoint xyPoint = new XYPoint(x,y);
277283
AxisAlignedBoundingBox range = new AxisAlignedBoundingBox(xyPoint,height,width);
278-
root.queryRange(range,pointsInRange);
279-
return (List<B>)pointsInRange;
284+
root.queryRange(range,geometricObjectsInRange);
285+
return (List<B>)geometricObjectsInRange;
280286
}
281287

282288
/**
@@ -297,11 +303,14 @@ protected RectangleQuadNode(AxisAlignedBoundingBox aabb) {
297303

298304
/**
299305
* {@inheritDoc}
306+
*
307+
* returns True if inserted or already contains.
300308
*/
301309
@Override
302310
protected boolean insert(AABB b) {
303311
// Ignore objects which do not belong in this quad tree
304-
if (!aabb.intersectsBox(b) || aabbs.contains(b)) return false; // object cannot be added
312+
if (!aabb.intersectsBox(b)) return false; // object cannot be added
313+
if (aabbs.contains(b)) return true; // already exists
305314

306315
// If this is the biggest bounding box which completely contains the aabb.
307316
float nextLevelsHeight = aabb.height/2;

0 commit comments

Comments
 (0)