checkpoint
authoradam <adam@megacz.com>
Wed, 5 Dec 2007 03:58:26 +0000 (19:58 -0800)
committeradam <adam@megacz.com>
Wed, 5 Dec 2007 03:58:26 +0000 (19:58 -0800)
darcs-hash:20071205035826-5007d-bcf53b88b32cb3020d6da3b4a10fdf49c8438a40.gz

src/Geom.java
src/Main.java

index c9404d9..6a11064 100644 (file)
@@ -19,7 +19,7 @@ public class Geom implements Iterable<Geom.T> {
 
     public Iterator<T> iterator() { return ts.iterator(); }
 
-    public P origin() { return newP(0, 0, 0); }
+    public P origin() { return new P(0, 0, 0); }
 
     public Geom score_against = null;
     public double score = 0;
@@ -91,9 +91,6 @@ public class Geom implements Iterable<Geom.T> {
                      (float)(max_z + min_z)/2);
     }
 
-    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(V p12, V p23, V p31, Vec norm) {
         Vec norm2 = p31.p.minus(p12.p).cross(p23.p.minus(p12.p));
         float dot = norm.dot(norm2);
@@ -102,12 +99,11 @@ public class Geom implements Iterable<Geom.T> {
         return newT(p12, p23, p31);
     }
 
-
     public float volume() {
         double total = 0;
         for(T t : ts) {
             double area = t.area();
-            Vec origin_to_centroid = new Vec(newP(0, 0, 0), t.centroid());
+            Vec origin_to_centroid = new Vec(new P(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;
@@ -176,7 +172,7 @@ public class Geom implements Iterable<Geom.T> {
         }
         public V partner() { return watch==null ? this : watch; }
         public V watchback() { return watch_count==0 ? partner() :
-                newP(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count).register(); }
+                new P(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count).register(); }
         public void rescore() {
             if (score_against == null) return;
 
@@ -335,13 +331,14 @@ public class Geom implements Iterable<Geom.T> {
 
     public class P {
         float x, y, z;
+        public P(double x, double y, double z) { this((float)x, (float)y, (float)z); }
         public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
         public float distance(P 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 V register() { V v = ps.get(this); return v==null ? new V(this) : v; }
         public P times(M m) { return m.times(this); }
         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 P plus(Vec v) { return new P(x+v.x, y+v.y, z+v.z); }
         public boolean equals(Object o) { return o!=null && (o instanceof P) && ((P)o).x==x && ((P)o).y==y && ((P)o).z==z; }
         public void glVertex(GL gl) { _glVertex(gl); }
         private void _glVertex(GL gl) { gl.glVertex3f(x, y, z); }
@@ -623,7 +620,7 @@ public class Geom implements Iterable<Geom.T> {
             this.pair = pair;
             sync();
         }
-        public P midpoint() { return newP((p1.p.x+p2.p.x)/2, (p1.p.y+p2.p.y)/2, (p1.p.z+p2.p.z)/2); }
+        public P midpoint() { return new P((p1.p.x+p2.p.x)/2, (p1.p.y+p2.p.y)/2, (p1.p.z+p2.p.z)/2); }
         public boolean has(V v) { return v==p1 || v==p2; }
         public float length() { return p1.p.minus(p2.p).mag(); }
         public String toString() { return p1+"->"+p2; }
@@ -698,7 +695,7 @@ public class Geom implements Iterable<Geom.T> {
             p3().p.glVertex(gl);
         }
 
-        public P centroid() { return newP((p1().p.x+p2().p.x+p3().p.x)/3,
+        public P centroid() { return new P((p1().p.x+p2().p.x+p3().p.x)/3,
                                           (p1().p.y+p2().p.y+p3().p.y)/3, 
                                           (p1().p.z+p2().p.z+p3().p.z)/3); }
         public float diameter() {
@@ -764,7 +761,7 @@ public class Geom implements Iterable<Geom.T> {
             d = h = l = 0;
         }
         public P times(P p) {
-            return newP(a*p.x + b*p.y + c*p.z + d,
+            return new P(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);
         }
index bc01a06..0408329 100644 (file)
@@ -77,9 +77,9 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
     public Main(StlFile stlf) {
 
         for(int i=0; i<stlf.coordArray.length; i+=3) {
-            Geom.V p0 = goal.newP(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG).register();
-            Geom.V p1 = goal.newP(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG).register();
-            Geom.V p2 = goal.newP(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG).register();
+            Geom.V p0 = goal.new P(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG).register();
+            Geom.V p1 = goal.new P(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG).register();
+            Geom.V p2 = goal.new P(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG).register();
             Geom.Vec n  = goal.new Vec(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y  * MAG, stlf.normArray[i/3].z * MAG);
             Geom.T t  = goal.newT(p0, p1, p2, n);
         }
@@ -115,18 +115,18 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
         };
 
 
-        Geom.V ltf = tile.newP(-(width/2),  (height/2),  (depth/2)).register();
-        Geom.V mtf = tile.newP( 0.0,        (height/2),  (depth/2)).register();
-        Geom.V rtf = tile.newP( (width/2),  (height/2),  (depth/2)).register();
-        Geom.V ltn = tile.newP(-(width/2),  (height/2), -(depth/2)).register();
-        Geom.V mtn = tile.newP( 0.0,        (height/2), -(depth/2)).register();
-        Geom.V rtn = tile.newP( (width/2),  (height/2), -(depth/2)).register();
-        Geom.V lbf = tile.newP(-(width/2), -(height/2),  (depth/2)).register();
-        Geom.V mbf = tile.newP( 0.0,       -(height/2),  (depth/2)).register();
-        Geom.V rbf = tile.newP( (width/2), -(height/2),  (depth/2)).register();
-        Geom.V lbn = tile.newP(-(width/2), -(height/2), -(depth/2)).register();
-        Geom.V mbn = tile.newP( 0.0,       -(height/2), -(depth/2)).register();
-        Geom.V rbn = tile.newP( (width/2), -(height/2), -(depth/2)).register();
+        Geom.V ltf = tile.new P(-(width/2),  (height/2),  (depth/2)).register();
+        Geom.V mtf = tile.new P( 0.0,        (height/2),  (depth/2)).register();
+        Geom.V rtf = tile.new P( (width/2),  (height/2),  (depth/2)).register();
+        Geom.V ltn = tile.new P(-(width/2),  (height/2), -(depth/2)).register();
+        Geom.V mtn = tile.new P( 0.0,        (height/2), -(depth/2)).register();
+        Geom.V rtn = tile.new P( (width/2),  (height/2), -(depth/2)).register();
+        Geom.V lbf = tile.new P(-(width/2), -(height/2),  (depth/2)).register();
+        Geom.V mbf = tile.new P( 0.0,       -(height/2),  (depth/2)).register();
+        Geom.V rbf = tile.new P( (width/2), -(height/2),  (depth/2)).register();
+        Geom.V lbn = tile.new P(-(width/2), -(height/2), -(depth/2)).register();
+        Geom.V mbn = tile.new P( 0.0,       -(height/2), -(depth/2)).register();
+        Geom.V rbn = tile.new P( (width/2), -(height/2), -(depth/2)).register();
         
         points = new Geom.V[] {
             ltf,
@@ -351,7 +351,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
             //if (v1.z==0 && v1.y==0) continue;
             i++;
             if (i != 1 /*&& i!=4*/) continue;
-            Geom.V p = tile.newP(0, 0, 0).times(m).register();
+            Geom.V p = tile.new P(0, 0, 0).times(m).register();
             Geom.Vec v = tile.new Vec(p.p.x, p.p.y, p.p.z);
             v = v.times((float)1.04);
             gl.glTranslatef(v.x, v.y, v.z);