Algorithm for determining grid based on variably sized "blocks"?
Posted
by
Lite Byte
on Programmers
See other posts from Programmers
or by Lite Byte
Published on 2012-03-26T01:14:08Z
Indexed on
2012/03/26
5:41 UTC
Read the original article
Hit count: 185
algorithms
I'm trying to convert a set of "blocks" in to a grid-like layout. The blocks have a width of either 25%, 33%, 50%, 66%, or 75% of their container and each row of the grid should try to fit as many blocks as possible, up to a total width of 100%.
I've discovered that trying to do this while leaving no remaining blocks in the original set is very hard. Eventually, I think my solution will be to upgrade/downgrade various block sizes (based on their priority or something) so they all fit in to a row.
Either case, before I do that, I thought I'd check if someone has some code (or a paper) demonstrating a solution to this problem already? And bonus points if the solution incorporates varying block heights in to its calculations :)
Thanks!
© Programmers or respective owner