}
public class BindingGroup {
- private HashSet<E> ess = new HashSet<E>();
+ private HashSet<E> left = new HashSet<E>();
+ private HashSet<E> right = new HashSet<E>();
public BindingGroup() { }
public BindingGroup(E e) {
- ess.add(e);
+ left.add(e);
}
public void add(E e) {
if (e.bg != null) {
- for(E ex : e.bg.ess) {
- ex.bg = null;
- add(ex);
+ if (e.bg == this) return;
+ for(E ex : e.bg.left) {
+ ex.bg = this;
+ left.add(ex);
+ }
+ for(E ex : e.bg.right) {
+ ex.bg = this;
+ right.add(ex);
}
} else {
- ess.add(e);
+ left.add(e);
e.bg = this;
}
}
public void dobind(E e) {
- for(E ex : ess) {
+ // assumes e is part of the "left" set
+ for(E ex : left) {
if (ex==e) continue;
e.p1.bind(ex.p1);
e.p2.bind(ex.p2);
}
+ for(E ex : right) {
+ if (ex==e) continue;
+ e.p1.bind(ex.pair.p1);
+ e.p2.bind(ex.pair.p2);
+ }
}
public void shatter(BindingGroup bg1, BindingGroup bg2) {
- for(E e : ess) {
+ for(E e : left) {
e.shatter(e.midpoint(), bg1, bg2);
}
+ for(E e : right) {
+ e.shatter(e.midpoint(), bg2, bg1); /* swap correct? */
+ }
}
}