36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
namespace AdventOfCode.Core.Shared.Grid
|
|
{
|
|
internal static class IntersectHelpers
|
|
{
|
|
public static bool Intersect(Point one, Point two)
|
|
{
|
|
if (one == null || two == null) return false;
|
|
|
|
return one.X == two.X && one.Y == two.Y;
|
|
}
|
|
|
|
public static bool Intersect(Line line, Point point)
|
|
{
|
|
if (line == null || point == null) return false;
|
|
|
|
if (point.Y != line.Start.Y) return false;
|
|
|
|
return point.X >= line.Start.X && point.X <= line.End.X;
|
|
}
|
|
|
|
public static bool Intersect(Line one, Line two)
|
|
{
|
|
if (one == null || two == null) return false;
|
|
|
|
if (one.Start.Y != two.Start.Y) return false;
|
|
|
|
// sort the lines so testing is easier
|
|
(Line first, Line second) = one.Start.X <=two.Start.X ? (one, two) : (two, one);
|
|
|
|
return Intersect(first, second.Start) // is the start point of the other line in this line
|
|
|| Intersect(first, second.End) // is the end point of the other line in this line
|
|
|| (first.Start.X <= second.Start.X && first.End.X >= second.End.X); // is this line fully within the other line
|
|
}
|
|
}
|
|
}
|