- 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);
+ }
+ }
+
+ boolean shattered = false;
+ public P shatter() { return shatter(midpoint(), null, null); }
+ public P shatter(P mid, BindingGroup bg1, BindingGroup bg2) {
+ if (shattered) return mid;
+ shattered = true;
+
+ P r = next.p2;
+ E next = this.next;
+ E prev = this.prev;
+
+ if (bg1==null) bg1 = new BindingGroup();
+ if (bg2==null) bg2 = new BindingGroup();
+ for(E e : bg.es) e.shatter(e.midpoint(), bg1, bg2);
+ pair.shatter();
+ destroy();
+
+ newT(r, p1, mid);
+ newT(r, mid, p2);
+ bg1.add(p1.getE(mid));
+ bg2.add(mid.getE(p2));
+ return mid;