Optimization 这个代码(按比例缩放图像以填充/覆盖矩形)可以优化吗?

Optimization 这个代码(按比例缩放图像以填充/覆盖矩形)可以优化吗?,optimization,Optimization,我不太擅长与数学相关的东西,所以结果有点长 imageRatio = imageWidth / imageHeight if (imageWidth > imageHeight) { resizeWidth = containerHeight * imageRatio resizeHeight = containerHeight if (resizeWidth < containerWidth) { resizeWidth = contai

我不太擅长与数学相关的东西,所以结果有点长

imageRatio = imageWidth / imageHeight

if (imageWidth > imageHeight) {
    resizeWidth = containerHeight * imageRatio
    resizeHeight = containerHeight

    if (resizeWidth < containerWidth) {
        resizeWidth = containerWidth
        resizeHeight = containerWidth / imageRatio
    }
} else {
    resizeWidth = containerWidth
    resizeHeight = containerWidth / imageRatio

    if (resizeHeight < containerHeight) {
        resizeWidth = containerHeight * imageRatio
        resizeHeight = containerHeight
    }
}
imageRatio=imageWidth/imageHeight
如果(图像宽度>图像高度){
resizeWidth=containerHeight*imageRatio
调整高度=容器高度
如果(调整宽度<容器宽度){
resizeWidth=容器宽度
resizeHeight=容器宽度/图像比率
}
}否则{
resizeWidth=容器宽度
resizeHeight=容器宽度/图像比率
if(调整高度<容器高度){
resizeWidth=containerHeight*imageRatio
调整高度=容器高度
}
}