Fix infinite loop in zoomToBestFit()

Thanks @jvmatl and @willie68