X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fbind%2FBindingGroup.java;h=9356ec455b6aceae2696800a9b520e38947629c0;hp=e93edf86accb46df2c9e86d0c529fdd5ba0ba3b5;hb=553823b9fbe373bbc8b5409c423857253f18c4aa;hpb=1cfea6e5d6ca9e75578e97d1fdccf2b306af56c4 diff --git a/src/edu/berkeley/qfat/bind/BindingGroup.java b/src/edu/berkeley/qfat/bind/BindingGroup.java index e93edf8..9356ec4 100644 --- a/src/edu/berkeley/qfat/bind/BindingGroup.java +++ b/src/edu/berkeley/qfat/bind/BindingGroup.java @@ -21,30 +21,28 @@ class BindingGroup implements Iterable { int size() { return matrices.size(); } - /** merge another binding group with this one */ - void merge(BindingGroup bg, Matrix m) { + /** merge another binding group into this one */ + void merge(BindingGroup bg, Matrix m, float epsilon) { if (bg==this) { - if (m.equalsModuloEpsilon(Matrix.ONE, 0.001f)) return; - constraint = constraint.intersect(m.getAffineConstraint(0.001f), 0.001f); + if (m.equalsModuloEpsilon(Matrix.ONE, epsilon)) return; + // FIXME: what if points do not fall on the merged constraint-line? + constraint = constraint.intersect(m.getAffineConstraint(epsilon), epsilon); return; } - for(HasBindingGroup hbg : bg.matrices.keySet()) { - matrices.put((T)hbg, bg.matrices.get(hbg).times(m)); + for(HasBindingGroup hbg : bg) { + matrices.put((T)hbg, bg.getMatrix((T)hbg).times(m)); hbg.bindingGroup = this; } // FIXME: what if points do not fall on the merged constraint-line? AffineConstraint ac = bg.constraint.multiply(getMatrix(master, bg.master)); - constraint = constraint.intersect(ac, 0.001f); + constraint = constraint.intersect(ac, epsilon); - HashSet stuff = new HashSet(); - for(HasBindingGroup hbg : bg.matrices.keySet()) - stuff.add(hbg); - bg.matrices.clear(); bg.master = null; - for(HasBindingGroup hbg : stuff) - hbg.bindingGroupChanged(); + for(HasBindingGroup hbg : bg) hbg.bindingGroupChanged(); + bg.matrices.clear(); + bg.matrices = null; } public Matrix getMatrix(T t) { return matrices.get(t); } @@ -59,11 +57,11 @@ class BindingGroup implements Iterable { return getMatrix(t1).times(getMatrix(t2).inverse()); } - public AffineConstraint getConstraint(T t) { + public AffineConstraint getAffineConstraint(T t) { return constraint.multiply(matrices.get(t)); } - public void unbind(T trem) { + void unbind(T trem) { if (trem != master) { matrices.remove(trem); return; @@ -76,7 +74,11 @@ class BindingGroup implements Iterable { Iterator it = iterator(); T newmaster = it.next(); if (newmaster==trem) newmaster = it.next(); - if (newmaster==trem) throw new Error(); + if (newmaster==trem) throw new Error("impossible"); + + // FIXME: is this correct? + constraint = constraint.multiply(getMatrix(newmaster, master)); + HashMap newmatrices = new HashMap(); for(T t : matrices.keySet()) { if (t==trem) continue;