X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeom.java;h=445c896f391e1229d3d16e23d1bf004e0057cf9a;hb=04b2e2c139e2087242fa911a6d3a8991d285bbb3;hp=080690e66e577ad6ec109eaca8a9e0c60245b951;hpb=113b9ec23d89a15c3d57532909e85580df4c4580;p=anneal.git diff --git a/src/Geom.java b/src/Geom.java index 080690e..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; @@ -196,10 +211,44 @@ public class Geom implements Iterable { E next; // next half-edge E pair; // partner half-edge + + public BindingGroup bg = null; + public void bind(E e) { bind(e, new M()); } public void bind(E e, M m) { - p1.bind(e.p2); - p2.bind(e.p1); + 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 (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() {