public void GetPolygons_PlusShape() { var polygon = new GridPolygonBuilder() .AddPoint(0, 2) .AddPoint(0, 4) .AddPoint(2, 4) .AddPoint(2, 6) .AddPoint(4, 6) .AddPoint(4, 4) .AddPoint(6, 4) .AddPoint(6, 2) .AddPoint(4, 2) .AddPoint(4, 0) .AddPoint(2, 0) .AddPoint(2, 2) .Build(); var partitions = partitioner.GetPartitions(polygon); var expected = new List <List <GridRectangle> >() { new List <GridRectangle>() { new GridRectangle(new IntVector2(2, 0), new IntVector2(4, 2)), new GridRectangle(new IntVector2(0, 2), new IntVector2(6, 4)), new GridRectangle(new IntVector2(2, 4), new IntVector2(4, 6)), }, new List <GridRectangle>() { new GridRectangle(new IntVector2(0, 2), new IntVector2(2, 4)), new GridRectangle(new IntVector2(2, 0), new IntVector2(4, 6)), new GridRectangle(new IntVector2(4, 2), new IntVector2(6, 4)), } }; var matched = false; foreach (var rectangles in expected) { foreach (var r in rectangles) { if (!partitions.Contains(r)) { break; } } matched = true; } Assert.AreEqual(expected[0].Count, partitions.Count); Assert.AreEqual(true, matched); foreach (var p in polygon.GetAllRotations().Select(x => utils.NormalizePolygon(x))) { var rotated = partitioner.GetPartitions(p); Assert.AreEqual(expected[0].Count, rotated.Count); } }
public void NormalizePolygon_Polygon_ReturnsNormalizedPolygon() { var polygon = new PolygonGrid2DBuilder() .AddPoint(0, 5) .AddPoint(5, 5) .AddPoint(5, 0) .AddPoint(2, 0) .AddPoint(2, 3) .AddPoint(0, 3) .Build(); var normalized = utils.NormalizePolygon(polygon); var squarePoints = normalized.GetPoints(); var expectedPoints = new List <Vector2Int>() { new Vector2Int(0, 3), new Vector2Int(0, 5), new Vector2Int(5, 5), new Vector2Int(5, 0), new Vector2Int(2, 0), new Vector2Int(2, 3), }; Assert.IsTrue(expectedPoints.SequenceEqual(squarePoints)); }