diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-07 15:53:41 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-08 12:49:56 +0300 |
commit | f29e63de51933e526c5a4cfc41945180ee11c961 (patch) | |
tree | 2f779ef1aabd5b6a1e490fd7de8a2bb0ea542876 | |
parent | af4c0e975c2a942c82841be4e3a43e8bc7ccc581 (diff) |
Review fixes.
-rw-r--r-- | map/chart_generator.cpp | 91 | ||||
-rw-r--r-- | map/chart_generator.hpp | 19 | ||||
-rw-r--r-- | map/framework.cpp | 26 | ||||
-rw-r--r-- | map/framework.hpp | 3 | ||||
-rw-r--r-- | map/map_tests/chart_generator_tests.cpp | 42 | ||||
-rw-r--r-- | routing/bicycle_directions.cpp | 4 | ||||
-rw-r--r-- | routing/osrm_path_segment_factory.cpp | 4 | ||||
-rw-r--r-- | routing/osrm_router.cpp | 16 | ||||
-rw-r--r-- | routing/road_graph_router.cpp | 8 | ||||
-rw-r--r-- | routing/route.hpp | 8 | ||||
-rw-r--r-- | routing/routing_result_graph.hpp | 4 | ||||
-rw-r--r-- | routing/routing_session.cpp | 11 | ||||
-rw-r--r-- | routing/routing_session.hpp | 10 | ||||
-rw-r--r-- | routing/routing_tests/route_tests.cpp | 10 |
14 files changed, 148 insertions, 108 deletions
diff --git a/map/chart_generator.cpp b/map/chart_generator.cpp index 0d6ce6abbc..c478d3de6f 100644 --- a/map/chart_generator.cpp +++ b/map/chart_generator.cpp @@ -1,6 +1,7 @@ #include "map/chart_generator.hpp" #include "base/assert.hpp" +#include "base/math.hpp" #include "std/algorithm.hpp" #include "std/fstream.hpp" @@ -48,22 +49,26 @@ struct BlendAdaptor }; } // namespace -void NormalizeChartData(deque<double> const & distanceDataM, +namespace maps +{ +bool NormalizeChartData(vector<double> const & distanceDataM, feature::TAltitudes const & altitudeDataM, size_t resultPointCount, vector<double> & uniformAltitudeDataM) { - uniformAltitudeDataM.clear(); - if (distanceDataM.empty() || resultPointCount == 0 || + double constexpr kEpsilon = 1e-6; + + if (distanceDataM.empty() || resultPointCount == 0 || resultPointCount == 1 || distanceDataM.size() != altitudeDataM.size()) - return; + { + return false; + } if (!is_sorted(distanceDataM.cbegin(), distanceDataM.cend())) { LOG(LERROR, ("Route segment distances are not sorted.")); - return; + return false; } - uniformAltitudeDataM.resize(resultPointCount); double const routeLenM = distanceDataM.back(); double const stepLenM = routeLenM / static_cast<double>(resultPointCount - 1); @@ -80,10 +85,10 @@ void NormalizeChartData(deque<double> const & distanceDataM, return static_cast<double>(altitudeDataM.back()); size_t const nextPointIdx = distance(distanceDataM.cbegin(), lowerIt); - CHECK_LESS(0, nextPointIdx, ()); + CHECK_LESS(0, nextPointIdx, ("distFormStartM is greater than 0 but nextPointIdx == 0.")); size_t const prevPointIdx = nextPointIdx - 1; - if (distanceDataM[prevPointIdx] == distanceDataM[nextPointIdx]) + if (my::AlmostEqualAbs(distanceDataM[prevPointIdx], distanceDataM[nextPointIdx], kEpsilon)) return static_cast<double>(altitudeDataM[prevPointIdx]); double const k = (altitudeDataM[nextPointIdx] - altitudeDataM[prevPointIdx]) / @@ -95,17 +100,22 @@ void NormalizeChartData(deque<double> const & distanceDataM, uniformAltitudeDataM.resize(resultPointCount); for (size_t i = 0; i < resultPointCount; ++i) uniformAltitudeDataM[i] = calculateAltitude(static_cast<double>(i) * stepLenM); + + return true; } -void GenerateYAxisChartData(size_t height, double minMetersPerPxl, +void GenerateYAxisChartData(uint32_t height, double minMetersPerPxl, vector<double> const & altitudeDataM, vector<double> & yAxisDataPxl) { - uint32_t constexpr kHeightIndentPxl = 2.0; yAxisDataPxl.clear(); + if (altitudeDataM.empty()) + return; + + uint32_t constexpr kHeightIndentPxl = 2; uint32_t heightIndent = kHeightIndentPxl; if (height <= 2 * kHeightIndentPxl) { - LOG(LERROR, ("Chart height is less then 2 * kHeightIndentPxl (", 2 * kHeightIndentPxl, ")")); + LOG(LERROR, ("Chart height is less or equal than 2 * kHeightIndentPxl (", 2 * kHeightIndentPxl, ")")); heightIndent = 0; } @@ -127,8 +137,8 @@ void GenerateYAxisChartData(size_t height, double minMetersPerPxl, yAxisDataPxl[i] = height - heightIndent - (altitudeDataM[i] - minAltM) / meterPerPxl; } -void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const & geometry, - bool day, vector<uint8_t> & frameBuffer) +void GenerateChartByPoints(uint32_t width, uint32_t height, vector<m2::PointD> const & geometry, + bool lightTheme, vector<uint8_t> & frameBuffer) { frameBuffer.clear(); if (width == 0 || height == 0 || geometry.empty()) @@ -136,8 +146,8 @@ void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const agg::rgba8 const kBackgroundColor = agg::rgba8(255, 255, 255, 0); agg::rgba8 const kLineColor = - day ? agg::rgba8(30, 150, 240, 255) : agg::rgba8(255, 230, 140, 255); - agg::rgba8 const kCurveColor = day ? agg::rgba8(30, 150, 240, 20) : agg::rgba8(255, 230, 140, 20); + lightTheme ? agg::rgba8(30, 150, 240, 255) : agg::rgba8(255, 230, 140, 255); + agg::rgba8 const kCurveColor = lightTheme ? agg::rgba8(30, 150, 240, 20) : agg::rgba8(255, 230, 140, 20); double constexpr kLineWidthPxl = 2.0; uint32_t constexpr kBPP = 4; @@ -151,15 +161,15 @@ void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const agg::rendering_buffer renderBuffer; TPixelFormat pixelFormat(renderBuffer, agg::comp_op_src_over); - TBaseRenderer m_baseRenderer(pixelFormat); + TBaseRenderer baseRenderer(pixelFormat); frameBuffer.assign(width * kBPP * height, 0); - renderBuffer.attach(&frameBuffer[0], static_cast<unsigned int>(width), - static_cast<unsigned int>(height), static_cast<int>(width * kBPP)); - m_baseRenderer.reset_clipping(true); + renderBuffer.attach(&frameBuffer[0], static_cast<unsigned>(width), + static_cast<unsigned>(height), static_cast<int>(width * kBPP)); + baseRenderer.reset_clipping(true); unsigned op = pixelFormat.comp_op(); pixelFormat.comp_op(agg::comp_op_src); - m_baseRenderer.clear(kBackgroundColor); + baseRenderer.clear(kBackgroundColor); pixelFormat.comp_op(op); agg::rasterizer_scanline_aa<> rasterizer; @@ -176,7 +186,7 @@ void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const agg::conv_curve<agg::path_storage> curve(underChartGeometryPath); rasterizer.add_path(curve); agg::scanline32_p8 scanline; - agg::render_scanlines_aa_solid(rasterizer, scanline, m_baseRenderer, kCurveColor); + agg::render_scanlines_aa_solid(rasterizer, scanline, baseRenderer, kCurveColor); // Chart line. TPath path_adaptor(geometry, false); @@ -186,30 +196,41 @@ void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const stroke.line_join(agg::round_join); rasterizer.add_path(stroke); - agg::render_scanlines_aa_solid(rasterizer, scanline, m_baseRenderer, kLineColor); + agg::render_scanlines_aa_solid(rasterizer, scanline, baseRenderer, kLineColor); } -void GenerateChart(size_t width, size_t height, deque<double> const & distanceDataM, - feature::TAltitudes const & altitudeDataM, bool day, +bool GenerateChart(uint32_t width, uint32_t height, vector<double> const & distanceDataM, + feature::TAltitudes const & altitudeDataM, bool lightTheme, vector<uint8_t> & frameBuffer) { - frameBuffer.clear(); - if (altitudeDataM.empty() || distanceDataM.size() != altitudeDataM.size()) - return; + if (distanceDataM.size() != altitudeDataM.size()) + { + LOG(LERROR, ("The route is in inconsistent state. Size of altitudes is", altitudeDataM.size(), + ". Number of segment is", distanceDataM.size())); + return false; + } + + if (altitudeDataM.empty()) + return false; vector<double> uniformAltitudeDataM; - NormalizeChartData(distanceDataM, altitudeDataM, width, uniformAltitudeDataM); - if (uniformAltitudeDataM.empty()) - return; + if (!NormalizeChartData(distanceDataM, altitudeDataM, width, uniformAltitudeDataM)) + return false; vector<double> yAxisDataPxl; GenerateYAxisChartData(height, 1.0 /* minMetersPerPxl */, uniformAltitudeDataM, yAxisDataPxl); - size_t const uniformAltitudeDataSz = yAxisDataPxl.size(); - double const oneSegLenPix = static_cast<double>(width) / (uniformAltitudeDataSz - 1); - vector<m2::PointD> geometry(uniformAltitudeDataSz); - for (size_t i = 0; i < uniformAltitudeDataSz; ++i) + size_t const uniformAltitudeDataSize = yAxisDataPxl.size(); + if (uniformAltitudeDataSize <= 1) + return false; + + double const oneSegLenPix = static_cast<double>(width) / (uniformAltitudeDataSize - 1); + vector<m2::PointD> geometry(uniformAltitudeDataSize); + for (size_t i = 0; i < uniformAltitudeDataSize; ++i) geometry[i] = m2::PointD(i * oneSegLenPix, yAxisDataPxl[i]); - GenerateChartByPoints(width, height, geometry, day, frameBuffer); + frameBuffer.clear(); + GenerateChartByPoints(width, height, geometry, lightTheme, frameBuffer); + return true; } +} // namespace maps diff --git a/map/chart_generator.hpp b/map/chart_generator.hpp index f4dc1ede5f..51c66bd8f2 100644 --- a/map/chart_generator.hpp +++ b/map/chart_generator.hpp @@ -4,13 +4,15 @@ #include "geometry/point2d.hpp" -#include "std/deque.hpp" +#include "std/cstdint.hpp" #include "std/vector.hpp" +namespace maps +{ /// \brief fills uniformAltitudeDataM with altitude data which evenly distributed by /// |resultPointCount| points. |distanceDataM| and |altitudeDataM| form a curve of route altitude. /// This method is used to generalize and evenly distribute points of the chart. -void NormalizeChartData(deque<double> const & distanceDataM, +bool NormalizeChartData(vector<double> const & distanceDataM, feature::TAltitudes const & altitudeDataM, size_t resultPointCount, vector<double> & uniformAltitudeDataM); @@ -20,7 +22,7 @@ void NormalizeChartData(deque<double> const & distanceDataM, /// \param minMetersInPixel minimum meter number per height pixel. /// \param altitudeDataM altitude data vector in meters. /// \param yAxisDataPxl Y-axis data of altitude chart in pixels. -void GenerateYAxisChartData(size_t height, double minMetersPerPxl, +void GenerateYAxisChartData(uint32_t height, double minMetersPerPxl, vector<double> const & altitudeDataM, vector<double> & yAxisDataPxl); /// \brief generates chart image on a canvas with size |width|, |height| with |geometry|. @@ -28,11 +30,14 @@ void GenerateYAxisChartData(size_t height, double minMetersPerPxl, /// \param width is result image width in pixels. /// \param height is result image height in pixels. /// \param geometry is points which is used to draw a curve of the chart. +/// \param lightTheme is true for light theme image colors +/// and false for night image colors. /// \param frameBuffer is a vector for a result image. It's resized in this method. /// It's filled with RGBA(8888) image date. -void GenerateChartByPoints(size_t width, size_t height, vector<m2::PointD> const & geometry, - bool day, vector<uint8_t> & frameBuffer); +void GenerateChartByPoints(uint32_t width, uint32_t height, vector<m2::PointD> const & geometry, + bool lightTheme, vector<uint8_t> & frameBuffer); -void GenerateChart(size_t width, size_t height, deque<double> const & distanceDataM, - feature::TAltitudes const & altitudeDataM, bool day, +bool GenerateChart(uint32_t width, uint32_t height, vector<double> const & distanceDataM, + feature::TAltitudes const & altitudeDataM, bool lightTheme, vector<uint8_t> & frameBuffer); +} // namespace maps diff --git a/map/framework.cpp b/map/framework.cpp index 292140a2ba..33d6315a92 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1,6 +1,6 @@ #include "map/framework.hpp" -#include "map/ge0_parser.hpp" #include "map/chart_generator.hpp" +#include "map/ge0_parser.hpp" #include "map/geourl_process.hpp" #include "map/gps_tracker.hpp" #include "map/user_mark.hpp" @@ -80,7 +80,6 @@ #include "std/algorithm.hpp" #include "std/bind.hpp" -#include "std/deque.hpp" #include "std/target_os.hpp" #include "std/vector.hpp" @@ -1695,6 +1694,11 @@ MapStyle Framework::GetMapStyle() const return GetStyleReader().GetCurrentStyle(); } +bool Framework::IsLightMapTheme() const +{ + return GetMapStyle() != MapStyleDark; +} + void Framework::SetupMeasurementSystem() { GetPlatform().SetupMeasurementSystem(); @@ -2986,25 +2990,17 @@ bool Framework::OriginalFeatureHasDefaultName(FeatureID const & fid) const bool Framework::HasRouteAltitude() const { return m_routingSession.HasRouteAltitude(); } -bool Framework::GenerateRouteAltitudeChart(size_t width, size_t height, +bool Framework::GenerateRouteAltitudeChart(uint32_t width, uint32_t height, vector<uint8_t> & imageRGBAData) const { feature::TAltitudes altitudes; if (!m_routingSession.GetRouteAltitudes(altitudes)) return false; - deque<double> segDistanceM; + vector<double> segDistanceM; if (!m_routingSession.GetSegDistanceM(segDistanceM) && segDistanceM.empty()) return false; - segDistanceM.push_front(0.0); + segDistanceM.insert(segDistanceM.begin(), 0.0); - if (altitudes.size() != segDistanceM.size()) - { - LOG(LERROR, ("The route is in inconsistent state. Size of altitudes is", altitudes.size(), - ". Number of segment is", segDistanceM.size())); - return false; - } - - bool day = (GetMapStyle() != MapStyleDark); - GenerateChart(width, height, segDistanceM, altitudes, day, imageRGBAData); - return true; + return maps::GenerateChart(width, height, segDistanceM, altitudes, + IsLightMapTheme(), imageRGBAData); } diff --git a/map/framework.hpp b/map/framework.hpp index a1d6bbd0c3..09f820140d 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -416,6 +416,7 @@ public: void SetMapStyle(MapStyle mapStyle); void MarkMapStyle(MapStyle mapStyle); MapStyle GetMapStyle() const; + bool IsLightMapTheme() const; void SetupMeasurementSystem(); @@ -726,7 +727,7 @@ public: void SaveAutoZoom(bool allowAutoZoom); bool HasRouteAltitude() const; - bool GenerateRouteAltitudeChart(size_t width, size_t height, + bool GenerateRouteAltitudeChart(uint32_t width, uint32_t height, vector<uint8_t> & imageRGBAData) const; public: diff --git a/map/map_tests/chart_generator_tests.cpp b/map/map_tests/chart_generator_tests.cpp index eec4f88666..40ed7bb2dd 100644 --- a/map/map_tests/chart_generator_tests.cpp +++ b/map/map_tests/chart_generator_tests.cpp @@ -4,7 +4,6 @@ #include "base/math.hpp" -#include "std/deque.hpp" #include "std/vector.hpp" namespace @@ -34,59 +33,70 @@ bool IsColor(vector<uint8_t> const & frameBuffer, size_t startColorIdx, uint8_t frameBuffer[startColorIdx + 2] == expectedB && frameBuffer[startColorIdx + 3] == expectedA; } -UNIT_TEST(NormalizeChartDataZeroTest) +UNIT_TEST(NormalizeChartData_SmokeTest) { - deque<double> const distanceDataM = {0.0, 0.0, 0.0}; + vector<double> const distanceDataM = {0.0, 0.0, 0.0}; feature::TAltitudes const altitudeDataM = {0, 0, 0}; vector<double> uniformAltitudeDataM; - NormalizeChartData(distanceDataM, altitudeDataM, 2 /* resultPointCount */, uniformAltitudeDataM); + TEST(maps::NormalizeChartData(distanceDataM, altitudeDataM, 2 /* resultPointCount */, uniformAltitudeDataM), + ()); vector<double> const expectedUniformAltitudeDataM = {0.0, 0.0}; TEST_EQUAL(expectedUniformAltitudeDataM, uniformAltitudeDataM, ()); } -UNIT_TEST(NormalizeChartDataTest) +UNIT_TEST(NormalizeChartData_Test) { - deque<double> const distanceDataM = {0.0, 2.0, 4.0, 6.0}; + vector<double> const distanceDataM = {0.0, 2.0, 4.0, 6.0}; feature::TAltitudes const altitudeDataM = {-9, 0, 9, 18}; vector<double> uniformAltitudeDataM; - NormalizeChartData(distanceDataM, altitudeDataM, 10 /* resultPointCount */, uniformAltitudeDataM); + TEST(maps::NormalizeChartData(distanceDataM, altitudeDataM, 10 /* resultPointCount */, uniformAltitudeDataM), + ()); vector<double> const expectedUniformAltitudeDataM = {-9.0, -6.0, -3.0, 0.0, 3.0, 6.0, 9.0, 12.0, 15.0, 18.0}; TEST(AlmostEqualAbs(uniformAltitudeDataM, expectedUniformAltitudeDataM), ()); } -UNIT_TEST(GenerateYAxisChartDataZeroTest) +UNIT_TEST(GenerateYAxisChartData_SmokeTest) { vector<double> const altitudeDataM = {0.0, 0.0}; vector<double> yAxisDataPxl; - GenerateYAxisChartData(30 /* height */, 1.0 /* minMetersPerPxl */, altitudeDataM, yAxisDataPxl); + maps::GenerateYAxisChartData(30 /* height */, 1.0 /* minMetersPerPxl */, altitudeDataM, yAxisDataPxl); vector<double> expecttedYAxisDataPxl = {28.0, 28.0}; TEST(AlmostEqualAbs(yAxisDataPxl, expecttedYAxisDataPxl), ()); } +UNIT_TEST(GenerateYAxisChartData_EmptyAltitudeDataTest) +{ + vector<double> const altitudeDataM = {}; + vector<double> yAxisDataPxl; + + maps::GenerateYAxisChartData(30 /* height */, 1.0 /* minMetersPerPxl */, altitudeDataM, yAxisDataPxl); + TEST(yAxisDataPxl.empty(), ()); +} + UNIT_TEST(GenerateYAxisChartDataTest) { vector<double> const altitudeDataM = {0.0, 2.0, 0.0, -2.0, 1.0}; vector<double> yAxisDataPxl; - GenerateYAxisChartData(100 /* height */, 1.0 /* minMetersPerPxl */, altitudeDataM, yAxisDataPxl); + maps::GenerateYAxisChartData(100 /* height */, 1.0 /* minMetersPerPxl */, altitudeDataM, yAxisDataPxl); vector<double> expecttedYAxisDataPxl = {96.0, 94.0, 96.0, 98.0, 95.0}; TEST(AlmostEqualAbs(yAxisDataPxl, expecttedYAxisDataPxl), ()); } -UNIT_TEST(GenerateChartByPointsTest) +UNIT_TEST(GenerateChartByPoints_Test) { vector<m2::PointD> const geometry = {{0.0, 0.0}, {10.0, 10.0}}; size_t constexpr width = 40; vector<uint8_t> frameBuffer; - GenerateChartByPoints(width, 40 /* height */, geometry, true /* day */, frameBuffer); + maps::GenerateChartByPoints(width, 40 /* height */, geometry, true /* day */, frameBuffer); TEST(IsColor(frameBuffer, 0 /* startColorIdx */, 30 /* expectedR */, 150 /* expectedG */, 240 /* expectedB */, 255 /* expectedA */), ()); @@ -95,14 +105,16 @@ UNIT_TEST(GenerateChartByPointsTest) ()); } -UNIT_TEST(GenerateChartTest) +UNIT_TEST(GenerateChart_Test) { size_t constexpr width = 50; - deque<double> const distanceDataM = {0.0, 100.0}; + vector<double> const distanceDataM = {0.0, 100.0}; feature::TAltitudes const & altitudeDataM = {0, 1000}; vector<uint8_t> frameBuffer; - GenerateChart(width, 50 /* height */, distanceDataM, altitudeDataM, false /* day */, frameBuffer); + TEST(maps::GenerateChart(width, 50 /* height */, distanceDataM, altitudeDataM, false /* day */, + frameBuffer), + ()); TEST(IsColor(frameBuffer, 0 /* startColorIdx */, 255 /* expectedR */, 255 /* expectedG */, 255 /* expectedB */, 0 /* expectedA */), ()); diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 965bbe5173..19f3ab28b0 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -56,13 +56,13 @@ public: double GetPathLength() const override { return m_routeLength; } - Junction const & GetStartPoint() const override + Junction GetStartPoint() const override { CHECK(!m_routeEdges.empty(), ()); return m_routeEdges.front().GetStartJunction(); } - Junction const & GetEndPoint() const override + Junction GetEndPoint() const override { CHECK(!m_routeEdges.empty(), ()); return m_routeEdges.back().GetEndJunction(); diff --git a/routing/osrm_path_segment_factory.cpp b/routing/osrm_path_segment_factory.cpp index c861707003..3005d8ec19 100644 --- a/routing/osrm_path_segment_factory.cpp +++ b/routing/osrm_path_segment_factory.cpp @@ -57,13 +57,13 @@ void LoadPathGeometry(buffer_vector<TSeg, 8> const & buffer, size_t startIndex, if (startIdx < endIdx) { for (auto idx = startIdx; idx <= endIdx; ++idx) - loadPathGeometry.m_path.push_back(routing::Junction(ft.GetPoint(idx), feature::kDefaultAltitudeMeters)); + loadPathGeometry.m_path.emplace_back(ft.GetPoint(idx), feature::kDefaultAltitudeMeters); } else { // I use big signed type because endIdx can be 0. for (int64_t idx = startIdx; idx >= static_cast<int64_t>(endIdx); --idx) - loadPathGeometry.m_path.push_back(routing::Junction(ft.GetPoint(idx), feature::kDefaultAltitudeMeters)); + loadPathGeometry.m_path.emplace_back(ft.GetPoint(idx), feature::kDefaultAltitudeMeters); } // Load lanes if it is a last segment before junction. diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 402853ffc7..3ce50d4db3 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -153,12 +153,12 @@ public: double GetPathLength() const override { return m_rawResult.shortestPathLength; } - Junction const & GetStartPoint() const override + Junction GetStartPoint() const override { return Junction(m_rawResult.sourceEdge.segmentPoint, feature::kDefaultAltitudeMeters); } - Junction const & GetEndPoint() const override + Junction GetEndPoint() const override { return Junction(m_rawResult.targetEdge.segmentPoint, feature::kDefaultAltitudeMeters); } @@ -377,9 +377,9 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & } route.SetGeometry(points.begin(), points.end()); - route.SwapTurnInstructions(turnsDir); - route.SwapSectionTimes(times); - route.SwapStreetNames(streets); + route.SetTurnInstructions(move(turnsDir)); + route.SetSectionTimes(move(times)); + route.SetStreetNames(move(streets)); return NoError; } @@ -518,9 +518,9 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, JunctionsToPoints(junctions, points); route.SetGeometry(points.begin(), points.end()); - route.SwapTurnInstructions(turnsDir); - route.SwapSectionTimes(times); - route.SwapStreetNames(streets); + route.SetTurnInstructions(move(turnsDir)); + route.SetSectionTimes(move(times)); + route.SetStreetNames(move(streets)); return NoError; } diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index f449e70531..2ce3321978 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -255,10 +255,10 @@ void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route, JunctionsToAltitudes(junctions, altitudes); route.SetGeometry(routeGeometry.begin(), routeGeometry.end()); - route.SwapSectionTimes(times); - route.SwapTurnInstructions(turnsDir); - route.SwapStreetNames(streetNames); - route.SwapAltitudes(altitudes); + route.SetSectionTimes(move(times)); + route.SetTurnInstructions(move(turnsDir)); + route.SetStreetNames(move(streetNames)); + route.SetAltitudes(move(altitudes)); } unique_ptr<IRouter> CreatePedestrianAStarRouter(Index & index, TCountryFileFn const & countryFileFn) diff --git a/routing/route.hpp b/routing/route.hpp index 7c1fdb294a..6e729b855c 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -55,10 +55,10 @@ public: Update(); } - inline void SwapTurnInstructions(TTurns & v) { swap(m_turns, v); } - inline void SwapSectionTimes(TTimes & v) { swap(m_times, v); } - inline void SwapStreetNames(TStreets & v) { swap(m_streets, v); } - inline void SwapAltitudes(feature::TAltitudes & v) { swap(m_altitudes, v); } + inline void SetTurnInstructions(TTurns &&v) { m_turns = move(v); } + inline void SetSectionTimes(TTimes && v) { m_times = move(v); } + inline void SetStreetNames(TStreets && v) { m_streets = move(v); } + inline void SetAltitudes(feature::TAltitudes && v) { m_altitudes = move(v); } uint32_t GetTotalTimeSec() const; uint32_t GetCurrentTimeToEndSec() const; diff --git a/routing/routing_result_graph.hpp b/routing/routing_result_graph.hpp index d815b228ec..2fac67733d 100644 --- a/routing/routing_result_graph.hpp +++ b/routing/routing_result_graph.hpp @@ -25,8 +25,8 @@ public: m2::PointD const & junctionPoint, size_t & ingoingCount, TurnCandidates & outgoingTurns) const = 0; virtual double GetPathLength() const = 0; - virtual Junction const & GetStartPoint() const = 0; - virtual Junction const & GetEndPoint() const = 0; + virtual Junction GetStartPoint() const = 0; + virtual Junction GetEndPoint() const = 0; virtual ~IRoutingResult() = default; }; diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index dbdb08c515..2f918a2079 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -523,7 +523,12 @@ void RoutingSession::EmitCloseRoutingEvent() const alohalytics::Location::FromLatLon(lastGoodPoint.lat, lastGoodPoint.lon)); } -bool RoutingSession::HasRouteAltitudeImpl() const { return !m_route.GetAltitudes().empty(); } +bool RoutingSession::HasRouteAltitudeImpl() const +{ + return !m_route.GetAltitudes().empty() + && m_route.GetAltitudes().size() == m_route.GetSegDistanceM().size() + 1; +} + bool RoutingSession::HasRouteAltitude() const { threads::MutexGuard guard(m_routeSessionMutex); @@ -539,12 +544,12 @@ bool RoutingSession::GetRouteAltitudes(feature::TAltitudes & routeAltitudes) con return true; } -bool RoutingSession::GetSegDistanceM(deque<double> & routeSegDistanceM) const +bool RoutingSession::GetSegDistanceM(vector<double> & routeSegDistanceM) const { threads::MutexGuard guard(m_routeSessionMutex); if (!m_route.IsValid()) return false; - routeSegDistanceM.assign(m_route.GetSegDistanceM().begin(), m_route.GetSegDistanceM().end()); + routeSegDistanceM = m_route.GetSegDistanceM(); return true; } diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index a15b50a6f0..9156ab53ae 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -15,7 +15,6 @@ #include "base/mutex.hpp" #include "std/atomic.hpp" -#include "std/deque.hpp" #include "std/limits.hpp" #include "std/unique_ptr.hpp" @@ -106,15 +105,15 @@ public: inline void SetState(State state) { m_state = state; } Route const & GetRoute() const { return m_route; } - /// \returns true if any altitude information along |m_route| is available and + /// \returns true if altitude information along |m_route| is available and /// false otherwise. bool HasRouteAltitude() const; /// \brief copies route altitude information to |routeAltitudes| if any is available and - /// returns true. If no route altitude information is available returns false. + /// returns true. If there's no navigation route, the method returns false. bool GetRouteAltitudes(feature::TAltitudes & routeAltitudes) const; /// \brief copies distance from route beginning to ends of route segments in meters and /// returns true. If the route is not valid returns false. - bool GetSegDistanceM(deque<double> & routeSegDistanceM) const; + bool GetSegDistanceM(vector<double> & routeSegDistanceM) const; State OnLocationPositionChanged(location::GpsInfo const & info, Index const & index); void GetRouteFollowingInfo(location::FollowingInfo & info) const; @@ -148,7 +147,6 @@ public: double GetCompletionPercent() const; void EmitCloseRoutingEvent() const; - bool HasRouteAltitudeImpl() const; private: struct DoReadyCallback @@ -176,6 +174,8 @@ private: void RemoveRoute(); void RemoveRouteImpl(); + bool HasRouteAltitudeImpl() const; + private: unique_ptr<AsyncRouter> m_router; Route m_route; diff --git a/routing/routing_tests/route_tests.cpp b/routing/routing_tests/route_tests.cpp index 821e4a59ac..985d270935 100644 --- a/routing/routing_tests/route_tests.cpp +++ b/routing/routing_tests/route_tests.cpp @@ -50,7 +50,7 @@ UNIT_TEST(DistanceToCurrentTurnTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SwapTurnInstructions(turns); + route.SetTurnInstructions(move(turns)); double distance; turns::TurnItem turn; @@ -85,7 +85,7 @@ UNIT_TEST(NextTurnTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SwapTurnInstructions(turns); + route.SetTurnInstructions(move(turns)); double distance, nextDistance; turns::TurnItem turn; @@ -114,7 +114,7 @@ UNIT_TEST(NextTurnsTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SwapTurnInstructions(turns); + route.SetTurnInstructions(move(turns)); vector<turns::TurnItemDist> turnsDist; { @@ -165,9 +165,9 @@ UNIT_TEST(RouteNameTest) route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SwapTurnInstructions(turns); + route.SetTurnInstructions(move(turns)); Route::TStreets names(kTestNames); - route.SwapStreetNames(names); + route.SetStreetNames(move(names)); string name; route.GetCurrentStreetName(name); |