X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2FGeom.java;h=445c896f391e1229d3d16e23d1bf004e0057cf9a;hb=04b2e2c139e2087242fa911a6d3a8991d285bbb3;hp=42abd82b039ef1fd01ec3049e35efa33814fdd93;hpb=1a864cc577c2b31049cd46f4fd9ed703802d7d17;p=anneal.git diff --git a/src/Geom.java b/src/Geom.java index 42abd82..445c896 100644 --- a/src/Geom.java +++ b/src/Geom.java @@ -188,6 +188,21 @@ public class Geom implements Iterable { public String toString() { return "<"+x+","+y+","+z+">"; } } + public class BindingGroup { + public HashSet es = new HashSet(); + public BindingGroup() { } + public merge(E e) { + if (e.bg != null) merge(e.bg); + else { es.add(e); e.bg = this; } + } + public merge(BindingGroup bg) { + for(E e : bg.es) { + e.bg = this; + this.bg.add(e); + } + } + } + /** [UNIQUE] an edge */ public final class E { public final P p1, p2; @@ -197,27 +212,43 @@ public class Geom implements Iterable { E pair; // partner half-edge - public E bound_to = this; - public M bound_m = new M(); + public BindingGroup bg = null; 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) { + if (e.bg != null) e.bg.merge(this); + else if (bg != null) bg.merge(e); + else { + bg = new BindingGroup(); + bg.merge(this); + bg.merge(e); + } } 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); + if (bg==null) return; + for(E ex : bg.es) { + if (ex==this) continue; + p1.bind(ex.p1); + p2.bind(ex.p2); + } } + public boolean destroyed = false; public void shatter() { + if (destroyed) return; + /* + HashSet eh = new HashSet(); + 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() {