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

Count actual roundabout exits, not just passed steps #4551

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions features/guidance/roundabout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,34 @@ Feature: Basic Roundabout
| from | to | route | turns | distance |
| e | k | ebds,ufghl,ufghl,jhik,jhik | depart,rstur-exit-2,exit rotary right,turn right,arrive | 189.1m |
| 1 | k | ebds,ufghl,ufghl,jhik,jhik | depart,rstur-exit-2,exit rotary right,turn right,arrive | 159.1m |


Scenario: count exit numbers properly when multiple exits from a single node
Given the node map
"""
f-----e
/ \
g--a l d-----h
\ \ /
b-----c
\\\
ijk

"""

And the ways
| nodes | highway | junction | oneway |
| abcdefa | tertiary | roundabout | yes |
| ga | tertiary | | |
| ci | tertiary | | |
| cj | tertiary | | |
| ck | tertiary | | |
| cl | tertiary | | |
| dh | tertiary | | |

When I route I should get
| from | to | route | turns |
| g | i | ga,ci,ci,ci | depart,abcdefa-exit-1,exit rotary right,arrive |
| g | j | ga,cj,cj,cj | depart,abcdefa-exit-2,exit rotary right,arrive |
| g | k | ga,ck,ck,ck | depart,abcdefa-exit-3,exit rotary right,arrive |
| g | h | ga,dh,dh,dh | depart,abcdefa-exit-5,exit rotary right,arrive |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is l decided as being the fourth exit. It looks similar to i in terms of distance from g?

65 changes: 59 additions & 6 deletions src/engine/guidance/post_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,66 @@ void processRoundaboutExits(const RouteStepIterator begin, const RouteStepIterat
return;
}

const auto passes_exit_or_leaves_roundabout = [](auto const &step) {
return staysOnRoundabout(step.maneuver.instruction) ||
leavesRoundabout(step.maneuver.instruction);
};
const auto exit = std::accumulate(begin, end, 0, [](const long a, const auto &step) {
if (staysOnRoundabout(step.maneuver.instruction))
{
// Count all the possible exits from from the step, minus one, which is the
// "continue on the roundabout" exit
const auto step_intersection = step.intersections.front();
const auto num_exits_from_step = std::count_if(std::begin(step_intersection.entry),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic doesn't work for throughabouts. If a road (bidirectional) passes through a roundabout, the exit will be counted twice.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this would need to ignore exits that cannot be entered (exit against roundabout direction)

std::end(step_intersection.entry),
[](const auto &entry) { return entry; });
// minus 1, because the step actual exit will be included, but should not
// contribute to the tally (it's the one that follows the roundabout, as we're
// staying on)
return a + num_exits_from_step - 1;
}
else if (leavesRoundabout(step.maneuver.instruction))
{
// Count all the possible exits between the exit we want to take,
// and the entry angle:
//
// f-----e
// / \
// g--a d-----h
// \ /
// b-----c---j
// \
// i
//
// If we exit the roundabout at "c", and head toward "j",
// we need to count "i" as an intersection we passed.
// However, if we exit at "c" and to go "i", "j" should
// not be included in the count.
const auto step_intersection = step.intersections.front();

auto num_exits_from_step_before_actual_exit = 0;
// TODO: how do we find the driving side for this location?
const auto right_side_driving = true;
// TODO: is it correct to reverse this for left-side-driving?
const int increment = (right_side_driving) ? -1 : 1;

// Look at each entry between the in and out positions,
// tallying them up if they're possible exits. The
// "increment" here is to enable us to go clockwise/anticlockwise
// to support left or right-sided driving
for (int pos = step_intersection.in; pos != step_intersection.out;
pos = (pos + increment < 0 ? step_intersection.entry.size() - 1
: ((pos + increment) % step_intersection.entry.size())))
{
num_exits_from_step_before_actual_exit += step_intersection.entry[pos] ? 1 : 0;
}

// exit count
const auto exit = std::count_if(begin, end, passes_exit_or_leaves_roundabout);
// Plus one, because in the above loop, we only count the exits *between*
// the entry and the exit we're actually taking, which needs to be included
// in the final tally.
return a + num_exits_from_step_before_actual_exit + 1;
}
else
{
return a;
}
});

// removes all intermediate instructions, assigns names and exit numbers
BOOST_ASSERT(leavesRoundabout(last->maneuver.instruction));
Expand Down