Exemplo n.º 1
0
        public void IsNeighborTest(
            [Values] HexagonalGridType type,
            [Values(-13, -8, 0, 15, 22)] int offsetX,
            [Values(-13, -8, 0, 15, 22)] int offsetY,
            [Values(-1, 0, 1, 2, 3, 4, 5, 6)] int neighborIndex)
        {
            var grid   = new HexagonalGrid(type, InscribedRadius);
            var offset = new Offset(offsetX, offsetY);
            var axial  = grid.ToAxial(offset);
            var cubic  = grid.ToCubic(offset);

            Assert.IsTrue(cubic.IsValid(), $"Invalid cubic coordinate: {cubic.X}-{cubic.Y}-{cubic.Z}");

            var oNeighbor = grid.GetNeighbor(offset, neighborIndex);
            var aNeighbor = grid.GetNeighbor(axial, neighborIndex);
            var cNeighbor = grid.GetNeighbor(cubic, neighborIndex);

            Assert.IsTrue(cNeighbor.IsValid(), $"Invalid cubic coordinate: {cNeighbor.X}-{cNeighbor.Y}-{cNeighbor.Z}");
            Assert.IsTrue(grid.IsNeighbors(offset, oNeighbor), $"Neighbor1={offset}; Neighbor2={oNeighbor}; Index={neighborIndex};");
            Assert.IsTrue(grid.IsNeighbors(axial, aNeighbor), $"Neighbor1={axial}; Neighbor2={aNeighbor}; Index={neighborIndex};");
            Assert.IsTrue(grid.IsNeighbors(cubic, cNeighbor), $"Neighbor1={cubic}; Neighbor2={cNeighbor}; Index={neighborIndex};");
        }
Exemplo n.º 2
0
        public void NeighborsOrderTest(
            [Values] HexagonalGridType type,
            [Values(-13, -8, 0, 15, 22)] int offsetX,
            [Values(-13, -8, 0, 15, 22)] int offsetY,
            [Values(-1, 0, 1, 2, 3, 4, 5, 6)] int neighborIndex)
        {
            var grid   = new HexagonalGrid(type, InscribedRadius);
            var offset = new Offset(offsetX, offsetY);
            var axial  = grid.ToAxial(offset);
            var cubic  = grid.ToCubic(offset);

            var oNeighbor = grid.GetNeighbor(offset, neighborIndex);
            var aNeighbor = grid.GetNeighbor(axial, neighborIndex);
            var cNeighbor = grid.GetNeighbor(cubic, neighborIndex);

            Assert.IsTrue(cNeighbor.IsValid(), $"Invalid cubic coordinate: {cNeighbor.X}-{cNeighbor.Y}-{cNeighbor.Z}");

            var fromAxial = grid.ToOffset(aNeighbor);
            var fromCubic = grid.ToOffset(cNeighbor);

            Assert.AreEqual(oNeighbor, fromAxial, $"Center=({offset} - {axial}); Current=({oNeighbor} - {aNeighbor}); Index={neighborIndex};");
            Assert.AreEqual(oNeighbor, fromCubic, $"Center=({offset} - {cubic}); Current=({oNeighbor} - {cNeighbor}); Index={neighborIndex};");
        }