X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FPointSet.java;h=11e48a224834d9f6afb0aa7fbe2ca71b20565dc5;hp=2733daf1297bcf4baa8efefc3c7506a553ce5228;hb=de2400d58116bd995e73baf7a429e22def1e4067;hpb=f9488635746daea6f8ccbb4680ff7f169dc5b2e5 diff --git a/src/edu/berkeley/qfat/geom/PointSet.java b/src/edu/berkeley/qfat/geom/PointSet.java index 2733daf..11e48a2 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,9 +36,10 @@ 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); } public Vec diagonal() { @@ -51,7 +49,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 +61,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 +69,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;