From f1f64fea5eb7450f5f7c01e89fc00f306cdfdedb Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Fri, 1 Apr 2016 13:05:26 +0300 Subject: [PATCH 1/6] Add new streets storage to route. --- routing/osrm_router.cpp | 53 ++++++++++++++++++++++------------- routing/osrm_router.hpp | 3 +- routing/road_graph_router.cpp | 2 ++ routing/route.hpp | 14 +++++++-- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 28ee8aecef..df35245358 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -160,9 +160,10 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & RouterDelegate const & delegate, Route & route) { - Route::TTurns TurnsDir; - Route::TTimes Times; - vector Points; + Route::TTurns turnsDir; + Route::TTimes times; + Route::TStreets streets; + vector points; for (RoutePathCross cross : path) { ASSERT_EQUAL(cross.startNode.mwmId, cross.finalNode.mwmId, ()); @@ -176,49 +177,59 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & if (!FindSingleRoute(cross.startNode, cross.finalNode, mwmMapping->m_dataFacade, routingResult)) return RouteNotFound; - if (!Points.empty()) + if (!points.empty()) { // Remove road end point and turn instruction. - Points.pop_back(); - TurnsDir.pop_back(); - Times.pop_back(); + points.pop_back(); + turnsDir.pop_back(); + times.pop_back(); } // Get annotated route. - Route::TTurns mwmTurnsDir; + Route::TTurns mwmturnsDir; Route::TTimes mwmTimes; + Route::TStreets mwmStreets; vector mwmPoints; - if (MakeTurnAnnotation(routingResult, mwmMapping, delegate, mwmPoints, mwmTurnsDir, mwmTimes) != NoError) + if (MakeTurnAnnotation(routingResult, mwmMapping, delegate, mwmPoints, mwmturnsDir, mwmTimes, mwmStreets) != NoError) { LOG(LWARNING, ("Can't load road path data from disk for", mwmMapping->GetCountryName())); return RouteNotFound; } // Connect annotated route. - auto const pSize = static_cast(Points.size()); - for (auto turn : mwmTurnsDir) + auto const pSize = static_cast(points.size()); + for (auto turn : mwmturnsDir) { if (turn.m_index == 0) continue; turn.m_index += pSize; - TurnsDir.push_back(turn); + turnsDir.push_back(turn); } - double const estimationTime = Times.size() ? Times.back().second : 0.0; + for (auto street : mwmStreets) + { + if (street.first == 0) + continue; + street.first += pSize; + streets.push_back(street); + } + + double const estimationTime = times.size() ? times.back().second : 0.0; for (auto time : mwmTimes) { if (time.first == 0) continue; time.first += pSize; time.second += estimationTime; - Times.push_back(time); + times.push_back(time); } - Points.insert(Points.end(), mwmPoints.begin(), mwmPoints.end()); + points.insert(points.end(), mwmPoints.begin(), mwmPoints.end()); } - route.SetGeometry(Points.begin(), Points.end()); - route.SetTurnInstructions(TurnsDir); - route.SetSectionTimes(Times); + route.SetGeometry(points.begin(), points.end()); + route.SetTurnInstructions(turnsDir); + route.SetSectionTimes(times); + route.SetStreetNames(streets); return NoError; } @@ -343,9 +354,10 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, Route::TTurns turnsDir; Route::TTimes times; + Route::TStreets streets; vector points; - if (MakeTurnAnnotation(routingResult, startMapping, delegate, points, turnsDir, times) != NoError) + if (MakeTurnAnnotation(routingResult, startMapping, delegate, points, turnsDir, times, streets) != NoError) { LOG(LWARNING, ("Can't load road path data from disk!")); return RouteNotFound; @@ -354,6 +366,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, route.SetGeometry(points.begin(), points.end()); route.SetTurnInstructions(turnsDir); route.SetSectionTimes(times); + route.SetStreetNames(streets); return NoError; } @@ -412,7 +425,7 @@ IRouter::ResultCode OsrmRouter::FindPhantomNodes(m2::PointD const & point, OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( RawRoutingResult const & routingResult, TRoutingMappingPtr const & mapping, RouterDelegate const & delegate, vector & points, Route::TTurns & turnsDir, - Route::TTimes & times) + Route::TTimes & times, Route::TStreets & streets) { ASSERT(mapping, ()); diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index e01b5e0510..05493058cc 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -81,12 +81,13 @@ protected: * \param points Storage for unpacked points of the path. * \param turnsDir output turns annotation storage. * \param times output times annotation storage. + * \param streets output street names along the path. * \return routing operation result code. */ ResultCode MakeTurnAnnotation(RawRoutingResult const & routingResult, TRoutingMappingPtr const & mapping, RouterDelegate const & delegate, vector & points, - Route::TTurns & turnsDir, Route::TTimes & times); + Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets); private: /*! diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index cf678a987d..36b2b9a631 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -251,12 +251,14 @@ void RoadGraphRouter::ReconstructRoute(vector && path, Route & route, Route::TTimes times; Route::TTurns turnsDir; + Route::TStreets streetNames; if (m_directionsEngine) m_directionsEngine->Generate(*m_roadGraph, path, times, turnsDir, cancellable); route.SetGeometry(geometry.begin(), geometry.end()); route.SetSectionTimes(times); route.SetTurnInstructions(turnsDir); + route.SetStreetNames(streetNames); } unique_ptr CreatePedestrianAStarRouter(Index & index, TCountryFileFn const & countryFileFn) diff --git a/routing/route.hpp b/routing/route.hpp index 21bc3340b2..dbbec4d4b9 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -23,9 +23,11 @@ namespace routing class Route { public: - typedef vector TTurns; - typedef pair TTimeItem; - typedef vector TTimes; + using TTurns = vector; + using TTimeItem = pair; + using TTimes = vector; + using TStreetItem = pair; + using TStreets = vector; explicit Route(string const & router) : m_router(router), m_routingSettings(GetCarRoutingSettings()) {} @@ -57,6 +59,11 @@ public: swap(m_times, v); } + inline void SetStreetNames(TStreets & v) + { + swap(m_streets, v); + } + uint32_t GetTotalTimeSec() const; uint32_t GetCurrentTimeToEndSec() const; @@ -130,6 +137,7 @@ private: TTurns m_turns; TTimes m_times; + TStreets m_streets; mutable double m_currentTime; }; From 406187e731ec164c2efad97bc62a0c42898c3572 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Fri, 1 Apr 2016 16:24:24 +0300 Subject: [PATCH 2/6] Streets reading implementation. --- routing/osrm_router.cpp | 14 ++++++++--- routing/route.cpp | 49 ++++++++++++++++++++++++++++++++++++- routing/route.hpp | 7 ++++++ routing/routing_session.cpp | 4 +-- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index df35245358..7a36f21aef 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -183,21 +183,23 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & points.pop_back(); turnsDir.pop_back(); times.pop_back(); + if (streets.back().first >= points.size()) + streets.pop_back(); } // Get annotated route. - Route::TTurns mwmturnsDir; + Route::TTurns mwmTurnsDir; Route::TTimes mwmTimes; Route::TStreets mwmStreets; vector mwmPoints; - if (MakeTurnAnnotation(routingResult, mwmMapping, delegate, mwmPoints, mwmturnsDir, mwmTimes, mwmStreets) != NoError) + if (MakeTurnAnnotation(routingResult, mwmMapping, delegate, mwmPoints, mwmTurnsDir, mwmTimes, mwmStreets) != NoError) { LOG(LWARNING, ("Can't load road path data from disk for", mwmMapping->GetCountryName())); return RouteNotFound; } // Connect annotated route. auto const pSize = static_cast(points.size()); - for (auto turn : mwmturnsDir) + for (auto turn : mwmTurnsDir) { if (turn.m_index == 0) continue; @@ -205,6 +207,8 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & turnsDir.push_back(turn); } + if (!mwmStreets.empty() && !streets.empty() && mwmStreets.front().second == streets.back().second) + mwmStreets.erase(mwmStreets.begin()); for (auto street : mwmStreets) { if (street.first == 0) @@ -472,6 +476,10 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( // ETA information. double const nodeTimeSeconds = loadedSegment.m_weight * kOSRMWeightToSecondsMultiplier; + // Street names. I put empty names too, to avoid freezing old street name while riding on + // unnamed street. + streets.emplace_back(max(points.size(), (size_t)1) - 1, loadedSegment.m_name); + // Turns information. if (segmentIndex > 0 && !points.empty() && skipTurnSegments == 0) { diff --git a/routing/route.cpp b/routing/route.cpp index a0e172d133..b1a8ceb130 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -19,7 +19,7 @@ namespace { double constexpr kLocationTimeThreshold = 60.0 * 1.0; double constexpr kOnEndToleranceM = 10.0; - +double constexpr kSteetNameLinkMeters = 400.; } // namespace Route::Route(string const & router, vector const & points, string const & name) @@ -39,6 +39,7 @@ void Route::Swap(Route & rhs) swap(m_currentTime, rhs.m_currentTime); swap(m_turns, rhs.m_turns); swap(m_times, rhs.m_times); + swap(m_streets, rhs.m_streets); m_absentCountries.swap(rhs.m_absentCountries); } @@ -150,6 +151,52 @@ Route::TTurns::const_iterator Route::GetCurrentTurn() const }); } +void Route::GetCurrentStreetName(string & name) const +{ + auto it = GetCurrentStreetNameIterAfter(m_poly.GetCurrentIter()); + if (it == m_streets.cend()) + name.clear(); + name = it->second; +} + +void Route::GetStreetNameAfterIdx(uint32_t idx, string & name) const +{ + name.clear(); + auto polyIter = m_poly.GetIterToIndex(idx); + auto it = GetCurrentStreetNameIterAfter(polyIter); + if (it == m_streets.cend()) + return; + for (;it != m_streets.cend(); ++it) + if (!it->second.empty()) + { + if (m_poly.GetDistanceM(polyIter, m_poly.GetIterToIndex(it->first)) < kSteetNameLinkMeters) + name = it->second; + return; + } +} + +Route::TStreets::const_iterator Route::GetCurrentStreetNameIterAfter(FollowedPolyline::Iter iter) const +{ + if (m_streets.empty()) + { + ASSERT(false, ()); + return m_streets.cend(); + } + + TStreets::const_iterator curIter = m_streets.cbegin(); + TStreets::const_iterator prevIter = curIter; + curIter++; + + while (curIter->first<=iter.m_ind) + { + ++prevIter; + ++curIter; + if (curIter==m_streets.cend()) + return curIter; + } + return prevIter; +} + bool Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const { auto it = GetCurrentTurn(); diff --git a/routing/route.hpp b/routing/route.hpp index dbbec4d4b9..b47acef439 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -86,6 +86,12 @@ public: /// \param turn is information about the nearest turn. bool GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const; + /// \brief Returns a name of a street where the user rides at this moment. + void GetCurrentStreetName(string &) const; + + /// \brief Returns a name of a street next to idx point of the path. Function avoids short unnamed links. + void GetStreetNameAfterIdx(uint32_t idx, string &) const; + /// @return true if GetNextTurn() returns a valid result in parameters, false otherwise. /// \param distanceToTurnMeters is a distance from current position to the second turn. /// \param turn is information about the second turn. @@ -122,6 +128,7 @@ private: void Update(); double GetPolySegAngle(size_t ind) const; TTurns::const_iterator GetCurrentTurn() const; + TStreets::const_iterator GetCurrentStreetNameIterAfter(FollowedPolyline::Iter iter) const; private: friend string DebugPrint(Route const & r); diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 36115d69fa..d522b609e1 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -288,8 +288,8 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const info.m_exitNum = turn.m_exitNum; info.m_time = max(kMinimumETASec, m_route.GetCurrentTimeToEndSec()); - info.m_sourceName = turn.m_sourceName; - info.m_targetName = turn.m_targetName; + m_route.GetCurrentStreetName(info.m_sourceName); + m_route.GetStreetNameAfterIdx(turn.m_index, info.m_targetName); info.m_completionPercent = GetCompletionPercent(); // Lane information. if (distanceToTurnMeters < kShowLanesDistInMeters) From 19d7673519385aba508be31b200240cec76ee680 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Mon, 4 Apr 2016 14:13:17 +0300 Subject: [PATCH 3/6] Street names integration test. --- .../osrm_street_names_test.cpp | 59 +++++++++++++++++++ .../routing_integration_tests.pro | 1 + .../routing_test_tools.cpp | 17 ++++++ .../routing_test_tools.hpp | 4 ++ 4 files changed, 81 insertions(+) create mode 100644 routing/routing_integration_tests/osrm_street_names_test.cpp diff --git a/routing/routing_integration_tests/osrm_street_names_test.cpp b/routing/routing_integration_tests/osrm_street_names_test.cpp new file mode 100644 index 0000000000..945da30f07 --- /dev/null +++ b/routing/routing_integration_tests/osrm_street_names_test.cpp @@ -0,0 +1,59 @@ +#include "testing/testing.hpp" + +#include "routing/routing_integration_tests/routing_test_tools.hpp" + +#include "routing/route.hpp" + +#include "platform/location.hpp" + + +using namespace routing; +using namespace routing::turns; + +void MoveRoute(Route & route, ms::LatLon const & coords) +{ + location::GpsInfo info; + info.m_horizontalAccuracy = 0.01; + info.m_verticalAccuracy = 0.01; + info.m_longitude = coords.lon; + info.m_latitude = coords.lat; + route.MoveIterator(info); +} + +UNIT_TEST(RussiaTulskayaToPaveletskayaStreetNamesTest) +{ + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetOsrmComponents(), + MercatorBounds::FromLatLon(55.70839, 37.62145), {0., 0.}, + MercatorBounds::FromLatLon(55.73198, 37.63945)); + + Route & route = *routeResult.first; + IRouter::ResultCode const result = routeResult.second; + TEST_EQUAL(result, IRouter::NoError, ()); + + integration::TestCurrentStreetName(route, "Большая Тульская улица"); + integration::TestNextStreetName(route, "Подольское шоссе"); + + MoveRoute(route, ms::LatLon(55.71398, 37.62443)); + + integration::TestCurrentStreetName(route, "Подольское шоссе"); + integration::TestNextStreetName(route, "Валовая улица"); + + + MoveRoute(route, ms::LatLon(55.72059, 37.62766)); + + integration::TestCurrentStreetName(route, "Павловская улица"); + integration::TestNextStreetName(route, "Валовая улица"); + + MoveRoute(route, ms::LatLon(55.72469, 37.62624)); + + integration::TestCurrentStreetName(route, "Большая Серпуховская улица"); + integration::TestNextStreetName(route, "Валовая улица"); + + MoveRoute(route, ms::LatLon(55.73034, 37.63099)); + + integration::TestCurrentStreetName(route, "Валовая улица"); + integration::TestNextStreetName(route, ""); + + integration::TestRouteLength(route, 3390.); +} diff --git a/routing/routing_integration_tests/routing_integration_tests.pro b/routing/routing_integration_tests/routing_integration_tests.pro index e3b4166285..c814a80d6b 100644 --- a/routing/routing_integration_tests/routing_integration_tests.pro +++ b/routing/routing_integration_tests/routing_integration_tests.pro @@ -30,6 +30,7 @@ SOURCES += \ osrm_turn_test.cpp \ pedestrian_route_test.cpp \ routing_test_tools.cpp \ + osrm_street_names_test.cpp \ HEADERS += \ routing_test_tools.hpp \ diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index 7f7110323b..2a04eed3fc 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -188,6 +188,23 @@ namespace integration TEST_EQUAL(route.GetTurns().size() - 1, expectedTurnCount, ()); } + void TestCurrentStreetName(routing::Route const & route, string const & expectedStreetName) + { + string streetName; + route.GetCurrentStreetName(streetName); + TEST_EQUAL(streetName, expectedStreetName, ()); + } + + void TestNextStreetName(routing::Route const & route, string const & expectedStreetName) + { + string streetName; + double distance; + turns::TurnItem turn; + TEST(route.GetCurrentTurn(distance, turn), ()); + route.GetStreetNameAfterIdx(turn.m_index, streetName); + TEST_EQUAL(streetName, expectedStreetName, ()); + } + void TestRouteLength(Route const & route, double expectedRouteMeters, double relativeError) { diff --git a/routing/routing_integration_tests/routing_test_tools.hpp b/routing/routing_integration_tests/routing_test_tools.hpp index 93e505e022..c0e3a8e894 100644 --- a/routing/routing_integration_tests/routing_test_tools.hpp +++ b/routing/routing_integration_tests/routing_test_tools.hpp @@ -144,4 +144,8 @@ unique_ptr CreateCountryInfoGetter(); /// Extracting appropriate TestTurn if any. If not TestTurn::isValid() returns false. /// inaccuracy is set in meters. TestTurn GetNthTurn(Route const & route, uint32_t turnNumber); + + void TestCurrentStreetName(routing::Route const & route, string const & expectedStreetName); + + void TestNextStreetName(routing::Route const & route, string const & expectedStreetName); } From 5c83b3debdaa336c207b19965aead892a43992f9 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Mon, 4 Apr 2016 16:31:40 +0300 Subject: [PATCH 4/6] More tests. --- routing/route.cpp | 6 +++--- routing/routing_tests/route_tests.cpp | 31 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/routing/route.cpp b/routing/route.cpp index b1a8ceb130..ad1ad6015c 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -169,7 +169,7 @@ void Route::GetStreetNameAfterIdx(uint32_t idx, string & name) const for (;it != m_streets.cend(); ++it) if (!it->second.empty()) { - if (m_poly.GetDistanceM(polyIter, m_poly.GetIterToIndex(it->first)) < kSteetNameLinkMeters) + if (m_poly.GetDistanceM(polyIter, m_poly.GetIterToIndex(max(it->first, static_cast(polyIter.m_ind)))) < kSteetNameLinkMeters) name = it->second; return; } @@ -187,14 +187,14 @@ Route::TStreets::const_iterator Route::GetCurrentStreetNameIterAfter(FollowedPol TStreets::const_iterator prevIter = curIter; curIter++; - while (curIter->first<=iter.m_ind) + while (curIter->first < iter.m_ind) { ++prevIter; ++curIter; if (curIter==m_streets.cend()) return curIter; } - return prevIter; + return curIter->first == iter.m_ind ? curIter : prevIter; } bool Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn) const diff --git a/routing/routing_tests/route_tests.cpp b/routing/routing_tests/route_tests.cpp index fd65001cbe..aa512729dd 100644 --- a/routing/routing_tests/route_tests.cpp +++ b/routing/routing_tests/route_tests.cpp @@ -18,6 +18,7 @@ static vector const kTestGeometry({{0, 0}, {0,1}, {1,1}, {1,2}, {1,3 static vector const kTestTurns({turns::TurnItem(1, turns::TurnDirection::TurnLeft), turns::TurnItem(2, turns::TurnDirection::TurnRight), turns::TurnItem(4, turns::TurnDirection::ReachedYourDestination)}); +static Route::TStreets const kTestNames({{0,"Street1"}, {1, "Street2"}, {4, "Street3"}}); location::GpsInfo GetGps(double x, double y) { @@ -157,3 +158,33 @@ UNIT_TEST(NextTurnsTest) TEST_EQUAL(turnsDist.size(), 1, ()); } } + +UNIT_TEST(RouteNameTest) +{ + Route route("TestRouter"); + + route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); + vector turns(kTestTurns); + route.SetTurnInstructions(turns); + Route::TStreets names(kTestNames); + route.SetStreetNames(names); + + string name; + route.GetCurrentStreetName(name); + TEST_EQUAL(name, "Street1", ()); + + route.GetStreetNameAfterIdx(0, name); + TEST_EQUAL(name, "Street1", ()); + + route.GetStreetNameAfterIdx(1, name); + TEST_EQUAL(name, "Street2", ()); + + route.GetStreetNameAfterIdx(2, name); + TEST_EQUAL(name, "Street2", ()); + + route.GetStreetNameAfterIdx(3, name); + TEST_EQUAL(name, "Street2", ()); + + route.GetStreetNameAfterIdx(4, name); + TEST_EQUAL(name, "Street3", ()); +} From b5efa9533070de39ea3ed99384a517dcbf410654 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Mon, 4 Apr 2016 16:34:12 +0300 Subject: [PATCH 5/6] clang-format --- routing/osrm_router.hpp | 6 +++--- .../routing_integration_tests/osrm_street_names_test.cpp | 5 +---- routing/routing_tests/route_tests.cpp | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index 05493058cc..b9cf3d0128 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -85,9 +85,9 @@ protected: * \return routing operation result code. */ ResultCode MakeTurnAnnotation(RawRoutingResult const & routingResult, - TRoutingMappingPtr const & mapping, - RouterDelegate const & delegate, vector & points, - Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets); + TRoutingMappingPtr const & mapping, RouterDelegate const & delegate, + vector & points, Route::TTurns & turnsDir, + Route::TTimes & times, Route::TStreets & streets); private: /*! diff --git a/routing/routing_integration_tests/osrm_street_names_test.cpp b/routing/routing_integration_tests/osrm_street_names_test.cpp index 945da30f07..a59aea2cd1 100644 --- a/routing/routing_integration_tests/osrm_street_names_test.cpp +++ b/routing/routing_integration_tests/osrm_street_names_test.cpp @@ -6,7 +6,6 @@ #include "platform/location.hpp" - using namespace routing; using namespace routing::turns; @@ -23,8 +22,7 @@ void MoveRoute(Route & route, ms::LatLon const & coords) UNIT_TEST(RussiaTulskayaToPaveletskayaStreetNamesTest) { TRouteResult const routeResult = integration::CalculateRoute( - integration::GetOsrmComponents(), - MercatorBounds::FromLatLon(55.70839, 37.62145), {0., 0.}, + integration::GetOsrmComponents(), MercatorBounds::FromLatLon(55.70839, 37.62145), {0., 0.}, MercatorBounds::FromLatLon(55.73198, 37.63945)); Route & route = *routeResult.first; @@ -39,7 +37,6 @@ UNIT_TEST(RussiaTulskayaToPaveletskayaStreetNamesTest) integration::TestCurrentStreetName(route, "Подольское шоссе"); integration::TestNextStreetName(route, "Валовая улица"); - MoveRoute(route, ms::LatLon(55.72059, 37.62766)); integration::TestCurrentStreetName(route, "Павловская улица"); diff --git a/routing/routing_tests/route_tests.cpp b/routing/routing_tests/route_tests.cpp index aa512729dd..bbb2c7a06f 100644 --- a/routing/routing_tests/route_tests.cpp +++ b/routing/routing_tests/route_tests.cpp @@ -18,7 +18,7 @@ static vector const kTestGeometry({{0, 0}, {0,1}, {1,1}, {1,2}, {1,3 static vector const kTestTurns({turns::TurnItem(1, turns::TurnDirection::TurnLeft), turns::TurnItem(2, turns::TurnDirection::TurnRight), turns::TurnItem(4, turns::TurnDirection::ReachedYourDestination)}); -static Route::TStreets const kTestNames({{0,"Street1"}, {1, "Street2"}, {4, "Street3"}}); +static Route::TStreets const kTestNames({{0, "Street1"}, {1, "Street2"}, {4, "Street3"}}); location::GpsInfo GetGps(double x, double y) { From e91a1892c082340ec8c25d8479b1e85f20da2ae0 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Tue, 5 Apr 2016 12:55:40 +0300 Subject: [PATCH 6/6] Review fixes. --- routing/osrm_router.cpp | 5 ++--- routing/route.cpp | 5 +++-- .../routing_integration_tests/routing_integration_tests.pro | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 7a36f21aef..34d5471a10 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -183,8 +183,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & points.pop_back(); turnsDir.pop_back(); times.pop_back(); - if (streets.back().first >= points.size()) - streets.pop_back(); + // Streets might not point to the last point of the path. } // Get annotated route. @@ -478,7 +477,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( // Street names. I put empty names too, to avoid freezing old street name while riding on // unnamed street. - streets.emplace_back(max(points.size(), (size_t)1) - 1, loadedSegment.m_name); + streets.emplace_back(max(points.size(), static_cast(1)) - 1, loadedSegment.m_name); // Turns information. if (segmentIndex > 0 && !points.empty() && skipTurnSegments == 0) diff --git a/routing/route.cpp b/routing/route.cpp index ad1ad6015c..35a939b579 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -156,7 +156,8 @@ void Route::GetCurrentStreetName(string & name) const auto it = GetCurrentStreetNameIterAfter(m_poly.GetCurrentIter()); if (it == m_streets.cend()) name.clear(); - name = it->second; + else + name = it->second; } void Route::GetStreetNameAfterIdx(uint32_t idx, string & name) const @@ -191,7 +192,7 @@ Route::TStreets::const_iterator Route::GetCurrentStreetNameIterAfter(FollowedPol { ++prevIter; ++curIter; - if (curIter==m_streets.cend()) + if (curIter == m_streets.cend()) return curIter; } return curIter->first == iter.m_ind ? curIter : prevIter; diff --git a/routing/routing_integration_tests/routing_integration_tests.pro b/routing/routing_integration_tests/routing_integration_tests.pro index c814a80d6b..691c7a9292 100644 --- a/routing/routing_integration_tests/routing_integration_tests.pro +++ b/routing/routing_integration_tests/routing_integration_tests.pro @@ -27,10 +27,10 @@ SOURCES += \ cross_section_tests.cpp \ online_cross_tests.cpp \ osrm_route_test.cpp \ + osrm_street_names_test.cpp \ osrm_turn_test.cpp \ pedestrian_route_test.cpp \ routing_test_tools.cpp \ - osrm_street_names_test.cpp \ HEADERS += \ routing_test_tools.hpp \