checkpoint
[anneal.git] / src / Geom.java
index 42abd82..316e334 100644 (file)
@@ -198,26 +198,36 @@ public class Geom implements Iterable<Geom.T> {
 
 
         public E bound_to = this;
-        public M bound_m  = new M();
 
         public void bind(E e) { bind(e, new M()); }
-        public void bind(E e2, M m) {
-            E e1 = this;
-            while(e1.bound_to != e1) e1 = e1.bound_to;
-            while(e2.bound_to != e2) e2 = e2.bound_to;
-            e1.bound_to = e2;
+        public void bind(E e, M m) {
+            E old = this.bound_to;
+            this.bound_to = e.bound_to;
+            e.bound_to = old;
         }
 
         public void dobind() {
-            if (bound_to == this) return;
-            E ex = this;
-            M m = new M();
-            while(ex.bound_to != ex) { m = m.times(ex.bound_m); ex = ex.bound_to; }
-            p1.bind(ex.bound_to.p1);
-            p2.bind(ex.bound_to.p2);
+            for(E ex = bound_to; ex != this; ex = ex.bound_to) {
+                p1.bind(ex.p1);
+                p2.bind(ex.p2);
+            }
         }
 
+        public boolean destroyed = false;
         public void shatter() {
+            if (destroyed) return;
+            /*
+            HashSet<E> eh = new HashSet<E>();
+            eh.add(this);
+            for(E ex = bound_to; ex != this; ex = ex.bound_to) eh.add(ex);
+            E[] es = (E[])eh.toArray(new E[0]);
+            */
+            destroy();
+            pair.shatter();
+            for(E ex = bound_to; ex != this; ex = ex.bound_to) ex.shatter();
+        }
+        public void destroy() {
+            this.destroyed = true;
         }
 
         private void sync() {