1
$\begingroup$

Lately I've been trying to develop a layout engine for my own purposes, from scratch. Similar to CSS layout systems like flex, my layout system works on the basis of a tree of rectangles, with some constraints between them. For example, you might have a parent rectangle with a height of 100 pixels and a width of "fit content", and then inside that, two child rectangles with widths of 300 pixels each and heights of "fill parent". The point of the algorithm is then to resolve these constraints to calculate a width, height, x and y for each rectangle.

This is more complicated than it seems, because sometimes you can have circular or ambiguous dependencies. For instance, say a parent container has a width of "fit content", and the child has a width of "fill parent". Then in some sense, any width is valid for the parent, so long as we also assign it to the child.

What I'm really looking for here is some kind of mathematical model of layout algorithms that can help me clarify my thoughts on this problem. Of course I can come up with ad hoc solutions, but is this an actual field of research? Has anyone out there written a PhD thesis about mathematical models of layout algorithms?

$\endgroup$
1
  • $\begingroup$ I'm not familiar with this very much, but I can say it sounds (at a quick glance) very similar to other fields that are well studied (i.e, specifically the idea of having some "constraint" be filled automatically) - e.g, compiler optimizations, programming language semantics, and specification-based programming. Or even linear-programming and similar optimization problems $\endgroup$ Commented Jan 10 at 13:40

1 Answer 1

1
$\begingroup$

I don't know, and I'm not able to propose a specific algorithm without knowing the full set of possible constraints. But this sounds like it might be addressable with techniques used in the field of operations research.

In particular, it sounds like this can be expressed as an instance of linear programming and solved with an off-the-shelf LP solver. Whether that will be possible will depend on the exact set of constraints that are allowed. It's even possible this might be a specialized subclass of LP problems that can be solved more efficiently (e.g., difference constraints, which can be solved with a Bellman-Ford shortest-paths algorithm).

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.