checkpoint autogen tile
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 0d7a96a..1e83eee 100644 (file)
@@ -192,12 +192,18 @@ public class Mesh implements Iterable<Mesh.T> {
                     throw new Error(v.p+" "+pt2+"\n"+op+" "+pt+"\n"+v.getBindingMatrix(this));
                 if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) < 1/5) throw new Error();
                 */
-                good &= v.transform(pt2,
-                                    ignoreProblems, v.getBindingMatrix(this));
+                good &= v.transform(pt2, ignoreProblems, v.getBindingMatrix(this));
+            }
+
+            if (!good) {
+                for(Vertex v : (Iterable<Vertex>)getBoundPeers()) 
+                    v.transform(v.oldp, true, null);
             }
 
             for(Vertex v : (Iterable<Vertex>)getBoundPeers())
                 v.recomputeFundamentalQuadricIfNeighborChanged();
+            for(Vertex v : (Iterable<Vertex>)getBoundPeers())
+                v.reComputeErrorAround();
             return good;
         }
 
@@ -411,12 +417,14 @@ public class Mesh implements Iterable<Mesh.T> {
                 Point mid = e.midpoint();
                 Vertex r = e.next.p2;
                 Vertex l = e.pair.next.p2;
-                e.destroy();
-                e.pair.destroy();
-                newT(r.p, e.p1.p, mid,    null, 0);
-                newT(r.p, mid,    e.p2.p, null, 0);
-                newT(l.p, mid,    e.p1.p, null, 0);
-                newT(l.p, e.p2.p, mid,    null, 0);
+                if (!e.destroyed) {
+                    e.destroy();
+                    e.pair.destroy();
+                    newT(r.p, e.p1.p, mid,    null, 0);
+                    newT(r.p, mid,    e.p2.p, null, 0);
+                    newT(l.p, mid,    e.p1.p, null, 0);
+                    newT(l.p, e.p2.p, mid,    null, 0);
+                }
             }
             for(E e : (Iterable<E>)getBoundPeers()) {
                 Point mid = e.midpoint();
@@ -431,6 +439,10 @@ public class Mesh implements Iterable<Mesh.T> {
                 e.p1.getE(mid).pair.     bindTo(e.getBindingMatrix(firste), first.pair);
                 e.p2.getE(mid).pair.     bindTo(e.getBindingMatrix(firste), firstq);
                 e.p2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
+                first.bindingGroup.setKrank(e.bindingGroup.krank);
+                firstq.bindingGroup.setKrank(e.bindingGroup.krank);
+                first.pair.bindingGroup.setKrank(e.bindingGroup.krank);
+                firstq.pair.bindingGroup.setKrank(e.bindingGroup.krank);
             }
             return null;
         }