
Hi, I have a mess The mess on the left is a pretty array of rectangles with some holes (marked in red). I am looking for a way to combine them so that I have as few rectangles as possible, and it is desirable that most of them be as close to the squares as possible. Look at the image on the right, that what I'm trying to do is a little prettier and preferably a little more automatic.
I need this for the game, and it will not be done at run time, so speed is not a problem (if it is not too slow, because I have to do it on a fairly large area), but I have never done something like this before and I honestly have no idea where to start.
I already tried to go over my way through the array, starting from the top left square and merging, until there was nothing left to merge, but it really is not so effective, since it cannot consider merging 3x2, 4x3 rectangles, etc.
If you can point me to any algorithms that can handle such things or have an idea of how this could be done, that would be highly appreciated. Thanks!
source
share