@@ -3,6 +3,7 @@ package com.mapbox.navigation.core.formatter
3
3
import android.content.Context
4
4
import android.content.res.Configuration
5
5
import android.content.res.Resources
6
+ import com.mapbox.navigation.base.formatter.Rounding
6
7
import com.mapbox.navigation.base.formatter.UnitType
7
8
import com.mapbox.navigation.core.R
8
9
import com.mapbox.turf.TurfConstants
@@ -16,6 +17,7 @@ import kotlin.math.roundToInt
16
17
*/
17
18
object MapboxDistanceUtil {
18
19
20
+ private const val INVALID_ROUNDING_INCREMENT = 50
19
21
private val enLanguage = Locale (" en" ).language
20
22
21
23
/* *
@@ -84,12 +86,28 @@ object MapboxDistanceUtil {
84
86
distanceInMeters !in 0.0 .. Double .MAX_VALUE -> smallValue(
85
87
0.0 ,
86
88
roundingIncrement,
89
+ INVALID_ROUNDING_INCREMENT ,
90
+ TurfConstants .UNIT_METERS ,
91
+ UnitType .METRIC
92
+ )
93
+ distanceInMeters < 25.0 -> smallValue(
94
+ distanceInMeters,
95
+ roundingIncrement,
96
+ 5 ,
97
+ TurfConstants .UNIT_METERS ,
98
+ UnitType .METRIC
99
+ )
100
+ distanceInMeters < 100 -> smallValue(
101
+ distanceInMeters,
102
+ roundingIncrement,
103
+ 25 ,
87
104
TurfConstants .UNIT_METERS ,
88
105
UnitType .METRIC
89
106
)
90
107
distanceInMeters < 1000.0 -> smallValue(
91
108
distanceInMeters,
92
109
roundingIncrement,
110
+ 50 ,
93
111
TurfConstants .UNIT_METERS ,
94
112
UnitType .METRIC
95
113
)
@@ -128,6 +146,7 @@ object MapboxDistanceUtil {
128
146
distanceInMiles !in 0.0 .. Double .MAX_VALUE -> smallValue(
129
147
0.0 ,
130
148
roundingIncrement,
149
+ INVALID_ROUNDING_INCREMENT ,
131
150
TurfConstants .UNIT_YARDS ,
132
151
UnitType .IMPERIAL
133
152
)
@@ -137,12 +156,30 @@ object MapboxDistanceUtil {
137
156
TurfConstants .UNIT_MILES ,
138
157
TurfConstants .UNIT_YARDS
139
158
)
140
- smallValue(
141
- distanceInYards,
142
- roundingIncrement,
143
- TurfConstants .UNIT_YARDS ,
144
- UnitType .IMPERIAL
145
- )
159
+ when {
160
+ distanceInYards < 20 -> smallValue(
161
+ distanceInYards,
162
+ roundingIncrement,
163
+ 10 ,
164
+ TurfConstants .UNIT_YARDS ,
165
+ UnitType .IMPERIAL
166
+ )
167
+ distanceInYards < 100 -> smallValue(
168
+ distanceInYards,
169
+ roundingIncrement,
170
+ 25 ,
171
+ TurfConstants .UNIT_YARDS ,
172
+ UnitType .IMPERIAL
173
+ )
174
+ else -> smallValue(
175
+ distanceInYards,
176
+ roundingIncrement,
177
+ 50 ,
178
+ TurfConstants .UNIT_YARDS ,
179
+ UnitType .IMPERIAL
180
+ )
181
+ }
182
+
146
183
}
147
184
distanceInMiles < 3.0 -> largeValue(
148
185
distanceInMiles,
@@ -170,6 +207,7 @@ object MapboxDistanceUtil {
170
207
distanceInMiles !in 0.0 .. Double .MAX_VALUE -> smallValue(
171
208
0.0 ,
172
209
roundingIncrement,
210
+ INVALID_ROUNDING_INCREMENT ,
173
211
TurfConstants .UNIT_FEET ,
174
212
UnitType .IMPERIAL
175
213
)
@@ -182,6 +220,7 @@ object MapboxDistanceUtil {
182
220
smallValue(
183
221
distanceInFeet,
184
222
roundingIncrement,
223
+ 50 ,
185
224
TurfConstants .UNIT_FEET ,
186
225
UnitType .IMPERIAL
187
226
)
@@ -206,12 +245,15 @@ object MapboxDistanceUtil {
206
245
private fun smallValue (
207
246
distance : Double ,
208
247
roundingIncrement : Int ,
248
+ defaultRoundingIncrement : Int ,
209
249
unitTypeString : String ,
210
250
unitType : UnitType
211
251
): FormattingData {
252
+ val inferredRoundingIncrement = if (roundingIncrement == Rounding .INCREMENT_UNDEFINED )
253
+ defaultRoundingIncrement else roundingIncrement
212
254
val roundedValue = roundSmallDistance(
213
255
distance,
214
- roundingIncrement ,
256
+ inferredRoundingIncrement ,
215
257
)
216
258
return FormattingData (
217
259
roundedValue.toDouble(),
0 commit comments