public void ShouldGetAllPositionsWithinDistanceWhenCrossDomain()
        {
            var offsetToCrossDomain = new AxialCoordinate(-4, -2);
            var coord = new AxialCoordinate(3, 2) + offsetToCrossDomain;
            //var realOffsetCoord = new AxialCoordinate(coord.x, coord.y);
            var expectedCoordsInDistance = new[]
            {
                new AxialCoordinate(3, 2),

                new AxialCoordinate(3, 3),
                new AxialCoordinate(2, 3),
                new AxialCoordinate(4, 2),
                new AxialCoordinate(2, 2),
                new AxialCoordinate(4, 1),
                new AxialCoordinate(3, 1),

                new AxialCoordinate(3, 4),
                new AxialCoordinate(2, 4),
                new AxialCoordinate(4, 3),
                new AxialCoordinate(1, 4),
                new AxialCoordinate(5, 2),
                new AxialCoordinate(1, 3),
                new AxialCoordinate(5, 1),
                new AxialCoordinate(1, 2),
                new AxialCoordinate(5, 0),
                new AxialCoordinate(2, 1),
                new AxialCoordinate(4, 0),
                new AxialCoordinate(3, 0),
            }
            .Select(x => x + offsetToCrossDomain)
            .OrderBy(x => x.q)
            .ThenBy(x => x.r)
            .ToList();

            var coordSystem = new HexCoordinateSystem(2);

            var actualJumps = HexCoordinateSystem.GetPositionsWithinJumpDistance(coord, 2)
                              .OrderBy(x => x.q)
                              .ThenBy(x => x.r)
                              .ToList();

            Assert.AreEqual(expectedCoordsInDistance.Count, actualJumps.Count);

            foreach (var pair in expectedCoordsInDistance
                     .Zip(actualJumps, (a, b) => new { expected = a, actual = b }))
            {
                Assert.AreEqual(
                    pair.expected,
                    pair.actual);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <ITilemapMember> GetMembersWithinJumpDistanceByChunk(AxialCoordinate origin, int jumpDistance)
        {
            var chunk = this.GetIndexInChunkMap(origin);
            var originOffsetByDistance = origin + new AxialCoordinate(jumpDistance, 0);
            var maxChunkOffset         = GetIndexInChunkMap(originOffsetByDistance);

            // the distance between these two points will always be the maximum distance we need to traverse
            //  in chunk-space to encompass every point in regular-space that is JumpDistance or more distance away
            var chunkDistance = chunk.DistanceTo(maxChunkOffset);

            return(HexCoordinateSystem.GetPositionsWithinJumpDistance(chunk.ToAxial(), chunkDistance)
                   .Where(pos => tileMemberChunkMap.ContainsKey(pos))
                   .SelectMany(pos => tileMemberChunkMap[pos]));
        }
Ejemplo n.º 3
0
 public static IEnumerable <AxialCoordinate> GetPositionsWithinJumpDistance(AxialCoordinate origin, int jumpDistance)
 {
     return(HexCoordinateSystem.GetPositionsWithinJumpDistance(origin, jumpDistance));
 }