Merge pull request #10028 from bykoianko/master-two-straight-alternatives

[routing] Straight turn correction in case of two go straight or slight ways out.
This commit is contained in:
gmoryes 2018-12-12 11:07:11 +03:00 committed by GitHub
commit b68f1e4efa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 3 deletions

View file

@ -542,7 +542,7 @@ UNIT_TEST(RussiaMoscowSvobodaStTest)
TEST_EQUAL(result, RouterResultCode::NoError, ());
integration::TestTurnCount(route, 1 /* expectedTurnCount */);
integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::GoStraight);
integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnSlightLeft);
}
UNIT_TEST(RussiaTiinskTest)
@ -766,7 +766,7 @@ UNIT_TEST(NetherlandsBarneveldTest)
TEST_EQUAL(result, RouterResultCode::NoError, ());
integration::TestTurnCount(route, 1 /* expectedTurnCount */);
integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::GoStraight);
integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnSlightRight);
}
UNIT_TEST(GermanyRaunheimAirportTest)
@ -1011,3 +1011,18 @@ UNIT_TEST(RussiaMoscowTTKNoGoStraightTurnTest)
TEST_EQUAL(result, RouterResultCode::NoError, ());
integration::TestTurnCount(route, 0 /* expectedTurnCount */);
}
UNIT_TEST(RussiaMoscowLeninskyProsp2Test)
{
TRouteResult const routeResult =
integration::CalculateRoute(integration::GetVehicleComponents<VehicleType::Car>(),
MercatorBounds::FromLatLon(55.80376, 37.52048), {0., 0.},
MercatorBounds::FromLatLon(55.80442, 37.51802));
Route const & route = *routeResult.first;
RouterResultCode const result = routeResult.second;
TEST_EQUAL(result, RouterResultCode::NoError, ());
integration::TestTurnCount(route, 1 /* expectedTurnCount */);
integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnSlightRight);
}

View file

@ -509,6 +509,23 @@ bool GetPrevInSegmentRoutePoint(RoutePointIndex const & index, RoutePointIndex &
nextIndex = {index.m_segmentIndex, index.m_pathIndex - 1};
return true;
}
/*!
* \brief Corrects |turn.m_turn| if |turn.m_turn == CarDirection::GoStraight| and there're only
* two ways out from this junction. In that case the other way (the way which is not covered by
* the route) is checked. If the other way is "go straight" or "slight turn", turn.m_turn is set
* to |turnToSet|.
*/
void GoStraightCorrection(TurnCandidate const & notRouteCandidate, CarDirection turnToSet,
TurnItem & turn)
{
CHECK_EQUAL(turn.m_turn, CarDirection::GoStraight, ());
if (!IsGoStraightOrSlightTurn(IntermediateDirection(notRouteCandidate.m_angle)))
return;
turn.m_turn = turnToSet;
}
} // namespace
namespace routing
@ -991,7 +1008,27 @@ void GetTurnDirection(IRoutingResult const & result, size_t outgoingSegmentIndex
{
if (!hasMultiTurns)
turn.m_turn = CarDirection::None;
return;
// Note. If the turn direction is |CarDirection::GoStraight| and there's only one extra way out
// from the junction the direction may be corrected in some cases. So two turn candidates
// (one for the route and an extra one) require special processing.
if (nodes.candidates.size() != 2)
return;
if (nodes.candidates.front().m_segment == firstOutgoingSeg)
{
// The route goes along the leftmost candidate.
GoStraightCorrection(nodes.candidates.back(), CarDirection::TurnSlightLeft, turn);
}
else if (nodes.candidates.back().m_segment == firstOutgoingSeg)
{
// The route goes along the rightmost candidate.
GoStraightCorrection(nodes.candidates.front(), CarDirection::TurnSlightRight, turn);
}
// Note. It's possible that |firstOutgoingSeg| is not contained in |nodes.candidates|.
// It may happened if |firstOutgoingSeg| and candidates in |nodes.candidates| are
// from different mwms.
}
}