diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index b6d9442ad1..d5a787f530 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1315,24 +1315,27 @@ extern "C" jclass const klass = env->FindClass("com/mapswithme/maps/LocationState$RoutingInfo"); ASSERT(klass, (jni::DescribeException())); - static jmethodID const ctorRouteInfoID = env->GetMethodID(klass, "", - "(Ljava/lang/String;Ljava/lang/String;" - "Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II" - "[Lcom/mapswithme/maps/LocationState$SingleLaneInfo;)V"); + static jmethodID const ctorRouteInfoID = + env->GetMethodID(klass, "", + "(Ljava/lang/String;Ljava/lang/String;" + "Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II" + "[Lcom/mapswithme/maps/LocationState$SingleLaneInfo;)V"); ASSERT(ctorRouteInfoID, (jni::DescribeException())); - vector const & lanes = info.m_lanes; + vector const & lanes = info.m_lanes; jobjectArray jLanes = nullptr; if (!lanes.empty()) { // A new java array of SingleLaneInfo classes for lane information is allocated here. // Then it will be saved in com.mapswithme.maps.LocationState, and then removed by java GC. - jclass const myClassArray = env->FindClass("com/mapswithme/maps/LocationState$SingleLaneInfo"); - ASSERT(myClassArray, (jni::DescribeException())); + jclass const singleLaneInfoClass = + env->FindClass("com/mapswithme/maps/LocationState$SingleLaneInfo"); + ASSERT(singleLaneInfoClass, (jni::DescribeException())); size_t const lanesSize = lanes.size(); - jLanes = env->NewObjectArray(lanesSize, myClassArray, nullptr); + jLanes = env->NewObjectArray(lanesSize, singleLaneInfoClass, nullptr); ASSERT(jLanes, (jni::DescribeException())); - static jmethodID const ctorSingleLaneInfoID = env->GetMethodID(myClassArray, "", "([BZ)V"); + static jmethodID const ctorSingleLaneInfoID = + env->GetMethodID(singleLaneInfoClass, "", "([BZ)V"); ASSERT(ctorSingleLaneInfoID, (jni::DescribeException())); jbyteArray singleLane = nullptr; @@ -1344,7 +1347,8 @@ extern "C" singleLane = env->NewByteArray(laneSize); ASSERT(singleLane, (jni::DescribeException())); env->SetByteArrayRegion(singleLane, 0, laneSize, lanes[j].m_lane.data()); - singleLaneInfo = env->NewObject(myClassArray, ctorSingleLaneInfoID, singleLane, lanes[j].m_isActive); + singleLaneInfo = env->NewObject(singleLaneInfoClass, ctorSingleLaneInfoID, singleLane, + lanes[j].m_isRecommended); ASSERT(singleLaneInfo, (jni::DescribeException())); env->SetObjectArrayElement(jLanes, j, singleLaneInfo); env->DeleteLocalRef(singleLaneInfo); @@ -1354,8 +1358,7 @@ extern "C" jobject const result = env->NewObject( klass, ctorRouteInfoID, jni::ToJavaString(env, info.m_distToTarget), - jni::ToJavaString(env, info.m_targetUnitsSuffix), - jni::ToJavaString(env, info.m_distToTurn), + jni::ToJavaString(env, info.m_targetUnitsSuffix), jni::ToJavaString(env, info.m_distToTurn), jni::ToJavaString(env, info.m_turnUnitsSuffix), jni::ToJavaString(env, info.m_targetName), info.m_turn, info.m_time, jLanes); ASSERT(result, (jni::DescribeException())); diff --git a/android/src/com/mapswithme/maps/LocationState.java b/android/src/com/mapswithme/maps/LocationState.java index 196155861c..86edae96bf 100644 --- a/android/src/com/mapswithme/maps/LocationState.java +++ b/android/src/com/mapswithme/maps/LocationState.java @@ -37,11 +37,12 @@ public enum LocationState mIsActive = isActive; } - private String DumpString() + @Override + public String toString() { - final int startCapacity = 32; - StringBuilder sb = new StringBuilder(startCapacity); - sb.append("Is lane active? ").append(mIsActive).append(":"); + final int initialCapacity = 32; + StringBuilder sb = new StringBuilder(initialCapacity); + sb.append("Is the lane active? ").append(mIsActive).append(". The lane directions IDs are"); for (byte i : mLane) sb.append(" ").append(i); return sb.toString(); @@ -125,9 +126,9 @@ public enum LocationState { for (int j = 0; j < lanes.length; j++) { - final int startCapacity = 32; - StringBuilder sb = new StringBuilder(startCapacity); - sb.append("Lane number ").append(j).append(":").append(lanes[j].DumpString()); + final int initialCapacity = 32; + StringBuilder sb = new StringBuilder(initialCapacity); + sb.append("Lane number ").append(j).append(". ").append(lanes[j]); Log.d("JNIARRAY", " " + sb.toString()); } } diff --git a/integration_tests/osrm_route_test.cpp b/integration_tests/osrm_route_test.cpp index 9dfbe4b488..d95fea49b2 100644 --- a/integration_tests/osrm_route_test.cpp +++ b/integration_tests/osrm_route_test.cpp @@ -10,59 +10,59 @@ namespace { UNIT_TEST(RussiaMoscowLenigradskiy39GerPanfilovtsev22RouteTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {37.53758809983519, 67.536162466434234}, - {0., 0.}, {37.40993977728661, 67.644784047393685}, 14296.); + integration::CalculateRouteAndTestRouteLength(integration::GetAllMaps(), + {37.53758809983519, 67.536162466434234}, {0., 0.}, + {37.40993977728661, 67.644784047393685}, 14296.); } UNIT_TEST(RussiaMoscowGerPanfilovtsev22SolodchaPravdiRouteTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {37.409929478750627, 67.644798619710073}, - {0., 0.}, {39.836562407458047, 65.774372510437971}, 239426.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), {37.409929478750627, 67.644798619710073}, {0., 0.}, + {39.836562407458047, 65.774372510437971}, 239426.); } UNIT_TEST(UKRugbyStIvesRouteTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {-1.2653036222483705, 61.691304855049886}, - {0., 0.}, {-5.4799407508360218, 58.242809563579847}, 455902.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), {-1.2653036222483705, 61.691304855049886}, {0., 0.}, + {-5.4799407508360218, 58.242809563579847}, 455902.); } UNIT_TEST(RussiaMoscowLenigradskiy39ItalySienaCenterRouteTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {37.537596024929826, 67.536160359657288}, - {0., 0.}, {11.327927635052676, 48.166256203616726}, 2870710.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), {37.537596024929826, 67.536160359657288}, {0., 0.}, + {11.327927635052676, 48.166256203616726}, 2870710.); } UNIT_TEST(RussiaMoscowLenigradskiy39EnglandLondonCenterRouteTest) { //@todo put down a correct route length when router is fixed - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {37.537572384446207, 67.536189683408367}, - {0., 0.}, {-0.084976483156808751, 60.298304898120428}, 1000.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), {37.537572384446207, 67.536189683408367}, {0., 0.}, + {-0.084976483156808751, 60.298304898120428}, 1000.); } UNIT_TEST(RussiaMoscowLenigradskiy39RepublicOfSouthAfricaCapeTownCenterRouteTest) { //@todo put down a correct route length when router is fixed - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, {37.537543510152318, 67.536217686389165}, - {0., 0.}, {18.542688617866236, -36.095015335418523}, 1000.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), {37.537543510152318, 67.536217686389165}, {0., 0.}, + {18.542688617866236, -36.095015335418523}, 1000.); } UNIT_TEST(ArbatBaliCrimeanForwardCrossMwmTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, MercatorBounds::FromLatLon(46.152324, 34.804955), - {0., 0.}, MercatorBounds::FromLatLon(45.35697, 35.369712), 105000.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), MercatorBounds::FromLatLon(46.152324, 34.804955), {0., 0.}, + MercatorBounds::FromLatLon(45.35697, 35.369712), 105000.); } UNIT_TEST(ArbatBaliCrimeanBackwardCrossTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - integration::CalculateRouteAndTestRouteLength(routerComponents, MercatorBounds::FromLatLon(45.356971, 35.369712), - {0., 0.}, MercatorBounds::FromLatLon(46.152324, 34.804955), 105000.); + integration::CalculateRouteAndTestRouteLength( + integration::GetAllMaps(), MercatorBounds::FromLatLon(45.356971, 35.369712), {0., 0.}, + MercatorBounds::FromLatLon(46.152324, 34.804955), 105000.); } } diff --git a/integration_tests/osrm_test_tools.cpp b/integration_tests/osrm_test_tools.cpp index 4791aab6a8..64447eb402 100644 --- a/integration_tests/osrm_test_tools.cpp +++ b/integration_tests/osrm_test_tools.cpp @@ -130,49 +130,51 @@ namespace integration return LoadMaps(maps); } - shared_ptr GetAllMaps() + OsrmRouterComponents const & GetAllMaps() { - static shared_ptr inst = LoadAllMaps(); + static shared_ptr const inst = LoadAllMaps(); ASSERT(inst, ()); - return inst; + return *inst; } - RouteResultT CalculateRoute(shared_ptr routerComponents, - m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt) + TRouteResult CalculateRoute(OsrmRouterComponents const & routerComponents, + m2::PointD const & startPoint, m2::PointD const & startDirection, + m2::PointD const & finalPoint) { - ASSERT(routerComponents, ()); - OsrmRouter * osrmRouter = routerComponents->GetOsrmRouter(); + OsrmRouter * osrmRouter = routerComponents.GetOsrmRouter(); ASSERT(osrmRouter, ()); shared_ptr route(new Route("mapsme")); OsrmRouter::ResultCode result = - osrmRouter->CalculateRoute(startPt, startDr, finalPt, *route.get()); - return RouteResultT(route, result); - } - - void TestTurnCount(shared_ptr const route, uint32_t referenceTurnCount) - { + osrmRouter->CalculateRoute(startPoint, startDirection, finalPoint, *route.get()); ASSERT(route, ()); - TEST_EQUAL(route->GetTurnsGeometry().size(), referenceTurnCount, ()); + return TRouteResult(route, result); } - void TestRouteLength(shared_ptr const route, double referenceRouteLength, double routeLenInaccuracy) + void TestTurnCount(routing::Route const & route, uint32_t expectedTurnCount) { - ASSERT(route, ()); - double const delta = referenceRouteLength * routeLenInaccuracy; - double const routeLength = route->GetDistance(); - TEST_LESS_OR_EQUAL(routeLength - delta, referenceRouteLength, ()); - TEST_GREATER_OR_EQUAL(routeLength + delta, referenceRouteLength, ()); + TEST_EQUAL(route.GetTurnsGeometry().size(), expectedTurnCount, ()); } - void CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, - m2::PointD const & startDr, m2::PointD const & finalPt, double referenceRouteLength, - double routeLenInaccuracy) + void TestRouteLength(Route const & route, double expectedRouteLength, + double relativeError) { - RouteResultT routeResult = CalculateRoute(routerComponents, startPt, startDr, finalPt); - shared_ptr const route = routeResult.first; + double const delta = expectedRouteLength * relativeError; + double const routeLength = route.GetDistance(); + TEST_LESS_OR_EQUAL(routeLength - delta, expectedRouteLength, ()); + TEST_GREATER_OR_EQUAL(routeLength + delta, expectedRouteLength, ()); + } + + void CalculateRouteAndTestRouteLength(OsrmRouterComponents const & routerComponents, + m2::PointD const & startPoint, + m2::PointD const & startDirection, + m2::PointD const & finalPoint, double expectedRouteLength, + double relativeError) + { + TRouteResult routeResult = + CalculateRoute(routerComponents, startPoint, startDirection, finalPoint); OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); - TestRouteLength(route, referenceRouteLength, routeLenInaccuracy); + TestRouteLength(*routeResult.first, expectedRouteLength, relativeError); } const TestTurn & TestTurn::TestValid() const @@ -187,65 +189,65 @@ namespace integration return *this; } - const TestTurn & TestTurn::TestPoint(m2::PointD const & referencePnt, double inaccuracy) const + const TestTurn & TestTurn::TestPoint(m2::PointD const & expectedPoint, double inaccuracyMeters) const { - double const dist = ms::DistanceOnEarth(referencePnt.y, referencePnt.x, m_pnt.y, m_pnt.x); - TEST_LESS(dist, inaccuracy, ()); + double const dist = ms::DistanceOnEarth(expectedPoint.y, expectedPoint.x, m_point.y, m_point.x); + TEST_LESS(dist, inaccuracyMeters, ()); return *this; } - const TestTurn & TestTurn::TestDirection(routing::turns::TurnDirection referenceDirection) const + const TestTurn & TestTurn::TestDirection(routing::turns::TurnDirection expectedDirection) const { - TEST_EQUAL(m_direction, referenceDirection, ()); + TEST_EQUAL(m_direction, expectedDirection, ()); return *this; } - const TestTurn & TestTurn::TestOneOfDirections(set referenceDirections) const + const TestTurn & TestTurn::TestOneOfDirections( + set const & expectedDirections) const { - TEST(referenceDirections.find(m_direction) != referenceDirections.end(), ()); + TEST(expectedDirections.find(m_direction) != expectedDirections.cend(), ()); return *this; } - const TestTurn & TestTurn::TestRoundAboutExitNum(uint32_t referenceRoundAboutExitNum) const + const TestTurn & TestTurn::TestRoundAboutExitNum(uint32_t expectedRoundAboutExitNum) const { - TEST_EQUAL(m_roundAboutExitNum, referenceRoundAboutExitNum, ()); + TEST_EQUAL(m_roundAboutExitNum, expectedRoundAboutExitNum, ()); return *this; } - TestTurn GetNthTurn(shared_ptr const route, uint32_t referenceTurnNumber) + TestTurn GetNthTurn(routing::Route const & route, uint32_t expectedTurnNumber) { - ASSERT(route, ()); - - turns::TurnsGeomT const & turnsGeom = route->GetTurnsGeometry(); - if (referenceTurnNumber >= turnsGeom.size()) + turns::TurnsGeomT const & turnsGeom = route.GetTurnsGeometry(); + if (expectedTurnNumber >= turnsGeom.size()) return TestTurn(); - Route::TurnsT const & turns = route->GetTurns(); - if (referenceTurnNumber >= turns.size()) + Route::TurnsT const & turns = route.GetTurns(); + if (expectedTurnNumber >= turns.size()) return TestTurn(); - turns::TurnGeom const & turnGeom = turnsGeom[referenceTurnNumber]; + turns::TurnGeom const & turnGeom = turnsGeom[expectedTurnNumber]; ASSERT_LESS(turnGeom.m_turnIndex, turnGeom.m_points.size(), ()); - TurnItem const & turn = turns[referenceTurnNumber]; + TurnItem const & turn = turns[expectedTurnNumber]; return TestTurn(turnGeom.m_points[turnGeom.m_turnIndex], turn.m_turn, turn.m_exitNum); } - TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & referenceTurnPnt, double inaccuracy) + TestTurn GetTurnByPoint(routing::Route const & route, m2::PointD const & expectedTurnPoint, + double inaccuracyMeters) { - ASSERT(route, ()); - turns::TurnsGeomT const & turnsGeom = route->GetTurnsGeometry(); - Route::TurnsT const & turns = route->GetTurns(); + turns::TurnsGeomT const & turnsGeom = route.GetTurnsGeometry(); + Route::TurnsT const & turns = route.GetTurns(); ASSERT_EQUAL(turnsGeom.size() + 1, turns.size(), ()); for (int i = 0; i != turnsGeom.size(); ++i) { turns::TurnGeom const & turnGeom = turnsGeom[i]; ASSERT_LESS(turnGeom.m_turnIndex, turnGeom.m_points.size(), ()); - m2::PointD const turnPnt = turnGeom.m_points[turnGeom.m_turnIndex]; - if (ms::DistanceOnEarth(turnPnt.y, turnPnt.x, referenceTurnPnt.y, referenceTurnPnt.x) <= inaccuracy) + m2::PointD const turnPoint = turnGeom.m_points[turnGeom.m_turnIndex]; + if (ms::DistanceOnEarth(turnPoint.y, turnPoint.x, expectedTurnPoint.y, expectedTurnPoint.x) <= + inaccuracyMeters) { TurnItem const & turn = turns[i]; - return TestTurn(turnPnt, turn.m_turn, turn.m_exitNum); + return TestTurn(turnPoint, turn.m_turn, turn.m_exitNum); } } return TestTurn(); diff --git a/integration_tests/osrm_test_tools.hpp b/integration_tests/osrm_test_tools.hpp index 0aad5cb2fd..4a44e4ee85 100644 --- a/integration_tests/osrm_test_tools.hpp +++ b/integration_tests/osrm_test_tools.hpp @@ -1,16 +1,17 @@ #pragma once +#include "std/set.hpp" #include "std/shared_ptr.hpp" #include "std/string.hpp" +#include "std/utility.hpp" #include "std/vector.hpp" -#include "std/set.hpp" #include "routing/osrm_router.hpp" /* * These tests are developed to simplify routing integration tests writing. * You can use the interface bellow however you want but there are some hints. - * 1. Most likely you want to use GetAllMaps() to get shared_ptr. + * 1. Most likely you want to use GetAllMaps() to get ref to OsrmRouterComponents. * It loads all the maps from directories Platform::WritableDir() * and Platform::ResourcesDir() only once and then reuse it. * Use LoadMaps() only if you want to test something on a special map set. @@ -25,7 +26,8 @@ * - to get all necessary parameters and result of the route calculation; * - to place them into the test you're writing. * 5. The recommended way for naming tests for a route from one place to another one is - * + * * 6. It's a good idea to use short routes for testing turns. The thing is geometry of long routes * could be changes for one dataset (osrm version) to another one. * The shorter route the less chance it'll be changed. @@ -33,7 +35,7 @@ using namespace routing; using namespace turns; -typedef pair, OsrmRouter::ResultCode> RouteResultT; +typedef pair, OsrmRouter::ResultCode> TRouteResult; namespace integration { @@ -41,49 +43,67 @@ namespace integration void TestOnlineCrosses(m2::PointD const & startPoint, m2::PointD const & finalPoint, vector const & expected, - shared_ptr & routerComponents); + OsrmRouterComponents & routerComponents); - shared_ptr GetAllMaps(); + OsrmRouterComponents const & GetAllMaps(); shared_ptr LoadMaps(vector const & mapNames); - RouteResultT CalculateRoute(shared_ptr routerComponents, - m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt); + TRouteResult CalculateRoute(OsrmRouterComponents const & routerComponents, + m2::PointD const & startPoint, m2::PointD const & startDirection, + m2::PointD const & finalPoint); - void TestTurnCount(shared_ptr const route, uint32_t referenceTurnCount); + void TestTurnCount(Route const & route, uint32_t expectedTurnCount); /// Testing route length. - /// It is used for checking if routes have reference(sample) length. - /// The a created route will pass the test iff - /// referenceRouteLength - referenceRouteLength * routeLenInaccuracy <= route->GetDistance() - /// && referenceRouteLength + referenceRouteLength * routeLenInaccuracy >= route->GetDistance() - void TestRouteLength(shared_ptr const route, double referenceRouteLength, double routeLenInaccuracy = 0.01); - void CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, - m2::PointD const & startDr, m2::PointD const & finalPt, double referenceRouteLength, - double routeLenInaccuracy = 0.07); + /// It is used for checking if routes have expected(sample) length. + /// A created route will pass the test iff + /// expectedRouteLength - expectedRouteLength * relativeError <= route->GetDistance() + /// && expectedRouteLength + expectedRouteLength * relativeError >= route->GetDistance() + void TestRouteLength(Route const & route, double expectedRouteLength, + double relativeError = 0.01); + void CalculateRouteAndTestRouteLength(OsrmRouterComponents const & routerComponents, + m2::PointD const & startPoint, + m2::PointD const & startDirection, + m2::PointD const & finalPoint, double expectedRouteLength, + double relativeError = 0.07); class TestTurn { - friend TestTurn GetNthTurn(shared_ptr const route, uint32_t turnNumber); - friend TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & turnPnt, double inaccuracy); + friend TestTurn GetNthTurn(Route const & route, uint32_t expectedTurnNumber); + friend TestTurn GetTurnByPoint(Route const & route, m2::PointD const & expectedTurnPoint, + double inaccuracy); - m2::PointD const m_pnt; + m2::PointD const m_point; TurnDirection const m_direction; uint32_t const m_roundAboutExitNum; bool const m_isValid; - TestTurn() : m_pnt({0., 0.}), m_direction(TurnDirection::NoTurn), m_roundAboutExitNum(0), m_isValid(false) {} - TestTurn(m2::PointD const & pnt, TurnDirection direction, uint32_t roundAboutExitNum) : - m_pnt(pnt), m_direction(direction), m_roundAboutExitNum(roundAboutExitNum), m_isValid(true) {} + TestTurn() + : m_point({0., 0.}), + m_direction(TurnDirection::NoTurn), + m_roundAboutExitNum(0), + m_isValid(false) + { + } + TestTurn(m2::PointD const & pnt, TurnDirection direction, uint32_t roundAboutExitNum) + : m_point(pnt), + m_direction(direction), + m_roundAboutExitNum(roundAboutExitNum), + m_isValid(true) + { + } + public: const TestTurn & TestValid() const; const TestTurn & TestNotValid() const; - const TestTurn & TestPoint(m2::PointD const & referencePnt, double inaccuracy = 3.) const; - const TestTurn & TestDirection(TurnDirection referenceDirection) const; - const TestTurn & TestOneOfDirections(set referenceDirections) const; - const TestTurn & TestRoundAboutExitNum(uint32_t referenceRoundAboutExitNum) const; + const TestTurn & TestPoint(m2::PointD const & expectedPoint, double inaccuracyMeters = 3.) const; + const TestTurn & TestDirection(TurnDirection expectedDirection) const; + const TestTurn & TestOneOfDirections(set const & expectedDirections) const; + const TestTurn & TestRoundAboutExitNum(uint32_t expectedRoundAboutExitNum) const; }; /// Extracting appropriate TestTurn if any. If not TestTurn::isValid() returns false. /// inaccuracy is set in meters. - TestTurn GetNthTurn(shared_ptr const route, uint32_t turnNumber); - TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & turnPnt, double inaccuracy = 3.); + TestTurn GetNthTurn(Route const & route, uint32_t expectedTurnNumber); + TestTurn GetTurnByPoint(Route const & route, m2::PointD const & expectedTurnPoint, + double inaccuracyMeters = 3.); } diff --git a/integration_tests/osrm_turn_test.cpp b/integration_tests/osrm_turn_test.cpp index da2e75a536..09716cfb89 100644 --- a/integration_tests/osrm_turn_test.cpp +++ b/integration_tests/osrm_turn_test.cpp @@ -10,57 +10,80 @@ using namespace routing::turns; UNIT_TEST(RussiaMoscowLenigradskiy39UturnTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.537544383032568, 67.536216737893028}, {0., 0.}, + {37.538908531885973, 67.54544090660923}); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.537544383032568, 67.536216737893028}, - {0., 0.}, {37.538908531885973, 67.54544090660923}); - - shared_ptr const route = routeResult.first; + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); - integration::GetNthTurn(route, 0).TestValid().TestPoint({37.545981835916507, 67.530713137468041}) - .TestOneOfDirections({TurnDirection::TurnSlightLeft , TurnDirection::TurnLeft}); - integration::GetNthTurn(route, 1).TestValid().TestPoint({37.546738218864334, 67.531659957257347}).TestDirection(TurnDirection::TurnLeft); - integration::GetNthTurn(route, 2).TestValid().TestPoint({37.539925407915746, 67.537083383925875}).TestDirection(TurnDirection::TurnRight); + integration::GetNthTurn(route, 0) + .TestValid() + .TestPoint({37.545981835916507, 67.530713137468041}) + .TestOneOfDirections({TurnDirection::TurnSlightLeft, TurnDirection::TurnLeft}); + integration::GetNthTurn(route, 1) + .TestValid() + .TestPoint({37.546738218864334, 67.531659957257347}) + .TestDirection(TurnDirection::TurnLeft); + integration::GetNthTurn(route, 2) + .TestValid() + .TestPoint({37.539925407915746, 67.537083383925875}) + .TestDirection(TurnDirection::TurnRight); integration::GetTurnByPoint(route, {37., 67.}).TestNotValid(); - integration::GetTurnByPoint(route, {37.546738218864334, 67.531659957257347}).TestValid().TestDirection(TurnDirection::TurnLeft); + integration::GetTurnByPoint(route, {37.546738218864334, 67.531659957257347}) + .TestValid() + .TestDirection(TurnDirection::TurnLeft); integration::TestRouteLength(route, 2033.); } UNIT_TEST(RussiaMoscowSalameiNerisUturnTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.395332276656617, 67.633925439079519}, - {0., 0.}, {37.392503720352721, 67.61975260731343}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.395332276656617, 67.633925439079519}, {0., 0.}, + {37.392503720352721, 67.61975260731343}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 4); - integration::GetNthTurn(route, 0).TestValid().TestPoint({37.388482521388539, 67.633382734905041}, 5.) + integration::GetNthTurn(route, 0) + .TestValid() + .TestPoint({37.388482521388539, 67.633382734905041}, 5.) .TestDirection(TurnDirection::TurnSlightRight); - integration::GetNthTurn(route, 1).TestValid().TestPoint({37.387117276989784, 67.633369323859881}).TestDirection(TurnDirection::TurnLeft); - integration::GetNthTurn(route, 2).TestValid().TestPoint({37.387380133475205, 67.632781920081243}).TestDirection(TurnDirection::TurnLeft); - integration::GetNthTurn(route, 3).TestValid().TestPoint({37.390526364673121, 67.633106467374461}).TestDirection(TurnDirection::TurnRight); + integration::GetNthTurn(route, 1) + .TestValid() + .TestPoint({37.387117276989784, 67.633369323859881}) + .TestDirection(TurnDirection::TurnLeft); + integration::GetNthTurn(route, 2) + .TestValid() + .TestPoint({37.387380133475205, 67.632781920081243}) + .TestDirection(TurnDirection::TurnLeft); + integration::GetNthTurn(route, 3) + .TestValid() + .TestPoint({37.390526364673121, 67.633106467374461}) + .TestDirection(TurnDirection::TurnRight); integration::TestRouteLength(route, 1637.); } UNIT_TEST(RussiaMoscowTrikotagniAndPohodniRoundaboutTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.405153751040686, 67.5971698246356}, - {0., 0.}, {37.40521071657038, 67.601903779043795}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = + integration::CalculateRoute(integration::GetAllMaps(), {37.405153751040686, 67.5971698246356}, + {0., 0.}, {37.40521071657038, 67.601903779043795}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 2); - integration::GetNthTurn(route, 0).TestValid().TestDirection(TurnDirection::EnterRoundAbout).TestRoundAboutExitNum(2); + integration::GetNthTurn(route, 0) + .TestValid() + .TestDirection(TurnDirection::EnterRoundAbout) + .TestRoundAboutExitNum(2); integration::GetNthTurn(route, 1).TestValid().TestDirection(TurnDirection::LeaveRoundAbout); integration::TestRouteLength(route, 387.); @@ -68,10 +91,10 @@ UNIT_TEST(RussiaMoscowTrikotagniAndPohodniRoundaboutTurnTest) UNIT_TEST(RussiaMoscowPlanetnaiTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.546683164991776, 67.545511147376089}, - {0., 0.}, {37.549153861529007, 67.54467404790482}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.546683164991776, 67.545511147376089}, {0., 0.}, + {37.549153861529007, 67.54467404790482}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); @@ -83,15 +106,17 @@ UNIT_TEST(RussiaMoscowPlanetnaiTurnTest) UNIT_TEST(RussiaMoscowNoTurnsOnMKADTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.391635636579785, 67.62455792789649}, - {0., 0.}, {37.692547253527685, 67.127684414191762}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.391635636579785, 67.62455792789649}, {0., 0.}, + {37.692547253527685, 67.127684414191762}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 1); - integration::GetNthTurn(route, 0).TestValid().TestPoint({37.682761085650043, 67.140620702062705}) + integration::GetNthTurn(route, 0) + .TestValid() + .TestPoint({37.682761085650043, 67.140620702062705}) .TestOneOfDirections({TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); integration::TestRouteLength(route, 43233.7); @@ -99,26 +124,28 @@ UNIT_TEST(RussiaMoscowNoTurnsOnMKADTurnTest) UNIT_TEST(RussiaMoscowTTKKashirskoeShosseOutTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.606320023648998, 67.36682695403141}, - {0., 0.}, {37.621220025471168, 67.352441627022912}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.606320023648998, 67.36682695403141}, {0., 0.}, + {37.621220025471168, 67.352441627022912}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 2); /// Checking turn in case going from not link to link - integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections({TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); + integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections( + {TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); /// Checking turn in case of ingoing edge(s) - integration::GetNthTurn(route, 1).TestValid().TestOneOfDirections({TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); + integration::GetNthTurn(route, 1).TestValid().TestOneOfDirections( + {TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); } UNIT_TEST(RussiaMoscowPankratevskiPerBolshaySuharedskazPloschadTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.635563528539393, 67.491460725721268}, - {0., 0.}, {37.637054339197832, 67.491929797067371}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.635563528539393, 67.491460725721268}, {0., 0.}, + {37.637054339197832, 67.491929797067371}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); @@ -128,23 +155,24 @@ UNIT_TEST(RussiaMoscowPankratevskiPerBolshaySuharedskazPloschadTurnTest) UNIT_TEST(RussiaMoscowMKADPutilkovskeShosseTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.394141645624103, 67.63612831787222}, - {0., 0.}, {37.391050708989461, 67.632454269643091}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.394141645624103, 67.63612831787222}, {0., 0.}, + {37.391050708989461, 67.632454269643091}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 1); - integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections({TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); + integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections( + {TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); } UNIT_TEST(RussiaMoscowPetushkovaShodniaReverTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.405917692164508, 67.614731601278493}, - {0., 0.}, {37.408550782937482, 67.61160397953185}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.405917692164508, 67.614731601278493}, {0., 0.}, + {37.408550782937482, 67.61160397953185}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); @@ -153,27 +181,34 @@ UNIT_TEST(RussiaMoscowPetushkovaShodniaReverTurnTest) UNIT_TEST(RussiaHugeRoundaboutTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.325810690728495, 67.544175542376436}, - {0., 0.}, {37.325360456262153, 67.543013703414516}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {37.325810690728495, 67.544175542376436}, {0., 0.}, + {37.325360456262153, 67.543013703414516}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 2); - integration::GetNthTurn(route, 0).TestValid().TestDirection(TurnDirection::EnterRoundAbout).TestRoundAboutExitNum(5); - integration::GetNthTurn(route, 1).TestValid().TestDirection(TurnDirection::LeaveRoundAbout).TestRoundAboutExitNum(0); + integration::GetNthTurn(route, 0) + .TestValid() + .TestDirection(TurnDirection::EnterRoundAbout) + .TestRoundAboutExitNum(5); + integration::GetNthTurn(route, 1) + .TestValid() + .TestDirection(TurnDirection::LeaveRoundAbout) + .TestRoundAboutExitNum(0); } UNIT_TEST(BelarusMiskProspNezavisimostiMKADTurnTest) { - shared_ptr routerComponents = integration::GetAllMaps(); - RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {27.658572046123947, 64.302533720228126}, - {0., 0.}, {27.670461944729382, 64.307480201489582}); - shared_ptr const route = routeResult.first; + TRouteResult const routeResult = integration::CalculateRoute( + integration::GetAllMaps(), {27.658572046123947, 64.302533720228126}, {0., 0.}, + {27.670461944729382, 64.307480201489582}); + Route const & route = *routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); integration::TestTurnCount(route, 1); - integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections({TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); + integration::GetNthTurn(route, 0).TestValid().TestOneOfDirections( + {TurnDirection::TurnSlightRight, TurnDirection::TurnRight}); } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index e9689fae4c..c0ea765234 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -178,20 +178,28 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick"; using namespace routing::turns; switch (type) { - case TurnDirection::TurnSlightRight: return @"right-1"; - case TurnDirection::TurnRight: return @"right-2"; - case TurnDirection::TurnSharpRight: return @"right-3"; - - case TurnDirection::TurnSlightLeft: return @"left-1"; - case TurnDirection::TurnLeft: return @"left-2"; - case TurnDirection::TurnSharpLeft: return @"left-3"; - - case TurnDirection::UTurn: return @"turn-around"; - + case TurnDirection::TurnSlightRight: + return @"right-1"; + case TurnDirection::TurnRight: + return @"right-2"; + case TurnDirection::TurnSharpRight: + return @"right-3"; + + case TurnDirection::TurnSlightLeft: + return @"left-1"; + case TurnDirection::TurnLeft: + return @"left-2"; + case TurnDirection::TurnSharpLeft: + return @"left-3"; + + case TurnDirection::UTurn: + return @"turn-around"; + case TurnDirection::LeaveRoundAbout: case TurnDirection::StayOnRoundAbout: - case TurnDirection::EnterRoundAbout: return @"circle"; - + case TurnDirection::EnterRoundAbout: + return @"circle"; + default: return @"straight"; } } diff --git a/map/routing_session.cpp b/map/routing_session.cpp index 7167e392ca..1a3f847c44 100644 --- a/map/routing_session.cpp +++ b/map/routing_session.cpp @@ -173,12 +173,14 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const if (dist < kShowLanesDistInMeters) { - // There are two nested loops below. Outer one is for lanes and inner one (ctor of SingleLaneInfo) is - // for each lane's directions. The size of turn.m_lanes is relatively small. Less than 10 in most cases. + // There are two nested loops below. Outer one is for lanes and inner one (ctor of + // SingleLaneInfo) is + // for each lane's directions. The size of turn.m_lanes is relatively small. Less than 10 in + // most cases. info.m_lanes.clear(); for (size_t j = 0; j < turn.m_lanes.size(); ++j) { - info.m_lanes.push_back(move(FollowingInfo::SingleLaneInfoOuter(turn.m_lanes[j]))); + info.m_lanes.emplace_back(turn.m_lanes[j]); } } else diff --git a/platform/location.hpp b/platform/location.hpp index 2bb9921230..28bc74b369 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -93,16 +93,22 @@ namespace location class FollowingInfo { public: - struct SingleLaneInfoOuter + // SingleLaneInfoClient is used for passing information about a lane to client platforms such as + // Android, iOS and so on. + struct SingleLaneInfoClient { - vector m_lane; - bool m_isActive; - SingleLaneInfoOuter(routing::turns::SingleLaneInfo singleLaneInfo) : m_isActive(singleLaneInfo.m_isActive) + vector m_lane; // Possible directions for the lane. + bool m_isRecommended; // m_isRecommended is true if the lane is recommended for a user. + + SingleLaneInfoClient(routing::turns::SingleLaneInfo const & singleLaneInfo) + : m_isRecommended(singleLaneInfo.m_isRecommended) { routing::turns::TSingleLane const & lane = singleLaneInfo.m_lane; m_lane.resize(lane.size()); - transform(lane.begin(), lane.end(), m_lane.begin(), - [] (routing::turns::LaneWay l) { return static_cast(l); }); + transform(lane.cbegin(), lane.cend(), m_lane.begin(), [](routing::turns::LaneWay l) + { + return static_cast(l); + }); } }; @@ -121,7 +127,7 @@ namespace location //@} int m_time; // m_lanes contains lane information on the edge before the turn. - vector m_lanes; + vector m_lanes; // The next street name string m_targetName; diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 8cd3063cf3..1c1fc0baa2 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -1335,18 +1335,18 @@ turns::TurnDirection OsrmRouter::InvertDirection(turns::TurnDirection dir) const { switch (dir) { - case turns::TurnDirection::TurnSharpRight: - return turns::TurnDirection::TurnSharpLeft; - case turns::TurnDirection::TurnRight: - return turns::TurnDirection::TurnLeft; - case turns::TurnDirection::TurnSlightRight: - return turns::TurnDirection::TurnSlightLeft; - case turns::TurnDirection::TurnSlightLeft: - return turns::TurnDirection::TurnSlightRight; - case turns::TurnDirection::TurnLeft: - return turns::TurnDirection::TurnRight; - case turns::TurnDirection::TurnSharpLeft: - return turns::TurnDirection::TurnSharpRight; + case turns::TurnDirection::TurnSlightRight: + return turns::TurnDirection::TurnSlightLeft; + case turns::TurnDirection::TurnRight: + return turns::TurnDirection::TurnLeft; + case turns::TurnDirection::TurnSharpRight: + return turns::TurnDirection::TurnSharpLeft; + case turns::TurnDirection::TurnSlightLeft: + return turns::TurnDirection::TurnSlightRight; + case turns::TurnDirection::TurnLeft: + return turns::TurnDirection::TurnRight; + case turns::TurnDirection::TurnSharpLeft: + return turns::TurnDirection::TurnSharpRight; default: return dir; }; @@ -1365,15 +1365,15 @@ turns::TurnDirection OsrmRouter::MostRightDirection(const double angle) const if (angle >= lowerSharpRightBound && angle < upperSharpRightBound) return turns::TurnDirection::TurnSharpRight; else if (angle >= upperSharpRightBound && angle < upperRightBound) - return turns::TurnDirection::TurnRight; + return turns::TurnDirection::TurnRight; else if (angle >= upperRightBound && angle < upperSlightRight) return turns::TurnDirection::TurnSlightRight; else if (angle >= upperSlightRight && angle < upperGoStraitBound) - return turns::TurnDirection::GoStraight; + return turns::TurnDirection::GoStraight; else if (angle >= upperGoStraitBound && angle < upperSlightLeftBound) - return turns::TurnDirection::TurnSlightLeft; + return turns::TurnDirection::TurnSlightLeft; else if (angle >= upperSlightLeftBound && angle < upperLeftBound) - return turns::TurnDirection::TurnLeft; + return turns::TurnDirection::TurnLeft; return turns::TurnDirection::NoTurn; } @@ -1396,15 +1396,15 @@ turns::TurnDirection OsrmRouter::IntermediateDirection(const double angle) const if (angle >= lowerSharpRightBound && angle < upperSharpRightBound) return turns::TurnDirection::TurnSharpRight; else if (angle >= upperSharpRightBound && angle < upperRightBound) - return turns::TurnDirection::TurnRight; + return turns::TurnDirection::TurnRight; else if (angle >= upperRightBound && angle < upperSlightRight) return turns::TurnDirection::TurnSlightRight; else if (angle >= upperSlightRight && angle < upperGoStraitBound) - return turns::TurnDirection::GoStraight; + return turns::TurnDirection::GoStraight; else if (angle >= upperGoStraitBound && angle < upperSlightLeftBound) - return turns::TurnDirection::TurnSlightLeft; + return turns::TurnDirection::TurnSlightLeft; else if (angle >= upperSlightLeftBound && angle < upperLeftBound) - return turns::TurnDirection::TurnLeft; + return turns::TurnDirection::TurnLeft; else if (angle >= upperLeftBound && angle < upperSharpLeftBound) return turns::TurnDirection::TurnSharpLeft; return turns::TurnDirection::NoTurn; diff --git a/routing/route.cpp b/routing/route.cpp index 6d01607aeb..9758a7bed4 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -26,8 +26,7 @@ string DebugPrint(TurnItem const & turnItem) stringstream out; out << "[ TurnItem: m_index = " << turnItem.m_index << ", m_turn = " << DebugPrint(turnItem.m_turn) - << ", m_lanes = " << ::DebugPrint(turnItem.m_lanes) - << ", m_exitNum = " << turnItem.m_exitNum + << ", m_lanes = " << ::DebugPrint(turnItem.m_lanes) << ", m_exitNum = " << turnItem.m_exitNum << ", m_sourceName = " << turnItem.m_sourceName << ", m_targetName = " << turnItem.m_targetName << ", m_keepAnyway = " << turnItem.m_keepAnyway << " ]" << endl; diff --git a/routing/route.hpp b/routing/route.hpp index 358925da40..da9068f085 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -20,8 +20,10 @@ namespace routing struct TurnItem { TurnItem() - : m_index(numeric_limits::max()) - , m_turn(turns::TurnDirection::NoTurn), m_exitNum(0), m_keepAnyway(false) + : m_index(numeric_limits::max()), + m_turn(turns::TurnDirection::NoTurn), + m_exitNum(0), + m_keepAnyway(false) { } diff --git a/routing/routing_tests/turns_generator_test.cpp b/routing/routing_tests/turns_generator_test.cpp index 7b7f888cd3..449824779c 100644 --- a/routing/routing_tests/turns_generator_test.cpp +++ b/routing/routing_tests/turns_generator_test.cpp @@ -21,12 +21,11 @@ UNIT_TEST(TestSplitLanes) { vector result; SplitLanes("through|through|through|through;right", '|', result); - vector expected1 = {"through", "through", "through", "through;right"}; + vector const expected1 = {"through", "through", "through", "through;right"}; TEST_EQUAL(result, expected1, ()); SplitLanes("adsjkddfasui8747&sxdsdlad8\"\'", '|', result); - TEST_EQUAL(result.size(), 1, ()); - TEST_EQUAL(result[0], "adsjkddfasui8747&sxdsdlad8\"\'", ()); + TEST_EQUAL(result, vector({"adsjkddfasui8747&sxdsdlad8\"\'"}), ()); SplitLanes("|||||||", '|', result); vector expected2 = {"", "", "", "", "", "", ""}; @@ -37,7 +36,7 @@ UNIT_TEST(TestParseSingleLane) { TSingleLane result; TEST(ParseSingleLane("through;right", ';', result), ()); - TSingleLane expected1 = {LaneWay::Through, LaneWay::Right}; + TSingleLane const expected1 = {LaneWay::Through, LaneWay::Right}; TEST_EQUAL(result, expected1, ()); TEST(!ParseSingleLane("through;Right", ';', result), ()); @@ -67,57 +66,40 @@ UNIT_TEST(TestParseLanes) { vector result; TEST(ParseLanes("through|through|through|through;right", result), ()); - TEST_EQUAL(result.size(), 4, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[3].m_lane.size(), 2, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[3].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[3].m_lane[1], LaneWay::Right, ()); + vector const expected1 = {{LaneWay::Through}, + {LaneWay::Through}, + {LaneWay::Through}, + {LaneWay::Through, LaneWay::Right}}; + TEST_EQUAL(result, expected1, ()); TEST(ParseLanes("left|left;through|through|through", result), ()); - TEST_EQUAL(result.size(), 4, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[1].m_lane.size(), 2, ()); - TEST_EQUAL(result[3].m_lane.size(), 1, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[1].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[1].m_lane[1], LaneWay::Through, ()); - TEST_EQUAL(result[3].m_lane[0], LaneWay::Through, ()); + vector const expected2 = { + {LaneWay::Left}, {LaneWay::Left, LaneWay::Through}, {LaneWay::Through}, {LaneWay::Through}}; + TEST_EQUAL(result, expected2, ()); TEST(ParseLanes("left|through|through", result), ()); - TEST_EQUAL(result.size(), 3, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[1].m_lane.size(), 1, ()); - TEST_EQUAL(result[2].m_lane.size(), 1, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[1].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[2].m_lane[0], LaneWay::Through, ()); + vector const expected3 = { + {LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}}; + TEST_EQUAL(result, expected3, ()); TEST(ParseLanes("left|le ft| through|through | right", result), ()); - TEST_EQUAL(result.size(), 5, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[4].m_lane.size(), 1, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[1].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[2].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[3].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[4].m_lane[0], LaneWay::Right, ()); + vector const expected4 = { + {LaneWay::Left}, {LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}, {LaneWay::Right}}; + TEST_EQUAL(result, expected4, ()); TEST(ParseLanes("left|Left|through|througH|right", result), ()); - TEST_EQUAL(result.size(), 5, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[4].m_lane.size(), 1, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[4].m_lane[0], LaneWay::Right, ()); + vector const expected5 = { + {LaneWay::Left}, {LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}, {LaneWay::Right}}; + TEST_EQUAL(result, expected5, ()); TEST(ParseLanes("left|Left|through|througH|through;right;sharp_rIght", result), ()); - TEST_EQUAL(result.size(), 5, ()); - TEST_EQUAL(result[0].m_lane.size(), 1, ()); - TEST_EQUAL(result[4].m_lane.size(), 3, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[4].m_lane[0], LaneWay::Through, ()); - TEST_EQUAL(result[4].m_lane[1], LaneWay::Right, ()); - TEST_EQUAL(result[4].m_lane[2], LaneWay::SharpRight, ()); + vector const expected6 = { + {LaneWay::Left}, + {LaneWay::Left}, + {LaneWay::Through}, + {LaneWay::Through}, + {LaneWay::Through, LaneWay::Right, LaneWay::SharpRight}}; + TEST_EQUAL(result, expected6, ()); TEST(!ParseLanes("left|Leftt|through|througH|right", result), ()); TEST_EQUAL(result.size(), 0, ()); @@ -129,9 +111,9 @@ UNIT_TEST(TestParseLanes) TEST_EQUAL(result.size(), 0, ()); TEST(ParseLanes("left |Left|through|througH|right", result), ()); - TEST_EQUAL(result.size(), 5, ()); - TEST_EQUAL(result[0].m_lane[0], LaneWay::Left, ()); - TEST_EQUAL(result[1].m_lane[0], LaneWay::Left, ()); + vector const expected7 = { + {LaneWay::Left}, {LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}, {LaneWay::Right}}; + TEST_EQUAL(result, expected7, ()); } UNIT_TEST(TestFixupTurns) @@ -149,19 +131,15 @@ UNIT_TEST(TestFixupTurns) }; // The constructor TurnItem(uint32_t idx, TurnDirection t, uint32_t exitNum = 0) // is used for initialization of vector below. - Route::TurnsT turnsDir1 = { - { 0, TurnDirection::EnterRoundAbout }, - { 1, TurnDirection::StayOnRoundAbout }, - { 2, TurnDirection::LeaveRoundAbout }, - { 3, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT turnsDir1 = {{0, TurnDirection::EnterRoundAbout}, + {1, TurnDirection::StayOnRoundAbout}, + {2, TurnDirection::LeaveRoundAbout}, + {3, TurnDirection::ReachedYourDestination}}; FixupTurns(pointsMerc1, turnsDir1); - Route::TurnsT expectedTurnDir1 = { - { 0, TurnDirection::EnterRoundAbout, 2 }, - { 2, TurnDirection::LeaveRoundAbout }, - { 3, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT const expectedTurnDir1 = {{0, TurnDirection::EnterRoundAbout, 2}, + {2, TurnDirection::LeaveRoundAbout}, + {3, TurnDirection::ReachedYourDestination}}; TEST_EQUAL(turnsDir1, expectedTurnDir1, ()); // Merging turns which are close to each other. @@ -169,17 +147,13 @@ UNIT_TEST(TestFixupTurns) { kSquareNearZero.minX(), kSquareNearZero.minY()}, { kSquareCenterLonLat.x, kSquareCenterLonLat.y }, { kSquareNearZero.maxX(), kSquareNearZero.maxY() }}; - Route::TurnsT turnsDir2 = { - { 0, TurnDirection::GoStraight }, - { 1, TurnDirection::TurnLeft }, - { 2, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT turnsDir2 = {{0, TurnDirection::GoStraight}, + {1, TurnDirection::TurnLeft}, + {2, TurnDirection::ReachedYourDestination}}; FixupTurns(pointsMerc2, turnsDir2); - Route::TurnsT expectedTurnDir2 = { - { 1, TurnDirection::TurnLeft }, - { 2, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT const expectedTurnDir2 = {{1, TurnDirection::TurnLeft}, + {2, TurnDirection::ReachedYourDestination}}; TEST_EQUAL(turnsDir2, expectedTurnDir2, ()); // No turn is removed. @@ -187,16 +161,12 @@ UNIT_TEST(TestFixupTurns) { kSquareNearZero.minX(), kSquareNearZero.minY()}, { kSquareNearZero.minX(), kSquareNearZero.maxY() }, { kSquareNearZero.maxX(), kSquareNearZero.maxY() }}; - Route::TurnsT turnsDir3 = { - { 1, TurnDirection::TurnRight }, - { 2, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT turnsDir3 = {{1, TurnDirection::TurnRight}, + {2, TurnDirection::ReachedYourDestination}}; FixupTurns(pointsMerc3, turnsDir3); - Route::TurnsT expectedTurnDir3 = { - { 1, TurnDirection::TurnRight }, - { 2, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT const expectedTurnDir3 = {{1, TurnDirection::TurnRight}, + {2, TurnDirection::ReachedYourDestination}}; TEST_EQUAL(turnsDir3, expectedTurnDir3, ()); } @@ -222,10 +192,8 @@ UNIT_TEST(TestCalculateTurnGeometry) { kSquareNearZero.maxX(), kSquareNearZero.maxY() }, { kSquareNearZero.minX(), kSquareNearZero.maxY() } }; - Route::TurnsT const turnsDir2 = { - { 1, TurnDirection::TurnLeft }, - { 2, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT const turnsDir2 = {{1, TurnDirection::TurnLeft}, + {2, TurnDirection::ReachedYourDestination}}; TurnsGeomT turnsGeom2; CalculateTurnGeometry(points2, turnsDir2, turnsGeom2); @@ -251,11 +219,9 @@ UNIT_TEST(TestCalculateTurnGeometry) { kSquareNearZero.maxX(), kSquareNearZero.minY() }, { kSquareCenterLonLat.x, kSquareCenterLonLat.y } }; - Route::TurnsT const turnsDir3 = { - { 0, TurnDirection::GoStraight }, - { 3, TurnDirection::TurnSharpRight }, - { 4, TurnDirection::ReachedYourDestination } - }; + Route::TurnsT const turnsDir3 = {{0, TurnDirection::GoStraight}, + {3, TurnDirection::TurnSharpRight}, + {4, TurnDirection::ReachedYourDestination}}; TurnsGeomT turnsGeom3; CalculateTurnGeometry(points3, turnsDir3, turnsGeom3); @@ -302,7 +268,8 @@ UNIT_TEST(TestIsLaneWayConformedTurnDirectionApproximately) TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SharpRight, TurnDirection::UTurn), ()); TEST(!IsLaneWayConformedTurnDirection(LaneWay::Through, TurnDirection::ReachedYourDestination), ()); TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::Through, TurnDirection::TurnRight), ()); - TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SlightRight, TurnDirection::TurnSharpLeft), ()); + TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SlightRight, + TurnDirection::TurnSharpLeft), ()); } UNIT_TEST(TestAddingActiveLaneInformation) @@ -317,13 +284,13 @@ UNIT_TEST(TestAddingActiveLaneInformation) turns[1].m_lanes.push_back({LaneWay::Through}); turns[1].m_lanes.push_back({LaneWay::Through}); - AddingActiveLaneInformation(turns); + SelectRecommendedLanes(turns); - TEST(turns[0].m_lanes[0].m_isActive, ()); - TEST(!turns[0].m_lanes[1].m_isActive, ()); + TEST(turns[0].m_lanes[0].m_isRecommended, ()); + TEST(!turns[0].m_lanes[1].m_isRecommended, ()); - TEST(turns[1].m_lanes[0].m_isActive, ()); - TEST(!turns[1].m_lanes[1].m_isActive, ()); - TEST(!turns[1].m_lanes[1].m_isActive, ()); + TEST(turns[1].m_lanes[0].m_isRecommended, ()); + TEST(!turns[1].m_lanes[1].m_isRecommended, ()); + TEST(!turns[1].m_lanes[1].m_isRecommended, ()); } -} // namespace +} // namespace diff --git a/routing/turns.cpp b/routing/turns.cpp index e9684b75e4..7880e9e96a 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -10,41 +10,39 @@ namespace using namespace routing::turns; // The order is important. Starting with the most frequent tokens according to // taginfo.openstreetmap.org to minimize the number of comparisons in ParseSingleLane(). -array, static_cast(LaneWay::Count)> const g_laneWayNames = -{{ - { LaneWay::Through, "through" }, - { LaneWay::Left, "left" }, - { LaneWay::Right, "right" }, - { LaneWay::None, "none" }, - { LaneWay::SharpLeft, "sharp_left" }, - { LaneWay::SlightLeft, "slight_left" }, - { LaneWay::MergeToRight, "merge_to_right" }, - { LaneWay::MergeToLeft, "merge_to_left" }, - { LaneWay::SlightRight, "slight_right" }, - { LaneWay::SharpRight, "sharp_right" }, - { LaneWay::Reverse, "reverse" } -}}; -static_assert(g_laneWayNames.size() == static_cast(LaneWay::Count), "Check the size of g_laneWayNames"); +array, static_cast(LaneWay::Count)> const g_laneWayNames = { + {{LaneWay::Through, "through"}, + {LaneWay::Left, "left"}, + {LaneWay::Right, "right"}, + {LaneWay::None, "none"}, + {LaneWay::SharpLeft, "sharp_left"}, + {LaneWay::SlightLeft, "slight_left"}, + {LaneWay::MergeToRight, "merge_to_right"}, + {LaneWay::MergeToLeft, "merge_to_left"}, + {LaneWay::SlightRight, "slight_right"}, + {LaneWay::SharpRight, "sharp_right"}, + {LaneWay::Reverse, "reverse"}}}; +static_assert(g_laneWayNames.size() == static_cast(LaneWay::Count), + "Check the size of g_laneWayNames"); -array, static_cast(TurnDirection::Count)> const g_turnNames = -{{ - { TurnDirection::NoTurn, "NoTurn" }, - { TurnDirection::GoStraight, "GoStraight" }, - { TurnDirection::TurnRight, "TurnRight" }, - { TurnDirection::TurnSharpRight, "TurnSharpRight" }, - { TurnDirection::TurnSlightRight, "TurnSlightRight" }, - { TurnDirection::TurnLeft, "TurnLeft" }, - { TurnDirection::TurnSharpLeft, "TurnSharpLeft" }, - { TurnDirection::TurnSlightLeft, "TurnSlightLeft" }, - { TurnDirection::UTurn, "UTurn" }, - { TurnDirection::TakeTheExit, "TakeTheExit" }, - { TurnDirection::EnterRoundAbout, "EnterRoundAbout" }, - { TurnDirection::LeaveRoundAbout, "LeaveRoundAbout" }, - { TurnDirection::StayOnRoundAbout, "StayOnRoundAbout" }, - { TurnDirection::StartAtEndOfStreet, "StartAtEndOfStreet" }, - { TurnDirection::ReachedYourDestination, "ReachedYourDestination" } -}}; -static_assert(g_turnNames.size() == static_cast(TurnDirection::Count), "Check the size of g_turnNames"); +array, static_cast(TurnDirection::Count)> const g_turnNames = { + {{TurnDirection::NoTurn, "NoTurn"}, + {TurnDirection::GoStraight, "GoStraight"}, + {TurnDirection::TurnRight, "TurnRight"}, + {TurnDirection::TurnSharpRight, "TurnSharpRight"}, + {TurnDirection::TurnSlightRight, "TurnSlightRight"}, + {TurnDirection::TurnLeft, "TurnLeft"}, + {TurnDirection::TurnSharpLeft, "TurnSharpLeft"}, + {TurnDirection::TurnSlightLeft, "TurnSlightLeft"}, + {TurnDirection::UTurn, "UTurn"}, + {TurnDirection::TakeTheExit, "TakeTheExit"}, + {TurnDirection::EnterRoundAbout, "EnterRoundAbout"}, + {TurnDirection::LeaveRoundAbout, "LeaveRoundAbout"}, + {TurnDirection::StayOnRoundAbout, "StayOnRoundAbout"}, + {TurnDirection::StartAtEndOfStreet, "StartAtEndOfStreet"}, + {TurnDirection::ReachedYourDestination, "ReachedYourDestination"}}}; +static_assert(g_turnNames.size() == static_cast(TurnDirection::Count), + "Check the size of g_turnNames"); } namespace routing @@ -59,22 +57,24 @@ bool TurnGeom::operator==(TurnGeom const & other) const bool SingleLaneInfo::operator==(SingleLaneInfo const & other) const { - return m_lane == other.m_lane && m_isActive == other.m_isActive; + return m_lane == other.m_lane && m_isRecommended == other.m_isRecommended; } string const GetTurnString(TurnDirection turn) { - stringstream out; - auto const it = find_if(g_turnNames.begin(), g_turnNames.end(), + auto const it = find_if(g_turnNames.cbegin(), g_turnNames.cend(), [&turn](pair const & p) { return p.first == turn; }); if (it == g_turnNames.end()) + { + stringstream out; out << "unknown TurnDirection (" << static_cast(turn) << ")"; - out << it->second; - return out.str(); + return out.str(); + } + return it->second; } bool IsLeftTurn(TurnDirection t) @@ -99,70 +99,57 @@ bool IsStayOnRoad(TurnDirection t) bool IsGoStraightOrSlightTurn(TurnDirection t) { - return (t == TurnDirection::GoStraight || t == TurnDirection::TurnSlightLeft || t == TurnDirection::TurnSlightRight); + return (t == TurnDirection::GoStraight || t == TurnDirection::TurnSlightLeft || + t == TurnDirection::TurnSlightRight); } bool IsLaneWayConformedTurnDirection(LaneWay l, TurnDirection t) { - switch(t) + switch (t) { - case TurnDirection::NoTurn: - case TurnDirection::TakeTheExit: - case TurnDirection::EnterRoundAbout: - case TurnDirection::LeaveRoundAbout: - case TurnDirection::StayOnRoundAbout: - case TurnDirection::StartAtEndOfStreet: - case TurnDirection::ReachedYourDestination: - default: - return false; - case TurnDirection::GoStraight: - return l == LaneWay::Through; - case TurnDirection::TurnRight: - return l == LaneWay::Right; - case TurnDirection::TurnSharpRight: - return l == LaneWay::SharpRight; - case TurnDirection::TurnSlightRight: - return l == LaneWay::SlightRight; - case TurnDirection::TurnLeft: - return l == LaneWay::Left; - case TurnDirection::TurnSharpLeft: - return l == LaneWay::SharpLeft; - case TurnDirection::TurnSlightLeft: - return l == LaneWay::SlightLeft; - case TurnDirection::UTurn: - return l == LaneWay::Reverse; + default: + return false; + case TurnDirection::GoStraight: + return l == LaneWay::Through; + case TurnDirection::TurnRight: + return l == LaneWay::Right; + case TurnDirection::TurnSharpRight: + return l == LaneWay::SharpRight; + case TurnDirection::TurnSlightRight: + return l == LaneWay::SlightRight; + case TurnDirection::TurnLeft: + return l == LaneWay::Left; + case TurnDirection::TurnSharpLeft: + return l == LaneWay::SharpLeft; + case TurnDirection::TurnSlightLeft: + return l == LaneWay::SlightLeft; + case TurnDirection::UTurn: + return l == LaneWay::Reverse; } } bool IsLaneWayConformedTurnDirectionApproximately(LaneWay l, TurnDirection t) { - switch(t) + switch (t) { - case TurnDirection::NoTurn: - case TurnDirection::TakeTheExit: - case TurnDirection::EnterRoundAbout: - case TurnDirection::LeaveRoundAbout: - case TurnDirection::StayOnRoundAbout: - case TurnDirection::StartAtEndOfStreet: - case TurnDirection::ReachedYourDestination: - default: - return false; - case TurnDirection::GoStraight: - return l == LaneWay::Through || l == LaneWay::SlightRight || l == LaneWay::SlightLeft; - case TurnDirection::TurnRight: - return l == LaneWay::Right || l == LaneWay::SharpRight || l == LaneWay::SlightRight; - case TurnDirection::TurnSharpRight: - return l == LaneWay::SharpRight || l == LaneWay::Right; - case TurnDirection::TurnSlightRight: - return l == LaneWay::SlightRight || l == LaneWay::Through || l == LaneWay::Right; - case TurnDirection::TurnLeft: - return l == LaneWay::Left || l == LaneWay::SlightLeft || l == LaneWay::SharpLeft; - case TurnDirection::TurnSharpLeft: - return l == LaneWay::SharpLeft || l == LaneWay::Left; - case TurnDirection::TurnSlightLeft: - return l == LaneWay::SlightLeft || l == LaneWay::Through || l == LaneWay::Left; - case TurnDirection::UTurn: - return l == LaneWay::Reverse; + default: + return false; + case TurnDirection::GoStraight: + return l == LaneWay::Through || l == LaneWay::SlightRight || l == LaneWay::SlightLeft; + case TurnDirection::TurnRight: + return l == LaneWay::Right || l == LaneWay::SharpRight || l == LaneWay::SlightRight; + case TurnDirection::TurnSharpRight: + return l == LaneWay::SharpRight || l == LaneWay::Right; + case TurnDirection::TurnSlightRight: + return l == LaneWay::SlightRight || l == LaneWay::Through || l == LaneWay::Right; + case TurnDirection::TurnLeft: + return l == LaneWay::Left || l == LaneWay::SlightLeft || l == LaneWay::SharpLeft; + case TurnDirection::TurnSharpLeft: + return l == LaneWay::SharpLeft || l == LaneWay::Left; + case TurnDirection::TurnSlightLeft: + return l == LaneWay::SlightLeft || l == LaneWay::Through || l == LaneWay::Left; + case TurnDirection::UTurn: + return l == LaneWay::Reverse; } } @@ -230,7 +217,6 @@ string DebugPrint(TurnGeom const & turnGeom) string DebugPrint(LaneWay const l) { - stringstream out; auto const it = find_if(g_laneWayNames.begin(), g_laneWayNames.end(), [&l](pair const & p) { @@ -238,9 +224,12 @@ string DebugPrint(LaneWay const l) }); if (it == g_laneWayNames.end()) + { + stringstream out; out << "unknown LaneWay (" << static_cast(l) << ")"; - out << it->second; - return out.str(); + return out.str(); + } + return it->second; } string DebugPrint(TurnDirection const turn) @@ -253,8 +242,8 @@ string DebugPrint(TurnDirection const turn) string DebugPrint(SingleLaneInfo const & singleLaneInfo) { stringstream out; - out << "[ m_isActive == " << singleLaneInfo.m_isActive << ". m_lane == " - << ::DebugPrint(singleLaneInfo.m_lane) << " ]" << endl; + out << "[ m_isRecommended == " << singleLaneInfo.m_isRecommended + << ", m_lane == " << ::DebugPrint(singleLaneInfo.m_lane) << " ]" << endl; return out.str(); } diff --git a/routing/turns.hpp b/routing/turns.hpp index 8ff71486d0..bdbf3766dc 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -91,11 +91,10 @@ typedef vector TSingleLane; struct SingleLaneInfo { - SingleLaneInfo(initializer_list const & l = {}) : m_lane(l), m_isActive(false) {} - TSingleLane m_lane; - bool m_isActive; + bool m_isRecommended; + SingleLaneInfo(initializer_list const & l = {}) : m_lane(l), m_isRecommended(false) {} bool operator==(SingleLaneInfo const & other) const; }; @@ -109,7 +108,18 @@ bool IsLeftOrRightTurn(TurnDirection t); bool IsStayOnRoad(TurnDirection t); bool IsGoStraightOrSlightTurn(TurnDirection t); +/* + * \return True if l corresponds with t exactly. For example it returns true + * when |l| equals to LaneWay::Right and |t| equals to TurnDirection::TurnRight. + * Otherwise it returns false. + */ bool IsLaneWayConformedTurnDirection(LaneWay l, TurnDirection t); + +/* + * \return True if l corresponds with t approximately. For example it returns true + * when |l| equals to LaneWay::Right and |t| equals to TurnDirection::TurnSlightRight. + * Otherwise it returns false. + */ bool IsLaneWayConformedTurnDirectionApproximately(LaneWay l, TurnDirection t); /*! diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index d69d1a9e1c..0cd219b20c 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -12,26 +12,24 @@ namespace { using namespace routing::turns; -bool FixupLaneSet(TurnDirection turn, vector & lanes, function checker) +bool FixupLaneSet(TurnDirection turn, vector & lanes, + function checker) { bool isLaneConformed = false; // There are two hidden nested loops below (transform and find_if). // But the number of calls of the body of inner one (lambda in find_if) is relatively small. // Less than 10 in most cases. - transform(lanes.begin(), lanes.end(), lanes.begin(), - [&isLaneConformed, turn, checker] (SingleLaneInfo & singleLane) - { - if (find_if(singleLane.m_lane.cbegin(), singleLane.m_lane.cend(), - [turn, checker] (LaneWay l) { return checker(l, turn); }) != singleLane.m_lane.cend()) - { - singleLane.m_isActive = true; - isLaneConformed = true; - } - return singleLane; - }); + for (auto & singleLane : lanes) + for (LaneWay laneWay : singleLane.m_lane) + if (checker(laneWay, turn)) + { + singleLane.m_isRecommended = true; + isLaneConformed = true; + break; + } return isLaneConformed; } -} // namespace +} // namespace namespace routing { @@ -46,9 +44,8 @@ OsrmMappingTypes::FtSeg GetSegment(PathData const & node, RoutingMapping const & return seg; } -vector GetLanesInfo(PathData const & node, - RoutingMapping const & routingMapping, - TGetIndexFunction GetIndex, Index const & index) +vector GetLanesInfo(PathData const & node, RoutingMapping const & routingMapping, + TGetIndexFunction GetIndex, Index const & index) { // seg1 is the last segment before a point of bifurcation (before turn) OsrmMappingTypes::FtSeg const seg1 = GetSegment(node, routingMapping, GetIndex); @@ -138,8 +135,8 @@ void FixupTurns(vector const & points, Route::TurnsT & turnsDir) for (size_t idx = 0; idx < turnsDir.size(); ) { TurnItem & t = turnsDir[idx]; - if (roundabout && t.m_turn != TurnDirection::StayOnRoundAbout - && t.m_turn != TurnDirection::LeaveRoundAbout) + if (roundabout && t.m_turn != TurnDirection::StayOnRoundAbout && + t.m_turn != TurnDirection::LeaveRoundAbout) { exitNum = 0; roundabout = nullptr; @@ -166,8 +163,7 @@ void FixupTurns(vector const & points, Route::TurnsT & turnsDir) // distance(turnsDir[idx - 1].m_index, turnsDir[idx].m_index) < kMergeDistMeters // means the distance in meters between the former turn (idx - 1) // and the current turn (idx). - if (idx > 0 && - IsStayOnRoad(turnsDir[idx - 1].m_turn) && + if (idx > 0 && IsStayOnRoad(turnsDir[idx - 1].m_turn) && IsLeftOrRightTurn(turnsDir[idx].m_turn) && routeDistanceMeters(turnsDir[idx - 1].m_index, turnsDir[idx].m_index) < kMergeDistMeters) { @@ -175,10 +171,8 @@ void FixupTurns(vector const & points, Route::TurnsT & turnsDir) continue; } - if (!t.m_keepAnyway - && IsGoStraightOrSlightTurn(t.m_turn) - && !t.m_sourceName.empty() - && strings::AlmostEqual(t.m_sourceName, t.m_targetName, 2 /* mismatched symbols count */)) + if (!t.m_keepAnyway && IsGoStraightOrSlightTurn(t.m_turn) && !t.m_sourceName.empty() && + strings::AlmostEqual(t.m_sourceName, t.m_targetName, 2 /* mismatched symbols count */)) { turnsDir.erase(turnsDir.begin() + idx); continue; @@ -186,11 +180,11 @@ void FixupTurns(vector const & points, Route::TurnsT & turnsDir) ++idx; } - AddingActiveLaneInformation(turnsDir); + SelectRecommendedLanes(turnsDir); return; } -void AddingActiveLaneInformation(Route::TurnsT & turnsDir) +void SelectRecommendedLanes(Route::TurnsT & turnsDir) { for (auto & t : turnsDir) { @@ -198,11 +192,14 @@ void AddingActiveLaneInformation(Route::TurnsT & turnsDir) if (lanes.empty()) continue; TurnDirection const turn = t.m_turn; - if (FixupLaneSet(turn, lanes, IsLaneWayConformedTurnDirection)) + // Checking if threre are elements in lanes which correspond with the turn exactly. + // If so fixing up all the elements in lanes which correspond with the turn. + if (FixupLaneSet(turn, lanes, &IsLaneWayConformedTurnDirection)) continue; - FixupLaneSet(turn, lanes, IsLaneWayConformedTurnDirectionApproximately); + // If not checking if there are elements in lanes which corresponds with the turn + // approximately. If so fixing up all these elements. + FixupLaneSet(turn, lanes, &IsLaneWayConformedTurnDirectionApproximately); } } - } } diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index c461911908..c96707b0b1 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -22,16 +22,15 @@ typedef function)> TGetIndexFunction; OsrmMappingTypes::FtSeg GetSegment(PathData const & node, RoutingMapping const & routingMapping, TGetIndexFunction GetIndex); -vector GetLanesInfo(PathData const & node, - RoutingMapping const & routingMapping, - TGetIndexFunction GetIndex, Index const & index); +vector GetLanesInfo(PathData const & node, RoutingMapping const & routingMapping, + TGetIndexFunction GetIndex, Index const & index); /// CalculateTurnGeometry calculates geometry for all the turns. That means that for every turn /// CalculateTurnGeometry calculates a sequence of points which will be used /// for displaying arrows on the route. void CalculateTurnGeometry(vector const & points, Route::TurnsT const & turnsDir, TurnsGeomT & turnsGeom); // Selects lanes which are recommended for the end user. -void AddingActiveLaneInformation(Route::TurnsT & turnsDir); +void SelectRecommendedLanes(Route::TurnsT & turnsDir); void FixupTurns(vector const & points, Route::TurnsT & turnsDir); } }