Browse Source

Changes the method to return a factor instead of a percentage

Former-commit-id: 75fa0d3daf53263ab1b411b910d1b90580e7ec7d
Former-commit-id: c19f6cbbf92b6fca98a0f05eec8ccc4d31f9934b
pull/17/head
Thomas Broust 11 years ago
parent
commit
6217257444
  1. 11
      src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs
  2. 19
      src/ImageProcessor/Imaging/Rotation.cs

11
src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs

@ -18,5 +18,16 @@
result.Width.Should().Be(expectedWidth, "because the rotated width should have been calculated");
result.Height.Should().Be(expectedHeight, "because the rotated height should have been calculated");
}
[Test]
[TestCase(100, 100, 45, 1.41f)]
[TestCase(100, 100, 15, 1.22f)]
[TestCase(100, 200, 45, 2.12f)]
public void RotationZoomIsCalculated(int imageWidth, int imageHeight, float angle, float expected)
{
float result = Rotation.ZoomAfterRotation(imageWidth, imageHeight, angle);
result.Should().BeApproximately(expected, 0.01f, "because the zoom level after rotation should have been calculated");
}
}
}

19
src/ImageProcessor/Imaging/Rotation.cs

@ -39,5 +39,24 @@
return result;
}
/// <summary>
/// Calculates the zoom needed after the rotation.
/// </summary>
/// <param name="imageWidth">Width of the image.</param>
/// <param name="imageHeight">Height of the image.</param>
/// <param name="angle">The angle.</param>
/// <returns>The zoom needed</returns>
public static float ZoomAfterRotation(int imageWidth, int imageHeight, float angle)
{
double radians = angle * Math.PI / 180d;
double radiansSin = Math.Sin(radians);
double radiansCos = Math.Cos(radians);
double widthRotated = (imageWidth * radiansCos) + (imageHeight * radiansSin);
double heightRotated = (imageWidth * radiansSin) + (imageHeight * radiansCos);
return (float)(Math.Max(widthRotated, heightRotated) / 100);
}
}
}
Loading…
Cancel
Save