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 encoding rounding #697

Merged
merged 2 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to Mapbox Directions for Swift

## main

* Removed limiting `RouteStep.distance`, `RouteStep.expectedTravelTime` and `RouteStep.typicalTravelTime` precision to 1 decimal digit when being encoded. ([#697](https://github.com/mapbox/mapbox-directions-swift/pull/697))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Removed limiting `RouteStep.distance`, `RouteStep.expectedTravelTime` and `RouteStep.typicalTravelTime` precision to 1 decimal digit when being encoded. ([#697](https://github.com/mapbox/mapbox-directions-swift/pull/697))
* Fixed an issue where `RouteStep.distance`, `RouteStep.expectedTravelTime` and `RouteStep.typicalTravelTime` were rounded to one decimal place when being encoded. ([#697](https://github.com/mapbox/mapbox-directions-swift/pull/697))


## v2.5.0

* Added the `RestStop.name` property. ([#689](https://github.com/mapbox/mapbox-directions-swift/pull/689))
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapboxDirections/RouteStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ open class RouteStep: Codable, ForeignMemberContainerClass {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(instructionsSpokenAlongStep, forKey: .instructionsSpokenAlongStep)
try container.encodeIfPresent(instructionsDisplayedAlongStep, forKey: .instructionsDisplayedAlongStep)
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)
try container.encode(distance, forKey: .distance)
try container.encode(expectedTravelTime, forKey: .expectedTravelTime)
try container.encodeIfPresent(typicalTravelTime, forKey: .typicalTravelTime)
try container.encode(transportType, forKey: .transportType)

let isRound = maneuverType == .takeRotary || maneuverType == .takeRoundabout
Expand Down
8 changes: 4 additions & 4 deletions Tests/MapboxDirectionsTests/RouteStepTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ class RouteStepTests: XCTestCase {
],
"ref": "CA 24",
"weight": 2.5,
"duration": 2.5,
"duration": 2.55,
"duration_typical": 2.369,
"name": "Grove Shafter Freeway",
"pronunciation": "ˈaɪˌfoʊ̯n ˈtɛn",
"distance": 24.5,
"distance": 24.50001,
] as [String: Any?]

let stepData = try! JSONSerialization.data(withJSONObject: stepJSON, options: [])
Expand All @@ -139,11 +139,11 @@ class RouteStepTests: XCTestCase {
XCTAssertEqual(step.maneuverType, .reachFork)
XCTAssertEqual(step.instructions, "Keep right onto CA 24")
XCTAssertEqual(step.codes, ["CA 24"])
XCTAssertEqual(step.expectedTravelTime, 2.5)
XCTAssertEqual(step.expectedTravelTime, 2.55)
XCTAssertEqual(step.typicalTravelTime, 2.369)
XCTAssertEqual(step.names, ["Grove Shafter Freeway"])
XCTAssertEqual(step.phoneticNames, ["ˈaɪˌfoʊ̯n ˈtɛn"])
XCTAssertEqual(step.distance, 24.5)
XCTAssertEqual(step.distance, 24.50001)
}
}

Expand Down