From 81a00a636f09bf6ca9e1e76811031b7dba284034 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 5 May 2024 21:10:59 +0200 Subject: [PATCH 1/8] Upgrade clang-format to version 14 Version 14 is the version available on ubuntu-latest in Github actions --- .github/workflows/osrm-backend.yml | 4 ++-- CONTRIBUTING.md | 2 +- scripts/format.sh | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 6e8be0645fe..d1a14d8a972 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -71,7 +71,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} format-taginfo-docs: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - name: Use Node.js @@ -88,7 +88,7 @@ jobs: - name: Prepare environment run: | npm ci --ignore-scripts - clang-format-10 --version + clang-format-14 --version - name: Run checks run: | ./scripts/check_taginfo.py taginfo.json profiles/car.lua diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 30b697e550c..2b36d2b6cb7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ You can add a :+1: emoji reaction to the issue if you want to express interest i # Developer -We use `clang-format` version `3.8` to consistently format the code base. There is a helper script under `scripts/format.sh`. +We use `clang-format` version `14` to consistently format the code base. There is a helper script under `scripts/format.sh`. The format is automatically checked by the `mason-linux-release` job of a Travis CI build. To save development time a local hook `.git/hooks/pre-push` ``` diff --git a/scripts/format.sh b/scripts/format.sh index 03ffcaba1aa..1a256d27e31 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -19,18 +19,18 @@ elif [[ ${OS} = "Darwin" ]] ; then fi # Discover clang-format -if type clang-format-10 2> /dev/null ; then - CLANG_FORMAT=clang-format-10 +if type clang-format-14 2> /dev/null ; then + CLANG_FORMAT=clang-format-14 elif type clang-format 2> /dev/null ; then # Clang format found, but need to check version CLANG_FORMAT=clang-format V=$(clang-format --version) - if [[ $V != *10.0* ]] ; then - echo "clang-format is not 10.0 (returned ${V})" + if [[ $V != *14.0* ]] ; then + echo "clang-format is not 14.0 (returned ${V})" #exit 1 fi else - echo "No appropriate clang-format found (expected clang-format-10, or clang-format)" + echo "No appropriate clang-format found (expected clang-format-14, or clang-format)" exit 1 fi From 0e5e7fddc8be7966b3b036a301e36ddbca8901fb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 5 May 2024 21:23:10 +0200 Subject: [PATCH 2/8] Apply formatting --- .../contractor/contract_excludable_graph.hpp | 14 +- .../contractor/contracted_edge_container.hpp | 73 ++--- include/customizer/cell_customizer.hpp | 3 +- include/engine/api/base_api.hpp | 13 +- include/engine/api/base_parameters.hpp | 3 +- include/engine/api/match_api.hpp | 7 +- include/engine/api/match_parameters.hpp | 4 +- include/engine/api/nearest_api.hpp | 27 +- include/engine/api/route_api.hpp | 111 ++++---- include/engine/api/route_parameters.hpp | 16 +- include/engine/api/table_api.hpp | 88 +++--- include/engine/api/table_parameters.hpp | 6 +- include/engine/api/trip_api.hpp | 8 +- include/engine/api/trip_parameters.hpp | 2 +- .../contiguous_internalmem_datafacade.hpp | 30 ++- include/engine/geospatial_query.hpp | 63 +++-- include/engine/guidance/assemble_leg.hpp | 65 +++-- .../engine/guidance/collapsing_utility.hpp | 17 +- .../guidance/postprocessing_toolkit.hpp | 14 +- include/engine/phantom_node.hpp | 8 +- include/engine/plugins/plugin_base.hpp | 70 ++--- include/engine/polyline_compressor.hpp | 3 +- .../routing_algorithms/routing_base.hpp | 6 +- .../routing_algorithms/routing_base_ch.hpp | 9 +- .../routing_algorithms/routing_base_mld.hpp | 32 ++- .../routing_algorithms/shortest_path_impl.hpp | 40 +-- include/extractor/class_data.hpp | 6 +- .../extractor/extraction_helper_functions.hpp | 5 +- include/extractor/extraction_relation.hpp | 6 +- include/extractor/files.hpp | 3 +- .../intersection/intersection_view.hpp | 24 +- include/extractor/node_restriction_map.hpp | 5 +- include/guidance/intersection_handler.hpp | 26 +- include/partitioner/bisection_graph.hpp | 19 +- include/partitioner/cell_storage.hpp | 9 +- .../partitioner/edge_based_graph_reader.hpp | 56 ++-- include/partitioner/multi_level_graph.hpp | 23 +- include/partitioner/multi_level_partition.hpp | 8 +- include/partitioner/partition_graph.hpp | 4 +- include/partitioner/remove_unconnected.hpp | 22 +- include/partitioner/reorder_first_last.hpp | 8 +- .../server/api/base_parameters_grammar.hpp | 54 ++-- .../server/api/route_parameters_grammar.hpp | 5 +- include/storage/serialization.hpp | 6 +- include/storage/shared_data_index.hpp | 8 +- include/storage/shared_datatype.hpp | 9 +- include/storage/shared_memory.hpp | 3 +- include/storage/view_factory.hpp | 6 +- include/updater/csv_file_parser.hpp | 41 +-- include/updater/source.hpp | 9 +- include/util/alias.hpp | 2 +- include/util/coordinate_calculation.hpp | 56 ++-- include/util/deallocating_vector.hpp | 2 +- include/util/dynamic_graph.hpp | 43 +-- include/util/filtered_graph.hpp | 6 +- include/util/geojson_debug_logger.hpp | 6 +- include/util/guidance/name_announcements.hpp | 18 +- include/util/indexed_data.hpp | 5 +- include/util/integer_range.hpp | 9 +- include/util/node_based_graph.hpp | 3 +- include/util/opening_hours.hpp | 15 +- include/util/query_heap.hpp | 6 +- include/util/range_table.hpp | 3 +- include/util/static_graph.hpp | 14 +- include/util/static_rtree.hpp | 8 +- include/util/std_hash.hpp | 4 +- include/util/string_util.hpp | 3 +- include/util/timed_histogram.hpp | 22 +- src/benchmarks/static_rtree.cpp | 12 +- src/contractor/graph_contractor.cpp | 32 ++- src/customize/customizer.cpp | 13 +- src/engine/api/json_factory.cpp | 13 +- src/engine/douglas_peucker.cpp | 8 +- src/engine/engine_config.cpp | 5 +- src/engine/guidance/assemble_overview.cpp | 19 +- src/engine/guidance/assemble_route.cpp | 27 +- .../guidance/collapse_scenario_detection.cpp | 3 +- src/engine/guidance/collapse_turns.cpp | 18 +- src/engine/guidance/lane_processing.cpp | 253 +++++++++--------- src/engine/guidance/post_processing.cpp | 37 +-- src/engine/guidance/verbosity_reduction.cpp | 52 ++-- src/engine/hint.cpp | 8 +- src/engine/plugins/match.cpp | 22 +- src/engine/plugins/tile.cpp | 8 +- src/engine/plugins/viaroute.cpp | 36 +-- .../alternative_path_mld.cpp | 45 ++-- .../direct_shortest_path.cpp | 19 +- .../routing_algorithms/many_to_many_mld.cpp | 70 ++--- .../routing_algorithms/map_matching.cpp | 37 +-- .../routing_algorithms/routing_base.cpp | 16 +- .../routing_algorithms/routing_base_ch.cpp | 5 +- src/engine/routing_algorithms/tile_turns.cpp | 21 +- src/extractor/edge_based_graph_factory.cpp | 88 +++--- src/extractor/extraction_containers.cpp | 67 +++-- src/extractor/extractor.cpp | 32 ++- src/extractor/extractor_callbacks.cpp | 118 ++++---- src/extractor/graph_compressor.cpp | 38 +-- .../intersection/coordinate_extractor.cpp | 174 ++++++------ .../intersection/intersection_analysis.cpp | 63 +++-- .../intersection/mergable_road_detector.cpp | 29 +- .../intersection/node_based_graph_walker.cpp | 19 +- src/extractor/location_dependent_data.cpp | 115 ++++---- src/extractor/node_based_graph_factory.cpp | 56 ++-- src/extractor/restriction_graph.cpp | 40 +-- src/extractor/scripting_environment_lua.cpp | 96 ++++--- src/extractor/turn_path_compressor.cpp | 12 +- src/extractor/turn_path_filter.cpp | 20 +- src/extractor/way_restriction_map.cpp | 7 +- src/guidance/driveway_handler.cpp | 47 ++-- src/guidance/guidance_processing.cpp | 31 +-- src/guidance/intersection_handler.cpp | 3 +- src/guidance/motorway_handler.cpp | 29 +- src/guidance/roundabout_handler.cpp | 39 +-- ...segregated_intersection_classification.cpp | 48 ++-- src/guidance/sliproad_handler.cpp | 35 ++- src/guidance/suppress_mode_handler.cpp | 29 +- src/guidance/turn_analysis.cpp | 14 +- src/guidance/turn_classification.cpp | 8 +- src/guidance/turn_discovery.cpp | 5 +- src/guidance/turn_handler.cpp | 70 +++-- src/guidance/turn_lane_augmentation.cpp | 24 +- src/guidance/turn_lane_data.cpp | 47 ++-- src/guidance/turn_lane_handler.cpp | 45 ++-- src/guidance/turn_lane_matcher.cpp | 14 +- src/partitioner/bisection_to_partition.cpp | 10 +- src/partitioner/dinic_max_flow.cpp | 33 +-- src/partitioner/inertial_flow.cpp | 80 +++--- src/partitioner/recursive_bisection.cpp | 64 +++-- src/partitioner/recursive_bisection_state.cpp | 74 ++--- src/partitioner/renumber.cpp | 16 +- src/tools/partition.cpp | 6 +- src/tools/routed.cpp | 10 +- src/updater/csv_source.cpp | 6 +- src/updater/updater.cpp | 239 +++++++++-------- src/util/coordinate_calculation.cpp | 14 +- src/util/log.cpp | 3 +- src/util/opening_hours.cpp | 10 +- src/util/timezones.cpp | 3 +- unit_tests/engine/douglas_peucker.cpp | 3 +- .../extractor/intersection_analysis_tests.cpp | 35 +-- unit_tests/extractor/restriction_graph.cpp | 31 ++- unit_tests/library/tile.cpp | 12 +- unit_tests/partitioner/bisection_graph.cpp | 3 +- unit_tests/partitioner/cell_storage.cpp | 3 +- unit_tests/partitioner/dinic.cpp | 6 +- .../partitioner/multi_level_partition.cpp | 13 +- .../partitioner/recursive_bisection.cpp | 17 +- unit_tests/partitioner/scc_integration.cpp | 15 +- unit_tests/storage/tar.cpp | 3 +- unit_tests/util/indexed_data.cpp | 10 +- unit_tests/util/static_rtree.cpp | 4 +- 151 files changed, 2374 insertions(+), 1912 deletions(-) diff --git a/include/contractor/contract_excludable_graph.hpp b/include/contractor/contract_excludable_graph.hpp index f6a34fc4a6a..75e3aceda0f 100644 --- a/include/contractor/contract_excludable_graph.hpp +++ b/include/contractor/contract_excludable_graph.hpp @@ -61,10 +61,12 @@ inline auto contractExcludableGraph(ContractorGraph contractor_graph_, // Add all non-core edges to container { auto non_core_edges = toEdges(contractor_graph); - auto new_end = - std::remove_if(non_core_edges.begin(), non_core_edges.end(), [&](const auto &edge) { - return is_shared_core[edge.source] && is_shared_core[edge.target]; - }); + auto new_end = std::remove_if(non_core_edges.begin(), + non_core_edges.end(), + [&](const auto &edge) { + return is_shared_core[edge.source] && + is_shared_core[edge.target]; + }); non_core_edges.resize(new_end - non_core_edges.begin()); edge_container.Insert(std::move(non_core_edges)); @@ -75,8 +77,8 @@ inline auto contractExcludableGraph(ContractorGraph contractor_graph_, } // Extract core graph for further contraction - shared_core_graph = contractor_graph.Filter( - [&is_shared_core](const NodeID node) { return is_shared_core[node]; }); + shared_core_graph = contractor_graph.Filter([&is_shared_core](const NodeID node) + { return is_shared_core[node]; }); } for (const auto &filter : filters) diff --git a/include/contractor/contracted_edge_container.hpp b/include/contractor/contracted_edge_container.hpp index 4dec3be6298..c7fe48fb685 100644 --- a/include/contractor/contracted_edge_container.hpp +++ b/include/contractor/contracted_edge_container.hpp @@ -89,37 +89,40 @@ struct ContractedEdgeContainer // Remove all edges that are contained in the old set of edges and set the appropriate flag. auto new_end = - std::remove_if(new_edges.begin(), new_edges.end(), [&](const QueryEdge &edge) { - // check if the new edge would be sorted before the currend old edge - // if so it is not contained yet in the set of old edges - if (edge_iter == edge_end || mergeCompare(edge, *edge_iter)) - { - return false; - } - - // find the first old edge that is equal or greater then the new edge - while (edge_iter != edge_end && mergeCompare(*edge_iter, edge)) - { - BOOST_ASSERT(flags_iter != flags.end()); - edge_iter++; - flags_iter++; - } - - // all new edges will be sorted after the old edges - if (edge_iter == edge_end) - { - return false; - } - - BOOST_ASSERT(edge_iter != edge_end); - if (mergable(edge, *edge_iter)) - { - *flags_iter = *flags_iter | flag; - return true; - } - BOOST_ASSERT(mergeCompare(edge, *edge_iter)); - return false; - }); + std::remove_if(new_edges.begin(), + new_edges.end(), + [&](const QueryEdge &edge) + { + // check if the new edge would be sorted before the currend old edge + // if so it is not contained yet in the set of old edges + if (edge_iter == edge_end || mergeCompare(edge, *edge_iter)) + { + return false; + } + + // find the first old edge that is equal or greater then the new edge + while (edge_iter != edge_end && mergeCompare(*edge_iter, edge)) + { + BOOST_ASSERT(flags_iter != flags.end()); + edge_iter++; + flags_iter++; + } + + // all new edges will be sorted after the old edges + if (edge_iter == edge_end) + { + return false; + } + + BOOST_ASSERT(edge_iter != edge_end); + if (mergable(edge, *edge_iter)) + { + *flags_iter = *flags_iter | flag; + return true; + } + BOOST_ASSERT(mergeCompare(edge, *edge_iter)); + return false; + }); // append new edges edges.insert(edges.end(), new_edges.begin(), new_end); @@ -132,10 +135,10 @@ struct ContractedEdgeContainer // enforce sorting for next merge step std::vector ordering(edges_size); std::iota(ordering.begin(), ordering.end(), 0); - tbb::parallel_sort( - ordering.begin(), ordering.end(), [&](const auto lhs_idx, const auto rhs_idx) { - return mergeCompare(edges[lhs_idx], edges[rhs_idx]); - }); + tbb::parallel_sort(ordering.begin(), + ordering.end(), + [&](const auto lhs_idx, const auto rhs_idx) + { return mergeCompare(edges[lhs_idx], edges[rhs_idx]); }); auto permutation = util::orderingToPermutation(ordering); util::inplacePermutation(edges.begin(), edges.end(), permutation); diff --git a/include/customizer/cell_customizer.hpp b/include/customizer/cell_customizer.hpp index bf625fa9b34..00d03163a7d 100644 --- a/include/customizer/cell_customizer.hpp +++ b/include/customizer/cell_customizer.hpp @@ -122,7 +122,8 @@ class CellCustomizer for (std::size_t level = 1; level < partition.GetNumberOfLevels(); ++level) { tbb::parallel_for(tbb::blocked_range(0, partition.GetNumberOfCells(level)), - [&](const tbb::blocked_range &range) { + [&](const tbb::blocked_range &range) + { auto &heap = heaps.local(); for (auto id = range.begin(), end = range.end(); id != end; ++id) { diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index a2acfcfbcf6..344f6499a55 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -40,10 +40,10 @@ class BaseAPI util::json::Array waypoints; waypoints.values.resize(parameters.coordinates.size()); - boost::range::transform( - waypoint_candidates, - waypoints.values.begin(), - [this](const PhantomNodeCandidates &candidates) { return MakeWaypoint(candidates); }); + boost::range::transform(waypoint_candidates, + waypoints.values.begin(), + [this](const PhantomNodeCandidates &candidates) + { return MakeWaypoint(candidates); }); return waypoints; } @@ -104,9 +104,8 @@ class BaseAPI std::transform(waypoint_candidates.begin(), waypoint_candidates.end(), waypoints.begin(), - [this, builder](const PhantomNodeCandidates &candidates) { - return MakeWaypoint(builder, candidates)->Finish(); - }); + [this, builder](const PhantomNodeCandidates &candidates) + { return MakeWaypoint(builder, candidates)->Finish(); }); return builder->CreateVector(waypoints); } diff --git a/include/engine/api/base_parameters.hpp b/include/engine/api/base_parameters.hpp index 56b8604ed1f..d7422566f0a 100644 --- a/include/engine/api/base_parameters.hpp +++ b/include/engine/api/base_parameters.hpp @@ -112,7 +112,8 @@ struct BaseParameters (approaches.empty() || approaches.size() == coordinates.size()) && std::all_of(bearings.begin(), bearings.end(), - [](const boost::optional &bearing_and_range) { + [](const boost::optional &bearing_and_range) + { if (bearing_and_range) { return bearing_and_range->IsValid(); diff --git a/include/engine/api/match_api.hpp b/include/engine/api/match_api.hpp index 20034e75b50..1a6172abf8e 100644 --- a/include/engine/api/match_api.hpp +++ b/include/engine/api/match_api.hpp @@ -52,9 +52,10 @@ class MatchAPI final : public RouteAPI data_version_string = fb_result.CreateString(data_timestamp); } - auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() { - return MakeTracepoints(fb_result, sub_matchings); - }); + auto response = MakeFBResponse(sub_routes, + fb_result, + [this, &fb_result, &sub_matchings]() + { return MakeTracepoints(fb_result, sub_matchings); }); if (!data_timestamp.empty()) { diff --git a/include/engine/api/match_parameters.hpp b/include/engine/api/match_parameters.hpp index 52fc64c1e82..abc93a650a2 100644 --- a/include/engine/api/match_parameters.hpp +++ b/include/engine/api/match_parameters.hpp @@ -67,7 +67,7 @@ struct MatchParameters : public RouteParameters MatchParameters(const std::vector ×tamps_, GapsType gaps_, bool tidy_, - Args &&... args_) + Args &&...args_) : MatchParameters(timestamps_, gaps_, tidy_, {}, std::forward(args_)...) { } @@ -77,7 +77,7 @@ struct MatchParameters : public RouteParameters GapsType gaps_, bool tidy_, const std::vector &waypoints_, - Args &&... args_) + Args &&...args_) : RouteParameters{std::forward(args_)..., waypoints_}, timestamps{std::move( timestamps_)}, gaps(gaps_), tidy(tidy_) diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index bc1d4e04f8a..53ea1fd4360 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -57,20 +57,20 @@ class NearestAPI final : public BaseAPI { std::vector> waypoints; waypoints.resize(phantom_nodes.front().size()); - std::transform( - phantom_nodes.front().begin(), - phantom_nodes.front().end(), - waypoints.begin(), - [this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) { - auto &phantom_node = phantom_with_distance.phantom_node; + std::transform(phantom_nodes.front().begin(), + phantom_nodes.front().end(), + waypoints.begin(), + [this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) + { + auto &phantom_node = phantom_with_distance.phantom_node; - auto node_values = MakeNodes(phantom_node); - fbresult::Uint64Pair nodes{node_values.first, node_values.second}; + auto node_values = MakeNodes(phantom_node); + fbresult::Uint64Pair nodes{node_values.first, node_values.second}; - auto waypoint = MakeWaypoint(&fb_result, {phantom_node}); - waypoint->add_nodes(&nodes); - return waypoint->Finish(); - }); + auto waypoint = MakeWaypoint(&fb_result, {phantom_node}); + waypoint->add_nodes(&nodes); + return waypoint->Finish(); + }); waypoints_vector = fb_result.CreateVector(waypoints); } @@ -94,7 +94,8 @@ class NearestAPI final : public BaseAPI std::transform(phantom_nodes.front().begin(), phantom_nodes.front().end(), waypoints.values.begin(), - [this](const PhantomNodeWithDistance &phantom_with_distance) { + [this](const PhantomNodeWithDistance &phantom_with_distance) + { auto &phantom_node = phantom_with_distance.phantom_node; auto waypoint = MakeWaypoint({phantom_node}); diff --git a/include/engine/api/route_api.hpp b/include/engine/api/route_api.hpp index 088235e5411..cbff9ce3b54 100644 --- a/include/engine/api/route_api.hpp +++ b/include/engine/api/route_api.hpp @@ -77,9 +77,10 @@ class RouteAPI : public BaseAPI } auto response = - MakeFBResponse(raw_routes, fb_result, [this, &waypoint_candidates, &fb_result]() { - return BaseAPI::MakeWaypoints(&fb_result, waypoint_candidates); - }); + MakeFBResponse(raw_routes, + fb_result, + [this, &waypoint_candidates, &fb_result]() + { return BaseAPI::MakeWaypoints(&fb_result, waypoint_candidates); }); if (!data_timestamp.empty()) { @@ -171,10 +172,15 @@ class RouteAPI : public BaseAPI } std::vector coordinates; coordinates.resize(std::distance(begin, end)); - std::transform(begin, end, coordinates.begin(), [](const Coordinate &c) { - return fbresult::Position{static_cast(util::toFloating(c.lon).__value), - static_cast(util::toFloating(c.lat).__value)}; - }); + std::transform(begin, + end, + coordinates.begin(), + [](const Coordinate &c) + { + return fbresult::Position{ + static_cast(util::toFloating(c.lon).__value), + static_cast(util::toFloating(c.lat).__value)}; + }); return builder.CreateVectorOfStructs(coordinates); } @@ -354,9 +360,8 @@ class RouteAPI : public BaseAPI std::transform(leg.steps.begin(), leg.steps.end(), legSteps.begin(), - [this, &fb_result, &leg_geometry](auto &step) { - return this->MakeFBStep(fb_result, leg_geometry, step); - }); + [this, &fb_result, &leg_geometry](auto &step) + { return this->MakeFBStep(fb_result, leg_geometry, step); }); } auto steps_vector = fb_result.CreateVector(legSteps); @@ -441,7 +446,8 @@ class RouteAPI : public BaseAPI speed = GetAnnotations(fb_result, leg_geometry, - [&prev_speed](const guidance::LegGeometry::Annotation &anno) { + [&prev_speed](const guidance::LegGeometry::Annotation &anno) + { if (anno.duration < std::numeric_limits::min()) { return prev_speed; @@ -459,37 +465,37 @@ class RouteAPI : public BaseAPI flatbuffers::Offset> duration; if (requested_annotations & RouteParameters::AnnotationsType::Duration) { - duration = GetAnnotations( - fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.duration; - }); + duration = GetAnnotations(fb_result, + leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.duration; }); } flatbuffers::Offset> distance; if (requested_annotations & RouteParameters::AnnotationsType::Distance) { - distance = GetAnnotations( - fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.distance; - }); + distance = GetAnnotations(fb_result, + leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.distance; }); } flatbuffers::Offset> weight; if (requested_annotations & RouteParameters::AnnotationsType::Weight) { - weight = GetAnnotations( - fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.weight; - }); + weight = GetAnnotations(fb_result, + leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.weight; }); } flatbuffers::Offset> datasources; if (requested_annotations & RouteParameters::AnnotationsType::Datasources) { - datasources = GetAnnotations( - fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.datasource; - }); + datasources = GetAnnotations(fb_result, + leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.datasource; }); } std::vector nodes; if (requested_annotations & RouteParameters::AnnotationsType::Nodes) @@ -653,7 +659,8 @@ class RouteAPI : public BaseAPI step.intersections.begin(), step.intersections.end(), intersections.begin(), - [&fb_result, this](const guidance::IntermediateIntersection &intersection) { + [&fb_result, this](const guidance::IntermediateIntersection &intersection) + { std::vector> lanes; if (json::detail::hasValidLanes(intersection)) { @@ -681,11 +688,11 @@ class RouteAPI : public BaseAPI auto bearings_vector = fb_result.CreateVector(intersection.bearings); std::vector> classes; classes.resize(intersection.classes.size()); - std::transform( - intersection.classes.begin(), - intersection.classes.end(), - classes.begin(), - [&fb_result](const std::string &cls) { return fb_result.CreateString(cls); }); + std::transform(intersection.classes.begin(), + intersection.classes.end(), + classes.begin(), + [&fb_result](const std::string &cls) + { return fb_result.CreateString(cls); }); auto classes_vector = fb_result.CreateVector(classes); auto entry_vector = fb_result.CreateVector(intersection.entry); @@ -720,9 +727,10 @@ class RouteAPI : public BaseAPI std::vector step_geometries; const auto total_step_count = - std::accumulate(legs.begin(), legs.end(), 0, [](const auto &v, const auto &leg) { - return v + leg.steps.size(); - }); + std::accumulate(legs.begin(), + legs.end(), + 0, + [](const auto &v, const auto &leg) { return v + leg.steps.size(); }); step_geometries.reserve(total_step_count); for (const auto idx : util::irange(0UL, legs.size())) @@ -733,7 +741,8 @@ class RouteAPI : public BaseAPI legs[idx].steps.begin(), legs[idx].steps.end(), std::back_inserter(step_geometries), - [this, &leg_geometry](const guidance::RouteStep &step) { + [this, &leg_geometry](const guidance::RouteStep &step) + { if (parameters.geometries == RouteParameters::GeometriesType::Polyline) { return static_cast(json::makePolyline<100000>( @@ -778,7 +787,9 @@ class RouteAPI : public BaseAPI { double prev_speed = 0; annotation.values["speed"] = GetAnnotations( - leg_geometry, [&prev_speed](const guidance::LegGeometry::Annotation &anno) { + leg_geometry, + [&prev_speed](const guidance::LegGeometry::Annotation &anno) + { if (anno.duration < std::numeric_limits::min()) { return prev_speed; @@ -794,17 +805,17 @@ class RouteAPI : public BaseAPI if (requested_annotations & RouteParameters::AnnotationsType::Duration) { - annotation.values["duration"] = GetAnnotations( - leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.duration; - }); + annotation.values["duration"] = + GetAnnotations(leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.duration; }); } if (requested_annotations & RouteParameters::AnnotationsType::Distance) { - annotation.values["distance"] = GetAnnotations( - leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.distance; - }); + annotation.values["distance"] = + GetAnnotations(leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.distance; }); } if (requested_annotations & RouteParameters::AnnotationsType::Weight) { @@ -814,10 +825,10 @@ class RouteAPI : public BaseAPI } if (requested_annotations & RouteParameters::AnnotationsType::Datasources) { - annotation.values["datasources"] = GetAnnotations( - leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { - return anno.datasource; - }); + annotation.values["datasources"] = + GetAnnotations(leg_geometry, + [](const guidance::LegGeometry::Annotation &anno) + { return anno.datasource; }); } if (requested_annotations & RouteParameters::AnnotationsType::Nodes) { diff --git a/include/engine/api/route_parameters.hpp b/include/engine/api/route_parameters.hpp index 3593ecf5ba5..267058a46bc 100644 --- a/include/engine/api/route_parameters.hpp +++ b/include/engine/api/route_parameters.hpp @@ -83,7 +83,7 @@ struct RouteParameters : public BaseParameters const GeometriesType geometries_, const OverviewType overview_, const boost::optional continue_straight_, - Args &&... args_) + Args &&...args_) // Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one // below. : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, @@ -101,7 +101,7 @@ struct RouteParameters : public BaseParameters const GeometriesType geometries_, const OverviewType overview_, const boost::optional continue_straight_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, @@ -119,7 +119,7 @@ struct RouteParameters : public BaseParameters const GeometriesType geometries_, const OverviewType overview_, const boost::optional continue_straight_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_ != AnnotationsType::None}, annotations_type{annotations_}, @@ -137,7 +137,7 @@ struct RouteParameters : public BaseParameters const OverviewType overview_, const boost::optional continue_straight_, std::vector waypoints_, - const Args &&... args_) + const Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, @@ -155,7 +155,7 @@ struct RouteParameters : public BaseParameters const OverviewType overview_, const boost::optional continue_straight_, std::vector waypoints_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_ != AnnotationsType::None}, @@ -180,9 +180,9 @@ struct RouteParameters : public BaseParameters const auto coordinates_ok = coordinates.size() >= 2; const auto base_params_ok = BaseParameters::IsValid(); const auto valid_waypoints = - std::all_of(waypoints.begin(), waypoints.end(), [this](const auto &w) { - return w < coordinates.size(); - }); + std::all_of(waypoints.begin(), + waypoints.end(), + [this](const auto &w) { return w < coordinates.size(); }); return coordinates_ok && base_params_ok && valid_waypoints; } }; diff --git a/include/engine/api/table_api.hpp b/include/engine/api/table_api.hpp index af4e692e35f..20d6a4a23f4 100644 --- a/include/engine/api/table_api.hpp +++ b/include/engine/api/table_api.hpp @@ -245,9 +245,8 @@ class TableAPI final : public BaseAPI boost::range::transform(candidates, std::back_inserter(waypoints), - [this, &builder](const PhantomNodeCandidates &candidates) { - return BaseAPI::MakeWaypoint(&builder, candidates)->Finish(); - }); + [this, &builder](const PhantomNodeCandidates &candidates) + { return BaseAPI::MakeWaypoint(&builder, candidates)->Finish(); }); return builder.CreateVector(waypoints); } @@ -261,7 +260,8 @@ class TableAPI final : public BaseAPI boost::range::transform( indices, std::back_inserter(waypoints), - [this, &builder, &candidates](const std::size_t idx) { + [this, &builder, &candidates](const std::size_t idx) + { BOOST_ASSERT(idx < candidates.size()); return BaseAPI::MakeWaypoint(&builder, candidates[idx])->Finish(); }); @@ -274,14 +274,17 @@ class TableAPI final : public BaseAPI { std::vector distance_table; distance_table.resize(values.size()); - std::transform( - values.begin(), values.end(), distance_table.begin(), [](const EdgeDuration duration) { - if (duration == MAXIMAL_EDGE_DURATION) - { - return 0.; - } - return from_alias(duration) / 10.; - }); + std::transform(values.begin(), + values.end(), + distance_table.begin(), + [](const EdgeDuration duration) + { + if (duration == MAXIMAL_EDGE_DURATION) + { + return 0.; + } + return from_alias(duration) / 10.; + }); return builder.CreateVector(distance_table); } @@ -291,14 +294,17 @@ class TableAPI final : public BaseAPI { std::vector duration_table; duration_table.resize(values.size()); - std::transform( - values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) { - if (distance == INVALID_EDGE_DISTANCE) - { - return 0.; - } - return std::round(from_alias(distance) * 10) / 10.; - }); + std::transform(values.begin(), + values.end(), + duration_table.begin(), + [](const EdgeDistance distance) + { + if (distance == INVALID_EDGE_DISTANCE) + { + return 0.; + } + return std::round(from_alias(distance) * 10) / 10.; + }); return builder.CreateVector(duration_table); } @@ -308,11 +314,13 @@ class TableAPI final : public BaseAPI { std::vector fb_table; fb_table.reserve(fallback_speed_cells.size()); - std::for_each( - fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) { - fb_table.push_back(cell.row); - fb_table.push_back(cell.column); - }); + std::for_each(fallback_speed_cells.begin(), + fallback_speed_cells.end(), + [&](const auto &cell) + { + fb_table.push_back(cell.row); + fb_table.push_back(cell.column); + }); return builder.CreateVector(fb_table); } @@ -325,9 +333,8 @@ class TableAPI final : public BaseAPI boost::range::transform(candidates, std::back_inserter(json_waypoints.values), - [this](const PhantomNodeCandidates &candidates) { - return BaseAPI::MakeWaypoint(candidates); - }); + [this](const PhantomNodeCandidates &candidates) + { return BaseAPI::MakeWaypoint(candidates); }); return json_waypoints; } @@ -338,7 +345,8 @@ class TableAPI final : public BaseAPI json_waypoints.values.reserve(indices.size()); boost::range::transform(indices, std::back_inserter(json_waypoints.values), - [this, &candidates](const std::size_t idx) { + [this, &candidates](const std::size_t idx) + { BOOST_ASSERT(idx < candidates.size()); return BaseAPI::MakeWaypoint(candidates[idx]); }); @@ -359,7 +367,8 @@ class TableAPI final : public BaseAPI std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), - [](const EdgeDuration duration) { + [](const EdgeDuration duration) + { if (duration == MAXIMAL_EDGE_DURATION) { return util::json::Value(util::json::Null()); @@ -387,7 +396,8 @@ class TableAPI final : public BaseAPI std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), - [](const EdgeDistance distance) { + [](const EdgeDistance distance) + { if (distance == INVALID_EDGE_DISTANCE) { return util::json::Value(util::json::Null()); @@ -405,13 +415,15 @@ class TableAPI final : public BaseAPI MakeEstimatesTable(const std::vector &fallback_speed_cells) const { util::json::Array json_table; - std::for_each( - fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) { - util::json::Array row; - row.values.push_back(util::json::Number(cell.row)); - row.values.push_back(util::json::Number(cell.column)); - json_table.values.push_back(std::move(row)); - }); + std::for_each(fallback_speed_cells.begin(), + fallback_speed_cells.end(), + [&](const auto &cell) + { + util::json::Array row; + row.values.push_back(util::json::Number(cell.row)); + row.values.push_back(util::json::Number(cell.column)); + json_table.values.push_back(std::move(row)); + }); return json_table; } diff --git a/include/engine/api/table_parameters.hpp b/include/engine/api/table_parameters.hpp index be65b9a7792..bbc76b6b93d 100644 --- a/include/engine/api/table_parameters.hpp +++ b/include/engine/api/table_parameters.hpp @@ -81,7 +81,7 @@ struct TableParameters : public BaseParameters template TableParameters(std::vector sources_, std::vector destinations_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, sources{std::move(sources_)}, destinations{std::move(destinations_)} { @@ -91,7 +91,7 @@ struct TableParameters : public BaseParameters TableParameters(std::vector sources_, std::vector destinations_, const AnnotationsType annotations_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, sources{std::move(sources_)}, destinations{std::move(destinations_)}, annotations{annotations_} { @@ -104,7 +104,7 @@ struct TableParameters : public BaseParameters double fallback_speed_, FallbackCoordinateType fallback_coordinate_type_, double scale_factor_, - Args &&... args_) + Args &&...args_) : BaseParameters{std::forward(args_)...}, sources{std::move(sources_)}, destinations{std::move(destinations_)}, fallback_speed{fallback_speed_}, fallback_coordinate_type{fallback_coordinate_type_}, annotations{annotations_}, diff --git a/include/engine/api/trip_api.hpp b/include/engine/api/trip_api.hpp index f15d2142288..d7a4ab69c06 100644 --- a/include/engine/api/trip_api.hpp +++ b/include/engine/api/trip_api.hpp @@ -50,10 +50,10 @@ class TripAPI final : public RouteAPI data_version_string = fb_result.CreateString(data_timestamp); } - auto response = - MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &candidates]() { - return MakeWaypoints(fb_result, sub_trips, candidates); - }); + auto response = MakeFBResponse(sub_routes, + fb_result, + [this, &fb_result, &sub_trips, &candidates]() + { return MakeWaypoints(fb_result, sub_trips, candidates); }); if (!data_timestamp.empty()) { diff --git a/include/engine/api/trip_parameters.hpp b/include/engine/api/trip_parameters.hpp index 6cfffd295a3..7ad785ac097 100644 --- a/include/engine/api/trip_parameters.hpp +++ b/include/engine/api/trip_parameters.hpp @@ -60,7 +60,7 @@ struct TripParameters : public RouteParameters TripParameters(SourceType source_, DestinationType destination_, bool roundtrip_, - Args &&... args_) + Args &&...args_) : RouteParameters{std::forward(args_)...}, source{source_}, destination{destination_}, roundtrip{roundtrip_} { diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 0e990278500..9b35989e1a2 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -440,9 +440,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto indexes = extractor::getClassIndexes(class_data); std::vector classes(indexes.size()); - std::transform(indexes.begin(), indexes.end(), classes.begin(), [this](const auto index) { - return m_profile_properties->GetClassName(index); - }); + std::transform(indexes.begin(), + indexes.end(), + classes.begin(), + [this](const auto index) + { return m_profile_properties->GetClassName(index); }); return classes; } @@ -600,15 +602,19 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade auto found_range = std::equal_range( m_maneuver_overrides.begin(), m_maneuver_overrides.end(), edge_based_node_id, Comp{}); - std::for_each(found_range.first, found_range.second, [&](const auto &override) { - std::vector sequence( - m_maneuver_override_node_sequences.begin() + override.node_sequence_offset_begin, - m_maneuver_override_node_sequences.begin() + override.node_sequence_offset_end); - results.push_back(extractor::ManeuverOverride{std::move(sequence), - override.instruction_node, - override.override_type, - override.direction}); - }); + std::for_each(found_range.first, + found_range.second, + [&](const auto &override) + { + std::vector sequence(m_maneuver_override_node_sequences.begin() + + override.node_sequence_offset_begin, + m_maneuver_override_node_sequences.begin() + + override.node_sequence_offset_end); + results.push_back(extractor::ManeuverOverride{std::move(sequence), + override.instruction_node, + override.override_type, + override.direction}); + }); return results; } }; diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index f25122afbbf..b8e43b6372f 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -60,7 +60,8 @@ template class GeospatialQuery auto results = rtree.Nearest( input_coordinate, [this, approach, &input_coordinate, &bearing_with_range, &use_all_edges]( - const CandidateSegment &segment) { + const CandidateSegment &segment) + { auto valid = CheckSegmentExclude(segment) && CheckApproach(input_coordinate, segment, approach) && (use_all_edges ? HasValidEdge(segment, *use_all_edges) @@ -70,7 +71,8 @@ template class GeospatialQuery return valid; }, [this, &max_distance, &max_results, input_coordinate](const std::size_t num_results, - const CandidateSegment &segment) { + const CandidateSegment &segment) + { return (max_results && num_results >= *max_results) || (max_distance && max_distance != -1.0 && CheckSegmentDistance(input_coordinate, segment, *max_distance)); @@ -107,7 +109,8 @@ template class GeospatialQuery &big_component_coord, &big_component_distance, &use_all_edges, - &bearing_with_range](const CandidateSegment &segment) { + &bearing_with_range](const CandidateSegment &segment) + { auto is_big_component = !IsTinyComponent(segment); auto not_nearest = has_nearest && segment.fixed_projected_coordinate != nearest_coord; @@ -159,7 +162,8 @@ template class GeospatialQuery return use_candidate; }, [this, &has_big_component, &max_distance, input_coordinate, &big_component_distance]( - const std::size_t /*num_results*/, const CandidateSegment &segment) { + const std::size_t /*num_results*/, const CandidateSegment &segment) + { auto distance = GetSegmentDistance(input_coordinate, segment); auto further_than_big_component = distance > big_component_distance; auto no_more_candidates = has_big_component && further_than_big_component; @@ -190,13 +194,17 @@ template class GeospatialQuery PhantomNodeCandidates nearest_phantoms; PhantomNodeCandidates big_component_phantoms; - const auto add_to_candidates = [this, &input_coordinate](PhantomNodeCandidates &candidates, - const EdgeData data) { + const auto add_to_candidates = + [this, &input_coordinate](PhantomNodeCandidates &candidates, const EdgeData data) + { auto candidate_it = - std::find_if(candidates.begin(), candidates.end(), [&](const PhantomNode &node) { - return data.forward_segment_id.id == node.forward_segment_id.id && - data.reverse_segment_id.id == node.reverse_segment_id.id; - }); + std::find_if(candidates.begin(), + candidates.end(), + [&](const PhantomNode &node) + { + return data.forward_segment_id.id == node.forward_segment_id.id && + data.reverse_segment_id.id == node.reverse_segment_id.id; + }); if (candidate_it == candidates.end()) { // First candidate from this segment @@ -259,17 +267,20 @@ template class GeospatialQuery } }; - std::for_each(results.begin(), results.end(), [&](const CandidateSegment &segment) { - if (segment.fixed_projected_coordinate == nearest_coord) - { - add_to_candidates(nearest_phantoms, segment.data); - } - else - { - // Can only be from a big component for the alternative candidates - add_to_candidates(big_component_phantoms, segment.data); - } - }); + std::for_each(results.begin(), + results.end(), + [&](const CandidateSegment &segment) + { + if (segment.fixed_projected_coordinate == nearest_coord) + { + add_to_candidates(nearest_phantoms, segment.data); + } + else + { + // Can only be from a big component for the alternative candidates + add_to_candidates(big_component_phantoms, segment.data); + } + }); return std::make_pair(std::move(nearest_phantoms), std::move(big_component_phantoms)); } @@ -281,9 +292,8 @@ template class GeospatialQuery std::transform(results.begin(), results.end(), distance_and_phantoms.begin(), - [this, &input_coordinate](const CandidateSegment &segment) { - return MakePhantomNode(input_coordinate, segment.data); - }); + [this, &input_coordinate](const CandidateSegment &segment) + { return MakePhantomNode(input_coordinate, segment.data); }); return distance_and_phantoms; } @@ -400,9 +410,8 @@ template class GeospatialQuery } // check phantom node segments validity - auto areSegmentsValid = [](auto first, auto last) -> bool { - return std::find(first, last, INVALID_SEGMENT_WEIGHT) == last; - }; + auto areSegmentsValid = [](auto first, auto last) -> bool + { return std::find(first, last, INVALID_SEGMENT_WEIGHT) == last; }; bool is_forward_valid_source = areSegmentsValid(forward_weights.begin(), forward_weights.end()); bool is_forward_valid_target = areSegmentsValid( diff --git a/include/engine/guidance/assemble_leg.hpp b/include/engine/guidance/assemble_leg.hpp index 31dfc702736..1906ae50f70 100644 --- a/include/engine/guidance/assemble_leg.hpp +++ b/include/engine/guidance/assemble_leg.hpp @@ -43,7 +43,8 @@ std::array summarizeRoute(const datafacade::BaseDa const bool target_traversed_in_reverse) { // merges segments with same name id - const auto collapse_segments = [](std::vector &segments) { + const auto collapse_segments = [](std::vector &segments) + { auto out = segments.begin(); auto end = segments.end(); @@ -75,7 +76,8 @@ std::array summarizeRoute(const datafacade::BaseDa std::transform(route_data.begin(), route_data.end(), segments.begin(), - [&index, &facade](const PathData &point) { + [&index, &facade](const PathData &point) + { return NamedSegment{point.duration_until_turn, index++, facade.GetNameIndex(point.from_edge_based_node)}; @@ -87,33 +89,37 @@ std::array summarizeRoute(const datafacade::BaseDa if (target_duration > EdgeDuration{1}) segments.push_back({target_duration, index++, facade.GetNameIndex(target_node_id)}); // this makes sure that the segment with the lowest position comes first - std::sort( - segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs) { - return lhs.name_id < rhs.name_id || - (lhs.name_id == rhs.name_id && lhs.position < rhs.position); - }); + std::sort(segments.begin(), + segments.end(), + [](const NamedSegment &lhs, const NamedSegment &rhs) + { + return lhs.name_id < rhs.name_id || + (lhs.name_id == rhs.name_id && lhs.position < rhs.position); + }); auto new_end = collapse_segments(segments); segments.resize(new_end - segments.begin()); // Filter out segments with an empty name (name_id == 0) - new_end = std::remove_if(segments.begin(), segments.end(), [](const NamedSegment &segment) { - return segment.name_id == 0; - }); + new_end = std::remove_if(segments.begin(), + segments.end(), + [](const NamedSegment &segment) { return segment.name_id == 0; }); segments.resize(new_end - segments.begin()); // sort descending - std::sort( - segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs) { - return lhs.duration > rhs.duration || - (lhs.duration == rhs.duration && lhs.position < rhs.position); - }); + std::sort(segments.begin(), + segments.end(), + [](const NamedSegment &lhs, const NamedSegment &rhs) + { + return lhs.duration > rhs.duration || + (lhs.duration == rhs.duration && lhs.position < rhs.position); + }); // make sure the segments are sorted by position segments.resize(std::min(segments.size(), SegmentNumber)); - std::sort( - segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs) { - return lhs.position < rhs.position; - }); + std::sort(segments.begin(), + segments.end(), + [](const NamedSegment &lhs, const NamedSegment &rhs) + { return lhs.position < rhs.position; }); std::array summary; std::fill(summary.begin(), summary.end(), EMPTY_NAMEID); @@ -138,7 +144,8 @@ inline std::string assembleSummary(const datafacade::BaseDataFacade &facade, // transform a name_id into a string containing either the name, or -if the name is empty- // the reference. - const auto name_id_to_string = [&](const NameID name_id) { + const auto name_id_to_string = [&](const NameID name_id) + { const auto name = facade.GetNameForID(name_id); if (!name.empty()) return std::string(name); @@ -178,14 +185,16 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade, const auto target_weight = (target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight); - auto duration = std::accumulate( - route_data.begin(), route_data.end(), 0, [](const double sum, const PathData &data) { - return sum + from_alias(data.duration_until_turn); - }); - auto weight = std::accumulate( - route_data.begin(), route_data.end(), 0, [](const double sum, const PathData &data) { - return sum + from_alias(data.weight_until_turn); - }); + auto duration = std::accumulate(route_data.begin(), + route_data.end(), + 0, + [](const double sum, const PathData &data) + { return sum + from_alias(data.duration_until_turn); }); + auto weight = std::accumulate(route_data.begin(), + route_data.end(), + 0, + [](const double sum, const PathData &data) + { return sum + from_alias(data.weight_until_turn); }); // s // | diff --git a/include/engine/guidance/collapsing_utility.hpp b/include/engine/guidance/collapsing_utility.hpp index 8d990e1943a..c0a0121981c 100644 --- a/include/engine/guidance/collapsing_utility.hpp +++ b/include/engine/guidance/collapsing_utility.hpp @@ -122,9 +122,8 @@ inline bool haveSameMode(const RouteStep &first, const RouteStep &second, const // alias for readability inline bool haveSameName(const RouteStep &lhs, const RouteStep &rhs) { - const auto has_name_or_ref = [](auto const &step) { - return !step.name.empty() || !step.ref.empty(); - }; + const auto has_name_or_ref = [](auto const &step) + { return !step.name.empty() || !step.ref.empty(); }; // make sure empty is not involved if (!has_name_or_ref(lhs) || !has_name_or_ref(rhs)) @@ -151,12 +150,14 @@ inline bool haveSameName(const RouteStep &lhs, const RouteStep &rhs) // alias for readability, both turn right | left inline bool areSameSide(const RouteStep &lhs, const RouteStep &rhs) { - const auto is_left = [](const RouteStep &step) { + const auto is_left = [](const RouteStep &step) + { return hasModifier(step, osrm::guidance::DirectionModifier::Straight) || hasLeftModifier(step.maneuver.instruction); }; - const auto is_right = [](const RouteStep &step) { + const auto is_right = [](const RouteStep &step) + { return hasModifier(step, osrm::guidance::DirectionModifier::Straight) || hasRightModifier(step.maneuver.instruction); }; @@ -174,7 +175,8 @@ inline std::vector removeNoTurnInstructions(std::vector st // Two valid NO_TURNs exist in each leg in the form of Depart/Arrive // keep valid instructions - const auto not_is_valid = [](const RouteStep &step) { + const auto not_is_valid = [](const RouteStep &step) + { return step.maneuver.instruction == osrm::guidance::TurnInstruction::NO_TURN() && step.maneuver.waypoint_type == WaypointType::None; }; @@ -225,7 +227,8 @@ inline double totalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_ inline bool bearingsAreReversed(const double bearing_in, const double bearing_out) { // Nearly perfectly reversed angles have a difference close to 180 degrees (straight) - const double left_turn_angle = [&]() { + const double left_turn_angle = [&]() + { if (0 <= bearing_out && bearing_out <= bearing_in) return bearing_in - bearing_out; return bearing_in + 360 - bearing_out; diff --git a/include/engine/guidance/postprocessing_toolkit.hpp b/include/engine/guidance/postprocessing_toolkit.hpp index f861ed3c359..0dda0e4e513 100644 --- a/include/engine/guidance/postprocessing_toolkit.hpp +++ b/include/engine/guidance/postprocessing_toolkit.hpp @@ -20,14 +20,16 @@ template inline Fn forEachRoundabout(Iter first, It { while (first != last) { - const auto enter = std::find_if(first, last, [](const RouteStep &step) { - return entersRoundabout(step.maneuver.instruction); - }); + const auto enter = std::find_if(first, + last, + [](const RouteStep &step) + { return entersRoundabout(step.maneuver.instruction); }); // enter has to come before leave, otherwise: faulty data / partial roundabout, skip those - const auto leave = std::find_if(enter, last, [](const RouteStep &step) { - return leavesRoundabout(step.maneuver.instruction); - }); + const auto leave = std::find_if(enter, + last, + [](const RouteStep &step) + { return leavesRoundabout(step.maneuver.instruction); }); // No roundabouts, or partial one (like start / end inside a roundabout) if (enter == last || leave == last) diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 19bdde520ca..c7d0c0bf2a3 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -259,10 +259,10 @@ inline util::Coordinate candidatesInputLocation(const PhantomNodeCandidates &can inline bool candidatesHaveComponent(const PhantomNodeCandidates &candidates, uint32_t component_id) { - return std::any_of( - candidates.begin(), candidates.end(), [component_id](const PhantomNode &node) { - return node.component.id == component_id; - }); + return std::any_of(candidates.begin(), + candidates.end(), + [component_id](const PhantomNode &node) + { return node.component.id == component_id; }); } struct PhantomEndpoints diff --git a/include/engine/plugins/plugin_base.hpp b/include/engine/plugins/plugin_base.hpp index 37545689755..5fb0ffc58b8 100644 --- a/include/engine/plugins/plugin_base.hpp +++ b/include/engine/plugins/plugin_base.hpp @@ -33,10 +33,10 @@ class BasePlugin bool CheckAllCoordinates(const std::vector &coordinates) const { - return !std::any_of( - std::begin(coordinates), std::end(coordinates), [](const util::Coordinate coordinate) { - return !coordinate.IsValid(); - }); + return !std::any_of(std::begin(coordinates), + std::end(coordinates), + [](const util::Coordinate coordinate) + { return !coordinate.IsValid(); }); } bool CheckAlgorithms(const api::BaseParameters ¶ms, @@ -105,45 +105,45 @@ class BasePlugin { // are all phantoms from a tiny cc? const auto all_in_same_tiny_component = - [](const std::vector &alts_list) { - return std::any_of( - alts_list.front().first.begin(), - alts_list.front().first.end(), - // For each of the first possible phantoms, check if all other - // positions in the list have a phantom from the same small component. - [&](const PhantomNode &phantom) { - if (!phantom.component.is_tiny) - { - return false; - } - const auto component_id = phantom.component.id; - return std::all_of( - std::next(alts_list.begin()), - std::end(alts_list), - [component_id](const PhantomCandidateAlternatives &alternatives) { - return candidatesHaveComponent(alternatives.first, component_id); - }); - }); - }; + [](const std::vector &alts_list) + { + return std::any_of( + alts_list.front().first.begin(), + alts_list.front().first.end(), + // For each of the first possible phantoms, check if all other + // positions in the list have a phantom from the same small component. + [&](const PhantomNode &phantom) + { + if (!phantom.component.is_tiny) + { + return false; + } + const auto component_id = phantom.component.id; + return std::all_of( + std::next(alts_list.begin()), + std::end(alts_list), + [component_id](const PhantomCandidateAlternatives &alternatives) + { return candidatesHaveComponent(alternatives.first, component_id); }); + }); + }; // Move the alternative into the final list - const auto fallback_to_big_component = [](PhantomCandidateAlternatives &alternatives) { + const auto fallback_to_big_component = [](PhantomCandidateAlternatives &alternatives) + { auto no_big_alternative = alternatives.second.empty(); return no_big_alternative ? std::move(alternatives.first) : std::move(alternatives.second); }; // Move the alternative into the final list - const auto use_closed_phantom = [](PhantomCandidateAlternatives &alternatives) { - return std::move(alternatives.first); - }; + const auto use_closed_phantom = [](PhantomCandidateAlternatives &alternatives) + { return std::move(alternatives.first); }; const auto no_alternatives = std::all_of(alternatives_list.begin(), alternatives_list.end(), - [](const PhantomCandidateAlternatives &alternatives) { - return alternatives.second.empty(); - }); + [](const PhantomCandidateAlternatives &alternatives) + { return alternatives.second.empty(); }); std::vector snapped_phantoms; snapped_phantoms.reserve(alternatives_list.size()); @@ -313,12 +313,12 @@ class BasePlugin alternatives.end(), coordinates.begin(), coordinates.end(), - [](const auto &candidates_pair, const auto &coordinate) { + [](const auto &candidates_pair, const auto &coordinate) + { return std::any_of(candidates_pair.first.begin(), candidates_pair.first.end(), - [&](const auto &phantom) { - return phantom.input_location == coordinate; - }); + [&](const auto &phantom) + { return phantom.input_location == coordinate; }); }); std::size_t missing_index = std::distance(alternatives.begin(), mismatch.first); return std::string("Could not find a matching segment for coordinate ") + diff --git a/include/engine/polyline_compressor.hpp b/include/engine/polyline_compressor.hpp index f313ccfe54e..b2a50576449 100644 --- a/include/engine/polyline_compressor.hpp +++ b/include/engine/polyline_compressor.hpp @@ -39,7 +39,8 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter begin, end, [&delta_numbers, ¤t_lat, ¤t_lon, coordinate_to_polyline]( - const util::Coordinate loc) { + const util::Coordinate loc) + { const int lat_diff = std::round(static_cast(loc.lat) * coordinate_to_polyline) - current_lat; const int lon_diff = diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 4d56f86d61f..15c5ea55ad4 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -190,8 +190,10 @@ void annotatePath(const FacadeT &facade, std::vector duration_vector; std::vector datasource_vector; - const auto get_segment_geometry = [&](const auto geometry_index) { - const auto copy = [](auto &vector, const auto range) { + const auto get_segment_geometry = [&](const auto geometry_index) + { + const auto copy = [](auto &vector, const auto range) + { vector.resize(range.size()); std::copy(range.begin(), range.end(), vector.begin()); }; diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 7ac0530d861..2714e025b96 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -294,9 +294,9 @@ EdgeDistance calculateEBGNodeAnnotations(const DataFacade &facade, // Look for an edge on the forward CH graph (.forward) EdgeID smaller_edge_id = - facade.FindSmallestEdge(std::get<0>(edge), std::get<1>(edge), [](const auto &data) { - return data.forward; - }); + facade.FindSmallestEdge(std::get<0>(edge), + std::get<1>(edge), + [](const auto &data) { return data.forward; }); // If we didn't find one there, the we might be looking at a part of the path that // was found using the backward search. Here, we flip the node order (.second, @@ -381,7 +381,8 @@ void unpackPath(const FacadeT &facade, unpackPath(facade, packed_path_begin, packed_path_end, - [&](std::pair &edge, const auto &edge_id) { + [&](std::pair &edge, const auto &edge_id) + { BOOST_ASSERT(edge.first == unpacked_nodes.back()); unpacked_nodes.push_back(edge.second); unpacked_edges.push_back(edge_id); diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 39e93c5df3c..c577c3be3b2 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -30,7 +30,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, const PhantomNode &source, const PhantomNode &target) { - auto level = [&partition, node](const SegmentID &source, const SegmentID &target) { + auto level = [&partition, node](const SegmentID &source, const SegmentID &target) + { if (source.enabled && target.enabled) return partition.GetQueryLevel(source.id, target.id, node); return INVALID_LEVEL_ID; @@ -59,7 +60,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, endpoint_candidates.source_phantoms.begin(), endpoint_candidates.source_phantoms.end(), INVALID_LEVEL_ID, - [&](LevelID current_level, const PhantomNode &source) { + [&](LevelID current_level, const PhantomNode &source) + { return std::min( current_level, getNodeQueryLevel(partition, node, source, endpoint_candidates.target_phantom)); @@ -76,7 +78,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, endpoint_candidates.source_phantoms.begin(), endpoint_candidates.source_phantoms.end(), INVALID_LEVEL_ID, - [&](LevelID level_1, const PhantomNode &source) { + [&](LevelID level_1, const PhantomNode &source) + { return std::min( level_1, std::accumulate(endpoint_candidates.target_phantoms.begin(), @@ -119,7 +122,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, const NodeID node, const PhantomNodeCandidates &candidates) { - auto highest_different_level = [&partition, node](const SegmentID &segment) { + auto highest_different_level = [&partition, node](const SegmentID &segment) + { return segment.enabled ? partition.GetHighestDifferentLevel(segment.id, node) : INVALID_LEVEL_ID; }; @@ -128,7 +132,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, std::accumulate(candidates.begin(), candidates.end(), INVALID_LEVEL_ID, - [&](LevelID current_level, const PhantomNode &phantom_node) { + [&](LevelID current_level, const PhantomNode &phantom_node) + { auto highest_level = std::min(highest_different_level(phantom_node.forward_segment_id), highest_different_level(phantom_node.reverse_segment_id)); @@ -151,9 +156,11 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition, // This is equivalent to min_{∀ source, target} partition.GetQueryLevel(source, node, target) auto init = getNodeQueryLevel(partition, node, candidates_list[phantom_index]); auto result = std::accumulate( - phantom_indices.begin(), phantom_indices.end(), init, [&](LevelID level, size_t index) { - return std::min(level, getNodeQueryLevel(partition, node, candidates_list[index])); - }); + phantom_indices.begin(), + phantom_indices.end(), + init, + [&](LevelID level, size_t index) + { return std::min(level, getNodeQueryLevel(partition, node, candidates_list[index])); }); return result; } } // namespace @@ -266,7 +273,7 @@ template void relaxOutgoingEdges(const DataFacade &facade, typename SearchEngineData::QueryHeap &forward_heap, const typename SearchEngineData::QueryHeap::HeapNode &heapNode, - const Args &... args) + const Args &...args) { const auto &partition = facade.GetMultiLevelPartition(); const auto &cells = facade.GetCellStorage(); @@ -384,7 +391,7 @@ void routingStep(const DataFacade &facade, EdgeWeight &path_upper_bound, const std::vector &force_loop_forward_nodes, const std::vector &force_loop_reverse_nodes, - const Args &... args) + const Args &...args) { const auto heapNode = forward_heap.DeleteMinGetHeapNode(); const auto weight = heapNode.weight; @@ -434,7 +441,7 @@ UnpackedPath search(SearchEngineData &engine_working_data, const std::vector &force_loop_forward_nodes, const std::vector &force_loop_reverse_nodes, EdgeWeight weight_upper_bound, - const Args &... args) + const Args &...args) { if (forward_heap.Empty() || reverse_heap.Empty()) { @@ -601,7 +608,8 @@ void unpackPath(const FacadeT &facade, util::for_each_pair( packed_path_begin, packed_path_end, - [&facade, &unpacked_nodes, &unpacked_edges](const auto from, const auto to) { + [&facade, &unpacked_nodes, &unpacked_edges](const auto from, const auto to) + { unpacked_nodes.push_back(to); unpacked_edges.push_back(facade.FindEdge(from, to)); }); diff --git a/include/engine/routing_algorithms/shortest_path_impl.hpp b/include/engine/routing_algorithms/shortest_path_impl.hpp index f23ae76542e..a1e2c786c2d 100644 --- a/include/engine/routing_algorithms/shortest_path_impl.hpp +++ b/include/engine/routing_algorithms/shortest_path_impl.hpp @@ -248,7 +248,8 @@ constructRouteResult(const DataFacade &facade, auto source_it = std::find_if(source_candidates.begin(), source_candidates.end(), - [&start_node](const auto &source_phantom) { + [&start_node](const auto &source_phantom) + { return (start_node == source_phantom.forward_segment_id.id || start_node == source_phantom.reverse_segment_id.id); }); @@ -257,7 +258,8 @@ constructRouteResult(const DataFacade &facade, auto target_it = std::find_if(target_candidates.begin(), target_candidates.end(), - [&end_node](const auto &target_phantom) { + [&end_node](const auto &target_phantom) + { return (end_node == target_phantom.forward_segment_id.id || end_node == target_phantom.reverse_segment_id.id); }); @@ -466,16 +468,16 @@ struct route_state last.total_weight_to_forward.resize(init_candidates.size(), {0}); last.total_weight_to_reverse.resize(init_candidates.size(), {0}); // Initialize routability from source validity. - std::transform( - init_candidates.begin(), - init_candidates.end(), - std::back_inserter(last.reached_forward_node_target), - [](const PhantomNode &phantom_node) { return phantom_node.IsValidForwardSource(); }); - std::transform( - init_candidates.begin(), - init_candidates.end(), - std::back_inserter(last.reached_reverse_node_target), - [](const PhantomNode &phantom_node) { return phantom_node.IsValidReverseSource(); }); + std::transform(init_candidates.begin(), + init_candidates.end(), + std::back_inserter(last.reached_forward_node_target), + [](const PhantomNode &phantom_node) + { return phantom_node.IsValidForwardSource(); }); + std::transform(init_candidates.begin(), + init_candidates.end(), + std::back_inserter(last.reached_reverse_node_target), + [](const PhantomNode &phantom_node) + { return phantom_node.IsValidReverseSource(); }); } bool completeLeg() @@ -613,15 +615,21 @@ struct route_state { // Find the segment from final leg with the shortest path auto forward_range = util::irange(0UL, last.total_weight_to_forward.size()); - auto forward_min = - std::min_element(forward_range.begin(), forward_range.end(), [&](size_t a, size_t b) { + auto forward_min = std::min_element( + forward_range.begin(), + forward_range.end(), + [&](size_t a, size_t b) + { return (last.total_weight_to_forward[a] < last.total_weight_to_forward[b] || (last.total_weight_to_forward[a] == last.total_weight_to_forward[b] && last.total_nodes_to_forward[a] < last.total_nodes_to_forward[b])); }); auto reverse_range = util::irange(0UL, last.total_weight_to_reverse.size()); - auto reverse_min = - std::min_element(reverse_range.begin(), reverse_range.end(), [&](size_t a, size_t b) { + auto reverse_min = std::min_element( + reverse_range.begin(), + reverse_range.end(), + [&](size_t a, size_t b) + { return (last.total_weight_to_reverse[a] < last.total_weight_to_reverse[b] || (last.total_weight_to_reverse[a] == last.total_weight_to_reverse[b] && last.total_nodes_to_reverse[a] < last.total_nodes_to_reverse[b])); diff --git a/include/extractor/class_data.hpp b/include/extractor/class_data.hpp index 99cb02e03a7..87945a0b0b0 100644 --- a/include/extractor/class_data.hpp +++ b/include/extractor/class_data.hpp @@ -27,9 +27,9 @@ inline auto getClassData(const std::size_t index) inline bool isValidClassName(const std::string &name) { - return std::find_if_not(name.begin(), name.end(), [](const auto c) { - return std::isalnum(c); - }) == name.end(); + return std::find_if_not(name.begin(), + name.end(), + [](const auto c) { return std::isalnum(c); }) == name.end(); } } // namespace osrm::extractor diff --git a/include/extractor/extraction_helper_functions.hpp b/include/extractor/extraction_helper_functions.hpp index 8156e47183b..94b52db15b2 100644 --- a/include/extractor/extraction_helper_functions.hpp +++ b/include/extractor/extraction_helper_functions.hpp @@ -125,9 +125,8 @@ inline std::string canonicalizeStringList(std::string strlist, const std::string // collapse spaces; this is needed in case we expand "; X" => "; X" above // but also makes sense to do irregardless of the fact - canonicalizing strings. - const auto spaces = [](unsigned char lhs, unsigned char rhs) { - return ::isspace(lhs) && ::isspace(rhs); - }; + const auto spaces = [](unsigned char lhs, unsigned char rhs) + { return ::isspace(lhs) && ::isspace(rhs); }; auto it = std::unique(begin(strlist), end(strlist), spaces); strlist.erase(it, end(strlist)); diff --git a/include/extractor/extraction_relation.hpp b/include/extractor/extraction_relation.hpp index 0e333295143..94012b6e0e4 100644 --- a/include/extractor/extraction_relation.hpp +++ b/include/extractor/extraction_relation.hpp @@ -133,7 +133,8 @@ class ExtractionRelationContainer (void)res; // prevent unused warning in release } - auto MergeRefMap = [&](RelationRefMap &source, RelationRefMap &target) { + auto MergeRefMap = [&](RelationRefMap &source, RelationRefMap &target) + { for (auto it : source) { auto &v = target[it.first]; @@ -151,7 +152,8 @@ class ExtractionRelationContainer const RelationIDList &GetRelations(const OsmIDTyped &member_id) const { auto getFromMap = [this](std::uint64_t id, - const RelationRefMap &map) -> const RelationIDList & { + const RelationRefMap &map) -> const RelationIDList & + { auto it = map.find(id); if (it != map.end()) return it->second; diff --git a/include/extractor/files.hpp b/include/extractor/files.hpp index f3f759470d6..bb4a4a2bd8c 100644 --- a/include/extractor/files.hpp +++ b/include/extractor/files.hpp @@ -453,7 +453,8 @@ void readRawNBGraph(const boost::filesystem::path &path, coordinates.resize(number_of_nodes); osm_node_ids.reserve(number_of_nodes); auto index = 0; - auto decode = [&](const auto ¤t_node) { + auto decode = [&](const auto ¤t_node) + { coordinates[index].lon = current_node.lon; coordinates[index].lat = current_node.lat; osm_node_ids.push_back(current_node.node_id); diff --git a/include/extractor/intersection/intersection_view.hpp b/include/extractor/intersection/intersection_view.hpp index 2da17db6a6c..c1517c65f73 100644 --- a/include/extractor/intersection/intersection_view.hpp +++ b/include/extractor/intersection/intersection_view.hpp @@ -26,16 +26,14 @@ namespace osrm::extractor::intersection inline auto makeCompareAngularDeviation(const double angle) { - return [angle](const auto &lhs, const auto &rhs) { - return util::angularDeviation(lhs.angle, angle) < util::angularDeviation(rhs.angle, angle); - }; + return [angle](const auto &lhs, const auto &rhs) + { return util::angularDeviation(lhs.angle, angle) < util::angularDeviation(rhs.angle, angle); }; } inline auto makeExtractLanesForRoad(const util::NodeBasedDynamicGraph &node_based_graph) { - return [&node_based_graph](const auto &road) { - return node_based_graph.GetEdgeData(road.eid).road_classification.GetNumberOfLanes(); - }; + return [&node_based_graph](const auto &road) + { return node_based_graph.GetEdgeData(road.eid).road_classification.GetNumberOfLanes(); }; } // When viewing an intersection from an incoming edge, we can transform a shape into a view which @@ -63,7 +61,10 @@ template struct EnableShapeOps auto FindClosestBearing(double base_bearing) const { return std::min_element( - self()->begin(), self()->end(), [base_bearing](const auto &lhs, const auto &rhs) { + self()->begin(), + self()->end(), + [base_bearing](const auto &lhs, const auto &rhs) + { return util::angularDeviation(lhs.perceived_bearing, base_bearing) < util::angularDeviation(rhs.perceived_bearing, base_bearing); }); @@ -81,7 +82,8 @@ template struct EnableShapeOps BOOST_ASSERT(!self()->empty()); auto initial = converter(self()->front()); - const auto extract_maximal_value = [&initial, converter](const auto &road) { + const auto extract_maximal_value = [&initial, converter](const auto &road) + { initial = std::max(initial, converter(road)); return false; }; @@ -191,8 +193,10 @@ template struct EnableIntersectionOps auto findClosestTurn(const double angle, const UnaryPredicate filter) const { BOOST_ASSERT(!self()->empty()); - const auto candidate = - boost::range::min_element(*self(), [angle, &filter](const auto &lhs, const auto &rhs) { + const auto candidate = boost::range::min_element( + *self(), + [angle, &filter](const auto &lhs, const auto &rhs) + { const auto filtered_lhs = filter(lhs), filtered_rhs = filter(rhs); const auto deviation_lhs = util::angularDeviation(lhs.angle, angle), deviation_rhs = util::angularDeviation(rhs.angle, angle); diff --git a/include/extractor/node_restriction_map.hpp b/include/extractor/node_restriction_map.hpp index 1a0b7303a77..6c65a6592cb 100644 --- a/include/extractor/node_restriction_map.hpp +++ b/include/extractor/node_restriction_map.hpp @@ -32,9 +32,8 @@ template class NodeRestrictionMap // Find all restrictions applicable to (from,via,to) turns auto Restrictions(NodeID from, NodeID via, NodeID to) const { - const auto turnFilter = [this, to](const auto &restriction) { - return index_filter(restriction) && restriction->IsTurnRestricted(to); - }; + const auto turnFilter = [this, to](const auto &restriction) + { return index_filter(restriction) && restriction->IsTurnRestricted(to); }; return getRange(from, via) | boost::adaptors::filtered(turnFilter); }; diff --git a/include/guidance/intersection_handler.hpp b/include/guidance/intersection_handler.hpp index dcd62d4cbbe..b54d8223046 100644 --- a/include/guidance/intersection_handler.hpp +++ b/include/guidance/intersection_handler.hpp @@ -187,11 +187,11 @@ IntersectionHandler::IsDistinctNarrowTurn(const EdgeID via_edge, node_data_container.GetAnnotation(candidate_data.annotation_data); auto const candidate_deviation = util::angularDeviation(candidate->angle, STRAIGHT_ANGLE); - auto const num_lanes = [](auto const &data) { - return data.flags.road_classification.GetNumberOfLanes(); - }; + auto const num_lanes = [](auto const &data) + { return data.flags.road_classification.GetNumberOfLanes(); }; - auto const lanes_number_equal = [&](auto const &compare_data) { + auto const lanes_number_equal = [&](auto const &compare_data) + { // Check if the lanes number is the same going from the inbound edge to the compare road return num_lanes(compare_data) > 0 && num_lanes(compare_data) == num_lanes(via_edge_data); }; @@ -210,7 +210,8 @@ IntersectionHandler::IsDistinctNarrowTurn(const EdgeID via_edge, // check if there are other narrow turns are not considered passing a low category or simply // a link of the same type as the potentially obvious turn - auto const is_similar_turn = [&](auto const &road) { + auto const is_similar_turn = [&](auto const &road) + { // 1. Skip the candidate road if (road.eid == candidate->eid) { @@ -405,7 +406,8 @@ IntersectionHandler::IsDistinctWideTurn(const EdgeID via_edge, // Deviation is larger than NARROW_TURN_ANGLE0 here for the candidate // check if there is any turn, that might look just as obvious, even though it might not // be allowed. Entry-allowed isn't considered a valid distinction criterion here - auto const is_similar_turn = [&](auto const &road) { + auto const is_similar_turn = [&](auto const &road) + { // 1. Skip over our candidate if (road.eid == candidate->eid) return false; @@ -503,7 +505,8 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge, node_data_container.GetAnnotation(via_edge_data.annotation_data); // implement a filter, taking out all roads of lower class or different names - auto const continues_on_name_with_higher_class = [&](auto const &road) { + auto const continues_on_name_with_higher_class = [&](auto const &road) + { // it needs to be possible to enter the road if (!road.entry_allowed) return true; @@ -550,7 +553,8 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge, // this check is not part of the main conditions, so that if the turn looks obvious from all // other perspectives, a mode change will not result in different classification - auto const to_index_if_valid = [&](auto const iterator) -> std::size_t { + auto const to_index_if_valid = [&](auto const iterator) -> std::size_t + { auto const &from_data = node_based_graph.GetEdgeData(via_edge); auto const &to_data = node_based_graph.GetEdgeData(iterator->eid); @@ -577,7 +581,8 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge, // opposed to before, we do not care about name changes, again: this is a filter, so internal // false/true will be negated for selection - auto const valid_of_higher_or_same_category = [&](auto const &road) { + auto const valid_of_higher_or_same_category = [&](auto const &road) + { if (!road.entry_allowed) return true; @@ -640,7 +645,8 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge, const auto all_roads_have_same_name = std::all_of(intersection.begin(), intersection.end(), - [id = via_edge_annotation.name_id, this](auto const &road) { + [id = via_edge_annotation.name_id, this](auto const &road) + { auto const data_id = node_based_graph.GetEdgeData(road.eid).annotation_data; auto const name_id = node_data_container.GetAnnotation(data_id).name_id; return (name_id != EMPTY_NAMEID) && (name_id == id); diff --git a/include/partitioner/bisection_graph.hpp b/include/partitioner/bisection_graph.hpp index e6d18530d28..52139a85c9b 100644 --- a/include/partitioner/bisection_graph.hpp +++ b/include/partitioner/bisection_graph.hpp @@ -65,8 +65,8 @@ inline BisectionGraph makeBisectionGraph(const std::vector &co result_edges.reserve(edges.size()); // find the end of edges that belong to node_id - const auto advance_edge_itr = [&edges, &result_edges](const std::size_t node_id, - auto edge_itr) { + const auto advance_edge_itr = [&edges, &result_edges](const std::size_t node_id, auto edge_itr) + { while (edge_itr != edges.end() && edge_itr->source == node_id) { result_edges.push_back(edge_itr->Reduce()); @@ -76,9 +76,9 @@ inline BisectionGraph makeBisectionGraph(const std::vector &co }; // create a bisection node, requires the ID of the node as well as the lower bound to its edges - const auto make_bisection_node = [&edges, &coordinates](const std::size_t node_id, - const auto begin_itr, - const auto end_itr) { + const auto make_bisection_node = + [&edges, &coordinates](const std::size_t node_id, const auto begin_itr, const auto end_itr) + { std::size_t range_begin = std::distance(edges.begin(), begin_itr); std::size_t range_end = std::distance(edges.begin(), end_itr); return BisectionGraph::NodeT(range_begin, range_end, coordinates[node_id], node_id); @@ -102,9 +102,12 @@ std::vector adaptToBisectionEdge(std::vector edge std::vector result; result.reserve(edges.size()); - std::transform(begin(edges), end(edges), std::back_inserter(result), [](const auto &edge) { - return BisectionInputEdge{edge.source, edge.target}; - }); + std::transform(begin(edges), + end(edges), + std::back_inserter(result), + [](const auto &edge) { + return BisectionInputEdge{edge.source, edge.target}; + }); return result; } diff --git a/include/partitioner/cell_storage.hpp b/include/partitioner/cell_storage.hpp index 6229b6b7971..e0d315b6aa2 100644 --- a/include/partitioner/cell_storage.hpp +++ b/include/partitioner/cell_storage.hpp @@ -298,7 +298,8 @@ template class CellStorageImpl auto set_num_nodes_fn, auto set_boundary_offset_fn, auto begin, - auto end) { + auto end) + { BOOST_ASSERT(std::distance(begin, end) > 0); const auto cell_id = begin->first; @@ -316,7 +317,8 @@ template class CellStorageImpl util::for_each_range( level_source_boundary.begin(), level_source_boundary.end(), - [this, insert_cell_boundary](auto begin, auto end) { + [this, insert_cell_boundary](auto begin, auto end) + { insert_cell_boundary( source_boundary, [](auto &cell, auto value) { cell.num_source_nodes = value; }, @@ -327,7 +329,8 @@ template class CellStorageImpl util::for_each_range( level_destination_boundary.begin(), level_destination_boundary.end(), - [this, insert_cell_boundary](auto begin, auto end) { + [this, insert_cell_boundary](auto begin, auto end) + { insert_cell_boundary( destination_boundary, [](auto &cell, auto value) { cell.num_destination_nodes = value; }, diff --git a/include/partitioner/edge_based_graph_reader.hpp b/include/partitioner/edge_based_graph_reader.hpp index 669035682cf..06b8b6ae95a 100644 --- a/include/partitioner/edge_based_graph_reader.hpp +++ b/include/partitioner/edge_based_graph_reader.hpp @@ -64,10 +64,13 @@ std::vector prepareEdgesForUsageInGraph(std::vector output_edges; output_edges.reserve(edges.size()); @@ -77,10 +80,11 @@ std::vector prepareEdgesForUsageInGraph(std::vectorsource; const NodeID target = begin_interval->target; - auto end_interval = - std::find_if_not(begin_interval, edges.end(), [source, target](const auto &edge) { - return std::tie(edge.source, edge.target) == std::tie(source, target); - }); + auto end_interval = std::find_if_not( + begin_interval, + edges.end(), + [source, target](const auto &edge) + { return std::tie(edge.source, edge.target) == std::tie(source, target); }); BOOST_ASSERT(begin_interval != end_interval); // remove eigenloops @@ -144,7 +148,8 @@ graphToEdges(const DynamicEdgeBasedGraph &edge_based_graph) auto max_turn_id = tbb::parallel_reduce( range, NodeID{0}, - [&edge_based_graph](const auto range, NodeID initial) { + [&edge_based_graph](const auto range, NodeID initial) + { NodeID max_turn_id = initial; for (auto node = range.begin(); node < range.end(); ++node) { @@ -159,26 +164,29 @@ graphToEdges(const DynamicEdgeBasedGraph &edge_based_graph) [](const NodeID lhs, const NodeID rhs) { return std::max(lhs, rhs); }); std::vector edges(max_turn_id + 1); - tbb::parallel_for(range, [&](const auto range) { - for (auto node = range.begin(); node < range.end(); ++node) + tbb::parallel_for( + range, + [&](const auto range) { - for (auto edge : edge_based_graph.GetAdjacentEdgeRange(node)) + for (auto node = range.begin(); node < range.end(); ++node) { - const auto &data = edge_based_graph.GetEdgeData(edge); - // we only need to save the forward edges, since the read method will - // convert from forward to bi-directional edges again - if (data.forward) + for (auto edge : edge_based_graph.GetAdjacentEdgeRange(node)) { - auto target = edge_based_graph.GetTarget(edge); - BOOST_ASSERT(data.turn_id <= max_turn_id); - edges[data.turn_id] = extractor::EdgeBasedEdge{node, target, data}; - // only save the forward edge - edges[data.turn_id].data.forward = true; - edges[data.turn_id].data.backward = false; + const auto &data = edge_based_graph.GetEdgeData(edge); + // we only need to save the forward edges, since the read method will + // convert from forward to bi-directional edges again + if (data.forward) + { + auto target = edge_based_graph.GetTarget(edge); + BOOST_ASSERT(data.turn_id <= max_turn_id); + edges[data.turn_id] = extractor::EdgeBasedEdge{node, target, data}; + // only save the forward edge + edges[data.turn_id].data.forward = true; + edges[data.turn_id].data.backward = false; + } } } - } - }); + }); return edges; } diff --git a/include/partitioner/multi_level_graph.hpp b/include/partitioner/multi_level_graph.hpp index 288663b8889..0c1c8d75d8e 100644 --- a/include/partitioner/multi_level_graph.hpp +++ b/include/partitioner/multi_level_graph.hpp @@ -159,10 +159,11 @@ class MultiLevelGraph : public util::StaticGraph auto GetHighestBorderLevel(const MultiLevelPartition &mlp, const ContainerT &edges) const { std::vector highest_border_level(edges.size()); - std::transform( - edges.begin(), edges.end(), highest_border_level.begin(), [&mlp](const auto &edge) { - return mlp.GetHighestDifferentLevel(edge.source, edge.target); - }); + std::transform(edges.begin(), + edges.end(), + highest_border_level.begin(), + [&mlp](const auto &edge) + { return mlp.GetHighestDifferentLevel(edge.source, edge.target); }); return highest_border_level; } @@ -175,7 +176,8 @@ class MultiLevelGraph : public util::StaticGraph tbb::parallel_sort( permutation.begin(), permutation.end(), - [&edges, &highest_border_level](const auto &lhs, const auto &rhs) { + [&edges, &highest_border_level](const auto &lhs, const auto &rhs) + { // sort by source node and then by level in ascending order return std::tie(edges[lhs].source, highest_border_level[lhs], edges[lhs].target) < std::tie(edges[rhs].source, highest_border_level[rhs], edges[rhs].target); @@ -201,11 +203,12 @@ class MultiLevelGraph : public util::StaticGraph auto level_begin = iter; for (auto level : util::irange(0, mlp.GetNumberOfLevels())) { - iter = std::find_if( - iter, edge_and_level_end, [node, level](const auto &edge_and_level) { - return boost::get<0>(edge_and_level).source != node || - boost::get<1>(edge_and_level) != level; - }); + iter = std::find_if(iter, + edge_and_level_end, + [node, level](const auto &edge_and_level) { + return boost::get<0>(edge_and_level).source != node || + boost::get<1>(edge_and_level) != level; + }); EdgeOffset offset = std::distance(level_begin, iter); node_to_edge_offset.push_back(offset); } diff --git a/include/partitioner/multi_level_partition.hpp b/include/partitioner/multi_level_partition.hpp index afdde0b6d95..2373ec30e47 100644 --- a/include/partitioner/multi_level_partition.hpp +++ b/include/partitioner/multi_level_partition.hpp @@ -207,7 +207,8 @@ template class MultiLevelPartitionImpl final auto lidx = 0UL; util::for_each_pair(level_offsets.begin(), level_offsets.begin() + num_level, - [&](const auto offset, const auto next_offset) { + [&](const auto offset, const auto next_offset) + { // create mask that has `bits` ones at its LSBs. // 000011 BOOST_ASSERT(offset <= NUM_PARTITION_BITS); @@ -274,9 +275,8 @@ template class MultiLevelPartitionImpl final { std::stable_sort(permutation.begin(), permutation.end(), - [&partition](const auto lhs, const auto rhs) { - return partition[lhs] < partition[rhs]; - }); + [&partition](const auto lhs, const auto rhs) + { return partition[lhs] < partition[rhs]; }); } // top down assign new cell ids diff --git a/include/partitioner/partition_graph.hpp b/include/partitioner/partition_graph.hpp index f425a3520af..86b3a546d3a 100644 --- a/include/partitioner/partition_graph.hpp +++ b/include/partitioner/partition_graph.hpp @@ -21,7 +21,7 @@ template class NodeEntryWrapper : public Base { public: template - NodeEntryWrapper(std::size_t edges_begin_, std::size_t edges_end_, Args &&... args) + NodeEntryWrapper(std::size_t edges_begin_, std::size_t edges_end_, Args &&...args) : Base(std::forward(args)...), edges_begin(edges_begin_), edges_end(edges_end_) { } @@ -41,7 +41,7 @@ template class GraphConstructionWrapper : public Base { public: template - GraphConstructionWrapper(const NodeID source_, Args &&... args) + GraphConstructionWrapper(const NodeID source_, Args &&...args) : Base(std::forward(args)...), source(source_) { } diff --git a/include/partitioner/remove_unconnected.hpp b/include/partitioner/remove_unconnected.hpp index c3ad1e5218b..1b0c9963f67 100644 --- a/include/partitioner/remove_unconnected.hpp +++ b/include/partitioner/remove_unconnected.hpp @@ -59,11 +59,13 @@ std::size_t removeUnconnectedBoundaryNodes(const GraphT &edge_based_graph, if (level_index < static_cast(partitions.size() - 1)) { - auto new_end = std::remove_if( - witnesses.begin(), witnesses.end(), [&](const auto &witness) { - return partitions[level_index + 1][node] != - partitions[level_index + 1][witness.id]; - }); + auto new_end = + std::remove_if(witnesses.begin(), + witnesses.end(), + [&](const auto &witness) { + return partitions[level_index + 1][node] != + partitions[level_index + 1][witness.id]; + }); witnesses.resize(new_end - witnesses.begin()); } if (witnesses.size() == 0) @@ -87,10 +89,12 @@ std::size_t removeUnconnectedBoundaryNodes(const GraphT &edge_based_graph, } } - auto best_witness = std::min_element( - witnesses.begin(), witnesses.end(), [](const auto &lhs, const auto &rhs) { - return lhs.induced_border_edges < rhs.induced_border_edges; - }); + auto best_witness = + std::min_element(witnesses.begin(), + witnesses.end(), + [](const auto &lhs, const auto &rhs) { + return lhs.induced_border_edges < rhs.induced_border_edges; + }); BOOST_ASSERT(best_witness != witnesses.end()); // assign `node` to same subcells as `best_witness` diff --git a/include/partitioner/reorder_first_last.hpp b/include/partitioner/reorder_first_last.hpp index b5e5b779830..a5d2b32584b 100644 --- a/include/partitioner/reorder_first_last.hpp +++ b/include/partitioner/reorder_first_last.hpp @@ -30,10 +30,10 @@ void reorderFirstLast(RandomIt first, RandomIt last, std::size_t n, Comparator c // requirements. std::reverse_iterator rfirst{last}, rlast{first + n}; - const auto flipped = [](auto fn) { - return [fn](auto &&lhs, auto &&rhs) { - return fn(std::forward(rhs), std::forward(lhs)); - }; + const auto flipped = [](auto fn) + { + return [fn](auto &&lhs, auto &&rhs) + { return fn(std::forward(rhs), std::forward(lhs)); }; }; std::nth_element(rfirst, rfirst + (n - 1), rlast, flipped(comp)); diff --git a/include/server/api/base_parameters_grammar.hpp b/include/server/api/base_parameters_grammar.hpp index d9f429ba8bc..80fda760bca 100644 --- a/include/server/api/base_parameters_grammar.hpp +++ b/include/server/api/base_parameters_grammar.hpp @@ -74,16 +74,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar : BaseParametersGrammar::base_type(root_rule) { const auto add_hint = [](engine::api::BaseParameters &base_parameters, - const std::vector &hint_strings) { + const std::vector &hint_strings) + { if (!hint_strings.empty()) { std::vector location_hints(hint_strings.size()); std::transform(hint_strings.begin(), hint_strings.end(), location_hints.begin(), - [](const auto &hint_string) { - return engine::SegmentHint::FromBase64(hint_string); - }); + [](const auto &hint_string) + { return engine::SegmentHint::FromBase64(hint_string); }); base_parameters.hints.push_back(engine::Hint{std::move(location_hints)}); } else @@ -94,15 +94,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar const auto add_bearing = [](engine::api::BaseParameters &base_parameters, - boost::optional> bearing_range) { - boost::optional bearing; - if (bearing_range) - { - bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range), - boost::fusion::at_c<1>(*bearing_range)}; - } - base_parameters.bearings.push_back(std::move(bearing)); - }; + boost::optional> bearing_range) + { + boost::optional bearing; + if (bearing_range) + { + bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range), + boost::fusion::at_c<1>(*bearing_range)}; + } + base_parameters.bearings.push_back(std::move(bearing)); + }; polyline_chars = qi::char_("a-zA-Z0-9_.--[]{}@?|\\%~`^"); base64_char = qi::char_("a-zA-Z0-9--_="); @@ -118,7 +119,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar location_rule = (double_ > qi::lit(',') > double_)[qi::_val = ph::bind( - [](double lon, double lat) { + [](double lon, double lat) + { return util::Coordinate( util::toFixed(util::UnsafeFloatLongitude{lon}), util::toFixed(util::UnsafeFloatLatitude{lat})); @@ -126,19 +128,17 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar qi::_1, qi::_2)]; - polyline_rule = qi::as_string[qi::lit("polyline(") > +polyline_chars > ')'] - [qi::_val = ph::bind( - [](const std::string &polyline) { - return engine::decodePolyline(polyline); - }, - qi::_1)]; - - polyline6_rule = qi::as_string[qi::lit("polyline6(") > +polyline_chars > ')'] - [qi::_val = ph::bind( - [](const std::string &polyline) { - return engine::decodePolyline<1000000>(polyline); - }, - qi::_1)]; + polyline_rule = + qi::as_string[qi::lit("polyline(") > +polyline_chars > ')'] + [qi::_val = ph::bind([](const std::string &polyline) + { return engine::decodePolyline(polyline); }, + qi::_1)]; + + polyline6_rule = + qi::as_string[qi::lit("polyline6(") > +polyline_chars > ')'] + [qi::_val = ph::bind([](const std::string &polyline) + { return engine::decodePolyline<1000000>(polyline); }, + qi::_1)]; query_rule = ((location_rule % ';') | polyline_rule | diff --git a/include/server/api/route_parameters_grammar.hpp b/include/server/api/route_parameters_grammar.hpp index f6cfa0c3489..5ef668e6c09 100644 --- a/include/server/api/route_parameters_grammar.hpp +++ b/include/server/api/route_parameters_grammar.hpp @@ -54,8 +54,9 @@ struct RouteParametersGrammar : public BaseParametersGrammar(count - index, BLOCK_BITS); unpackBits(data, index, read_size, block); index += BLOCK_BITS; @@ -87,7 +88,8 @@ void writeBoolVector(tar::FileWriter &writer, const std::string &name, const Vec // FIXME on old boost version the function_input_iterator does not work with lambdas // so we need to wrap it in a function here. - const std::function encode_function = [&]() -> BlockType { + const std::function encode_function = [&]() -> BlockType + { auto write_size = std::min(count - index, BLOCK_BITS); auto packed = packBits(data, index, write_size); index += BLOCK_BITS; diff --git a/include/storage/shared_data_index.hpp b/include/storage/shared_data_index.hpp index fb156f988af..fc8212f50a3 100644 --- a/include/storage/shared_data_index.hpp +++ b/include/storage/shared_data_index.hpp @@ -28,10 +28,10 @@ class SharedDataIndex // Build mapping from block name to region for (auto index : util::irange(0, regions.size())) { - regions[index].layout->List("", - boost::make_function_output_iterator([&](const auto &name) { - block_to_region[name] = index; - })); + regions[index].layout->List( + "", + boost::make_function_output_iterator([&](const auto &name) + { block_to_region[name] = index; })); } } diff --git a/include/storage/shared_datatype.hpp b/include/storage/shared_datatype.hpp index 82d185cec3a..fae3989a2e1 100644 --- a/include/storage/shared_datatype.hpp +++ b/include/storage/shared_datatype.hpp @@ -223,9 +223,12 @@ struct SharedRegionRegister // Returns the key of the region with the given name RegionID Find(const std::string &name) const { - auto iter = std::find_if(regions.begin(), regions.end(), [&](const auto ®ion) { - return std::strncmp(region.name, name.c_str(), SharedRegion::MAX_NAME_LENGTH) == 0; - }); + auto iter = std::find_if( + regions.begin(), + regions.end(), + [&](const auto ®ion) { + return std::strncmp(region.name, name.c_str(), SharedRegion::MAX_NAME_LENGTH) == 0; + }); if (iter == regions.end()) { diff --git a/include/storage/shared_memory.hpp b/include/storage/shared_memory.hpp index d5a661bd479..76a385b889e 100644 --- a/include/storage/shared_memory.hpp +++ b/include/storage/shared_memory.hpp @@ -113,7 +113,8 @@ class SharedMemory { auto shmid = shm.get_shmid(); ::shmid_ds xsi_ds; - const auto errorToMessage = [](int error) -> std::string { + const auto errorToMessage = [](int error) -> std::string + { switch (error) { case EPERM: diff --git a/include/storage/view_factory.hpp b/include/storage/view_factory.hpp index 8279f84c50d..88e99e8e8fd 100644 --- a/include/storage/view_factory.hpp +++ b/include/storage/view_factory.hpp @@ -241,9 +241,9 @@ inline auto make_contracted_metric_view(const SharedDataIndex &index, const std: std::vector> edge_filter; index.List(name + "/exclude", - boost::make_function_output_iterator([&](const auto &filter_name) { - edge_filter.push_back(make_vector_view(index, filter_name)); - })); + boost::make_function_output_iterator( + [&](const auto &filter_name) + { edge_filter.push_back(make_vector_view(index, filter_name)); })); return contractor::ContractedMetricView{{node_list, edge_list}, std::move(edge_filter)}; } diff --git a/include/updater/csv_file_parser.hpp b/include/updater/csv_file_parser.hpp index e21565f1a73..1b1bffb9218 100644 --- a/include/updater/csv_file_parser.hpp +++ b/include/updater/csv_file_parser.hpp @@ -46,31 +46,36 @@ template struct CSVFilesParser { tbb::spin_mutex mutex; std::vector> lookup; - tbb::parallel_for(std::size_t{0}, csv_filenames.size(), [&](const std::size_t idx) { - auto local = ParseCSVFile(csv_filenames[idx], start_index + idx); - - { // Merge local CSV results into a flat global vector - tbb::spin_mutex::scoped_lock _{mutex}; - lookup.insert(end(lookup), - std::make_move_iterator(begin(local)), - std::make_move_iterator(end(local))); - } - }); + tbb::parallel_for(std::size_t{0}, + csv_filenames.size(), + [&](const std::size_t idx) + { + auto local = ParseCSVFile(csv_filenames[idx], start_index + idx); + + { // Merge local CSV results into a flat global vector + tbb::spin_mutex::scoped_lock _{mutex}; + lookup.insert(end(lookup), + std::make_move_iterator(begin(local)), + std::make_move_iterator(end(local))); + } + }); // With flattened map-ish view of all the files, make a stable sort on key and source // and unique them on key to keep only the value with the largest file index // and the largest line number in a file. // The operands order is swapped to make descending ordering on (key, source) - tbb::parallel_sort(begin(lookup), end(lookup), [](const auto &lhs, const auto &rhs) { - return std::tie(rhs.first, rhs.second.source) < - std::tie(lhs.first, lhs.second.source); - }); + tbb::parallel_sort(begin(lookup), + end(lookup), + [](const auto &lhs, const auto &rhs) { + return std::tie(rhs.first, rhs.second.source) < + std::tie(lhs.first, lhs.second.source); + }); // Unique only on key to take the source precedence into account and remove duplicates. - const auto it = - std::unique(begin(lookup), end(lookup), [](const auto &lhs, const auto &rhs) { - return lhs.first == rhs.first; - }); + const auto it = std::unique(begin(lookup), + end(lookup), + [](const auto &lhs, const auto &rhs) + { return lhs.first == rhs.first; }); lookup.erase(it, end(lookup)); util::Log() << "In total loaded " << csv_filenames.size() << " file(s) with a total of " diff --git a/include/updater/source.hpp b/include/updater/source.hpp index 0b3dec11b74..72bea7f541f 100644 --- a/include/updater/source.hpp +++ b/include/updater/source.hpp @@ -15,10 +15,11 @@ template struct LookupTable boost::optional operator()(const Key &key) const { using Result = boost::optional; - const auto it = std::lower_bound( - lookup.begin(), lookup.end(), key, [](const auto &lhs, const auto &rhs) { - return rhs < lhs.first; - }); + const auto it = + std::lower_bound(lookup.begin(), + lookup.end(), + key, + [](const auto &lhs, const auto &rhs) { return rhs < lhs.first; }); return it != std::end(lookup) && !(it->first < key) ? Result(it->second) : Result(); } diff --git a/include/util/alias.hpp b/include/util/alias.hpp index 6a109ffddec..f335f474203 100644 --- a/include/util/alias.hpp +++ b/include/util/alias.hpp @@ -46,7 +46,7 @@ template struct Alias final static_assert(std::is_arithmetic::value, "Needs to be based on an arithmetic type"); From __value; - friend std::ostream &operator<<(std::ostream &stream, const Alias &inst); + friend std::ostream &operator<< (std::ostream &stream, const Alias &inst); explicit operator From &() { return __value; } explicit operator From() const { return __value; } diff --git a/include/util/coordinate_calculation.hpp b/include/util/coordinate_calculation.hpp index c7bd9371b8d..3ab8db07608 100644 --- a/include/util/coordinate_calculation.hpp +++ b/include/util/coordinate_calculation.hpp @@ -179,7 +179,8 @@ template double getLength(iterator_type begin, const iterator_type end, BinaryOperation op) { double result = 0; - const auto functor = [&result, op](const Coordinate lhs, const Coordinate rhs) { + const auto functor = [&result, op](const Coordinate lhs, const Coordinate rhs) + { result += op(lhs, rhs); return false; }; @@ -197,8 +198,9 @@ findClosestDistance(const Coordinate coordinate, const iterator_type begin, cons double current_min = std::numeric_limits::max(); // comparator updating current_min without ever finding an element - const auto compute_minimum_distance = [¤t_min, coordinate](const Coordinate lhs, - const Coordinate rhs) { + const auto compute_minimum_distance = + [¤t_min, coordinate](const Coordinate lhs, const Coordinate rhs) + { current_min = std::min(current_min, findClosestDistance(coordinate, lhs, rhs)); return false; }; @@ -216,8 +218,9 @@ double findClosestDistance(const iterator_type lhs_begin, { double current_min = std::numeric_limits::max(); - const auto compute_minimum_distance_in_rhs = [¤t_min, rhs_begin, rhs_end]( - const Coordinate coordinate) { + const auto compute_minimum_distance_in_rhs = + [¤t_min, rhs_begin, rhs_end](const Coordinate coordinate) + { current_min = std::min(current_min, findClosestDistance(coordinate, rhs_begin, rhs_end)); return false; }; @@ -233,13 +236,11 @@ std::pair leastSquareRegression(const iterator_type begi // following the formulas of https://faculty.elgin.edu/dkernler/statistics/ch04/4-2.html const auto number_of_coordinates = std::distance(begin, end); BOOST_ASSERT(number_of_coordinates >= 2); - const auto extract_lon = [](const Coordinate coordinate) { - return static_cast(toFloating(coordinate.lon)); - }; + const auto extract_lon = [](const Coordinate coordinate) + { return static_cast(toFloating(coordinate.lon)); }; - const auto extract_lat = [](const Coordinate coordinate) { - return static_cast(toFloating(coordinate.lat)); - }; + const auto extract_lat = [](const Coordinate coordinate) + { return static_cast(toFloating(coordinate.lat)); }; double min_lon = extract_lon(*begin); double max_lon = extract_lon(*begin); @@ -262,19 +263,21 @@ std::pair leastSquareRegression(const iterator_type begi { std::vector rotated_coordinates(number_of_coordinates); // rotate all coordinates to the right - std::transform(begin, end, rotated_coordinates.begin(), [](const auto coordinate) { - return rotateCCWAroundZero(coordinate, detail::degToRad(-90)); - }); + std::transform(begin, + end, + rotated_coordinates.begin(), + [](const auto coordinate) + { return rotateCCWAroundZero(coordinate, detail::degToRad(-90)); }); const auto rotated_regression = leastSquareRegression(rotated_coordinates.begin(), rotated_coordinates.end()); return {rotateCCWAroundZero(rotated_regression.first, detail::degToRad(90)), rotateCCWAroundZero(rotated_regression.second, detail::degToRad(90))}; } - const auto make_accumulate = [](const auto extraction_function) { - return [extraction_function](const double sum_so_far, const Coordinate coordinate) { - return sum_so_far + extraction_function(coordinate); - }; + const auto make_accumulate = [](const auto extraction_function) + { + return [extraction_function](const double sum_so_far, const Coordinate coordinate) + { return sum_so_far + extraction_function(coordinate); }; }; const auto accumulated_lon = std::accumulate(begin, end, 0., make_accumulate(extract_lon)); @@ -283,8 +286,10 @@ std::pair leastSquareRegression(const iterator_type begi const auto mean_lon = accumulated_lon / number_of_coordinates; const auto mean_lat = accumulated_lat / number_of_coordinates; - const auto make_variance = [](const auto mean, const auto extraction_function) { - return [extraction_function, mean](const double sum_so_far, const Coordinate coordinate) { + const auto make_variance = [](const auto mean, const auto extraction_function) + { + return [extraction_function, mean](const double sum_so_far, const Coordinate coordinate) + { const auto difference = extraction_function(coordinate) - mean; return sum_so_far + difference * difference; }; @@ -312,7 +317,8 @@ std::pair leastSquareRegression(const iterator_type begi std::accumulate(begin, end, 0., - [&](const auto sum_so_far, const auto current_coordinate) { + [&](const auto sum_so_far, const auto current_coordinate) + { return sum_so_far + (extract_lon(current_coordinate) - mean_lon) * (extract_lat(current_coordinate) - mean_lat) / (sample_variance_lon * sample_variance_lat); @@ -323,9 +329,8 @@ std::pair leastSquareRegression(const iterator_type begi const auto intercept = mean_lat - slope * mean_lon; const auto GetLatAtLon = [intercept, - slope](const util::FloatLongitude longitude) -> util::FloatLatitude { - return {intercept + slope * static_cast((longitude))}; - }; + slope](const util::FloatLongitude longitude) -> util::FloatLatitude + { return {intercept + slope * static_cast((longitude))}; }; const double offset = 0.00001; const Coordinate regression_first = { @@ -359,7 +364,8 @@ bool areParallel(const iterator_type lhs_begin, const auto rotation_angle_radians = detail::degToRad(bearing_lhs - 90); const auto rotated_difference_rhs = rotateCCWAroundZero(difference_rhs, rotation_angle_radians); - const auto get_slope = [](const Coordinate from, const Coordinate to) { + const auto get_slope = [](const Coordinate from, const Coordinate to) + { const auto diff_lat = static_cast(from.lat) - static_cast(to.lat); const auto diff_lon = static_cast(from.lon) - static_cast(to.lon); if (diff_lon == 0) diff --git a/include/util/deallocating_vector.hpp b/include/util/deallocating_vector.hpp index f5f3d1c7d89..9cb5641e335 100644 --- a/include/util/deallocating_vector.hpp +++ b/include/util/deallocating_vector.hpp @@ -254,7 +254,7 @@ template class DeallocatingVector ++current_size; } - template void emplace_back(Ts &&... element) + template void emplace_back(Ts &&...element) { const std::size_t current_capacity = capacity(); if (current_size == current_capacity) diff --git a/include/util/dynamic_graph.hpp b/include/util/dynamic_graph.hpp index bbb67a45acd..9efbf1402ec 100644 --- a/include/util/dynamic_graph.hpp +++ b/include/util/dynamic_graph.hpp @@ -68,7 +68,7 @@ template class DynamicGraph } template - InputEdge(NodeIterator source, NodeIterator target, Ts &&... data) + InputEdge(NodeIterator source, NodeIterator target, Ts &&...data) : source(source), target(target), data(std::forward(data)...) { } @@ -189,25 +189,28 @@ template class DynamicGraph other.node_array.resize(node_array.size()); NodeID node_id = 0; - std::transform( - node_array.begin(), node_array.end(), other.node_array.begin(), [&](const Node &node) { - const EdgeIterator first_edge = other.edge_list.size(); - - BOOST_ASSERT(node_id < number_of_nodes); - if (filter(node_id++)) - { - std::copy_if(edge_list.begin() + node.first_edge, - edge_list.begin() + node.first_edge + node.edges, - std::back_inserter(other.edge_list), - [&](const auto &edge) { return filter(edge.target); }); - const unsigned num_edges = other.edge_list.size() - first_edge; - return Node{first_edge, num_edges}; - } - else - { - return Node{first_edge, 0}; - } - }); + std::transform(node_array.begin(), + node_array.end(), + other.node_array.begin(), + [&](const Node &node) + { + const EdgeIterator first_edge = other.edge_list.size(); + + BOOST_ASSERT(node_id < number_of_nodes); + if (filter(node_id++)) + { + std::copy_if(edge_list.begin() + node.first_edge, + edge_list.begin() + node.first_edge + node.edges, + std::back_inserter(other.edge_list), + [&](const auto &edge) { return filter(edge.target); }); + const unsigned num_edges = other.edge_list.size() - first_edge; + return Node{first_edge, num_edges}; + } + else + { + return Node{first_edge, 0}; + } + }); return other; } diff --git a/include/util/filtered_graph.hpp b/include/util/filtered_graph.hpp index cfab67102db..2da008fad50 100644 --- a/include/util/filtered_graph.hpp +++ b/include/util/filtered_graph.hpp @@ -37,9 +37,9 @@ class FilteredGraphImpl, Ownership> unsigned GetOutDegree(const NodeIterator n) const { auto range = graph.GetAdjacentEdgeRange(n); - return std::count_if(range.begin(), range.end(), [this](const EdgeIterator edge) { - return edge_filter[edge]; - }); + return std::count_if(range.begin(), + range.end(), + [this](const EdgeIterator edge) { return edge_filter[edge]; }); } inline NodeIterator GetTarget(const EdgeIterator e) const diff --git a/include/util/geojson_debug_logger.hpp b/include/util/geojson_debug_logger.hpp index 9d35803fa0d..ea86535d5db 100644 --- a/include/util/geojson_debug_logger.hpp +++ b/include/util/geojson_debug_logger.hpp @@ -58,7 +58,7 @@ class GeojsonLogger } // writes a single feature into the Geojson file - template static bool Write(Args &&... args) + template static bool Write(Args &&...args) { // make sure to syncronize logging output, our writing should be sequential std::lock_guard guard(lock); @@ -146,7 +146,7 @@ class ScopedGeojsonLoggerGuard { public: template - ScopedGeojsonLoggerGuard(const std::string &logfile, Args &&... args) + ScopedGeojsonLoggerGuard(const std::string &logfile, Args &&...args) : policy(std::forward(args)...) { GeojsonLogger::Open(logfile); @@ -159,7 +159,7 @@ class ScopedGeojsonLoggerGuard GeojsonLogger::SetPolicy(nullptr); } - template static bool Write(Args &&... args) + template static bool Write(Args &&...args) { return GeojsonLogger::Write( std::forward(args)...); diff --git a/include/util/guidance/name_announcements.hpp b/include/util/guidance/name_announcements.hpp index a3b1094e274..52f435750f4 100644 --- a/include/util/guidance/name_announcements.hpp +++ b/include/util/guidance/name_announcements.hpp @@ -63,14 +63,16 @@ template inline auto decompose(const StringView &lhs, cons auto const lcs = longest_common_substring(lhs, rhs); // trim spaces, transform to lower - const auto trim = [](StringView view) { + const auto trim = [](StringView view) + { // we compare suffixes based on this value, it might break UTF chars, but as long as we are // consistent in handling, we do not create bad results std::string str; str.reserve(view.size()); - std::transform(view.begin(), view.end(), std::back_inserter(str), [](unsigned char c) { - return std::tolower(c); - }); + std::transform(view.begin(), + view.end(), + std::back_inserter(str), + [](unsigned char c) { return std::tolower(c); }); auto front = str.find_first_not_of(' '); if (front == std::string::npos) @@ -131,13 +133,13 @@ inline bool requiresNameAnnounced(const StringView &from_name, const auto checkForPrefixOrSuffixChange = [](const std::string_view first, const std::string_view second, - const SuffixTable &suffix_table) { + const SuffixTable &suffix_table) + { std::string first_prefix, first_suffix, second_prefix, second_suffix; std::tie(first_prefix, first_suffix, second_prefix, second_suffix) = decompose(first, second); - const auto checkTable = [&](const std::string &str) { - return str.empty() || suffix_table.isSuffix(str); - }; + const auto checkTable = [&](const std::string &str) + { return str.empty() || suffix_table.isSuffix(str); }; return checkTable(first_prefix) && checkTable(first_suffix) && checkTable(second_prefix) && checkTable(second_suffix); diff --git a/include/util/indexed_data.hpp b/include/util/indexed_data.hpp index 486c68334f1..edc2e7a4728 100644 --- a/include/util/indexed_data.hpp +++ b/include/util/indexed_data.hpp @@ -315,9 +315,8 @@ template struct Indexe values_byte_iter = block.WriteBlockPrefix(curr, next, values_byte_iter); std::advance(next, std::min(1, std::distance(next, sentinel))); - auto to_bytes = [&](const auto &data) { - values_byte_iter = std::copy_n(&data, sizeof(ValueType), values_byte_iter); - }; + auto to_bytes = [&](const auto &data) + { values_byte_iter = std::copy_n(&data, sizeof(ValueType), values_byte_iter); }; std::copy(data + *curr, data + *next, boost::make_function_output_iterator(std::cref(to_bytes))); diff --git a/include/util/integer_range.hpp b/include/util/integer_range.hpp index 20089708a84..973197b7ff6 100644 --- a/include/util/integer_range.hpp +++ b/include/util/integer_range.hpp @@ -43,11 +43,10 @@ class integer_iterator : public boost::iterator_facade difference_type distance_to(const integer_iterator &other) const { - return std::is_signed::value - ? (other.m_value - m_value) - : (other.m_value >= m_value) - ? static_cast(other.m_value - m_value) - : -static_cast(m_value - other.m_value); + return std::is_signed::value ? (other.m_value - m_value) + : (other.m_value >= m_value) + ? static_cast(other.m_value - m_value) + : -static_cast(m_value - other.m_value); } friend class ::boost::iterator_core_access; diff --git a/include/util/node_based_graph.hpp b/include/util/node_based_graph.hpp index 6f2760928e3..b45358fee5b 100644 --- a/include/util/node_based_graph.hpp +++ b/include/util/node_based_graph.hpp @@ -79,7 +79,8 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes, auto edges_list = directedEdgesFromCompressed( input_edge_list, [](NodeBasedDynamicGraph::InputEdge &output_edge, - const extractor::NodeBasedEdge &input_edge) { + const extractor::NodeBasedEdge &input_edge) + { output_edge.data.weight = input_edge.weight; output_edge.data.duration = input_edge.duration; output_edge.data.distance = input_edge.distance; diff --git a/include/util/opening_hours.hpp b/include/util/opening_hours.hpp index 45af422037c..90e25f9ca30 100644 --- a/include/util/opening_hours.hpp +++ b/include/util/opening_hours.hpp @@ -193,23 +193,20 @@ struct OpeningHours && (times.empty() || std::any_of(times.begin(), times.end(), - [&time, &use_curr_day, &use_next_day](const auto &x) { - return x.IsInRange(time, use_curr_day, use_next_day); - })) + [&time, &use_curr_day, &use_next_day](const auto &x) + { return x.IsInRange(time, use_curr_day, use_next_day); })) // .. and if weekdays are not specified or matches weekdays range && (weekdays.empty() || std::any_of(weekdays.begin(), weekdays.end(), - [&time, use_curr_day, use_next_day](const auto &x) { - return x.IsInRange(time, use_curr_day, use_next_day); - })) + [&time, use_curr_day, use_next_day](const auto &x) + { return x.IsInRange(time, use_curr_day, use_next_day); })) // .. and if month-day ranges are not specified or is in any month-day range && (monthdays.empty() || std::any_of(monthdays.begin(), monthdays.end(), - [&time, use_curr_day, use_next_day](const auto &x) { - return x.IsInRange(time, use_curr_day, use_next_day); - })); + [&time, use_curr_day, use_next_day](const auto &x) + { return x.IsInRange(time, use_curr_day, use_next_day); })); } std::vector times; diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index de43ebd9ea0..2c27ad74505 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -345,9 +345,9 @@ class QueryHeap void DeleteAll() { auto const none_handle = heap.s_handle_from_iterator(heap.end()); - std::for_each(inserted_nodes.begin(), inserted_nodes.end(), [&none_handle](auto &node) { - node.handle = none_handle; - }); + std::for_each(inserted_nodes.begin(), + inserted_nodes.end(), + [&none_handle](auto &node) { node.handle = none_handle; }); heap.clear(); } diff --git a/include/util/range_table.hpp b/include/util/range_table.hpp index 75746257021..2808f6c1854 100644 --- a/include/util/range_table.hpp +++ b/include/util/range_table.hpp @@ -64,7 +64,8 @@ template class RangeTable // construct table from length vector template explicit RangeTable(const VectorT &lengths) { - const unsigned number_of_blocks = [&lengths]() { + const unsigned number_of_blocks = [&lengths]() + { unsigned num = (lengths.size() + 1) / (BLOCK_SIZE + 1); if ((lengths.size() + 1) % (BLOCK_SIZE + 1) != 0) { diff --git a/include/util/static_graph.hpp b/include/util/static_graph.hpp index be713a1cd9d..c010471ea37 100644 --- a/include/util/static_graph.hpp +++ b/include/util/static_graph.hpp @@ -94,7 +94,7 @@ template struct SortableEdgeWithData : SortableEdgeWithData SortableEdgeWithData() = default; template - SortableEdgeWithData(NodeIterator source, NodeIterator target, Ts &&... data) + SortableEdgeWithData(NodeIterator source, NodeIterator target, Ts &&...data) : Base{source, target}, data{std::forward(data)...} { } @@ -304,10 +304,14 @@ class StaticGraph BOOST_ASSERT(node_array.size() == number_of_nodes + 1); edge_array.resize(number_of_edges); - std::transform(begin, end, edge_array.begin(), [](const auto &from) { - return static_graph_details::edgeToEntry( - from, traits::HasDataMember{}); - }); + std::transform(begin, + end, + edge_array.begin(), + [](const auto &from) + { + return static_graph_details::edgeToEntry( + from, traits::HasDataMember{}); + }); } protected: diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index 291c35f4d41..d39d8454d0a 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -281,7 +281,8 @@ class StaticRTree tbb::parallel_for( tbb::blocked_range(0, element_count), [&input_data_vector, &input_wrapper_vector, this]( - const tbb::blocked_range &range) { + const tbb::blocked_range &range) + { for (uint64_t element_counter = range.begin(), end = range.end(); element_counter != end; ++element_counter) @@ -560,9 +561,8 @@ class StaticRTree return Nearest( input_coordinate, [](const CandidateSegment &) { return std::make_pair(true, true); }, - [max_results](const std::size_t num_results, const CandidateSegment &) { - return num_results >= max_results; - }); + [max_results](const std::size_t num_results, const CandidateSegment &) + { return num_results >= max_results; }); } // Return edges in distance order with the coordinate of the closest point on the edge. diff --git a/include/util/std_hash.hpp b/include/util/std_hash.hpp index b4010f439e6..16bf278dc89 100644 --- a/include/util/std_hash.hpp +++ b/include/util/std_hash.hpp @@ -14,13 +14,13 @@ template void hash_combine(std::size_t &seed, const T &val) template void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); } template -void hash_val(std::size_t &seed, const T &val, const Types &... args) +void hash_val(std::size_t &seed, const T &val, const Types &...args) { hash_combine(seed, val); hash_val(seed, args...); } -template std::size_t hash_val(const Types &... args) +template std::size_t hash_val(const Types &...args) { std::size_t seed = 0; hash_val(seed, args...); diff --git a/include/util/string_util.hpp b/include/util/string_util.hpp index 6133b2618b6..ae881c5146a 100644 --- a/include/util/string_util.hpp +++ b/include/util/string_util.hpp @@ -18,7 +18,8 @@ template char *printInt(char *buffer, int value) static_assert(length > 0, "length must be positive"); static_assert(precision > 0, "precision must be positive"); - const bool minus = [&value] { + const bool minus = [&value] + { if (value >= 0) { value = -value; diff --git a/include/util/timed_histogram.hpp b/include/util/timed_histogram.hpp index cd2b822356f..9338154463c 100644 --- a/include/util/timed_histogram.hpp +++ b/include/util/timed_histogram.hpp @@ -51,16 +51,20 @@ template class { std::stringstream out; - const auto print_bins = [&out](auto frame_index, auto begin, auto end) { + const auto print_bins = [&out](auto frame_index, auto begin, auto end) + { auto bin_index = 0; - std::for_each(begin, end, [&](const auto count) { - if (count > 0) - { - out << (frame_index * TimeBinSize) << "," << (bin_index * IndexBinSize) << "," - << count << std::endl; - } - bin_index++; - }); + std::for_each(begin, + end, + [&](const auto count) + { + if (count > 0) + { + out << (frame_index * TimeBinSize) << "," + << (bin_index * IndexBinSize) << "," << count << std::endl; + } + bin_index++; + }); }; if (frame_offsets.size() == 0) diff --git a/src/benchmarks/static_rtree.cpp b/src/benchmarks/static_rtree.cpp index fae84bb0f59..d2dd08fe553 100644 --- a/src/benchmarks/static_rtree.cpp +++ b/src/benchmarks/static_rtree.cpp @@ -65,12 +65,12 @@ void benchmark(BenchStaticRTree &rtree, unsigned num_queries) util::FixedLatitude{lat_udist(mt_rand)}); } - benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const util::Coordinate &q) { - return rtree.Nearest(q, 1); - }); - benchmarkQuery(queries, "raw RTree queries (10 results)", [&rtree](const util::Coordinate &q) { - return rtree.Nearest(q, 10); - }); + benchmarkQuery(queries, + "raw RTree queries (1 result)", + [&rtree](const util::Coordinate &q) { return rtree.Nearest(q, 1); }); + benchmarkQuery(queries, + "raw RTree queries (10 results)", + [&rtree](const util::Coordinate &q) { return rtree.Nearest(q, 10); }); } } // namespace osrm::benchmarks diff --git a/src/contractor/graph_contractor.cpp b/src/contractor/graph_contractor.cpp index 0e02101fe1a..9bee894b253 100644 --- a/src/contractor/graph_contractor.cpp +++ b/src/contractor/graph_contractor.cpp @@ -619,7 +619,8 @@ std::vector contractGraph(ContractorGraph &graph, util::UnbufferedLog log; log << "initializing node priorities..."; tbb::parallel_for(tbb::blocked_range(0, remaining_nodes.size(), PQGrainSize), - [&](const auto &range) { + [&](const auto &range) + { ContractorThreadData *data = thread_data_list.GetThreadData(); for (auto x = range.begin(), end = range.end(); x != end; ++x) { @@ -656,7 +657,8 @@ std::vector contractGraph(ContractorGraph &graph, tbb::parallel_for( tbb::blocked_range(0, remaining_nodes.size(), IndependentGrainSize), - [&](const auto &range) { + [&](const auto &range) + { ContractorThreadData *data = thread_data_list.GetThreadData(); // determine independent node set for (auto i = range.begin(), end = range.end(); i != end; ++i) @@ -669,9 +671,9 @@ std::vector contractGraph(ContractorGraph &graph, // sort all remaining nodes to the beginning of the sequence const auto begin_independent_nodes = std::stable_partition( - remaining_nodes.begin(), remaining_nodes.end(), [](RemainingNodeData node_data) { - return !node_data.is_independent; - }); + remaining_nodes.begin(), + remaining_nodes.end(), + [](RemainingNodeData node_data) { return !node_data.is_independent; }); auto begin_independent_nodes_idx = std::distance(remaining_nodes.begin(), begin_independent_nodes); auto end_independent_nodes_idx = remaining_nodes.size(); @@ -680,7 +682,8 @@ std::vector contractGraph(ContractorGraph &graph, tbb::parallel_for( tbb::blocked_range( begin_independent_nodes_idx, end_independent_nodes_idx, ContractGrainSize), - [&](const auto &range) { + [&](const auto &range) + { ContractorThreadData *data = thread_data_list.GetThreadData(); for (auto position = range.begin(), end = range.end(); position != end; ++position) { @@ -699,7 +702,8 @@ std::vector contractGraph(ContractorGraph &graph, tbb::parallel_for( tbb::blocked_range( begin_independent_nodes_idx, end_independent_nodes_idx, DeleteGrainSize), - [&](const auto &range) { + [&](const auto &range) + { ContractorThreadData *data = thread_data_list.GetThreadData(); for (auto position = range.begin(), end = range.end(); position != end; ++position) { @@ -709,10 +713,13 @@ std::vector contractGraph(ContractorGraph &graph, }); // make sure we really sort each block - tbb::parallel_for(thread_data_list.data.range(), [&](const auto &range) { - for (auto &data : range) - tbb::parallel_sort(data->inserted_edges.begin(), data->inserted_edges.end()); - }); + tbb::parallel_for(thread_data_list.data.range(), + [&](const auto &range) + { + for (auto &data : range) + tbb::parallel_sort(data->inserted_edges.begin(), + data->inserted_edges.end()); + }); // insert new edges for (auto &data : thread_data_list.data) @@ -743,7 +750,8 @@ std::vector contractGraph(ContractorGraph &graph, tbb::parallel_for( tbb::blocked_range( begin_independent_nodes_idx, end_independent_nodes_idx, NeighboursGrainSize), - [&](const auto &range) { + [&](const auto &range) + { ContractorThreadData *data = thread_data_list.GetThreadData(); for (auto position = range.begin(), end = range.end(); position != end; ++position) { diff --git a/src/customize/customizer.cpp b/src/customize/customizer.cpp index e9a3b08e523..6a0ec102a22 100644 --- a/src/customize/customizer.cpp +++ b/src/customize/customizer.cpp @@ -47,17 +47,18 @@ void printUnreachableStatistics(const Partition &partition, for (auto node : cell.GetSourceNodes()) { const auto &weights = cell.GetOutWeight(node); - invalid_sources += std::all_of(weights.begin(), weights.end(), [](auto weight) { - return weight == INVALID_EDGE_WEIGHT; - }); + invalid_sources += + std::all_of(weights.begin(), + weights.end(), + [](auto weight) { return weight == INVALID_EDGE_WEIGHT; }); } for (auto node : cell.GetDestinationNodes()) { const auto &weights = cell.GetInWeight(node); invalid_destinations += - std::all_of(weights.begin(), weights.end(), [](auto weight) { - return weight == INVALID_EDGE_WEIGHT; - }); + std::all_of(weights.begin(), + weights.end(), + [](auto weight) { return weight == INVALID_EDGE_WEIGHT; }); } } diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 960bd13e3ad..988ca08e8db 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -129,7 +129,8 @@ util::json::Object makeIntersection(const guidance::IntermediateIntersection &in std::transform(intersection.entry.begin(), intersection.entry.end(), std::back_inserter(entry.values), - [](const bool has_entry) -> util::json::Value { + [](const bool has_entry) -> util::json::Value + { if (has_entry) return util::json::True(); else @@ -151,11 +152,11 @@ util::json::Object makeIntersection(const guidance::IntermediateIntersection &in { util::json::Array classes; classes.values.reserve(intersection.classes.size()); - std::transform( - intersection.classes.begin(), - intersection.classes.end(), - std::back_inserter(classes.values), - [](const std::string &class_name) { return util::json::String{class_name}; }); + std::transform(intersection.classes.begin(), + intersection.classes.end(), + std::back_inserter(classes.values), + [](const std::string &class_name) + { return util::json::String{class_name}; }); result.values["classes"] = std::move(classes); } diff --git a/src/engine/douglas_peucker.cpp b/src/engine/douglas_peucker.cpp index 75a6f121b0a..2daefe2954f 100644 --- a/src/engine/douglas_peucker.cpp +++ b/src/engine/douglas_peucker.cpp @@ -43,9 +43,11 @@ std::vector douglasPeucker(std::vector::cons } std::vector projected_coordinates(size); - std::transform(begin, end, projected_coordinates.begin(), [](const util::Coordinate coord) { - return util::web_mercator::fromWGS84(coord); - }); + std::transform(begin, + end, + projected_coordinates.begin(), + [](const util::Coordinate coord) + { return util::web_mercator::fromWGS84(coord); }); std::vector is_necessary(size, false); BOOST_ASSERT(is_necessary.size() >= 2); diff --git a/src/engine/engine_config.cpp b/src/engine/engine_config.cpp index 16cfebd0b66..bfe92841c63 100644 --- a/src/engine/engine_config.cpp +++ b/src/engine/engine_config.cpp @@ -9,9 +9,8 @@ bool EngineConfig::IsValid() const // leads to an empty path const bool all_path_are_empty = storage_config.GetPath("").empty(); - const auto unlimited_or_more_than = [](const auto v, const auto limit) { - return v == -1 || v > limit; - }; + const auto unlimited_or_more_than = [](const auto v, const auto limit) + { return v == -1 || v > limit; }; const bool limits_valid = unlimited_or_more_than(max_locations_distance_table, 2) && diff --git a/src/engine/guidance/assemble_overview.cpp b/src/engine/guidance/assemble_overview.cpp index 0f02c15cf86..9ee7688656b 100644 --- a/src/engine/guidance/assemble_overview.cpp +++ b/src/engine/guidance/assemble_overview.cpp @@ -40,22 +40,21 @@ unsigned calculateOverviewZoomLevel(const std::vector &leg_geometri std::vector assembleOverview(const std::vector &leg_geometries, const bool use_simplification) { - auto overview_size = - std::accumulate(leg_geometries.begin(), - leg_geometries.end(), - 0, - [](const std::size_t sum, const LegGeometry &leg_geometry) { - return sum + leg_geometry.locations.size(); - }) - - leg_geometries.size() + 1; + auto overview_size = std::accumulate(leg_geometries.begin(), + leg_geometries.end(), + 0, + [](const std::size_t sum, const LegGeometry &leg_geometry) + { return sum + leg_geometry.locations.size(); }) - + leg_geometries.size() + 1; std::vector overview_geometry; overview_geometry.reserve(overview_size); using GeometryIter = decltype(overview_geometry)::const_iterator; auto leg_reverse_index = leg_geometries.size(); - const auto insert_without_overlap = [&leg_reverse_index, &overview_geometry](GeometryIter begin, - GeometryIter end) { + const auto insert_without_overlap = + [&leg_reverse_index, &overview_geometry](GeometryIter begin, GeometryIter end) + { // not the last leg if (leg_reverse_index > 1) { diff --git a/src/engine/guidance/assemble_route.cpp b/src/engine/guidance/assemble_route.cpp index a5f7abef139..ec4a4197d71 100644 --- a/src/engine/guidance/assemble_route.cpp +++ b/src/engine/guidance/assemble_route.cpp @@ -7,18 +7,21 @@ namespace osrm::engine::guidance Route assembleRoute(const std::vector &route_legs) { - auto distance = std::accumulate( - route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) { - return sum + leg.distance; - }); - auto duration = std::accumulate( - route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) { - return sum + leg.duration; - }); - auto weight = std::accumulate( - route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) { - return sum + leg.weight; - }); + auto distance = + std::accumulate(route_legs.begin(), + route_legs.end(), + 0., + [](const double sum, const RouteLeg &leg) { return sum + leg.distance; }); + auto duration = + std::accumulate(route_legs.begin(), + route_legs.end(), + 0., + [](const double sum, const RouteLeg &leg) { return sum + leg.duration; }); + auto weight = + std::accumulate(route_legs.begin(), + route_legs.end(), + 0., + [](const double sum, const RouteLeg &leg) { return sum + leg.weight; }); return Route{distance, duration, weight}; } diff --git a/src/engine/guidance/collapse_scenario_detection.cpp b/src/engine/guidance/collapse_scenario_detection.cpp index 6b8517466b9..e9c00c94035 100644 --- a/src/engine/guidance/collapse_scenario_detection.cpp +++ b/src/engine/guidance/collapse_scenario_detection.cpp @@ -102,7 +102,8 @@ bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection, // If adjusted, make sure to check validity of the is_right/is_left classification below const constexpr auto MAX_STAGGERED_DISTANCE = 3; // debatable, but keep short to be on safe side - const auto angle = [](const RouteStep &step) { + const auto angle = [](const RouteStep &step) + { const auto &intersection = step.intersections.front(); const auto entry_bearing = util::bearing::reverse(intersection.bearings[intersection.in]); const auto exit_bearing = intersection.bearings[intersection.out]; diff --git a/src/engine/guidance/collapse_turns.cpp b/src/engine/guidance/collapse_turns.cpp index e15047fb2e1..7f40c7c510d 100644 --- a/src/engine/guidance/collapse_turns.cpp +++ b/src/engine/guidance/collapse_turns.cpp @@ -59,7 +59,8 @@ double findTotalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_ste // c // | // d - const auto use_total_angle = [&]() { + const auto use_total_angle = [&]() + { // only consider actual turns in combination: if (angularDeviation(total_angle, 180) < 0.5 * NARROW_TURN_ANGLE) return false; @@ -99,7 +100,8 @@ inline void handleSliproad(RouteStepIterator sliproad_step) { // find the next step after the sliproad step itself (this is not necessarily the next step, // since we might have to skip over traffic lights/node penalties) - auto next_step = [&sliproad_step]() { + auto next_step = [&sliproad_step]() + { auto next_step = findNextTurn(sliproad_step); while (isTrafficLightStep(*next_step)) { @@ -196,7 +198,8 @@ void AdjustToCombinedTurnStrategy::operator()(RouteStep &step_at_turn_location, : getTurnDirection(angle); // a turn that is a new name or straight (turn/continue) - const auto is_non_turn = [](const RouteStep &step) { + const auto is_non_turn = [](const RouteStep &step) + { return hasTurnType(step, TurnType::NewName) || (hasTurnType(step, TurnType::Turn) && hasModifier(step, DirectionModifier::Straight)) || @@ -307,7 +310,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location, // Used to control updating of the modifier based on turn direction bool update_modifier_for_turn_direction = true; - const auto calculate_turn_angle = [](const RouteStep &entry_step, const RouteStep &exit_step) { + const auto calculate_turn_angle = [](const RouteStep &entry_step, const RouteStep &exit_step) + { return util::bearing::angleBetween(entry_step.maneuver.bearing_before, exit_step.maneuver.bearing_after); }; @@ -316,7 +320,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location, const auto turn_angle = calculate_turn_angle(step_at_turn_location, transfer_from_step); const auto turn_direction = getTurnDirection(turn_angle); - const auto is_straight_step = [](const RouteStep &step) { + const auto is_straight_step = [](const RouteStep &step) + { return ((hasTurnType(step, TurnType::NewName) || hasTurnType(step, TurnType::Continue) || hasTurnType(step, TurnType::Suppressed) || hasTurnType(step, TurnType::Turn)) && (hasModifier(step, DirectionModifier::Straight) || @@ -324,7 +329,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location, hasModifier(step, DirectionModifier::SlightRight))); }; - const auto is_turn_step = [](const RouteStep &step) { + const auto is_turn_step = [](const RouteStep &step) + { return (hasTurnType(step, TurnType::Turn) || hasTurnType(step, TurnType::Continue) || hasTurnType(step, TurnType::NewName) || hasTurnType(step, TurnType::Suppressed)); }; diff --git a/src/engine/guidance/lane_processing.cpp b/src/engine/guidance/lane_processing.cpp index 105b3d53a0a..fb2aadfb17b 100644 --- a/src/engine/guidance/lane_processing.cpp +++ b/src/engine/guidance/lane_processing.cpp @@ -17,7 +17,8 @@ std::vector anticipateLaneChange(std::vector steps, const double min_distance_needed_for_lane_change) { // Lane anticipation works on contiguous ranges of short steps that have lane information - const auto is_short_has_lanes = [&](const RouteStep &step) { + const auto is_short_has_lanes = [&](const RouteStep &step) + { const auto has_lanes = step.intersections.front().lanes.lanes_in_turn > 0; if (!has_lanes) @@ -45,7 +46,8 @@ std::vector anticipateLaneChange(std::vector steps, std::vector quick_lanes_ranges; - const auto range_back_inserter = [&](StepIterRange range) { + const auto range_back_inserter = [&](StepIterRange range) + { if (std::distance(range.first, range.second) > 1) quick_lanes_ranges.push_back(std::move(range)); }; @@ -58,7 +60,8 @@ std::vector anticipateLaneChange(std::vector steps, // Walk backwards over all turns, constraining possible turn lanes. // Later turn lanes constrain earlier ones: we have to anticipate lane changes. - const auto constrain_lanes = [&](const StepIterRange &turns) { + const auto constrain_lanes = [&](const StepIterRange &turns) + { const std::reverse_iterator rev_first{turns.second}; const std::reverse_iterator rev_last{turns.first}; @@ -74,127 +77,135 @@ std::vector anticipateLaneChange(std::vector steps, // segment for a lane switch, but the total distance shouldn't be unlimited. double distance_to_constrained = 0.0; - util::for_each_pair(rev_first, rev_last, [&](RouteStep ¤t, RouteStep &previous) { - const auto current_inst = current.maneuver.instruction; - const auto current_lanes = current.intersections.front().lanes; - - // Constrain the previous turn's lanes - auto &previous_lanes = previous.intersections.front().lanes; - const auto previous_inst = previous.maneuver.instruction; - - // Lane mapping (N:M) from previous lanes (N) to current lanes (M), with: - // N > M, N > 1 fan-in situation, constrain N lanes to min(N,M) shared lanes - // otherwise nothing to constrain - const bool lanes_to_constrain = previous_lanes.lanes_in_turn > 1; - const bool lanes_fan_in = previous_lanes.lanes_in_turn > current_lanes.lanes_in_turn; - - // only prevent use lanes due to making all turns. don't make turns during curvy - // segments - if (previous_inst.type == TurnType::Suppressed) - distance_to_constrained += previous.distance; - else - distance_to_constrained = 0.; - - const auto lane_delta = previous_lanes.lanes_in_turn - current_lanes.lanes_in_turn; - const auto can_make_all_turns = - distance_to_constrained > lane_delta * min_distance_needed_for_lane_change; - - if (!lanes_to_constrain || !lanes_fan_in || can_make_all_turns) - return; - - // We do not have a mapping from lanes to lanes. All we have is the lanes in the turn - // and all the lanes at that situation. To perfectly handle lane anticipation in cases - // where lanes in the turn fan in but for example the overall lanes at that location - // fan out, we would have to know the asymmetric mapping of lanes. This is currently - // not possible at the moment. In the following we implement a heuristic instead. - const LaneID current_num_lanes_right_of_turn = current.NumLanesToTheRight(); - const LaneID current_num_lanes_left_of_turn = current.NumLanesToTheLeft(); - - // 0/ Tag keep straight with the next turn's direction if available - const auto previous_is_straight = - !isLeftTurn(previous_inst) && !isRightTurn(previous_inst); - - if (previous_is_straight) + util::for_each_pair( + rev_first, + rev_last, + [&](RouteStep ¤t, RouteStep &previous) { - if (isLeftTurn(current_inst) || is_straight_left.count(¤t) > 0) - is_straight_left.insert(&previous); - else if (isRightTurn(current_inst) || is_straight_right.count(¤t) > 0) - is_straight_right.insert(&previous); - } - - // 1/ How to anticipate left, right: - const auto anticipate_for_left_turn = [&] { - // Current turn is left turn, already keep left during previous turn. - // This implies constraining the rightmost lanes in previous step. - LaneID new_first_lane_from_the_right = - previous_lanes.first_lane_from_the_right // start from rightmost lane - + previous_lanes.lanes_in_turn // one past leftmost lane - - current_lanes.lanes_in_turn; // back number of new lanes - - // The leftmost target lanes might not be involved in the turn. Figure out - // how many lanes are to the left and not in the turn. - new_first_lane_from_the_right -= - std::min(current_num_lanes_left_of_turn, current_lanes.lanes_in_turn); - - previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right}; - }; - - const auto anticipate_for_right_turn = [&] { - // Current turn is right turn, already keep right during the previous turn. - // This implies constraining the leftmost lanes in the previous turn step. - LaneID new_first_lane_from_the_right = previous_lanes.first_lane_from_the_right; - - // The rightmost target lanes might not be involved in the turn. Figure out - // how many lanes are to the right and not in the turn. - new_first_lane_from_the_right += - std::min(current_num_lanes_right_of_turn, current_lanes.lanes_in_turn); - - previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right}; - }; - - // 2/ When to anticipate a left, right turn - if (isLeftTurn(current_inst)) - anticipate_for_left_turn(); - else if (isRightTurn(current_inst)) - anticipate_for_right_turn(); - else // keepStraight - { - // Heuristic: we do not have a from-lanes -> to-lanes mapping. What we use - // here instead in addition is the number of all lanes (not only the lanes - // in a turn): - // - // -v-v v-v- straight follows - // | | | | - // <- v v -> keep straight here - // | | - // <-| |-> - // - // A route from the top left to the bottom right here goes over a keep - // straight. If we handle all keep straights as right turns (in right-sided - // driving), we wrongly guide the user to the rightmost lanes in the first turn. - // Not only is this wrong but the opposite of what we expect. - // - // The following implements a heuristic to determine a keep straight's - // direction in relation to the next step. In the above example we would get: - // - // coming from right, going to left (in direction of way) -> handle as left turn - - if (is_straight_left.count(¤t) > 0) + const auto current_inst = current.maneuver.instruction; + const auto current_lanes = current.intersections.front().lanes; + + // Constrain the previous turn's lanes + auto &previous_lanes = previous.intersections.front().lanes; + const auto previous_inst = previous.maneuver.instruction; + + // Lane mapping (N:M) from previous lanes (N) to current lanes (M), with: + // N > M, N > 1 fan-in situation, constrain N lanes to min(N,M) shared lanes + // otherwise nothing to constrain + const bool lanes_to_constrain = previous_lanes.lanes_in_turn > 1; + const bool lanes_fan_in = + previous_lanes.lanes_in_turn > current_lanes.lanes_in_turn; + + // only prevent use lanes due to making all turns. don't make turns during curvy + // segments + if (previous_inst.type == TurnType::Suppressed) + distance_to_constrained += previous.distance; + else + distance_to_constrained = 0.; + + const auto lane_delta = previous_lanes.lanes_in_turn - current_lanes.lanes_in_turn; + const auto can_make_all_turns = + distance_to_constrained > lane_delta * min_distance_needed_for_lane_change; + + if (!lanes_to_constrain || !lanes_fan_in || can_make_all_turns) + return; + + // We do not have a mapping from lanes to lanes. All we have is the lanes in the + // turn and all the lanes at that situation. To perfectly handle lane anticipation + // in cases where lanes in the turn fan in but for example the overall lanes at that + // location fan out, we would have to know the asymmetric mapping of lanes. This is + // currently not possible at the moment. In the following we implement a heuristic + // instead. + const LaneID current_num_lanes_right_of_turn = current.NumLanesToTheRight(); + const LaneID current_num_lanes_left_of_turn = current.NumLanesToTheLeft(); + + // 0/ Tag keep straight with the next turn's direction if available + const auto previous_is_straight = + !isLeftTurn(previous_inst) && !isRightTurn(previous_inst); + + if (previous_is_straight) + { + if (isLeftTurn(current_inst) || is_straight_left.count(¤t) > 0) + is_straight_left.insert(&previous); + else if (isRightTurn(current_inst) || is_straight_right.count(¤t) > 0) + is_straight_right.insert(&previous); + } + + // 1/ How to anticipate left, right: + const auto anticipate_for_left_turn = [&] + { + // Current turn is left turn, already keep left during previous turn. + // This implies constraining the rightmost lanes in previous step. + LaneID new_first_lane_from_the_right = + previous_lanes.first_lane_from_the_right // start from rightmost lane + + previous_lanes.lanes_in_turn // one past leftmost lane + - current_lanes.lanes_in_turn; // back number of new lanes + + // The leftmost target lanes might not be involved in the turn. Figure out + // how many lanes are to the left and not in the turn. + new_first_lane_from_the_right -= + std::min(current_num_lanes_left_of_turn, current_lanes.lanes_in_turn); + + previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right}; + }; + + const auto anticipate_for_right_turn = [&] + { + // Current turn is right turn, already keep right during the previous turn. + // This implies constraining the leftmost lanes in the previous turn step. + LaneID new_first_lane_from_the_right = previous_lanes.first_lane_from_the_right; + + // The rightmost target lanes might not be involved in the turn. Figure out + // how many lanes are to the right and not in the turn. + new_first_lane_from_the_right += + std::min(current_num_lanes_right_of_turn, current_lanes.lanes_in_turn); + + previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right}; + }; + + // 2/ When to anticipate a left, right turn + if (isLeftTurn(current_inst)) anticipate_for_left_turn(); - else if (is_straight_right.count(¤t) > 0) - anticipate_for_right_turn(); - else // FIXME: right-sided driving + else if (isRightTurn(current_inst)) anticipate_for_right_turn(); - } - - if (previous_inst.type == TurnType::Suppressed && - current_inst.type == TurnType::Suppressed && previous.mode == current.mode && - previous_lanes == current_lanes) - { - previous.ElongateBy(current); - current.Invalidate(); - } - }); + else // keepStraight + { + // Heuristic: we do not have a from-lanes -> to-lanes mapping. What we use + // here instead in addition is the number of all lanes (not only the lanes + // in a turn): + // + // -v-v v-v- straight follows + // | | | | + // <- v v -> keep straight here + // | | + // <-| |-> + // + // A route from the top left to the bottom right here goes over a keep + // straight. If we handle all keep straights as right turns (in right-sided + // driving), we wrongly guide the user to the rightmost lanes in the first turn. + // Not only is this wrong but the opposite of what we expect. + // + // The following implements a heuristic to determine a keep straight's + // direction in relation to the next step. In the above example we would get: + // + // coming from right, going to left (in direction of way) -> handle as left turn + + if (is_straight_left.count(¤t) > 0) + anticipate_for_left_turn(); + else if (is_straight_right.count(¤t) > 0) + anticipate_for_right_turn(); + else // FIXME: right-sided driving + anticipate_for_right_turn(); + } + + if (previous_inst.type == TurnType::Suppressed && + current_inst.type == TurnType::Suppressed && previous.mode == current.mode && + previous_lanes == current_lanes) + { + previous.ElongateBy(current); + current.Invalidate(); + } + }); }; std::for_each(begin(quick_lanes_ranges), end(quick_lanes_ranges), constrain_lanes); diff --git a/src/engine/guidance/post_processing.cpp b/src/engine/guidance/post_processing.cpp index 0e29b2e0cb7..1e1abcf650e 100644 --- a/src/engine/guidance/post_processing.cpp +++ b/src/engine/guidance/post_processing.cpp @@ -77,7 +77,8 @@ void processRoundaboutExits(const RouteStepIterator begin, const RouteStepIterat return; } - const auto passes_exit_or_leaves_roundabout = [](auto const &step) { + const auto passes_exit_or_leaves_roundabout = [](auto const &step) + { return staysOnRoundabout(step.maneuver.instruction) || leavesRoundabout(step.maneuver.instruction); }; @@ -142,9 +143,8 @@ void processRoundaboutExits(const RouteStepIterator begin, const RouteStepIterat // instructions in between void processRoundaboutGroups(const std::pair &range) { - const auto leaves_roundabout = [](auto const &step) { - return leavesRoundabout(step.maneuver.instruction); - }; + const auto leaves_roundabout = [](auto const &step) + { return leavesRoundabout(step.maneuver.instruction); }; auto itr = range.first; while (itr != range.second) @@ -174,9 +174,8 @@ void processRoundaboutGroups(const std::pair handleRoundabouts(std::vector steps) { // check if a step has roundabout type - const auto has_roundabout_type = [](auto const &step) { - return hasRoundaboutType(step.maneuver.instruction); - }; + const auto has_roundabout_type = [](auto const &step) + { return hasRoundaboutType(step.maneuver.instruction); }; const auto first_roundabout_type = std::find_if(steps.begin(), steps.end(), has_roundabout_type); @@ -193,7 +192,8 @@ std::vector handleRoundabouts(std::vector steps) // this group by paradigm does might contain intermediate roundabout instructions, when they are // directly connected. Otherwise it will be a sequence containing everything from enter to exit. // If we already start on the roundabout, the first valid place will be steps.begin(). - const auto is_on_roundabout = [¤tly_on_roundabout](const auto &step) { + const auto is_on_roundabout = [¤tly_on_roundabout](const auto &step) + { if (currently_on_roundabout) { if (leavesRoundabout(step.maneuver.instruction)) @@ -327,10 +327,13 @@ void trimShortSegments(std::vector &steps, LegGeometry &geometry) } // and update the leg geometry indices for the removed entry - std::for_each(steps.begin(), steps.end(), [offset](RouteStep &step) { - step.geometry_begin -= offset; - step.geometry_end -= offset; - }); + std::for_each(steps.begin(), + steps.end(), + [offset](RouteStep &step) + { + step.geometry_begin -= offset; + step.geometry_end -= offset; + }); auto &first_step = steps.front(); auto bearing = first_bearing; @@ -645,16 +648,18 @@ void applyOverrides(const datafacade::BaseDataFacade &facade, auto step_to_update = std::find_if( current_step_it, route_iter, - [&leg_geometry, &via_node_coords](const auto &step) { + [&leg_geometry, &via_node_coords](const auto &step) + { util::Log(logDEBUG) << "Leg geom from " << step.geometry_begin << " to " << step.geometry_end << std::endl; // iterators over geometry of current step auto begin = leg_geometry.locations.begin() + step.geometry_begin; auto end = leg_geometry.locations.begin() + step.geometry_end; - auto via_match = std::find_if(begin, end, [&](const auto &location) { - return location == via_node_coords; - }); + auto via_match = std::find_if(begin, + end, + [&](const auto &location) + { return location == via_node_coords; }); if (via_match != end) { util::Log(logDEBUG) diff --git a/src/engine/guidance/verbosity_reduction.cpp b/src/engine/guidance/verbosity_reduction.cpp index a138524ebfe..761910b7f8e 100644 --- a/src/engine/guidance/verbosity_reduction.cpp +++ b/src/engine/guidance/verbosity_reduction.cpp @@ -15,19 +15,20 @@ std::vector suppressShortNameSegments(std::vector steps) return steps; // we remove only name changes that don't offer additional information - const auto name_change_without_lanes = [](const RouteStep &step) { - return hasTurnType(step, TurnType::NewName) && !hasLanes(step); - }; + const auto name_change_without_lanes = [](const RouteStep &step) + { return hasTurnType(step, TurnType::NewName) && !hasLanes(step); }; // check if the next step is not important enough to announce - const auto can_be_extended_to = [](const RouteStep &step) { + const auto can_be_extended_to = [](const RouteStep &step) + { const auto is_not_arrive = !hasWaypointType(step); const auto is_silent = !hasTurnType(step) || hasTurnType(step, TurnType::Suppressed); return is_not_arrive && is_silent; }; - const auto suppress = [](RouteStep &from_step, RouteStep &onto_step) { + const auto suppress = [](RouteStep &from_step, RouteStep &onto_step) + { from_step.ElongateBy(onto_step); onto_step.Invalidate(); }; @@ -36,28 +37,29 @@ std::vector suppressShortNameSegments(std::vector steps) // only available for a very short time const auto reduce_verbosity_if_possible = [suppress, can_be_extended_to](RouteStepIterator ¤t_turn_itr, - RouteStepIterator &previous_turn_itr) { - if (haveSameName(*previous_turn_itr, *current_turn_itr)) - suppress(*previous_turn_itr, *current_turn_itr); - else + RouteStepIterator &previous_turn_itr) + { + if (haveSameName(*previous_turn_itr, *current_turn_itr)) + suppress(*previous_turn_itr, *current_turn_itr); + else + { + // remember the location of the name change so we can advance the previous turn + const auto location_of_name_change = current_turn_itr; + auto distance = current_turn_itr->distance; + // sum up all distances that can be relevant to the name change + while (can_be_extended_to(*(current_turn_itr + 1)) && + distance < NAME_SEGMENT_CUTOFF_LENGTH) { - // remember the location of the name change so we can advance the previous turn - const auto location_of_name_change = current_turn_itr; - auto distance = current_turn_itr->distance; - // sum up all distances that can be relevant to the name change - while (can_be_extended_to(*(current_turn_itr + 1)) && - distance < NAME_SEGMENT_CUTOFF_LENGTH) - { - ++current_turn_itr; - distance += current_turn_itr->distance; - } - - if (distance < NAME_SEGMENT_CUTOFF_LENGTH) - suppress(*previous_turn_itr, *current_turn_itr); - else - previous_turn_itr = location_of_name_change; + ++current_turn_itr; + distance += current_turn_itr->distance; } - }; + + if (distance < NAME_SEGMENT_CUTOFF_LENGTH) + suppress(*previous_turn_itr, *current_turn_itr); + else + previous_turn_itr = location_of_name_change; + } + }; BOOST_ASSERT(!hasTurnType(steps.back()) && hasWaypointType(steps.back())); for (auto previous_turn_itr = steps.begin(), current_turn_itr = std::next(previous_turn_itr); diff --git a/src/engine/hint.cpp b/src/engine/hint.cpp index 16677a765e9..cce3ebe68fe 100644 --- a/src/engine/hint.cpp +++ b/src/engine/hint.cpp @@ -93,10 +93,10 @@ Hint Hint::FromBase64(const std::string &base64Hint) bool Hint::IsValid(const util::Coordinate new_input_coordinates, const datafacade::BaseDataFacade &facade) const { - const auto all_valid = - std::all_of(segment_hints.begin(), segment_hints.end(), [&](const auto &seg_hint) { - return seg_hint.IsValid(new_input_coordinates, facade); - }); + const auto all_valid = std::all_of(segment_hints.begin(), + segment_hints.end(), + [&](const auto &seg_hint) + { return seg_hint.IsValid(new_input_coordinates, facade); }); if (!all_valid) { return false; diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 1005b54dd39..fef9aac4e3f 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -50,7 +50,8 @@ void filterCandidates(const std::vector &coordinates, // sort by forward id, then by reverse id and then by distance std::sort(candidates.begin(), candidates.end(), - [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) { + [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) + { return lhs.phantom_node.forward_segment_id.id < rhs.phantom_node.forward_segment_id.id || (lhs.phantom_node.forward_segment_id.id == @@ -65,7 +66,8 @@ void filterCandidates(const std::vector &coordinates, auto new_end = std::unique(candidates.begin(), candidates.end(), - [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) { + [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) + { return lhs.phantom_node.forward_segment_id.id == rhs.phantom_node.forward_segment_id.id && lhs.phantom_node.reverse_segment_id.id == @@ -95,9 +97,8 @@ void filterCandidates(const std::vector &coordinates, // sort by distance to make pruning effective std::sort(candidates.begin(), candidates.end(), - [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) { - return lhs.distance < rhs.distance; - }); + [](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs) + { return lhs.distance < rhs.distance; }); } } @@ -133,7 +134,8 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, if (max_radius_map_matching > 0 && std::any_of(parameters.radiuses.begin(), parameters.radiuses.end(), - [&](const auto &radius) { + [&](const auto &radius) + { if (!radius) return false; return *radius > max_radius_map_matching; @@ -192,7 +194,8 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, tidied.parameters.radiuses.begin(), tidied.parameters.radiuses.end(), search_radiuses.begin(), - [default_radius = this->default_radius](const boost::optional &maybe_radius) { + [default_radius = this->default_radius](const boost::optional &maybe_radius) + { if (maybe_radius) { return *maybe_radius * RADIUS_MULTIPLIER; @@ -212,9 +215,8 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, filterCandidates(tidied.parameters.coordinates, candidates_lists); if (std::all_of(candidates_lists.begin(), candidates_lists.end(), - [](const std::vector &candidates) { - return candidates.empty(); - })) + [](const std::vector &candidates) + { return candidates.empty(); })) { return Error("NoSegment", std::string("Could not find a matching segment for any coordinate."), diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index 2a37824aa91..17f896b6d9e 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -251,7 +251,8 @@ std::vector getEdgeIndex(const std::vector &edges) // as the sort condition std::sort(sorted_edge_indexes.begin(), sorted_edge_indexes.end(), - [&edges](const std::size_t &left, const std::size_t &right) -> bool { + [&edges](const std::size_t &left, const std::size_t &right) -> bool + { return (edges[left].u != edges[right].u) ? edges[left].u < edges[right].u : edges[left].v < edges[right].v; }); @@ -430,9 +431,8 @@ void encodeVectorTile(const DataFacadeBase &facade, { vtzero::tile_builder tile; - const auto get_geometry_id = [&facade](auto edge) { - return facade.GetGeometryIndex(edge.forward_segment_id.id).id; - }; + const auto get_geometry_id = [&facade](auto edge) + { return facade.GetGeometryIndex(edge.forward_segment_id.id).id; }; // Convert tile coordinates into mercator coordinates double min_mercator_lon, min_mercator_lat, max_mercator_lon, max_mercator_lat; diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index fe072793664..a8a1b2ee6f8 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -137,7 +137,8 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm std::vector waypoint_legs(route_parameters.coordinates.size(), false); std::for_each(route_parameters.waypoints.begin(), route_parameters.waypoints.end(), - [&](const std::size_t waypoint_index) { + [&](const std::size_t waypoint_index) + { BOOST_ASSERT(waypoint_index < waypoint_legs.size()); waypoint_legs[waypoint_index] = true; }); @@ -156,22 +157,23 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm else { const auto all_in_same_component = - [](const std::vector &waypoint_candidates) { - return std::any_of(waypoint_candidates.front().begin(), - waypoint_candidates.front().end(), - // For each of the first possible phantoms, check if all other - // positions in the list have a phantom from the same component. - [&](const PhantomNode &phantom) { - const auto component_id = phantom.component.id; - return std::all_of( - std::next(waypoint_candidates.begin()), - std::end(waypoint_candidates), - [component_id](const PhantomNodeCandidates &candidates) { - return candidatesHaveComponent(candidates, - component_id); - }); - }); - }; + [](const std::vector &waypoint_candidates) + { + return std::any_of(waypoint_candidates.front().begin(), + waypoint_candidates.front().end(), + // For each of the first possible phantoms, check if all other + // positions in the list have a phantom from the same component. + [&](const PhantomNode &phantom) + { + const auto component_id = phantom.component.id; + return std::all_of( + std::next(waypoint_candidates.begin()), + std::end(waypoint_candidates), + [component_id](const PhantomNodeCandidates &candidates) { + return candidatesHaveComponent(candidates, component_id); + }); + }); + }; if (!all_in_same_component(snapped_phantoms)) { diff --git a/src/engine/routing_algorithms/alternative_path_mld.cpp b/src/engine/routing_algorithms/alternative_path_mld.cpp index cffd325a209..945aa15fe23 100644 --- a/src/engine/routing_algorithms/alternative_path_mld.cpp +++ b/src/engine/routing_algorithms/alternative_path_mld.cpp @@ -223,9 +223,8 @@ RandIt filterViaCandidatesByStretch(RandIt first, const auto stretch_weight_limit = (1. + parameters.kAtMostLongerBy) * from_alias(weight); - const auto over_weight_limit = [=](const auto via) { - return from_alias(via.weight) > stretch_weight_limit; - }; + const auto over_weight_limit = [=](const auto via) + { return from_alias(via.weight) > stretch_weight_limit; }; return std::remove_if(first, last, over_weight_limit); } @@ -298,13 +297,15 @@ RandIt filterPackedPathsByCellSharing(RandIt first, for (const auto &edge : shortest_path.path) cells.insert(get_cell(std::get<1>(edge))); - const auto over_sharing_limit = [&](const auto &packed) { + const auto over_sharing_limit = [&](const auto &packed) + { if (packed.path.empty()) { // don't remove routes with single-node (empty) path return false; } - const auto not_seen = [&](const PackedEdge edge) { + const auto not_seen = [&](const PackedEdge edge) + { const auto source_cell = get_cell(std::get<0>(edge)); const auto target_cell = get_cell(std::get<1>(edge)); return cells.count(source_cell) < 1 && cells.count(target_cell) < 1; @@ -364,7 +365,8 @@ RandIt filterPackedPathsByLocalOptimality(const WeightedViaNodePackedPath &path, BOOST_ASSERT(path.via.weight != INVALID_EDGE_WEIGHT); // node == parent_in_main_heap(parent_in_side_heap(v)) -> plateaux at `node` - const auto has_plateaux_at_node = [&](const NodeID node, const Heap &fst, const Heap &snd) { + const auto has_plateaux_at_node = [&](const NodeID node, const Heap &fst, const Heap &snd) + { BOOST_ASSERT(fst.WasInserted(node)); auto const parent = fst.GetData(node).parent; return snd.WasInserted(parent) && snd.GetData(parent).parent == node; @@ -374,7 +376,8 @@ RandIt filterPackedPathsByLocalOptimality(const WeightedViaNodePackedPath &path, // tree from t overlap. An edge is part of such a plateaux around `v` if: // v == parent_in_reverse_search(parent_in_forward_search(v)). // Here we calculate the last node on the plateaux in either direction. - const auto plateaux_end = [&](NodeID node, const Heap &fst, const Heap &snd) { + const auto plateaux_end = [&](NodeID node, const Heap &fst, const Heap &snd) + { BOOST_ASSERT(node != SPECIAL_NODEID); BOOST_ASSERT(fst.WasInserted(node)); BOOST_ASSERT(snd.WasInserted(node)); @@ -388,7 +391,8 @@ RandIt filterPackedPathsByLocalOptimality(const WeightedViaNodePackedPath &path, return node; }; - const auto is_not_locally_optimal = [&](const auto &packed) { + const auto is_not_locally_optimal = [&](const auto &packed) + { BOOST_ASSERT(packed.via.node != path.via.node); BOOST_ASSERT(packed.via.weight != INVALID_EDGE_WEIGHT); BOOST_ASSERT(packed.via.node != SPECIAL_NODEID); @@ -475,14 +479,16 @@ RandIt filterUnpackedPathsBySharing(RandIt first, nodes.insert(begin(shortest_path.nodes), end(shortest_path.nodes)); - const auto over_sharing_limit = [&](auto &unpacked) { + const auto over_sharing_limit = [&](auto &unpacked) + { if (unpacked.edges.empty()) { // don't remove routes with single-node (empty) path return false; } EdgeDuration total_duration = {0}; - const auto add_if_seen = [&](const EdgeDuration duration, const NodeID node) { + const auto add_if_seen = [&](const EdgeDuration duration, const NodeID node) + { auto node_duration = facade.GetNodeDuration(node); total_duration += node_duration; if (nodes.count(node) > 0) @@ -533,9 +539,8 @@ RandIt filterAnnotatedRoutesByStretch(RandIt first, const auto stretch_duration_limit = (1. + parameters.kAtMostLongerBy) * from_alias(shortest_route_duration); - const auto over_duration_limit = [=](const auto &route) { - return from_alias(route.duration()) > stretch_duration_limit; - }; + const auto over_duration_limit = [=](const auto &route) + { return from_alias(route.duration()) > stretch_duration_limit; }; return std::remove_if(first, last, over_duration_limit); } @@ -837,9 +842,9 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData &sear it = filterViaCandidatesByStretch(begin(candidate_vias), it, shortest_path_weight, parameters); // Pre-rank by weight; sharing filtering below then discards by similarity. - std::sort(begin(candidate_vias), it, [](const auto lhs, const auto rhs) { - return lhs.weight < rhs.weight; - }); + std::sort(begin(candidate_vias), + it, + [](const auto lhs, const auto rhs) { return lhs.weight < rhs.weight; }); // Filtered and ranked candidate range const auto candidate_vias_first = begin(candidate_vias); @@ -850,7 +855,8 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData &sear // The recursive path unpacking below destructs heaps. // We need to save all packed paths from the heaps upfront. - const auto extract_packed_path_from_heaps = [&](WeightedViaNode via) { + const auto extract_packed_path_from_heaps = [&](WeightedViaNode via) + { auto packed_path = retrievePackedPathFromHeap(forward_heap, reverse_heap, via.node); return WeightedViaNodePackedPath{via, std::move(packed_path)}; @@ -928,9 +934,8 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData &sear std::vector routes; routes.reserve(number_of_unpacked_paths); - const auto unpacked_path_to_route = [&](const WeightedViaNodeUnpackedPath &path) { - return extractRoute(facade, path.via.weight, endpoint_candidates, path.nodes, path.edges); - }; + const auto unpacked_path_to_route = [&](const WeightedViaNodeUnpackedPath &path) + { return extractRoute(facade, path.via.weight, endpoint_candidates, path.nodes, path.edges); }; std::transform(unpacked_paths_first, unpacked_paths_last, diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 598bd44492d..923c6e4f705 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -45,15 +45,16 @@ InternalRouteResult directShortestPathSearch(SearchEngineData &en unpacked_nodes.reserve(packed_leg.size()); unpacked_edges.reserve(packed_leg.size()); unpacked_nodes.push_back(packed_leg.front()); - ch::unpackPath(facade, - packed_leg.begin(), - packed_leg.end(), - [&unpacked_nodes, &unpacked_edges](std::pair &edge, - const auto &edge_id) { - BOOST_ASSERT(edge.first == unpacked_nodes.back()); - unpacked_nodes.push_back(edge.second); - unpacked_edges.push_back(edge_id); - }); + ch::unpackPath( + facade, + packed_leg.begin(), + packed_leg.end(), + [&unpacked_nodes, &unpacked_edges](std::pair &edge, const auto &edge_id) + { + BOOST_ASSERT(edge.first == unpacked_nodes.back()); + unpacked_nodes.push_back(edge.second); + unpacked_edges.push_back(edge_id); + }); } return extractRoute(facade, weight, endpoint_candidates, unpacked_nodes, unpacked_edges); diff --git a/src/engine/routing_algorithms/many_to_many_mld.cpp b/src/engine/routing_algorithms/many_to_many_mld.cpp index 500b7d2f4b3..e40c889ba14 100644 --- a/src/engine/routing_algorithms/many_to_many_mld.cpp +++ b/src/engine/routing_algorithms/many_to_many_mld.cpp @@ -95,7 +95,7 @@ void relaxOutgoingEdges( const DataFacade &facade, const typename SearchEngineData::ManyToManyQueryHeap::HeapNode &heapNode, typename SearchEngineData::ManyToManyQueryHeap &query_heap, - const Args &... args) + const Args &...args) { BOOST_ASSERT(!facade.ExcludeNode(heapNode.node)); @@ -280,49 +280,51 @@ oneToManySearch(SearchEngineData &engine_working_data, // Check if node is in the destinations list and update weights/durations auto update_values = - [&](NodeID node, EdgeWeight weight, EdgeDuration duration, EdgeDistance distance) { - auto candidates = target_nodes_index.equal_range(node); - for (auto it = candidates.first; it != candidates.second;) + [&](NodeID node, EdgeWeight weight, EdgeDuration duration, EdgeDistance distance) + { + auto candidates = target_nodes_index.equal_range(node); + for (auto it = candidates.first; it != candidates.second;) + { + std::size_t index; + EdgeWeight target_weight; + EdgeDuration target_duration; + EdgeDistance target_distance; + std::tie(index, target_weight, target_duration, target_distance) = it->second; + + const auto path_weight = weight + target_weight; + if (path_weight >= EdgeWeight{0}) { - std::size_t index; - EdgeWeight target_weight; - EdgeDuration target_duration; - EdgeDistance target_distance; - std::tie(index, target_weight, target_duration, target_distance) = it->second; - - const auto path_weight = weight + target_weight; - if (path_weight >= EdgeWeight{0}) - { - const auto path_duration = duration + target_duration; - const auto path_distance = distance + target_distance; + const auto path_duration = duration + target_duration; + const auto path_distance = distance + target_distance; - EdgeDistance nulldistance = {0}; - auto ¤t_distance = - distances_table.empty() ? nulldistance : distances_table[index]; + EdgeDistance nulldistance = {0}; + auto ¤t_distance = + distances_table.empty() ? nulldistance : distances_table[index]; - if (std::tie(path_weight, path_duration, path_distance) < - std::tie(weights_table[index], durations_table[index], current_distance)) - { - weights_table[index] = path_weight; - durations_table[index] = path_duration; - current_distance = path_distance; - middle_nodes_table[index] = node; - } - - // Remove node from destinations list - it = target_nodes_index.erase(it); - } - else + if (std::tie(path_weight, path_duration, path_distance) < + std::tie(weights_table[index], durations_table[index], current_distance)) { - ++it; + weights_table[index] = path_weight; + durations_table[index] = path_duration; + current_distance = path_distance; + middle_nodes_table[index] = node; } + + // Remove node from destinations list + it = target_nodes_index.erase(it); + } + else + { + ++it; } - }; + } + }; auto insert_node = [&](NodeID node, EdgeWeight initial_weight, EdgeDuration initial_duration, - EdgeDistance initial_distance) { + EdgeDistance initial_distance) + { if (target_nodes_index.count(node)) { // Source and target on the same edge node. If target is not reachable directly via diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index 32d71b9ad79..3bbf96c2273 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -83,7 +83,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, const bool use_timestamps = trace_timestamps.size() > 1; - const auto median_sample_time = [&] { + const auto median_sample_time = [&] + { if (use_timestamps) { return std::max(1u, getMedianSampleTime(trace_timestamps)); @@ -104,9 +105,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, std::transform(candidates_list[t].begin(), candidates_list[t].end(), emission_log_probabilities[t].begin(), - [&](const PhantomNodeWithDistance &candidate) { - return default_emission_log_probability(candidate.distance); - }); + [&](const PhantomNodeWithDistance &candidate) + { return default_emission_log_probability(candidate.distance); }); } } else @@ -118,22 +118,19 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, { map_matching::EmissionLogProbability emission_log_probability( *trace_gps_precision[t]); - std::transform( - candidates_list[t].begin(), - candidates_list[t].end(), - emission_log_probabilities[t].begin(), - [&emission_log_probability](const PhantomNodeWithDistance &candidate) { - return emission_log_probability(candidate.distance); - }); + std::transform(candidates_list[t].begin(), + candidates_list[t].end(), + emission_log_probabilities[t].begin(), + [&emission_log_probability](const PhantomNodeWithDistance &candidate) + { return emission_log_probability(candidate.distance); }); } else { std::transform(candidates_list[t].begin(), candidates_list[t].end(), emission_log_probabilities[t].begin(), - [&](const PhantomNodeWithDistance &candidate) { - return default_emission_log_probability(candidate.distance); - }); + [&](const PhantomNodeWithDistance &candidate) + { return default_emission_log_probability(candidate.distance); }); } } } @@ -158,7 +155,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, for (auto t = initial_timestamp + 1; t < candidates_list.size(); ++t) { - const auto step_time = [&] { + const auto step_time = [&] + { if (use_timestamps) { return trace_timestamps[t] - trace_timestamps[prev_unbroken_timestamps.back()]; @@ -169,7 +167,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, } }(); - const auto max_distance_delta = [&] { + const auto max_distance_delta = [&] + { if (use_timestamps) { return step_time * facade.GetMapMatchingMaxSpeed(); @@ -180,7 +179,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, } }(); - const bool gap_in_trace = [&]() { + const bool gap_in_trace = [&]() + { // use temporal information if available to determine a split // but do not determine split by timestamps if wasn't asked about it if (use_timestamps && allow_splitting) @@ -419,7 +419,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, util::for_each_pair( reconstructed_indices, [&trace_distance, &trace_coordinates](const std::pair &prev, - const std::pair &curr) { + const std::pair &curr) + { trace_distance += util::coordinate_calculation::greatCircleDistance( trace_coordinates[prev.first], trace_coordinates[curr.first]); }); diff --git a/src/engine/routing_algorithms/routing_base.cpp b/src/engine/routing_algorithms/routing_base.cpp index 6d5eec88ff9..29dec6bd437 100644 --- a/src/engine/routing_algorithms/routing_base.cpp +++ b/src/engine/routing_algorithms/routing_base.cpp @@ -25,9 +25,8 @@ std::vector getForwardLoopNodes(const PhantomEndpointCandidates &endpoin auto requires_loop = std::any_of(endpoint_candidates.target_phantoms.begin(), endpoint_candidates.target_phantoms.end(), - [&](const auto &target_phantom) { - return requiresForwardLoop(source_phantom, target_phantom); - }); + [&](const auto &target_phantom) + { return requiresForwardLoop(source_phantom, target_phantom); }); if (requires_loop) { res.push_back(source_phantom.forward_segment_id.id); @@ -57,9 +56,8 @@ std::vector getBackwardLoopNodes(const PhantomEndpointCandidates &endpoi auto requires_loop = std::any_of(endpoint_candidates.target_phantoms.begin(), endpoint_candidates.target_phantoms.end(), - [&](const auto &target_phantom) { - return requiresBackwardLoop(source_phantom, target_phantom); - }); + [&](const auto &target_phantom) + { return requiresBackwardLoop(source_phantom, target_phantom); }); if (requires_loop) { res.push_back(source_phantom.reverse_segment_id.id); @@ -86,7 +84,8 @@ PhantomEndpoints endpointsFromCandidates(const PhantomEndpointCandidates &candid { auto source_it = std::find_if(candidates.source_phantoms.begin(), candidates.source_phantoms.end(), - [&path](const auto &source_phantom) { + [&path](const auto &source_phantom) + { return path.front() == source_phantom.forward_segment_id.id || path.front() == source_phantom.reverse_segment_id.id; }); @@ -94,7 +93,8 @@ PhantomEndpoints endpointsFromCandidates(const PhantomEndpointCandidates &candid auto target_it = std::find_if(candidates.target_phantoms.begin(), candidates.target_phantoms.end(), - [&path](const auto &target_phantom) { + [&path](const auto &target_phantom) + { return path.back() == target_phantom.forward_segment_id.id || path.back() == target_phantom.reverse_segment_id.id; }); diff --git a/src/engine/routing_algorithms/routing_base_ch.cpp b/src/engine/routing_algorithms/routing_base_ch.cpp index a882dab2017..304fce6309d 100644 --- a/src/engine/routing_algorithms/routing_base_ch.cpp +++ b/src/engine/routing_algorithms/routing_base_ch.cpp @@ -19,9 +19,8 @@ void unpackEdge(const DataFacade &facade, unpackPath(facade, path.begin(), path.end(), - [&unpacked_path](const std::pair &edge, const auto & /* data */) { - unpacked_path.emplace_back(edge.first); - }); + [&unpacked_path](const std::pair &edge, const auto & /* data */) + { unpacked_path.emplace_back(edge.first); }); unpacked_path.emplace_back(to); } diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index 8171f7e7b8d..e2d133930da 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -35,9 +35,8 @@ std::vector generateTurns(const datafacade &facade, // it saves us a bunch of re-allocations during iteration. directed_graph.reserve(edges.size() * 2); - const auto get_geometry_id = [&facade](auto edge) { - return facade.GetGeometryIndex(edge.forward_segment_id.id).id; - }; + const auto get_geometry_id = [&facade](auto edge) + { return facade.GetGeometryIndex(edge.forward_segment_id.id).id; }; // To build a tile, we can only rely on the r-tree to quickly find all data visible within the // tile itself. The Rtree returns a series of segments that may or may not offer turns @@ -215,10 +214,10 @@ std::vector getTileTurns(const DataFacade &facade, // // would offer a backward edge at `b` to `a` (due to the oneway from a to b) // but could also offer a shortcut (b-c-a) from `b` to `a` which is longer. - EdgeID edge_id = facade.FindSmallestEdge( - approach_node, exit_node, [](const contractor::QueryEdge::EdgeData &data) { - return data.forward && !data.shortcut; - }); + EdgeID edge_id = facade.FindSmallestEdge(approach_node, + exit_node, + [](const contractor::QueryEdge::EdgeData &data) + { return data.forward && !data.shortcut; }); // Depending on how the graph is constructed, we might have to look for // a backwards edge instead. They're equivalent, just one is available for @@ -227,10 +226,10 @@ std::vector getTileTurns(const DataFacade &facade, // If we didn't find a forward edge, try for a backward one if (SPECIAL_EDGEID == edge_id) { - edge_id = facade.FindSmallestEdge( - exit_node, approach_node, [](const contractor::QueryEdge::EdgeData &data) { - return data.backward && !data.shortcut; - }); + edge_id = facade.FindSmallestEdge(exit_node, + approach_node, + [](const contractor::QueryEdge::EdgeData &data) + { return data.backward && !data.shortcut; }); } BOOST_ASSERT_MSG(edge_id == SPECIAL_EDGEID || !facade.GetEdgeData(edge_id).shortcut, diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index cfb29e6c103..a84fdbebe5a 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -151,7 +151,8 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N NodeID current_edge_source_coordinate_id = node_u; - const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id) { + const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id) + { if (edge_based_node_id == SPECIAL_NODEID) { return SegmentID{SPECIAL_SEGMENTID, false}; @@ -409,7 +410,8 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const WayRestrictionMap &way_re NodeID current_edge_source_coordinate_id = node_u; const EdgeData &forward_data = m_node_based_graph.GetEdgeData(eid); - const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id) { + const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id) + { if (edge_based_node_id == SPECIAL_NODEID) { return SegmentID{SPECIAL_SEGMENTID, false}; @@ -532,7 +534,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( TurnPenalty turn_duration_penalty; }; - auto const transfer_data = [&](const EdgeWithData &edge_with_data) { + auto const transfer_data = [&](const EdgeWithData &edge_with_data) + { m_edge_based_edge_list.push_back(edge_with_data.edge); turn_weight_penalties.push_back(edge_with_data.turn_weight_penalty); turn_duration_penalties.push_back(edge_with_data.turn_duration_penalty); @@ -568,7 +571,9 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( // First part of the pipeline generates iterator ranges of IDs in sets of GRAINSIZE tbb::filter> generator_stage( - tbb::filter_mode::serial_in_order, [&](tbb::flow_control &fc) { + tbb::filter_mode::serial_in_order, + [&](tbb::flow_control &fc) + { if (current_node < node_count) { auto next_node = std::min(current_node + GRAINSIZE, node_count); @@ -599,7 +604,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( const auto &turn_angle, const auto &road_legs_on_the_right, const auto &road_legs_on_the_left, - const auto &edge_geometries) { + const auto &edge_geometries) + { const auto &edge_data1 = m_node_based_graph.GetEdgeData(node_based_edge_from); const auto &edge_data2 = m_node_based_graph.GetEdgeData(node_based_edge_to); @@ -710,7 +716,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( // tbb::filter, EdgesPipelineBufferPtr> processor_stage( tbb::filter_mode::parallel, - [&](const tbb::blocked_range &intersection_node_range) { + [&](const tbb::blocked_range &intersection_node_range) + { auto buffer = std::make_shared(); buffer->nodes_processed = intersection_node_range.size(); @@ -795,16 +802,16 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( const auto turn = std::find_if(connected_roads.begin(), connected_roads.end(), - [edge = outgoing_edge.edge](const auto &road) { - return road.eid == edge; - }); + [edge = outgoing_edge.edge](const auto &road) + { return road.eid == edge; }); OSRM_ASSERT(turn != connected_roads.end(), m_coordinates[intersection_node]); std::vector road_legs_on_the_right; std::vector road_legs_on_the_left; - auto get_connected_road_info = [&](const auto &connected_edge) { + auto get_connected_road_info = [&](const auto &connected_edge) + { const auto &edge_data = m_node_based_graph.GetEdgeData(connected_edge.eid); @@ -1012,9 +1019,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( auto const has_unconditional = std::any_of(restrictions.begin(), restrictions.end(), - [](const auto &restriction) { - return restriction->IsUnconditional(); - }); + [](const auto &restriction) + { return restriction->IsUnconditional(); }); if (has_unconditional) continue; @@ -1120,7 +1126,9 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( util::Percent routing_progress(log, node_count); std::vector delayed_data; tbb::filter output_stage( - tbb::filter_mode::serial_in_order, [&](auto buffer) { + tbb::filter_mode::serial_in_order, + [&](auto buffer) + { routing_progress.PrintAddition(buffer->nodes_processed); m_connectivity_checksum = buffer->checksum.update_checksum(m_connectivity_checksum); @@ -1140,7 +1148,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( std::for_each(buffer->turn_to_ebn_map.begin(), buffer->turn_to_ebn_map.end(), - [&global_turn_to_ebn_map](const auto &p) { + [&global_turn_to_ebn_map](const auto &p) + { // TODO: log conflicts here global_turn_to_ebn_map.insert(p); }); @@ -1178,26 +1187,32 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( return std::vector{turn_edges.second.first, turn_edges.second.second}; }); - std::for_each(std::next(turns.begin()), turns.end(), [&](const auto &turn) { - std::vector> next_node_sequences; - const auto next_turn_edges = global_turn_to_ebn_map.equal_range(turn); - for (auto &node_sequence : node_sequences) - { - const auto found_it = std::find_if( - next_turn_edges.first, next_turn_edges.second, [&](const auto &turn_edges) { - const auto pre_turn_edge = turn_edges.second.first; - return (node_sequence.back() == pre_turn_edge); - }); - - if (found_it != next_turn_edges.second) - { - const auto post_turn_edge = found_it->second.second; - node_sequence.push_back(post_turn_edge); - next_node_sequences.push_back(std::move(node_sequence)); - } - } - node_sequences = std::move(next_node_sequences); - }); + std::for_each(std::next(turns.begin()), + turns.end(), + [&](const auto &turn) + { + std::vector> next_node_sequences; + const auto next_turn_edges = global_turn_to_ebn_map.equal_range(turn); + for (auto &node_sequence : node_sequences) + { + const auto found_it = std::find_if( + next_turn_edges.first, + next_turn_edges.second, + [&](const auto &turn_edges) + { + const auto pre_turn_edge = turn_edges.second.first; + return (node_sequence.back() == pre_turn_edge); + }); + + if (found_it != next_turn_edges.second) + { + const auto post_turn_edge = found_it->second.second; + node_sequence.push_back(post_turn_edge); + next_node_sequences.push_back(std::move(node_sequence)); + } + } + node_sequences = std::move(next_node_sequences); + }); for (const auto &node_sequence : node_sequences) { @@ -1237,7 +1252,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( // Now, update the turn_id property on every EdgeBasedEdge - it will equal the position in the // m_edge_based_edge_list array for each object. tbb::parallel_for(tbb::blocked_range(0, m_edge_based_edge_list.size()), - [this](const tbb::blocked_range &range) { + [this](const tbb::blocked_range &range) + { for (auto x = range.begin(), end = range.end(); x != end; ++x) { m_edge_based_edge_list[x].data.turn_id = x; diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index ab8e74ad337..bea4493906b 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -460,10 +460,10 @@ void ExtractionContainers::PrepareNodes() util::UnbufferedLog log; log << "Sorting all nodes ... " << std::flush; TIMER_START(sorting_nodes); - tbb::parallel_sort( - all_nodes_list.begin(), all_nodes_list.end(), [](const auto &left, const auto &right) { - return left.node_id < right.node_id; - }); + tbb::parallel_sort(all_nodes_list.begin(), + all_nodes_list.end(), + [](const auto &left, const auto &right) + { return left.node_id < right.node_id; }); TIMER_STOP(sorting_nodes); log << "ok, after " << TIMER_SEC(sorting_nodes) << "s"; } @@ -629,7 +629,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm // Remove all remaining edges. They are invalid because there are no corresponding nodes for // them. This happens when using osmosis with bbox or polygon to extract smaller areas. - auto markSourcesInvalid = [](InternalExtractorEdge &edge) { + auto markSourcesInvalid = [](InternalExtractorEdge &edge) + { util::Log(logDEBUG) << "Found invalid node reference " << edge.result.source; edge.result.source = SPECIAL_NODEID; edge.result.osm_source_id = SPECIAL_OSM_NODEID; @@ -743,7 +744,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm // Remove all remaining edges. They are invalid because there are no corresponding nodes for // them. This happens when using osmosis with bbox or polygon to extract smaller areas. - auto markTargetsInvalid = [](InternalExtractorEdge &edge) { + auto markTargetsInvalid = [](InternalExtractorEdge &edge) + { util::Log(logDEBUG) << "Found invalid node reference " << edge.result.target; edge.result.target = SPECIAL_NODEID; }; @@ -898,7 +900,8 @@ ExtractionContainers::ReferencedWays ExtractionContainers::IdentifyManeuverOverr << " maneuver overrides..."; TIMER_START(identify_maneuver_override_ways); - const auto mark_ids = [&](auto const &external_maneuver_override) { + const auto mark_ids = [&](auto const &external_maneuver_override) + { NodesOfWay dummy_segment{MAX_OSM_WAYID, {MAX_OSM_NODEID, MAX_OSM_NODEID}}; const auto &turn_path = external_maneuver_override.turn_path; maneuver_override_ways[turn_path.From()] = dummy_segment; @@ -918,7 +921,8 @@ ExtractionContainers::ReferencedWays ExtractionContainers::IdentifyManeuverOverr std::for_each( external_maneuver_overrides_list.begin(), external_maneuver_overrides_list.end(), mark_ids); - const auto set_ids = [&](size_t way_list_idx, auto const &way_id) { + const auto set_ids = [&](size_t way_list_idx, auto const &way_id) + { auto itr = maneuver_override_ways.find(way_id); if (itr != maneuver_override_ways.end()) { @@ -984,7 +988,8 @@ void ExtractionContainers::PrepareTrafficSignals( void ExtractionContainers::PrepareManeuverOverrides(const ReferencedWays &maneuver_override_ways) { - auto const osm_node_to_internal_nbn = [&](auto const osm_node) { + auto const osm_node_to_internal_nbn = [&](auto const osm_node) + { auto internal = mapExternalToInternalNodeID( used_node_id_list.begin(), used_node_id_list.end(), osm_node); if (internal == SPECIAL_NODEID) @@ -994,8 +999,9 @@ void ExtractionContainers::PrepareManeuverOverrides(const ReferencedWays &maneuv return internal; }; - const auto strings_to_turn_type_and_direction = [](const std::string &turn_string, - const std::string &direction_string) { + const auto strings_to_turn_type_and_direction = + [](const std::string &turn_string, const std::string &direction_string) + { auto result = std::make_pair(guidance::TurnType::MaxTurnType, guidance::DirectionModifier::MaxDirectionModifier); @@ -1059,7 +1065,8 @@ void ExtractionContainers::PrepareManeuverOverrides(const ReferencedWays &maneuv // Returns true on successful transformation, false in case of invalid references. // Later, the UnresolvedManeuverOverride will be converted into a final ManeuverOverride // once the edge-based-node IDs are generated by the edge-based-graph-factory - const auto transform = [&](const auto &external_type, auto &internal_type) { + const auto transform = [&](const auto &external_type, auto &internal_type) + { if (external_type.turn_path.Type() == TurnPathType::VIA_WAY_TURN_PATH) { auto const &external = external_type.turn_path.AsViaWayPath(); @@ -1092,11 +1099,12 @@ void ExtractionContainers::PrepareManeuverOverrides(const ReferencedWays &maneuv }; const auto transform_into_internal_types = - [&](const InputManeuverOverride &external_maneuver_override) { - UnresolvedManeuverOverride internal_maneuver_override; - if (transform(external_maneuver_override, internal_maneuver_override)) - internal_maneuver_overrides.push_back(std::move(internal_maneuver_override)); - }; + [&](const InputManeuverOverride &external_maneuver_override) + { + UnresolvedManeuverOverride internal_maneuver_override; + if (transform(external_maneuver_override, internal_maneuver_override)) + internal_maneuver_overrides.push_back(std::move(internal_maneuver_override)); + }; // Transforming the overrides into the dedicated internal types { @@ -1124,7 +1132,8 @@ ExtractionContainers::ReferencedWays ExtractionContainers::IdentifyRestrictionWa // Enter invalid IDs into the map to indicate that we want to find out about // nodes of these ways. - const auto mark_ids = [&](auto const &turn_restriction) { + const auto mark_ids = [&](auto const &turn_restriction) + { NodesOfWay dummy_segment{MAX_OSM_WAYID, {MAX_OSM_NODEID, MAX_OSM_NODEID}}; const auto &turn_path = turn_restriction.turn_path; restriction_ways[turn_path.From()] = dummy_segment; @@ -1142,7 +1151,8 @@ ExtractionContainers::ReferencedWays ExtractionContainers::IdentifyRestrictionWa std::for_each(restrictions_list.begin(), restrictions_list.end(), mark_ids); // Update the values for all ways already sporting SPECIAL_NODEID - const auto set_ids = [&](const size_t way_list_idx, auto const &way_id) { + const auto set_ids = [&](const size_t way_list_idx, auto const &way_id) + { auto itr = restriction_ways.find(way_id); if (itr != restriction_ways.end()) { @@ -1178,7 +1188,8 @@ ExtractionContainers::ReferencedTrafficSignals ExtractionContainers::IdentifyTra std::unordered_set bidirectional_signals; - const auto mark_signals = [&](auto const &traffic_signal) { + const auto mark_signals = [&](auto const &traffic_signal) + { if (traffic_signal.second == TrafficLightClass::DIRECTION_FORWARD || traffic_signal.second == TrafficLightClass::DIRECTION_REVERSE) { @@ -1193,7 +1204,8 @@ ExtractionContainers::ReferencedTrafficSignals ExtractionContainers::IdentifyTra std::for_each(external_traffic_signals.begin(), external_traffic_signals.end(), mark_signals); // Extract all the segments that lead up to unidirectional traffic signals. - const auto set_segments = [&](const size_t way_list_idx, auto const & /*unused*/) { + const auto set_segments = [&](const size_t way_list_idx, auto const & /*unused*/) + { const auto node_start_offset = used_node_id_list.begin() + way_node_id_offsets[way_list_idx]; const auto node_end_offset = @@ -1227,7 +1239,9 @@ ExtractionContainers::ReferencedTrafficSignals ExtractionContainers::IdentifyTra util::for_each_indexed(ways_list.cbegin(), ways_list.cend(), set_segments); util::for_each_pair( - signal_segments, [](const auto pair_a, const auto pair_b) { + signal_segments, + [](const auto pair_a, const auto pair_b) + { if (pair_a.first == pair_b.first) { // If a node is appearing multiple times in this map, then it's ambiguous. @@ -1252,7 +1266,8 @@ ExtractionContainers::ReferencedTrafficSignals ExtractionContainers::IdentifyTra void ExtractionContainers::PrepareRestrictions(const ReferencedWays &restriction_ways) { - auto const to_internal = [&](auto const osm_node) { + auto const to_internal = [&](auto const osm_node) + { auto internal = mapExternalToInternalNodeID( used_node_id_list.begin(), used_node_id_list.end(), osm_node); if (internal == SPECIAL_NODEID) @@ -1264,7 +1279,8 @@ void ExtractionContainers::PrepareRestrictions(const ReferencedWays &restriction // Transform an OSMRestriction (based on WayIDs) into an OSRM restriction (base on NodeIDs). // Returns true on successful transformation, false in case of invalid references. - const auto transform = [&](const auto &external_type, auto &internal_type) { + const auto transform = [&](const auto &external_type, auto &internal_type) + { if (external_type.turn_path.Type() == TurnPathType::VIA_WAY_TURN_PATH) { auto const &external = external_type.turn_path.AsViaWayPath(); @@ -1293,7 +1309,8 @@ void ExtractionContainers::PrepareRestrictions(const ReferencedWays &restriction return internal_type.Valid(); }; - const auto transform_into_internal_types = [&](InputTurnRestriction &external_restriction) { + const auto transform_into_internal_types = [&](InputTurnRestriction &external_restriction) + { TurnRestriction restriction; if (transform(external_restriction, restriction)) { diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index a48ffdb0277..634395457f3 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -442,9 +442,12 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting ExtractionRelationContainer relations; - const auto buffer_reader = [](osmium::io::Reader &reader) { + const auto buffer_reader = [](osmium::io::Reader &reader) + { return tbb::filter( - tbb::filter_mode::serial_in_order, [&reader](tbb::flow_control &fc) { + tbb::filter_mode::serial_in_order, + [&reader](tbb::flow_control &fc) + { if (auto buffer = reader.read()) { return std::make_shared(std::move(buffer)); @@ -466,7 +469,9 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting osmium_location_handler_type location_handler(location_cache); tbb::filter location_cacher( - tbb::filter_mode::serial_in_order, [&location_handler](SharedBuffer buffer) { + tbb::filter_mode::serial_in_order, + [&location_handler](SharedBuffer buffer) + { osmium::apply(buffer->begin(), buffer->end(), location_handler); return buffer; }); @@ -475,7 +480,8 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting tbb::filter buffer_transformer( tbb::filter_mode::parallel, // NOLINTNEXTLINE(performance-unnecessary-value-param) - [&](const SharedBuffer buffer) { + [&](const SharedBuffer buffer) + { ParsedBuffer parsed_buffer; parsed_buffer.buffer = buffer; scripting_environment.ProcessElements(*buffer, @@ -495,7 +501,9 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting unsigned number_of_restrictions = 0; unsigned number_of_maneuver_overrides = 0; tbb::filter buffer_storage( - tbb::filter_mode::serial_in_order, [&](const ParsedBuffer &parsed_buffer) { + tbb::filter_mode::serial_in_order, + [&](const ParsedBuffer &parsed_buffer) + { number_of_nodes += parsed_buffer.resulting_nodes.size(); // put parsed objects thru extractor callbacks for (const auto &result : parsed_buffer.resulting_nodes) @@ -524,7 +532,8 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting tbb::filter> buffer_relation_cache( tbb::filter_mode::parallel, // NOLINTNEXTLINE(performance-unnecessary-value-param) - [&](const SharedBuffer buffer) { + [&](const SharedBuffer buffer) + { if (!buffer) return std::shared_ptr{}; @@ -562,7 +571,8 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting tbb::filter, void> buffer_storage_relation( tbb::filter_mode::serial_in_order, // NOLINTNEXTLINE(performance-unnecessary-value-param) - [&](const std::shared_ptr parsed_relations) { + [&](const std::shared_ptr parsed_relations) + { number_of_relations += parsed_relations->GetRelationsNum(); relations.Merge(std::move(*parsed_relations)); }); @@ -749,7 +759,8 @@ EdgeID Extractor::BuildEdgeExpandedGraph( segregated_edges, turn_lane_map); - const auto create_edge_based_edges = [&]() { + const auto create_edge_based_edges = [&]() + { // scoped to release intermediate data structures right after the call RestrictionMap unconditional_node_restriction_map(restriction_graph); ConditionalRestrictionMap conditional_node_restriction_map(restriction_graph); @@ -795,9 +806,8 @@ void Extractor::BuildRTree(std::vector edge_based_node_seg auto start_point_count = std::accumulate(edge_based_node_segments.begin(), edge_based_node_segments.end(), 0, - [](const size_t so_far, const auto &segment) { - return so_far + (segment.is_startpoint ? 1 : 0); - }); + [](const size_t so_far, const auto &segment) + { return so_far + (segment.is_startpoint ? 1 : 0); }); if (start_point_count == 0) { throw util::exception("There are no snappable edges left after processing. Are you " diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index 3601fc40202..cfbd6493323 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -140,7 +140,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti InternalExtractorEdge::WeightData forward_weight_data; InternalExtractorEdge::WeightData backward_weight_data; - const auto toValueByEdgeOrByMeter = [&nodes](const double by_way, const double by_meter) { + const auto toValueByEdgeOrByMeter = [&nodes](const double by_way, const double by_meter) + { using Value = detail::ByEdgeOrByMeterValue; // get value by weight per edge if (by_way >= 0) @@ -194,7 +195,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti } } - const auto classStringToMask = [this](const std::string &class_name) { + const auto classStringToMask = [this](const std::string &class_name) + { auto iter = classes_map.find(class_name); if (iter == classes_map.end()) { @@ -212,7 +214,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti return iter->second; } }; - const auto classesToMask = [&](const auto &classes) { + const auto classesToMask = [&](const auto &classes) + { ClassData mask = 0; for (const auto &name_and_flag : classes) { @@ -232,7 +235,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti const ClassData forward_classes = classesToMask(parsed_way.forward_classes); const ClassData backward_classes = classesToMask(parsed_way.backward_classes); - const auto laneStringToDescription = [](const std::string &lane_string) -> TurnLaneDescription { + const auto laneStringToDescription = [](const std::string &lane_string) -> TurnLaneDescription + { if (lane_string.empty()) return {}; @@ -332,7 +336,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti road_classification.SetNumberOfLanes(std::max(road_deduced_num_lanes, // len(turn:lanes) road_classification.GetNumberOfLanes())); - const auto GetNameID = [this, &parsed_way](bool is_forward) -> NameID { + const auto GetNameID = [this, &parsed_way](bool is_forward) -> NameID + { const std::string &ref = is_forward ? parsed_way.forward_ref : parsed_way.backward_ref; // Get the unique identifier for the street name, destination, and ref const auto name_iterator = string_map.find(MapKey(parsed_way.name, @@ -418,30 +423,31 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti forward_classes, parsed_way.forward_travel_mode, parsed_way.is_left_hand_driving}); - util::for_each_pair( - nodes, [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) { - NodeBasedEdgeWithOSM edge = { - OSMNodeID{static_cast(first_node.ref())}, - OSMNodeID{static_cast(last_node.ref())}, - {0}, // weight - {0}, // duration - {0}, // distance - {}, // geometry id - static_cast(annotation_data_id), - {true, - in_backward_direction && !split_edge, - split_edge, - parsed_way.roundabout, - parsed_way.circular, - parsed_way.is_startpoint, - parsed_way.forward_restricted, - road_classification, - parsed_way.highway_turn_classification, - parsed_way.access_turn_classification}}; - - external_memory.all_edges_list.push_back( - InternalExtractorEdge(edge, forward_weight_data, forward_duration_data, {})); - }); + util::for_each_pair(nodes, + [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) + { + NodeBasedEdgeWithOSM edge = { + OSMNodeID{static_cast(first_node.ref())}, + OSMNodeID{static_cast(last_node.ref())}, + {0}, // weight + {0}, // duration + {0}, // distance + {}, // geometry id + static_cast(annotation_data_id), + {true, + in_backward_direction && !split_edge, + split_edge, + parsed_way.roundabout, + parsed_way.circular, + parsed_way.is_startpoint, + parsed_way.forward_restricted, + road_classification, + parsed_way.highway_turn_classification, + parsed_way.access_turn_classification}}; + + external_memory.all_edges_list.push_back(InternalExtractorEdge( + edge, forward_weight_data, forward_duration_data, {})); + }); } if (in_backward_direction && (!in_forward_direction || split_edge)) @@ -452,38 +458,38 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti backward_classes, parsed_way.backward_travel_mode, parsed_way.is_left_hand_driving}); - util::for_each_pair( - nodes, [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) { - NodeBasedEdgeWithOSM edge = { - OSMNodeID{static_cast(first_node.ref())}, - OSMNodeID{static_cast(last_node.ref())}, - {0}, // weight - {0}, // duration - {0}, // distance - {}, // geometry id - static_cast(annotation_data_id), - {false, - true, - split_edge, - parsed_way.roundabout, - parsed_way.circular, - parsed_way.is_startpoint, - parsed_way.backward_restricted, - road_classification, - parsed_way.highway_turn_classification, - parsed_way.access_turn_classification}}; - - external_memory.all_edges_list.push_back( - InternalExtractorEdge(edge, backward_weight_data, backward_duration_data, {})); - }); + util::for_each_pair(nodes, + [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) + { + NodeBasedEdgeWithOSM edge = { + OSMNodeID{static_cast(first_node.ref())}, + OSMNodeID{static_cast(last_node.ref())}, + {0}, // weight + {0}, // duration + {0}, // distance + {}, // geometry id + static_cast(annotation_data_id), + {false, + true, + split_edge, + parsed_way.roundabout, + parsed_way.circular, + parsed_way.is_startpoint, + parsed_way.backward_restricted, + road_classification, + parsed_way.highway_turn_classification, + parsed_way.access_turn_classification}}; + + external_memory.all_edges_list.push_back(InternalExtractorEdge( + edge, backward_weight_data, backward_duration_data, {})); + }); } std::transform(nodes.begin(), nodes.end(), std::back_inserter(external_memory.used_node_id_list), - [](const osmium::NodeRef &ref) { - return OSMNodeID{static_cast(ref.ref())}; - }); + [](const osmium::NodeRef &ref) + { return OSMNodeID{static_cast(ref.ref())}; }); auto way_id = OSMWayID{static_cast(input_way.id())}; external_memory.ways_list.push_back(way_id); diff --git a/src/extractor/graph_compressor.cpp b/src/extractor/graph_compressor.cpp index cee5afe929a..ba1e8bebc4a 100644 --- a/src/extractor/graph_compressor.cpp +++ b/src/extractor/graph_compressor.cpp @@ -37,7 +37,8 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, // restriction path. std::unordered_set incompressible_via_nodes; - const auto remember_via_nodes = [&](const auto &restriction) { + const auto remember_via_nodes = [&](const auto &restriction) + { if (restriction.turn_path.Type() == TurnPathType::VIA_NODE_TURN_PATH) { incompressible_via_nodes.insert(restriction.turn_path.AsViaNodePath().via); @@ -186,16 +187,17 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, */ const auto selectAnnotation = [&node_data_container](const AnnotationID front_annotation, - const AnnotationID back_annotation) { - // A lane has tags: u - (front) - v - (back) - w - // During contraction, we keep only one of the tags. Usually the one closer - // to the intersection is preferred. If its empty, however, we keep the - // non-empty one - if (node_data_container[back_annotation].lane_description_id == - INVALID_LANE_DESCRIPTIONID) - return front_annotation; - return back_annotation; - }; + const AnnotationID back_annotation) + { + // A lane has tags: u - (front) - v - (back) - w + // During contraction, we keep only one of the tags. Usually the one closer + // to the intersection is preferred. If its empty, however, we keep the + // non-empty one + if (node_data_container[back_annotation].lane_description_id == + INVALID_LANE_DESCRIPTIONID) + return front_annotation; + return back_annotation; + }; graph.GetEdgeData(forward_e1).annotation_data = selectAnnotation( fwd_edge_data1.annotation_data, fwd_edge_data2.annotation_data); @@ -250,10 +252,10 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, roads_on_the_left); scripting_environment.ProcessTurn(extraction_turn); - auto update_direction_penalty = [&extraction_turn, weight_multiplier]( - bool signal, - EdgeDuration &duration_penalty, - EdgeWeight &weight_penalty) { + auto update_direction_penalty = + [&extraction_turn, weight_multiplier]( + bool signal, EdgeDuration &duration_penalty, EdgeWeight &weight_penalty) + { if (signal) { duration_penalty = to_alias(extraction_turn.duration * @@ -303,7 +305,8 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, auto apply_e2_to_e1 = [&graph](EdgeID edge1, EdgeID edge2, EdgeWeight &weight_penalty, - EdgeDuration &duration_penalty) { + EdgeDuration &duration_penalty) + { auto &edge1_data = graph.GetEdgeData(edge1); const auto &edge2_data = graph.GetEdgeData(edge2); edge1_data.weight += edge2_data.weight; @@ -345,7 +348,8 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, // Set a dummy empty penalty weight if opposite value exists. auto set_dummy_penalty = [](EdgeWeight &weight_penalty, EdgeDuration &duration_penalty, - EdgeWeight &other_weight_penalty) { + EdgeWeight &other_weight_penalty) + { if (weight_penalty == INVALID_EDGE_WEIGHT && other_weight_penalty != INVALID_EDGE_WEIGHT) { diff --git a/src/extractor/intersection/coordinate_extractor.cpp b/src/extractor/intersection/coordinate_extractor.cpp index 95a12f61a85..fa71031aa24 100644 --- a/src/extractor/intersection/coordinate_extractor.cpp +++ b/src/extractor/intersection/coordinate_extractor.cpp @@ -88,9 +88,8 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate( std::vector coordinates) const { // check if the coordinate is equal to the interseciton coordinate - const auto not_same_as_start = [&](const util::Coordinate coordinate) { - return node_coordinates[traversed_in_reverse ? to_node : intersection_node] != coordinate; - }; + const auto not_same_as_start = [&](const util::Coordinate coordinate) + { return node_coordinates[traversed_in_reverse ? to_node : intersection_node] != coordinate; }; // this is only used for debug purposes in assertions. We don't want warnings about it (void)not_same_as_start; @@ -176,7 +175,8 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate( * information on the very first turn angle (requires knowledge about previous road) and the * respective lane widths. */ - const bool first_coordinate_is_far_away = [&first_distance, considered_lanes]() { + const bool first_coordinate_is_far_away = [&first_distance, considered_lanes]() + { const auto required_distance = considered_lanes * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES; return first_distance > required_distance; @@ -256,7 +256,8 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate( * possible negative: * http://www.openstreetmap.org/search?query=52.514503%2013.32252#map=19/52.51450/13.32252 */ - const auto straight_distance_and_index = [&]() { + const auto straight_distance_and_index = [&]() + { auto straight_distance = segment_distances[1]; std::size_t index; @@ -276,7 +277,8 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate( const auto straight_distance = straight_distance_and_index.second; const auto straight_index = straight_distance_and_index.first; - const bool starts_of_without_turn = [&]() { + const bool starts_of_without_turn = [&]() + { return straight_distance >= considered_lanes * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES; }(); @@ -435,7 +437,8 @@ CoordinateExtractor::ExtractCoordinateAtLength(const double distance, auto length_cache_itr = length_cache.begin() + 1; // find the end of the segment containing the coordinate which is at least distance away const auto find_coordinate_at_distance = [distance, &accumulated_distance, &length_cache_itr]( - const util::Coordinate /*coordinate*/) mutable { + const util::Coordinate /*coordinate*/) mutable + { const auto result = (accumulated_distance + *length_cache_itr) >= distance; if (!result) { @@ -468,18 +471,19 @@ util::Coordinate CoordinateExtractor::ExtractCoordinateAtLength( // checks (via its state) for an accumulated distance const auto coordinate_at_distance = [distance, &accumulated_distance, last_coordinate = coordinates.front()]( - const util::Coordinate coordinate) mutable { - const double segment_distance = - util::coordinate_calculation::greatCircleDistance(last_coordinate, coordinate); - const auto result = (accumulated_distance + segment_distance) >= distance; - if (!result) - { - accumulated_distance += segment_distance; - last_coordinate = coordinate; - } + const util::Coordinate coordinate) mutable + { + const double segment_distance = + util::coordinate_calculation::greatCircleDistance(last_coordinate, coordinate); + const auto result = (accumulated_distance + segment_distance) >= distance; + if (!result) + { + accumulated_distance += segment_distance; + last_coordinate = coordinate; + } - return result; - }; + return result; + }; // find the begin of the segment containing the coordinate const auto coordinate_after = @@ -514,9 +518,8 @@ util::Coordinate CoordinateExtractor::GetCoordinateCloseToTurn(const NodeID from // the compressed edges contain node ids, we transfer them to coordinates accessing the // node_coordinates array const auto compressedGeometryToCoordinate = - [this](const CompressedEdgeContainer::OnewayCompressedEdge &compressed_edge) { - return node_coordinates[compressed_edge.node_id]; - }; + [this](const CompressedEdgeContainer::OnewayCompressedEdge &compressed_edge) + { return node_coordinates[compressed_edge.node_id]; }; // return the first coordinate that is reasonably far away from the start node const util::Coordinate start_coordinate = node_coordinates[start_node]; @@ -526,10 +529,11 @@ util::Coordinate CoordinateExtractor::GetCoordinateCloseToTurn(const NodeID from // away from the first entry const auto far_enough_away = [start_coordinate, compressedGeometryToCoordinate]( - const CompressedEdgeContainer::OnewayCompressedEdge &compressed_edge) { - return util::coordinate_calculation::greatCircleDistance( - compressedGeometryToCoordinate(compressed_edge), start_coordinate) > 1; - }; + const CompressedEdgeContainer::OnewayCompressedEdge &compressed_edge) + { + return util::coordinate_calculation::greatCircleDistance( + compressedGeometryToCoordinate(compressed_edge), start_coordinate) > 1; + }; // find the first coordinate, that is at least unequal to the begin of the edge if (traversed_in_reverse) @@ -614,7 +618,8 @@ CoordinateExtractor::GetMaxDeviation(std::vector::const_iterat const util::Coordinate straight_end) const { // compute the deviation of a single coordinate from a straight line - auto get_single_deviation = [&](const util::Coordinate coordinate) { + auto get_single_deviation = [&](const util::Coordinate coordinate) + { // find the projected coordinate auto coord_between = util::coordinate_calculation::projectPointOnSegment( straight_begin, straight_end, coordinate) @@ -626,10 +631,11 @@ CoordinateExtractor::GetMaxDeviation(std::vector::const_iterat // note: we don't accumulate here but rather compute the maximum. The functor passed here is not // summing up anything. - return std::accumulate( - range_begin, range_end, 0.0, [&](const double current, const util::Coordinate coordinate) { - return std::max(current, get_single_deviation(coordinate)); - }); + return std::accumulate(range_begin, + range_end, + 0.0, + [&](const double current, const util::Coordinate coordinate) + { return std::max(current, get_single_deviation(coordinate)); }); } bool CoordinateExtractor::IsCurve(const std::vector &coordinates, @@ -645,7 +651,8 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat return true; // TODO we might have to fix this to better compensate for errors due to repeated coordinates - const bool takes_an_actual_turn = [&coordinates]() { + const bool takes_an_actual_turn = [&coordinates]() + { const auto begin_bearing = util::coordinate_calculation::bearing(coordinates[0], coordinates[1]); const auto end_bearing = util::coordinate_calculation::bearing( @@ -660,7 +667,8 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat const auto get_deviation = [](const util::Coordinate line_start, const util::Coordinate line_end, - const util::Coordinate point) { + const util::Coordinate point) + { // find the projected coordinate auto coord_between = util::coordinate_calculation::projectPointOnSegment(line_start, line_end, point).second; @@ -669,19 +677,22 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat }; // a curve needs to be on one side of the coordinate array - const bool all_same_side = [&]() { + const bool all_same_side = [&]() + { if (coordinates.size() <= 3) return true; const bool ccw = util::coordinate_calculation::isCCW( coordinates.front(), coordinates.back(), coordinates[1]); - return std::all_of( - coordinates.begin() + 2, coordinates.end() - 1, [&](const util::Coordinate coordinate) { - const bool compare_ccw = util::coordinate_calculation::isCCW( - coordinates.front(), coordinates.back(), coordinate); - return ccw == compare_ccw; - }); + return std::all_of(coordinates.begin() + 2, + coordinates.end() - 1, + [&](const util::Coordinate coordinate) + { + const bool compare_ccw = util::coordinate_calculation::isCCW( + coordinates.front(), coordinates.back(), coordinate); + return ccw == compare_ccw; + }); }(); if (!all_same_side) @@ -694,13 +705,16 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat double maximum_deviation = 0; std::tie(has_up_down_deviation, maximum_deviation_index, maximum_deviation) = - [&coordinates, get_deviation]() -> std::tuple { - const auto increasing = [&](const util::Coordinate lhs, const util::Coordinate rhs) { + [&coordinates, get_deviation]() -> std::tuple + { + const auto increasing = [&](const util::Coordinate lhs, const util::Coordinate rhs) + { return get_deviation(coordinates.front(), coordinates.back(), lhs) < get_deviation(coordinates.front(), coordinates.back(), rhs); }; - const auto decreasing = [&](const util::Coordinate lhs, const util::Coordinate rhs) { + const auto decreasing = [&](const util::Coordinate lhs, const util::Coordinate rhs) + { return get_deviation(coordinates.front(), coordinates.back(), lhs) > get_deviation(coordinates.front(), coordinates.back(), rhs); }; @@ -744,7 +758,8 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat BOOST_ASSERT(coordinates.size() >= 3); // Compute all turn angles along the road - const auto turn_angles = [coordinates]() { + const auto turn_angles = [coordinates]() + { std::vector turn_angles; turn_angles.reserve(coordinates.size() - 2); for (std::size_t index = 0; index + 2 < coordinates.size(); ++index) @@ -755,10 +770,9 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat return turn_angles; }(); - const bool curve_is_valid = [&turn_angles, - &segment_distances, - &segment_length, - &considered_lane_width]() { + const bool curve_is_valid = + [&turn_angles, &segment_distances, &segment_length, &considered_lane_width]() + { // internal state for our lamdae bool last_was_straight = false; // a turn angle represents two segments between three coordinates. We initialize the @@ -769,8 +783,9 @@ bool CoordinateExtractor::IsCurve(const std::vector &coordinat // every call to the lamda requires a call to the distances. They need to be aligned BOOST_ASSERT(segment_distances.size() == turn_angles.size() + 2); - const auto detect_invalid_curve = [&](const double previous_angle, - const double current_angle) { + const auto detect_invalid_curve = + [&](const double previous_angle, const double current_angle) + { const auto both_actually_turn = (util::angularDeviation(previous_angle, STRAIGHT_ANGLE) > FUZZY_ANGLE_DIFFERENCE) && (util::angularDeviation(current_angle, STRAIGHT_ANGLE) > FUZZY_ANGLE_DIFFERENCE); @@ -822,7 +837,8 @@ bool CoordinateExtractor::IsDirectOffset(const std::vector &co const std::uint8_t considered_lanes) const { // check if a given length is with half a lane of the assumed lane offset - const auto IsCloseToLaneDistance = [considered_lanes](const double width) { + const auto IsCloseToLaneDistance = [considered_lanes](const double width) + { // a road usually is connected to the middle of the lanes. So the lane-offset has to // consider half to road const auto lane_offset = 0.5 * considered_lanes * ASSUMED_LANE_WIDTH; @@ -856,7 +872,8 @@ bool CoordinateExtractor::IsDirectOffset(const std::vector &co const auto segment_offset_past_thirty_meters = std::find_if(segment_distances.begin() + offset_index, segment_distances.end(), - [accumulated_distance = 0.](const auto value) mutable { + [accumulated_distance = 0.](const auto value) mutable + { accumulated_distance += value; return value >= 30; }); @@ -888,20 +905,21 @@ CoordinateExtractor::PrepareLengthCache(const std::vector &coo // sentinel // NOLINTNEXTLINE(bugprone-unused-return-value) // We're only interested in the side effect of the lambda, not the return value - [[maybe_unused]] auto _ = std::find_if( - std::next(std::begin(coordinates)), - std::end(coordinates), - [last_coordinate = coordinates.front(), - limit, - &segment_distances, - accumulated_distance = 0.](const util::Coordinate current_coordinate) mutable { - const auto distance = util::coordinate_calculation::greatCircleDistance( - last_coordinate, current_coordinate); - accumulated_distance += distance; - last_coordinate = current_coordinate; - segment_distances.push_back(distance); - return accumulated_distance >= limit; - }); + [[maybe_unused]] auto _ = + std::find_if(std::next(std::begin(coordinates)), + std::end(coordinates), + [last_coordinate = coordinates.front(), + limit, + &segment_distances, + accumulated_distance = 0.](const util::Coordinate current_coordinate) mutable + { + const auto distance = util::coordinate_calculation::greatCircleDistance( + last_coordinate, current_coordinate); + accumulated_distance += distance; + last_coordinate = current_coordinate; + segment_distances.push_back(distance); + return accumulated_distance >= limit; + }); return segment_distances; } @@ -916,19 +934,18 @@ CoordinateExtractor::TrimCoordinatesToLength(std::vector coord double distance_to_current_coordinate = 0; std::size_t coordinate_index = 0; - const auto compute_length = - [&coordinate_index, &distance_to_current_coordinate, &coordinates]() { - const auto new_distance = - distance_to_current_coordinate + - util::coordinate_calculation::greatCircleDistance(coordinates[coordinate_index - 1], - coordinates[coordinate_index]); - return new_distance; - }; - - const auto read_length_from_cache = [&length_cache, &coordinate_index]() { - return length_cache[coordinate_index]; + const auto compute_length = [&coordinate_index, &distance_to_current_coordinate, &coordinates]() + { + const auto new_distance = + distance_to_current_coordinate + + util::coordinate_calculation::greatCircleDistance(coordinates[coordinate_index - 1], + coordinates[coordinate_index]); + return new_distance; }; + const auto read_length_from_cache = [&length_cache, &coordinate_index]() + { return length_cache[coordinate_index]; }; + bool use_cache = !length_cache.empty(); if (use_cache && length_cache.back() < desired_length && coordinates.size() >= 2) @@ -1044,8 +1061,9 @@ CoordinateExtractor::SampleCoordinates(const std::vector &coor double carry_length = 0., total_length = 0.; // interpolate coordinates as long as we are not past the desired length - const auto add_samples_until_length_limit = [&](const util::Coordinate previous_coordinate, - const util::Coordinate current_coordinate) { + const auto add_samples_until_length_limit = + [&](const util::Coordinate previous_coordinate, const util::Coordinate current_coordinate) + { // pretend to have found an element and stop the sampling if (total_length > max_sample_length) return true; diff --git a/src/extractor/intersection/intersection_analysis.cpp b/src/extractor/intersection/intersection_analysis.cpp index e73b90d1d80..e1b5ad3a4fd 100644 --- a/src/extractor/intersection/intersection_analysis.cpp +++ b/src/extractor/intersection/intersection_analysis.cpp @@ -67,9 +67,8 @@ getEdgeCoordinates(const extractor::CompressedEdgeContainer &compressed_geometri std::transform(geometry.begin(), geometry.end(), std::back_inserter(result), - [&node_coordinates](const auto &compressed_edge) { - return node_coordinates[compressed_edge.node_id]; - }); + [&node_coordinates](const auto &compressed_edge) + { return node_coordinates[compressed_edge.node_id]; }); // filter duplicated coordinates result.erase(std::unique(result.begin(), result.end()), result.end()); @@ -95,7 +94,8 @@ double findClosestOppositeBearing(const IntersectionEdgeGeometries &edge_geometr const auto min = std::min_element( edge_geometries.begin(), edge_geometries.end(), - [bearing = util::bearing::reverse(bearing)](const auto &lhs, const auto &rhs) { + [bearing = util::bearing::reverse(bearing)](const auto &lhs, const auto &rhs) + { return util::angularDeviation(lhs.perceived_bearing, bearing) < util::angularDeviation(rhs.perceived_bearing, bearing); }); @@ -239,9 +239,10 @@ getIntersectionOutgoingGeometries(const util::NodeBasedDynamicGraph &graph, } // Sort edges in the clockwise bearings order - std::sort(edge_geometries.begin(), edge_geometries.end(), [](const auto &lhs, const auto &rhs) { - return lhs.perceived_bearing < rhs.perceived_bearing; - }); + std::sort(edge_geometries.begin(), + edge_geometries.end(), + [](const auto &lhs, const auto &rhs) + { return lhs.perceived_bearing < rhs.perceived_bearing; }); return edge_geometries; } } // namespace @@ -317,9 +318,8 @@ getIntersectionGeometries(const util::NodeBasedDynamicGraph &graph, neighbor_geometries.begin(), std::find_if(neighbor_geometries.begin(), neighbor_geometries.end(), - [&graph, &intersection_node](const auto &road) { - return graph.GetTarget(road.eid) == intersection_node; - })); + [&graph, &intersection_node](const auto &road) + { return graph.GetTarget(road.eid) == intersection_node; })); BOOST_ASSERT(static_cast(neighbor_curr) != neighbor_geometries.size()); const auto neighbor_prev = (neighbor_curr + neighbor_edges - 1) % neighbor_edges; const auto neighbor_next = (neighbor_curr + 1) % neighbor_edges; @@ -403,10 +403,11 @@ getIntersectionGeometries(const util::NodeBasedDynamicGraph &graph, inline auto findEdge(const IntersectionEdgeGeometries &geometries, const EdgeID &edge) { - const auto it = std::lower_bound( - geometries.begin(), geometries.end(), edge, [](const auto &geometry, const auto edge) { - return geometry.eid < edge; - }); + const auto it = + std::lower_bound(geometries.begin(), + geometries.end(), + edge, + [](const auto &geometry, const auto edge) { return geometry.eid < edge; }); BOOST_ASSERT(it != geometries.end() && it->eid == edge); return it; } @@ -425,9 +426,10 @@ template bool isTurnRestricted(const RestrictionsRange &restrictions, const NodeID to) { // Check if any of the restrictions would prevent a turn to 'to' - return std::any_of(restrictions.begin(), restrictions.end(), [&to](const auto &restriction) { - return restriction->IsTurnRestricted(to); - }); + return std::any_of(restrictions.begin(), + restrictions.end(), + [&to](const auto &restriction) + { return restriction->IsTurnRestricted(to); }); } bool isTurnAllowed(const util::NodeBasedDynamicGraph &graph, @@ -614,9 +616,8 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr IntersectionViewData uturn{{SPECIAL_EDGEID, 0., 0., 0.}, false, 0.}; std::size_t allowed_uturns_number = 0; - const auto is_uturn = [](const auto angle) { - return std::fabs(angle) < std::numeric_limits::epsilon(); - }; + const auto is_uturn = [](const auto angle) + { return std::fabs(angle) < std::numeric_limits::epsilon(); }; for (const auto &outgoing_edge : outgoing_edges) { @@ -665,9 +666,9 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr // 2) use turn angle if the smallest arc between turn and initial angles passes 0° const auto use_turn_angle = (turn_angle > 270 && initial_angle < 90) || (turn_angle < 90 && initial_angle > 270); - const auto adjusted_angle = is_uturn(initial_angle) - ? (turn_angle > 180. ? 360. : 0.) - : use_turn_angle ? turn_angle : initial_angle; + const auto adjusted_angle = is_uturn(initial_angle) ? (turn_angle > 180. ? 360. : 0.) + : use_turn_angle ? turn_angle + : initial_angle; pre_intersection_view.push_back({road, adjusted_angle}); } } @@ -680,12 +681,11 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr } // Order roads in counter-clockwise order starting from the U-turn edge in the OSM order - std::stable_sort(pre_intersection_view.begin(), - pre_intersection_view.end(), - [](const auto &lhs, const auto &rhs) { - return std::tie(lhs.second, lhs.first.angle) < - std::tie(rhs.second, rhs.first.angle); - }); + std::stable_sort( + pre_intersection_view.begin(), + pre_intersection_view.end(), + [](const auto &lhs, const auto &rhs) + { return std::tie(lhs.second, lhs.first.angle) < std::tie(rhs.second, rhs.first.angle); }); // Adjust perceived bearings to keep the initial OSM order with respect to the first edge for (auto curr = pre_intersection_view.begin(), next = std::next(curr); @@ -706,9 +706,8 @@ IntersectionView convertToIntersectionView(const util::NodeBasedDynamicGraph &gr auto no_uturn = std::none_of(pre_intersection_view.begin(), pre_intersection_view.end(), - [&is_uturn](const IntersectionViewDataWithAngle &road) { - return is_uturn(road.first.angle); - }); + [&is_uturn](const IntersectionViewDataWithAngle &road) + { return is_uturn(road.first.angle); }); // After all of this, if we now don't have a u-turn, let's add one to the intersection. // This is a hack to fix the triggered assertion ( see: // https://github.com/Project-OSRM/osrm-backend/issues/6218 ). Ideally we would fix this more diff --git a/src/extractor/intersection/mergable_road_detector.cpp b/src/extractor/intersection/mergable_road_detector.cpp index eba2319df0b..449a15e9ef5 100644 --- a/src/extractor/intersection/mergable_road_detector.cpp +++ b/src/extractor/intersection/mergable_road_detector.cpp @@ -27,7 +27,8 @@ inline auto makeCheckRoadForName(const NameID name_id, const SuffixTable &suffix_table) { return [name_id, &node_based_graph, &node_data_container, &name_table, &suffix_table]( - const MergableRoadDetector::MergableRoadData &road) { + const MergableRoadDetector::MergableRoadData &road) + { // since we filter here, we don't want any other name than the one we are looking for const auto road_name_id = node_data_container @@ -89,9 +90,8 @@ bool MergableRoadDetector::CanMergeRoad(const NodeID intersection_node, * / -- \ * a ---- b - - / */ - const auto road_target = [this](const MergableRoadData &road) { - return node_based_graph.GetTarget(road.eid); - }; + const auto road_target = [this](const MergableRoadData &road) + { return node_based_graph.GetTarget(road.eid); }; // TODO might have to skip over trivial intersections if (road_target(lhs) == intersection_node || road_target(rhs) == intersection_node) @@ -262,7 +262,8 @@ bool MergableRoadDetector::IsNarrowTriangle(const NodeID intersection_node, if (angularDeviation(connector_turn->angle, ORTHOGONAL_ANGLE) > NARROW_TURN_ANGLE) return false; - const auto num_lanes = [this](const MergableRoadData &road) { + const auto num_lanes = [this](const MergableRoadData &road) + { return std::max( node_based_graph.GetEdgeData(road.eid).flags.road_classification.GetNumberOfLanes(), 1); }; @@ -308,7 +309,8 @@ bool MergableRoadDetector::IsCircularShape(const NodeID intersection_node, node_restriction_map, barrier_nodes, turn_lanes_data); - const auto getCoordinatesAlongWay = [&](const EdgeID edge_id, const double max_length) { + const auto getCoordinatesAlongWay = [&](const EdgeID edge_id, const double max_length) + { LengthLimitedCoordinateAccumulator accumulator(coordinate_extractor, max_length); SelectStraightmostRoadByNameAndOnlyChoice selector( node_data_container.GetAnnotation(node_based_graph.GetEdgeData(edge_id).annotation_data) @@ -380,7 +382,8 @@ bool MergableRoadDetector::HaveSameDirection(const NodeID intersection_node, node_restriction_map, barrier_nodes, turn_lanes_data); - const auto getCoordinatesAlongWay = [&](const EdgeID edge_id, const double max_length) { + const auto getCoordinatesAlongWay = [&](const EdgeID edge_id, const double max_length) + { LengthLimitedCoordinateAccumulator accumulator(coordinate_extractor, max_length); SelectStraightmostRoadByNameAndOnlyChoice selector( node_data_container.GetAnnotation(node_based_graph.GetEdgeData(edge_id).annotation_data) @@ -424,7 +427,8 @@ bool MergableRoadDetector::HaveSameDirection(const NodeID intersection_node, /* extract the number of lanes for a road * restricts a vector to the last two thirds of the length */ - const auto prune = [](auto &data_vector) { + const auto prune = [](auto &data_vector) + { BOOST_ASSERT(data_vector.size() >= 3); // erase the first third of the vector data_vector.erase(data_vector.begin(), data_vector.begin() + data_vector.size() / 3); @@ -493,7 +497,8 @@ bool MergableRoadDetector::IsTrafficIsland(const NodeID intersection_node, return false; // check if all entries at the destination or at the source are the same - const auto all_same_name_and_degree_three = [this](const NodeID nid) { + const auto all_same_name_and_degree_three = [this](const NodeID nid) + { // check if the intersection found has degree three if (node_based_graph.GetOutDegree(nid) != 3) return false; @@ -505,7 +510,8 @@ bool MergableRoadDetector::IsTrafficIsland(const NodeID intersection_node, .GetAnnotation(node_based_graph.GetEdgeData(range.front()).annotation_data) .name_id; - const auto has_required_name = [this, required_name_id](const auto edge_id) { + const auto has_required_name = [this, required_name_id](const auto edge_id) + { const auto road_name_id = node_data_container .GetAnnotation(node_based_graph.GetEdgeData(edge_id).annotation_data) @@ -562,7 +568,8 @@ bool MergableRoadDetector::IsLinkRoad(const NodeID intersection_node, barrier_nodes, turn_lanes_data, next_intersection_parameters); - const auto extract_name_id = [this](const MergableRoadData &road) { + const auto extract_name_id = [this](const MergableRoadData &road) + { return node_data_container .GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) .name_id; diff --git a/src/extractor/intersection/node_based_graph_walker.cpp b/src/extractor/intersection/node_based_graph_walker.cpp index 72dd8ff2342..3f3b67fb90f 100644 --- a/src/extractor/intersection/node_based_graph_walker.cpp +++ b/src/extractor/intersection/node_based_graph_walker.cpp @@ -74,10 +74,12 @@ boost::optional SelectRoadByNameOnlyChoiceAndStraightness::operator()( const EdgeBasedNodeDataContainer &node_data_container) const { BOOST_ASSERT(!intersection.empty()); - const auto comparator = [&](const IntersectionViewData &lhs, const IntersectionViewData &rhs) { + const auto comparator = [&](const IntersectionViewData &lhs, const IntersectionViewData &rhs) + { // the score of an elemnt results in an ranking preferring valid entries, if required over // invalid requested name_ids over non-requested narrow deviations over non-narrow - const auto score = [&](const IntersectionViewData &road) { + const auto score = [&](const IntersectionViewData &road) + { double result_score = 0; // since angular deviation is limited by 0-180, we add 360 for invalid if (requires_entry && !road.entry_allowed) @@ -127,10 +129,12 @@ boost::optional SelectStraightmostRoadByNameAndOnlyChoice::operator()( if (intersection.size() == 1) return {}; - const auto comparator = [&](const IntersectionViewData &lhs, const IntersectionViewData &rhs) { + const auto comparator = [&](const IntersectionViewData &lhs, const IntersectionViewData &rhs) + { // the score of an elemnt results in an ranking preferring valid entries, if required over // invalid requested name_ids over non-requested narrow deviations over non-narrow - const auto score = [&](const IntersectionViewData &road) { + const auto score = [&](const IntersectionViewData &road) + { double result_score = 0; // since angular deviation is limited by 0-180, we add 360 for invalid if (requires_entry && !road.entry_allowed) @@ -149,8 +153,11 @@ boost::optional SelectStraightmostRoadByNameAndOnlyChoice::operator()( return score(lhs) < score(rhs); }; - const auto count_desired_name = - std::count_if(std::begin(intersection), std::end(intersection), [&](const auto &road) { + const auto count_desired_name = std::count_if( + std::begin(intersection), + std::end(intersection), + [&](const auto &road) + { return node_data_container .GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) .name_id == desired_name_id; diff --git a/src/extractor/location_dependent_data.cpp b/src/extractor/location_dependent_data.cpp index fe80e0b5f92..475f15f20f7 100644 --- a/src/extractor/location_dependent_data.cpp +++ b/src/extractor/location_dependent_data.cpp @@ -65,7 +65,8 @@ void LocationDependentData::loadLocationDependentData( const auto &features_array = geojson["features"].GetArray(); - auto convert_value = [](const auto &property) -> property_t { + auto convert_value = [](const auto &property) -> property_t + { if (property.IsString()) return std::string(property.GetString()); if (property.IsNumber()) @@ -75,7 +76,8 @@ void LocationDependentData::loadLocationDependentData( return {}; }; - auto collect_properties = [this, &convert_value](const auto &object) -> std::size_t { + auto collect_properties = [this, &convert_value](const auto &object) -> std::size_t + { properties_t object_properties; for (const auto &property : object) { @@ -86,18 +88,21 @@ void LocationDependentData::loadLocationDependentData( return index; }; - auto index_polygon = [this, &bounding_boxes](const auto &rings, auto properties_index) { + auto index_polygon = [this, &bounding_boxes](const auto &rings, auto properties_index) + { // At least an outer ring in polygon https://tools.ietf.org/html/rfc7946#section-3.1.6 BOOST_ASSERT(rings.Size() > 0); - auto to_point = [](const auto &json) -> point_t { + auto to_point = [](const auto &json) -> point_t + { util::validateCoordinate(json); const auto &coords = json.GetArray(); return {coords[0].GetDouble(), coords[1].GetDouble()}; }; std::vector segments; - auto append_ring_segments = [&segments, &to_point](const auto &coordinates_array) -> box_t { + auto append_ring_segments = [&segments, &to_point](const auto &coordinates_array) -> box_t + { using coord_t = boost::geometry::traits::coordinate_type::type; auto x_min = std::numeric_limits::max(); auto y_min = std::numeric_limits::max(); @@ -208,68 +213,72 @@ LocationDependentData::FindByKey(const std::vector &property_indexe std::vector LocationDependentData::GetPropertyIndexes(const point_t &point) const { std::vector result; - auto inserter = [this, &result](const rtree_t::value_type &rtree_entry) { + auto inserter = [this, &result](const rtree_t::value_type &rtree_entry) + { const auto properties_index = polygons[rtree_entry.second].second; result.push_back(properties_index); }; // Search the R-tree and collect a Lua table of tags that correspond to the location - rtree.query(boost::geometry::index::intersects(point) && - boost::geometry::index::satisfies([this, &point](const rtree_t::value_type &v) { - // Simple point-in-polygon algorithm adapted from - // https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html - - const auto &envelop = v.first; - const auto &bands = polygons[v.second].first; - - const auto y_min = envelop.min_corner().y(); - const auto y_max = envelop.max_corner().y(); - const auto dy = (y_max - y_min) / bands.size(); - - std::size_t band = (point.y() - y_min) / dy; - if (band >= bands.size()) - { - band = bands.size() - 1; + rtree.query( + boost::geometry::index::intersects(point) && + boost::geometry::index::satisfies( + [this, &point](const rtree_t::value_type &v) + { + // Simple point-in-polygon algorithm adapted from + // https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html + + const auto &envelop = v.first; + const auto &bands = polygons[v.second].first; + + const auto y_min = envelop.min_corner().y(); + const auto y_max = envelop.max_corner().y(); + const auto dy = (y_max - y_min) / bands.size(); + + std::size_t band = (point.y() - y_min) / dy; + if (band >= bands.size()) + { + band = bands.size() - 1; + } + + bool inside = false; + + for (const auto &segment : bands[band]) + { + const auto point_x = point.x(), point_y = point.y(); + const auto from_x = segment.first.x(), from_y = segment.first.y(); + const auto to_x = segment.second.x(), to_y = segment.second.y(); + + if (to_y == from_y) + { // handle horizontal segments: check if on boundary or skip + if ((to_y == point_y) && + (from_x == point_x || (to_x > point_x) != (from_x > point_x))) + return true; + continue; } - bool inside = false; - - for (const auto &segment : bands[band]) + if ((to_y > point_y) != (from_y > point_y)) { - const auto point_x = point.x(), point_y = point.y(); - const auto from_x = segment.first.x(), from_y = segment.first.y(); - const auto to_x = segment.second.x(), to_y = segment.second.y(); - - if (to_y == from_y) - { // handle horizontal segments: check if on boundary or skip - if ((to_y == point_y) && - (from_x == point_x || (to_x > point_x) != (from_x > point_x))) - return true; - continue; - } - - if ((to_y > point_y) != (from_y > point_y)) - { - const auto ax = to_x - from_x; - const auto ay = to_y - from_y; - const auto tx = point_x - from_x; - const auto ty = point_y - from_y; + const auto ax = to_x - from_x; + const auto ay = to_y - from_y; + const auto tx = point_x - from_x; + const auto ty = point_y - from_y; - const auto cross_product = tx * ay - ax * ty; + const auto cross_product = tx * ay - ax * ty; - if (cross_product == 0) - return true; + if (cross_product == 0) + return true; - if ((ay > 0) == (cross_product > 0)) - { - inside = !inside; - } + if ((ay > 0) == (cross_product > 0)) + { + inside = !inside; } } + } - return inside; - }), - boost::make_function_output_iterator(std::ref(inserter))); + return inside; + }), + boost::make_function_output_iterator(std::ref(inserter))); return result; } diff --git a/src/extractor/node_based_graph_factory.cpp b/src/extractor/node_based_graph_factory.cpp index 045e495436b..9fb50149d4d 100644 --- a/src/extractor/node_based_graph_factory.cpp +++ b/src/extractor/node_based_graph_factory.cpp @@ -46,27 +46,31 @@ void NodeBasedGraphFactory::BuildCompressedOutputGraph(const std::vectortarget; @@ -154,18 +155,22 @@ struct transferBuilder // the transfer const auto &restrictions = rg.GetRestrictions(cur_node); const auto is_restricted = - std::any_of(restrictions.begin(), restrictions.end(), [&](const auto &restriction) { - return restriction->IsTurnRestricted(suffix_edge.node_based_to) && - restriction->IsUnconditional(); - }); + std::any_of(restrictions.begin(), + restrictions.end(), + [&](const auto &restriction) + { + return restriction->IsTurnRestricted(suffix_edge.node_based_to) && + restriction->IsUnconditional(); + }); if (is_restricted) continue; const auto &edges = rg.GetEdges(cur_node); // Check that the suffix edge is not a next edge along the current path. - const auto can_transfer = std::none_of(edges.begin(), edges.end(), [&](auto &edge) { - return edge.node_based_to == suffix_edge.node_based_to; - }); + const auto can_transfer = std::none_of( + edges.begin(), + edges.end(), + [&](auto &edge) { return edge.node_based_to == suffix_edge.node_based_to; }); if (can_transfer) { insertEdge(rg, @@ -186,9 +191,9 @@ struct transferBuilder this->next_suffixes(from, to); - std::for_each(suffix_nodes.begin(), suffix_nodes.end(), [&](const auto &suffix_node) { - this->add_suffix_transfer(suffix_node); - }); + std::for_each(suffix_nodes.begin(), + suffix_nodes.end(), + [&](const auto &suffix_node) { this->add_suffix_transfer(suffix_node); }); for (const auto &suffix_node : suffix_nodes) { @@ -207,7 +212,8 @@ struct transferBuilder template void buildGraph(RestrictionGraph &rg, const std::vector &restrictions) { - const auto run_builder = [&](const auto &restriction) { + const auto run_builder = [&](const auto &restriction) + { builder_type builder(rg); builder.start(restriction.turn_path.From(), restriction.turn_path.FirstVia()); @@ -248,9 +254,9 @@ RestrictionGraph constructRestrictionGraph(const std::vector &t // Start renumbering const auto permutation = util::orderingToPermutation(ordering); util::inplacePermutation(rg.nodes.begin(), rg.nodes.end(), permutation); - std::for_each(rg.edges.begin(), rg.edges.end(), [&](auto &edge) { - edge.target = permutation[edge.target]; - }); + std::for_each(rg.edges.begin(), + rg.edges.end(), + [&](auto &edge) { edge.target = permutation[edge.target]; }); rg.num_via_nodes = std::count(is_via_node.begin(), is_via_node.end(), true); for (auto &entry : rg.via_edge_to_node) { diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index 0521ce15f26..f73c16eed80 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -245,7 +245,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "valid", &osmium::Location::valid); - auto get_location_tag = [](auto &context, const auto &location, const char *key) { + auto get_location_tag = [](auto &context, const auto &location, const char *key) + { if (context.location_dependent_data.empty()) return sol::object(context.state); @@ -272,7 +273,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "get_nodes", [](const osmium::Way &way) { return sol::as_table(&way.nodes()); }, "get_location_tag", - [&context, &get_location_tag](const osmium::Way &way, const char *key) { + [&context, &get_location_tag](const osmium::Way &way, const char *key) + { // HEURISTIC: use a single node (last) of the way to localize the way // For more complicated scenarios a proper merging of multiple tags // at one or many locations must be provided @@ -292,9 +294,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "version", &osmium::Node::version, "get_location_tag", - [&context, &get_location_tag](const osmium::Node &node, const char *key) { - return get_location_tag(context, node.location(), key); - }); + [&context, &get_location_tag](const osmium::Node &node, const char *key) + { return get_location_tag(context, node.location(), key); }); context.state.new_enum("traffic_lights", "none", @@ -310,7 +311,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "ResultNode", "traffic_lights", sol::property([](const ExtractionNode &node) { return node.traffic_lights; }, - [](ExtractionNode &node, const sol::object &obj) { + [](ExtractionNode &node, const sol::object &obj) + { if (obj.is()) { // The old approach of assigning a boolean traffic light @@ -361,7 +363,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) sol::property(&ExtractionWay::GetName, &ExtractionWay::SetName), "ref", // backward compatibility sol::property(&ExtractionWay::GetForwardRef, - [](ExtractionWay &way, const char *ref) { + [](ExtractionWay &way, const char *ref) + { way.SetForwardRef(ref); way.SetBackwardRef(ref); }), @@ -420,7 +423,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) sol::property([](const ExtractionWay &way) { return way.access_turn_classification; }, [](ExtractionWay &way, int flag) { way.access_turn_classification = flag; })); - auto getTypedRefBySol = [](const sol::object &obj) -> ExtractionRelation::OsmIDTyped { + auto getTypedRefBySol = [](const sol::object &obj) -> ExtractionRelation::OsmIDTyped + { if (obj.is()) { osmium::Way *way = obj.as(); @@ -456,20 +460,19 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "get_value_by_key", [](ExtractionRelation &rel, const char *key) -> const char * { return rel.GetAttr(key); }, "get_role", - [&getTypedRefBySol](ExtractionRelation &rel, const sol::object &obj) -> const char * { - return rel.GetRole(getTypedRefBySol(obj)); - }); + [&getTypedRefBySol](ExtractionRelation &rel, const sol::object &obj) -> const char * + { return rel.GetRole(getTypedRefBySol(obj)); }); context.state.new_usertype( "ExtractionRelationContainer", "get_relations", [&getTypedRefBySol](ExtractionRelationContainer &cont, const sol::object &obj) - -> const ExtractionRelationContainer::RelationIDList & { - return cont.GetRelations(getTypedRefBySol(obj)); - }, + -> const ExtractionRelationContainer::RelationIDList & + { return cont.GetRelations(getTypedRefBySol(obj)); }, "relation", - [](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped &rel_id) - -> const ExtractionRelation & { return cont.GetRelationData(rel_id); }); + [](ExtractionRelationContainer &cont, + const ExtractionRelation::OsmIDTyped &rel_id) -> const ExtractionRelation & + { return cont.GetRelationData(rel_id); }); context.state.new_usertype( "NodeBasedEdgeClassification", @@ -489,17 +492,14 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "restricted", sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.restricted; }), "road_classification", - sol::property([](NodeBasedEdgeClassification &c) -> RoadClassification { - return c.road_classification; - }), + sol::property([](NodeBasedEdgeClassification &c) -> RoadClassification + { return c.road_classification; }), "highway_turn_classification", - sol::property([](NodeBasedEdgeClassification &c) -> uint8_t { - return c.highway_turn_classification; - }), + sol::property([](NodeBasedEdgeClassification &c) -> uint8_t + { return c.highway_turn_classification; }), "access_turn_classification", - sol::property([](NodeBasedEdgeClassification &c) -> uint8_t { - return c.access_turn_classification; - })); + sol::property([](NodeBasedEdgeClassification &c) -> uint8_t + { return c.access_turn_classification; })); context.state.new_usertype("ExtractionSegment", "source", @@ -517,10 +517,12 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) // Keep in mind .location is available only if .pbf is preprocessed to set the location with the // ref using osmium command "osmium add-locations-to-ways" - context.state.new_usertype( - "NodeRef", "id", &osmium::NodeRef::ref, "location", [](const osmium::NodeRef &nref) { - return nref.location(); - }); + context.state.new_usertype("NodeRef", + "id", + &osmium::NodeRef::ref, + "location", + [](const osmium::NodeRef &nref) + { return nref.location(); }); context.state.new_usertype("EdgeSource", "source_coordinate", @@ -576,7 +578,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) util::Log() << "Using profile api version " << context.api_version; // version-dependent parts of the api - auto initV2Context = [&]() { + auto initV2Context = [&]() + { // clear global not used in v2 context.state["properties"] = sol::nullopt; @@ -667,26 +670,31 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) } }; - auto initialize_V3_extraction_turn = [&]() { + auto initialize_V3_extraction_turn = [&]() + { context.state.new_usertype( "ExtractionTurn", "angle", &ExtractionTurn::angle, "turn_type", - sol::property([](const ExtractionTurn &turn) { - if (turn.number_of_roads > 2 || turn.source_mode != turn.target_mode || - turn.is_u_turn) - return osrm::guidance::TurnType::Turn; - else - return osrm::guidance::TurnType::NoTurn; - }), + sol::property( + [](const ExtractionTurn &turn) + { + if (turn.number_of_roads > 2 || turn.source_mode != turn.target_mode || + turn.is_u_turn) + return osrm::guidance::TurnType::Turn; + else + return osrm::guidance::TurnType::NoTurn; + }), "direction_modifier", - sol::property([](const ExtractionTurn &turn) { - if (turn.is_u_turn) - return osrm::guidance::DirectionModifier::UTurn; - else - return osrm::guidance::DirectionModifier::Straight; - }), + sol::property( + [](const ExtractionTurn &turn) + { + if (turn.is_u_turn) + return osrm::guidance::DirectionModifier::UTurn; + else + return osrm::guidance::DirectionModifier::Straight; + }), "has_traffic_light", &ExtractionTurn::has_traffic_light, "weight", diff --git a/src/extractor/turn_path_compressor.cpp b/src/extractor/turn_path_compressor.cpp index f46b07718e9..223950ab743 100644 --- a/src/extractor/turn_path_compressor.cpp +++ b/src/extractor/turn_path_compressor.cpp @@ -12,7 +12,8 @@ TurnPathCompressor::TurnPathCompressor(std::vector &restriction std::vector &maneuver_overrides) { // Track all turn paths by their respective start/via/end nodes. - auto index = [&](auto &element) { + auto index = [&](auto &element) + { starts.insert({element.From(), &element}); ends.insert({element.To(), &element}); if (element.Type() == TurnPathType::VIA_WAY_TURN_PATH) @@ -44,7 +45,8 @@ void TurnPathCompressor::Compress(const NodeID from, const NodeID via, const Nod std::back_inserter(start_ptrs), [](const auto pair) { return pair.second; }); - const auto update_start = [&](auto ptr) { + const auto update_start = [&](auto ptr) + { if (ptr->Type() == TurnPathType::VIA_NODE_TURN_PATH) { @@ -97,7 +99,8 @@ void TurnPathCompressor::Compress(const NodeID from, const NodeID via, const Nod std::back_inserter(end_ptrs), [](const auto pair) { return pair.second; }); - const auto update_end = [&](auto ptr) { + const auto update_end = [&](auto ptr) + { if (ptr->Type() == TurnPathType::VIA_NODE_TURN_PATH) { auto &node_ptr = ptr->AsViaNodePath(); @@ -145,7 +148,8 @@ void TurnPathCompressor::Compress(const NodeID from, const NodeID via, const Nod // remove compressed node from all via paths auto all_vias_range = vias.equal_range(via); - const auto update_via = [&](auto restriction_pair) { + const auto update_via = [&](auto restriction_pair) + { BOOST_ASSERT(restriction_pair.second->Type() == TurnPathType::VIA_WAY_TURN_PATH); auto &way_ptr = restriction_pair.second->AsViaWayPath(); BOOST_ASSERT(std::find(way_ptr.via.begin(), way_ptr.via.end(), via) != way_ptr.via.end()); diff --git a/src/extractor/turn_path_filter.cpp b/src/extractor/turn_path_filter.cpp index 190fec51467..6285656de58 100644 --- a/src/extractor/turn_path_filter.cpp +++ b/src/extractor/turn_path_filter.cpp @@ -18,7 +18,8 @@ std::vector removeInvalidTurnPaths(std::vector turn_relations, log << "Removing invalid " << T::Name() << "s..."; TIMER_START(remove_invalid_turn_paths); - const auto is_valid_edge = [&node_based_graph](const auto from, const auto to) { + const auto is_valid_edge = [&node_based_graph](const auto from, const auto to) + { const auto eid = node_based_graph.FindEdge(from, to); if (eid == SPECIAL_EDGEID) { @@ -35,26 +36,29 @@ std::vector removeInvalidTurnPaths(std::vector turn_relations, return true; }; - const auto is_valid_node = [is_valid_edge](const auto &via_node_path) { + const auto is_valid_node = [is_valid_edge](const auto &via_node_path) + { return is_valid_edge(via_node_path.from, via_node_path.via) && is_valid_edge(via_node_path.via, via_node_path.to); }; - const auto is_valid_way = [is_valid_edge](const auto &via_way_path) { + const auto is_valid_way = [is_valid_edge](const auto &via_way_path) + { if (!is_valid_edge(via_way_path.from, via_way_path.via.front())) return false; - const auto invalid_it = std::adjacent_find( - via_way_path.via.begin(), via_way_path.via.end(), [&](auto via_from, auto via_to) { - return !is_valid_edge(via_from, via_to); - }); + const auto invalid_it = std::adjacent_find(via_way_path.via.begin(), + via_way_path.via.end(), + [&](auto via_from, auto via_to) + { return !is_valid_edge(via_from, via_to); }); if (invalid_it != via_way_path.via.end()) return false; return is_valid_edge(via_way_path.via.back(), via_way_path.to); }; - const auto is_invalid = [is_valid_way, is_valid_node](const auto &turn_relation) { + const auto is_invalid = [is_valid_way, is_valid_node](const auto &turn_relation) + { if (turn_relation.turn_path.Type() == TurnPathType::VIA_NODE_TURN_PATH) { return !is_valid_node(turn_relation.turn_path.AsViaNodePath()); diff --git a/src/extractor/way_restriction_map.cpp b/src/extractor/way_restriction_map.cpp index 98ebf19df37..d49bec87b8d 100644 --- a/src/extractor/way_restriction_map.cpp +++ b/src/extractor/way_restriction_map.cpp @@ -38,9 +38,10 @@ bool WayRestrictionMap::IsRestricted(DuplicatedNodeID duplicated_node, const Nod // Checks if a turn to 'to' is restricted BOOST_ASSERT(duplicated_node < restriction_graph.num_via_nodes); const auto &restrictions = restriction_graph.GetRestrictions(duplicated_node); - return std::any_of(restrictions.begin(), restrictions.end(), [&to](const auto &restriction) { - return restriction->IsTurnRestricted(to); - }); + return std::any_of(restrictions.begin(), + restrictions.end(), + [&to](const auto &restriction) + { return restriction->IsTurnRestricted(to); }); } std::vector diff --git a/src/guidance/driveway_handler.cpp b/src/guidance/driveway_handler.cpp index 58f07600d77..5e781a9bb30 100644 --- a/src/guidance/driveway_handler.cpp +++ b/src/guidance/driveway_handler.cpp @@ -43,10 +43,13 @@ bool DrivewayHandler::canProcess(const NodeID /*nid*/, return false; auto low_priority_count = - std::count_if(intersection.begin(), intersection.end(), [this](const auto &road) { - return node_based_graph.GetEdgeData(road.eid) - .flags.road_classification.IsLowPriorityRoadClass(); - }); + std::count_if(intersection.begin(), + intersection.end(), + [this](const auto &road) + { + return node_based_graph.GetEdgeData(road.eid) + .flags.road_classification.IsLowPriorityRoadClass(); + }); // Process intersection if it has two edges with normal priority and one is the entry edge, // and also has at least one edge with lower priority @@ -57,11 +60,13 @@ Intersection DrivewayHandler::operator()(const NodeID nid, const EdgeID source_edge_id, Intersection intersection) const { - auto road = - std::find_if(intersection.begin() + 1, intersection.end(), [this](const auto &road) { - return !node_based_graph.GetEdgeData(road.eid) - .flags.road_classification.IsLowPriorityRoadClass(); - }); + auto road = std::find_if(intersection.begin() + 1, + intersection.end(), + [this](const auto &road) + { + return !node_based_graph.GetEdgeData(road.eid) + .flags.road_classification.IsLowPriorityRoadClass(); + }); (void)nid; OSRM_ASSERT(road != intersection.end(), node_coordinates[nid]); @@ -76,14 +81,22 @@ Intersection DrivewayHandler::operator()(const NodeID nid, if (road->instruction.direction_modifier == DirectionModifier::Straight) { - std::for_each(intersection.begin() + 1, road, [](auto &side_road) { - if (side_road.instruction.direction_modifier == DirectionModifier::Straight) - side_road.instruction.direction_modifier = DirectionModifier::SlightRight; - }); - std::for_each(road + 1, intersection.end(), [](auto &side_road) { - if (side_road.instruction.direction_modifier == DirectionModifier::Straight) - side_road.instruction.direction_modifier = DirectionModifier::SlightLeft; - }); + std::for_each( + intersection.begin() + 1, + road, + [](auto &side_road) + { + if (side_road.instruction.direction_modifier == DirectionModifier::Straight) + side_road.instruction.direction_modifier = DirectionModifier::SlightRight; + }); + std::for_each( + road + 1, + intersection.end(), + [](auto &side_road) + { + if (side_road.instruction.direction_modifier == DirectionModifier::Straight) + side_road.instruction.direction_modifier = DirectionModifier::SlightLeft; + }); } return intersection; diff --git a/src/guidance/guidance_processing.cpp b/src/guidance/guidance_processing.cpp index 0c510b54b0d..2debabb04f8 100644 --- a/src/guidance/guidance_processing.cpp +++ b/src/guidance/guidance_processing.cpp @@ -96,7 +96,9 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, // First part of the pipeline generates iterator ranges of IDs in sets of GRAINSIZE tbb::filter> generator_stage( - tbb::filter_mode::serial_in_order, [&](tbb::flow_control &fc) { + tbb::filter_mode::serial_in_order, + [&](tbb::flow_control &fc) + { if (current_node < node_count) { auto next_node = std::min(current_node + GRAINSIZE, node_count); @@ -116,7 +118,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, // tbb::filter, TurnsPipelineBufferPtr> guidance_stage( tbb::filter_mode::parallel, - [&](const tbb::blocked_range &intersection_node_range) { + [&](const tbb::blocked_range &intersection_node_range) + { auto buffer = std::make_shared(); buffer->nodes_processed = intersection_node_range.size(); @@ -224,9 +227,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, const auto turn = std::find_if(intersection.begin(), intersection.end(), - [edge = outgoing_edge.edge](const auto &road) { - return road.eid == edge; - }); + [edge = outgoing_edge.edge](const auto &road) + { return road.eid == edge; }); OSRM_ASSERT(turn != intersection.end(), node_coordinates[intersection_node]); @@ -267,9 +269,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, auto has_unconditional = std::any_of(restrictions.begin(), restrictions.end(), - [](const auto &restriction) { - return restriction->IsUnconditional(); - }); + [](const auto &restriction) + { return restriction->IsUnconditional(); }); if (has_unconditional) continue; @@ -307,7 +308,9 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, std::vector delayed_turn_data; tbb::filter guidance_output_stage( - tbb::filter_mode::serial_in_order, [&](auto buffer) { + tbb::filter_mode::serial_in_order, + [&](auto buffer) + { guidance_progress.PrintAddition(buffer->nodes_processed); connectivity_checksum = buffer->checksum.update_checksum(connectivity_checksum); @@ -315,9 +318,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, // Guidance data std::for_each(buffer->continuous_turn_data.begin(), buffer->continuous_turn_data.end(), - [&turn_data_container](const auto &turn_data) { - turn_data_container.push_back(turn_data); - }); + [&turn_data_container](const auto &turn_data) + { turn_data_container.push_back(turn_data); }); // Copy via-way restrictions delayed data delayed_turn_data.insert(delayed_turn_data.end(), @@ -336,9 +338,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, // NOTE: EBG edges delayed_data and turns delayed_turn_data have the same index std::for_each(delayed_turn_data.begin(), delayed_turn_data.end(), - [&turn_data_container](const auto &turn_data) { - turn_data_container.push_back(turn_data); - }); + [&turn_data_container](const auto &turn_data) + { turn_data_container.push_back(turn_data); }); } util::Log() << "done."; diff --git a/src/guidance/intersection_handler.cpp b/src/guidance/intersection_handler.cpp index 6cbd016a01f..5fe6bc21a06 100644 --- a/src/guidance/intersection_handler.cpp +++ b/src/guidance/intersection_handler.cpp @@ -356,7 +356,8 @@ void IntersectionHandler::assignFork(const EdgeID via_edge, ConnectedRoad &right) const { // TODO handle low priority road classes in a reasonable way - const auto suppressed_type = [&](const ConnectedRoad &road) { + const auto suppressed_type = [&](const ConnectedRoad &road) + { const auto in_mode = node_data_container .GetAnnotation(node_based_graph.GetEdgeData(via_edge).annotation_data) diff --git a/src/guidance/motorway_handler.cpp b/src/guidance/motorway_handler.cpp index f2138c81327..5c85e2edf5f 100644 --- a/src/guidance/motorway_handler.cpp +++ b/src/guidance/motorway_handler.cpp @@ -96,10 +96,13 @@ MotorwayHandler::operator()(const NodeID, const EdgeID via_eid, Intersection int if (isMotorwayClass(via_eid, node_based_graph)) { intersection = fromMotorway(via_eid, std::move(intersection)); - std::for_each(intersection.begin(), intersection.end(), [](ConnectedRoad &road) { - if (road.instruction.type == TurnType::OnRamp) - road.instruction.type = TurnType::OffRamp; - }); + std::for_each(intersection.begin(), + intersection.end(), + [](ConnectedRoad &road) + { + if (road.instruction.type == TurnType::OnRamp) + road.instruction.type = TurnType::OffRamp; + }); return intersection; } else // coming from a ramp @@ -116,7 +119,8 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in BOOST_ASSERT(isMotorwayClass(via_eid, node_based_graph)); // find the angle that continues on our current highway - const auto getContinueAngle = [this, in_data](const Intersection &intersection) { + const auto getContinueAngle = [this, in_data](const Intersection &intersection) + { for (const auto &road : intersection) { if (!road.entry_allowed) @@ -136,7 +140,8 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in return intersection[0].angle; }; - const auto getMostLikelyContinue = [this](const Intersection &intersection) { + const auto getMostLikelyContinue = [this](const Intersection &intersection) + { double angle = intersection[0].angle; double best = 180; for (const auto &road : intersection) @@ -151,7 +156,8 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in return angle; }; - const auto findBestContinue = [&]() { + const auto findBestContinue = [&]() + { const double continue_angle = getContinueAngle(intersection); if (continue_angle != intersection[0].angle) return continue_angle; @@ -209,10 +215,11 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in const auto valid_exits = std::count_if(intersection.begin(), intersection.end(), [](const auto &road) { return road.entry_allowed; }); - const auto exiting_motorways = - std::count_if(intersection.begin(), intersection.end(), [this](const auto &road) { - return road.entry_allowed && isMotorwayClass(road.eid, node_based_graph); - }); + const auto exiting_motorways = std::count_if( + intersection.begin(), + intersection.end(), + [this](const auto &road) + { return road.entry_allowed && isMotorwayClass(road.eid, node_based_graph); }); if (exiting_motorways == 0) { diff --git a/src/guidance/roundabout_handler.cpp b/src/guidance/roundabout_handler.cpp index 99fcfc1c78e..29f7173f538 100644 --- a/src/guidance/roundabout_handler.cpp +++ b/src/guidance/roundabout_handler.cpp @@ -119,11 +119,11 @@ bool RoundaboutHandler::qualifiesAsRoundaboutIntersection( if (!has_limited_size) return false; - const bool simple_exits = - roundabout_nodes.end() == - std::find_if(roundabout_nodes.begin(), roundabout_nodes.end(), [this](const NodeID node) { - return (node_based_graph.GetOutDegree(node) > 3); - }); + const bool simple_exits = roundabout_nodes.end() == + std::find_if(roundabout_nodes.begin(), + roundabout_nodes.end(), + [this](const NodeID node) + { return (node_based_graph.GetOutDegree(node) > 3); }); if (!simple_exits) return false; @@ -131,7 +131,8 @@ bool RoundaboutHandler::qualifiesAsRoundaboutIntersection( // Find all exit bearings. Only if they are well distinct (at least 60 degrees between // them), we allow a roundabout turn - const auto exit_bearings = [this, &roundabout_nodes]() { + const auto exit_bearings = [this, &roundabout_nodes]() + { std::vector result; for (const auto node : roundabout_nodes) { @@ -151,7 +152,8 @@ bool RoundaboutHandler::qualifiesAsRoundaboutIntersection( edge_range.begin(), edge_range.end(), std::uint8_t{0}, - [this](const auto current_max, const auto current_eid) { + [this](const auto current_max, const auto current_eid) + { return std::max(current_max, node_based_graph.GetEdgeData(current_eid) .flags.road_classification.GetNumberOfLanes()); @@ -187,7 +189,8 @@ bool RoundaboutHandler::qualifiesAsRoundaboutIntersection( return result; }(); - const bool well_distinct_bearings = [](const std::vector &bearings) { + const bool well_distinct_bearings = [](const std::vector &bearings) + { for (std::size_t bearing_index = 0; bearing_index < bearings.size(); ++bearing_index) { const double difference = @@ -207,10 +210,10 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const std::unordered_set roundabout_name_ids; std::unordered_set connected_names; - const auto getNextOnRoundabout = [this, &roundabout_name_ids, &connected_names]( - const NodeID node, - const bool roundabout, - const bool circular) { + const auto getNextOnRoundabout = + [this, &roundabout_name_ids, &connected_names]( + const NodeID node, const bool roundabout, const bool circular) + { BOOST_ASSERT(roundabout != circular); EdgeID continue_edge = SPECIAL_EDGEID; for (const auto edge_id : node_based_graph.GetAdjacentEdgeRange(node)) @@ -230,7 +233,8 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const if (!edge_name_empty) { - const auto announce = [&](unsigned id) { + const auto announce = [&](unsigned id) + { return util::guidance::requiresNameAnnounced( id, edge_data.name_id, name_table, street_name_suffix_table); }; @@ -250,7 +254,8 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const }; // this value is a hard abort to deal with potential self-loops - const auto countRoundaboutFlags = [&](const NodeID at_node) { + const auto countRoundaboutFlags = [&](const NodeID at_node) + { // FIXME: this would be nicer as boost::count_if, but our integer range does not support // these range based handlers std::size_t count = 0; @@ -263,7 +268,8 @@ RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const return count; }; - const auto getEdgeLength = [&](const NodeID source_node, EdgeID eid) { + const auto getEdgeLength = [&](const NodeID source_node, EdgeID eid) + { double length = 0.; auto last_coord = node_coordinates[source_node]; const auto &edge_bucket = compressed_geometries.GetBucketReference(eid); @@ -404,7 +410,8 @@ Intersection RoundaboutHandler::handleRoundabouts(const RoundaboutType roundabou else { // Check if there is a non-service exit - const auto has_non_ignorable_exit = [&]() { + const auto has_non_ignorable_exit = [&]() + { for (const auto eid : node_based_graph.GetAdjacentEdgeRange(node_at_center_of_intersection)) { diff --git a/src/guidance/segregated_intersection_classification.cpp b/src/guidance/segregated_intersection_classification.cpp index bee364bb450..7a9ad4a471c 100644 --- a/src/guidance/segregated_intersection_classification.cpp +++ b/src/guidance/segregated_intersection_classification.cpp @@ -46,7 +46,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa extractor::intersection::CoordinateExtractor coordExtractor( graph, factory.GetCompressedEdges(), coordinates); - auto const get_edge_length = [&](NodeID from_node, EdgeID edge_id, NodeID to_node) { + auto const get_edge_length = [&](NodeID from_node, EdgeID edge_id, NodeID to_node) + { auto const geom = coordExtractor.GetCoordinatesAlongRoad(from_node, edge_id, false, to_node); double length = 0.0; @@ -58,7 +59,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa }; // Returns an angle between edges from from_edge_id to to_edge_id - auto const get_angle = [&](NodeID from_node, EdgeID from_edge_id, EdgeID to_edge_id) { + auto const get_angle = [&](NodeID from_node, EdgeID from_edge_id, EdgeID to_edge_id) + { auto intersection_node = graph.GetTarget(from_edge_id); auto from_edge_id_outgoing = graph.FindEdge(intersection_node, from_node); auto to_node = graph.GetTarget(to_edge_id); @@ -70,7 +72,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa node_from, coordinates[intersection_node], node_to); }; - auto const get_edge_info = [&](EdgeID edge_id, NodeID node, auto const &edge_data) -> EdgeInfo { + auto const get_edge_info = [&](EdgeID edge_id, NodeID node, auto const &edge_data) -> EdgeInfo + { /// @todo Make string normalization/lowercase/trim for comparison ... auto const id = annotation[edge_data.annotation_data].name_id; @@ -84,22 +87,24 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa edge_data.flags}; }; - auto is_bidirectional = [](auto flags) { - return flags.is_split || (!flags.is_split && flags.forward && flags.backward); - }; + auto is_bidirectional = [](auto flags) + { return flags.is_split || (!flags.is_split && flags.forward && flags.backward); }; - auto is_internal_straight = [](auto const turn_degree) { + auto is_internal_straight = [](auto const turn_degree) + { return (turn_degree > INTERNAL_STRAIGHT_LOWER_BOUND && turn_degree < INTERNAL_STRAIGHT_UPPER_BOUND); }; // Lambda to check if the turn set includes a right turn type - const auto has_turn_right = [](std::set &turn_types) { + const auto has_turn_right = [](std::set &turn_types) + { return turn_types.find(guidance::DirectionModifier::Right) != turn_types.end() || turn_types.find(guidance::DirectionModifier::SharpRight) != turn_types.end(); }; // Lambda to check if the turn set includes a left turn type - const auto has_turn_left = [](std::set &turn_types) { + const auto has_turn_left = [](std::set &turn_types) + { return turn_types.find(guidance::DirectionModifier::Left) != turn_types.end() || turn_types.find(guidance::DirectionModifier::SharpLeft) != turn_types.end(); }; @@ -108,7 +113,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa const std::vector &v1, const std::vector &v2, EdgeInfo const ¤t, - double edge_length) { + double edge_length) + { // Internal intersection edges must be short and cannot be a roundabout. // Also they must be a road use (not footway, cycleway, etc.) // TODO - consider whether alleys, cul-de-sacs, and other road uses @@ -219,7 +225,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa return true; }; - auto const collect_edge_info_fn = [&](auto const &edges1, NodeID node2) { + auto const collect_edge_info_fn = [&](auto const &edges1, NodeID node2) + { std::vector info; for (auto e : edges1) @@ -234,15 +241,15 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa if (info.empty()) return info; - std::sort(info.begin(), info.end(), [](EdgeInfo const &e1, EdgeInfo const &e2) { - return e1.node < e2.node; - }); + std::sort(info.begin(), + info.end(), + [](EdgeInfo const &e1, EdgeInfo const &e2) { return e1.node < e2.node; }); - info.erase( - std::unique(info.begin(), - info.end(), - [](EdgeInfo const &e1, EdgeInfo const &e2) { return e1.node == e2.node; }), - info.end()); + info.erase(std::unique(info.begin(), + info.end(), + [](EdgeInfo const &e1, EdgeInfo const &e2) + { return e1.node == e2.node; }), + info.end()); return info; }; @@ -253,7 +260,8 @@ std::unordered_set findSegregatedNodes(const extractor::NodeBasedGraphFa NodeID node1, auto const &edges2, NodeID node2, - double edge_length) { + double edge_length) + { return isSegregated(node1, collect_edge_info_fn(edges1, node2), collect_edge_info_fn(edges2, node1), diff --git a/src/guidance/sliproad_handler.cpp b/src/guidance/sliproad_handler.cpp index 702bdf59a38..5339ed6c625 100644 --- a/src/guidance/sliproad_handler.cpp +++ b/src/guidance/sliproad_handler.cpp @@ -91,7 +91,8 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, } // Link-check for (bc) and later on (cd) which both are getting shortcutted by Sliproad - const auto is_potential_link = [this, main_road](const ConnectedRoad &road) { + const auto is_potential_link = [this, main_road](const ConnectedRoad &road) + { if (!road.entry_allowed) { return false; @@ -188,7 +189,8 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, const auto is_left_sliproad_turn = road_index > *obvious; // Road at the intersection the main road leads onto which the sliproad arrives onto - const auto crossing_road = [&] { + const auto crossing_road = [&] + { if (is_left_sliproad_turn) return main_road_intersection->intersection.getLeftmostRoad(); @@ -266,7 +268,8 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, if (target_intersection.isDeadEnd()) continue; - const auto find_valid = [](const extractor::intersection::IntersectionView &view) { + const auto find_valid = [](const extractor::intersection::IntersectionView &view) + { // according to our current sliproad idea, there should only be one valid turn auto itr = std::find_if( view.begin(), view.end(), [](const auto &road) { return road.entry_allowed; }); @@ -326,16 +329,19 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, is_left_sliproad_turn ? main_road_intersection->intersection.size() - 2 : 2; auto next_to_crossing_road = main_road_intersection->intersection[next_to_crossing_idx]; auto next_to_crossing_node = node_based_graph.GetTarget(next_to_crossing_road.eid); - auto found_common_node = std::find_if( - begin(target_intersection), end(target_intersection), [&](const auto &road) { - if (next_to_crossing_node == node_based_graph.GetTarget(road.eid)) - { - auto direction = getTurnDirection(road.angle); - return direction == DirectionModifier::SharpRight || - direction == DirectionModifier::SharpLeft; - } - return false; - }); + auto found_common_node = + std::find_if(begin(target_intersection), + end(target_intersection), + [&](const auto &road) + { + if (next_to_crossing_node == node_based_graph.GetTarget(road.eid)) + { + auto direction = getTurnDirection(road.angle); + return direction == DirectionModifier::SharpRight || + direction == DirectionModifier::SharpLeft; + } + return false; + }); if (found_common_node == target_intersection.end()) continue; } @@ -499,7 +505,8 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/, node_based_graph.GetEdgeData(candidate_road.eid).annotation_data); // Name mismatch: check roads at `c` and `d` for same name - const auto name_mismatch = [&](const NameID road_name_id) { + const auto name_mismatch = [&](const NameID road_name_id) + { return util::guidance::requiresNameAnnounced(road_name_id, // candidate_data.name_id, // name_table, // diff --git a/src/guidance/suppress_mode_handler.cpp b/src/guidance/suppress_mode_handler.cpp index b808abc6edd..e1356de6b9f 100644 --- a/src/guidance/suppress_mode_handler.cpp +++ b/src/guidance/suppress_mode_handler.cpp @@ -50,11 +50,15 @@ bool SuppressModeHandler::canProcess(const NodeID, const auto first = begin(intersection); const auto last = end(intersection); - const auto all_share_mode = std::all_of(first, last, [this, &in_mode](const auto &road) { - return node_data_container - .GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) - .travel_mode == in_mode; - }); + const auto all_share_mode = std::all_of( + first, + last, + [this, &in_mode](const auto &road) + { + return node_data_container + .GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) + .travel_mode == in_mode; + }); return (suppress_in_mode != end(suppressed)) && all_share_mode; } @@ -65,13 +69,16 @@ SuppressModeHandler::operator()(const NodeID, const EdgeID, Intersection interse const auto first = begin(intersection); const auto last = end(intersection); - std::for_each(first, last, [&](auto &road) { - const auto modifier = road.instruction.direction_modifier; - // use NoTurn, to not even have it as an IntermediateIntersection - const auto type = TurnType::NoTurn; + std::for_each(first, + last, + [&](auto &road) + { + const auto modifier = road.instruction.direction_modifier; + // use NoTurn, to not even have it as an IntermediateIntersection + const auto type = TurnType::NoTurn; - road.instruction = {type, modifier}; - }); + road.instruction = {type, modifier}; + }); return intersection; } diff --git a/src/guidance/turn_analysis.cpp b/src/guidance/turn_analysis.cpp index ca50f203f8a..414b6fdd3a5 100644 --- a/src/guidance/turn_analysis.cpp +++ b/src/guidance/turn_analysis.cpp @@ -105,7 +105,8 @@ Intersection TurnAnalysis::AssignTurnTypes( std::transform(intersection_view.begin(), intersection_view.end(), std::back_inserter(intersection), - [&](const extractor::intersection::IntersectionViewData &data) { + [&](const extractor::intersection::IntersectionViewData &data) + { return ConnectedRoad(data, {TurnType::Invalid, DirectionModifier::UTurn}, INVALID_LANE_DATAID); @@ -161,10 +162,13 @@ Intersection TurnAnalysis::AssignTurnTypes( // Turn On Ramps Into Off Ramps, if we come from a motorway-like road if (node_based_graph.GetEdgeData(entering_via_edge).flags.road_classification.IsMotorwayClass()) { - std::for_each(intersection.begin(), intersection.end(), [](ConnectedRoad &road) { - if (road.instruction.type == TurnType::OnRamp) - road.instruction.type = TurnType::OffRamp; - }); + std::for_each(intersection.begin(), + intersection.end(), + [](ConnectedRoad &road) + { + if (road.instruction.type == TurnType::OnRamp) + road.instruction.type = TurnType::OffRamp; + }); } // After we ran all handlers and determined instruction type diff --git a/src/guidance/turn_classification.cpp b/src/guidance/turn_classification.cpp index c191b65e0d5..f6d26cfef10 100644 --- a/src/guidance/turn_classification.cpp +++ b/src/guidance/turn_classification.cpp @@ -17,14 +17,14 @@ classifyIntersection(Intersection intersection, const osrm::util::Coordinate &lo std::sort(intersection.begin(), intersection.end(), - [](const ConnectedRoad &left, const ConnectedRoad &right) { - return left.perceived_bearing < right.perceived_bearing; - }); + [](const ConnectedRoad &left, const ConnectedRoad &right) + { return left.perceived_bearing < right.perceived_bearing; }); util::guidance::EntryClass entry_class; util::guidance::BearingClass bearing_class; - const bool canBeDiscretized = [&]() { + const bool canBeDiscretized = [&]() + { if (intersection.size() <= 1) return true; diff --git a/src/guidance/turn_discovery.cpp b/src/guidance/turn_discovery.cpp index 20005dd12d0..57b66f8a75c 100644 --- a/src/guidance/turn_discovery.cpp +++ b/src/guidance/turn_discovery.cpp @@ -127,9 +127,8 @@ bool findPreviousIntersection(const NodeID node_v, result_intersection.end() != std::find_if(result_intersection.begin(), result_intersection.end(), - [via_edge](const extractor::intersection::IntersectionViewData &road) { - return road.eid == via_edge; - }); + [via_edge](const extractor::intersection::IntersectionViewData &road) + { return road.eid == via_edge; }); if (!check_via_edge) { diff --git a/src/guidance/turn_handler.cpp b/src/guidance/turn_handler.cpp index b13cbf1c927..ec77b63566a 100644 --- a/src/guidance/turn_handler.cpp +++ b/src/guidance/turn_handler.cpp @@ -223,10 +223,12 @@ bool TurnHandler::isObviousOfTwo(const EdgeID via_edge, bool TurnHandler::hasObvious(const EdgeID &via_edge, const Fork &fork) const { - auto obvious_road = - std::adjacent_find(fork.begin, fork.end, [&, this](const auto &a, const auto &b) { - return this->isObviousOfTwo(via_edge, a, b) || this->isObviousOfTwo(via_edge, b, a); - }); + auto obvious_road = std::adjacent_find(fork.begin, + fork.end, + [&, this](const auto &a, const auto &b) { + return this->isObviousOfTwo(via_edge, a, b) || + this->isObviousOfTwo(via_edge, b, a); + }); // return whether an obvious road was found return obvious_road != fork.end; } @@ -246,10 +248,11 @@ Intersection TurnHandler::handleThreeWayTurn(const EdgeID via_edge, Intersection OOOOOOO */ - const auto all_links = - std::all_of(intersection.begin(), intersection.end(), [this](const auto &road) { - return node_based_graph.GetEdgeData(road.eid).flags.road_classification.IsLinkClass(); - }); + const auto all_links = std::all_of( + intersection.begin(), + intersection.end(), + [this](const auto &road) + { return node_based_graph.GetEdgeData(road.eid).flags.road_classification.IsLinkClass(); }); auto fork = findFork(via_edge, intersection); if (fork && (all_links || obvious_index == 0)) @@ -438,7 +441,8 @@ Intersection TurnHandler::assignLeftTurns(const EdgeID via_edge, const std::size_t starting_at) const { BOOST_ASSERT(starting_at < intersection.size()); - const auto switch_left_and_right = [](Intersection &intersection) { + const auto switch_left_and_right = [](Intersection &intersection) + { BOOST_ASSERT(!intersection.empty()); for (auto &road : intersection) @@ -462,7 +466,8 @@ Intersection TurnHandler::assignRightTurns(const EdgeID via_edge, const std::size_t up_to) const { BOOST_ASSERT(up_to <= intersection.size()); - const auto count_valid = [&intersection, up_to]() { + const auto count_valid = [&intersection, up_to]() + { std::size_t count = 0; for (std::size_t i = 1; i < up_to; ++i) if (intersection[i].entry_allowed) @@ -656,24 +661,36 @@ bool TurnHandler::isCompatibleByRoadClass(const Intersection &intersection, cons // except if rightmost fork candidate is also a link road const auto is_right_link_class = node_based_graph.GetEdgeData(fork.getRight().eid).flags.road_classification.IsLinkClass(); - if (!std::all_of(fork.begin + 1, fork.end, [&](ConnectedRoad &road) { - return is_right_link_class == - node_based_graph.GetEdgeData(road.eid).flags.road_classification.IsLinkClass(); - })) + if (!std::all_of(fork.begin + 1, + fork.end, + [&](ConnectedRoad &road) + { + return is_right_link_class == node_based_graph.GetEdgeData(road.eid) + .flags.road_classification.IsLinkClass(); + })) { return false; } - return std::all_of(fork.begin, fork.end, [&](ConnectedRoad &base) { - const auto base_class = node_based_graph.GetEdgeData(base.eid).flags.road_classification; - // check that there is no turn obvious == check that all turns are non-onvious - return std::all_of(fork.begin, fork.end, [&](ConnectedRoad &compare) { - const auto compare_class = - node_based_graph.GetEdgeData(compare.eid).flags.road_classification; - return compare.eid == base.eid || - !(obviousByRoadClass(via_class, base_class, compare_class)); + return std::all_of( + fork.begin, + fork.end, + [&](ConnectedRoad &base) + { + const auto base_class = + node_based_graph.GetEdgeData(base.eid).flags.road_classification; + // check that there is no turn obvious == check that all turns are non-onvious + return std::all_of( + fork.begin, + fork.end, + [&](ConnectedRoad &compare) + { + const auto compare_class = + node_based_graph.GetEdgeData(compare.eid).flags.road_classification; + return compare.eid == base.eid || + !(obviousByRoadClass(via_class, base_class, compare_class)); + }); }); - }); } // Checks whether a three-way-intersection coming from `via_edge` is a fork @@ -703,8 +720,11 @@ boost::optional TurnHandler::findFork(const EdgeID via_edge, // check if all entries in the fork range allow entry const bool only_valid_entries = intersection.hasAllValidEntries(fork->begin, fork->end); - const auto has_compatible_modes = - std::all_of(fork->begin, fork->end, [&](const auto &road) { + const auto has_compatible_modes = std::all_of( + fork->begin, + fork->end, + [&](const auto &road) + { return node_data_container .GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data) .travel_mode == diff --git a/src/guidance/turn_lane_augmentation.cpp b/src/guidance/turn_lane_augmentation.cpp index 862f9c35ed3..3977d0abefb 100644 --- a/src/guidance/turn_lane_augmentation.cpp +++ b/src/guidance/turn_lane_augmentation.cpp @@ -26,9 +26,9 @@ const constexpr extractor::TurnLaneType::Mask tag_by_modifier[] = { std::size_t getNumberOfTurns(const Intersection &intersection) { - return std::count_if(intersection.begin(), intersection.end(), [](const ConnectedRoad &road) { - return road.entry_allowed; - }); + return std::count_if(intersection.begin(), + intersection.end(), + [](const ConnectedRoad &road) { return road.entry_allowed; }); } LaneDataVector augmentMultiple(const std::size_t none_index, @@ -41,7 +41,8 @@ LaneDataVector augmentMultiple(const std::size_t none_index, // entries? // looking at the left side first - const auto range = [&]() { + const auto range = [&]() + { if (none_index == 0) { // find first connection_count - lane_data.size() valid turns @@ -106,17 +107,18 @@ LaneDataVector augmentMultiple(const std::size_t none_index, const auto intersection_range_first = intersection.begin() + range.first; const auto intersection_range_end = intersection.begin() + range.second; const auto allowed_in_range = - std::count_if(intersection_range_first, intersection_range_end, [](const auto &road) { - return road.entry_allowed; - }); + std::count_if(intersection_range_first, + intersection_range_end, + [](const auto &road) { return road.entry_allowed; }); if (allowed_in_range > 1 && lane_data[none_index].to - lane_data[none_index].from >= 1) { // check if there is a straight turn - auto straight_itr = - std::find_if(intersection_range_first, intersection_range_end, [](const auto &road) { - return road.instruction.direction_modifier == DirectionModifier::Straight; - }); + auto straight_itr = std::find_if( + intersection_range_first, + intersection_range_end, + [](const auto &road) + { return road.instruction.direction_modifier == DirectionModifier::Straight; }); // we have a straight turn? if (straight_itr != intersection_range_end) diff --git a/src/guidance/turn_lane_data.cpp b/src/guidance/turn_lane_data.cpp index 3be149442ba..952d788d7e1 100644 --- a/src/guidance/turn_lane_data.cpp +++ b/src/guidance/turn_lane_data.cpp @@ -67,26 +67,26 @@ LaneDataVector laneDataFromDescription(const TurnLaneDescription &turn_lane_desc const auto num_lanes = boost::numeric_cast(turn_lane_description.size()); const auto setLaneData = - [&](LaneMap &map, TurnLaneType::Mask full_mask, const LaneID current_lane) { - const auto isSet = [&](const TurnLaneType::Mask test_mask) -> bool { - return (test_mask & full_mask) == test_mask; - }; + [&](LaneMap &map, TurnLaneType::Mask full_mask, const LaneID current_lane) + { + const auto isSet = [&](const TurnLaneType::Mask test_mask) -> bool + { return (test_mask & full_mask) == test_mask; }; - for (const auto shift : util::irange(0, TurnLaneType::NUM_TYPES)) + for (const auto shift : util::irange(0, TurnLaneType::NUM_TYPES)) + { + TurnLaneType::Mask mask = 1 << shift; + if (isSet(mask)) { - TurnLaneType::Mask mask = 1 << shift; - if (isSet(mask)) + auto map_iterator = map.find(mask); + if (map_iterator == map.end()) + map[mask] = std::make_pair(current_lane, current_lane); + else { - auto map_iterator = map.find(mask); - if (map_iterator == map.end()) - map[mask] = std::make_pair(current_lane, current_lane); - else - { - map_iterator->second.first = current_lane; - } + map_iterator->second.first = current_lane; } } - }; + } + }; LaneMap lane_map; LaneID lane_nr = num_lanes - 1; @@ -108,7 +108,8 @@ LaneDataVector laneDataFromDescription(const TurnLaneDescription &turn_lane_desc std::sort(lane_data.begin(), lane_data.end()); // check whether a given turn lane string resulted in valid lane data - const auto hasValidOverlaps = [](const LaneDataVector &lane_data) { + const auto hasValidOverlaps = [](const LaneDataVector &lane_data) + { // Allow an overlap of at most one. Larger overlaps would result in crossing another turn, // which is invalid for (std::size_t index = 1; index < lane_data.size(); ++index) @@ -134,15 +135,17 @@ LaneDataVector laneDataFromDescription(const TurnLaneDescription &turn_lane_desc LaneDataVector::iterator findTag(const TurnLaneType::Mask tag, LaneDataVector &data) { - return std::find_if(data.begin(), data.end(), [&](const TurnLaneData &lane_data) { - return (tag & lane_data.tag) != TurnLaneType::empty; - }); + return std::find_if(data.begin(), + data.end(), + [&](const TurnLaneData &lane_data) + { return (tag & lane_data.tag) != TurnLaneType::empty; }); } LaneDataVector::const_iterator findTag(const TurnLaneType::Mask tag, const LaneDataVector &data) { - return std::find_if(data.cbegin(), data.cend(), [&](const TurnLaneData &lane_data) { - return (tag & lane_data.tag) != TurnLaneType::empty; - }); + return std::find_if(data.cbegin(), + data.cend(), + [&](const TurnLaneData &lane_data) + { return (tag & lane_data.tag) != TurnLaneType::empty; }); } bool hasTag(const TurnLaneType::Mask tag, const LaneDataVector &data) diff --git a/src/guidance/turn_lane_handler.cpp b/src/guidance/turn_lane_handler.cpp index e9891c86184..98938525d73 100644 --- a/src/guidance/turn_lane_handler.cpp +++ b/src/guidance/turn_lane_handler.cpp @@ -24,9 +24,9 @@ namespace { std::size_t getNumberOfTurns(const Intersection &intersection) { - return std::count_if(intersection.begin(), intersection.end(), [](const ConnectedRoad &road) { - return road.entry_allowed; - }); + return std::count_if(intersection.begin(), + intersection.end(), + [](const ConnectedRoad &road) { return road.entry_allowed; }); } } // namespace @@ -158,10 +158,10 @@ TurnLaneScenario TurnLaneHandler::deduceScenario(const NodeID at, return TurnLaneScenario::NONE; // really don't touch roundabouts (#2626) - if (intersection.end() != - std::find_if(intersection.begin(), intersection.end(), [](const auto &road) { - return hasRoundaboutType(road.instruction); - })) + if (intersection.end() != std::find_if(intersection.begin(), + intersection.end(), + [](const auto &road) + { return hasRoundaboutType(road.instruction); })) return TurnLaneScenario::NONE; // if only a uturn exists, there is nothing we can do @@ -233,7 +233,8 @@ TurnLaneScenario TurnLaneHandler::deduceScenario(const NodeID at, if (via_edge == road.eid) return TurnLaneScenario::SLIPROAD; - const auto &closest_road = [&]() { + const auto &closest_road = [&]() + { if (road_index + 1 == previous_intersection.size()) { BOOST_ASSERT(road_index > 1); @@ -419,7 +420,8 @@ bool TurnLaneHandler::isSimpleIntersection(const LaneDataVector &lane_data, return std::count_if( lane_data.begin(), lane_data.end(), - [](const TurnLaneData &data) { + [](const TurnLaneData &data) + { return ((data.tag & TurnLaneType::merge_to_left) != TurnLaneType::empty) || ((data.tag & TurnLaneType::merge_to_right) != TurnLaneType::empty); }) + @@ -429,7 +431,8 @@ bool TurnLaneHandler::isSimpleIntersection(const LaneDataVector &lane_data, // in case an intersection offers far more lane data items than actual turns, some of them // have to be for another intersection. A single additional item can be for an invalid bus lane. - const auto num_turns = [&]() { + const auto num_turns = [&]() + { auto count = getNumberOfTurns(intersection); if (count < lane_data.size() && !intersection[0].entry_allowed && lane_data.back().tag == TurnLaneType::uturn) @@ -453,10 +456,10 @@ bool TurnLaneHandler::isSimpleIntersection(const LaneDataVector &lane_data, // more turns than lane data if (num_turns > lane_data.size() && - lane_data.end() == - std::find_if(lane_data.begin(), lane_data.end(), [](const TurnLaneData &data) { - return data.tag == TurnLaneType::none; - })) + lane_data.end() == std::find_if(lane_data.begin(), + lane_data.end(), + [](const TurnLaneData &data) + { return data.tag == TurnLaneType::none; })) { return false; } @@ -485,7 +488,8 @@ bool TurnLaneHandler::isSimpleIntersection(const LaneDataVector &lane_data, // u-turn tags are at the outside of the lane-tags and require special handling, since // locating their best match requires knowledge on the neighboring tag. (see documentation // on findBestMatch/findBestMatchForReverse - const auto best_match = [&]() { + const auto best_match = [&]() + { // normal tag or u-turn as only choice (no other tag present) if (data.tag != TurnLaneType::uturn || lane_data.size() == 1) return findBestMatch(data.tag, intersection); @@ -644,7 +648,8 @@ std::pair TurnLaneHandler::partitionLaneData( matched_at_second[none_index] = true; } - const auto augmentEntry = [&](TurnLaneData &data) { + const auto augmentEntry = [&](TurnLaneData &data) + { for (std::size_t lane = 0; lane < turn_lane_data.size(); ++lane) if (matched_at_second[lane]) { @@ -713,15 +718,15 @@ Intersection TurnLaneHandler::handleSliproadTurn(Intersection intersection, std::distance(previous_intersection.begin(), std::find_if(previous_intersection.begin(), previous_intersection.end(), - [](const ConnectedRoad &road) { - return road.instruction.type == TurnType::Sliproad; - })); + [](const ConnectedRoad &road) + { return road.instruction.type == TurnType::Sliproad; })); BOOST_ASSERT(sliproad_index <= previous_intersection.size()); const auto &sliproad = previous_intersection[sliproad_index]; // code duplicatino with deduceScenario: TODO refactor - const auto &main_road = [&]() { + const auto &main_road = [&]() + { if (sliproad_index + 1 == previous_intersection.size()) { BOOST_ASSERT(sliproad_index > 1); diff --git a/src/guidance/turn_lane_matcher.cpp b/src/guidance/turn_lane_matcher.cpp index ede3304262d..31bc1df57dc 100644 --- a/src/guidance/turn_lane_matcher.cpp +++ b/src/guidance/turn_lane_matcher.cpp @@ -49,9 +49,8 @@ DirectionModifier::Enum getMatchingModifier(const TurnLaneType::Mask tag) // check whether a match of a given tag and a turn instruction can be seen as valid bool isValidMatch(const TurnLaneType::Mask tag, const TurnInstruction instruction) { - const auto isMirroredModifier = [](const TurnInstruction instruction) { - return instruction.type == TurnType::Merge; - }; + const auto isMirroredModifier = [](const TurnInstruction instruction) + { return instruction.type == TurnType::Merge; }; if (tag == TurnLaneType::uturn) { @@ -114,7 +113,8 @@ typename Intersection::const_iterator findBestMatch(const TurnLaneType::Mask tag { return std::min_element(intersection.begin(), intersection.end(), - [tag](const ConnectedRoad &lhs, const ConnectedRoad &rhs) { + [tag](const ConnectedRoad &lhs, const ConnectedRoad &rhs) + { // prefer valid matches if (isValidMatch(tag, lhs.instruction) != isValidMatch(tag, rhs.instruction)) @@ -144,7 +144,8 @@ typename Intersection::const_iterator findBestMatchForReverse(const TurnLaneType return std::min_element( intersection.begin() + std::distance(intersection.begin(), neighbor_itr), intersection.end(), - [](const ConnectedRoad &lhs, const ConnectedRoad &rhs) { + [](const ConnectedRoad &lhs, const ConnectedRoad &rhs) + { const TurnLaneType::Mask tag = TurnLaneType::uturn; // prefer valid matches if (isValidMatch(tag, lhs.instruction) != isValidMatch(tag, rhs.instruction)) @@ -197,7 +198,8 @@ Intersection triviallyMatchLanesToTurns(Intersection intersection, { std::size_t road_index = 1, lane = 0; - const auto matchRoad = [&](ConnectedRoad &road, const TurnLaneData &data) { + const auto matchRoad = [&](ConnectedRoad &road, const TurnLaneData &data) + { util::guidance::LaneTupleIdPair key{{LaneID(data.to - data.from + 1), data.from}, lane_string_id}; diff --git a/src/partitioner/bisection_to_partition.cpp b/src/partitioner/bisection_to_partition.cpp index a567dc524e5..9cf5276cf76 100644 --- a/src/partitioner/bisection_to_partition.cpp +++ b/src/partitioner/bisection_to_partition.cpp @@ -64,9 +64,8 @@ void partitionLevel(const std::vector &node_to_bisection_id, std::accumulate(permutation.begin() + cell.begin, permutation.begin() + cell.end, BisectionID{0}, - [&node_to_bisection_id](const BisectionID lhs, const NodeID rhs) { - return lhs | node_to_bisection_id[rhs]; - }); + [&node_to_bisection_id](const BisectionID lhs, const NodeID rhs) + { return lhs | node_to_bisection_id[rhs]; }); // masks all bit strictly higher then cell.bit BOOST_ASSERT(sizeof(unsigned long long) * CHAR_BIT > sizeof(BisectionID) * CHAR_BIT); const BisectionID mask = (1ULL << (cell.bit + 1)) - 1; @@ -88,9 +87,8 @@ void partitionLevel(const std::vector &node_to_bisection_id, std::uint32_t middle = std::partition(permutation.begin() + cell.begin, permutation.begin() + cell.end, - [is_left_mask, &node_to_bisection_id](const auto node_id) { - return node_to_bisection_id[node_id] & is_left_mask; - }) - + [is_left_mask, &node_to_bisection_id](const auto node_id) + { return node_to_bisection_id[node_id] & is_left_mask; }) - permutation.begin(); if (bit > 0) diff --git a/src/partitioner/dinic_max_flow.cpp b/src/partitioner/dinic_max_flow.cpp index 91b99b587ea..ae1765b6df0 100644 --- a/src/partitioner/dinic_max_flow.cpp +++ b/src/partitioner/dinic_max_flow.cpp @@ -19,10 +19,10 @@ const auto constexpr INVALID_LEVEL = std::numeric_limits::m auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set, const BisectionGraphView &view) { - return [&](const NodeID nid) { - const auto is_not_contained = [&set](const BisectionEdge &edge) { - return set.count(edge.target) == 0; - }; + return [&](const NodeID nid) + { + const auto is_not_contained = [&set](const BisectionEdge &edge) + { return set.count(edge.target) == 0; }; return view.EndEdges(nid) != std::find_if(view.BeginEdges(nid), view.EndEdges(nid), is_not_contained); }; @@ -132,12 +132,12 @@ DinicMaxFlow::ComputeLevelGraph(const BisectionGraphView &view, levels[edge.target] = 0; } // check if there is flow present on an edge - const auto has_flow = [&](const NodeID from, const NodeID to) { - return flow[from].find(to) != flow[from].end(); - }; + const auto has_flow = [&](const NodeID from, const NodeID to) + { return flow[from].find(to) != flow[from].end(); }; // perform a relaxation step in the BFS algorithm - const auto relax_node = [&](const NodeID node_id) { + const auto relax_node = [&](const NodeID node_id) + { // don't relax sink nodes if (sink_nodes.count(node_id)) return; @@ -180,9 +180,11 @@ std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow, std::size_t flow_increase = 0; // augment the flow along a path in the level graph - const auto augment_flow = [&flow](const std::vector &path) { + const auto augment_flow = [&flow](const std::vector &path) + { // add/remove flow edges from the current residual graph - const auto augment_one = [&flow](const NodeID from, const NodeID to) { + const auto augment_one = [&flow](const NodeID from, const NodeID to) + { // check if there is flow in the opposite direction auto existing_edge = flow[to].find(from); if (existing_edge != flow[to].end()) @@ -200,7 +202,8 @@ std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow, [[maybe_unused]] auto _ = std::adjacent_find(path.begin(), path.end(), augment_one); }; - const auto augment_all_paths = [&](const NodeID sink_node_id) { + const auto augment_all_paths = [&](const NodeID sink_node_id) + { // only augment sinks if (levels[sink_node_id] == INVALID_LEVEL) return; @@ -295,10 +298,10 @@ bool DinicMaxFlow::Validate(const BisectionGraphView &view, const SourceSinkNodes &sink_nodes) const { // sink and source cannot share a common node - const auto separated = - std::find_if(source_nodes.begin(), source_nodes.end(), [&sink_nodes](const auto node) { - return sink_nodes.count(node); - }) == source_nodes.end(); + const auto separated = std::find_if(source_nodes.begin(), + source_nodes.end(), + [&sink_nodes](const auto node) + { return sink_nodes.count(node); }) == source_nodes.end(); const auto invalid_id = [&view](const NodeID nid) { return nid >= view.NumberOfNodes(); }; const auto in_range_source = diff --git a/src/partitioner/inertial_flow.cpp b/src/partitioner/inertial_flow.cpp index 6bc5cf1b7d4..04805faaa54 100644 --- a/src/partitioner/inertial_flow.cpp +++ b/src/partitioner/inertial_flow.cpp @@ -53,21 +53,25 @@ makeSpatialOrder(const BisectionGraphView &view, const double ratio, const doubl // adress of the very first node const auto node_zero = &(*view.Begin()); - std::transform(view.Begin(), view.End(), std::back_inserter(embedding), [&](const auto &node) { - const auto node_id = static_cast(&node - node_zero); - return NodeWithCoordinate{node_id, node.coordinate}; - }); - - const auto project = [slope](const auto &each) { + std::transform(view.Begin(), + view.End(), + std::back_inserter(embedding), + [&](const auto &node) + { + const auto node_id = static_cast(&node - node_zero); + return NodeWithCoordinate{node_id, node.coordinate}; + }); + + const auto project = [slope](const auto &each) + { auto lon = static_cast(each.coordinate.lon); auto lat = static_cast(each.coordinate.lat); return slope * lon + (1. - std::fabs(slope)) * lat; }; - const auto spatially = [&](const auto &lhs, const auto &rhs) { - return project(lhs) < project(rhs); - }; + const auto spatially = [&](const auto &lhs, const auto &rhs) + { return project(lhs) < project(rhs); }; const std::size_t n = ratio * embedding.size(); @@ -96,7 +100,8 @@ DinicMaxFlow::MinCut bestMinCut(const BisectionGraphView &view, DinicMaxFlow::MinCut best; best.num_edges = -1; - const auto get_balance = [&view, balance](const auto num_nodes_source) { + const auto get_balance = [&view, balance](const auto num_nodes_source) + { const auto perfect_balance = view.NumberOfNodes() / 2; const auto allowed_balance = balance * perfect_balance; const auto bigger_side = @@ -114,36 +119,41 @@ DinicMaxFlow::MinCut bestMinCut(const BisectionGraphView &view, tbb::blocked_range range{0, n, 1}; - const auto balance_delta = [&view](const auto num_nodes_source) { + const auto balance_delta = [&view](const auto num_nodes_source) + { const std::int64_t difference = static_cast(view.NumberOfNodes()) / 2 - num_nodes_source; return std::abs(difference); }; - tbb::parallel_for(range, [&](const auto &chunk) { - for (auto round = chunk.begin(), end = chunk.end(); round != end; ++round) - { - const auto slope = -1. + round * (2. / n); - - auto order = makeSpatialOrder(view, ratio, slope); - auto cut = DinicMaxFlow()(view, order.sources, order.sinks); - auto cut_balance = get_balance(cut.num_nodes_source); - - { - std::lock_guard guard{lock}; - - // Swap to keep the destruction of the old object outside of critical section. - if (cut.num_edges * cut_balance < best.num_edges * best_balance || - (cut.num_edges == best.num_edges && - balance_delta(cut.num_nodes_source) < balance_delta(best.num_nodes_source))) - { - best_balance = cut_balance; - std::swap(best, cut); - } - } - // cut gets destroyed here - } - }); + tbb::parallel_for(range, + [&](const auto &chunk) + { + for (auto round = chunk.begin(), end = chunk.end(); round != end; ++round) + { + const auto slope = -1. + round * (2. / n); + + auto order = makeSpatialOrder(view, ratio, slope); + auto cut = DinicMaxFlow()(view, order.sources, order.sinks); + auto cut_balance = get_balance(cut.num_nodes_source); + + { + std::lock_guard guard{lock}; + + // Swap to keep the destruction of the old object outside of + // critical section. + if (cut.num_edges * cut_balance < best.num_edges * best_balance || + (cut.num_edges == best.num_edges && + balance_delta(cut.num_nodes_source) < + balance_delta(best.num_nodes_source))) + { + best_balance = cut_balance; + std::swap(best, cut); + } + } + // cut gets destroyed here + } + }); return best; } diff --git a/src/partitioner/recursive_bisection.cpp b/src/partitioner/recursive_bisection.cpp index de9e509d91b..63b3a39fdb5 100644 --- a/src/partitioner/recursive_bisection.cpp +++ b/src/partitioner/recursive_bisection.cpp @@ -58,40 +58,48 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_, std::vector forest; forest.reserve(last - first); - std::transform(first, last, std::back_inserter(forest), [this](auto graph) { - return TreeNode{std::move(graph), internal_state.SCCDepth()}; - }); + std::transform(first, + last, + std::back_inserter(forest), + [this](auto graph) { + return TreeNode{std::move(graph), internal_state.SCCDepth()}; + }); using Feeder = tbb::feeder; TIMER_START(bisection); // Bisect graph into two parts. Get partition point and recurse left and right in parallel. - tbb::parallel_for_each(begin(forest), end(forest), [&](const TreeNode &node, Feeder &feeder) { - const auto cut = - computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor); - const auto center = internal_state.ApplyBisection( - node.graph.Begin(), node.graph.End(), node.depth, cut.flags); - - const auto terminal = [&](const auto &node) { - const auto maximum_depth = sizeof(BisectionID) * CHAR_BIT; - const auto too_small = node.graph.NumberOfNodes() < maximum_cell_size; - const auto too_deep = node.depth >= maximum_depth; - return too_small || too_deep; - }; - - BisectionGraphView left_graph{bisection_graph, node.graph.Begin(), center}; - TreeNode left_node{std::move(left_graph), node.depth + 1}; - - if (!terminal(left_node)) - feeder.add(left_node); - - BisectionGraphView right_graph{bisection_graph, center, node.graph.End()}; - TreeNode right_node{std::move(right_graph), node.depth + 1}; - - if (!terminal(right_node)) - feeder.add(right_node); - }); + tbb::parallel_for_each( + begin(forest), + end(forest), + [&](const TreeNode &node, Feeder &feeder) + { + const auto cut = + computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor); + const auto center = internal_state.ApplyBisection( + node.graph.Begin(), node.graph.End(), node.depth, cut.flags); + + const auto terminal = [&](const auto &node) + { + const auto maximum_depth = sizeof(BisectionID) * CHAR_BIT; + const auto too_small = node.graph.NumberOfNodes() < maximum_cell_size; + const auto too_deep = node.depth >= maximum_depth; + return too_small || too_deep; + }; + + BisectionGraphView left_graph{bisection_graph, node.graph.Begin(), center}; + TreeNode left_node{std::move(left_graph), node.depth + 1}; + + if (!terminal(left_node)) + feeder.add(left_node); + + BisectionGraphView right_graph{bisection_graph, center, node.graph.End()}; + TreeNode right_node{std::move(right_graph), node.depth + 1}; + + if (!terminal(right_node)) + feeder.add(right_node); + }); TIMER_STOP(bisection); diff --git a/src/partitioner/recursive_bisection_state.cpp b/src/partitioner/recursive_bisection_state.cpp index f6581674cc1..21acf142b43 100644 --- a/src/partitioner/recursive_bisection_state.cpp +++ b/src/partitioner/recursive_bisection_state.cpp @@ -45,9 +45,8 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin, } // Keep items with `0` as partition id to the left, move other to the right - auto by_flag_bit = [this, flag](const auto &node) { - return BisectionID{0} == (bisection_ids[node.original_id] & flag); - }; + auto by_flag_bit = [this, flag](const auto &node) + { return BisectionID{0} == (bisection_ids[node.original_id] & flag); }; auto begin = bisection_graph.Begin() + std::distance(bisection_graph.CBegin(), const_begin); const auto end = begin + std::distance(const_begin, const_end); @@ -59,26 +58,34 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin, std::transform(const_begin, const_end, mapping.begin(), - [by_flag_bit, &lesser_id, &upper_id](const auto &node) { - return by_flag_bit(node) ? lesser_id++ : upper_id++; - }); + [by_flag_bit, &lesser_id, &upper_id](const auto &node) + { return by_flag_bit(node) ? lesser_id++ : upper_id++; }); // erase all edges that point into different partitions - std::for_each(begin, end, [&](auto &node) { - const auto node_flag = by_flag_bit(node); - bisection_graph.RemoveEdges(node, [&](const BisectionGraph::EdgeT &edge) { - const auto target_flag = by_flag_bit(*(const_begin + edge.target)); - return (node_flag != target_flag); - }); - }); + std::for_each(begin, + end, + [&](auto &node) + { + const auto node_flag = by_flag_bit(node); + bisection_graph.RemoveEdges(node, + [&](const BisectionGraph::EdgeT &edge) + { + const auto target_flag = + by_flag_bit(*(const_begin + edge.target)); + return (node_flag != target_flag); + }); + }); auto center = std::stable_partition(begin, end, by_flag_bit); // remap all remaining edges - std::for_each(const_begin, const_end, [&](const auto &node) { - for (auto &edge : bisection_graph.Edges(node)) - edge.target = mapping[edge.target]; - }); + std::for_each(const_begin, + const_end, + [&](const auto &node) + { + for (auto &edge : bisection_graph.Edges(node)) + edge.target = mapping[edge.target]; + }); return const_begin + std::distance(begin, center); } @@ -93,13 +100,13 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s scc_algo.Run(); // Map Edges to Sccs - const auto in_small = [&scc_algo, small_component_size](const NodeID node_id) { - return scc_algo.GetComponentSize(scc_algo.GetComponentID(node_id)) <= small_component_size; - }; + const auto in_small = [&scc_algo, small_component_size](const NodeID node_id) + { return scc_algo.GetComponentSize(scc_algo.GetComponentID(node_id)) <= small_component_size; }; const constexpr std::size_t small_component_id = -1; std::unordered_map component_map; - const auto transform_id = [&](const NodeID node_id) -> std::size_t { + const auto transform_id = [&](const NodeID node_id) -> std::size_t + { if (in_small(node_id)) return small_component_id; else @@ -111,16 +118,19 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s mapping[node.original_id] = component_map[transform_id(node.original_id)]++; // needs to remove edges, if we should ever switch to directed graphs here - std::stable_sort( - bisection_graph.Begin(), bisection_graph.End(), [&](const auto &lhs, const auto &rhs) { - return transform_id(lhs.original_id) < transform_id(rhs.original_id); - }); + std::stable_sort(bisection_graph.Begin(), + bisection_graph.End(), + [&](const auto &lhs, const auto &rhs) + { return transform_id(lhs.original_id) < transform_id(rhs.original_id); }); // remap all remaining edges - std::for_each(bisection_graph.Begin(), bisection_graph.End(), [&](const auto &node) { - for (auto &edge : bisection_graph.Edges(node)) - edge.target = mapping[edge.target]; - }); + std::for_each(bisection_graph.Begin(), + bisection_graph.End(), + [&](const auto &node) + { + for (auto &edge : bisection_graph.Edges(node)) + edge.target = mapping[edge.target]; + }); std::vector views; auto last = bisection_graph.CBegin(); @@ -139,7 +149,8 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s } views.push_back(BisectionGraphView(bisection_graph, last, bisection_graph.CEnd())); - bool has_small_component = [&]() { + bool has_small_component = [&]() + { for (std::size_t i = 0; i < scc_algo.GetNumberOfComponents(); ++i) if (scc_algo.GetComponentSize(i) <= small_component_size) return true; @@ -154,7 +165,8 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s // ceil(log_2(components)) scc_levels = ceil(log(views.size()) / log(2.0)); - const auto conscutive_component_id = [&](const NodeID nid) { + const auto conscutive_component_id = [&](const NodeID nid) + { const auto component_id = transform_id(nid); const auto itr = ordered_component_ids.find(component_id); BOOST_ASSERT(itr != ordered_component_ids.end()); diff --git a/src/partitioner/renumber.cpp b/src/partitioner/renumber.cpp index 278a0ea81aa..14f2ca660aa 100644 --- a/src/partitioner/renumber.cpp +++ b/src/partitioner/renumber.cpp @@ -46,10 +46,10 @@ std::vector makePermutation(const DynamicEdgeBasedGraph &graph, // Nodes in the same cell will be sorted by cell ID on the level below for (const auto &partition : partitions) { - std::stable_sort( - ordering.begin(), ordering.end(), [&partition](const auto lhs, const auto rhs) { - return partition[lhs] < partition[rhs]; - }); + std::stable_sort(ordering.begin(), + ordering.end(), + [&partition](const auto lhs, const auto rhs) + { return partition[lhs] < partition[rhs]; }); } // Now sort the nodes by the level at which they are a border node, descening. @@ -57,10 +57,10 @@ std::vector makePermutation(const DynamicEdgeBasedGraph &graph, // whereas nodes that are nerver border nodes are sorted to the end of the array. // Note: Since we use a stable sort that preserves the cell sorting within each level auto border_level = getHighestBorderLevel(graph, partitions); - std::stable_sort( - ordering.begin(), ordering.end(), [&border_level](const auto lhs, const auto rhs) { - return border_level[lhs] > border_level[rhs]; - }); + std::stable_sort(ordering.begin(), + ordering.end(), + [&border_level](const auto lhs, const auto rhs) + { return border_level[lhs] > border_level[rhs]; }); return util::orderingToPermutation(ordering); } diff --git a/src/tools/partition.cpp b/src/tools/partition.cpp index 44f06fad73b..acc06a045be 100644 --- a/src/tools/partition.cpp +++ b/src/tools/partition.cpp @@ -53,7 +53,8 @@ void validate(boost::any &v, const std::vector &values, MaxCellSize std::transform(std::sregex_token_iterator(s.begin(), s.end(), re, -1), std::sregex_token_iterator(), std::back_inserter(output), - [](const auto &x) { + [](const auto &x) + { try { return boost::lexical_cast(x); @@ -215,7 +216,8 @@ try return EXIT_FAILURE; } - auto check_file = [](const boost::filesystem::path &path) { + auto check_file = [](const boost::filesystem::path &path) + { if (!boost::filesystem::is_regular_file(path)) { util::Log(logERROR) << "Input file " << path << " not found!"; diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index 1e6a9c2661a..4f2fae5ef91 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -343,10 +343,12 @@ try } else { - std::packaged_task server_task([&] { - routing_server->Run(); - return 0; - }); + std::packaged_task server_task( + [&] + { + routing_server->Run(); + return 0; + }); auto future = server_task.get_future(); std::thread server_thread(std::move(server_task)); diff --git a/src/updater/csv_source.cpp b/src/updater/csv_source.cpp index 97316248773..ffcdc9ac50d 100644 --- a/src/updater/csv_source.cpp +++ b/src/updater/csv_source.cpp @@ -39,9 +39,9 @@ SegmentLookupTable readSegmentValues(const std::vector &paths) // Check consistency of keys in the result lookup table auto result = parser(paths); const auto found_inconsistency = - std::find_if(std::begin(result.lookup), std::end(result.lookup), [](const auto &entry) { - return entry.first.from == entry.first.to; - }); + std::find_if(std::begin(result.lookup), + std::end(result.lookup), + [](const auto &entry) { return entry.first.from == entry.first.to; }); if (found_inconsistency != std::end(result.lookup)) { util::Log(logWARNING) << "Empty segment in CSV with node " + diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index a9ec31a6f23..d467675df39 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -155,10 +155,11 @@ updateSegmentData(const UpdaterConfig &config, // closure to convert SpeedSource value to weight and count fallbacks to durations std::atomic fallbacks_to_duration{0}; - auto convertToWeight = [&profile_properties, - &fallbacks_to_duration](const SegmentWeight &existing_weight, - const SpeedSource &value, - double distance_in_meters) { + auto convertToWeight = + [&profile_properties, &fallbacks_to_duration](const SegmentWeight &existing_weight, + const SpeedSource &value, + double distance_in_meters) + { double rate = std::numeric_limits::quiet_NaN(); // if value.rate is not set, we fall back to duration @@ -211,96 +212,104 @@ updateSegmentData(const UpdaterConfig &config, using DirectionalGeometryID = extractor::SegmentDataContainer::DirectionalGeometryID; auto range = tbb::blocked_range(0, segment_data.GetNumberOfGeometries()); - tbb::parallel_for(range, [&](const auto &range) { - auto &counters = segment_speeds_counters.local(); - std::vector segment_lengths; - for (auto geometry_id = range.begin(); geometry_id < range.end(); geometry_id++) + tbb::parallel_for( + range, + [&](const auto &range) { - auto nodes_range = segment_data.GetForwardGeometry(geometry_id); - - segment_lengths.clear(); - segment_lengths.reserve(nodes_range.size() + 1); - util::for_each_pair(nodes_range, [&](const auto &u, const auto &v) { - segment_lengths.push_back(util::coordinate_calculation::greatCircleDistance( - coordinates[u], coordinates[v])); - }); - - auto fwd_weights_range = segment_data.GetForwardWeights(geometry_id); - auto fwd_durations_range = segment_data.GetForwardDurations(geometry_id); - auto fwd_datasources_range = segment_data.GetForwardDatasources(geometry_id); - bool fwd_was_updated = false; - for (const auto segment_offset : util::irange(0, fwd_weights_range.size())) + auto &counters = segment_speeds_counters.local(); + std::vector segment_lengths; + for (auto geometry_id = range.begin(); geometry_id < range.end(); geometry_id++) { - auto u = osm_node_ids[nodes_range[segment_offset]]; - auto v = osm_node_ids[nodes_range[segment_offset + 1]]; - - // Self-loops are artifical segments (e.g. traffic light nodes), do not - // waste time updating them with traffic data - if (u == v) - continue; - - if (auto value = segment_speed_lookup({u, v})) + auto nodes_range = segment_data.GetForwardGeometry(geometry_id); + + segment_lengths.clear(); + segment_lengths.reserve(nodes_range.size() + 1); + util::for_each_pair(nodes_range, + [&](const auto &u, const auto &v) + { + segment_lengths.push_back( + util::coordinate_calculation::greatCircleDistance( + coordinates[u], coordinates[v])); + }); + + auto fwd_weights_range = segment_data.GetForwardWeights(geometry_id); + auto fwd_durations_range = segment_data.GetForwardDurations(geometry_id); + auto fwd_datasources_range = segment_data.GetForwardDatasources(geometry_id); + bool fwd_was_updated = false; + for (const auto segment_offset : + util::irange(0, fwd_weights_range.size())) { - auto segment_length = segment_lengths[segment_offset]; - auto new_duration = convertToDuration(value->speed, segment_length); - auto new_weight = - convertToWeight(fwd_weights_range[segment_offset], *value, segment_length); - fwd_was_updated = true; - - fwd_weights_range[segment_offset] = new_weight; - fwd_durations_range[segment_offset] = new_duration; - fwd_datasources_range[segment_offset] = value->source; - counters[value->source] += 1; + auto u = osm_node_ids[nodes_range[segment_offset]]; + auto v = osm_node_ids[nodes_range[segment_offset + 1]]; + + // Self-loops are artifical segments (e.g. traffic light nodes), do not + // waste time updating them with traffic data + if (u == v) + continue; + + if (auto value = segment_speed_lookup({u, v})) + { + auto segment_length = segment_lengths[segment_offset]; + auto new_duration = convertToDuration(value->speed, segment_length); + auto new_weight = convertToWeight( + fwd_weights_range[segment_offset], *value, segment_length); + fwd_was_updated = true; + + fwd_weights_range[segment_offset] = new_weight; + fwd_durations_range[segment_offset] = new_duration; + fwd_datasources_range[segment_offset] = value->source; + counters[value->source] += 1; + } + else + { + counters[LUA_SOURCE] += 1; + } } - else + if (fwd_was_updated) + updated_segments.push_back(GeometryID{geometry_id, true}); + + // In this case we want it oriented from in forward directions + auto rev_weights_range = + boost::adaptors::reverse(segment_data.GetReverseWeights(geometry_id)); + auto rev_durations_range = + boost::adaptors::reverse(segment_data.GetReverseDurations(geometry_id)); + auto rev_datasources_range = + boost::adaptors::reverse(segment_data.GetReverseDatasources(geometry_id)); + bool rev_was_updated = false; + + for (const auto segment_offset : + util::irange(0, rev_weights_range.size())) { - counters[LUA_SOURCE] += 1; + auto u = osm_node_ids[nodes_range[segment_offset]]; + auto v = osm_node_ids[nodes_range[segment_offset + 1]]; + + // Self-loops are artifical segments (e.g. traffic light nodes), do not + // waste time updating them with traffic data + if (u == v) + continue; + + if (auto value = segment_speed_lookup({v, u})) + { + auto segment_length = segment_lengths[segment_offset]; + auto new_duration = convertToDuration(value->speed, segment_length); + auto new_weight = convertToWeight( + rev_weights_range[segment_offset], *value, segment_length); + rev_was_updated = true; + + rev_weights_range[segment_offset] = new_weight; + rev_durations_range[segment_offset] = new_duration; + rev_datasources_range[segment_offset] = value->source; + counters[value->source] += 1; + } + else + { + counters[LUA_SOURCE] += 1; + } } + if (rev_was_updated) + updated_segments.push_back(GeometryID{geometry_id, false}); } - if (fwd_was_updated) - updated_segments.push_back(GeometryID{geometry_id, true}); - - // In this case we want it oriented from in forward directions - auto rev_weights_range = - boost::adaptors::reverse(segment_data.GetReverseWeights(geometry_id)); - auto rev_durations_range = - boost::adaptors::reverse(segment_data.GetReverseDurations(geometry_id)); - auto rev_datasources_range = - boost::adaptors::reverse(segment_data.GetReverseDatasources(geometry_id)); - bool rev_was_updated = false; - - for (const auto segment_offset : util::irange(0, rev_weights_range.size())) - { - auto u = osm_node_ids[nodes_range[segment_offset]]; - auto v = osm_node_ids[nodes_range[segment_offset + 1]]; - - // Self-loops are artifical segments (e.g. traffic light nodes), do not - // waste time updating them with traffic data - if (u == v) - continue; - - if (auto value = segment_speed_lookup({v, u})) - { - auto segment_length = segment_lengths[segment_offset]; - auto new_duration = convertToDuration(value->speed, segment_length); - auto new_weight = - convertToWeight(rev_weights_range[segment_offset], *value, segment_length); - rev_was_updated = true; - - rev_weights_range[segment_offset] = new_weight; - rev_durations_range[segment_offset] = new_duration; - rev_datasources_range[segment_offset] = value->source; - counters[value->source] += 1; - } - else - { - counters[LUA_SOURCE] += 1; - } - } - if (rev_was_updated) - updated_segments.push_back(GeometryID{geometry_id, false}); - } - }); // parallel_for + }); // parallel_for counters_type merged_counters(num_counters, 0); for (const auto &counters : segment_speeds_counters) @@ -587,20 +596,22 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e if (update_edge_weights || update_turn_penalties || update_conditional_turns) { tbb::parallel_invoke( - [&] { - extractor::files::readSegmentData(config.GetPath(".osrm.geometry"), segment_data); - }, + [&] + { extractor::files::readSegmentData(config.GetPath(".osrm.geometry"), segment_data); }, [&] { extractor::files::readNodeData(config.GetPath(".osrm.ebg_nodes"), node_data); }, - [&] { + [&] + { extractor::files::readTurnWeightPenalty( config.GetPath(".osrm.turn_weight_penalties"), turn_weight_penalties); }, - [&] { + [&] + { extractor::files::readTurnDurationPenalty( config.GetPath(".osrm.turn_duration_penalties"), turn_duration_penalties); }, - [&] { + [&] + { extractor::files::readProfileProperties(config.GetPath(".osrm.properties"), profile_properties); }); @@ -647,7 +658,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e std::transform(updated_turn_penalties.begin(), updated_turn_penalties.end(), updated_segments.begin() + offset, - [&node_data, &edge_based_edge_list](const std::uint64_t turn_id) { + [&node_data, &edge_based_edge_list](const std::uint64_t turn_id) + { const auto node_id = edge_based_edge_list[turn_id].source; return node_data.GetGeometryID(node_id); }); @@ -672,7 +684,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e std::transform(updated_turn_penalties.begin(), updated_turn_penalties.end(), updated_segments.begin() + offset, - [&node_data, &edge_based_edge_list](const std::uint64_t turn_id) { + [&node_data, &edge_based_edge_list](const std::uint64_t turn_id) + { const auto node_id = edge_based_edge_list[turn_id].source; return node_data.GetGeometryID(node_id); }); @@ -680,13 +693,13 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e tbb::parallel_sort(updated_segments.begin(), updated_segments.end(), - [](const GeometryID lhs, const GeometryID rhs) { - return std::tie(lhs.id, lhs.forward) < std::tie(rhs.id, rhs.forward); - }); + [](const GeometryID lhs, const GeometryID rhs) + { return std::tie(lhs.id, lhs.forward) < std::tie(rhs.id, rhs.forward); }); using WeightAndDuration = std::tuple; const auto compute_new_weight_and_duration = - [&](const GeometryID geometry_id) -> WeightAndDuration { + [&](const GeometryID geometry_id) -> WeightAndDuration + { EdgeWeight new_weight = {0}; EdgeDuration new_duration = {0}; if (geometry_id.forward) @@ -728,7 +741,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e std::vector accumulated_segment_data(updated_segments.size()); tbb::parallel_for(tbb::blocked_range(0, updated_segments.size()), - [&](const auto &range) { + [&](const auto &range) + { for (auto index = range.begin(); index < range.end(); ++index) { accumulated_segment_data[index] = @@ -736,16 +750,16 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e } }); - const auto update_edge = [&](extractor::EdgeBasedEdge &edge) { + const auto update_edge = [&](extractor::EdgeBasedEdge &edge) + { const auto node_id = edge.source; const auto geometry_id = node_data.GetGeometryID(node_id); - auto updated_iter = std::lower_bound(updated_segments.begin(), - updated_segments.end(), - geometry_id, - [](const GeometryID lhs, const GeometryID rhs) { - return std::tie(lhs.id, lhs.forward) < - std::tie(rhs.id, rhs.forward); - }); + auto updated_iter = std::lower_bound( + updated_segments.begin(), + updated_segments.end(), + geometry_id, + [](const GeometryID lhs, const GeometryID rhs) + { return std::tie(lhs.id, lhs.forward) < std::tie(rhs.id, rhs.forward); }); if (updated_iter != updated_segments.end() && updated_iter->id == geometry_id.id && updated_iter->forward == geometry_id.forward) { @@ -806,7 +820,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e if (updated_segments.size() > 0) { tbb::parallel_for(tbb::blocked_range(0, edge_based_edge_list.size()), - [&](const auto &range) { + [&](const auto &range) + { for (auto index = range.begin(); index < range.end(); ++index) { update_edge(edge_based_edge_list[index]); @@ -817,11 +832,13 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e if (update_turn_penalties || update_conditional_turns) { tbb::parallel_invoke( - [&] { + [&] + { extractor::files::writeTurnWeightPenalty( config.GetPath(".osrm.turn_weight_penalties"), turn_weight_penalties); }, - [&] { + [&] + { extractor::files::writeTurnDurationPenalty( config.GetPath(".osrm.turn_duration_penalties"), turn_duration_penalties); }); diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 46dec8af2a7..70a0d2cb4e1 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -317,7 +317,8 @@ double findClosestDistance(const std::vector &lhs, const std::vector { double current_min = std::numeric_limits::max(); - const auto compute_minimum_distance_in_rhs = [¤t_min, &rhs](const Coordinate coordinate) { + const auto compute_minimum_distance_in_rhs = [¤t_min, &rhs](const Coordinate coordinate) + { current_min = std::min(current_min, findClosestDistance(coordinate, rhs.begin(), rhs.end())); return false; @@ -331,9 +332,8 @@ double findClosestDistance(const std::vector &lhs, const std::vector std::vector getDeviations(const std::vector &from, const std::vector &to) { - auto find_deviation = [&to](const Coordinate coordinate) { - return findClosestDistance(coordinate, to.begin(), to.end()); - }; + auto find_deviation = [&to](const Coordinate coordinate) + { return findClosestDistance(coordinate, to.begin(), to.end()); }; std::vector deviations_from; deviations_from.reserve(from.size()); @@ -385,9 +385,9 @@ double computeArea(const std::vector &polygon) // ⚠ ref_latitude is the standard parallel for the equirectangular projection // that is not an area-preserving projection const auto ref_point = - std::min_element(polygon.begin(), polygon.end(), [](const auto &lhs, const auto &rhs) { - return lhs.lat < rhs.lat; - }); + std::min_element(polygon.begin(), + polygon.end(), + [](const auto &lhs, const auto &rhs) { return lhs.lat < rhs.lat; }); const auto ref_latitude = ref_point->lat; // Compute area of under a curve and a line that is parallel the equator with ref_latitude diff --git a/src/util/log.cpp b/src/util/log.cpp index 17196ec1893..aee8594b7b9 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -73,7 +73,8 @@ void Log::Init() { const bool is_terminal = IsStdoutATTY(); - auto format = [is_terminal](const char *level, const char *color) { + auto format = [is_terminal](const char *level, const char *color) + { const auto timestamp = std::chrono::system_clock::now(); return fmt::format("{}[{:%FT%H:%M:}{:%S}] [{}] ", is_terminal ? color : "", diff --git a/src/util/opening_hours.cpp b/src/util/opening_hours.cpp index e50cfe86752..d96c3f6b5d7 100644 --- a/src/util/opening_hours.cpp +++ b/src/util/opening_hours.cpp @@ -327,13 +327,9 @@ struct opening_hours_grammar : qi::grammar()> time_domain; diff --git a/src/util/timezones.cpp b/src/util/timezones.cpp index 179e2d11ae3..3f478eff34c 100644 --- a/src/util/timezones.cpp +++ b/src/util/timezones.cpp @@ -79,7 +79,8 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut // Lambda function that returns local time in the tzname time zone // Thread safety: MT-Unsafe const:env std::unordered_map local_time_memo; - auto get_local_time_in_tz = [utc_time, &local_time_memo](const char *tzname) { + auto get_local_time_in_tz = [utc_time, &local_time_memo](const char *tzname) + { auto it = local_time_memo.find(tzname); if (it == local_time_memo.end()) { diff --git a/unit_tests/engine/douglas_peucker.cpp b/unit_tests/engine/douglas_peucker.cpp index 1b9967d214d..3433a772b9f 100644 --- a/unit_tests/engine/douglas_peucker.cpp +++ b/unit_tests/engine/douglas_peucker.cpp @@ -82,7 +82,8 @@ BOOST_AUTO_TEST_CASE(removed_middle_test_zoom_sensitive) BOOST_AUTO_TEST_CASE(remove_second_node_test) { // derived from the degreeToPixel function - const auto delta_pixel_to_delta_degree = [](const int pixel, const unsigned zoom) { + const auto delta_pixel_to_delta_degree = [](const int pixel, const unsigned zoom) + { const double shift = (1u << zoom) * 256; const double b = shift / 2.0; return pixel * 180. / b; diff --git a/unit_tests/extractor/intersection_analysis_tests.cpp b/unit_tests/extractor/intersection_analysis_tests.cpp index 9514a958d0b..947359c598a 100644 --- a/unit_tests/extractor/intersection_analysis_tests.cpp +++ b/unit_tests/extractor/intersection_analysis_tests.cpp @@ -40,17 +40,18 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity) // ↓ // 4 const auto unit_edge = - [](const NodeID from, const NodeID to, bool allowed, AnnotationID annotation) { - return InputEdge{from, - to, - EdgeWeight{1}, - EdgeDuration{1}, - EdgeDistance{1}, - GeometryID{0, false}, - !allowed, - NodeBasedEdgeClassification(), - annotation}; - }; + [](const NodeID from, const NodeID to, bool allowed, AnnotationID annotation) + { + return InputEdge{from, + to, + EdgeWeight{1}, + EdgeDuration{1}, + EdgeDistance{1}, + GeometryID{0, false}, + !allowed, + NodeBasedEdgeClassification(), + annotation}; + }; std::vector edges = {unit_edge(0, 2, true, 1), unit_edge(0, 5, true, 0), @@ -102,7 +103,8 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity) RestrictionGraph restriction_graph = constructRestrictionGraph(restrictions); RestrictionMap restriction_map(restriction_graph); - const auto connectivity_matrix = [&](NodeID node) { + const auto connectivity_matrix = [&](NodeID node) + { std::vector result; const auto incoming_edges = getIncomingEdges(graph, node); const auto outgoing_edges = getOutgoingEdges(graph, node); @@ -167,7 +169,8 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity) // 0 // ↙ ↑ ↘ // 4 5 6 - const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed, bool roundabout) { + const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed, bool roundabout) + { return InputEdge{from, to, EdgeWeight{1}, @@ -226,7 +229,8 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity) RestrictionGraph restriction_graph = constructRestrictionGraph(restrictions); RestrictionMap restriction_map(restriction_graph); - const auto connectivity_matrix = [&](NodeID node) { + const auto connectivity_matrix = [&](NodeID node) + { std::vector result; const auto incoming_edges = getIncomingEdges(graph, node); const auto outgoing_edges = getOutgoingEdges(graph, node); @@ -274,7 +278,8 @@ BOOST_AUTO_TEST_CASE(skip_degree_two_nodes) // ↑ ↕ ↕ // 6 8 ↔ 9 // - const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed) { + const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed) + { return InputEdge{from, to, EdgeWeight{1}, diff --git a/unit_tests/extractor/restriction_graph.cpp b/unit_tests/extractor/restriction_graph.cpp index e0fac7bcc46..b5c24694f14 100644 --- a/unit_tests/extractor/restriction_graph.cpp +++ b/unit_tests/extractor/restriction_graph.cpp @@ -56,14 +56,12 @@ void checkInstructions(RestrictionGraph::RestrictionRange restrictions, }); std::sort(actual_instructions.begin(), actual_instructions.end(), - [](const auto &lhs, const auto &rhs) { - return (lhs.to < rhs.to) || (lhs.to == rhs.to && lhs.is_only); - }); + [](const auto &lhs, const auto &rhs) + { return (lhs.to < rhs.to) || (lhs.to == rhs.to && lhs.is_only); }); std::sort(expected_instructions.begin(), expected_instructions.end(), - [](const auto &lhs, const auto &rhs) { - return (lhs.to < rhs.to) || (lhs.to == rhs.to && lhs.is_only); - }); + [](const auto &lhs, const auto &rhs) + { return (lhs.to < rhs.to) || (lhs.to == rhs.to && lhs.is_only); }); BOOST_REQUIRE_EQUAL_COLLECTIONS(actual_instructions.begin(), actual_instructions.end(), @@ -88,10 +86,11 @@ void checkEdges(RestrictionGraph::EdgeRange edges, std::vector expected_ std::map nextEdges(RestrictionGraph::EdgeRange edges) { std::map res; - std::transform( - edges.begin(), edges.end(), std::inserter(res, res.end()), [&](const auto &edge) { - return std::make_pair(edge.node_based_to, edge.target); - }); + std::transform(edges.begin(), + edges.end(), + std::inserter(res, res.end()), + [&](const auto &edge) + { return std::make_pair(edge.node_based_to, edge.target); }); return res; } @@ -132,12 +131,12 @@ validateViaRestrictionNode(RestrictionGraph &graph, BOOST_REQUIRE_GE(graph.via_edge_to_node.count({from, to}), 1); auto node_match_it = graph.via_edge_to_node.equal_range({from, to}); - BOOST_REQUIRE_MESSAGE( - std::any_of(node_match_it.first, - node_match_it.second, - [&](const auto node_match) { return node_match.second == via_node_idx; }), - "Could not find expected via_node_idx " << via_node_idx << " for graph edge " << from << "," - << to); + BOOST_REQUIRE_MESSAGE(std::any_of(node_match_it.first, + node_match_it.second, + [&](const auto node_match) + { return node_match.second == via_node_idx; }), + "Could not find expected via_node_idx " + << via_node_idx << " for graph edge " << from << "," << to); BOOST_REQUIRE_LT(via_node_idx, graph.num_via_nodes); return checkNode( diff --git a/unit_tests/library/tile.cpp b/unit_tests/library/tile.cpp index 00a6c38467e..43b74bada2d 100644 --- a/unit_tests/library/tile.cpp +++ b/unit_tests/library/tile.cpp @@ -87,9 +87,9 @@ void validate_feature_layer(vtzero::layer layer) } auto number_of_uint_values = - std::count_if(layer.value_table().begin(), layer.value_table().end(), [](auto v) { - return v.type() == vtzero::property_value_type::uint_value; - }); + std::count_if(layer.value_table().begin(), + layer.value_table().end(), + [](auto v) { return v.type() == vtzero::property_value_type::uint_value; }); BOOST_CHECK_EQUAL(number_of_uint_values, 79); } @@ -129,9 +129,9 @@ void validate_turn_layer(vtzero::layer layer) } auto number_of_float_values = - std::count_if(layer.value_table().begin(), layer.value_table().end(), [](auto v) { - return v.type() == vtzero::property_value_type::float_value; - }); + std::count_if(layer.value_table().begin(), + layer.value_table().end(), + [](auto v) { return v.type() == vtzero::property_value_type::float_value; }); BOOST_CHECK_EQUAL(number_of_float_values, 73); } diff --git a/unit_tests/partitioner/bisection_graph.cpp b/unit_tests/partitioner/bisection_graph.cpp index 7dc664e5169..db46c4ed1ae 100644 --- a/unit_tests/partitioner/bisection_graph.cpp +++ b/unit_tests/partitioner/bisection_graph.cpp @@ -28,7 +28,8 @@ BOOST_AUTO_TEST_CASE(access_nodes) const auto to_row = [cols](const NodeID nid) { return nid / cols; }; const auto to_col = [cols](const NodeID nid) { return nid % cols; }; - const auto get_expected = [&](const NodeID id) { + const auto get_expected = [&](const NodeID id) + { const auto expected_lon = FloatLongitude{to_col(id) * step_size}; const auto expected_lat = FloatLatitude{to_row(id) * step_size}; Coordinate compare(expected_lon, expected_lat); diff --git a/unit_tests/partitioner/cell_storage.cpp b/unit_tests/partitioner/cell_storage.cpp index 26113a0feff..53fc0208b62 100644 --- a/unit_tests/partitioner/cell_storage.cpp +++ b/unit_tests/partitioner/cell_storage.cpp @@ -40,7 +40,8 @@ BOOST_AUTO_TEST_SUITE(cell_storage_tests) BOOST_AUTO_TEST_CASE(mutable_cell_storage) { - const auto fill_range = [](auto range, const std::vector &values) { + const auto fill_range = [](auto range, const std::vector &values) + { auto iter = range.begin(); for (auto v : values) *iter++ = v; diff --git a/unit_tests/partitioner/dinic.cpp b/unit_tests/partitioner/dinic.cpp index 51f9b164c7e..1d2ebf4510a 100644 --- a/unit_tests/partitioner/dinic.cpp +++ b/unit_tests/partitioner/dinic.cpp @@ -21,11 +21,13 @@ BOOST_AUTO_TEST_CASE(horizontal_cut_between_two_grids) const int cols = 10; // build a small grid (10*10) and a (100 * 10) below (to make the different steps unique) - auto graph = [&]() { + auto graph = [&]() + { std::vector grid_coordinates; std::vector grid_edges; - const auto connect = [&grid_edges](const NodeID from, const NodeID to) { + const auto connect = [&grid_edges](const NodeID from, const NodeID to) + { grid_edges.push_back({from, to, 1}); grid_edges.push_back({to, from, 1}); }; diff --git a/unit_tests/partitioner/multi_level_partition.cpp b/unit_tests/partitioner/multi_level_partition.cpp index 62fca2772c0..3d4901155a9 100644 --- a/unit_tests/partitioner/multi_level_partition.cpp +++ b/unit_tests/partitioner/multi_level_partition.cpp @@ -192,9 +192,10 @@ BOOST_AUTO_TEST_CASE(large_cell_number) for (auto l : util::irange(1UL, num_levels)) { - std::transform(levels[l - 1].begin(), levels[l - 1].end(), levels[l].begin(), [](auto val) { - return val / 2; - }); + std::transform(levels[l - 1].begin(), + levels[l - 1].end(), + levels[l].begin(), + [](auto val) { return val / 2; }); levels_to_num_cells[l] = levels_to_num_cells[l - 1] / 2; } @@ -244,7 +245,8 @@ BOOST_AUTO_TEST_CASE(cell_64_bits) std::vector(level_cells[0])); std::vector levels_to_num_cells(level_cells.size()); - const auto set_level_cells = [&](size_t level, auto const num_cells) { + const auto set_level_cells = [&](size_t level, auto const num_cells) + { for (auto val : util::irange(0ULL, NUM_PARTITIONS)) { levels[level][val] = std::min(val, num_cells - 1); @@ -273,7 +275,8 @@ BOOST_AUTO_TEST_CASE(cell_overflow_bits) std::vector(level_cells[0])); std::vector levels_to_num_cells(level_cells.size()); - const auto set_level_cells = [&](size_t level, auto const num_cells) { + const auto set_level_cells = [&](size_t level, auto const num_cells) + { for (auto val : util::irange(0ULL, NUM_PARTITIONS)) { levels[level][val] = std::min(val, num_cells - 1); diff --git a/unit_tests/partitioner/recursive_bisection.cpp b/unit_tests/partitioner/recursive_bisection.cpp index dfcbb805f1e..3ecb06a93a0 100644 --- a/unit_tests/partitioner/recursive_bisection.cpp +++ b/unit_tests/partitioner/recursive_bisection.cpp @@ -20,18 +20,19 @@ BOOST_AUTO_TEST_CASE(dividing_four_grid_cells) const int cols = 10; const int cut_edges = 4; - auto graph = [&]() { + auto graph = [&]() + { std::vector grid_coordinates; std::vector grid_edges; - const auto connect = - [&grid_edges](int min_left, int max_left, int min_right, int max_right) { - const NodeID source = (rand() % (max_left - min_left)) + min_left; - const NodeID target = (rand() % (max_right - min_right)) + min_right; + const auto connect = [&grid_edges](int min_left, int max_left, int min_right, int max_right) + { + const NodeID source = (rand() % (max_left - min_left)) + min_left; + const NodeID target = (rand() % (max_right - min_right)) + min_right; - grid_edges.push_back({source, target, 1}); - grid_edges.push_back({target, source, 1}); - }; + grid_edges.push_back({source, target, 1}); + grid_edges.push_back({target, source, 1}); + }; // generate 10 big components for (int i = 0; i < 4; ++i) diff --git a/unit_tests/partitioner/scc_integration.cpp b/unit_tests/partitioner/scc_integration.cpp index f9cb4eb3923..59e462d1e81 100644 --- a/unit_tests/partitioner/scc_integration.cpp +++ b/unit_tests/partitioner/scc_integration.cpp @@ -21,7 +21,8 @@ BOOST_AUTO_TEST_CASE(graph_views_on_components) const int num_components = 10; - auto graph = [&]() { + auto graph = [&]() + { std::vector grid_coordinates; std::vector grid_edges; @@ -56,14 +57,14 @@ BOOST_AUTO_TEST_CASE(graph_views_on_components) const auto &view = views[comp]; BOOST_CHECK(views[comp].NumberOfNodes() == 10); - const auto to_component_id = [&](const auto &node) { - return node.original_id / (rows * cols + 1); - }; + const auto to_component_id = [&](const auto &node) + { return node.original_id / (rows * cols + 1); }; std::size_t expected_component_id = to_component_id(view.Node(0)); - BOOST_CHECK(std::all_of(view.Begin(), view.End(), [&](const auto &node) { - return to_component_id(node) == expected_component_id; - })); + BOOST_CHECK(std::all_of(view.Begin(), + view.End(), + [&](const auto &node) + { return to_component_id(node) == expected_component_id; })); for (const auto &node : view.Nodes()) { diff --git a/unit_tests/storage/tar.cpp b/unit_tests/storage/tar.cpp index c15a1ea4f2e..0e30fc99d7f 100644 --- a/unit_tests/storage/tar.cpp +++ b/unit_tests/storage/tar.cpp @@ -201,7 +201,8 @@ BOOST_AUTO_TEST_CASE(write_huge_tar_file, *boost::unit_test::disabled()) { storage::tar::FileWriter writer(tmp.path, storage::tar::FileWriter::GenerateFingerprint); std::uint64_t value = 0; - const std::function encode_function = [&]() -> std::uint64_t { + const std::function encode_function = [&]() -> std::uint64_t + { reference_checksum += value; return value++; }; diff --git a/unit_tests/util/indexed_data.cpp b/unit_tests/util/indexed_data.cpp index 40b79f9be8c..d7deb61c927 100644 --- a/unit_tests/util/indexed_data.cpp +++ b/unit_tests/util/indexed_data.cpp @@ -113,12 +113,10 @@ BOOST_AUTO_TEST_CASE(check_max_size) std::vector name_data(0x1000000, '#'); std::vector name_offsets; - auto test_variable = [&name_offsets, &name_data]() { - test_rw>>(name_offsets, name_data); - }; - auto test_fixed = [&name_offsets, &name_data]() { - test_rw>>(name_offsets, name_data); - }; + auto test_variable = [&name_offsets, &name_data]() + { test_rw>>(name_offsets, name_data); }; + auto test_fixed = [&name_offsets, &name_data]() + { test_rw>>(name_offsets, name_data); }; name_offsets = {0, 0x1000000}; BOOST_CHECK_THROW(test_variable(), osrm::util::exception); diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 5a9336e1faa..f46aa738790 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -61,8 +61,8 @@ template class LinearSearchNN std::vector local_edges(edges); auto projected_input = web_mercator::fromWGS84(input_coordinate); - const auto segment_comparator = [this, &projected_input](const DataT &lhs, - const DataT &rhs) { + const auto segment_comparator = [this, &projected_input](const DataT &lhs, const DataT &rhs) + { using web_mercator::fromWGS84; const auto lhs_result = coordinate_calculation::projectPointOnSegment( fromWGS84(coords[lhs.u]), fromWGS84(coords[lhs.v]), projected_input); From f63a2d740d879bd2fd1f628ccac9a589ed27977d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 5 May 2024 21:25:07 +0200 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd5967c8c0d..48756e14365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - REMOVED: Drop support of Node 12 & 14. [#6431](https://github.com/Project-OSRM/osrm-backend/pull/6431) - ADDED: Add 'load directly' mode to default Cucumber test suite. [#6663](https://github.com/Project-OSRM/osrm-backend/pull/6663) - CHANGED: Drop support for Node 16 [#6855](https://github.com/Project-OSRM/osrm-backend/pull/6855) + - Changed: Upgrade clang-format to version 14 [#6859](https://github.com/Project-OSRM/osrm-backend/pull/6859) - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: From e0e5be7c7a1dcdcbdb8880957c8ead384dc4fc51 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 5 May 2024 21:44:40 +0200 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48756e14365..5acca79578a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - REMOVED: Drop support of Node 12 & 14. [#6431](https://github.com/Project-OSRM/osrm-backend/pull/6431) - ADDED: Add 'load directly' mode to default Cucumber test suite. [#6663](https://github.com/Project-OSRM/osrm-backend/pull/6663) - CHANGED: Drop support for Node 16 [#6855](https://github.com/Project-OSRM/osrm-backend/pull/6855) - - Changed: Upgrade clang-format to version 14 [#6859](https://github.com/Project-OSRM/osrm-backend/pull/6859) + - CHANGED: Upgrade clang-format to version 14 [#6859](https://github.com/Project-OSRM/osrm-backend/pull/6859) - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: From fe350a43ae69b6b5690fe3134753813e4f6feef2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 6 May 2024 06:49:24 +0200 Subject: [PATCH 5/8] Test if Ubuntu 24.04 is available --- .github/workflows/osrm-backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index d1a14d8a972..a0f1df371ea 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -71,7 +71,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} format-taginfo-docs: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 - name: Use Node.js From f7427b383f80a7a649ba2ba93b32453b1e41112c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 6 May 2024 06:54:57 +0200 Subject: [PATCH 6/8] Use Ubuntu 22.04 --- .github/workflows/osrm-backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index a0f1df371ea..d1a14d8a972 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -71,7 +71,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} format-taginfo-docs: - runs-on: ubuntu-24.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - name: Use Node.js From 3dc407095ea5ef9661ca2b69d524ab20b97587a5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 6 May 2024 07:55:22 +0200 Subject: [PATCH 7/8] Jump to clang-format-15 since it is available on 22.04 github runners --- .github/workflows/osrm-backend.yml | 2 +- CHANGELOG.md | 2 +- CONTRIBUTING.md | 2 +- scripts/format.sh | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index d1a14d8a972..f338e05fbc3 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -88,7 +88,7 @@ jobs: - name: Prepare environment run: | npm ci --ignore-scripts - clang-format-14 --version + clang-format-15 --version - name: Run checks run: | ./scripts/check_taginfo.py taginfo.json profiles/car.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index 5acca79578a..c6037518565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - REMOVED: Drop support of Node 12 & 14. [#6431](https://github.com/Project-OSRM/osrm-backend/pull/6431) - ADDED: Add 'load directly' mode to default Cucumber test suite. [#6663](https://github.com/Project-OSRM/osrm-backend/pull/6663) - CHANGED: Drop support for Node 16 [#6855](https://github.com/Project-OSRM/osrm-backend/pull/6855) - - CHANGED: Upgrade clang-format to version 14 [#6859](https://github.com/Project-OSRM/osrm-backend/pull/6859) + - CHANGED: Upgrade clang-format to version 15 [#6859](https://github.com/Project-OSRM/osrm-backend/pull/6859) - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2b36d2b6cb7..2b01a4a77dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ You can add a :+1: emoji reaction to the issue if you want to express interest i # Developer -We use `clang-format` version `14` to consistently format the code base. There is a helper script under `scripts/format.sh`. +We use `clang-format` version `15` to consistently format the code base. There is a helper script under `scripts/format.sh`. The format is automatically checked by the `mason-linux-release` job of a Travis CI build. To save development time a local hook `.git/hooks/pre-push` ``` diff --git a/scripts/format.sh b/scripts/format.sh index 1a256d27e31..93e6a50f9e3 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -19,18 +19,18 @@ elif [[ ${OS} = "Darwin" ]] ; then fi # Discover clang-format -if type clang-format-14 2> /dev/null ; then - CLANG_FORMAT=clang-format-14 +if type clang-format-15 2> /dev/null ; then + CLANG_FORMAT=clang-format-15 elif type clang-format 2> /dev/null ; then # Clang format found, but need to check version CLANG_FORMAT=clang-format V=$(clang-format --version) - if [[ $V != *14.0* ]] ; then - echo "clang-format is not 14.0 (returned ${V})" + if [[ $V != *15.0* ]] ; then + echo "clang-format is not 15.0 (returned ${V})" #exit 1 fi else - echo "No appropriate clang-format found (expected clang-format-14, or clang-format)" + echo "No appropriate clang-format found (expected clang-format-15, or clang-format)" exit 1 fi From 4caee0339e06e49c0dd87ce22e435f3e39de4fb1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 6 May 2024 08:12:55 +0200 Subject: [PATCH 8/8] Apply formatting --- .../guidance/collapse_scenario_detection.hpp | 14 +++++++------- .../intersection/intersection_analysis.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/engine/guidance/collapse_scenario_detection.hpp b/include/engine/guidance/collapse_scenario_detection.hpp index b072627c75c..47ab9fbf9b5 100644 --- a/include/engine/guidance/collapse_scenario_detection.hpp +++ b/include/engine/guidance/collapse_scenario_detection.hpp @@ -16,7 +16,7 @@ bool basicCollapsePreconditions(const RouteStepIterator first, // Staggered intersection are very short zig-zags of a few meters. // We do not want to announce these short left-rights or right-lefts: -//  +//   // * -> b a -> * // | or | becomes a -> b // a -> * * -> b @@ -26,7 +26,7 @@ bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection, // Two two turns following close after another, we can announce them as a U-Turn if both end up // involving the same (segregated) road. -//  +//   // b < - y // | will be represented by at x, turn around instead of turn left at x, turn left at y // a - > x @@ -42,11 +42,11 @@ bool isNameOszillation(const RouteStepIterator step_prior_to_intersection, // Sometimes, segments names don't match the perceived turns. We try to detect these additional // name changes and issue a combined turn. -//  +//   // | e | // a - b - c // d -//  +//   // can have `a-b` as one name, `b-c-d` as a second. At `b` we would issue a new name, even though // the road turns right after. The offset would only be there due to the broad road at `e` bool maneuverPreceededByNameChange(const RouteStepIterator step_prior_to_intersection, @@ -73,11 +73,11 @@ bool doubleChoiceless(const RouteStepIterator step_entering_intersection, // Due to obvious detection, sometimes we can have straight turns followed by a different turn right // next to each other. We combine both turns into one, if the second turn is without choice -//  -//  e +//   +//   e // a - b - c // ' d -//  +//   // with a main road `abd`, the turn `continue straight` at `b` and `turn left at `c` will become a // `turn left` at `b` bool straightTurnFollowedByChoiceless(const RouteStepIterator step_entering_intersection, diff --git a/src/extractor/intersection/intersection_analysis.cpp b/src/extractor/intersection/intersection_analysis.cpp index e1b5ad3a4fd..98c8ef8a7fa 100644 --- a/src/extractor/intersection/intersection_analysis.cpp +++ b/src/extractor/intersection/intersection_analysis.cpp @@ -128,7 +128,7 @@ std::pair findMergedBearing(const util::NodeBasedDynamicGraph &gra { // In some intersections, turning roads can introduce artificial turns if we merge here. // Consider a scenario like: - //  + //   // a . g - f // | . // | . @@ -136,7 +136,7 @@ std::pair findMergedBearing(const util::NodeBasedDynamicGraph &gra // d-b--------e // | // c - //  + //   // Merging `bgf` and `be` would introduce an angle, even though d-b-e is perfectly straight // We don't change the angle, if such an opposite road exists return {false, entry.perceived_bearing};