From 62985c22ba82dba58ba86a668d6193bf01727657 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 18 May 2016 13:42:57 +0300 Subject: [PATCH] Getting ready pedestrian and bicycle routing for one point paths and zero point paths. --- routing/bicycle_directions.cpp | 10 +++++----- routing/directions_engine.cpp | 7 ++++--- routing/pedestrian_directions.cpp | 7 ++++++- routing/road_graph_router.cpp | 7 ++++--- routing/route.cpp | 11 ++++++++++- routing/route.hpp | 5 ++++- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index cccba63e0e..b026f9f605 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -84,24 +84,24 @@ void BicycleDirectionsEngine::Generate(IRoadGraph const & graph, vector & routeGeometry, my::Cancellable const & cancellable) { - size_t const pathSize = path.size(); - CHECK_NOT_EQUAL(pathSize, 0, ()); - times.clear(); turns.clear(); routeGeometry.clear(); m_adjacentEdges.clear(); m_pathSegments.clear(); + size_t const pathSize = path.size(); + if (pathSize == 0) + return; + auto emptyPathWorkaround = [&]() { 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) + if (pathSize == 1) { - ASSERT(false, (pathSize)); emptyPathWorkaround(); return; } diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp index b883da100d..4576ee2586 100644 --- a/routing/directions_engine.cpp +++ b/routing/directions_engine.cpp @@ -12,6 +12,10 @@ namespace routing void IDirectionsEngine::CalculateTimes(IRoadGraph const & graph, vector const & path, Route::TTimes & times) const { + times.clear(); + if (path.size() <= 1) + return; + double const speedMPS = graph.GetMaxSpeedKMPH() * KMPH2MPS; times.reserve(path.size()); @@ -39,10 +43,7 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector & routeGeometry, my::Cancellable const & cancellable) { - CHECK_GREATER(path.size(), 1, ()); + times.clear(); + turns.clear(); + routeGeometry.clear(); + + if (path.size() <= 1) + return; CalculateTimes(graph, path, times); diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 40748bf84a..46719f87c0 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -165,7 +165,6 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route) { - if (!CheckMapExistence(startPoint, route) || !CheckMapExistence(finalPoint, route)) return RouteFileNotExist; @@ -259,7 +258,8 @@ unique_ptr CreatePedestrianAStarRouter(Index & index, TCountryFileFn co unique_ptr vehicleModelFactory(new PedestrianModelFactory()); unique_ptr algorithm(new AStarRoutingAlgorithm()); unique_ptr directionsEngine(new PedestrianDirectionsEngine()); - unique_ptr router(new RoadGraphRouter("astar-pedestrian", index, countryFileFn, move(vehicleModelFactory), move(algorithm), move(directionsEngine))); + unique_ptr router(new RoadGraphRouter("astar-pedestrian", index, countryFileFn, + move(vehicleModelFactory), move(algorithm), move(directionsEngine))); return router; } @@ -268,7 +268,8 @@ unique_ptr CreatePedestrianAStarBidirectionalRouter(Index & index, TCou unique_ptr vehicleModelFactory(new PedestrianModelFactory()); unique_ptr algorithm(new AStarBidirectionalRoutingAlgorithm()); unique_ptr directionsEngine(new PedestrianDirectionsEngine()); - unique_ptr router(new RoadGraphRouter("astar-bidirectional-pedestrian", index, countryFileFn, move(vehicleModelFactory), move(algorithm), move(directionsEngine))); + unique_ptr router(new RoadGraphRouter("astar-bidirectional-pedestrian", index, countryFileFn, + move(vehicleModelFactory), move(algorithm), move(directionsEngine))); return router; } diff --git a/routing/route.cpp b/routing/route.cpp index 8eae9308d7..da81fb98dd 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -50,18 +50,25 @@ void Route::AddAbsentCountry(string const & name) double Route::GetTotalDistanceMeters() const { + if (!m_poly.IsValid()) + return 0.0; return m_poly.GetTotalDistanceM(); } double Route::GetCurrentDistanceFromBeginMeters() const { + if (!m_poly.IsValid()) + return 0.0; return m_poly.GetDistanceFromBeginM(); } void Route::GetTurnsDistances(vector & distances) const { - double mercatorDistance = 0; distances.clear(); + if (!m_poly.IsValid()) + return; + + double mercatorDistance = 0.0; auto const & polyline = m_poly.GetPolyline(); for (auto currentTurn = m_turns.begin(); currentTurn != m_turns.end(); ++currentTurn) { @@ -84,6 +91,8 @@ void Route::GetTurnsDistances(vector & distances) const double Route::GetCurrentDistanceToEndMeters() const { + if (!m_poly.IsValid()) + return 0.0; return m_poly.GetDistanceToEndM(); } diff --git a/routing/route.hpp b/routing/route.hpp index b47acef439..0014f81f88 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -45,7 +45,10 @@ public: template void SetGeometry(TIter beg, TIter end) { - FollowedPolyline(beg, end).Swap(m_poly); + if (beg == end) + FollowedPolyline().Swap(m_poly); + else + FollowedPolyline(beg, end).Swap(m_poly); Update(); }