checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 1a1b9a3..50df8dd 100644 (file)
@@ -17,8 +17,8 @@ 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  ArrayList<T>         ts = new ArrayList<T>();
 
     public Iterator<T> iterator() { return ts.iterator(); }
 
@@ -28,15 +28,17 @@ public class Mesh implements Iterable<Mesh.T> {
     public double score = 0;
     public float score() { return (float)score; }
 
-    public void unbind() {
+    public int numedges = 0;
+    public float avgedge = 0;
 
+    public void unbind() {
         for(Mesh.T t : this) {
             t.p1().unbind();
             t.p2().unbind();
             t.p3().unbind();
         }
-
     }
+
     public void bind() {
         for(Mesh.T t : this) {
             t.e1().dobind();
@@ -44,8 +46,6 @@ public class Mesh implements Iterable<Mesh.T> {
             t.e3().dobind();
         }
     }
-    public int numedges = 0;
-    public float avgedge = 0;
 
     public float rescore() {
         int num = 0;
@@ -111,14 +111,6 @@ public class Mesh implements Iterable<Mesh.T> {
                      (float)(max_z + min_z)/2);
     }
 
-    public T newT(Vert p12, Vert p23, Vert p31, Vec norm) {
-        Vec norm2 = p31.p.minus(p12.p).cross(p23.p.minus(p12.p));
-        float dot = norm.dot(norm2);
-        //if (Math.abs(dot) < EPointSILON) throw new Error("dot products within epsilon of each other: "+norm+" "+norm2);
-        if (dot < 0) { Vert p = p12; p12=p23; p23 = p; }
-        return newT(p12, p23, p31);
-    }
-
     public float volume() {
         double total = 0;
         for(T t : ts) {
@@ -137,7 +129,13 @@ public class Mesh implements Iterable<Mesh.T> {
         return (Vert)results[0];
     }
 
-    public T newT(Vert p1, Vert p2, Vert p3) {
+    public T newT(Vert p1, Vert p2, Vert p3, Vec norm) {
+        if (norm != null) {
+            Vec norm2 = p3.p.minus(p1.p).cross(p2.p.minus(p1.p));
+            float dot = norm.dot(norm2);
+            //if (Math.abs(dot) < EPointSILON) throw new Error("dot products within epsilon of each other: "+norm+" "+norm2);
+            if (dot < 0) { Vert p = p1; p1=p2; p2 = p; }
+        }
         E e12 = p1.makeE(p2);
         E e23 = p2.makeE(p3);
         E e31 = p3.makeE(p1);
@@ -238,7 +236,6 @@ public class Mesh implements Iterable<Mesh.T> {
             score += oldscore;
         }
 
-
         /** does NOT update bound pairs! */
         public boolean transform(Matrix m) {
             // FIXME: screws up kdtree 
@@ -478,8 +475,8 @@ public class Mesh implements Iterable<Mesh.T> {
             pair.shatter();
             destroy();
 
-            newT(r, p1, mid);
-            newT(r, mid, p2);
+            newT(r, p1, mid, null);
+            newT(r, mid, p2, null);
             bg1.add(p1.getE(mid));
             bg2.add(mid.getE(p2));
             return mid;