From 637a7c3ca298937d44a95b267f023ccc7faf8dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D1=80=D1=8B=D0=B8=CC=86=20=D0=AD=D1=8D?= =?UTF-8?q?=D1=85?= Date: Tue, 27 Jun 2017 15:05:58 +0300 Subject: [PATCH] [routing] Pull request #6402 review fixes --- map/routing_manager.cpp | 2 +- routing/async_router.cpp | 7 ++---- routing/checkpoints.hpp | 22 +++++++++++++++++-- routing/index_router.cpp | 2 +- routing/road_graph_router.cpp | 8 +++---- .../routing_test_tools.cpp | 2 +- routing/routing_tests/async_router_test.cpp | 6 +++-- .../routing_tests/routing_session_test.cpp | 8 +++---- .../routing/routing.xcodeproj/project.pbxproj | 4 ++++ 9 files changed, 39 insertions(+), 22 deletions(-) diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 5d3d61a5d4..d18c0d00ad 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -537,7 +537,7 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec) for (auto const & point : routePoints) points.push_back(point.m_position); - m_routingSession.BuildRoute(Checkpoints(std::move(points)), timeoutSec); + m_routingSession.BuildRoute(Checkpoints(0 /* arriveIdx */, std::move(points)), timeoutSec); } void RoutingManager::SetUserCurrentPosition(m2::PointD const & position) diff --git a/routing/async_router.cpp b/routing/async_router.cpp index 2d5d2c87b5..422496643d 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -297,11 +297,8 @@ void AsyncRouter::CalculateRoute() absentFetcher->GenerateRequest(checkpoints.GetStart(), checkpoints.GetFinish()); // Run basic request. - code = router->CalculateRoute(checkpoints, - startDirection, - adjustToPrevRoute, - delegate->GetDelegate(), - route); + code = router->CalculateRoute(checkpoints, startDirection, adjustToPrevRoute, + delegate->GetDelegate(), route); elapsedSec = timer.ElapsedSeconds(); // routing time LogCode(code, elapsedSec); diff --git a/routing/checkpoints.hpp b/routing/checkpoints.hpp index 10794e792a..6c440621fe 100644 --- a/routing/checkpoints.hpp +++ b/routing/checkpoints.hpp @@ -16,7 +16,11 @@ public: Checkpoints(m2::PointD const & start, m2::PointD const & finish) : m_points({start, finish}) {} - Checkpoints(std::vector && points) : m_points(std::move(points)) { CheckValid(); } + Checkpoints(size_t arriveIdx, std::vector && points) + : m_points(std::move(points)), m_arriveIdx(arriveIdx) + { + CheckValid(); + } m2::PointD const & GetStart() const { @@ -42,12 +46,26 @@ public: return m_points; } + size_t GetArriveIdx() const { return m_arriveIdx; } + + void ArriveNextPoint() + { + ++m_arriveIdx; + CheckValid(); + } + void CheckValid() const { - CHECK_GREATER_OR_EQUAL(m_points.size(), 2, ("Checkpoints should contain start and finish")); + CHECK_GREATER_OR_EQUAL(m_points.size(), 2, + ("Checkpoints should at least contain start and finish")); + CHECK_LESS(m_arriveIdx, m_points.size(), ()); } private: + // m_points contains start, finish and intermediate points. std::vector m_points; + // Arrive idx is the index of the checkpoint by which the user passed by. + // By default, user has arrived at 0, it is start point. + size_t m_arriveIdx = 0; }; } // namespace routing diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 21f50edb0c..7c2a6be6ae 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -161,7 +161,7 @@ IRouter::ResultCode IndexRouter::CalculateRoute(Checkpoints const & checkpoints, double const distanceToFinish = MercatorBounds::DistanceOnEarth(startPoint, finalPoint); if (distanceToRoute <= kAdjustRangeM && distanceToFinish >= kMinDistanceToFinishM) { - auto code = AdjustRoute(startPoint, startDirection, finalPoint, delegate, route); + auto const code = AdjustRoute(startPoint, startDirection, finalPoint, delegate, route); if (code != IRouter::RouteNotFound) return code; diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 863391449c..5af5073057 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -144,11 +144,9 @@ bool RoadGraphRouter::CheckMapExistence(m2::PointD const & point, Route & route) return true; } -IRouter::ResultCode RoadGraphRouter::CalculateRoute(Checkpoints const &checkpoints, - m2::PointD const &, - bool, - RouterDelegate const &delegate, - Route &route) +IRouter::ResultCode RoadGraphRouter::CalculateRoute(Checkpoints const & checkpoints, + m2::PointD const &, bool, + RouterDelegate const & delegate, Route & route) { auto const & startPoint = checkpoints.GetStart(); auto const & finalPoint = checkpoints.GetFinish(); diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index e6aba71422..6d6cabef6c 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -245,7 +245,7 @@ namespace integration shared_ptr route(new Route("mapsme")); IRouter::ResultCode result = router->CalculateRoute(Checkpoints(startPoint, finalPoint), startDirection, - false /* adjust */, delegate, *route.get()); + false /* adjust */, delegate, *route); ASSERT(route, ()); return TRouteResult(route, result); } diff --git a/routing/routing_tests/async_router_test.cpp b/routing/routing_tests/async_router_test.cpp index 2df9de4b4a..7a4c9a219d 100644 --- a/routing/routing_tests/async_router_test.cpp +++ b/routing/routing_tests/async_router_test.cpp @@ -96,7 +96,8 @@ UNIT_TEST(NeedMoreMapsSignalTest) DummyResultCallback resultCallback(2 /* expectedCalls */); AsyncRouter async(DummyStatisticsCallback, nullptr /* pointCheckCallback */); async.SetRouter(move(router), move(fetcher)); - async.CalculateRoute(Checkpoints({1, 2}, {5, 6}), {3, 4}, false, bind(ref(resultCallback), _1, _2), nullptr, 0); + async.CalculateRoute(Checkpoints({1, 2} /* start */, {5, 6} /* finish */), {3, 4}, false, + bind(ref(resultCallback), _1, _2), nullptr, 0); resultCallback.WaitFinish(); @@ -116,7 +117,8 @@ UNIT_TEST(StandartAsyncFogTest) DummyResultCallback resultCallback(1 /* expectedCalls */); AsyncRouter async(DummyStatisticsCallback, nullptr /* pointCheckCallback */); async.SetRouter(move(router), move(fetcher)); - async.CalculateRoute(Checkpoints({1, 2}, {5, 6}), {3, 4}, false, bind(ref(resultCallback), _1, _2), nullptr, 0); + async.CalculateRoute(Checkpoints({1, 2} /* start */, {5, 6} /* finish */), {3, 4}, false, + bind(ref(resultCallback), _1, _2), nullptr, 0); resultCallback.WaitFinish(); diff --git a/routing/routing_tests/routing_session_test.cpp b/routing/routing_tests/routing_session_test.cpp index 6869dca6a1..e755fc738f 100644 --- a/routing/routing_tests/routing_session_test.cpp +++ b/routing/routing_tests/routing_session_test.cpp @@ -30,11 +30,9 @@ public: } string GetName() const override { return "dummy"; } void ClearState() override {} - ResultCode CalculateRoute(Checkpoints const &, - m2::PointD const &, - bool adjust, - RouterDelegate const &, - Route &route) override + ResultCode CalculateRoute(Checkpoints const & /* checkpoints */, + m2::PointD const & /* startDirection */, bool /* adjust */, + RouterDelegate const & /* delegate */, Route & route) override { ++m_buildCount; route = m_route; diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index fd2dd59385..2e8dc1116c 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 0C0DF92A1DE898FF0055A22F /* routing_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0C0DF9281DE898FF0055A22F /* routing_helpers.cpp */; }; 0C12ED231E5C822A0080D0F4 /* index_router.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0C12ED211E5C822A0080D0F4 /* index_router.cpp */; }; 0C12ED241E5C822A0080D0F4 /* index_router.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0C12ED221E5C822A0080D0F4 /* index_router.hpp */; }; + 0C15B8021F02A61B0058E253 /* checkpoints.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0C15B8011F02A61B0058E253 /* checkpoints.hpp */; }; 0C470E701E0D4EB1005B824D /* segment.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0C470E6F1E0D4EB1005B824D /* segment.hpp */; }; 0C5992E21E433BE600203653 /* num_mwm_id.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0C5992E11E433BE600203653 /* num_mwm_id.hpp */; }; 0C5BC9D11E28FD4E0071BFDD /* index_road_graph.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0C5BC9CF1E28FD4E0071BFDD /* index_road_graph.cpp */; }; @@ -279,6 +280,7 @@ 0C0DF9281DE898FF0055A22F /* routing_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_helpers.cpp; sourceTree = ""; }; 0C12ED211E5C822A0080D0F4 /* index_router.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = index_router.cpp; sourceTree = ""; }; 0C12ED221E5C822A0080D0F4 /* index_router.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = index_router.hpp; sourceTree = ""; }; + 0C15B8011F02A61B0058E253 /* checkpoints.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = checkpoints.hpp; sourceTree = ""; }; 0C470E6F1E0D4EB1005B824D /* segment.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = segment.hpp; sourceTree = ""; }; 0C5992E11E433BE600203653 /* num_mwm_id.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = num_mwm_id.hpp; sourceTree = ""; }; 0C5BC9CF1E28FD4E0071BFDD /* index_road_graph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = index_road_graph.cpp; sourceTree = ""; }; @@ -738,6 +740,7 @@ 671F58BA1B874EA20032311E /* base */, 56099E301CC9247E00A7772A /* bicycle_directions.cpp */, 56099E311CC9247E00A7772A /* bicycle_directions.hpp */, + 0C15B8011F02A61B0058E253 /* checkpoints.hpp */, 0C62BFE51E8ADC3100055A79 /* coding.hpp */, 0C5F5D1E1E798B0400307B98 /* cross_mwm_connector.cpp */, 0C5F5D1F1E798B0400307B98 /* cross_mwm_connector.hpp */, @@ -917,6 +920,7 @@ 0C8705051E0182F200BCAF71 /* route_point.hpp in Headers */, A1876BC71BB19C4300C9C743 /* speed_camera.hpp in Headers */, 56EA2FD51D8FD8590083F01A /* routing_helpers.hpp in Headers */, + 0C15B8021F02A61B0058E253 /* checkpoints.hpp in Headers */, 0C5F5D211E798B0400307B98 /* cross_mwm_connector_serialization.hpp in Headers */, 0C0DF9221DE898B70055A22F /* index_graph_starter.hpp in Headers */, 0C090C881E4E276700D52AFD /* world_graph.hpp in Headers */,