namespace AntdWpf.Utils { using System.Windows; public static class CornerRadiusUtil { /// /// 验证角半径是否只包含有效值 /// 有效性检查集作为参数传递。 /// /// CornerRadius value /// allows negative values /// allows Double.NaN /// allows Double.PositiveInfinity /// allows Double.NegativeInfinity /// Whether or not the CornerRadius complies to the range specified public static bool IsValid(CornerRadius corner, bool allowNegative, bool allowNaN, bool allowPositiveInfinity, bool allowNegativeInfinity) { if (!allowNegative) { if (corner.TopLeft < 0d || corner.TopRight < 0d || corner.BottomLeft < 0d || corner.BottomRight < 0d) { return false; } } if (!allowNaN) { if (DoubleUtil.IsNaN(corner.TopLeft) || DoubleUtil.IsNaN(corner.TopRight) || DoubleUtil.IsNaN(corner.BottomLeft) || DoubleUtil.IsNaN(corner.BottomRight)) { return false; } } if (!allowPositiveInfinity) { if (double.IsPositiveInfinity(corner.TopLeft) || double.IsPositiveInfinity(corner.TopRight) || double.IsPositiveInfinity(corner.BottomLeft) || double.IsPositiveInfinity(corner.BottomRight)) { return false; } } if (!allowNegativeInfinity) { if (double.IsNegativeInfinity(corner.TopLeft) || double.IsNegativeInfinity(corner.TopRight) || double.IsNegativeInfinity(corner.BottomLeft) || double.IsNegativeInfinity(corner.BottomRight)) { return false; } } return true; } /// /// Verifies if the CornerRadius contains only zero values /// /// CornerRadius /// Size public static bool IsZero(CornerRadius corner) { return DoubleUtil.IsZero(corner.TopLeft) && DoubleUtil.IsZero(corner.TopRight) && DoubleUtil.IsZero(corner.BottomRight) && DoubleUtil.IsZero(corner.BottomLeft); } /// /// Verifies if the CornerRadius contains same values /// /// CornerRadius /// true if yes, otherwise false public static bool IsUniform(CornerRadius corner) { var topLeft = corner.TopLeft; return DoubleUtil.AreClose(topLeft, corner.TopRight) && DoubleUtil.AreClose(topLeft, corner.BottomRight) && DoubleUtil.AreClose(topLeft, corner.BottomLeft); } } }