X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FPointSet.java;h=b75038cfdb3405bb7c4b110de2722fbc3bb41731;hb=468b086402bb0ccae7ce4dda8b009d61bfc37a71;hp=2733daf1297bcf4baa8efefc3c7506a553ce5228;hpb=f9488635746daea6f8ccbb4680ff7f169dc5b2e5;p=anneal.git diff --git a/src/edu/berkeley/qfat/geom/PointSet.java b/src/edu/berkeley/qfat/geom/PointSet.java index 2733daf..b75038c 100644 --- a/src/edu/berkeley/qfat/geom/PointSet.java +++ b/src/edu/berkeley/qfat/geom/PointSet.java @@ -1,6 +1,7 @@ package edu.berkeley.qfat.geom; import java.util.*; +/** a set of points, plus many useful methods operating over the set */ public class PointSet implements Iterable { private RTree rtree = new RTree(); @@ -9,11 +10,10 @@ public class PointSet implements Iterable { public int size() { return exact.size(); } - public Iterator iterator() { - return exact.values().iterator(); - } + public Iterator iterator() { return rtree.iterator(); } + public void clear() { - exact = new HashMap(); + exact.clear(); rtree = new RTree(); } @@ -21,9 +21,6 @@ public class PointSet implements Iterable { return exact.get(p); } - public void rebuild() { - } - public void add(V v) { V x = get(v.getPoint()); if (x != null && x.equals(v)) return; @@ -39,11 +36,13 @@ public class PointSet implements Iterable { exact.remove(p); } - public V nearest(Point p) { + public V nearest(Point p) { return nearest(p, null); } + public V nearest(Point p, Visitor vis) { if (exact.size()==0) return null; - return rtree.nearest(p); + return rtree.nearest(p, vis); } + // FEATURE: compute incrementally? public Vec diagonal() { float min_x = Float.MAX_VALUE; float min_y = Float.MAX_VALUE; @@ -51,7 +50,8 @@ public class PointSet implements Iterable { float max_x = Float.MIN_VALUE; float max_y = Float.MIN_VALUE; float max_z = Float.MIN_VALUE; - for(Point p : exact.keySet()) { + for(V v : this) { + Point p = v.getPoint(); if (p.x < min_x) min_x = p.x; if (p.y < min_y) min_y = p.y; if (p.z < min_z) min_z = p.z; @@ -62,6 +62,7 @@ public class PointSet implements Iterable { return new Vec(max_x - min_x, max_y - min_y, max_z - min_z); } + // FEATURE: compute incrementally? public Point centroid() { float min_x = Float.MAX_VALUE; float min_y = Float.MAX_VALUE; @@ -69,7 +70,8 @@ public class PointSet implements Iterable { float max_x = Float.MIN_VALUE; float max_y = Float.MIN_VALUE; float max_z = Float.MIN_VALUE; - for(Point p : exact.keySet()) { + for(V v : this) { + Point p = v.getPoint(); if (p.x < min_x) min_x = p.x; if (p.y < min_y) min_y = p.y; if (p.z < min_z) min_z = p.z;