Skip to content

Commit 523b88e

Browse files
committed
WIP #275 - consolidate sanitization logic
1 parent b205f3e commit 523b88e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

CSF.Screenplay.Selenium/Color.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ public struct Color
7070
public readonly double Alpha
7171
{
7272
get => alpha;
73-
init => this.alpha = value < 0 ? 0 : value > 1 ? 1 : value;
73+
init => this.alpha = SanitizeAlpha(value);
7474
}
7575
#else
7676
public double Alpha
7777
{
7878
get => alpha;
79-
private set => alpha = value < 0 ? 0 : value > 1 ? 1 : value;
79+
private set => alpha = SanitizeAlpha(value);
8080
}
8181
#endif
8282

@@ -142,9 +142,21 @@ public Color(byte red, byte green, byte blue, double alpha)
142142
Red = red;
143143
Green = green;
144144
Blue = blue;
145-
this.alpha = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
145+
this.alpha = SanitizeAlpha(alpha);
146146
}
147147

148+
/// <summary>
149+
/// Sanitizes a value intended for <see cref="Alpha"/>.
150+
/// </summary>
151+
/// <remarks>
152+
/// <para>If <paramref name="alpha"/> is less than zero then this method returns zero.
153+
/// If <paramref name="alpha"/> is more than one then this method returns one.
154+
/// Otherwise, this method returns <paramref name="alpha"/>.</para>
155+
/// </remarks>
156+
/// <param name="alpha">The alpha value.</param>
157+
/// <returns>A sanitized alpha value.</returns>
158+
static double SanitizeAlpha(double alpha) => alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
159+
148160
/// <summary>
149161
/// Converts a <see cref="System.Drawing.Color"/> into a <see cref="Color"/>.
150162
/// </summary>

0 commit comments

Comments
 (0)