diff --git a/example/example.cpp b/example/example.cpp index 37c39cfe3..7815aaaa5 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -52,10 +52,8 @@ int main(int argc, const char *argv[]) try // Route is in Berlin. Latitude, Longitude // TODO(daniel-j-h): use either coordinate_precision or better provide double,double-taking ctor - params.coordinates.push_back({static_cast(43.731142 * osrm::COORDINATE_PRECISION), - static_cast(7.419758 * osrm::COORDINATE_PRECISION)}); - params.coordinates.push_back({static_cast(43.736825 * osrm::COORDINATE_PRECISION), - static_cast(7.419505 * osrm::COORDINATE_PRECISION)}); + params.coordinates.push_back({osrm::util::FloatLongitude(7.419758), osrm::util::FloatLatitude(43.731142)}); + params.coordinates.push_back({osrm::util::FloatLongitude(7.419505), osrm::util::FloatLatitude(43.736825)}); // Response is in JSON format osrm::json::Object result; diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index 14db568a1..904c56478 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -26,8 +26,7 @@ class BaseAPI { } - util::json::Array - MakeWaypoints(const std::vector &segment_end_coordinates) const + util::json::Array MakeWaypoints(const std::vector &segment_end_coordinates) const { BOOST_ASSERT(parameters.coordinates.size() > 0); BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); @@ -47,8 +46,8 @@ class BaseAPI } protected: - util::json::Object MakeWaypoint(const util::FixedPointCoordinate input_coordinate, - const PhantomNode &phantom) const + util::json::Object MakeWaypoint(const util::Coordinate input_coordinate, + const PhantomNode &phantom) const { return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id), Hint{input_coordinate, phantom, facade.GetCheckSum()}); diff --git a/include/engine/api/base_parameters.hpp b/include/engine/api/base_parameters.hpp index 04865be77..2798c398e 100644 --- a/include/engine/api/base_parameters.hpp +++ b/include/engine/api/base_parameters.hpp @@ -23,7 +23,7 @@ struct BaseParameters short range; }; - std::vector coordinates; + std::vector coordinates; std::vector> hints; std::vector> radiuses; std::vector> bearings; diff --git a/include/engine/api/json_factory.hpp b/include/engine/api/json_factory.hpp index 586ba3989..bbf60603a 100644 --- a/include/engine/api/json_factory.hpp +++ b/include/engine/api/json_factory.hpp @@ -38,7 +38,7 @@ namespace detail std::string instructionToString(extractor::TurnInstruction instruction); -util::json::Array coordinateToLonLat(const FixedPointCoordinate &coordinate); +util::json::Array coordinateToLonLat(const util::Coordinate &coordinate); std::string modeToString(const extractor::TravelMode mode); @@ -58,7 +58,7 @@ util::json::Object makeGeoJSONLineString(ForwardIter begin, ForwardIter end) geojson.values["type"] = "LineString"; util::json::Array coordinates; std::transform(begin, end, std::back_inserter(coordinates.values), - [](const util::FixedPointCoordinate loc) + [](const util::Coordinate loc) { return detail::coordinateToLonLat(loc); }); @@ -76,7 +76,7 @@ util::json::Object makeRoute(const guidance::Route &route, boost::optional geometry); util::json::Object -makeWaypoint(const FixedPointCoordinate location, std::string &&name, const Hint &hint); +makeWaypoint(const util::Coordinate location, std::string &&name, const Hint &hint); util::json::Object makeRouteLeg(guidance::RouteLeg &&leg, util::json::Array &&steps); diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 592a5079d..1dc2e77cd 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -64,7 +64,7 @@ class BaseDataFacade FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0; // node and edge information access - virtual util::FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const = 0; + virtual util::Coordinate GetCoordinateOfNode(const unsigned id) const = 0; virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0; @@ -80,49 +80,48 @@ class BaseDataFacade virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0; - virtual std::vector GetEdgesInBox(const util::FixedPointCoordinate &south_west, - const util::FixedPointCoordinate &north_east) = 0; + virtual std::vector GetEdgesInBox(const util::Coordinate south_west, + const util::Coordinate north_east) = 0; virtual std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance, const int bearing, const int bearing_range) = 0; virtual std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance) = 0; virtual std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance, const int bearing, const int bearing_range) = 0; virtual std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const int bearing, const int bearing_range) = 0; virtual std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, - const unsigned max_results) = 0; + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results) = 0; virtual std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, - const unsigned max_results, const double max_distance) = 0; + NearestPhantomNodes(const util::Coordinate input_coordinate, + const unsigned max_results, + const double max_distance) = 0; + virtual std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate) = 0; + virtual std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance) = 0; + virtual std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance, + const int bearing, + const int bearing_range) = 0; virtual std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate) = 0; - virtual std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, const double max_distance) = 0; - virtual std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const double max_distance, - const int bearing, - const int bearing_range) = 0; - virtual std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const int bearing, - const int bearing_range) = 0; + const util::Coordinate input_coordinate, const int bearing, const int bearing_range) = 0; virtual unsigned GetCheckSum() const = 0; diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index e79c708e4..02784fc2e 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -55,7 +55,7 @@ class InternalDataFacade final : public BaseDataFacade using InputEdge = typename QueryGraph::InputEdge; using RTreeLeaf = typename super::RTreeLeaf; using InternalRTree = - util::StaticRTree::vector, false>; + util::StaticRTree::vector, false>; using InternalGeospatialQuery = GeospatialQuery; InternalDataFacade() {} @@ -65,7 +65,7 @@ class InternalDataFacade final : public BaseDataFacade std::unique_ptr m_query_graph; std::string m_timestamp; - std::shared_ptr::vector> m_coordinate_list; + std::shared_ptr::vector> m_coordinate_list; util::ShM::vector m_via_node_list; util::ShM::vector m_name_ID_list; util::ShM::vector m_turn_instruction_list; @@ -132,15 +132,12 @@ class InternalDataFacade final : public BaseDataFacade extractor::QueryNode current_node; unsigned number_of_coordinates = 0; nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned)); - m_coordinate_list = - std::make_shared>(number_of_coordinates); + m_coordinate_list = std::make_shared>(number_of_coordinates); for (unsigned i = 0; i < number_of_coordinates; ++i) { nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode)); - m_coordinate_list->at(i) = - util::FixedPointCoordinate(current_node.lat, current_node.lon); - BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0); - BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0); + m_coordinate_list->at(i) = util::Coordinate(current_node.lon, current_node.lat); + BOOST_ASSERT(m_coordinate_list->at(i).IsValid()); } boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); @@ -325,7 +322,7 @@ class InternalDataFacade final : public BaseDataFacade } // node and edge information access - util::FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const override final + util::Coordinate GetCoordinateOfNode(const unsigned id) const override final { return m_coordinate_list->at(id); } @@ -340,22 +337,21 @@ class InternalDataFacade final : public BaseDataFacade return m_travel_mode_list.at(id); } - std::vector - GetEdgesInBox(const util::FixedPointCoordinate &south_west, - const util::FixedPointCoordinate &north_east) override final + std::vector GetEdgesInBox(const util::Coordinate south_west, + const util::Coordinate north_east) override final { if (!m_static_rtree.get()) { LoadRTree(); BOOST_ASSERT(m_geospatial_query.get()); } - const util::RectangleInt2D bbox{ - south_west.lon, north_east.lon, south_west.lat, north_east.lat}; + const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat, + north_east.lat}; return m_geospatial_query->Search(bbox); } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance) override final { if (!m_static_rtree.get()) @@ -368,7 +364,7 @@ class InternalDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance, const int bearing, const int bearing_range) override final @@ -384,7 +380,7 @@ class InternalDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results) override final { if (!m_static_rtree.get()) @@ -397,7 +393,7 @@ class InternalDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance) override final { @@ -411,7 +407,7 @@ class InternalDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const int bearing, const int bearing_range) override final @@ -427,7 +423,7 @@ class InternalDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance, const int bearing, @@ -443,8 +439,9 @@ class InternalDataFacade final : public BaseDataFacade bearing, bearing_range); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, const double max_distance) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance) override final { if (!m_static_rtree.get()) { @@ -457,7 +454,7 @@ class InternalDataFacade final : public BaseDataFacade } std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate) override final + const util::Coordinate input_coordinate) override final { if (!m_static_rtree.get()) { @@ -469,11 +466,11 @@ class InternalDataFacade final : public BaseDataFacade input_coordinate); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const double max_distance, - const int bearing, - const int bearing_range) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance, + const int bearing, + const int bearing_range) override final { if (!m_static_rtree.get()) { @@ -485,10 +482,10 @@ class InternalDataFacade final : public BaseDataFacade input_coordinate, max_distance, bearing, bearing_range); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const int bearing, - const int bearing_range) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const int bearing, + const int bearing_range) override final { if (!m_static_rtree.get()) { diff --git a/include/engine/datafacade/shared_datafacade.hpp b/include/engine/datafacade/shared_datafacade.hpp index 6d3b967b2..74973cd60 100644 --- a/include/engine/datafacade/shared_datafacade.hpp +++ b/include/engine/datafacade/shared_datafacade.hpp @@ -48,7 +48,7 @@ class SharedDataFacade final : public BaseDataFacade using InputEdge = typename QueryGraph::InputEdge; using RTreeLeaf = typename super::RTreeLeaf; using SharedRTree = - util::StaticRTree::vector, true>; + util::StaticRTree::vector, true>; using SharedGeospatialQuery = GeospatialQuery; using TimeStampedRTreePair = std::pair>; using RTreeNode = typename SharedRTree::TreeNode; @@ -67,7 +67,7 @@ class SharedDataFacade final : public BaseDataFacade std::unique_ptr m_large_memory; std::string m_timestamp; - std::shared_ptr::vector> m_coordinate_list; + std::shared_ptr::vector> m_coordinate_list; util::ShM::vector m_via_node_list; util::ShM::vector m_name_ID_list; util::ShM::vector m_turn_instruction_list; @@ -133,9 +133,9 @@ class SharedDataFacade final : public BaseDataFacade void LoadNodeAndEdgeInformation() { - auto coordinate_list_ptr = data_layout->GetBlockPtr( + auto coordinate_list_ptr = data_layout->GetBlockPtr( shared_memory, storage::SharedDataLayout::COORDINATE_LIST); - m_coordinate_list = util::make_unique::vector>( + m_coordinate_list = util::make_unique::vector>( coordinate_list_ptr, data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]); @@ -365,7 +365,7 @@ class SharedDataFacade final : public BaseDataFacade } // node and edge information access - util::FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const override final + util::Coordinate GetCoordinateOfNode(const NodeID id) const override final { return m_coordinate_list->at(id); } @@ -408,22 +408,21 @@ class SharedDataFacade final : public BaseDataFacade return m_travel_mode_list.at(id); } - std::vector - GetEdgesInBox(const util::FixedPointCoordinate &south_west, - const util::FixedPointCoordinate &north_east) override final + std::vector GetEdgesInBox(const util::Coordinate south_west, + const util::Coordinate north_east) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) { LoadRTree(); BOOST_ASSERT(m_geospatial_query.get()); } - const util::RectangleInt2D bbox{ - south_west.lon, north_east.lon, south_west.lat, north_east.lat}; + const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat, + north_east.lat}; return m_geospatial_query->Search(bbox); } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) @@ -436,7 +435,7 @@ class SharedDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const float max_distance, const int bearing, const int bearing_range) override final @@ -452,7 +451,7 @@ class SharedDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) @@ -465,7 +464,7 @@ class SharedDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance) override final { @@ -479,7 +478,7 @@ class SharedDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const int bearing, const int bearing_range) override final @@ -495,7 +494,7 @@ class SharedDataFacade final : public BaseDataFacade } std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance, const int bearing, @@ -512,7 +511,7 @@ class SharedDataFacade final : public BaseDataFacade } std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate) override final + const util::Coordinate input_coordinate) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) { @@ -524,8 +523,9 @@ class SharedDataFacade final : public BaseDataFacade input_coordinate); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, const double max_distance) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) { @@ -537,11 +537,11 @@ class SharedDataFacade final : public BaseDataFacade input_coordinate, max_distance); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const double max_distance, - const int bearing, - const int bearing_range) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance, + const int bearing, + const int bearing_range) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) { @@ -553,10 +553,10 @@ class SharedDataFacade final : public BaseDataFacade input_coordinate, max_distance, bearing, bearing_range); } - std::pair NearestPhantomNodeWithAlternativeFromBigComponent( - const util::FixedPointCoordinate input_coordinate, - const int bearing, - const int bearing_range) override final + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const int bearing, + const int bearing_range) override final { if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) { diff --git a/include/engine/douglas_peucker.hpp b/include/engine/douglas_peucker.hpp index 279a449c4..468c6c76e 100644 --- a/include/engine/douglas_peucker.hpp +++ b/include/engine/douglas_peucker.hpp @@ -44,14 +44,13 @@ const constexpr auto DOUGLAS_PEUCKER_THRESHOLDS_SIZE = // Input is vector of pairs. Each pair consists of the point information and a // bit indicating if the points is present in the generalization. // Note: points may also be pre-selected*/ -std::vector -douglasPeucker(std::vector::const_iterator begin, - std::vector::const_iterator end, - const unsigned zoom_level); +std::vector douglasPeucker(std::vector::const_iterator begin, + std::vector::const_iterator end, + const unsigned zoom_level); // Convenience range-based function -inline std::vector -douglasPeucker(const std::vector &geometry, const unsigned zoom_level) +inline std::vector douglasPeucker(const std::vector &geometry, + const unsigned zoom_level) { return douglasPeucker(begin(geometry), end(geometry), zoom_level); } diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index af5cab038..fb99ad4e0 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -41,16 +41,17 @@ 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, - const double max_distance) + NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance) { - auto results = - rtree.Nearest(input_coordinate, - [] (const EdgeData &) { return std::make_pair(true, true); }, - [max_distance](const std::size_t, const double min_dist) - { - return min_dist > max_distance; - }); + auto results = rtree.Nearest(input_coordinate, + [](const EdgeData &) + { + return std::make_pair(true, true); + }, + [max_distance](const std::size_t, const double min_dist) + { + return min_dist > max_distance; + }); return MakePhantomNodes(input_coordinate, results); } @@ -58,7 +59,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::Coordinate input_coordinate, const double max_distance, const int bearing, const int bearing_range) @@ -80,7 +81,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::Coordinate input_coordinate, const unsigned max_results, const int bearing, const int bearing_range) @@ -98,24 +99,26 @@ template class GeospatialQuery return MakePhantomNodes(input_coordinate, results); } - // Returns max_results nearest PhantomNodes in the given bearing range within the maximum distance. + // Returns max_results nearest PhantomNodes in the given bearing range within the maximum + // distance. // Does not filter by small/big component! std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance, const int bearing, const int bearing_range) { - auto results = rtree.Nearest(input_coordinate, - [this, bearing, bearing_range](const EdgeData &data) - { - return checkSegmentBearing(data, bearing, bearing_range); - }, - [max_results, max_distance](const std::size_t num_results, const double min_dist) - { - return num_results >= max_results || min_dist > max_distance; - }); + auto results = rtree.Nearest( + input_coordinate, + [this, bearing, bearing_range](const EdgeData &data) + { + return checkSegmentBearing(data, bearing, bearing_range); + }, + [max_results, max_distance](const std::size_t num_results, const double min_dist) + { + return num_results >= max_results || min_dist > max_distance; + }); return MakePhantomNodes(input_coordinate, results); } @@ -123,8 +126,7 @@ template class GeospatialQuery // Returns max_results nearest PhantomNodes. // Does not filter by small/big component! std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, - const unsigned max_results) + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results) { auto results = rtree.Nearest(input_coordinate, [](const EdgeData &) @@ -142,27 +144,29 @@ template class GeospatialQuery // Returns max_results nearest PhantomNodes in the given max distance. // Does not filter by small/big component! std::vector - NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, + NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results, const double max_distance) { - auto results = rtree.Nearest(input_coordinate, - [](const EdgeData &) - { - return std::make_pair(true, true); - }, - [max_results, max_distance](const std::size_t num_results, const double min_dist) - { - return num_results >= max_results || min_dist > max_distance; - }); + auto results = rtree.Nearest( + input_coordinate, + [](const EdgeData &) + { + return std::make_pair(true, true); + }, + [max_results, max_distance](const std::size_t num_results, const double min_dist) + { + return num_results >= max_results || min_dist > max_distance; + }); return MakePhantomNodes(input_coordinate, results); } // 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 double max_distance) + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance) { bool has_small_component = false; bool has_big_component = false; @@ -196,8 +200,8 @@ 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) + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate) { bool has_small_component = false; bool has_big_component = false; @@ -232,9 +236,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 int bearing, - const int bearing_range) + const util::Coordinate input_coordinate, const int bearing, const int bearing_range) { bool has_small_component = false; bool has_big_component = false; @@ -276,11 +278,11 @@ 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 double max_distance, - const int bearing, - const int bearing_range) + std::pair + NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, + const double max_distance, + const int bearing, + const int bearing_range) { bool has_small_component = false; bool has_big_component = false; @@ -322,7 +324,7 @@ template class GeospatialQuery private: std::vector - MakePhantomNodes(const util::FixedPointCoordinate input_coordinate, + MakePhantomNodes(const util::Coordinate input_coordinate, const std::vector &results) const { std::vector distance_and_phantoms(results.size()); @@ -334,10 +336,10 @@ template class GeospatialQuery return distance_and_phantoms; } - PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate input_coordinate, + PhantomNodeWithDistance MakePhantomNode(const util::Coordinate input_coordinate, const EdgeData &data) const { - util::FixedPointCoordinate point_on_segment; + util::Coordinate point_on_segment; double ratio; const auto current_perpendicular_distance = util::coordinate_calculation::perpendicularDistance( diff --git a/include/engine/guidance/assemble_overview.hpp b/include/engine/guidance/assemble_overview.hpp index c3bc85230..f801d6c22 100644 --- a/include/engine/guidance/assemble_overview.hpp +++ b/include/engine/guidance/assemble_overview.hpp @@ -3,6 +3,8 @@ #include "engine/guidance/leg_geometry.hpp" +#include "util/coordinate.hpp" + #include namespace osrm @@ -12,8 +14,8 @@ namespace engine namespace guidance { -std::vector -assembleOverview(const std::vector &leg_geometries, const bool use_simplification); +std::vector assembleOverview(const std::vector &leg_geometries, + const bool use_simplification); } // namespace guidance } // namespace engine diff --git a/include/engine/guidance/leg_geometry.hpp b/include/engine/guidance/leg_geometry.hpp index 71aaa5d22..1b2d184d1 100644 --- a/include/engine/guidance/leg_geometry.hpp +++ b/include/engine/guidance/leg_geometry.hpp @@ -23,7 +23,7 @@ namespace guidance // offsets 0 2 n-1 n struct LegGeometry { - std::vector locations; + std::vector locations; // segment_offset[i] .. segment_offset[i+1] (inclusive) // contains the geometry of segment i std::vector segment_offsets; @@ -45,7 +45,6 @@ struct LegGeometry BOOST_ASSERT(segment_offsets.size() > 0); return segment_offsets.size() - 1; } - }; } } diff --git a/include/engine/guidance/step_maneuver.hpp b/include/engine/guidance/step_maneuver.hpp index 6f9c94fd1..f0b9b4135 100644 --- a/include/engine/guidance/step_maneuver.hpp +++ b/include/engine/guidance/step_maneuver.hpp @@ -13,14 +13,12 @@ namespace guidance struct StepManeuver { - util::FixedPointCoordinate location; + util::Coordinate location; double bearing_before; double bearing_after; extractor::TurnInstruction instruction; }; - } } } #endif - diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index 8bd722b30..4ebb320e7 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -4,6 +4,9 @@ #include "engine/object_encoder.hpp" #include "engine/phantom_node.hpp" +#include "util/coordinate.hpp" +#include "phantom_node.hpp" + #include #include @@ -19,15 +22,15 @@ namespace engine // Is returned as a temporary identifier for snapped coodinates struct Hint { - FixedPointCoordinate input_coordinate; + util::Coordinate input_coordinate; PhantomNode phantom; std::uint32_t data_checksum; template - bool IsValid(const FixedPointCoordinate new_input_coordinates, DataFacadeT &facade) const + bool IsValid(const util::Coordinate new_input_coordinates, DataFacadeT &facade) const { - auto is_same_input_coordinate = new_input_coordinates.lat == input_coordinate.lat && - new_input_coordinates.lon == input_coordinate.lon; + auto is_same_input_coordinate = new_input_coordinates.lon == input_coordinate.lon && + new_input_coordinates.lat == input_coordinate.lat; return is_same_input_coordinate && phantom.IsValid(facade.GetNumberOfNodes()) && facade.GetCheckSum() == data_checksum; } diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 066ff2a6b..a2b1443cb 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -28,7 +28,7 @@ struct PhantomNode unsigned reverse_packed_geometry_id_, bool is_tiny_component, unsigned component_id, - util::FixedPointCoordinate location, + util::Coordinate location, unsigned short fwd_segment_position, extractor::TravelMode forward_travel_mode, extractor::TravelMode backward_travel_mode) @@ -37,9 +37,9 @@ struct PhantomNode forward_offset(forward_offset), reverse_offset(reverse_offset), forward_packed_geometry_id(forward_packed_geometry_id_), reverse_packed_geometry_id(reverse_packed_geometry_id_), - component{component_id, is_tiny_component}, - location(std::move(location)), fwd_segment_position(fwd_segment_position), - forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) + component{component_id, is_tiny_component}, location(std::move(location)), + fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode), + backward_travel_mode(backward_travel_mode) { } @@ -47,10 +47,9 @@ struct PhantomNode : forward_node_id(SPECIAL_NODEID), reverse_node_id(SPECIAL_NODEID), name_id(std::numeric_limits::max()), forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0), - forward_packed_geometry_id(SPECIAL_EDGEID), - reverse_packed_geometry_id(SPECIAL_EDGEID), - component{INVALID_COMPONENTID, false}, - fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), + forward_packed_geometry_id(SPECIAL_EDGEID), reverse_packed_geometry_id(SPECIAL_EDGEID), + component{INVALID_COMPONENTID, false}, fwd_segment_position(0), + forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), backward_travel_mode(TRAVEL_MODE_INACCESSIBLE) { } @@ -94,7 +93,12 @@ struct PhantomNode bool operator==(const PhantomNode &other) const { return location == other.location; } template - explicit PhantomNode(const OtherT &other, int forward_weight_, int forward_offset_, int reverse_weight_, int reverse_offset_, const util::FixedPointCoordinate foot_point) + explicit PhantomNode(const OtherT &other, + int forward_weight_, + int forward_offset_, + int reverse_weight_, + int reverse_offset_, + const util::Coordinate foot_point) { forward_node_id = other.forward_edge_based_node_id; reverse_node_id = other.reverse_edge_based_node_id; @@ -137,7 +141,7 @@ struct PhantomNode #ifndef _MSC_VER static_assert(sizeof(ComponentType) == 4, "ComponentType needs to 4 bytes big"); #endif - util::FixedPointCoordinate location; + util::Coordinate location; unsigned short fwd_segment_position; // note 4 bits would suffice for each, // but the saved byte would be padding anyway diff --git a/include/engine/plugins/plugin_base.hpp b/include/engine/plugins/plugin_base.hpp index 2124558be..9552bb82e 100644 --- a/include/engine/plugins/plugin_base.hpp +++ b/include/engine/plugins/plugin_base.hpp @@ -28,10 +28,10 @@ class BasePlugin datafacade::BaseDataFacade &facade; BasePlugin(datafacade::BaseDataFacade &facade_) : facade(facade_) {} - bool CheckAllCoordinates(const std::vector &coordinates) + bool CheckAllCoordinates(const std::vector &coordinates) { return !std::any_of(std::begin(coordinates), std::end(coordinates), - [](const util::FixedPointCoordinate &coordinate) + [](const util::Coordinate coordinate) { return !coordinate.IsValid(); }); @@ -150,9 +150,11 @@ class BasePlugin return phantom_nodes; } - std::vector> GetPhantomNodes(const api::BaseParameters ¶meters, unsigned number_of_results) + std::vector> + GetPhantomNodes(const api::BaseParameters ¶meters, unsigned number_of_results) { - std::vector> phantom_nodes(parameters.coordinates.size()); + std::vector> phantom_nodes( + parameters.coordinates.size()); const bool use_hints = !parameters.hints.empty(); const bool use_bearings = !parameters.bearings.empty(); @@ -176,32 +178,28 @@ class BasePlugin { if (use_radiuses && parameters.radiuses[i]) { - phantom_nodes[i] = - facade.NearestPhantomNodes( - parameters.coordinates[i], number_of_results, *parameters.radiuses[i], - parameters.bearings[i]->bearing, parameters.bearings[i]->range); + phantom_nodes[i] = facade.NearestPhantomNodes( + parameters.coordinates[i], number_of_results, *parameters.radiuses[i], + parameters.bearings[i]->bearing, parameters.bearings[i]->range); } else { - phantom_nodes[i] = - facade.NearestPhantomNodes( - parameters.coordinates[i], number_of_results, parameters.bearings[i]->bearing, - parameters.bearings[i]->range); + phantom_nodes[i] = facade.NearestPhantomNodes( + parameters.coordinates[i], number_of_results, + parameters.bearings[i]->bearing, parameters.bearings[i]->range); } } else { if (use_radiuses && parameters.radiuses[i]) { - phantom_nodes[i] = - facade.NearestPhantomNodes( - parameters.coordinates[i], number_of_results, *parameters.radiuses[i]); + phantom_nodes[i] = facade.NearestPhantomNodes( + parameters.coordinates[i], number_of_results, *parameters.radiuses[i]); } else { phantom_nodes[i] = - facade.NearestPhantomNodes( - parameters.coordinates[i], number_of_results); + facade.NearestPhantomNodes(parameters.coordinates[i], number_of_results); } } diff --git a/include/engine/polyline_compressor.hpp b/include/engine/polyline_compressor.hpp index bba2ab199..a1b7241f2 100644 --- a/include/engine/polyline_compressor.hpp +++ b/include/engine/polyline_compressor.hpp @@ -1,7 +1,7 @@ #ifndef POLYLINECOMPRESSOR_H_ #define POLYLINECOMPRESSOR_H_ -#include "osrm/coordinate.hpp" +#include "util/coordinate.hpp" #include #include @@ -12,19 +12,19 @@ namespace engine { namespace detail { - constexpr double POLYLINE_PECISION = 1e5; - constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION; - constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION; +constexpr double POLYLINE_PECISION = 1e5; +constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION; +constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION; } -using CoordVectorForwardIter = std::vector::const_iterator; +using CoordVectorForwardIter = std::vector::const_iterator; // Encodes geometry into polyline format. // See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end); // Decodes geometry from polyline format // See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm -std::vector decodePolyline(const std::string &polyline); +std::vector decodePolyline(const std::string &polyline); } } diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index 78f3f1380..36721dedb 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -76,7 +76,7 @@ class MapMatching final : public BasicRoutingInterface &trace_coordinates, + const std::vector &trace_coordinates, const std::vector &trace_timestamps, const std::vector> &trace_gps_precision) const { diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 39e7ba66a..da2302dcb 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -334,7 +334,7 @@ template class BasicRoutingInterface id_vector); const bool is_local_path = (phantom_node_pair.source_phantom.forward_packed_geometry_id == phantom_node_pair.target_phantom.forward_packed_geometry_id) && - unpacked_path.empty(); + unpacked_path.empty(); std::size_t start_index = 0; if (is_local_path) @@ -351,8 +351,7 @@ template class BasicRoutingInterface if (target_traversed_in_reverse) { std::reverse(id_vector.begin(), id_vector.end()); - end_index = - id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; + end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; } if (start_index > end_index) @@ -365,8 +364,8 @@ template class BasicRoutingInterface BOOST_ASSERT(i < id_vector.size()); BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0); unpacked_path.emplace_back( - PathData{id_vector[i], phantom_node_pair.target_phantom.name_id, - 0, extractor::TurnInstruction::NoTurn, + PathData{id_vector[i], phantom_node_pair.target_phantom.name_id, 0, + extractor::TurnInstruction::NoTurn, target_traversed_in_reverse ? phantom_node_pair.target_phantom.backward_travel_mode : phantom_node_pair.target_phantom.forward_travel_mode}); @@ -385,7 +384,8 @@ template class BasicRoutingInterface // looks like a trivially true check but tests for underflow BOOST_ASSERT(last_index > second_to_last_index); - if (unpacked_path[last_index].turn_via_node == unpacked_path[second_to_last_index].turn_via_node) + if (unpacked_path[last_index].turn_via_node == + unpacked_path[second_to_last_index].turn_via_node) { unpacked_path.pop_back(); } @@ -743,8 +743,8 @@ template class BasicRoutingInterface nodes.target_phantom = target_phantom; UnpackPath(packed_path.begin(), packed_path.end(), nodes, unpacked_path); - util::FixedPointCoordinate previous_coordinate = source_phantom.location; - util::FixedPointCoordinate current_coordinate; + util::Coordinate previous_coordinate = source_phantom.location; + util::Coordinate current_coordinate; double distance = 0; for (const auto &p : unpacked_path) { diff --git a/include/extractor/edge_based_node.hpp b/include/extractor/edge_based_node.hpp index c383d932e..ae85b02c7 100644 --- a/include/extractor/edge_based_node.hpp +++ b/include/extractor/edge_based_node.hpp @@ -22,8 +22,7 @@ struct EdgeBasedNode EdgeBasedNode() : forward_edge_based_node_id(SPECIAL_NODEID), reverse_edge_based_node_id(SPECIAL_NODEID), u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0), - forward_packed_geometry_id(SPECIAL_EDGEID), - reverse_packed_geometry_id(SPECIAL_EDGEID), + forward_packed_geometry_id(SPECIAL_EDGEID), reverse_packed_geometry_id(SPECIAL_EDGEID), component{INVALID_COMPONENTID, false}, fwd_segment_position(std::numeric_limits::max()), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), @@ -47,21 +46,19 @@ struct EdgeBasedNode reverse_edge_based_node_id(reverse_edge_based_node_id), u(u), v(v), name_id(name_id), forward_packed_geometry_id(forward_weight_or_packed_geometry_id_), reverse_packed_geometry_id(reverse_weight_or_packed_geometry_id_), - component{component_id, is_tiny_component}, - fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode), - backward_travel_mode(backward_travel_mode) + component{component_id, is_tiny_component}, fwd_segment_position(fwd_segment_position), + forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) { BOOST_ASSERT((forward_edge_based_node_id != SPECIAL_NODEID) || (reverse_edge_based_node_id != SPECIAL_NODEID)); } - static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate a, - const util::FixedPointCoordinate b) + static inline util::Coordinate Centroid(const util::Coordinate a, const util::Coordinate b) { - util::FixedPointCoordinate centroid; + util::Coordinate centroid; // The coordinates of the midpoint are given by: - centroid.lat = (a.lat + b.lat) / 2; - centroid.lon = (a.lon + b.lon) / 2; + centroid.lon = (a.lon + b.lon) / util::FixedLongitude(2); + centroid.lat = (a.lat + b.lat) / util::FixedLatitude(2); return centroid; } diff --git a/include/extractor/external_memory_node.hpp b/include/extractor/external_memory_node.hpp index 6658a7e6e..d26f7d3ec 100644 --- a/include/extractor/external_memory_node.hpp +++ b/include/extractor/external_memory_node.hpp @@ -12,8 +12,12 @@ namespace extractor struct ExternalMemoryNode : QueryNode { - ExternalMemoryNode(int lat, int lon, OSMNodeID node_id, bool barrier, bool traffic_lights) - : QueryNode(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights) + ExternalMemoryNode(const util::FixedLongitude lon_, + const util::FixedLatitude lat_, + OSMNodeID node_id_, + bool barrier_, + bool traffic_lights_) + : QueryNode(lon_, lat_, node_id_), barrier(barrier_), traffic_lights(traffic_lights_) { } @@ -21,12 +25,14 @@ struct ExternalMemoryNode : QueryNode static ExternalMemoryNode min_value() { - return ExternalMemoryNode(0, 0, MIN_OSM_NODEID, false, false); + return ExternalMemoryNode(util::FixedLongitude(0), util::FixedLatitude(0), MIN_OSM_NODEID, + false, false); } static ExternalMemoryNode max_value() { - return ExternalMemoryNode(std::numeric_limits::max(), std::numeric_limits::max(), + return ExternalMemoryNode(util::FixedLongitude(std::numeric_limits::max()), + util::FixedLatitude(std::numeric_limits::max()), MAX_OSM_NODEID, false, false); } diff --git a/include/extractor/internal_extractor_edge.hpp b/include/extractor/internal_extractor_edge.hpp index a85a95d99..57075f20f 100644 --- a/include/extractor/internal_extractor_edge.hpp +++ b/include/extractor/internal_extractor_edge.hpp @@ -85,7 +85,7 @@ struct InternalExtractorEdge // intermediate edge weight WeightData weight_data; // coordinate of the source node - util::FixedPointCoordinate source_coordinate; + util::Coordinate source_coordinate; // necessary static util functions for stxxl's sorting static InternalExtractorEdge min_osm_value() diff --git a/include/extractor/query_node.hpp b/include/extractor/query_node.hpp index f62dd33b3..93c2d61b2 100644 --- a/include/extractor/query_node.hpp +++ b/include/extractor/query_node.hpp @@ -3,7 +3,7 @@ #include "util/typedefs.hpp" -#include "osrm/coordinate.hpp" +#include "util/coordinate.hpp" #include @@ -17,30 +17,32 @@ struct QueryNode using key_type = OSMNodeID; // type of NodeID using value_type = int; // type of lat,lons - explicit QueryNode(int lat, int lon, key_type node_id) - : lat(lat), lon(lon), node_id(std::move(node_id)) + explicit QueryNode(const util::FixedLongitude lon_, + const util::FixedLatitude lat_, + key_type node_id) + : lon(lon_), lat(lat_), node_id(std::move(node_id)) { } QueryNode() - : lat(std::numeric_limits::max()), lon(std::numeric_limits::max()), + : lon(std::numeric_limits::max()), lat(std::numeric_limits::max()), node_id(SPECIAL_OSM_NODEID) { } - int lat; - int lon; + util::FixedLongitude lon; + util::FixedLatitude lat; key_type node_id; static QueryNode min_value() { - return QueryNode(static_cast(-90 * COORDINATE_PRECISION), - static_cast(-180 * COORDINATE_PRECISION), MIN_OSM_NODEID); + return QueryNode(util::FixedLongitude(-180 * COORDINATE_PRECISION), + util::FixedLatitude(-90 * COORDINATE_PRECISION), MIN_OSM_NODEID); } static QueryNode max_value() { - return QueryNode(static_cast(90 * COORDINATE_PRECISION), - static_cast(180 * COORDINATE_PRECISION), MAX_OSM_NODEID); + return QueryNode(util::FixedLongitude(180 * COORDINATE_PRECISION), + util::FixedLatitude(90 * COORDINATE_PRECISION), MAX_OSM_NODEID); } }; } diff --git a/include/osrm/coordinate.hpp b/include/osrm/coordinate.hpp index 34fbb5e26..cec72d27e 100644 --- a/include/osrm/coordinate.hpp +++ b/include/osrm/coordinate.hpp @@ -5,7 +5,7 @@ namespace osrm { - using util::FixedPointCoordinate; +using util::Coordinate; } #endif diff --git a/include/server/api/parameters_parser.hpp b/include/server/api/parameters_parser.hpp index 548f48aab..d7693b228 100644 --- a/include/server/api/parameters_parser.hpp +++ b/include/server/api/parameters_parser.hpp @@ -33,7 +33,7 @@ template ::value, int>::type = 0> boost::optional parseParameters(std::string options_string) { - const auto first = options_string.begin(); + auto first = options_string.begin(); const auto last = options_string.end(); return parseParameters(first, last); } diff --git a/include/server/api/parsed_url.hpp b/include/server/api/parsed_url.hpp index bf8d317b7..da53e2b3b 100644 --- a/include/server/api/parsed_url.hpp +++ b/include/server/api/parsed_url.hpp @@ -18,10 +18,9 @@ struct ParsedURL std::string service; unsigned version; std::string profile; - std::vector coordinates; + std::vector coordinates; std::string options; }; - } } } diff --git a/include/server/service/base_service.hpp b/include/server/service/base_service.hpp index 90ff84648..da38f75d2 100644 --- a/include/server/service/base_service.hpp +++ b/include/server/service/base_service.hpp @@ -21,7 +21,7 @@ class BaseService BaseService(OSRM &routing_machine) : routing_machine(routing_machine) {} virtual ~BaseService() = default; - virtual engine::Status RunQuery(std::vector coordinates, + virtual engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &json_result) = 0; diff --git a/include/server/service/match_service.hpp b/include/server/service/match_service.hpp index e74275a57..92cc09590 100644 --- a/include/server/service/match_service.hpp +++ b/include/server/service/match_service.hpp @@ -22,7 +22,7 @@ class MatchService final : public BaseService public: MatchService(OSRM &routing_machine) : BaseService(routing_machine) {} - engine::Status RunQuery(std::vector coordinates, + engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) final override; diff --git a/include/server/service/nearest_service.hpp b/include/server/service/nearest_service.hpp index 00e4a9119..76e72aa72 100644 --- a/include/server/service/nearest_service.hpp +++ b/include/server/service/nearest_service.hpp @@ -22,7 +22,7 @@ class NearestService final : public BaseService public: NearestService(OSRM &routing_machine) : BaseService(routing_machine) {} - engine::Status RunQuery(std::vector coordinates, + engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) final override; diff --git a/include/server/service/route_service.hpp b/include/server/service/route_service.hpp index 57fb1ab5c..b03114b1e 100644 --- a/include/server/service/route_service.hpp +++ b/include/server/service/route_service.hpp @@ -22,7 +22,7 @@ class RouteService final : public BaseService public: RouteService(OSRM &routing_machine) : BaseService(routing_machine) {} - engine::Status RunQuery(std::vector coordinates, + engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) final override; diff --git a/include/server/service/table_service.hpp b/include/server/service/table_service.hpp index 9978702ed..75967c1f7 100644 --- a/include/server/service/table_service.hpp +++ b/include/server/service/table_service.hpp @@ -22,7 +22,7 @@ class TableService final : public BaseService public: TableService(OSRM &routing_machine) : BaseService(routing_machine) {} - engine::Status RunQuery(std::vector coordinates, + engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) final override; diff --git a/include/server/service/trip_service.hpp b/include/server/service/trip_service.hpp index 4af1121d5..6cb77b470 100644 --- a/include/server/service/trip_service.hpp +++ b/include/server/service/trip_service.hpp @@ -22,7 +22,7 @@ class TripService final : public BaseService public: TripService(OSRM &routing_machine) : BaseService(routing_machine) {} - engine::Status RunQuery(std::vector coordinates, + engine::Status RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) final override; diff --git a/include/util/coordinate.hpp b/include/util/coordinate.hpp index 8ca1636a6..39eb02f3f 100644 --- a/include/util/coordinate.hpp +++ b/include/util/coordinate.hpp @@ -28,9 +28,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef COORDINATE_HPP_ #define COORDINATE_HPP_ +#include "util/strong_typedef.hpp" + #include //for std::ostream #include #include +#include namespace osrm { @@ -40,35 +43,60 @@ constexpr const double COORDINATE_PRECISION = 1e6; namespace util { -struct FixedPointCoordinate +OSRM_STRONG_TYPEDEF(int32_t, FixedLatitude) +OSRM_STRONG_TYPEDEF(int32_t, FixedLongitude) +OSRM_STRONG_TYPEDEF(double, FloatLatitude) +OSRM_STRONG_TYPEDEF(double, FloatLongitude) + +inline FixedLatitude toFixed(const FloatLatitude floating) { - int lat; - int lon; + return FixedLatitude(static_cast(floating) * COORDINATE_PRECISION); +} - FixedPointCoordinate(); - FixedPointCoordinate(int lat, int lon); +inline FixedLongitude toFixed(const FloatLongitude floating) +{ + return FixedLongitude(static_cast(floating) * COORDINATE_PRECISION); +} - template - FixedPointCoordinate(const T &coordinate) - : lat(coordinate.lat), lon(coordinate.lon) +inline FloatLatitude toFloating(const FixedLatitude fixed) +{ + return FloatLatitude(static_cast(fixed) / COORDINATE_PRECISION); +} + +inline FloatLongitude toFloating(const FixedLongitude fixed) +{ + return FloatLongitude(static_cast(fixed) / COORDINATE_PRECISION); +} + +// Coordinate encoded as longitude, latitude +struct Coordinate +{ + FixedLongitude lon; + FixedLatitude lat; + + Coordinate(); + Coordinate(const FixedLongitude lon_, const FixedLatitude lat_); + Coordinate(const FloatLongitude lon_, const FloatLatitude lat_); + + template Coordinate(const T &coordinate) : lon(coordinate.lon), lat(coordinate.lat) { - static_assert(!std::is_same::value, "This constructor should not be used for FixedPointCoordinates"); - static_assert(std::is_same::value, - "coordinate types incompatible"); + static_assert(!std::is_same::value, + "This constructor should not be used for Coordinates"); static_assert(std::is_same::value, "coordinate types incompatible"); + static_assert(std::is_same::value, + "coordinate types incompatible"); } bool IsValid() const; - friend bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); - friend bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); - friend std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate); + friend bool operator==(const Coordinate lhs, const Coordinate rhs); + friend bool operator!=(const Coordinate lhs, const Coordinate rhs); + friend std::ostream &operator<<(std::ostream &out, const Coordinate coordinate); }; -bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); -std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate); +bool operator==(const Coordinate lhs, const Coordinate rhs); +std::ostream &operator<<(std::ostream &out, const Coordinate coordinate); } - } #endif /* COORDINATE_HPP_ */ diff --git a/include/util/coordinate_calculation.hpp b/include/util/coordinate_calculation.hpp index b7758f294..f2191c624 100644 --- a/include/util/coordinate_calculation.hpp +++ b/include/util/coordinate_calculation.hpp @@ -1,7 +1,7 @@ #ifndef COORDINATE_CALCULATION #define COORDINATE_CALCULATION -#include "osrm/coordinate.hpp" +#include "util/coordinate.hpp" #include #include @@ -18,55 +18,47 @@ const constexpr long double EARTH_RADIUS = 6372797.560856; 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 Coordinate first_coordinate, const Coordinate second_coordinate); -double greatCircleDistance(const FixedPointCoordinate first_coordinate, - const FixedPointCoordinate second_coordinate); +double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate); -double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2); +double perpendicularDistance(const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate 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 perpendicularDistance(const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate query_location, + Coordinate &nearest_location, double &ratio); -double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, - const FixedPointCoordinate segment_target, - const FixedPointCoordinate query_location, - const std::pair projected_coordinate); +double perpendicularDistanceFromProjectedCoordinate( + const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate query_location, + const std::pair projected_xy_coordinate); -double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, - const FixedPointCoordinate segment_target, - const FixedPointCoordinate query_location, - const std::pair projected_coordinate, - FixedPointCoordinate &nearest_location, - double &ratio); +double perpendicularDistanceFromProjectedCoordinate( + const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate query_location, + const std::pair projected_xy_coordinate, + Coordinate &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 Coordinate first_coordinate, const Coordinate 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 Coordinate first, const Coordinate second, const Coordinate third); namespace mercator { -double yToLat(const double value); -double latToY(const double latitude); +FloatLatitude yToLat(const double value); +double latToY(const FloatLatitude latitude); } // ns mercator } // ns coordinate_calculation } // ns util diff --git a/include/util/graph_loader.hpp b/include/util/graph_loader.hpp index 5d060809e..b611e04bb 100644 --- a/include/util/graph_loader.hpp +++ b/include/util/graph_loader.hpp @@ -86,7 +86,7 @@ NodeID loadNodesFromFile(std::istream &input_stream, { input_stream.read(reinterpret_cast(¤t_node), sizeof(extractor::ExternalMemoryNode)); - node_array.emplace_back(current_node.lat, current_node.lon, current_node.node_id); + node_array.emplace_back(current_node.lon, current_node.lat, current_node.node_id); if (current_node.barrier) { barrier_node_list.emplace_back(i); diff --git a/include/util/hilbert_value.hpp b/include/util/hilbert_value.hpp index fb9274458..2acb6b402 100644 --- a/include/util/hilbert_value.hpp +++ b/include/util/hilbert_value.hpp @@ -11,7 +11,7 @@ namespace util { // Computes a 64 bit value that corresponds to the hilbert space filling curve -std::uint64_t hilbertCode(const FixedPointCoordinate coordinate); +std::uint64_t hilbertCode(const Coordinate coordinate); } } diff --git a/include/util/matching_debug_info.hpp b/include/util/matching_debug_info.hpp index cdd3651b4..8377e8e17 100644 --- a/include/util/matching_debug_info.hpp +++ b/include/util/matching_debug_info.hpp @@ -39,9 +39,9 @@ struct MatchingDebugInfo { json::Object state; state.values["transitions"] = json::Array(); - state.values["coordinate"] = - json::make_array(elem_s.phantom_node.location.lat / COORDINATE_PRECISION, - elem_s.phantom_node.location.lon / COORDINATE_PRECISION); + state.values["coordinate"] = json::make_array( + static_cast(toFloating(elem_s.phantom_node.location.lat)), + static_cast(toFloating(elem_s.phantom_node.location.lon))); state.values["viterbi"] = json::clamp_float(engine::map_matching::IMPOSSIBLE_LOG_PROB); state.values["pruned"] = 0u; @@ -124,8 +124,10 @@ struct MatchingDebugInfo json::Array a; for (const bool v : breakage) { - if (v) a.values.emplace_back(json::True()); - else a.values.emplace_back(json::False()); + if (v) + a.values.emplace_back(json::True()); + else + a.values.emplace_back(json::False()); } json::get(*object, "breakage") = std::move(a); diff --git a/include/util/rectangle.hpp b/include/util/rectangle.hpp index c832b91fd..3c058d0ca 100644 --- a/include/util/rectangle.hpp +++ b/include/util/rectangle.hpp @@ -29,16 +29,25 @@ struct RectangleInt2D { } - RectangleInt2D(std::int32_t min_lon_, - std::int32_t max_lon_, - std::int32_t min_lat_, - std::int32_t max_lat_) + RectangleInt2D(FixedLongitude min_lon_, + FixedLongitude max_lon_, + FixedLatitude min_lat_, + FixedLatitude max_lat_) : min_lon(min_lon_), max_lon(max_lon_), min_lat(min_lat_), max_lat(max_lat_) { } - std::int32_t min_lon, max_lon; - std::int32_t min_lat, max_lat; + RectangleInt2D(FloatLongitude min_lon_, + FloatLongitude max_lon_, + FloatLatitude min_lat_, + FloatLatitude max_lat_) + : min_lon(toFixed(min_lon_)), max_lon(toFixed(max_lon_)), min_lat(toFixed(min_lat_)), + max_lat(toFixed(max_lat_)) + { + } + + FixedLongitude min_lon, max_lon; + FixedLatitude min_lat, max_lat; void MergeBoundingBoxes(const RectangleInt2D &other) { @@ -46,19 +55,19 @@ struct RectangleInt2D max_lon = std::max(max_lon, other.max_lon); min_lat = std::min(min_lat, other.min_lat); max_lat = std::max(max_lat, other.max_lat); - BOOST_ASSERT(min_lat != std::numeric_limits::min()); - BOOST_ASSERT(min_lon != std::numeric_limits::min()); - BOOST_ASSERT(max_lat != std::numeric_limits::min()); - BOOST_ASSERT(max_lon != std::numeric_limits::min()); + BOOST_ASSERT(min_lon != FixedLongitude(std::numeric_limits::min())); + BOOST_ASSERT(min_lat != FixedLatitude(std::numeric_limits::min())); + BOOST_ASSERT(max_lon != FixedLongitude(std::numeric_limits::min())); + BOOST_ASSERT(max_lat != FixedLatitude(std::numeric_limits::min())); } - FixedPointCoordinate Centroid() const + Coordinate Centroid() const { - FixedPointCoordinate centroid; + Coordinate centroid; // The coordinates of the midpoints are given by: // x = (x1 + x2) /2 and y = (y1 + y2) /2. - centroid.lon = (min_lon + max_lon) / 2; - centroid.lat = (min_lat + max_lat) / 2; + centroid.lon = (min_lon + max_lon) / FixedLongitude(2); + centroid.lat = (min_lat + max_lat) / FixedLatitude(2); return centroid; } @@ -70,7 +79,7 @@ struct RectangleInt2D min_lat > other.max_lat); } - double GetMinDist(const FixedPointCoordinate location) const + double GetMinDist(const Coordinate location) const { const bool is_contained = Contains(location); if (is_contained) @@ -108,35 +117,35 @@ struct RectangleInt2D { case NORTH: min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(max_lat, location.lon)); + location, Coordinate(location.lon, max_lat)); break; case SOUTH: min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(min_lat, location.lon)); + location, Coordinate(location.lon, min_lat)); break; case WEST: min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(location.lat, min_lon)); + location, Coordinate(min_lon, location.lat)); break; case EAST: min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(location.lat, max_lon)); + location, Coordinate(max_lon, location.lat)); break; case NORTH_EAST: - min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(max_lat, max_lon)); + min_dist = + coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, max_lat)); break; case NORTH_WEST: - min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(max_lat, min_lon)); + min_dist = + coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, max_lat)); break; case SOUTH_EAST: - min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(min_lat, max_lon)); + min_dist = + coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, min_lat)); break; case SOUTH_WEST: - min_dist = coordinate_calculation::greatCircleDistance( - location, FixedPointCoordinate(min_lat, min_lon)); + min_dist = + coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, min_lat)); break; default: break; @@ -147,14 +156,14 @@ struct RectangleInt2D return min_dist; } - double GetMinMaxDist(const FixedPointCoordinate location) const + double GetMinMaxDist(const Coordinate location) const { double min_max_dist = std::numeric_limits::max(); // Get minmax distance to each of the four sides - const FixedPointCoordinate upper_left(max_lat, min_lon); - const FixedPointCoordinate upper_right(max_lat, max_lon); - const FixedPointCoordinate lower_right(min_lat, max_lon); - const FixedPointCoordinate lower_left(min_lat, min_lon); + const Coordinate upper_left(min_lon, max_lat); + const Coordinate upper_right(max_lon, max_lat); + const Coordinate lower_right(max_lon, min_lat); + const Coordinate lower_left(min_lon, min_lat); min_max_dist = std::min(min_max_dist, @@ -178,11 +187,11 @@ struct RectangleInt2D return min_max_dist; } - bool Contains(const FixedPointCoordinate location) const + bool Contains(const Coordinate 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); - return lats_contained && lons_contained; + const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat); + return lons_contained && lats_contained; } }; } diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index f630fd671..e3d2cc9ef 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -37,7 +37,7 @@ namespace util // Static RTree for serving nearest neighbour queries template , + class CoordinateListT = std::vector, bool UseSharedMemory = false, std::uint32_t BRANCHING_FACTOR = 64, std::uint32_t LEAF_NODE_SIZE = 1024> @@ -122,8 +122,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, &coordinate_list]( - const tbb::blocked_range &range) + [&input_data_vector, &input_wrapper_vector, + &coordinate_list](const tbb::blocked_range &range) { for (uint64_t element_counter = range.begin(), end = range.end(); element_counter != end; ++element_counter) @@ -137,14 +137,14 @@ class StaticRTree BOOST_ASSERT(current_element.u < coordinate_list.size()); BOOST_ASSERT(current_element.v < coordinate_list.size()); - FixedPointCoordinate current_centroid = EdgeDataT::Centroid( - FixedPointCoordinate(coordinate_list[current_element.u].lat, - coordinate_list[current_element.u].lon), - FixedPointCoordinate(coordinate_list[current_element.v].lat, - coordinate_list[current_element.v].lon)); - current_centroid.lat = - COORDINATE_PRECISION * coordinate_calculation::mercator::latToY( - current_centroid.lat / COORDINATE_PRECISION); + Coordinate current_centroid = + EdgeDataT::Centroid(Coordinate(coordinate_list[current_element.u].lon, + coordinate_list[current_element.u].lat), + Coordinate(coordinate_list[current_element.v].lon, + coordinate_list[current_element.v].lat)); + current_centroid.lat = FixedLatitude( + COORDINATE_PRECISION * + coordinate_calculation::mercator::latToY(toFloating(current_centroid.lat))); current_wrapper.m_hilbert_value = hilbertCode(current_centroid); } @@ -377,8 +377,7 @@ class StaticRTree } // Override filter and terminator for the desired behaviour. - std::vector Nearest(const FixedPointCoordinate input_coordinate, - const std::size_t max_results) + std::vector Nearest(const Coordinate input_coordinate, const std::size_t max_results) { return Nearest(input_coordinate, [](const EdgeDataT &) @@ -393,14 +392,13 @@ class StaticRTree // Override filter and terminator for the desired behaviour. template - std::vector Nearest(const FixedPointCoordinate input_coordinate, - const FilterT filter, - const TerminationT terminate) + std::vector + Nearest(const Coordinate input_coordinate, const FilterT filter, const TerminationT terminate) { std::vector results; std::pair projected_coordinate = { - coordinate_calculation::mercator::latToY(input_coordinate.lat / COORDINATE_PRECISION), - input_coordinate.lon / COORDINATE_PRECISION}; + static_cast(toFloating(input_coordinate.lon)), + coordinate_calculation::mercator::latToY(toFloating(input_coordinate.lat))}; // initialize queue with root element std::priority_queue traversal_queue; @@ -462,7 +460,7 @@ class StaticRTree private: template void ExploreLeafNode(const std::uint32_t leaf_id, - const FixedPointCoordinate input_coordinate, + const Coordinate input_coordinate, const std::pair &projected_coordinate, QueueT &traversal_queue) { @@ -487,7 +485,7 @@ class StaticRTree template void ExploreTreeNode(const TreeNode &parent, - const FixedPointCoordinate input_coordinate, + const Coordinate input_coordinate, QueueT &traversal_queue) { for (std::uint32_t i = 0; i < parent.child_count; ++i) @@ -542,10 +540,10 @@ class StaticRTree std::max(rectangle.max_lat, std::max(coordinate_list[objects[i].u].lat, coordinate_list[objects[i].v].lat)); } - BOOST_ASSERT(rectangle.min_lat != std::numeric_limits::min()); - BOOST_ASSERT(rectangle.min_lon != std::numeric_limits::min()); - BOOST_ASSERT(rectangle.max_lat != std::numeric_limits::min()); - BOOST_ASSERT(rectangle.max_lon != std::numeric_limits::min()); + BOOST_ASSERT(rectangle.min_lon != FixedLongitude(std::numeric_limits::min())); + BOOST_ASSERT(rectangle.min_lat != FixedLatitude(std::numeric_limits::min())); + BOOST_ASSERT(rectangle.max_lon != FixedLongitude(std::numeric_limits::min())); + BOOST_ASSERT(rectangle.max_lat != FixedLatitude(std::numeric_limits::min())); } }; diff --git a/include/util/strong_typedef.hpp b/include/util/strong_typedef.hpp index 8aa49b515..911194443 100644 --- a/include/util/strong_typedef.hpp +++ b/include/util/strong_typedef.hpp @@ -18,21 +18,30 @@ namespace osrm { \ static_assert(std::is_arithmetic(), ""); \ From x; \ - friend std::ostream& operator<<(std::ostream& stream, const To& inst); \ + friend std::ostream &operator<<(std::ostream &stream, const To &inst); \ \ public: \ To() = default; \ explicit To(const From x_) : x(x_) {} \ explicit operator From &() { return x; } \ - explicit operator const From &() const { return x; } \ - bool operator<(const To &z_) const { return x < static_cast(z_); } \ - bool operator>(const To &z_) const { return x > static_cast(z_); } \ - bool operator<=(const To &z_) const { return x <= static_cast(z_); } \ - bool operator>=(const To &z_) const { return x >= static_cast(z_); } \ - bool operator==(const To &z_) const { return x == static_cast(z_); } \ - bool operator!=(const To &z_) const { return x != static_cast(z_); } \ + explicit operator From() const { return x; } \ + To operator+(const To rhs_) const { return To(x + static_cast(rhs_)); } \ + To operator-(const To rhs_) const { return To(x - static_cast(rhs_)); } \ + To operator*(const To rhs_) const { return To(x * static_cast(rhs_)); } \ + To operator/(const To rhs_) const { return To(x / static_cast(rhs_)); } \ + bool operator<(const To z_) const { return x < static_cast(z_); } \ + bool operator>(const To z_) const { return x > static_cast(z_); } \ + bool operator<=(const To z_) const { return x <= static_cast(z_); } \ + bool operator>=(const To z_) const { return x >= static_cast(z_); } \ + bool operator==(const To z_) const { return x == static_cast(z_); } \ + bool operator!=(const To z_) const { return x != static_cast(z_); } \ }; \ - inline From To##_to_##From(To to) { return static_cast(to); } \ + inline std::ostream &operator<<(std::ostream &stream, const To &inst) \ + { \ + return stream << #To << '(' << inst.x << ')'; \ + } + +#define OSRM_STRONG_TYPEDEF_HASHABLE(From, To) \ namespace std \ { \ template <> struct hash \ @@ -42,9 +51,6 @@ namespace osrm return std::hash()(static_cast(k)); \ } \ }; \ - } \ - inline std::ostream& operator<<(std::ostream& stream, const To& inst) { \ - return stream << #To << '(' << inst.x << ')'; \ } } diff --git a/include/util/tiles.hpp b/include/util/tiles.hpp index ce4afee68..425993b39 100644 --- a/include/util/tiles.hpp +++ b/include/util/tiles.hpp @@ -1,6 +1,8 @@ #ifndef UTIL_TILES_HPP #define UTIL_TILES_HPP +#include "util/coordinate.hpp" + #include #include @@ -46,20 +48,20 @@ inline unsigned getBBMaxZoom(const Tile top_left, const Tile bottom_left) } } -inline Tile pointToTile(const double lon, const double lat) +inline Tile pointToTile(const FloatLongitude lon, const FloatLatitude lat) { - auto sin_lat = std::sin(lat * M_PI / 180.); + auto sin_lat = std::sin(static_cast(lat) * M_PI / 180.); auto p2z = std::pow(2, detail::MAX_ZOOM); - unsigned x = p2z * (lon / 360. + 0.5); + unsigned x = p2z * (static_cast(lon) / 360. + 0.5); unsigned y = p2z * (0.5 - 0.25 * std::log((1 + sin_lat) / (1 - sin_lat)) / M_PI); return Tile{x, y, detail::MAX_ZOOM}; } -inline Tile getBBMaxZoomTile(const double min_lon, - const double min_lat, - const double max_lon, - const double max_lat) +inline Tile getBBMaxZoomTile(const FloatLongitude min_lon, + const FloatLatitude min_lat, + const FloatLongitude max_lon, + const FloatLatitude max_lat) { const auto top_left = pointToTile(min_lon, min_lat); const auto bottom_left = pointToTile(max_lon, max_lat); diff --git a/include/util/typedefs.hpp b/include/util/typedefs.hpp index 8dc417a41..1fd24d495 100644 --- a/include/util/typedefs.hpp +++ b/include/util/typedefs.hpp @@ -8,7 +8,10 @@ // OpenStreetMap node ids are higher than 2^32 OSRM_STRONG_TYPEDEF(uint64_t, OSMNodeID) +OSRM_STRONG_TYPEDEF_HASHABLE(uint64_t, OSMNodeID) + OSRM_STRONG_TYPEDEF(uint32_t, OSMWayID) +OSRM_STRONG_TYPEDEF_HASHABLE(uint32_t, OSMWayID) static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits::max()); static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID(std::numeric_limits::max()); diff --git a/src/benchmarks/static_rtree.cpp b/src/benchmarks/static_rtree.cpp index 745fad3df..58f57f92c 100644 --- a/src/benchmarks/static_rtree.cpp +++ b/src/benchmarks/static_rtree.cpp @@ -4,8 +4,7 @@ #include "engine/geospatial_query.hpp" #include "util/timing_util.hpp" #include "mocks/mock_datafacade.hpp" - -#include "osrm/coordinate.hpp" +#include "util/coordinate.hpp" #include #include @@ -25,23 +24,23 @@ constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION; constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; using RTreeLeaf = extractor::EdgeBasedNode; -using FixedPointCoordinateListPtr = std::shared_ptr>; +using CoordinateListPtr = std::shared_ptr>; using BenchStaticRTree = - util::StaticRTree::vector, false>; + util::StaticRTree::vector, false>; using BenchQuery = engine::GeospatialQuery; -FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file) +CoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file) { boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary); extractor::QueryNode current_node; unsigned coordinate_count = 0; nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned)); - auto coords = std::make_shared>(coordinate_count); + auto coords = std::make_shared>(coordinate_count); for (unsigned i = 0; i < coordinate_count; ++i) { nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode)); - coords->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon); + coords->at(i) = util::Coordinate(current_node.lon, current_node.lat); BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0); BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0); } @@ -49,7 +48,7 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes } template -void benchmarkQuery(const std::vector &queries, +void benchmarkQuery(const std::vector &queries, const std::string &name, QueryT query) { @@ -75,38 +74,35 @@ void benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer std::mt19937 mt_rand(RANDOM_SEED); std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON); - std::vector queries; + std::vector queries; for (unsigned i = 0; i < num_queries; i++) { queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand)); } - benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q) + 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 FixedPointCoordinate &q) + benchmarkQuery(queries, "raw RTree queries (10 results)", [&rtree](const util::Coordinate &q) { return rtree.Nearest(q, 10); }); benchmarkQuery(queries, "big component alternative queries", - [&geo_query](const FixedPointCoordinate &q) + [&geo_query](const util::Coordinate &q) { return geo_query.NearestPhantomNodeWithAlternativeFromBigComponent(q); }); - benchmarkQuery(queries, "max distance 1000", [&geo_query](const FixedPointCoordinate &q) + benchmarkQuery(queries, "max distance 1000", [&geo_query](const util::Coordinate &q) { return geo_query.NearestPhantomNodesInRange(q, 1000); }); - benchmarkQuery(queries, "PhantomNode query (1 result)", - [&geo_query](const FixedPointCoordinate &q) + benchmarkQuery(queries, "PhantomNode query (1 result)", [&geo_query](const util::Coordinate &q) { return geo_query.NearestPhantomNodes(q, 1); }); - benchmarkQuery(queries, "PhantomNode query (10 result)", - [&geo_query](const FixedPointCoordinate &q) + benchmarkQuery(queries, "PhantomNode query (10 result)", [&geo_query](const util::Coordinate &q) { return geo_query.NearestPhantomNodes(q, 10); }); @@ -130,7 +126,8 @@ int main(int argc, char **argv) auto coords = osrm::benchmarks::loadCoordinates(nodes_path); osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords); - std::unique_ptr mockfacade_ptr(new osrm::benchmarks::MockDataFacade); + std::unique_ptr mockfacade_ptr( + new osrm::benchmarks::MockDataFacade); osrm::benchmarks::BenchQuery query(rtree, coords, *mockfacade_ptr); osrm::benchmarks::benchmark(rtree, query, 10000); diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index 1f2bc66e8..8df0f9237 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -37,7 +37,7 @@ template <> struct hash> { std::size_t operator()(const std::pair &k) const { - return OSMNodeID_to_uint64_t(k.first) ^ (OSMNodeID_to_uint64_t(k.second) << 12); + return static_cast(k.first) ^ (static_cast(k.second) << 12); } }; } @@ -70,9 +70,8 @@ int Contractor::Run() util::DeallocatingVector edge_based_edge_list; std::size_t max_edge_id = LoadEdgeExpandedGraph( - config.edge_based_graph_path, edge_based_edge_list, - config.edge_segment_lookup_path, config.edge_penalty_path, - config.segment_speed_lookup_path, config.node_based_graph_path, + config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path, + config.edge_penalty_path, config.segment_speed_lookup_path, config.node_based_graph_path, config.geometry_path, config.rtree_leaf_path); // Contracting the edge-expanded graph @@ -195,7 +194,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph( if (!nodes_input_stream) { - throw util::exception("Failed to open "+nodes_filename); + throw util::exception("Failed to open " + nodes_filename); } unsigned number_of_nodes = 0; @@ -203,7 +202,8 @@ std::size_t Contractor::LoadEdgeExpandedGraph( internal_to_external_node_map.resize(number_of_nodes); // Load all the query nodes into a vector - nodes_input_stream.read(reinterpret_cast(&(internal_to_external_node_map[0])), number_of_nodes * sizeof(extractor::QueryNode)); + nodes_input_stream.read(reinterpret_cast(&(internal_to_external_node_map[0])), + number_of_nodes * sizeof(extractor::QueryNode)); } std::vector m_geometry_indices; @@ -213,7 +213,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph( std::ifstream geometry_stream(geometry_filename, std::ios::binary); if (!geometry_stream) { - throw util::exception("Failed to open "+geometry_filename); + throw util::exception("Failed to open " + geometry_filename); } unsigned number_of_indices = 0; unsigned number_of_compressed_geometries = 0; @@ -224,18 +224,20 @@ std::size_t Contractor::LoadEdgeExpandedGraph( if (number_of_indices > 0) { geometry_stream.read((char *)&(m_geometry_indices[0]), - number_of_indices * sizeof(unsigned)); + number_of_indices * sizeof(unsigned)); } geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned)); BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries); m_geometry_list.resize(number_of_compressed_geometries); - + if (number_of_compressed_geometries > 0) { - geometry_stream.read((char *)&(m_geometry_list[0]), - number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); + geometry_stream.read( + (char *)&(m_geometry_list[0]), + number_of_compressed_geometries * + sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); } } @@ -249,7 +251,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph( std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in); if (!leaf_node_file) { - throw util::exception("Failed to open "+rtree_leaf_filename); + throw util::exception("Failed to open " + rtree_leaf_filename); } uint64_t m_element_count; leaf_node_file.read((char *)&m_element_count, sizeof(uint64_t)); @@ -259,90 +261,115 @@ std::size_t Contractor::LoadEdgeExpandedGraph( { leaf_node_file.read(reinterpret_cast(¤t_node), sizeof(current_node)); - for (size_t i=0; i< current_node.object_count; i++) + for (size_t i = 0; i < current_node.object_count; i++) { - auto & leaf_object = current_node.objects[i]; + auto &leaf_object = current_node.objects[i]; extractor::QueryNode *u; extractor::QueryNode *v; if (leaf_object.forward_packed_geometry_id != SPECIAL_EDGEID) { - const unsigned forward_begin = m_geometry_indices.at(leaf_object.forward_packed_geometry_id); + const unsigned forward_begin = + m_geometry_indices.at(leaf_object.forward_packed_geometry_id); if (leaf_object.fwd_segment_position == 0) { u = &(internal_to_external_node_map[leaf_object.u]); - v = &(internal_to_external_node_map[m_geometry_list[forward_begin].node_id]); + v = &(internal_to_external_node_map[m_geometry_list[forward_begin] + .node_id]); } else { - u = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position - 1].node_id]); - v = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position].node_id]); + u = &(internal_to_external_node_map + [m_geometry_list[forward_begin + + leaf_object.fwd_segment_position - 1] + .node_id]); + v = &(internal_to_external_node_map + [m_geometry_list[forward_begin + + leaf_object.fwd_segment_position] + .node_id]); } const double segment_length = - util::coordinate_calculation::greatCircleDistance( - u->lat, u->lon, v->lat, v->lon); + util::coordinate_calculation::greatCircleDistance( + util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat}); - auto forward_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id)); + auto forward_speed_iter = + segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id)); if (forward_speed_iter != segment_speed_lookup.end()) { - int new_segment_weight = - std::max(1, static_cast(std::floor( - (segment_length * 10.) / (forward_speed_iter->second / 3.6) + .5))); - m_geometry_list[forward_begin + leaf_object.fwd_segment_position].weight = new_segment_weight; + int new_segment_weight = std::max( + 1, static_cast(std::floor( + (segment_length * 10.) / (forward_speed_iter->second / 3.6) + + .5))); + m_geometry_list[forward_begin + leaf_object.fwd_segment_position] + .weight = new_segment_weight; } } if (leaf_object.reverse_packed_geometry_id != SPECIAL_EDGEID) { - const unsigned reverse_begin = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id); - const unsigned reverse_end = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1); + const unsigned reverse_begin = + m_geometry_indices.at(leaf_object.reverse_packed_geometry_id); + const unsigned reverse_end = + m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1); - int rev_segment_position = (reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1; + int rev_segment_position = + (reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1; if (rev_segment_position == 0) { u = &(internal_to_external_node_map[leaf_object.v]); - v = &(internal_to_external_node_map[m_geometry_list[reverse_begin].node_id]); + v = &(internal_to_external_node_map[m_geometry_list[reverse_begin] + .node_id]); } else { - u = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position - 1].node_id]); - v = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position].node_id]); + u = &(internal_to_external_node_map + [m_geometry_list[reverse_begin + rev_segment_position - 1] + .node_id]); + v = &( + internal_to_external_node_map[m_geometry_list[reverse_begin + + rev_segment_position] + .node_id]); } const double segment_length = - util::coordinate_calculation::greatCircleDistance( - u->lat, u->lon, v->lat, v->lon); + util::coordinate_calculation::greatCircleDistance( + util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat}); - auto reverse_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id)); + auto reverse_speed_iter = + segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id)); if (reverse_speed_iter != segment_speed_lookup.end()) { - int new_segment_weight = - std::max(1, static_cast(std::floor( - (segment_length * 10.) / (reverse_speed_iter->second / 3.6) + .5))); - m_geometry_list[reverse_begin + rev_segment_position].weight = new_segment_weight; + int new_segment_weight = std::max( + 1, static_cast(std::floor( + (segment_length * 10.) / (reverse_speed_iter->second / 3.6) + + .5))); + m_geometry_list[reverse_begin + rev_segment_position].weight = + new_segment_weight; } } } m_element_count -= current_node.object_count; - } } - + // Now save out the updated compressed geometries { std::ofstream geometry_stream(geometry_filename, std::ios::binary); if (!geometry_stream) { - throw util::exception("Failed to open "+geometry_filename+" for writing"); + throw util::exception("Failed to open " + geometry_filename + " for writing"); } const unsigned number_of_indices = m_geometry_indices.size(); const unsigned number_of_compressed_geometries = m_geometry_list.size(); - geometry_stream.write(reinterpret_cast(&number_of_indices), sizeof(unsigned)); - geometry_stream.write(reinterpret_cast(&(m_geometry_indices[0])), number_of_indices * sizeof(unsigned)); - geometry_stream.write(reinterpret_cast(&number_of_compressed_geometries), sizeof(unsigned)); - geometry_stream.write(reinterpret_cast(&(m_geometry_list[0])), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); + geometry_stream.write(reinterpret_cast(&number_of_indices), + sizeof(unsigned)); + geometry_stream.write(reinterpret_cast(&(m_geometry_indices[0])), + number_of_indices * sizeof(unsigned)); + geometry_stream.write(reinterpret_cast(&number_of_compressed_geometries), + sizeof(unsigned)); + geometry_stream.write(reinterpret_cast(&(m_geometry_list[0])), + number_of_compressed_geometries * + sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); } - - } // TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily diff --git a/src/engine/api/josn_factory.cpp b/src/engine/api/josn_factory.cpp index d5c69b5a9..fb0309d74 100644 --- a/src/engine/api/josn_factory.cpp +++ b/src/engine/api/josn_factory.cpp @@ -93,11 +93,11 @@ std::string instructionToString(extractor::TurnInstruction instruction) return token; } -util::json::Array coordinateToLonLat(const FixedPointCoordinate &coordinate) +util::json::Array coordinateToLonLat(const util::Coordinate &coordinate) { util::json::Array array; - array.values.push_back(coordinate.lon / COORDINATE_PRECISION); - array.values.push_back(coordinate.lat / COORDINATE_PRECISION); + array.values.push_back(static_cast(toFloating(coordinate.lon))); + array.values.push_back(static_cast(toFloating(coordinate.lat))); return array; } @@ -164,7 +164,7 @@ util::json::Object makeRoute(const guidance::Route &route, } util::json::Object -makeWaypoint(const FixedPointCoordinate location, std::string &&name, const Hint &hint) +makeWaypoint(const util::Coordinate location, std::string &&name, const Hint &hint) { util::json::Object waypoint; waypoint.values["location"] = detail::coordinateToLonLat(location); diff --git a/src/engine/douglas_peucker.cpp b/src/engine/douglas_peucker.cpp index e2dc953b6..c14c8632d 100644 --- a/src/engine/douglas_peucker.cpp +++ b/src/engine/douglas_peucker.cpp @@ -24,21 +24,21 @@ namespace struct CoordinatePairCalculator { CoordinatePairCalculator() = delete; - CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a, - const util::FixedPointCoordinate coordinate_b) + CoordinatePairCalculator(const util::Coordinate coordinate_a, + const util::Coordinate coordinate_b) { // initialize distance calculator with two fixed coordinates a, b - first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD; - first_lon = (coordinate_a.lon / COORDINATE_PRECISION) * util::RAD; - second_lat = (coordinate_b.lat / COORDINATE_PRECISION) * util::RAD; - second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD; + first_lon = static_cast(toFloating(coordinate_a.lon)) * util::RAD; + first_lat = static_cast(toFloating(coordinate_a.lat)) * util::RAD; + second_lon = static_cast(toFloating(coordinate_b.lon)) * util::RAD; + second_lat = static_cast(toFloating(coordinate_b.lat)) * util::RAD; } - int operator()(const util::FixedPointCoordinate other) const + int operator()(const util::Coordinate other) const { // set third coordinate c - const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD; - const float float_lon1 = (other.lon / COORDINATE_PRECISION) * util::RAD; + const float float_lon1 = static_cast(toFloating(other.lon)) * util::RAD; + const float float_lat1 = static_cast(toFloating(other.lat)) * util::RAD; // compute distance (a,c) const float x_value_1 = (first_lon - float_lon1) * cos((float_lat1 + first_lat) / 2.f); @@ -61,13 +61,12 @@ struct CoordinatePairCalculator }; } -std::vector -douglasPeucker(std::vector::const_iterator begin, - std::vector::const_iterator end, - const unsigned zoom_level) +std::vector douglasPeucker(std::vector::const_iterator begin, + std::vector::const_iterator end, + const unsigned zoom_level) { BOOST_ASSERT_MSG(zoom_level < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE, - "unsupported zoom level"); + "unsupported zoom level"); const auto size = std::distance(begin, end); if (size < 2) @@ -83,7 +82,7 @@ douglasPeucker(std::vector::const_iterator begin, std::stack recursion_stack; - recursion_stack.emplace(0UL, size-1); + recursion_stack.emplace(0UL, size - 1); // mark locations as 'necessary' by divide-and-conquer while (!recursion_stack.empty()) @@ -131,7 +130,7 @@ douglasPeucker(std::vector::const_iterator begin, } auto simplified_size = std::count(is_necessary.begin(), is_necessary.end(), true); - std::vector simplified_geometry; + std::vector simplified_geometry; simplified_geometry.reserve(simplified_size); for (auto idx : boost::irange(0UL, size)) { diff --git a/src/engine/guidance/assemble_overview.cpp b/src/engine/guidance/assemble_overview.cpp index 13c099783..aefdac9e0 100644 --- a/src/engine/guidance/assemble_overview.cpp +++ b/src/engine/guidance/assemble_overview.cpp @@ -20,10 +20,10 @@ namespace unsigned calculateOverviewZoomLevel(const std::vector &leg_geometries) { - int min_lon = std::numeric_limits::max(); - int min_lat = std::numeric_limits::max(); - int max_lon = -std::numeric_limits::max(); - int max_lat = -std::numeric_limits::max(); + util::FixedLongitude min_lon{std::numeric_limits::max()}; + util::FixedLongitude max_lon{-std::numeric_limits::max()}; + util::FixedLatitude min_lat{std::numeric_limits::max()}; + util::FixedLatitude max_lat{-std::numeric_limits::max()}; for (const auto &leg_geometry : leg_geometries) { @@ -36,12 +36,15 @@ unsigned calculateOverviewZoomLevel(const std::vector &leg_geometri } } - return util::tiles::getBBMaxZoomTile(min_lon, min_lat, max_lon, max_lat).z; + return util::tiles::getBBMaxZoomTile(toFloating(min_lon), toFloating(min_lat), + toFloating(max_lon), toFloating(max_lat)) + .z; } -std::vector simplifyGeometry(const std::vector &leg_geometries, const unsigned zoom_level) +std::vector simplifyGeometry(const std::vector &leg_geometries, + const unsigned zoom_level) { - std::vector overview_geometry; + std::vector overview_geometry; auto leg_index = 0UL; for (const auto geometry : leg_geometries) { @@ -59,8 +62,8 @@ std::vector simplifyGeometry(const std::vector -assembleOverview(const std::vector &leg_geometries, const bool use_simplification) +std::vector assembleOverview(const std::vector &leg_geometries, + const bool use_simplification) { if (use_simplification) { @@ -75,7 +78,7 @@ assembleOverview(const std::vector &leg_geometries, const bool use_ return sum + leg_geometry.locations.size(); }) - leg_geometries.size() + 1; - std::vector overview_geometry; + std::vector overview_geometry; overview_geometry.reserve(overview_size); auto leg_index = 0UL; diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 6f25b9361..e95e86163 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -26,7 +26,7 @@ namespace plugins { // Filters PhantomNodes to obtain a set of viable candiates -void filterCandidates(const std::vector &coordinates, +void filterCandidates(const std::vector &coordinates, MatchPlugin::CandidateLists &candidates_lists) { for (const auto current_coordinate : util::irange(0, coordinates.size())) diff --git a/src/engine/polyline_compressor.cpp b/src/engine/polyline_compressor.cpp index 12887030a..7f3fd2cc3 100644 --- a/src/engine/polyline_compressor.cpp +++ b/src/engine/polyline_compressor.cpp @@ -57,7 +57,6 @@ std::string encode(std::vector &numbers) } } // anonymous ns - std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end) { auto size = std::distance(begin, end); @@ -69,20 +68,22 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter std::vector delta_numbers; BOOST_ASSERT(size > 0); delta_numbers.reserve((size - 1) * 2); - util::FixedPointCoordinate previous_coordinate = {0, 0}; - std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const FixedPointCoordinate loc) - { - const int lat_diff = (loc.lat - previous_coordinate.lat) * detail::COORDINATE_TO_POLYLINE; - const int lon_diff = (loc.lon - previous_coordinate.lon) * detail::COORDINATE_TO_POLYLINE; - delta_numbers.emplace_back(lat_diff); - delta_numbers.emplace_back(lon_diff); - previous_coordinate = loc; - }); + util::Coordinate previous_coordinate{util::FixedLongitude(0), util::FixedLatitude(0)}; + std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const util::Coordinate loc) + { + const int lat_diff = static_cast(loc.lat - previous_coordinate.lat) * + detail::COORDINATE_TO_POLYLINE; + const int lon_diff = static_cast(loc.lon - previous_coordinate.lon) * + detail::COORDINATE_TO_POLYLINE; + delta_numbers.emplace_back(lat_diff); + delta_numbers.emplace_back(lon_diff); + previous_coordinate = loc; + }); return encode(delta_numbers); } -std::vector decodePolyline(const std::string &geometry_string) +std::vector decodePolyline(const std::string &geometry_string) { - std::vector new_coordinates; + std::vector new_coordinates; int index = 0, len = geometry_string.size(); int lat = 0, lng = 0; @@ -109,9 +110,9 @@ std::vector decodePolyline(const std::string &geomet int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; - util::FixedPointCoordinate p; - p.lat = lat * detail::POLYLINE_TO_COORDINATE; - p.lon = lng * detail::POLYLINE_TO_COORDINATE; + util::Coordinate p; + p.lat = util::FixedLatitude(lat * detail::POLYLINE_TO_COORDINATE); + p.lon = util::FixedLongitude(lng * detail::POLYLINE_TO_COORDINATE); new_coordinates.push_back(p); } diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 77ea0757f..002826411 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -73,10 +73,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector &nodes) #ifndef NDEBUG for (const EdgeBasedNode &node : m_edge_based_node_list) { - BOOST_ASSERT(m_node_info_list.at(node.u).lat != INT_MAX); - BOOST_ASSERT(m_node_info_list.at(node.u).lon != INT_MAX); - BOOST_ASSERT(m_node_info_list.at(node.v).lon != INT_MAX); - BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX); + BOOST_ASSERT( + util::Coordinate(m_node_info_list[node.u].lon, m_node_info_list[node.u].lat).IsValid()); + BOOST_ASSERT( + util::Coordinate(m_node_info_list[node.v].lon, m_node_info_list[node.v].lat).IsValid()); } #endif using std::swap; // Koenig swap @@ -424,8 +424,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( const QueryNode &from = m_node_info_list[previous]; const QueryNode &to = m_node_info_list[target_node.node_id]; const double segment_length = - util::coordinate_calculation::greatCircleDistance(from.lat, from.lon, - to.lat, to.lon); + util::coordinate_calculation::greatCircleDistance(from, to); edge_segment_file.write(reinterpret_cast(&to.node_id), sizeof(to.node_id)); @@ -1003,10 +1002,9 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src, { if (m_compressed_edge_container.HasEntryForID(via_eid)) { - util::FixedPointCoordinate prev = util::FixedPointCoordinate( - m_node_info_list[INVERTED ? tgt : src].lat, - m_node_info_list[INVERTED ? tgt : src].lon), - cur; + util::Coordinate prev = util::Coordinate(m_node_info_list[INVERTED ? tgt : src].lon, + m_node_info_list[INVERTED ? tgt : src].lat), + cur; // walk along the edge for the first 5 meters const auto &geometry = m_compressed_edge_container.GetBucketReference(via_eid); double dist = 0; @@ -1035,8 +1033,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src, for (auto itr = geometry.rbegin(), end = geometry.rend(); itr != end; ++itr) { const auto compressed_node = *itr; - cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat, - m_node_info_list[compressed_node.node_id].lon); + cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon, + m_node_info_list[compressed_node.node_id].lat); this_dist = util::coordinate_calculation::haversineDistance(prev, cur); if (dist + this_dist > DESIRED_SEGMENT_LENGTH) { @@ -1047,7 +1045,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src, prev = cur; prev_id = compressed_node.node_id; } - cur = util::FixedPointCoordinate(m_node_info_list[src].lat, m_node_info_list[src].lon); + cur = util::Coordinate(m_node_info_list[src].lon, m_node_info_list[src].lat); this_dist = util::coordinate_calculation::haversineDistance(prev, cur); return selectBestCandidate(src, dist + this_dist, prev_id, dist); } @@ -1056,8 +1054,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src, for (auto itr = geometry.begin(), end = geometry.end(); itr != end; ++itr) { const auto compressed_node = *itr; - cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat, - m_node_info_list[compressed_node.node_id].lon); + cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon, + m_node_info_list[compressed_node.node_id].lat); this_dist = util::coordinate_calculation::haversineDistance(prev, cur); if (dist + this_dist > DESIRED_SEGMENT_LENGTH) { @@ -1068,7 +1066,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src, prev = cur; prev_id = compressed_node.node_id; } - cur = util::FixedPointCoordinate(m_node_info_list[tgt].lat, m_node_info_list[tgt].lon); + cur = util::Coordinate(m_node_info_list[tgt].lon, m_node_info_list[tgt].lat); this_dist = util::coordinate_calculation::haversineDistance(prev, cur); return selectBestCandidate(tgt, dist + this_dist, prev_id, dist); } diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index 14cf391ed..0762d95b8 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -301,7 +301,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state) { util::SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference " - << OSMNodeID_to_uint64_t(edge_iterator->result.osm_target_id); + << static_cast(edge_iterator->result.osm_target_id); edge_iterator->result.target = SPECIAL_NODEID; ++edge_iterator; continue; @@ -314,12 +314,14 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state) BOOST_ASSERT(edge_iterator->result.osm_target_id == node_iterator->node_id); BOOST_ASSERT(edge_iterator->weight_data.speed >= 0); - BOOST_ASSERT(edge_iterator->source_coordinate.lat != std::numeric_limits::min()); - BOOST_ASSERT(edge_iterator->source_coordinate.lon != std::numeric_limits::min()); + BOOST_ASSERT(edge_iterator->source_coordinate.lat != + util::FixedLatitude(std::numeric_limits::min())); + BOOST_ASSERT(edge_iterator->source_coordinate.lon != + util::FixedLongitude(std::numeric_limits::min())); const double distance = util::coordinate_calculation::greatCircleDistance( - edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon, - node_iterator->lat, node_iterator->lon); + edge_iterator->source_coordinate, + util::Coordinate(node_iterator->lon, node_iterator->lat)); if (util::lua_function_exists(segment_state, "segment_function")) { diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index 9fd4b73dc..441ac3986 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -39,8 +39,8 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node, const ExtractionNode &result_node) { external_memory.all_nodes_list.push_back( - {static_cast(input_node.location().lat() * COORDINATE_PRECISION), - static_cast(input_node.location().lon() * COORDINATE_PRECISION), + {util::toFixed(util::FloatLongitude(input_node.location().lon())), + util::toFixed(util::FloatLatitude(input_node.location().lat())), OSMNodeID(input_node.id()), result_node.barrier, result_node.traffic_lights}); } diff --git a/src/extractor/scripting_environment.cpp b/src/extractor/scripting_environment.cpp index 4fd77c1e1..7bfae286f 100644 --- a/src/extractor/scripting_environment.cpp +++ b/src/extractor/scripting_environment.cpp @@ -31,6 +31,16 @@ auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_v return object.get_value_by_key(key, ""); } +template double latToDouble(T const &object) +{ + return static_cast(util::toFloating(object.lat)); +} + +template double lonToDouble(T const &object) +{ + return static_cast(util::toFloating(object.lon)); +} + // Error handler int luaErrorCallback(lua_State *state) { @@ -108,18 +118,18 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state) .def("get_value_by_key", &get_value_by_key) .def("id", &osmium::Way::id), luabind::class_("EdgeSource") - .property("source_coordinate", &InternalExtractorEdge::source_coordinate) - .property("weight_data", &InternalExtractorEdge::weight_data), + .def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate) + .def_readwrite("weight_data", &InternalExtractorEdge::weight_data), luabind::class_("WeightData") .def_readwrite("speed", &InternalExtractorEdge::WeightData::speed), luabind::class_("EdgeTarget") - .property("lat", &ExternalMemoryNode::lat) - .property("lon", &ExternalMemoryNode::lon), - luabind::class_("Coordinate") - .property("lat", &util::FixedPointCoordinate::lat) - .property("lon", &util::FixedPointCoordinate::lon), + .property("lon", &lonToDouble) + .property("lat", &latToDouble), + luabind::class_("Coordinate") + .property("lon", &lonToDouble) + .property("lat", &latToDouble), luabind::class_("RasterDatum") - .property("datum", &RasterDatum::datum) + .def_readonly("datum", &RasterDatum::datum) .def("invalid_data", &RasterDatum::get_invalid)]; if (0 != luaL_dofile(lua_state, file_name.c_str())) diff --git a/src/server/api/url_parser.cpp b/src/server/api/url_parser.cpp index 90768bd35..f75b7227b 100644 --- a/src/server/api/url_parser.cpp +++ b/src/server/api/url_parser.cpp @@ -47,9 +47,9 @@ struct URLGrammar : boost::spirit::qi::grammar }; const auto add_coordinate = [this](const boost::fusion::vector &lonLat) { - parsed_url.coordinates.emplace_back( - util::FixedPointCoordinate(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION, - boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION)); + parsed_url.coordinates.emplace_back(util::Coordinate( + util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION), + util::FixedLatitude(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION))); }; const auto polyline_to_coordinates = [this](const std::string &polyline) { diff --git a/src/server/service/match_service.cpp b/src/server/service/match_service.cpp index 2f519fc2e..39b2e8da0 100644 --- a/src/server/service/match_service.cpp +++ b/src/server/service/match_service.cpp @@ -40,7 +40,7 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters ¶meters) } } // anon. ns -engine::Status MatchService::RunQuery(std::vector coordinates, +engine::Status MatchService::RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) { diff --git a/src/server/service/nearest_service.cpp b/src/server/service/nearest_service.cpp index 067bd70aa..e0c41b066 100644 --- a/src/server/service/nearest_service.cpp +++ b/src/server/service/nearest_service.cpp @@ -39,7 +39,7 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters ¶meters) } } // anon. ns -engine::Status NearestService::RunQuery(std::vector coordinates, +engine::Status NearestService::RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) { diff --git a/src/server/service/route_service.cpp b/src/server/service/route_service.cpp index a715662d6..f4c791e71 100644 --- a/src/server/service/route_service.cpp +++ b/src/server/service/route_service.cpp @@ -38,7 +38,7 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters ¶meters) } } // anon. ns -engine::Status RouteService::RunQuery(std::vector coordinates, +engine::Status RouteService::RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) { diff --git a/src/server/service/table_service.cpp b/src/server/service/table_service.cpp index 1d9e2bc0c..a0393a050 100644 --- a/src/server/service/table_service.cpp +++ b/src/server/service/table_service.cpp @@ -57,7 +57,7 @@ std::string getWrongOptionHelp(const engine::api::TableParameters ¶meters) } } // anon. ns -engine::Status TableService::RunQuery(std::vector coordinates, +engine::Status TableService::RunQuery(std::vector coordinates, std::string &options, util::json::Object &result) { diff --git a/src/server/service/trip_service.cpp b/src/server/service/trip_service.cpp index 698018cfd..1e9e5fec0 100644 --- a/src/server/service/trip_service.cpp +++ b/src/server/service/trip_service.cpp @@ -38,9 +38,9 @@ std::string getWrongOptionHelp(const engine::api::TripParameters ¶meters) } } // anon. ns -engine::Status TripService::RunQuery(std::vector coordinates, - std::string &options, - util::json::Object &result) +engine::Status TripService::RunQuery(std::vector coordinates, + std::string &options, + util::json::Object &result) { auto options_iterator = options.begin(); auto parameters = @@ -67,7 +67,6 @@ engine::Status TripService::RunQuery(std::vector coo return BaseService::routing_machine.Trip(*parameters, result); } - } } } diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index f7cd366c4..2c2361256 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -17,8 +17,7 @@ #include "util/exception.hpp" #include "util/simple_logger.hpp" #include "util/typedefs.hpp" - -#include "osrm/coordinate.hpp" +#include "util/coordinate.hpp" #ifdef __linux__ #include @@ -38,11 +37,9 @@ namespace osrm namespace storage { -using RTreeLeaf = - typename engine::datafacade::BaseDataFacade::RTreeLeaf; -using RTreeNode = util::StaticRTree::vector, - true>::TreeNode; +using RTreeLeaf = typename engine::datafacade::BaseDataFacade::RTreeLeaf; +using RTreeNode = + util::StaticRTree::vector, true>::TreeNode; using QueryGraph = util::StaticGraph; // delete a shared memory region. report warning if it could not be deleted @@ -309,8 +306,8 @@ int Storage::Run() boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary); unsigned coordinate_list_size = 0; nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned)); - shared_layout_ptr->SetBlockSize(SharedDataLayout::COORDINATE_LIST, - coordinate_list_size); + shared_layout_ptr->SetBlockSize(SharedDataLayout::COORDINATE_LIST, + coordinate_list_size); // load geometries sizes std::ifstream geometry_input_stream(geometries_data_path.string().c_str(), std::ios::binary); @@ -438,15 +435,14 @@ int Storage::Run() } // Loading list of coordinates - util::FixedPointCoordinate *coordinates_ptr = - shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::COORDINATE_LIST); + util::Coordinate *coordinates_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::COORDINATE_LIST); extractor::QueryNode current_node; for (unsigned i = 0; i < coordinate_list_size; ++i) { nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode)); - coordinates_ptr[i] = util::FixedPointCoordinate(current_node.lat, current_node.lon); + coordinates_ptr[i] = util::Coordinate(current_node.lon, current_node.lat); } nodes_input_stream.close(); diff --git a/src/util/coordinate.cpp b/src/util/coordinate.cpp index 2d6c75df5..f98995c58 100644 --- a/src/util/coordinate.cpp +++ b/src/util/coordinate.cpp @@ -16,49 +16,52 @@ namespace osrm namespace util { -FixedPointCoordinate::FixedPointCoordinate() - : lat(std::numeric_limits::min()), lon(std::numeric_limits::min()) +Coordinate::Coordinate() + : lon(std::numeric_limits::min()), lat(std::numeric_limits::min()) { } -FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon) +Coordinate::Coordinate(const FloatLongitude lon_, const FloatLatitude lat_) + : Coordinate(toFixed(lon_), toFixed(lat_)) +{ +} + +Coordinate::Coordinate(const FixedLongitude lon_, const FixedLatitude lat_) : lon(lon_), lat(lat_) { #ifndef NDEBUG - if (0 != (std::abs(lat) >> 30)) + if (0 != (std::abs(static_cast(lon)) >> 30)) { - std::bitset<32> y_coordinate_vector(lat); - SimpleLogger().Write(logDEBUG) << "broken lat: " << lat - << ", bits: " << y_coordinate_vector; - } - if (0 != (std::abs(lon) >> 30)) - { - std::bitset<32> x_coordinate_vector(lon); + std::bitset<32> x_coordinate_vector(static_cast(lon)); SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x_coordinate_vector; } + if (0 != (std::abs(static_cast(lat)) >> 30)) + { + std::bitset<32> y_coordinate_vector(static_cast(lat)); + SimpleLogger().Write(logDEBUG) << "broken lat: " << lat + << ", bits: " << y_coordinate_vector; + } #endif } -bool FixedPointCoordinate::IsValid() const +bool Coordinate::IsValid() const { - return !(lat > 90 * COORDINATE_PRECISION || lat < -90 * COORDINATE_PRECISION || - lon > 180 * COORDINATE_PRECISION || lon < -180 * COORDINATE_PRECISION); + return !(lat > FixedLatitude(90 * COORDINATE_PRECISION) || + lat < FixedLatitude(-90 * COORDINATE_PRECISION) || + lon > FixedLongitude(180 * COORDINATE_PRECISION) || + lon < FixedLongitude(-180 * COORDINATE_PRECISION)); } -bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs) +bool operator==(const Coordinate lhs, const Coordinate rhs) { return lhs.lat == rhs.lat && lhs.lon == rhs.lon; } -bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs) -{ - return !(lhs == rhs); -} +bool operator!=(const Coordinate lhs, const Coordinate rhs) { return !(lhs == rhs); } -std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate) +std::ostream &operator<<(std::ostream &out, const Coordinate coordinate) { - out << "(" << static_cast(coordinate.lat / COORDINATE_PRECISION) << "," - << static_cast(coordinate.lon / COORDINATE_PRECISION) << ")"; + out << "(lon:" << toFloating(coordinate.lon) << ", lat:" << toFloating(coordinate.lat) << ")"; return out; } } diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 61fd77cab..f8aad77ef 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -17,12 +17,16 @@ namespace util namespace coordinate_calculation { -double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2) +double haversineDistance(const Coordinate coordinate_1, const Coordinate coordinate_2) { - BOOST_ASSERT(lat1 != std::numeric_limits::min()); + auto lon1 = static_cast(coordinate_1.lon); + auto lat1 = static_cast(coordinate_1.lat); + auto lon2 = static_cast(coordinate_2.lon); + auto lat2 = static_cast(coordinate_2.lat); BOOST_ASSERT(lon1 != std::numeric_limits::min()); - BOOST_ASSERT(lat2 != std::numeric_limits::min()); + BOOST_ASSERT(lat1 != std::numeric_limits::min()); BOOST_ASSERT(lon2 != std::numeric_limits::min()); + BOOST_ASSERT(lat2 != std::numeric_limits::min()); const double lt1 = lat1 / COORDINATE_PRECISION; const double ln1 = lon1 / COORDINATE_PRECISION; const double lt2 = lat2 / COORDINATE_PRECISION; @@ -42,22 +46,12 @@ 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) -{ - return haversineDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, - coordinate_2.lon); -} - -double greatCircleDistance(const FixedPointCoordinate coordinate_1, - const FixedPointCoordinate coordinate_2) -{ - return greatCircleDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, - coordinate_2.lon); -} - -double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2) +double greatCircleDistance(const Coordinate coordinate_1, const Coordinate coordinate_2) { + auto lon1 = static_cast(coordinate_1.lon); + auto lat1 = static_cast(coordinate_1.lat); + auto lon2 = static_cast(coordinate_2.lon); + auto lat2 = static_cast(coordinate_2.lat); BOOST_ASSERT(lat1 != std::numeric_limits::min()); BOOST_ASSERT(lon1 != std::numeric_limits::min()); BOOST_ASSERT(lat2 != std::numeric_limits::min()); @@ -73,65 +67,65 @@ 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 Coordinate source_coordinate, + const Coordinate target_coordinate, + const Coordinate query_location) { double ratio; - FixedPointCoordinate nearest_location; + Coordinate nearest_location; return perpendicularDistance(source_coordinate, target_coordinate, query_location, nearest_location, ratio); } -double perpendicularDistance(const FixedPointCoordinate segment_source, - const FixedPointCoordinate segment_target, - const FixedPointCoordinate query_location, - FixedPointCoordinate &nearest_location, +double perpendicularDistance(const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate query_location, + Coordinate &nearest_location, double &ratio) { using namespace coordinate_calculation; return perpendicularDistanceFromProjectedCoordinate( segment_source, segment_target, query_location, - {mercator::latToY(query_location.lat / COORDINATE_PRECISION), - query_location.lon / COORDINATE_PRECISION}, + {static_cast(toFloating(query_location.lon)), + mercator::latToY(toFloating(query_location.lat))}, nearest_location, ratio); } -double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate source_coordinate, - const FixedPointCoordinate target_coordinate, - const FixedPointCoordinate query_location, - const std::pair projected_coordinate) +double perpendicularDistanceFromProjectedCoordinate( + const Coordinate source_coordinate, + const Coordinate target_coordinate, + const Coordinate query_location, + const std::pair projected_xy_coordinate) { double ratio; - FixedPointCoordinate nearest_location; + Coordinate nearest_location; return perpendicularDistanceFromProjectedCoordinate(source_coordinate, target_coordinate, - query_location, projected_coordinate, + query_location, projected_xy_coordinate, nearest_location, ratio); } -double -perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, - const FixedPointCoordinate segment_target, - const FixedPointCoordinate query_location, - const std::pair projected_coordinate, - FixedPointCoordinate &nearest_location, - double &ratio) +double perpendicularDistanceFromProjectedCoordinate( + const Coordinate segment_source, + const Coordinate segment_target, + const Coordinate query_location, + const std::pair projected_xy_coordinate, + Coordinate &nearest_location, + double &ratio) { using namespace coordinate_calculation; BOOST_ASSERT(query_location.IsValid()); // initialize values - const double x = projected_coordinate.first; - const double y = projected_coordinate.second; - const double a = mercator::latToY(segment_source.lat / COORDINATE_PRECISION); - const double b = segment_source.lon / COORDINATE_PRECISION; - const double c = mercator::latToY(segment_target.lat / COORDINATE_PRECISION); - const double d = segment_target.lon / COORDINATE_PRECISION; + const double x = projected_xy_coordinate.first; + const double y = projected_xy_coordinate.second; + const double a = mercator::latToY(toFloating(segment_source.lat)); + const double b = static_cast(toFloating(segment_source.lon)); + const double c = mercator::latToY(toFloating(segment_target.lat)); + const double d = static_cast(toFloating(segment_target.lon)); double p, q /*,mX*/, new_y; if (std::abs(a - c) > std::numeric_limits::epsilon()) { @@ -184,8 +178,8 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_ else { // point lies in between - nearest_location.lat = static_cast(mercator::yToLat(p) * COORDINATE_PRECISION); - nearest_location.lon = static_cast(q * COORDINATE_PRECISION); + nearest_location.lon = toFixed(FloatLongitude(q)); + nearest_location.lat = toFixed(FloatLatitude(mercator::yToLat(p))); } BOOST_ASSERT(nearest_location.IsValid()); @@ -206,14 +200,13 @@ double radToDeg(const double radian) return radian * (180.0 * (1. / pi())); } -double bearing(const FixedPointCoordinate first_coordinate, - const FixedPointCoordinate second_coordinate) +double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate) { const double lon_diff = - second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION; + static_cast(toFloating(second_coordinate.lon - first_coordinate.lon)); const double lon_delta = degToRad(lon_diff); - const double lat1 = degToRad(first_coordinate.lat / COORDINATE_PRECISION); - const double lat2 = degToRad(second_coordinate.lat / COORDINATE_PRECISION); + const double lat1 = degToRad(static_cast(toFloating(first_coordinate.lat))); + const double lat2 = degToRad(static_cast(toFloating(second_coordinate.lat))); const double y = std::sin(lon_delta) * std::cos(lat2); const double x = std::cos(lat1) * std::sin(lat2) - std::sin(lat1) * std::cos(lat2) * std::cos(lon_delta); @@ -230,19 +223,17 @@ double bearing(const FixedPointCoordinate first_coordinate, return result; } -double computeAngle(const FixedPointCoordinate first, - const FixedPointCoordinate second, - const FixedPointCoordinate third) +double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third) { using namespace boost::math::constants; using namespace coordinate_calculation; - const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION; - const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) - - mercator::latToY(second.lat / COORDINATE_PRECISION); - const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION; - const double v2y = mercator::latToY(third.lat / COORDINATE_PRECISION) - - mercator::latToY(second.lat / COORDINATE_PRECISION); + const double v1x = static_cast(toFloating(first.lon - second.lon)); + const double v1y = + mercator::latToY(toFloating(first.lat)) - mercator::latToY(toFloating(second.lat)); + const double v2x = static_cast(toFloating(third.lon - second.lon)); + const double v2y = + mercator::latToY(toFloating(third.lat)) - mercator::latToY(toFloating(second.lat)); double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / pi(); @@ -256,20 +247,22 @@ double computeAngle(const FixedPointCoordinate first, namespace mercator { -double yToLat(const double value) +FloatLatitude yToLat(const double value) { using namespace boost::math::constants; - return 180. * (1. / pi()) * - (2. * std::atan(std::exp(value * pi() / 180.)) - half_pi()); + return FloatLatitude( + 180. * (1. / pi()) * + (2. * std::atan(std::exp(value * pi() / 180.)) - half_pi())); } -double latToY(const double latitude) +double latToY(const FloatLatitude latitude) { using namespace boost::math::constants; return 180. * (1. / pi()) * - std::log(std::tan((pi() / 4.) + latitude * (pi() / 180.) / 2.)); + std::log(std::tan((pi() / 4.) + + static_cast(latitude) * (pi() / 180.) / 2.)); } } // ns mercato // ns mercatorr } // ns coordinate_calculation diff --git a/src/util/hilbert_value.cpp b/src/util/hilbert_value.cpp index 15f0c08c0..a1505ee67 100644 --- a/src/util/hilbert_value.cpp +++ b/src/util/hilbert_value.cpp @@ -8,7 +8,7 @@ namespace util namespace { -std::uint64_t bitInterleaving(const std::uint32_t latitude, const std::uint32_t longitude) +std::uint64_t bitInterleaving(const std::uint32_t longitude, const std::uint32_t latitude) { std::uint64_t result = 0; for (std::int8_t index = 31; index >= 0; --index) @@ -69,11 +69,13 @@ void transposeCoordinate(std::uint32_t *x) } } // anonymous ns -std::uint64_t hilbertCode(const FixedPointCoordinate coordinate) +std::uint64_t hilbertCode(const Coordinate coordinate) { - unsigned location[2]; - location[0] = coordinate.lat + static_cast(90 * COORDINATE_PRECISION); - location[1] = coordinate.lon + static_cast(180 * COORDINATE_PRECISION); + std::uint32_t location[2]; + location[0] = static_cast(coordinate.lon) + + static_cast(180 * COORDINATE_PRECISION); + location[1] = static_cast(coordinate.lat) + + static_cast(90 * COORDINATE_PRECISION); transposeCoordinate(location); return bitInterleaving(location[0], location[1]); diff --git a/unit_tests/engine/douglas_peucker.cpp b/unit_tests/engine/douglas_peucker.cpp index 93143d071..a1290eba5 100644 --- a/unit_tests/engine/douglas_peucker.cpp +++ b/unit_tests/engine/douglas_peucker.cpp @@ -21,15 +21,15 @@ BOOST_AUTO_TEST_CASE(removed_middle_test) / \ x x */ - std::vector coordinates = { - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 5 * COORDINATE_PRECISION), - util::FixedPointCoordinate(6 * COORDINATE_PRECISION, 6 * COORDINATE_PRECISION), - util::FixedPointCoordinate(10 * COORDINATE_PRECISION, 10 * COORDINATE_PRECISION), - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 15 * COORDINATE_PRECISION)}; + std::vector coordinates = { + util::Coordinate(util::FloatLongitude(5), util::FloatLatitude(5)), + util::Coordinate(util::FloatLongitude(6), util::FloatLatitude(6)), + util::Coordinate(util::FloatLongitude(10), util::FloatLatitude(10)), + util::Coordinate(util::FloatLongitude(15), util::FloatLatitude(5))}; // FIXME this test fails for everything below z4 because the DP algorithms // only used a naive distance measurement - //for (unsigned z = 0; z < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE; z++) + // for (unsigned z = 0; z < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE; z++) for (unsigned z = 0; z < 2; z++) { auto result = douglasPeucker(coordinates, z); @@ -51,20 +51,22 @@ BOOST_AUTO_TEST_CASE(remove_second_node_test) | x */ - std::vector input = { - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 5 * COORDINATE_PRECISION), - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, - 5 * COORDINATE_PRECISION + - detail::DOUGLAS_PEUCKER_THRESHOLDS[z]), - util::FixedPointCoordinate(10 * COORDINATE_PRECISION, 10 * COORDINATE_PRECISION), - util::FixedPointCoordinate(10 * COORDINATE_PRECISION, - 10 + COORDINATE_PRECISION + - detail::DOUGLAS_PEUCKER_THRESHOLDS[z] * 2), - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 15 * COORDINATE_PRECISION), - util::FixedPointCoordinate(5 * COORDINATE_PRECISION + - detail::DOUGLAS_PEUCKER_THRESHOLDS[z], - 15 * COORDINATE_PRECISION), - }; + std::vector input = { + util::Coordinate(util::FixedLongitude(5 * COORDINATE_PRECISION), + util::FixedLatitude(5 * COORDINATE_PRECISION)), + util::Coordinate(util::FixedLongitude(5 * COORDINATE_PRECISION), + util::FixedLatitude(5 * COORDINATE_PRECISION + + detail::DOUGLAS_PEUCKER_THRESHOLDS[z])), + util::Coordinate(util::FixedLongitude(10 * COORDINATE_PRECISION), + util::FixedLatitude(10 * COORDINATE_PRECISION)), + util::Coordinate(util::FixedLongitude(10 * COORDINATE_PRECISION), + util::FixedLatitude(10 + COORDINATE_PRECISION + + detail::DOUGLAS_PEUCKER_THRESHOLDS[z] * 2)), + util::Coordinate(util::FixedLongitude(5 * COORDINATE_PRECISION), + util::FixedLatitude(15 * COORDINATE_PRECISION)), + util::Coordinate(util::FixedLongitude(5 * COORDINATE_PRECISION + + detail::DOUGLAS_PEUCKER_THRESHOLDS[z]), + util::FixedLatitude(15 * COORDINATE_PRECISION))}; BOOST_TEST_MESSAGE("Threshold (" << z << "): " << detail::DOUGLAS_PEUCKER_THRESHOLDS[z]); auto result = douglasPeucker(input, z); BOOST_CHECK_EQUAL(result.size(), 4); diff --git a/unit_tests/engine/geometry_string.cpp b/unit_tests/engine/geometry_string.cpp index b4fde0287..5209460ec 100644 --- a/unit_tests/engine/geometry_string.cpp +++ b/unit_tests/engine/geometry_string.cpp @@ -17,36 +17,28 @@ using namespace osrm::engine; BOOST_AUTO_TEST_CASE(decode) { // Polyline string for the 5 coordinates - const std::string polyline = "_gjaR_gjaR_pR_ibE_pR_ibE_pR_ibE_pR_ibE"; + const std::string polyline = "_c`|@_c`|@o}@_pRo}@_pRo}@_pRo}@_pR"; const auto coords = decodePolyline(polyline); // Test coordinates; these would be the coordinates we give the loc parameter, // e.g. loc=10.00,10.0&loc=10.01,10.1... - util::FixedPointCoordinate coord1(10.00 * COORDINATE_PRECISION, 10.0 * COORDINATE_PRECISION); - util::FixedPointCoordinate coord2(10.01 * COORDINATE_PRECISION, 10.1 * COORDINATE_PRECISION); - util::FixedPointCoordinate coord3(10.02 * COORDINATE_PRECISION, 10.2 * COORDINATE_PRECISION); - util::FixedPointCoordinate coord4(10.03 * COORDINATE_PRECISION, 10.3 * COORDINATE_PRECISION); - util::FixedPointCoordinate coord5(10.04 * COORDINATE_PRECISION, 10.4 * COORDINATE_PRECISION); + util::Coordinate coord1(util::FloatLongitude(10.0), util::FloatLatitude(10.00)); + util::Coordinate coord2(util::FloatLongitude(10.1), util::FloatLatitude(10.01)); + util::Coordinate coord3(util::FloatLongitude(10.2), util::FloatLatitude(10.02)); + util::Coordinate coord4(util::FloatLongitude(10.3), util::FloatLatitude(10.03)); + util::Coordinate coord5(util::FloatLongitude(10.4), util::FloatLatitude(10.04)); // Put the test coordinates into the vector for comparison - std::vector cmp_coords; - cmp_coords.emplace_back(coord1); - cmp_coords.emplace_back(coord2); - cmp_coords.emplace_back(coord3); - cmp_coords.emplace_back(coord4); - cmp_coords.emplace_back(coord5); + std::vector cmp_coords = {coord1, coord2, coord3, coord4, coord5}; BOOST_CHECK_EQUAL(cmp_coords.size(), coords.size()); for (unsigned i = 0; i < cmp_coords.size(); ++i) { - const double cmp1_lat = coords.at(i).lat; - const double cmp2_lat = cmp_coords.at(i).lat; - BOOST_CHECK_CLOSE(cmp1_lat, cmp2_lat, 0.0001); - - const double cmp1_lon = coords.at(i).lon; - const double cmp2_lon = cmp_coords.at(i).lon; - BOOST_CHECK_CLOSE(cmp1_lon, cmp2_lon, 0.0001); + BOOST_CHECK_CLOSE(static_cast(util::toFloating(coords[i].lat)), + static_cast(util::toFloating(cmp_coords[i].lat)), 0.0001); + BOOST_CHECK_CLOSE(static_cast(util::toFloating(coords[i].lon)), + static_cast(util::toFloating(cmp_coords[i].lon)), 0.0001); } } diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index d9fa68a3e..951eed254 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -1,5 +1,9 @@ #include "server/api/parameters_parser.hpp" +#include "engine/api/base_parameters.hpp" +#include "engine/api/route_parameters.hpp" +#include "engine/api/table_parameters.hpp" + #include namespace osrm @@ -156,7 +160,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) engine::api::RouteParameters::GeometriesType::Polyline, engine::api::RouteParameters::OverviewType::Simplified, std::vector>{}, - std::vector{}, + std::vector{}, hints_4, std::vector>{}, std::vector>{}}; @@ -186,7 +190,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) engine::api::RouteParameters::GeometriesType::Polyline, engine::api::RouteParameters::OverviewType::Simplified, std::vector>{}, - std::vector{}, + std::vector{}, std::vector> {}, std::vector>{}, bearings_4}; diff --git a/unit_tests/server/url_parser.cpp b/unit_tests/server/url_parser.cpp index 613ba9f33..140f43195 100644 --- a/unit_tests/server/url_parser.cpp +++ b/unit_tests/server/url_parser.cpp @@ -57,11 +57,11 @@ BOOST_AUTO_TEST_CASE(invalid_urls) BOOST_AUTO_TEST_CASE(valid_urls) { - std::vector coords_1 = { + std::vector coords_1 = { // lat,lon - util::FixedPointCoordinate(1 * COORDINATE_PRECISION, 0 * COORDINATE_PRECISION), - util::FixedPointCoordinate(3 * COORDINATE_PRECISION, 2 * COORDINATE_PRECISION), - util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 4 * COORDINATE_PRECISION), + util::Coordinate(util::FloatLongitude(0), util::FloatLatitude(1)), + util::Coordinate(util::FloatLongitude(2), util::FloatLatitude(3)), + util::Coordinate(util::FloatLongitude(4), util::FloatLatitude(5)), }; api::ParsedURL reference_1{"route", 1, "profile", coords_1, "options=value&foo=bar"}; auto result_1 = api::parseURL("/route/v1/profile/0,1;2,3;4,5?options=value&foo=bar"); @@ -83,9 +83,8 @@ BOOST_AUTO_TEST_CASE(valid_urls) BOOST_CHECK_EQUAL(reference_2.options, result_2->options); // one coordinate - std::vector coords_3 = { - // lat,lon - util::FixedPointCoordinate(1 * COORDINATE_PRECISION, 0 * COORDINATE_PRECISION), + std::vector coords_3 = { + util::Coordinate(util::FloatLongitude(0), util::FloatLatitude(1)), }; api::ParsedURL reference_3{"route", 1, "profile", coords_3, ""}; auto result_3 = api::parseURL("/route/v1/profile/0,1"); diff --git a/unit_tests/util/coordinate.cpp b/unit_tests/util/coordinate.cpp index 8c32f080c..4fdf2640a 100644 --- a/unit_tests/util/coordinate.cpp +++ b/unit_tests/util/coordinate.cpp @@ -12,14 +12,14 @@ using namespace osrm::util; // Regression test for bug captured in #1347 BOOST_AUTO_TEST_CASE(regression_test_1347) { - FixedPointCoordinate u(10 * COORDINATE_PRECISION, -100 * COORDINATE_PRECISION); - FixedPointCoordinate v(10.001 * COORDINATE_PRECISION, -100.002 * COORDINATE_PRECISION); - FixedPointCoordinate q(10.002 * COORDINATE_PRECISION, -100.001 * COORDINATE_PRECISION); + Coordinate u(FloatLongitude(-100), FloatLatitude(10)); + Coordinate v(FloatLongitude(-100.002), FloatLatitude(10.001)); + Coordinate q(FloatLongitude(-100.001), FloatLatitude(10.002)); double d1 = coordinate_calculation::perpendicularDistance(u, v, q); double ratio; - FixedPointCoordinate nearest_location; + Coordinate nearest_location; double d2 = coordinate_calculation::perpendicularDistance(u, v, q, nearest_location, ratio); BOOST_CHECK_LE(std::abs(d1 - d2), 0.01); diff --git a/unit_tests/util/rectangle.cpp b/unit_tests/util/rectangle.cpp index 12bfdb630..b35f5d32c 100644 --- a/unit_tests/util/rectangle.cpp +++ b/unit_tests/util/rectangle.cpp @@ -26,23 +26,23 @@ BOOST_AUTO_TEST_CASE(get_min_dist_test) // | // +- -80 // | - RectangleInt2D nw(10 * COORDINATE_PRECISION, 80 * COORDINATE_PRECISION, - 10 * COORDINATE_PRECISION, 100 * COORDINATE_PRECISION); - RectangleInt2D ne(10 * COORDINATE_PRECISION, 80 * COORDINATE_PRECISION, - -100 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION); - RectangleInt2D sw(-80 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION, - 10 * COORDINATE_PRECISION, 100 * COORDINATE_PRECISION); - RectangleInt2D se(-80 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION, - -100 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION); + RectangleInt2D nw{FloatLongitude(10), FloatLongitude(100), FloatLatitude(10), + FloatLatitude(80)}; + // RectangleInt2D ne {FloatLongitude(-100), FloatLongitude(-10), FloatLatitude(10), + // FloatLatitude(80)}; + // RectangleInt2D sw {FloatLongitude(10), FloatLongitude(100), FloatLatitude(-80), + // FloatLatitude(-10)}; + RectangleInt2D se{FloatLongitude(-100), FloatLongitude(-10), FloatLatitude(-80), + FloatLatitude(-10)}; - FixedPointCoordinate nw_sw(9.9 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); - FixedPointCoordinate nw_se(9.9 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); - FixedPointCoordinate nw_ne(80.1 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); - FixedPointCoordinate nw_nw(80.1 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); - FixedPointCoordinate nw_s(9.9 * COORDINATE_PRECISION, 55 * COORDINATE_PRECISION); - FixedPointCoordinate nw_e(45.0 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); - FixedPointCoordinate nw_w(45.0 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); - FixedPointCoordinate nw_n(80.1 * COORDINATE_PRECISION, 55 * COORDINATE_PRECISION); + Coordinate nw_sw{FloatLongitude(9.9), FloatLatitude(9.9)}; + Coordinate nw_se{FloatLongitude(100.1), FloatLatitude(9.9)}; + Coordinate nw_ne{FloatLongitude(100.1), FloatLatitude(80.1)}; + Coordinate nw_nw{FloatLongitude(9.9), FloatLatitude(80.1)}; + Coordinate nw_s{FloatLongitude(55), FloatLatitude(9.9)}; + Coordinate nw_e{FloatLongitude(100.1), FloatLatitude(45.0)}; + Coordinate nw_w{FloatLongitude(9.9), FloatLatitude(45.0)}; + Coordinate nw_n{FloatLongitude(55), FloatLatitude(80.1)}; BOOST_CHECK_CLOSE(nw.GetMinDist(nw_sw), 15611.9, 0.1); BOOST_CHECK_CLOSE(nw.GetMinDist(nw_se), 15611.9, 0.1); BOOST_CHECK_CLOSE(nw.GetMinDist(nw_ne), 11287.4, 0.1); @@ -52,14 +52,14 @@ BOOST_AUTO_TEST_CASE(get_min_dist_test) BOOST_CHECK_CLOSE(nw.GetMinDist(nw_w), 7864.89, 0.1); BOOST_CHECK_CLOSE(nw.GetMinDist(nw_n), 11122.6, 0.1); - FixedPointCoordinate se_ne(-9.9 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); - FixedPointCoordinate se_nw(-9.9 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); - FixedPointCoordinate se_sw(-80.1 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); - FixedPointCoordinate se_se(-80.1 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); - FixedPointCoordinate se_n(-9.9 * COORDINATE_PRECISION, -55 * COORDINATE_PRECISION); - FixedPointCoordinate se_w(-45.0 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); - FixedPointCoordinate se_e(-45.0 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); - FixedPointCoordinate se_s(-80.1 * COORDINATE_PRECISION, -55 * COORDINATE_PRECISION); + Coordinate se_ne{FloatLongitude(-9.9), FloatLatitude(-9.9)}; + Coordinate se_nw{FloatLongitude(-100.1), FloatLatitude(-9.9)}; + Coordinate se_sw{FloatLongitude(-100.1), FloatLatitude(-80.1)}; + Coordinate se_se{FloatLongitude(-9.9), FloatLatitude(-80.1)}; + Coordinate se_n{FloatLongitude(-55), FloatLatitude(-9.9)}; + Coordinate se_w{FloatLongitude(-100.1), FloatLatitude(-45.0)}; + Coordinate se_e{FloatLongitude(-9.9), FloatLatitude(-45.0)}; + Coordinate se_s{FloatLongitude(-55), FloatLatitude(-80.1)}; BOOST_CHECK_CLOSE(se.GetMinDist(se_sw), 11287.4, 0.1); BOOST_CHECK_CLOSE(se.GetMinDist(se_se), 11287.4, 0.1); BOOST_CHECK_CLOSE(se.GetMinDist(se_ne), 15611.9, 0.1); diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index bec4527ef..c51aa070b 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -38,11 +38,11 @@ constexpr uint32_t TEST_LEAF_NODE_SIZE = 64; using TestData = extractor::EdgeBasedNode; using TestStaticRTree = StaticRTree, + std::vector, false, TEST_BRANCHING_FACTOR, TEST_LEAF_NODE_SIZE>; -using MiniStaticRTree = StaticRTree, false, 2, 3>; +using MiniStaticRTree = StaticRTree, false, 2, 3>; // Choosen by a fair W20 dice roll (this value is completely arbitrary) constexpr unsigned RANDOM_SEED = 42; @@ -54,14 +54,13 @@ static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; template class LinearSearchNN { public: - LinearSearchNN(const std::shared_ptr> &coords, + LinearSearchNN(const std::shared_ptr> &coords, const std::vector &edges) : coords(coords), edges(edges) { } - std::vector Nearest(const FixedPointCoordinate &input_coordinate, - const unsigned num_results) + std::vector Nearest(const Coordinate &input_coordinate, const unsigned num_results) { std::vector local_edges(edges); @@ -70,7 +69,7 @@ template class LinearSearchNN [this, &input_coordinate](const DataT &lhs, const DataT &rhs) { double current_ratio = 0.; - FixedPointCoordinate nearest; + Coordinate nearest; const double lhs_dist = coordinate_calculation::perpendicularDistance( coords->at(lhs.u), coords->at(lhs.v), input_coordinate, nearest, current_ratio); const double rhs_dist = coordinate_calculation::perpendicularDistance( @@ -83,7 +82,7 @@ template class LinearSearchNN } private: - const std::shared_ptr> &coords; + const std::shared_ptr> &coords; const std::vector &edges; }; @@ -103,7 +102,7 @@ template struct RandomGraphFixture } }; - RandomGraphFixture() : coords(std::make_shared>()) + RandomGraphFixture() : coords(std::make_shared>()) { BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges."); @@ -114,10 +113,11 @@ template struct RandomGraphFixture for (unsigned i = 0; i < NUM_NODES; i++) { - int lat = lat_udist(g); int lon = lon_udist(g); - nodes.emplace_back(extractor::QueryNode(lat, lon, OSMNodeID(i))); - coords->emplace_back(FixedPointCoordinate(lat, lon)); + int lat = lat_udist(g); + nodes.emplace_back( + extractor::QueryNode(FixedLongitude(lat), FixedLatitude(lon), OSMNodeID(i))); + coords->emplace_back(Coordinate(FixedLongitude(lon), FixedLatitude(lat))); } std::uniform_int_distribution<> edge_udist(0, nodes.size() - 1); @@ -140,23 +140,22 @@ template struct RandomGraphFixture } std::vector nodes; - std::shared_ptr> coords; + std::shared_ptr> coords; std::vector edges; }; struct GraphFixture { - GraphFixture(const std::vector> &input_coords, + GraphFixture(const std::vector> &input_coords, const std::vector> &input_edges) - : coords(std::make_shared>()) + : coords(std::make_shared>()) { for (unsigned i = 0; i < input_coords.size(); i++) { - FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION, - input_coords[i].second * COORDINATE_PRECISION); - coords->emplace_back(c); - nodes.emplace_back(extractor::QueryNode(c.lat, c.lon, OSMNodeID(i))); + coords->emplace_back(input_coords[i].first, input_coords[i].second); + nodes.emplace_back(extractor::QueryNode(toFixed(input_coords[i].first), + toFixed(input_coords[i].second), OSMNodeID(i))); } for (const auto &pair : input_edges) @@ -175,7 +174,7 @@ struct GraphFixture } std::vector nodes; - std::shared_ptr> coords; + std::shared_ptr> coords; std::vector edges; }; @@ -194,14 +193,14 @@ typedef RandomGraphFixture void simple_verify_rtree(RTreeT &rtree, - const std::shared_ptr> &coords, + const std::shared_ptr> &coords, const std::vector &edges) { BOOST_TEST_MESSAGE("Verify end points"); for (const auto &e : edges) { - const FixedPointCoordinate &pu = coords->at(e.u); - const FixedPointCoordinate &pv = coords->at(e.v); + const Coordinate &pu = coords->at(e.u); + const Coordinate &pv = coords->at(e.v); auto result_u = rtree.Nearest(pu, 1); auto result_v = rtree.Nearest(pv, 1); BOOST_CHECK(result_u.size() == 1 && result_v.size() == 1); @@ -213,16 +212,16 @@ void simple_verify_rtree(RTreeT &rtree, template void sampling_verify_rtree(RTreeT &rtree, LinearSearchNN &lsnn, - const std::vector &coords, + const std::vector &coords, unsigned num_samples) { std::mt19937 g(RANDOM_SEED); std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON); - std::vector queries; + std::vector queries; for (unsigned i = 0; i < num_samples; i++) { - queries.emplace_back(FixedPointCoordinate(lat_udist(g), lon_udist(g))); + queries.emplace_back(FixedLongitude(lon_udist(g)), FixedLatitude(lat_udist(g))); } BOOST_TEST_MESSAGE("Sampling queries"); @@ -238,7 +237,7 @@ void sampling_verify_rtree(RTreeT &rtree, auto lsnn_v = result_lsnn.back().v; double current_ratio = 0.; - FixedPointCoordinate nearest; + Coordinate nearest; const double rtree_dist = coordinate_calculation::perpendicularDistance( coords[rtree_u], coords[rtree_v], q, nearest, current_ratio); const double lsnn_dist = coordinate_calculation::perpendicularDistance( @@ -307,24 +306,26 @@ BOOST_FIXTURE_TEST_CASE(construct_multiple_levels_test, TestRandomGraphFixture_M // one BB will be pruned, even if it could contain a nearer match. BOOST_AUTO_TEST_CASE(regression_test) { - using Coord = std::pair; + using Coord = std::pair; using Edge = std::pair; GraphFixture fixture( { - Coord(40.0, 0.0), - Coord(35.0, 5.0), - - Coord(5.0, 5.0), - Coord(0.0, 10.0), - - Coord(20.0, 10.0), - Coord(20.0, 5.0), - - Coord(40.0, 100.0), - Coord(35.0, 105.0), - - Coord(5.0, 105.0), - Coord(0.0, 110.0), + Coord{FloatLongitude{0.0}, FloatLatitude{40.0}}, // + Coord{FloatLongitude{5.0}, FloatLatitude{35.0}}, // + Coord{FloatLongitude{5.0}, + FloatLatitude{ + 5.0, + }}, // + Coord{FloatLongitude{10.0}, + FloatLatitude{ + 0.0, + }}, // + Coord{FloatLongitude{10.0}, FloatLatitude{20.0}}, // + Coord{FloatLongitude{5.0}, FloatLatitude{20.0}}, // + Coord{FloatLongitude{100.0}, FloatLatitude{40.0}}, // + Coord{FloatLongitude{105.0}, FloatLatitude{35.0}}, // + Coord{FloatLongitude{105.0}, FloatLatitude{5.0}}, // + Coord{FloatLongitude{110.0}, FloatLatitude{0.0}}, // }, {Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)}); @@ -336,7 +337,7 @@ BOOST_AUTO_TEST_CASE(regression_test) LinearSearchNN lsnn(fixture.coords, fixture.edges); // query a node just right of the center of the gap - FixedPointCoordinate input(20.0 * COORDINATE_PRECISION, 55.1 * COORDINATE_PRECISION); + Coordinate input(FloatLongitude(55.1), FloatLatitude(20.0)); auto result_rtree = rtree.Nearest(input, 1); auto result_ls = lsnn.Nearest(input, 1); @@ -349,52 +350,48 @@ BOOST_AUTO_TEST_CASE(regression_test) void TestRectangle(double width, double height, double center_lat, double center_lon) { - FixedPointCoordinate center(center_lat * COORDINATE_PRECISION, - center_lon * COORDINATE_PRECISION); + Coordinate center{FloatLongitude(center_lon), FloatLatitude(center_lat)}; TestStaticRTree::Rectangle rect; - rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION; - rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION; - rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION; - rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION; + rect.min_lat = center.lat - FixedLatitude(height / 2.0 * COORDINATE_PRECISION); + rect.max_lat = center.lat + FixedLatitude(height / 2.0 * COORDINATE_PRECISION); + rect.min_lon = center.lon - FixedLongitude(width / 2.0 * COORDINATE_PRECISION); + rect.max_lon = center.lon + FixedLongitude(width / 2.0 * COORDINATE_PRECISION); - unsigned offset = 5 * COORDINATE_PRECISION; - FixedPointCoordinate north(rect.max_lat + offset, center.lon); - FixedPointCoordinate south(rect.min_lat - offset, center.lon); - FixedPointCoordinate west(center.lat, rect.min_lon - offset); - FixedPointCoordinate east(center.lat, rect.max_lon + offset); - FixedPointCoordinate north_east(rect.max_lat + offset, rect.max_lon + offset); - FixedPointCoordinate north_west(rect.max_lat + offset, rect.min_lon - offset); - FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset); - FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset); + const FixedLongitude lon_offset(5. * COORDINATE_PRECISION); + const FixedLatitude lat_offset(5. * COORDINATE_PRECISION); + Coordinate north(center.lon, rect.max_lat + lat_offset); + Coordinate south(center.lon, rect.min_lat - lat_offset); + Coordinate west(rect.min_lon - lon_offset, center.lat); + Coordinate east(rect.max_lon + lon_offset, center.lat); + Coordinate north_east(rect.max_lon + lon_offset, rect.max_lat + lat_offset); + Coordinate north_west(rect.min_lon - lon_offset, rect.max_lat + lat_offset); + Coordinate south_east(rect.max_lon + lon_offset, rect.min_lat - lat_offset); + Coordinate south_west(rect.min_lon - lon_offset, rect.min_lat - lat_offset); /* Distance to line segments of rectangle */ - BOOST_CHECK_EQUAL(rect.GetMinDist(north), - coordinate_calculation::greatCircleDistance( - north, FixedPointCoordinate(rect.max_lat, north.lon))); - BOOST_CHECK_EQUAL(rect.GetMinDist(south), - coordinate_calculation::greatCircleDistance( - south, FixedPointCoordinate(rect.min_lat, south.lon))); - BOOST_CHECK_EQUAL(rect.GetMinDist(west), - coordinate_calculation::greatCircleDistance( - west, FixedPointCoordinate(west.lat, rect.min_lon))); - BOOST_CHECK_EQUAL(rect.GetMinDist(east), - coordinate_calculation::greatCircleDistance( - east, FixedPointCoordinate(east.lat, rect.max_lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(north), coordinate_calculation::greatCircleDistance( + north, Coordinate(north.lon, rect.max_lat))); + BOOST_CHECK_EQUAL(rect.GetMinDist(south), coordinate_calculation::greatCircleDistance( + south, Coordinate(south.lon, rect.min_lat))); + BOOST_CHECK_EQUAL(rect.GetMinDist(west), coordinate_calculation::greatCircleDistance( + west, Coordinate(rect.min_lon, west.lat))); + BOOST_CHECK_EQUAL(rect.GetMinDist(east), coordinate_calculation::greatCircleDistance( + east, Coordinate(rect.max_lon, east.lat))); /* Distance to corner points */ BOOST_CHECK_EQUAL(rect.GetMinDist(north_east), coordinate_calculation::greatCircleDistance( - north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon))); + north_east, Coordinate(rect.max_lon, rect.max_lat))); BOOST_CHECK_EQUAL(rect.GetMinDist(north_west), coordinate_calculation::greatCircleDistance( - north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon))); + north_west, Coordinate(rect.min_lon, rect.max_lat))); BOOST_CHECK_EQUAL(rect.GetMinDist(south_east), coordinate_calculation::greatCircleDistance( - south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon))); + south_east, Coordinate(rect.max_lon, rect.min_lat))); BOOST_CHECK_EQUAL(rect.GetMinDist(south_west), coordinate_calculation::greatCircleDistance( - south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon))); + south_west, Coordinate(rect.min_lon, rect.min_lat))); } BOOST_AUTO_TEST_CASE(rectangle_test) @@ -408,11 +405,12 @@ BOOST_AUTO_TEST_CASE(rectangle_test) BOOST_AUTO_TEST_CASE(bearing_tests) { - using Coord = std::pair; + using Coord = std::pair; using Edge = std::pair; GraphFixture fixture( { - Coord(0.0, 0.0), Coord(10.0, 10.0), + Coord(FloatLongitude(0.0), FloatLatitude(0.0)), + Coord(FloatLongitude(10.0), FloatLatitude(10.0)), }, {Edge(0, 1), Edge(1, 0)}); @@ -423,7 +421,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests) std::unique_ptr mockfacade_ptr(new MockDataFacade); engine::GeospatialQuery query(rtree, fixture.coords, *mockfacade_ptr); - FixedPointCoordinate input(5.0 * COORDINATE_PRECISION, 5.1 * COORDINATE_PRECISION); + Coordinate input(FloatLongitude(5.1), FloatLatitude(5.0)); { auto results = query.NearestPhantomNodes(input, 5); @@ -468,12 +466,16 @@ BOOST_AUTO_TEST_CASE(bearing_tests) BOOST_AUTO_TEST_CASE(bbox_search_tests) { - using Coord = std::pair; + using Coord = std::pair; using Edge = std::pair; GraphFixture fixture( { - Coord(0.0, 0.0), Coord(1.0, 1.0), Coord(2.0, 2.0), Coord(3.0, 3.0), Coord(4.0, 4.0), + Coord(FloatLongitude(0.0), FloatLatitude(0.0)), + Coord(FloatLongitude(1.0), FloatLatitude(1.0)), + Coord(FloatLongitude(2.0), FloatLatitude(2.0)), + Coord(FloatLongitude(3.0), FloatLatitude(3.0)), + Coord(FloatLongitude(4.0), FloatLatitude(4.0)), }, {Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 4)}); @@ -485,19 +487,15 @@ BOOST_AUTO_TEST_CASE(bbox_search_tests) engine::GeospatialQuery query(rtree, fixture.coords, *mockfacade_ptr); { - RectangleInt2D bbox = {static_cast(0.5 * COORDINATE_PRECISION), - static_cast(1.5 * COORDINATE_PRECISION), - static_cast(0.5 * COORDINATE_PRECISION), - static_cast(1.5 * COORDINATE_PRECISION)}; + RectangleInt2D bbox = {FloatLongitude(0.5), FloatLongitude(1.5), FloatLatitude(0.5), + FloatLatitude(1.5)}; auto results = query.Search(bbox); BOOST_CHECK_EQUAL(results.size(), 2); } { - RectangleInt2D bbox = {static_cast(1.5 * COORDINATE_PRECISION), - static_cast(3.5 * COORDINATE_PRECISION), - static_cast(1.5 * COORDINATE_PRECISION), - static_cast(3.5 * COORDINATE_PRECISION)}; + RectangleInt2D bbox = {FloatLongitude(1.5), FloatLongitude(3.5), FloatLatitude(1.5), + FloatLatitude(3.5)}; auto results = query.Search(bbox); BOOST_CHECK_EQUAL(results.size(), 3); } diff --git a/unit_tests/util/tiles.cpp b/unit_tests/util/tiles.cpp index 816009121..4cd41a0be 100644 --- a/unit_tests/util/tiles.cpp +++ b/unit_tests/util/tiles.cpp @@ -15,19 +15,25 @@ using namespace osrm::util; BOOST_AUTO_TEST_CASE(point_to_tile_test) { - tiles::Tile tile_1_reference{2306375680,1409941503,32}; - tiles::Tile tile_2_reference{2308259840,1407668224,32}; - tiles::Tile tile_3_reference{616562688,2805989376,32}; - tiles::Tile tile_4_reference{1417674752,2084569088,32}; - tiles::Tile tile_5_reference{616562688,2805989376,32}; - tiles::Tile tile_6_reference{712654285,2671662374,32}; + tiles::Tile tile_1_reference{2306375680, 1409941503, 32}; + tiles::Tile tile_2_reference{2308259840, 1407668224, 32}; + tiles::Tile tile_3_reference{616562688, 2805989376, 32}; + tiles::Tile tile_4_reference{1417674752, 2084569088, 32}; + tiles::Tile tile_5_reference{616562688, 2805989376, 32}; + tiles::Tile tile_6_reference{712654285, 2671662374, 32}; - auto tile_1 = tiles::pointToTile(13.31817626953125,52.449314140869696); - auto tile_2 = tiles::pointToTile(13.476104736328125,52.56529070208021); - auto tile_3 = tiles::pointToTile(-128.32031249999997,-48.224672649565186); - auto tile_4 = tiles::pointToTile(-61.17187499999999,5.266007882805498); - auto tile_5 = tiles::pointToTile(-128.32031249999997,-48.224672649565186); - auto tile_6 = tiles::pointToTile(-120.266007882805532,-40.17187499999999); + auto tile_1 = + tiles::pointToTile(FloatLongitude(13.31817626953125), FloatLatitude(52.449314140869696)); + auto tile_2 = + tiles::pointToTile(FloatLongitude(13.476104736328125), FloatLatitude(52.56529070208021)); + auto tile_3 = + tiles::pointToTile(FloatLongitude(-128.32031249999997), FloatLatitude(-48.224672649565186)); + auto tile_4 = + tiles::pointToTile(FloatLongitude(-61.17187499999999), FloatLatitude(5.266007882805498)); + auto tile_5 = + tiles::pointToTile(FloatLongitude(-128.32031249999997), FloatLatitude(-48.224672649565186)); + auto tile_6 = + tiles::pointToTile(FloatLongitude(-120.266007882805532), FloatLatitude(-40.17187499999999)); BOOST_CHECK_EQUAL(tile_1.x, tile_1_reference.x); BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y); BOOST_CHECK_EQUAL(tile_1.z, tile_1_reference.z); @@ -54,12 +60,15 @@ BOOST_AUTO_TEST_CASE(bounding_box_to_tile_test) tiles::Tile tile_1_reference{17, 10, 5}; tiles::Tile tile_2_reference{0, 0, 0}; tiles::Tile tile_3_reference{0, 2, 2}; - auto tile_1 = tiles::getBBMaxZoomTile(13.31817626953125, 52.449314140869696, - 13.476104736328125, 52.56529070208021); - auto tile_2 = tiles::getBBMaxZoomTile(-128.32031249999997, -48.224672649565186, - -61.17187499999999, 5.266007882805498); - auto tile_3 = tiles::getBBMaxZoomTile(-128.32031249999997, -48.224672649565186, - -120.2660078828055, -40.17187499999999); + auto tile_1 = tiles::getBBMaxZoomTile( + FloatLongitude(13.31817626953125), FloatLatitude(52.449314140869696), + FloatLongitude(13.476104736328125), FloatLatitude(52.56529070208021)); + auto tile_2 = tiles::getBBMaxZoomTile( + FloatLongitude(-128.32031249999997), FloatLatitude(-48.224672649565186), + FloatLongitude(-61.17187499999999), FloatLatitude(5.266007882805498)); + auto tile_3 = tiles::getBBMaxZoomTile( + FloatLongitude(-128.32031249999997), FloatLatitude(-48.224672649565186), + FloatLongitude(-120.2660078828055), FloatLatitude(-40.17187499999999)); BOOST_CHECK_EQUAL(tile_1.x, tile_1_reference.x); BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y); BOOST_CHECK_EQUAL(tile_1.z, tile_1_reference.z);