public void GetDirectionStep_South_Should_Be_0_minus1()
        {
            Coordinate result = CoordinateMap.GetDirectionStep(Direction.S);

            Assert.AreEqual(0, result.X);
            Assert.AreEqual(-1, result.Y);
        }
        public void GetDirectionStep_West_Should_Be_minus1_0()
        {
            Coordinate result = CoordinateMap.GetDirectionStep(Direction.W);

            Assert.AreEqual(-1, result.X);
            Assert.AreEqual(0, result.Y);
        }
        public void GetDirectionStep_East_Should_Be_1_0()
        {
            Coordinate result = CoordinateMap.GetDirectionStep(Direction.E);

            Assert.AreEqual(1, result.X);
            Assert.AreEqual(0, result.Y);
        }
        public void Challenge10_ReturnsCorrectNumberOfVisibleAsteroids()
        {
            var map           = C10.Challenge.Parse(C10Test1Input);
            var coordinateMap = new CoordinateMap(map.map);

            var asteroidLocations = coordinateMap.AsteroidLocations;
            var expected          = new (Coordinate c, int count)[]
        static LineList ConvertedGeoLines(GeoLineList geoLines, CoordinateMap coordinateMap = null)
        {
            LineList lines = new LineList();

            if (coordinateMap == null)
            {
                coordinateMap = MakeCoordinateMap(geoLines);
                DebugLogText(LogLevel.DEBUG, "Created coordinate map: {0}", coordinateMap);
            }

            int lineCount  = 0;
            int pointCount = 0;

            foreach (GeoLine line in geoLines)
            {
                line.SetPrecision(EarthGeo.GeoPrecision);

                /** convert to local coordinate system */
                PointD p1 = coordinateMap.GetPixelPoint(line.P1 as GeoPoint).Round(3) as PointD;
                p1.Name = String.Format("Pt {0}", ++pointCount);

                PointD p2 = coordinateMap.GetPixelPoint(line.P2 as GeoPoint).Round(3) as PointD;
                p2.Name = String.Format("Pt {0}", ++pointCount);

                Line l = new Line(p1, p2);
                l.Name = String.Format("Line {0}", ++lineCount);
                lines.Add(l);

                DebugLogText(LogLevel.DEBUG, "Converted Line {0} {1} to {2}", line, lineCount, l);
            }

            return(lines);
        }
        public void GetDirectionStep_North_should_be_0_1()
        {
            Coordinate result = CoordinateMap.GetDirectionStep(Direction.N);

            Assert.AreEqual(0, result.X);
            Assert.AreEqual(1, result.Y);
        }
Beispiel #7
0
        public MoveCommand ReadCommand()
        {
            string line = _view.ReadLine();

            string[] details = line.Split(' ');
            return(new MoveCommand(CoordinateMap.GetDirection(details[0]), int.Parse(details[1])));
        }
        public GeoSpanningTree(GeoLineList geoLines, CoordinateMap coordinateMap)
        {
            _coordinateMap = coordinateMap;

            m_LinesToConstructor = GeoSpanningTree.ConvertedGeoLines(geoLines, coordinateMap);

            Initialize();
        }
        public void Challenge10_Returns8AsteroidsSpottedAt_3_4()
        {
            var map           = C10.Challenge.Parse(C10Test1Input);
            var coordinateMap = new CoordinateMap(map.map);
            var count         = coordinateMap.VisibleAsteroids(new Coordinate(3, 4)).Count();

            Assert.Equal(8, count);
        }
Beispiel #10
0
        private void PlaceTileMapping(int x, int y, int tileSetId, int tileId)
        {
            var tileCoordinate = new TileCoordinate(x, y, tileSetId, tileId);

            if (CoordinateMap.Contains(tileCoordinate))
            {
                var index = CoordinateMap.IndexOf(tileCoordinate);
                CoordinateMap[index] = tileCoordinate;
            }
            else
            {
                CoordinateMap.Add(tileCoordinate);
            }
        }
Beispiel #11
0
 private void PopulateMap(char marker = '#')
 {
     if (CoordinateMap.Any())
     {
         CoordinateMap = new List <Point>();
     }
     string[] rows = _rawInput.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
     mapSizeX = rows[0].Length;
     mapSizeY = rows.Length;
     for (int y = 0; y < mapSizeY; y++)
     {
         for (int x = 0; x < mapSizeX; x++)
         {
             if (rows[y][x] == marker)
             {
                 CoordinateMap.Add(new Point(x, y));
             }
         }
     }
 }
        public static CoordinateMap GetCoordonation(GoogleWaypointsModel datas)
        {
            var results = new CoordinateMap {
                Waypoints = new List <IEnumerable <CoordinateEntity> >()
            };

            var parseString = datas;

            if (parseString == null)
            {
                return(results);
            }

            foreach (var item in parseString.Routes)
            {
                var data = CoordinateJob.Decode(item.OverviewPolyline?.Points);
                results.Data = data;

                foreach (var waypoint in item.Legs)
                {
                    var polylines = new List <CoordinateEntity>();
                    foreach (var step in waypoint.Steps)
                    {
                        polylines.AddRange(CoordinateJob.Decode(step.Polyline.Points));
                    }
                    results.Waypoints.Add(polylines);
                }

                var resultDistance = item.Legs.Select(x => x.Distance.Text).ToList();
                var resultDuration = item.Legs.Select(x => x.Duration.Text).ToList();

                results.Time          = resultDuration;
                results.Distance      = resultDistance;
                results.WaypointOrder = item.WaypointOrder; //new List<int> { 0 , 1 };
            }

            return(results);
        }
Beispiel #13
0
 /// <summary>
 /// Sets the coordinate mapping used during the conversion.
 /// </summary>
 /// <param name="coordinateMap">The new coordinate mapping.</param>
 public virtual void SetCoordinateMap(CoordinateMap coordinateMap)
 {
     this.coordinateMap = coordinateMap;
 }
Beispiel #14
0
        private bool PointIsVisible(Point origin, Point target)
        {
            Fraction slope;
            bool     slopeIsUndefined = false;
            int      deltaX           = target.X - origin.X;
            int      deltaY           = target.Y - origin.Y;

            // Test for purely vertical slope
            if (deltaX == 0)
            {
                slopeIsUndefined = true;
                // This slope value will be ignored, but needs assigned so the program compiles
                slope = new Fraction();
            }
            // Test for purely horizontal slope
            else if (deltaY == 0)
            {
                // This slope value will be ignored, but needs assigned so the program compiles
                slope = new Fraction();
            }
            // Any other slope
            else
            {
                slope = new Fraction(deltaY, deltaX);
            }

            bool negativeDirection = false;

            // Check UP-DOWN direction when deniminator is 0
            if (slopeIsUndefined)
            {
                if (target.Y < origin.Y)
                {
                    negativeDirection = true;
                }
            }
            // Check LEFT-RIGHT direction when numerator is 0
            if (slope.Numerator == 0 && target.X < origin.X)
            {
                negativeDirection = true;
            }

            //Console.WriteLine($"origin: {origin} | target: {target} | deltaX={deltaX} deltaY={deltaY} | slope: {slope.ToString()} neg: {negativeDirection}");

            // Handling for straight vertical slope
            if (slopeIsUndefined)
            {
                // Note: Negative Y direction visually goes UP on the input grid, since the top-left corner is (0,0)
                if (negativeDirection)
                {
                    for (int y = origin.Y - 1; y >= target.Y; y--)
                    {
                        Point currentPoint = new Point(origin.X, y);
                        if (CoordinateMap.Contains(currentPoint))
                        {
                            if (currentPoint.Equals(target))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    throw new InvalidProgramException($"Failed to process with origin: {origin} | target: {target}");
                }
                // Note: Negative Y direction visually goes DOWN on the input grid, since the top-left corner is (0,0)
                else
                {
                    for (int y = origin.Y + 1; y <= target.Y; y++)
                    {
                        Point currentPoint = new Point(origin.X, y);
                        if (CoordinateMap.Contains(currentPoint))
                        {
                            if (currentPoint.Equals(target))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            // Handling for straight horizontal slope
            if (slope.Numerator == 0)
            {
                if (negativeDirection)
                {
                    for (int x = origin.X - 1; x >= target.X; x--)
                    {
                        Point currentPoint = new Point(x, origin.Y);
                        if (CoordinateMap.Contains(currentPoint))
                        {
                            if (currentPoint.Equals(target))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    for (int x = origin.X + 1; x <= target.X; x++)
                    {
                        Point currentPoint = new Point(x, origin.Y);
                        if (CoordinateMap.Contains(currentPoint))
                        {
                            if (currentPoint.Equals(target))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            // Handling for all other slope values
            bool endLoop  = false;
            long runningX = origin.X;
            long runningY = origin.Y;

            while (!endLoop)
            {
                runningX += slope.Denominator;
                runningY += slope.Numerator;

                Point currentPoint = new Point((int)runningX, (int)runningY);
                if (CoordinateMap.Contains(currentPoint))
                {
                    if (currentPoint.Equals(target))
                    {
                        endLoop = true;
                        return(true);
                    }
                    else
                    {
                        endLoop = true;
                        return(false);
                    }
                }
            }
            throw new InvalidProgramException($"Failed to find visible point with origin: {origin} | target: {target}");
        }
Beispiel #15
0
        public void EraseTile(int x, int y)
        {
            var tileCoordinate = new TileCoordinate(x, y, 0, 0);

            CoordinateMap.Remove(tileCoordinate);
        }
 public MoveCommand ReadDirection(string direction)
 {
     return(new MoveCommand(CoordinateMap.GetDirection(direction[0].ToString()), int.Parse(direction[1].ToString())));
 }
    CoordinateMap map; //call function updateCoordinate to determine which object should be activited

    #endregion Fields

    #region Methods

    // Use this for initialization
    void Start()
    {
        map = GameObject.FindGameObjectWithTag (Tags.GameController).GetComponent<CoordinateMap> ();
    }
Beispiel #18
0
    CoordinateMap map;     //call function updateCoordinate to determine which object should be activited

    // Use this for initialization
    void Start()
    {
        map = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <CoordinateMap> ();
    }