-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade RouteProgress Step Data (#812)
* Add current and upcoming step coordinates to RouteProgress * Update route progress with current and upcoming step points - Update tests * Add tunnel distance calculation * Finish intersection calculations * Move distance processing to RouteProcessor * Don't allow processing of first point * Update next step nullable * Update tests * Add current annotation work - Begin current and upcoming StepIntersections * Add current and upcoming intersections in RouteStepProgress * Finish tests and update test fixtures * Remove tunnel milestone, no longer in scope * Update CurrentLegAnnotation javadoc
- Loading branch information
1 parent
9e95f4b
commit 2387ad5
Showing
39 changed files
with
2,344 additions
and
1,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 20 additions & 16 deletions
36
...id-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import com.google.gson.JsonParser; | ||
import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Scanner; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static okhttp3.internal.Util.UTF_8; | ||
|
||
public class BaseTest { | ||
|
||
public static final double DELTA = 1E-10; | ||
public static final double LARGE_DELTA = 0.1; | ||
protected static final double DELTA = 1E-10; | ||
|
||
public static final String ACCESS_TOKEN = "pk.XXX"; | ||
private TestRouteBuilder routeBuilder; | ||
private TestRouteProgressBuilder routeProgressBuilder; | ||
|
||
public void compareJson(String json1, String json2) { | ||
JsonParser parser = new JsonParser(); | ||
assertEquals(parser.parse(json1), parser.parse(json2)); | ||
public BaseTest() { | ||
routeBuilder = new TestRouteBuilder(); | ||
routeProgressBuilder = new TestRouteProgressBuilder(); | ||
} | ||
|
||
protected String loadJsonFixture(String filename) throws IOException { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
InputStream inputStream = classLoader.getResourceAsStream(filename); | ||
Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A"); | ||
return scanner.hasNext() ? scanner.next() : ""; | ||
return routeBuilder.loadJsonFixture(filename); | ||
} | ||
|
||
protected RouteProgress buildRouteProgress(DirectionsRoute route, | ||
double stepDistanceRemaining, | ||
double legDistanceRemaining, | ||
double distanceRemaining, | ||
int stepIndex, | ||
int legIndex) throws Exception { | ||
return routeProgressBuilder.buildTestRouteProgress( | ||
route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, legIndex | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/TestRouteBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Scanner; | ||
|
||
import static okhttp3.internal.Util.UTF_8; | ||
|
||
class TestRouteBuilder { | ||
|
||
String loadJsonFixture(String filename) throws IOException { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
InputStream inputStream = classLoader.getResourceAsStream(filename); | ||
Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A"); | ||
return scanner.hasNext() ? scanner.next() : ""; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
.../src/test/java/com/mapbox/services/android/navigation/ui/v5/TestRouteProgressBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.support.v4.util.Pair; | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
import com.mapbox.api.directions.v5.models.LegStep; | ||
import com.mapbox.api.directions.v5.models.StepIntersection; | ||
import com.mapbox.geojson.Point; | ||
import com.mapbox.geojson.utils.PolylineUtils; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.util.List; | ||
|
||
import static com.mapbox.core.constants.Constants.PRECISION_6; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.createDistancesToIntersections; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.createIntersectionsList; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.findCurrentIntersection; | ||
import static com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.findUpcomingIntersection; | ||
|
||
class TestRouteProgressBuilder { | ||
|
||
RouteProgress buildTestRouteProgress(DirectionsRoute route, | ||
double stepDistanceRemaining, | ||
double legDistanceRemaining, | ||
double distanceRemaining, | ||
int stepIndex, | ||
int legIndex) throws Exception { | ||
List<LegStep> steps = route.legs().get(legIndex).steps(); | ||
LegStep currentStep = steps.get(stepIndex); | ||
String currentStepGeometry = currentStep.geometry(); | ||
List<Point> currentStepPoints = buildStepPointsFromGeometry(currentStepGeometry); | ||
int upcomingStepIndex = stepIndex + 1; | ||
List<Point> upcomingStepPoints = null; | ||
LegStep upcomingStep = null; | ||
if (upcomingStepIndex < steps.size()) { | ||
upcomingStep = steps.get(upcomingStepIndex); | ||
String upcomingStepGeometry = upcomingStep.geometry(); | ||
upcomingStepPoints = buildStepPointsFromGeometry(upcomingStepGeometry); | ||
} | ||
List<StepIntersection> intersections = createIntersectionsList(currentStep, upcomingStep); | ||
List<Pair<StepIntersection, Double>> intersectionDistances = createDistancesToIntersections( | ||
currentStepPoints, intersections | ||
); | ||
|
||
double stepDistanceTraveled = currentStep.distance() - stepDistanceRemaining; | ||
StepIntersection currentIntersection = findCurrentIntersection(intersections, | ||
intersectionDistances, stepDistanceTraveled | ||
); | ||
StepIntersection upcomingIntersection = findUpcomingIntersection( | ||
intersections, upcomingStep, currentIntersection | ||
); | ||
|
||
return RouteProgress.builder() | ||
.stepDistanceRemaining(stepDistanceRemaining) | ||
.legDistanceRemaining(legDistanceRemaining) | ||
.distanceRemaining(distanceRemaining) | ||
.directionsRoute(route) | ||
.currentStepPoints(currentStepPoints) | ||
.upcomingStepPoints(upcomingStepPoints) | ||
.intersections(intersections) | ||
.currentIntersection(currentIntersection) | ||
.upcomingIntersection(upcomingIntersection) | ||
.intersectionDistancesAlongStep(intersectionDistances) | ||
.stepIndex(stepIndex) | ||
.legIndex(legIndex) | ||
.build(); | ||
} | ||
|
||
private List<Point> buildStepPointsFromGeometry(String stepGeometry) { | ||
return PolylineUtils.decode(stepGeometry, PRECISION_6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.