I have an array of rectangles (length and width). Not guaranteed to be square, but always guaranteed to be whole numbers. I want to position the blocks in a coordinate system as efficiently as possible so that the bounding box that contains all elements is as small as possible. I also want to tend toward a square. The variance in terms of size won’t be too great, but I’d like a generic algorithm.
I found this somewhat difficult to search for, just looking for someone to point me in the right direction. Just looking for pseudo-code (language is irrelevant) or a library that could be implemented in Java if need be. Performance is an issue so I really need it to be as efficient as possible in every regard.
Note: If this somehow becomes much easier if I’m restricted to squares only, that might be an option.
The Packing problem article on Wikipedia links to this algorithm, described in this paper – “Optimal Rectangle Packing: Initial Results”.