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

Preferred lane direction is now a ManeuverDirection #535

Merged
merged 5 commits into from
Apr 14, 2021

Conversation

jill-cardamon
Copy link
Contributor

Description

This PR is to change the type of preferred lane direction from LaneIndication to ManeuverDirection to remove the hacks introduced in #529 and #532 and avoid converting within the Nav SDK.

  • Update property type for preferred lane direction propeties
  • Update tests

@jill-cardamon
Copy link
Contributor Author

Tests are failing because of a nil value error.

@1ec5 1ec5 added the op-ex Refactoring, Tech Debt or any other operational excellence work. label Apr 12, 2021
@1ec5 1ec5 added this to the v2.0.0 (RC) milestone Apr 12, 2021
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
// lanes![i].validIndication = usableLaneIndication
// }
// let usable = LaneIndication(descriptions: [usableLaneIndication.rawValue])
if lanes![i].indications.contains(LaneIndication(descriptions: [usableLaneIndication.rawValue])!) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is implicitly reinterpreting a maneuver direction description string as a lane indication description string. That is what we want, but we should make this step more explicit. Let’s create a convenience initializer on LaneIndication that takes a ManeuverDirection. It can switch over all the anticipated description strings to create the corresponding LaneIndication, or it can use the same rawValue-based approach here, but at least it would be better documented that way.

Copy link
Contributor Author

@jill-cardamon jill-cardamon Apr 13, 2021

Choose a reason for hiding this comment

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

Another way is to compare the string descriptions of the LaneIndication to the ManeuverDirection's raw value:

lanes![i].indications.descriptions.contains(usableLaneIndication.rawValue).

If this comparison is used, is the convenience initializer even necessary?

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 it would be preferable to make the conversion explicit in some fashion. Otherwise it would be more difficult to find this raw value–based conversion if the assumption ever breaks in the future.

Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
@jill-cardamon jill-cardamon self-assigned this Apr 13, 2021
Comment on lines 267 to 270
/**
The maneuver has no direction.
*/
case none
Copy link
Contributor Author

@jill-cardamon jill-cardamon Apr 13, 2021

Choose a reason for hiding this comment

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

Adding this case was necessary for getting "road-tripping" to work properly since there is no initializer for ManeuverDirection that handles none.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s make the usableLaneIndication property optional instead, since Optional already has a none case.

// usableLaneIndication = usableIndications.reduce(ManeuverDirection(rawValue: "none")) { $0.union($1) }
if Set(lanes.compactMap { $0.validIndication}).count > 1 {
let context = EncodingError.Context(codingPath: decoder.codingPath, debugDescription: "Inconsistent valid indications.")
throw EncodingError.invalidValue(Set(lanes.compactMap { $0.validIndication}).count, context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning the set itself would be more informative than the count of unique indications.

Comment on lines 267 to 270
/**
The maneuver has no direction.
*/
case none
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s make the usableLaneIndication property optional instead, since Optional already has a none case.

@jill-cardamon
Copy link
Contributor Author

Let’s make the usableLaneIndication property optional instead, since Optional already has a none case.

usableLaneIndication is an optional already. However, lanes would not encode during the V5 testEncoding() test when usableLaneIndication was a nil value.

let context = EncodingError.Context(codingPath: decoder.codingPath, debugDescription: "Inconsistent valid indications.")
throw EncodingError.invalidValue(validIndications, context)
}
usableLaneIndication = lanes.compactMap { $0.validIndication }.first
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
usableLaneIndication = lanes.compactMap { $0.validIndication }.first
usableLaneIndication = validIndications.first

@@ -69,6 +69,10 @@ public struct LaneIndication: OptionSet, CustomStringConvertible {
self.init(rawValue: laneIndication.rawValue)
}

public init?(from direction: ManeuverDirection) {
self.init(descriptions: [direction.rawValue])
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment noting the assumption that every possible raw value of ManeuverDirection matches a valid raw value of LaneIndication.

@@ -69,6 +69,10 @@ public struct LaneIndication: OptionSet, CustomStringConvertible {
self.init(rawValue: laneIndication.rawValue)
}

public init?(from direction: ManeuverDirection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this method need to be public? If so, add a documentation comment for it.

Comment on lines 220 to 223
// var preferredDirection: ManeuverDirection? = nil
// if let preferredDirectionDescription = try container.decodeIfPresent(ManeuverDirection.self, forKey: .activeDirection) {
// preferredDirection = ManeuverDirection(rawValue: preferredDirectionDescription)
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this commented-out code.

@jill-cardamon jill-cardamon merged commit ca5148c into release-v2.0 Apr 14, 2021
@@ -260,15 +260,16 @@ extension Intersection: Codable {
try container.encode(outletArray, forKey: .outletIndexes)

var lanes: [Lane]?
print("lanes: \(String(describing: lanes))")
Copy link
Contributor

Choose a reason for hiding this comment

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

@jill-cardamon This print should be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
op-ex Refactoring, Tech Debt or any other operational excellence work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preferred lane direction should be a ManeuverDirection, not a LaneIndication
3 participants