Search in sources :

Example 11 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method stepIntersections_handlesNullNextManeuverCorrectly.

@Test
public void stepIntersections_handlesNullNextManeuverCorrectly() throws Exception {
    int lastStepIndex = (route.legs().get(0).steps().size() - 1);
    RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(0).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(lastStepIndex).legIndex(0).build();
    RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    int currentStepTotal = route.legs().get(0).steps().get(lastStepIndex).intersections().size();
    List<Point> lastStepLocation = PolylineUtils.decode(route.legs().get(0).steps().get(lastStepIndex).geometry(), Constants.PRECISION_6);
    assertEquals(currentStepTotal, routeStepProgress.intersections().size());
    assertEquals(routeStepProgress.intersections().get(0).location().latitude(), lastStepLocation.get(0).latitude());
    assertEquals(routeStepProgress.intersections().get(0).location().longitude(), lastStepLocation.get(0).longitude());
}
Also used : Point(com.mapbox.geojson.Point) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 12 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method fractionTraveled_equalsCorrectValueAtIntervals.

@Test
public void fractionTraveled_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < firstStep.distance(); i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        float fractionRemaining = (float) ((firstStep.distance() - distance) / firstStep.distance());
        if (fractionRemaining < 0) {
            fractionRemaining = 0;
        }
        assertEquals(fractionRemaining, routeStepProgress.fractionTraveled(), DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 13 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method stepDistance_equalsZeroOnOneCoordSteps.

@Test
public void stepDistance_equalsZeroOnOneCoordSteps() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
    String body = loadJsonFixture(DCMAPBOX_CHIPOLTLE);
    response = gson.fromJson(body, DirectionsResponse.class);
    DirectionsRoute route = response.routes().get(0);
    RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(0).legDistanceRemaining(0).distanceRemaining(0).directionsRoute(route).stepIndex(route.legs().get(0).steps().size() - 1).legIndex(0).build();
    RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    assertNotNull("should not be null", routeStepProgress);
    assertEquals(1, routeStepProgress.fractionTraveled(), DELTA);
    assertEquals(0, routeStepProgress.distanceRemaining(), DELTA);
    assertEquals(0, routeStepProgress.distanceTraveled(), DELTA);
    assertEquals(0, routeStepProgress.durationRemaining(), DELTA);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Gson(com.google.gson.Gson) LineString(com.mapbox.geojson.LineString) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 14 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method distanceRemaining_equalsStepDistanceAtBeginning.

@Test
public void distanceRemaining_equalsStepDistanceAtBeginning() {
    LineString lineString = LineString.fromPolyline(firstLeg.steps().get(5).geometry(), Constants.PRECISION_6);
    double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
    RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(firstLeg.steps().get(5).distance()).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(4).legIndex(0).build();
    RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    assertEquals(stepDistance, routeStepProgress.distanceRemaining(), BaseTest.LARGE_DELTA);
}
Also used : LineString(com.mapbox.geojson.LineString) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 15 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method distanceTraveled_equalsCorrectValueAtIntervals.

@Test
public void distanceTraveled_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < firstStep.distance(); i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        distance = firstStep.distance() - distance;
        if (distance < 0) {
            distance = 0;
        }
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(firstLeg.steps().get(0).distance() - distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        assertEquals(distance, routeStepProgress.distanceTraveled(), BaseTest.DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)44 Test (org.junit.Test)44 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)39 Point (com.mapbox.geojson.Point)30 Location (android.location.Location)19 LineString (com.mapbox.geojson.LineString)12 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)10 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)3 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)3 Context (android.content.Context)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)2 RouteStepProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)2 DistanceUtils (com.mapbox.services.android.navigation.v5.utils.DistanceUtils)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2