checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / Point.java
diff --git a/src/edu/berkeley/qfat/geom/Point.java b/src/edu/berkeley/qfat/geom/Point.java
new file mode 100644 (file)
index 0000000..d54e631
--- /dev/null
@@ -0,0 +1,19 @@
+package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
+
+/** point in 3-space; immutable */
+public final class Point {
+    public final float x, y, z;
+    public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
+    public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
+    public float distance(Point 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 Point times(Matrix m) { return m.times(this); }
+    public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
+    public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
+    public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)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+")"; }
+    public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
+}