@@ -3,6 +3,7 @@ package com.mapbox.navigation.core.formatter
33import android.content.Context
44import android.content.res.Configuration
55import android.content.res.Resources
6+ import com.mapbox.navigation.base.formatter.Rounding
67import com.mapbox.navigation.base.formatter.UnitType
78import com.mapbox.navigation.core.R
89import com.mapbox.turf.TurfConstants
@@ -16,6 +17,7 @@ import kotlin.math.roundToInt
1617 */
1718object MapboxDistanceUtil {
1819
20+ private const val INVALID_ROUNDING_INCREMENT = 50
1921 private val enLanguage = Locale (" en" ).language
2022
2123 /* *
@@ -84,12 +86,28 @@ object MapboxDistanceUtil {
8486 distanceInMeters !in 0.0 .. Double .MAX_VALUE -> smallValue(
8587 0.0 ,
8688 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 ,
87104 TurfConstants .UNIT_METERS ,
88105 UnitType .METRIC
89106 )
90107 distanceInMeters < 1000.0 -> smallValue(
91108 distanceInMeters,
92109 roundingIncrement,
110+ 50 ,
93111 TurfConstants .UNIT_METERS ,
94112 UnitType .METRIC
95113 )
@@ -128,6 +146,7 @@ object MapboxDistanceUtil {
128146 distanceInMiles !in 0.0 .. Double .MAX_VALUE -> smallValue(
129147 0.0 ,
130148 roundingIncrement,
149+ INVALID_ROUNDING_INCREMENT ,
131150 TurfConstants .UNIT_YARDS ,
132151 UnitType .IMPERIAL
133152 )
@@ -137,12 +156,30 @@ object MapboxDistanceUtil {
137156 TurfConstants .UNIT_MILES ,
138157 TurfConstants .UNIT_YARDS
139158 )
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+
146183 }
147184 distanceInMiles < 3.0 -> largeValue(
148185 distanceInMiles,
@@ -170,6 +207,7 @@ object MapboxDistanceUtil {
170207 distanceInMiles !in 0.0 .. Double .MAX_VALUE -> smallValue(
171208 0.0 ,
172209 roundingIncrement,
210+ INVALID_ROUNDING_INCREMENT ,
173211 TurfConstants .UNIT_FEET ,
174212 UnitType .IMPERIAL
175213 )
@@ -182,6 +220,7 @@ object MapboxDistanceUtil {
182220 smallValue(
183221 distanceInFeet,
184222 roundingIncrement,
223+ 50 ,
185224 TurfConstants .UNIT_FEET ,
186225 UnitType .IMPERIAL
187226 )
@@ -206,12 +245,15 @@ object MapboxDistanceUtil {
206245 private fun smallValue (
207246 distance : Double ,
208247 roundingIncrement : Int ,
248+ defaultRoundingIncrement : Int ,
209249 unitTypeString : String ,
210250 unitType : UnitType
211251 ): FormattingData {
252+ val inferredRoundingIncrement = if (roundingIncrement == Rounding .INCREMENT_UNDEFINED )
253+ defaultRoundingIncrement else roundingIncrement
212254 val roundedValue = roundSmallDistance(
213255 distance,
214- roundingIncrement ,
256+ inferredRoundingIncrement ,
215257 )
216258 return FormattingData (
217259 roundedValue.toDouble(),
@@ -266,6 +308,7 @@ object MapboxDistanceUtil {
266308 * @param distanceInMeters in meters
267309 * @param roundingIncrement used to alter the original value for display purposes
268310 * @param unitType indicates whether the value should be returned as metric or imperial
311+ * @param locale a specified locale to use rather than the default locale provided by the context
269312 * @return an object containing values for displaying the formatted distance
270313 */
271314 @JvmOverloads
0 commit comments