Browse Source

fix code styling issues

af/merge-core
Peter Amrehn 8 years ago
parent
commit
bf17832847
  1. 54
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs
  2. 45
      tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs

54
src/ImageSharp.Drawing/Processing/Drawing/Brushes/LinearGradientBrush.cs

@ -19,33 +19,6 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
public class LinearGradientBrush<TPixel> : IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// A struct that defines a single color stop.
/// </summary>
public struct ColorStop
{
/// <summary>
/// Create a new ColorStop
/// </summary>
/// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the <see cref="LinearGradientBrush{TPixel}"/>.</param>
/// <param name="color">What color should be used at that point?</param>
public ColorStop(float ratio, TPixel color)
{
this.Ratio = ratio;
this.Color = color;
}
/// <summary>
/// The point along the defined <see cref="LinearGradientBrush{TPixel}" /> gradient axis.
/// </summary>
public float Ratio { get; }
/// <summary>
/// The color to be used.
/// </summary>
public TPixel Color { get; }
}
private readonly Point p1;
private readonly Point p2;
@ -73,6 +46,33 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
=> new LinearGradientBrushApplicator(source, this.p1, this.p2, this.colorStops, region, options);
/// <summary>
/// A struct that defines a single color stop.
/// </summary>
public struct ColorStop
{
/// <summary>
/// Initializes a new instance of the <see cref="ColorStop" /> struct.
/// </summary>
/// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the <see cref="LinearGradientBrush{TPixel}"/>.</param>
/// <param name="color">What color should be used at that point?</param>
public ColorStop(float ratio, TPixel color)
{
this.Ratio = ratio;
this.Color = color;
}
/// <summary>
/// Gets the point along the defined <see cref="LinearGradientBrush{TPixel}" /> gradient axis.
/// </summary>
public float Ratio { get; }
/// <summary>
/// Gets the color to be used.
/// </summary>
public TPixel Color { get; }
}
/// <summary>
/// The linear gradient brush applicator.
/// </summary>

45
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<Rgba32>(width, height))
{
LinearGradientBrush<Rgba32> unicolorLinearGradientBrush =
new LinearGradientBrush<Rgba32>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(500, 0),
new LinearGradientBrush<Rgba32>.ColorStop(0, Rgba32.Red),
new LinearGradientBrush<Rgba32>.ColorStop(1, Rgba32.Yellow));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.Save($"{path}/horizontalGradient.png");
using (PixelAccessor<Rgba32> 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]);
}
}
}
}
}
}
}
Loading…
Cancel
Save