示例#1
0
        public void AxialToPoint()
        {
            HexGrid grid      = new HexGrid(2f);
            float   hexRadius = grid.HexRadius;
            Vec2D   point     = grid.AxialToPoint(new AxialHexCoord(10, 10));

            float xExpected = hexRadius * SQRT_3 * (10 + 10 / 2);
            float yExpected = hexRadius * (3f / 2f) * 10;

            Assert.That(point.x, Is.InRange <float>(xExpected - EPSILON, xExpected + EPSILON));
            Assert.That(point.y, Is.InRange <float>(yExpected - EPSILON, yExpected + EPSILON));
        }
示例#2
0
        public void PointToDirectionInHex()
        {
            HexGrid grid   = new HexGrid(2f);
            Vec2D   hexPos = grid.AxialToPoint(new AxialHexCoord(10, 10));
            float   offset = 0.5f * grid.HexRadius;

            Vec2D[] points = new Vec2D[12] {
                new Vec2D(hexPos.x + offset, hexPos.y + 0f * offset - 0.01f),                              // 0a
                new Vec2D(hexPos.x + offset, hexPos.y + 0f * offset + 0.01f),                              // 0b
                new Vec2D(hexPos.x + offset, hexPos.y + 1f * offset - 0.01f),                              // 1a
                new Vec2D(hexPos.x + offset, hexPos.y + 1f * offset + 0.01f),                              // 1b
                new Vec2D(hexPos.x - offset, hexPos.y + 1f * offset + 0.01f),                              // 2a
                new Vec2D(hexPos.x - offset, hexPos.y + 1f * offset - 0.01f),                              // 2b
                new Vec2D(hexPos.x - offset, hexPos.y + 0f * offset + 0.01f),                              // 3a
                new Vec2D(hexPos.x - offset, hexPos.y + 0f * offset - 0.01f),                              // 3b
                new Vec2D(hexPos.x - offset, hexPos.y - 1f * offset + 0.01f),                              // 4a
                new Vec2D(hexPos.x - offset, hexPos.y - 1f * offset - 0.01f),                              // 4b
                new Vec2D(hexPos.x + offset, hexPos.y - 1f * offset - 0.01f),                              // 5a
                new Vec2D(hexPos.x + offset, hexPos.y - 1f * offset + 0.01f)                               // 5b
            };

            DirectionEnum[] results = new DirectionEnum[12];
            for (int i = 0; i < points.Length; i++)
            {
                results[i] = grid.PointToDirectionInHex(points[i]);
            }

            Assert.That(results, Is.EquivalentTo(new DirectionEnum[12] {
                DirectionEnum.E,                  // 0a
                DirectionEnum.E,                  // 0b
                DirectionEnum.SE,                 // 1a
                DirectionEnum.SE,                 // 1b
                DirectionEnum.SW,                 // 2a
                DirectionEnum.SW,                 // 2b
                DirectionEnum.W,                  // 3a
                DirectionEnum.W,                  // 3b
                DirectionEnum.NW,                 // 4a
                DirectionEnum.NW,                 // 4b
                DirectionEnum.NE,                 // 5a
                DirectionEnum.NE                  // 5b
            }));
        }