double mratio = mwidth / mheight;
// Adjust bounds to be less than ideal to meet spec
if (bbratio > mratio) {
// Too wide, need to increase height of bb
double diff = ((bbwidth / mratio) - bbheight) / 2;
aggregateBbox.expandBy(0, diff);
} else {
// Too tall, need to increase width of bb
double diff = ((bbheight * mratio) - bbwidth) / 2;
aggregateBbox.expandBy(diff, 0);
}