From 74ee173fc0f69c6a7c5f9f58024d3131361182cd Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 1 Mar 2018 14:52:50 +1100 Subject: [PATCH] Use Size --- .../DefaultInternalImageProcessorContext.cs | 4 +-- .../IImageProcessingContext{TPixel}.cs | 4 +-- .../Processing/Transforms/Resize.cs | 6 ++-- .../Processing/Transforms/Rotate.cs | 2 +- src/ImageSharp/Processing/Transforms/Skew.cs | 2 +- .../Processing/Transforms/Transform.cs | 4 +-- .../FakeImageOperationsProvider.cs | 4 +-- .../Image/ImageProcessingContextTests.cs | 30 +++++++++---------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs index 9dbd108e5..c3378cf98 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp } /// - public Rectangle Bounds() => this.destination?.Bounds() ?? this.source.Bounds(); + public Size GetCurrentSize() => this.destination?.Size() ?? this.source.Size(); /// public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp /// public IImageProcessingContext ApplyProcessor(IImageProcessor processor) { - return this.ApplyProcessor(processor, this.Bounds()); + return this.ApplyProcessor(processor, this.source.Bounds()); } } } \ No newline at end of file diff --git a/src/ImageSharp/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/IImageProcessingContext{TPixel}.cs index c58dffcec..0e8efde3b 100644 --- a/src/ImageSharp/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/IImageProcessingContext{TPixel}.cs @@ -22,10 +22,10 @@ namespace SixLabors.ImageSharp MemoryManager MemoryManager { get; } /// - /// Gets the image bounds at the current point in the processing pipeline. + /// Gets the image dimensions at the current point in the processing pipeline. /// /// The - Rectangle Bounds(); + Size GetCurrentSize(); /// /// Adds the processor to the current set of image operations to be applied. diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index 853f46133..285f3206d 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(options, source.Bounds().Size)); + => source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize())); /// /// Resizes an image to the given . @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.Bounds().Size, targetRectangle, compand), sourceRectangle); + => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand), sourceRectangle); /// /// Resizes an image to the given width and height with the given sampler and source rectangle. @@ -171,6 +171,6 @@ namespace SixLabors.ImageSharp Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.Bounds().Size, targetRectangle, compand)); + => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index 6ffefca5c..faecdf91f 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -44,6 +44,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees, IResampler sampler) where TPixel : struct, IPixel - => source.ApplyProcessor(new RotateProcessor(degrees, sampler, source.Bounds().Size)); + => source.ApplyProcessor(new RotateProcessor(degrees, sampler, source.GetCurrentSize())); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index 25db33059..fb054211a 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -35,6 +35,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY, IResampler sampler) where TPixel : struct, IPixel - => source.ApplyProcessor(new SkewProcessor(degreesX, degreesY, sampler, source.Bounds().Size)); + => source.ApplyProcessor(new SkewProcessor(degreesX, degreesY, sampler, source.GetCurrentSize())); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Transform.cs b/src/ImageSharp/Processing/Transforms/Transform.cs index 58d3ae13e..66d5d5de7 100644 --- a/src/ImageSharp/Processing/Transforms/Transform.cs +++ b/src/ImageSharp/Processing/Transforms/Transform.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix3x2 matrix, IResampler sampler) where TPixel : struct, IPixel - => Transform(source, matrix, sampler, source.Bounds()); + => source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, source.GetCurrentSize())); /// /// Transforms an image by the given matrix using the specified sampling algorithm @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp /// The internal static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix4x4 matrix, IResampler sampler) where TPixel : struct, IPixel - => Transform(source, matrix, sampler, source.Bounds()); + => source.ApplyProcessor(new ProjectiveTransformProcessor(matrix, sampler, source.GetCurrentSize())); /// /// Applies a projective transform to the image by the given matrix using the specified sampling algorithm. diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index 58f88eba4..db1e7903d 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp.Tests return this.Source; } - public Rectangle Bounds() + public Size GetCurrentSize() { - return this.Source.Bounds(); + return this.Source.Size(); } public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) diff --git a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs index 8411dd2f0..f8f7b6758 100644 --- a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Tests public class ImageProcessingContextTests { [Fact] - public void MutatedBoundsAreAccuratePerOperation() + public void MutatedSizeIsAccuratePerOperation() { var x500 = new Size(500, 500); var x400 = new Size(400, 400); @@ -19,16 +19,16 @@ namespace SixLabors.ImageSharp.Tests using (var image = new Image(500, 500)) { image.Mutate(x => - x.AssertBounds(x500) - .Resize(x400).AssertBounds(x400) - .Resize(x300).AssertBounds(x300) - .Resize(x200).AssertBounds(x200) - .Resize(x100).AssertBounds(x100)); + x.AssertSize(x500) + .Resize(x400).AssertSize(x400) + .Resize(x300).AssertSize(x300) + .Resize(x200).AssertSize(x200) + .Resize(x100).AssertSize(x100)); } } [Fact] - public void ClonedBoundsAreAccuratePerOperation() + public void ClonedSizeIsAccuratePerOperation() { var x500 = new Size(500, 500); var x400 = new Size(400, 400); @@ -38,20 +38,20 @@ namespace SixLabors.ImageSharp.Tests using (var image = new Image(500, 500)) { image.Clone(x => - x.AssertBounds(x500) - .Resize(x400).AssertBounds(x400) - .Resize(x300).AssertBounds(x300) - .Resize(x200).AssertBounds(x200) - .Resize(x100).AssertBounds(x100)); + x.AssertSize(x500) + .Resize(x400).AssertSize(x400) + .Resize(x300).AssertSize(x300) + .Resize(x200).AssertSize(x200) + .Resize(x100).AssertSize(x100)); } } } - public static class BoundsAssertationExtensions + public static class SizeAssertationExtensions { - public static IImageProcessingContext AssertBounds(this IImageProcessingContext context, Size size) + public static IImageProcessingContext AssertSize(this IImageProcessingContext context, Size size) { - Assert.Equal(size, context.Bounds().Size); + Assert.Equal(size, context.GetCurrentSize()); return context; } }