diff --git a/src/Magick.NET.Core/Factories/ISettingsFactory.cs b/src/Magick.NET.Core/Factories/ISettingsFactory.cs index fbb8d3dac7..283d2290f0 100644 --- a/src/Magick.NET.Core/Factories/ISettingsFactory.cs +++ b/src/Magick.NET.Core/Factories/ISettingsFactory.cs @@ -15,8 +15,9 @@ public interface ISettingsFactory /// /// Initializes a new instance that implements . /// + /// The error metric to use. /// A new instance. - ICompareSettings CreateCompareSettings(); + ICompareSettings CreateCompareSettings(ErrorMetric metric); /// /// Initializes a new instance that implements . diff --git a/src/Magick.NET.Core/Settings/ICompareSettings{TQuantumType}.cs b/src/Magick.NET.Core/Settings/ICompareSettings{TQuantumType}.cs index dbe637900c..63086be388 100644 --- a/src/Magick.NET.Core/Settings/ICompareSettings{TQuantumType}.cs +++ b/src/Magick.NET.Core/Settings/ICompareSettings{TQuantumType}.cs @@ -13,9 +13,9 @@ public interface ICompareSettings where TQuantumType : struct, IConvertible { /// - /// Gets or sets the error metric to use. + /// Gets the error metric to use. /// - ErrorMetric Metric { get; set; } + ErrorMetric Metric { get; } /// /// Gets or sets the color that emphasize pixel differences. diff --git a/src/Magick.NET/Factories/SettingsFactory.cs b/src/Magick.NET/Factories/SettingsFactory.cs index 6986d8f7a2..16c2c97d6e 100644 --- a/src/Magick.NET/Factories/SettingsFactory.cs +++ b/src/Magick.NET/Factories/SettingsFactory.cs @@ -21,9 +21,10 @@ public sealed class SettingsFactory : ISettingsFactory /// /// Initializes a new instance that implements . /// + /// The error metric to use. /// A new instance. - public ICompareSettings CreateCompareSettings() - => new CompareSettings(); + public ICompareSettings CreateCompareSettings(ErrorMetric metric) + => new CompareSettings(metric); /// /// Initializes a new instance that implements . diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs index abc4853053..1fae3a2b36 100644 --- a/src/Magick.NET/MagickImage.cs +++ b/src/Magick.NET/MagickImage.cs @@ -1746,7 +1746,7 @@ public IMagickImage Compare(IMagickImage image, ErrorMetric metric, /// The image that contains the difference. /// Thrown when an error is raised by ImageMagick. public IMagickImage Compare(IMagickImage image, ErrorMetric metric, Channels channels, out double distortion) - => Compare(image, new CompareSettings { Metric = metric }, channels, out distortion); + => Compare(image, new CompareSettings(metric), channels, out distortion); /// /// Returns the distortion based on the specified metric. diff --git a/src/Magick.NET/Settings/CompareSettings.cs b/src/Magick.NET/Settings/CompareSettings.cs index 20c85661e5..6ad200ddce 100644 --- a/src/Magick.NET/Settings/CompareSettings.cs +++ b/src/Magick.NET/Settings/CompareSettings.cs @@ -19,9 +19,16 @@ namespace ImageMagick; public sealed class CompareSettings : ICompareSettings { /// - /// Gets or sets the error metric to use. + /// Initializes a new instance of the class. /// - public ErrorMetric Metric { get; set; } + /// The error metric to use. + public CompareSettings(ErrorMetric metric) + => Metric = metric; + + /// + /// Gets the error metric to use. + /// + public ErrorMetric Metric { get; } /// /// Gets or sets the color that emphasize pixel differences. diff --git a/tests/Magick.NET.Tests/Factories/SettingsFactoryTests/TheCreateCompareSettingsMethod.cs b/tests/Magick.NET.Tests/Factories/SettingsFactoryTests/TheCreateCompareSettingsMethod.cs index 92118f9b2d..cd96eb77f4 100644 --- a/tests/Magick.NET.Tests/Factories/SettingsFactoryTests/TheCreateCompareSettingsMethod.cs +++ b/tests/Magick.NET.Tests/Factories/SettingsFactoryTests/TheCreateCompareSettingsMethod.cs @@ -16,10 +16,11 @@ public void ShouldCreateInstance() { var factory = new SettingsFactory(); - var settings = factory.CreateCompareSettings(); + var settings = factory.CreateCompareSettings(ErrorMetric.NormalizedCrossCorrelation); Assert.NotNull(settings); Assert.IsType(settings); + Assert.Equal(ErrorMetric.NormalizedCrossCorrelation, settings.Metric); } } } diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheCompareMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheCompareMethod.cs index 665eb654b3..c35d093d78 100644 --- a/tests/Magick.NET.Tests/MagickImageTests/TheCompareMethod.cs +++ b/tests/Magick.NET.Tests/MagickImageTests/TheCompareMethod.cs @@ -44,7 +44,7 @@ public void ShouldThrowAnExceptionWhenImageIsNullAndSettingsAreNotNull() { using var image = new MagickImage(); - Assert.Throws("image", () => image.Compare(null, new CompareSettings(), out var distortion)); + Assert.Throws("image", () => image.Compare(null, new CompareSettings(ErrorMetric.PeakSignalToNoiseRatio), out var distortion)); } [Fact] @@ -71,10 +71,7 @@ public void ShouldReturnEmptyErrorInfoWhenTheImagesAreEqual() [Fact] public void ShouldReturnZeroWhenTheImagesAreEqual() { - var settings = new CompareSettings - { - Metric = ErrorMetric.RootMeanSquared, - }; + var settings = new CompareSettings(ErrorMetric.RootMeanSquared); using var image = new MagickImage(Files.Builtin.Logo); using var other = new MagickImage(Files.Builtin.Logo); @@ -114,9 +111,8 @@ public void ShouldReturnErrorInfoWhenTheImagesAreNotEqual() [Fact] public void ShouldReturnNonZeroValueWhenTheImagesAreNotEqual() { - var settings = new CompareSettings + var settings = new CompareSettings(ErrorMetric.RootMeanSquared) { - Metric = ErrorMetric.RootMeanSquared, HighlightColor = MagickColors.Yellow, LowlightColor = MagickColors.Red, MasklightColor = MagickColors.Magenta,