From 88da4bcba303c335d457edce326e1640c972e167 Mon Sep 17 00:00:00 2001 From: Peter Amrehn Date: Sun, 11 Nov 2018 21:28:53 +0100 Subject: [PATCH] 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. --- src/ImageSharp/Processing/ResizeHelper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Processing/ResizeHelper.cs b/src/ImageSharp/Processing/ResizeHelper.cs index 92af89d9e8..aaac7346d7 100644 --- a/src/ImageSharp/Processing/ResizeHelper.cs +++ b/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; }