mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Equality methods
This commit is contained in:
parent
23a8e49efb
commit
2686cda333
9 changed files with 47 additions and 91 deletions
|
|
@ -1,47 +1,27 @@
|
|||
namespace MapControl
|
||||
using System;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Replaces Windows.Foundation.Point for double floating point precision.
|
||||
/// </summary>
|
||||
public readonly struct Point
|
||||
public readonly struct Point(double x, double y) : IEquatable<Point>
|
||||
{
|
||||
public Point(double x, double y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
public double X => x;
|
||||
public double Y => y;
|
||||
|
||||
public double X { get; }
|
||||
public double Y { get; }
|
||||
public static implicit operator Windows.Foundation.Point(Point p) => new(p.X, p.Y);
|
||||
|
||||
public static implicit operator Windows.Foundation.Point(Point p)
|
||||
{
|
||||
return new Windows.Foundation.Point(p.X, p.Y);
|
||||
}
|
||||
public static implicit operator Point(Windows.Foundation.Point p) => new(p.X, p.Y);
|
||||
|
||||
public static implicit operator Point(Windows.Foundation.Point p)
|
||||
{
|
||||
return new Point(p.X, p.Y);
|
||||
}
|
||||
public static bool operator ==(Point p1, Point p2) => p1.Equals(p2);
|
||||
|
||||
public static bool operator ==(Point p1, Point p2)
|
||||
{
|
||||
return p1.X == p2.X && p1.Y == p2.Y;
|
||||
}
|
||||
public static bool operator !=(Point p1, Point p2) => !p1.Equals(p2);
|
||||
|
||||
public static bool operator !=(Point p1, Point p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
public bool Equals(Point p) => X == p.X && Y == p.Y;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is Point p && this == p;
|
||||
}
|
||||
public override bool Equals(object obj) => obj is Point p && Equals(p);
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return X.GetHashCode() ^ Y.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue