47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using static System.Collections.Specialized.BitVector32;
|
|
|
|
namespace AdventOfCode.Core.Shared.Grid
|
|
{
|
|
public class Rectangle (Point pointOne, Point pointTwo)
|
|
{
|
|
public Point PointOne { get; set; } = pointOne;
|
|
public Point PointTwo { get; set; } = pointTwo;
|
|
|
|
public string Value { get; set; } = string.Empty;
|
|
|
|
public Rectangle (Point pointOne, Point pointTwo, string value) : this (pointOne, pointTwo) => Value = value;
|
|
|
|
public bool Intersect(Point point)
|
|
{
|
|
if (point == null) return false;
|
|
|
|
return point.X >= PointOne.X && point.X <= PointTwo.X
|
|
&& point.Y >= PointOne.Y && point.Y <= PointTwo.Y;
|
|
}
|
|
|
|
public bool Intersect(Line line)
|
|
{
|
|
if (line == null) return false;
|
|
return Intersect(line.Start)
|
|
|| Intersect(line.End)
|
|
|| ( line.Start.X < PointOne.X
|
|
&& line.End.X > PointTwo.X
|
|
&& line.Start.Y < PointOne.Y
|
|
&& line.End.Y > PointTwo.Y);
|
|
}
|
|
|
|
//public bool Intersect(Rectangle rectangle)
|
|
//{
|
|
// if (point == null) return false;
|
|
// //if (point.Y != Start.Y) return false;
|
|
// //return point.X >= Start.X && point.X <= End.X;
|
|
// return false;
|
|
//}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"[{PointOne.Y},{PointOne.X}] {Value}";
|
|
}
|
|
}
|
|
}
|