private static Envelope envelope(Boundable b) { return (Envelope)b.getBounds(); }
private static double area(Boundable b) { return ((Envelope) b.getBounds()).getArea(); }
protected Object computeBounds() { Envelope bounds = null; for (Iterator i = getChildBoundables().iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (bounds == null) { bounds = new Envelope((Envelope)childBoundable.getBounds()); } else { bounds.expandToInclude((Envelope)childBoundable.getBounds()); } } return bounds; } }
protected Object computeBounds() { Interval bounds = null; for (Iterator i = getChildBoundables().iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (bounds == null) { bounds = new Interval((Interval)childBoundable.getBounds()); } else { bounds.expandToInclude((Interval)childBoundable.getBounds()); } } return bounds; } };
private static void addBounds(Boundable bnd, List bounds, GeometryFactory factory) { // don't include bounds of leaf nodes if (! (bnd instanceof AbstractNode)) return; Envelope env = (Envelope) bnd.getBounds(); bounds.add(factory.toGeometry(env)); if (bnd instanceof AbstractNode) { AbstractNode node = (AbstractNode) bnd; List children = node.getChildBoundables(); for (Iterator i = children.iterator(); i.hasNext(); ) { Boundable child = (Boundable) i.next(); addBounds(child, bounds, factory); } } }
/** * Computes the distance between the {@link Boundable}s in this pair. * The boundables are either composites or leaves. * If either is composite, the distance is computed as the minimum distance * between the bounds. * If both are leaves, the distance is computed by {@link #itemDistance(ItemBoundable, ItemBoundable)}. * * @return */ private double distance() { // if items, compute exact distance if (isLeaves()) { return itemDistance.distance((ItemBoundable) boundable1, (ItemBoundable) boundable2); } // otherwise compute distance between bounds of boundables return ((Envelope) boundable1.getBounds()).distance( ((Envelope) boundable2.getBounds())); }
private void queryInternal(Object searchBounds, AbstractNode node, List matches) { List childBoundables = node.getChildBoundables(); for (int i = 0; i < childBoundables.size(); i++) { Boundable childBoundable = (Boundable) childBoundables.get(i); if (! getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { queryInternal(searchBounds, (AbstractNode) childBoundable, matches); } else if (childBoundable instanceof ItemBoundable) { matches.add(((ItemBoundable)childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } }
private boolean remove(Object searchBounds, AbstractNode node, Object item) { // first try removing item from this node boolean found = removeItem(node, item); if (found) return true; AbstractNode childToPrune = null; // next try removing item from lower nodes for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (!getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { found = remove(searchBounds, (AbstractNode) childBoundable, item); // if found, record child for pruning and exit if (found) { childToPrune = (AbstractNode) childBoundable; break; } } } // prune child if possible if (childToPrune != null) { if (childToPrune.getChildBoundables().isEmpty()) { node.getChildBoundables().remove(childToPrune); } } return found; }
private void queryInternal(Object searchBounds, AbstractNode node, ItemVisitor visitor) { List childBoundables = node.getChildBoundables(); for (int i = 0; i < childBoundables.size(); i++) { Boundable childBoundable = (Boundable) childBoundables.get(i); if (! getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { queryInternal(searchBounds, (AbstractNode) childBoundable, visitor); } else if (childBoundable instanceof ItemBoundable) { visitor.visitItem(((ItemBoundable)childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } }