From 3117ecbc5ec225ef36409fb905b0cff8498a01b0 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Fri, 10 Apr 2015 22:58:48 +0300 Subject: [PATCH] clang-format --- map/framework.cpp | 11 +++++++-- routing/astar_router.cpp | 5 ++-- routing/astar_router.hpp | 5 +++- routing/dijkstra_router.hpp | 5 +++- routing/features_road_graph.cpp | 15 +++++------ routing/nearest_finder.cpp | 23 +++++++++-------- routing/nearest_finder.hpp | 44 +++++++++++++++++++++------------ routing/road_graph_router.cpp | 18 ++++++++------ 8 files changed, 79 insertions(+), 47 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index f54b98bdd6..0b8bc23366 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2100,9 +2100,9 @@ void Framework::BuildRoute(m2::PointD const & destination) vector absentFiles; if (code == IRouter::NoError) { - if(route.GetPoly().GetSize() < 2) + if (route.GetPoly().GetSize() < 2) { - LOG(LWARNING, ("Invalide track for drawing. Have only ",route.GetPoly().GetSize(), "points")); + LOG(LWARNING, ("Invalid track - only", route.GetPoly().GetSize(), "point(s).")); return; } InsertRoute(route); @@ -2186,7 +2186,14 @@ void Framework::CheckLocationForRouting(GpsInfo const & info) m_routingSession.RebuildRoute(position, [this] (Route const & route, IRouter::ResultCode code) { if (code == IRouter::NoError) + { + if (route.GetPoly().GetSize() < 2) + { + LOG(LWARNING, ("Invalid track - only", route.GetPoly().GetSize(), "point(s).")); + return; + } InsertRoute(route); + } }); } } diff --git a/routing/astar_router.cpp b/routing/astar_router.cpp index 831485ebec..a93253fae4 100644 --- a/routing/astar_router.cpp +++ b/routing/astar_router.cpp @@ -131,9 +131,10 @@ IRouter::ResultCode AStarRouter::CalculateRouteM2M(vector const & start if (v.dist > bestDistance[v.pos]) continue; - /// We need the original start position because it contains the projection point to the road feature. + /// We need the original start position because it contains the projection point to the road + /// feature. auto pos = lower_bound(sortedStartPos.begin(), sortedStartPos.end(), v.pos); - if (pos != sortedStartPos.end() && *pos==v.pos) + if (pos != sortedStartPos.end() && *pos == v.pos) { ReconstructRoute(*pos, parent, route); return IRouter::NoError; diff --git a/routing/astar_router.hpp b/routing/astar_router.hpp index 4aeb62a019..cf4f717244 100644 --- a/routing/astar_router.hpp +++ b/routing/astar_router.hpp @@ -12,7 +12,10 @@ class AStarRouter : public RoadGraphRouter { typedef RoadGraphRouter BaseT; public: - AStarRouter(Index const * pIndex = 0) : BaseT(pIndex, unique_ptr(new PedestrianModel())) {} + AStarRouter(Index const * pIndex = 0) + : BaseT(pIndex, unique_ptr(new PedestrianModel())) + { + } // IRouter overrides: string GetName() const override { return "astar-pedestrian"; } diff --git a/routing/dijkstra_router.hpp b/routing/dijkstra_router.hpp index f8a5fdd8b0..b3b9c64316 100644 --- a/routing/dijkstra_router.hpp +++ b/routing/dijkstra_router.hpp @@ -11,7 +11,10 @@ class DijkstraRouter : public RoadGraphRouter typedef RoadGraphRouter BaseT; public: - DijkstraRouter(Index const * pIndex = 0) : BaseT(pIndex,unique_ptr(new PedestrianModel())) {} + DijkstraRouter(Index const * pIndex = 0) + : BaseT(pIndex, unique_ptr(new PedestrianModel())) + { + } // IRouter overrides: string GetName() const override { return "pedestrian-dijkstra"; } diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index 21d6bc1757..ae56e22527 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -17,7 +17,7 @@ namespace uint32_t const FEATURE_CACHE_SIZE = 10; uint32_t const READ_ROAD_SCALE = 13; double const READ_CROSS_EPSILON = 1.0E-4; -double const NORMALIZE_TO_SECONDS = 3.6; /* 60 * 60 / 1000 m/s to km/h*/ +double const KMPH2MPS = 1000.0 / (60 * 60); uint32_t indexFound = 0; uint32_t indexCheck = 0; @@ -258,12 +258,12 @@ void FeaturesRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route int const inc = pos1.IsForward() ? -1 : 1; int ptID = pos1.GetSegStartPointId(); m2::PointD curPoint; - double segmentLength = 0.0; + double segmentLengthM = 0.0; do { curPoint = ft1.GetPoint(ptID); poly.push_back(curPoint); - segmentLength += CalcDistanceMeters(curPoint, prevPoint); + segmentLengthM += CalcDistanceMeters(curPoint, prevPoint); prevPoint = curPoint; LOG(LDEBUG, (curPoint, pos1.GetFeatureId(), ptID)); @@ -272,9 +272,9 @@ void FeaturesRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route } while (ptID >= 0 && ptID < ft1.GetPointsCount() && !m2::AlmostEqual(curPoint, lastPt)); - segmentLength += CalcDistanceMeters(lastPt, prevPoint); + segmentLengthM += CalcDistanceMeters(lastPt, prevPoint); // Calculation total feature time. Seconds. - trackTime += NORMALIZE_TO_SECONDS * segmentLength / m_vehicleModel->GetSpeed(ft1); + trackTime += segmentLengthM / (m_vehicleModel->GetSpeed(ft1) * KMPH2MPS); // Assign current processing feature. if (diffIDs) @@ -282,9 +282,10 @@ void FeaturesRoadGraph::ReconstructPath(RoadPosVectorT const & positions, Route } poly.push_back(positions.front().GetSegEndpoint()); - trackTime += NORMALIZE_TO_SECONDS * CalcDistanceMeters(poly.back(), prevPoint) / m_vehicleModel->GetSpeed(ft1); + trackTime += + CalcDistanceMeters(poly.back(), prevPoint) / (m_vehicleModel->GetSpeed(ft1) * KMPH2MPS); - ASSERT_GREATER(poly.size(), 1, ("Track with no points")); + ASSERT_GREATER(poly.size(), 1, ("Empty track")); if (poly.size() > 1) { diff --git a/routing/nearest_finder.cpp b/routing/nearest_finder.cpp index 523ca57ba3..2a62271baf 100644 --- a/routing/nearest_finder.cpp +++ b/routing/nearest_finder.cpp @@ -1,9 +1,12 @@ #include "nearest_finder.hpp" +#include "../geometry/distance.hpp" + +#include "../indexer/feature.hpp" + namespace routing { - -void NearestFinder::operator()(const FeatureType &ft) +void NearestRoadPosFinder::AddInformationSource(const FeatureType & ft) { if (ft.GetFeatureType() != feature::GEOM_LINE || m_vehicleModel->GetSpeed(ft) == 0.0) return; @@ -26,7 +29,7 @@ void NearestFinder::operator()(const FeatureType &ft) { res.m_dist = d; res.m_fid = ft.GetID().m_offset; - res.m_segIdx = i - 1; + res.m_segId = i - 1; res.m_point = pt; res.m_isOneway = m_vehicleModel->IsOneWay(ft); @@ -40,11 +43,11 @@ void NearestFinder::operator()(const FeatureType &ft) m_candidates.push_back(res); } -void NearestFinder::MakeResult(vector &res, const size_t maxCount) +void NearestRoadPosFinder::MakeResult(vector & res, const size_t maxCount) { - if (m_mwmId == numeric_limits::max()) + if (m_mwmId == INVALID_MWWMID) return; - sort(m_candidates.begin(), m_candidates.end(), [] (Candidate const & r1, Candidate const & r2) + sort(m_candidates.begin(), m_candidates.end(), [](Candidate const & r1, Candidate const & r2) { return (r1.m_dist < r2.m_dist); }); @@ -52,17 +55,17 @@ void NearestFinder::MakeResult(vector &res, const size_t maxCount) res.clear(); res.reserve(maxCount); - for (Candidate const & candidate: m_candidates) + for (Candidate const & candidate : m_candidates) { if (res.size() == maxCount) break; - res.push_back(RoadPos(candidate.m_fid, true, candidate.m_segIdx, candidate.m_point)); + res.push_back(RoadPos(candidate.m_fid, true, candidate.m_segId, candidate.m_point)); if (res.size() == maxCount) break; if (candidate.m_isOneway) continue; - res.push_back(RoadPos(candidate.m_fid, false, candidate.m_segIdx, candidate.m_point)); + res.push_back(RoadPos(candidate.m_fid, false, candidate.m_segId, candidate.m_point)); } } -} //namespace routing +} // namespace routing diff --git a/routing/nearest_finder.hpp b/routing/nearest_finder.hpp index a4a3323374..49d7b9b954 100644 --- a/routing/nearest_finder.hpp +++ b/routing/nearest_finder.hpp @@ -3,28 +3,39 @@ #include "road_graph.hpp" #include "vehicle_model.hpp" -#include "../geometry/distance.hpp" #include "../geometry/point2d.hpp" #include "../indexer/index.hpp" #include "../std/unique_ptr.hpp" +#include "../std/vector.hpp" + +class FeatureType; namespace routing { - -class NearestFinder +/// Helper functor class to filter nearest RoadPos'es to the given starting point. +class NearestRoadPosFinder { - static constexpr uint32_t INVALID_FID = numeric_limits::max(); + static constexpr uint32_t INVALID_FID = numeric_limits::infinity(); + static constexpr uint32_t INVALID_MWWMID = numeric_limits::infinity(); struct Candidate { double m_dist; - uint32_t m_segIdx; + uint32_t m_segId; m2::PointD m_point; uint32_t m_fid; bool m_isOneway; - Candidate() : m_dist(numeric_limits::max()), m_fid(INVALID_FID) {} + + Candidate() + : m_dist(numeric_limits::max()), + m_segId(0), + m_point(m2::PointD::Zero()), + m_fid(INVALID_FID), + m_isOneway(false) + { + } }; m2::PointD m_point; @@ -34,21 +45,22 @@ class NearestFinder uint32_t m_mwmId; public: - NearestFinder(m2::PointD const & point, - m2::PointD const & direction, + + NearestRoadPosFinder(m2::PointD const & point, m2::PointD const & direction, unique_ptr const & vehicleModel) - : m_point(point), m_direction(direction), m_vehicleModel(vehicleModel), - m_mwmId(numeric_limits::max()) - {} + : m_point(point), + m_direction(direction), + m_vehicleModel(vehicleModel), + m_mwmId(INVALID_MWWMID) + { + } - bool HasCandidates() const { return !m_candidates.empty(); } + inline bool HasCandidates() const { return !m_candidates.empty(); } - void operator() (FeatureType const & ft); + void AddInformationSource(FeatureType const & ft); void MakeResult(vector & res, size_t const maxCount); - uint32_t GetMwmID() {return m_mwmId;} - + inline uint32_t GetMwmID() const { return m_mwmId; } }; - } diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 644f459363..da73189916 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -1,8 +1,8 @@ -#include "road_graph_router.hpp" #include "features_road_graph.hpp" +#include "nearest_finder.hpp" +#include "road_graph_router.hpp" #include "route.hpp" #include "vehicle_model.hpp" -#include "nearest_finder.hpp" #include "../indexer/feature.hpp" #include "../indexer/ftypes_matcher.hpp" @@ -11,7 +11,6 @@ #include "../geometry/distance.hpp" #include "../base/timer.hpp" - #include "../base/logging.hpp" namespace @@ -28,14 +27,17 @@ RoadGraphRouter::~RoadGraphRouter() } RoadGraphRouter::RoadGraphRouter(Index const * pIndex, unique_ptr && vehicleModel) - : m_vehicleModel(move(vehicleModel)), m_pIndex(pIndex) {} + : m_vehicleModel(move(vehicleModel)), m_pIndex(pIndex) +{ +} size_t RoadGraphRouter::GetRoadPos(m2::PointD const & pt, vector & pos) { - NearestFinder finder(pt, m2::PointD::Zero() /* undirected */, m_vehicleModel); - m_pIndex->ForEachInRect(finder, - MercatorBounds::RectByCenterXYAndSizeInMeters(pt, FEATURE_BY_POINT_RADIUS_M), - FeaturesRoadGraph::GetStreetReadScale()); + NearestRoadPosFinder finder(pt, m2::PointD::Zero() /* undirected */, m_vehicleModel); + auto f = [&finder](FeatureType & ft) { finder.AddInformationSource(ft); }; + m_pIndex->ForEachInRect( + f, MercatorBounds::RectByCenterXYAndSizeInMeters(pt, FEATURE_BY_POINT_RADIUS_M), + FeaturesRoadGraph::GetStreetReadScale()); finder.MakeResult(pos, MAX_ROAD_CANDIDATES); return finder.GetMwmID();