What is the algorithm for packing squares and rectangles?

As in the Windows 8 Slate interface, how nice is it to fill the screen with squares and rectangles without leaving the hole?

Assumptions:

  • the rectangle is basically two connected squares
  • rectangles can be horizontal or vertical.
  • screen width 3 times the width of the square
  • the screen fills from top to bottom
  • so that the bottom of the screen cannot be fully aligned.
  • the order of the rectangles and squares comes randomly (but can be reconfigured in a small cache before being placed on the screen, the cache size is limited, say, 12)

For instance:

  +---++---++---+
  |   ||   ||   |
  +---++---+|   |
  +---++---+|   |
  |   ||   ||   |
  +---+|   |+---+
  +---+|   |+---+
  |   ||   ||   |
  +---++---++---+
  +--------++---+
  |        ||   |
  +--------+|   |
  +---++---+|   |
  |   ||   ||   |
  |   |+---++---+
  |   |
  |   |
  +---+
+3
source share
2 answers

, .

- .

, , , . / /. , .

, , .

. , . :.

Take items in order of display preference
Start at the top-left
For each item:
    Try to stack horizontally, going right ("favoring" left)
    if it won't fit on the screen:
        try to stack on the next row
        when trying to stack on the next row:
            if any "gaps" exist in the current row:
                see if you have a less "regular" rectangle that will fit in the gap
            else
                "favor" placing it farther left

Edit:

.

, , , - , - , - .

, , . 1x1, , , , . , , . , / , , .

+3

, " ". , , .

, , - Redcliff...

0

All Articles