Exemplo n.º 1
0
        public void RoadSplitterNoSplitAtStartTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },

                new GpsCoordinate()
                {
                    x = 0, y = 0.1
                },
                new GpsCoordinate()
                {
                    x = 1, y = 0.5
                },
                new GpsCoordinate()
                {
                    x = 2, y = 1
                },
                new GpsCoordinate()
                {
                    x = 3, y = 2
                },
            }, 2);

            var splitter = new RoadSplitter(1, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(4, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
            Assert.AreEqual(3, pathList[0].Points[3].x);

            Assert.AreEqual(4, pathList[1].Points.Count);
            Assert.AreEqual(0.1, pathList[1].Points[0].y);
            Assert.AreEqual(0.5, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
            Assert.AreEqual(2, pathList[1].Points[3].y);
        }
Exemplo n.º 2
0
        public void RoadSplitterOnePathTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
            }, 2);

            var splitter = new RoadSplitter(2, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(1, pathList.Count);
            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
        }
Exemplo n.º 3
0
        public void RoadSplitterCrossNoConnectionTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },

                new GpsCoordinate()
                {
                    y = -1
                },
                new GpsCoordinate()
                {
                    y = 0
                },
                new GpsCoordinate()
                {
                    y = 1
                },
            }, 1);

            var splitter = new RoadSplitter(0.5f, new PathConnections());

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(-1, pathList[0].Points[0].x);
            Assert.AreEqual(0, pathList[0].Points[1].x);
            Assert.AreEqual(1, pathList[0].Points[2].x);

            Assert.AreEqual(3, pathList[1].Points.Count);
            Assert.AreEqual(-1, pathList[1].Points[0].y);
            Assert.AreEqual(0, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
        }
Exemplo n.º 4
0
        public void RoadSplitterTooFarTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },

                new GpsCoordinate()
                {
                    y = -1
                },
                new GpsCoordinate()
                {
                    y = 0.2
                },
                new GpsCoordinate()
                {
                    y = 1
                },
            }, 1.2f);

            var splitter = new RoadSplitter(0.1f, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(3, pathList[0].Points.Count);
            Assert.AreEqual(-1, pathList[0].Points[0].x);
            Assert.AreEqual(0, pathList[0].Points[1].x);
            Assert.AreEqual(1, pathList[0].Points[2].x);

            Assert.AreEqual(3, pathList[1].Points.Count);
            Assert.AreEqual(-1, pathList[1].Points[0].y);
            Assert.AreEqual(0.2, pathList[1].Points[1].y);
            Assert.AreEqual(1, pathList[1].Points[2].y);
        }
Exemplo n.º 5
0
        public void RoadSplitterComplexConnectionTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },                                // 0
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },
                new GpsCoordinate()
                {
                    x = 4
                },
                new GpsCoordinate()
                {
                    x = 5
                },
                new GpsCoordinate()
                {
                    x = 6
                },

                new GpsCoordinate()
                {
                    x = 1, y = 2
                },                                       // 1
                new GpsCoordinate()
                {
                    x = 1, y = 1
                },
                new GpsCoordinate()
                {
                    x = 1, y = 0.1
                },

                new GpsCoordinate()
                {
                    x = 3, y = -0.1
                },                                          // 2
                new GpsCoordinate()
                {
                    x = 3, y = -1
                },
                new GpsCoordinate()
                {
                    x = 3, y = -2
                },

                new GpsCoordinate()
                {
                    x = 5, y = 2
                },                                       // 3
                new GpsCoordinate()
                {
                    x = 5, y = 1
                },
                new GpsCoordinate()
                {
                    x = 5, y = 0.1
                },

                new GpsCoordinate()
                {
                    x = 6.1
                },                                  //4
                new GpsCoordinate()
                {
                    x = 7
                },

                new GpsCoordinate()
                {
                    x = -2
                },                                 // 5
                new GpsCoordinate()
                {
                    x = -1
                },
                new GpsCoordinate()
                {
                    x = -0.1
                },
            }, 1);

            var pathConnections = new PathConnections();

            pathConnections.Add(0, 4);
            pathConnections.Add(1, 0);
            pathConnections.Add(0, 2);
            pathConnections.Add(3, 0);
            pathConnections.Add(5, 0);

            var splitter = new RoadSplitter(0.5f, pathConnections);

            splitter.Process(paths);

            var connectionsTracker = new PathConnectionsChecksTracker(pathConnections);

            Assert.IsTrue(connectionsTracker.HasConnection(5, 0));
            Assert.IsTrue(connectionsTracker.HasConnection(0, 6));
            Assert.IsTrue(connectionsTracker.HasConnection(1, 6));
            Assert.IsTrue(connectionsTracker.HasConnection(6, 7));
            Assert.IsTrue(connectionsTracker.HasConnection(6, 2));
            Assert.IsTrue(connectionsTracker.HasConnection(3, 8));
            Assert.IsTrue(connectionsTracker.HasConnection(7, 8));
            Assert.IsTrue(connectionsTracker.HasConnection(8, 4));
            Assert.IsTrue(connectionsTracker.AllConnectionsChecked());
        }
Exemplo n.º 6
0
        public void RoadSplitterZigZagTest1()
        {
            var paths = PointUtils.CreateFromPoints(
                new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0
                },
                new GpsCoordinate()
                {
                    x = 1
                },
                new GpsCoordinate()
                {
                    x = 2
                },
                new GpsCoordinate()
                {
                    x = 3
                },
                new GpsCoordinate()
                {
                    x = 4
                },
            }, 1);

            paths.AddRange(PointUtils.CreateFromPoints(
                               new List <GpsCoordinate>()
            {
                new GpsCoordinate()
                {
                    x = 0, y = 0.5
                },
                new GpsCoordinate()
                {
                    x = 1, y = 2
                },
                new GpsCoordinate()
                {
                    x = 2, y = -0.5
                },
                new GpsCoordinate()
                {
                    x = 3, y = -2
                },
                new GpsCoordinate()
                {
                    x = 4, y = 0.5
                },
            }, 3));

            var splitter = new RoadSplitter(1, null);

            splitter.Process(paths);

            var pathList = (List <PathData>)paths;

            Assert.AreEqual(2, pathList.Count);

            Assert.AreEqual(5, pathList[0].Points.Count);
            Assert.AreEqual(0, pathList[0].Points[0].x);
            Assert.AreEqual(1, pathList[0].Points[1].x);
            Assert.AreEqual(2, pathList[0].Points[2].x);
            Assert.AreEqual(3, pathList[0].Points[3].x);
            Assert.AreEqual(4, pathList[0].Points[4].x);

            Assert.AreEqual(5, pathList[1].Points.Count);
            Assert.AreEqual(0.5, pathList[1].Points[0].y);
            Assert.AreEqual(2, pathList[1].Points[1].y);
            Assert.AreEqual(-0.5, pathList[1].Points[2].y);
            Assert.AreEqual(-2, pathList[1].Points[3].y);
            Assert.AreEqual(0.5, pathList[1].Points[4].y);
        }