diff --git a/src/Uno.Foundation/Point.cs b/src/Uno.Foundation/Point.cs index cfef40dc1583..0e357d6eac42 100644 --- a/src/Uno.Foundation/Point.cs +++ b/src/Uno.Foundation/Point.cs @@ -25,44 +25,36 @@ public Point(double x, double y) public double X { get; set; } public double Y { get; set; } - public override string ToString() - { - return "[{0}, {1}]".InvariantCultureFormat(X, Y); - } - - internal string ToDebugString() - => FormattableString.Invariant($"{X:F2},{Y:F2}"); - internal Point WithX(double x) => new Point(x, Y); internal Point WithY(double y) => new Point(X, y); - internal Point GetOpposite() => new Point(-X, -Y); + public override int GetHashCode() + => X.GetHashCode() ^ Y.GetHashCode(); + + public override bool Equals(object obj) + => obj is Point other && Equals(this, other); + + public bool Equals(Point value) // Even if not in public doc, this is public on UWP + => Equals(this, value); + + private static bool Equals(Point left, Point right) + => left.X == right.X && left.Y == right.Y; public static bool operator ==(Point left, Point right) - { - return left.Equals(right); - } + => Equals(left, right); public static bool operator !=(Point left, Point right) - { - return !left.Equals(right); - } + => !Equals(left, right); public static Point operator +(Point p1, Point p2) - { - return new Point(p1.X + p2.X, p1.Y + p2.Y); - } + => new Point(p1.X + p2.X, p1.Y + p2.Y); public static Point operator -(Point p1, Point p2) - { - return new Point(p1.X - p2.X, p1.Y - p2.Y); - } + => new Point(p1.X - p2.X, p1.Y - p2.Y); public static Point operator -(Point a) - { - return new Point(-a.X, -a.Y); - } + => new Point(-a.X, -a.Y); public static implicit operator Point(string point) { @@ -83,19 +75,11 @@ public static implicit operator Point(string point) } } - public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode(); - - public override bool Equals(object obj) - { - if (obj is Point) - { - var point = (Point)obj; - - return X == point.X && Y == point.Y; - } + public override string ToString() + => "[{0}, {1}]".InvariantCultureFormat(X, Y); - return false; - } + internal string ToDebugString() + => FormattableString.Invariant($"{X:F2},{Y:F2}"); private string DebugDisplay => $"{X:f1},{Y:f1}"; }