add items to TODO list
[anneal.git] / src / edu / berkeley / qfat / geom / Point.java
index 2de47a6..f011243 100644 (file)
@@ -3,17 +3,20 @@ import javax.media.opengl.*;
 import javax.media.opengl.glu.*;
 
 /** point in 3-space; immutable */
-public final class Point implements HasBoundingBox {
+public final class Point implements HasBoundingBox, AffineConstraint, HasPoint {
+
+    public static final Point ZERO = new Point(0,0,0);
+
     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 static final Point ORIGIN = new Point(0,0,0);
-
     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)); }
 
     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 Point midpoint(Point p) { return new Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2); }
 
     public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
 
@@ -22,6 +25,8 @@ public final class Point implements HasBoundingBox {
     public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
     public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
 
+    public Point getPoint() { return this; }
+
     public float getMaxX() { return x; }
     public float getMinX() { return x; }
     public float getMaxY() { return y; }
@@ -29,18 +34,14 @@ public final class Point implements HasBoundingBox {
     public float getMaxZ() { return z; }
     public float getMinZ() { return z; }
 
-    public Point glProject(GL gl) {
-        Point p = this;
-        int viewport[] = new int[4];
-        double mvmatrix[] = new double[16];
-        double projmatrix[] = new double[16];
-        double wcoord[] = new double[4];
-        gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
-        gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
-        gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
-        GLU glu = new GLU();
-        glu.gluProject(p.x, p.y, p.z, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);
-        return new Point(wcoord[0], wcoord[1], 0);
+    public Point getProjection(Point p) { return this; }
+    public AffineConstraint intersect(AffineConstraint c, float epsilon) {
+        Point p2 = c.getProjection(this);
+        if (p2==null) return AffineConstraint.NONE;
+        if (p2.distance(this) <= epsilon) return this;
+        return AffineConstraint.NONE;
     }
+    public AffineConstraint multiply(Matrix m) { return m.times(this); }
+
 }