use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteUtilsTest method isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotValidMetersRemaining.
@Test
public void isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotValidMetersRemaining() throws Exception {
DirectionsRoute aRoute = buildDirectionsRoute();
int lastStepIndex = obtainLastStepIndex(aRoute);
RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepIndex(lastStepIndex).legDistanceRemaining(100).build();
boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
assertFalse(isArrivalEvent);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteUtilsTest method isArrivalEvent_returnsTrueWhenManeuverTypeIsArrival_andIsValidMetersRemaining.
@Test
public void isArrivalEvent_returnsTrueWhenManeuverTypeIsArrival_andIsValidMetersRemaining() throws Exception {
DirectionsRoute aRoute = buildDirectionsRoute();
int lastStepIndex = obtainLastStepIndex(aRoute);
RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepDistanceRemaining(30).legDistanceRemaining(30).distanceRemaining(30).stepIndex(lastStepIndex).build();
boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
assertTrue(isArrivalEvent);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteUtilsTest method isArrivalEvent_returnsFalseWhenManeuverTypeIsNotArrival_andIsNotValidMetersRemaining.
@Test
public void isArrivalEvent_returnsFalseWhenManeuverTypeIsNotArrival_andIsNotValidMetersRemaining() throws Exception {
DirectionsRoute aRoute = buildDirectionsRoute();
int lastStepIndex = obtainLastStepIndex(aRoute);
RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepDistanceRemaining(200).legDistanceRemaining(300).distanceRemaining(300).stepIndex(lastStepIndex - 1).build();
boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
assertFalse(isArrivalEvent);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class RouteUtilsTest method obtainLastStepIndex.
private int obtainLastStepIndex(DirectionsRoute route) throws IOException {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
return lastStepIndex;
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationRouteProcessor method buildNewRouteProgress.
/**
* Will take a given location update and create a new {@link RouteProgress}
* based on our calculations of the distances remaining.
* <p>
* Also in charge of detecting if a step / leg has finished and incrementing the
* indices if needed ({@link NavigationRouteProcessor#advanceIndices(MapboxNavigation)} handles
* the decoding of the next step point list).
*
* @param mapboxNavigation for the current route / options
* @param location for step / leg / route distance remaining
* @return new route progress along the route
*/
RouteProgress buildNewRouteProgress(MapboxNavigation mapboxNavigation, Location location) {
DirectionsRoute directionsRoute = mapboxNavigation.getRoute();
MapboxNavigationOptions options = mapboxNavigation.options();
double completionOffset = options.maxTurnCompletionOffset();
double maneuverZoneRadius = options.maneuverZoneRadius();
checkNewRoute(mapboxNavigation);
double stepDistanceRemaining = calculateStepDistanceRemaining(location, directionsRoute);
boolean withinManeuverRadius = stepDistanceRemaining < maneuverZoneRadius;
boolean bearingMatchesManeuver = checkBearingForStepCompletion(location, previousRouteProgress, stepDistanceRemaining, completionOffset);
boolean forceIncreaseIndices = stepDistanceRemaining == 0 && !bearingMatchesManeuver;
if ((bearingMatchesManeuver && withinManeuverRadius) || forceIncreaseIndices) {
advanceIndices(mapboxNavigation);
stepDistanceRemaining = calculateStepDistanceRemaining(location, directionsRoute);
}
int legIndex = indices.legIndex();
int stepIndex = indices.stepIndex();
double legDistanceRemaining = legDistanceRemaining(stepDistanceRemaining, legIndex, stepIndex, directionsRoute);
double routeDistanceRemaining = routeDistanceRemaining(legDistanceRemaining, legIndex, directionsRoute);
return RouteProgress.builder().stepDistanceRemaining(stepDistanceRemaining).legDistanceRemaining(legDistanceRemaining).distanceRemaining(routeDistanceRemaining).directionsRoute(directionsRoute).stepIndex(stepIndex).legIndex(legIndex).build();
}
Aggregations