use of com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress 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());
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress 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);
}
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress 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);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress 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);
}
use of com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress 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);
}
}
Aggregations