checkpoint
[anneal.git] / src / edu / berkeley / qfat / geom / Point.java
1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3
4 /** point in 3-space; immutable */
5 public final class Point implements HasBoundingBox {
6     public final float x, y, z;
7     public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
8     public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
9
10     public float distance(Point p) { return (float)Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z)); }
11
12     public Point times(Matrix m) { return m.times(this); }
13     public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
14     public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
15
16     public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
17
18     public String toString() { return "("+x+","+y+","+z+")"; }
19
20     public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
21     public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
22
23     public float getMaxX() { return x; }
24     public float getMinX() { return x; }
25     public float getMaxY() { return y; }
26     public float getMinY() { return y; }
27     public float getMaxZ() { return z; }
28     public float getMinZ() { return z; }
29 }
30