From e1c98cd4f9a87f1145fcea943a235b7bfd721d48 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Mon, 16 May 2016 15:44:00 +0300 Subject: [PATCH] [bicycle routing] Calling FeaturesLoaderGuard constructor if it's needed. --- routing/bicycle_directions.cpp | 101 +++++++++++++++--------------- routing/bicycle_directions.hpp | 10 ++- routing/pedestrian_directions.cpp | 6 +- routing/turn_candidate.hpp | 2 +- routing/turns.hpp | 2 +- 5 files changed, 66 insertions(+), 55 deletions(-) diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index ffdb95c67e..c68c9c2c49 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -43,7 +43,7 @@ public: ingoingCount = 0; outgoingTurns.candidates.clear(); - auto adjacentEdges = m_adjacentEdges.find(node); + auto const adjacentEdges = m_adjacentEdges.find(node); if (adjacentEdges == m_adjacentEdges.cend()) { ASSERT(false, ()); @@ -74,49 +74,6 @@ private: TUnpackedPathSegments const & m_pathSegments; double m_routeLength; }; - -ftypes::HighwayClass GetHighwayClass(FeatureID const & featureId, Index const & index) -{ - ftypes::HighwayClass highWayClass = ftypes::HighwayClass::Undefined; - MwmSet::MwmId const & mwmId = featureId.m_mwmId; - uint32_t const featureIndex = featureId.m_index; - - FeatureType ft; - Index::FeaturesLoaderGuard loader(index, mwmId); - loader.GetFeatureByIndex(featureIndex, ft); - highWayClass = ftypes::GetHighwayClass(ft); - ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Error, ()); - ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Undefined, ()); - return highWayClass; -} - -void LoadPathGeometry(FeatureID const & featureId, Index const & index, - vector const & path, LoadedPathSegment & pathSegment) -{ - pathSegment.Clear(); - - MwmSet::MwmId const & mwmId = featureId.m_mwmId; - if (!featureId.IsValid()) - { - ASSERT(false, ()); - return; - } - - FeatureType ft; - Index::FeaturesLoaderGuard loader(index, mwmId); - loader.GetFeatureByIndex(featureId.m_index, ft); - pathSegment.m_highwayClass = ftypes::GetHighwayClass(ft); - ASSERT_NOT_EQUAL(pathSegment.m_highwayClass, ftypes::HighwayClass::Error, ()); - ASSERT_NOT_EQUAL(pathSegment.m_highwayClass, ftypes::HighwayClass::Undefined, ()); - pathSegment.m_isLink = ftypes::IsLinkChecker::Instance()(ft); - - ft.GetName(FeatureType::DEFAULT_LANG, pathSegment.m_name); - - pathSegment.m_nodeId = featureId.m_index; - pathSegment.m_onRoundabout = ftypes::IsRoundAboutChecker::Instance()(ft); - pathSegment.m_path = path; - // @TODO(bykoianko) It's better to fill pathSegment.m_weight. -} } // namespace namespace routing @@ -190,15 +147,12 @@ void BicycleDirectionsEngine::Generate(IRoadGraph const & graph, vectorGetFeatureByIndex(featureIndex, ft); + highWayClass = ftypes::GetHighwayClass(ft); + ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Error, ()); + ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Undefined, ()); + return highWayClass; +} + +void BicycleDirectionsEngine::LoadPathGeometry(FeatureID const & featureId, vector const & path, + LoadedPathSegment & pathSegment) +{ + pathSegment.Clear(); + + MwmSet::MwmId const & mwmId = featureId.m_mwmId; + if (!featureId.IsValid()) + { + ASSERT(false, ()); + return; + } + + FeatureType ft; + UpdateFeatureLoaderGuardIfNeeded(m_index, mwmId); + m_featuresLoaderGuard->GetFeatureByIndex(featureId.m_index, ft); + pathSegment.m_highwayClass = ftypes::GetHighwayClass(ft); + ASSERT_NOT_EQUAL(pathSegment.m_highwayClass, ftypes::HighwayClass::Error, ()); + ASSERT_NOT_EQUAL(pathSegment.m_highwayClass, ftypes::HighwayClass::Undefined, ()); + pathSegment.m_isLink = ftypes::IsLinkChecker::Instance()(ft); + + ft.GetName(FeatureType::DEFAULT_LANG, pathSegment.m_name); + + pathSegment.m_nodeId = featureId.m_index; + pathSegment.m_onRoundabout = ftypes::IsRoundAboutChecker::Instance()(ft); + pathSegment.m_path = path; + // @TODO(bykoianko) It's better to fill pathSegment.m_weight. +} } // namespace routing diff --git a/routing/bicycle_directions.hpp b/routing/bicycle_directions.hpp index f934df4fe2..f0cbec5522 100644 --- a/routing/bicycle_directions.hpp +++ b/routing/bicycle_directions.hpp @@ -5,6 +5,7 @@ #include "routing/turn_candidate.hpp" #include "std/map.hpp" +#include "std/unique_ptr.hpp" class Index; @@ -12,7 +13,7 @@ namespace routing { struct AdjacentEdges { - AdjacentEdges(size_t ingoingTurnsCount = 0) : m_ingoingTurnsCount(ingoingTurnsCount) {} + explicit AdjacentEdges(size_t ingoingTurnsCount = 0) : m_ingoingTurnsCount(ingoingTurnsCount) {} turns::TurnCandidates m_outgoingTurns; size_t m_ingoingTurnsCount; @@ -31,8 +32,15 @@ public: my::Cancellable const & cancellable) override; private: + void UpdateFeatureLoaderGuardIfNeeded(Index const & index, MwmSet::MwmId const & mwmId); + ftypes::HighwayClass GetHighwayClass(FeatureID const & featureId); + void LoadPathGeometry(FeatureID const & featureId, vector const & path, + LoadedPathSegment & pathSegment); + AdjacentEdgesMap m_adjacentEdges; TUnpackedPathSegments m_pathSegments; + unique_ptr m_featuresLoaderGuard; + MwmSet::MwmId m_mwmIdFeaturesLoaderGuard; Index const & m_index; }; } // namespace routing diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 362a710116..fb41aff5eb 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -23,9 +23,9 @@ bool HasType(uint32_t type, feature::TypesHolder const & types) void Convert(vector const & path, vector & geometry) { - size_t const pathSz = path.size(); - geometry.resize(pathSz); - for (size_t i = 0; i < pathSz; ++i) + size_t const pathSize = path.size(); + geometry.resize(pathSize); + for (size_t i = 0; i < pathSize; ++i) geometry[i] = path[i].GetPoint(); } } // namespace diff --git a/routing/turn_candidate.hpp b/routing/turn_candidate.hpp index 07e13285b9..d18f150d03 100644 --- a/routing/turn_candidate.hpp +++ b/routing/turn_candidate.hpp @@ -46,7 +46,7 @@ struct TurnCandidates vector candidates; bool isCandidatesAngleValid; - TurnCandidates(bool angleValid = true) : isCandidatesAngleValid(angleValid) {} + explicit TurnCandidates(bool angleValid = true) : isCandidatesAngleValid(angleValid) {} }; } // namespace routing diff --git a/routing/turns.hpp b/routing/turns.hpp index 5e2a397c04..05773bcc46 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -206,7 +206,7 @@ void SplitLanes(string const & lanesString, char delimiter, vector & lan bool ParseSingleLane(string const & laneString, char delimiter, TSingleLane & lane); /*! - * \returns pi minus an angle from vector [junctionPoint, ingoingPoint] + * \returns pi minus angle from vector [junctionPoint, ingoingPoint] * to vector [junctionPoint, outgoingPoint]. A counterclockwise rotation. * Angle is in range [-pi, pi]. */