AdventOfCode/AdventOfCode.Core/Shared/Grid/Point.cs
2023-12-17 22:24:16 +01:00

38 lines
1.1 KiB
C#

namespace AdventOfCode.Core.Shared.Grid
{
public class Point(long X, long Y, char Value = ' ') : IEquatable<Point>
{
public long X { get; set; } = X;
public long Y { get; set; } = Y;
public char Value { get; set; } = Value;
public Point() : this(-1, -1) { }
public Point(Point point) : this(point.X, point.Y, point.Value) { }
public long GetManhattanDistance(Point other) =>
Math.Abs(X - other.X) + Math.Abs(Y - other.Y);
public bool Intersect(Point other) =>
other != null
&& this.X == other.X
&& this.Y == other.Y;
public override string ToString() =>
$"[{Y},{X}] {Value}";
public override bool Equals(object? obj) =>
Equals(obj as Point);
public bool Equals(Point? other) =>
other != null
&& this.X == other.X
&& this.Y == other.Y
&& this.Value == other.Value;
public override int GetHashCode() =>
this.X.GetHashCode() ^ this.Y.GetHashCode() ^ this.Value.GetHashCode();
}
}