Skip to content

Commit e7acc9d

Browse files
committed
Fix turn.roads_on_the_left and turn.roads_on_the right for two-way roads #5128
1 parent b6557b8 commit e7acc9d

File tree

3 files changed

+81
-25
lines changed

3 files changed

+81
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- FIXED: Reduce copying in API parameter constructors [#5925](https://github.com/Project-OSRM/osrm-backend/pull/5925)
1010
- Misc:
1111
- CHANGED: Unify `.osrm.turn_penalites_index` dump processing same with `.osrm.turn_weight_penalties` and `.osrm.turn_duration_penalties` [#5868](https://github.com/Project-OSRM/osrm-backend/pull/5868)
12+
- FIXED: turn.roads_on_the_left not containing incoming roads and turn.roads_on_the_right not containing outgoing roads on two-way roads [#5128](https://github.com/Project-OSRM/osrm-backend/issues/5128)
1213
- Profile:
1314
- ADDED: Profile debug script which fetches a way from OSM then outputs the result of the profile. [#5908](https://github.com/Project-OSRM/osrm-backend/pull/5908)
1415
- Infrastructure

features/options/extract/turn_function.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,30 @@ Feature: Turn Function Information
180180
And stdout should contain /roads_on_the_right \[1\] speed: [0-9]+, is_incoming: true, is_outgoing: false, highway_turn_classification: 3, access_turn_classification: 0/
181181
# turning abc, give information about about db
182182
And stdout should contain /roads_on_the_left \[1\] speed: [0-9]+, is_incoming: true, is_outgoing: false, highway_turn_classification: 0, access_turn_classification: 1/
183+
184+
Scenario: Turns should have correct information of two-way roads at intersection
185+
Given the node map
186+
"""
187+
b
188+
|
189+
a-c-d
190+
|
191+
e
192+
"""
193+
And the ways
194+
| nodes | highway | oneway |
195+
| ac | motorway | yes |
196+
| cd | motorway_link | yes |
197+
| bc | trunk | yes |
198+
| cb | trunk_link | yes |
199+
| ce | primary | yes |
200+
| ec | primary_link | yes |
201+
And the data has been saved to disk
202+
203+
When I run "osrm-extract --profile {profile_file} {osm_file}"
204+
Then it should exit successfully
205+
# Turn acd
206+
# on the left there should be cb (and bc)
207+
And stdout should contain /roads_on_the_left \[1\] speed: [0-9]+, is_incoming: true, is_outgoing: true, highway_turn_classification: [0-9]+, access_turn_classification: 0, priority_class: 3/
208+
# on the right there should be ce and ec
209+
And stdout should contain /roads_on_the_right \[1\] speed: [0-9]+, is_incoming: true, is_outgoing: true, highway_turn_classification: [0-9]+, access_turn_classification: 0, priority_class: 4/

src/extractor/edge_based_graph_factory.cpp

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,15 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
714714
{
715715
++node_based_edge_counter;
716716

717-
const auto intersection_view =
718-
convertToIntersectionView(m_node_based_graph,
719-
m_edge_based_node_container,
720-
unconditional_node_restriction_map,
721-
m_barrier_nodes,
722-
edge_geometries,
723-
turn_lanes_data,
724-
incoming_edge,
725-
outgoing_edges,
726-
merged_edge_ids);
717+
const auto connected_roads =
718+
extractor::intersection::getConnectedRoads<false>(m_node_based_graph,
719+
m_edge_based_node_container,
720+
m_coordinates,
721+
m_compressed_edge_container,
722+
unconditional_node_restriction_map,
723+
m_barrier_nodes,
724+
turn_lanes_data,
725+
incoming_edge);
727726

728727
// check if this edge is part of a restriction via-way
729728
const auto is_restriction_via_edge =
@@ -746,12 +745,12 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
746745
continue;
747746

748747
const auto turn =
749-
std::find_if(intersection_view.begin(),
750-
intersection_view.end(),
748+
std::find_if(connected_roads.begin(),
749+
connected_roads.end(),
751750
[edge = outgoing_edge.edge](const auto &road) {
752751
return road.eid == edge;
753752
});
754-
OSRM_ASSERT(turn != intersection_view.end(),
753+
OSRM_ASSERT(turn != connected_roads.end(),
755754
m_coordinates[intersection_node]);
756755

757756
std::vector<ExtractionTurnLeg> road_legs_on_the_right;
@@ -760,6 +759,37 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
760759
auto get_connected_road_info = [&](const auto &connected_edge) {
761760
const auto &edge_data =
762761
m_node_based_graph.GetEdgeData(connected_edge.eid);
762+
763+
bool is_incoming, is_outgoing;
764+
if (edge_data.reversed)
765+
{
766+
// If getConnectedRoads adds reversed edge it means
767+
// this edge is incoming-only
768+
is_incoming = true;
769+
is_outgoing = false;
770+
}
771+
else
772+
{
773+
// It does not add incoming edge if there is outgoing so we should
774+
// find it ourselves
775+
is_incoming = false;
776+
auto reversed_edge = m_node_based_graph.FindEdge(
777+
m_node_based_graph.GetTarget(connected_edge.eid),
778+
intersection_node);
779+
if (reversed_edge != SPECIAL_EDGEID)
780+
{
781+
const auto &reversed_edge_data =
782+
m_node_based_graph.GetEdgeData(reversed_edge);
783+
784+
if (!reversed_edge_data.reversed)
785+
{
786+
is_incoming = true;
787+
}
788+
}
789+
790+
is_outgoing = true;
791+
}
792+
763793
return ExtractionTurnLeg(
764794
edge_data.flags.restricted,
765795
edge_data.flags.road_classification.IsMotorwayClass(),
@@ -772,54 +802,52 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
772802
edge_data.duration) *
773803
36,
774804
edge_data.flags.road_classification.GetPriority(),
775-
!connected_edge.entry_allowed ||
776-
(edge_data.flags.forward &&
777-
edge_data.flags.backward), // is incoming
778-
connected_edge.entry_allowed);
805+
is_incoming,
806+
is_outgoing);
779807
};
780808

781809
// all connected roads on the right of a u turn
782810
const auto is_uturn = guidance::getTurnDirection(turn->angle) ==
783811
guidance::DirectionModifier::UTurn;
784812
if (is_uturn)
785813
{
786-
if (turn != intersection_view.begin())
814+
if (turn != connected_roads.begin())
787815
{
788-
std::transform(intersection_view.begin() + 1,
816+
std::transform(connected_roads.begin() + 1,
789817
turn,
790818
std::back_inserter(road_legs_on_the_right),
791819
get_connected_road_info);
792820
}
793821

794822
std::transform(turn + 1,
795-
intersection_view.end(),
823+
connected_roads.end(),
796824
std::back_inserter(road_legs_on_the_right),
797825
get_connected_road_info);
798826
}
799827
else
800828
{
801-
if (intersection_view.begin() != turn)
829+
if (connected_roads.begin() != turn)
802830
{
803-
std::transform(intersection_view.begin() + 1,
831+
std::transform(connected_roads.begin() + 1,
804832
turn,
805833
std::back_inserter(road_legs_on_the_right),
806834
get_connected_road_info);
807835
}
808836
std::transform(turn + 1,
809-
intersection_view.end(),
837+
connected_roads.end(),
810838
std::back_inserter(road_legs_on_the_left),
811839
get_connected_road_info);
812840
}
813841

814-
if (is_uturn && turn != intersection_view.begin())
842+
if (is_uturn && turn != connected_roads.begin())
815843
{
816844
util::Log(logWARNING)
817845
<< "Turn is a u turn but not turning to the first connected "
818846
"edge of the intersection. Node ID: "
819847
<< intersection_node << ", OSM link: "
820848
<< toOSMLink(m_coordinates[intersection_node]);
821849
}
822-
else if (turn == intersection_view.begin() && !is_uturn)
850+
else if (turn == connected_roads.begin() && !is_uturn)
823851
{
824852
util::Log(logWARNING)
825853
<< "Turn is a u turn but not classified as a u turn. Node ID: "

0 commit comments

Comments
 (0)