Upgrade clang-format to version 15 (#6859)

This commit is contained in:
Dennis Luxen 2024-05-06 09:14:46 +02:00 committed by GitHub
parent b503e96a98
commit 7f9d591ab7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
156 changed files with 2357 additions and 1894 deletions

View File

@ -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-15 --version
- name: Run checks
run: |
./scripts/check_taginfo.py taginfo.json profiles/car.lua

View File

@ -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 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:

View File

@ -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 `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`
```

View File

@ -61,9 +61,11 @@ inline auto contractExcludableGraph(ContractorGraph contractor_graph_,
// Add all non-core edges to container
{
auto non_core_edges = toEdges<QueryEdge>(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)

View File

@ -89,7 +89,10 @@ 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) {
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))
@ -132,10 +135,10 @@ struct ContractedEdgeContainer
// enforce sorting for next merge step
std::vector<unsigned> 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);

View File

@ -122,7 +122,8 @@ class CellCustomizer
for (std::size_t level = 1; level < partition.GetNumberOfLevels(); ++level)
{
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, partition.GetNumberOfCells(level)),
[&](const tbb::blocked_range<std::size_t> &range) {
[&](const tbb::blocked_range<std::size_t> &range)
{
auto &heap = heaps.local();
for (auto id = range.begin(), end = range.end(); id != end; ++id)
{

View File

@ -40,10 +40,10 @@ class BaseAPI
util::json::Array waypoints;
waypoints.values.resize(parameters.coordinates.size());
boost::range::transform(
waypoint_candidates,
boost::range::transform(waypoint_candidates,
waypoints.values.begin(),
[this](const PhantomNodeCandidates &candidates) { return MakeWaypoint(candidates); });
[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);
}

View File

@ -112,7 +112,8 @@ struct BaseParameters
(approaches.empty() || approaches.size() == coordinates.size()) &&
std::all_of(bearings.begin(),
bearings.end(),
[](const boost::optional<Bearing> &bearing_and_range) {
[](const boost::optional<Bearing> &bearing_and_range)
{
if (bearing_and_range)
{
return bearing_and_range->IsValid();

View File

@ -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())
{

View File

@ -57,11 +57,11 @@ class NearestAPI final : public BaseAPI
{
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(phantom_nodes.front().size());
std::transform(
phantom_nodes.front().begin(),
std::transform(phantom_nodes.front().begin(),
phantom_nodes.front().end(),
waypoints.begin(),
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) {
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance)
{
auto &phantom_node = phantom_with_distance.phantom_node;
auto node_values = MakeNodes(phantom_node);
@ -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});

View File

@ -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,8 +172,13 @@ class RouteAPI : public BaseAPI
}
std::vector<fbresult::Position> coordinates;
coordinates.resize(std::distance(begin, end));
std::transform(begin, end, coordinates.begin(), [](const Coordinate &c) {
return fbresult::Position{static_cast<float>(util::toFloating(c.lon).__value),
std::transform(begin,
end,
coordinates.begin(),
[](const Coordinate &c)
{
return fbresult::Position{
static_cast<float>(util::toFloating(c.lon).__value),
static_cast<float>(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<float>(fb_result,
leg_geometry,
[&prev_speed](const guidance::LegGeometry::Annotation &anno) {
[&prev_speed](const guidance::LegGeometry::Annotation &anno)
{
if (anno.duration < std::numeric_limits<float>::min())
{
return prev_speed;
@ -459,37 +465,37 @@ class RouteAPI : public BaseAPI
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> duration;
if (requested_annotations & RouteParameters::AnnotationsType::Duration)
{
duration = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.duration;
});
duration = GetAnnotations<uint32_t>(fb_result,
leg_geometry,
[](const guidance::LegGeometry::Annotation &anno)
{ return anno.duration; });
}
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> distance;
if (requested_annotations & RouteParameters::AnnotationsType::Distance)
{
distance = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.distance;
});
distance = GetAnnotations<uint32_t>(fb_result,
leg_geometry,
[](const guidance::LegGeometry::Annotation &anno)
{ return anno.distance; });
}
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> weight;
if (requested_annotations & RouteParameters::AnnotationsType::Weight)
{
weight = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.weight;
});
weight = GetAnnotations<uint32_t>(fb_result,
leg_geometry,
[](const guidance::LegGeometry::Annotation &anno)
{ return anno.weight; });
}
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> datasources;
if (requested_annotations & RouteParameters::AnnotationsType::Datasources)
{
datasources = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.datasource;
});
datasources = GetAnnotations<uint32_t>(fb_result,
leg_geometry,
[](const guidance::LegGeometry::Annotation &anno)
{ return anno.datasource; });
}
std::vector<uint32_t> 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<flatbuffers::Offset<fbresult::Lane>> lanes;
if (json::detail::hasValidLanes(intersection))
{
@ -681,11 +688,11 @@ class RouteAPI : public BaseAPI
auto bearings_vector = fb_result.CreateVector(intersection.bearings);
std::vector<flatbuffers::Offset<flatbuffers::String>> classes;
classes.resize(intersection.classes.size());
std::transform(
intersection.classes.begin(),
std::transform(intersection.classes.begin(),
intersection.classes.end(),
classes.begin(),
[&fb_result](const std::string &cls) { return fb_result.CreateString(cls); });
[&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<util::json::Value> 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<std::size_t>(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<util::json::Value>(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<double>::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)
{

View File

@ -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;
}
};

View File

@ -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,8 +274,11 @@ class TableAPI final : public BaseAPI
{
std::vector<float> distance_table;
distance_table.resize(values.size());
std::transform(
values.begin(), values.end(), distance_table.begin(), [](const EdgeDuration duration) {
std::transform(values.begin(),
values.end(),
distance_table.begin(),
[](const EdgeDuration duration)
{
if (duration == MAXIMAL_EDGE_DURATION)
{
return 0.;
@ -291,8 +294,11 @@ class TableAPI final : public BaseAPI
{
std::vector<float> duration_table;
duration_table.resize(values.size());
std::transform(
values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) {
std::transform(values.begin(),
values.end(),
duration_table.begin(),
[](const EdgeDistance distance)
{
if (distance == INVALID_EDGE_DISTANCE)
{
return 0.;
@ -308,8 +314,10 @@ class TableAPI final : public BaseAPI
{
std::vector<uint32_t> fb_table;
fb_table.reserve(fallback_speed_cells.size());
std::for_each(
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
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);
});
@ -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,8 +415,10 @@ class TableAPI final : public BaseAPI
MakeEstimatesTable(const std::vector<TableCellRef> &fallback_speed_cells) const
{
util::json::Array json_table;
std::for_each(
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
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));

View File

@ -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())
{

View File

@ -440,9 +440,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
auto indexes = extractor::getClassIndexes(class_data);
std::vector<std::string> 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,10 +602,14 @@ 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<NodeID> sequence(
m_maneuver_override_node_sequences.begin() + override.node_sequence_offset_begin,
m_maneuver_override_node_sequences.begin() + override.node_sequence_offset_end);
std::for_each(found_range.first,
found_range.second,
[&](const auto &override)
{
std::vector<NodeID> 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,

View File

@ -60,7 +60,8 @@ template <typename RTreeT, typename DataFacadeT> 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 <typename RTreeT, typename DataFacadeT> 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 <typename RTreeT, typename DataFacadeT> 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 <typename RTreeT, typename DataFacadeT> 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,10 +194,14 @@ template <typename RTreeT, typename DataFacadeT> 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) {
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;
});
@ -259,7 +267,10 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
};
std::for_each(results.begin(), results.end(), [&](const CandidateSegment &segment) {
std::for_each(results.begin(),
results.end(),
[&](const CandidateSegment &segment)
{
if (segment.fixed_projected_coordinate == nearest_coord)
{
add_to_candidates(nearest_phantoms, segment.data);
@ -281,9 +292,8 @@ template <typename RTreeT, typename DataFacadeT> 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 <typename RTreeT, typename DataFacadeT> 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(

View File

@ -43,7 +43,8 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const datafacade::BaseDa
const bool target_traversed_in_reverse)
{
// merges segments with same name id
const auto collapse_segments = [](std::vector<NamedSegment> &segments) {
const auto collapse_segments = [](std::vector<NamedSegment> &segments)
{
auto out = segments.begin();
auto end = segments.end();
@ -75,7 +76,8 @@ std::array<std::uint32_t, SegmentNumber> 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,8 +89,10 @@ std::array<std::uint32_t, SegmentNumber> 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) {
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);
});
@ -96,24 +100,26 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const datafacade::BaseDa
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) {
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<std::uint32_t, SegmentNumber> 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<double>(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<double>(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<double>(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<double>(data.weight_until_turn); });
// s
// |

View File

@ -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<RouteStep> removeNoTurnInstructions(std::vector<RouteStep> 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;

View File

@ -20,14 +20,16 @@ template <typename Iter, typename Fn> 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)

View File

@ -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

View File

@ -33,10 +33,10 @@ class BasePlugin
bool CheckAllCoordinates(const std::vector<util::Coordinate> &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 &params,
@ -105,13 +105,15 @@ class BasePlugin
{
// are all phantoms from a tiny cc?
const auto all_in_same_tiny_component =
[](const std::vector<PhantomCandidateAlternatives> &alts_list) {
[](const std::vector<PhantomCandidateAlternatives> &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) {
[&](const PhantomNode &phantom)
{
if (!phantom.component.is_tiny)
{
return false;
@ -120,30 +122,28 @@ class BasePlugin
return std::all_of(
std::next(alts_list.begin()),
std::end(alts_list),
[component_id](const PhantomCandidateAlternatives &alternatives) {
return candidatesHaveComponent(alternatives.first, component_id);
});
[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<PhantomNodeCandidates> 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 ") +

View File

@ -39,7 +39,8 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
begin,
end,
[&delta_numbers, &current_lat, &current_lon, coordinate_to_polyline](
const util::Coordinate loc) {
const util::Coordinate loc)
{
const int lat_diff =
std::round(static_cast<int>(loc.lat) * coordinate_to_polyline) - current_lat;
const int lon_diff =

View File

@ -190,8 +190,10 @@ void annotatePath(const FacadeT &facade,
std::vector<SegmentDuration> duration_vector;
std::vector<DatasourceID> 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());
};

View File

@ -294,9 +294,9 @@ EdgeDistance calculateEBGNodeAnnotations(const DataFacade<Algorithm> &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<NodeID, NodeID> &edge, const auto &edge_id) {
[&](std::pair<NodeID, NodeID> &edge, const auto &edge_id)
{
BOOST_ASSERT(edge.first == unpacked_nodes.back());
unpacked_nodes.push_back(edge.second);
unpacked_edges.push_back(edge_id);

View File

@ -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
@ -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));
});

View File

@ -247,7 +247,8 @@ constructRouteResult(const DataFacade<Algorithm> &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);
});
@ -256,7 +257,8 @@ constructRouteResult(const DataFacade<Algorithm> &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);
});
@ -464,16 +466,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(),
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(),
[](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(); });
[](const PhantomNode &phantom_node)
{ return phantom_node.IsValidReverseSource(); });
}
bool completeLeg()
@ -611,15 +613,21 @@ struct route_state
{
// Find the segment from final leg with the shortest path
auto forward_range = util::irange<std::size_t>(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<std::size_t>(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]));

View File

@ -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

View File

@ -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));

View File

@ -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;

View File

@ -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 &current_node) {
auto decode = [&](const auto &current_node)
{
coordinates[index].lon = current_node.lon;
coordinates[index].lat = current_node.lat;
osm_node_ids.push_back(current_node.node_id);

View File

@ -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 <typename Self> 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 <typename Self> 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 <typename Self> 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);

View File

@ -32,9 +32,8 @@ template <typename RestrictionFilter> 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);
};

View File

@ -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);

View File

@ -65,8 +65,8 @@ inline BisectionGraph makeBisectionGraph(const std::vector<util::Coordinate> &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<util::Coordinate> &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,7 +102,10 @@ std::vector<BisectionInputEdge> adaptToBisectionEdge(std::vector<InputEdge> edge
std::vector<BisectionInputEdge> result;
result.reserve(edges.size());
std::transform(begin(edges), end(edges), std::back_inserter(result), [](const auto &edge) {
std::transform(begin(edges),
end(edges),
std::back_inserter(result),
[](const auto &edge) {
return BisectionInputEdge{edge.source, edge.target};
});

View File

@ -298,7 +298,8 @@ template <storage::Ownership Ownership> 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 <storage::Ownership Ownership> 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 <storage::Ownership Ownership> 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; },

View File

@ -64,7 +64,10 @@ std::vector<OutputEdgeT> prepareEdgesForUsageInGraph(std::vector<extractor::Edge
// sort into blocks of edges with same source + target
// the we partition by the forward flag to sort all edges with a forward direction first.
// the we sort by weight to ensure the first forward edge is the smallest forward edge
std::sort(begin(edges), end(edges), [](const auto &lhs, const auto &rhs) {
std::sort(begin(edges),
end(edges),
[](const auto &lhs, const auto &rhs)
{
return std::tie(lhs.source, lhs.target, rhs.data.forward, lhs.data.weight) <
std::tie(rhs.source, rhs.target, lhs.data.forward, rhs.data.weight);
});
@ -77,10 +80,11 @@ std::vector<OutputEdgeT> prepareEdgesForUsageInGraph(std::vector<extractor::Edge
const NodeID source = begin_interval->source;
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,7 +164,10 @@ graphToEdges(const DynamicEdgeBasedGraph &edge_based_graph)
[](const NodeID lhs, const NodeID rhs) { return std::max(lhs, rhs); });
std::vector<extractor::EdgeBasedEdge> edges(max_turn_id + 1);
tbb::parallel_for(range, [&](const auto range) {
tbb::parallel_for(
range,
[&](const auto range)
{
for (auto node = range.begin(); node < range.end(); ++node)
{
for (auto edge : edge_based_graph.GetAdjacentEdgeRange(node))

View File

@ -159,10 +159,11 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
auto GetHighestBorderLevel(const MultiLevelPartition &mlp, const ContainerT &edges) const
{
std::vector<LevelID> 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<EdgeDataT, Ownership>
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,8 +203,9 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
auto level_begin = iter;
for (auto level : util::irange<LevelID>(0, mlp.GetNumberOfLevels()))
{
iter = std::find_if(
iter, edge_and_level_end, [node, level](const auto &edge_and_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;
});

View File

@ -207,7 +207,8 @@ template <storage::Ownership Ownership> 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 <storage::Ownership Ownership> 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

View File

@ -59,8 +59,10 @@ std::size_t removeUnconnectedBoundaryNodes(const GraphT &edge_based_graph,
if (level_index < static_cast<int>(partitions.size() - 1))
{
auto new_end = std::remove_if(
witnesses.begin(), witnesses.end(), [&](const auto &witness) {
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];
});
@ -87,8 +89,10 @@ 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) {
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());

View File

@ -30,10 +30,10 @@ void reorderFirstLast(RandomIt first, RandomIt last, std::size_t n, Comparator c
// requirements.
std::reverse_iterator<RandomIt> rfirst{last}, rlast{first + n};
const auto flipped = [](auto fn) {
return [fn](auto &&lhs, auto &&rhs) {
return fn(std::forward<decltype(lhs)>(rhs), std::forward<decltype(rhs)>(lhs));
};
const auto flipped = [](auto fn)
{
return [fn](auto &&lhs, auto &&rhs)
{ return fn(std::forward<decltype(lhs)>(rhs), std::forward<decltype(rhs)>(lhs)); };
};
std::nth_element(rfirst, rfirst + (n - 1), rlast, flipped(comp));

View File

@ -74,16 +74,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
: BaseParametersGrammar::base_type(root_rule)
{
const auto add_hint = [](engine::api::BaseParameters &base_parameters,
const std::vector<std::string> &hint_strings) {
const std::vector<std::string> &hint_strings)
{
if (!hint_strings.empty())
{
std::vector<engine::SegmentHint> 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,7 +94,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
const auto add_bearing =
[](engine::api::BaseParameters &base_parameters,
boost::optional<boost::fusion::vector2<short, short>> bearing_range) {
boost::optional<boost::fusion::vector2<short, short>> bearing_range)
{
boost::optional<engine::Bearing> bearing;
if (bearing_range)
{
@ -118,7 +119,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
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,18 +128,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
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);
},
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);
},
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 =

View File

@ -54,8 +54,9 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
#endif
using AnnotationsType = engine::api::RouteParameters::AnnotationsType;
const auto add_annotation = [](engine::api::RouteParameters &route_parameters,
AnnotationsType route_param) {
const auto add_annotation =
[](engine::api::RouteParameters &route_parameters, AnnotationsType route_param)
{
route_parameters.annotations_type = route_parameters.annotations_type | route_param;
route_parameters.annotations =
route_parameters.annotations_type != AnnotationsType::None;

View File

@ -66,7 +66,8 @@ void readBoolVector(tar::FileReader &reader, const std::string &name, VectorT &d
using BlockType = std::uint64_t;
constexpr std::uint64_t BLOCK_BITS = CHAR_BIT * sizeof(BlockType);
const auto decode = [&](const BlockType block) {
const auto decode = [&](const BlockType block)
{
auto read_size = std::min<std::size_t>(count - index, BLOCK_BITS);
unpackBits<VectorT, BlockType>(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<BlockType()> encode_function = [&]() -> BlockType {
const std::function<BlockType()> encode_function = [&]() -> BlockType
{
auto write_size = std::min<std::size_t>(count - index, BLOCK_BITS);
auto packed = packBits<VectorT, BlockType>(data, index, write_size);
index += BLOCK_BITS;

View File

@ -28,10 +28,10 @@ class SharedDataIndex
// Build mapping from block name to region
for (auto index : util::irange<std::uint32_t>(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; }));
}
}

View File

@ -223,7 +223,10 @@ 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 &region) {
auto iter = std::find_if(
regions.begin(),
regions.end(),
[&](const auto &region) {
return std::strncmp(region.name, name.c_str(), SharedRegion::MAX_NAME_LENGTH) == 0;
});

View File

@ -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:

View File

@ -241,9 +241,9 @@ inline auto make_contracted_metric_view(const SharedDataIndex &index, const std:
std::vector<util::vector_view<bool>> edge_filter;
index.List(name + "/exclude",
boost::make_function_output_iterator([&](const auto &filter_name) {
edge_filter.push_back(make_vector_view<bool>(index, filter_name));
}));
boost::make_function_output_iterator(
[&](const auto &filter_name)
{ edge_filter.push_back(make_vector_view<bool>(index, filter_name)); }));
return contractor::ContractedMetricView{{node_list, edge_list}, std::move(edge_filter)};
}

View File

@ -46,7 +46,10 @@ template <typename Key, typename Value> struct CSVFilesParser
{
tbb::spin_mutex mutex;
std::vector<std::pair<Key, Value>> lookup;
tbb::parallel_for(std::size_t{0}, csv_filenames.size(), [&](const std::size_t idx) {
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
@ -61,16 +64,18 @@ template <typename Key, typename Value> struct CSVFilesParser
// 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) {
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 "

View File

@ -15,10 +15,11 @@ template <typename Key, typename Value> struct LookupTable
boost::optional<Value> operator()(const Key &key) const
{
using Result = boost::optional<Value>;
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();
}

View File

@ -179,7 +179,8 @@ template <class BinaryOperation, typename iterator_type>
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<double>::max();
// comparator updating current_min without ever finding an element
const auto compute_minimum_distance = [&current_min, coordinate](const Coordinate lhs,
const Coordinate rhs) {
const auto compute_minimum_distance =
[&current_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<double>::max();
const auto compute_minimum_distance_in_rhs = [&current_min, rhs_begin, rhs_end](
const Coordinate coordinate) {
const auto compute_minimum_distance_in_rhs =
[&current_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<Coordinate, Coordinate> 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<double>(toFloating(coordinate.lon));
};
const auto extract_lon = [](const Coordinate coordinate)
{ return static_cast<double>(toFloating(coordinate.lon)); };
const auto extract_lat = [](const Coordinate coordinate) {
return static_cast<double>(toFloating(coordinate.lat));
};
const auto extract_lat = [](const Coordinate coordinate)
{ return static_cast<double>(toFloating(coordinate.lat)); };
double min_lon = extract_lon(*begin);
double max_lon = extract_lon(*begin);
@ -262,19 +263,21 @@ std::pair<Coordinate, Coordinate> leastSquareRegression(const iterator_type begi
{
std::vector<util::Coordinate> 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<Coordinate, Coordinate> 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<Coordinate, Coordinate> 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<Coordinate, Coordinate> 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<double>((longitude))};
};
slope](const util::FloatLongitude longitude) -> util::FloatLatitude
{ return {intercept + slope * static_cast<double>((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<int>(from.lat) - static_cast<int>(to.lat);
const auto diff_lon = static_cast<int>(from.lon) - static_cast<int>(to.lon);
if (diff_lon == 0)

View File

@ -189,8 +189,11 @@ template <typename EdgeDataT> 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) {
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);

View File

@ -37,9 +37,9 @@ class FilteredGraphImpl<util::StaticGraph<EdgeDataT, Ownership>, 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

View File

@ -63,14 +63,16 @@ template <typename StringView> 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);

View File

@ -315,9 +315,8 @@ template <typename GroupBlockPolicy, storage::Ownership Ownership> struct Indexe
values_byte_iter = block.WriteBlockPrefix(curr, next, values_byte_iter);
std::advance(next, std::min<diff_type>(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)));

View File

@ -43,8 +43,7 @@ class integer_iterator : public boost::iterator_facade<integer_iterator<Integer>
difference_type distance_to(const integer_iterator &other) const
{
return std::is_signed<value_type>::value
? (other.m_value - m_value)
return std::is_signed<value_type>::value ? (other.m_value - m_value)
: (other.m_value >= m_value)
? static_cast<difference_type>(other.m_value - m_value)
: -static_cast<difference_type>(m_value - other.m_value);

View File

@ -79,7 +79,8 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes,
auto edges_list = directedEdgesFromCompressed<NodeBasedDynamicGraph::InputEdge>(
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;

View File

@ -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<TimeSpan> times;

View File

@ -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();
}

View File

@ -64,7 +64,8 @@ template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
// construct table from length vector
template <typename VectorT> 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)
{

View File

@ -304,7 +304,11 @@ 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) {
std::transform(begin,
end,
edge_array.begin(),
[](const auto &from)
{
return static_graph_details::edgeToEntry<EdgeArrayEntry>(
from, traits::HasDataMember<EdgeArrayEntry>{});
});

View File

@ -281,7 +281,8 @@ class StaticRTree
tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, element_count),
[&input_data_vector, &input_wrapper_vector, this](
const tbb::blocked_range<uint64_t> &range) {
const tbb::blocked_range<uint64_t> &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.

View File

@ -18,7 +18,8 @@ template <int length, int precision> 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;

View File

@ -51,13 +51,17 @@ template <std::size_t TimeBinSize = 1000, std::size_t IndexBinSize = 1000> 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) {
std::for_each(begin,
end,
[&](const auto count)
{
if (count > 0)
{
out << (frame_index * TimeBinSize) << "," << (bin_index * IndexBinSize) << ","
<< count << std::endl;
out << (frame_index * TimeBinSize) << ","
<< (bin_index * IndexBinSize) << "," << count << std::endl;
}
bin_index++;
});

View File

@ -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-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 != *10.0* ]] ; then
echo "clang-format is not 10.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-10, or clang-format)"
echo "No appropriate clang-format found (expected clang-format-15, or clang-format)"
exit 1
fi

View File

@ -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

View File

@ -619,7 +619,8 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
util::UnbufferedLog log;
log << "initializing node priorities...";
tbb::parallel_for(tbb::blocked_range<std::size_t>(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<bool> contractGraph(ContractorGraph &graph,
tbb::parallel_for(
tbb::blocked_range<NodeID>(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<bool> 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<bool> contractGraph(ContractorGraph &graph,
tbb::parallel_for(
tbb::blocked_range<NodeID>(
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<bool> contractGraph(ContractorGraph &graph,
tbb::parallel_for(
tbb::blocked_range<NodeID>(
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,9 +713,12 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
});
// make sure we really sort each block
tbb::parallel_for(thread_data_list.data.range(), [&](const auto &range) {
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_sort(data->inserted_edges.begin(),
data->inserted_edges.end());
});
// insert new edges
@ -743,7 +750,8 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
tbb::parallel_for(
tbb::blocked_range<NodeID>(
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)
{

View File

@ -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; });
}
}

View File

@ -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(),
std::transform(intersection.classes.begin(),
intersection.classes.end(),
std::back_inserter(classes.values),
[](const std::string &class_name) { return util::json::String{class_name}; });
[](const std::string &class_name)
{ return util::json::String{class_name}; });
result.values["classes"] = std::move(classes);
}

View File

@ -43,9 +43,11 @@ std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::cons
}
std::vector<util::FloatCoordinate> 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<bool> is_necessary(size, false);
BOOST_ASSERT(is_necessary.size() >= 2);

View File

@ -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) &&

View File

@ -40,13 +40,11 @@ unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometri
std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
const bool use_simplification)
{
auto overview_size =
std::accumulate(leg_geometries.begin(),
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();
}) -
[](const std::size_t sum, const LegGeometry &leg_geometry)
{ return sum + leg_geometry.locations.size(); }) -
leg_geometries.size() + 1;
std::vector<util::Coordinate> overview_geometry;
overview_geometry.reserve(overview_size);
@ -54,8 +52,9 @@ std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &l
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)
{

View File

@ -7,18 +7,21 @@ namespace osrm::engine::guidance
Route assembleRoute(const std::vector<RouteLeg> &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};
}

View File

@ -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];

View File

@ -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));
};

View File

@ -17,7 +17,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> 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<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
std::vector<StepIterRange> 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<RouteStep> anticipateLaneChange(std::vector<RouteStep> 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<StepIter> rev_first{turns.second};
const std::reverse_iterator<StepIter> rev_last{turns.first};
@ -74,7 +77,11 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> 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 &current, RouteStep &previous) {
util::for_each_pair(
rev_first,
rev_last,
[&](RouteStep &current, RouteStep &previous)
{
const auto current_inst = current.maneuver.instruction;
const auto current_lanes = current.intersections.front().lanes;
@ -86,7 +93,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
// 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;
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
@ -102,11 +110,12 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
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.
// 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();
@ -123,7 +132,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
}
// 1/ How to anticipate left, right:
const auto anticipate_for_left_turn = [&] {
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 =
@ -139,7 +149,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
};
const auto anticipate_for_right_turn = [&] {
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;

View File

@ -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<RouteStepIterator, RouteStepIterator> &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<RouteStepIterator, RouteStepIterato
std::vector<RouteStep> handleRoundabouts(std::vector<RouteStep> 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<RouteStep> handleRoundabouts(std::vector<RouteStep> 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 = [&currently_on_roundabout](const auto &step) {
const auto is_on_roundabout = [&currently_on_roundabout](const auto &step)
{
if (currently_on_roundabout)
{
if (leavesRoundabout(step.maneuver.instruction))
@ -327,7 +327,10 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
}
// and update the leg geometry indices for the removed entry
std::for_each(steps.begin(), steps.end(), [offset](RouteStep &step) {
std::for_each(steps.begin(),
steps.end(),
[offset](RouteStep &step)
{
step.geometry_begin -= offset;
step.geometry_end -= offset;
});
@ -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)

View File

@ -15,19 +15,20 @@ std::vector<RouteStep> suppressShortNameSegments(std::vector<RouteStep> 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,7 +37,8 @@ std::vector<RouteStep> suppressShortNameSegments(std::vector<RouteStep> steps)
// only available for a very short time
const auto reduce_verbosity_if_possible =
[suppress, can_be_extended_to](RouteStepIterator &current_turn_itr,
RouteStepIterator &previous_turn_itr) {
RouteStepIterator &previous_turn_itr)
{
if (haveSameName(*previous_turn_itr, *current_turn_itr))
suppress(*previous_turn_itr, *current_turn_itr);
else

View File

@ -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;

View File

@ -50,7 +50,8 @@ void filterCandidates(const std::vector<util::Coordinate> &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<util::Coordinate> &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<util::Coordinate> &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<double> &maybe_radius) {
[default_radius = this->default_radius](const boost::optional<double> &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<PhantomNodeWithDistance> &candidates) {
return candidates.empty();
}))
[](const std::vector<PhantomNodeWithDistance> &candidates)
{ return candidates.empty(); }))
{
return Error("NoSegment",
std::string("Could not find a matching segment for any coordinate."),

View File

@ -251,7 +251,8 @@ std::vector<std::size_t> getEdgeIndex(const std::vector<RTreeLeaf> &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;

View File

@ -137,7 +137,8 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
std::vector<bool> 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,19 +157,20 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
else
{
const auto all_in_same_component =
[](const std::vector<PhantomNodeCandidates> &waypoint_candidates) {
[](const std::vector<PhantomNodeCandidates> &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 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);
return candidatesHaveComponent(candidates, component_id);
});
});
};

View File

@ -223,9 +223,8 @@ RandIt filterViaCandidatesByStretch(RandIt first,
const auto stretch_weight_limit =
(1. + parameters.kAtMostLongerBy) * from_alias<double>(weight);
const auto over_weight_limit = [=](const auto via) {
return from_alias<double>(via.weight) > stretch_weight_limit;
};
const auto over_weight_limit = [=](const auto via)
{ return from_alias<double>(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<double>(shortest_route_duration);
const auto over_duration_limit = [=](const auto &route) {
return from_alias<double>(route.duration()) > stretch_duration_limit;
};
const auto over_duration_limit = [=](const auto &route)
{ return from_alias<double>(route.duration()) > stretch_duration_limit; };
return std::remove_if(first, last, over_duration_limit);
}
@ -837,9 +842,9 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData<Algorithm> &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<Algorithm> &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<Algorithm> &sear
std::vector<InternalRouteResult> 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,

View File

@ -45,11 +45,12 @@ InternalRouteResult directShortestPathSearch(SearchEngineData<ch::Algorithm> &en
unpacked_nodes.reserve(packed_leg.size());
unpacked_edges.reserve(packed_leg.size());
unpacked_nodes.push_back(packed_leg.front());
ch::unpackPath(facade,
ch::unpackPath(
facade,
packed_leg.begin(),
packed_leg.end(),
[&unpacked_nodes, &unpacked_edges](std::pair<NodeID, NodeID> &edge,
const auto &edge_id) {
[&unpacked_nodes, &unpacked_edges](std::pair<NodeID, NodeID> &edge, const auto &edge_id)
{
BOOST_ASSERT(edge.first == unpacked_nodes.back());
unpacked_nodes.push_back(edge.second);
unpacked_edges.push_back(edge_id);

View File

@ -280,7 +280,8 @@ oneToManySearch(SearchEngineData<Algorithm> &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) {
[&](NodeID node, EdgeWeight weight, EdgeDuration duration, EdgeDistance distance)
{
auto candidates = target_nodes_index.equal_range(node);
for (auto it = candidates.first; it != candidates.second;)
{
@ -322,7 +323,8 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
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

View File

@ -83,7 +83,8 @@ SubMatchingList mapMatching(SearchEngineData<Algorithm> &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<Algorithm> &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<Algorithm> &engine_working_data,
{
map_matching::EmissionLogProbability emission_log_probability(
*trace_gps_precision[t]);
std::transform(
candidates_list[t].begin(),
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);
});
[&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<Algorithm> &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<Algorithm> &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<Algorithm> &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<Algorithm> &engine_working_data,
util::for_each_pair(
reconstructed_indices,
[&trace_distance, &trace_coordinates](const std::pair<std::size_t, std::size_t> &prev,
const std::pair<std::size_t, std::size_t> &curr) {
const std::pair<std::size_t, std::size_t> &curr)
{
trace_distance += util::coordinate_calculation::greatCircleDistance(
trace_coordinates[prev.first], trace_coordinates[curr.first]);
});

View File

@ -25,9 +25,8 @@ std::vector<NodeID> 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<NodeID> 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;
});

View File

@ -19,9 +19,8 @@ void unpackEdge(const DataFacade<Algorithm> &facade,
unpackPath(facade,
path.begin(),
path.end(),
[&unpacked_path](const std::pair<NodeID, NodeID> &edge, const auto & /* data */) {
unpacked_path.emplace_back(edge.first);
});
[&unpacked_path](const std::pair<NodeID, NodeID> &edge, const auto & /* data */)
{ unpacked_path.emplace_back(edge.first); });
unpacked_path.emplace_back(to);
}

View File

@ -35,9 +35,8 @@ std::vector<TurnData> 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<TurnData> getTileTurns(const DataFacade<ch::Algorithm> &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<TurnData> getTileTurns(const DataFacade<ch::Algorithm> &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,

View File

@ -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<void, tbb::blocked_range<NodeID>> 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<tbb::blocked_range<NodeID>, EdgesPipelineBufferPtr> processor_stage(
tbb::filter_mode::parallel,
[&](const tbb::blocked_range<NodeID> &intersection_node_range) {
[&](const tbb::blocked_range<NodeID> &intersection_node_range)
{
auto buffer = std::make_shared<EdgesPipelineBuffer>();
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<ExtractionTurnLeg> road_legs_on_the_right;
std::vector<ExtractionTurnLeg> 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<EdgeWithData> delayed_data;
tbb::filter<EdgesPipelineBufferPtr, void> 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,13 +1187,19 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
return std::vector<NodeID>{turn_edges.second.first, turn_edges.second.second};
});
std::for_each(std::next(turns.begin()), turns.end(), [&](const auto &turn) {
std::for_each(std::next(turns.begin()),
turns.end(),
[&](const auto &turn)
{
std::vector<std::vector<NodeID>> 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) {
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);
});
@ -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<NodeID>(0, m_edge_based_edge_list.size()),
[this](const tbb::blocked_range<NodeID> &range) {
[this](const tbb::blocked_range<NodeID> &range)
{
for (auto x = range.begin(), end = range.end(); x != end; ++x)
{
m_edge_based_edge_list[x].data.turn_id = x;

View File

@ -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,7 +1099,8 @@ void ExtractionContainers::PrepareManeuverOverrides(const ReferencedWays &maneuv
};
const auto transform_into_internal_types =
[&](const InputManeuverOverride &external_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));
@ -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<OSMNodeID> 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))
{

View File

@ -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<void, SharedBuffer>(
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<osmium::memory::Buffer>(std::move(buffer));
@ -466,7 +469,9 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting
osmium_location_handler_type location_handler(location_cache);
tbb::filter<SharedBuffer, SharedBuffer> 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<SharedBuffer, ParsedBuffer> 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<ParsedBuffer, void> 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<SharedBuffer, std::shared_ptr<ExtractionRelationContainer>> buffer_relation_cache(
tbb::filter_mode::parallel,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
[&](const SharedBuffer buffer) {
[&](const SharedBuffer buffer)
{
if (!buffer)
return std::shared_ptr<ExtractionRelationContainer>{};
@ -562,7 +571,8 @@ Extractor::ParsedOSMData Extractor::ParseOSMData(ScriptingEnvironment &scripting
tbb::filter<std::shared_ptr<ExtractionRelationContainer>, void> buffer_storage_relation(
tbb::filter_mode::serial_in_order,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
[&](const std::shared_ptr<ExtractionRelationContainer> parsed_relations) {
[&](const std::shared_ptr<ExtractionRelationContainer> 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<EdgeBasedNodeSegment> 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 "

View File

@ -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,8 +423,9 @@ 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) {
util::for_each_pair(nodes,
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
{
NodeBasedEdgeWithOSM edge = {
OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
@ -439,8 +445,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
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, {}));
external_memory.all_edges_list.push_back(InternalExtractorEdge(
edge, forward_weight_data, forward_duration_data, {}));
});
}
@ -452,8 +458,9 @@ 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) {
util::for_each_pair(nodes,
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
{
NodeBasedEdgeWithOSM edge = {
OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
@ -473,17 +480,16 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
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, {}));
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<std::uint64_t>(ref.ref())};
});
[](const osmium::NodeRef &ref)
{ return OSMNodeID{static_cast<std::uint64_t>(ref.ref())}; });
auto way_id = OSMWayID{static_cast<std::uint64_t>(input_way.id())};
external_memory.ways_list.push_back(way_id);

View File

@ -37,7 +37,8 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
// restriction path.
std::unordered_set<NodeID> 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,7 +187,8 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
*/
const auto selectAnnotation =
[&node_data_container](const AnnotationID front_annotation,
const AnnotationID 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
@ -250,10 +252,10 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &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<EdgeDuration>(extraction_turn.duration *
@ -303,7 +305,8 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &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<NodeID> &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)
{

View File

@ -88,9 +88,8 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(
std::vector<util::Coordinate> 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,7 +471,8 @@ 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 util::Coordinate coordinate) mutable
{
const double segment_distance =
util::coordinate_calculation::greatCircleDistance(last_coordinate, coordinate);
const auto result = (accumulated_distance + segment_distance) >= distance;
@ -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,7 +529,8 @@ 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) {
const CompressedEdgeContainer::OnewayCompressedEdge &compressed_edge)
{
return util::coordinate_calculation::greatCircleDistance(
compressedGeometryToCoordinate(compressed_edge), start_coordinate) > 1;
};
@ -614,7 +618,8 @@ CoordinateExtractor::GetMaxDeviation(std::vector<util::Coordinate>::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<util::Coordinate>::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<util::Coordinate> &coordinates,
@ -645,7 +651,8 @@ bool CoordinateExtractor::IsCurve(const std::vector<util::Coordinate> &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<util::Coordinate> &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,15 +677,18 @@ bool CoordinateExtractor::IsCurve(const std::vector<util::Coordinate> &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) {
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;
@ -694,13 +705,16 @@ bool CoordinateExtractor::IsCurve(const std::vector<util::Coordinate> &coordinat
double maximum_deviation = 0;
std::tie(has_up_down_deviation, maximum_deviation_index, maximum_deviation) =
[&coordinates, get_deviation]() -> std::tuple<bool, std::size_t, double> {
const auto increasing = [&](const util::Coordinate lhs, const util::Coordinate rhs) {
[&coordinates, get_deviation]() -> std::tuple<bool, std::size_t, double>
{
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<util::Coordinate> &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<double> 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<util::Coordinate> &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<util::Coordinate> &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<util::Coordinate> &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<util::Coordinate> &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,13 +905,14 @@ CoordinateExtractor::PrepareLengthCache(const std::vector<util::Coordinate> &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)),
[[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 {
accumulated_distance = 0.](const util::Coordinate current_coordinate) mutable
{
const auto distance = util::coordinate_calculation::greatCircleDistance(
last_coordinate, current_coordinate);
accumulated_distance += distance;
@ -916,8 +934,8 @@ CoordinateExtractor::TrimCoordinatesToLength(std::vector<util::Coordinate> 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 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],
@ -925,9 +943,8 @@ CoordinateExtractor::TrimCoordinatesToLength(std::vector<util::Coordinate> coord
return new_distance;
};
const auto read_length_from_cache = [&length_cache, &coordinate_index]() {
return length_cache[coordinate_index];
};
const auto read_length_from_cache = [&length_cache, &coordinate_index]()
{ return length_cache[coordinate_index]; };
bool use_cache = !length_cache.empty();
@ -1044,8 +1061,9 @@ CoordinateExtractor::SampleCoordinates(const std::vector<util::Coordinate> &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;

View File

@ -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<std::size_t>(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 <typename RestrictionsRange>
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<double>::epsilon();
};
const auto is_uturn = [](const auto angle)
{ return std::fabs(angle) < std::numeric_limits<double>::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(),
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);
});
[](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

View File

@ -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<std::uint8_t>(
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;

View File

@ -74,10 +74,12 @@ boost::optional<EdgeID> 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<EdgeID> 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<EdgeID> 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;

View File

@ -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<segment_t> 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<point_t>::type;
auto x_min = std::numeric_limits<coord_t>::max();
auto y_min = std::numeric_limits<coord_t>::max();
@ -208,14 +213,18 @@ LocationDependentData::FindByKey(const std::vector<std::size_t> &property_indexe
std::vector<std::size_t> LocationDependentData::GetPropertyIndexes(const point_t &point) const
{
std::vector<std::size_t> 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) {
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

View File

@ -46,8 +46,11 @@ void NodeBasedGraphFactory::BuildCompressedOutputGraph(const std::vector<NodeBas
util::NodeBasedDynamicGraphFromEdges(number_of_node_based_nodes, edge_list);
// check whether the graph is sane
BOOST_ASSERT([this]() {
for (const auto nbg_node_u : util::irange(0u, compressed_output_graph.GetNumberOfNodes()))
BOOST_ASSERT(
[this]()
{
for (const auto nbg_node_u :
util::irange(0u, compressed_output_graph.GetNumberOfNodes()))
{
for (EdgeID nbg_edge_id : compressed_output_graph.GetAdjacentEdgeRange(nbg_node_u))
{
@ -59,7 +62,8 @@ void NodeBasedGraphFactory::BuildCompressedOutputGraph(const std::vector<NodeBas
auto reverse = compressed_output_graph.FindEdge(nbg_node_v, nbg_node_u);
// found an edge that is reversed in both directions, should be two distinct edges
// found an edge that is reversed in both directions, should be two distinct
// edges
if (compressed_output_graph.GetEdgeData(nbg_edge_id).reversed &&
compressed_output_graph.GetEdgeData(reverse).reversed)
return false;
@ -208,11 +212,13 @@ void NodeBasedGraphFactory::CompressAnnotationData()
}
// remove unreferenced entries, shifting other entries to the front
const auto new_end =
std::remove_if(annotation_data.begin(), annotation_data.end(), [&](auto const &data) {
// both elements are considered equal (to remove the second
// one) if the annotation mapping of the second one is
// invalid
const auto new_end = std::remove_if(annotation_data.begin(),
annotation_data.end(),
[&](auto const &data)
{
// both elements are considered equal (to remove the
// second one) if the annotation mapping of the second
// one is invalid
return data.name_id == INVALID_NAMEID;
});

View File

@ -123,9 +123,10 @@ struct transferBuilder
for (const auto &suffix_node : suffix_nodes)
{
const auto &edges = rg.GetEdges(suffix_node);
const auto edge_it = std::find_if(edges.begin(), edges.end(), [&to](const auto &edge) {
return edge.node_based_to == to && !edge.is_transfer;
});
const auto edge_it = std::find_if(
edges.begin(),
edges.end(),
[&to](const auto &edge) { return edge.node_based_to == to && !edge.is_transfer; });
if (edge_it != edges.end())
{
*(new_suffix_it++) = edge_it->target;
@ -154,7 +155,10 @@ 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) {
std::any_of(restrictions.begin(),
restrictions.end(),
[&](const auto &restriction)
{
return restriction->IsTurnRestricted(suffix_edge.node_based_to) &&
restriction->IsUnconditional();
});
@ -163,9 +167,10 @@ struct transferBuilder
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 <typename builder_type>
void buildGraph(RestrictionGraph &rg, const std::vector<TurnRestriction> &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<TurnRestriction> &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)
{

Some files were not shown because too many files have changed in this diff Show More