MoonTools.Bonk/Bonk/Shapes/RectanglePolygonComparison.cs

26 lines
783 B
C#
Raw Normal View History

2020-02-21 02:07:59 +00:00
using MoonTools.Structs;
2020-02-21 02:07:59 +00:00
namespace MoonTools.Bonk
{
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; }
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;
}
}
}