using static System.Collections.Specialized.BitVector32; namespace AdventOfCode.Core.Shared.Grid { /// /// A horizontal line based on the Start Y value. /// /// /// public class Line(Point start, Point end) { public Point Start { get; set; } = start; public Point End { get; set; } = end; public string Value { get; set; } = string.Empty; public Line(Point start, long length) : this(start, new Point (start.X + length - 1, start.Y)) { } public Line(Point start, long length, string value) : this(start, length) => Value = value; /// /// This intersect assumes that the line horizontal. /// Vertical may need to be added later /// /// The point search in this line. /// public bool Intersect(Point point) { if (point == null) return false; if (point.Y != Start.Y) return false; return point.X >= Start.X && point.X <= End.X; } /// /// This intersect assumes that the line horizontal. /// Vertical may need to be added later /// /// The line to seach in this line. /// public bool Intersect(Line line) { if (line == null) return false; if (line.Start.Y != Start.Y) return false; return Intersect(line.Start) // is the start point of the other line in this line || Intersect(line.End) // is the end point of the other line in this line || (line.Start.X <= Start.X && line.End.X >= End.X); // is this line fully within the other line } public override string ToString() { return $"[{Start.Y},{Start.X}] {Value}"; } } }