Skip to content

Commit

Permalink
Merge pull request #1332 from SixLabors/sp/bokeh-blur-init-tweaks
Browse files Browse the repository at this point in the history
Bokeh blur constructor tweaks (input validation, tiny speedup)
  • Loading branch information
antonfirsov authored Aug 31, 2020
2 parents 801961d + 38311ed commit 9b9e134
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public sealed class BokehBlurProcessor : IImageProcessor
/// Initializes a new instance of the <see cref="BokehBlurProcessor"/> class.
/// </summary>
public BokehBlurProcessor()
: this(DefaultRadius, DefaultComponents, DefaultGamma)
{
this.Radius = DefaultRadius;
this.Components = DefaultComponents;
this.Gamma = DefaultGamma;
}

/// <summary>
Expand All @@ -47,6 +49,8 @@ public BokehBlurProcessor()
/// </param>
public BokehBlurProcessor(int radius, int components, float gamma)
{
Guard.MustBeGreaterThan(radius, 0, nameof(radius));
Guard.MustBeBetweenOrEqualTo(components, 1, 6, nameof(components));
Guard.MustBeGreaterThanOrEqualTo(gamma, 1, nameof(gamma));

this.Radius = radius;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ [[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
0.02565295+0.01611732j 0.0153483+0.01605112j 0.00698622+0.01370844j
0.00135338+0.00998296j -0.00152245+0.00604545j -0.00227282+0.002851j ]]";

[Theory]
[InlineData(-10, 2, 3f)]
[InlineData(-1, 2, 3f)]
[InlineData(0, 2, 3f)]
[InlineData(20, -1, 3f)]
[InlineData(20, -0, 3f)]
[InlineData(20, 4, -10f)]
[InlineData(20, 4, 0f)]
public void VerifyBokehBlurProcessorArguments_Fail(int radius, int components, float gamma)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new BokehBlurProcessor(radius, components, gamma));
}

[Fact]
public void VerifyComplexComponents()
{
Expand Down

0 comments on commit 9b9e134

Please sign in to comment.