- public Vec norm() {
- Vec norm = new Vec(0, 0, 0);
- E e = this.e;
- do {
- if (e.t != null) norm = norm.plus(e.t.norm().times((float)e.prev.angle()));
- e = e.pair.next;
- } while(e != this.e);
- return norm.norm();
+ }
+
+ public class BindingGroup {
+ private HashSet<E> left = new HashSet<E>();
+ private HashSet<E> right = new HashSet<E>();
+ public BindingGroup() { }
+ public BindingGroup(E e) {
+ left.add(e);
+ }
+ public void add(E e, boolean swap) {
+ if (e.bg != null) {
+ if (e.bg == this) return;
+ 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;
+ }
+ }
+ public void dobind(E e) {
+ // assumes e is part of the "left" set
+ 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);
+ }
+ for(E e : right) {
+ e.shatter(e.midpoint(), bg2, bg1); /* swap correct? */
+ }