From: adam Date: Wed, 5 Dec 2007 03:45:42 +0000 (-0800) Subject: checkpoint X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=2b22e6b0af24d1f81ced5f19ff6a742f60187d4e checkpoint darcs-hash:20071205034542-5007d-1056fc87199114429fd3b94c26378ecc7ba786f6.gz --- diff --git a/src/Geom.java b/src/Geom.java index 1c050c4..9cc1a4c 100644 --- a/src/Geom.java +++ b/src/Geom.java @@ -141,10 +141,12 @@ public class Geom implements Iterable { } public final class V extends P { + public P p = this; public V(P p) { super(p.x, p.y, p.z); if (ps.get(p) != null) throw new Error(); - ps.put(this, this); + this.p = p; + ps.put(this.p, this); } /* public int hashCode() { @@ -154,13 +156,11 @@ public class Geom implements Iterable { public void kdremove() { if (!inserted) return; inserted = false; - V p = this; try { kd.delete(new double[]{p.x,p.y,p.z}); } catch (Exception e) { } } public void kdinsert() { if (inserted) return; inserted = true; - V p = this; try { kd.insert(new double[]{p.x,p.y,p.z},this); } catch (Exception e) { throw new Error(e); } } @@ -218,16 +218,17 @@ public class Geom implements Iterable { // FIXME: screws up hashmap unscore(); try { - if (ps.get(this)==null) throw new Error(); - ps.remove(this); - float newx = m.a*x + m.b*y + m.c*z + m.d; - float newy = m.e*x + m.f*y + m.g*z + m.h; - float newz = m.i*x + m.j*y + m.k*z + m.l; + if (ps.get(this.p)==null) throw new Error(); + ps.remove(this.p); + float newx = m.a*p.x + m.b*p.y + m.c*p.z + m.d; + float newy = m.e*p.x + m.f*p.y + m.g*p.z + m.h; + float newz = m.i*p.x + m.j*p.y + m.k*p.z + m.l; this.x = newx; this.y = newy; this.z = newz; + this.p = new P(newx, newy, newz); // FIXME: what if we move onto exactly where another point is? - ps.put((V)this,(V)this); + ps.put(this.p,(V)this); } catch (Exception e) { throw new RuntimeException(e); } @@ -262,7 +263,6 @@ public class Geom implements Iterable { } public E makeE(V p2) { - p2 = p2.register(); E e = getE(p2); if (e != null) return e; e = p2.getE(this); @@ -331,41 +331,31 @@ public class Geom implements Iterable { return norm.norm(); } V bound_to = this; - } - - public class P { - float x, y, z; int watch_count; float watch_x; float watch_y; float watch_z; V watch; - E e; // some edge *leaving* this point M binding = new M(); - float oldscore = 0; - boolean inserted = false; + } + + public class P { + float x, y, 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 P(float x, float y, float z) { - this.x = x; this.y = y; this.z = 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; - return p.x==x && p.y==y && p.z==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); } + public String toString() { return "("+x+","+y+","+z+")"; } // FIXME: moving a point alters its hashCode public int hashCode() { return @@ -373,9 +363,6 @@ public class Geom implements Iterable { Float.floatToIntBits(y) ^ Float.floatToIntBits(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+")"; } } /** vector in 3-space */