In any given size of model or window there are two possiblities, the model fits the window either vertically or horizontally. To do the fitting I assume you use some kind of zoom factor at the moment? Compare the zoom for model width into window width and model height into window height and choose the one which is best. That would typically be the smaller of the two.

For example lets say the window is 100 pixels wide by 30 pixels high, the model is 50 (somethings) wide by 20 tall.

Vertical is less than horizontal so this model fits the window vertically at a zoom of 1.5

Window is 100 X 30 again, this time model is 80 x 15

This time horizontal is less than vertical, so the model fits horizontally, at zoom 1.25.

I can explain more details of how to apply this if needs be, it depends on what graphics system you are using.

For example lets say the window is 100 pixels wide by 30 pixels high, the model is 50 (somethings) wide by 20 tall.

Horizontal = 100 / 50 = 2

Vertical = 30 / 20 = 1.5

Vertical = 30 / 20 = 1.5

Vertical is less than horizontal so this model fits the window vertically at a zoom of 1.5

Window is 100 X 30 again, this time model is 80 x 15

Horizontal = 100 / 80 = 1.25

Vertical = 30 / 15 = 2

Vertical = 30 / 15 = 2

This time horizontal is less than vertical, so the model fits horizontally, at zoom 1.25.

I can explain more details of how to apply this if needs be, it depends on what graphics system you are using.