}
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() {
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); }
}
// 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);
}
}
public E makeE(V p2) {
- p2 = p2.register();
E e = getE(p2);
if (e != null) return e;
e = p2.getE(this);
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
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 */