Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit types #2855

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
[*.{cs,csx,cake}]
# 'var' preferences
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
csharp_style_var_elsewhere = false:error
# Expression-bodied members
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
Expand Down
3 changes: 2 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# file-scoped namespaces and global usings
5528a2923ccc63d776c91994b0b17a2c3ad5be94
d14c82023fc01a6fca99c42212cb3c97991fae9e
0e9a066195a100ae56b4ca49cee9927fb15e1482
0e9a066195a100ae56b4ca49cee9927fb15e1482
dfa0188f245f4671c8f1a4607f911869e2c6ec9d
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelExecutionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ParallelExecutionSettings MultiplyMinimumPixelsPerTask(int multiplier)
{
Guard.MustBeGreaterThan(multiplier, 0, nameof(multiplier));

return new ParallelExecutionSettings(
return new(
this.MaxDegreeOfParallelism,
this.MinimumPixelsProcessedPerTask * multiplier,
this.MemoryAllocator);
Expand All @@ -92,6 +92,6 @@ public ParallelExecutionSettings MultiplyMinimumPixelsPerTask(int multiplier)
/// <returns>The <see cref="ParallelExecutionSettings"/>.</returns>
public static ParallelExecutionSettings FromConfiguration(Configuration configuration)
{
return new ParallelExecutionSettings(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
return new(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
}
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void Invoke(int i)
}

int yMax = Math.Min(yMin + this.stepY, this.maxY);
var rows = new RowInterval(yMin, yMax);
RowInterval rows = new(yMin, yMax);

// Skip the safety copy when invoking a potentially impure method on a readonly field
Unsafe.AsRef(in this.operation).Invoke(in rows);
Expand Down Expand Up @@ -185,7 +185,7 @@ public void Invoke(int i)
}

int yMax = Math.Min(yMin + this.stepY, this.maxY);
var rows = new RowInterval(yMin, yMax);
RowInterval rows = new RowInterval(yMin, yMax);

using IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.bufferLength);

Expand Down
28 changes: 14 additions & 14 deletions src/ImageSharp/Advanced/ParallelRowIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class ParallelRowIterator
public static void IterateRows<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -65,8 +65,8 @@ public static void IterateRows<T>(
}

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowOperationWrapper<T>(top, bottom, verticalStep, in operation);
ParallelOptions? parallelOptions = new() { MaxDegreeOfParallelism = numOfSteps };
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved
RowOperationWrapper<T> wrappingOperation = new(top, bottom, verticalStep, in operation);

Parallel.For(
0,
Expand All @@ -88,7 +88,7 @@ public static void IterateRows<T, TBuffer>(Configuration configuration, Rectangl
where T : struct, IRowOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -135,8 +135,8 @@ public static void IterateRows<T, TBuffer>(
}

int verticalStep = DivideCeil(height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
RowOperationWrapper<T, TBuffer> wrappingOperation = new RowOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);

Parallel.For(
0,
Expand All @@ -156,7 +156,7 @@ public static void IterateRows<T, TBuffer>(
public static void IterateRowIntervals<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowIntervalOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -186,14 +186,14 @@ public static void IterateRowIntervals<T>(
// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
RowInterval rows = new RowInterval(top, bottom);
Unsafe.AsRef(in operation).Invoke(in rows);
return;
}

int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowIntervalOperationWrapper<T>(top, bottom, verticalStep, in operation);
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
RowIntervalOperationWrapper<T> wrappingOperation = new RowIntervalOperationWrapper<T>(top, bottom, verticalStep, in operation);

Parallel.For(
0,
Expand All @@ -215,7 +215,7 @@ public static void IterateRowIntervals<T, TBuffer>(Configuration configuration,
where T : struct, IRowIntervalOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public static void IterateRowIntervals<T, TBuffer>(
// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
RowInterval rows = new RowInterval(top, bottom);
using IMemoryOwner<TBuffer> buffer = allocator.Allocate<TBuffer>(bufferLength);

Unsafe.AsRef(in operation).Invoke(in rows, buffer.Memory.Span);
Expand All @@ -259,8 +259,8 @@ public static void IterateRowIntervals<T, TBuffer>(
}

int verticalStep = DivideCeil(height, numOfSteps);
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
var wrappingOperation = new RowIntervalOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
RowIntervalOperationWrapper<T, TBuffer> wrappingOperation = new RowIntervalOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);

Parallel.For(
0,
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Color/Color.WebSafePalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp;
/// </content>
public partial struct Color
{
private static readonly Lazy<Color[]> WebSafePaletteLazy = new Lazy<Color[]>(CreateWebSafePalette, true);
private static readonly Lazy<Color[]> WebSafePaletteLazy = new(CreateWebSafePalette, true);

/// <summary>
/// Gets a collection of named, web safe colors as defined in the CSS Color Module Level 4.
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Color/Color.WernerPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp;
/// </content>
public partial struct Color
{
private static readonly Lazy<Color[]> WernerPaletteLazy = new Lazy<Color[]>(CreateWernerPalette, true);
private static readonly Lazy<Color[]> WernerPaletteLazy = new(CreateWernerPalette, true);

/// <summary>
/// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/ColorProfiles/CieLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static CieLab FromProfileConnectingSpace(ColorConversionOptions options,
float a = 500F * (fx - fy);
float b = 200F * (fy - fz);

return new CieLab(l, a, b);
return new(l, a, b);
}

/// <inheritdoc/>
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/ColorProfiles/CieLch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLch(float l, float c, float h)
: this(new Vector3(l, c, h))
: this(new(l, c, h))
{
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public static CieLch FromProfileConnectingSpace(ColorConversionOptions options,
hDegrees += 360;
}

return new CieLch(l, c, hDegrees);
return new(l, c, hDegrees);
}

/// <inheritdoc/>
Expand All @@ -127,7 +127,7 @@ public CieLab ToProfileConnectingSpace(ColorConversionOptions options)
float a = c * MathF.Cos(hRadians);
float b = c * MathF.Sin(hRadians);

return new CieLab(l, a, b);
return new(l, a, b);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/ColorProfiles/CieLchuv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLchuv(float l, float c, float h)
: this(new Vector3(l, c, h))
: this(new(l, c, h))
{
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public static CieLchuv FromProfileConnectingSpace(ColorConversionOptions options
hDegrees += 360;
}

return new CieLchuv(l, c, hDegrees);
return new(l, c, hDegrees);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/ColorProfiles/CieLuv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static CieLuv FromProfileConnectingSpace(ColorConversionOptions options,
v = 0;
}

return new CieLuv((float)l, (float)u, (float)v);
return new((float)l, (float)u, (float)v);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -177,7 +177,7 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
z = 0;
}

return new CieXyz((float)x, (float)y, (float)z);
return new((float)x, (float)y, (float)z);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/ColorProfiles/CieXyy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static CieXyy FromProfileConnectingSpace(ColorConversionOptions options,

if (float.IsNaN(x) || float.IsNaN(y))
{
return new CieXyy(0, 0, source.Y);
return new(0, 0, source.Y);
}

return new CieXyy(x, y, source.Y);
return new(x, y, source.Y);
}

/// <inheritdoc/>
Expand All @@ -113,14 +113,14 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
{
if (MathF.Abs(this.Y) < Constants.Epsilon)
{
return new CieXyz(0, 0, this.Yl);
return new(0, 0, this.Yl);
}

float x = (this.X * this.Yl) / this.Y;
float y = this.Yl;
float z = ((1 - this.X - this.Y) * y) / this.Y;

return new CieXyz(x, y, z);
return new(x, y, z);
}

/// <inheritdoc/>
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/ColorProfiles/Cmyk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="k">The keyline black component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Cmyk(float c, float m, float y, float k)
: this(new Vector4(c, m, y, k))
: this(new(c, m, y, k))
{
}

Expand Down Expand Up @@ -100,12 +100,12 @@ public static Cmyk FromProfileConnectingSpace(ColorConversionOptions options, in

if (MathF.Abs(k.X - 1F) < Constants.Epsilon)
{
return new Cmyk(0, 0, 0, 1F);
return new(0, 0, 0, 1F);
}

cmy = (cmy - k) / (Vector3.One - k);

return new Cmyk(cmy.X, cmy.Y, cmy.Z, k.X);
return new(cmy.X, cmy.Y, cmy.Z, k.X);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/ColorProfiles/Hsl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="l">The l value (lightness) component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Hsl(float h, float s, float l)
: this(new Vector3(h, s, l))
: this(new(h, s, l))
{
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public static Hsl FromProfileConnectingSpace(ColorConversionOptions options, in

if (MathF.Abs(chroma) < Constants.Epsilon)
{
return new Hsl(0F, s, l);
return new(0F, s, l);
}

if (MathF.Abs(r - max) < Constants.Epsilon)
Expand Down Expand Up @@ -130,7 +130,7 @@ public static Hsl FromProfileConnectingSpace(ColorConversionOptions options, in
s = chroma / (2F - max - min);
}

return new Hsl(h, s, l);
return new(h, s, l);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -171,7 +171,7 @@ public Rgb ToProfileConnectingSpace(ColorConversionOptions options)
}
}

return new Rgb(r, g, b);
return new(r, g, b);
}

/// <inheritdoc/>
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/ColorProfiles/Hsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <param name="v">The v value (brightness) component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Hsv(float h, float s, float v)
: this(new Vector3(h, s, v))
: this(new(h, s, v))
{
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public static Hsv FromProfileConnectingSpace(ColorConversionOptions options, in

if (MathF.Abs(chroma) < Constants.Epsilon)
{
return new Hsv(0, s, v);
return new(0, s, v);
}

if (MathF.Abs(r - max) < Constants.Epsilon)
Expand All @@ -121,7 +121,7 @@ public static Hsv FromProfileConnectingSpace(ColorConversionOptions options, in

s = chroma / v;

return new Hsv(h, s, v);
return new(h, s, v);
}

/// <inheritdoc/>
Expand All @@ -143,7 +143,7 @@ public Rgb ToProfileConnectingSpace(ColorConversionOptions options)

if (MathF.Abs(s) < Constants.Epsilon)
{
return new Rgb(v, v, v);
return new(v, v, v);
}

float h = (MathF.Abs(this.H - 360) < Constants.Epsilon) ? 0 : this.H / 60;
Expand Down Expand Up @@ -194,7 +194,7 @@ public Rgb ToProfileConnectingSpace(ColorConversionOptions options)
break;
}

return new Rgb(r, g, b);
return new(r, g, b);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/ColorProfiles/HunterLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static HunterLab FromProfileConnectingSpace(ColorConversionOptions option
b = 0;
}

return new HunterLab(l, a, b);
return new(l, a, b);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -141,7 +141,7 @@ public CieXyz ToProfileConnectingSpace(ColorConversionOptions options)
float x = (((a / ka) * sqrtPow) + pow) * xn;
float z = (((b / kb) * sqrtPow) - pow) * (-zn);

return new CieXyz(x, y, z);
return new(x, y, z);
}

/// <inheritdoc/>
Expand Down
Loading
Loading