From d391df52ba6b66f1a03e6005417dc53a8f537b3a Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Thu, 21 Jan 2016 13:07:24 +0100 Subject: [PATCH] Be kind to the optimizer, pass coordinates by value (just two ints) --- include/engine/datafacade/datafacade_base.hpp | 6 +- .../engine/datafacade/internal_datafacade.hpp | 6 +- .../engine/datafacade/shared_datafacade.hpp | 100 ++++++++++-------- include/engine/geospatial_query.hpp | 14 +-- include/engine/guidance/segment_list.hpp | 4 +- include/engine/phantom_node.hpp | 6 +- include/engine/plugins/hello_world.hpp | 2 +- include/engine/plugins/plugin_base.hpp | 2 +- include/extractor/edge_based_node.hpp | 4 +- include/util/coordinate_calculation.hpp | 50 ++++----- include/util/debug_geometry.hpp | 19 ++-- include/util/hilbert_value.hpp | 11 +- include/util/rectangle.hpp | 6 +- include/util/static_rtree.hpp | 12 +-- src/engine/douglas_peucker.cpp | 6 +- src/util/coordinate_calculation.cpp | 48 ++++----- src/util/hilbert_value.cpp | 31 +++--- 17 files changed, 165 insertions(+), 162 deletions(-) diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index c4c4c87f4..c7006e4d3 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -74,19 +74,19 @@ template class BaseDataFacade virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0; virtual std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, const float max_distance, const int bearing = 0, const int bearing_range = 180) = 0; virtual std::vector - NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, const unsigned max_results, const int bearing = 0, const int bearing_range = 180) = 0; virtual std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate &input_coordinate, + const util::FixedPointCoordinate input_coordinate, const int bearing = 0, const int bearing_range = 180) = 0; diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index bbe18249a..b78e5c040 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -343,7 +343,7 @@ template class InternalDataFacade final : public BaseDataFacad } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, const float max_distance, const int bearing = 0, const int bearing_range = 180) override final @@ -359,7 +359,7 @@ template class InternalDataFacade final : public BaseDataFacad } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, const unsigned max_results, const int bearing = 0, const int bearing_range = 180) override final @@ -375,7 +375,7 @@ template class InternalDataFacade final : public BaseDataFacad } std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate &input_coordinate, + const util::FixedPointCoordinate input_coordinate, const int bearing = 0, const int bearing_range = 180) override final { diff --git a/include/engine/datafacade/shared_datafacade.hpp b/include/engine/datafacade/shared_datafacade.hpp index 7238bec6c..bbb2accb0 100644 --- a/include/engine/datafacade/shared_datafacade.hpp +++ b/include/engine/datafacade/shared_datafacade.hpp @@ -79,8 +79,8 @@ template class SharedDataFacade final : public BaseDataFacade< void LoadChecksum() { - m_check_sum = - *data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::HSGR_CHECKSUM); + m_check_sum = *data_layout->GetBlockPtr(shared_memory, + storage::SharedDataLayout::HSGR_CHECKSUM); util::SimpleLogger().Write() << "set checksum: " << m_check_sum; } @@ -98,8 +98,8 @@ template class SharedDataFacade final : public BaseDataFacade< { BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree"); - RTreeNode *tree_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::R_SEARCH_TREE); + RTreeNode *tree_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::R_SEARCH_TREE); m_static_rtree.reset(new TimeStampedRTreePair( CURRENT_TIMESTAMP, util::make_unique( @@ -111,11 +111,11 @@ template class SharedDataFacade final : public BaseDataFacade< void LoadGraph() { - GraphNode *graph_nodes_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::GRAPH_NODE_LIST); + GraphNode *graph_nodes_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::GRAPH_NODE_LIST); - GraphEdge *graph_edges_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::GRAPH_EDGE_LIST); + GraphEdge *graph_edges_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::GRAPH_EDGE_LIST); typename util::ShM::vector node_list( graph_nodes_ptr, data_layout->num_entries[storage::SharedDataLayout::GRAPH_NODE_LIST]); @@ -128,10 +128,11 @@ template class SharedDataFacade final : public BaseDataFacade< { util::FixedPointCoordinate *coordinate_list_ptr = - data_layout->GetBlockPtr(shared_memory, - storage::SharedDataLayout::COORDINATE_LIST); + data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::COORDINATE_LIST); m_coordinate_list = util::make_unique::vector>( - coordinate_list_ptr, data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]); + coordinate_list_ptr, + data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]); extractor::TravelMode *travel_mode_list_ptr = data_layout->GetBlockPtr(shared_memory, @@ -148,8 +149,8 @@ template class SharedDataFacade final : public BaseDataFacade< data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]); m_turn_instruction_list.swap(turn_instruction_list); - unsigned *name_id_list_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::NAME_ID_LIST); + unsigned *name_id_list_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::NAME_ID_LIST); typename util::ShM::vector name_id_list( name_id_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_ID_LIST]); m_name_ID_list.swap(name_id_list); @@ -157,8 +158,8 @@ template class SharedDataFacade final : public BaseDataFacade< void LoadViaNodeList() { - NodeID *via_node_list_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::VIA_NODE_LIST); + NodeID *via_node_list_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::VIA_NODE_LIST); typename util::ShM::vector via_node_list( via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]); m_via_node_list.swap(via_node_list); @@ -166,17 +167,17 @@ template class SharedDataFacade final : public BaseDataFacade< void LoadNames() { - unsigned *offsets_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::NAME_OFFSETS); - NameIndexBlock *blocks_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::NAME_BLOCKS); + unsigned *offsets_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::NAME_OFFSETS); + NameIndexBlock *blocks_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::NAME_BLOCKS); typename util::ShM::vector name_offsets( offsets_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_OFFSETS]); typename util::ShM::vector name_blocks( blocks_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_BLOCKS]); - char *names_list_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST); + char *names_list_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST); typename util::ShM::vector names_char_list( names_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_CHAR_LIST]); m_name_table = util::make_unique>( @@ -192,8 +193,8 @@ template class SharedDataFacade final : public BaseDataFacade< return; } - unsigned *core_marker_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::CORE_MARKER); + unsigned *core_marker_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::CORE_MARKER); typename util::ShM::vector is_core_node( core_marker_ptr, data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER]); m_is_core_node.swap(is_core_node); @@ -208,16 +209,18 @@ template class SharedDataFacade final : public BaseDataFacade< data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDICATORS]); m_edge_is_compressed.swap(edge_is_compressed); - unsigned *geometries_index_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX); + unsigned *geometries_index_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX); typename util::ShM::vector geometry_begin_indices( - geometries_index_ptr, data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]); + geometries_index_ptr, + data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]); m_geometry_indices.swap(geometry_begin_indices); - unsigned *geometries_list_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST); + unsigned *geometries_list_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST); typename util::ShM::vector geometry_list( - geometries_list_ptr, data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]); + geometries_list_ptr, + data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]); m_geometry_list.swap(geometry_list); } @@ -230,12 +233,12 @@ template class SharedDataFacade final : public BaseDataFacade< { if (!storage::SharedMemory::RegionExists(storage::CURRENT_REGIONS)) { - throw util::exception("No shared memory blocks found, have you forgotten to run osrm-datastore?"); + throw util::exception( + "No shared memory blocks found, have you forgotten to run osrm-datastore?"); } data_timestamp_ptr = static_cast( storage::makeSharedMemory(storage::CURRENT_REGIONS, - sizeof(storage::SharedDataTimestamp), false, false) - ->Ptr()); + sizeof(storage::SharedDataTimestamp), false, false)->Ptr()); CURRENT_LAYOUT = storage::LAYOUT_NONE; CURRENT_DATA = storage::DATA_NONE; CURRENT_TIMESTAMP = 0; @@ -263,14 +266,15 @@ template class SharedDataFacade final : public BaseDataFacade< CURRENT_LAYOUT = data_timestamp_ptr->layout; CURRENT_DATA = data_timestamp_ptr->data; - CURRENT_TIMESTAMP = 0; // Force trigger a reload + CURRENT_TIMESTAMP = 0; // Force trigger a reload - util::SimpleLogger().Write(logDEBUG) << "Current layout was different to new layout, swapping"; + util::SimpleLogger().Write(logDEBUG) + << "Current layout was different to new layout, swapping"; } else { - util::SimpleLogger().Write(logDEBUG) << "Current layout was same to new layout, not swapping"; - + util::SimpleLogger().Write(logDEBUG) + << "Current layout was same to new layout, not swapping"; } if (CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) @@ -280,19 +284,20 @@ template class SharedDataFacade final : public BaseDataFacade< util::SimpleLogger().Write(logDEBUG) << "Performing data reload"; m_layout_memory.reset(storage::makeSharedMemory(CURRENT_LAYOUT)); - data_layout = (storage::SharedDataLayout *) (m_layout_memory->Ptr()); + data_layout = (storage::SharedDataLayout *)(m_layout_memory->Ptr()); m_large_memory.reset(storage::makeSharedMemory(CURRENT_DATA)); - shared_memory = (char *) (m_large_memory->Ptr()); + shared_memory = (char *)(m_large_memory->Ptr()); - const char *file_index_ptr = - data_layout->GetBlockPtr(shared_memory, storage::SharedDataLayout::FILE_INDEX_PATH); + const char *file_index_ptr = data_layout->GetBlockPtr( + shared_memory, storage::SharedDataLayout::FILE_INDEX_PATH); file_index_path = boost::filesystem::path(file_index_ptr); - if (!boost::filesystem::exists(file_index_path)) { + if (!boost::filesystem::exists(file_index_path)) + { util::SimpleLogger().Write(logDEBUG) << "Leaf file name " - << file_index_path.string(); + << file_index_path.string(); throw util::exception("Could not load leaf index file. " - "Is any data loaded into shared memory?"); + "Is any data loaded into shared memory?"); } LoadGraph(); @@ -304,7 +309,8 @@ template class SharedDataFacade final : public BaseDataFacade< LoadNames(); LoadCoreInformation(); - util::SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size(); + util::SimpleLogger().Write() + << "number of geometries: " << m_coordinate_list->size(); for (unsigned i = 0; i < m_coordinate_list->size(); ++i) { if (!GetCoordinateOfNode(i).IsValid()) @@ -398,7 +404,7 @@ template class SharedDataFacade final : public BaseDataFacade< } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, const float max_distance, const int bearing = 0, const int bearing_range = 180) override final @@ -414,7 +420,7 @@ template class SharedDataFacade final : public BaseDataFacade< } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, const unsigned max_results, const int bearing = 0, const int bearing_range = 180) override final @@ -430,7 +436,7 @@ template class SharedDataFacade final : public BaseDataFacade< } std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate &input_coordinate, + const util::FixedPointCoordinate input_coordinate, const int bearing = 0, const int bearing_range = 180) override final { diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 11b0db648..1aad5388b 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -35,7 +35,7 @@ template class GeospatialQuery // Returns nearest PhantomNodes in the given bearing range within max_distance. // Does not filter by small/big component! std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, const double max_distance, const int bearing = 0, const int bearing_range = 180) @@ -57,7 +57,7 @@ template class GeospatialQuery // Returns max_results nearest PhantomNodes in the given bearing range. // Does not filter by small/big component! std::vector - NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate, + NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, const unsigned max_results, const int bearing = 0, const int bearing_range = 180) @@ -78,7 +78,7 @@ template class GeospatialQuery // Returns the nearest phantom node. If this phantom node is not from a big component // a second phantom node is return that is the nearest coordinate in a big component. std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate &input_coordinate, + const util::FixedPointCoordinate input_coordinate, const int bearing = 0, const int bearing_range = 180) { @@ -86,8 +86,8 @@ template class GeospatialQuery bool has_big_component = false; auto results = rtree.Nearest( input_coordinate, - [this, bearing, bearing_range, &has_big_component, - &has_small_component](const EdgeData &data) + [this, bearing, bearing_range, &has_big_component, &has_small_component]( + const EdgeData &data) { auto use_segment = (!has_small_component || (!has_big_component && !data.component.is_tiny)); @@ -122,7 +122,7 @@ template class GeospatialQuery private: std::vector - MakePhantomNodes(const util::FixedPointCoordinate &input_coordinate, + MakePhantomNodes(const util::FixedPointCoordinate input_coordinate, const std::vector &results) const { std::vector distance_and_phantoms(results.size()); @@ -134,7 +134,7 @@ template class GeospatialQuery return distance_and_phantoms; } - PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate &input_coordinate, + PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate input_coordinate, const EdgeData &data) const { util::FixedPointCoordinate point_on_segment; diff --git a/include/engine/guidance/segment_list.hpp b/include/engine/guidance/segment_list.hpp index 07c932de1..011b31d8a 100644 --- a/include/engine/guidance/segment_list.hpp +++ b/include/engine/guidance/segment_list.hpp @@ -51,7 +51,7 @@ template class SegmentList const bool is_via_leg, const DataFacade *facade); - void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &path_point); + void AppendSegment(const FixedPointCoordinate coordinate, const PathData &path_point); void Finalize(const bool extract_alternative, const InternalRouteResult &raw_route, const unsigned zoom_level, @@ -192,7 +192,7 @@ std::vector const &SegmentList::Get() const } template -void SegmentList::AppendSegment(const FixedPointCoordinate &coordinate, +void SegmentList::AppendSegment(const FixedPointCoordinate coordinate, const PathData &path_point) { // if the start location is on top of a node, the first movement might be zero-length, diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index ca9b685c2..3cb43c019 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -27,7 +27,7 @@ struct PhantomNode unsigned packed_geometry_id, bool is_tiny_component, unsigned component_id, - util::FixedPointCoordinate &location, + util::FixedPointCoordinate location, unsigned short fwd_segment_position, extractor::TravelMode forward_travel_mode, extractor::TravelMode backward_travel_mode) @@ -35,7 +35,7 @@ struct PhantomNode forward_weight(forward_weight), reverse_weight(reverse_weight), forward_offset(forward_offset), reverse_offset(reverse_offset), packed_geometry_id(packed_geometry_id), component{component_id, is_tiny_component}, - location(location), fwd_segment_position(fwd_segment_position), + location(std::move(location)), fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) { } @@ -89,7 +89,7 @@ struct PhantomNode bool operator==(const PhantomNode &other) const { return location == other.location; } template - PhantomNode(const OtherT &other, const util::FixedPointCoordinate &foot_point) + PhantomNode(const OtherT &other, const util::FixedPointCoordinate foot_point) { forward_node_id = other.forward_edge_based_node_id; reverse_node_id = other.reverse_edge_based_node_id; diff --git a/include/engine/plugins/hello_world.hpp b/include/engine/plugins/hello_world.hpp index 1b79ca3e2..312b6e5d6 100644 --- a/include/engine/plugins/hello_world.hpp +++ b/include/engine/plugins/hello_world.hpp @@ -50,7 +50,7 @@ class HelloWorldPlugin final : public BasePlugin util::json::Array json_locations; unsigned counter = 0; - for (const util::FixedPointCoordinate &coordinate : routeParameters.coordinates) + for (const auto coordinate : routeParameters.coordinates) { util::json::Object json_location; util::json::Array json_coordinates; diff --git a/include/engine/plugins/plugin_base.hpp b/include/engine/plugins/plugin_base.hpp index 3f3e62719..0eb36e948 100644 --- a/include/engine/plugins/plugin_base.hpp +++ b/include/engine/plugins/plugin_base.hpp @@ -38,7 +38,7 @@ class BasePlugin const unsigned min = 2) const final { if (min > coordinates.size() || std::any_of(std::begin(coordinates), std::end(coordinates), - [](const util::FixedPointCoordinate &coordinate) + [](const util::FixedPointCoordinate coordinate) { return !coordinate.IsValid(); })) diff --git a/include/extractor/edge_based_node.hpp b/include/extractor/edge_based_node.hpp index c41c3b8e3..4c821d275 100644 --- a/include/extractor/edge_based_node.hpp +++ b/include/extractor/edge_based_node.hpp @@ -58,8 +58,8 @@ struct EdgeBasedNode (reverse_edge_based_node_id != SPECIAL_NODEID)); } - static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate &a, - const util::FixedPointCoordinate &b) + static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate a, + const util::FixedPointCoordinate b) { util::FixedPointCoordinate centroid; // The coordinates of the midpoint are given by: diff --git a/include/util/coordinate_calculation.hpp b/include/util/coordinate_calculation.hpp index decef8d64..ea80f8d6b 100644 --- a/include/util/coordinate_calculation.hpp +++ b/include/util/coordinate_calculation.hpp @@ -1,6 +1,8 @@ #ifndef COORDINATE_CALCULATION #define COORDINATE_CALCULATION +#include "osrm/coordinate.hpp" + #include #include @@ -14,54 +16,52 @@ const constexpr long double RAD = 0.017453292519943295769236907684886; // The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles) const constexpr long double EARTH_RADIUS = 6372797.560856; -struct FixedPointCoordinate; - namespace coordinate_calculation { double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2); -double haversineDistance(const FixedPointCoordinate &first_coordinate, - const FixedPointCoordinate &second_coordinate); +double haversineDistance(const FixedPointCoordinate first_coordinate, + const FixedPointCoordinate second_coordinate); -double greatCircleDistance(const FixedPointCoordinate &first_coordinate, - const FixedPointCoordinate &second_coordinate); +double greatCircleDistance(const FixedPointCoordinate first_coordinate, + const FixedPointCoordinate second_coordinate); double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2); -double perpendicularDistance(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location); +double perpendicularDistance(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location); -double perpendicularDistance(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, +double perpendicularDistance(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location, FixedPointCoordinate &nearest_location, double &ratio); double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate); +perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location, + const std::pair projected_coordinate); double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate, +perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location, + const std::pair projected_coordinate, FixedPointCoordinate &nearest_location, double &ratio); double degToRad(const double degree); double radToDeg(const double radian); -double bearing(const FixedPointCoordinate &first_coordinate, - const FixedPointCoordinate &second_coordinate); +double bearing(const FixedPointCoordinate first_coordinate, + const FixedPointCoordinate second_coordinate); // Get angle of line segment (A,C)->(C,B) -double computeAngle(const FixedPointCoordinate &first, - const FixedPointCoordinate &second, - const FixedPointCoordinate &third); +double computeAngle(const FixedPointCoordinate first, + const FixedPointCoordinate second, + const FixedPointCoordinate third); } } } diff --git a/include/util/debug_geometry.hpp b/include/util/debug_geometry.hpp index 73e829175..be9da638d 100644 --- a/include/util/debug_geometry.hpp +++ b/include/util/debug_geometry.hpp @@ -3,6 +3,7 @@ #include "contractor/contractor_config.hpp" #include "extractor/query_node.hpp" +#include "osrm/coordinate.hpp" #ifndef DEBUG_GEOMETRY @@ -23,7 +24,7 @@ inline void DEBUG_GEOMETRY_STOP() {} inline void DEBUG_TURNS_START(const std::string & /* debug_turns_filename */) {} inline void DEBUG_TURN(const NodeID /* node */, const std::vector & /* m_node_info_list */, - const FixedPointCoordinate & /* first_coordinate */, + const FixedPointCoordinate /* first_coordinate */, const int /* turn_angle */, const int /* turn_penalty */) { @@ -95,11 +96,9 @@ inline void DEBUG_GEOMETRY_EDGE(int new_segment_weight, if (!dg_first_debug_geometry) debug_geometry_file << "," << std::endl; debug_geometry_file << "{ \"type\":\"Feature\",\"properties\":{\"original\":false, " - "\"weight\":" - << new_segment_weight / 10.0 << ",\"speed\":" - << static_cast( - std::floor((segment_length / new_segment_weight) * 10. * 3.6)) - << ","; + "\"weight\":" << new_segment_weight / 10.0 << ",\"speed\":" + << static_cast(std::floor((segment_length / new_segment_weight) * + 10. * 3.6)) << ","; debug_geometry_file << "\"from_node\": " << previous_osm_node_id << ", \"to_node\": " << this_osm_node_id << ","; debug_geometry_file << "\"timestamp\": \"" << dg_time_buffer << "\"},"; @@ -114,7 +113,8 @@ inline void DEBUG_GEOMETRY_STOP() { if (dg_output_debug_geometry) { - debug_geometry_file << std::endl << "]}" << std::endl; + debug_geometry_file << std::endl + << "]}" << std::endl; debug_geometry_file.close(); } } @@ -169,7 +169,7 @@ inline void DEBUG_UTURN(const NodeID node, inline void DEBUG_TURN(const NodeID node, const std::vector &m_node_info_list, - const FixedPointCoordinate &first_coordinate, + const FixedPointCoordinate first_coordinate, const int turn_angle, const int turn_penalty) { @@ -201,7 +201,8 @@ inline void DEBUG_TURNS_STOP() { if (dg_output_turn_debug) { - dg_debug_turns_file << std::endl << "]}" << std::endl; + dg_debug_turns_file << std::endl + << "]}" << std::endl; dg_debug_turns_file.close(); } } diff --git a/include/util/hilbert_value.hpp b/include/util/hilbert_value.hpp index 641782e85..858260278 100644 --- a/include/util/hilbert_value.hpp +++ b/include/util/hilbert_value.hpp @@ -1,6 +1,8 @@ #ifndef HILBERT_VALUE_HPP #define HILBERT_VALUE_HPP +#include "osrm/coordinate.hpp" + #include namespace osrm @@ -9,19 +11,16 @@ namespace util { // computes a 64 bit value that corresponds to the hilbert space filling curve - -struct FixedPointCoordinate; - class HilbertCode { public: - uint64_t operator()(const FixedPointCoordinate ¤t_coordinate) const; + std::uint64_t operator()(const FixedPointCoordinate current_coordinate) const; HilbertCode() {} HilbertCode(const HilbertCode &) = delete; private: - inline uint64_t BitInterleaving(const uint32_t a, const uint32_t b) const; - inline void TransposeCoordinate(uint32_t *X) const; + inline std::uint64_t BitInterleaving(const std::uint32_t a, const std::uint32_t b) const; + inline void TransposeCoordinate(std::uint32_t *x) const; }; } } diff --git a/include/util/rectangle.hpp b/include/util/rectangle.hpp index 947f438f0..80aa98cfd 100644 --- a/include/util/rectangle.hpp +++ b/include/util/rectangle.hpp @@ -62,7 +62,7 @@ struct RectangleInt2D Contains(lower_left)); } - double GetMinDist(const FixedPointCoordinate &location) const + double GetMinDist(const FixedPointCoordinate location) const { const bool is_contained = Contains(location); if (is_contained) @@ -139,7 +139,7 @@ struct RectangleInt2D return min_dist; } - double GetMinMaxDist(const FixedPointCoordinate &location) const + double GetMinMaxDist(const FixedPointCoordinate location) const { double min_max_dist = std::numeric_limits::max(); // Get minmax distance to each of the four sides @@ -170,7 +170,7 @@ struct RectangleInt2D return min_max_dist; } - bool Contains(const FixedPointCoordinate &location) const + bool Contains(const FixedPointCoordinate location) const { const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat); const bool lons_contained = (location.lon >= min_lon) && (location.lon <= max_lon); diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index 3aea17943..616300c12 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -124,8 +124,8 @@ class StaticRTree // generate auxiliary vector of hilbert-values tbb::parallel_for( tbb::blocked_range(0, m_element_count), - [&input_data_vector, &input_wrapper_vector, &get_hilbert_number, - &coordinate_list](const tbb::blocked_range &range) + [&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list]( + const tbb::blocked_range &range) { for (uint64_t element_counter = range.begin(), end = range.end(); element_counter != end; ++element_counter) @@ -322,7 +322,7 @@ class StaticRTree } // Override filter and terminator for the desired behaviour. - std::vector Nearest(const FixedPointCoordinate &input_coordinate, + std::vector Nearest(const FixedPointCoordinate input_coordinate, const std::size_t max_results) { return Nearest(input_coordinate, @@ -338,7 +338,7 @@ class StaticRTree // Override filter and terminator for the desired behaviour. template - std::vector Nearest(const FixedPointCoordinate &input_coordinate, + std::vector Nearest(const FixedPointCoordinate input_coordinate, const FilterT filter, const TerminationT terminate) { @@ -407,7 +407,7 @@ class StaticRTree private: template void ExploreLeafNode(const std::uint32_t leaf_id, - const FixedPointCoordinate &input_coordinate, + const FixedPointCoordinate input_coordinate, const std::pair &projected_coordinate, QueueT &traversal_queue) { @@ -432,7 +432,7 @@ class StaticRTree template void ExploreTreeNode(const TreeNode &parent, - const FixedPointCoordinate &input_coordinate, + const FixedPointCoordinate input_coordinate, QueueT &traversal_queue) { for (uint32_t i = 0; i < parent.child_count; ++i) diff --git a/src/engine/douglas_peucker.cpp b/src/engine/douglas_peucker.cpp index 67760bc1c..be3572306 100644 --- a/src/engine/douglas_peucker.cpp +++ b/src/engine/douglas_peucker.cpp @@ -20,8 +20,8 @@ namespace struct CoordinatePairCalculator { CoordinatePairCalculator() = delete; - CoordinatePairCalculator(const util::FixedPointCoordinate &coordinate_a, - const util::FixedPointCoordinate &coordinate_b) + CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a, + const util::FixedPointCoordinate coordinate_b) { // initialize distance calculator with two fixed coordinates a, b first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD; @@ -30,7 +30,7 @@ struct CoordinatePairCalculator second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD; } - int operator()(util::FixedPointCoordinate &other) const + int operator()(const util::FixedPointCoordinate other) const { // set third coordinate c const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD; diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index f2d99ed4f..e0dfe006a 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -6,8 +6,6 @@ #include -#include "osrm/coordinate.hpp" - #include #include @@ -44,15 +42,15 @@ double haversineDistance(const int lat1, const int lon1, const int lat2, const i return EARTH_RADIUS * charv; } -double haversineDistance(const FixedPointCoordinate &coordinate_1, - const FixedPointCoordinate &coordinate_2) +double haversineDistance(const FixedPointCoordinate coordinate_1, + const FixedPointCoordinate coordinate_2) { return haversineDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); } -double greatCircleDistance(const FixedPointCoordinate &coordinate_1, - const FixedPointCoordinate &coordinate_2) +double greatCircleDistance(const FixedPointCoordinate coordinate_1, + const FixedPointCoordinate coordinate_2) { return greatCircleDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); @@ -75,9 +73,9 @@ double greatCircleDistance(const int lat1, const int lon1, const int lat2, const return std::hypot(x_value, y_value) * EARTH_RADIUS; } -double perpendicularDistance(const FixedPointCoordinate &source_coordinate, - const FixedPointCoordinate &target_coordinate, - const FixedPointCoordinate &query_location) +double perpendicularDistance(const FixedPointCoordinate source_coordinate, + const FixedPointCoordinate target_coordinate, + const FixedPointCoordinate query_location) { double ratio; FixedPointCoordinate nearest_location; @@ -86,9 +84,9 @@ double perpendicularDistance(const FixedPointCoordinate &source_coordinate, nearest_location, ratio); } -double perpendicularDistance(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, +double perpendicularDistance(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location, FixedPointCoordinate &nearest_location, double &ratio) { @@ -100,10 +98,10 @@ double perpendicularDistance(const FixedPointCoordinate &segment_source, } double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &source_coordinate, - const FixedPointCoordinate &target_coordinate, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate) +perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate source_coordinate, + const FixedPointCoordinate target_coordinate, + const FixedPointCoordinate query_location, + const std::pair projected_coordinate) { double ratio; FixedPointCoordinate nearest_location; @@ -114,10 +112,10 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &source_ } double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate, +perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, + const FixedPointCoordinate segment_target, + const FixedPointCoordinate query_location, + const std::pair projected_coordinate, FixedPointCoordinate &nearest_location, double &ratio) { @@ -196,8 +194,8 @@ double degToRad(const double degree) { return degree * (static_cast(M_PI double radToDeg(const double radian) { return radian * (180.0 * static_cast(M_1_PI)); } -double bearing(const FixedPointCoordinate &first_coordinate, - const FixedPointCoordinate &second_coordinate) +double bearing(const FixedPointCoordinate first_coordinate, + const FixedPointCoordinate second_coordinate) { const double lon_diff = second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION; @@ -220,9 +218,9 @@ double bearing(const FixedPointCoordinate &first_coordinate, return result; } -double computeAngle(const FixedPointCoordinate &first, - const FixedPointCoordinate &second, - const FixedPointCoordinate &third) +double computeAngle(const FixedPointCoordinate first, + const FixedPointCoordinate second, + const FixedPointCoordinate third) { const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION; const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) - diff --git a/src/util/hilbert_value.cpp b/src/util/hilbert_value.cpp index 5ddfce0b4..a7d23eef0 100644 --- a/src/util/hilbert_value.cpp +++ b/src/util/hilbert_value.cpp @@ -1,13 +1,11 @@ #include "util/hilbert_value.hpp" -#include "osrm/coordinate.hpp" - namespace osrm { namespace util { -uint64_t HilbertCode::operator()(const FixedPointCoordinate ¤t_coordinate) const +std::uint64_t HilbertCode::operator()(const FixedPointCoordinate current_coordinate) const { unsigned location[2]; location[0] = current_coordinate.lat + static_cast(90 * COORDINATE_PRECISION); @@ -17,10 +15,11 @@ uint64_t HilbertCode::operator()(const FixedPointCoordinate ¤t_coordinate) return BitInterleaving(location[0], location[1]); } -uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t longitude) const +std::uint64_t HilbertCode::BitInterleaving(const std::uint32_t latitude, + const std::uint32_t longitude) const { - uint64_t result = 0; - for (int8_t index = 31; index >= 0; --index) + std::uint64_t result = 0; + for (std::int8_t index = 31; index >= 0; --index) { result |= (latitude >> index) & 1; result <<= 1; @@ -33,9 +32,9 @@ uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t lo return result; } -void HilbertCode::TransposeCoordinate(uint32_t *X) const +void HilbertCode::TransposeCoordinate(std::uint32_t *x) const { - uint32_t M = 1u << (32 - 1), P, Q, t; + std::uint32_t M = 1u << (32 - 1), P, Q, t; int i; // Inverse undo for (Q = M; Q > 1; Q >>= 1) @@ -44,28 +43,28 @@ void HilbertCode::TransposeCoordinate(uint32_t *X) const for (i = 0; i < 2; ++i) { - const bool condition = (X[i] & Q); + const bool condition = (x[i] & Q); if (condition) { - X[0] ^= P; // invert + x[0] ^= P; // invert } else { - t = (X[0] ^ X[i]) & P; - X[0] ^= t; - X[i] ^= t; + t = (x[0] ^ x[i]) & P; + x[0] ^= t; + x[i] ^= t; } } // exchange } // Gray encode for (i = 1; i < 2; ++i) { - X[i] ^= X[i - 1]; + x[i] ^= x[i - 1]; } t = 0; for (Q = M; Q > 1; Q >>= 1) { - const bool condition = (X[2 - 1] & Q); + const bool condition = (x[2 - 1] & Q); if (condition) { t ^= Q - 1; @@ -73,7 +72,7 @@ void HilbertCode::TransposeCoordinate(uint32_t *X) const } // check if this for loop is wrong for (i = 0; i < 2; ++i) { - X[i] ^= t; + x[i] ^= t; } } }