|
|
|
@ -8,7 +8,10 @@ using Avalonia.Utilities; |
|
|
|
|
|
|
|
namespace Avalonia |
|
|
|
{ |
|
|
|
public struct CornerRadius |
|
|
|
/// <summary>
|
|
|
|
/// Represents the radii of a rectangle's corners.
|
|
|
|
/// </summary>
|
|
|
|
public readonly struct CornerRadius : IEquatable<CornerRadius> |
|
|
|
{ |
|
|
|
static CornerRadius() |
|
|
|
{ |
|
|
|
@ -33,20 +36,60 @@ namespace Avalonia |
|
|
|
BottomLeft = bottomLeft; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Radius of the top left corner.
|
|
|
|
/// </summary>
|
|
|
|
public double TopLeft { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Radius of the top right corner.
|
|
|
|
/// </summary>
|
|
|
|
public double TopRight { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Radius of the bottom right corner.
|
|
|
|
/// </summary>
|
|
|
|
public double BottomRight { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Radius of the bottom left corner.
|
|
|
|
/// </summary>
|
|
|
|
public double BottomLeft { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether all corner radii are set to 0.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsEmpty => TopLeft.Equals(0) && IsUniform; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether all corner radii are equal.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsUniform => TopLeft.Equals(TopRight) && BottomLeft.Equals(BottomRight) && TopRight.Equals(BottomRight); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a boolean indicating whether the corner radius is equal to the other given corner radius.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The other corner radius to test equality against.</param>
|
|
|
|
/// <returns>True if this corner radius is equal to other; False otherwise.</returns>
|
|
|
|
public bool Equals(CornerRadius other) |
|
|
|
{ |
|
|
|
// ReSharper disable CompareOfFloatsByEqualityOperator
|
|
|
|
return TopLeft == other.TopLeft && |
|
|
|
|
|
|
|
TopRight == other.TopRight && |
|
|
|
BottomRight == other.BottomRight && |
|
|
|
BottomLeft == other.BottomLeft; |
|
|
|
// ReSharper restore CompareOfFloatsByEqualityOperator
|
|
|
|
} |
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
{ |
|
|
|
if (obj is CornerRadius) |
|
|
|
if (!(obj is CornerRadius)) |
|
|
|
{ |
|
|
|
return this == (CornerRadius)obj; |
|
|
|
return false; |
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
return Equals((CornerRadius)obj); |
|
|
|
} |
|
|
|
|
|
|
|
public override int GetHashCode() |
|
|
|
@ -61,7 +104,9 @@ namespace Avalonia |
|
|
|
|
|
|
|
public static CornerRadius Parse(string s) |
|
|
|
{ |
|
|
|
using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Thickness")) |
|
|
|
const string exceptionMessage = "Invalid CornerRadius."; |
|
|
|
|
|
|
|
using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage)) |
|
|
|
{ |
|
|
|
if (tokenizer.TryReadDouble(out var a)) |
|
|
|
{ |
|
|
|
@ -78,21 +123,18 @@ namespace Avalonia |
|
|
|
return new CornerRadius(a); |
|
|
|
} |
|
|
|
|
|
|
|
throw new FormatException("Invalid CornerRadius."); |
|
|
|
throw new FormatException(exceptionMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static bool operator ==(CornerRadius cr1, CornerRadius cr2) |
|
|
|
public static bool operator ==(CornerRadius left, CornerRadius right) |
|
|
|
{ |
|
|
|
return cr1.TopLeft.Equals(cr2.TopLeft) |
|
|
|
&& cr1.TopRight.Equals(cr2.TopRight) |
|
|
|
&& cr1.BottomRight.Equals(cr2.BottomRight) |
|
|
|
&& cr1.BottomLeft.Equals(cr2.BottomLeft); |
|
|
|
return left.Equals(right); |
|
|
|
} |
|
|
|
|
|
|
|
public static bool operator !=(CornerRadius cr1, CornerRadius cr2) |
|
|
|
public static bool operator !=(CornerRadius left, CornerRadius right) |
|
|
|
{ |
|
|
|
return !(cr1 == cr2); |
|
|
|
return !(left == right); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|