Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAVAND-979: support yards and ios/android thresholds parity #6786

Merged
merged 2 commits into from
May 31, 2023

Conversation

dzinad
Copy link
Contributor

@dzinad dzinad commented Jan 5, 2023

This PR:

  1. Uses yards for imperial UK distances;
  2. Supports android/iOS parity for distance thresholds (https://github.com/mapbox/mapbox-navigation-ios/blob/96d0fc0744d64d2a092f571e1583eeb86831a774/Sources/MapboxCoreNavigation/DistanceFormatter.swift#L82).

Rounding increment parity is not supported here, it will be addressed separately.

@dzinad dzinad force-pushed the NAVAND-979-dd-yards branch from d7f4ce4 to fdb327e Compare January 5, 2023 13:49
@dzinad dzinad marked this pull request as ready for review January 5, 2023 13:49
@dzinad dzinad requested a review from abhishek1508 January 5, 2023 13:49
@github-actions github-actions bot requested a review from RingerJK January 5, 2023 13:50
@dzinad dzinad force-pushed the NAVAND-979-dd-yards branch from 331b93d to e361c64 Compare January 5, 2023 15:44
TurfConstants.UNIT_KILOMETERS
)
when {
distanceInMeters < 3000.0 -> largeValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exact values here are a bit confusing. Why these values were chosen (like 1000.0 3000.0)? It's not clear from the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android/iOS parity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as soon as the PR will be merged, it's lost the context of these values. Could you move values to const and add comments 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just that it's not really clear how to call those constants. While here it's more or less already explained in the code.
For example, for this 3000 I can think of a name: MIN_DISTANCE_TO_USE_LARGE_UNITS_AND_1_FRACTION_DIGIT. Would it really help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so 👍 IMO the same important make leave the comments that the values are in sync with iOS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really agree here. What if we add a new dimension? For example, determine font size along with units and fraction digits (artificial example, but I can't think of a better one from the top of my head). Should I change the constant name then to MIN_DISTANCE_TO_USE_LARGE_UNITS_AND_1_FRACTION_DIGIT_AND_FONT_SIZE_14?
I think it's redundant. It's all specified in the code in place of usage. We pass it all as arguments.

if (locale.language == enLanguage && locale.country == "GB") {
getUKDistance(distanceInMiles, roundingIncrement, locale)
} else {
getUSDistance(distanceInMiles, roundingIncrement, locale)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really an expert, but should we take into account other locations (like Australia and maybe some else)? Maybe set a more generic name for this? like getYardDistance.
Also, do we really need to check the language for the GB locale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. In the ticket only UK was being discussed.
@abhishek1508 @1ec5 are there any other countries that we should use yards in? As far as I understood, on iOS it's just GB, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -105,132 +268,44 @@ object MapboxDistanceUtil {
* @param unitType indicates whether the value should be returned as metric or imperial
* @return an object containing values for displaying the formatted distance
*/
@JvmOverloads
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt if change the signature to wrapper (builder included) to support future possible changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean introduce a new method like
formatDistance(Wrapper)
where Wrapper is a model class with builder?
I'm not sure. I mean if we add a new parameter we will probably need it in our calculations. Which means that we will have to provide the default value anyway to be backward compatible. How is Builder going to help here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java developers cannot fully rely on default parameters. For instance in the method

@JvmOverloads
fun method(
  a: A,
  b: B = defaultB,
  c: C = defaultC
)

java developers cannot overload the default value for param b, and keep the same for c, so invoking of method on the java side would look like (we're forcing to set param c, even if default value exists)

#method(a, customValuesB, defaultC)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant the other way around.
But OK, agreed that default parameters may be tricky to support in the future so I'll add a new method just the way it's done for the formatDistance that returns FormattedDistanceData.

@codecov
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #6786 (52f8230) into main (4fa9622) will increase coverage by 0.04%.
The diff coverage is 97.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #6786      +/-   ##
============================================
+ Coverage     72.53%   72.57%   +0.04%     
+ Complexity     5559     5556       -3     
============================================
  Files           779      779              
  Lines         30092    30131      +39     
  Branches       3547     3551       +4     
============================================
+ Hits          21826    21869      +43     
+ Misses         6841     6840       -1     
+ Partials       1425     1422       -3     
Impacted Files Coverage Δ
...ox/navigation/core/formatter/MapboxDistanceUtil.kt 95.39% <97.47%> (+5.12%) ⬆️

@dzinad dzinad force-pushed the NAVAND-979-dd-yards branch from 450307a to 1d8116f Compare January 6, 2023 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants