Mesh.java: better error for zero-length edges, and add numTriangles() method
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index 502fa6d..1a96e7d 100644 (file)
@@ -85,6 +85,7 @@ public class Mesh implements Iterable<Mesh.T> {
     public float error() { return (float)error; }
 
     public int size() { return vertices.size(); }
     public float error() { return (float)error; }
 
     public int size() { return vertices.size(); }
+    public int numTriangles() { return triangles.size(); }
     public Iterable<Vertex> vertices() { return vertices; }
     public Iterator<T> iterator() { return triangles.iterator(); }
 
     public Iterable<Vertex> vertices() { return vertices; }
     public Iterator<T> iterator() { return triangles.iterator(); }
 
@@ -713,6 +714,7 @@ public class Mesh implements Iterable<Mesh.T> {
             bindEdge(e, m);
         }
         public void bindEdge(E e, Matrix m) {
             bindEdge(e, m);
         }
         public void bindEdge(E e, Matrix m) {
+            /*
             for(E e_ : (Iterable<E>)e.getBoundPeers()) {
                 if (e.v1.getPoint().distance((e.getBindingMatrix(e_).times(e_.v1.getPoint()))) > 0.01f)
                     throw new RuntimeException("blah! " + e.v1.getPoint() + " " + e.getBindingMatrix(e_).times(e_.v1.getPoint()));
             for(E e_ : (Iterable<E>)e.getBoundPeers()) {
                 if (e.v1.getPoint().distance((e.getBindingMatrix(e_).times(e_.v1.getPoint()))) > 0.01f)
                     throw new RuntimeException("blah! " + e.v1.getPoint() + " " + e.getBindingMatrix(e_).times(e_.v1.getPoint()));
@@ -723,6 +725,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 if (v2.getPoint().distance(m.times(e.getBindingMatrix(e_).times(e_.v2.getPoint()))) > 0.01f)
                     throw new RuntimeException("blah! " + v2.getPoint() + " " + m.times(e_.v2.getPoint()));
             }
                 if (v2.getPoint().distance(m.times(e.getBindingMatrix(e_).times(e_.v2.getPoint()))) > 0.01f)
                     throw new RuntimeException("blah! " + v2.getPoint() + " " + m.times(e_.v2.getPoint()));
             }
+            */
             this.bindTo(m, e,      EPSILON);
             this.pair.bindTo(m, e.pair, EPSILON);
         }
             this.bindTo(m, e,      EPSILON);
             this.pair.bindTo(m, e.pair, EPSILON);
         }
@@ -896,6 +899,7 @@ public class Mesh implements Iterable<Mesh.T> {
         public E(Point v1, Point v2) {
             if (vertices.get(v1) != null) throw new Error();
             if (vertices.get(v2) != null) throw new Error();
         public E(Point v1, Point v2) {
             if (vertices.get(v1) != null) throw new Error();
             if (vertices.get(v2) != null) throw new Error();
+            if (v1.equals(v2)) throw new Error("attempt to create a zero-length edge!");
             this.v1 = new Vertex(v1);
             this.v2 = new Vertex(v2);
             this.prev = this.next = this.pair = new E(this, this, this);
             this.v1 = new Vertex(v1);
             this.v2 = new Vertex(v2);
             this.prev = this.next = this.pair = new E(this, this, this);