checkpoint
[anneal.git] / src / Geom.java
1 import java.awt.*;
2 import java.util.*;
3 import java.awt.event.*;
4 import javax.swing.*;
5 import javax.media.opengl.*;
6 import javax.media.opengl.glu.*;
7
8 public class Geom {
9
10     private HashMap<P,P> ps = new HashMap<P,P>();
11
12     public P newP(float x, float y, float z) {
13         P p = new P(x, y, z);
14         P p2 = ps.get(p);
15         if (p2 != null) return p2;
16         ps.put(p, p);
17         return p;
18     }
19
20     /** point in 3-space */
21     public class P {
22         public final float x, y, z;
23         public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
24         public V minus(P p) { return null; }
25         public boolean equals(Object o) {
26             if (o==null || !(o instanceof P)) return false;
27             P p = (P)o;
28             return p.x==x && p.y==y && p.z==z;
29         }
30         public int hashCode() {
31             return
32                 Float.floatToIntBits(x) ^
33                 Float.floatToIntBits(y) ^
34                 Float.floatToIntBits(z);
35         }
36     }
37
38     /** vector in 3-space */
39     public class V {
40         private final float x, y, z;
41         public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
42         public V norm() { return null; /* FIXME */ }
43         public boolean sameDirection(V v) { throw new Error(); }
44         public V cross(V v) { return null; }
45     }
46
47     /** an edge */
48     public class E {
49         public final P p1, p2;
50         private T t1, t2;
51         public E(P p1, P p2) { this.p1 = p1; this.p2 = p2; }
52         public boolean equals(Object o) {
53             if (o==null || !(o instanceof E)) return false;
54             E e = (E)o;
55             if (this.p1 == e.p1 && this.p2 == e.p2) return true;
56             if (this.p2 == e.p1 && this.p1 == e.p2) return true;
57             return false;
58         }
59         public P shared(E e) { return null; }
60     }
61
62     /** a triangle (face) */
63     public class T {
64         public final E e1, e2, e3;
65         public T(E e1, E e2, E e3, V normal) {
66             P p1 = e1.shared(e2);
67             P p2 = e2.shared(e3);
68             P p3 = e3.shared(e1);
69             V norm = p2.minus(p1).cross(p3.minus(p1));
70             if (norm.sameDirection(normal)) {
71                 this.e1 = e1;
72                 this.e2 = e2;
73                 this.e3 = e3;
74             } else {
75                 this.e1 = e3;
76                 this.e2 = e2;
77                 this.e3 = e1;
78             }
79         }
80         public V norm() {
81             P p1 = e1.shared(e2);
82             P p2 = e2.shared(e3);
83             P p3 = e3.shared(e1);
84             return p2.minus(p1).cross(p3.minus(p1)).norm();
85         }
86         public T(E e1, E e2, E e3) { this.e1 = e1; this.e2 = e2; this.e3 = e3; }
87     }
88
89     /** matrix */
90     public class M {
91     }
92
93 }