Skip to content

Commit 6503461

Browse files
committed
check for empty name_id before getting data
1 parent bd427e9 commit 6503461

File tree

10 files changed

+153
-130
lines changed

10 files changed

+153
-130
lines changed

include/engine/api/route_api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class RouteAPI : public BaseAPI
173173

174174
guidance::trimShortSegments(steps, leg_geometry);
175175
leg.steps = guidance::handleRoundabouts(std::move(steps));
176-
leg.steps = guidance::collapseTurnInstructions(std::move(leg.steps), facade);
176+
leg.steps = guidance::collapseTurnInstructions(std::move(leg.steps));
177177
leg.steps = guidance::anticipateLaneChange(std::move(leg.steps));
178178
leg.steps = guidance::buildIntersections(std::move(leg.steps));
179179
leg.steps = guidance::suppressShortNameSegments(std::move(leg.steps));

include/engine/guidance/collapse_turns.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ namespace guidance
2020
// Collapsing such turns into a single turn instruction, we give a clearer
2121
// set of instructionst that is not cluttered by unnecessary turns/name changes.
2222
OSRM_ATTR_WARN_UNUSED
23-
std::vector<RouteStep> collapseTurnInstructions(std::vector<RouteStep> steps,
24-
const datafacade::BaseDataFacade &facade);
23+
std::vector<RouteStep> collapseTurnInstructions(std::vector<RouteStep> steps);
2524

2625
// A combined turn is a set of two instructions that actually form a single turn, as far as we
2726
// perceive it. A u-turn consisting of two left turns is one such example. But there are also lots

src/engine/guidance/collapse_scenario_detection.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ bool noIntermediaryIntersections(const RouteStep &step)
4141
}
4242

4343
// Link roads, as far as we are concerned, are short unnamed segments between to named segments.
44-
bool isLinkRoad(const RouteStep &link_step,
45-
const std::string &pre_link_step_name,
46-
const std::string &post_link_step_name)
44+
bool isLinkRoad(const RouteStep &pre_link_step,
45+
const RouteStep &link_step,
46+
const RouteStep &post_link_step)
4747
{
4848
const constexpr double MAX_LINK_ROAD_LENGTH = 2 * MAX_COLLAPSE_DISTANCE;
4949
const auto is_short = link_step.distance <= MAX_LINK_ROAD_LENGTH;
5050
const auto unnamed = link_step.name.empty();
51-
const auto between_named = !pre_link_step_name.empty() && !post_link_step_name.empty();
51+
const auto between_named = !pre_link_step.name.empty() && !post_link_step.name.empty();
5252

5353
return is_short && unnamed && between_named && noIntermediaryIntersections(link_step);
5454
}
@@ -163,9 +163,6 @@ bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection,
163163
bool isUTurn(const RouteStepIterator step_prior_to_intersection,
164164
const RouteStepIterator step_entering_intersection,
165165
const RouteStepIterator step_leaving_intersection)
166-
// const std::string &step_prior_name,
167-
// const std::string &step_entering_name,
168-
// const std::string &step_leaving_name)
169166
{
170167
if (!basicCollapsePreconditions(
171168
step_prior_to_intersection, step_entering_intersection, step_leaving_intersection))
@@ -198,9 +195,9 @@ bool isUTurn(const RouteStepIterator step_prior_to_intersection,
198195
const auto only_allowed_turn = (numberOfAllowedTurns(*step_leaving_intersection) == 1) &&
199196
noIntermediaryIntersections(*step_entering_intersection);
200197

201-
return collapsable || isLinkRoad(*step_entering_intersection,
202-
step_prior_to_intersection->name,
203-
step_leaving_intersection->name) ||
198+
return collapsable || isLinkRoad(*step_prior_to_intersection,
199+
*step_entering_intersection,
200+
*step_leaving_intersection) ||
204201
only_allowed_turn;
205202
}
206203

src/engine/guidance/collapse_turns.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void suppressStep(RouteStep &step_at_turn_location, RouteStep &step_after_turn_l
326326

327327
// OTHER IMPLEMENTATIONS
328328
OSRM_ATTR_WARN_UNUSED
329-
RouteSteps collapseTurnInstructions(RouteSteps steps, const datafacade::BaseDataFacade &facade)
329+
RouteSteps collapseTurnInstructions(RouteSteps steps)
330330
{
331331
// make sure we can safely iterate over all steps (has depart/arrive with TurnType::NoTurn)
332332
BOOST_ASSERT(!hasTurnType(steps.front()) && !hasTurnType(steps.back()));
@@ -464,7 +464,6 @@ RouteSteps collapseTurnInstructions(RouteSteps steps, const datafacade::BaseData
464464
if (!hasWaypointType(*previous_step))
465465
{
466466
const auto far_back_step = findPreviousTurn(previous_step);
467-
const auto far_back_step_name = facade.GetNameForID(far_back_step->name_id).to_string();
468467
// due to name changes, we can find u-turns a bit late. Thats why we check far back as
469468
// well
470469
if (isUTurn(far_back_step, previous_step, current_step))

src/extractor/guidance/intersection_handler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ TurnType::Enum IntersectionHandler::findBasicTurnType(const EdgeID via_edge,
7777
const auto &out_name_id =
7878
node_data_container.GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data)
7979
.name_id;
80-
const auto &in_name = name_table.GetNameForID(in_name_id).to_string();
81-
const auto &out_name = name_table.GetNameForID(out_name_id).to_string();
80+
const auto &in_name_empty = name_table.GetNameForID(in_name_id).to_string().empty();
81+
const auto &out_name_empty = name_table.GetNameForID(out_name_id).to_string().empty();
8282

8383
const auto same_name = !util::guidance::requiresNameAnnounced(
8484
in_name_id, out_name_id, name_table, street_name_suffix_table);
8585

86-
if (!in_name.empty() && !out_name.empty() && same_name)
86+
if (!in_name_empty && !out_name_empty && same_name)
8787
{
8888
return TurnType::Continue;
8989
}

src/extractor/guidance/mergable_road_detector.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace guidance
2323
namespace
2424
{
2525
// check a connected road for equality of a name
26+
// returns 'true' if no equality because this is used as a filter elsewhere, i.e. filter if fn
27+
// returns 'true'
2628
inline auto makeCheckRoadForName(const NameID name_id,
2729
const util::NodeBasedDynamicGraph &node_based_graph,
2830
const EdgeBasedNodeDataContainer &node_data_container,
@@ -36,8 +38,11 @@ inline auto makeCheckRoadForName(const NameID name_id,
3638
node_data_container
3739
.GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data)
3840
.name_id;
39-
const auto road_name = name_table.GetNameForID(road_name_id).to_string();
40-
if (name_id == EMPTY_NAMEID || road_name.empty())
41+
if (name_id == EMPTY_NAMEID || road_name_id == EMPTY_NAMEID)
42+
return true;
43+
const auto road_name_empty = name_table.GetNameForID(road_name_id).to_string().empty();
44+
const auto in_name_empty = name_table.GetNameForID(name_id).to_string().empty();
45+
if (in_name_empty || road_name_empty)
4146
return true;
4247
const auto requires_announcement =
4348
util::guidance::requiresNameAnnounced(
@@ -465,16 +470,20 @@ bool MergableRoadDetector::IsTrafficIsland(const NodeID intersection_node,
465470
node_data_container
466471
.GetAnnotation(node_based_graph.GetEdgeData(range.front()).annotation_data)
467472
.name_id;
473+
if (required_name_id == EMPTY_NAMEID)
474+
return false;
468475

469476
const auto has_required_name = [this, required_name_id](const auto edge_id) {
470477
const auto road_name_id =
471478
node_data_container
472479
.GetAnnotation(node_based_graph.GetEdgeData(edge_id).annotation_data)
473480
.name_id;
474-
const auto &road_name = name_table.GetNameForID(road_name_id).to_string();
475-
const auto &required_name = name_table.GetNameForID(required_name_id).to_string();
476-
if (required_name_id == EMPTY_NAMEID || road_name_id == EMPTY_NAMEID ||
477-
(required_name.empty() && road_name.empty()))
481+
if (road_name_id == EMPTY_NAMEID)
482+
return false;
483+
const auto &road_name_empty = name_table.GetNameForID(road_name_id).to_string().empty();
484+
const auto &required_name_empty =
485+
name_table.GetNameForID(required_name_id).to_string().empty();
486+
if (required_name_empty && road_name_empty)
478487
return false;
479488
return !util::guidance::requiresNameAnnounced(
480489
required_name_id, road_name_id, name_table, street_name_suffix_table) ||

src/extractor/guidance/motorway_handler.cpp

Lines changed: 99 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -361,111 +361,120 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters
361361
node_based_graph.GetEdgeData(intersection[2].eid).annotation_data);
362362
const auto &first_intersection_data = node_data_container.GetAnnotation(
363363
node_based_graph.GetEdgeData(intersection[1].eid).annotation_data);
364-
const auto first_second_same_name =
365-
!util::guidance::requiresNameAnnounced(second_intersection_data.name_id,
366-
first_intersection_data.name_id,
367-
name_table,
368-
street_name_suffix_table);
369-
370-
// merging onto a passing highway / or two ramps merging onto the same highway
371-
if (num_valid_turns == 1)
364+
if (first_intersection_data.name_id == EMPTY_NAMEID ||
365+
second_intersection_data.name_id == EMPTY_NAMEID)
372366
{
373-
BOOST_ASSERT(!intersection[0].entry_allowed);
374-
// check order of highways
375-
// 4
376-
// 5 3
377-
//
378-
// 6 2
379-
//
380-
// 7 1
381-
// 0
382-
const auto &first_intersection_name =
383-
name_table.GetNameForID(first_intersection_data.name_id).to_string();
384-
const auto &second_intersection_name =
385-
name_table.GetNameForID(second_intersection_data.name_id).to_string();
386-
if (intersection[1].entry_allowed)
367+
return fallback(std::move(intersection));
368+
}
369+
else
370+
{
371+
const auto first_second_same_name =
372+
!util::guidance::requiresNameAnnounced(second_intersection_data.name_id,
373+
first_intersection_data.name_id,
374+
name_table,
375+
street_name_suffix_table);
376+
377+
// merging onto a passing highway / or two ramps merging onto the same highway
378+
if (num_valid_turns == 1)
387379
{
388-
if (isMotorwayClass(intersection[1].eid, node_based_graph) &&
389-
!second_intersection_name.empty() && !first_intersection_name.empty() &&
390-
first_second_same_name)
380+
BOOST_ASSERT(!intersection[0].entry_allowed);
381+
// check order of highways
382+
// 4
383+
// 5 3
384+
//
385+
// 6 2
386+
//
387+
// 7 1
388+
// 0
389+
const auto &first_intersection_name =
390+
name_table.GetNameForID(first_intersection_data.name_id).to_string();
391+
const auto &second_intersection_name =
392+
name_table.GetNameForID(second_intersection_data.name_id).to_string();
393+
if (intersection[1].entry_allowed)
391394
{
392-
// circular order indicates a merge to the left (0-3 onto 4
393-
if (angularDeviation(intersection[1].angle, STRAIGHT_ANGLE) <
394-
2 * NARROW_TURN_ANGLE)
395-
intersection[1].instruction = {TurnType::Merge,
396-
DirectionModifier::SlightLeft};
397-
else // fallback
398-
intersection[1].instruction = {TurnType::Merge,
399-
getTurnDirection(intersection[1].angle)};
395+
if (isMotorwayClass(intersection[1].eid, node_based_graph) &&
396+
!second_intersection_name.empty() && !first_intersection_name.empty() &&
397+
first_second_same_name)
398+
{
399+
// circular order indicates a merge to the left (0-3 onto 4
400+
if (angularDeviation(intersection[1].angle, STRAIGHT_ANGLE) <
401+
2 * NARROW_TURN_ANGLE)
402+
intersection[1].instruction = {TurnType::Merge,
403+
DirectionModifier::SlightLeft};
404+
else // fallback
405+
intersection[1].instruction = {TurnType::Merge,
406+
getTurnDirection(intersection[1].angle)};
407+
}
408+
else // passing by the end of a motorway
409+
{
410+
intersection[1].instruction =
411+
getInstructionForObvious(intersection.size(),
412+
via_eid,
413+
isThroughStreet(1, intersection),
414+
intersection[1]);
415+
}
400416
}
401-
else // passing by the end of a motorway
417+
else
402418
{
403-
intersection[1].instruction =
404-
getInstructionForObvious(intersection.size(),
405-
via_eid,
406-
isThroughStreet(1, intersection),
407-
intersection[1]);
419+
BOOST_ASSERT(intersection[2].entry_allowed);
420+
if (isMotorwayClass(intersection[2].eid, node_based_graph) &&
421+
!second_intersection_name.empty() && !first_intersection_name.empty() &&
422+
first_second_same_name)
423+
{
424+
// circular order (5-0) onto 4
425+
if (angularDeviation(intersection[2].angle, STRAIGHT_ANGLE) <
426+
2 * NARROW_TURN_ANGLE)
427+
intersection[2].instruction = {TurnType::Merge,
428+
DirectionModifier::SlightRight};
429+
else // fallback
430+
intersection[2].instruction = {TurnType::Merge,
431+
getTurnDirection(intersection[2].angle)};
432+
}
433+
else // passing the end of a highway
434+
{
435+
intersection[2].instruction =
436+
getInstructionForObvious(intersection.size(),
437+
via_eid,
438+
isThroughStreet(2, intersection),
439+
intersection[2]);
440+
}
408441
}
409442
}
410443
else
411444
{
445+
BOOST_ASSERT(num_valid_turns == 2);
446+
// UTurn on ramps is not possible
447+
BOOST_ASSERT(!intersection[0].entry_allowed);
448+
BOOST_ASSERT(intersection[1].entry_allowed);
412449
BOOST_ASSERT(intersection[2].entry_allowed);
413-
if (isMotorwayClass(intersection[2].eid, node_based_graph) &&
414-
!second_intersection_name.empty() && !first_intersection_name.empty() &&
415-
first_second_same_name)
416-
{
417-
// circular order (5-0) onto 4
418-
if (angularDeviation(intersection[2].angle, STRAIGHT_ANGLE) <
419-
2 * NARROW_TURN_ANGLE)
420-
intersection[2].instruction = {TurnType::Merge,
421-
DirectionModifier::SlightRight};
422-
else // fallback
423-
intersection[2].instruction = {TurnType::Merge,
424-
getTurnDirection(intersection[2].angle)};
425-
}
426-
else // passing the end of a highway
427-
{
428-
intersection[2].instruction =
429-
getInstructionForObvious(intersection.size(),
430-
via_eid,
431-
isThroughStreet(2, intersection),
432-
intersection[2]);
433-
}
434-
}
435-
}
436-
else
437-
{
438-
BOOST_ASSERT(num_valid_turns == 2);
439-
// UTurn on ramps is not possible
440-
BOOST_ASSERT(!intersection[0].entry_allowed);
441-
BOOST_ASSERT(intersection[1].entry_allowed);
442-
BOOST_ASSERT(intersection[2].entry_allowed);
443-
// two motorways starting at end of ramp (fork)
444-
// M M
445-
// \ /
446-
// |
447-
// R
448-
if (isMotorwayClass(intersection[1].eid, node_based_graph) &&
449-
isMotorwayClass(intersection[2].eid, node_based_graph))
450-
{
451-
assignFork(via_eid, intersection[2], intersection[1]);
452-
}
453-
else
454-
{
455-
// continued ramp passing motorway entry
456-
// M R
457-
// M R
458-
// | /
450+
// two motorways starting at end of ramp (fork)
451+
// M M
452+
// \ /
453+
// |
459454
// R
460-
if (isMotorwayClass(intersection[1].eid, node_based_graph))
455+
if (isMotorwayClass(intersection[1].eid, node_based_graph) &&
456+
isMotorwayClass(intersection[2].eid, node_based_graph))
461457
{
462-
intersection[1].instruction = {TurnType::Turn, DirectionModifier::SlightRight};
463-
intersection[2].instruction = {TurnType::Continue,
464-
DirectionModifier::SlightLeft};
458+
assignFork(via_eid, intersection[2], intersection[1]);
465459
}
466460
else
467461
{
468-
assignFork(via_eid, intersection[2], intersection[1]);
462+
// continued ramp passing motorway entry
463+
// M R
464+
// M R
465+
// | /
466+
// R
467+
if (isMotorwayClass(intersection[1].eid, node_based_graph))
468+
{
469+
intersection[1].instruction = {TurnType::Turn,
470+
DirectionModifier::SlightRight};
471+
intersection[2].instruction = {TurnType::Continue,
472+
DirectionModifier::SlightLeft};
473+
}
474+
else
475+
{
476+
assignFork(via_eid, intersection[2], intersection[1]);
477+
}
469478
}
470479
}
471480
}

0 commit comments

Comments
 (0)