AdventOfCode/AdventOfCode.Core/Shared/Grid/Point.cs
Rob Stoffelen 22a31d0b29 .
2023-12-19 08:45:27 +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();
}
}