-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Update name_id/name checks for empty IDs and empty strings #4684
Changes from 9 commits
2ae6361
1d62d5d
abbc2d8
178f270
4c68866
b981db2
6ead257
84d294b
00f79f3
d58414d
aad3b28
faa9ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,15 +41,14 @@ bool noIntermediaryIntersections(const RouteStep &step) | |
} | ||
|
||
// Link roads, as far as we are concerned, are short unnamed segments between to named segments. | ||
bool isLinkroad(const RouteStep &pre_link_step, | ||
const RouteStep &link_step, | ||
const RouteStep &post_link_step) | ||
bool isLinkRoad(const RouteStep &link_step, | ||
const std::string &pre_link_step_name, | ||
const std::string &post_link_step_name) | ||
{ | ||
const constexpr double MAX_LINK_ROAD_LENGTH = 2 * MAX_COLLAPSE_DISTANCE; | ||
const auto is_short = link_step.distance <= MAX_LINK_ROAD_LENGTH; | ||
const auto unnamed = link_step.name_id == EMPTY_NAMEID; | ||
const auto between_named = | ||
(pre_link_step.name_id != EMPTY_NAMEID) && (post_link_step.name_id != EMPTY_NAMEID); | ||
const auto unnamed = link_step.name.empty(); | ||
const auto between_named = !pre_link_step_name.empty() && !post_link_step_name.empty(); | ||
|
||
return is_short && unnamed && between_named && noIntermediaryIntersections(link_step); | ||
} | ||
|
@@ -164,6 +163,9 @@ bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection, | |
bool isUTurn(const RouteStepIterator step_prior_to_intersection, | ||
const RouteStepIterator step_entering_intersection, | ||
const RouteStepIterator step_leaving_intersection) | ||
// const std::string &step_prior_name, | ||
// const std::string &step_entering_name, | ||
// const std::string &step_leaving_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
{ | ||
if (!basicCollapsePreconditions( | ||
step_prior_to_intersection, step_entering_intersection, step_leaving_intersection)) | ||
|
@@ -196,9 +198,9 @@ bool isUTurn(const RouteStepIterator step_prior_to_intersection, | |
const auto only_allowed_turn = (numberOfAllowedTurns(*step_leaving_intersection) == 1) && | ||
noIntermediaryIntersections(*step_entering_intersection); | ||
|
||
return collapsable || isLinkroad(*step_prior_to_intersection, | ||
*step_entering_intersection, | ||
*step_leaving_intersection) || | ||
return collapsable || isLinkRoad(*step_entering_intersection, | ||
step_prior_to_intersection->name, | ||
step_leaving_intersection->name) || | ||
only_allowed_turn; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,7 +326,7 @@ void suppressStep(RouteStep &step_at_turn_location, RouteStep &step_after_turn_l | |
|
||
// OTHER IMPLEMENTATIONS | ||
OSRM_ATTR_WARN_UNUSED | ||
RouteSteps collapseTurnInstructions(RouteSteps steps) | ||
RouteSteps collapseTurnInstructions(RouteSteps steps, const datafacade::BaseDataFacade &facade) | ||
{ | ||
// make sure we can safely iterate over all steps (has depart/arrive with TurnType::NoTurn) | ||
BOOST_ASSERT(!hasTurnType(steps.front()) && !hasTurnType(steps.back())); | ||
|
@@ -463,6 +463,7 @@ RouteSteps collapseTurnInstructions(RouteSteps steps) | |
if (!hasWaypointType(*previous_step)) | ||
{ | ||
const auto far_back_step = findPreviousTurn(previous_step); | ||
const auto far_back_step_name = facade.GetNameForID(far_back_step->name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused, can this be removed, and then can the facade also be removed from the function signature? |
||
// due to name changes, we can find u-turns a bit late. Thats why we check far back as | ||
// well | ||
if (isUTurn(far_back_step, previous_step, current_step)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,17 +71,19 @@ TurnType::Enum IntersectionHandler::findBasicTurnType(const EdgeID via_edge, | |
if (!on_ramp && onto_ramp) | ||
return TurnType::OnRamp; | ||
|
||
const auto &in_name = | ||
const auto &in_name_id = | ||
node_data_container.GetAnnotation(node_based_graph.GetEdgeData(via_edge).annotation_data) | ||
.name_id; | ||
const auto &out_name = | ||
const auto &out_name_id = | ||
node_data_container.GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) | ||
.name_id; | ||
const auto &in_name = name_table.GetNameForID(in_name_id).to_string(); | ||
const auto &out_name = name_table.GetNameForID(out_name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to make two string copies here? Or can we already check the string view for empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea! |
||
|
||
const auto same_name = !util::guidance::requiresNameAnnounced( | ||
in_name, out_name, name_table, street_name_suffix_table); | ||
in_name_id, out_name_id, name_table, street_name_suffix_table); | ||
|
||
if (in_name != EMPTY_NAMEID && out_name != EMPTY_NAMEID && same_name) | ||
if (!in_name.empty() && !out_name.empty() && same_name) | ||
{ | ||
return TurnType::Continue; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,15 +32,17 @@ inline auto makeCheckRoadForName(const NameID name_id, | |
return [name_id, &node_based_graph, &node_data_container, &name_table, &suffix_table]( | ||
const MergableRoadDetector::MergableRoadData &road) { | ||
// since we filter here, we don't want any other name than the one we are looking for | ||
const auto road_name = | ||
const auto road_name_id = | ||
node_data_container | ||
.GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) | ||
.name_id; | ||
if (name_id == EMPTY_NAMEID || road_name == EMPTY_NAMEID) | ||
const auto road_name = name_table.GetNameForID(road_name_id).to_string(); | ||
if (name_id == EMPTY_NAMEID || road_name.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this - why to we
what will happen if the name id is invalid and we call GetNameForID on it? |
||
return true; | ||
const auto requires_announcement = | ||
util::guidance::requiresNameAnnounced(name_id, road_name, name_table, suffix_table) || | ||
util::guidance::requiresNameAnnounced(road_name, name_id, name_table, suffix_table); | ||
util::guidance::requiresNameAnnounced( | ||
name_id, road_name_id, name_table, suffix_table) || | ||
util::guidance::requiresNameAnnounced(road_name_id, name_id, name_table, suffix_table); | ||
|
||
return requires_announcement; | ||
}; | ||
|
@@ -465,16 +467,19 @@ bool MergableRoadDetector::IsTrafficIsland(const NodeID intersection_node, | |
.name_id; | ||
|
||
const auto has_required_name = [this, required_name_id](const auto edge_id) { | ||
const auto road_name = | ||
const auto road_name_id = | ||
node_data_container | ||
.GetAnnotation(node_based_graph.GetEdgeData(edge_id).annotation_data) | ||
.name_id; | ||
if (required_name_id == EMPTY_NAMEID || road_name == EMPTY_NAMEID) | ||
const auto &road_name = name_table.GetNameForID(road_name_id).to_string(); | ||
const auto &required_name = name_table.GetNameForID(required_name_id).to_string(); | ||
if (required_name_id == EMPTY_NAMEID || road_name_id == EMPTY_NAMEID || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
(required_name.empty() && road_name.empty())) | ||
return false; | ||
return !util::guidance::requiresNameAnnounced( | ||
required_name_id, road_name, name_table, street_name_suffix_table) || | ||
required_name_id, road_name_id, name_table, street_name_suffix_table) || | ||
!util::guidance::requiresNameAnnounced( | ||
road_name, required_name_id, name_table, street_name_suffix_table); | ||
road_name_id, required_name_id, name_table, street_name_suffix_table); | ||
}; | ||
|
||
/* the beautiful way would be: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,11 +379,15 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters | |
// | ||
// 7 1 | ||
// 0 | ||
const auto &first_intersection_name = | ||
name_table.GetNameForID(first_intersection_data.name_id).to_string(); | ||
const auto &second_intersection_name = | ||
name_table.GetNameForID(second_intersection_data.name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here - what happens if name id is invalid |
||
if (intersection[1].entry_allowed) | ||
{ | ||
if (isMotorwayClass(intersection[1].eid, node_based_graph) && | ||
second_intersection_data.name_id != EMPTY_NAMEID && | ||
first_intersection_data.name_id != EMPTY_NAMEID && first_second_same_name) | ||
!second_intersection_name.empty() && !first_intersection_name.empty() && | ||
first_second_same_name) | ||
{ | ||
// circular order indicates a merge to the left (0-3 onto 4 | ||
if (angularDeviation(intersection[1].angle, STRAIGHT_ANGLE) < | ||
|
@@ -407,8 +411,8 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters | |
{ | ||
BOOST_ASSERT(intersection[2].entry_allowed); | ||
if (isMotorwayClass(intersection[2].eid, node_based_graph) && | ||
second_intersection_data.name_id != EMPTY_NAMEID && | ||
first_intersection_data.name_id != EMPTY_NAMEID && first_second_same_name) | ||
!second_intersection_name.empty() && !first_intersection_name.empty() && | ||
first_second_same_name) | ||
{ | ||
// circular order (5-0) onto 4 | ||
if (angularDeviation(intersection[2].angle, STRAIGHT_ANGLE) < | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,7 +295,8 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const | |
return SPECIAL_EDGEID; | ||
} | ||
|
||
if (EMPTY_NAMEID != edge_data.name_id) | ||
const auto &edge_name = name_table.GetNameForID(edge_data.name_id).to_string(); | ||
if (!edge_name.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here |
||
{ | ||
|
||
const auto announce = [&](unsigned id) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -474,7 +474,8 @@ operator()(const NodeID /*nid*/, const EdgeID source_edge_id, Intersection inter | |
|
||
// Name mismatch: check roads at `c` and `d` for same name | ||
const auto name_mismatch = [&](const NameID road_name_id) { | ||
const auto unnamed = road_name_id == EMPTY_NAMEID; | ||
const auto &road_name = name_table.GetNameForID(road_name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
const auto unnamed = road_name.empty(); | ||
|
||
return unnamed || | ||
util::guidance::requiresNameAnnounced(road_name_id, // | ||
|
@@ -501,9 +502,13 @@ operator()(const NodeID /*nid*/, const EdgeID source_edge_id, Intersection inter | |
.name_id; | ||
const auto &sliproad_annotation = | ||
node_data_container.GetAnnotation(sliproad_edge_data.annotation_data); | ||
const auto &sliproad_name = | ||
name_table.GetNameForID(sliproad_annotation.name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
const auto &main_road_name = name_table.GetNameForID(main_road_name_id).to_string(); | ||
const auto &candidate_road_name = | ||
name_table.GetNameForID(candidate_data.name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if (!sliproad_edge_data.flags.road_classification.IsLinkClass() && | ||
sliproad_annotation.name_id != EMPTY_NAMEID && main_road_name_id != EMPTY_NAMEID && | ||
candidate_data.name_id != EMPTY_NAMEID && | ||
!sliproad_name.empty() && !main_road_name.empty() && !candidate_road_name.empty() && | ||
util::guidance::requiresNameAnnounced(main_road_name_id, | ||
sliproad_annotation.name_id, | ||
name_table, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,8 @@ bool TurnHandler::isObviousOfTwo(const EdgeID via_edge, | |
|
||
const bool turn_is_perfectly_straight = | ||
angularDeviation(road.angle, STRAIGHT_ANGLE) < std::numeric_limits<double>::epsilon(); | ||
if (via_data.name_id != EMPTY_NAMEID) | ||
const auto &via_name = name_table.GetNameForID(via_data.name_id).to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
if (!via_name.empty()) | ||
{ | ||
const auto same_name = !util::guidance::requiresNameAnnounced( | ||
via_data.name_id, road_data.name_id, name_table, street_name_suffix_table); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change here?