checkpoint
authoradam <adam@megacz.com>
Mon, 26 Nov 2007 04:32:41 +0000 (20:32 -0800)
committeradam <adam@megacz.com>
Mon, 26 Nov 2007 04:32:41 +0000 (20:32 -0800)
darcs-hash:20071126043241-5007d-01db63af80f2573f11f0fb94ac110291d8a7fb05.gz

src/Geom.java
src/Main.java

index 944ee61..9c639e1 100644 (file)
@@ -9,7 +9,7 @@ public class Geom implements Iterable<Geom.T> {
 
     private HashMap<P,P> ps = new HashMap<P,P>();
     private HashMap<E,E> es = new HashMap<E,E>();
-    private HashSet<T> ts = new HashSet<T>();
+    private HashSet<T>   ts = new HashSet<T>();
 
     public Iterator<T> iterator() { return ts.iterator(); }
 
@@ -39,11 +39,11 @@ public class Geom implements Iterable<Geom.T> {
         return new T(e1, e2, e3);
     }
 
-    /** point in 3-space */
+    /** [UNIQUE] point in 3-space */
     public final class P {
         public final float x, y, z;
         public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
-        public V minus(P p) { return null; }
+        public V minus(P p) { return new V(x-p.x, y-p.y, z-p.z); }
         public boolean equals(Object o) {
             if (o==null || !(o instanceof P)) return false;
             P p = (P)o;
@@ -62,12 +62,13 @@ public class Geom implements Iterable<Geom.T> {
     public final class V {
         private final float x, y, z;
         public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
-        public V norm() { return null; /* FIXME */ }
         public boolean sameDirection(V v) { throw new Error(); }
-        public V cross(V v) { return null; }
+        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 float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
+        public V norm() { float m = mag(); return new V(x/m, y/m, z/m); }
     }
 
-    /** an edge */
+    /** [UNIQUE] an edge */
     public final class E {
         public final P p1, p2;
         T t1, t2;
@@ -96,7 +97,7 @@ public class Geom implements Iterable<Geom.T> {
         }
     }
 
-    /** a triangle (face) */
+    /** [UNIQUE] a triangle (face) */
     public final class T {
         public final E e1, e2, e3;
         public T(E e1, E e2, E e3, V normal) {
@@ -134,19 +135,6 @@ public class Geom implements Iterable<Geom.T> {
             ts.add(this);
         }
         public boolean hasE(E e) { return e1==e || e2==e || e3==e; }
-
-        // technically not required
-        /*
-        public int hashCode() { return e1.hashCode() ^ e2.hashCode() ^ e3.hashCode(); }
-        public boolean equals(Object o) {
-            if (o==null || !(o instanceof T)) return false;
-            T t = (T)o;
-            if (this.e1 == t.e1 && this.e2 == t.e2 && this.e3 == t.e3) return true;
-            if (this.e1 == t.e2 && this.e2 == t.e3 && this.e3 == t.e1) return true;
-            if (this.e1 == t.e3 && this.e2 == t.e1 && this.e3 == t.e2) return true;
-            return false;
-        }
-        */
         public void glVertices(GL gl) {
             e1.unshared(e2).glVertex(gl);
             e1.shared(e2).glVertex(gl);
index 64852c9..3acb5e0 100644 (file)
@@ -10,18 +10,10 @@ public class Main implements GLEventListener {
 
     public Main(StlFile stlf) {
         for(int i=0; i<stlf.coordArray.length; i+=3) {
-            Geom.P p0 = geom.newP(stlf.coordArray[i+0].x,
-                                  stlf.coordArray[i+0].y,
-                                  stlf.coordArray[i+0].z);
-            Geom.P p1 = geom.newP(stlf.coordArray[i+1].x,
-                                  stlf.coordArray[i+1].y,
-                                  stlf.coordArray[i+1].z);
-            Geom.P p2 = geom.newP(stlf.coordArray[i+2].x,
-                                  stlf.coordArray[i+2].y,
-                                  stlf.coordArray[i+2].z);
-            Geom.T t = geom.newT(geom.newE(p0, p1),
-                                 geom.newE(p1, p2),
-                                 geom.newE(p2, p0));
+            Geom.P p0 = geom.newP(stlf.coordArray[i+0].x, stlf.coordArray[i+0].y, stlf.coordArray[i+0].z);
+            Geom.P p1 = geom.newP(stlf.coordArray[i+1].x, stlf.coordArray[i+1].y, stlf.coordArray[i+1].z);
+            Geom.P p2 = geom.newP(stlf.coordArray[i+2].x, stlf.coordArray[i+2].y, stlf.coordArray[i+2].z);
+            Geom.T t  = geom.newT(geom.newE(p0, p1), geom.newE(p1, p2), geom.newE(p2, p0));
         }
     }
 
@@ -39,9 +31,8 @@ public class Main implements GLEventListener {
         display(gld);
     }
 
-    /**
-     * Take care of drawing here.
-     */
+    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
     public void display(GLAutoDrawable drawable) {
         float red = 0.0f;
         float green = 0.0f;
@@ -63,9 +54,6 @@ public class Main implements GLEventListener {
             gl.glEnd();
         }
     }
-    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
-    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
-
 
     public static void main(String[] s) throws Exception {
         StlFile stlf = new StlFile();