checkpoint
[anneal.git] / src / Geom.java
index 6bfe4f1..c7374f7 100644 (file)
@@ -13,11 +13,9 @@ public class Geom implements Iterable<Geom.T> {
     public static float EPSILON = (float)0.0001;
     public static Random random = new Random();
 
-    private HashMap<P,P> ps = new HashMap<P,P>();
-    //public PriorityQueue<E>   es = new PriorityQueue<E>();
-    public HashSet<E>   es = new HashSet<E>();
-    //private HashSet<T>   ts = new HashSet<T>();
-    public ArrayList<T>   ts = new ArrayList<T>();
+    private HashMap<P,P>  ps = new HashMap<P,P>();
+    public  HashSet<E>    es = new HashSet<E>();
+    public  ArrayList<T>  ts = new ArrayList<T>();
 
     public Iterator<T> iterator() { return ts.iterator(); }
 
@@ -55,7 +53,7 @@ public class Geom implements Iterable<Geom.T> {
         for(P p : set) p.transform(m);
     }
 
-    public V diagonal() {
+    public Vec diagonal() {
         float min_x = Float.MAX_VALUE;
         float min_y = Float.MAX_VALUE;
         float min_z = Float.MAX_VALUE;
@@ -70,7 +68,7 @@ public class Geom implements Iterable<Geom.T> {
             if (p.y > max_y) max_y = p.y;
             if (p.z > max_z) max_z = p.z;
         }
-        return new V(max_x - min_x, max_y - min_y, max_z - min_z);
+        return new Vec(max_x - min_x, max_y - min_y, max_z - min_z);
     }
 
     public P centroid() {
@@ -96,8 +94,8 @@ public class Geom implements Iterable<Geom.T> {
     public P newP(double x, double y, double z) { return newP((float)x, (float)y, (float)z); }
     public P newP(float x, float y, float z) { return new P(x, y, z); }
     
-    public T newT(P p12, P p23, P p31, V norm) {
-        V norm2 = p31.minus(p12).cross(p23.minus(p12));
+    public T newT(P p12, P p23, P p31, Vec norm) {
+        Vec norm2 = p31.minus(p12).cross(p23.minus(p12));
         float dot = norm.dot(norm2);
         //if (Math.abs(dot) < EPSILON) throw new Error("dot products within epsilon of each other: "+norm+" "+norm2);
         if (dot < 0) { P p = p12; p12=p23; p23 = p; }
@@ -109,7 +107,7 @@ public class Geom implements Iterable<Geom.T> {
         double total = 0;
         for(T t : ts) {
             double area = t.area();
-            V origin_to_centroid = new V(newP(0, 0, 0), t.centroid());
+            Vec origin_to_centroid = new Vec(newP(0, 0, 0), t.centroid());
             boolean facingAway = t.norm().dot(origin_to_centroid) > 0;
             double height = Math.abs(t.norm().dot(origin_to_centroid));
             total += ((facingAway ? 1 : -1) * area * height) / 3.0;
@@ -142,14 +140,11 @@ public class Geom implements Iterable<Geom.T> {
         return ret;
     }
 
-    private char allname = 'A';
-
     public M aspect = new M();
     public M invaspect = new M();
 
     /** [UNIQUE] point in 3-space */
     public final class P {
-        char name;
 
         float x, y, z;
 
@@ -169,7 +164,7 @@ public class Geom implements Iterable<Geom.T> {
 
         public P register() {
             P p2 = ps.get(this);
-            if (p2==null) { p2 = this; ps.put(this,this); name = allname++; }
+            if (p2==null) { p2 = this; ps.put(this,this); }
             return p2;
         }
 
@@ -284,7 +279,7 @@ public class Geom implements Iterable<Geom.T> {
             */
             return good;
         }
-        public boolean move(V v) {
+        public boolean move(Vec v) {
             M m = new M(v);
             P p = this;
             boolean good = true;
@@ -361,8 +356,8 @@ public class Geom implements Iterable<Geom.T> {
             this.x = x; this.y = y; this.z = z;
         }
 
-        public V minus(P p) { return new V(x-p.x, y-p.y, z-p.z); }
-        public P plus(V v) { return newP(x+v.x, y+v.y, z+v.z); }
+        public Vec minus(P p) { return new Vec(x-p.x, y-p.y, z-p.z); }
+        public P plus(Vec v) { return newP(x+v.x, y+v.y, z+v.z); }
         public boolean equals(Object o) {
             if (o==null || !(o instanceof P)) return false;
             P p = (P)o;
@@ -382,8 +377,8 @@ public class Geom implements Iterable<Geom.T> {
             gl.glVertex3f(x, y, z);
         }
         public String toString() { return "("+x+","+y+","+z+")"; }
-        public V norm() {
-            V norm = new V(0, 0, 0);
+        public Vec norm() {
+            Vec norm = new Vec(0, 0, 0);
             E e = this.e;
             do {
                 if (e.t != null) norm = norm.plus(e.t.norm().times((float)e.prev.angle()));
@@ -394,19 +389,19 @@ public class Geom implements Iterable<Geom.T> {
     }
 
     /** vector in 3-space */
-    public final class V {
+    public final class Vec {
         public final float x, y, z;
-        public V(double x, double y, double z) { this((float)x, (float)y, (float)z); }
-        public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
-        public V(P p1, P p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
-        public V cross(V v) { return new V(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
-        public V plus(V v) { return new V(x+v.x, y+v.y, z+v.z); }
-        public V norm() { return mag()==0 ? this : div(mag()); }
-        public V times(M m) { return m.apply(this); }
+        public Vec(double x, double y, double z) { this((float)x, (float)y, (float)z); }
+        public Vec(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
+        public Vec(P p1, P p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
+        public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
+        public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); }
+        public Vec norm() { return mag()==0 ? this : div(mag()); }
+        public Vec times(M m) { return m.apply(this); }
         public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
-        public float dot(V v) { return x*v.x + y*v.y + z*v.z; }
-        public V times(float mag) { return new V(x*mag, y*mag, z*mag); }
-        public V div(float mag) { return new V(x/mag, y/mag, z/mag); }
+        public float dot(Vec v) { return x*v.x + y*v.y + z*v.z; }
+        public Vec times(float mag) { return new Vec(x*mag, y*mag, z*mag); }
+        public Vec div(float mag) { return new Vec(x/mag, y/mag, z/mag); }
         public String toString() { return "<"+x+","+y+","+z+">"; }
     }
 
@@ -600,8 +595,8 @@ public class Geom implements Iterable<Geom.T> {
 
         /** angle between this half-edge and the next */
         public double angle() {
-            V v1 = next.p2.minus(p2);
-            V v2 = this.p1.minus(p2);
+            Vec v1 = next.p2.minus(p2);
+            Vec v2 = this.p1.minus(p2);
             return Math.acos(v1.norm().dot(v2.norm()));
         }
 
@@ -729,12 +724,12 @@ public class Geom implements Iterable<Geom.T> {
         public E e1() { return e1; }
         public E e2() { return e1.next; }
         public E e3() { return e1.prev; }
-        public V norm() { return p2().minus(p1()).cross(p3().minus(p1())).norm(); }
+        public Vec norm() { return p2().minus(p1()).cross(p3().minus(p1())).norm(); }
         public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; }
         public boolean has(P p) { return p1()==p || p2()==p || p3()==p; }
 
         public float area() {
-            return (float)Math.abs(0.5 * e1().length() * new V(p1(), p2()).norm().dot(new V(p2(), p3())));
+            return (float)Math.abs(0.5 * e1().length() * new Vec(p1(), p2()).norm().dot(new Vec(p2(), p3())));
         }
 
         public void glVertices(GL gl) {
@@ -775,7 +770,7 @@ public class Geom implements Iterable<Geom.T> {
             k = scalez;
             l = h = d = e = b = i = c = j = g = 0;            
         }
-        public M(V translate) {
+        public M(Vec translate) {
             d = translate.x; h = translate.y; l = translate.z;
             a = f = k = 1;
             b = c = e = g = i = j = 0;
@@ -787,7 +782,7 @@ public class Geom implements Iterable<Geom.T> {
         public M times(float x) {
             return new M(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x);
         }
-        public M(V axis, float angle) {
+        public M(Vec axis, float angle) {
             double q = Math.cos(angle);
             double s = Math.sin(angle);
             double t = 1.0 - q;
@@ -814,7 +809,7 @@ public class Geom implements Iterable<Geom.T> {
                         i*p.x + j*p.y + k*p.z + l);
         }
         public P apply(P p) { return p; }
-        public V apply(V v) { return v; }
+        public Vec apply(Vec v) { return v; }
         public M invert() { return this; }
         public M times(M m) { return this; }
     }