-
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.
fix a bug where
RouteAlertGeometry.toLineString
would not return la…
…st geometry segment
- Loading branch information
1 parent
b1d6eb2
commit 4613556
Showing
3 changed files
with
76 additions
and
4 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
74 changes: 74 additions & 0 deletions
74
...ion-base/src/test/java/com/mapbox/navigation/base/trip/model/alert/RouteAlertUtilsTest.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,74 @@ | ||
package com.mapbox.navigation.base.trip.model.alert | ||
|
||
import com.mapbox.api.directions.v5.models.DirectionsResponse | ||
import com.mapbox.api.directions.v5.models.DirectionsRoute | ||
import com.mapbox.geojson.LineString | ||
import com.mapbox.geojson.Point | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class RouteAlertUtilsTest { | ||
|
||
@Test | ||
fun `verify alert geometry linestring`() { | ||
val directionsRoute = getDirectionsRoutesFromJsonResponse( | ||
"mock_response_multi_leg_route_alerts_restricted_tunnel.json" | ||
) | ||
val alertGeometry = RouteAlertGeometry.Builder( | ||
length = 27.962033570785458, | ||
startCoordinate = Point.fromLngLat(17.043697, 51.117523), | ||
startGeometryIndex = 0, | ||
endCoordinate = Point.fromLngLat(17.043299, 51.117504), | ||
endGeometryIndex = 2 | ||
).build() | ||
val expectedLineString = LineString.fromLngLats( | ||
listOf( | ||
Point.fromLngLat(17.043697, 51.117523), | ||
Point.fromLngLat(17.043516, 51.117515), | ||
Point.fromLngLat(17.043298, 51.117504) | ||
) | ||
) | ||
|
||
val actualLineString = alertGeometry.toLineString(directionsRoute, 6) | ||
|
||
assertEquals(expectedLineString, actualLineString) | ||
} | ||
|
||
@Test | ||
fun `verify alert geometry linestring second leg`() { | ||
val directionsRoute = getDirectionsRoutesFromJsonResponse( | ||
"mock_response_multi_leg_route_alerts_restricted_tunnel.json" | ||
) | ||
val alertGeometry = RouteAlertGeometry.Builder( | ||
length = 43.13547754234237, | ||
startCoordinate = Point.fromLngLat(17.043299, 51.117504), | ||
startGeometryIndex = 2, | ||
endCoordinate = Point.fromLngLat(17.043203, 51.117191), | ||
endGeometryIndex = 7 | ||
).build() | ||
val expectedLineString = LineString.fromLngLats( | ||
listOf( | ||
Point.fromLngLat(17.043298, 51.117504), | ||
Point.fromLngLat(17.043174, 51.1175), | ||
Point.fromLngLat(17.043186, 51.117378), | ||
Point.fromLngLat(17.043197, 51.117252), | ||
Point.fromLngLat(17.043199, 51.117237), | ||
Point.fromLngLat(17.043203, 51.117191) | ||
) | ||
) | ||
|
||
val actualLineString = alertGeometry.toLineString(directionsRoute, 6) | ||
|
||
assertEquals(expectedLineString, actualLineString) | ||
} | ||
|
||
private fun getDirectionsRoutesFromJsonResponse( | ||
fileName: String, | ||
routeIndex: Int = 0 | ||
): DirectionsRoute { | ||
val responseJson = javaClass.classLoader?.getResourceAsStream(fileName) | ||
?.bufferedReader() | ||
?.use { it.readText() }!! | ||
return DirectionsResponse.fromJson(responseJson).routes()[routeIndex] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ation-base/src/test/resources/mock_response_multi_leg_route_alerts_restricted_tunnel.json
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 @@ | ||
{"routes":[{"duration_typical":36.213,"weight_name":"auto","weight":92.726,"duration":36.213,"distance":86.376,"legs":[{"steps":[{"voiceInstructions":[{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">Drivewest.Then,in90feet,Youwillarriveatyourdestination.</prosody></amazon:effect></speak>","announcement":"Drivewest.Then,in90feet,Youwillarriveatyourdestination.","distanceAlongGeometry":28.016},{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">Youhavearrivedatyourdestination.</prosody></amazon:effect></speak>","announcement":"Youhavearrivedatyourdestination.","distanceAlongGeometry":13.889}],"bannerInstructions":[{"primary":{"components":[{"type":"text","text":"Youwillarriveatyourdestination"}],"type":"arrive","modifier":"straight","text":"Youwillarriveatyourdestination"},"distanceAlongGeometry":28.016},{"primary":{"components":[{"type":"text","text":"Youhavearrivedatyourdestination"}],"type":"arrive","modifier":"straight","text":"Youhavearrivedatyourdestination"},"distanceAlongGeometry":13.889}],"maneuver":{"type":"depart","instruction":"Drivewest.","bearing_after":266,"bearing_before":0,"location":[17.043697,51.117523]},"intersections":[{"classes":["restricted"],"entry":[true],"bearings":[266],"duration":4.568,"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":0,"weight":5.14,"geometry_index":0,"location":[17.043697,51.117523]},{"bearings":[86,265],"entry":[false,true],"classes":["restricted"],"in":0,"turn_weight":3.3,"turn_duration":0.007,"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":1,"geometry_index":1,"location":[17.043516,51.117516]}],"weight":14.647,"duration":10.093,"distance":28.016,"name":"","driving_side":"right","duration_typical":10.093,"mode":"driving","weight_typical":14.647,"geometry":"e|}n`Bango_@NhJTrL"},{"voiceInstructions":[],"bannerInstructions":[],"maneuver":{"type":"arrive","instruction":"Youhavearrivedatyourdestination.","bearing_after":0,"bearing_before":265,"location":[17.043299,51.117504]},"intersections":[{"bearings":[85],"entry":[true],"in":0,"admin_index":0,"geometry_index":2,"location":[17.043299,51.117504]}],"weight":0,"duration":0,"distance":0,"name":"","driving_side":"right","duration_typical":0,"mode":"driving","weight_typical":0,"geometry":"_{}n`Bcufo_@??"}],"admins":[{"iso_3166_1_alpha3":"POL","iso_3166_1":"PL"}],"weight_typical":14.647,"duration_typical":10.093,"duration":10.093,"annotation":{"congestion":["unknown","unknown"],"speed":[2.8,2.8],"distance":[12.7,15.2]},"distance":28.016,"weight":14.647,"summary":""},{"steps":[{"voiceInstructions":[{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">Drivewest.ThenTurnleft.</prosody></amazon:effect></speak>","announcement":"Drivewest.ThenTurnleft.","distanceAlongGeometry":8.674}],"bannerInstructions":[{"primary":{"components":[{"type":"text","text":"Turnleft"}],"type":"turn","modifier":"left","text":"Turnleft"},"distanceAlongGeometry":8.674}],"maneuver":{"type":"depart","instruction":"Drivewest.","bearing_after":267,"bearing_before":0,"location":[17.043299,51.117504]},"intersections":[{"classes":["restricted"],"bearings":[267],"entry":[true],"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":0,"geometry_index":0,"location":[17.043299,51.117504]}],"weight":3.513,"duration":3.123,"distance":8.674,"name":"","driving_side":"right","duration_typical":3.123,"mode":"driving","weight_typical":3.513,"geometry":"_{}n`Bcufo_@FvF"},{"voiceInstructions":[{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">In100feet,TurnrightontoHenrykaSienkiewicza.</prosody></amazon:effect></speak>","announcement":"In100feet,TurnrightontoHenrykaSienkiewicza.","distanceAlongGeometry":31.667},{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">TurnrightontoHenrykaSienkiewicza.ThenYouwillarriveatyourdestination.</prosody></amazon:effect></speak>","announcement":"TurnrightontoHenrykaSienkiewicza.ThenYouwillarriveatyourdestination.","distanceAlongGeometry":21.111}],"bannerInstructions":[{"primary":{"components":[{"type":"text","text":"HenrykaSienkiewicza"}],"type":"turn","modifier":"right","text":"HenrykaSienkiewicza"},"distanceAlongGeometry":35}],"maneuver":{"type":"turn","instruction":"Turnleft.","modifier":"left","bearing_after":177,"bearing_before":267,"location":[17.043175,51.1175]},"intersections":[{"mapbox_streets_v8":{"class":"service"},"location":[17.043175,51.1175],"geometry_index":1,"admin_index":0,"weight":30.796,"is_urban":true,"turn_weight":25,"duration":10.315,"bearings":[87,177],"out":1,"in":0,"turn_duration":5.275,"classes":["restricted"],"entry":[false,true]},{"entry":[true,false],"classes":["tunnel","restricted"],"in":1,"bearings":[177,357],"duration":5.04,"turn_weight":3.75,"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":0,"weight":9.546,"geometry_index":2,"location":[17.043186,51.117378]},{"entry":[true,false],"classes":["restricted"],"in":1,"bearings":[177,357],"duration":0.72,"turn_weight":3.75,"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":0,"weight":4.578,"geometry_index":3,"location":[17.043198,51.117252]},{"bearings":[177,357],"entry":[true,false],"classes":["restricted"],"in":1,"turn_weight":15,"turn_duration":0.007,"mapbox_streets_v8":{"class":"service"},"is_urban":true,"admin_index":0,"out":0,"geometry_index":4,"location":[17.0432,51.117237]}],"weight":61.99,"duration":17.883,"distance":35,"name":"","driving_side":"right","duration_typical":17.883,"mode":"driving","weight_typical":61.99,"geometry":"wz}n`Bkmfo_@rFWzFU\\CzAG"},{"voiceInstructions":[{"ssmlAnnouncement":"<speak><amazon:effectname=\"drc\"><prosodyrate=\"1.08\">Youhavearrivedatyourdestination.</prosody></amazon:effect></speak>","announcement":"Youhavearrivedatyourdestination.","distanceAlongGeometry":14.686}],"bannerInstructions":[{"primary":{"components":[{"type":"text","text":"Youhavearrivedatyourdestination"}],"type":"arrive","modifier":"straight","text":"Youhavearrivedatyourdestination"},"distanceAlongGeometry":14.686}],"maneuver":{"type":"endofroad","instruction":"TurnrightontoHenrykaSienkiewicza.","modifier":"right","bearing_after":267,"bearing_before":177,"location":[17.043203,51.117191]},"intersections":[{"bearings":[267,357],"entry":[true,false],"in":1,"turn_weight":9,"turn_duration":2.005,"mapbox_streets_v8":{"class":"tertiary"},"is_urban":true,"admin_index":0,"out":0,"geometry_index":5,"location":[17.043203,51.117191]}],"weight":12.576,"duration":5.115,"distance":14.686,"name":"HenrykaSienkiewicza","driving_side":"right","duration_typical":5.115,"mode":"driving","weight_typical":12.576,"geometry":"mg}n`Beofo_@NbL"},{"voiceInstructions":[],"bannerInstructions":[],"maneuver":{"type":"arrive","instruction":"Youhavearrivedatyourdestination.","bearing_after":0,"bearing_before":267,"location":[17.042994,51.117184]},"intersections":[{"bearings":[87],"entry":[true],"in":0,"admin_index":0,"geometry_index":6,"location":[17.042994,51.117184]}],"weight":0,"duration":0,"distance":0,"name":"HenrykaSienkiewicza","driving_side":"right","duration_typical":0,"mode":"driving","weight_typical":0,"geometry":"}f}n`Babfo_@??"}],"admins":[{"iso_3166_1_alpha3":"POL","iso_3166_1":"PL"}],"weight_typical":78.079,"duration_typical":26.12,"duration":26.12,"annotation":{"congestion":["unknown","unknown","unknown","unknown","unknown","unknown"],"speed":[2.8,2.8,2.8,2.8,2.8,4.7],"distance":[8.7,13.6,14,1.7,5.1,14.7]},"distance":58.36,"weight":78.079,"summary":"HenrykaSienkiewicza"}],"weight_typical":92.726,"geometry":"e|}n`Bango_@NhJTrLFvFrFWzFU\\CzAGNbL","voiceLocale":"en-US"}],"waypoints":[{"distance":26.404,"name":"","location":[17.043697,51.117523]},{"distance":1.282,"name":"","location":[17.043299,51.117504]},{"distance":0.845,"name":"HenrykaSienkiewicza","location":[17.042994,51.117184]}],"code":"Ok","uuid":"id"} |