checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index c583106..3208442 100644 (file)
@@ -19,7 +19,6 @@ public class Mesh implements Iterable<Mesh.T> {
     private PointSet<Vertex> vertices  = new PointSet<Vertex>();
 
     public boolean immutableVertices;
-    public boolean ignorecollision    = false;
     public Mesh    error_against      = null;
     public double  error              = 0;
 
@@ -92,6 +91,8 @@ public class Mesh implements Iterable<Mesh.T> {
             vertices.add(this);
         }
 
+        public void reinsert() { vertices.remove(this); vertices.add(this); }
+
         public float olderror = 0;
         public void setError(float nerror) {
             error -= olderror;
@@ -135,29 +136,21 @@ public class Mesh implements Iterable<Mesh.T> {
 
             unApplyQuadricToNeighbor();
 
-            if (vertices.get(this.p)==null) throw new Error();
-            vertices.remove(this);
-            for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
-                if (e.t != null) e.t.removeFromRTree();
             this.p = newp;
-            for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
-                if (e.t != null) e.t.addToRTree();
-            vertices.add(this);
+            for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) e.t.reinsert();
+            reinsert();
 
             applyQuadricToNeighbor();
 
-            good = true;
-
-            if (!ignoreProblems)
-                for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
-                    if (Math.abs(e.crossAngle()) > (Math.PI * 0.9) || Math.abs(e.next.crossAngle()) > (Math.PI * 0.9)) good = false;
-                    if (e.t.aspect() < 0.1) good = false;
-                    e.p2.quadricStale = true;
-                }
-
-            if (!ignorecollision && !ignoreProblems && good)
-                triangles.range(oldp, this.p, (Visitor<T>)this);
+            if (ignoreProblems) return true;
 
+            good = true;
+            for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
+                if (Math.abs(e.crossAngle()) > (Math.PI * 0.9) || Math.abs(e.next.crossAngle()) > (Math.PI * 0.9)) good = false;
+                if (e.t.aspect() < 0.1) good = false;
+                e.p2.quadricStale = true;
+            }
+            if (good) triangles.range(oldp, this.p, (Visitor<T>)this);
             return good;
         }
 
@@ -165,10 +158,8 @@ public class Mesh implements Iterable<Mesh.T> {
             reComputeError();
             if (nearest_in_other_mesh != null)
                 nearest_in_other_mesh.reComputeError();
-            /*
             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next)
                 e.p2.reComputeError();
-            */
         }
 
         public boolean visit(Object o) {
@@ -510,18 +501,12 @@ public class Mesh implements Iterable<Mesh.T> {
         return ret;
     }
 
-
     /** [UNIQUE] a triangle (face) */
     public final class T extends Triangle {
         public final E e1;
         public final int color;
         public final int colorclass;
 
-        public void removeFromRTree() { triangles.remove(this); }
-        public void addToRTree() { triangles.insert(this); }
-
-        public void destroy() { triangles.remove(this); }
-
         T(E e1, int colorclass) {
             this.e1 = e1;
             E e2 = e1.next;
@@ -559,6 +544,11 @@ public class Mesh implements Iterable<Mesh.T> {
         public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; }
         public boolean has(Vertex v) { return v1()==v || v2()==v || v3()==v; }
 
+        public void removeFromRTree() { triangles.remove(this); }
+        public void addToRTree() { triangles.insert(this); }
+        public void destroy() { triangles.remove(this); }
+        public void reinsert() { triangles.remove(this); triangles.add(this); }
+
         public boolean shouldBeDrawn() {
             if (e1().bind_to.set.size() == 0) return false;
             if (e2().bind_to.set.size() == 0) return false;