From 7c3b58702852b9ff912ec54f763ef52d54ebd8c0 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Mon, 12 Sep 2016 10:08:01 +0200 Subject: [PATCH] fix looping in sliproad handler for lanes --- src/engine/api/json_factory.cpp | 3 ++- src/extractor/guidance/sliproad_handler.cpp | 15 +++++++++++++-- src/extractor/guidance/turn_analysis.cpp | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 8ebfac8b5..7e30e0004 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -235,7 +235,8 @@ util::json::Object makeRouteStep(guidance::RouteStep step, util::json::Value geo route_step.values["distance"] = std::round(step.distance * 10) / 10.; route_step.values["duration"] = std::round(step.duration * 10) / 10.; route_step.values["name"] = std::move(step.name); - if (!step.ref.empty()) route_step.values["ref"] = std::move(step.ref); + if (!step.ref.empty()) + route_step.values["ref"] = std::move(step.ref); if (!step.pronunciation.empty()) route_step.values["pronunciation"] = std::move(step.pronunciation); if (!step.destinations.empty()) diff --git a/src/extractor/guidance/sliproad_handler.cpp b/src/extractor/guidance/sliproad_handler.cpp index 169cc3efa..6c8359385 100644 --- a/src/extractor/guidance/sliproad_handler.cpp +++ b/src/extractor/guidance/sliproad_handler.cpp @@ -37,9 +37,9 @@ SliproadHandler::SliproadHandler(const IntersectionGenerator &intersection_gener // included for interface reasons only bool SliproadHandler::canProcess(const NodeID /*nid*/, const EdgeID /*via_eid*/, - const Intersection & /*intersection*/) const + const Intersection &intersection) const { - return true; + return intersection.size() > 2; } Intersection SliproadHandler:: @@ -59,6 +59,13 @@ operator()(const NodeID, const EdgeID source_edge_id, Intersection intersection) while (intersection.size() == 2) { const auto node = node_based_graph.GetTarget(in_edge); + if (node == at_node) + { + // we ended up in a loop without exit + output_node = SPECIAL_NODEID; + intersection.clear(); + return intersection; + } in_edge = intersection[1].turn.eid; output_node = node_based_graph.GetTarget(in_edge); intersection = intersection_generator(node, in_edge); @@ -82,6 +89,10 @@ operator()(const NodeID, const EdgeID source_edge_id, Intersection intersection) intersection_node_id, intersection[1], intersection_node_one); const auto intersection_following_index_two = findNextIntersectionForRoad( intersection_node_id, intersection[2], intersection_node_two); + // in case of broken roads, we return + if (intersection_following_index_one.empty() || + intersection_following_index_two.empty()) + return 0; // In case of loops at the end of the road, we will arrive back at the intersection // itself. If that is the case, the road is obviously not a sliproad. diff --git a/src/extractor/guidance/turn_analysis.cpp b/src/extractor/guidance/turn_analysis.cpp index 99c081742..50b496ca1 100644 --- a/src/extractor/guidance/turn_analysis.cpp +++ b/src/extractor/guidance/turn_analysis.cpp @@ -94,7 +94,8 @@ Intersection TurnAnalysis::assignTurnTypes(const NodeID from_nid, } } // Handle sliproads - intersection = sliproad_handler(from_nid, via_eid, std::move(intersection)); + if (sliproad_handler.canProcess(from_nid, via_eid, intersection)) + intersection = sliproad_handler(from_nid, via_eid, std::move(intersection)); // Turn On Ramps Into Off Ramps, if we come from a motorway-like road if (node_based_graph.GetEdgeData(via_eid).road_classification.IsMotorwayClass())