checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 68e9c23..951f53a 100644 (file)
@@ -78,8 +78,6 @@ public class Mesh implements Iterable<Mesh.T> {
         public Point p, oldp, goodp;
         E e;                // some edge *leaving* this point
 
-        Matrix binding = Matrix.ONE;
-        Vertex bound_to = this;
         private boolean illegal = false;
 
         public Point getPoint() { return p; }
@@ -161,11 +159,14 @@ public class Mesh implements Iterable<Mesh.T> {
 
         public boolean move(Matrix m, boolean ignoreProblems) {
             boolean good = true;
-            for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to)
+
+            for(Vertex p : (Iterable<Vertex>)getBoundPeers())
                 good &= p.transform(m.times(p.p), ignoreProblems);
-            for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to)
+
+            for(Vertex p : (Iterable<Vertex>)getBoundPeers())
                 if (good || ignoreProblems)  p.reComputeErrorAround();
-                else                         p.transform(p.oldp, true);
+                else                              p.transform(p.oldp, true);
+
             return good;
         }
 
@@ -260,24 +261,7 @@ public class Mesh implements Iterable<Mesh.T> {
             return norm.norm();
         }
 
-        public boolean isBoundTo(Vertex p) {
-            for(Vertex px = p; px!=null; px=(px.bound_to==p?null:px.bound_to))
-                if (px==this)
-                    return true;
-            return false;
-        }
-
-        public void unbind() { bound_to = this; binding = Matrix.ONE; }
-        public void bind(Vertex p) { bind(p, Matrix.ONE); }
-        public void bind(Vertex p, Matrix binding) {
-            if (isBoundTo(p)) return;
-            Vertex temp_bound_to = p.bound_to;
-            Matrix temp_binding = p.binding;
-            p.bound_to = this.bound_to;
-            p.binding = binding.times(this.binding); // FIXME: may have order wrong here
-            this.bound_to = temp_bound_to;
-            this.binding = temp_binding.times(temp_binding); // FIXME: may have order wrong here
-        }
+        public void bindTo(Vertex p) { bindTo(Matrix.ONE, p); }
     }
 
     public class BindingGroup {
@@ -309,8 +293,8 @@ public class Mesh implements Iterable<Mesh.T> {
         }
         public void dobind(E e) {
             for(E ebound : set) {
-                e.p1.bind(ebound.p2);
-                e.p2.bind(ebound.p1);
+                e.p1.bindTo(Matrix.ONE, ebound.p2);
+                e.p2.bindTo(Matrix.ONE, ebound.p1);
             }
         }
         public void shatter(BindingGroup bg1, BindingGroup bg2, boolean triangles) {
@@ -357,6 +341,9 @@ public class Mesh implements Iterable<Mesh.T> {
         public Point shatter() { return shatter(true); }
         public Point shatter(boolean triangles) { return shatter(midpoint(), null, null, triangles); }
         public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2, boolean triangles) {
+            return shatter(mid, bg1, bg2, triangles, false);
+        }
+        public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2, boolean triangles, boolean leader) {
             if (shattered || destroyed) return mid;
             shattered = true;
 
@@ -382,6 +369,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 newT(r.p, mid, p2.p, null, old_colorclass);
                 bg1.add(p1.getE(mid));
                 bg2.add(p2.getE(mid).pair);
+                if (leader) p1.getE(mid).shatter();
             }
             return mid;
         }
@@ -602,6 +590,9 @@ public class Mesh implements Iterable<Mesh.T> {
         public void reinsert() { triangles.remove(this); triangles.add(this); }
 
         public boolean shouldBeDrawn() {
+            if (e1().bind_to==null) return false;
+            if (e2().bind_to==null) return false;
+            if (e3().bind_to==null) return false;
             if (e1().bind_to.set.size() == 0) return false;
             if (e2().bind_to.set.size() == 0) return false;
             if (e3().bind_to.set.size() == 0) return false;