diff --git a/routing/cross_mwm_graph.cpp b/routing/cross_mwm_graph.cpp index 74fe9bcdb3..3e8c39bf62 100644 --- a/routing/cross_mwm_graph.cpp +++ b/routing/cross_mwm_graph.cpp @@ -24,7 +24,9 @@ struct ClosestSegment { ClosestSegment() = default; ClosestSegment(double minDistM, Segment const & bestSeg, bool exactMatchFound) - : m_bestDistM(minDistM), m_bestSeg(bestSeg), m_exactMatchFound(exactMatchFound) {} + : m_bestDistM(minDistM), m_bestSeg(bestSeg), m_exactMatchFound(exactMatchFound) + { + } double m_bestDistM = kInvalidDistance; Segment m_bestSeg; @@ -57,9 +59,11 @@ bool CrossMwmGraph::IsTransition(Segment const & s, bool isOutgoing) void CrossMwmGraph::GetTwins(Segment const & s, bool isOutgoing, vector & twins) { - CHECK(IsTransition(s, isOutgoing), ("The segment", s, "is not a transition segment for isOutgoing ==", isOutgoing)); + CHECK(IsTransition(s, isOutgoing), + ("The segment", s, "is not a transition segment for isOutgoing ==", isOutgoing)); // Note. There's an extremely rare case when a segment is ingoing and outgoing at the same time. - // |twins| is not filled for such cases. For details please see a note in CrossMwmGraph::GetEdgeList(). + // |twins| is not filled for such cases. For details please see a note in + // CrossMwmGraph::GetEdgeList(). if (IsTransition(s, !isOutgoing)) return; @@ -76,15 +80,15 @@ void CrossMwmGraph::GetTwins(Segment const & s, bool isOutgoing, vector // Node. The map below is necessary because twin segments could belong to several mwm. // It happens when a segment crosses more than one feature. map minDistSegs; - auto const findBestTwins = [&](FeatureType & ft){ + auto const findBestTwins = [&](FeatureType & ft) { if (ft.GetID().m_mwmId.GetInfo()->GetType() != MwmInfo::COUNTRY) return; if (!ft.GetID().IsValid()) return; - NumMwmId const numMwmId = m_numMwmIds->GetId(ft.GetID().m_mwmId. - GetInfo()->GetLocalFile().GetCountryFile()); + NumMwmId const numMwmId = + m_numMwmIds->GetId(ft.GetID().m_mwmId.GetInfo()->GetLocalFile().GetCountryFile()); if (numMwmId == s.GetMwmId()) return; @@ -105,9 +109,8 @@ void CrossMwmGraph::GetTwins(Segment const & s, bool isOutgoing, vector twins.push_back(tc); minDistSegs[numMwmId].m_exactMatchFound = true; } - if (!minDistSegs[numMwmId].m_exactMatchFound - && distM <= kTransitionEqualityDistM - && distM < minDistSegs[numMwmId].m_bestDistM) + if (!minDistSegs[numMwmId].m_exactMatchFound && distM <= kTransitionEqualityDistM && + distM < minDistSegs[numMwmId].m_bestDistM) { minDistSegs[numMwmId].m_bestDistM = distM; minDistSegs[numMwmId].m_bestSeg = tc; @@ -116,9 +119,9 @@ void CrossMwmGraph::GetTwins(Segment const & s, bool isOutgoing, vector } }; - m_index.ForEachInRect(findBestTwins, - MercatorBounds::RectByCenterXYAndSizeInMeters(p, kTransitionEqualityDistM), - scales::GetUpperScale()); + m_index.ForEachInRect( + findBestTwins, MercatorBounds::RectByCenterXYAndSizeInMeters(p, kTransitionEqualityDistM), + scales::GetUpperScale()); for (auto const & kv : minDistSegs) { @@ -138,15 +141,17 @@ void CrossMwmGraph::GetTwins(Segment const & s, bool isOutgoing, vector void CrossMwmGraph::GetEdgeList(Segment const & s, bool isOutgoing, vector & edges) { - CHECK(IsTransition(s, !isOutgoing), ("The segment is not a transition segment. IsTransition(", - s, "," , !isOutgoing, ") returns false.")); + CHECK(IsTransition(s, !isOutgoing), ("The segment is not a transition segment. IsTransition(", s, + ",", !isOutgoing, ") returns false.")); edges.clear(); // Osrm based cross-mwm information. - // Note. According to cross-mwm OSRM sections there is a node id that could be ingoing and outgoing + // Note. According to cross-mwm OSRM sections there is a node id that could be ingoing and + // outgoing // at the same time. For example in Berlin mwm on Nordlicher Berliner Ring (A10) near crossing - // with A11 there's such node id. It's an extremely rare case. There're probably several such node id + // with A11 there's such node id. It's an extremely rare case. There're probably several such node + // id // for the whole Europe. Such cases are not processed in WorldGraph::GetEdgeList() for the time // being. // To prevent filling |edges| with twins instead of leap edges and vice versa in @@ -188,10 +193,13 @@ bool CrossMwmGraph::CrossMwmSectionExists(NumMwmId numMwmId) return value->m_cont.IsExist(CROSS_MWM_FILE_TAG); } -void CrossMwmGraph::GetTwinCandidates(FeatureType const & ft, bool isOutgoing, vector & twinCandidates) +void CrossMwmGraph::GetTwinCandidates(FeatureType const & ft, bool isOutgoing, + vector & twinCandidates) { - NumMwmId const numMwmId = m_numMwmIds->GetId(ft.GetID().m_mwmId.GetInfo()->GetLocalFile().GetCountryFile()); - bool const isOneWay = m_vehicleModelFactory->GetVehicleModelForCountry(ft.GetID().GetMwmName())->IsOneWay(ft); + NumMwmId const numMwmId = + m_numMwmIds->GetId(ft.GetID().m_mwmId.GetInfo()->GetLocalFile().GetCountryFile()); + bool const isOneWay = + m_vehicleModelFactory->GetVehicleModelForCountry(ft.GetID().GetMwmName())->IsOneWay(ft); for (uint32_t segIdx = 0; segIdx + 1 < ft.GetPointsCount(); ++segIdx) { diff --git a/routing/cross_mwm_graph.hpp b/routing/cross_mwm_graph.hpp index 31c55c94e9..e83b68cfa0 100644 --- a/routing/cross_mwm_graph.hpp +++ b/routing/cross_mwm_graph.hpp @@ -23,7 +23,8 @@ class CrossMwmGraph final { public: CrossMwmGraph(Index & index, std::shared_ptr numMwmIds, - std::shared_ptr vehicleModelFactory, RoutingIndexManager & indexManager); + std::shared_ptr vehicleModelFactory, + RoutingIndexManager & indexManager); /// \brief Transition segment is a segment which is crossed by mwm border. That means /// start and finsh of such segment have to lie in different mwms. If a segment is @@ -58,8 +59,10 @@ public: /// the mehtod fills |twins| with appropriate enter transition segments. /// If |isOutgoing| == false |s| should be an enter transition segment and /// the method fills |twins| with appropriate exit transition segments. - /// \note GetTwins(s, isOutgoing, ...) shall be called only if IsTransition(s, isOutgoing) returns true. - /// \note GetTwins(s, isOutgoing, twins) fills |twins| only if mwm contained |twins| has been downloaded. + /// \note GetTwins(s, isOutgoing, ...) shall be called only if IsTransition(s, isOutgoing) returns + /// true. + /// \note GetTwins(s, isOutgoing, twins) fills |twins| only if mwm contained |twins| has been + /// downloaded. /// If not, |twins| could be emply after a GetTwins(...) call. void GetTwins(Segment const & s, bool isOutgoing, std::vector & twins); @@ -77,17 +80,20 @@ public: void Clear(); private: - /// \returns points of |s|. |s| should be a transition segment of mwm with an OSRM cross-mwm sections or + /// \returns points of |s|. |s| should be a transition segment of mwm with an OSRM cross-mwm + /// sections or /// with an index graph cross-mwm section. /// \param s is a transition segment of type |isOutgoing|. - /// \note the result of the method is returned by value because the size of the vector is usually one + /// \note the result of the method is returned by value because the size of the vector is usually + /// one /// or very small in rare cases in OSRM. TransitionPoints GetTransitionPoints(Segment const & s, bool isOutgoing); bool CrossMwmSectionExists(NumMwmId numMwmId); /// \brief Fills |twins| with transition segments of feature |ft| of type |isOutgoing|. - void GetTwinCandidates(FeatureType const & ft, bool isOutgoing, std::vector & twinCandidates); + void GetTwinCandidates(FeatureType const & ft, bool isOutgoing, + std::vector & twinCandidates); Index & m_index; std::shared_ptr m_numMwmIds; diff --git a/routing/cross_mwm_index_graph.cpp b/routing/cross_mwm_index_graph.cpp index ffe4fa5b2a..342b042bc8 100644 --- a/routing/cross_mwm_index_graph.cpp +++ b/routing/cross_mwm_index_graph.cpp @@ -1,5 +1,5 @@ -#include "routing/cross_mwm_road_graph.hpp" #include "routing/cross_mwm_connector_serialization.hpp" +#include "routing/cross_mwm_road_graph.hpp" using namespace std; @@ -11,7 +11,8 @@ bool CrossMwmIndexGraph::IsTransition(Segment const & s, bool isOutgoing) return c.IsTransition(s, isOutgoing); } -void CrossMwmIndexGraph::GetEdgeList(Segment const & s, bool isOutgoing, vector & edges) +void CrossMwmIndexGraph::GetEdgeList(Segment const & s, bool isOutgoing, + vector & edges) { CrossMwmConnector const & c = GetCrossMwmConnectorWithWeights(s.GetMwmId()); c.GetEdgeList(s, isOutgoing, edges); @@ -23,8 +24,9 @@ CrossMwmConnector const & CrossMwmIndexGraph::GetCrossMwmConnectorWithTransition if (it != m_connectors.cend()) return it->second; - return Deserialize(numMwmId, - CrossMwmConnectorSerializer::DeserializeTransitions>); + return Deserialize( + numMwmId, + CrossMwmConnectorSerializer::DeserializeTransitions>); } CrossMwmConnector const & CrossMwmIndexGraph::GetCrossMwmConnectorWithWeights(NumMwmId numMwmId) @@ -33,8 +35,9 @@ CrossMwmConnector const & CrossMwmIndexGraph::GetCrossMwmConnectorWithWeights(Nu if (c.WeightsWereLoaded()) return c; - return Deserialize(numMwmId, - CrossMwmConnectorSerializer::DeserializeWeights>); + return Deserialize( + numMwmId, + CrossMwmConnectorSerializer::DeserializeWeights>); } TransitionPoints CrossMwmIndexGraph::GetTransitionPoints(Segment const & s, bool isOutgoing) diff --git a/routing/cross_mwm_index_graph.hpp b/routing/cross_mwm_index_graph.hpp index e3ef3ac1e7..9e6b839e82 100644 --- a/routing/cross_mwm_index_graph.hpp +++ b/routing/cross_mwm_index_graph.hpp @@ -23,15 +23,15 @@ class CrossMwmIndexGraph final { public: CrossMwmIndexGraph(Index & index, std::shared_ptr numMwmIds) - : m_index(index), m_numMwmIds(numMwmIds) {} + : m_index(index), m_numMwmIds(numMwmIds) + { + } bool IsTransition(Segment const & s, bool isOutgoing); void GetEdgeList(Segment const & s, bool isOutgoing, std::vector & edges); void Clear() { m_connectors.clear(); } - TransitionPoints GetTransitionPoints(Segment const & s, bool isOutgoing); bool HasCache(NumMwmId numMwmId) const { return m_connectors.count(numMwmId) != 0; } - private: CrossMwmConnector const & GetCrossMwmConnectorWithTransitions(NumMwmId numMwmId); CrossMwmConnector const & GetCrossMwmConnectorWithWeights(NumMwmId numMwmId); @@ -44,7 +44,8 @@ private: MwmValue * value = handle.GetValue(); CHECK(value != nullptr, ("Country file:", m_numMwmIds->GetFile(numMwmId))); - auto const reader = make_unique(value->m_cont.GetReader(CROSS_MWM_FILE_TAG)); + auto const reader = + make_unique(value->m_cont.GetReader(CROSS_MWM_FILE_TAG)); ReaderSource src(*reader); auto const p = m_connectors.emplace(numMwmId, CrossMwmConnector(numMwmId)); fn(VehicleType::Car, p.first->second, src); @@ -56,7 +57,8 @@ private: /// \note |m_connectors| contains cache with transition segments and leap edges. /// Each mwm in |m_connectors| may be in two conditions: - /// * with loaded transition segments (after a call to CrossMwmConnectorSerializer::DeserializeTransitions()) + /// * with loaded transition segments (after a call to + /// CrossMwmConnectorSerializer::DeserializeTransitions()) /// * with loaded transition segments and with loaded weights /// (after a call to CrossMwmConnectorSerializer::DeserializeTransitions() /// and CrossMwmConnectorSerializer::DeserializeWeights()) diff --git a/routing/cross_mwm_osrm_graph.cpp b/routing/cross_mwm_osrm_graph.cpp index cd6547dee0..ef73ef0b99 100644 --- a/routing/cross_mwm_osrm_graph.cpp +++ b/routing/cross_mwm_osrm_graph.cpp @@ -48,7 +48,8 @@ bool GetFirstValidSegment(OsrmFtSegMapping const & segMapping, NumMwmId numMwmId { OsrmMappingTypes::FtSeg seg; // The meaning of node id in osrm is an edge between two joints. - // So, it's possible to consider the first valid segment from the range which returns by GetSegmentsRange(). + // So, it's possible to consider the first valid segment from the range which returns by + // GetSegmentsRange(). segMapping.GetSegmentByIndex(segmentIndex, seg); if (!seg.IsValid()) @@ -96,7 +97,8 @@ void AddSegmentEdge(NumMwmIds const & numMwmIds, OsrmFtSegMapping const & segMap // ids (edges). // This factor makes index graph (used in AStar) edge weight smaller than node ids weight. // - // As a result large cross mwm routes with connectors works as Dijkstra, but short and medium routes + // As a result large cross mwm routes with connectors works as Dijkstra, but short and medium + // routes // without connectors works as AStar. // Most of routes don't use leaps, therefore it is important to keep AStar performance. double constexpr kAstarHeuristicFactor = 100000; @@ -107,14 +109,14 @@ void AddSegmentEdge(NumMwmIds const & numMwmIds, OsrmFtSegMapping const & segMap namespace routing { -CrossMwmOsrmGraph::CrossMwmOsrmGraph(shared_ptr numMwmIds, RoutingIndexManager & indexManager) +CrossMwmOsrmGraph::CrossMwmOsrmGraph(shared_ptr numMwmIds, + RoutingIndexManager & indexManager) : m_numMwmIds(numMwmIds), m_indexManager(indexManager) { Clear(); } CrossMwmOsrmGraph::~CrossMwmOsrmGraph() {} - bool CrossMwmOsrmGraph::IsTransition(Segment const & s, bool isOutgoing) { TransitionSegments const & t = GetSegmentMaps(s.GetMwmId()); @@ -124,8 +126,7 @@ bool CrossMwmOsrmGraph::IsTransition(Segment const & s, bool isOutgoing) return t.m_ingoing.count(s) != 0; } -void CrossMwmOsrmGraph::GetEdgeList(Segment const & s, bool isOutgoing, - vector & edges) +void CrossMwmOsrmGraph::GetEdgeList(Segment const & s, bool isOutgoing, vector & edges) { auto const fillEdgeList = [&](TRoutingMappingPtr const & mapping) { vector borderCrosses; @@ -159,8 +160,8 @@ void CrossMwmOsrmGraph::Clear() TransitionPoints CrossMwmOsrmGraph::GetTransitionPoints(Segment const & s, bool isOutgoing) { - vector const & latLons = isOutgoing ? GetOutgoingTransitionPoints(s) - : GetIngoingTransitionPoints(s); + vector const & latLons = + isOutgoing ? GetOutgoingTransitionPoints(s) : GetIngoingTransitionPoints(s); TransitionPoints points; points.reserve(latLons.size()); for (auto const & latLon : latLons) @@ -170,22 +171,19 @@ TransitionPoints CrossMwmOsrmGraph::GetTransitionPoints(Segment const & s, bool CrossMwmOsrmGraph::TransitionSegments const & CrossMwmOsrmGraph::LoadSegmentMaps(NumMwmId numMwmId) { - //map::iterator auto it = m_transitionCache.find(numMwmId); if (it != m_transitionCache.cend()) return it->second; auto const fillAllTransitionSegments = [&](TRoutingMappingPtr const & mapping) { TransitionSegments transitionSegments; - mapping->m_crossContext.ForEachOutgoingNode([&](OutgoingCrossNode const & node) - { - FillTransitionSegments(mapping->m_segMapping, node.m_nodeId, numMwmId, - node.m_point, transitionSegments.m_outgoing); + mapping->m_crossContext.ForEachOutgoingNode([&](OutgoingCrossNode const & node) { + FillTransitionSegments(mapping->m_segMapping, node.m_nodeId, numMwmId, node.m_point, + transitionSegments.m_outgoing); }); - mapping->m_crossContext.ForEachIngoingNode([&](IngoingCrossNode const & node) - { - FillTransitionSegments(mapping->m_segMapping, node.m_nodeId, numMwmId, - node.m_point, transitionSegments.m_ingoing); + mapping->m_crossContext.ForEachIngoingNode([&](IngoingCrossNode const & node) { + FillTransitionSegments(mapping->m_segMapping, node.m_nodeId, numMwmId, node.m_point, + transitionSegments.m_ingoing); }); auto const p = m_transitionCache.emplace(numMwmId, move(transitionSegments)); UNUSED_VALUE(p); diff --git a/routing/cross_mwm_osrm_graph.hpp b/routing/cross_mwm_osrm_graph.hpp index 95fa7ed33c..5e6e5cdfa4 100644 --- a/routing/cross_mwm_osrm_graph.hpp +++ b/routing/cross_mwm_osrm_graph.hpp @@ -63,7 +63,7 @@ private: CHECK(mapping, ("No routing mapping file for countryFile:", countryFile)); if (!mapping->IsValid()) - return false; // mwm was not loaded. + return false; // mwm was not loaded. auto const it = m_mappingGuards.find(numMwmId); if (it == m_mappingGuards.cend()) @@ -80,7 +80,8 @@ private: // OSRM based cross-mwm information. RoutingIndexManager & m_indexManager; - /// \note According to the constructor CrossMwmRoadGraph is initialized with RoutingIndexManager &. + /// \note According to the constructor CrossMwmRoadGraph is initialized with RoutingIndexManager + /// &. /// But then it is copied by value to CrossMwmRoadGraph::RoutingIndexManager m_indexManager. /// It means that there're two copies of RoutingIndexManager in CrossMwmGraph. std::unique_ptr m_crossMwmGraph; diff --git a/routing/cross_mwm_road_graph.cpp b/routing/cross_mwm_road_graph.cpp index 867d664a30..762bee4d76 100644 --- a/routing/cross_mwm_road_graph.cpp +++ b/routing/cross_mwm_road_graph.cpp @@ -124,8 +124,8 @@ bool FindCrossNode(CrossRoutingContextReader const & currentContext, CrossNode c template vector const & ConstructBorderCrossImpl( TWrittenNodeId nodeId, TRoutingMappingPtr const & currentMapping, - unordered_map, CrossMwmRoadGraph::Hash> const & - cachedNextNodes, + unordered_map, + CrossMwmRoadGraph::Hash> const & cachedNextNodes, Fn && borderCrossConstructor) { auto const key = make_pair(nodeId, currentMapping->GetMwmId()); @@ -260,9 +260,9 @@ IRouter::ResultCode CrossMwmRoadGraph::SetFinalNode(CrossNode const & finalNode) return IRouter::NoError; } -bool CrossMwmRoadGraph::ConstructBorderCrossByOutgoingImpl(OutgoingCrossNode const & startNode, - TRoutingMappingPtr const & currentMapping, - vector & crosses) const +bool CrossMwmRoadGraph::ConstructBorderCrossByOutgoingImpl( + OutgoingCrossNode const & startNode, TRoutingMappingPtr const & currentMapping, + vector & crosses) const { auto const fromCross = CrossNode(startNode.m_nodeId, currentMapping->GetMwmId(), startNode.m_point); string const & nextMwm = currentMapping->m_crossContext.GetOutgoingMwmName(startNode); diff --git a/routing/cross_mwm_road_graph.hpp b/routing/cross_mwm_road_graph.hpp index cc1c9ffac4..e4f4ee2704 100644 --- a/routing/cross_mwm_road_graph.hpp +++ b/routing/cross_mwm_road_graph.hpp @@ -36,7 +36,13 @@ struct CrossNode final { } - CrossNode() : node(INVALID_NODE_ID), reverseNode(INVALID_NODE_ID), point(ms::LatLon::Zero()), isVirtual(false) {} + CrossNode() + : node(INVALID_NODE_ID) + , reverseNode(INVALID_NODE_ID) + , point(ms::LatLon::Zero()) + , isVirtual(false) + { + } inline bool IsValid() const { return node != INVALID_NODE_ID; } diff --git a/routing/world_graph.cpp b/routing/world_graph.cpp index 373d3abe51..1f7e4c1249 100644 --- a/routing/world_graph.cpp +++ b/routing/world_graph.cpp @@ -4,8 +4,8 @@ namespace routing { using namespace std; -WorldGraph::WorldGraph(unique_ptr crossMwmGraph, - unique_ptr loader, shared_ptr estimator) +WorldGraph::WorldGraph(unique_ptr crossMwmGraph, unique_ptr loader, + shared_ptr estimator) : m_crossMwmGraph(move(crossMwmGraph)), m_loader(move(loader)), m_estimator(estimator) { CHECK(m_loader, ()); diff --git a/routing/world_graph.hpp b/routing/world_graph.hpp index 6a2a62f4cb..be568b12de 100644 --- a/routing/world_graph.hpp +++ b/routing/world_graph.hpp @@ -23,8 +23,8 @@ public: WorldWithoutLeaps, }; - WorldGraph(std::unique_ptr crossMwmGraph, - std::unique_ptr loader, std::shared_ptr estimator); + WorldGraph(std::unique_ptr crossMwmGraph, std::unique_ptr loader, + std::shared_ptr estimator); void GetEdgeList(Segment const & segment, bool isOutgoing, bool isLeap, std::vector & edges);