From 7e0e4d98cb0afca247ed165adc2f5368f68052e3 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 17 Jan 2018 15:49:06 +0300 Subject: [PATCH] Review fixes. --- routing/bicycle_directions.cpp | 4 ++-- routing/turn_candidate.hpp | 6 +++--- routing/turns.cpp | 15 +++++++-------- routing/turns.hpp | 20 +++++++++----------- routing/turns_generator.cpp | 2 +- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 8df139863d..5822077014 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -55,7 +55,7 @@ public: m2::PointD const & junctionPoint, size_t & ingoingCount, TurnCandidates & outgoingTurns) const override { - CHECK(!segmentRange.IsClear(), ("SegmentRange presents a fake feature. ingoingPoint:", + CHECK(!segmentRange.IsEmpty(), ("SegmentRange presents a fake feature. ingoingPoint:", MercatorBounds::ToLatLon(ingoingPoint), "junctionPoint:", MercatorBounds::ToLatLon(junctionPoint))); @@ -361,7 +361,7 @@ void BicycleDirectionsEngine::FillPathSegmentsAndAdjacentEdgesMap( CHECK_EQUAL(prevSegments.size() + 1, prevJunctionSize, ()); pathSegment.m_segments = move(prevSegments); - if (!segmentRange.IsClear()) + if (!segmentRange.IsEmpty()) { auto const it = m_adjacentEdges.find(segmentRange); // A route may be build through intermediate points. So it may contain the same |segmentRange| diff --git a/routing/turn_candidate.hpp b/routing/turn_candidate.hpp index 3a448c376e..17c9cfe611 100644 --- a/routing/turn_candidate.hpp +++ b/routing/turn_candidate.hpp @@ -4,7 +4,7 @@ #include "base/math.hpp" -#include "std/vector.hpp" +#include namespace ftypes { @@ -51,7 +51,7 @@ struct TurnCandidate } }; -inline bool IsAlmostEqual(vector const & lhs, vector const & rhs) +inline bool IsAlmostEqual(std::vector const & lhs, std::vector const & rhs) { if (lhs.size() != rhs.size()) return false; @@ -66,7 +66,7 @@ inline bool IsAlmostEqual(vector const & lhs, vector candidates; + std::vector candidates; bool isCandidatesAngleValid; explicit TurnCandidates(bool angleValid = true) : isCandidatesAngleValid(angleValid) {} diff --git a/routing/turns.cpp b/routing/turns.cpp index 8d521f255c..a5c31746e7 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -3,6 +3,8 @@ #include "geometry/angles.hpp" #include "base/internal/message.hpp" +#include "base/stl_helpers.hpp" +#include "base/string_utils.hpp" #include #include @@ -93,9 +95,9 @@ void SegmentRange::Clear() m_forward = true; } -bool SegmentRange::IsClear() const +bool SegmentRange::IsEmpty() const { - return m_featureId == FeatureID() && m_startSegId == 0 && m_endSegId == 0 && m_forward; + return !m_featureId.IsValid() && m_startSegId == 0 && m_endSegId == 0 && m_forward; } FeatureID const & SegmentRange::GetFeature() const @@ -115,7 +117,7 @@ string DebugPrint(SegmentRange const & segmentRange) << ", m_startSegId = " << segmentRange.m_startSegId << ", m_endSegId = " << segmentRange.m_endSegId << ", m_forward = " << segmentRange.m_forward - << ", ]" << endl; + << "]" << endl; return out.str(); } @@ -276,11 +278,8 @@ bool ParseLanes(string lanesString, vector & lanes) if (lanesString.empty()) return false; lanes.clear(); - transform(lanesString.begin(), lanesString.end(), lanesString.begin(), - [](string::value_type c) { return tolower(c); }); - lanesString.erase( - remove_if(lanesString.begin(), lanesString.end(), [](char c) { return isspace(c); }), - lanesString.end()); + strings::AsciiToLower(lanesString); + my::EraseIf(lanesString, [](char c) { return isspace(c); }); vector SplitLanesStrings; SingleLaneInfo lane; diff --git a/routing/turns.hpp b/routing/turns.hpp index 65f2fc278e..538cb52cd9 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -23,7 +23,7 @@ struct SegmentRange bool operator==(SegmentRange const & rh) const; bool operator<(SegmentRange const & rh) const; void Clear(); - bool IsClear() const; + bool IsEmpty() const; FeatureID const & GetFeature() const; /// \returns true if the instance of SegmentRange is correct. bool IsCorrect() const; @@ -37,8 +37,6 @@ private: bool m_forward = true; // Segment direction in |m_featureId|. }; -std::string DebugPrint(SegmentRange const & segmentRange); - namespace turns { /// @todo(vbykoianko) It's a good idea to gather all the turns information into one entity. @@ -136,7 +134,7 @@ std::string DebugPrint(SingleLaneInfo const & singleLaneInfo); struct TurnItem { TurnItem() - : m_index(numeric_limits::max()), + : m_index(std::numeric_limits::max()), m_turn(CarDirection::None), m_exitNum(0), m_keepAnyway(false), @@ -164,12 +162,12 @@ struct TurnItem m_pedestrianTurn == rhs.m_pedestrianTurn; } - uint32_t m_index; /*!< Index of point on route polyline (number of segment + 1). */ - CarDirection m_turn; /*!< The turn instruction of the TurnItem */ - vector m_lanes; /*!< Lane information on the edge before the turn. */ - uint32_t m_exitNum; /*!< Number of exit on roundabout. */ - std::string m_sourceName; /*!< Name of the street which the ingoing edge belongs to */ - std::string m_targetName; /*!< Name of the street which the outgoing edge belongs to */ + uint32_t m_index; /*!< Index of point on route polyline (number of segment + 1). */ + CarDirection m_turn; /*!< The turn instruction of the TurnItem */ + std::vector m_lanes; /*!< Lane information on the edge before the turn. */ + uint32_t m_exitNum; /*!< Number of exit on roundabout. */ + std::string m_sourceName; /*!< Name of the street which the ingoing edge belongs to */ + std::string m_targetName; /*!< Name of the street which the outgoing edge belongs to */ /*! * \brief m_keepAnyway is true if the turn shall not be deleted * and shall be demonstrated to an end user. @@ -232,7 +230,7 @@ bool IsLaneWayConformedTurnDirectionApproximately(LaneWay l, CarDirection t); * Note 1: if @lanesString is empty returns false. * Note 2: @laneString is passed by value on purpose. It'll be used(changed) in the method. */ -bool ParseLanes(std::string lanesString, vector & lanes); +bool ParseLanes(std::string lanesString, std::vector & lanes); void SplitLanes(std::string const & lanesString, char delimiter, std::vector & lanes); bool ParseSingleLane(std::string const & laneString, char delimiter, TSingleLane & lane); diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 928002e1a8..7fe9df964c 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -539,7 +539,7 @@ CarDirection IntermediateDirection(const double angle) void GetTurnDirection(IRoutingResult const & result, TurnInfo & turnInfo, TurnItem & turn) { - if (!turnInfo.IsSegmentsValid() || turnInfo.m_ingoing.m_segmentRange.IsClear()) + if (!turnInfo.IsSegmentsValid() || turnInfo.m_ingoing.m_segmentRange.IsEmpty()) return; ASSERT(!turnInfo.m_ingoing.m_path.empty(), ());