From 53237d2ef2f69c57bc4f32943066412c218c4e06 Mon Sep 17 00:00:00 2001 From: robloo Date: Wed, 2 Mar 2022 16:39:03 -0500 Subject: [PATCH] Remove IsNaN checks from constructor In XAML NaN is used in some cases so I wanted to cover this case. However, it isn't worth the performance cost in a constructor like this. NaN, Infinity, etc. will cause exceptions. --- src/Avalonia.Visuals/Media/HsvColor.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Visuals/Media/HsvColor.cs b/src/Avalonia.Visuals/Media/HsvColor.cs index b7b98e4227..0a2eb3a45c 100644 --- a/src/Avalonia.Visuals/Media/HsvColor.cs +++ b/src/Avalonia.Visuals/Media/HsvColor.cs @@ -27,10 +27,10 @@ namespace Avalonia.Media double saturation, double value) { - A = 1.0; - H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360); - S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1); - V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1); + A = 1.0; // Default to no transparency + H = MathUtilities.Clamp(hue, 0.0, 360.0); + S = MathUtilities.Clamp(saturation, 0.0, 1.0); + V = MathUtilities.Clamp(value, 0.0, 1.0); } /// @@ -46,10 +46,10 @@ namespace Avalonia.Media double saturation, double value) { - A = MathUtilities.Clamp((double.IsNaN(alpha) ? 1 : alpha), 0, 1); // Default to no transparency - H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360); - S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1); - V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1); + A = MathUtilities.Clamp(alpha, 0.0, 1.0); + H = MathUtilities.Clamp(hue, 0.0, 360.0); + S = MathUtilities.Clamp(saturation, 0.0, 1.0); + V = MathUtilities.Clamp(value, 0.0, 1.0); } ///