From 3b3dd514ddc6861b08fc3deffaa018f32b7c9c78 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 4 Dec 2007 19:58:26 -0800 Subject: [PATCH] checkpoint darcs-hash:20071205035826-5007d-bcf53b88b32cb3020d6da3b4a10fdf49c8438a40.gz --- src/Geom.java | 19 ++++++++----------- src/Main.java | 32 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Geom.java b/src/Geom.java index c9404d9..6a11064 100644 --- a/src/Geom.java +++ b/src/Geom.java @@ -19,7 +19,7 @@ public class Geom implements Iterable { public Iterator 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 { (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 { 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 { } 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 { 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 { 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 { 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 { 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); } diff --git a/src/Main.java b/src/Main.java index bc01a06..0408329 100644 --- a/src/Main.java +++ b/src/Main.java @@ -77,9 +77,9 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener public Main(StlFile stlf) { for(int i=0; i