int size() { return matrices.size(); }
- /** merge another binding group with this one */
+ /** merge another binding group into this one */
void merge(BindingGroup<T> bg, Matrix m, float epsilon) {
if (bg==this) {
if (m.equalsModuloEpsilon(Matrix.ONE, epsilon)) return;
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;
}
constraint = constraint.intersect(ac, epsilon);
bg.master = null;
- for(HasBindingGroup hbg : bg.matrices.keySet())
- hbg.bindingGroupChanged();
+ for(HasBindingGroup hbg : bg) hbg.bindingGroupChanged();
bg.matrices.clear();
+ bg.matrices = null;
}
public Matrix getMatrix(T t) { return matrices.get(t); }
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;
Iterator<T> 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<T,Matrix> newmatrices = new HashMap<T,Matrix>();
for(T t : matrices.keySet()) {
if (t==trem) continue;