checkpoint
authoradam <adam@megacz.com>
Mon, 7 Jul 2008 19:26:04 +0000 (12:26 -0700)
committeradam <adam@megacz.com>
Mon, 7 Jul 2008 19:26:04 +0000 (12:26 -0700)
darcs-hash:20080707192604-5007d-38b0642d2f0011b30fb9326c87523a15e351cc1d.gz

src/edu/berkeley/qfat/Mesh.java
src/edu/berkeley/qfat/bind/BindingGroup.java
src/edu/berkeley/qfat/bind/HasBindingGroup.java
src/edu/berkeley/qfat/geom/Matrix.java

index 3a53041..3111b81 100644 (file)
@@ -687,8 +687,8 @@ public class Mesh implements Iterable<Mesh.T> {
                 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());
                 */
             }
         }
@@ -732,8 +732,8 @@ public class Mesh implements Iterable<Mesh.T> {
                 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());
         }
@@ -1065,8 +1065,8 @@ public class Mesh implements Iterable<Mesh.T> {
             }
             */
             /*
-            first.setConstraint(firste.getConstraint());
-            firstq.setConstraint(firste.getConstraint());
+            first.setConstraint(firste.getAffineConstraint());
+            firstq.setConstraint(firste.getAffineConstraint());
             */
             return null;
         }
index 270bc78..9356ec4 100644 (file)
@@ -21,7 +21,7 @@ class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
 
     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;
@@ -30,8 +30,8 @@ class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
             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;
         }
 
@@ -40,9 +40,9 @@ class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
         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); }
@@ -57,11 +57,11 @@ class BindingGroup<T extends HasBindingGroup> implements Iterable<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;
@@ -74,7 +74,11 @@ class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
         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;
index 1b19310..42cd2d0 100644 (file)
@@ -35,7 +35,7 @@ public abstract class HasBindingGroup {
 
     public AffineConstraint getBindingConstraint() {
         if (bindingGroup==null) return new AffineConstraint.All();
-        return bindingGroup.getConstraint(this);
+        return bindingGroup.getAffineConstraint(this);
     }
 
     public Matrix getBindingMatrix() {
index 3713761..c2419d6 100644 (file)
@@ -368,15 +368,15 @@ public class Matrix {
 
     /** 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;