Sprite fitting layout, related to SMARTSPRITES-64 and SMARTSPRITES-72 #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not really a Java developer by any means, but I just thought I'd contribute this rough patch to do a reasonably good job at fitting sprites tightly in the generated image. It uses a greedy algorithm, which is probably suboptimal for this type of problem, but on my site it generates good results with no obvious errors.
The patch does change your hashCode algorithm for images, which I found generated quite a lot of collisions even in a small space if images are similar. I don't think there's really going to be much of a significant penalty to CRC'ing every pixel on modern machines, and a collision-free hashCode was necessary for TreeSet to function properly (at least in my naive implementation).
The patch also fails some of your test cases, but I think it's just because the order of the images shifted from the order expected in your tests. Due to the implementation, in all cases, images will be placed in order of total size descending.
Thanks for developing this excellent piece of software!