2020-02-21 02:07:59 +00:00
|
|
|
|
using MoonTools.Structs;
|
2019-12-09 03:46:08 +00:00
|
|
|
|
|
2020-02-21 02:07:59 +00:00
|
|
|
|
namespace MoonTools.Bonk
|
2019-12-09 03:46:08 +00:00
|
|
|
|
{
|
|
|
|
|
internal static class RectanglePolygonComparison
|
|
|
|
|
{
|
|
|
|
|
public static bool Equals(Polygon polygon, Rectangle rectangle)
|
|
|
|
|
{
|
2020-01-02 04:01:05 +00:00
|
|
|
|
if (polygon.VertexCount != 4) { return false; }
|
2019-12-09 03:46:08 +00:00
|
|
|
|
|
2020-01-02 04:01:05 +00:00
|
|
|
|
int? minIndex = null;
|
|
|
|
|
for (var i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (polygon.Vertices[i] == rectangle.Min) { minIndex = i; break; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!minIndex.HasValue) { return false; }
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
polygon.Vertices[(minIndex.Value + 1) % 4] == rectangle.TopRight &&
|
|
|
|
|
polygon.Vertices[(minIndex.Value + 2) % 4] == rectangle.Max &&
|
|
|
|
|
polygon.Vertices[(minIndex.Value + 3) % 4] == rectangle.BottomLeft;
|
2019-12-09 03:46:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|