checkpoint
authoradam <adam@megacz.com>
Wed, 5 Dec 2007 03:26:31 +0000 (19:26 -0800)
committeradam <adam@megacz.com>
Wed, 5 Dec 2007 03:26:31 +0000 (19:26 -0800)
darcs-hash:20071205032631-5007d-c425261bd24cc4e183fc92ea17f05bb4174d6a5e.gz

src/Geom.java

index c7374f7..89acb70 100644 (file)
@@ -13,7 +13,7 @@ public class Geom implements Iterable<Geom.T> {
     public static float EPSILON = (float)0.0001;
     public static Random random = new Random();
 
-    private HashMap<P,P>  ps = new HashMap<P,P>();
+    private HashMap<P,V>  ps = new HashMap<P,V>();
     public  HashSet<E>    es = new HashSet<E>();
     public  ArrayList<T>  ts = new ArrayList<T>();
 
@@ -143,9 +143,15 @@ public class Geom implements Iterable<Geom.T> {
     public M aspect = new M();
     public M invaspect = new M();
 
-    /** [UNIQUE] point in 3-space */
-    public final class P {
+    public final class V extends P {
+        public V(P p) {
+            super(p.x, p.y, p.z);
+            if (ps.get(p) != null) throw new Error();
+            ps.put(this, this);
+        }
+    }
 
+    public class P {
         float x, y, z;
 
         int watch_count;
@@ -162,10 +168,10 @@ public class Geom implements Iterable<Geom.T> {
         
         private boolean inserted = false;
 
-        public P register() {
-            P p2 = ps.get(this);
-            if (p2==null) { p2 = this; ps.put(this,this); }
-            return p2;
+        public V register() {
+            V v = ps.get(this);
+            if (v==null) v = new V(this);
+            return (V)v;
         }
 
         public void kdremove() {
@@ -257,7 +263,7 @@ public class Geom implements Iterable<Geom.T> {
                 this.y = newy;
                 this.z = newz;
                 // FIXME: what if we move onto exactly where another point is?
-                ps.put(this,this);
+                ps.put((V)this,(V)this);
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }