Skip to content

Commit

Permalink
Traffic control devices flags (#706)
Browse files Browse the repository at this point in the history
* vk-686-traffic-control: added trafic control devices flags support to Intersection object. Unit test updated; CHANGELOG updated; added API breakage path.
  • Loading branch information
Udumft committed Jun 8, 2022
1 parent 0309c64 commit b0d779b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* MapboxDirections now requires [Turf v2.4](https://github.com/mapbox/turf-swift/releases/tag/v2.4.0). ([#703](https://github.com/mapbox/mapbox-directions-swift/pull/703))
* Added the `RouteOptions.maximumWeight` property to compute routes that excludes roads with a lower weight limit. ([#694](https://github.com/mapbox/mapbox-directions-swift/pull/694))
* Added `Route.refreshLegIncidents(from:)` method to allow refreshing `RouteLeg.incidents` during a route refresh. ([#704](https://github.com/mapbox/mapbox-directions-swift/pull/704))
* Added the `Intersection.railroadCrossing`, `Intersection.trafficSignal`, `Intersection.stopSign` and `Intersection.yieldSign` properties to indicate the kind of traffic control devices at an intersection along the route. ([#706](https://github.com/mapbox/mapbox-directions-swift/pull/706))

## v2.5.0

Expand Down
69 changes: 67 additions & 2 deletions Sources/MapboxDirections/Intersection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public struct Intersection: ForeignMemberContainer {
restStop: RestStop? = nil,
isUrban: Bool? = nil,
regionCode: String? = nil,
outletMapboxStreetsRoadClass: MapboxStreetsRoadClass? = nil) {
outletMapboxStreetsRoadClass: MapboxStreetsRoadClass? = nil,
railroadCrossing: Bool? = nil,
trafficSignal: Bool? = nil,
stopSign: Bool? = nil,
yieldSign: Bool? = nil) {
self.location = location
self.headings = headings
self.approachIndex = approachIndex
Expand All @@ -42,6 +46,10 @@ public struct Intersection: ForeignMemberContainer {
self.restStop = restStop
self.regionCode = regionCode
self.outletMapboxStreetsRoadClass = outletMapboxStreetsRoadClass
self.railroadCrossing = railroadCrossing
self.trafficSignal = trafficSignal
self.stopSign = stopSign
self.yieldSign = yieldSign
}

// MARK: Getting the Location of the Intersection
Expand Down Expand Up @@ -169,6 +177,34 @@ public struct Intersection: ForeignMemberContainer {
If no lane information is available for the intersection, this property’s value is `nil`
*/
public let usableLaneIndication: ManeuverDirection?

/**
Indicates whether there is a railroad crossing at the intersection.
If such information is not available for an intersection, this property’s value is `nil`.
*/
public let railroadCrossing: Bool?

/**
Indicates whether there is a traffic signal at the intersection.
If such information is not available for an intersection, this property’s value is `nil`.
*/
public let trafficSignal: Bool?

/**
Indicates whether there is a stop sign at the intersection.
If such information is not available for an intersection, this property’s value is `nil`.
*/
public let stopSign: Bool?

/**
Indicates whether there is a yield sign at the intersection.
If such information is not available for an intersection, this property’s value is `nil`.
*/
public let yieldSign: Bool?
}

extension Intersection: Codable {
Expand All @@ -187,6 +223,10 @@ extension Intersection: Codable {
case restStop = "rest_stop"
case administrativeRegionIndex = "admin_index"
case geometryIndex = "geometry_index"
case railroadCrossing = "railway_crossing"
case trafficSignal = "traffic_signal"
case stopSign = "stop_sign"
case yieldSign = "yield_sign"
}

/// Used to code `Intersection.outletMapboxStreetsRoadClass`
Expand Down Expand Up @@ -328,6 +368,22 @@ extension Intersection: Codable {
try container.encode(geoIndex, forKey: .geometryIndex)
}

if let railwayCrossing = railroadCrossing {
try container.encode(railwayCrossing, forKey: .railroadCrossing)
}

if let trafficSignal = trafficSignal {
try container.encode(trafficSignal, forKey: .trafficSignal)
}

if let stopSign = stopSign {
try container.encode(stopSign, forKey: .stopSign)
}

if let yieldSign = yieldSign {
try container.encode(yieldSign, forKey: .yieldSign)
}

try encodeForeignMembers(notKeyedBy: CodingKeys.self, to: encoder)
}

Expand Down Expand Up @@ -372,6 +428,11 @@ extension Intersection: Codable {

restStop = try container.decodeIfPresent(RestStop.self, forKey: .restStop)

railroadCrossing = try container.decodeIfPresent(Bool.self, forKey: .railroadCrossing)
trafficSignal = try container.decodeIfPresent(Bool.self, forKey: .trafficSignal)
stopSign = try container.decodeIfPresent(Bool.self, forKey: .stopSign)
yieldSign = try container.decodeIfPresent(Bool.self, forKey: .yieldSign)

try decodeForeignMembers(notKeyedBy: CodingKeys.self, with: decoder)
}
}
Expand All @@ -393,6 +454,10 @@ extension Intersection: Equatable {
lhs.outletRoadClasses == rhs.outletRoadClasses &&
lhs.tollCollection == rhs.tollCollection &&
lhs.tunnelName == rhs.tunnelName &&
lhs.isUrban == rhs.isUrban
lhs.isUrban == rhs.isUrban &&
lhs.railroadCrossing == rhs.railroadCrossing &&
lhs.trafficSignal == rhs.trafficSignal &&
lhs.stopSign == rhs.stopSign &&
lhs.yieldSign == rhs.yieldSign
}
}
14 changes: 13 additions & 1 deletion Tests/MapboxDirectionsTests/IntersectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class IntersectionTests: XCTestCase {
"type": "toll_booth",
"name": "test toll booth"
],
"railway_crossing": true,
"traffic_signal": true,
"stop_sign": false,
"yield_sign": false
],
[
"out": 1,
Expand Down Expand Up @@ -59,6 +63,10 @@ class IntersectionTests: XCTestCase {
XCTAssertEqual(intersection.headings, [80.0])
XCTAssertEqual(intersection.location, LocationCoordinate2D(latitude: 52.508068, longitude: 13.426579))
XCTAssertEqual(intersection.outletMapboxStreetsRoadClass, MapboxStreetsRoadClass.streetLimited)
XCTAssertEqual(intersection.railroadCrossing, true)
XCTAssertEqual(intersection.trafficSignal, true)
XCTAssertEqual(intersection.stopSign, false)
XCTAssertEqual(intersection.yieldSign, false)
}

intersections = [
Expand All @@ -76,7 +84,11 @@ class IntersectionTests: XCTestCase {
tunnelName: nil,
restStop: nil,
isUrban: nil,
outletMapboxStreetsRoadClass: .streetLimited),
outletMapboxStreetsRoadClass: .streetLimited,
railroadCrossing: true,
trafficSignal: true,
stopSign: false,
yieldSign: false),
Intersection(location: LocationCoordinate2D(latitude: 52.508022, longitude: 13.426688),
headings: [30.0, 120.0, 300.0],
approachIndex: 2,
Expand Down
3 changes: 2 additions & 1 deletion swift-package-baseline/breakage-allowlist-path.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
API breakage: var RouteLegRefreshSource.refreshedIncidents has been added as a protocol requirement
API breakage: var RouteLegRefreshSource.refreshedIncidents has been added as a protocol requirement
API breakage: constructor Intersection.init(location:headings:approachIndex:outletIndex:outletIndexes:approachLanes:usableApproachLanes:preferredApproachLanes:usableLaneIndication:outletRoadClasses:tollCollection:tunnelName:restStop:isUrban:regionCode:outletMapboxStreetsRoadClass:) has been removed

0 comments on commit b0d779b

Please sign in to comment.