diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 36427085d6..f7daf09aea 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -572,16 +572,18 @@ void RoutingManager::CollectRoadWarnings(vector const & s { auto const isWarnedType = [](RoutingOptions::Road roadType) { - return roadType == RoutingOptions::Road::Toll || roadType == RoutingOptions::Road::Ferry || - roadType == RoutingOptions::Road::Dirty; + return (roadType == RoutingOptions::Road::Toll || roadType == RoutingOptions::Road::Ferry || + roadType == RoutingOptions::Road::Dirty); }; + bool const isCarRouter = (m_currentRouterType == RouterType::Vehicle); + double currentDistance = baseDistance; double startDistance = baseDistance; RoutingOptions::Road lastType = RoutingOptions::Road::Usual; for (size_t i = 0; i < segments.size(); ++i) { - auto const currentType = ChooseMainRoutingOptionRoad(segments[i].GetRoadTypes()); + auto const currentType = ChooseMainRoutingOptionRoad(segments[i].GetRoadTypes(), isCarRouter); if (currentType != lastType) { if (isWarnedType(lastType)) @@ -648,7 +650,7 @@ bool RoutingManager::InsertRoute(Route const & route) RoadWarningsCollection roadWarnings; - auto const isTransitRoute = m_currentRouterType == RouterType::Transit; + bool const isTransitRoute = (m_currentRouterType == RouterType::Transit); shared_ptr transitRouteDisplay; if (isTransitRoute) { @@ -678,8 +680,6 @@ bool RoutingManager::InsertRoute(Route const & route) subroute->AddStyle(df::SubrouteStyle(df::kRouteColor, df::kRouteOutlineColor)); FillTrafficForRendering(segments, subroute->m_traffic); FillTurnsDistancesForRendering(segments, subroute->m_baseDistance, subroute->m_turns); - if (m_currentRouterType == RouterType::Vehicle) - CollectRoadWarnings(segments, startPt, subroute->m_baseDistance, getMwmId, roadWarnings); break; } case RouterType::Transit: @@ -705,6 +705,8 @@ bool RoutingManager::InsertRoute(Route const & route) default: CHECK(false, ("Unknown router type")); } + CollectRoadWarnings(segments, startPt, subroute->m_baseDistance, getMwmId, roadWarnings); + auto const subrouteId = m_drapeEngine.SafeCallWithResult(&df::DrapeEngine::AddSubroute, df::SubrouteConstPtr(subroute.release())); @@ -727,12 +729,11 @@ bool RoutingManager::InsertRoute(Route const & route) }); } - if (!roadWarnings.empty()) - { + bool const hasWarnings = !roadWarnings.empty(); + if (hasWarnings && m_currentRouterType == RouterType::Vehicle) CreateRoadWarningMarks(move(roadWarnings)); - return true; - } - return false; + + return hasWarnings; } void RoutingManager::FollowRoute() diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 8394252dd2..3dd0b7ce36 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -1685,10 +1685,10 @@ RouterResultCode IndexRouter::RedressRoute(vector const & segments, auto & segment = routeSegment.GetSegment(); routeSegment.SetTransitInfo(worldGraph.GetTransitInfo(segment)); + routeSegment.SetRoadTypes(starter.GetRoutingOptions(segment)); + if (m_vehicleType == VehicleType::Car) { - routeSegment.SetRoadTypes(starter.GetRoutingOptions(segment)); - if (segment.IsRealSegment()) { if (!AreSpeedCamerasProhibited(segment.GetMwmId())) diff --git a/routing/routing_options.cpp b/routing/routing_options.cpp index 8a7f144a53..3868981d62 100644 --- a/routing/routing_options.cpp +++ b/routing/routing_options.cpp @@ -6,18 +6,13 @@ #include "base/assert.hpp" #include "base/checked_cast.hpp" -#include "base/logging.hpp" -#include "base/macros.hpp" #include "base/string_utils.hpp" -#include #include -#include - -using namespace std; namespace routing { +using namespace std; // RoutingOptions ------------------------------------------------------------------------------------- @@ -74,17 +69,18 @@ RoutingOptionsClassifier::RoutingOptionsClassifier() {{"psurface", "unpaved_good"}, RoutingOptions::Road::Dirty} }; + m_data.Reserve(std::size(types)); for (auto const & data : types) - VERIFY(m_data.insert({c.GetTypeByPath(data.first), data.second}).second, ()); + m_data.Insert(c.GetTypeByPath(data.first), data.second); + m_data.FinishBuilding(); } optional RoutingOptionsClassifier::Get(uint32_t type) const { - auto const it = m_data.find(type); - if (it == m_data.cend()) - return {}; - - return it->second; + auto const * res = m_data.Find(type); + if (res) + return *res; + return {}; } RoutingOptionsClassifier const & RoutingOptionsClassifier::Instance() @@ -93,9 +89,9 @@ RoutingOptionsClassifier const & RoutingOptionsClassifier::Instance() return instance; } -RoutingOptions::Road ChooseMainRoutingOptionRoad(RoutingOptions options) +RoutingOptions::Road ChooseMainRoutingOptionRoad(RoutingOptions options, bool isCarRouter) { - if (options.Has(RoutingOptions::Road::Toll)) + if (isCarRouter && options.Has(RoutingOptions::Road::Toll)) return RoutingOptions::Road::Toll; if (options.Has(RoutingOptions::Road::Ferry)) diff --git a/routing/routing_options.hpp b/routing/routing_options.hpp index 0b3faedca6..ba4f9d7141 100644 --- a/routing/routing_options.hpp +++ b/routing/routing_options.hpp @@ -1,9 +1,10 @@ #pragma once +#include "base/small_map.hpp" + #include #include #include -#include namespace routing { @@ -50,10 +51,10 @@ public: static RoutingOptionsClassifier const & Instance(); private: - std::unordered_map m_data; + base::SmallMap m_data; }; -RoutingOptions::Road ChooseMainRoutingOptionRoad(RoutingOptions options); +RoutingOptions::Road ChooseMainRoutingOptionRoad(RoutingOptions options, bool isCarRouter); std::string DebugPrint(RoutingOptions const & routingOptions); std::string DebugPrint(RoutingOptions::Road type);