diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-05-11 13:42:48 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-05-19 16:21:48 +0300 |
commit | c4e67688ca9cf24d6ac1eeba0e7dae4d19007d52 (patch) | |
tree | c8c1bec0302e2530e03cb38481ec15f358ec8f2e /routing | |
parent | d1c87452f37aa4118485ed5e78e334cf2cbfd283 (diff) |
Review fixes.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/bicycle_directions.cpp | 118 | ||||
-rw-r--r-- | routing/bicycle_directions.hpp | 15 | ||||
-rw-r--r-- | routing/directions_engine.cpp | 11 | ||||
-rw-r--r-- | routing/directions_engine.hpp | 7 | ||||
-rw-r--r-- | routing/osrm_router.cpp | 11 | ||||
-rw-r--r-- | routing/pedestrian_directions.cpp | 30 | ||||
-rw-r--r-- | routing/pedestrian_directions.hpp | 6 | ||||
-rw-r--r-- | routing/road_graph_router.cpp | 1 | ||||
-rw-r--r-- | routing/routing_integration_tests/bicycle_route_test.cpp | 3 | ||||
-rw-r--r-- | routing/routing_integration_tests/bicycle_turn_test.cpp | 18 | ||||
-rw-r--r-- | routing/routing_integration_tests/routing_test_tools.cpp | 46 | ||||
-rw-r--r-- | routing/routing_integration_tests/routing_test_tools.hpp | 3 | ||||
-rw-r--r-- | routing/routing_result_graph.hpp | 16 | ||||
-rw-r--r-- | routing/turns.cpp | 5 | ||||
-rw-r--r-- | routing/turns.hpp | 11 | ||||
-rw-r--r-- | routing/turns_generator.cpp | 4 | ||||
-rw-r--r-- | routing/turns_generator.hpp | 5 |
17 files changed, 153 insertions, 157 deletions
diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 8642b8b2da..606128e7aa 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -4,25 +4,27 @@ #include "routing/routing_result_graph.hpp" #include "routing/turns_generator.hpp" -#include "geometry/point2d.hpp" - #include "indexer/ftypes_matcher.hpp" #include "indexer/index.hpp" #include "indexer/scales.hpp" +#include "geometry/point2d.hpp" + namespace { using namespace routing; using namespace routing::turns; -class AStarRoutingResultGraph : public IRoutingResultGraph +class AStarRoutingResult : public IRoutingResult { public: - AStarRoutingResultGraph(IRoadGraph::TEdgeVector const & routeEdges, - AdjacentEdgesMap const & adjacentEdges, - TUnpackedPathSegments const & pathSegments) - : m_routeEdges(routeEdges), m_adjacentEdges(adjacentEdges), m_pathSegments(pathSegments), - m_routeLength(0) + AStarRoutingResult(IRoadGraph::TEdgeVector const & routeEdges, + AdjacentEdgesMap const & adjacentEdges, + TUnpackedPathSegments const & pathSegments) + : m_routeEdges(routeEdges) + , m_adjacentEdges(adjacentEdges) + , m_pathSegments(pathSegments) + , m_routeLength(0) { for (auto const & edge : routeEdges) { @@ -31,33 +33,31 @@ public: } } - ~AStarRoutingResultGraph() {} - - virtual TUnpackedPathSegments const & GetSegments() const override - { - return m_pathSegments; - } + // turns::IRoutingResult overrides: + virtual TUnpackedPathSegments const & GetSegments() const override { return m_pathSegments; } virtual void GetPossibleTurns(TNodeId node, m2::PointD const & ingoingPoint, - m2::PointD const & junctionPoint, - size_t & ingoingCount, + m2::PointD const & junctionPoint, size_t & ingoingCount, TTurnCandidates & outgoingTurns) const override { - if (node >= m_routeEdges.size() || node >= m_adjacentEdges.size()) + ingoingCount = 0; + outgoingTurns.clear(); + + if (node >= m_routeEdges.size()) { - ASSERT(false, ()); + ASSERT(false, (m_routeEdges.size())); return; } - AdjacentEdgesMap::const_iterator adjacentEdges = m_adjacentEdges.find(node); + auto adjacentEdges = m_adjacentEdges.find(node); if (adjacentEdges == m_adjacentEdges.cend()) { ASSERT(false, ()); return; } - ingoingCount = adjacentEdges->second.ingoingTurnCount; - outgoingTurns = adjacentEdges->second.outgoingTurns; + ingoingCount = adjacentEdges->second.m_ingoingTurnsCount; + outgoingTurns = adjacentEdges->second.m_outgoingTurns; } virtual double GetPathLength() const override { return m_routeLength; } @@ -75,10 +75,10 @@ public: } private: - IRoadGraph::TEdgeVector const & m_routeEdges; - AdjacentEdgesMap const & m_adjacentEdges; - TUnpackedPathSegments const & m_pathSegments; - double m_routeLength; + IRoadGraph::TEdgeVector const & m_routeEdges; + AdjacentEdgesMap const & m_adjacentEdges; + TUnpackedPathSegments const & m_pathSegments; + double m_routeLength; }; ftypes::HighwayClass GetHighwayClass(FeatureID const & featureId, Index const & index) @@ -90,7 +90,6 @@ ftypes::HighwayClass GetHighwayClass(FeatureID const & featureId, Index const & FeatureType ft; Index::FeaturesLoaderGuard loader(index, mwmId); loader.GetFeatureByIndex(featureIndex, ft); - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); highWayClass = ftypes::GetHighwayClass(ft); ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Error, ()); ASSERT_NOT_EQUAL(highWayClass, ftypes::HighwayClass::Undefined, ()); @@ -100,32 +99,37 @@ ftypes::HighwayClass GetHighwayClass(FeatureID const & featureId, Index const & namespace routing { -BicycleDirectionsEngine::BicycleDirectionsEngine(Index const & index) : m_index(index) -{ -} +BicycleDirectionsEngine::BicycleDirectionsEngine(Index const & index) : m_index(index) {} void BicycleDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junction> const & path, - Route::TTimes & times, - Route::TTurns & turnsDir, + Route::TTimes & times, Route::TTurns & turns, vector<m2::PointD> & routeGeometry, my::Cancellable const & cancellable) { - LOG(LINFO, ("BicycleDirectionsEngine::Generate")); - CHECK_GREATER(path.size(), 1, ()); + size_t const pathSize = path.size(); + CHECK_NOT_EQUAL(pathSize, 0, ()); + times.clear(); - turnsDir.clear(); + turns.clear(); routeGeometry.clear(); m_adjacentEdges.clear(); m_pathSegments.clear(); - CalculateTimes(graph, path, times); - auto emptyPathWorkaround = [&]() { - turnsDir.emplace_back(path.size() - 1, turns::TurnDirection::ReachedYourDestination); - this->m_adjacentEdges[0] = {{}, 1}; // There's one ingoing edge to the finish. + turns.emplace_back(pathSize - 1, turns::TurnDirection::ReachedYourDestination); + this->m_adjacentEdges[0] = AdjacentEdges(1); // There's one ingoing edge to the finish. }; + if (pathSize <= 1) + { + ASSERT(false, (pathSize)); + emptyPathWorkaround(); + return; + } + + CalculateTimes(graph, path, times); + IRoadGraph::TEdgeVector routeEdges; if (!ReconstructPath(graph, path, routeEdges, cancellable)) { @@ -141,34 +145,32 @@ void BicycleDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junction } // Filling |m_adjacentEdges|. - size_t const pathSize = path.size(); - m_adjacentEdges.insert(make_pair(0, AdjacentEdges({{} /* outgoingEdges */, 0 /* ingoingEdges.size() */}))); + m_adjacentEdges.insert(make_pair(0, AdjacentEdges(0))); for (size_t i = 1; i < pathSize; ++i) { - Junction const & formerJunction = path[i - 1]; - Junction const & currentJunction = path[i]; + Junction const & prevJunction = path[i - 1]; + Junction const & currJunction = path[i]; IRoadGraph::TEdgeVector outgoingEdges, ingoingEdges; - graph.GetOutgoingEdges(currentJunction, outgoingEdges); - graph.GetIngoingEdges(currentJunction, ingoingEdges); + graph.GetOutgoingEdges(currJunction, outgoingEdges); + graph.GetIngoingEdges(currJunction, ingoingEdges); - AdjacentEdges adjacentEdges = {{}, ingoingEdges.size()}; - adjacentEdges.outgoingTurns.reserve(outgoingEdges.size()); - for (auto const & outgoingEdge : outgoingEdges) + AdjacentEdges adjacentEdges = AdjacentEdges(ingoingEdges.size()); + adjacentEdges.m_outgoingTurns.reserve(outgoingEdges.size()); + for (auto const & edge : outgoingEdges) { - auto const & outgoingFeatureId = outgoingEdge.GetFeatureId(); - // Checking for if |outgoingEdge| is a fake edge. - if (!outgoingFeatureId.m_mwmId.IsAlive()) + auto const & featureId = edge.GetFeatureId(); + // Checking for if |edge| is a fake edge. + if (!featureId.m_mwmId.IsAlive()) continue; - double const angle = turns::PiMinusTwoVectorsAngle(formerJunction.GetPoint(), - currentJunction.GetPoint(), - outgoingEdge.GetEndJunction().GetPoint()); - adjacentEdges.outgoingTurns.emplace_back(angle, outgoingFeatureId.m_index, - GetHighwayClass(outgoingFeatureId, m_index)); + double const angle = turns::PiMinusTwoVectorsAngle( + currJunction.GetPoint(), prevJunction.GetPoint(), edge.GetEndJunction().GetPoint()); + adjacentEdges.m_outgoingTurns.emplace_back(angle, featureId.m_index, + GetHighwayClass(featureId, m_index)); } // Filling |m_pathSegments| based on |path|. LoadedPathSegment pathSegment; - pathSegment.m_path = { formerJunction.GetPoint(), currentJunction.GetPoint() }; + pathSegment.m_path = {prevJunction.GetPoint(), currJunction.GetPoint()}; pathSegment.m_nodeId = i; // @TODO(bykoianko) It's necessary to fill more fields of m_pathSegments. @@ -176,10 +178,10 @@ void BicycleDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junction m_pathSegments.push_back(move(pathSegment)); } - AStarRoutingResultGraph resultGraph(routeEdges, m_adjacentEdges, m_pathSegments); + AStarRoutingResult resultGraph(routeEdges, m_adjacentEdges, m_pathSegments); RouterDelegate delegate; Route::TTimes turnAnnotationTimes; Route::TStreets streetNames; - MakeTurnAnnotation(resultGraph, delegate, routeGeometry, turnsDir, turnAnnotationTimes, streetNames); + MakeTurnAnnotation(resultGraph, delegate, routeGeometry, turns, turnAnnotationTimes, streetNames); } } // namespace routing diff --git a/routing/bicycle_directions.hpp b/routing/bicycle_directions.hpp index 660ee31cf6..96102857d3 100644 --- a/routing/bicycle_directions.hpp +++ b/routing/bicycle_directions.hpp @@ -1,7 +1,7 @@ #pragma once #include "routing/directions_engine.hpp" -#include "loaded_path_segment.hpp" +#include "routing/loaded_path_segment.hpp" #include "routing/turn_candidate.hpp" #include "std/map.hpp" @@ -12,8 +12,10 @@ namespace routing { struct AdjacentEdges { - turns::TTurnCandidates outgoingTurns; - size_t ingoingTurnCount; + AdjacentEdges(size_t ingoingTurnsCount = 0) : m_ingoingTurnsCount(ingoingTurnsCount) {} + + turns::TTurnCandidates m_outgoingTurns; + size_t m_ingoingTurnsCount; }; using AdjacentEdgesMap = map<TNodeId, AdjacentEdges>; @@ -24,11 +26,10 @@ public: BicycleDirectionsEngine(Index const & index); // IDirectionsEngine override: - void Generate(IRoadGraph const & graph, vector<Junction> const & path, - Route::TTimes & times, - Route::TTurns & turnsDir, - vector<m2::PointD> & routeGeometry, + void Generate(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times, + Route::TTurns & turns, vector<m2::PointD> & routeGeometry, my::Cancellable const & cancellable) override; + private: AdjacentEdgesMap m_adjacentEdges; TUnpackedPathSegments m_pathSegments; diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp index c79d997457..b883da100d 100644 --- a/routing/directions_engine.cpp +++ b/routing/directions_engine.cpp @@ -37,6 +37,13 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junctio vector<Edge> & routeEdges, my::Cancellable const & cancellable) const { + routeEdges.clear(); + if (path.size() <= 1) + { + ASSERT(false, (path.size())); + return false; + } + routeEdges.reserve(path.size() - 1); Junction curr = path[0]; @@ -52,7 +59,7 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junctio graph.GetOutgoingEdges(curr, currEdges); bool found = false; - for (Edge const & e : currEdges) + for (auto const & e : currEdges) { if (e.GetEndJunction() == next) { @@ -68,7 +75,7 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junctio curr = next; } - ASSERT_EQUAL(routeEdges.size()+1, path.size(), ()); + ASSERT_EQUAL(routeEdges.size() + 1, path.size(), ()); return true; } diff --git a/routing/directions_engine.hpp b/routing/directions_engine.hpp index 957536ba82..ada7b51c90 100644 --- a/routing/directions_engine.hpp +++ b/routing/directions_engine.hpp @@ -16,14 +16,13 @@ public: virtual ~IDirectionsEngine() = default; virtual void Generate(IRoadGraph const & graph, vector<Junction> const & path, - Route::TTimes & times, - Route::TTurns & turnsDir, + Route::TTimes & times, Route::TTurns & turns, vector<m2::PointD> & routeGeometry, my::Cancellable const & cancellable) = 0; + protected: bool ReconstructPath(IRoadGraph const & graph, vector<Junction> const & path, - vector<Edge> & routeEdges, - my::Cancellable const & cancellable) const; + vector<Edge> & routeEdges, my::Cancellable const & cancellable) const; void CalculateTimes(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times) const; diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index b177ac509d..ed57dc3a64 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -56,10 +56,10 @@ double constexpr kPathFoundProgress = 70.0f; using RawRouteData = InternalRouteResult; -class OSRMRoutingResultGraph : public turns::IRoutingResultGraph +class OSRMRoutingResult : public turns::IRoutingResult { public: - // turns::IRoutingResultGraph overrides: + // turns::IRoutingResult overrides: virtual TUnpackedPathSegments const & GetSegments() const override { return m_loadedSegments; @@ -161,7 +161,7 @@ public: return m_rawResult.targetEdge.segmentPoint; } - OSRMRoutingResultGraph(Index const & index, RoutingMapping & mapping, RawRoutingResult & result) + OSRMRoutingResult(Index const & index, RoutingMapping & mapping, RawRoutingResult & result) : m_rawResult(result), m_index(index), m_routingMapping(mapping) { for (auto const & pathSegments : m_rawResult.unpackedPathSegments) @@ -187,7 +187,6 @@ public: } } - ~OSRMRoutingResultGraph() {} private: TUnpackedPathSegments m_loadedSegments; RawRoutingResult m_rawResult; @@ -330,7 +329,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & Route::TTimes mwmTimes; Route::TStreets mwmStreets; vector<m2::PointD> mwmPoints; - OSRMRoutingResultGraph resultGraph(*m_pIndex, *mwmMapping, routingResult); + OSRMRoutingResult resultGraph(*m_pIndex, *mwmMapping, routingResult); if (MakeTurnAnnotation(resultGraph, delegate, mwmPoints, mwmTurnsDir, mwmTimes, mwmStreets) != NoError) { LOG(LWARNING, ("Can't load road path data from disk for", mwmMapping->GetCountryName())); @@ -500,7 +499,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, Route::TStreets streets; vector<m2::PointD> points; - OSRMRoutingResultGraph resultGraph(*m_pIndex, *startMapping, routingResult); + OSRMRoutingResult resultGraph(*m_pIndex, *startMapping, routingResult); if (MakeTurnAnnotation(resultGraph, delegate, points, turnsDir, times, streets) != NoError) { LOG(LWARNING, ("Can't load road path data from disk!")); diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 455ec6a62b..362a710116 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -23,10 +23,10 @@ bool HasType(uint32_t type, feature::TypesHolder const & types) void Convert(vector<routing::Junction> const & path, vector<m2::PointD> & geometry) { - geometry.clear(); - geometry.reserve(path.size()); - for (auto const & pos : path) - geometry.emplace_back(pos.GetPoint()); + size_t const pathSz = path.size(); + geometry.resize(pathSz); + for (size_t i = 0; i < pathSz; ++i) + geometry[i] = path[i].GetPoint(); } } // namespace @@ -41,8 +41,7 @@ PedestrianDirectionsEngine::PedestrianDirectionsEngine() } void PedestrianDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junction> const & path, - Route::TTimes & times, - Route::TTurns & turnsDir, + Route::TTimes & times, Route::TTurns & turns, vector<m2::PointD> & routeGeometry, my::Cancellable const & cancellable) { @@ -55,16 +54,17 @@ void PedestrianDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junct { LOG(LDEBUG, ("Couldn't reconstruct path")); // use only "arrival" direction - turnsDir.emplace_back(path.size() - 1, turns::PedestrianDirection::ReachedYourDestination); + turns.emplace_back(path.size() - 1, turns::PedestrianDirection::ReachedYourDestination); return; } - CalculateTurns(graph, routeEdges, turnsDir, cancellable); + CalculateTurns(graph, routeEdges, turns, cancellable); Convert(path, routeGeometry); } -void PedestrianDirectionsEngine::CalculateTurns(IRoadGraph const & graph, vector<Edge> const & routeEdges, - Route::TTurns & turnsDir, +void PedestrianDirectionsEngine::CalculateTurns(IRoadGraph const & graph, + vector<Edge> const & routeEdges, + Route::TTurns & turns, my::Cancellable const & cancellable) const { for (size_t i = 0; i < routeEdges.size(); ++i) @@ -80,23 +80,23 @@ void PedestrianDirectionsEngine::CalculateTurns(IRoadGraph const & graph, vector if (HasType(m_typeSteps, types)) { if (edge.IsForward()) - turnsDir.emplace_back(i, turns::PedestrianDirection::Upstairs); + turns.emplace_back(i, turns::PedestrianDirection::Upstairs); else - turnsDir.emplace_back(i, turns::PedestrianDirection::Downstairs); + turns.emplace_back(i, turns::PedestrianDirection::Downstairs); } else { graph.GetJunctionTypes(edge.GetStartJunction(), types); if (HasType(m_typeLiftGate, types)) - turnsDir.emplace_back(i, turns::PedestrianDirection::LiftGate); + turns.emplace_back(i, turns::PedestrianDirection::LiftGate); else if (HasType(m_typeGate, types)) - turnsDir.emplace_back(i, turns::PedestrianDirection::Gate); + turns.emplace_back(i, turns::PedestrianDirection::Gate); } } // direction "arrival" // (index of last junction is the same as number of edges) - turnsDir.emplace_back(routeEdges.size(), turns::PedestrianDirection::ReachedYourDestination); + turns.emplace_back(routeEdges.size(), turns::PedestrianDirection::ReachedYourDestination); } } // namespace routing diff --git a/routing/pedestrian_directions.hpp b/routing/pedestrian_directions.hpp index 45c3236b08..c00af9b3eb 100644 --- a/routing/pedestrian_directions.hpp +++ b/routing/pedestrian_directions.hpp @@ -11,10 +11,8 @@ public: PedestrianDirectionsEngine(); // IDirectionsEngine override: - void Generate(IRoadGraph const & graph, vector<Junction> const & path, - Route::TTimes & times, - Route::TTurns & turnsDir, - vector<m2::PointD> & routeGeometry, + void Generate(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times, + Route::TTurns & turns, vector<m2::PointD> & routeGeometry, my::Cancellable const & cancellable) override; private: diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index d56b933d54..40748bf84a 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -230,7 +230,6 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route, my::Cancellable const & cancellable) const { - LOG(LINFO, ("RoadGraphRouter::ReconstructRoute path.size()", path.size())); CHECK(!path.empty(), ("Can't reconstruct route from an empty list of positions.")); // By some reason there're two adjacent positions on a road with diff --git a/routing/routing_integration_tests/bicycle_route_test.cpp b/routing/routing_integration_tests/bicycle_route_test.cpp index e2b6e48265..afcd96f95e 100644 --- a/routing/routing_integration_tests/bicycle_route_test.cpp +++ b/routing/routing_integration_tests/bicycle_route_test.cpp @@ -10,7 +10,6 @@ using namespace routing::turns; UNIT_TEST(RussiaMoscowSevTushinoParkPreferingBicycleWay) { integration::CalculateRouteAndTestRouteLength( - integration::GetBicycleComponents(), - MercatorBounds::FromLatLon(55.87445, 37.43711), {0., 0.}, + integration::GetBicycleComponents(), MercatorBounds::FromLatLon(55.87445, 37.43711), {0., 0.}, MercatorBounds::FromLatLon(55.87203, 37.44274), 460.); } diff --git a/routing/routing_integration_tests/bicycle_turn_test.cpp b/routing/routing_integration_tests/bicycle_turn_test.cpp index 04e85460a5..a158231573 100644 --- a/routing/routing_integration_tests/bicycle_turn_test.cpp +++ b/routing/routing_integration_tests/bicycle_turn_test.cpp @@ -4,16 +4,14 @@ #include "routing/route.hpp" - using namespace routing; using namespace routing::turns; UNIT_TEST(RussiaMoscowSevTushinoParkBicycleWayTurnTest) { TRouteResult const routeResult = integration::CalculateRoute( - integration::GetBicycleComponents(), - MercatorBounds::FromLatLon(55.87445, 37.43711), {0.0, 0.0}, - MercatorBounds::FromLatLon(55.8719, 37.4464)); + integration::GetBicycleComponents(), MercatorBounds::FromLatLon(55.87445, 37.43711), + {0.0, 0.0}, MercatorBounds::FromLatLon(55.8719, 37.4464)); Route const & route = *routeResult.first; IRouter::ResultCode const result = routeResult.second; @@ -21,15 +19,9 @@ UNIT_TEST(RussiaMoscowSevTushinoParkBicycleWayTurnTest) integration::TestTurnCount(route, 3); - integration::GetNthTurn(route, 0) - .TestValid() - .TestDirection(TurnDirection::TurnRight); - integration::GetNthTurn(route, 1) - .TestValid() - .TestDirection(TurnDirection::TurnLeft); - integration::GetNthTurn(route, 2) - .TestValid() - .TestDirection(TurnDirection::TurnRight); + integration::GetNthTurn(route, 0).TestValid().TestDirection(TurnDirection::TurnRight); + integration::GetNthTurn(route, 1).TestValid().TestDirection(TurnDirection::TurnLeft); + integration::GetNthTurn(route, 2).TestValid().TestDirection(TurnDirection::TurnRight); integration::TestRouteLength(route, 711.); } diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index 2c824b0fa5..ebd322baa5 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -31,7 +31,8 @@ using namespace routing; -using TRouterFactory = function<unique_ptr<IRouter>(Index & index, TCountryFileFn const & countryFileFn)>; +using TRouterFactory = + function<unique_ptr<IRouter>(Index & index, TCountryFileFn const & countryFileFn)>; namespace { @@ -71,19 +72,17 @@ namespace integration return storage::CountryInfoReader::CreateCountryInfoReader(platform); } - shared_ptr<OsrmRouter> CreateOsrmRouter(Index & index, + unique_ptr<OsrmRouter> CreateOsrmRouter(Index & index, storage::CountryInfoGetter const & infoGetter) { - shared_ptr<OsrmRouter> osrmRouter(new OsrmRouter( - &index, [&infoGetter](m2::PointD const & pt) - { - return infoGetter.GetRegionCountryId(pt); - } - )); + unique_ptr<OsrmRouter> osrmRouter(new OsrmRouter(&index, [&infoGetter](m2::PointD const & pt) + { + return infoGetter.GetRegionCountryId(pt); + })); return osrmRouter; } - shared_ptr<IRouter> CreateAStarRouter(Index & index, + unique_ptr<IRouter> CreateAStarRouter(Index & index, storage::CountryInfoGetter const & infoGetter, TRouterFactory const & routerFactory) { @@ -92,7 +91,7 @@ namespace integration return infoGetter.GetRegionCountryId(pt); }; unique_ptr<IRouter> router = routerFactory(index, countryFileGetter); - return shared_ptr<IRouter>(move(router)); + return unique_ptr<IRouter>(move(router)); } class OsrmRouterComponents : public IRouterComponents @@ -107,7 +106,7 @@ namespace integration IRouter * GetRouter() const override { return m_osrmRouter.get(); } private: - shared_ptr<OsrmRouter> m_osrmRouter; + unique_ptr<OsrmRouter> m_osrmRouter; }; class PedestrianRouterComponents : public IRouterComponents @@ -123,7 +122,7 @@ namespace integration IRouter * GetRouter() const override { return m_router.get(); } private: - shared_ptr<IRouter> m_router; + unique_ptr<IRouter> m_router; }; class BicycleRouterComponents : public IRouterComponents @@ -139,7 +138,7 @@ namespace integration IRouter * GetRouter() const override { return m_router.get(); } private: - shared_ptr<IRouter> m_router; + unique_ptr<IRouter> m_router; }; template <typename TRouterComponents> @@ -171,9 +170,9 @@ namespace integration IRouterComponents & GetOsrmComponents() { - static shared_ptr<IRouterComponents> const inst = CreateAllMapsComponents<OsrmRouterComponents>(); - ASSERT(inst, ()); - return *inst; + static auto const instance = CreateAllMapsComponents<OsrmRouterComponents>(); + ASSERT(instance, ()); + return *instance; } shared_ptr<IRouterComponents> GetPedestrianComponents(vector<platform::LocalCountryFile> const & localFiles) @@ -183,21 +182,22 @@ namespace integration IRouterComponents & GetPedestrianComponents() { - static shared_ptr<IRouterComponents> const inst = CreateAllMapsComponents<PedestrianRouterComponents>(); - ASSERT(inst, ()); - return *inst; + static auto const instance = CreateAllMapsComponents<PedestrianRouterComponents>(); + ASSERT(instance, ()); + return *instance; } - shared_ptr<IRouterComponents> GetBicycleComponents(vector<platform::LocalCountryFile> const & localFiles) + shared_ptr<IRouterComponents> GetBicycleComponents( + vector<platform::LocalCountryFile> const & localFiles) { return make_shared<BicycleRouterComponents>(localFiles); } IRouterComponents & GetBicycleComponents() { - static shared_ptr<IRouterComponents> const inst = CreateAllMapsComponents<BicycleRouterComponents>(); - ASSERT(inst, ()); - return *inst; + static auto const instance = CreateAllMapsComponents<BicycleRouterComponents>(); + ASSERT(instance, ()); + return *instance; } TRouteResult CalculateRoute(IRouterComponents const & routerComponents, diff --git a/routing/routing_integration_tests/routing_test_tools.hpp b/routing/routing_integration_tests/routing_test_tools.hpp index ce9c382fe8..4145b18bce 100644 --- a/routing/routing_integration_tests/routing_test_tools.hpp +++ b/routing/routing_integration_tests/routing_test_tools.hpp @@ -88,7 +88,8 @@ unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter(); /// Gets bicycle router components. IRouterComponents & GetBicycleComponents(); - shared_ptr<IRouterComponents> GetBicycleComponents(vector<platform::LocalCountryFile> const & localFiles); + shared_ptr<IRouterComponents> GetBicycleComponents( + vector<platform::LocalCountryFile> const & localFiles); TRouteResult CalculateRoute(IRouterComponents const & routerComponents, m2::PointD const & startPoint, m2::PointD const & startDirection, diff --git a/routing/routing_result_graph.hpp b/routing/routing_result_graph.hpp index ef6f26269b..d3a9e24059 100644 --- a/routing/routing_result_graph.hpp +++ b/routing/routing_result_graph.hpp @@ -9,32 +9,26 @@ namespace routing { namespace turns { - /*! - * \brief The IRoutingResultGraph interface for the routing result. Uncouple router from the + * \brief The IRoutingResult interface for the routing result. Uncouple router from the * annotation code that describes turns. See routers for detail implementations. */ -class IRoutingResultGraph +class IRoutingResult { public: /// \returns information about all route segments. virtual TUnpackedPathSegments const & GetSegments() const = 0; - /// \brief for number of a |node|, point of the node (|junctionPoint|) and for a point - /// just before the node (|ingoingPoint|) it fills - /// * |ingoingCount| - number of incomming ways to |junctionPoint|. (|junctionPoint| >= 1) - /// * |outgoingTurns| - vector of ways to leave |junctionPoint|. + /// \brief For a |node|, |junctionPoint| and |ingoingPoint| (point before the |node|) + /// this method computes number of ingoing ways to |junctionPoint| and fills |outgoingTurns|. virtual void GetPossibleTurns(TNodeId node, m2::PointD const & ingoingPoint, m2::PointD const & junctionPoint, size_t & ingoingCount, TTurnCandidates & outgoingTurns) const = 0; - /// \returns route length. virtual double GetPathLength() const = 0; - /// \returns route start point. virtual m2::PointD const & GetStartPoint() const = 0; - /// \returns route finish point. virtual m2::PointD const & GetEndPoint() const = 0; - virtual ~IRoutingResultGraph() = default; + virtual ~IRoutingResult() = default; }; } // namespace routing } // namespace turns diff --git a/routing/turns.cpp b/routing/turns.cpp index 7760ab8e20..c63145eff5 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -280,9 +280,10 @@ string DebugPrint(SingleLaneInfo const & singleLaneInfo) return out.str(); } -double PiMinusTwoVectorsAngle(m2::PointD const & p, m2::PointD const & p1, m2::PointD const & p2) +double PiMinusTwoVectorsAngle(m2::PointD const & junctionPoint, m2::PointD const & ingoingPoint, + m2::PointD const & outgoingPoint) { - return math::pi - ang::TwoVectorsAngle(p, p1, p2); + return math::pi - ang::TwoVectorsAngle(junctionPoint, ingoingPoint, outgoingPoint); } } // namespace turns } // namespace routing diff --git a/routing/turns.hpp b/routing/turns.hpp index 03f21db4de..5e2a397c04 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -19,8 +19,6 @@ namespace turns /// @todo(vbykoianko) It's a good idea to gather all the turns information into one entity. /// For the time being several separate entities reflect the turn information. Like Route::TTurns -using TGeomTurnCandidate = vector<double>; - double constexpr kFeaturesNearTurnMeters = 3.0; /*! @@ -206,6 +204,13 @@ bool IsLaneWayConformedTurnDirectionApproximately(LaneWay l, TurnDirection t); bool ParseLanes(string lanesString, vector<SingleLaneInfo> & lanes); void SplitLanes(string const & lanesString, char delimiter, vector<string> & lanes); bool ParseSingleLane(string const & laneString, char delimiter, TSingleLane & lane); -double PiMinusTwoVectorsAngle(m2::PointD const & p, m2::PointD const & p1, m2::PointD const & p2); + +/*! + * \returns pi minus an angle from vector [junctionPoint, ingoingPoint] + * to vector [junctionPoint, outgoingPoint]. A counterclockwise rotation. + * Angle is in range [-pi, pi]. +*/ +double PiMinusTwoVectorsAngle(m2::PointD const & junctionPoint, m2::PointD const & ingoingPoint, + m2::PointD const & outgoingPoint); } // namespace turns } // namespace routing diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 6d12e1ecc3..c84c267be6 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -253,7 +253,7 @@ bool TurnInfo::IsSegmentsValid() const return true; } -IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResultGraph const & result, +IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, RouterDelegate const & delegate, vector<m2::PointD> & points, Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets) @@ -561,7 +561,7 @@ TurnDirection IntermediateDirection(const double angle) return FindDirectionByAngle(kLowerBounds, angle); } -void GetTurnDirection(IRoutingResultGraph const & result, TurnInfo & turnInfo, TurnItem & turn) +void GetTurnDirection(IRoutingResult const & result, TurnInfo & turnInfo, TurnItem & turn) { if (!turnInfo.IsSegmentsValid()) return; diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index a5441d0950..80bd0e27b8 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -42,7 +42,7 @@ using TGetIndexFunction = function<size_t(pair<size_t, size_t>)>; * \param streets output street names along the path. * \return routing operation result code. */ -IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResultGraph const & result, +IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, RouterDelegate const & delegate, vector<m2::PointD> & points, Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets); @@ -127,8 +127,7 @@ TurnDirection GetRoundaboutDirection(bool isIngoingEdgeRoundabout, bool isOutgoi * \param turnInfo is used for cashing some information while turn calculation. * \param turn is used for keeping the result of turn calculation. */ -void GetTurnDirection(IRoutingResultGraph const & result, turns::TurnInfo & turnInfo, - TurnItem & turn); +void GetTurnDirection(IRoutingResult const & result, turns::TurnInfo & turnInfo, TurnItem & turn); /*! * \brief Finds an UTurn that starts from current segment and returns how many segments it lasts. |