more speed enhancements for simplex
[org.ibex.core.git] / src / org / ibex / Box.java
index 3c3b868..59d4ca7 100644 (file)
@@ -245,7 +245,7 @@ public final class Box extends JSScope implements Scheduler.Task {
 
     void constrain() {
         //#repeat contentwidth/contentheight colspan/rowspan col/row cols/rows minwidth/minheight \
-        //        textwidth/textheight maxwidth/maxheight cols/rows
+        //        textwidth/textheight maxwidth/maxheight cols/rows rowspan/colspan row/col rows/cols
         // FIXME: inefficient
         contentwidth = 0;
         for(int i=0; i<rows; i++) {
@@ -294,14 +294,14 @@ public final class Box extends JSScope implements Scheduler.Task {
     }
 
     private static float[] coeff = null;
-    private static LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex(50, 50, 300);
-    private static LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex(50, 50, 300);
+    private static LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex(100, 100, 300);
+    private static LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex(100, 100, 300);
 
     void place_children() {
         int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
-        //#repeat col/row colspan/rowspan contentwidth/contentheight width/height \
+        //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK \
         //        maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp_v lp_h/lp_v
-        do {
+       if (cols > 1) {
             int nc = numkids * 2 + cols * 3 + 1 + 2;
             if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
             lp_h.init(nc);
@@ -326,11 +326,12 @@ public final class Box extends JSScope implements Scheduler.Task {
                 for(int i=0; i<coeff.length; i++)
                     coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
                 lp_h.add_constraint(coeff, LinearProgramming.GE, (float)child.contentwidth);
-                if (child.maxwidth < Integer.MAX_VALUE) {
+                int child_maxwidth = child.test(HSHRINK) ? min(child.maxwidth, child.contentwidth) : child.maxwidth;
+                if (child_maxwidth < Integer.MAX_VALUE) {
                     for(int i=0; i<coeff.length; i++)
                         coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
                     coeff[cols*2+childnum] = (float)-1.0;
-                    lp_h.add_constraint(coeff, LinearProgramming.EQ, (float)child.maxwidth);
+                    lp_h.add_constraint(coeff, LinearProgramming.EQ, (float)child_maxwidth);
                 }
                 for(int j=0; j<coeff.length; j++) coeff[j] = (float)0.0;
                 childnum++;
@@ -348,7 +349,7 @@ public final class Box extends JSScope implements Scheduler.Task {
             }
             for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
             lp_h.solve();
-        } while(false);
+        }
         //#end
         
         for(Box child = getChild(0); child != null; child = child.nextSibling()) {
@@ -370,8 +371,15 @@ public final class Box extends JSScope implements Scheduler.Task {
                 //        child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP lp_h/lp_v
                 child_width = 0;
                 child_x = 0;
-                for(int i=0; i < child.col; i++) child_x += Math.round(lp_h.solution[lp_h.rows+i+1]);
-                for(int i = child.col; i<child.col + child.colspan; i++) child_width += Math.round(lp_h.solution[lp_h.rows+i+1]);
+                if (cols == 1) {
+                    child_x = 0;
+                    child_width = width;
+                } else {
+                    for(int i=0; i < child.col; i++)
+                        child_x += Math.round(lp_h.solution[lp_h.rows+i+1]);
+                    for(int i = child.col; i<child.col + child.colspan; i++)
+                        child_width += Math.round(lp_h.solution[lp_h.rows+i+1]);
+                }
                 diff = (child_width - min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth));
                 child_x += (child.test(ALIGN_RIGHT) ? diff : child.test(ALIGN_LEFT) ? 0 : diff / 2);
                 child_width = min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth);
@@ -731,6 +739,7 @@ public final class Box extends JSScope implements Scheduler.Task {
             fillcolor = newfillcolor;
         } else if(value instanceof JS) {
             texture = Picture.load((JS)value, this);
+            if (texture != null && texture.isLoaded) perform();
         } else {
             throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass());
         }