more precise formulation
Adam Megacz <[email protected]> Fri, 02 Apr 2004 22:39:01 -0800
| Newsgroups | gmane.comp.java.xwt.core |
|---|---|
| Organization | Myself |
| Message-ID | <[email protected]> |
Okay, I think I have a sufficiently precise formulation of Charlie's
idea:
Let c1..cn be the widths of the columns. Create a set of constraint
equations such that:
c1 + c2 + c3 >= [minwidth of box spanning columns 1-3]
c2 + c3 + c4 >= [minwidth of box spanning columns 2-4]
Then, subject to these constraints, find the c1..cn that minimizes the
total sum of all columns. This is the 'contentwidth' that determines
the overall minimum size of the box (ie the constraining phase of
layout).
Once the parent's size has been chosen (ie in the sizing phase), *add*
the following equations to the constraint system:
c1 + c2 + c3 + ... = width
k1 = abs(width/n - c1)
k2 = abs(width/n - c2)
k3 = abs(width/n - c3)
...
Where n is the number of columns. Then solve with the goal of
minimizing k1+k2+k3.
To make the problem workable in the 9999-column case, you can
"collapse" a sequence of adjacent columns if they contain the same set
of boxes:
c1 + 2*c23 >= ...
2*c23 + c3 >= ...
Note that all the problems above are what are called "linear
programming problems" [*]; there has been a lot of work on doing these
quickly, so very fast algorithms are plentiful.
- a
[*] technically absolute value is not a linear function, but you can
cheat by changing this to:
width/n - c1 <= k1
- width/n + c1 <= k1
width/n - c2 <= k2
- width/n + c2 <= k2
and then solving to minimize k1+k2... etc
--
"It's lucky," he added, after a pause, "that there are such a lot of
islands in the world. I almost envy you, Mr. Watson."
-- Mustapha Mond