38 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|