TITLE: Maximum square cells in a rectangle
QUESTION [6 upvotes]: I know this sounds like bin packing but it's a bit different so please read the question to the end.
Given a rectangle of known width and height, I need to divide it into smaller rectangles using column and rows. I'm essentially creating a grid(Think of iPhone's home screen, it's a grid with square icons).
Now the problem(constrain):

Cells' have a minimum size(say height > 10 and width > 10)
The proportion of the cell needs to be as close to a square(1:1) as possible
All cells' dimension need to be uniform in the grid.

I'm solving for the number of columns and rows needed to satisfy the requirements above.
Example:
A rectangle of width=3; height=3 and with a cell minimum size of width >= 1; height >= 1 
Becomes:

In this example, column and row is 3 while all cells have a width and height of 1
UPDATE:
A very rough solution that works some of the time:
size = max(cellMinWidth, cellMinHeight)
columns = floor(width/size)
rows = floor(height/size)

This fails when the difference between the width and height of the rectangle is big.

REPLY [2 votes]: The solution is to project a centered subdivided square onto a rectangular region via uniform padding as calculated from the difference between the rectangle and calculated square dimensions. This will, in effect, create a table with cell padding in which the centers will be placed your desired imagery:

Let K be min(width, height), the dimensions of the rectangle.
Let J be max(width, height) - min(width,height), the total padding.
Let M be max(cellMinWidth, cellMinHeight).
Let G be K / M, the number of columns and the number of rows (square).
Let P be J / G, which produces the padding amount between either the columns or the rows (not both; because square dimensions), depending on the orientation mode of the device or the layout needs.
Calculate centers of the tiling, taking into account padding and column or row mode, offset by half the width or height of the image dimensions being placed there.

Note: this method can be extended for the floating (padded) dimension by increasing the padding off screen by a minimum of another row or column of size M + P, which would allow scrubbing (scrolling) on that dimension.