Skip to content

Commit d4dd48f

Browse files
SimonCroppJimBobSquarePants
authored andcommitted
use var where apparent (SixLabors#972)
* use var where apparent * use var where apparent * should use Rgb24
1 parent 7b9ec2b commit d4dd48f

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ using SixLabors.ImageSharp;
9292
using SixLabors.ImageSharp.PixelFormats;
9393

9494
// Individual pixels
95-
using (Image<Rgba32> image = new Image<Rgba32>(400, 400))
95+
using (var image = new Image<Rgba32>(400, 400))
9696
{
9797
image[200, 200] = Rgba32.White;
9898
}

src/ImageSharp.Drawing/Processing/DrawingHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ internal static class DrawingHelpers
1414
public static DenseMatrix<TPixel> ToPixelMatrix<TPixel>(this DenseMatrix<Color> colorMatrix, Configuration configuration)
1515
where TPixel : struct, IPixel<TPixel>
1616
{
17-
DenseMatrix<TPixel> result = new DenseMatrix<TPixel>(colorMatrix.Columns, colorMatrix.Rows);
17+
var result = new DenseMatrix<TPixel>(colorMatrix.Columns, colorMatrix.Rows);
1818
Color.ToPixel(configuration, colorMatrix.Span, result.Span);
1919
return result;
2020
}
2121
}
22-
}
22+
}

tests/ImageSharp.Tests/Drawing/DrawImageTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -75,13 +75,13 @@ public void WorksWithDifferentConfigurations<TPixel>(
7575
using (Image<TPixel> image = provider.GetImage())
7676
using (var blend = Image.Load<TPixel>(TestFile.Create(brushImage).Bytes))
7777
{
78-
Size size = new Size(image.Width * 3 / 4, image.Height * 3 / 4);
79-
Point position = new Point(image.Width / 8, image.Height / 8);
78+
var size = new Size(image.Width * 3 / 4, image.Height * 3 / 4);
79+
var position = new Point(image.Width / 8, image.Height / 8);
8080
blend.Mutate(x => x.Resize(size.Width, size.Height, KnownResamplers.Bicubic));
8181
image.Mutate(x => x.DrawImage(blend, position, mode, opacity));
8282
FormattableString testInfo = $"{System.IO.Path.GetFileNameWithoutExtension(brushImage)}-{mode}-{opacity}";
8383

84-
PngEncoder encoder = new PngEncoder();
84+
var encoder = new PngEncoder();
8585

8686
if (provider.PixelType == PixelTypes.Rgba64)
8787
{
@@ -197,4 +197,4 @@ void Test()
197197

198198

199199
}
200-
}
200+
}

tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -59,20 +59,20 @@ public void DrawPath<TPixel>(TestImageProvider<TPixel> provider, string colorNam
5959
public void PathExtendingOffEdgeOfImageShouldNotBeCropped<TPixel>(TestImageProvider<TPixel> provider)
6060
where TPixel : struct, IPixel<TPixel>
6161
{
62-
Color color = Color.White;
62+
var color = Color.White;
6363
Pen pen = Pens.Solid(color, 5f);
6464

6565
provider.RunValidatingProcessorTest(
6666
x =>
6767
{
6868
for (int i = 0; i < 300; i += 20)
6969
{
70-
PointF[] points = new PointF[] { new Vector2(100, 2), new Vector2(-10, i) };
70+
var points = new PointF[] { new Vector2(100, 2), new Vector2(-10, i) };
7171
x.DrawLines(pen, points);
7272
}
7373
},
7474
appendPixelTypeToFileName: false,
7575
appendSourceFileOrDescription: false);
7676
}
7777
}
78-
}
78+
}

tests/ImageSharp.Tests/Drawing/FillPolygonTests.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -28,34 +28,34 @@ public void FillPolygon_Solid<TPixel>(TestImageProvider<TPixel> provider, string
2828
new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)
2929
};
3030
Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha);
31-
32-
GraphicsOptions options = new GraphicsOptions(antialias);
31+
32+
var options = new GraphicsOptions(antialias);
3333

3434
string aa = antialias ? "" : "_NoAntialias";
3535
FormattableString outputDetails = $"{colorName}_A{alpha}{aa}";
36-
36+
3737
provider.RunValidatingProcessorTest(
3838
c => c.FillPolygon(options, color, simplePath),
3939
outputDetails,
4040
appendSourceFileOrDescription: false);
4141
}
42-
42+
4343
[Theory]
4444
[WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32)]
4545
public void FillPolygon_Concave<TPixel>(TestImageProvider<TPixel> provider)
4646
where TPixel : struct, IPixel<TPixel>
4747
{
4848
var points = new SixLabors.Primitives.PointF[]
4949
{
50-
new Vector2(8, 8),
51-
new Vector2(64, 8),
52-
new Vector2(64, 64),
50+
new Vector2(8, 8),
51+
new Vector2(64, 8),
52+
new Vector2(64, 64),
5353
new Vector2(120, 64),
54-
new Vector2(120, 120),
54+
new Vector2(120, 120),
5555
new Vector2(8, 120)
5656
};
57-
58-
Color color = Color.LightGreen;
57+
58+
var color = Color.LightGreen;
5959

6060
provider.RunValidatingProcessorTest(
6161
c => c.FillPolygon(color, points),
@@ -72,15 +72,15 @@ public void FillPolygon_Pattern<TPixel>(TestImageProvider<TPixel> provider)
7272
{
7373
new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)
7474
};
75-
Color color = Color.Yellow;
75+
var color = Color.Yellow;
7676

7777
var brush = Brushes.Horizontal(color);
78-
78+
7979
provider.RunValidatingProcessorTest(
8080
c => c.FillPolygon(brush, simplePath),
8181
appendSourceFileOrDescription: false);
8282
}
83-
83+
8484
[Theory]
8585
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, TestImages.Png.Ducky)]
8686
[WithBasicTestPatternImages(250, 350, PixelTypes.Rgba32, TestImages.Bmp.Car)]
@@ -95,7 +95,7 @@ public void FillPolygon_ImageBrush<TPixel>(TestImageProvider<TPixel> provider, s
9595
using (Image<TPixel> brushImage = Image.Load<TPixel>(TestFile.Create(brushImageName).Bytes))
9696
{
9797
var brush = new ImageBrush(brushImage);
98-
98+
9999
provider.RunValidatingProcessorTest(
100100
c => c.FillPolygon(brush, simplePath),
101101
System.IO.Path.GetFileNameWithoutExtension(brushImageName),
@@ -109,13 +109,13 @@ public void Fill_RectangularPolygon<TPixel>(TestImageProvider<TPixel> provider)
109109
where TPixel : struct, IPixel<TPixel>
110110
{
111111
var polygon = new SixLabors.Shapes.RectangularPolygon(10, 10, 190, 140);
112-
Color color = Color.White;
112+
var color = Color.White;
113113

114114
provider.RunValidatingProcessorTest(
115115
c => c.Fill(color, polygon),
116-
appendSourceFileOrDescription: false);
116+
appendSourceFileOrDescription: false);
117117
}
118-
118+
119119
[Theory]
120120
[WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32, 3, 50, 0f)]
121121
[WithBasicTestPatternImages(200, 200, PixelTypes.Rgba32, 3, 60, 20f)]
@@ -127,7 +127,7 @@ public void Fill_RegularPolygon<TPixel>(TestImageProvider<TPixel> provider, int
127127
{
128128
float angle = GeometryUtilities.DegreeToRadian(angleDeg);
129129
var polygon = new RegularPolygon(100, 100, vertices, radius, angle);
130-
Color color = Color.Yellow;
130+
var color = Color.Yellow;
131131

132132
FormattableString testOutput = $"V({vertices})_R({radius})_Ang({angleDeg})";
133133
provider.RunValidatingProcessorTest(
@@ -143,7 +143,7 @@ public void Fill_EllipsePolygon<TPixel>(TestImageProvider<TPixel> provider)
143143
where TPixel : struct, IPixel<TPixel>
144144
{
145145
var polygon = new EllipsePolygon(100, 100, 80, 120);
146-
Color color = Color.Azure;
146+
var color = Color.Azure;
147147

148148
provider.RunValidatingProcessorTest(
149149
c => c.Fill(color, polygon),

tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void DoesNotDependOnSize<TPixel>(TestImageProvider<TPixel> provider)
3030
{
3131
using (Image<TPixel> image = provider.GetImage())
3232
{
33-
Color color = Color.HotPink;
33+
var color = Color.HotPink;
3434
image.Mutate(c => c.Fill(color));
3535

3636
image.DebugSave(provider, appendPixelTypeToFileName: false);
@@ -45,7 +45,7 @@ public void DoesNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> pro
4545
{
4646
using (Image<TPixel> image = provider.GetImage())
4747
{
48-
Color color = Color.HotPink;
48+
var color = Color.HotPink;
4949
image.Mutate(c => c.Fill(color));
5050

5151
image.DebugSave(provider, appendSourceFileOrDescription: false);

tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestIm
4040
where TPixel : struct, IPixel<TPixel>
4141
{
4242
Font font = CreateFont("OpenSans-Regular.ttf", 36);
43-
Color color = Color.Black;
43+
var color = Color.Black;
4444
var text = "A short piece of text";
4545

4646
using (var img = provider.GetImage())
@@ -52,7 +52,7 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestIm
5252
float scalingFactor = Math.Min(img.Width / size.Width, img.Height / size.Height);
5353

5454
//create a new font
55-
Font scaledFont = new Font(font, scalingFactor * font.Size);
55+
var scaledFont = new Font(font, scalingFactor * font.Size);
5656

5757
var center = new PointF(img.Width / 2, img.Height / 2);
5858
var textGraphicOptions = new TextGraphicsOptions(true)
@@ -80,7 +80,7 @@ public void FontShapesAreRenderedCorrectly<TPixel>(
8080
where TPixel : struct, IPixel<TPixel>
8181
{
8282
Font font = CreateFont(fontName, fontSize);
83-
Color color = Color.Black;
83+
var color = Color.Black;
8484

8585
provider.VerifyOperation(
8686
TextDrawingComparer,
@@ -125,7 +125,7 @@ public void FontShapesAreRenderedCorrectly_LargeText<TPixel>(
125125
HorizontalAlignment = HorizontalAlignment.Left,
126126
};
127127

128-
Color color = Color.Black;
128+
var color = Color.Black;
129129

130130
// Based on the reported 0.0270% difference with AccuracyMultiple = 8
131131
// We should avoid quality regressions leading to higher difference!
@@ -155,7 +155,7 @@ public void FontShapesAreRenderedCorrectlyWithAPen<TPixel>(
155155
where TPixel : struct, IPixel<TPixel>
156156
{
157157
Font font = CreateFont(fontName, fontSize);
158-
Color color = Color.Black;
158+
var color = Color.Black;
159159

160160
provider.VerifyOperation(
161161
OutlinedTextDrawingComparer,
@@ -182,7 +182,7 @@ public void FontShapesAreRenderedCorrectlyWithAPenPatterned<TPixel>(
182182
where TPixel : struct, IPixel<TPixel>
183183
{
184184
Font font = CreateFont(fontName, fontSize);
185-
Color color = Color.Black;
185+
var color = Color.Black;
186186

187187
provider.VerifyOperation(
188188
OutlinedTextDrawingComparer,

tests/ImageSharp.Tests/ImageOperationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ImageOperationTests()
2929
{
3030
this.provider = new FakeImageOperationsProvider();
3131

32-
Mock<IImageProcessor> processorMock = new Mock<IImageProcessor>();
32+
var processorMock = new Mock<IImageProcessor>();
3333
this.processorDefinition = processorMock.Object;
3434

3535
this.image = new Image<Rgba32>(new Configuration
@@ -155,7 +155,7 @@ private static string GetExpectedExceptionText()
155155
{
156156
try
157157
{
158-
Image<Rgba32> img = new Image<Rgba32>(1, 1);
158+
var img = new Image<Rgba32>(1, 1);
159159
img.Dispose();
160160
img.EnsureNotDisposed();
161161
}

0 commit comments

Comments
 (0)