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

RouteStep rounds distances and times when encoding #670

Closed
1ec5 opened this issue Mar 25, 2022 · 0 comments · Fixed by #697
Closed

RouteStep rounds distances and times when encoding #670

1ec5 opened this issue Mar 25, 2022 · 0 comments · Fixed by #697

Comments

@1ec5
Copy link
Contributor

1ec5 commented Mar 25, 2022

@Udumft noticed that RouteStep rounds distances to increments of 0.1 meters and times to increments of 0.1 seconds when encoding to JSON:

try container.encode(distance.rounded(to: 1e1), forKey: .distance)
try container.encode(expectedTravelTime.rounded(to: 1e1), forKey: .expectedTravelTime)
try container.encodeIfPresent(typicalTravelTime?.rounded(to: 1e1), forKey: .typicalTravelTime)

This is not a lot of precision loss, but in principle, this library should be able to round-trip the same number that it got from the Directions API. Otherwise, there could be some inconsistency with other libraries like MapboxNavigationNative and MapboxMaps.

This behavior was introduced in 9cffdd3 for #382, apparently to make an integration test pass. Most likely, the test had been failing because of an overly strict XCTAssertEquals(_:_:_:) call, which should’ve been replaced by either XCTAssertEqualsWithAccuracy(_:_:accuracy:_:) or JSONSerialization.assertObjectsAreEqual(_:_:approximate:). The latter method was implemented in 4292391, later in the same PR.

/cc @mapbox/navigation-ios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants