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

Fix mismatch of triplegedge roadclass and directededge roadclass #2507

Merged
merged 3 commits into from Jul 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -68,7 +68,8 @@
* FIXED: Zero initialize EdgeInfoInner.spare0_. Uninitialized spare0_ field produced UB which causes gurka_reproduce_tile_build to fail intermittently. [2499](https://github.com/valhalla/valhalla/pull/2499)
* FIXED: Drop unused CHANGELOG validation script, straggling NodeJS references [#2506](https://github.com/valhalla/valhalla/pull/2506)
* FIXED: Fix missing nullptr checks in graphreader and loki::Reach (causing segfault during routing with not all levels of tiles availble) [#2504](https://github.com/valhalla/valhalla/pull/2504)

* FIXED: Fix mismatch of triplegedge roadclass and directededge roadclass [#2507](https://github.com/valhalla/valhalla/pull/2507)

* **Enhancement**
* ADDED: Add explicit include for sstream to be compatible with msvc_x64 toolset. [#2449](https://github.com/valhalla/valhalla/pull/2449)
* ADDED: Add ability to provide custom implementation for candidate collection in CandidateQuery. [#2328](https://github.com/valhalla/valhalla/pull/2328)
Expand Down
2 changes: 2 additions & 0 deletions proto/trip.proto
Expand Up @@ -40,6 +40,7 @@ message TripLeg {
kDriveThruUse = 8; // Commercial drive-thru (banks/fast-food)
kCuldesacUse = 9; // Cul-de-sac (edge that forms a loop and is only
// connected at one node to another edge.
kLivingStreetUse = 10; // Shared space for cars, bikes, pedestrians

// Bicycle specific uses
kCyclewayUse = 20; // Dedicated bicycle path
Expand Down Expand Up @@ -214,6 +215,7 @@ message TripLeg {
optional bool has_time_restrictions = 43;
optional float default_speed = 44; // km/h
optional Restriction restriction = 45;
optional bool destination_only = 46;
}

message IntersectingEdge {
Expand Down
1 change: 1 addition & 0 deletions src/thor/attributes_controller.cc
Expand Up @@ -71,6 +71,7 @@ const std::unordered_map<std::string, bool> AttributesController::kDefaultAttrib
{kEdgeTruckSpeed, true},
{kEdgeTruckRoute, true},
{kEdgeDefaultSpeed, true},
{kEdgeDestinationOnly, true},

// Node keys
{kNodeIntersectingEdgeBeginHeading, true},
Expand Down
45 changes: 7 additions & 38 deletions src/thor/triplegbuilder.cc
Expand Up @@ -335,6 +335,8 @@ TripLeg_Use GetTripLegUse(const Use use) {
return TripLeg_Use_kDriveThruUse;
case Use::kCuldesac:
return TripLeg_Use_kCuldesacUse;
case Use::kLivingStreet:
return TripLeg_Use_kLivingStreetUse;
case Use::kCycleway:
return TripLeg_Use_kCyclewayUse;
case Use::kMountainBike:
Expand Down Expand Up @@ -528,43 +530,6 @@ void AddTransitNodes(TripLeg_Node* trip_node,
}
}

void SetTripEdgeRoadClass(TripLeg_Edge* trip_edge,
const DirectedEdge* directededge,
const GraphTile* graphtile,
GraphReader& graphreader) {
trip_edge->set_road_class(GetRoadClass(directededge->classification()));
// If this is a ramp it may have been reclassified in graph enhancer.
// To restore the original road class for motorway_links, we check if any of the adjacent edges is
// a motorway.
if (directededge->use() == Use::kRamp) {
const DirectedEdge* opposing_edge = graphreader.GetOpposingEdge(directededge, graphtile);
for (const auto* edge : {directededge, opposing_edge}) {
if (!edge || !graphreader.GetGraphTile(edge->endnode(), graphtile)) {
// If this edge was invalid or we couldn't get the opposing edge's tile, skip
continue;
}
// check edges leaving node
for (const auto& adjacent_edge : graphtile->GetDirectedEdges(edge->endnode())) {
if (adjacent_edge.classification() == baldr::RoadClass::kMotorway) {
trip_edge->set_road_class(valhalla::RoadClass::kMotorway);
return;
}
}
// check transition nodes too
auto transition_nodes = graphtile->GetNodeTransitions(edge->endnode());
for (const auto& transition : transition_nodes) {
auto trans_tile = graphreader.GetGraphTile(transition.endnode());
for (const auto& adjacent_edge : trans_tile->GetDirectedEdges(transition.endnode())) {
if (adjacent_edge.classification() == baldr::RoadClass::kMotorway) {
trip_edge->set_road_class(valhalla::RoadClass::kMotorway);
return;
}
}
}
}
}
}

/**
* Add trip edge. (TODO more comments)
* @param controller Controller to determine which attributes to set.
Expand Down Expand Up @@ -727,7 +692,7 @@ TripLeg_Edge* AddTripEdge(const AttributesController& controller,

// Set road class if requested
if (controller.attributes.at(kEdgeRoadClass)) {
SetTripEdgeRoadClass(trip_edge, directededge, graphtile, graphreader);
trip_edge->set_road_class(GetRoadClass(directededge->classification()));
}

// Set speed if requested
Expand Down Expand Up @@ -838,6 +803,10 @@ TripLeg_Edge* AddTripEdge(const AttributesController& controller,
trip_edge->set_surface(GetTripLegSurface(directededge->surface()));
}

if (directededge->destonly() && controller.attributes.at(kEdgeDestinationOnly)) {
trip_edge->set_destination_only(directededge->destonly());
}

// Set the mode and travel type
if (mode == sif::TravelMode::kBicycle) {
// Override bicycle mode with pedestrian if dismount flag or steps
Expand Down
44 changes: 0 additions & 44 deletions test/gurka/test_intersection_classes.cc

This file was deleted.

8 changes: 8 additions & 0 deletions valhalla/odin/enhancedtrippath.h
Expand Up @@ -339,6 +339,14 @@ class EnhancedTripLeg_Edge {
return mutable_edge_->mutable_turn_lanes();
}

bool has_restriction() const {
return mutable_edge_->has_restriction();
}

bool destination_only() const {
return mutable_edge_->destination_only();
}

bool IsUnnamed() const;

// Use
Expand Down
1 change: 1 addition & 0 deletions valhalla/thor/attributes_controller.h
Expand Up @@ -68,6 +68,7 @@ const std::string kEdgeSpeedLimit = "edge.speed_limit";
const std::string kEdgeTruckSpeed = "edge.truck_speed";
const std::string kEdgeTruckRoute = "edge.truck_route";
const std::string kEdgeDefaultSpeed = "edge.default_speed";
const std::string kEdgeDestinationOnly = "edge.destination_only";

// Node keys
const std::string kNodeIntersectingEdgeBeginHeading = "node.intersecting_edge.begin_heading";
Expand Down