-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Ensure u-turn exists in intersection view #6376
Merged
mjjbell
merged 1 commit into
Project-OSRM:master
from
mjjbell:mbell/fix_intersection_uturn
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@routing @foot | ||
Feature: Foot - Intersections | ||
|
||
Background: | ||
Given the profile "foot" | ||
Given a grid size of 2 meters | ||
|
||
# https://github.com/Project-OSRM/osrm-backend/issues/6218 | ||
Scenario: Foot - Handles non-planar intersections | ||
Given the node map | ||
|
||
""" | ||
f | ||
| | ||
a | ||
| | ||
b---c---d | ||
| | ||
e | ||
""" | ||
|
||
And the ways | ||
| nodes | highway | foot | layer | | ||
| ac | footway | yes | 0 | | ||
| bc | footway | yes | 0 | | ||
| cd | footway | yes | 0 | | ||
| cef | footway | yes | 1 | | ||
|
||
When I route I should get | ||
| from | to | route | | ||
| a | d | ac,cd,cd | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -617,12 +617,13 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr | |
std::vector<IntersectionViewDataWithAngle> pre_intersection_view; | ||
IntersectionViewData uturn{{SPECIAL_EDGEID, 0., 0., 0.}, false, 0.}; | ||
std::size_t allowed_uturns_number = 0; | ||
|
||
const auto is_uturn = [](const auto angle) { | ||
return std::fabs(angle) < std::numeric_limits<double>::epsilon(); | ||
}; | ||
|
||
for (const auto &outgoing_edge : outgoing_edges) | ||
{ | ||
const auto is_uturn = [](const auto angle) { | ||
return std::fabs(angle) < std::numeric_limits<double>::epsilon(); | ||
}; | ||
|
||
const auto edge_it = findEdge(edge_geometries, outgoing_edge.edge); | ||
const auto is_merged = merged_edges.count(outgoing_edge.edge) != 0; | ||
const auto is_turn_allowed = intersection::isTurnAllowed(graph, | ||
|
@@ -678,6 +679,7 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr | |
BOOST_ASSERT(uturn.eid != SPECIAL_EDGEID); | ||
if (uturn.entry_allowed || allowed_uturns_number == 0) | ||
{ // Add the true U-turn if it is allowed or no other U-turns found | ||
BOOST_ASSERT(uturn.angle == 0.); | ||
pre_intersection_view.insert(pre_intersection_view.begin(), {uturn, 0}); | ||
} | ||
|
||
|
@@ -706,6 +708,22 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr | |
} | ||
} | ||
|
||
auto no_uturn = std::none_of(pre_intersection_view.begin(), | ||
pre_intersection_view.end(), | ||
[&is_uturn](const IntersectionViewDataWithAngle &road) { | ||
return is_uturn(road.first.angle); | ||
}); | ||
// After all of this, if we now don't have a u-turn, let's add one to the intersection. | ||
// This is a hack to fix the triggered assertion ( see: | ||
// https://github.com/Project-OSRM/osrm-backend/issues/6218 ). Ideally we would fix this more | ||
// robustly, but this will require overhauling all of the intersection logic. | ||
if (no_uturn) | ||
{ | ||
BOOST_ASSERT(!uturn.entry_allowed && allowed_uturns_number > 0); | ||
BOOST_ASSERT(uturn.angle == 0.); | ||
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 comment as above. The other assertion is because we only manually insert here if we didn't above. |
||
pre_intersection_view.insert(pre_intersection_view.begin(), {uturn, 0}); | ||
} | ||
|
||
// Copy intersection view data | ||
IntersectionView intersection_view; | ||
intersection_view.reserve(pre_intersection_view.size()); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
angle
is the perceived angle between the incoming and outgoing edges at the intersection. It can differ from the real angle because it does smart stuff like look further ahead down the road to understand where we're actually heading.For the u-turn incoming/outgoing pair along the same edge, any changes in angle will always match, so the difference remains
0.
. This is the important assumption that by adding it here guarantees we always have a 0° turn in the intersection view.