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) {
+ public BindingGroup(E e) { add(null, e, false); }
+ public void add(E ethis, E e, boolean swap) {
+ if (ethis==null) { }
+ else if (right.contains(ethis)) swap = !swap;
+ else if (!left.contains(ethis)) throw new Error();
+
if (e.bg != null) {
- if (e.bg == this) return; /* fixme what if it is in the "other" set? */
+ if (e.bg == this) {
+ if ((!swap ? right : left).contains(e)) throw new Error("double bind!");
+ return;
+ }
for(E ex : (!swap ? e.bg.left : e.bg.right)) {
ex.bg = this;
left.add(ex);
(!swap ? left : right).add(e);
e.bg = this;
}
-
for(E ex : (!swap ? right : left)) {
- if (e.next.isBoundTo(ex.next)) {
+ if (e.prev.isBoundTo(ex.prev)) {
System.out.println("hit!");
}
}
public int compareTo(E e) { return e.length() > length() ? 1 : -1; }
-
- public void bindEdge(E e) {
- bg.add(e, true);
- }
+ public void bindEdge(E e) { bg.add(this, e, true); }
public void dobind() { if (bg != null) bg.dobind(this); }
public Point shatter() { return shatter(midpoint(), null, null, false); }
newT(r.p, p1.p, mid, null);
newT(r.p, mid, p2.p, null);
- (swap ? bg1 : bg2).add(p1.getE(mid), swap);
- (swap ? bg2 : bg1).add(p2.getE(mid).pair, swap);
+ (swap ? bg1 : bg2).add(null, p1.getE(mid), swap);
+ (swap ? bg2 : bg1).add(null, p2.getE(mid).pair, swap);
return mid;
}