checkpoint
[anneal.git] / src / edu / berkeley / qfat / Geom.java
index 80d2dd6..18b17d1 100644 (file)
@@ -5,7 +5,9 @@ import java.awt.event.*;
 import javax.swing.*;
 import javax.media.opengl.*;
 import javax.media.opengl.glu.*;
+import edu.berkeley.qfat.geom.*;
 import edu.wlu.cs.levy.CG.KDTree;
+import edu.berkeley.qfat.geom.Point;
 
 public class Geom implements Iterable<Geom.T> {
 
@@ -65,7 +67,7 @@ public class Geom implements Iterable<Geom.T> {
         return (float)(dist/num);
     }
 
-    public void transform(M m) {
+    public void transform(Matrix m) {
         ArrayList<Vert> set = new ArrayList<Vert>();
         set.addAll(ps.values());
         for(Vert v : set) v.transform(m);
@@ -237,7 +239,7 @@ public class Geom implements Iterable<Geom.T> {
 
 
         /** does NOT update bound pairs! */
-        public boolean transform(M m) {
+        public boolean transform(Matrix m) {
             // FIXME: screws up kdtree 
             // FIXME: screws up hashmap
             unscore();
@@ -272,7 +274,7 @@ public class Geom implements Iterable<Geom.T> {
             return good;
         }
         public boolean move(Vec v) {
-            M m = new M(v);
+            Matrix m = new Matrix(v);
             Vert p = this;
             boolean good = true;
             do {
@@ -328,12 +330,12 @@ public class Geom implements Iterable<Geom.T> {
             return false;
         }
 
-        public void unbind() { bound_to = this; binding = new M(); }
-        public void bind(Vert p) { bind(p, new M()); }
-        public void bind(Vert p, M binding) {
+        public void unbind() { bound_to = this; binding = new Matrix(); }
+        public void bind(Vert p) { bind(p, new Matrix()); }
+        public void bind(Vert p, Matrix binding) {
             if (isBoundTo(p)) return;
             Vert temp_bound_to = p.bound_to;
-            M temp_binding = p.binding;
+            Matrix temp_binding = p.binding;
             p.bound_to = this.bound_to;
             p.binding = binding.times(this.binding); // FIXME: may have order wrong here
             this.bound_to = temp_bound_to;
@@ -356,7 +358,7 @@ public class Geom implements Iterable<Geom.T> {
         float watch_z;
         Vert watch;
         E e;                // some edge *leaving* this point
-        M binding = new M();
+        Matrix binding = new Matrix();
         float oldscore = 0;
         boolean inserted = false;
     }
@@ -447,8 +449,8 @@ public class Geom implements Iterable<Geom.T> {
 
         public BindingGroup bg = new BindingGroup(this);
 
-        public void bind(E e) { bind(e, new M()); }
-        public void bind(E e, M m) { e.bg.add(this); }
+        public void bind(E e) { bind(e, new Matrix()); }
+        public void bind(E e, Matrix m) { e.bg.add(this); }
 
         public void dobind() {
             if (bg==null) return;
@@ -681,104 +683,4 @@ public class Geom implements Iterable<Geom.T> {
     
     public Vert register(Point p) { Vert v = ps.get(p); return v==null ? new Vert(p) : v; }
 
-    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    /** point in 3-space; immutable */
-    public static final class Point {
-        public final float x, y, z;
-        public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
-        public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
-        public float distance(Point p) { return distance(p.x, p.y, p.z); }
-        public float distance(float ox, float oy, float oz) { return (float)Math.sqrt((x-ox)*(x-ox)+(y-oy)*(y-oy)+(z-oz)*(z-oz)); }
-        public Point times(M m) { return m.times(this); }
-        public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
-        public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
-        public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
-        public void glVertex(GL gl) { _glVertex(gl); }
-        private void _glVertex(GL gl) { gl.glVertex3f(x, y, z); }
-        public String toString() { return "("+x+","+y+","+z+")"; }
-        public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
-    }
-
-    /** vector in 3-space; immutable */
-    public static final class Vec {
-        public final float x, y, z;
-        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(Point p1, Point 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(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+">"; }
-    }
-
-    /** affine matrix; immutable */
-    public static class M {
-        //
-        //  [ a b c d ]   [ x ]
-        //  [ e f g h ]   [ y ]
-        //  [ i j k l ]   [ z ]
-        //  [ 0 0 0 1 ]   [ 1 ]
-        //
-        public final float a, b, c, d, e, f, g, h, i, j, k, l;
-        public M() { this(1); }
-        public M(float scale) {
-            a = f = k = scale;
-            l = h = d = e = b = i = c = j = g = 0;            
-        }
-        public M(float scalex, float scaley, float scalez) {
-            a = scalex;
-            f = scaley;
-            k = scalez;
-            l = h = d = e = b = i = c = j = g = 0;            
-        }
-        public M(Vec translate) {
-            d = translate.x; h = translate.y; l = translate.z;
-            a = f = k = 1;
-            b = c = e = g = i = j = 0;
-        }
-        public M(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
-            this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f; this.g = g; this.h = h; this.i = i;
-            this.j = j; this.k = k; this.l = l;
-        }
-        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(Vec axis, float angle) {
-            double q = Math.cos(angle);
-            double s = Math.sin(angle);
-            double t = 1.0 - q;
-            a = (float)(q + axis.x*axis.x*t);
-            f = (float)(q + axis.y*axis.y*t);
-            k = (float)(q + axis.z*axis.z*t);
-            double tmp1 = axis.x*axis.y*t;
-            double tmp2 = axis.z*s;
-            e = (float)(tmp1 + tmp2);
-            b = (float)(tmp1 - tmp2);
-            tmp1 = axis.x*axis.z*t;
-            tmp2 = axis.y*s;
-            i = (float)(tmp1 - tmp2);
-            c = (float)(tmp1 + tmp2);
-            tmp1 = axis.y*axis.z*t;
-            tmp2 = axis.x*s;
-            j = (float)(tmp1 + tmp2);
-            g = (float)(tmp1 - tmp2);
-            d = h = l = 0;
-        }
-        public Point times(Point p) {
-            return new Point(a*p.x + b*p.y + c*p.z + d,
-                        e*p.x + f*p.y + g*p.z + h,
-                        i*p.x + j*p.y + k*p.z + l);
-        }
-        public Point apply(Point p) { return p; }
-        public Vec apply(Vec v) { return v; }
-        public M invert() { return this; }
-        public M times(M m) { return this; }
-    }
-
 }