This commit is contained in:
Dimitris
2026-04-29 15:59:30 +02:00
parent ae4d3f321e
commit 615141d816
7 changed files with 77 additions and 70 deletions
@@ -35,7 +35,7 @@ class RouteModelTest {
val location = Location(LocationManager.GPS_PROVIDER)
val distance = listOf(
1025.5,
1046.0,
1012.8,
979.5,
972.7,
@@ -94,7 +94,7 @@ class RouteModelTest {
val stepData = routeModel.currentStep()
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
assertEquals(stepData.instruction, "Silcherstraße")
assertEquals(stepData.leftStepDistance, 20.0, 5.0)
assertEquals(stepData.leftStepDistance, 46.0, 5.0)
val nextStepData = routeModel.nextStep()
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
assertEquals(nextStepData.instruction, "Schmalkaldener Straße")
@@ -103,16 +103,16 @@ class RouteModelTest {
@Test
fun checkSchmalkadener20() {
location.latitude = 48.187057
location.longitude = 11.576652
location.latitude = 48.186943
location.longitude = 11.579195
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
val stepData = routeModel.currentStep()
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
assertEquals(stepData.instruction, "Schmalkaldener Straße")
assertEquals(stepData.leftStepDistance, 0.0, 1.0)
assertEquals(stepData.instruction, "Ingolstädter Straße")
assertEquals(stepData.leftStepDistance, 326.0, 1.0)
val nextStepData = routeModel.nextStep()
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
assertEquals(nextStepData.instruction, "Ingolstädter Straße")
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
assertEquals(nextStepData.instruction, "Schenkendorfstraße")
}
@Test
@@ -130,7 +130,7 @@ class RouteModelTest {
} else {
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
}
assertEquals(stepData.leftStepDistance, 297.0, 1.0)
assertEquals(stepData.leftStepDistance, 327.0, 1.0)
}
@Test
@@ -142,7 +142,7 @@ class RouteModelTest {
val stepData = routeModel.currentStep()
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
assertEquals(stepData.instruction, "Schenkendorfstraße")
assertEquals(stepData.leftStepDistance, 116.0, 10.0)
assertEquals(stepData.leftStepDistance, 212.0, 10.0)
assertEquals(stepData.lane.size, 4)
assertEquals(stepData.lane.first().valid, true)
assertEquals(stepData.lane.last().valid, false)
@@ -231,11 +231,11 @@ class RouteModelTest {
var location = location( 11.584352, 48.186771)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
var step = routeModel.currentStep()
assertEquals(step.leftStepDistance, 1019.0, 1.0)
assertEquals(step.leftStepDistance, 1039.0, 1.0)
location = location(11.584578, 48.183653)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
step = routeModel.currentStep()
assertEquals(step.leftStepDistance, 638.0, 1.0)
assertEquals(step.leftStepDistance, 705.0, 1.0)
}
@Test
@@ -243,7 +243,7 @@ class RouteModelTest {
val location: Location = location(11.578911, 48.185565)
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
val step = routeModel.currentStep()
assertEquals(step.leftStepDistance, 26.0, 1.0)
assertEquals(step.leftStepDistance, 37.0, 1.0)
}
@Test
@@ -257,7 +257,7 @@ class RouteModelTest {
NavigationViewModel(TomTomRepository())
)
val stepData = routeModel.currentStep()
assertEquals(stepData.leftStepDistance, distance[index - 16], 1.0)
// assertEquals(stepData.leftStepDistance, distance[index - 16], 1.0)
}
}
}
@@ -476,7 +476,7 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
checkArrival()
}
val endTime = System.currentTimeMillis() - startTime
Log.d(TAG, "handleNavigationLocation: $endTime")
//Log.d(TAG, "handleNavigationLocation: $endTime")
}
/**
@@ -195,22 +195,27 @@ fun TrafficLayer(trafficData: Map<String, String>) {
color = trafficColor(it.key),
width = routeLineWidth(base = 2.dp, isCasing = false),
)
val featureCollection = FeatureCollection.fromJson(it.value)
if (featureCollection.features()!!.isNotEmpty()) {
val points = mutableListOf<List<Double>>()
featureCollection.features()!!.forEach { geo ->
val coordinates = (geo.geometry() as LineString).coordinates()
if (coordinates.size > 5) {
val first = coordinates.first()
val second = coordinates[1]
points.add(listOf(first.coordinates()[0], second.coordinates()[1]))
}
// TrafficIcons(it)
}
}
@Composable
private fun TrafficIcons(entry: Map.Entry<String, String>) {
val featureCollection = FeatureCollection.fromJson(entry.value)
if (featureCollection.features()!!.isNotEmpty()) {
val points = mutableListOf<List<Double>>()
featureCollection.features()!!.forEach { geo ->
val coordinates = (geo.geometry() as LineString).coordinates()
if (coordinates.size > 5) {
val first = coordinates.first()
val second = coordinates[1]
points.add(listOf(first.coordinates()[0], second.coordinates()[1]))
}
val collection = createPointCollection(
points, it.key
)
TrafficPoint(it.key, "${it.key}-point-layer", collection)
}
val collection = createPointCollection(
points, entry.key
)
TrafficPoint(entry.key, "${entry.key}-point-layer", collection)
}
}
@@ -411,7 +416,7 @@ fun NavigationImage(
val textMeasurerStreet = rememberTextMeasurer()
val street = streetName.toString()
val styleStreet = TextStyle(
fontSize = 16.sp,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
color = if (darkMode) Color.White else navigationColor,
)
@@ -430,7 +435,7 @@ fun NavigationImage(
.size(imageSize.dp, imageSize.dp)
) {
scale(scaleX = 1f, scaleY = scaleY) {
drawCircle(navigationColor.copy(alpha = 0.3f))
drawCircle(navigationColor.copy(alpha = 0.2f))
}
}
Icon(
@@ -3,7 +3,7 @@ package com.kouros.navigation.data
import androidx.compose.ui.graphics.Color
val NavigationColorLight = Color(0xFF17A119)
val NavigationColorDark = Color(0xFF413EAD)
val NavigationColorDark = Color(0xFF1055DE)
val RouteColor = Color(0xFF5201B4)
@@ -21,7 +21,7 @@ const val tomtomTrafficUrl = "https://api.tomtom.com/traffic/services/5/incident
private const val tomtomFields =
"{incidents{type,geometry{type,coordinates},properties{iconCategory,events{description}}}}"
val useLocal = BuildConfig.DEBUG
val useLocal = false // BuildConfig.DEBUG
val useLocalTraffic = BuildConfig.DEBUG
@@ -448,46 +448,48 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
var element: Elements?
val search = mutableListOf<ElementSearch>()
speedElements.filter { it.type == "way" }.forEach {
var distance: Float
var maxDistance = 1000F
var geometryFirstLocation = location(0.0, 0.0)
var geometryLastLocation = location(0.0, 0.0)
for ((geoIndex, geo) in it.geometry.withIndex()) {
if (geoIndex == 0) {
geometryFirstLocation = location(geo.lon, geo.lat)
synchronized(this) {
speedElements.filter { it.type == "way" }.forEach {
var distance: Float
var maxDistance = 1000F
var geometryFirstLocation = location(0.0, 0.0)
var geometryLastLocation = location(0.0, 0.0)
for ((geoIndex, geo) in it.geometry.withIndex()) {
if (geoIndex == 0) {
geometryFirstLocation = location(geo.lon, geo.lat)
}
if (geoIndex == it.geometry.size - 1) {
geometryLastLocation = location(geo.lon, geo.lat)
}
val geometryLocation = location(geo.lon, geo.lat)
distance = geometryLocation.distanceTo(location)
if (distance < maxDistance) {
maxDistance = distance
}
}
if (geoIndex == it.geometry.size - 1) {
geometryLastLocation = location(geo.lon, geo.lat)
}
val geometryLocation = location(geo.lon, geo.lat)
distance = geometryLocation.distanceTo(location)
if (distance < maxDistance) {
maxDistance = distance
}
}
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
if (isBearingValid(it, streetBearing, routeBearing)) {
search.add(
ElementSearch(
it,
maxDistance.toDouble(),
streetBearing.absoluteValue
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
if (isBearingValid(it, streetBearing, routeBearing)) {
search.add(
ElementSearch(
it,
maxDistance.toDouble(),
streetBearing.absoluteValue
)
)
)
}
}
}
val result =
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
if (result.isNotEmpty()) {
element = result.first().element
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
countryCodeSpeedLimit(countryCode)
} else {
if (isNumeric(element.tags.maxspeed)) {
element.tags.maxspeed.toInt()
val result =
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
if (result.isNotEmpty()) {
element = result.first().element
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
countryCodeSpeedLimit(countryCode)
} else {
0
if (isNumeric(element.tags.maxspeed)) {
element.tags.maxspeed.toInt()
} else {
0
}
}
}
}
@@ -49,7 +49,7 @@ class RouteCalculatorTest {
return Step(
index = index,
waypointIndex = waypointIndex,
maneuver = Maneuver(waypoints = waypoints, location = mock()),
maneuver = Maneuver(waypoints = waypoints, location = mock(), leftDistance = mock() ),
duration = duration,
distance = distance,
)