20048e46a0ee404ac80755411a5efd3ba0098ee5
[anneal.git] / src / edu / berkeley / qfat / geom / Point.java
1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3 import javax.media.opengl.glu.*;
4
5 /** point in 3-space; immutable */
6 public final class Point extends HasPoint implements HasBoundingBox {
7
8     public static final Point ZERO = new Point(0,0,0);
9
10     public final float x, y, z;
11
12     public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
13     public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
14
15     public static final Point ORIGIN = new Point(0,0,0);
16
17     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)); }
18
19     public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
20     public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
21     public Point midpoint(Point p) { return new Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2); }
22
23     public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
24
25     public String toString() { return "("+x+","+y+","+z+")"; }
26
27     public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
28     public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
29
30     public Point getPoint() { return this; }
31
32     public float getMaxX() { return x; }
33     public float getMinX() { return x; }
34     public float getMaxY() { return y; }
35     public float getMinY() { return y; }
36     public float getMaxZ() { return z; }
37     public float getMinZ() { return z; }
38 }
39