From 44bc0a521eae7e304ccfa8626de61e54bfe72ebc Mon Sep 17 00:00:00 2001 From: Vsevolod Novikov Date: Mon, 15 Feb 2021 19:46:06 +0300 Subject: [PATCH] #5325 CLang format --- include/engine/guidance/assemble_geometry.hpp | 2 +- .../extractor/compressed_edge_container.hpp | 5 +- include/extractor/node_based_edge.hpp | 2 +- .../server/api/route_parameters_grammar.hpp | 6 +- src/engine/guidance/post_processing.cpp | 2 +- src/extractor/compressed_edge_container.cpp | 54 ++++--- src/extractor/extractor.cpp | 18 +-- src/extractor/extractor_callbacks.cpp | 3 +- src/extractor/node_based_graph_factory.cpp | 3 +- unit_tests/library/route.cpp | 136 +++++++++--------- 10 files changed, 122 insertions(+), 109 deletions(-) diff --git a/include/engine/guidance/assemble_geometry.hpp b/include/engine/guidance/assemble_geometry.hpp index b651fbd07..a9623c209 100644 --- a/include/engine/guidance/assemble_geometry.hpp +++ b/include/engine/guidance/assemble_geometry.hpp @@ -56,7 +56,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id; const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id; const auto source_geometry = facade.GetUncompressedForwardGeometry(source_geometry_id); - //const auto source_osm_way_ids = facade.GetUncompressedForwardWayIDs(source_geometry_id); + // const auto source_osm_way_ids = facade.GetUncompressedForwardWayIDs(source_geometry_id); geometry.osm_node_ids.push_back( facade.GetOSMNodeIDOfNode(source_geometry(source_segment_start_coordinate))); diff --git a/include/extractor/compressed_edge_container.hpp b/include/extractor/compressed_edge_container.hpp index 904369b0e..7412d7606 100644 --- a/include/extractor/compressed_edge_container.hpp +++ b/include/extractor/compressed_edge_container.hpp @@ -1,8 +1,8 @@ #ifndef GEOMETRY_COMPRESSOR_HPP_ #define GEOMETRY_COMPRESSOR_HPP_ -#include "extractor/segment_data_container.hpp" #include "extractor/node_based_edge.hpp" +#include "extractor/segment_data_container.hpp" #include "util/typedefs.hpp" @@ -49,7 +49,8 @@ class CompressedEdgeContainer const SegmentWeight duration); void InitializeBothwayVector(); - unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos, OSMWayIDMap &osm_way_id_map); + unsigned + ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos, OSMWayIDMap &osm_way_id_map); bool HasEntryForID(const EdgeID edge_id) const; bool HasZippedEntryForForwardID(const EdgeID edge_id) const; diff --git a/include/extractor/node_based_edge.hpp b/include/extractor/node_based_edge.hpp index 44f198da7..09148422a 100644 --- a/include/extractor/node_based_edge.hpp +++ b/include/extractor/node_based_edge.hpp @@ -2,8 +2,8 @@ #define NODE_BASED_EDGE_HPP #include -#include #include +#include #include "extractor/class_data.hpp" #include "extractor/travel_mode.hpp" diff --git a/include/server/api/route_parameters_grammar.hpp b/include/server/api/route_parameters_grammar.hpp index dc005043b..653ed5df7 100644 --- a/include/server/api/route_parameters_grammar.hpp +++ b/include/server/api/route_parameters_grammar.hpp @@ -73,10 +73,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar &steps, LegGeometry &geometry) geometry.osm_node_ids.erase(geometry.osm_node_ids.begin(), geometry.osm_node_ids.begin() + offset); geometry.osm_way_ids.erase(geometry.osm_way_ids.begin(), - geometry.osm_way_ids.begin() + offset); + geometry.osm_way_ids.begin() + offset); } auto const first_bearing = steps.front().maneuver.bearing_after; diff --git a/src/extractor/compressed_edge_container.cpp b/src/extractor/compressed_edge_container.cpp index 81b2e631c..92db95896 100644 --- a/src/extractor/compressed_edge_container.cpp +++ b/src/extractor/compressed_edge_container.cpp @@ -262,7 +262,9 @@ void CompressedEdgeContainer::InitializeBothwayVector() segment_data->rev_datasources.reserve(m_compressed_oneway_geometries.size()); } -unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID r_edge_id, OSMWayIDMap &osm_way_id_map) +unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, + const EdgeID r_edge_id, + OSMWayIDMap &osm_way_id_map) { if (!segment_data) InitializeBothwayVector(); @@ -299,18 +301,27 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID BOOST_ASSERT(fwd_node.node_id == rev_node.node_id); auto node_id = fwd_node.node_id; - if( node_id != prev_node_id ) { - auto find_way_id = osm_way_id_map.find( OSMWayIDMapKey(prev_node_id, node_id) ); - if( find_way_id == osm_way_id_map.cend() ) { - find_way_id = osm_way_id_map.find( OSMWayIDMapKey(node_id, prev_node_id) ); + if (node_id != prev_node_id) + { + auto find_way_id = osm_way_id_map.find(OSMWayIDMapKey(prev_node_id, node_id)); + if (find_way_id == osm_way_id_map.cend()) + { + find_way_id = osm_way_id_map.find(OSMWayIDMapKey(node_id, prev_node_id)); } - if( find_way_id == osm_way_id_map.cend() ) { - util::Log(logERROR) << "OSM Way ID not found for (nbg) nodes, it should never be happened: " << prev_node_id << "<-x->" << node_id; + if (find_way_id == osm_way_id_map.cend()) + { + util::Log(logERROR) + << "OSM Way ID not found for (nbg) nodes, it should never be happened: " + << prev_node_id << "<-x->" << node_id; segment_data->osm_ways.emplace_back(osm_way_id); - } else { + } + else + { segment_data->osm_ways.emplace_back(osm_way_id = find_way_id->second); } - } else { + } + else + { // Special case (artificial lighting signal edge) segment_data->osm_ways.emplace_back(osm_way_id); } @@ -327,18 +338,27 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID const auto &last_node = forward_bucket.back(); auto node_id = last_node.node_id; - if( node_id != prev_node_id ) { - auto find_way_id = osm_way_id_map.find( OSMWayIDMapKey(prev_node_id, node_id) ); - if( find_way_id == osm_way_id_map.cend() ) { - find_way_id = osm_way_id_map.find( OSMWayIDMapKey(node_id, prev_node_id) ); + if (node_id != prev_node_id) + { + auto find_way_id = osm_way_id_map.find(OSMWayIDMapKey(prev_node_id, node_id)); + if (find_way_id == osm_way_id_map.cend()) + { + find_way_id = osm_way_id_map.find(OSMWayIDMapKey(node_id, prev_node_id)); } - if( find_way_id == osm_way_id_map.cend() ) { - util::Log(logERROR) << "OSM Way ID not found for (nbg) nodes, it should never be happened: " << prev_node_id << "<-x->" << node_id; + if (find_way_id == osm_way_id_map.cend()) + { + util::Log(logERROR) + << "OSM Way ID not found for (nbg) nodes, it should never be happened: " + << prev_node_id << "<-x->" << node_id; segment_data->osm_ways.emplace_back(osm_way_id); - } else { + } + else + { segment_data->osm_ways.emplace_back(osm_way_id = find_way_id->second); } - } else { + } + else + { // Special case (artificial lighting signal edge) segment_data->osm_ways.emplace_back(osm_way_id); } diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 641e80b34..eb9b6829f 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -370,10 +370,12 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) return 0; } -std:: - tuple, std::vector> - Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, - const unsigned number_of_threads) +std::tuple, + std::vector> +Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, + const unsigned number_of_threads) { TIMER_START(extracting); @@ -631,10 +633,10 @@ std:: files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties); // Fill OSM Way ID Lookup Map to use it later - for(auto edge: extraction_containers.all_edges_list) { - osm_way_id_map[ - OSMWayIDMapKey(edge.result.source, edge.result.target) - ] = edge.result.osm_way_id; + for (auto edge : extraction_containers.all_edges_list) + { + osm_way_id_map[OSMWayIDMapKey(edge.result.source, edge.result.target)] = + edge.result.osm_way_id; } TIMER_STOP(extracting); diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index 4b6bf84e2..bc5f5627a 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -32,8 +32,7 @@ ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containe OSMWayIDMap &osm_way_id_map, const ProfileProperties &properties) : external_memory(extraction_containers_), classes_map(classes_map), - lane_description_map(lane_description_map), - osm_way_id_map(osm_way_id_map), + lane_description_map(lane_description_map), osm_way_id_map(osm_way_id_map), fallback_to_duration(properties.fallback_to_duration), force_split_edges(properties.force_split_edges) { diff --git a/src/extractor/node_based_graph_factory.cpp b/src/extractor/node_based_graph_factory.cpp index 6ae8dbf94..4ca097b46 100644 --- a/src/extractor/node_based_graph_factory.cpp +++ b/src/extractor/node_based_graph_factory.cpp @@ -127,7 +127,8 @@ void NodeBasedGraphFactory::CompressGeometry(OSMWayIDMap &osm_way_id_map) const EdgeID edge_id_2 = compressed_output_graph.FindEdge(to, from); BOOST_ASSERT(edge_id_2 != SPECIAL_EDGEID); - auto packed_geometry_id = compressed_edge_container.ZipEdges(edge_id_1, edge_id_2, osm_way_id_map); + auto packed_geometry_id = + compressed_edge_container.ZipEdges(edge_id_1, edge_id_2, osm_way_id_map); // remember the geometry ID for both edges in the node-based graph compressed_output_graph.GetEdgeData(edge_id_1).geometry_id = {packed_geometry_id, true}; diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index cd853f4b0..75444061a 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -14,9 +14,9 @@ #include "osrm/osrm.hpp" #include "osrm/route_parameters.hpp" #include "osrm/status.hpp" -#include -#include #include +#include +#include #include #include #include @@ -601,17 +601,22 @@ BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_new_api) test_manual_setting_of_annotations_property(false); } -using NodePair = std::pair; -using NodePairToWayIDMap = std::map; +using NodePair = std::pair; +using NodePairToWayIDMap = std::map; -NodePairToWayIDMap read_node_pair_to_way_id_map(osmium::io::Reader &osm) { - struct H: public osmium::handler::Handler { +NodePairToWayIDMap read_node_pair_to_way_id_map(osmium::io::Reader &osm) +{ + struct H : public osmium::handler::Handler + { NodePairToWayIDMap ret; - void way(const osmium::Way &way) { + void way(const osmium::Way &way) + { auto first = osmium::unsigned_object_id_type(-1); - for( const auto &n: way.nodes() ) { + for (const auto &n : way.nodes()) + { const auto second = n.positive_ref(); - if( first != osmium::unsigned_object_id_type(-1) ) { + if (first != osmium::unsigned_object_id_type(-1)) + { ret[{first, second}] = way.id(); } first = second; @@ -625,19 +630,17 @@ NodePairToWayIDMap read_node_pair_to_way_id_map(osmium::io::Reader &osm) { using LonLat = std::pair; using LonLatVector = std::vector; -LonLatVector check_route_annotated_ways( - std::vector &coordinates, - osrm::OSRM &osrm, - NodePairToWayIDMap &node_pair_to_way_id_map, - bool use_steps -) { +LonLatVector check_route_annotated_ways(std::vector &coordinates, + osrm::OSRM &osrm, + NodePairToWayIDMap &node_pair_to_way_id_map, + bool use_steps) +{ LonLatVector ret; using namespace osrm; - (void) node_pair_to_way_id_map; + (void)node_pair_to_way_id_map; RouteParameters params{}; params.annotations_type = - RouteParameters::AnnotationsType::Nodes | - RouteParameters::AnnotationsType::Ways; + RouteParameters::AnnotationsType::Nodes | RouteParameters::AnnotationsType::Ways; params.steps = use_steps; params.geometries = engine::api::RouteParameters::GeometriesType::GeoJSON; params.coordinates = coordinates; @@ -649,37 +652,33 @@ LonLatVector check_route_annotated_ways( const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - auto routes = json_result.values["routes"] - .get() - .values; + auto routes = json_result.values["routes"].get().values; BOOST_CHECK_EQUAL(routes.size(), 1); auto route = routes[0]; auto geom = route.get() - .values["geometry"] - .get() - .values["coordinates"] - .get() - .values; + .values["geometry"] + .get() + .values["coordinates"] + .get() + .values; - auto legs = route.get() - .values["legs"] - .get() - .values; - for(auto leg: legs) { - if( use_steps ) { - auto steps = leg.get() - .values["steps"] - .get() - .values; - for(auto step: steps) { + auto legs = route.get().values["legs"].get().values; + for (auto leg : legs) + { + if (use_steps) + { + auto steps = leg.get().values["steps"].get().values; + for (auto step : steps) + { auto geom = step.get() - .values["geometry"] - .get() - .values["coordinates"] - .get() - .values; - for(auto gleg: geom) { + .values["geometry"] + .get() + .values["coordinates"] + .get() + .values; + for (auto gleg : geom) + { auto p = gleg.get().values; auto lon = p[0].get().value; auto lat = p[1].get().value; @@ -687,38 +686,30 @@ LonLatVector check_route_annotated_ways( } } } - auto annotations = leg.get() - .values["annotation"] - .get() - .values; + auto annotations = leg.get().values["annotation"].get().values; BOOST_CHECK_EQUAL(annotations.size(), 2); - auto nodes = annotations["nodes"] - .get() - .values; - auto ways = annotations["ways"] - .get() - .values; + auto nodes = annotations["nodes"].get().values; + auto ways = annotations["ways"].get().values; BOOST_CHECK_GT(nodes.size(), 1); BOOST_CHECK_EQUAL(nodes.size() - 1, ways.size()); auto nodes_it = nodes.cbegin(); auto ways_it = ways.cbegin(); osmium::unsigned_object_id_type first = nodes_it->get().value; - for(nodes_it++; nodes_it != nodes.cend(); nodes_it++, ways_it++) { + for (nodes_it++; nodes_it != nodes.cend(); nodes_it++, ways_it++) + { osmium::unsigned_object_id_type second = nodes_it->get().value; osmium::unsigned_object_id_type way_id = ways_it->get().value; auto found = node_pair_to_way_id_map.find(NodePair(first, second)); - if( found == node_pair_to_way_id_map.end() ) + if (found == node_pair_to_way_id_map.end()) found = node_pair_to_way_id_map.find(NodePair(second, first)); - BOOST_CHECK_MESSAGE( - found != node_pair_to_way_id_map.end(), - "The node pair not found: " << first << "<->" << second - ); - BOOST_CHECK_MESSAGE( - found->second == way_id, - "The node pair way doesn't correspond: " << first << "<->" << second << "=" << found->second << "=?=" << way_id - ); + BOOST_CHECK_MESSAGE(found != node_pair_to_way_id_map.end(), + "The node pair not found: " << first << "<->" << second); + BOOST_CHECK_MESSAGE(found->second == way_id, + "The node pair way doesn't correspond: " << first << "<->" << second + << "=" << found->second + << "=?=" << way_id); first = second; } } @@ -737,21 +728,22 @@ BOOST_AUTO_TEST_CASE(test_route_annotated_ways) BOOST_TEST_MESSAGE("split_trace_locations with steps"); check_route_annotated_ways(coordinates, osrm, node_pair_to_way_id_map, true); coordinates = get_locations_in_big_component(); - // auto coords = + // auto coords = BOOST_TEST_MESSAGE("locations_in_big_component without steps"); check_route_annotated_ways(coordinates, osrm, node_pair_to_way_id_map, false); BOOST_TEST_MESSAGE("locations_in_big_component with steps"); auto coords = check_route_annotated_ways(coordinates, osrm, node_pair_to_way_id_map, true); auto c1 = coords.cbegin(), c2 = coords.cend(); - for( c1++, c2--; c1 != coords.cend() && c2 != coords.cbegin(); c1++, c2--) { - if( c1 == c2 ) + for (c1++, c2--; c1 != coords.cend() && c2 != coords.cbegin(); c1++, c2--) + { + if (c1 == c2) continue; - coordinates = Locations{{Longitude{c1->first},Latitude{c1->second}},{Longitude{c2->first},Latitude{c2->second}}}; - BOOST_TEST_MESSAGE( - "Checking: <" << - osrm::util::toFloating(coordinates[0].lat) << ":" << osrm::util::toFloating(coordinates[0].lon) << "> -> <" << - osrm::util::toFloating(coordinates[1].lat) << ":" << osrm::util::toFloating(coordinates[1].lon) << ">" - ); + coordinates = Locations{{Longitude{c1->first}, Latitude{c1->second}}, + {Longitude{c2->first}, Latitude{c2->second}}}; + BOOST_TEST_MESSAGE("Checking: <" << osrm::util::toFloating(coordinates[0].lat) << ":" + << osrm::util::toFloating(coordinates[0].lon) << "> -> <" + << osrm::util::toFloating(coordinates[1].lat) << ":" + << osrm::util::toFloating(coordinates[1].lon) << ">"); check_route_annotated_ways(coordinates, osrm, node_pair_to_way_id_map, false); check_route_annotated_ways(coordinates, osrm, node_pair_to_way_id_map, true); }