Browse Source

inline division as it's only used in some cases (and done at most once)

pull/771/head
Peter Amrehn 8 years ago
committed by Unknown
parent
commit
ea6fc641c3
  1. 6
      src/ImageSharp/Processing/ResizeHelper.cs

6
src/ImageSharp/Processing/ResizeHelper.cs

@ -337,21 +337,19 @@ namespace SixLabors.ImageSharp.Processing
float percentHeight = MathF.Abs(height / (float)sourceHeight); float percentHeight = MathF.Abs(height / (float)sourceHeight);
float percentWidth = MathF.Abs(width / (float)sourceWidth); float percentWidth = MathF.Abs(width / (float)sourceWidth);
float sourceRatio = (float)sourceHeight / sourceWidth;
// Find the shortest distance to go. // Find the shortest distance to go.
int widthDiff = sourceWidth - width; int widthDiff = sourceWidth - width;
int heightDiff = sourceHeight - height; int heightDiff = sourceHeight - height;
if (widthDiff < heightDiff) if (widthDiff < heightDiff)
{ {
destinationHeight = (int)MathF.Round(width * sourceRatio); destinationHeight = (int)MathF.Round(width * ((float)sourceHeight / sourceWidth));
height = destinationHeight; height = destinationHeight;
destinationWidth = width; destinationWidth = width;
} }
else if (widthDiff > heightDiff) else if (widthDiff > heightDiff)
{ {
destinationWidth = (int)MathF.Round(height / sourceRatio); destinationWidth = (int)MathF.Round(height * ((float)sourceWidth / sourceHeight));
destinationHeight = height; destinationHeight = height;
width = destinationWidth; width = destinationWidth;
} }

Loading…
Cancel
Save