diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs
index b1827d5c3c7..3e7c8c6a2cf 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs
@@ -632,12 +632,7 @@ internal static bool IsValidAnimationValueDecimal(Decimal value)
internal static bool IsValidAnimationValueDouble(Double value)
{
- if (IsInvalidDouble(value))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value);
}
internal static bool IsValidAnimationValueInt16(Int16 value)
@@ -662,45 +657,23 @@ internal static bool IsValidAnimationValueMatrix(Matrix value)
internal static bool IsValidAnimationValuePoint(Point value)
{
- if (IsInvalidDouble(value.X) || IsInvalidDouble(value.Y))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.X) && double.IsFinite(value.Y);
}
internal static bool IsValidAnimationValuePoint3D(Point3D value)
{
- if (IsInvalidDouble(value.X) || IsInvalidDouble(value.Y) || IsInvalidDouble(value.Z))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.X) && double.IsFinite(value.Y) && double.IsFinite(value.Z);
}
internal static bool IsValidAnimationValueQuaternion(Quaternion value)
{
- if ( IsInvalidDouble(value.X) || IsInvalidDouble(value.Y)
- || IsInvalidDouble(value.Z) || IsInvalidDouble(value.W))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.X) && double.IsFinite(value.Y) && double.IsFinite(value.Z) && double.IsFinite(value.W);
}
internal static bool IsValidAnimationValueRect(Rect value)
{
- if ( IsInvalidDouble(value.Location.X) || IsInvalidDouble(value.Location.Y)
- || IsInvalidDouble(value.Size.Width) || IsInvalidDouble(value.Size.Height)
- || value.IsEmpty)
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.Location.X) && double.IsFinite(value.Location.Y) &&
+ double.IsFinite(value.Size.Width) && double.IsFinite(value.Size.Height) && !value.IsEmpty;
}
internal static bool IsValidAnimationValueRotation3D(Rotation3D value)
@@ -708,49 +681,29 @@ internal static bool IsValidAnimationValueRotation3D(Rotation3D value)
return IsValidAnimationValueQuaternion(value.InternalQuaternion);
}
- internal static bool IsValidAnimationValueSingle(Single value)
+ internal static bool IsValidAnimationValueSingle(float value)
{
- if (IsInvalidDouble(value))
- {
- return false;
- }
-
- return true;
+ return float.IsFinite(value);
}
internal static bool IsValidAnimationValueSize(Size value)
{
- if (IsInvalidDouble(value.Width) || IsInvalidDouble(value.Height))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.Width) && double.IsFinite(value.Height);
}
- internal static bool IsValidAnimationValueString(String value)
+ internal static bool IsValidAnimationValueString(string value)
{
return true;
}
- internal static bool IsValidAnimationValueVector(System.Windows.Vector value)
+ internal static bool IsValidAnimationValueVector(Vector value)
{
- if (IsInvalidDouble(value.X) || IsInvalidDouble(value.Y))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.X) && double.IsFinite(value.Y);
}
internal static bool IsValidAnimationValueVector3D(Vector3D value)
{
- if (IsInvalidDouble(value.X) || IsInvalidDouble(value.Y) || IsInvalidDouble(value.Z))
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value.X) && double.IsFinite(value.Y) && double.IsFinite(value.Z);
}
#endregion
@@ -839,14 +792,5 @@ internal static Rotation3D GetZeroValueRotation3D(Rotation3D baseValue)
#endregion
- #region Helpers
-
- private static Boolean IsInvalidDouble(Double value)
- {
- return Double.IsInfinity(value)
- || double.IsNaN(value);
- }
-
- #endregion
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StylusShape.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StylusShape.cs
index eeb4e614752..9808b6a0f50 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StylusShape.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StylusShape.cs
@@ -38,17 +38,17 @@ internal StylusShape(){}
///
internal StylusShape(StylusTip tip, double width, double height, double rotation)
{
- if (Double.IsNaN(width) || Double.IsInfinity(width) || width < DrawingAttributes.MinWidth || width > DrawingAttributes.MaxWidth)
+ if (!double.IsFinite(width) || width < DrawingAttributes.MinWidth || width > DrawingAttributes.MaxWidth)
{
throw new ArgumentOutOfRangeException(nameof(width));
}
- if (Double.IsNaN(height) || Double.IsInfinity(height) || height < DrawingAttributes.MinHeight || height > DrawingAttributes.MaxHeight)
+ if (!double.IsFinite(height) || height < DrawingAttributes.MinHeight || height > DrawingAttributes.MaxHeight)
{
throw new ArgumentOutOfRangeException(nameof(height));
}
- if (Double.IsNaN(rotation) || Double.IsInfinity(rotation))
+ if (!double.IsFinite(rotation))
{
throw new ArgumentOutOfRangeException(nameof(rotation));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs
index fcbf93a4a6b..6bd7023d250 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs
@@ -49,7 +49,7 @@ public double DesiredDeceleration
get { return _desiredDeceleration; }
set
{
- if (Double.IsInfinity(value) || Double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs
index 6265d7cc138..658c5913756 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs
@@ -49,7 +49,7 @@ public double DesiredDeceleration
get { return _desiredDeceleration; }
set
{
- if (Double.IsInfinity(value) || Double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
@@ -69,7 +69,7 @@ public double DesiredRotation
get { return _desiredRotation; }
set
{
- if (Double.IsInfinity(value) || Double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaTranslationBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaTranslationBehavior.cs
index cf0cd5d1bbd..65cef5cdc68 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaTranslationBehavior.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaTranslationBehavior.cs
@@ -49,7 +49,7 @@ public double DesiredDeceleration
get { return _desiredDeceleration; }
set
{
- if (Double.IsInfinity(value) || Double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
@@ -69,7 +69,7 @@ public double DesiredDisplacement
get { return _desiredDisplacement; }
set
{
- if (Double.IsInfinity(value) || Double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs
index 8ea3d780f54..eee47e03008 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs
@@ -35,7 +35,7 @@ namespace System.Windows.Media.Animation
/// The number of iterations specified by this RepeatBehavior.
public RepeatBehavior(double count)
{
- if (double.IsInfinity(count) || double.IsNaN(count) || count < 0.0)
+ if (!double.IsFinite(count) || count < 0.0)
throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.Timing_RepeatBehaviorInvalidIterationCount, count));
_repeatDuration = TimeSpan.Zero;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/MeshGeometry3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/MeshGeometry3D.cs
index f1046645ae3..7a6bad49cdd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/MeshGeometry3D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/MeshGeometry3D.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
@@ -404,8 +404,7 @@ ref Point barycentric
return;
}
- Debug.Assert(!double.IsInfinity(pz / pw) && !double.IsNaN(pz / pw),
- "Expected near/far tests to cull -Inf/+Inf and NaN.");
+ Debug.Assert(double.IsFinite(pz / pw), "Expected near/far tests to cull -Inf/+Inf and NaN.");
}
double dist = (worldPointHit - rayParams.Origin).Length;
@@ -490,8 +489,7 @@ ref Point barycentric
return;
}
- Debug.Assert(!double.IsInfinity(pz / pw) && !double.IsNaN(pz / pw),
- "Expected near/far tests to cull -Inf/+Inf and NaN.");
+ Debug.Assert(double.IsFinite(pz / pw), "Expected near/far tests to cull -Inf/+Inf and NaN.");
}
Point3D a = v0, b = v1, c = v2;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
index 33241ed2c7d..1d3afc1cded 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs
@@ -1085,9 +1085,7 @@ internal static double RoundLayoutValue(double value, double dpiScale)
{
newValue = Math.Round(value * dpiScale) / dpiScale;
// If rounding produces a value unacceptable to layout (NaN, Infinity or MaxValue), use the original value.
- if (double.IsNaN(newValue) ||
- Double.IsInfinity(newValue) ||
- DoubleUtil.AreClose(newValue, Double.MaxValue))
+ if (!double.IsFinite(newValue) || DoubleUtil.AreClose(newValue, double.MaxValue))
{
newValue = value;
}
@@ -1388,9 +1386,9 @@ private static void RenderTransform_Changed(DependencyObject d, DependencyProper
private static bool IsRenderTransformOriginValid(object value)
{
- Point v = (Point)value;
- return ( (!double.IsNaN(v.X) && !Double.IsPositiveInfinity(v.X) && !Double.IsNegativeInfinity(v.X))
- && (!double.IsNaN(v.Y) && !Double.IsPositiveInfinity(v.Y) && !Double.IsNegativeInfinity(v.Y)));
+ Point origin = (Point)value;
+
+ return double.IsFinite(origin.X) && double.IsFinite(origin.Y);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs
index 704e464d12c..bd60ec39d82 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -113,28 +113,10 @@ internal static Thickness ScaleThickness(Thickness value, double factor)
#region IsValidAnimationValue Methods
- private static bool IsValidAnimationValueDouble(Double value)
- {
- if (IsInvalidDouble(value))
- {
- return false;
- }
-
- return true;
- }
-
internal static bool IsValidAnimationValueThickness(Thickness value)
{
// At least one of the sub-values must be an interpolatable length.
- if ( IsValidAnimationValueDouble(value.Left)
- || IsValidAnimationValueDouble(value.Top)
- || IsValidAnimationValueDouble(value.Right)
- || IsValidAnimationValueDouble(value.Bottom))
- {
- return true;
- }
-
- return false;
+ return double.IsFinite(value.Left) || double.IsFinite(value.Top) || double.IsFinite(value.Right) || double.IsFinite(value.Bottom);
}
#endregion
@@ -157,14 +139,5 @@ internal static Thickness GetZeroValueThickness(Thickness baseValue)
#endregion
- #region Helpers
-
- private static bool IsInvalidDouble(double value)
- {
- return Double.IsInfinity(value)
- || double.IsNaN(value);
- }
-
- #endregion
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
index 1c2731685ad..b559be1a8e0 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs
@@ -540,17 +540,6 @@ internal static Size ArrangeElementWithSingleChild(UIElement element, Size arran
return arrangeSize;
}
- ///
- /// Helper method used for double parameter validation. Returns false
- /// if the value is either Infinity (positive or negative) or NaN.
- ///
- /// The double value to test
- /// Whether the value is a valid double.
- internal static bool IsDoubleValid(double value)
- {
- return !(Double.IsInfinity(value) || Double.IsNaN(value));
- }
-
///
/// Checks if the given IProvideValueTarget can receive
/// a DynamicResource or Binding MarkupExtension.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
index e28eb3645d5..316eee3749a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
@@ -422,7 +422,7 @@ public void SetScale(double scale)
{
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(scale, 0.0);
- if (!Helper.IsDoubleValid(scale))
+ if (!double.IsFinite(scale))
{
throw new ArgumentOutOfRangeException(nameof(scale));
}
@@ -798,7 +798,7 @@ public double VerticalPageSpacing
set
{
- if (!Helper.IsDoubleValid(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
@@ -820,7 +820,7 @@ public double HorizontalPageSpacing
set
{
- if (!Helper.IsDoubleValid(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridSplitterAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridSplitterAutomationPeer.cs
index 469df6390e8..bb349e9747f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridSplitterAutomationPeer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridSplitterAutomationPeer.cs
@@ -39,10 +39,10 @@ void ITransformProvider.Move(double x, double y)
if (!IsEnabled())
throw new ElementNotEnabledException();
- if (double.IsInfinity(x) || double.IsNaN(x))
+ if (!double.IsFinite(x))
throw new ArgumentOutOfRangeException(nameof(x));
- if (double.IsInfinity(y) || double.IsNaN(y))
+ if (!double.IsFinite(y))
throw new ArgumentOutOfRangeException(nameof(y));
((GridSplitter)Owner).KeyboardMoveSplitter(x, y);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Border.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Border.cs
index 0352bbc136b..9c79f5a9e63 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Border.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Border.cs
@@ -159,7 +159,8 @@ public static readonly DependencyProperty CornerRadiusProperty
private static bool IsCornerRadiusValid(object value)
{
CornerRadius cr = (CornerRadius)value;
- return (cr.IsValid(false, false, false, false));
+
+ return cr.IsValid();
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs
index 02efc989cf3..bf2ef8d867e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs
@@ -2014,7 +2014,7 @@ private double GetViewportWidth()
if (DoubleUtil.AreClose(availableViewportWidth, 0.0) && parentRowsPresenter != null)
{
Size rowPresenterAvailableSize = parentRowsPresenter.AvailableSize;
- if (!double.IsNaN(rowPresenterAvailableSize.Width) && !Double.IsInfinity(rowPresenterAvailableSize.Width))
+ if (double.IsFinite(rowPresenterAvailableSize.Width))
{
availableViewportWidth = rowPresenterAvailableSize.Width;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
index 80861d2c491..97155e12aa5 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
@@ -72,7 +72,7 @@ public DataGridLength(double value, DataGridLengthUnitType type)
///
public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue)
{
- if (double.IsNaN(value) || Double.IsInfinity(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentException(
SR.DataGridLength_Infinity,
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
index c5eb7ab7690..e5f0b63b1f9 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
@@ -2260,41 +2260,6 @@ private void FindZoomLevelIndex()
}
}
- ///
- /// Determines if the parameter represents a valid double (that is a value other
- /// than NaN, PositiveInfinity, or NegativeInfinity).
- ///
- /// The double value to be checked
- /// True if the double value is valid, false otherwise.
- private static bool DoubleValue_Validate(object value)
- {
- // Place this helper method
- // in a location with standard utilities.
-
- bool ok;
-
- // Ensure value is double
- if (value is double checkValue)
- {
-
- // Check if double is within an assumed range
- if ((double.IsNaN(checkValue)) ||
- (double.IsInfinity(checkValue)))
- {
- ok = false;
- }
- else
- {
- ok = true;
- }
- }
- else
- {
- ok = false;
- }
- return ok;
- }
-
///
/// Converts an IDocumentScrollInfo's Scale value to a Zoom
///
@@ -2325,7 +2290,7 @@ private static double ZoomToScale(double zoom)
/// True if the offset is valid, false otherwise.
private static bool ValidateOffset(object value)
{
- return DoubleValue_Validate(value) && ((double)value >= 0.0);
+ return value is double doubleValue && double.IsFinite(doubleValue) && doubleValue >= 0.0;
}
///
@@ -2508,7 +2473,7 @@ private static void OnMaxPagesAcrossChanged(DependencyObject d, DependencyProper
/// True if the offset is valid, false otherwise.
private static bool ValidatePageSpacing(object value)
{
- return DoubleValue_Validate(value) && ((double)value >= 0.0);
+ return value is double doubleValue && double.IsFinite(doubleValue) && doubleValue >= 0.0;
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
index 9266295e69e..8ad30869ec5 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
@@ -1782,17 +1782,6 @@ private static void MinZoomChanged(DependencyObject d, DependencyPropertyChanged
viewer.SetValue(CanDecreaseZoomPropertyKey, BooleanBoxes.Box(DoubleUtil.LessThan(viewer.MinZoom, viewer.Zoom)));
}
- ///
- /// Validate Zoom, MaxZoom, MinZoom and ZoomIncrement value.
- ///
- /// Value to validate.
- /// True if the value is valid, false otherwise.
- private static bool ZoomValidateValue(object o)
- {
- double value = (double)o;
- return (!Double.IsNaN(value) && !Double.IsInfinity(value) && DoubleUtil.GreaterThanZero(value));
- }
-
///
/// PropertyChanged callback for a property that affects the selection or caret rendering.
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs
index edd31ba527f..61f845c09e2 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs
@@ -1672,17 +1672,6 @@ private static void MinZoomChanged(DependencyObject d, DependencyPropertyChanged
viewer.SetValue(CanDecreaseZoomPropertyKey, BooleanBoxes.Box(DoubleUtil.LessThan(viewer.MinZoom, viewer.Zoom)));
}
- ///
- /// Validate Zoom, MaxZoom, MinZoom and ZoomIncrement value.
- ///
- /// Value to validate.
- /// True if the value is valid, false otherwise.
- private static bool ZoomValidateValue(object o)
- {
- double value = (double)o;
- return (!Double.IsNaN(value) && !Double.IsInfinity(value) && DoubleUtil.GreaterThanZero(value));
- }
-
///
/// Called from the event handler to make sure the target is visible in the client area.
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs
index 5556ca6377e..01df474e510 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs
@@ -1567,12 +1567,8 @@ private void EnsureMinSizeInDefinitionRange(
double sizeToDistribute = requestedSize - rangeMaxSize;
// sanity check: totalRemainingSize and sizeToDistribute must be real positive numbers
- Debug.Assert( !double.IsInfinity(totalRemainingSize)
- && !double.IsNaN(totalRemainingSize)
- && totalRemainingSize > 0
- && !double.IsInfinity(sizeToDistribute)
- && !double.IsNaN(sizeToDistribute)
- && sizeToDistribute > 0 );
+ Debug.Assert(double.IsFinite(totalRemainingSize) && totalRemainingSize > 0 &&
+ double.IsFinite(sizeToDistribute) && sizeToDistribute > 0);
for (int i = 0; i < count; ++i)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumn.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumn.cs
index b5498e8eb65..b6c417d08f8 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumn.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumn.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -419,7 +419,7 @@ public double ActualWidth
private set
{
- if (Double.IsNaN(value) || Double.IsInfinity(value) || value < 0.0)
+ if (!double.IsFinite(value) || value < 0.0)
{
Debug.Assert(false, "Invalid value for ActualWidth.");
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs
index 5f8e436f2a1..b3c8220d016 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs
@@ -1834,15 +1834,11 @@ public void Paste(Point point)
{
VerifyAccess();
- if (double.IsNaN(point.X) ||
- double.IsNaN(point.Y) ||
- Double.IsInfinity(point.X)||
- Double.IsInfinity(point.Y) )
+ if (!double.IsFinite(point.X) || !double.IsFinite(point.Y))
{
- throw new ArgumentException(SR.InvalidPoint, nameof(point));
+ throw new ArgumentException(SR.InvalidPoint, nameof(point));
}
-
//
// only do this if the user is not editing (input active)
// or we will violate a dispatcher lock
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs
index 4c6c2f4b74f..a0221758e97 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs
@@ -247,9 +247,9 @@ protected virtual void OnValueChanged(double oldValue, double newValue)
/// Returns False if value is NaN or NegativeInfinity or PositiveInfinity. Otherwise, returns True.
private static bool IsValidDoubleValue(object value)
{
- double d = (double)value;
+ double valueDouble = (double)value;
- return !(double.IsNaN(d) || double.IsInfinity(d));
+ return double.IsFinite(valueDouble);
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs
index 0a63ef95c2f..9196786d182 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs
@@ -795,8 +795,11 @@ private void VerifyScrollData(Size viewport, Size extent)
// Infinity size from measure, which is a regression from the old scrolling model.
// They also have the incidental affect of probably avoiding reinvalidation at Arrange
// when inside a parent that measures you to Infinity.
- if (Double.IsInfinity(viewport.Width)) viewport.Width = extent.Width;
- if (Double.IsInfinity(viewport.Height)) viewport.Height = extent.Height;
+ if (double.IsInfinity(viewport.Width))
+ viewport.Width = extent.Width;
+
+ if (double.IsInfinity(viewport.Height))
+ viewport.Height = extent.Height;
fValid &= DoubleUtil.AreClose(viewport, _scrollData._viewport);
fValid &= DoubleUtil.AreClose(extent, _scrollData._extent);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs
index 3edfcf72836..3fef0ab58eb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs
@@ -128,7 +128,7 @@ protected override Size MeasureOverride(Size constraint)
contentSize.Height = _rowHeight * _numRows;
// If we don't have constraint or content wisth is smaller than constraint width then size to content
- if (double.IsInfinity(contentSize.Width) || double.IsNaN(contentSize.Width) || maxRowWidth < constraint.Width)
+ if (!double.IsFinite(contentSize.Width) || maxRowWidth < constraint.Width)
contentSize.Width = maxRowWidth;
else
contentSize.Width = constraint.Width;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs
index 3d65364a361..507c27d0a3f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs
@@ -1445,7 +1445,8 @@ private static void MinZoomChanged(DependencyObject d, DependencyPropertyChanged
private static bool ZoomValidateValue(object o)
{
double value = (double)o;
- return (!Double.IsNaN(value) && !Double.IsInfinity(value) && DoubleUtil.GreaterThanZero(value));
+
+ return double.IsFinite(value) && DoubleUtil.GreaterThanZero(value);
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs
index 37d8a9a05bb..cff32e07985 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs
@@ -1415,9 +1415,9 @@ private void UpdateValue(double value)
/// Returns False if value is NaN or NegativeInfinity or PositiveInfinity. Otherwise, returns True.
private static bool IsValidDoubleValue(object value)
{
- double d = (double)value;
+ double valueDouble = (double)value;
- return !(double.IsNaN(d) || double.IsInfinity(d));
+ return double.IsFinite(valueDouble);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
index 334e9104175..5a8c7f93f82 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
@@ -190,53 +190,14 @@ public double BottomLeft
#region Internal Methods Properties
- internal bool IsValid(bool allowNegative, bool allowNaN, bool allowPositiveInfinity, bool allowNegativeInfinity)
+ internal readonly bool IsValid()
{
- if (!allowNegative)
+ if (_topLeft < 0d || _topRight < 0d || _bottomLeft < 0d || _bottomRight < 0d)
{
- if (_topLeft < 0d || _topRight < 0d || _bottomLeft < 0d || _bottomRight < 0d)
- {
- return (false);
- }
+ return false;
}
- if (!allowNaN)
- {
- if (double.IsNaN(_topLeft) || double.IsNaN(_topRight) || double.IsNaN(_bottomLeft) || double.IsNaN(_bottomRight))
- {
- return (false);
- }
- }
-
- if (!allowPositiveInfinity)
- {
- if (Double.IsPositiveInfinity(_topLeft) || Double.IsPositiveInfinity(_topRight) || Double.IsPositiveInfinity(_bottomLeft) || Double.IsPositiveInfinity(_bottomRight))
- {
- return (false);
- }
- }
-
- if (!allowNegativeInfinity)
- {
- if (Double.IsNegativeInfinity(_topLeft) || Double.IsNegativeInfinity(_topRight) || Double.IsNegativeInfinity(_bottomLeft) || Double.IsNegativeInfinity(_bottomRight))
- {
- return (false);
- }
- }
-
- return (true);
- }
-
- internal bool IsZero
- {
- get
- {
- return ( DoubleUtil.IsZero(_topLeft)
- && DoubleUtil.IsZero(_topRight)
- && DoubleUtil.IsZero(_bottomRight)
- && DoubleUtil.IsZero(_bottomLeft)
- );
- }
+ return double.IsFinite(_topLeft) && double.IsFinite(_topRight) && double.IsFinite(_bottomLeft) && double.IsFinite(_bottomRight);
}
#endregion Internal Methods Properties
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
index c765f42859a..e7b04de8425 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
@@ -77,7 +77,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if ((targetType == typeof(string)) || (targetType == typeof(object)))
{
// Check that value is a valid double.
- if ((double.IsNaN(percent)) || (double.IsInfinity(percent)))
+ if (!double.IsFinite(percent))
{
return DependencyProperty.UnsetValue;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs
index 4c0189b0aaa..f8fbeccdddd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs
@@ -519,13 +519,15 @@ internal Pen GetPen()
// Double verification helpers. Property system will verify type for us; we only need to verify the value.
internal static bool IsDoubleFiniteNonNegative(object o)
{
- double d = (double)o;
- return !(Double.IsInfinity(d) || double.IsNaN(d) || d < 0.0);
+ double value = (double)o;
+
+ return double.IsFinite(value) && value >= 0.0;
}
internal static bool IsDoubleFinite(object o)
{
- double d = (double)o;
- return !(Double.IsInfinity(d) || double.IsNaN(d));
+ double value = (double)o;
+
+ return double.IsFinite(value);
}
internal static bool IsDoubleFiniteOrNaN(object o)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/DoubleUtil.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/DoubleUtil.cs
index 4e92c39144e..401d26e0b19 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/DoubleUtil.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/DoubleUtil.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -35,91 +35,8 @@ public static bool AreClose(double value1, double value2)
}
double delta = value1 - value2;
- return (delta < Epsilon) && (delta > -Epsilon);
- }
-
- ///
- /// LessThan returns whether or not the first double is less than the second double.
- /// That is, whether or not the first is strictly less than *and* not within epsilon of
- /// the other number.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false.
- ///
- /// The first double to compare.
- /// The second double to compare.
- /// The result of the LessThan comparision.
- public static bool LessThan(double value1, double value2)
- {
- return (value1 < value2) && !AreClose(value1, value2);
- }
- ///
- /// GreaterThan returns whether or not the first double is greater than the second double.
- /// That is, whether or not the first is strictly greater than *and* not within epsilon of
- /// the other number.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false.
- ///
- /// The first double to compare.
- /// The second double to compare.
- /// The result of the GreaterThan comparision.
- public static bool GreaterThan(double value1, double value2)
- {
- return (value1 > value2) && !AreClose(value1, value2);
- }
-
- ///
- /// LessThanOrClose returns whether or not the first double is less than or close to
- /// the second double. That is, whether or not the first is strictly less than or within
- /// epsilon of the other number.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false.
- ///
- /// The first double to compare.
- /// The second double to compare.
- /// The result of the LessThanOrClose comparision.
- public static bool LessThanOrClose(double value1, double value2)
- {
- return (value1 < value2) || AreClose(value1, value2);
- }
-
- ///
- /// GreaterThanOrClose returns whether or not the first double is greater than or close to
- /// the second double. That is, whether or not the first is strictly greater than or within
- /// epsilon of the other number.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false.
- ///
- /// The first double to compare.
- /// The second double to compare.
- /// The result of the GreaterThanOrClose comparision.
- public static bool GreaterThanOrClose(double value1, double value2)
- {
- return (value1 > value2) || AreClose(value1, value2);
- }
-
- ///
- /// Test to see if a double is a finite number (is not NaN or Infinity).
- ///
- /// The value to test.
- /// Whether or not the value is a finite number.
- public static bool IsFinite(double value)
- {
- return !double.IsNaN(value) && !double.IsInfinity(value);
- }
-
- ///
- /// Test to see if a double a valid size value (is finite and > 0).
- ///
- /// The value to test.
- /// Whether or not the value is a valid size value.
- public static bool IsValidSize(double value)
- {
- return IsFinite(value) && GreaterThanOrClose(value, 0);
+ return delta is < Epsilon and > (-Epsilon);
}
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs
index a179ec754e4..a3f03729ee6 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -293,14 +293,9 @@ public static bool IsCornerRadiusValid(CornerRadius cornerRadius)
return true;
}
- public static bool IsDoubleFiniteAndNonNegative(double d)
+ public static bool IsDoubleFiniteAndNonNegative(double value)
{
- if (double.IsNaN(d) || double.IsInfinity(d) || d < 0)
- {
- return false;
- }
-
- return true;
+ return double.IsFinite(value) && value >= 0;
}
#endregion
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/ZoomComboBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/ZoomComboBox.cs
index 3f4a710dbea..5ffe9eb8c84 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/ZoomComboBox.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/ZoomComboBox.cs
@@ -457,7 +457,7 @@ private static void OnZoomChanged(DependencyObject d, DependencyPropertyChangedE
private static bool ZoomValueToString(double zoomValue, out string zoomString)
{
// Check that value is a valid double.
- if (!(double.IsNaN(zoomValue)) && !(double.IsInfinity(zoomValue)))
+ if (double.IsFinite(zoomValue))
{
try
{
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Utility.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Utility.cs
index 7608dd35b28..004a0c2562c 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Utility.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/Utility.cs
@@ -2070,7 +2070,7 @@ public static bool IsRenderVisible(Rect rect)
if (!rect.IsEmpty)
{
- result = IsValid(rect) && IsFinite(rect) && rect.Width > 0 && rect.Height > 0;
+ result = IsFinite(rect) && rect.Width > 0 && rect.Height > 0;
}
return result;
@@ -2095,23 +2095,18 @@ public static bool IsValidViewbox(Rect rect, bool hasStretch)
}
else
{
- return IsValid(rect) && IsFinite(rect) && rect.Width >= 0 && rect.Height >= 0;
+ return IsFinite(rect) && rect.Width >= 0 && rect.Height >= 0;
}
}
public static bool IsRenderVisible(Point point)
{
- return IsValid(point) && IsFinite(point);
- }
-
- public static bool IsRenderVisible(Size size)
- {
- return IsValid(size) && IsFinite(size) && size.Width > 0 && size.Height > 0;
+ return double.IsFinite(point.X) && double.IsFinite(point.Y);
}
public static bool IsRenderVisible(double value)
{
- return IsValid(value) && IsFinite(value);
+ return double.IsFinite(value);
}
public static bool IsRenderVisible(DrawingGroup drawing)
@@ -2147,22 +2142,6 @@ public static bool IsValid(double value)
return !double.IsNaN(value);
}
- public static bool IsValid(Point point)
- {
- return !double.IsNaN(point.X) && !double.IsNaN(point.Y);
- }
-
- ///
- /// Returns true if Size is valid.
- ///
- ///
- ///
- /// Empty size is treated as valid.
- public static bool IsValid(Size size)
- {
- return !double.IsNaN(size.Width) && !double.IsNaN(size.Height);
- }
-
///
/// Returns true if Rect is valid.
///
@@ -2193,27 +2172,12 @@ public static bool IsValid(Matrix matrix)
!double.IsNaN(matrix.OffsetY);
}
- public static bool IsFinite(double value)
- {
- return !double.IsInfinity(value);
- }
-
- public static bool IsFinite(Point point)
- {
- return !double.IsInfinity(point.X) && !double.IsInfinity(point.Y);
- }
-
- public static bool IsFinite(Size size)
- {
- return !double.IsInfinity(size.Width) && !double.IsInfinity(size.Height);
- }
-
+ ///
+ /// Determines whether the is finite (not NaN, not Infinity).
+ ///
public static bool IsFinite(Rect rect)
{
- return !double.IsInfinity(rect.X) &&
- !double.IsInfinity(rect.Y) &&
- !double.IsInfinity(rect.Width) &&
- !double.IsInfinity(rect.Height);
+ return double.IsFinite(rect.X) && double.IsFinite(rect.Y) && double.IsFinite(rect.Width) && double.IsFinite(rect.Height);
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
index b5bfbe971c6..0e4c3a142e9 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
@@ -1172,19 +1172,13 @@ PrintTicket printTicket
Size
ValidateDocumentSize(Size documentSize, PrintTicket printTicket)
{
- if (documentSize.Width == 0 ||
- documentSize.Height == 0 ||
- double.IsNaN(documentSize.Width) ||
- double.IsNaN(documentSize.Height) ||
- Double.IsPositiveInfinity(documentSize.Width) ||
- Double.IsPositiveInfinity(documentSize.Height) ||
- Double.IsNegativeInfinity(documentSize.Width) ||
- Double.IsNegativeInfinity(documentSize.Height)
- )
+ if (documentSize.Width == 0 || documentSize.Height == 0 ||
+ !double.IsFinite(documentSize.Width) ||
+ !double.IsFinite(documentSize.Height))
{
Size sz = new Size(0, 0);
- //if print ticket definied, use printTicket dimensions
+ // if print ticket defined, use printTicket dimensions
if (printTicket != null &&
printTicket.PageMediaSize != null &&
printTicket.PageMediaSize.Width.HasValue &&
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs
index e10b35699df..fd5fa9bfd0d 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -81,7 +81,7 @@ public double KeyTipHorizontalOffset
}
set
{
- if (double.IsInfinity(value) || double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentException(Microsoft.Windows.Controls.SR.InvalidKeyTipOffset);
}
@@ -100,7 +100,7 @@ public double KeyTipVerticalOffset
}
set
{
- if (double.IsInfinity(value) || double.IsNaN(value))
+ if (!double.IsFinite(value))
{
throw new ArgumentException(Microsoft.Windows.Controls.SR.InvalidKeyTipOffset);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/StarLayoutInfo.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/StarLayoutInfo.cs
index c429c498e90..cb33d3b06a8 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/StarLayoutInfo.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/StarLayoutInfo.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -102,9 +102,8 @@ internal static IComparer PotentialPerStarValueComparer
private static bool ValidateRequestedStarWeight(object value)
{
double starWeight = (double)value;
- return (!double.IsNaN(starWeight) &&
- !double.IsInfinity(starWeight) &&
- DoubleUtil.GreaterThanOrClose(starWeight, 0.0));
+
+ return double.IsFinite(starWeight) && DoubleUtil.GreaterThanOrClose(starWeight, 0.0);
}
private static void OnRequestedStarMinWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -116,9 +115,8 @@ private static void OnRequestedStarMinWidthChanged(DependencyObject d, Dependenc
private static bool ValidateRequestedStarMinWidth(object value)
{
double starMinWidth = (double)value;
- return (!double.IsNaN(starMinWidth) &&
- !double.IsInfinity(starMinWidth) &&
- DoubleUtil.GreaterThanOrClose(starMinWidth, 0.0));
+
+ return double.IsFinite(starMinWidth) && DoubleUtil.GreaterThanOrClose(starMinWidth, 0.0);
}
private static object OnCoerceRequestedStarMaxWidth(DependencyObject d, object baseValue)
@@ -190,4 +188,4 @@ public int Compare(StarLayoutInfo x, StarLayoutInfo y)
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/DoubleUtil.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/DoubleUtil.cs
index 8a3e290054f..e7530c1485b 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/DoubleUtil.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/DoubleUtil.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -13,138 +13,6 @@ internal static class DoubleUtil
// Const values come from sdk\inc\crt\float.h
private const double DBL_EPSILON = 2.2204460492503131e-016; /* smallest such that 1.0+DBL_EPSILON != 1.0 */
-#if false // unused
- ///
- /// AreClose - Returns whether or not two doubles are "close". That is, whether or
- /// not they are within epsilon of each other. Note that this epsilon is proportional
- /// to the numbers themselves to that AreClose survives scalar multiplication.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the AreClose comparision.
- ///
- /// The first double to compare.
- /// The second double to compare.
- public static bool AreClose(double value1, double value2)
- {
- //in case they are Infinities (then epsilon check does not work)
- if (value1 == value2) return true;
- // This computes (|value1-value2| / (|value1| + |value2| + 10.0)) < DBL_EPSILON
- double eps = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * DBL_EPSILON;
- double delta = value1 - value2;
- return (-eps < delta) && (eps > delta);
- }
-
- ///
- /// LessThan - Returns whether or not the first double is less than the second double.
- /// That is, whether or not the first is strictly less than *and* not within epsilon of
- /// the other number. Note that this epsilon is proportional to the numbers themselves
- /// to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the LessThan comparision.
- ///
- /// The first double to compare.
- /// The second double to compare.
- public static bool LessThan(double value1, double value2)
- {
- return (value1 < value2) && !AreClose(value1, value2);
- }
-
- ///
- /// GreaterThan - Returns whether or not the first double is greater than the second double.
- /// That is, whether or not the first is strictly greater than *and* not within epsilon of
- /// the other number. Note that this epsilon is proportional to the numbers themselves
- /// to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the GreaterThan comparision.
- ///
- /// The first double to compare.
- /// The second double to compare.
- public static bool GreaterThan(double value1, double value2)
- {
- return (value1 > value2) && !AreClose(value1, value2);
- }
-
- ///
- /// LessThanOrClose - Returns whether or not the first double is less than or close to
- /// the second double. That is, whether or not the first is strictly less than or within
- /// epsilon of the other number. Note that this epsilon is proportional to the numbers
- /// themselves to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the LessThanOrClose comparision.
- ///
- /// The first double to compare.
- /// The second double to compare.
- public static bool LessThanOrClose(double value1, double value2)
- {
- return (value1 < value2) || AreClose(value1, value2);
- }
-
- ///
- /// GreaterThanOrClose - Returns whether or not the first double is greater than or close to
- /// the second double. That is, whether or not the first is strictly greater than or within
- /// epsilon of the other number. Note that this epsilon is proportional to the numbers
- /// themselves to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the GreaterThanOrClose comparision.
- ///
- /// The first double to compare.
- /// The second double to compare.
- public static bool GreaterThanOrClose(double value1, double value2)
- {
- return (value1 > value2) || AreClose(value1, value2);
- }
-
- ///
- /// Verifies if the given value is a finite number.
- ///
- ///
- ///
- public static bool IsDoubleFinite(double d)
- {
- return !(double.IsInfinity(d) || double.IsNaN(d));
- }
-
-
- ///
- /// Verifies if the given value is a finite number or 0.
- ///
- ///
- ///
- public static bool IsDoubleFiniteNonZero(double d)
- {
- return IsDoubleFinite(d) && !IsZero(d);
- }
-#endif
-
///
/// Verifies if the given value is close to 0.
///
@@ -177,31 +45,5 @@ public static double Limit(double d, double min, double max)
return d;
}
-
-#if false // unused
- ///
- /// Converts a double to a float.
- ///
- /// the double value to convert
- ///
- public static float ConvertToFloat(double d)
- {
- float f = (float)d;
- if (!double.IsInfinity(d) && float.IsInfinity(f))
- {
- // The conversion exceeded the size of a float and the value became infinity.
- // Instead, set the value to the min/max for float.
- if (d > float.MaxValue)
- {
- f = float.MaxValue;
- }
- else if (d < float.MinValue)
- {
- f = float.MinValue;
- }
- }
- return f;
- }
-#endif
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaExpansionBehavior2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaExpansionBehavior2D.cs
index b6b4b4fae3c..dc77b948eb9 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaExpansionBehavior2D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaExpansionBehavior2D.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Windows.Input.Manipulations
@@ -309,7 +309,7 @@ private static string SubpropertyName(string paramName)
///
private static void CheckRadius(float value, string paramName)
{
- if (value < 1 || double.IsInfinity(value) || double.IsNaN(value))
+ if (value < 1 || !double.IsFinite(value))
{
throw Exceptions.IllegialInertiaRadius(paramName, value);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
index 36c1921d3e8..d2ef686b782 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -788,9 +788,7 @@ private bool ExtrapolateAndRaiseEvents(Int64 timestamp, bool forceCompleted)
double totalScale = this.initialScale;
if (this.expansion.ExtrapolationResult != ExtrapolationResult.Skip)
{
- Debug.Assert(this.expansion.InitialValue > 0 &&
- !double.IsInfinity(this.expansion.InitialValue) &&
- !double.IsNaN(this.expansion.InitialValue), "Invalid initial expansion value.");
+ Debug.Assert(expansion.InitialValue > 0 && double.IsFinite(expansion.InitialValue), "Invalid initial expansion value.");
totalScale *= extrapolatedExpansion.Value / this.expansion.InitialValue;
}
@@ -833,9 +831,7 @@ private bool ExtrapolateAndRaiseEvents(Int64 timestamp, bool forceCompleted)
double scaleDelta = 1;
if (this.expansion.ExtrapolationResult != ExtrapolationResult.Skip)
{
- Debug.Assert(this.expansion.InitialValue > 0 &&
- !double.IsInfinity(this.expansion.InitialValue) &&
- !double.IsNaN(this.expansion.InitialValue), "Invalid initial expansion value.");
+ Debug.Assert(expansion.InitialValue > 0 && double.IsFinite(expansion.InitialValue), "Invalid initial expansion value.");
totalScale *= extrapolatedExpansion.Value / this.expansion.InitialValue;
if (!DoubleUtil.IsZero(extrapolatedExpansion.Delta))
@@ -901,9 +897,9 @@ private bool ExtrapolateAndRaiseEvents(Int64 timestamp, bool forceCompleted)
private static double GetExtrapolatedValue(double initialValue, double initialVelocity, double deceleration, double timeDelta)
{
Debug.Assert(!double.IsNaN(initialVelocity) && !double.IsInfinity(initialValue));
- Debug.Assert(!double.IsNaN(initialVelocity) && !double.IsInfinity(initialVelocity));
- Debug.Assert(!double.IsNaN(deceleration) && !double.IsInfinity(deceleration));
- Debug.Assert(!double.IsNaN(timeDelta) && !double.IsInfinity(timeDelta) && timeDelta >= 0);
+ Debug.Assert(double.IsFinite(initialVelocity));
+ Debug.Assert(double.IsFinite(deceleration));
+ Debug.Assert(double.IsFinite(timeDelta) && timeDelta >= 0);
double result = initialValue + (initialVelocity - deceleration * timeDelta * 0.5) * timeDelta;
return result;
@@ -917,7 +913,7 @@ private static double GetExtrapolatedValue(double initialValue, double initialVe
///
private static ExtrapolatedValue GetExtrapolatedValueAndUpdateState(ExtrapolationState state, double timeDelta)
{
- Debug.Assert(!double.IsNaN(timeDelta) && !double.IsInfinity(timeDelta) && timeDelta >= 0);
+ Debug.Assert(double.IsFinite(timeDelta) && timeDelta >= 0);
if (state.ExtrapolationResult == ExtrapolationResult.Skip)
{
@@ -951,7 +947,7 @@ private static ExtrapolatedValue GetExtrapolatedValueAndUpdateState(Extrapolatio
resultAction = ExtrapolationResult.Stop;
}
}
- Debug.Assert(!double.IsNaN(resultValue) && !double.IsInfinity(resultValue), "Calculation error, value should be a finite number.");
+ Debug.Assert(double.IsFinite(resultValue), "Calculation error, value should be a finite number.");
ExtrapolatedValue value = new ExtrapolatedValue(resultValue,
resultValue - state.PreviousValue,
@@ -1056,7 +1052,7 @@ private static double ScaleValue(double value, double scale)
///
private static VectorD GetAbsoluteVector(double length, VectorD baseVector)
{
- Debug.Assert(!double.IsNaN(length) && length >= 0 && !double.IsInfinity(length));
+ Debug.Assert(double.IsFinite(length) && length >= 0);
Debug.Assert(!double.IsInfinity(baseVector.X));
Debug.Assert(!double.IsInfinity(baseVector.Y));
@@ -1259,7 +1255,7 @@ public float GetVelocity(long elapsedTimeSinceInitialTimestamp)
// convert to milliseconds
result = result * timestampTicksPerMillisecond;
- Debug.Assert(Validations.IsFinite((float)result));
+ Debug.Assert(float.IsFinite((float)result));
return (float)result;
}
@@ -1289,8 +1285,8 @@ public void AssertValid()
return;
}
- Debug.Assert(!double.IsNaN(this.InitialValue) && !double.IsInfinity(this.InitialValue));
- Debug.Assert(!double.IsNaN(this.InitialVelocity) && !double.IsInfinity(this.InitialVelocity));
+ Debug.Assert(double.IsFinite(InitialValue));
+ Debug.Assert(double.IsFinite(InitialVelocity));
Debug.Assert(!double.IsNaN(this.Offset)); // can be infinity
Debug.Assert(!double.IsNaN(this.AbsoluteDeceleration) && this.AbsoluteDeceleration >= 0 && !double.IsInfinity(this.InitialVelocity));
Debug.Assert(!double.IsNaN(this.Duration) && this.Duration >= 0); // can be infinity
@@ -1333,13 +1329,14 @@ private struct ExtrapolatedValue
public ExtrapolatedValue(double value, double delta, double total, ExtrapolationResult result)
{
- Debug.Assert(!double.IsNaN(value) && !double.IsInfinity(value));
- Debug.Assert(!double.IsNaN(delta) && !double.IsInfinity(delta));
- Debug.Assert(!double.IsNaN(total) && !double.IsInfinity(total));
- this.Value = value;
- this.Delta = delta;
- this.Total = total;
- this.ExtrapolationResult = result;
+ Debug.Assert(double.IsFinite(value));
+ Debug.Assert(double.IsFinite(delta));
+ Debug.Assert(double.IsFinite(total));
+
+ Value = value;
+ Delta = delta;
+ Total = total;
+ ExtrapolationResult = result;
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DCompletedEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DCompletedEventArgs.cs
index 5eac27fd488..9c3efdc89a3 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DCompletedEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DCompletedEventArgs.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -34,10 +34,11 @@ internal Manipulation2DCompletedEventArgs(
ManipulationVelocities2D velocities,
ManipulationDelta2D total)
{
- Debug.Assert(Validations.IsFinite(originX), "originX should be finite");
- Debug.Assert(Validations.IsFinite(originY), "originY should be finite");
+ Debug.Assert(float.IsFinite(originX), "originX should be finite");
+ Debug.Assert(float.IsFinite(originY), "originY should be finite");
Debug.Assert(velocities != null, "velocities should not be null");
Debug.Assert(total != null, "total should not be null");
+
this.originX = originX;
this.originY = originY;
this.velocities = velocities;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DDeltaEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DDeltaEventArgs.cs
index 47f78314589..57ccdccfae7 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DDeltaEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DDeltaEventArgs.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -37,11 +37,12 @@ internal Manipulation2DDeltaEventArgs(
ManipulationDelta2D delta,
ManipulationDelta2D cumulative)
{
- Debug.Assert(Validations.IsFinite(originX), "originX should be finite");
- Debug.Assert(Validations.IsFinite(originY), "originY should be finite");
+ Debug.Assert(float.IsFinite(originX), "originX should be finite");
+ Debug.Assert(float.IsFinite(originY), "originY should be finite");
Debug.Assert(velocities != null, "velocities should not be null");
Debug.Assert(delta != null, "delta should not be null");
Debug.Assert(cumulative != null, "cumulative should not be null");
+
this.originX = originX;
this.originY = originY;
this.velocities = velocities;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DStartedEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DStartedEventArgs.cs
index a8091d1fd7e..e599db321bf 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DStartedEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Manipulation2DStartedEventArgs.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -38,8 +38,9 @@ public class Manipulation2DStartedEventArgs: EventArgs
/// which are all invalid values.
internal Manipulation2DStartedEventArgs(float originX, float originY)
{
- Debug.Assert(Validations.IsFinite(originX));
- Debug.Assert(Validations.IsFinite(originY));
+ Debug.Assert(float.IsFinite(originX));
+ Debug.Assert(float.IsFinite(originY));
+
this.originX = originX;
this.originY = originY;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationDelta2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationDelta2D.cs
index b2395bb0421..12eecd3b618 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationDelta2D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationDelta2D.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
@@ -101,13 +101,14 @@ internal ManipulationDelta2D(
float expansionX,
float expansionY)
{
- Debug.Assert(Validations.IsFinite(translationX), "translationX should be finite");
- Debug.Assert(Validations.IsFinite(translationY), "translationY should be finite");
- Debug.Assert(Validations.IsFinite(rotation), "rotation should be finite");
+ Debug.Assert(float.IsFinite(translationX), "translationX should be finite");
+ Debug.Assert(float.IsFinite(translationY), "translationY should be finite");
+ Debug.Assert(float.IsFinite(rotation), "rotation should be finite");
Debug.Assert(Validations.IsFiniteNonNegative(scaleX), "scaleX should be finite and not negative");
Debug.Assert(Validations.IsFiniteNonNegative(scaleY), "scaleY should be finite and not negative");
- Debug.Assert(Validations.IsFinite(expansionX), "expansionX should be finite");
- Debug.Assert(Validations.IsFinite(expansionY), "expansionY should be finite");
+ Debug.Assert(float.IsFinite(expansionX), "expansionX should be finite");
+ Debug.Assert(float.IsFinite(expansionY), "expansionY should be finite");
+
this.translationX = translationX;
this.translationY = translationY;
this.rotation = rotation;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs
index 52665eb6ced..871cb9c15d5 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationSequence.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
@@ -272,7 +272,7 @@ private float GetSmoothScale()
result = this.cumulativeScale;
}
- Debug.Assert(!float.IsNaN(result) && !float.IsInfinity(result));
+ Debug.Assert(float.IsFinite(result));
return result;
}
@@ -1546,11 +1546,11 @@ private struct ManipulationState
public ManipulationState(in PointF position, float scale, float expansion, float orientation, Int64 timestamp)
{
- Debug.Assert(!float.IsNaN(position.X) && !float.IsNaN(position.Y));
- Debug.Assert(!float.IsInfinity(position.Y) && !float.IsInfinity(position.Y));
- Debug.Assert(!float.IsNaN(scale) && !float.IsInfinity(scale) && scale > 0);
- Debug.Assert(!float.IsNaN(expansion) && !float.IsInfinity(expansion));
- Debug.Assert(!float.IsNaN(orientation) && !float.IsInfinity(orientation));
+ Debug.Assert(float.IsFinite(position.X));
+ Debug.Assert(float.IsFinite(position.Y));
+ Debug.Assert(float.IsFinite(expansion));
+ Debug.Assert(float.IsFinite(orientation));
+ Debug.Assert(float.IsFinite(scale) && scale > 0);
Position = position;
Scale = scale;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationVelocities2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationVelocities2D.cs
index 736b5661ee1..09c9ef7a6ac 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationVelocities2D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationVelocities2D.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
@@ -82,10 +82,10 @@ internal ManipulationVelocities2D(
float angularVelocity,
float expansionVelocity)
{
- Debug.Assert(Validations.IsFinite(linearVelocityX));
- Debug.Assert(Validations.IsFinite(linearVelocityY));
- Debug.Assert(Validations.IsFinite(angularVelocity));
- Debug.Assert(Validations.IsFinite(expansionVelocity));
+ Debug.Assert(float.IsFinite(linearVelocityX));
+ Debug.Assert(float.IsFinite(linearVelocityY));
+ Debug.Assert(float.IsFinite(angularVelocity));
+ Debug.Assert(float.IsFinite(expansionVelocity));
this.linearVelocityX = new Lazy(linearVelocityX);
this.linearVelocityY = new Lazy(linearVelocityY);
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Validations.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Validations.cs
index 6e3e0fe94e6..98059b4d198 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Validations.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/Validations.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
@@ -10,16 +10,6 @@ namespace System.Windows.Input.Manipulations
///
internal static class Validations
{
- ///
- /// Gets whether the specified value is finite.
- ///
- ///
- ///
- public static bool IsFinite(float value)
- {
- return !float.IsNaN(value) && !float.IsInfinity(value);
- }
-
///
/// Throws unless the specified value is finite.
///
@@ -28,7 +18,8 @@ public static bool IsFinite(float value)
public static void CheckFinite(float value, string paramName)
{
Debug.Assert(paramName != null);
- if (!IsFinite(value))
+
+ if (!float.IsFinite(value))
{
throw Exceptions.ValueMustBeFinite(paramName, value);
}
@@ -52,6 +43,7 @@ public static bool IsFiniteOrNaN(float value)
public static void CheckFiniteOrNaN(float value, string paramName)
{
Debug.Assert(paramName != null);
+
if (!IsFiniteOrNaN(value))
{
throw Exceptions.ValueMustBeFiniteOrNaN(paramName, value);
@@ -65,7 +57,7 @@ public static void CheckFiniteOrNaN(float value, string paramName)
///
public static bool IsFiniteNonNegative(float value)
{
- return !float.IsInfinity(value) && !float.IsNaN(value) && (value >= 0);
+ return float.IsFinite(value) && value >= 0;
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
index fec14aefbbc..163810004b1 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
@@ -47,8 +47,7 @@ values[1] is not double ||
double height = (double)values[2];
// if an invalid height, return a null brush
- if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) ||
- height <= 0.0 || Double.IsInfinity(height) || Double.IsNaN(height) )
+ if (width <= 0.0 || !double.IsFinite(width) || height <= 0.0 || !double.IsFinite(height))
{
return null;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ScrollChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ScrollChrome.cs
index 392ad23cb9a..07ca1399128 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ScrollChrome.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero/Microsoft/Windows/Themes/ScrollChrome.cs
@@ -742,8 +742,7 @@ private void DrawArrow(DrawingContext dc, Brush brush, Rect bounds)
double x = (bounds.X + (bounds.Width * 0.5)) / widthScale - (glyphWidth * 0.5);
double y = (bounds.Y + (bounds.Height * 0.5)) / heightScale - (glyphHeight * 0.5);
- if (double.IsNaN(widthScale) || double.IsInfinity(widthScale) || double.IsNaN(heightScale) || double.IsInfinity(heightScale) ||
- double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(y) || double.IsInfinity(y))
+ if (!double.IsFinite(widthScale) || !double.IsFinite(heightScale) || !double.IsFinite(x) || !double.IsFinite(y))
{
return;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
index fec14aefbbc..163810004b1 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ProgressBarHighlightConverter.cs
@@ -47,8 +47,7 @@ values[1] is not double ||
double height = (double)values[2];
// if an invalid height, return a null brush
- if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) ||
- height <= 0.0 || Double.IsInfinity(height) || Double.IsNaN(height) )
+ if (width <= 0.0 || !double.IsFinite(width) || height <= 0.0 || !double.IsFinite(height))
{
return null;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ScrollChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ScrollChrome.cs
index 392ad23cb9a..07ca1399128 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ScrollChrome.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Aero2/Microsoft/Windows/Themes/ScrollChrome.cs
@@ -742,8 +742,7 @@ private void DrawArrow(DrawingContext dc, Brush brush, Rect bounds)
double x = (bounds.X + (bounds.Width * 0.5)) / widthScale - (glyphWidth * 0.5);
double y = (bounds.Y + (bounds.Height * 0.5)) / heightScale - (glyphHeight * 0.5);
- if (double.IsNaN(widthScale) || double.IsInfinity(widthScale) || double.IsNaN(heightScale) || double.IsInfinity(heightScale) ||
- double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(y) || double.IsInfinity(y))
+ if (!double.IsFinite(widthScale) || !double.IsFinite(heightScale) || !double.IsFinite(x) || !double.IsFinite(y))
{
return;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ScrollChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ScrollChrome.cs
index bf0ee90d15a..2217c412942 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ScrollChrome.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Luna/Microsoft/Windows/Themes/ScrollChrome.cs
@@ -594,8 +594,7 @@ private void DrawArrow(DrawingContext dc, Brush brush, Rect bounds, ScrollGlyph
double x = (bounds.X + (bounds.Width * 0.5)) / widthScale - (glyphWidth * 0.5);
double y = (bounds.Y + (bounds.Height * 0.5)) / heightScale - (glyphHeight * 0.5);
- if (double.IsNaN(widthScale) || double.IsInfinity(widthScale) || double.IsNaN(heightScale) || double.IsInfinity(heightScale) ||
- double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(y) || double.IsInfinity(y))
+ if (!double.IsFinite(widthScale) || !double.IsFinite(heightScale) || !double.IsFinite(x) || !double.IsFinite(y))
{
return;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ScrollChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ScrollChrome.cs
index a999ee14c8a..23e151c9f48 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ScrollChrome.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Royale/Microsoft/Windows/Themes/ScrollChrome.cs
@@ -554,8 +554,7 @@ private void DrawArrow(DrawingContext dc, Brush brush, Rect bounds, ScrollGlyph
double x = (bounds.X + (bounds.Width * 0.5)) / widthScale - (glyphWidth * 0.5);
double y = (bounds.Y + (bounds.Height * 0.5)) / heightScale - (glyphHeight * 0.5);
- if (double.IsNaN(widthScale) || double.IsInfinity(widthScale) || double.IsNaN(heightScale) || double.IsInfinity(heightScale) ||
- double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(y) || double.IsInfinity(y))
+ if (!double.IsFinite(widthScale) || !double.IsFinite(heightScale) || !double.IsFinite(x) || !double.IsFinite(y))
{
return;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/ProgressBarBrushConverter.cs b/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/ProgressBarBrushConverter.cs
index 2e6efa80c80..9d00d623acb 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/ProgressBarBrushConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/ProgressBarBrushConverter.cs
@@ -51,13 +51,11 @@ values[3] is not double ||
double trackWidth = (double)values[4];
// if an invalid height, return a null brush
- if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) ||
- height <= 0.0 || Double.IsInfinity(height) || Double.IsNaN(height) )
+ if (width <= 0.0 || !double.IsFinite(width) || height <= 0.0 || !double.IsFinite(height))
{
return null;
}
-
DrawingBrush newBrush = new DrawingBrush();
// Set the viewport and viewbox to the size of the progress region
diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/SystemDropShadowChrome.cs b/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/SystemDropShadowChrome.cs
index 5b3c2445a62..a7c47c32c49 100644
--- a/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/SystemDropShadowChrome.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Themes/Shared/Microsoft/Windows/Themes/SystemDropShadowChrome.cs
@@ -65,8 +65,7 @@ private static bool IsCornerRadiusValid(object value)
{
CornerRadius cr = (CornerRadius)value;
return !(cr.TopLeft < 0.0 || cr.TopRight < 0.0 || cr.BottomLeft < 0.0 || cr.BottomRight < 0.0 ||
- double.IsNaN(cr.TopLeft) || double.IsNaN(cr.TopRight) || double.IsNaN(cr.BottomLeft) || double.IsNaN(cr.BottomRight) ||
- double.IsInfinity(cr.TopLeft) || double.IsInfinity(cr.TopRight) || double.IsInfinity(cr.BottomLeft) || double.IsInfinity(cr.BottomRight));
+ !double.IsFinite(cr.TopLeft) || !double.IsFinite(cr.TopRight) || !double.IsFinite(cr.BottomLeft) || !double.IsFinite(cr.BottomRight));
}
///