/** * Associates the specified value with the specified coordinates in this * QuadTree. * * @param x x-coordinate where the specified value is to be associated. * @param y y-coordinate where the specified value is to be associated. * @param value value to be associated with the specified coordinates. * * @return true if insertion was successful and the data structure changed, * false otherwise. */ public boolean put(final double x, final double y, final T value) { if (!this.top.bounds.containsOrEquals(x, y)) { throw new IllegalArgumentException("cannot add a point at x=" + x + ", y=" + y + " with bounds " + this.top.bounds); } if (this.top.put(x, y, value)) { incrementSize(); return true; } return false; }
/* default */ Collection<T> get(final Rect bounds, final Collection<T> values) { if (this.hasChilds) { if (this.northwest.bounds.intersects(bounds)) { this.northwest.get(bounds, values); } if (this.northeast.bounds.intersects(bounds)) { this.northeast.get(bounds, values); } if (this.southeast.bounds.intersects(bounds)) { this.southeast.get(bounds, values); } if (this.southwest.bounds.intersects(bounds)) { this.southwest.get(bounds, values); } return values; } // no more childs, so we must contain the closest object if (this.leaves != null) { for (Leaf<T> leaf : this.leaves) { if (bounds.containsOrEquals(leaf.x, leaf.y)) { if (leaf.value != null) { values.add(leaf.value); } else { values.addAll(leaf.values); } } } } return values; }
if((cachedRect == null) || cachedRect.containsOrEquals(rect)) return cachedResult;