checkpoint
[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, AffineConstraint {
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 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)); }
16
17     public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
18     public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
19     public Point midpoint(Point p) { return new Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2); }
20
21     public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
22
23     public String toString() { return "("+x+","+y+","+z+")"; }
24
25     public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
26     public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
27
28     public Point getPoint() { return this; }
29
30     public float getMaxX() { return x; }
31     public float getMinX() { return x; }
32     public float getMaxY() { return y; }
33     public float getMinY() { return y; }
34     public float getMaxZ() { return z; }
35     public float getMinZ() { return z; }
36
37     public Point getProjection(Point p) { return this; }
38     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
39         if (c.getProjection(this).distance(this) <= epsilon) return this;
40         return null;
41     }
42 }
43