From 0bada235621816aa94ae61f2e76db3328e1379bd Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 22 Feb 2018 16:37:37 +0300 Subject: [PATCH] Review fixes. --- .../routing_integration_tests/turn_test.cpp | 4 +- routing/turn_candidate.hpp | 24 +++++----- routing/turns_generator.cpp | 44 ++++++++----------- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/routing/routing_integration_tests/turn_test.cpp b/routing/routing_integration_tests/turn_test.cpp index ae99b2853f..b4404dd478 100644 --- a/routing/routing_integration_tests/turn_test.cpp +++ b/routing/routing_integration_tests/turn_test.cpp @@ -586,7 +586,7 @@ UNIT_TEST(NetherlandsGorinchemBridgeTest) integration::TestTurnCount(route, 0 /* expectedTurnCount */); } -UNIT_TEST(RussiaVoronigProspTrudaTest) +UNIT_TEST(RussiaVoronezhProspTrudaTest) { TRouteResult const routeResult = integration::CalculateRoute(integration::GetVehicleComponents(), @@ -795,7 +795,7 @@ UNIT_TEST(GermanyRaunheimAirportTest) integration::GetNthTurn(route, 0).TestValid().TestDirection(CarDirection::TurnSlightRight); } -UNIT_TEST(BelorussianMinskTest) +UNIT_TEST(BelorussiaMinskTest) { TRouteResult const routeResult = integration::CalculateRoute(integration::GetVehicleComponents(), diff --git a/routing/turn_candidate.hpp b/routing/turn_candidate.hpp index dd83385534..ab54e2707a 100644 --- a/routing/turn_candidate.hpp +++ b/routing/turn_candidate.hpp @@ -16,30 +16,28 @@ namespace routing { namespace turns { -/*! - * \brief The TurnCandidate struct contains information about possible ways from a junction. - */ +/// \brief The TurnCandidate struct contains information about possible ways from a junction. struct TurnCandidate { -/// angle is an angle of the turn in degrees. It means angle is 180 minus -/// an angle between the current edge and the edge of the candidate. A counterclockwise rotation. -/// The current edge is an edge which belongs the route and located before the junction. -/// angle belongs to the range [-180; 180]; + /// |m_angle| is the angle of the turn in degrees. It means the angle is 180 minus + /// the angle between the current edge and the edge of the candidate. A counterclockwise rotation. + /// The current edge is an edge which belongs to the route and is located before the junction. + /// |m_angle| belongs to the range [-180; 180]; double m_angle; -/// |m_segment| is a first segment of a possible way from the junction. + /// |m_segment| is the first segment of a possible way from the junction. Segment m_segment; -/// \brief highwayClass field for the road class caching. Because feature reading is a long -/// function. + /// \brief highwayClass field for the road class caching. Because feature reading is a long + /// function. ftypes::HighwayClass m_highwayClass; -/// If |isLink| is true than the turn candidate is a link. + /// If |isLink| is true then the turn candidate is a link. bool m_isLink; - TurnCandidate(double a, Segment const & segment, ftypes::HighwayClass c, bool isLink) - : m_angle(a), m_segment(segment), m_highwayClass(c), m_isLink(isLink) + TurnCandidate(double angle, Segment const & segment, ftypes::HighwayClass c, bool isLink) + : m_angle(angle), m_segment(segment), m_highwayClass(c), m_isLink(isLink) { } diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 0daaffa7d1..299efe29f3 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -111,6 +111,13 @@ bool KeepRoundaboutTurnByHighwayClass(CarDirection turn, TurnCandidates const & return false; } +bool DoAllTurnCandidatesGoAlmostStraight(vector const & candidates) +{ + return all_of(candidates.cbegin(), candidates.cend(), [](TurnCandidate const & c) { + return IsGoStraightOrSlightTurn(IntermediateDirection(c.m_angle)); + }); +} + /// \brief Analyzes its args and makes a decision if it's possible to have a turn at this junction /// or not. /// \returns true if based on this analysis there's no turn at this junction and @@ -127,24 +134,12 @@ bool DiscardTurnByIngoingAndOutgoingEdges(CarDirection intermediateDirection, bo } // Checks if all turn candidates go straight or make a slight turn to left or to right. - bool otherTurnCandidatesGoAlmostStraight = true; - if (turnCandidates.isCandidatesAngleValid) - { - for (auto const & c : turnCandidates.candidates) - { - if (!IsGoStraightOrSlightTurn(IntermediateDirection(c.m_angle))) - { - otherTurnCandidatesGoAlmostStraight = false; - break; - } - } - } - else - { - otherTurnCandidatesGoAlmostStraight = false; - } + bool turnCandidatesGoAlmostStraight = + turnCandidates.isCandidatesAngleValid + ? DoAllTurnCandidatesGoAlmostStraight(turnCandidates.candidates) + : false; - if (otherTurnCandidatesGoAlmostStraight) + if (turnCandidatesGoAlmostStraight) return !hasMultiTurns; return ((!hasMultiTurns && IsGoStraightOrSlightTurn(intermediateDirection)) || @@ -290,15 +285,15 @@ size_t GetOutgoingPointIndex(const size_t start, const size_t end, const size_t return end > start ? start + i : start - i; } -size_t GetLinkNumber(vector const & candidates) +size_t GetLinkCount(vector const & candidates) { - size_t candidateLinkNumber = 0; + size_t numLinks = 0; for (auto const & c : candidates) { if (c.m_isLink) - ++candidateLinkNumber; + ++numLinks; } - return candidateLinkNumber; + return numLinks; } } // namespace @@ -601,7 +596,7 @@ CarDirection IntermediateDirection(const double angle) return FindDirectionByAngle(kLowerBounds, angle); } -/// \returns true if one of turn candidates goes along ingoing route segment and false otherwise. +/// \returns true iff one of the turn candidates goes along the ingoing route segment. bool OneOfTurnCandidatesGoesAlongIngoingSegment(NumMwmIds const & numMwmIds, TurnCandidates const & turnCandidates, TurnInfo const & turnInfo) @@ -613,7 +608,7 @@ bool OneOfTurnCandidatesGoesAlongIngoingSegment(NumMwmIds const & numMwmIds, for (auto const & c : turnCandidates.candidates) { if (c.m_segment.IsInverse(ingoingSegment)) - return true; // An inverse segment is found. + return true; } return false; } @@ -737,8 +732,7 @@ void GetTurnDirection(IRoutingResult const & result, NumMwmIds const & numMwmIds if (!turnInfo.m_ingoing.m_isLink && !turnInfo.m_outgoing.m_isLink && turnInfo.m_ingoing.m_highwayClass == turnInfo.m_outgoing.m_highwayClass) { - size_t const candidateLinkNumber = GetLinkNumber(nodes.candidates); - if (candidateLinkNumber + 1 == nodes.candidates.size()) + if (GetLinkCount(nodes.candidates) + 1 == nodes.candidates.size()) { turn.m_turn = CarDirection::None; return;