@@ -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,29 @@ 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
+ }
146
182
}
147
183
distanceInMiles < 3.0 -> largeValue(
148
184
distanceInMiles,
@@ -170,6 +206,7 @@ object MapboxDistanceUtil {
170
206
distanceInMiles !in 0.0 .. Double .MAX_VALUE -> smallValue(
171
207
0.0 ,
172
208
roundingIncrement,
209
+ INVALID_ROUNDING_INCREMENT ,
173
210
TurfConstants .UNIT_FEET ,
174
211
UnitType .IMPERIAL
175
212
)
@@ -182,6 +219,7 @@ object MapboxDistanceUtil {
182
219
smallValue(
183
220
distanceInFeet,
184
221
roundingIncrement,
222
+ 50 ,
185
223
TurfConstants .UNIT_FEET ,
186
224
UnitType .IMPERIAL
187
225
)
@@ -206,12 +244,18 @@ object MapboxDistanceUtil {
206
244
private fun smallValue (
207
245
distance : Double ,
208
246
roundingIncrement : Int ,
247
+ defaultRoundingIncrement : Int ,
209
248
unitTypeString : String ,
210
249
unitType : UnitType
211
250
): FormattingData {
251
+ val inferredRoundingIncrement = if (roundingIncrement == Rounding .INCREMENT_UNDEFINED ) {
252
+ defaultRoundingIncrement
253
+ } else {
254
+ roundingIncrement
255
+ }
212
256
val roundedValue = roundSmallDistance(
213
257
distance,
214
- roundingIncrement ,
258
+ inferredRoundingIncrement ,
215
259
)
216
260
return FormattingData (
217
261
roundedValue.toDouble(),
0 commit comments