Equality methods

This commit is contained in:
ClemensFischer 2026-01-09 23:43:39 +01:00
parent 23a8e49efb
commit 2686cda333
9 changed files with 47 additions and 91 deletions

View file

@ -5,7 +5,7 @@ namespace MapControl
/// <summary>
/// Replaces Windows.Foundation.Rect for double floating point precision.
/// </summary>
public readonly struct Rect
public readonly struct Rect : IEquatable<Rect>
{
public Rect(double x, double y, double width, double height)
{
@ -28,19 +28,20 @@ namespace MapControl
public double Width { get; }
public double Height { get; }
public bool Contains(Point p)
{
return p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height;
}
public static implicit operator Windows.Foundation.Rect(Rect r) => new(r.X, r.Y, r.Width, r.Height);
public static implicit operator Windows.Foundation.Rect(Rect r)
{
return new Windows.Foundation.Rect(r.X, r.Y, r.Width, r.Height);
}
public static implicit operator Rect(Windows.Foundation.Rect r) => new(r.X, r.Y, r.Width, r.Height);
public static implicit operator Rect(Windows.Foundation.Rect r)
{
return new Rect(r.X, r.Y, r.Width, r.Height);
}
public static bool operator ==(Rect r1, Rect r2) => r1.Equals(r2);
public static bool operator !=(Rect r1, Rect r2) => !r1.Equals(r2);
public bool Equals(Rect r) => X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
public override bool Equals(object obj) => obj is Rect r && Equals(r);
public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode();
public bool Contains(Point p) => p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height;
}
}