- 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 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); }
- public String toString() { return "("+x+","+y+","+z+")"; }
- // FIXME: moving a point alters its hashCode
- public int hashCode() {
- return
- Float.floatToIntBits(x) ^
- Float.floatToIntBits(y) ^
- Float.floatToIntBits(z);
- }
- }
-
- /** vector in 3-space */
- public final class Vec {
- public final float x, y, z;
- public Vec(double x, double y, double z) { this((float)x, (float)y, (float)z); }
- public Vec(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
- public Vec(P p1, P p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
- public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
- public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); }
- public Vec norm() { return mag()==0 ? this : div(mag()); }
- public Vec times(M m) { return m.apply(this); }
- public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
- public float dot(Vec v) { return x*v.x + y*v.y + z*v.z; }
- public Vec times(float mag) { return new Vec(x*mag, y*mag, z*mag); }
- public Vec div(float mag) { return new Vec(x/mag, y/mag, z/mag); }
- public String toString() { return "<"+x+","+y+","+z+">"; }
- }
-
- public class BindingGroup {
- public HashSet<E> es = new HashSet<E>();
- public BindingGroup() { }
- public BindingGroup(E e) {
- es.add(e);
- }
- public void add(E e) {
- if (e.bg != null) { merge(e.bg); return; }
- es.add(e);
- e.bg = this;
- }
- public void merge(BindingGroup bg) {
- for(E e : bg.es) {
- e.bg = null;
- add(e);
- }
- }
- }
-