diff --git a/plugins/match.hpp b/plugins/match.hpp index 441bbb798..b5f398ceb 100644 --- a/plugins/match.hpp +++ b/plugins/match.hpp @@ -133,6 +133,11 @@ template class MapMatchingPlugin : public BasePlugin auto range = input_bearings.size() > 0 ? (input_bearings[current_coordinate].second ? *input_bearings[current_coordinate].second : 10 ) : 180; auto candidates = facade->NearestPhantomNodesInRange(input_coords[current_coordinate], query_radius, bearing, range); + if (candidates.size() == 0) + { + return false; + } + // sort by foward id, then by reverse id and then by distance std::sort(candidates.begin(), candidates.end(), [](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) { @@ -361,6 +366,8 @@ template class MapMatchingPlugin : public BasePlugin { current_phantom_node_pair.source_phantom = sub.nodes[i]; current_phantom_node_pair.target_phantom = sub.nodes[i + 1]; + BOOST_ASSERT(current_phantom_node_pair.source_phantom.is_valid()); + BOOST_ASSERT(current_phantom_node_pair.target_phantom.is_valid()); raw_route.segment_end_coordinates.emplace_back(current_phantom_node_pair); } search_engine_ptr->shortest_path( diff --git a/routing_algorithms/shortest_path.hpp b/routing_algorithms/shortest_path.hpp index 3357670f7..a2646c500 100644 --- a/routing_algorithms/shortest_path.hpp +++ b/routing_algorithms/shortest_path.hpp @@ -375,7 +375,15 @@ class ShortestPathRouting final search_to_reverse_node, source_phantom, target_phantom, total_distance_to_forward, total_distance_to_reverse, new_total_distance_to_forward, packed_leg_to_forward); - if (target_phantom.reverse_node_id != SPECIAL_NODEID) + // if only the reverse node is valid (e.g. when using the match plugin) we actually need to move + if (target_phantom.forward_node_id == SPECIAL_NODEID) + { + BOOST_ASSERT(target_phantom.reverse_node_id != SPECIAL_NODEID); + new_total_distance_to_reverse = new_total_distance_to_forward; + packed_leg_to_reverse = std::move(packed_leg_to_forward); + new_total_distance_to_forward = INVALID_EDGE_WEIGHT; + } + else if (target_phantom.reverse_node_id != SPECIAL_NODEID) { new_total_distance_to_reverse = new_total_distance_to_forward; packed_leg_to_reverse = packed_leg_to_forward;