Пример #1
0
    /// <summary>
    /// Finds the shortest surface distance in the case of the points being on opposing faces.
    /// This method is separate from CalculateShortestSurfaceDistance only for readability purposes.
    /// </summary>
    private static int OpposingFaceDistance(GridPoint start, GridPoint end)
    {
        List <int> distances = new List <int>();

        GridZone gz = start.DetermineGridZone();

        ExtendedGrid[] grids;
        switch (gz)
        {
        case GridZone.TopLeft:
            grids = new[]
            {
                ExtendedGrid.TopMiddle, ExtendedGrid.TopRight,
                ExtendedGrid.RightMiddle,
                ExtendedGrid.BotMiddle,
                ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.TopMiddle:
            grids = new[]
            {
                ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle, ExtendedGrid.TopRight,
                ExtendedGrid.RightMiddle, ExtendedGrid.RightBot,
                ExtendedGrid.BotMiddle,
                ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.TopRight:
            grids = new[]
            {
                ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle,
                ExtendedGrid.RightMiddle, ExtendedGrid.RightBot,
                ExtendedGrid.BotMiddle,
                ExtendedGrid.LeftMiddle
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.BottomLeft:
            grids = new[]
            {
                ExtendedGrid.TopMiddle,
                ExtendedGrid.RightMiddle,
                ExtendedGrid.BotRight, ExtendedGrid.BotMiddle,
                ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.BottomMiddle:
            grids = new[]
            {
                ExtendedGrid.TopMiddle,
                ExtendedGrid.RightTop, ExtendedGrid.RightMiddle,
                ExtendedGrid.BotRight, ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft,
                ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.BottomRight:
            grids = new[]
            {
                ExtendedGrid.TopMiddle,
                ExtendedGrid.RightTop, ExtendedGrid.RightMiddle,
                ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft,
                ExtendedGrid.LeftMiddle
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.LeftMiddle:
            grids = new[]
            {
                ExtendedGrid.TopMiddle, ExtendedGrid.TopRight,
                ExtendedGrid.RightMiddle,
                ExtendedGrid.BotRight, ExtendedGrid.BotMiddle,
                ExtendedGrid.LeftBot, ExtendedGrid.LeftMiddle, ExtendedGrid.LeftTop
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        case GridZone.RightMiddle:
            grids = new[]
            {
                ExtendedGrid.TopLeft, ExtendedGrid.TopMiddle,
                ExtendedGrid.RightTop, ExtendedGrid.RightMiddle, ExtendedGrid.RightBot,
                ExtendedGrid.BotMiddle, ExtendedGrid.BotLeft,
                ExtendedGrid.LeftMiddle
            };
            distances.AddRange(grids.Select(grid => CalculateDistanceOnExtendedGrid(grid, start, end)));
            break;

        default:
            throw new Exception("uh oh...");
        }

        return(distances.Min());
    }