fix: Threading & optimizations

This commit is contained in:
Piotr Dec 2024-08-01 22:52:26 +02:00
parent 6d71245d9f
commit f5ec500343
Signed by: stawros
GPG key ID: F89F27AD8F881A91
4 changed files with 142 additions and 142 deletions

View file

@ -6,74 +6,78 @@ import com.mapbox.navigation.core.trip.session.LocationMatcherResult
class MapboxMapper {
companion object {
fun map(maneuver: Maneuver): GarminManeuver {
val state = GarminManeuver()
maneuver.apply {
this.primary.apply {
state.direction = Direction()
when (this.type) {
"roundabout" -> {
state.direction.out = OutType.RightRoundabout
}
"fork" -> state.direction.out = OutType.LongerLane
"arrive" -> {
state.flag = true
}
"turn" -> {
when (this.type) {
"straight" -> state.direction.angle = OutAngle.Straight
}
}
fun asDirection(maneuver: Maneuver): Direction {
val direction = Direction()
maneuver.primary.apply {
when (this.type) {
"roundabout" -> {
direction.out = OutType.RightRoundabout
}
when (this.modifier) {
"right" -> {
when (this.type) {
"turn" -> state.direction.angle = OutAngle.Right
"roundabout" -> {
when (this.degrees) {
137.0 -> state.direction.angle = OutAngle.EasyRight
180.0 -> state.direction.angle = OutAngle.Straight
}
}
"off ramp" -> {
state.direction.angle = OutAngle.EasyRight
state.direction.out = OutType.LongerLane
}
}
}
"left" -> {
when (this.type) {
"turn" -> state.direction.angle = OutAngle.Left
}
"fork" -> direction.out = OutType.LongerLane
"arrive" -> {
// flag = true
}
"turn" -> {
when (this.type) {
"straight" -> direction.angle = OutAngle.Straight
}
}
}
this.stepDistance.apply {
this.distanceRemaining?.apply {
distanceFormatter.formatDistance(this).split(" ").apply {
state.distance = Distance(
this[0].replace(',', '.').toDouble(),
when (this[1]) {
"m" -> Unit.Metres
"km" -> Unit.Kilometres
else -> Unit.Any
when (this.modifier) {
"right" -> {
when (this.type) {
"turn" -> direction.angle = OutAngle.Right
"roundabout" -> {
when (this.degrees) {
137.0 -> direction.angle = OutAngle.EasyRight
180.0 -> direction.angle = OutAngle.Straight
}
)
}
"off ramp" -> {
direction.angle = OutAngle.EasyRight
direction.out = OutType.LongerLane
}
}
}
}
// TODO: implement
state.lanes = Lanes(Arrows(listOf()), Arrows(listOf()))
this.laneGuidance?.apply {
this.allLanes.apply {
println()
"left" -> {
when (this.type) {
"turn" -> direction.angle = OutAngle.Left
"off ramp" -> {
direction.angle = OutAngle.EasyLeft
direction.out = OutType.LongerLane
}
}
}
}
}
return state
return direction
}
fun asDistance(maneuver: Maneuver): Distance {
return maneuver.stepDistance.let { step ->
step.distanceFormatter.formatDistance(step.distanceRemaining!!).split(" ").let {
Distance(
it[0].replace(',', '.').toDouble(),
when (it[1]) {
"m" -> Unit.Metres
"km" -> Unit.Kilometres
else -> Unit.Any
}
)
}
}
}
fun asLanes(maneuver: Maneuver): Lanes {
// TODO: implement
maneuver.laneGuidance?.apply {
this.allLanes.apply {
println()
}
}
return Lanes(Arrows(listOf()), Arrows(listOf()))
}
fun map(locationMatcherResult: LocationMatcherResult): GarminLocation {