+ public class BindingGroup {
+ private HashSet<E> left = new HashSet<E>();
+ private HashSet<E> right = new HashSet<E>();
+ public BindingGroup() { }
+ public BindingGroup(E e) { add(e, false); }
+ public void add(E e, boolean swap) {
+ if (e.bg != null) {
+ if (e.bg == this) return; /* fixme what if it is in the "other" set? */
+ for(E ex : (!swap ? e.bg.left : e.bg.right)) {
+ ex.bg = this;
+ left.add(ex);
+ }
+ for(E ex : (!swap ? e.bg.right : e.bg.left)) {
+ ex.bg = this;
+ right.add(ex);
+ }
+
+ } else {
+ (!swap ? left : right).add(e);
+ e.bg = this;
+ }
+
+ for(E ex : (!swap ? right : left)) {
+ if (e.next.isBoundTo(ex.next)) {
+ System.out.println("hit!");
+ }
+ }
+ }
+ public boolean isBoundTo(E e1, E e2) {
+ if (left.contains(e1) && right.contains(e2)) return true;
+ if (left.contains(e2) && right.contains(e1)) return true;
+ return false;
+ }
+ public void dobind(E e) {
+ Vert v1 = null;
+ Vert v2 = null;
+ if (left.contains(e)) { v1 = e.p1; v2 = e.p2; }
+ if (right.contains(e)) { v1 = e.p2; v2 = e.p1; }
+ for(E ex : left) {
+ if (ex==e) continue;
+ v1.bind(ex.p1);
+ v2.bind(ex.p2);
+ }
+ for(E ex : right) {
+ if (ex==e) continue;
+ v1.bind(ex.p2);
+ v2.bind(ex.p1);
+ }
+ }
+ public void shatter(BindingGroup bg1, BindingGroup bg2) {
+ for(E e : left) {
+ e.shatter(e.midpoint(), bg1, bg2, false);
+ }
+ for(E e : right) {
+ e.shatter(e.midpoint(), bg1, bg2, true); // swap correct?
+ }
+ }
+ }
+