- /** 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);
- }
- }