Calculate sizes of rectangles of fixed proportions that would fill a grid's height.

Each rectangle has a fixed proportion e.g. 1:2 Each rectangle has to be the same size Grid's height has to be filled Last row can have space if the number of elements is odd. Width might have space if proportions don't allow to fill it. What size each rectangle should be (the size will be the same among all rectangles)?

EDIT: What I ended up doing is this:

introducing some size e.g. 400x500 for rectangles

now if e.g. area to fit in is 3000x4000 I can calculate it's proportions (height/width)

so area proportions = height / width
add rect to upper left corner
while(there are still rectangles to position)
{
calculate current occupied area of all rects
current occupied area proportions = occupied area height / width
if area proportions < current occupied area proportions
fill column with rectangles
else
fill row with rectangles
}

areaHeightToOccupiedHeightProportion = Area.Height / currentOccupiedSpace.Height;
areaWidthToOccupiedWidthProportion = Area.Width / currentOccupiedSpace.Width;
if(areaHeightToOccupiedHeightProportion < areaWidthToOccupiedWidthProportion){
//scaling to maximum width would make the occupied area bigger than the   area we want to position rectangles in
var scale = areaHeightToOccupiedHeightProportion;
}
{
else scale = areaWidthToOccupiedWidthProportion;
}