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

Intersections indicate preferred lane usage #529

Merged
merged 8 commits into from
Apr 2, 2021

Conversation

jill-cardamon
Copy link
Contributor

@jill-cardamon jill-cardamon commented Mar 24, 2021

Description

This PR adds new Directions API response properties that indicate preferred lane usage #516.

  • Add new Lane object properties
  • Add new Instruction component property
  • Update tests for lane object propeties
  • Update tests for instruction component property
  • Update CHANGELOG.md

Implementation

For the banner instruction component object property active_direction: added preferredDirection argument (of type LaneIndication?) associated value of the VisualInstruction.Component.lane(indications:isUsable:) enumeration case.

For the lane object properties active and valid_indication: Added Intersection.preferredApproachLanes property (of type IndexSet?) modeled after Intersection.usableApproachLanes, added Intersection.usableLaneIndication property (of type LaneIndication?).

@jill-cardamon jill-cardamon self-assigned this Mar 24, 2021
@jill-cardamon jill-cardamon added this to the v2.0.0 (RC) milestone Mar 24, 2021
@jill-cardamon jill-cardamon added Core improvement Improvement for an existing feature. platform parity labels Mar 24, 2021
@jill-cardamon jill-cardamon linked an issue Mar 24, 2021 that may be closed by this pull request
@jill-cardamon jill-cardamon marked this pull request as ready for review March 29, 2021 15:02
@1ec5
Copy link
Contributor

1ec5 commented Mar 29, 2021

The build is currently erroring on type checking:

/Users/distiller/project/Tests/MapboxDirectionsTests/VisualInstructionTests.swift:259:107: error: type of expression is ambiguous without more context
            if case let VisualInstruction.Component.lane(indications, isUsable) = laneIndicationComponents[0] {
                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~^~~
/Users/distiller/project/Tests/MapboxDirectionsTests/VisualInstructionTests.swift:263:107: error: type of expression is ambiguous without more context
            if case let VisualInstruction.Component.lane(indications, isUsable) = laneIndicationComponents[1] {
                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~^~~
                     ^

Looks like the tests just need to be updated to account for a new argument to .lane.

README.md Outdated Show resolved Hide resolved
@jill-cardamon
Copy link
Contributor Author

I had one assertion that was failing, so I didn't push those updated tests.

@jill-cardamon jill-cardamon force-pushed the jill/preferredLaneUsage-516 branch from 05463ba to 92880c5 Compare March 31, 2021 17:43
CHANGELOG.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Intersection.swift Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -6,6 +6,9 @@
* This library requires Turf v2.0.0-alpha.3. ([#525](https://github.com/mapbox/mapbox-directions-swift/pull/525))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))

## v2.0.0
* Added the `Intersection.preferredApproachLanes`, `Intersection.usableLaneIndication`, `Lane.isActive`, and `Lane.validIndication` properties that indicate preferred lane usage. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
Copy link
Contributor

Choose a reason for hiding this comment

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

The Lane struct is internal, so we shouldn’t mention it in the changelog; the additions to Intersection are what concern developers. However, we should also mention that the VisualInstruction.Component.lane(indications:isUsable:) case has been renamed to VisualInstruction.Component.lane(indications:isUsable:preferredDirection:).

@jill-cardamon jill-cardamon force-pushed the jill/preferredLaneUsage-516 branch from 92880c5 to ee8d778 Compare April 2, 2021 21:55
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

There’s a little bit of fallout from the original merge in the readme. Otherwise, there are a few minor nits; feel free to merge once they’re addressed.

@@ -6,6 +6,9 @@
* This library requires Turf v2.0.0-alpha.3. ([#525](https://github.com/mapbox/mapbox-directions-swift/pull/525))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))

## v2.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Even the whole section above is for v2.0.0, but we can clean it up after merging the PR.

README.md Outdated

## Pricing

API calls made to the Directions API are individually billed by request. Review the [pricing information](https://docs.mapbox.com/api/navigation/directions/#directions-api-pricing) and the [pricing page](https://www.mapbox.com/pricing/#directions) for current rates.
Copy link
Contributor

Choose a reason for hiding this comment

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

This part shouldn’t be removed. We expect it to no longer be part of the diff after rebasing, but it should remain in the codebase because it’s now in release-v2.0.

Comment on lines 322 to 327
var usableIndications = [LaneIndication]()
lanes.forEach { lane in
if lane.validIndication != nil {
usableIndications.append(lane.validIndication!)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This can be written more succinctly and without an implicitly unwrapped optional:

Suggested change
var usableIndications = [LaneIndication]()
lanes.forEach { lane in
if lane.validIndication != nil {
usableIndications.append(lane.validIndication!)
}
}
let usableIndications = lanes.compactMap { lane.validIndication }

CHANGELOG.md Outdated
@@ -6,6 +6,9 @@
* This library requires Turf v2.0.0-alpha.3. ([#525](https://github.com/mapbox/mapbox-directions-swift/pull/525))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))

## v2.0.0
* Added the `Intersection.preferredApproachLanes` and `Intersection.usableLaneIndication` properties that indicate preferred lane usage. `VisualInstruction.Component.lane(indications:isUsable:)` has been renamed to `VisualInstruction.Component.lane(indications:isUsable:preferredDirection:)`. Note that comparison for `Intersection`s is now stricter around road classes, regions, and rest stops. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
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
* Added the `Intersection.preferredApproachLanes` and `Intersection.usableLaneIndication` properties that indicate preferred lane usage. `VisualInstruction.Component.lane(indications:isUsable:)` has been renamed to `VisualInstruction.Component.lane(indications:isUsable:preferredDirection:)`. Note that comparison for `Intersection`s is now stricter around road classes, regions, and rest stops. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
* Added the `Intersection.preferredApproachLanes` and `Intersection.usableLaneIndication` properties that indicate preferred lane usage. `VisualInstruction.Component.lane(indications:isUsable:)` has been renamed to `VisualInstruction.Component.lane(indications:isUsable:preferredDirection:)`. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
* Comparing two `Intersection`s with `==` now considers whether the `Intersection.restStop`, `Intersection.regionCode`, and `Intersection.outletMapboxStreetsRoadClass` properties are equal. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))

Comment on lines 49 to 50
let str = validIndication?.descriptions.first
try container.encodeIfPresent(str, forKey: .preferred)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Use a more descriptive constant name or inline it into the next line:

Suggested change
let str = validIndication?.descriptions.first
try container.encodeIfPresent(str, forKey: .preferred)
try container.encodeIfPresent(validIndication?.descriptions.first, forKey: .preferred)

Comment on lines 58 to 60
if let str = try container.decodeIfPresent(String.self, forKey: .preferred) {
validIndication = LaneIndication(descriptions: [str])
}
Copy link
Contributor

@1ec5 1ec5 Apr 2, 2021

Choose a reason for hiding this comment

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

This is a bit of a workaround for the fact that LaneIndication always corresponds to an array of values in JSON, whereas we’re using the type here out of convenience for roundtripping one “description” element within such an array. To make the use of lane indication descriptions more apparent, we can name the variable a bit more verbosely:

Suggested change
if let str = try container.decodeIfPresent(String.self, forKey: .preferred) {
validIndication = LaneIndication(descriptions: [str])
}
if let validIndicationDescription = try container.decodeIfPresent(String.self, forKey: .preferred) {
validIndication = LaneIndication(descriptions: [validIndicationDescription])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core improvement Improvement for an existing feature. platform parity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intersections should indicate preferred lane usage
2 participants