v1.bindTo(getBindingMatrix(e), e.v1);
v2.bindTo(getBindingMatrix(e), e.v2);
/*
- e.v1.setConstraint(getConstraint());
- e.v2.setConstraint(getConstraint());
+ e.v1.setConstraint(getAffineConstraint());
+ e.v2.setConstraint(getAffineConstraint());
*/
}
}
e.v2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
}
/*
- first.setConstraint(firste.getConstraint());
- firstq.setConstraint(firste.getConstraint());
+ first.setConstraint(firste.getAffineConstraint());
+ firstq.setConstraint(firste.getAffineConstraint());
*/
return nearest(midpoint());
}
}
*/
/*
- first.setConstraint(firste.getConstraint());
- firstq.setConstraint(firste.getConstraint());
+ first.setConstraint(firste.getAffineConstraint());
+ firstq.setConstraint(firste.getAffineConstraint());
*/
return null;
}
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;
public AffineConstraint getBindingConstraint() {
if (bindingGroup==null) return new AffineConstraint.All();
- return bindingGroup.getConstraint(this);
+ return bindingGroup.getAffineConstraint(this);
}
public Matrix getBindingMatrix() {
/** returns the constraint-conjunction "(forall v)Mv=v" */
public AffineConstraint getAffineConstraint(float epsilon) {
- AffineConstraint c1 = getConstraint(a-1, b, c, d , epsilon);
- AffineConstraint c2 = getConstraint(e, f-1, g, h , epsilon);
- AffineConstraint c3 = getConstraint(i, j, k-1, l , epsilon);
+ AffineConstraint c1 = getAffineConstraint(a-1, b, c, d , epsilon);
+ AffineConstraint c2 = getAffineConstraint(e, f-1, g, h , epsilon);
+ AffineConstraint c3 = getAffineConstraint(i, j, k-1, l , epsilon);
// FIXME: bottom row constraint?
return c1.intersect(c2.intersect(c3, epsilon), epsilon);
}
/** the AffineConstraint representing ax+by+cz+d=0 */
- private static AffineConstraint getConstraint(float a, float b, float c, float d, float epsilon) {
+ private static AffineConstraint getAffineConstraint(float a, float b, float c, float d, float epsilon) {
a = Math.abs(a) <= epsilon ? 0 : a;
b = Math.abs(b) <= epsilon ? 0 : b;
c = Math.abs(c) <= epsilon ? 0 : c;