[Routing] Refactoring
Small fixes for review. Signed-off-by: Anton Makouski <anton.makouski@gmail.com>
This commit is contained in:
parent
525b03154b
commit
05d857163b
4 changed files with 24 additions and 18 deletions
|
@ -30,10 +30,10 @@ void CarDirectionsEngine::FixupTurns(std::vector<geometry::PointWithAltitude> co
|
|||
|
||||
void FixupCarTurns(std::vector<geometry::PointWithAltitude> const & junctions, Route::TTurns & turnsDir)
|
||||
{
|
||||
uint32_t turn_index = static_cast<uint32_t>(junctions.size() - 1);
|
||||
uint32_t turn_index = base::asserted_cast<uint32_t>(junctions.size() - 1);
|
||||
turnsDir.emplace_back(TurnItem(turn_index, CarDirection::ReachedYourDestination));
|
||||
|
||||
double const kMergeDistMeters = 15.0;
|
||||
double constexpr kMergeDistMeters = 15.0;
|
||||
// For turns that are not EnterRoundAbout/ExitRoundAbout exitNum is always equal to zero.
|
||||
// If a turn is EnterRoundAbout exitNum is a number of turns between two junctions:
|
||||
// (1) the route enters to the roundabout;
|
||||
|
@ -171,11 +171,11 @@ bool KeepRoundaboutTurnByHighwayClass(TurnCandidates const & possibleTurns,
|
|||
TurnInfo const & turnInfo, NumMwmIds const & numMwmIds)
|
||||
{
|
||||
Segment firstOutgoingSegment;
|
||||
bool const validFirstOutgoingSeg = turnInfo.m_outgoing->m_segmentRange.GetFirstSegment(numMwmIds, firstOutgoingSegment);
|
||||
turnInfo.m_outgoing->m_segmentRange.GetFirstSegment(numMwmIds, firstOutgoingSegment);
|
||||
|
||||
for (auto const & t : possibleTurns.candidates)
|
||||
{
|
||||
if (!validFirstOutgoingSeg || t.m_segment == firstOutgoingSegment)
|
||||
if (t.m_segment == firstOutgoingSegment)
|
||||
continue;
|
||||
if (t.m_highwayClass != HighwayClass::Service)
|
||||
return true;
|
||||
|
@ -268,11 +268,8 @@ bool CanDiscardTurnByHighwayClassOrAngles(CarDirection const routeDirection,
|
|||
HighwayClass outgoingRouteRoadClass = turnInfo.m_outgoing->m_highwayClass;
|
||||
HighwayClass ingoingRouteRoadClass = turnInfo.m_ingoing->m_highwayClass;
|
||||
|
||||
// The turn should be kept if there's no any information about feature id of outgoing segment
|
||||
// just to be on the safe side. It may happen in case of outgoing segment is a finish segment.
|
||||
Segment firstOutgoingSegment;
|
||||
if (!turnInfo.m_outgoing->m_segmentRange.GetFirstSegment(numMwmIds, firstOutgoingSegment))
|
||||
return false;
|
||||
turnInfo.m_outgoing->m_segmentRange.GetFirstSegment(numMwmIds, firstOutgoingSegment);
|
||||
|
||||
for (auto const & t : turnCandidates)
|
||||
{
|
||||
|
@ -280,8 +277,12 @@ bool CanDiscardTurnByHighwayClassOrAngles(CarDirection const routeDirection,
|
|||
if (t.m_segment == firstOutgoingSegment)
|
||||
continue;
|
||||
|
||||
// Min difference of route and alternative turn abs angles in degrees
|
||||
// to ignore this alternative candidate (when route goes from non-link to link).
|
||||
double constexpr kMinAbsAngleDiffForGoLink = 70.0;
|
||||
|
||||
// If route goes from non-link to link and there is not too sharp candidate then turn can't be discarded.
|
||||
if (!turnInfo.m_ingoing->m_isLink && turnInfo.m_outgoing->m_isLink && abs(t.m_angle) < abs(routeAngle) + 70)
|
||||
if (!turnInfo.m_ingoing->m_isLink && turnInfo.m_outgoing->m_isLink && abs(t.m_angle) < abs(routeAngle) + kMinAbsAngleDiffForGoLink)
|
||||
return false;
|
||||
|
||||
HighwayClass candidateRoadClass = t.m_highwayClass;
|
||||
|
|
|
@ -353,9 +353,7 @@ RouterResultCode DirectionsEngine::MakeTurnAnnotation(IndexRoadGraph::EdgeVector
|
|||
// Turns information.
|
||||
if (!junctions.empty() && skipTurnSegments == 0)
|
||||
{
|
||||
auto const outgoingSegmentDist = distance(loadedSegments.begin(), loadedSegmentIt);
|
||||
CHECK_GREATER(outgoingSegmentDist, 0, ());
|
||||
auto const outgoingSegmentIndex = static_cast<size_t>(outgoingSegmentDist);
|
||||
size_t const outgoingSegmentIndex = base::asserted_cast<size_t>(distance(loadedSegments.begin(), loadedSegmentIt));
|
||||
|
||||
TurnItem turnItem;
|
||||
turnItem.m_index = static_cast<uint32_t>(junctions.size() - 1);
|
||||
|
|
|
@ -79,7 +79,7 @@ size_t PedestrianDirectionsEngine::GetTurnDirection(IRoutingResult const & resul
|
|||
void PedestrianDirectionsEngine::FixupTurns(std::vector<geometry::PointWithAltitude> const & junctions,
|
||||
Route::TTurns & turnsDir)
|
||||
{
|
||||
uint32_t turn_index = static_cast<uint32_t>(junctions.size() - 1);
|
||||
uint32_t turn_index = base::asserted_cast<uint32_t>(junctions.size() - 1);
|
||||
turnsDir.emplace_back(TurnItem(turn_index, PedestrianDirection::ReachedYourDestination));
|
||||
|
||||
double const kMergeDistMeters = 15.0;
|
||||
|
|
|
@ -277,13 +277,18 @@ void CorrectCandidatesSegmentByOutgoing(TurnInfo const & turnInfo, Segment const
|
|||
auto it = find_if(candidates.begin(), candidates.end(), IsFirstOutgoingSeg);
|
||||
if (it == candidates.end())
|
||||
{
|
||||
auto DoesAngleMatch = [&turnAngle](TurnCandidate const & turnCandidate)
|
||||
{ return base::AlmostEqualAbs(turnCandidate.m_angle, turnAngle, 0.001) || abs(turnCandidate.m_angle) + abs(turnAngle) > 359.999; };
|
||||
// firstOutgoingSeg not found. Try to match by angle.
|
||||
auto DoesAngleMatch = [&turnAngle](TurnCandidate const & candidate)
|
||||
{
|
||||
return base::AlmostEqualAbs(candidate.m_angle, turnAngle, 0.001) || abs(candidate.m_angle) + abs(turnAngle) > 359.999;
|
||||
};
|
||||
auto it = find_if(candidates.begin(), candidates.end(), DoesAngleMatch);
|
||||
if (it != candidates.end())
|
||||
{
|
||||
// Match by angle. Update candidate's segment.
|
||||
ASSERT(it->m_segment.GetMwmId() != firstOutgoingSeg.GetMwmId(), ());
|
||||
ASSERT(it->m_segment.GetSegmentIdx() == firstOutgoingSeg.GetSegmentIdx() && it->m_segment.IsForward() == firstOutgoingSeg.IsForward(), ());
|
||||
ASSERT(it->m_segment.GetSegmentIdx() == firstOutgoingSeg.GetSegmentIdx(), ());
|
||||
ASSERT(it->m_segment.IsForward() == firstOutgoingSeg.IsForward(), ());
|
||||
it->m_segment = firstOutgoingSeg;
|
||||
}
|
||||
else if (nodes.isCandidatesAngleValid)
|
||||
|
@ -294,8 +299,10 @@ void CorrectCandidatesSegmentByOutgoing(TurnInfo const & turnInfo, Segment const
|
|||
if (candidates.size() == 1)
|
||||
{
|
||||
ASSERT(candidates.front().m_segment.GetMwmId() != firstOutgoingSeg.GetMwmId(), ());
|
||||
ASSERT(candidates.front().m_segment.GetSegmentIdx() == firstOutgoingSeg.GetSegmentIdx() && candidates.front().m_segment.IsForward() == firstOutgoingSeg.IsForward(), ());
|
||||
ASSERT(candidates.front().m_segment.GetSegmentIdx() == firstOutgoingSeg.GetSegmentIdx(), ());
|
||||
ASSERT(candidates.front().m_segment.IsForward() == firstOutgoingSeg.IsForward(), ());
|
||||
candidates.front().m_segment = firstOutgoingSeg;
|
||||
candidates.front().m_angle = turnAngle;
|
||||
nodes.isCandidatesAngleValid = true;
|
||||
LOG(LWARNING, ("but since candidates.size() == 1, this was fixed."));
|
||||
}
|
||||
|
@ -303,7 +310,7 @@ void CorrectCandidatesSegmentByOutgoing(TurnInfo const & turnInfo, Segment const
|
|||
LOG(LWARNING, ("and since candidates.size() > 1, this can't be fixed."));
|
||||
}
|
||||
}
|
||||
else
|
||||
else // firstOutgoingSeg is found.
|
||||
{
|
||||
if (nodes.isCandidatesAngleValid)
|
||||
ASSERT((base::AlmostEqualAbs(it->m_angle, turnAngle, 0.001) || abs(it->m_angle) + abs(turnAngle) > 359.999), ());
|
||||
|
|
Reference in a new issue