AdventOfCode/AdventOfCode.Core/Shared/Grid/Line.cs
2023-12-10 14:42:35 +01:00

31 lines
1.1 KiB
C#

using static System.Collections.Specialized.BitVector32;
namespace AdventOfCode.Core.Shared.Grid
{
/// <summary>
/// A horizontal line based on the Start Y value.
/// </summary>
/// <param name="Start"></param>
/// <param name="End"></param>
public class Line(Point start, Point end)
{
public Point Start { get; set; } = start;
public Point End { get; set; } = end;
public long Length => End.X - Start.X + 1;
public string Value { get; set; } = string.Empty;
public Line(long X, long Y, long length, string value = "") : this (new Point(X, Y), length, value) { }
public Line(Point start, long length, string value = "") : this(start, length) => Value = value;
public Line(Point start, long length) : this(start, new Point (start.X + length - 1, start.Y)) { }
public bool Intersect(Point point) => IntersectHelpers.Intersect(this, point);
public bool Intersect(Line line) => IntersectHelpers.Intersect(this, line);
public override string ToString()
{
return $"[{Start.Y},{Start.X}] {Value}";
}
}
}