Use primary constructors in remaining projects

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-20 23:06:22 +01:00
1 親 46a6b25756
コミット 6897ecfcb2
14ファイル変更
+55 -174

検索条件に一致するファイルはありません

+5 -14
ファイルの表示
@@ -11,28 +11,19 @@ namespace SixLabors.ImageSharp;
/// <remarks>
/// This is a more efficient version of the <see cref="Complex64"/> type.
/// </remarks>
internal readonly struct Complex64
/// <param name="real">The real part in the complex number.</param>
/// <param name="imaginary">The imaginary part in the complex number.</param>
internal readonly struct Complex64(float real, float imaginary)
{
/// <summary>
/// The real part of the complex number.
/// </summary>
public readonly float Real;
public readonly float Real = real;
/// <summary>
/// The imaginary part of the complex number.
/// </summary>
public readonly float Imaginary;
/// <summary>
/// Initializes a new instance of the <see cref="Complex64"/> struct.
/// </summary>
/// <param name="real">The real part in the complex number.</param>
/// <param name="imaginary">The imaginary part in the complex number.</param>
public Complex64(float real, float imaginary)
{
this.Real = real;
this.Imaginary = imaginary;
}
public readonly float Imaginary = imaginary;
/// <summary>
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
+2
ファイルの表示
@@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
#pragma warning disable IDE0290
namespace ComputeSharp.BokehBlur.Processors;
/// <summary>
+2
ファイルの表示
@@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
#pragma warning disable IDE0290
namespace ComputeSharp.BokehBlur.Processors;
/// <summary>
+3 -16
ファイルの表示
@@ -56,7 +56,8 @@ internal abstract class PixelShaderEffect : CanvasEffect
/// An effect for an animated pixel shader.
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
public sealed class For<T> : PixelShaderEffect
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public sealed class For<T>(For<T>.Factory factory) : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
@@ -64,20 +65,6 @@ internal abstract class PixelShaderEffect : CanvasEffect
/// </summary>
private static readonly EffectNode<PixelShaderEffect<T>> Effect = new();
/// <summary>
/// The <typeparamref name="T"/> factory to use.
/// </summary>
private readonly Factory factory;
/// <summary>
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public For(Factory factory)
{
this.factory = factory;
}
/// <inheritdoc/>
protected override void BuildEffectGraph(EffectGraph effectGraph)
{
@@ -87,7 +74,7 @@ internal abstract class PixelShaderEffect : CanvasEffect
/// <inheritdoc/>
protected override void ConfigureEffectGraph(EffectGraph effectGraph)
{
effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight);
}
/// <summary>
+3 -16
ファイルの表示
@@ -56,7 +56,8 @@ public abstract class PixelShaderEffect : CanvasEffect
/// An effect for an animated pixel shader.
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
public sealed class For<T> : PixelShaderEffect
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public sealed class For<T>(For<T>.Factory factory) : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
@@ -64,20 +65,6 @@ public abstract class PixelShaderEffect : CanvasEffect
/// </summary>
private static readonly EffectNode<PixelShaderEffect<T>> Effect = new();
/// <summary>
/// The <typeparamref name="T"/> factory to use.
/// </summary>
private readonly Factory factory;
/// <summary>
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public For(Factory factory)
{
this.factory = factory;
}
/// <inheritdoc/>
protected override void BuildEffectGraph(EffectGraph effectGraph)
{
@@ -87,7 +74,7 @@ public abstract class PixelShaderEffect : CanvasEffect
/// <inheritdoc/>
protected override void ConfigureEffectGraph(EffectGraph effectGraph)
{
effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight);
}
/// <summary>
+10 -17
ファイルの表示
@@ -7,35 +7,28 @@ namespace ComputeSharp.SwapChain.Core.ViewModels;
/// <summary>
/// A viewmodel for a compute shader.
/// </summary>
public sealed partial class ShaderRunnerViewModel : ObservableObject
/// <param name="shaderType">The name of the shader type to execute.</param>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
public sealed partial class ShaderRunnerViewModel(
string shaderType,
IShaderRunner shaderRunner,
PixelShaderEffect pixelShaderEffect) : ObservableObject
{
/// <summary>
/// Creates a new <see cref="ShaderRunnerViewModel"/> instance.
/// </summary>
/// <param name="shaderType">The name of the shader type to execute.</param>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect)
{
ShaderType = shaderType;
ShaderRunner = shaderRunner;
PixelShaderEffect = pixelShaderEffect;
}
/// <summary>
/// Gets the name of the shader type to execute.
/// </summary>
public string ShaderType { get; }
public string ShaderType => shaderType;
/// <summary>
/// Gets the <see cref="IShaderRunner"/> instance to execute.
/// </summary>
public IShaderRunner ShaderRunner { get; }
public IShaderRunner ShaderRunner => shaderRunner;
/// <summary>
/// Gets the <see cref="PixelShaderEffect"/> instance to execute.
/// </summary>
public PixelShaderEffect PixelShaderEffect { get; }
public PixelShaderEffect PixelShaderEffect => pixelShaderEffect;
/// <summary>
/// Gets or sets whether the current shader is selected.
+3 -16
ファイルの表示
@@ -8,13 +8,9 @@ namespace ComputeSharp.SwapChain.Backend;
/// <summary>
/// A class representing a simple Win32 application.
/// </summary>
internal sealed unsafe class Win32Application
/// <param name="shaderCallback">The function pointer used to run a shader on a target texture.</param>
internal sealed unsafe class Win32Application(delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback)
{
/// <summary>
/// The function pointer used to run a shader on a target texture.
/// </summary>
private readonly delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback;
/// <summary>
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
/// </summary>
@@ -75,15 +71,6 @@ internal sealed unsafe class Win32Application
/// </summary>
private volatile bool isResizePending;
/// <summary>
/// Creates a new <see cref="Win32Application"/> instance with the specified parameters.
/// </summary>
/// <param name="shaderCallback">The function pointer used to run a shader on a target texture.</param>
public Win32Application(delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback)
{
this.shaderCallback = shaderCallback;
}
/// <summary>
/// Initializes the current application.
/// </summary>
@@ -241,7 +228,7 @@ internal sealed unsafe class Win32Application
}
// Generate the new frame by invoking the callback
this.shaderCallback(this.texture!, time);
shaderCallback(this.texture!, time);
using ComPtr<ID3D12Resource> d3D12Resource = default;
+6 -20
ファイルの表示
@@ -87,31 +87,17 @@ internal static class TolerantImageComparer
/// <summary>
/// A simple model repressenting info about a difference between two pixels.
/// </summary>
private readonly struct PixelDifference
private readonly struct PixelDifference(Point position, Color expected, Color actual)
{
public PixelDifference(Point position, Color expected, Color actual)
{
this.Position = position;
this.RedDifference = actual.R - expected.R;
this.GreenDifference = actual.G - expected.G;
this.BlueDifference = actual.B - expected.B;
this.AlphaDifference = actual.A - expected.A;
}
public readonly Point Position;
public readonly int RedDifference;
public readonly int GreenDifference;
public readonly int BlueDifference;
public readonly int AlphaDifference;
private readonly int redDifference = actual.R - expected.R;
private readonly int greenDifference = actual.G - expected.G;
private readonly int blueDifference = actual.B - expected.B;
private readonly int alphaDifference = actual.A - expected.A;
/// <inheritdoc/>
public override string ToString()
{
return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]";
return $"[delta({this.redDifference},{this.greenDifference},{this.blueDifference},{this.alphaDifference}) @ ({position.X},{position.Y})]";
}
}
}
+3 -11
ファイルの表示
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
/// <summary>
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> adding additional arbitrary input data.
/// </summary>
/// <param name="data">The additional input data.</param>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class AdditionalDataAttribute : Attribute
public sealed class AdditionalDataAttribute(params object[] data) : Attribute
{
/// <summary>
/// Creates a new <see cref="AdditionalDataAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="data">The additional input data.</param>
public AdditionalDataAttribute(params object[] data)
{
Data = data;
}
/// <summary>
/// Gets the additional input data for the current attribute.
/// </summary>
public object[] Data { get; }
public object[] Data => data;
}
+3 -11
ファイルの表示
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
/// <summary>
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> targeting an additional specific resource type.
/// </summary>
/// <param name="type">The additional resource type.</param>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class AdditionalResourceAttribute : Attribute
public sealed class AdditionalResourceAttribute(Type type) : Attribute
{
/// <summary>
/// Creates a new <see cref="AdditionalResourceAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="type">The additional resource type.</param>
public AdditionalResourceAttribute(Type type)
{
Type = type;
}
/// <summary>
/// Gets the additional resource type for the current attribute.
/// </summary>
public Type Type { get; }
public Type Type => type;
}
+3 -11
ファイルの表示
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
/// <summary>
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> adding arbitrary input data.
/// </summary>
/// <param name="data">The input data.</param>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class DataAttribute : Attribute
public sealed class DataAttribute(params object[] data) : Attribute
{
/// <summary>
/// Creates a new <see cref="DataAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="data">The input data.</param>
public DataAttribute(params object[] data)
{
Data = data;
}
/// <summary>
/// Gets the input data for the current attribute.
/// </summary>
public object[] Data { get; }
public object[] Data => data;
}
+3 -11
ファイルの表示
@@ -6,20 +6,12 @@ namespace ComputeSharp.Tests.Attributes;
/// <summary>
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> adding a specific <see cref="Extensions.Device"/> input.
/// </summary>
/// <param name="device">The target device type to use..</param>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class DeviceAttribute : Attribute
public sealed class DeviceAttribute(Device device) : Attribute
{
/// <summary>
/// Creates a new <see cref="DeviceAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="device">The target device type to use..</param>
public DeviceAttribute(Device device)
{
Device = device;
}
/// <summary>
/// Gets the <see cref="Extensions.Device"/> target to use.
/// </summary>
public Device Device { get; }
public Device Device => device;
}
+3 -11
ファイルの表示
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
/// <summary>
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> targeting a specific resource type.
/// </summary>
/// <param name="type">The resource type.</param>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class ResourceAttribute : Attribute
public sealed class ResourceAttribute(Type type) : Attribute
{
/// <summary>
/// Creates a new <see cref="ResourceAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="type">The resource type.</param>
public ResourceAttribute(Type type)
{
Type = type;
}
/// <summary>
/// Gets the resource type for the current attribute.
/// </summary>
public Type Type { get; }
public Type Type => type;
}
+6 -20
ファイルの表示
@@ -117,31 +117,17 @@ internal static class TolerantImageComparer
/// <summary>
/// A simple model repressenting info about a difference between two pixels.
/// </summary>
private readonly struct PixelDifference
private readonly struct PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual)
{
public PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual)
{
this.Position = position;
this.RedDifference = actual.R - expected.R;
this.GreenDifference = actual.G - expected.G;
this.BlueDifference = actual.B - expected.B;
this.AlphaDifference = actual.A - expected.A;
}
public readonly Point Position;
public readonly int RedDifference;
public readonly int GreenDifference;
public readonly int BlueDifference;
public readonly int AlphaDifference;
private readonly int redDifference = actual.R - expected.R;
private readonly int greenDifference = actual.G - expected.G;
private readonly int blueDifference = actual.B - expected.B;
private readonly int alphaDifference = actual.A - expected.A;
/// <inheritdoc/>
public override string ToString()
{
return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]";
return $"[delta({this.redDifference},{this.greenDifference},{this.blueDifference},{this.alphaDifference}) @ ({position.X},{position.Y})]";
}
}
}