checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 5b98a31..c570ede 100644 (file)
@@ -17,12 +17,31 @@ public class Mesh implements Iterable<Mesh.T> {
     public static Random random = new Random();
 
     private HashMap<Point,Vert>  ps = new HashMap<Point,Vert>();
-    public  HashSet<E>           es = new HashSet<E>();
-    public  ArrayList<T>         ts = new ArrayList<T>();
+    //public  HashSet<E>           es = new HashSet<E>();
+
+    public Iterable<E> edges() {
+        return
+            new Iterable<E>() {
+            public Iterator<E> iterator() {
+                // HACK
+                HashSet<E> hse = new HashSet<E>();
+                for(T t : Mesh.this) {
+                    hse.add(t.e1());
+                    hse.add(t.e2());
+                    hse.add(t.e3());
+                    hse.add(t.e1().pair);
+                    hse.add(t.e2().pair);
+                    hse.add(t.e3().pair);
+                }
+                return hse.iterator();
+            } };
+    }
 
     public Iterator<T> iterator() {
-        if (es.size() == 0) return new FaceIterator();
-        return new FaceIterator(es.iterator().next().p1);
+        for(Vert v : ps.values()) {
+            if (v.e != null && v.e.t != null) return new FaceIterator(v);
+        }
+        return new FaceIterator();
     }
 
     public Point origin() { return new Point(0, 0, 0); }
@@ -237,7 +256,7 @@ public class Mesh implements Iterable<Mesh.T> {
             rescore();
             boolean good = true;
             /*
-            for(T t : ts) {
+            for(T t : this) {
                 for(E e = this.e; ;) {
                     if (e.intersects(t)) { good = false; break; }
                     e = e.pair.next;
@@ -470,8 +489,6 @@ public class Mesh implements Iterable<Mesh.T> {
             pair.destroyed = true;
             if (next.t != null) next.t.destroy();
             if (prev.t != null) prev.t.destroy();
-            if (pair.next.t != null) ts.remove(pair.next.t);
-            if (pair.prev.t != null) ts.remove(pair.prev.t);
             next.t = null;
             prev.t = null;
             pair.next.t = null;
@@ -484,8 +501,6 @@ public class Mesh implements Iterable<Mesh.T> {
             pair.next = prev;
             if (p1.e == this) p1.e = prev.next;
             if (pair.p1.e == pair) pair.p1.e = pair.prev.next;
-            es.remove(this);
-            es.remove(pair);
             avgedge -= this.length();
             avgedge -= pair.length();
             numedges--;
@@ -499,7 +514,6 @@ public class Mesh implements Iterable<Mesh.T> {
             if (this.next.p1 != p2) throw new Error();
             if (this.prev.p2 != p1) throw new Error();
             if (this.p1.e == null) this.p1.e = this;
-            es.add(this);
             if (!added) {
                 added = true;
                 numedges++;
@@ -630,7 +644,6 @@ public class Mesh implements Iterable<Mesh.T> {
         public final int color;
 
         public void destroy() {
-            ts.remove(this);
         }
 
         T(E e1) {
@@ -656,8 +669,6 @@ public class Mesh implements Iterable<Mesh.T> {
             }
             this.color = color;
 
-            // FIXME unnecssary?
-            ts.add(this);
             v1().kdinsert();
             v2().kdinsert();
             v3().kdinsert();