I have a # of images that I\'m stitching together into a sprite sheet, how can I calculate the number of rows and columns to fit equally in an even rectangle (no blank space
Seems like you have to find all factor pairs of the number, then pick the pair the gives you the most 'desirable' row:column ratio.
So for example:
bestRows = 1
bestRatio = ((double) 1) / N;
for (int i : 1 to N) {
if ((N % i) == 0) {
r = N % i
c = N / i
ratio = ((double) r) / N;
if (firstIsBetter(ratio, bestRatio)) {
bestRows = r;
bestRatio = ratio;
}
}
}