First round of lat,lng -> lng,lat switcheroo

This commit is contained in:
Patrick Niklaus 2016-02-23 21:23:13 +01:00
parent 0fab6b7cab
commit d9d4742130
70 changed files with 893 additions and 817 deletions

View File

@ -52,10 +52,8 @@ int main(int argc, const char *argv[]) try
// Route is in Berlin. Latitude, Longitude // Route is in Berlin. Latitude, Longitude
// TODO(daniel-j-h): use either coordinate_precision or better provide double,double-taking ctor // TODO(daniel-j-h): use either coordinate_precision or better provide double,double-taking ctor
params.coordinates.push_back({static_cast<int>(43.731142 * osrm::COORDINATE_PRECISION), params.coordinates.push_back({osrm::util::FloatLongitude(7.419758), osrm::util::FloatLatitude(43.731142)});
static_cast<int>(7.419758 * osrm::COORDINATE_PRECISION)}); params.coordinates.push_back({osrm::util::FloatLongitude(7.419505), osrm::util::FloatLatitude(43.736825)});
params.coordinates.push_back({static_cast<int>(43.736825 * osrm::COORDINATE_PRECISION),
static_cast<int>(7.419505 * osrm::COORDINATE_PRECISION)});
// Response is in JSON format // Response is in JSON format
osrm::json::Object result; osrm::json::Object result;

View File

@ -26,8 +26,7 @@ class BaseAPI
{ {
} }
util::json::Array util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
{ {
BOOST_ASSERT(parameters.coordinates.size() > 0); BOOST_ASSERT(parameters.coordinates.size() > 0);
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
@ -47,7 +46,7 @@ class BaseAPI
} }
protected: protected:
util::json::Object MakeWaypoint(const util::FixedPointCoordinate input_coordinate, util::json::Object MakeWaypoint(const util::Coordinate input_coordinate,
const PhantomNode &phantom) const const PhantomNode &phantom) const
{ {
return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id), return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id),

View File

@ -23,7 +23,7 @@ struct BaseParameters
short range; short range;
}; };
std::vector<util::FixedPointCoordinate> coordinates; std::vector<util::Coordinate> coordinates;
std::vector<boost::optional<Hint>> hints; std::vector<boost::optional<Hint>> hints;
std::vector<boost::optional<double>> radiuses; std::vector<boost::optional<double>> radiuses;
std::vector<boost::optional<Bearing>> bearings; std::vector<boost::optional<Bearing>> bearings;

View File

@ -38,7 +38,7 @@ namespace detail
std::string instructionToString(extractor::TurnInstruction instruction); 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); std::string modeToString(const extractor::TravelMode mode);
@ -58,7 +58,7 @@ util::json::Object makeGeoJSONLineString(ForwardIter begin, ForwardIter end)
geojson.values["type"] = "LineString"; geojson.values["type"] = "LineString";
util::json::Array coordinates; util::json::Array coordinates;
std::transform(begin, end, std::back_inserter(coordinates.values), std::transform(begin, end, std::back_inserter(coordinates.values),
[](const util::FixedPointCoordinate loc) [](const util::Coordinate loc)
{ {
return detail::coordinateToLonLat(loc); return detail::coordinateToLonLat(loc);
}); });
@ -76,7 +76,7 @@ util::json::Object makeRoute(const guidance::Route &route,
boost::optional<util::json::Value> geometry); boost::optional<util::json::Value> geometry);
util::json::Object 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); util::json::Object makeRouteLeg(guidance::RouteLeg &&leg, util::json::Array &&steps);

View File

@ -64,7 +64,7 @@ class BaseDataFacade
FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0; FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const = 0;
// node and edge information access // 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; virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0;
@ -80,49 +80,48 @@ class BaseDataFacade
virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0; virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
virtual std::vector<RTreeLeaf> GetEdgesInBox(const util::FixedPointCoordinate &south_west, virtual std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
const util::FixedPointCoordinate &north_east) = 0; const util::Coordinate north_east) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance, const float max_distance,
const int bearing, const int bearing,
const int bearing_range) = 0; const int bearing_range) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) = 0; const float max_distance) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) = 0; const int bearing_range) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const int bearing, const int bearing,
const int bearing_range) = 0; const int bearing_range) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results) = 0;
const unsigned max_results) = 0;
virtual std::vector<PhantomNodeWithDistance> virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const double max_distance) = 0; const unsigned max_results,
const double max_distance) = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( virtual std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate) = 0; NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate) = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( virtual std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, const double max_distance) = 0; NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( const double max_distance) = 0;
const util::FixedPointCoordinate input_coordinate, virtual std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) = 0; const int bearing_range) = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate, const util::Coordinate input_coordinate, const int bearing, const int bearing_range) = 0;
const int bearing,
const int bearing_range) = 0;
virtual unsigned GetCheckSum() const = 0; virtual unsigned GetCheckSum() const = 0;

View File

@ -55,7 +55,7 @@ class InternalDataFacade final : public BaseDataFacade
using InputEdge = typename QueryGraph::InputEdge; using InputEdge = typename QueryGraph::InputEdge;
using RTreeLeaf = typename super::RTreeLeaf; using RTreeLeaf = typename super::RTreeLeaf;
using InternalRTree = using InternalRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, false>::vector, false>; util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, false>::vector, false>;
using InternalGeospatialQuery = GeospatialQuery<InternalRTree, BaseDataFacade>; using InternalGeospatialQuery = GeospatialQuery<InternalRTree, BaseDataFacade>;
InternalDataFacade() {} InternalDataFacade() {}
@ -65,7 +65,7 @@ class InternalDataFacade final : public BaseDataFacade
std::unique_ptr<QueryGraph> m_query_graph; std::unique_ptr<QueryGraph> m_query_graph;
std::string m_timestamp; std::string m_timestamp;
std::shared_ptr<util::ShM<util::FixedPointCoordinate, false>::vector> m_coordinate_list; std::shared_ptr<util::ShM<util::Coordinate, false>::vector> m_coordinate_list;
util::ShM<NodeID, false>::vector m_via_node_list; util::ShM<NodeID, false>::vector m_via_node_list;
util::ShM<unsigned, false>::vector m_name_ID_list; util::ShM<unsigned, false>::vector m_name_ID_list;
util::ShM<extractor::TurnInstruction, false>::vector m_turn_instruction_list; util::ShM<extractor::TurnInstruction, false>::vector m_turn_instruction_list;
@ -132,15 +132,12 @@ class InternalDataFacade final : public BaseDataFacade
extractor::QueryNode current_node; extractor::QueryNode current_node;
unsigned number_of_coordinates = 0; unsigned number_of_coordinates = 0;
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned)); nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
m_coordinate_list = m_coordinate_list = std::make_shared<std::vector<util::Coordinate>>(number_of_coordinates);
std::make_shared<std::vector<util::FixedPointCoordinate>>(number_of_coordinates);
for (unsigned i = 0; i < number_of_coordinates; ++i) for (unsigned i = 0; i < number_of_coordinates; ++i)
{ {
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode)); nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
m_coordinate_list->at(i) = m_coordinate_list->at(i) = util::Coordinate(current_node.lon, current_node.lat);
util::FixedPointCoordinate(current_node.lat, current_node.lon); BOOST_ASSERT(m_coordinate_list->at(i).IsValid());
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0);
BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0);
} }
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); 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 // 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); return m_coordinate_list->at(id);
} }
@ -340,22 +337,21 @@ class InternalDataFacade final : public BaseDataFacade
return m_travel_mode_list.at(id); return m_travel_mode_list.at(id);
} }
std::vector<RTreeLeaf> std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
GetEdgesInBox(const util::FixedPointCoordinate &south_west, const util::Coordinate north_east) override final
const util::FixedPointCoordinate &north_east) override final
{ {
if (!m_static_rtree.get()) if (!m_static_rtree.get())
{ {
LoadRTree(); LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
} }
const util::RectangleInt2D bbox{ const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat,
south_west.lon, north_east.lon, south_west.lat, north_east.lat}; north_east.lat};
return m_geospatial_query->Search(bbox); return m_geospatial_query->Search(bbox);
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) override final const float max_distance) override final
{ {
if (!m_static_rtree.get()) if (!m_static_rtree.get())
@ -368,7 +364,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance, const float max_distance,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -384,7 +380,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results) override final const unsigned max_results) override final
{ {
if (!m_static_rtree.get()) if (!m_static_rtree.get())
@ -397,7 +393,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance) override final const double max_distance) override final
{ {
@ -411,7 +407,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -427,7 +423,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
@ -443,8 +439,9 @@ class InternalDataFacade final : public BaseDataFacade
bearing, bearing_range); bearing, bearing_range);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, const double max_distance) override final NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance) override final
{ {
if (!m_static_rtree.get()) if (!m_static_rtree.get())
{ {
@ -457,7 +454,7 @@ class InternalDataFacade final : public BaseDataFacade
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate) override final const util::Coordinate input_coordinate) override final
{ {
if (!m_static_rtree.get()) if (!m_static_rtree.get())
{ {
@ -469,8 +466,8 @@ class InternalDataFacade final : public BaseDataFacade
input_coordinate); input_coordinate);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -485,8 +482,8 @@ class InternalDataFacade final : public BaseDataFacade
input_coordinate, max_distance, bearing, bearing_range); input_coordinate, max_distance, bearing, bearing_range);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {

View File

@ -48,7 +48,7 @@ class SharedDataFacade final : public BaseDataFacade
using InputEdge = typename QueryGraph::InputEdge; using InputEdge = typename QueryGraph::InputEdge;
using RTreeLeaf = typename super::RTreeLeaf; using RTreeLeaf = typename super::RTreeLeaf;
using SharedRTree = using SharedRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, true>::vector, true>; util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>;
using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>; using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>;
using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>; using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
using RTreeNode = typename SharedRTree::TreeNode; using RTreeNode = typename SharedRTree::TreeNode;
@ -67,7 +67,7 @@ class SharedDataFacade final : public BaseDataFacade
std::unique_ptr<storage::SharedMemory> m_large_memory; std::unique_ptr<storage::SharedMemory> m_large_memory;
std::string m_timestamp; std::string m_timestamp;
std::shared_ptr<util::ShM<util::FixedPointCoordinate, true>::vector> m_coordinate_list; std::shared_ptr<util::ShM<util::Coordinate, true>::vector> m_coordinate_list;
util::ShM<NodeID, true>::vector m_via_node_list; util::ShM<NodeID, true>::vector m_via_node_list;
util::ShM<unsigned, true>::vector m_name_ID_list; util::ShM<unsigned, true>::vector m_name_ID_list;
util::ShM<extractor::TurnInstruction, true>::vector m_turn_instruction_list; util::ShM<extractor::TurnInstruction, true>::vector m_turn_instruction_list;
@ -133,9 +133,9 @@ class SharedDataFacade final : public BaseDataFacade
void LoadNodeAndEdgeInformation() void LoadNodeAndEdgeInformation()
{ {
auto coordinate_list_ptr = data_layout->GetBlockPtr<util::FixedPointCoordinate>( auto coordinate_list_ptr = data_layout->GetBlockPtr<util::Coordinate>(
shared_memory, storage::SharedDataLayout::COORDINATE_LIST); shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
m_coordinate_list = util::make_unique<util::ShM<util::FixedPointCoordinate, true>::vector>( m_coordinate_list = util::make_unique<util::ShM<util::Coordinate, true>::vector>(
coordinate_list_ptr, coordinate_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]); data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
@ -365,7 +365,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
// node and edge information access // 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); return m_coordinate_list->at(id);
} }
@ -408,22 +408,21 @@ class SharedDataFacade final : public BaseDataFacade
return m_travel_mode_list.at(id); return m_travel_mode_list.at(id);
} }
std::vector<RTreeLeaf> std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
GetEdgesInBox(const util::FixedPointCoordinate &south_west, const util::Coordinate north_east) override final
const util::FixedPointCoordinate &north_east) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{ {
LoadRTree(); LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
} }
const util::RectangleInt2D bbox{ const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat,
south_west.lon, north_east.lon, south_west.lat, north_east.lat}; north_east.lat};
return m_geospatial_query->Search(bbox); return m_geospatial_query->Search(bbox);
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) override final const float max_distance) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
@ -436,7 +435,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance, const float max_distance,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -452,7 +451,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results) override final const unsigned max_results) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
@ -465,7 +464,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance) override final const double max_distance) override final
{ {
@ -479,7 +478,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -495,7 +494,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
@ -512,7 +511,7 @@ class SharedDataFacade final : public BaseDataFacade
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode> 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) if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{ {
@ -524,8 +523,9 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate); input_coordinate);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, const double max_distance) override final NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first) if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{ {
@ -537,8 +537,8 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate, max_distance); input_coordinate, max_distance);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
@ -553,8 +553,8 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate, max_distance, bearing, bearing_range); input_coordinate, max_distance, bearing, bearing_range);
} }
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {

View File

@ -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 // Input is vector of pairs. Each pair consists of the point information and a
// bit indicating if the points is present in the generalization. // bit indicating if the points is present in the generalization.
// Note: points may also be pre-selected*/ // Note: points may also be pre-selected*/
std::vector<util::FixedPointCoordinate> std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::const_iterator begin,
douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin, std::vector<util::Coordinate>::const_iterator end,
std::vector<util::FixedPointCoordinate>::const_iterator end,
const unsigned zoom_level); const unsigned zoom_level);
// Convenience range-based function // Convenience range-based function
inline std::vector<util::FixedPointCoordinate> inline std::vector<util::Coordinate> douglasPeucker(const std::vector<util::Coordinate> &geometry,
douglasPeucker(const std::vector<util::FixedPointCoordinate> &geometry, const unsigned zoom_level) const unsigned zoom_level)
{ {
return douglasPeucker(begin(geometry), end(geometry), zoom_level); return douglasPeucker(begin(geometry), end(geometry), zoom_level);
} }

View File

@ -41,12 +41,13 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns nearest PhantomNodes in the given bearing range within max_distance. // Returns nearest PhantomNodes in the given bearing range within max_distance.
// Does not filter by small/big component! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance)
const double max_distance)
{ {
auto results = auto results = rtree.Nearest(input_coordinate,
rtree.Nearest(input_coordinate, [](const EdgeData &)
[] (const EdgeData &) { return std::make_pair(true, true); }, {
return std::make_pair(true, true);
},
[max_distance](const std::size_t, const double min_dist) [max_distance](const std::size_t, const double min_dist)
{ {
return min_dist > max_distance; return min_dist > max_distance;
@ -58,7 +59,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns nearest PhantomNodes in the given bearing range within max_distance. // Returns nearest PhantomNodes in the given bearing range within max_distance.
// Does not filter by small/big component! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) const int bearing_range)
@ -80,7 +81,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes in the given bearing range. // Returns max_results nearest PhantomNodes in the given bearing range.
// Does not filter by small/big component! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const int bearing, const int bearing,
const int bearing_range) const int bearing_range)
@ -98,16 +99,18 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return MakePhantomNodes(input_coordinate, results); 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! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) const int bearing_range)
{ {
auto results = rtree.Nearest(input_coordinate, auto results = rtree.Nearest(
input_coordinate,
[this, bearing, bearing_range](const EdgeData &data) [this, bearing, bearing_range](const EdgeData &data)
{ {
return checkSegmentBearing(data, bearing, bearing_range); return checkSegmentBearing(data, bearing, bearing_range);
@ -123,8 +126,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes. // Returns max_results nearest PhantomNodes.
// Does not filter by small/big component! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results)
const unsigned max_results)
{ {
auto results = rtree.Nearest(input_coordinate, auto results = rtree.Nearest(input_coordinate,
[](const EdgeData &) [](const EdgeData &)
@ -142,11 +144,12 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes in the given max distance. // Returns max_results nearest PhantomNodes in the given max distance.
// Does not filter by small/big component! // Does not filter by small/big component!
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results, const unsigned max_results,
const double max_distance) const double max_distance)
{ {
auto results = rtree.Nearest(input_coordinate, auto results = rtree.Nearest(
input_coordinate,
[](const EdgeData &) [](const EdgeData &)
{ {
return std::make_pair(true, true); return std::make_pair(true, true);
@ -161,8 +164,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns the nearest phantom node. If this phantom node is not from a big component // 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. // a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, const double max_distance) NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance)
{ {
bool has_small_component = false; bool has_small_component = false;
bool has_big_component = false; bool has_big_component = false;
@ -196,8 +200,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns the nearest phantom node. If this phantom node is not from a big component // 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. // a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate) NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate)
{ {
bool has_small_component = false; bool has_small_component = false;
bool has_big_component = false; bool has_big_component = false;
@ -232,9 +236,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns the nearest phantom node. If this phantom node is not from a big component // 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. // a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate, const util::Coordinate input_coordinate, const int bearing, const int bearing_range)
const int bearing,
const int bearing_range)
{ {
bool has_small_component = false; bool has_small_component = false;
bool has_big_component = false; bool has_big_component = false;
@ -276,8 +278,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns the nearest phantom node. If this phantom node is not from a big component // 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. // a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode>
const util::FixedPointCoordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance, const double max_distance,
const int bearing, const int bearing,
const int bearing_range) const int bearing_range)
@ -322,7 +324,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
private: private:
std::vector<PhantomNodeWithDistance> std::vector<PhantomNodeWithDistance>
MakePhantomNodes(const util::FixedPointCoordinate input_coordinate, MakePhantomNodes(const util::Coordinate input_coordinate,
const std::vector<EdgeData> &results) const const std::vector<EdgeData> &results) const
{ {
std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size()); std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size());
@ -334,10 +336,10 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return distance_and_phantoms; return distance_and_phantoms;
} }
PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate input_coordinate, PhantomNodeWithDistance MakePhantomNode(const util::Coordinate input_coordinate,
const EdgeData &data) const const EdgeData &data) const
{ {
util::FixedPointCoordinate point_on_segment; util::Coordinate point_on_segment;
double ratio; double ratio;
const auto current_perpendicular_distance = const auto current_perpendicular_distance =
util::coordinate_calculation::perpendicularDistance( util::coordinate_calculation::perpendicularDistance(

View File

@ -3,6 +3,8 @@
#include "engine/guidance/leg_geometry.hpp" #include "engine/guidance/leg_geometry.hpp"
#include "util/coordinate.hpp"
#include <vector> #include <vector>
namespace osrm namespace osrm
@ -12,8 +14,8 @@ namespace engine
namespace guidance namespace guidance
{ {
std::vector<util::FixedPointCoordinate> std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_simplification); const bool use_simplification);
} // namespace guidance } // namespace guidance
} // namespace engine } // namespace engine

View File

@ -23,7 +23,7 @@ namespace guidance
// offsets 0 2 n-1 n // offsets 0 2 n-1 n
struct LegGeometry struct LegGeometry
{ {
std::vector<util::FixedPointCoordinate> locations; std::vector<util::Coordinate> locations;
// segment_offset[i] .. segment_offset[i+1] (inclusive) // segment_offset[i] .. segment_offset[i+1] (inclusive)
// contains the geometry of segment i // contains the geometry of segment i
std::vector<std::size_t> segment_offsets; std::vector<std::size_t> segment_offsets;
@ -45,7 +45,6 @@ struct LegGeometry
BOOST_ASSERT(segment_offsets.size() > 0); BOOST_ASSERT(segment_offsets.size() > 0);
return segment_offsets.size() - 1; return segment_offsets.size() - 1;
} }
}; };
} }
} }

View File

@ -13,14 +13,12 @@ namespace guidance
struct StepManeuver struct StepManeuver
{ {
util::FixedPointCoordinate location; util::Coordinate location;
double bearing_before; double bearing_before;
double bearing_after; double bearing_after;
extractor::TurnInstruction instruction; extractor::TurnInstruction instruction;
}; };
} }
} }
} }
#endif #endif

View File

@ -4,6 +4,9 @@
#include "engine/object_encoder.hpp" #include "engine/object_encoder.hpp"
#include "engine/phantom_node.hpp" #include "engine/phantom_node.hpp"
#include "util/coordinate.hpp"
#include "phantom_node.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <cstdint> #include <cstdint>
@ -19,15 +22,15 @@ namespace engine
// Is returned as a temporary identifier for snapped coodinates // Is returned as a temporary identifier for snapped coodinates
struct Hint struct Hint
{ {
FixedPointCoordinate input_coordinate; util::Coordinate input_coordinate;
PhantomNode phantom; PhantomNode phantom;
std::uint32_t data_checksum; std::uint32_t data_checksum;
template <typename DataFacadeT> template <typename DataFacadeT>
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 && auto is_same_input_coordinate = new_input_coordinates.lon == input_coordinate.lon &&
new_input_coordinates.lon == input_coordinate.lon; new_input_coordinates.lat == input_coordinate.lat;
return is_same_input_coordinate && phantom.IsValid(facade.GetNumberOfNodes()) && return is_same_input_coordinate && phantom.IsValid(facade.GetNumberOfNodes()) &&
facade.GetCheckSum() == data_checksum; facade.GetCheckSum() == data_checksum;
} }

View File

@ -28,7 +28,7 @@ struct PhantomNode
unsigned reverse_packed_geometry_id_, unsigned reverse_packed_geometry_id_,
bool is_tiny_component, bool is_tiny_component,
unsigned component_id, unsigned component_id,
util::FixedPointCoordinate location, util::Coordinate location,
unsigned short fwd_segment_position, unsigned short fwd_segment_position,
extractor::TravelMode forward_travel_mode, extractor::TravelMode forward_travel_mode,
extractor::TravelMode backward_travel_mode) extractor::TravelMode backward_travel_mode)
@ -37,9 +37,9 @@ struct PhantomNode
forward_offset(forward_offset), reverse_offset(reverse_offset), forward_offset(forward_offset), reverse_offset(reverse_offset),
forward_packed_geometry_id(forward_packed_geometry_id_), forward_packed_geometry_id(forward_packed_geometry_id_),
reverse_packed_geometry_id(reverse_packed_geometry_id_), reverse_packed_geometry_id(reverse_packed_geometry_id_),
component{component_id, is_tiny_component}, component{component_id, is_tiny_component}, location(std::move(location)),
location(std::move(location)), fwd_segment_position(fwd_segment_position), fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode),
forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) backward_travel_mode(backward_travel_mode)
{ {
} }
@ -47,10 +47,9 @@ struct PhantomNode
: forward_node_id(SPECIAL_NODEID), reverse_node_id(SPECIAL_NODEID), : forward_node_id(SPECIAL_NODEID), reverse_node_id(SPECIAL_NODEID),
name_id(std::numeric_limits<unsigned>::max()), forward_weight(INVALID_EDGE_WEIGHT), name_id(std::numeric_limits<unsigned>::max()), forward_weight(INVALID_EDGE_WEIGHT),
reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0), reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0),
forward_packed_geometry_id(SPECIAL_EDGEID), forward_packed_geometry_id(SPECIAL_EDGEID), reverse_packed_geometry_id(SPECIAL_EDGEID),
reverse_packed_geometry_id(SPECIAL_EDGEID), component{INVALID_COMPONENTID, false}, fwd_segment_position(0),
component{INVALID_COMPONENTID, false}, forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
backward_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; } bool operator==(const PhantomNode &other) const { return location == other.location; }
template <class OtherT> template <class OtherT>
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; forward_node_id = other.forward_edge_based_node_id;
reverse_node_id = other.reverse_edge_based_node_id; reverse_node_id = other.reverse_edge_based_node_id;
@ -137,7 +141,7 @@ struct PhantomNode
#ifndef _MSC_VER #ifndef _MSC_VER
static_assert(sizeof(ComponentType) == 4, "ComponentType needs to 4 bytes big"); static_assert(sizeof(ComponentType) == 4, "ComponentType needs to 4 bytes big");
#endif #endif
util::FixedPointCoordinate location; util::Coordinate location;
unsigned short fwd_segment_position; unsigned short fwd_segment_position;
// note 4 bits would suffice for each, // note 4 bits would suffice for each,
// but the saved byte would be padding anyway // but the saved byte would be padding anyway

View File

@ -28,10 +28,10 @@ class BasePlugin
datafacade::BaseDataFacade &facade; datafacade::BaseDataFacade &facade;
BasePlugin(datafacade::BaseDataFacade &facade_) : facade(facade_) {} BasePlugin(datafacade::BaseDataFacade &facade_) : facade(facade_) {}
bool CheckAllCoordinates(const std::vector<util::FixedPointCoordinate> &coordinates) bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates)
{ {
return !std::any_of(std::begin(coordinates), std::end(coordinates), return !std::any_of(std::begin(coordinates), std::end(coordinates),
[](const util::FixedPointCoordinate &coordinate) [](const util::Coordinate coordinate)
{ {
return !coordinate.IsValid(); return !coordinate.IsValid();
}); });
@ -150,9 +150,11 @@ class BasePlugin
return phantom_nodes; return phantom_nodes;
} }
std::vector<std::vector<PhantomNodeWithDistance>> GetPhantomNodes(const api::BaseParameters &parameters, unsigned number_of_results) std::vector<std::vector<PhantomNodeWithDistance>>
GetPhantomNodes(const api::BaseParameters &parameters, unsigned number_of_results)
{ {
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(parameters.coordinates.size()); std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
parameters.coordinates.size());
const bool use_hints = !parameters.hints.empty(); const bool use_hints = !parameters.hints.empty();
const bool use_bearings = !parameters.bearings.empty(); const bool use_bearings = !parameters.bearings.empty();
@ -176,32 +178,28 @@ class BasePlugin
{ {
if (use_radiuses && parameters.radiuses[i]) if (use_radiuses && parameters.radiuses[i])
{ {
phantom_nodes[i] = phantom_nodes[i] = facade.NearestPhantomNodes(
facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results, *parameters.radiuses[i], parameters.coordinates[i], number_of_results, *parameters.radiuses[i],
parameters.bearings[i]->bearing, parameters.bearings[i]->range); parameters.bearings[i]->bearing, parameters.bearings[i]->range);
} }
else else
{ {
phantom_nodes[i] = phantom_nodes[i] = facade.NearestPhantomNodes(
facade.NearestPhantomNodes( parameters.coordinates[i], number_of_results,
parameters.coordinates[i], number_of_results, parameters.bearings[i]->bearing, parameters.bearings[i]->bearing, parameters.bearings[i]->range);
parameters.bearings[i]->range);
} }
} }
else else
{ {
if (use_radiuses && parameters.radiuses[i]) if (use_radiuses && parameters.radiuses[i])
{ {
phantom_nodes[i] = phantom_nodes[i] = facade.NearestPhantomNodes(
facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results, *parameters.radiuses[i]); parameters.coordinates[i], number_of_results, *parameters.radiuses[i]);
} }
else else
{ {
phantom_nodes[i] = phantom_nodes[i] =
facade.NearestPhantomNodes( facade.NearestPhantomNodes(parameters.coordinates[i], number_of_results);
parameters.coordinates[i], number_of_results);
} }
} }

View File

@ -1,7 +1,7 @@
#ifndef POLYLINECOMPRESSOR_H_ #ifndef POLYLINECOMPRESSOR_H_
#define POLYLINECOMPRESSOR_H_ #define POLYLINECOMPRESSOR_H_
#include "osrm/coordinate.hpp" #include "util/coordinate.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
@ -12,19 +12,19 @@ namespace engine
{ {
namespace detail namespace detail
{ {
constexpr double POLYLINE_PECISION = 1e5; constexpr double POLYLINE_PECISION = 1e5;
constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION; constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION;
constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION; constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION;
} }
using CoordVectorForwardIter = std::vector<FixedPointCoordinate>::const_iterator; using CoordVectorForwardIter = std::vector<util::Coordinate>::const_iterator;
// Encodes geometry into polyline format. // Encodes geometry into polyline format.
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm // See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end); std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end);
// Decodes geometry from polyline format // Decodes geometry from polyline format
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm // See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::vector<util::FixedPointCoordinate> decodePolyline(const std::string &polyline); std::vector<util::Coordinate> decodePolyline(const std::string &polyline);
} }
} }

View File

@ -76,7 +76,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
SubMatchingList SubMatchingList
operator()(const CandidateLists &candidates_list, operator()(const CandidateLists &candidates_list,
const std::vector<util::FixedPointCoordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision) const const std::vector<boost::optional<double>> &trace_gps_precision) const
{ {

View File

@ -351,8 +351,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
if (target_traversed_in_reverse) if (target_traversed_in_reverse)
{ {
std::reverse(id_vector.begin(), id_vector.end()); std::reverse(id_vector.begin(), id_vector.end());
end_index = end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
} }
if (start_index > end_index) if (start_index > end_index)
@ -365,8 +364,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
BOOST_ASSERT(i < id_vector.size()); BOOST_ASSERT(i < id_vector.size());
BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0); BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0);
unpacked_path.emplace_back( unpacked_path.emplace_back(
PathData{id_vector[i], phantom_node_pair.target_phantom.name_id, PathData{id_vector[i], phantom_node_pair.target_phantom.name_id, 0,
0, extractor::TurnInstruction::NoTurn, extractor::TurnInstruction::NoTurn,
target_traversed_in_reverse target_traversed_in_reverse
? phantom_node_pair.target_phantom.backward_travel_mode ? phantom_node_pair.target_phantom.backward_travel_mode
: phantom_node_pair.target_phantom.forward_travel_mode}); : phantom_node_pair.target_phantom.forward_travel_mode});
@ -385,7 +384,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// looks like a trivially true check but tests for underflow // looks like a trivially true check but tests for underflow
BOOST_ASSERT(last_index > second_to_last_index); 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(); unpacked_path.pop_back();
} }
@ -743,8 +743,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
nodes.target_phantom = target_phantom; nodes.target_phantom = target_phantom;
UnpackPath(packed_path.begin(), packed_path.end(), nodes, unpacked_path); UnpackPath(packed_path.begin(), packed_path.end(), nodes, unpacked_path);
util::FixedPointCoordinate previous_coordinate = source_phantom.location; util::Coordinate previous_coordinate = source_phantom.location;
util::FixedPointCoordinate current_coordinate; util::Coordinate current_coordinate;
double distance = 0; double distance = 0;
for (const auto &p : unpacked_path) for (const auto &p : unpacked_path)
{ {

View File

@ -22,8 +22,7 @@ struct EdgeBasedNode
EdgeBasedNode() EdgeBasedNode()
: forward_edge_based_node_id(SPECIAL_NODEID), reverse_edge_based_node_id(SPECIAL_NODEID), : forward_edge_based_node_id(SPECIAL_NODEID), reverse_edge_based_node_id(SPECIAL_NODEID),
u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0), u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0),
forward_packed_geometry_id(SPECIAL_EDGEID), forward_packed_geometry_id(SPECIAL_EDGEID), reverse_packed_geometry_id(SPECIAL_EDGEID),
reverse_packed_geometry_id(SPECIAL_EDGEID),
component{INVALID_COMPONENTID, false}, component{INVALID_COMPONENTID, false},
fwd_segment_position(std::numeric_limits<unsigned short>::max()), fwd_segment_position(std::numeric_limits<unsigned short>::max()),
forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), 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), 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_), forward_packed_geometry_id(forward_weight_or_packed_geometry_id_),
reverse_packed_geometry_id(reverse_weight_or_packed_geometry_id_), reverse_packed_geometry_id(reverse_weight_or_packed_geometry_id_),
component{component_id, is_tiny_component}, component{component_id, is_tiny_component}, fwd_segment_position(fwd_segment_position),
fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode), forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode)
backward_travel_mode(backward_travel_mode)
{ {
BOOST_ASSERT((forward_edge_based_node_id != SPECIAL_NODEID) || BOOST_ASSERT((forward_edge_based_node_id != SPECIAL_NODEID) ||
(reverse_edge_based_node_id != SPECIAL_NODEID)); (reverse_edge_based_node_id != SPECIAL_NODEID));
} }
static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate a, static inline util::Coordinate Centroid(const util::Coordinate a, const util::Coordinate b)
const util::FixedPointCoordinate b)
{ {
util::FixedPointCoordinate centroid; util::Coordinate centroid;
// The coordinates of the midpoint are given by: // The coordinates of the midpoint are given by:
centroid.lat = (a.lat + b.lat) / 2; centroid.lon = (a.lon + b.lon) / util::FixedLongitude(2);
centroid.lon = (a.lon + b.lon) / 2; centroid.lat = (a.lat + b.lat) / util::FixedLatitude(2);
return centroid; return centroid;
} }

View File

@ -12,8 +12,12 @@ namespace extractor
struct ExternalMemoryNode : QueryNode struct ExternalMemoryNode : QueryNode
{ {
ExternalMemoryNode(int lat, int lon, OSMNodeID node_id, bool barrier, bool traffic_lights) ExternalMemoryNode(const util::FixedLongitude lon_,
: QueryNode(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights) 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() 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() static ExternalMemoryNode max_value()
{ {
return ExternalMemoryNode(std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), return ExternalMemoryNode(util::FixedLongitude(std::numeric_limits<int>::max()),
util::FixedLatitude(std::numeric_limits<int>::max()),
MAX_OSM_NODEID, false, false); MAX_OSM_NODEID, false, false);
} }

View File

@ -85,7 +85,7 @@ struct InternalExtractorEdge
// intermediate edge weight // intermediate edge weight
WeightData weight_data; WeightData weight_data;
// coordinate of the source node // coordinate of the source node
util::FixedPointCoordinate source_coordinate; util::Coordinate source_coordinate;
// necessary static util functions for stxxl's sorting // necessary static util functions for stxxl's sorting
static InternalExtractorEdge min_osm_value() static InternalExtractorEdge min_osm_value()

View File

@ -3,7 +3,7 @@
#include "util/typedefs.hpp" #include "util/typedefs.hpp"
#include "osrm/coordinate.hpp" #include "util/coordinate.hpp"
#include <limits> #include <limits>
@ -17,30 +17,32 @@ struct QueryNode
using key_type = OSMNodeID; // type of NodeID using key_type = OSMNodeID; // type of NodeID
using value_type = int; // type of lat,lons using value_type = int; // type of lat,lons
explicit QueryNode(int lat, int lon, key_type node_id) explicit QueryNode(const util::FixedLongitude lon_,
: lat(lat), lon(lon), node_id(std::move(node_id)) const util::FixedLatitude lat_,
key_type node_id)
: lon(lon_), lat(lat_), node_id(std::move(node_id))
{ {
} }
QueryNode() QueryNode()
: lat(std::numeric_limits<int>::max()), lon(std::numeric_limits<int>::max()), : lon(std::numeric_limits<int>::max()), lat(std::numeric_limits<int>::max()),
node_id(SPECIAL_OSM_NODEID) node_id(SPECIAL_OSM_NODEID)
{ {
} }
int lat; util::FixedLongitude lon;
int lon; util::FixedLatitude lat;
key_type node_id; key_type node_id;
static QueryNode min_value() static QueryNode min_value()
{ {
return QueryNode(static_cast<int>(-90 * COORDINATE_PRECISION), return QueryNode(util::FixedLongitude(-180 * COORDINATE_PRECISION),
static_cast<int>(-180 * COORDINATE_PRECISION), MIN_OSM_NODEID); util::FixedLatitude(-90 * COORDINATE_PRECISION), MIN_OSM_NODEID);
} }
static QueryNode max_value() static QueryNode max_value()
{ {
return QueryNode(static_cast<int>(90 * COORDINATE_PRECISION), return QueryNode(util::FixedLongitude(180 * COORDINATE_PRECISION),
static_cast<int>(180 * COORDINATE_PRECISION), MAX_OSM_NODEID); util::FixedLatitude(90 * COORDINATE_PRECISION), MAX_OSM_NODEID);
} }
}; };
} }

View File

@ -5,7 +5,7 @@
namespace osrm namespace osrm
{ {
using util::FixedPointCoordinate; using util::Coordinate;
} }
#endif #endif

View File

@ -33,7 +33,7 @@ template <typename ParameterT,
typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0> typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0>
boost::optional<ParameterT> parseParameters(std::string options_string) boost::optional<ParameterT> parseParameters(std::string options_string)
{ {
const auto first = options_string.begin(); auto first = options_string.begin();
const auto last = options_string.end(); const auto last = options_string.end();
return parseParameters<ParameterT>(first, last); return parseParameters<ParameterT>(first, last);
} }

View File

@ -18,10 +18,9 @@ struct ParsedURL
std::string service; std::string service;
unsigned version; unsigned version;
std::string profile; std::string profile;
std::vector<util::FixedPointCoordinate> coordinates; std::vector<util::Coordinate> coordinates;
std::string options; std::string options;
}; };
} }
} }
} }

View File

@ -21,7 +21,7 @@ class BaseService
BaseService(OSRM &routing_machine) : routing_machine(routing_machine) {} BaseService(OSRM &routing_machine) : routing_machine(routing_machine) {}
virtual ~BaseService() = default; virtual ~BaseService() = default;
virtual engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, virtual engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &json_result) = 0; util::json::Object &json_result) = 0;

View File

@ -22,7 +22,7 @@ class MatchService final : public BaseService
public: public:
MatchService(OSRM &routing_machine) : BaseService(routing_machine) {} MatchService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) final override; util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class NearestService final : public BaseService
public: public:
NearestService(OSRM &routing_machine) : BaseService(routing_machine) {} NearestService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) final override; util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class RouteService final : public BaseService
public: public:
RouteService(OSRM &routing_machine) : BaseService(routing_machine) {} RouteService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) final override; util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class TableService final : public BaseService
public: public:
TableService(OSRM &routing_machine) : BaseService(routing_machine) {} TableService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) final override; util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class TripService final : public BaseService
public: public:
TripService(OSRM &routing_machine) : BaseService(routing_machine) {} TripService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) final override; util::json::Object &result) final override;

View File

@ -28,9 +28,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef COORDINATE_HPP_ #ifndef COORDINATE_HPP_
#define COORDINATE_HPP_ #define COORDINATE_HPP_
#include "util/strong_typedef.hpp"
#include <iosfwd> //for std::ostream #include <iosfwd> //for std::ostream
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <cstddef>
namespace osrm namespace osrm
{ {
@ -40,35 +43,60 @@ constexpr const double COORDINATE_PRECISION = 1e6;
namespace util 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; return FixedLatitude(static_cast<double>(floating) * COORDINATE_PRECISION);
int lon; }
FixedPointCoordinate(); inline FixedLongitude toFixed(const FloatLongitude floating)
FixedPointCoordinate(int lat, int lon); {
return FixedLongitude(static_cast<double>(floating) * COORDINATE_PRECISION);
}
template <class T> inline FloatLatitude toFloating(const FixedLatitude fixed)
FixedPointCoordinate(const T &coordinate) {
: lat(coordinate.lat), lon(coordinate.lon) return FloatLatitude(static_cast<int32_t>(fixed) / COORDINATE_PRECISION);
}
inline FloatLongitude toFloating(const FixedLongitude fixed)
{
return FloatLongitude(static_cast<int32_t>(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 <class T> Coordinate(const T &coordinate) : lon(coordinate.lon), lat(coordinate.lat)
{ {
static_assert(!std::is_same<T, FixedPointCoordinate>::value, "This constructor should not be used for FixedPointCoordinates"); static_assert(!std::is_same<T, Coordinate>::value,
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value, "This constructor should not be used for Coordinates");
"coordinate types incompatible");
static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value, static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value,
"coordinate types incompatible"); "coordinate types incompatible");
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value,
"coordinate types incompatible");
} }
bool IsValid() const; bool IsValid() const;
friend bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); friend bool operator==(const Coordinate lhs, const Coordinate rhs);
friend bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); friend bool operator!=(const Coordinate lhs, const Coordinate rhs);
friend std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate); friend std::ostream &operator<<(std::ostream &out, const Coordinate coordinate);
}; };
bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs); bool operator==(const Coordinate lhs, const Coordinate rhs);
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate); std::ostream &operator<<(std::ostream &out, const Coordinate coordinate);
} }
} }
#endif /* COORDINATE_HPP_ */ #endif /* COORDINATE_HPP_ */

View File

@ -1,7 +1,7 @@
#ifndef COORDINATE_CALCULATION #ifndef COORDINATE_CALCULATION
#define COORDINATE_CALCULATION #define COORDINATE_CALCULATION
#include "osrm/coordinate.hpp" #include "util/coordinate.hpp"
#include <string> #include <string>
#include <utility> #include <utility>
@ -18,55 +18,47 @@ const constexpr long double EARTH_RADIUS = 6372797.560856;
namespace coordinate_calculation namespace coordinate_calculation
{ {
double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2);
double haversineDistance(const FixedPointCoordinate first_coordinate, double haversineDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
const FixedPointCoordinate second_coordinate);
double greatCircleDistance(const FixedPointCoordinate first_coordinate, double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
const FixedPointCoordinate 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, double perpendicularDistance(const Coordinate segment_source,
const FixedPointCoordinate segment_target, const Coordinate segment_target,
const FixedPointCoordinate query_location); const Coordinate query_location,
Coordinate &nearest_location,
double perpendicularDistance(const FixedPointCoordinate segment_source,
const FixedPointCoordinate segment_target,
const FixedPointCoordinate query_location,
FixedPointCoordinate &nearest_location,
double &ratio); double &ratio);
double double perpendicularDistanceFromProjectedCoordinate(
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, const Coordinate segment_source,
const FixedPointCoordinate segment_target, const Coordinate segment_target,
const FixedPointCoordinate query_location, const Coordinate query_location,
const std::pair<double, double> projected_coordinate); const std::pair<double, double> projected_xy_coordinate);
double double perpendicularDistanceFromProjectedCoordinate(
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, const Coordinate segment_source,
const FixedPointCoordinate segment_target, const Coordinate segment_target,
const FixedPointCoordinate query_location, const Coordinate query_location,
const std::pair<double, double> projected_coordinate, const std::pair<double, double> projected_xy_coordinate,
FixedPointCoordinate &nearest_location, Coordinate &nearest_location,
double &ratio); double &ratio);
double degToRad(const double degree); double degToRad(const double degree);
double radToDeg(const double radian); double radToDeg(const double radian);
double bearing(const FixedPointCoordinate first_coordinate, double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate);
const FixedPointCoordinate second_coordinate);
// Get angle of line segment (A,C)->(C,B) // Get angle of line segment (A,C)->(C,B)
double computeAngle(const FixedPointCoordinate first, double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third);
const FixedPointCoordinate second,
const FixedPointCoordinate third);
namespace mercator namespace mercator
{ {
double yToLat(const double value); FloatLatitude yToLat(const double value);
double latToY(const double latitude); double latToY(const FloatLatitude latitude);
} // ns mercator } // ns mercator
} // ns coordinate_calculation } // ns coordinate_calculation
} // ns util } // ns util

View File

@ -86,7 +86,7 @@ NodeID loadNodesFromFile(std::istream &input_stream,
{ {
input_stream.read(reinterpret_cast<char *>(&current_node), input_stream.read(reinterpret_cast<char *>(&current_node),
sizeof(extractor::ExternalMemoryNode)); 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) if (current_node.barrier)
{ {
barrier_node_list.emplace_back(i); barrier_node_list.emplace_back(i);

View File

@ -11,7 +11,7 @@ namespace util
{ {
// Computes a 64 bit value that corresponds to the hilbert space filling curve // 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);
} }
} }

View File

@ -39,9 +39,9 @@ struct MatchingDebugInfo
{ {
json::Object state; json::Object state;
state.values["transitions"] = json::Array(); state.values["transitions"] = json::Array();
state.values["coordinate"] = state.values["coordinate"] = json::make_array(
json::make_array(elem_s.phantom_node.location.lat / COORDINATE_PRECISION, static_cast<double>(toFloating(elem_s.phantom_node.location.lat)),
elem_s.phantom_node.location.lon / COORDINATE_PRECISION); static_cast<double>(toFloating(elem_s.phantom_node.location.lon)));
state.values["viterbi"] = state.values["viterbi"] =
json::clamp_float(engine::map_matching::IMPOSSIBLE_LOG_PROB); json::clamp_float(engine::map_matching::IMPOSSIBLE_LOG_PROB);
state.values["pruned"] = 0u; state.values["pruned"] = 0u;
@ -124,8 +124,10 @@ struct MatchingDebugInfo
json::Array a; json::Array a;
for (const bool v : breakage) for (const bool v : breakage)
{ {
if (v) a.values.emplace_back(json::True()); if (v)
else a.values.emplace_back(json::False()); a.values.emplace_back(json::True());
else
a.values.emplace_back(json::False());
} }
json::get(*object, "breakage") = std::move(a); json::get(*object, "breakage") = std::move(a);

View File

@ -29,16 +29,25 @@ struct RectangleInt2D
{ {
} }
RectangleInt2D(std::int32_t min_lon_, RectangleInt2D(FixedLongitude min_lon_,
std::int32_t max_lon_, FixedLongitude max_lon_,
std::int32_t min_lat_, FixedLatitude min_lat_,
std::int32_t max_lat_) FixedLatitude max_lat_)
: min_lon(min_lon_), max_lon(max_lon_), min_lat(min_lat_), max_lat(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; RectangleInt2D(FloatLongitude min_lon_,
std::int32_t min_lat, max_lat; 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) void MergeBoundingBoxes(const RectangleInt2D &other)
{ {
@ -46,19 +55,19 @@ struct RectangleInt2D
max_lon = std::max(max_lon, other.max_lon); max_lon = std::max(max_lon, other.max_lon);
min_lat = std::min(min_lat, other.min_lat); min_lat = std::min(min_lat, other.min_lat);
max_lat = std::max(max_lat, other.max_lat); max_lat = std::max(max_lat, other.max_lat);
BOOST_ASSERT(min_lat != std::numeric_limits<std::int32_t>::min()); BOOST_ASSERT(min_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(min_lon != std::numeric_limits<std::int32_t>::min()); BOOST_ASSERT(min_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(max_lat != std::numeric_limits<std::int32_t>::min()); BOOST_ASSERT(max_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(max_lon != std::numeric_limits<std::int32_t>::min()); BOOST_ASSERT(max_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
} }
FixedPointCoordinate Centroid() const Coordinate Centroid() const
{ {
FixedPointCoordinate centroid; Coordinate centroid;
// The coordinates of the midpoints are given by: // The coordinates of the midpoints are given by:
// x = (x1 + x2) /2 and y = (y1 + y2) /2. // x = (x1 + x2) /2 and y = (y1 + y2) /2.
centroid.lon = (min_lon + max_lon) / 2; centroid.lon = (min_lon + max_lon) / FixedLongitude(2);
centroid.lat = (min_lat + max_lat) / 2; centroid.lat = (min_lat + max_lat) / FixedLatitude(2);
return centroid; return centroid;
} }
@ -70,7 +79,7 @@ struct RectangleInt2D
min_lat > other.max_lat); min_lat > other.max_lat);
} }
double GetMinDist(const FixedPointCoordinate location) const double GetMinDist(const Coordinate location) const
{ {
const bool is_contained = Contains(location); const bool is_contained = Contains(location);
if (is_contained) if (is_contained)
@ -108,35 +117,35 @@ struct RectangleInt2D
{ {
case NORTH: case NORTH:
min_dist = coordinate_calculation::greatCircleDistance( min_dist = coordinate_calculation::greatCircleDistance(
location, FixedPointCoordinate(max_lat, location.lon)); location, Coordinate(location.lon, max_lat));
break; break;
case SOUTH: case SOUTH:
min_dist = coordinate_calculation::greatCircleDistance( min_dist = coordinate_calculation::greatCircleDistance(
location, FixedPointCoordinate(min_lat, location.lon)); location, Coordinate(location.lon, min_lat));
break; break;
case WEST: case WEST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist = coordinate_calculation::greatCircleDistance(
location, FixedPointCoordinate(location.lat, min_lon)); location, Coordinate(min_lon, location.lat));
break; break;
case EAST: case EAST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist = coordinate_calculation::greatCircleDistance(
location, FixedPointCoordinate(location.lat, max_lon)); location, Coordinate(max_lon, location.lat));
break; break;
case NORTH_EAST: case NORTH_EAST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist =
location, FixedPointCoordinate(max_lat, max_lon)); coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, max_lat));
break; break;
case NORTH_WEST: case NORTH_WEST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist =
location, FixedPointCoordinate(max_lat, min_lon)); coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, max_lat));
break; break;
case SOUTH_EAST: case SOUTH_EAST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist =
location, FixedPointCoordinate(min_lat, max_lon)); coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, min_lat));
break; break;
case SOUTH_WEST: case SOUTH_WEST:
min_dist = coordinate_calculation::greatCircleDistance( min_dist =
location, FixedPointCoordinate(min_lat, min_lon)); coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, min_lat));
break; break;
default: default:
break; break;
@ -147,14 +156,14 @@ struct RectangleInt2D
return min_dist; return min_dist;
} }
double GetMinMaxDist(const FixedPointCoordinate location) const double GetMinMaxDist(const Coordinate location) const
{ {
double min_max_dist = std::numeric_limits<double>::max(); double min_max_dist = std::numeric_limits<double>::max();
// Get minmax distance to each of the four sides // Get minmax distance to each of the four sides
const FixedPointCoordinate upper_left(max_lat, min_lon); const Coordinate upper_left(min_lon, max_lat);
const FixedPointCoordinate upper_right(max_lat, max_lon); const Coordinate upper_right(max_lon, max_lat);
const FixedPointCoordinate lower_right(min_lat, max_lon); const Coordinate lower_right(max_lon, min_lat);
const FixedPointCoordinate lower_left(min_lat, min_lon); const Coordinate lower_left(min_lon, min_lat);
min_max_dist = min_max_dist =
std::min(min_max_dist, std::min(min_max_dist,
@ -178,11 +187,11 @@ struct RectangleInt2D
return min_max_dist; 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); 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;
} }
}; };
} }

View File

@ -37,7 +37,7 @@ namespace util
// Static RTree for serving nearest neighbour queries // Static RTree for serving nearest neighbour queries
template <class EdgeDataT, template <class EdgeDataT,
class CoordinateListT = std::vector<FixedPointCoordinate>, class CoordinateListT = std::vector<Coordinate>,
bool UseSharedMemory = false, bool UseSharedMemory = false,
std::uint32_t BRANCHING_FACTOR = 64, std::uint32_t BRANCHING_FACTOR = 64,
std::uint32_t LEAF_NODE_SIZE = 1024> std::uint32_t LEAF_NODE_SIZE = 1024>
@ -122,8 +122,8 @@ class StaticRTree
// generate auxiliary vector of hilbert-values // generate auxiliary vector of hilbert-values
tbb::parallel_for( tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, m_element_count), tbb::blocked_range<uint64_t>(0, m_element_count),
[&input_data_vector, &input_wrapper_vector, &coordinate_list]( [&input_data_vector, &input_wrapper_vector,
const tbb::blocked_range<uint64_t> &range) &coordinate_list](const tbb::blocked_range<uint64_t> &range)
{ {
for (uint64_t element_counter = range.begin(), end = range.end(); for (uint64_t element_counter = range.begin(), end = range.end();
element_counter != end; ++element_counter) element_counter != end; ++element_counter)
@ -137,14 +137,14 @@ class StaticRTree
BOOST_ASSERT(current_element.u < coordinate_list.size()); BOOST_ASSERT(current_element.u < coordinate_list.size());
BOOST_ASSERT(current_element.v < coordinate_list.size()); BOOST_ASSERT(current_element.v < coordinate_list.size());
FixedPointCoordinate current_centroid = EdgeDataT::Centroid( Coordinate current_centroid =
FixedPointCoordinate(coordinate_list[current_element.u].lat, EdgeDataT::Centroid(Coordinate(coordinate_list[current_element.u].lon,
coordinate_list[current_element.u].lon), coordinate_list[current_element.u].lat),
FixedPointCoordinate(coordinate_list[current_element.v].lat, Coordinate(coordinate_list[current_element.v].lon,
coordinate_list[current_element.v].lon)); coordinate_list[current_element.v].lat));
current_centroid.lat = current_centroid.lat = FixedLatitude(
COORDINATE_PRECISION * coordinate_calculation::mercator::latToY( COORDINATE_PRECISION *
current_centroid.lat / COORDINATE_PRECISION); coordinate_calculation::mercator::latToY(toFloating(current_centroid.lat)));
current_wrapper.m_hilbert_value = hilbertCode(current_centroid); current_wrapper.m_hilbert_value = hilbertCode(current_centroid);
} }
@ -377,8 +377,7 @@ class StaticRTree
} }
// Override filter and terminator for the desired behaviour. // Override filter and terminator for the desired behaviour.
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate, std::vector<EdgeDataT> Nearest(const Coordinate input_coordinate, const std::size_t max_results)
const std::size_t max_results)
{ {
return Nearest(input_coordinate, return Nearest(input_coordinate,
[](const EdgeDataT &) [](const EdgeDataT &)
@ -393,14 +392,13 @@ class StaticRTree
// Override filter and terminator for the desired behaviour. // Override filter and terminator for the desired behaviour.
template <typename FilterT, typename TerminationT> template <typename FilterT, typename TerminationT>
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate, std::vector<EdgeDataT>
const FilterT filter, Nearest(const Coordinate input_coordinate, const FilterT filter, const TerminationT terminate)
const TerminationT terminate)
{ {
std::vector<EdgeDataT> results; std::vector<EdgeDataT> results;
std::pair<double, double> projected_coordinate = { std::pair<double, double> projected_coordinate = {
coordinate_calculation::mercator::latToY(input_coordinate.lat / COORDINATE_PRECISION), static_cast<double>(toFloating(input_coordinate.lon)),
input_coordinate.lon / COORDINATE_PRECISION}; coordinate_calculation::mercator::latToY(toFloating(input_coordinate.lat))};
// initialize queue with root element // initialize queue with root element
std::priority_queue<QueryCandidate> traversal_queue; std::priority_queue<QueryCandidate> traversal_queue;
@ -462,7 +460,7 @@ class StaticRTree
private: private:
template <typename QueueT> template <typename QueueT>
void ExploreLeafNode(const std::uint32_t leaf_id, void ExploreLeafNode(const std::uint32_t leaf_id,
const FixedPointCoordinate input_coordinate, const Coordinate input_coordinate,
const std::pair<double, double> &projected_coordinate, const std::pair<double, double> &projected_coordinate,
QueueT &traversal_queue) QueueT &traversal_queue)
{ {
@ -487,7 +485,7 @@ class StaticRTree
template <class QueueT> template <class QueueT>
void ExploreTreeNode(const TreeNode &parent, void ExploreTreeNode(const TreeNode &parent,
const FixedPointCoordinate input_coordinate, const Coordinate input_coordinate,
QueueT &traversal_queue) QueueT &traversal_queue)
{ {
for (std::uint32_t i = 0; i < parent.child_count; ++i) 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, std::max(rectangle.max_lat, std::max(coordinate_list[objects[i].u].lat,
coordinate_list[objects[i].v].lat)); coordinate_list[objects[i].v].lat));
} }
BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.min_lon != FixedLongitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.min_lat != FixedLatitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(rectangle.max_lat != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.max_lon != FixedLongitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(rectangle.max_lon != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.max_lat != FixedLatitude(std::numeric_limits<int>::min()));
} }
}; };

View File

@ -18,21 +18,30 @@ namespace osrm
{ \ { \
static_assert(std::is_arithmetic<From>(), ""); \ static_assert(std::is_arithmetic<From>(), ""); \
From x; \ From x; \
friend std::ostream& operator<<(std::ostream& stream, const To& inst); \ friend std::ostream &operator<<(std::ostream &stream, const To &inst); \
\ \
public: \ public: \
To() = default; \ To() = default; \
explicit To(const From x_) : x(x_) {} \ explicit To(const From x_) : x(x_) {} \
explicit operator From &() { return x; } \ explicit operator From &() { return x; } \
explicit operator const From &() const { return x; } \ explicit operator From() const { return x; } \
bool operator<(const To &z_) const { return x < static_cast<const From>(z_); } \ To operator+(const To rhs_) const { return To(x + static_cast<const From>(rhs_)); } \
bool operator>(const To &z_) const { return x > static_cast<const From>(z_); } \ To operator-(const To rhs_) const { return To(x - static_cast<const From>(rhs_)); } \
bool operator<=(const To &z_) const { return x <= static_cast<const From>(z_); } \ To operator*(const To rhs_) const { return To(x * static_cast<const From>(rhs_)); } \
bool operator>=(const To &z_) const { return x >= static_cast<const From>(z_); } \ To operator/(const To rhs_) const { return To(x / static_cast<const From>(rhs_)); } \
bool operator==(const To &z_) const { return x == static_cast<const From>(z_); } \ bool operator<(const To z_) const { return x < static_cast<const From>(z_); } \
bool operator!=(const To &z_) const { return x != static_cast<const From>(z_); } \ bool operator>(const To z_) const { return x > static_cast<const From>(z_); } \
bool operator<=(const To z_) const { return x <= static_cast<const From>(z_); } \
bool operator>=(const To z_) const { return x >= static_cast<const From>(z_); } \
bool operator==(const To z_) const { return x == static_cast<const From>(z_); } \
bool operator!=(const To z_) const { return x != static_cast<const From>(z_); } \
}; \ }; \
inline From To##_to_##From(To to) { return static_cast<From>(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 \ namespace std \
{ \ { \
template <> struct hash<To> \ template <> struct hash<To> \
@ -42,9 +51,6 @@ namespace osrm
return std::hash<From>()(static_cast<const From>(k)); \ return std::hash<From>()(static_cast<const From>(k)); \
} \ } \
}; \ }; \
} \
inline std::ostream& operator<<(std::ostream& stream, const To& inst) { \
return stream << #To << '(' << inst.x << ')'; \
} }
} }

View File

@ -1,6 +1,8 @@
#ifndef UTIL_TILES_HPP #ifndef UTIL_TILES_HPP
#define UTIL_TILES_HPP #define UTIL_TILES_HPP
#include "util/coordinate.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <cmath> #include <cmath>
@ -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<double>(lat) * M_PI / 180.);
auto p2z = std::pow(2, detail::MAX_ZOOM); auto p2z = std::pow(2, detail::MAX_ZOOM);
unsigned x = p2z * (lon / 360. + 0.5); unsigned x = p2z * (static_cast<double>(lon) / 360. + 0.5);
unsigned y = p2z * (0.5 - 0.25 * std::log((1 + sin_lat) / (1 - sin_lat)) / M_PI); unsigned y = p2z * (0.5 - 0.25 * std::log((1 + sin_lat) / (1 - sin_lat)) / M_PI);
return Tile{x, y, detail::MAX_ZOOM}; return Tile{x, y, detail::MAX_ZOOM};
} }
inline Tile getBBMaxZoomTile(const double min_lon, inline Tile getBBMaxZoomTile(const FloatLongitude min_lon,
const double min_lat, const FloatLatitude min_lat,
const double max_lon, const FloatLongitude max_lon,
const double max_lat) const FloatLatitude max_lat)
{ {
const auto top_left = pointToTile(min_lon, min_lat); const auto top_left = pointToTile(min_lon, min_lat);
const auto bottom_left = pointToTile(max_lon, max_lat); const auto bottom_left = pointToTile(max_lon, max_lat);

View File

@ -8,7 +8,10 @@
// OpenStreetMap node ids are higher than 2^32 // OpenStreetMap node ids are higher than 2^32
OSRM_STRONG_TYPEDEF(uint64_t, OSMNodeID) OSRM_STRONG_TYPEDEF(uint64_t, OSMNodeID)
OSRM_STRONG_TYPEDEF_HASHABLE(uint64_t, OSMNodeID)
OSRM_STRONG_TYPEDEF(uint32_t, OSMWayID) OSRM_STRONG_TYPEDEF(uint32_t, OSMWayID)
OSRM_STRONG_TYPEDEF_HASHABLE(uint32_t, OSMWayID)
static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::max()); static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::max());
static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::max()); static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::max());

View File

@ -4,8 +4,7 @@
#include "engine/geospatial_query.hpp" #include "engine/geospatial_query.hpp"
#include "util/timing_util.hpp" #include "util/timing_util.hpp"
#include "mocks/mock_datafacade.hpp" #include "mocks/mock_datafacade.hpp"
#include "util/coordinate.hpp"
#include "osrm/coordinate.hpp"
#include <iostream> #include <iostream>
#include <random> #include <random>
@ -25,23 +24,23 @@ constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
using RTreeLeaf = extractor::EdgeBasedNode; using RTreeLeaf = extractor::EdgeBasedNode;
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<util::FixedPointCoordinate>>; using CoordinateListPtr = std::shared_ptr<std::vector<util::Coordinate>>;
using BenchStaticRTree = using BenchStaticRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, false>::vector, false>; util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, false>::vector, false>;
using BenchQuery = engine::GeospatialQuery<BenchStaticRTree, MockDataFacade>; using BenchQuery = engine::GeospatialQuery<BenchStaticRTree, MockDataFacade>;
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); boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
extractor::QueryNode current_node; extractor::QueryNode current_node;
unsigned coordinate_count = 0; unsigned coordinate_count = 0;
nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned)); nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned));
auto coords = std::make_shared<std::vector<FixedPointCoordinate>>(coordinate_count); auto coords = std::make_shared<std::vector<Coordinate>>(coordinate_count);
for (unsigned i = 0; i < coordinate_count; ++i) for (unsigned i = 0; i < coordinate_count; ++i)
{ {
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode)); nodes_input_stream.read((char *)&current_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).lat) >> 30) == 0);
BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0); BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0);
} }
@ -49,7 +48,7 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes
} }
template <typename QueryT> template <typename QueryT>
void benchmarkQuery(const std::vector<FixedPointCoordinate> &queries, void benchmarkQuery(const std::vector<util::Coordinate> &queries,
const std::string &name, const std::string &name,
QueryT query) QueryT query)
{ {
@ -75,38 +74,35 @@ void benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer
std::mt19937 mt_rand(RANDOM_SEED); std::mt19937 mt_rand(RANDOM_SEED);
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); 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::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
std::vector<FixedPointCoordinate> queries; std::vector<util::Coordinate> queries;
for (unsigned i = 0; i < num_queries; i++) for (unsigned i = 0; i < num_queries; i++)
{ {
queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand)); 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); return rtree.Nearest(q, 1);
}); });
benchmarkQuery(queries, "raw RTree queries (10 results)", benchmarkQuery(queries, "raw RTree queries (10 results)", [&rtree](const util::Coordinate &q)
[&rtree](const FixedPointCoordinate &q)
{ {
return rtree.Nearest(q, 10); return rtree.Nearest(q, 10);
}); });
benchmarkQuery(queries, "big component alternative queries", benchmarkQuery(queries, "big component alternative queries",
[&geo_query](const FixedPointCoordinate &q) [&geo_query](const util::Coordinate &q)
{ {
return geo_query.NearestPhantomNodeWithAlternativeFromBigComponent(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); return geo_query.NearestPhantomNodesInRange(q, 1000);
}); });
benchmarkQuery(queries, "PhantomNode query (1 result)", benchmarkQuery(queries, "PhantomNode query (1 result)", [&geo_query](const util::Coordinate &q)
[&geo_query](const FixedPointCoordinate &q)
{ {
return geo_query.NearestPhantomNodes(q, 1); return geo_query.NearestPhantomNodes(q, 1);
}); });
benchmarkQuery(queries, "PhantomNode query (10 result)", benchmarkQuery(queries, "PhantomNode query (10 result)", [&geo_query](const util::Coordinate &q)
[&geo_query](const FixedPointCoordinate &q)
{ {
return geo_query.NearestPhantomNodes(q, 10); return geo_query.NearestPhantomNodes(q, 10);
}); });
@ -130,7 +126,8 @@ int main(int argc, char **argv)
auto coords = osrm::benchmarks::loadCoordinates(nodes_path); auto coords = osrm::benchmarks::loadCoordinates(nodes_path);
osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords); osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords);
std::unique_ptr<osrm::benchmarks::MockDataFacade> mockfacade_ptr(new osrm::benchmarks::MockDataFacade); std::unique_ptr<osrm::benchmarks::MockDataFacade> mockfacade_ptr(
new osrm::benchmarks::MockDataFacade);
osrm::benchmarks::BenchQuery query(rtree, coords, *mockfacade_ptr); osrm::benchmarks::BenchQuery query(rtree, coords, *mockfacade_ptr);
osrm::benchmarks::benchmark(rtree, query, 10000); osrm::benchmarks::benchmark(rtree, query, 10000);

View File

@ -37,7 +37,7 @@ template <> struct hash<std::pair<OSMNodeID, OSMNodeID>>
{ {
std::size_t operator()(const std::pair<OSMNodeID, OSMNodeID> &k) const std::size_t operator()(const std::pair<OSMNodeID, OSMNodeID> &k) const
{ {
return OSMNodeID_to_uint64_t(k.first) ^ (OSMNodeID_to_uint64_t(k.second) << 12); return static_cast<uint64_t>(k.first) ^ (static_cast<uint64_t>(k.second) << 12);
} }
}; };
} }
@ -70,9 +70,8 @@ int Contractor::Run()
util::DeallocatingVector<extractor::EdgeBasedEdge> edge_based_edge_list; util::DeallocatingVector<extractor::EdgeBasedEdge> edge_based_edge_list;
std::size_t max_edge_id = LoadEdgeExpandedGraph( std::size_t max_edge_id = LoadEdgeExpandedGraph(
config.edge_based_graph_path, edge_based_edge_list, config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path,
config.edge_segment_lookup_path, config.edge_penalty_path, config.edge_penalty_path, config.segment_speed_lookup_path, config.node_based_graph_path,
config.segment_speed_lookup_path, config.node_based_graph_path,
config.geometry_path, config.rtree_leaf_path); config.geometry_path, config.rtree_leaf_path);
// Contracting the edge-expanded graph // Contracting the edge-expanded graph
@ -195,7 +194,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (!nodes_input_stream) 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; unsigned number_of_nodes = 0;
@ -203,7 +202,8 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
internal_to_external_node_map.resize(number_of_nodes); internal_to_external_node_map.resize(number_of_nodes);
// Load all the query nodes into a vector // Load all the query nodes into a vector
nodes_input_stream.read(reinterpret_cast<char *>(&(internal_to_external_node_map[0])), number_of_nodes * sizeof(extractor::QueryNode)); nodes_input_stream.read(reinterpret_cast<char *>(&(internal_to_external_node_map[0])),
number_of_nodes * sizeof(extractor::QueryNode));
} }
std::vector<unsigned> m_geometry_indices; std::vector<unsigned> m_geometry_indices;
@ -213,7 +213,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ifstream geometry_stream(geometry_filename, std::ios::binary); std::ifstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream) 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_indices = 0;
unsigned number_of_compressed_geometries = 0; unsigned number_of_compressed_geometries = 0;
@ -234,8 +234,10 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (number_of_compressed_geometries > 0) if (number_of_compressed_geometries > 0)
{ {
geometry_stream.read((char *)&(m_geometry_list[0]), geometry_stream.read(
number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); (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); std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in);
if (!leaf_node_file) 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; uint64_t m_element_count;
leaf_node_file.read((char *)&m_element_count, sizeof(uint64_t)); leaf_node_file.read((char *)&m_element_count, sizeof(uint64_t));
@ -259,71 +261,93 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
{ {
leaf_node_file.read(reinterpret_cast<char *>(&current_node), sizeof(current_node)); leaf_node_file.read(reinterpret_cast<char *>(&current_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 *u;
extractor::QueryNode *v; extractor::QueryNode *v;
if (leaf_object.forward_packed_geometry_id != SPECIAL_EDGEID) 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) if (leaf_object.fwd_segment_position == 0)
{ {
u = &(internal_to_external_node_map[leaf_object.u]); 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 else
{ {
u = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position - 1].node_id]); u = &(internal_to_external_node_map
v = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position].node_id]); [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 = const double segment_length =
util::coordinate_calculation::greatCircleDistance( util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon); 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()) if (forward_speed_iter != segment_speed_lookup.end())
{ {
int new_segment_weight = int new_segment_weight = std::max(
std::max(1, static_cast<int>(std::floor( 1, static_cast<int>(std::floor(
(segment_length * 10.) / (forward_speed_iter->second / 3.6) + .5))); (segment_length * 10.) / (forward_speed_iter->second / 3.6) +
m_geometry_list[forward_begin + leaf_object.fwd_segment_position].weight = new_segment_weight; .5)));
m_geometry_list[forward_begin + leaf_object.fwd_segment_position]
.weight = new_segment_weight;
} }
} }
if (leaf_object.reverse_packed_geometry_id != SPECIAL_EDGEID) 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_begin =
const unsigned reverse_end = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1); 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) if (rev_segment_position == 0)
{ {
u = &(internal_to_external_node_map[leaf_object.v]); 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 else
{ {
u = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position - 1].node_id]); u = &(internal_to_external_node_map
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position].node_id]); [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 = const double segment_length =
util::coordinate_calculation::greatCircleDistance( util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon); 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()) if (reverse_speed_iter != segment_speed_lookup.end())
{ {
int new_segment_weight = int new_segment_weight = std::max(
std::max(1, static_cast<int>(std::floor( 1, static_cast<int>(std::floor(
(segment_length * 10.) / (reverse_speed_iter->second / 3.6) + .5))); (segment_length * 10.) / (reverse_speed_iter->second / 3.6) +
m_geometry_list[reverse_begin + rev_segment_position].weight = new_segment_weight; .5)));
m_geometry_list[reverse_begin + rev_segment_position].weight =
new_segment_weight;
} }
} }
} }
m_element_count -= current_node.object_count; m_element_count -= current_node.object_count;
} }
} }
@ -332,17 +356,20 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ofstream geometry_stream(geometry_filename, std::ios::binary); std::ofstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream) 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_indices = m_geometry_indices.size();
const unsigned number_of_compressed_geometries = m_geometry_list.size(); const unsigned number_of_compressed_geometries = m_geometry_list.size();
geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices), sizeof(unsigned)); geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices),
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])), number_of_indices * sizeof(unsigned)); sizeof(unsigned));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_compressed_geometries), sizeof(unsigned)); geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])),
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_list[0])), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge)); number_of_indices * sizeof(unsigned));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_compressed_geometries),
sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_list[0])),
number_of_compressed_geometries *
sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
} }
} }
// TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily // TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily

View File

@ -93,11 +93,11 @@ std::string instructionToString(extractor::TurnInstruction instruction)
return token; return token;
} }
util::json::Array coordinateToLonLat(const FixedPointCoordinate &coordinate) util::json::Array coordinateToLonLat(const util::Coordinate &coordinate)
{ {
util::json::Array array; util::json::Array array;
array.values.push_back(coordinate.lon / COORDINATE_PRECISION); array.values.push_back(static_cast<double>(toFloating(coordinate.lon)));
array.values.push_back(coordinate.lat / COORDINATE_PRECISION); array.values.push_back(static_cast<double>(toFloating(coordinate.lat)));
return array; return array;
} }
@ -164,7 +164,7 @@ util::json::Object makeRoute(const guidance::Route &route,
} }
util::json::Object 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; util::json::Object waypoint;
waypoint.values["location"] = detail::coordinateToLonLat(location); waypoint.values["location"] = detail::coordinateToLonLat(location);

View File

@ -24,21 +24,21 @@ namespace
struct CoordinatePairCalculator struct CoordinatePairCalculator
{ {
CoordinatePairCalculator() = delete; CoordinatePairCalculator() = delete;
CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a, CoordinatePairCalculator(const util::Coordinate coordinate_a,
const util::FixedPointCoordinate coordinate_b) const util::Coordinate coordinate_b)
{ {
// initialize distance calculator with two fixed coordinates a, b // initialize distance calculator with two fixed coordinates a, b
first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD; first_lon = static_cast<double>(toFloating(coordinate_a.lon)) * util::RAD;
first_lon = (coordinate_a.lon / COORDINATE_PRECISION) * util::RAD; first_lat = static_cast<double>(toFloating(coordinate_a.lat)) * util::RAD;
second_lat = (coordinate_b.lat / COORDINATE_PRECISION) * util::RAD; second_lon = static_cast<double>(toFloating(coordinate_b.lon)) * util::RAD;
second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD; second_lat = static_cast<double>(toFloating(coordinate_b.lat)) * util::RAD;
} }
int operator()(const util::FixedPointCoordinate other) const int operator()(const util::Coordinate other) const
{ {
// set third coordinate c // set third coordinate c
const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD; const float float_lon1 = static_cast<double>(toFloating(other.lon)) * util::RAD;
const float float_lon1 = (other.lon / COORDINATE_PRECISION) * util::RAD; const float float_lat1 = static_cast<double>(toFloating(other.lat)) * util::RAD;
// compute distance (a,c) // compute distance (a,c)
const float x_value_1 = (first_lon - float_lon1) * cos((float_lat1 + first_lat) / 2.f); const float x_value_1 = (first_lon - float_lon1) * cos((float_lat1 + first_lat) / 2.f);
@ -61,9 +61,8 @@ struct CoordinatePairCalculator
}; };
} }
std::vector<util::FixedPointCoordinate> std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::const_iterator begin,
douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin, std::vector<util::Coordinate>::const_iterator end,
std::vector<util::FixedPointCoordinate>::const_iterator end,
const unsigned zoom_level) const unsigned zoom_level)
{ {
BOOST_ASSERT_MSG(zoom_level < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE, BOOST_ASSERT_MSG(zoom_level < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE,
@ -83,7 +82,7 @@ douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
std::stack<GeometryRange> recursion_stack; std::stack<GeometryRange> recursion_stack;
recursion_stack.emplace(0UL, size-1); recursion_stack.emplace(0UL, size - 1);
// mark locations as 'necessary' by divide-and-conquer // mark locations as 'necessary' by divide-and-conquer
while (!recursion_stack.empty()) while (!recursion_stack.empty())
@ -131,7 +130,7 @@ douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
} }
auto simplified_size = std::count(is_necessary.begin(), is_necessary.end(), true); auto simplified_size = std::count(is_necessary.begin(), is_necessary.end(), true);
std::vector<util::FixedPointCoordinate> simplified_geometry; std::vector<util::Coordinate> simplified_geometry;
simplified_geometry.reserve(simplified_size); simplified_geometry.reserve(simplified_size);
for (auto idx : boost::irange<std::size_t>(0UL, size)) for (auto idx : boost::irange<std::size_t>(0UL, size))
{ {

View File

@ -20,10 +20,10 @@ namespace
unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometries) unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometries)
{ {
int min_lon = std::numeric_limits<int>::max(); util::FixedLongitude min_lon{std::numeric_limits<int>::max()};
int min_lat = std::numeric_limits<int>::max(); util::FixedLongitude max_lon{-std::numeric_limits<int>::max()};
int max_lon = -std::numeric_limits<int>::max(); util::FixedLatitude min_lat{std::numeric_limits<int>::max()};
int max_lat = -std::numeric_limits<int>::max(); util::FixedLatitude max_lat{-std::numeric_limits<int>::max()};
for (const auto &leg_geometry : leg_geometries) for (const auto &leg_geometry : leg_geometries)
{ {
@ -36,12 +36,15 @@ unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &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<util::FixedPointCoordinate> simplifyGeometry(const std::vector<LegGeometry> &leg_geometries, const unsigned zoom_level) std::vector<util::Coordinate> simplifyGeometry(const std::vector<LegGeometry> &leg_geometries,
const unsigned zoom_level)
{ {
std::vector<util::FixedPointCoordinate> overview_geometry; std::vector<util::Coordinate> overview_geometry;
auto leg_index = 0UL; auto leg_index = 0UL;
for (const auto geometry : leg_geometries) for (const auto geometry : leg_geometries)
{ {
@ -59,8 +62,8 @@ std::vector<util::FixedPointCoordinate> simplifyGeometry(const std::vector<LegGe
} }
} }
std::vector<util::FixedPointCoordinate> std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_simplification) const bool use_simplification)
{ {
if (use_simplification) if (use_simplification)
{ {
@ -75,7 +78,7 @@ assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_
return sum + leg_geometry.locations.size(); return sum + leg_geometry.locations.size();
}) - }) -
leg_geometries.size() + 1; leg_geometries.size() + 1;
std::vector<util::FixedPointCoordinate> overview_geometry; std::vector<util::Coordinate> overview_geometry;
overview_geometry.reserve(overview_size); overview_geometry.reserve(overview_size);
auto leg_index = 0UL; auto leg_index = 0UL;

View File

@ -26,7 +26,7 @@ namespace plugins
{ {
// Filters PhantomNodes to obtain a set of viable candiates // Filters PhantomNodes to obtain a set of viable candiates
void filterCandidates(const std::vector<util::FixedPointCoordinate> &coordinates, void filterCandidates(const std::vector<util::Coordinate> &coordinates,
MatchPlugin::CandidateLists &candidates_lists) MatchPlugin::CandidateLists &candidates_lists)
{ {
for (const auto current_coordinate : util::irange<std::size_t>(0, coordinates.size())) for (const auto current_coordinate : util::irange<std::size_t>(0, coordinates.size()))

View File

@ -57,7 +57,6 @@ std::string encode(std::vector<int> &numbers)
} }
} // anonymous ns } // anonymous ns
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end) std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end)
{ {
auto size = std::distance(begin, end); auto size = std::distance(begin, end);
@ -69,20 +68,22 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
std::vector<int> delta_numbers; std::vector<int> delta_numbers;
BOOST_ASSERT(size > 0); BOOST_ASSERT(size > 0);
delta_numbers.reserve((size - 1) * 2); delta_numbers.reserve((size - 1) * 2);
util::FixedPointCoordinate previous_coordinate = {0, 0}; util::Coordinate previous_coordinate{util::FixedLongitude(0), util::FixedLatitude(0)};
std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const FixedPointCoordinate loc) std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const util::Coordinate loc)
{ {
const int lat_diff = (loc.lat - previous_coordinate.lat) * detail::COORDINATE_TO_POLYLINE; const int lat_diff = static_cast<int>(loc.lat - previous_coordinate.lat) *
const int lon_diff = (loc.lon - previous_coordinate.lon) * detail::COORDINATE_TO_POLYLINE; detail::COORDINATE_TO_POLYLINE;
const int lon_diff = static_cast<int>(loc.lon - previous_coordinate.lon) *
detail::COORDINATE_TO_POLYLINE;
delta_numbers.emplace_back(lat_diff); delta_numbers.emplace_back(lat_diff);
delta_numbers.emplace_back(lon_diff); delta_numbers.emplace_back(lon_diff);
previous_coordinate = loc; previous_coordinate = loc;
}); });
return encode(delta_numbers); return encode(delta_numbers);
} }
std::vector<util::FixedPointCoordinate> decodePolyline(const std::string &geometry_string) std::vector<util::Coordinate> decodePolyline(const std::string &geometry_string)
{ {
std::vector<util::FixedPointCoordinate> new_coordinates; std::vector<util::Coordinate> new_coordinates;
int index = 0, len = geometry_string.size(); int index = 0, len = geometry_string.size();
int lat = 0, lng = 0; int lat = 0, lng = 0;
@ -109,9 +110,9 @@ std::vector<util::FixedPointCoordinate> decodePolyline(const std::string &geomet
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng; lng += dlng;
util::FixedPointCoordinate p; util::Coordinate p;
p.lat = lat * detail::POLYLINE_TO_COORDINATE; p.lat = util::FixedLatitude(lat * detail::POLYLINE_TO_COORDINATE);
p.lon = lng * detail::POLYLINE_TO_COORDINATE; p.lon = util::FixedLongitude(lng * detail::POLYLINE_TO_COORDINATE);
new_coordinates.push_back(p); new_coordinates.push_back(p);
} }

View File

@ -73,10 +73,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
#ifndef NDEBUG #ifndef NDEBUG
for (const EdgeBasedNode &node : m_edge_based_node_list) for (const EdgeBasedNode &node : m_edge_based_node_list)
{ {
BOOST_ASSERT(m_node_info_list.at(node.u).lat != INT_MAX); BOOST_ASSERT(
BOOST_ASSERT(m_node_info_list.at(node.u).lon != INT_MAX); util::Coordinate(m_node_info_list[node.u].lon, m_node_info_list[node.u].lat).IsValid());
BOOST_ASSERT(m_node_info_list.at(node.v).lon != INT_MAX); BOOST_ASSERT(
BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX); util::Coordinate(m_node_info_list[node.v].lon, m_node_info_list[node.v].lat).IsValid());
} }
#endif #endif
using std::swap; // Koenig swap using std::swap; // Koenig swap
@ -424,8 +424,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const QueryNode &from = m_node_info_list[previous]; const QueryNode &from = m_node_info_list[previous];
const QueryNode &to = m_node_info_list[target_node.node_id]; const QueryNode &to = m_node_info_list[target_node.node_id];
const double segment_length = const double segment_length =
util::coordinate_calculation::greatCircleDistance(from.lat, from.lon, util::coordinate_calculation::greatCircleDistance(from, to);
to.lat, to.lon);
edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id), edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id),
sizeof(to.node_id)); sizeof(to.node_id));
@ -1003,9 +1002,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
{ {
if (m_compressed_edge_container.HasEntryForID(via_eid)) if (m_compressed_edge_container.HasEntryForID(via_eid))
{ {
util::FixedPointCoordinate prev = util::FixedPointCoordinate( util::Coordinate prev = util::Coordinate(m_node_info_list[INVERTED ? tgt : src].lon,
m_node_info_list[INVERTED ? tgt : src].lat, m_node_info_list[INVERTED ? tgt : src].lat),
m_node_info_list[INVERTED ? tgt : src].lon),
cur; cur;
// walk along the edge for the first 5 meters // walk along the edge for the first 5 meters
const auto &geometry = m_compressed_edge_container.GetBucketReference(via_eid); const auto &geometry = m_compressed_edge_container.GetBucketReference(via_eid);
@ -1035,8 +1033,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
for (auto itr = geometry.rbegin(), end = geometry.rend(); itr != end; ++itr) for (auto itr = geometry.rbegin(), end = geometry.rend(); itr != end; ++itr)
{ {
const auto compressed_node = *itr; const auto compressed_node = *itr;
cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat, cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon,
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); this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
if (dist + this_dist > DESIRED_SEGMENT_LENGTH) if (dist + this_dist > DESIRED_SEGMENT_LENGTH)
{ {
@ -1047,7 +1045,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
prev = cur; prev = cur;
prev_id = compressed_node.node_id; 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); this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
return selectBestCandidate(src, dist + this_dist, prev_id, dist); 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) for (auto itr = geometry.begin(), end = geometry.end(); itr != end; ++itr)
{ {
const auto compressed_node = *itr; const auto compressed_node = *itr;
cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat, cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon,
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); this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
if (dist + this_dist > DESIRED_SEGMENT_LENGTH) if (dist + this_dist > DESIRED_SEGMENT_LENGTH)
{ {
@ -1068,7 +1066,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
prev = cur; prev = cur;
prev_id = compressed_node.node_id; 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); this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
return selectBestCandidate(tgt, dist + this_dist, prev_id, dist); return selectBestCandidate(tgt, dist + this_dist, prev_id, dist);
} }

View File

@ -301,7 +301,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
{ {
util::SimpleLogger().Write(LogLevel::logWARNING) util::SimpleLogger().Write(LogLevel::logWARNING)
<< "Found invalid node reference " << "Found invalid node reference "
<< OSMNodeID_to_uint64_t(edge_iterator->result.osm_target_id); << static_cast<uint64_t>(edge_iterator->result.osm_target_id);
edge_iterator->result.target = SPECIAL_NODEID; edge_iterator->result.target = SPECIAL_NODEID;
++edge_iterator; ++edge_iterator;
continue; 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->result.osm_target_id == node_iterator->node_id);
BOOST_ASSERT(edge_iterator->weight_data.speed >= 0); BOOST_ASSERT(edge_iterator->weight_data.speed >= 0);
BOOST_ASSERT(edge_iterator->source_coordinate.lat != std::numeric_limits<int>::min()); BOOST_ASSERT(edge_iterator->source_coordinate.lat !=
BOOST_ASSERT(edge_iterator->source_coordinate.lon != std::numeric_limits<int>::min()); util::FixedLatitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(edge_iterator->source_coordinate.lon !=
util::FixedLongitude(std::numeric_limits<int>::min()));
const double distance = util::coordinate_calculation::greatCircleDistance( const double distance = util::coordinate_calculation::greatCircleDistance(
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon, edge_iterator->source_coordinate,
node_iterator->lat, node_iterator->lon); util::Coordinate(node_iterator->lon, node_iterator->lat));
if (util::lua_function_exists(segment_state, "segment_function")) if (util::lua_function_exists(segment_state, "segment_function"))
{ {

View File

@ -39,8 +39,8 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
const ExtractionNode &result_node) const ExtractionNode &result_node)
{ {
external_memory.all_nodes_list.push_back( external_memory.all_nodes_list.push_back(
{static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION), {util::toFixed(util::FloatLongitude(input_node.location().lon())),
static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION), util::toFixed(util::FloatLatitude(input_node.location().lat())),
OSMNodeID(input_node.id()), result_node.barrier, result_node.traffic_lights}); OSMNodeID(input_node.id()), result_node.barrier, result_node.traffic_lights});
} }

View File

@ -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, ""); return object.get_value_by_key(key, "");
} }
template <class T> double latToDouble(T const &object)
{
return static_cast<double>(util::toFloating(object.lat));
}
template <class T> double lonToDouble(T const &object)
{
return static_cast<double>(util::toFloating(object.lon));
}
// Error handler // Error handler
int luaErrorCallback(lua_State *state) 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<osmium::Way>) .def("get_value_by_key", &get_value_by_key<osmium::Way>)
.def("id", &osmium::Way::id), .def("id", &osmium::Way::id),
luabind::class_<InternalExtractorEdge>("EdgeSource") luabind::class_<InternalExtractorEdge>("EdgeSource")
.property("source_coordinate", &InternalExtractorEdge::source_coordinate) .def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate)
.property("weight_data", &InternalExtractorEdge::weight_data), .def_readwrite("weight_data", &InternalExtractorEdge::weight_data),
luabind::class_<InternalExtractorEdge::WeightData>("WeightData") luabind::class_<InternalExtractorEdge::WeightData>("WeightData")
.def_readwrite("speed", &InternalExtractorEdge::WeightData::speed), .def_readwrite("speed", &InternalExtractorEdge::WeightData::speed),
luabind::class_<ExternalMemoryNode>("EdgeTarget") luabind::class_<ExternalMemoryNode>("EdgeTarget")
.property("lat", &ExternalMemoryNode::lat) .property("lon", &lonToDouble<ExternalMemoryNode>)
.property("lon", &ExternalMemoryNode::lon), .property("lat", &latToDouble<ExternalMemoryNode>),
luabind::class_<util::FixedPointCoordinate>("Coordinate") luabind::class_<util::Coordinate>("Coordinate")
.property("lat", &util::FixedPointCoordinate::lat) .property("lon", &lonToDouble<util::Coordinate>)
.property("lon", &util::FixedPointCoordinate::lon), .property("lat", &latToDouble<util::Coordinate>),
luabind::class_<RasterDatum>("RasterDatum") luabind::class_<RasterDatum>("RasterDatum")
.property("datum", &RasterDatum::datum) .def_readonly("datum", &RasterDatum::datum)
.def("invalid_data", &RasterDatum::get_invalid)]; .def("invalid_data", &RasterDatum::get_invalid)];
if (0 != luaL_dofile(lua_state, file_name.c_str())) if (0 != luaL_dofile(lua_state, file_name.c_str()))

View File

@ -47,9 +47,9 @@ struct URLGrammar : boost::spirit::qi::grammar<Iterator>
}; };
const auto add_coordinate = [this](const boost::fusion::vector<double, double> &lonLat) const auto add_coordinate = [this](const boost::fusion::vector<double, double> &lonLat)
{ {
parsed_url.coordinates.emplace_back( parsed_url.coordinates.emplace_back(util::Coordinate(
util::FixedPointCoordinate(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION, util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION),
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) const auto polyline_to_coordinates = [this](const std::string &polyline)
{ {

View File

@ -40,7 +40,7 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status MatchService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status MatchService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) util::json::Object &result)
{ {

View File

@ -39,7 +39,7 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status NearestService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status NearestService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) util::json::Object &result)
{ {

View File

@ -38,7 +38,7 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status RouteService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status RouteService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) util::json::Object &result)
{ {

View File

@ -57,7 +57,7 @@ std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status TableService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status TableService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) util::json::Object &result)
{ {

View File

@ -38,7 +38,7 @@ std::string getWrongOptionHelp(const engine::api::TripParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status TripService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates, engine::Status TripService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options, std::string &options,
util::json::Object &result) util::json::Object &result)
{ {
@ -67,7 +67,6 @@ engine::Status TripService::RunQuery(std::vector<util::FixedPointCoordinate> coo
return BaseService::routing_machine.Trip(*parameters, result); return BaseService::routing_machine.Trip(*parameters, result);
} }
} }
} }
} }

View File

@ -17,8 +17,7 @@
#include "util/exception.hpp" #include "util/exception.hpp"
#include "util/simple_logger.hpp" #include "util/simple_logger.hpp"
#include "util/typedefs.hpp" #include "util/typedefs.hpp"
#include "util/coordinate.hpp"
#include "osrm/coordinate.hpp"
#ifdef __linux__ #ifdef __linux__
#include <sys/mman.h> #include <sys/mman.h>
@ -38,11 +37,9 @@ namespace osrm
namespace storage namespace storage
{ {
using RTreeLeaf = using RTreeLeaf = typename engine::datafacade::BaseDataFacade::RTreeLeaf;
typename engine::datafacade::BaseDataFacade::RTreeLeaf; using RTreeNode =
using RTreeNode = util::StaticRTree<RTreeLeaf, util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>::TreeNode;
util::ShM<util::FixedPointCoordinate, true>::vector,
true>::TreeNode;
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>; using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;
// delete a shared memory region. report warning if it could not be deleted // delete a shared memory region. report warning if it could not be deleted
@ -309,7 +306,7 @@ int Storage::Run()
boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary); boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
unsigned coordinate_list_size = 0; unsigned coordinate_list_size = 0;
nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned)); nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned));
shared_layout_ptr->SetBlockSize<util::FixedPointCoordinate>(SharedDataLayout::COORDINATE_LIST, shared_layout_ptr->SetBlockSize<util::Coordinate>(SharedDataLayout::COORDINATE_LIST,
coordinate_list_size); coordinate_list_size);
// load geometries sizes // load geometries sizes
@ -438,15 +435,14 @@ int Storage::Run()
} }
// Loading list of coordinates // Loading list of coordinates
util::FixedPointCoordinate *coordinates_ptr = util::Coordinate *coordinates_ptr = shared_layout_ptr->GetBlockPtr<util::Coordinate, true>(
shared_layout_ptr->GetBlockPtr<util::FixedPointCoordinate, true>(
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST); shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
extractor::QueryNode current_node; extractor::QueryNode current_node;
for (unsigned i = 0; i < coordinate_list_size; ++i) for (unsigned i = 0; i < coordinate_list_size; ++i)
{ {
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode)); nodes_input_stream.read((char *)&current_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(); nodes_input_stream.close();

View File

@ -16,49 +16,52 @@ namespace osrm
namespace util namespace util
{ {
FixedPointCoordinate::FixedPointCoordinate() Coordinate::Coordinate()
: lat(std::numeric_limits<int>::min()), lon(std::numeric_limits<int>::min()) : lon(std::numeric_limits<int>::min()), lat(std::numeric_limits<int>::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 #ifndef NDEBUG
if (0 != (std::abs(lat) >> 30)) if (0 != (std::abs(static_cast<int>(lon)) >> 30))
{ {
std::bitset<32> y_coordinate_vector(lat); std::bitset<32> x_coordinate_vector(static_cast<int>(lon));
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
<< ", bits: " << y_coordinate_vector;
}
if (0 != (std::abs(lon) >> 30))
{
std::bitset<32> x_coordinate_vector(lon);
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon SimpleLogger().Write(logDEBUG) << "broken lon: " << lon
<< ", bits: " << x_coordinate_vector; << ", bits: " << x_coordinate_vector;
} }
if (0 != (std::abs(static_cast<int>(lat)) >> 30))
{
std::bitset<32> y_coordinate_vector(static_cast<int>(lat));
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
<< ", bits: " << y_coordinate_vector;
}
#endif #endif
} }
bool FixedPointCoordinate::IsValid() const bool Coordinate::IsValid() const
{ {
return !(lat > 90 * COORDINATE_PRECISION || lat < -90 * COORDINATE_PRECISION || return !(lat > FixedLatitude(90 * COORDINATE_PRECISION) ||
lon > 180 * COORDINATE_PRECISION || lon < -180 * 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; return lhs.lat == rhs.lat && lhs.lon == rhs.lon;
} }
bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs) bool operator!=(const Coordinate lhs, const Coordinate rhs) { return !(lhs == 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<double>(coordinate.lat / COORDINATE_PRECISION) << "," out << "(lon:" << toFloating(coordinate.lon) << ", lat:" << toFloating(coordinate.lat) << ")";
<< static_cast<double>(coordinate.lon / COORDINATE_PRECISION) << ")";
return out; return out;
} }
} }

View File

@ -17,12 +17,16 @@ namespace util
namespace coordinate_calculation 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<int>::min()); auto lon1 = static_cast<int>(coordinate_1.lon);
auto lat1 = static_cast<int>(coordinate_1.lat);
auto lon2 = static_cast<int>(coordinate_2.lon);
auto lat2 = static_cast<int>(coordinate_2.lat);
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon2 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
const double lt1 = lat1 / COORDINATE_PRECISION; const double lt1 = lat1 / COORDINATE_PRECISION;
const double ln1 = lon1 / COORDINATE_PRECISION; const double ln1 = lon1 / COORDINATE_PRECISION;
const double lt2 = lat2 / 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; return EARTH_RADIUS * charv;
} }
double haversineDistance(const FixedPointCoordinate coordinate_1, double greatCircleDistance(const Coordinate coordinate_1, const Coordinate coordinate_2)
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)
{ {
auto lon1 = static_cast<int>(coordinate_1.lon);
auto lat1 = static_cast<int>(coordinate_1.lat);
auto lon2 = static_cast<int>(coordinate_2.lon);
auto lat2 = static_cast<int>(coordinate_2.lat);
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min()); BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min()); BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
@ -73,52 +67,52 @@ double greatCircleDistance(const int lat1, const int lon1, const int lat2, const
return std::hypot(x_value, y_value) * EARTH_RADIUS; return std::hypot(x_value, y_value) * EARTH_RADIUS;
} }
double perpendicularDistance(const FixedPointCoordinate source_coordinate, double perpendicularDistance(const Coordinate source_coordinate,
const FixedPointCoordinate target_coordinate, const Coordinate target_coordinate,
const FixedPointCoordinate query_location) const Coordinate query_location)
{ {
double ratio; double ratio;
FixedPointCoordinate nearest_location; Coordinate nearest_location;
return perpendicularDistance(source_coordinate, target_coordinate, query_location, return perpendicularDistance(source_coordinate, target_coordinate, query_location,
nearest_location, ratio); nearest_location, ratio);
} }
double perpendicularDistance(const FixedPointCoordinate segment_source, double perpendicularDistance(const Coordinate segment_source,
const FixedPointCoordinate segment_target, const Coordinate segment_target,
const FixedPointCoordinate query_location, const Coordinate query_location,
FixedPointCoordinate &nearest_location, Coordinate &nearest_location,
double &ratio) double &ratio)
{ {
using namespace coordinate_calculation; using namespace coordinate_calculation;
return perpendicularDistanceFromProjectedCoordinate( return perpendicularDistanceFromProjectedCoordinate(
segment_source, segment_target, query_location, segment_source, segment_target, query_location,
{mercator::latToY(query_location.lat / COORDINATE_PRECISION), {static_cast<double>(toFloating(query_location.lon)),
query_location.lon / COORDINATE_PRECISION}, mercator::latToY(toFloating(query_location.lat))},
nearest_location, ratio); nearest_location, ratio);
} }
double double perpendicularDistanceFromProjectedCoordinate(
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate source_coordinate, const Coordinate source_coordinate,
const FixedPointCoordinate target_coordinate, const Coordinate target_coordinate,
const FixedPointCoordinate query_location, const Coordinate query_location,
const std::pair<double, double> projected_coordinate) const std::pair<double, double> projected_xy_coordinate)
{ {
double ratio; double ratio;
FixedPointCoordinate nearest_location; Coordinate nearest_location;
return perpendicularDistanceFromProjectedCoordinate(source_coordinate, target_coordinate, return perpendicularDistanceFromProjectedCoordinate(source_coordinate, target_coordinate,
query_location, projected_coordinate, query_location, projected_xy_coordinate,
nearest_location, ratio); nearest_location, ratio);
} }
double double perpendicularDistanceFromProjectedCoordinate(
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source, const Coordinate segment_source,
const FixedPointCoordinate segment_target, const Coordinate segment_target,
const FixedPointCoordinate query_location, const Coordinate query_location,
const std::pair<double, double> projected_coordinate, const std::pair<double, double> projected_xy_coordinate,
FixedPointCoordinate &nearest_location, Coordinate &nearest_location,
double &ratio) double &ratio)
{ {
using namespace coordinate_calculation; using namespace coordinate_calculation;
@ -126,12 +120,12 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_
BOOST_ASSERT(query_location.IsValid()); BOOST_ASSERT(query_location.IsValid());
// initialize values // initialize values
const double x = projected_coordinate.first; const double x = projected_xy_coordinate.first;
const double y = projected_coordinate.second; const double y = projected_xy_coordinate.second;
const double a = mercator::latToY(segment_source.lat / COORDINATE_PRECISION); const double a = mercator::latToY(toFloating(segment_source.lat));
const double b = segment_source.lon / COORDINATE_PRECISION; const double b = static_cast<double>(toFloating(segment_source.lon));
const double c = mercator::latToY(segment_target.lat / COORDINATE_PRECISION); const double c = mercator::latToY(toFloating(segment_target.lat));
const double d = segment_target.lon / COORDINATE_PRECISION; const double d = static_cast<double>(toFloating(segment_target.lon));
double p, q /*,mX*/, new_y; double p, q /*,mX*/, new_y;
if (std::abs(a - c) > std::numeric_limits<double>::epsilon()) if (std::abs(a - c) > std::numeric_limits<double>::epsilon())
{ {
@ -184,8 +178,8 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_
else else
{ {
// point lies in between // point lies in between
nearest_location.lat = static_cast<int>(mercator::yToLat(p) * COORDINATE_PRECISION); nearest_location.lon = toFixed(FloatLongitude(q));
nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION); nearest_location.lat = toFixed(FloatLatitude(mercator::yToLat(p)));
} }
BOOST_ASSERT(nearest_location.IsValid()); BOOST_ASSERT(nearest_location.IsValid());
@ -206,14 +200,13 @@ double radToDeg(const double radian)
return radian * (180.0 * (1. / pi<double>())); return radian * (180.0 * (1. / pi<double>()));
} }
double bearing(const FixedPointCoordinate first_coordinate, double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate)
const FixedPointCoordinate second_coordinate)
{ {
const double lon_diff = const double lon_diff =
second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION; static_cast<double>(toFloating(second_coordinate.lon - first_coordinate.lon));
const double lon_delta = degToRad(lon_diff); const double lon_delta = degToRad(lon_diff);
const double lat1 = degToRad(first_coordinate.lat / COORDINATE_PRECISION); const double lat1 = degToRad(static_cast<double>(toFloating(first_coordinate.lat)));
const double lat2 = degToRad(second_coordinate.lat / COORDINATE_PRECISION); const double lat2 = degToRad(static_cast<double>(toFloating(second_coordinate.lat)));
const double y = std::sin(lon_delta) * std::cos(lat2); const double y = std::sin(lon_delta) * std::cos(lat2);
const double x = const double x =
std::cos(lat1) * std::sin(lat2) - std::sin(lat1) * std::cos(lat2) * std::cos(lon_delta); 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; return result;
} }
double computeAngle(const FixedPointCoordinate first, double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third)
const FixedPointCoordinate second,
const FixedPointCoordinate third)
{ {
using namespace boost::math::constants; using namespace boost::math::constants;
using namespace coordinate_calculation; using namespace coordinate_calculation;
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION; const double v1x = static_cast<double>(toFloating(first.lon - second.lon));
const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) - const double v1y =
mercator::latToY(second.lat / COORDINATE_PRECISION); mercator::latToY(toFloating(first.lat)) - mercator::latToY(toFloating(second.lat));
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION; const double v2x = static_cast<double>(toFloating(third.lon - second.lon));
const double v2y = mercator::latToY(third.lat / COORDINATE_PRECISION) - const double v2y =
mercator::latToY(second.lat / COORDINATE_PRECISION); mercator::latToY(toFloating(third.lat)) - mercator::latToY(toFloating(second.lat));
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / pi<double>(); double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / pi<double>();
@ -256,20 +247,22 @@ double computeAngle(const FixedPointCoordinate first,
namespace mercator namespace mercator
{ {
double yToLat(const double value) FloatLatitude yToLat(const double value)
{ {
using namespace boost::math::constants; using namespace boost::math::constants;
return 180. * (1. / pi<long double>()) * return FloatLatitude(
(2. * std::atan(std::exp(value * pi<double>() / 180.)) - half_pi<double>()); 180. * (1. / pi<long double>()) *
(2. * std::atan(std::exp(value * pi<double>() / 180.)) - half_pi<double>()));
} }
double latToY(const double latitude) double latToY(const FloatLatitude latitude)
{ {
using namespace boost::math::constants; using namespace boost::math::constants;
return 180. * (1. / pi<double>()) * return 180. * (1. / pi<double>()) *
std::log(std::tan((pi<double>() / 4.) + latitude * (pi<double>() / 180.) / 2.)); std::log(std::tan((pi<double>() / 4.) +
static_cast<double>(latitude) * (pi<double>() / 180.) / 2.));
} }
} // ns mercato // ns mercatorr } // ns mercato // ns mercatorr
} // ns coordinate_calculation } // ns coordinate_calculation

View File

@ -8,7 +8,7 @@ namespace util
namespace 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; std::uint64_t result = 0;
for (std::int8_t index = 31; index >= 0; --index) for (std::int8_t index = 31; index >= 0; --index)
@ -69,11 +69,13 @@ void transposeCoordinate(std::uint32_t *x)
} }
} // anonymous ns } // anonymous ns
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate) std::uint64_t hilbertCode(const Coordinate coordinate)
{ {
unsigned location[2]; std::uint32_t location[2];
location[0] = coordinate.lat + static_cast<int>(90 * COORDINATE_PRECISION); location[0] = static_cast<std::int32_t>(coordinate.lon) +
location[1] = coordinate.lon + static_cast<int>(180 * COORDINATE_PRECISION); static_cast<std::int32_t>(180 * COORDINATE_PRECISION);
location[1] = static_cast<std::int32_t>(coordinate.lat) +
static_cast<std::int32_t>(90 * COORDINATE_PRECISION);
transposeCoordinate(location); transposeCoordinate(location);
return bitInterleaving(location[0], location[1]); return bitInterleaving(location[0], location[1]);

View File

@ -21,15 +21,15 @@ BOOST_AUTO_TEST_CASE(removed_middle_test)
/ \ / \
x x x x
*/ */
std::vector<util::FixedPointCoordinate> coordinates = { std::vector<util::Coordinate> coordinates = {
util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 5 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(5), util::FloatLatitude(5)),
util::FixedPointCoordinate(6 * COORDINATE_PRECISION, 6 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(6), util::FloatLatitude(6)),
util::FixedPointCoordinate(10 * COORDINATE_PRECISION, 10 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(10), util::FloatLatitude(10)),
util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 15 * COORDINATE_PRECISION)}; util::Coordinate(util::FloatLongitude(15), util::FloatLatitude(5))};
// FIXME this test fails for everything below z4 because the DP algorithms // FIXME this test fails for everything below z4 because the DP algorithms
// only used a naive distance measurement // 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++) for (unsigned z = 0; z < 2; z++)
{ {
auto result = douglasPeucker(coordinates, z); auto result = douglasPeucker(coordinates, z);
@ -51,20 +51,22 @@ BOOST_AUTO_TEST_CASE(remove_second_node_test)
| |
x x
*/ */
std::vector<util::FixedPointCoordinate> input = { std::vector<util::Coordinate> input = {
util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 5 * COORDINATE_PRECISION), util::Coordinate(util::FixedLongitude(5 * COORDINATE_PRECISION),
util::FixedPointCoordinate(5 * COORDINATE_PRECISION, util::FixedLatitude(5 * COORDINATE_PRECISION)),
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]), detail::DOUGLAS_PEUCKER_THRESHOLDS[z]),
util::FixedPointCoordinate(10 * COORDINATE_PRECISION, 10 * COORDINATE_PRECISION), util::FixedLatitude(15 * 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),
};
BOOST_TEST_MESSAGE("Threshold (" << z << "): " << detail::DOUGLAS_PEUCKER_THRESHOLDS[z]); BOOST_TEST_MESSAGE("Threshold (" << z << "): " << detail::DOUGLAS_PEUCKER_THRESHOLDS[z]);
auto result = douglasPeucker(input, z); auto result = douglasPeucker(input, z);
BOOST_CHECK_EQUAL(result.size(), 4); BOOST_CHECK_EQUAL(result.size(), 4);

View File

@ -17,36 +17,28 @@ using namespace osrm::engine;
BOOST_AUTO_TEST_CASE(decode) BOOST_AUTO_TEST_CASE(decode)
{ {
// Polyline string for the 5 coordinates // 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); const auto coords = decodePolyline(polyline);
// Test coordinates; these would be the coordinates we give the loc parameter, // Test coordinates; these would be the coordinates we give the loc parameter,
// e.g. loc=10.00,10.0&loc=10.01,10.1... // e.g. loc=10.00,10.0&loc=10.01,10.1...
util::FixedPointCoordinate coord1(10.00 * COORDINATE_PRECISION, 10.0 * COORDINATE_PRECISION); util::Coordinate coord1(util::FloatLongitude(10.0), util::FloatLatitude(10.00));
util::FixedPointCoordinate coord2(10.01 * COORDINATE_PRECISION, 10.1 * COORDINATE_PRECISION); util::Coordinate coord2(util::FloatLongitude(10.1), util::FloatLatitude(10.01));
util::FixedPointCoordinate coord3(10.02 * COORDINATE_PRECISION, 10.2 * COORDINATE_PRECISION); util::Coordinate coord3(util::FloatLongitude(10.2), util::FloatLatitude(10.02));
util::FixedPointCoordinate coord4(10.03 * COORDINATE_PRECISION, 10.3 * COORDINATE_PRECISION); util::Coordinate coord4(util::FloatLongitude(10.3), util::FloatLatitude(10.03));
util::FixedPointCoordinate coord5(10.04 * COORDINATE_PRECISION, 10.4 * COORDINATE_PRECISION); util::Coordinate coord5(util::FloatLongitude(10.4), util::FloatLatitude(10.04));
// Put the test coordinates into the vector for comparison // Put the test coordinates into the vector for comparison
std::vector<util::FixedPointCoordinate> cmp_coords; std::vector<util::Coordinate> cmp_coords = {coord1, coord2, coord3, coord4, coord5};
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);
BOOST_CHECK_EQUAL(cmp_coords.size(), coords.size()); BOOST_CHECK_EQUAL(cmp_coords.size(), coords.size());
for (unsigned i = 0; i < cmp_coords.size(); ++i) for (unsigned i = 0; i < cmp_coords.size(); ++i)
{ {
const double cmp1_lat = coords.at(i).lat; BOOST_CHECK_CLOSE(static_cast<double>(util::toFloating(coords[i].lat)),
const double cmp2_lat = cmp_coords.at(i).lat; static_cast<double>(util::toFloating(cmp_coords[i].lat)), 0.0001);
BOOST_CHECK_CLOSE(cmp1_lat, cmp2_lat, 0.0001); BOOST_CHECK_CLOSE(static_cast<double>(util::toFloating(coords[i].lon)),
static_cast<double>(util::toFloating(cmp_coords[i].lon)), 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);
} }
} }

View File

@ -1,5 +1,9 @@
#include "server/api/parameters_parser.hpp" #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 <fstream> #include <fstream>
namespace osrm namespace osrm
@ -156,7 +160,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
engine::api::RouteParameters::GeometriesType::Polyline, engine::api::RouteParameters::GeometriesType::Polyline,
engine::api::RouteParameters::OverviewType::Simplified, engine::api::RouteParameters::OverviewType::Simplified,
std::vector<boost::optional<bool>>{}, std::vector<boost::optional<bool>>{},
std::vector<util::FixedPointCoordinate>{}, std::vector<util::Coordinate>{},
hints_4, hints_4,
std::vector<boost::optional<double>>{}, std::vector<boost::optional<double>>{},
std::vector<boost::optional<engine::api::BaseParameters::Bearing>>{}}; std::vector<boost::optional<engine::api::BaseParameters::Bearing>>{}};
@ -186,7 +190,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
engine::api::RouteParameters::GeometriesType::Polyline, engine::api::RouteParameters::GeometriesType::Polyline,
engine::api::RouteParameters::OverviewType::Simplified, engine::api::RouteParameters::OverviewType::Simplified,
std::vector<boost::optional<bool>>{}, std::vector<boost::optional<bool>>{},
std::vector<util::FixedPointCoordinate>{}, std::vector<util::Coordinate>{},
std::vector<boost::optional<engine::Hint>> {}, std::vector<boost::optional<engine::Hint>> {},
std::vector<boost::optional<double>>{}, std::vector<boost::optional<double>>{},
bearings_4}; bearings_4};

View File

@ -57,11 +57,11 @@ BOOST_AUTO_TEST_CASE(invalid_urls)
BOOST_AUTO_TEST_CASE(valid_urls) BOOST_AUTO_TEST_CASE(valid_urls)
{ {
std::vector<util::FixedPointCoordinate> coords_1 = { std::vector<util::Coordinate> coords_1 = {
// lat,lon // lat,lon
util::FixedPointCoordinate(1 * COORDINATE_PRECISION, 0 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(0), util::FloatLatitude(1)),
util::FixedPointCoordinate(3 * COORDINATE_PRECISION, 2 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(2), util::FloatLatitude(3)),
util::FixedPointCoordinate(5 * COORDINATE_PRECISION, 4 * COORDINATE_PRECISION), util::Coordinate(util::FloatLongitude(4), util::FloatLatitude(5)),
}; };
api::ParsedURL reference_1{"route", 1, "profile", coords_1, "options=value&foo=bar"}; 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"); 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); BOOST_CHECK_EQUAL(reference_2.options, result_2->options);
// one coordinate // one coordinate
std::vector<util::FixedPointCoordinate> coords_3 = { std::vector<util::Coordinate> coords_3 = {
// lat,lon util::Coordinate(util::FloatLongitude(0), util::FloatLatitude(1)),
util::FixedPointCoordinate(1 * COORDINATE_PRECISION, 0 * COORDINATE_PRECISION),
}; };
api::ParsedURL reference_3{"route", 1, "profile", coords_3, ""}; api::ParsedURL reference_3{"route", 1, "profile", coords_3, ""};
auto result_3 = api::parseURL("/route/v1/profile/0,1"); auto result_3 = api::parseURL("/route/v1/profile/0,1");

View File

@ -12,14 +12,14 @@ using namespace osrm::util;
// Regression test for bug captured in #1347 // Regression test for bug captured in #1347
BOOST_AUTO_TEST_CASE(regression_test_1347) BOOST_AUTO_TEST_CASE(regression_test_1347)
{ {
FixedPointCoordinate u(10 * COORDINATE_PRECISION, -100 * COORDINATE_PRECISION); Coordinate u(FloatLongitude(-100), FloatLatitude(10));
FixedPointCoordinate v(10.001 * COORDINATE_PRECISION, -100.002 * COORDINATE_PRECISION); Coordinate v(FloatLongitude(-100.002), FloatLatitude(10.001));
FixedPointCoordinate q(10.002 * COORDINATE_PRECISION, -100.001 * COORDINATE_PRECISION); Coordinate q(FloatLongitude(-100.001), FloatLatitude(10.002));
double d1 = coordinate_calculation::perpendicularDistance(u, v, q); double d1 = coordinate_calculation::perpendicularDistance(u, v, q);
double ratio; double ratio;
FixedPointCoordinate nearest_location; Coordinate nearest_location;
double d2 = coordinate_calculation::perpendicularDistance(u, v, q, nearest_location, ratio); double d2 = coordinate_calculation::perpendicularDistance(u, v, q, nearest_location, ratio);
BOOST_CHECK_LE(std::abs(d1 - d2), 0.01); BOOST_CHECK_LE(std::abs(d1 - d2), 0.01);

View File

@ -26,23 +26,23 @@ BOOST_AUTO_TEST_CASE(get_min_dist_test)
// | // |
// +- -80 // +- -80
// | // |
RectangleInt2D nw(10 * COORDINATE_PRECISION, 80 * COORDINATE_PRECISION, RectangleInt2D nw{FloatLongitude(10), FloatLongitude(100), FloatLatitude(10),
10 * COORDINATE_PRECISION, 100 * COORDINATE_PRECISION); FloatLatitude(80)};
RectangleInt2D ne(10 * COORDINATE_PRECISION, 80 * COORDINATE_PRECISION, // RectangleInt2D ne {FloatLongitude(-100), FloatLongitude(-10), FloatLatitude(10),
-100 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION); // FloatLatitude(80)};
RectangleInt2D sw(-80 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION, // RectangleInt2D sw {FloatLongitude(10), FloatLongitude(100), FloatLatitude(-80),
10 * COORDINATE_PRECISION, 100 * COORDINATE_PRECISION); // FloatLatitude(-10)};
RectangleInt2D se(-80 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION, RectangleInt2D se{FloatLongitude(-100), FloatLongitude(-10), FloatLatitude(-80),
-100 * COORDINATE_PRECISION, -10 * COORDINATE_PRECISION); FloatLatitude(-10)};
FixedPointCoordinate nw_sw(9.9 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); Coordinate nw_sw{FloatLongitude(9.9), FloatLatitude(9.9)};
FixedPointCoordinate nw_se(9.9 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); Coordinate nw_se{FloatLongitude(100.1), FloatLatitude(9.9)};
FixedPointCoordinate nw_ne(80.1 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); Coordinate nw_ne{FloatLongitude(100.1), FloatLatitude(80.1)};
FixedPointCoordinate nw_nw(80.1 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); Coordinate nw_nw{FloatLongitude(9.9), FloatLatitude(80.1)};
FixedPointCoordinate nw_s(9.9 * COORDINATE_PRECISION, 55 * COORDINATE_PRECISION); Coordinate nw_s{FloatLongitude(55), FloatLatitude(9.9)};
FixedPointCoordinate nw_e(45.0 * COORDINATE_PRECISION, 100.1 * COORDINATE_PRECISION); Coordinate nw_e{FloatLongitude(100.1), FloatLatitude(45.0)};
FixedPointCoordinate nw_w(45.0 * COORDINATE_PRECISION, 9.9 * COORDINATE_PRECISION); Coordinate nw_w{FloatLongitude(9.9), FloatLatitude(45.0)};
FixedPointCoordinate nw_n(80.1 * COORDINATE_PRECISION, 55 * COORDINATE_PRECISION); 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_sw), 15611.9, 0.1);
BOOST_CHECK_CLOSE(nw.GetMinDist(nw_se), 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); 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_w), 7864.89, 0.1);
BOOST_CHECK_CLOSE(nw.GetMinDist(nw_n), 11122.6, 0.1); BOOST_CHECK_CLOSE(nw.GetMinDist(nw_n), 11122.6, 0.1);
FixedPointCoordinate se_ne(-9.9 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); Coordinate se_ne{FloatLongitude(-9.9), FloatLatitude(-9.9)};
FixedPointCoordinate se_nw(-9.9 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); Coordinate se_nw{FloatLongitude(-100.1), FloatLatitude(-9.9)};
FixedPointCoordinate se_sw(-80.1 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); Coordinate se_sw{FloatLongitude(-100.1), FloatLatitude(-80.1)};
FixedPointCoordinate se_se(-80.1 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); Coordinate se_se{FloatLongitude(-9.9), FloatLatitude(-80.1)};
FixedPointCoordinate se_n(-9.9 * COORDINATE_PRECISION, -55 * COORDINATE_PRECISION); Coordinate se_n{FloatLongitude(-55), FloatLatitude(-9.9)};
FixedPointCoordinate se_w(-45.0 * COORDINATE_PRECISION, -100.1 * COORDINATE_PRECISION); Coordinate se_w{FloatLongitude(-100.1), FloatLatitude(-45.0)};
FixedPointCoordinate se_e(-45.0 * COORDINATE_PRECISION, -9.9 * COORDINATE_PRECISION); Coordinate se_e{FloatLongitude(-9.9), FloatLatitude(-45.0)};
FixedPointCoordinate se_s(-80.1 * COORDINATE_PRECISION, -55 * COORDINATE_PRECISION); 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_sw), 11287.4, 0.1);
BOOST_CHECK_CLOSE(se.GetMinDist(se_se), 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); BOOST_CHECK_CLOSE(se.GetMinDist(se_ne), 15611.9, 0.1);

View File

@ -38,11 +38,11 @@ constexpr uint32_t TEST_LEAF_NODE_SIZE = 64;
using TestData = extractor::EdgeBasedNode; using TestData = extractor::EdgeBasedNode;
using TestStaticRTree = StaticRTree<TestData, using TestStaticRTree = StaticRTree<TestData,
std::vector<FixedPointCoordinate>, std::vector<Coordinate>,
false, false,
TEST_BRANCHING_FACTOR, TEST_BRANCHING_FACTOR,
TEST_LEAF_NODE_SIZE>; TEST_LEAF_NODE_SIZE>;
using MiniStaticRTree = StaticRTree<TestData, std::vector<FixedPointCoordinate>, false, 2, 3>; using MiniStaticRTree = StaticRTree<TestData, std::vector<Coordinate>, false, 2, 3>;
// Choosen by a fair W20 dice roll (this value is completely arbitrary) // Choosen by a fair W20 dice roll (this value is completely arbitrary)
constexpr unsigned RANDOM_SEED = 42; constexpr unsigned RANDOM_SEED = 42;
@ -54,14 +54,13 @@ static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
template <typename DataT> class LinearSearchNN template <typename DataT> class LinearSearchNN
{ {
public: public:
LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords, LinearSearchNN(const std::shared_ptr<std::vector<Coordinate>> &coords,
const std::vector<DataT> &edges) const std::vector<DataT> &edges)
: coords(coords), edges(edges) : coords(coords), edges(edges)
{ {
} }
std::vector<DataT> Nearest(const FixedPointCoordinate &input_coordinate, std::vector<DataT> Nearest(const Coordinate &input_coordinate, const unsigned num_results)
const unsigned num_results)
{ {
std::vector<DataT> local_edges(edges); std::vector<DataT> local_edges(edges);
@ -70,7 +69,7 @@ template <typename DataT> class LinearSearchNN
[this, &input_coordinate](const DataT &lhs, const DataT &rhs) [this, &input_coordinate](const DataT &lhs, const DataT &rhs)
{ {
double current_ratio = 0.; double current_ratio = 0.;
FixedPointCoordinate nearest; Coordinate nearest;
const double lhs_dist = coordinate_calculation::perpendicularDistance( const double lhs_dist = coordinate_calculation::perpendicularDistance(
coords->at(lhs.u), coords->at(lhs.v), input_coordinate, nearest, current_ratio); coords->at(lhs.u), coords->at(lhs.v), input_coordinate, nearest, current_ratio);
const double rhs_dist = coordinate_calculation::perpendicularDistance( const double rhs_dist = coordinate_calculation::perpendicularDistance(
@ -83,7 +82,7 @@ template <typename DataT> class LinearSearchNN
} }
private: private:
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords; const std::shared_ptr<std::vector<Coordinate>> &coords;
const std::vector<TestData> &edges; const std::vector<TestData> &edges;
}; };
@ -103,7 +102,7 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
} }
}; };
RandomGraphFixture() : coords(std::make_shared<std::vector<FixedPointCoordinate>>()) RandomGraphFixture() : coords(std::make_shared<std::vector<Coordinate>>())
{ {
BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges."); BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges.");
@ -114,10 +113,11 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
for (unsigned i = 0; i < NUM_NODES; i++) for (unsigned i = 0; i < NUM_NODES; i++)
{ {
int lat = lat_udist(g);
int lon = lon_udist(g); int lon = lon_udist(g);
nodes.emplace_back(extractor::QueryNode(lat, lon, OSMNodeID(i))); int lat = lat_udist(g);
coords->emplace_back(FixedPointCoordinate(lat, lon)); 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); std::uniform_int_distribution<> edge_udist(0, nodes.size() - 1);
@ -140,23 +140,22 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
} }
std::vector<extractor::QueryNode> nodes; std::vector<extractor::QueryNode> nodes;
std::shared_ptr<std::vector<FixedPointCoordinate>> coords; std::shared_ptr<std::vector<Coordinate>> coords;
std::vector<TestData> edges; std::vector<TestData> edges;
}; };
struct GraphFixture struct GraphFixture
{ {
GraphFixture(const std::vector<std::pair<double, double>> &input_coords, GraphFixture(const std::vector<std::pair<FloatLongitude, FloatLatitude>> &input_coords,
const std::vector<std::pair<unsigned, unsigned>> &input_edges) const std::vector<std::pair<unsigned, unsigned>> &input_edges)
: coords(std::make_shared<std::vector<FixedPointCoordinate>>()) : coords(std::make_shared<std::vector<Coordinate>>())
{ {
for (unsigned i = 0; i < input_coords.size(); i++) for (unsigned i = 0; i < input_coords.size(); i++)
{ {
FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION, coords->emplace_back(input_coords[i].first, input_coords[i].second);
input_coords[i].second * COORDINATE_PRECISION); nodes.emplace_back(extractor::QueryNode(toFixed(input_coords[i].first),
coords->emplace_back(c); toFixed(input_coords[i].second), OSMNodeID(i)));
nodes.emplace_back(extractor::QueryNode(c.lat, c.lon, OSMNodeID(i)));
} }
for (const auto &pair : input_edges) for (const auto &pair : input_edges)
@ -175,7 +174,7 @@ struct GraphFixture
} }
std::vector<extractor::QueryNode> nodes; std::vector<extractor::QueryNode> nodes;
std::shared_ptr<std::vector<FixedPointCoordinate>> coords; std::shared_ptr<std::vector<Coordinate>> coords;
std::vector<TestData> edges; std::vector<TestData> edges;
}; };
@ -194,14 +193,14 @@ typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
template <typename RTreeT> template <typename RTreeT>
void simple_verify_rtree(RTreeT &rtree, void simple_verify_rtree(RTreeT &rtree,
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords, const std::shared_ptr<std::vector<Coordinate>> &coords,
const std::vector<TestData> &edges) const std::vector<TestData> &edges)
{ {
BOOST_TEST_MESSAGE("Verify end points"); BOOST_TEST_MESSAGE("Verify end points");
for (const auto &e : edges) for (const auto &e : edges)
{ {
const FixedPointCoordinate &pu = coords->at(e.u); const Coordinate &pu = coords->at(e.u);
const FixedPointCoordinate &pv = coords->at(e.v); const Coordinate &pv = coords->at(e.v);
auto result_u = rtree.Nearest(pu, 1); auto result_u = rtree.Nearest(pu, 1);
auto result_v = rtree.Nearest(pv, 1); auto result_v = rtree.Nearest(pv, 1);
BOOST_CHECK(result_u.size() == 1 && result_v.size() == 1); BOOST_CHECK(result_u.size() == 1 && result_v.size() == 1);
@ -213,16 +212,16 @@ void simple_verify_rtree(RTreeT &rtree,
template <typename RTreeT> template <typename RTreeT>
void sampling_verify_rtree(RTreeT &rtree, void sampling_verify_rtree(RTreeT &rtree,
LinearSearchNN<TestData> &lsnn, LinearSearchNN<TestData> &lsnn,
const std::vector<FixedPointCoordinate> &coords, const std::vector<Coordinate> &coords,
unsigned num_samples) unsigned num_samples)
{ {
std::mt19937 g(RANDOM_SEED); std::mt19937 g(RANDOM_SEED);
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); 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::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
std::vector<FixedPointCoordinate> queries; std::vector<Coordinate> queries;
for (unsigned i = 0; i < num_samples; i++) 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"); BOOST_TEST_MESSAGE("Sampling queries");
@ -238,7 +237,7 @@ void sampling_verify_rtree(RTreeT &rtree,
auto lsnn_v = result_lsnn.back().v; auto lsnn_v = result_lsnn.back().v;
double current_ratio = 0.; double current_ratio = 0.;
FixedPointCoordinate nearest; Coordinate nearest;
const double rtree_dist = coordinate_calculation::perpendicularDistance( const double rtree_dist = coordinate_calculation::perpendicularDistance(
coords[rtree_u], coords[rtree_v], q, nearest, current_ratio); coords[rtree_u], coords[rtree_v], q, nearest, current_ratio);
const double lsnn_dist = coordinate_calculation::perpendicularDistance( 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. // one BB will be pruned, even if it could contain a nearer match.
BOOST_AUTO_TEST_CASE(regression_test) BOOST_AUTO_TEST_CASE(regression_test)
{ {
using Coord = std::pair<double, double>; using Coord = std::pair<FloatLongitude, FloatLatitude>;
using Edge = std::pair<unsigned, unsigned>; using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture( GraphFixture fixture(
{ {
Coord(40.0, 0.0), Coord{FloatLongitude{0.0}, FloatLatitude{40.0}}, //
Coord(35.0, 5.0), Coord{FloatLongitude{5.0}, FloatLatitude{35.0}}, //
Coord{FloatLongitude{5.0},
Coord(5.0, 5.0), FloatLatitude{
Coord(0.0, 10.0), 5.0,
}}, //
Coord(20.0, 10.0), Coord{FloatLongitude{10.0},
Coord(20.0, 5.0), FloatLatitude{
0.0,
Coord(40.0, 100.0), }}, //
Coord(35.0, 105.0), Coord{FloatLongitude{10.0}, FloatLatitude{20.0}}, //
Coord{FloatLongitude{5.0}, FloatLatitude{20.0}}, //
Coord(5.0, 105.0), Coord{FloatLongitude{100.0}, FloatLatitude{40.0}}, //
Coord(0.0, 110.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)}); {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<TestData> lsnn(fixture.coords, fixture.edges); LinearSearchNN<TestData> lsnn(fixture.coords, fixture.edges);
// query a node just right of the center of the gap // 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_rtree = rtree.Nearest(input, 1);
auto result_ls = lsnn.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) void TestRectangle(double width, double height, double center_lat, double center_lon)
{ {
FixedPointCoordinate center(center_lat * COORDINATE_PRECISION, Coordinate center{FloatLongitude(center_lon), FloatLatitude(center_lat)};
center_lon * COORDINATE_PRECISION);
TestStaticRTree::Rectangle rect; TestStaticRTree::Rectangle rect;
rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION; rect.min_lat = center.lat - FixedLatitude(height / 2.0 * COORDINATE_PRECISION);
rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION; rect.max_lat = center.lat + FixedLatitude(height / 2.0 * COORDINATE_PRECISION);
rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION; rect.min_lon = center.lon - FixedLongitude(width / 2.0 * COORDINATE_PRECISION);
rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION; rect.max_lon = center.lon + FixedLongitude(width / 2.0 * COORDINATE_PRECISION);
unsigned offset = 5 * COORDINATE_PRECISION; const FixedLongitude lon_offset(5. * COORDINATE_PRECISION);
FixedPointCoordinate north(rect.max_lat + offset, center.lon); const FixedLatitude lat_offset(5. * COORDINATE_PRECISION);
FixedPointCoordinate south(rect.min_lat - offset, center.lon); Coordinate north(center.lon, rect.max_lat + lat_offset);
FixedPointCoordinate west(center.lat, rect.min_lon - offset); Coordinate south(center.lon, rect.min_lat - lat_offset);
FixedPointCoordinate east(center.lat, rect.max_lon + offset); Coordinate west(rect.min_lon - lon_offset, center.lat);
FixedPointCoordinate north_east(rect.max_lat + offset, rect.max_lon + offset); Coordinate east(rect.max_lon + lon_offset, center.lat);
FixedPointCoordinate north_west(rect.max_lat + offset, rect.min_lon - offset); Coordinate north_east(rect.max_lon + lon_offset, rect.max_lat + lat_offset);
FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset); Coordinate north_west(rect.min_lon - lon_offset, rect.max_lat + lat_offset);
FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - 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 */ /* Distance to line segments of rectangle */
BOOST_CHECK_EQUAL(rect.GetMinDist(north), BOOST_CHECK_EQUAL(rect.GetMinDist(north), coordinate_calculation::greatCircleDistance(
coordinate_calculation::greatCircleDistance( north, Coordinate(north.lon, rect.max_lat)));
north, FixedPointCoordinate(rect.max_lat, north.lon))); BOOST_CHECK_EQUAL(rect.GetMinDist(south), coordinate_calculation::greatCircleDistance(
BOOST_CHECK_EQUAL(rect.GetMinDist(south), south, Coordinate(south.lon, rect.min_lat)));
coordinate_calculation::greatCircleDistance( BOOST_CHECK_EQUAL(rect.GetMinDist(west), coordinate_calculation::greatCircleDistance(
south, FixedPointCoordinate(rect.min_lat, south.lon))); west, Coordinate(rect.min_lon, west.lat)));
BOOST_CHECK_EQUAL(rect.GetMinDist(west), BOOST_CHECK_EQUAL(rect.GetMinDist(east), coordinate_calculation::greatCircleDistance(
coordinate_calculation::greatCircleDistance( east, Coordinate(rect.max_lon, east.lat)));
west, FixedPointCoordinate(west.lat, rect.min_lon)));
BOOST_CHECK_EQUAL(rect.GetMinDist(east),
coordinate_calculation::greatCircleDistance(
east, FixedPointCoordinate(east.lat, rect.max_lon)));
/* Distance to corner points */ /* Distance to corner points */
BOOST_CHECK_EQUAL(rect.GetMinDist(north_east), BOOST_CHECK_EQUAL(rect.GetMinDist(north_east),
coordinate_calculation::greatCircleDistance( 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), BOOST_CHECK_EQUAL(rect.GetMinDist(north_west),
coordinate_calculation::greatCircleDistance( 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), BOOST_CHECK_EQUAL(rect.GetMinDist(south_east),
coordinate_calculation::greatCircleDistance( 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), BOOST_CHECK_EQUAL(rect.GetMinDist(south_west),
coordinate_calculation::greatCircleDistance( 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) BOOST_AUTO_TEST_CASE(rectangle_test)
@ -408,11 +405,12 @@ BOOST_AUTO_TEST_CASE(rectangle_test)
BOOST_AUTO_TEST_CASE(bearing_tests) BOOST_AUTO_TEST_CASE(bearing_tests)
{ {
using Coord = std::pair<double, double>; using Coord = std::pair<FloatLongitude, FloatLatitude>;
using Edge = std::pair<unsigned, unsigned>; using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture( 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)}); {Edge(0, 1), Edge(1, 0)});
@ -423,7 +421,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests)
std::unique_ptr<MockDataFacade> mockfacade_ptr(new MockDataFacade); std::unique_ptr<MockDataFacade> mockfacade_ptr(new MockDataFacade);
engine::GeospatialQuery<MiniStaticRTree, MockDataFacade> query(rtree, fixture.coords, *mockfacade_ptr); engine::GeospatialQuery<MiniStaticRTree, MockDataFacade> 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); auto results = query.NearestPhantomNodes(input, 5);
@ -468,12 +466,16 @@ BOOST_AUTO_TEST_CASE(bearing_tests)
BOOST_AUTO_TEST_CASE(bbox_search_tests) BOOST_AUTO_TEST_CASE(bbox_search_tests)
{ {
using Coord = std::pair<double, double>; using Coord = std::pair<FloatLongitude, FloatLatitude>;
using Edge = std::pair<unsigned, unsigned>; using Edge = std::pair<unsigned, unsigned>;
GraphFixture fixture( 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)}); {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<MiniStaticRTree, MockDataFacade> query(rtree, fixture.coords, *mockfacade_ptr); engine::GeospatialQuery<MiniStaticRTree, MockDataFacade> query(rtree, fixture.coords, *mockfacade_ptr);
{ {
RectangleInt2D bbox = {static_cast<uint32_t>(0.5 * COORDINATE_PRECISION), RectangleInt2D bbox = {FloatLongitude(0.5), FloatLongitude(1.5), FloatLatitude(0.5),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION), FloatLatitude(1.5)};
static_cast<uint32_t>(0.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION)};
auto results = query.Search(bbox); auto results = query.Search(bbox);
BOOST_CHECK_EQUAL(results.size(), 2); BOOST_CHECK_EQUAL(results.size(), 2);
} }
{ {
RectangleInt2D bbox = {static_cast<uint32_t>(1.5 * COORDINATE_PRECISION), RectangleInt2D bbox = {FloatLongitude(1.5), FloatLongitude(3.5), FloatLatitude(1.5),
static_cast<uint32_t>(3.5 * COORDINATE_PRECISION), FloatLatitude(3.5)};
static_cast<uint32_t>(1.5 * COORDINATE_PRECISION),
static_cast<uint32_t>(3.5 * COORDINATE_PRECISION)};
auto results = query.Search(bbox); auto results = query.Search(bbox);
BOOST_CHECK_EQUAL(results.size(), 3); BOOST_CHECK_EQUAL(results.size(), 3);
} }

View File

@ -15,19 +15,25 @@ using namespace osrm::util;
BOOST_AUTO_TEST_CASE(point_to_tile_test) BOOST_AUTO_TEST_CASE(point_to_tile_test)
{ {
tiles::Tile tile_1_reference{2306375680,1409941503,32}; tiles::Tile tile_1_reference{2306375680, 1409941503, 32};
tiles::Tile tile_2_reference{2308259840,1407668224,32}; tiles::Tile tile_2_reference{2308259840, 1407668224, 32};
tiles::Tile tile_3_reference{616562688,2805989376,32}; tiles::Tile tile_3_reference{616562688, 2805989376, 32};
tiles::Tile tile_4_reference{1417674752,2084569088,32}; tiles::Tile tile_4_reference{1417674752, 2084569088, 32};
tiles::Tile tile_5_reference{616562688,2805989376,32}; tiles::Tile tile_5_reference{616562688, 2805989376, 32};
tiles::Tile tile_6_reference{712654285,2671662374,32}; tiles::Tile tile_6_reference{712654285, 2671662374, 32};
auto tile_1 = tiles::pointToTile(13.31817626953125,52.449314140869696); auto tile_1 =
auto tile_2 = tiles::pointToTile(13.476104736328125,52.56529070208021); tiles::pointToTile(FloatLongitude(13.31817626953125), FloatLatitude(52.449314140869696));
auto tile_3 = tiles::pointToTile(-128.32031249999997,-48.224672649565186); auto tile_2 =
auto tile_4 = tiles::pointToTile(-61.17187499999999,5.266007882805498); tiles::pointToTile(FloatLongitude(13.476104736328125), FloatLatitude(52.56529070208021));
auto tile_5 = tiles::pointToTile(-128.32031249999997,-48.224672649565186); auto tile_3 =
auto tile_6 = tiles::pointToTile(-120.266007882805532,-40.17187499999999); 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.x, tile_1_reference.x);
BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y); BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y);
BOOST_CHECK_EQUAL(tile_1.z, tile_1_reference.z); 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_1_reference{17, 10, 5};
tiles::Tile tile_2_reference{0, 0, 0}; tiles::Tile tile_2_reference{0, 0, 0};
tiles::Tile tile_3_reference{0, 2, 2}; tiles::Tile tile_3_reference{0, 2, 2};
auto tile_1 = tiles::getBBMaxZoomTile(13.31817626953125, 52.449314140869696, auto tile_1 = tiles::getBBMaxZoomTile(
13.476104736328125, 52.56529070208021); FloatLongitude(13.31817626953125), FloatLatitude(52.449314140869696),
auto tile_2 = tiles::getBBMaxZoomTile(-128.32031249999997, -48.224672649565186, FloatLongitude(13.476104736328125), FloatLatitude(52.56529070208021));
-61.17187499999999, 5.266007882805498); auto tile_2 = tiles::getBBMaxZoomTile(
auto tile_3 = tiles::getBBMaxZoomTile(-128.32031249999997, -48.224672649565186, FloatLongitude(-128.32031249999997), FloatLatitude(-48.224672649565186),
-120.2660078828055, -40.17187499999999); 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.x, tile_1_reference.x);
BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y); BOOST_CHECK_EQUAL(tile_1.y, tile_1_reference.y);
BOOST_CHECK_EQUAL(tile_1.z, tile_1_reference.z); BOOST_CHECK_EQUAL(tile_1.z, tile_1_reference.z);