Ejemplo n.º 1
0
        public async Task Test_DataService_GetGridCoordinateByGridIdAsync()
        {
            IGridCoordinate gridCoordinate = await dataService.GetGridCoordinateByGridIdAsync(2);

            Assert.AreEqual(5, gridCoordinate.MaxXCoordinate);
            Assert.AreEqual(5, gridCoordinate.MaxYCoordinate);
        }
Ejemplo n.º 2
0
        public void Test_DataService_GetGridCoordinateByGridId()
        {
            IGridCoordinate gridCoordinate = dataService.GetGridCoordinateByGridId(2);

            Assert.AreEqual(5, gridCoordinate.MaxXCoordinate);
            Assert.AreEqual(5, gridCoordinate.MaxYCoordinate);
        }
Ejemplo n.º 3
0
        private void ForwardInstructionProcess(IPositionFinal positionFinal, IGridCoordinate gridCoordinate)
        {
            switch (positionFinal.FinalOrientation)
            {
            case 'N':
                if (positionFinal.FinalYPosition + 1 > gridCoordinate.MaxYCoordinate)
                {
                    positionFinal.Lost = true;
                }
                else
                {
                    positionFinal.FinalYPosition += 1;
                }
                break;

            case 'S':
                if (positionFinal.FinalYPosition - 1 < 0)
                {
                    positionFinal.Lost = true;
                }
                else
                {
                    positionFinal.FinalYPosition -= 1;
                }
                break;

            case 'E':
                if (positionFinal.FinalXPosition + 1 > gridCoordinate.MaxXCoordinate)
                {
                    positionFinal.Lost = true;
                }
                else
                {
                    positionFinal.FinalXPosition += 1;
                }
                break;

            case 'W':
                if (positionFinal.FinalXPosition - 1 < 0)
                {
                    positionFinal.Lost = true;
                }
                else
                {
                    positionFinal.FinalXPosition -= 1;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 4
0
        public IPositionFinal GetFinalPostion(int gridId, IPositionStarting positionStarting)
        {
            IGridCoordinate gridCoordinate = _dataService.GetGridCoordinateByGridId(gridId);
            IPositionFinal  positionFinal  = new PositionFinal
            {
                FinalXPosition   = positionStarting.StartingXPosition,
                FinalYPosition   = positionStarting.StartingYPosition,
                FinalOrientation = positionStarting.Orientation,
                Lost             = false
            };

            char[] array = positionStarting.Instructions.ToCharArray();
            foreach (char instruction in array)
            {
                if (positionFinal.Lost)
                {
                    _dataService.SaveOffPosition(gridId, positionFinal);
                    break;
                }
                switch (instruction)
                {
                case 'L':
                    LeftInstructionProcess(positionFinal);
                    break;

                case 'R':
                    RightInstructionProcess(positionFinal);
                    break;

                case 'F':
                    if (!_dataService.IsOffPosition(gridId, positionFinal))
                    {
                        ForwardInstructionProcess(positionFinal, gridCoordinate);
                    }
                    break;

                default:
                    break;
                }
            }
            return(positionFinal);
        }
Ejemplo n.º 5
0
        public IGridIdentifer GetGridIdentifer(IGridCoordinate gridCoordinate)
        {
            int gridId = 0;

            if (gridDictionary.Values.Count > 0)
            {
                gridId = gridDictionary.FirstOrDefault(
                    grid =>
                    grid.Value.MaxXCoordinate == gridCoordinate.MaxXCoordinate &&
                    grid.Value.MaxYCoordinate == gridCoordinate.MaxYCoordinate
                    ).Key;
            }
            if (gridId == 0)
            {
                gridDictionary.Add(gridDictionary.Keys.Count() + 1, gridCoordinate);
                gridId = gridDictionary.Keys.Count;
            }
            return(new GridIdentifer {
                GridID = gridId
            });
        }
Ejemplo n.º 6
0
 public async Task <IGridIdentifer> GetGridIdentiferAsync(IGridCoordinate gridCoordinate)
 {
     return(await _dataService.GetGridIdentiferAsync(gridCoordinate));
 }
Ejemplo n.º 7
0
 public IGridIdentifer GetGridIdentifer(IGridCoordinate gridCoordinate)
 {
     return(_dataService.GetGridIdentifer(gridCoordinate));
 }
Ejemplo n.º 8
0
 public async Task <IGridIdentifer> GetGridIdentiferAsync(IGridCoordinate gridCoordinate)
 {
     return(await Task.FromResult(GetGridIdentifer(gridCoordinate)));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Find the nearest four points to a coordinate.
 /// </summary>
 /// <param name="coord">The reference coordinate.</param>
 /// <param name="searchType">The type of search to perform. Bitwise "or-able".</param>
 /// <returns>An array of the nearest four coordinates sorted by distance.</returns>
 public GridNearestCoordinate[] FindNearestCoordinates(IGridCoordinate coord, GribNearestToSame searchType = GribNearestToSame.POINT)
 {
     return(this.FindNearestCoordinates(coord.Latitude, coord.Longitude, searchType));
 }