From bf1783284727595d470a2c8e0be53111437c823e Mon Sep 17 00:00:00 2001 From: Peter Amrehn Date: Fri, 20 Apr 2018 19:18:04 +0200 Subject: [PATCH] fix code styling issues --- .../Drawing/Brushes/LinearGradientBrush.cs | 54 +++++++++---------- .../Drawing/FillLinearGradientBrushTests.cs | 45 +++++++++++++++- 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs index 99edb39f43..b955cd7504 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs @@ -19,33 +19,6 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes public class LinearGradientBrush : IBrush where TPixel : struct, IPixel { - /// - /// A struct that defines a single color stop. - /// - public struct ColorStop - { - /// - /// Create a new ColorStop - /// - /// Where should it be? 0 is at the start, 1 at the end of the . - /// What color should be used at that point? - public ColorStop(float ratio, TPixel color) - { - this.Ratio = ratio; - this.Color = color; - } - - /// - /// The point along the defined gradient axis. - /// - public float Ratio { get; } - - /// - /// The color to be used. - /// - public TPixel Color { get; } - } - private readonly Point p1; private readonly Point p2; @@ -73,6 +46,33 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes public BrushApplicator CreateApplicator(ImageFrame source, RectangleF region, GraphicsOptions options) => new LinearGradientBrushApplicator(source, this.p1, this.p2, this.colorStops, region, options); + /// + /// A struct that defines a single color stop. + /// + public struct ColorStop + { + /// + /// Initializes a new instance of the struct. + /// + /// Where should it be? 0 is at the start, 1 at the end of the . + /// What color should be used at that point? + public ColorStop(float ratio, TPixel color) + { + this.Ratio = ratio; + this.Color = color; + } + + /// + /// Gets the point along the defined gradient axis. + /// + public float Ratio { get; } + + /// + /// Gets the color to be used. + /// + public TPixel Color { get; } + } + /// /// The linear gradient brush applicator. /// diff --git a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs index 88ebc49c3f..e25a998a55 100644 --- a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -39,5 +39,48 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } } + + [Fact] + public void HorizontalLinearGradientBrushReturnsUnicolorColumns() + { + int width = 500; + int height = 500; + int lastColumnIndex = width - 1; + int lastRowIndex = height - 1; + + + string path = TestEnvironment.CreateOutputDirectory("Fill", "LinearGradientBrush"); + using (var image = new Image(width, height)) + { + LinearGradientBrush unicolorLinearGradientBrush = + new LinearGradientBrush( + new SixLabors.Primitives.Point(0, 0), + new SixLabors.Primitives.Point(500, 0), + new LinearGradientBrush.ColorStop(0, Rgba32.Red), + new LinearGradientBrush.ColorStop(1, Rgba32.Yellow)); + + image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); + image.Save($"{path}/horizontalGradient.png"); + + using (PixelAccessor sourcePixels = image.Lock()) + { + Rgba32 columnColor23 = sourcePixels[23, 0]; + Rgba32 columnColor42 = sourcePixels[42, 0]; + Rgba32 columnColor333 = sourcePixels[333, 0]; + + for (int i = 0; i < height; i++) + { + // check first and last column, these are known: + Assert.Equal(Rgba32.Red, sourcePixels[0, i]); + Assert.Equal(Rgba32.Yellow, sourcePixels[lastColumnIndex, i]); + + // check the random colors: + Assert.Equal(columnColor23, sourcePixels[23, i]); + Assert.Equal(columnColor42, sourcePixels[42, i]); + Assert.Equal(columnColor333, sourcePixels[333, i]); + } + } + } + } } -} +} \ No newline at end of file