checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / RTree.java
index 1e6e39a..5a29093 100644 (file)
@@ -55,22 +55,25 @@ public class RTree<V extends HasBoundingBox> implements Iterable<V> {
         rtree.delete(rect, id);
     }
 
-    public V nearest(Point p) {
+    public V nearest(Point p) { return nearest(p, null); }
+    public V nearest(Point p, Visitor<V> ip) {
         point.set(p.x, p.y, p.z);
+        this.visitor = ip;
         rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
+        this.visitor = null;
         V ret = found;
         found = null;
         return ret;
     }
 
-    public void range(HasBoundingBox v, Visitor vis) {
+    public void range(HasBoundingBox v, Visitor<V> vis) {
         visitor = vis;
         rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
         rtree.intersects(rect, myIntProcedure);
         visitor = null;
     }
 
-    public void range(Point p1, Point p2, Visitor vis) {
+    public void range(Point p1, Point p2, Visitor<V> vis) {
         visitor = vis;
         rect.set(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
         rtree.intersects(rect, myIntProcedure);
@@ -79,12 +82,10 @@ public class RTree<V extends HasBoundingBox> implements Iterable<V> {
 
     private class MyIntProcedure implements IntProcedure {
         public boolean execute(int id) {
+            found = idToV.get(id);
             if (visitor != null) {
-                V v = idToV.get(id);
-                visitor.visit(v);
-                return true;
+                return visitor.visit(found);
             } else {
-                found = idToV.get(id);
                 return false;
             }
         }