Пример #1
0
        public void RoutePositionAfterRegressionTest1()
        {
            var delta = .00001;

            // a route of approx 30 m along the following coordinates:
            // 50.98624687752063, 2.902620979360633
            // 50.98624687752063, 2.9027639004471673 (10m)
            // 50.986156907620895, 2.9027639004471673  (20m)
            // 50.9861564788317, 2.902620884621392 (30m)

            Route route1 = new Route();
            route1.Vehicle = Vehicle.Car.UniqueName;
            RouteSegment route1entry1 = new RouteSegment();
            route1entry1.Distance = -1;
            route1entry1.Latitude = 50.98624687752063f;
            route1entry1.Longitude = 2.902620979360633f;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = null;
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            RouteSegment route1entry2 = new RouteSegment();
            route1entry2.Distance = -1;
            route1entry2.Latitude = 50.98624687752063f;
            route1entry2.Longitude = 2.9027639004471673f;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry1.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = null;
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            RouteSegment route1entry3 = new RouteSegment();
            route1entry3.Distance = -1;
            route1entry3.Latitude = 50.986156907620895f;
            route1entry3.Longitude = 2.9027639004471673f;
            route1entry3.Metrics = null;
            route1entry3.Points = new RoutePoint[1];
            route1entry3.Points[0] = new RoutePoint();
            route1entry3.Points[0].Name = "TestPoint3";
            route1entry3.Points[0].Tags = new RouteTags[1];
            route1entry3.Points[0].Tags[0] = new RouteTags();
            route1entry3.Points[0].Tags[0].Value = "TestValue3";
            route1entry1.Points[0].Tags[0].Key = "TestKey3";
            route1entry3.SideStreets = null;
            route1entry3.Tags = new RouteTags[1];
            route1entry3.Tags[0] = new RouteTags();
            route1entry3.Tags[0].Key = "highway";
            route1entry3.Tags[0].Value = "residential";
            route1entry3.Time = 10;
            route1entry3.Type = RouteSegmentType.Start;
            route1entry3.Name = string.Empty;
            route1entry3.Names = null;

            RouteSegment route1entry4 = new RouteSegment();
            route1entry4.Distance = -1;
            route1entry4.Latitude = 50.9861564788317f;
            route1entry4.Longitude = 2.902620884621392f;
            route1entry4.Metrics = null;
            route1entry4.Points = new RoutePoint[1];
            route1entry4.Points[0] = new RoutePoint();
            route1entry4.Points[0].Name = "TestPoint4";
            route1entry4.Points[0].Tags = new RouteTags[1];
            route1entry4.Points[0].Tags[0] = new RouteTags();
            route1entry4.Points[0].Tags[0].Value = "TestValue4";
            route1entry1.Points[0].Tags[0].Key = "TestKey4";
            route1entry4.SideStreets = null;
            route1entry4.Tags = new RouteTags[1];
            route1entry4.Tags[0] = new RouteTags();
            route1entry4.Tags[0].Key = "highway";
            route1entry4.Tags[0].Value = "residential";
            route1entry4.Time = 10;
            route1entry4.Type = RouteSegmentType.Start;
            route1entry4.Name = string.Empty;
            route1entry4.Names = null;

            route1.Segments = new RouteSegment[4];
            route1.Segments[0] = route1entry1;
            route1.Segments[1] = route1entry2;
            route1.Segments[2] = route1entry3;
            route1.Segments[3] = route1entry4;

            // first test position after.
            var positionAfter = route1.PositionAfter(5);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(5.0, positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude)).Value, .0001);
            positionAfter = route1.PositionAfter(15);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(15.0,
                new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value +
                positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value, .0001);
            positionAfter = route1.PositionAfter(25);
            Assert.IsNotNull(positionAfter);
            Assert.AreEqual(25.0,
                new GeoCoordinate(route1.Segments[0].Latitude, route1.Segments[0].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude)).Value +
                new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude).DistanceReal(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude)).Value +
                positionAfter.DistanceReal(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude)).Value, .0001);

            // use position after to test project on.
            int entryIdx;
            GeoCoordinate projected;
            Meter distanceFromStart;
            Second timeFromStart;

            var distance = 5.0;
            var location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(0, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);

            distance = 15.0;
            location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(1, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);

            distance = 25;
            location = route1.PositionAfter(distance);
            Assert.IsTrue(route1.ProjectOn(location, out projected, out entryIdx, out distanceFromStart, out timeFromStart));
            Assert.AreEqual(distance, distanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
            Assert.AreEqual(2, entryIdx);

            location = route1.PositionAfter(distanceFromStart);
            Assert.AreEqual(location.Latitude, projected.Latitude, delta);
            Assert.AreEqual(location.Longitude, projected.Longitude, delta);
        }
Пример #2
0
        public void RoutePositionAfterRegressionTest1()
        {
            var delta = .00001;

            // a route of approx 30 m along the following coordinates:
            // 50.98624687752063, 2.902620979360633
            // 50.98624687752063, 2.9027639004471673 (10m)
            // 50.986156907620895, 2.9027639004471673  (20m)
            // 50.9861564788317, 2.902620884621392 (30m)

            var route1 = new Route();
            route1.Vehicle = Vehicle.Car.UniqueName;
            var route1entry1 = new RouteSegment();
            route1entry1.Distance = -1;
            route1entry1.Latitude = 50.98624687752063f;
            route1entry1.Longitude = 2.902620979360633f;
            route1entry1.Metrics = null;
            route1entry1.Points = new RoutePoint[1];
            route1entry1.Points[0] = new RoutePoint();
            route1entry1.Points[0].Name = "TestPoint1";
            route1entry1.Points[0].Tags = new RouteTags[1];
            route1entry1.Points[0].Tags[0] = new RouteTags();
            route1entry1.Points[0].Tags[0].Value = "TestValue1";
            route1entry1.Points[0].Tags[0].Key = "TestKey1";
            route1entry1.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry1.Tags = new RouteTags[1];
            route1entry1.Tags[0] = new RouteTags();
            route1entry1.Tags[0].Key = "highway";
            route1entry1.Tags[0].Value = "residential";
            route1entry1.Time = 10;
            route1entry1.Type = RouteSegmentType.Start;
            route1entry1.Name = string.Empty;
            route1entry1.Names = null;

            RouteSegment route1entry2 = new RouteSegment();
            route1entry2.Distance = -1;
            route1entry2.Latitude = 50.98624687752063f;
            route1entry2.Longitude = 2.9027639004471673f;
            route1entry2.Metrics = null;
            route1entry2.Points = new RoutePoint[1];
            route1entry2.Points[0] = new RoutePoint();
            route1entry2.Points[0].Name = "TestPoint2";
            route1entry2.Points[0].Tags = new RouteTags[1];
            route1entry2.Points[0].Tags[0] = new RouteTags();
            route1entry2.Points[0].Tags[0].Value = "TestValue2";
            route1entry1.Points[0].Tags[0].Key = "TestKey2";
            route1entry2.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry2.Tags = new RouteTags[1];
            route1entry2.Tags[0] = new RouteTags();
            route1entry2.Tags[0].Key = "highway";
            route1entry2.Tags[0].Value = "residential";
            route1entry2.Time = 10;
            route1entry2.Type = RouteSegmentType.Start;
            route1entry2.Name = string.Empty;
            route1entry2.Names = null;

            RouteSegment route1entry3 = new RouteSegment();
            route1entry3.Distance = -1;
            route1entry3.Latitude = 50.986156907620895f;
            route1entry3.Longitude = 2.9027639004471673f;
            route1entry3.Metrics = null;
            route1entry3.Points = new RoutePoint[1];
            route1entry3.Points[0] = new RoutePoint();
            route1entry3.Points[0].Name = "TestPoint3";
            route1entry3.Points[0].Tags = new RouteTags[1];
            route1entry3.Points[0].Tags[0] = new RouteTags();
            route1entry3.Points[0].Tags[0].Value = "TestValue3";
            route1entry1.Points[0].Tags[0].Key = "TestKey3";
            route1entry3.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry3.Tags = new RouteTags[1];
            route1entry3.Tags[0] = new RouteTags();
            route1entry3.Tags[0].Key = "highway";
            route1entry3.Tags[0].Value = "residential";
            route1entry3.Time = 10;
            route1entry3.Type = RouteSegmentType.Start;
            route1entry3.Name = string.Empty;
            route1entry3.Names = null;

            RouteSegment route1entry4 = new RouteSegment();
            route1entry4.Distance = -1;
            route1entry4.Latitude = 50.9861564788317f;
            route1entry4.Longitude = 2.902620884621392f;
            route1entry4.Metrics = null;
            route1entry4.Points = new RoutePoint[1];
            route1entry4.Points[0] = new RoutePoint();
            route1entry4.Points[0].Name = "TestPoint4";
            route1entry4.Points[0].Tags = new RouteTags[1];
            route1entry4.Points[0].Tags[0] = new RouteTags();
            route1entry4.Points[0].Tags[0].Value = "TestValue4";
            route1entry1.Points[0].Tags[0].Key = "TestKey4";
            route1entry4.SideStreets = new RouteSegmentBranch[] {
                    new RouteSegmentBranch() { 
                        Latitude = 51, 
                        Longitude = 3.999f,
                        Tags = new RouteTags[] {
                            new RouteTags() { Key = "name", Value = "Street B" },
                            new RouteTags() { Key = "highway", Value = "residential" }
                        },
                        Name = "Street B"
                    }
                };
            route1entry4.Tags = new RouteTags[1];
            route1entry4.Tags[0] = new RouteTags();
            route1entry4.Tags[0].Key = "highway";
            route1entry4.Tags[0].Value = "residential";
            route1entry4.Time = 10;
            route1entry4.Type = RouteSegmentType.Start;
            route1entry4.Name = string.Empty;
            route1entry4.Names = null;

            route1.Segments = new RouteSegment[4];
            route1.Segments[0] = route1entry1;
            route1.Segments[1] = route1entry2;
            route1.Segments[2] = route1entry3;
            route1.Segments[3] = route1entry4;

            // create the route tracker.
            var routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter());

            var distance = 5.0;
            var location = route1.PositionAfter(distance);
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta);
            var locationAfter = routeTracker.PositionAfter(10.0);

            distance = 15.0;
            location = route1.PositionAfter(distance);
            Assert.AreEqual(location.Latitude, locationAfter.Latitude, delta);
            Assert.AreEqual(location.Longitude, locationAfter.Longitude, delta);
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta);

            location = new GeoCoordinate(route1.Segments[3].Latitude, route1.Segments[3].Longitude);
            Meter distanceFromStart;
            route1.ProjectOn(location, out distanceFromStart);
            distance = distanceFromStart.Value;
            routeTracker.Track(location);
            Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta);
            Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta);
            Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta);
            Assert.AreEqual(0, routeTracker.DistanceNextInstruction.Value, delta);
        }
Пример #3
0
 /// <summary>
 /// Returns true if the move to the next position was succesfull.
 /// </summary>
 /// <returns></returns>
 public bool MoveNext()
 {
     _currentMeter += _intervalMeter;
     _current       = _route.PositionAfter((Meter)(_currentMeter));
     return(_current != null);
 }