checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 46c2200..e3a7cde 100644 (file)
@@ -126,6 +126,7 @@ public class Mesh implements Iterable<Mesh.T> {
     public Vert nearest(Point p) { return pointset.nearest(p); }
 
     public final class Vert extends HasPoint {
+        public String toString() { return p.toString(); }
         public Point p;
         E e;                // some edge *leaving* this point
 
@@ -233,35 +234,41 @@ public class Mesh implements Iterable<Mesh.T> {
         }
         public void computeError() {
             if (quadric_count == 0) {
-                if (nearest_in_other_mesh == null) {
+                if (!tilemesh) {
+                }
+                else if (nearest_in_other_mesh == null) {
                     if (score_against != null) {
                         Vert ne = score_against.nearest(p);
-                        oldscore = ne.fundamentalQuadric().preAndPostMultiply(p) * 100 * 3;
+                        oldscore = ne.fundamentalQuadric().preAndPostMultiply(p) * 100 * 100;
                     } else {
                         oldscore = 0;
                     }
                 } else {
-                    oldscore = nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 3;
+                    oldscore = nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 100;
                 }
             } else {
-                oldscore = (quadric.preAndPostMultiply(p) * 100) / quadric_count;
+                oldscore = (quadric.preAndPostMultiply(p) * 100);
             }
 
-            oldscore = oldscore*oldscore;
+            oldscore = oldscore;
 
             int numaspects = 0;
             float aspects = 0;
             E e = this.e;
             do {
+                //double ang = Math.abs(e.crossAngle());
                 double ang = Math.abs(e.crossAngle());
                 if (ang > Math.PI) throw new Error();
+                /*
                 if (e.t != null) {
                     numaspects++;
                     aspects += e.t.aspect()*e.t.aspect();
                 }
+                */
 
-                if (ang > Math.PI * 0.8)
-                    oldscore += (ang - (Math.PI*0.8)) * 10;
+                float minangle = (float)(Math.PI * 0.9);
+                if (ang > minangle)
+                    oldscore += (ang - minangle);
 
                 e = e.pair.next;
             } while (e != this.e);
@@ -297,7 +304,8 @@ public class Mesh implements Iterable<Mesh.T> {
 
             // FIXME: intersection test needed?
             boolean good = true;
-            /*
+
+            if (!ignorecollision)
             for(T t : Mesh.this) {
                 if (!good) break;
                 e = this.e;
@@ -311,7 +319,7 @@ public class Mesh implements Iterable<Mesh.T> {
                     e = e.pair.next;
                 } while(e != this.e);
             }
-            */
+
             reComputeErrorAround();
             return good;
         }
@@ -331,7 +339,14 @@ public class Mesh implements Iterable<Mesh.T> {
             E ret = getFreeIncident(e, e);
             if (ret != null) return ret;
             ret = getFreeIncident(e.pair.next, e.pair.next);
-            if (ret == null) throw new Error("unable to find free incident to " + this);
+            if (ret == null) {
+                E ex = e;
+                do {
+                    System.out.println(ex + " " + ex.t);
+                    ex = ex.pair.next;
+                } while (ex != e);
+                throw new Error("unable to find free incident to " + this);
+            }
             return ret;
         }
 
@@ -443,10 +458,20 @@ public class Mesh implements Iterable<Mesh.T> {
         boolean shattered = false;
 
         public float comparator() {
-            if (t==null) return length();
+            Vert nearest = score_against.nearest(midpoint());
+            //if (t==null) return length();
+            /*
+            double ang = Math.abs(crossAngle());
+            float minangle = (float)(Math.PI * 0.9);
+            if (ang > minangle)
+                return 300;
+            */
+            /*
             if ((length() * length()) / t.area() > 10)
                 return (float)(length()*Math.sqrt(t.area()));
             return length()*t.area();
+            */
+            return length() + midpoint().distance(nearest.p);
         }
         public int compareTo(E e) {
             return e.comparator() > comparator() ? 1 : -1;
@@ -804,5 +829,6 @@ public class Mesh implements Iterable<Mesh.T> {
             p3().glVertex(gl);
         }
     }
-
+    public boolean tilemesh = false;
+    public boolean ignorecollision = false;
 }