-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
239 additions
and
29 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
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
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
46 changes: 46 additions & 0 deletions
46
libnavigation-core/src/main/java/com/mapbox/navigation/core/fasterroute/RouteComparator.kt
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,46 @@ | ||
package com.mapbox.navigation.core.fasterroute | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsRoute | ||
import com.mapbox.api.directions.v5.models.LegStep | ||
import com.mapbox.navigation.base.trip.model.RouteProgress | ||
|
||
/** | ||
* Compares if an alternative route is different from the current route progress. | ||
*/ | ||
internal class RouteComparator { | ||
|
||
private val mapLegStepToName: (LegStep) -> String = { it.name() ?: "" } | ||
|
||
/** | ||
* @param routeProgress current route progress | ||
* @param alternativeRoute suggested new route | ||
* | ||
* @return true when the alternative route has different | ||
* geometry from the current route progress | ||
*/ | ||
fun isRouteDescriptionDifferent(routeProgress: RouteProgress, alternativeRoute: DirectionsRoute): Boolean { | ||
val currentDescription = routeDescription(routeProgress) | ||
val alternativeDescription = alternativeDescription(alternativeRoute) | ||
alternativeDescription.ifEmpty { | ||
return false | ||
} | ||
|
||
return currentDescription != alternativeDescription | ||
} | ||
|
||
private fun routeDescription(routeProgress: RouteProgress): String { | ||
val routeLeg = routeProgress.currentLegProgress?.routeLeg | ||
val steps = routeLeg?.steps() | ||
val stepIndex = routeProgress.currentLegProgress?.currentStepProgress?.stepIndex | ||
?: return "" | ||
|
||
return steps?.listIterator(stepIndex)?.asSequence() | ||
?.joinToString(transform = mapLegStepToName) ?: "" | ||
} | ||
|
||
private fun alternativeDescription(directionsRoute: DirectionsRoute): String { | ||
val steps = directionsRoute.legs()?.firstOrNull()?.steps() | ||
return steps?.asSequence() | ||
?.joinToString(transform = mapLegStepToName) ?: "" | ||
} | ||
} |
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.