AdventOfCode/AdventOfCode.Core/Shared/Grid/Point.cs

52 lines
1.3 KiB
C#

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