Browse Source

make code more clear by extracting the ratio to a variable again

while keeping it inlined to avoid it in the third case,
and while still replacing the division by a multiplication in the second case.
pull/771/head
Peter Amrehn 8 years ago
parent
commit
88da4bcba3
  1. 6
      src/ImageSharp/Processing/ResizeHelper.cs

6
src/ImageSharp/Processing/ResizeHelper.cs

@ -343,13 +343,15 @@ namespace SixLabors.ImageSharp.Processing
if (widthDiff < heightDiff)
{
destinationHeight = (int)MathF.Round(width * ((float)sourceHeight / sourceWidth));
float sourceRatio = (float)sourceHeight / sourceWidth;
destinationHeight = (int)MathF.Round(width * sourceRatio);
height = destinationHeight;
destinationWidth = width;
}
else if (widthDiff > heightDiff)
{
destinationWidth = (int)MathF.Round(height * ((float)sourceWidth / sourceHeight));
float sourceRatioInverse = (float)sourceWidth / sourceHeight;
destinationWidth = (int)MathF.Round(height * sourceRatioInverse);
destinationHeight = height;
width = destinationWidth;
}

Loading…
Cancel
Save