private static Rectangle2D getAdjustedViewBounds(Rectangle2D viewBounds, Size viewSize)
{
double width = viewBounds.Width;
double height = viewBounds.Height;
double ratio = viewSize.Height / viewSize.Width;
if ((height / width) > ratio)
{
width = height / ratio;
}
else
{
height = width * ratio;
}
return Rectangle2D.CreateFromXYWidthHeight(viewBounds.Center.X - (width / 2.0), viewBounds.Center.Y - (height / 2.0), width, height);
}