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
// 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),
static_cast<int>(7.419758 * osrm::COORDINATE_PRECISION)});
params.coordinates.push_back({static_cast<int>(43.736825 * osrm::COORDINATE_PRECISION),
static_cast<int>(7.419505 * osrm::COORDINATE_PRECISION)});
params.coordinates.push_back({osrm::util::FloatLongitude(7.419758), osrm::util::FloatLatitude(43.731142)});
params.coordinates.push_back({osrm::util::FloatLongitude(7.419505), osrm::util::FloatLatitude(43.736825)});
// Response is in JSON format
osrm::json::Object result;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ class SharedDataFacade final : public BaseDataFacade
using InputEdge = typename QueryGraph::InputEdge;
using RTreeLeaf = typename super::RTreeLeaf;
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 TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
using RTreeNode = typename SharedRTree::TreeNode;
@ -67,7 +67,7 @@ class SharedDataFacade final : public BaseDataFacade
std::unique_ptr<storage::SharedMemory> m_large_memory;
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<unsigned, true>::vector m_name_ID_list;
util::ShM<extractor::TurnInstruction, true>::vector m_turn_instruction_list;
@ -133,9 +133,9 @@ class SharedDataFacade final : public BaseDataFacade
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);
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,
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
@ -365,7 +365,7 @@ class SharedDataFacade final : public BaseDataFacade
}
// node and edge information access
util::FixedPointCoordinate GetCoordinateOfNode(const NodeID id) const override final
util::Coordinate GetCoordinateOfNode(const NodeID id) const override final
{
return m_coordinate_list->at(id);
}
@ -408,22 +408,21 @@ class SharedDataFacade final : public BaseDataFacade
return m_travel_mode_list.at(id);
}
std::vector<RTreeLeaf>
GetEdgesInBox(const util::FixedPointCoordinate &south_west,
const util::FixedPointCoordinate &north_east) override final
std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
const util::Coordinate north_east) override final
{
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get());
}
const util::RectangleInt2D bbox{
south_west.lon, north_east.lon, south_west.lat, north_east.lat};
const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat,
north_east.lat};
return m_geospatial_query->Search(bbox);
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) override final
{
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
@ -436,7 +435,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance,
const int bearing,
const int bearing_range) override final
@ -452,7 +451,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results) override final
{
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
@ -465,7 +464,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const double max_distance) override final
{
@ -479,7 +478,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const int bearing,
const int bearing_range) override final
@ -495,7 +494,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const double max_distance,
const int bearing,
@ -512,7 +511,7 @@ class SharedDataFacade final : public BaseDataFacade
}
std::pair<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)
{
@ -524,8 +523,9 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate, const double max_distance) override final
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance) override final
{
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
@ -537,8 +537,8 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate, max_distance);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate,
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range) override final
@ -553,8 +553,8 @@ class SharedDataFacade final : public BaseDataFacade
input_coordinate, max_distance, bearing, bearing_range);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate,
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const int bearing,
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
// bit indicating if the points is present in the generalization.
// Note: points may also be pre-selected*/
std::vector<util::FixedPointCoordinate>
douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
std::vector<util::FixedPointCoordinate>::const_iterator end,
std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::const_iterator begin,
std::vector<util::Coordinate>::const_iterator end,
const unsigned zoom_level);
// Convenience range-based function
inline std::vector<util::FixedPointCoordinate>
douglasPeucker(const std::vector<util::FixedPointCoordinate> &geometry, const unsigned zoom_level)
inline std::vector<util::Coordinate> douglasPeucker(const std::vector<util::Coordinate> &geometry,
const unsigned 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.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
const double max_distance)
NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance)
{
auto results =
rtree.Nearest(input_coordinate,
[] (const EdgeData &) { return std::make_pair(true, true); },
auto results = rtree.Nearest(input_coordinate,
[](const EdgeData &)
{
return std::make_pair(true, true);
},
[max_distance](const std::size_t, const double min_dist)
{
return min_dist > max_distance;
@ -58,7 +59,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns nearest PhantomNodes in the given bearing range within max_distance.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range)
@ -80,7 +81,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes in the given bearing range.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const int bearing,
const int bearing_range)
@ -98,16 +99,18 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return MakePhantomNodes(input_coordinate, results);
}
// Returns max_results nearest PhantomNodes in the given bearing range within the maximum distance.
// Returns max_results nearest PhantomNodes in the given bearing range within the maximum
// distance.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const double max_distance,
const int bearing,
const int bearing_range)
{
auto results = rtree.Nearest(input_coordinate,
auto results = rtree.Nearest(
input_coordinate,
[this, bearing, bearing_range](const EdgeData &data)
{
return checkSegmentBearing(data, bearing, bearing_range);
@ -123,8 +126,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
const unsigned max_results)
NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results)
{
auto results = rtree.Nearest(input_coordinate,
[](const EdgeData &)
@ -142,11 +144,12 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes in the given max distance.
// Does not filter by small/big component!
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results,
const double max_distance)
{
auto results = rtree.Nearest(input_coordinate,
auto results = rtree.Nearest(
input_coordinate,
[](const EdgeData &)
{
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
// a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate, const double max_distance)
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance)
{
bool has_small_component = false;
bool has_big_component = false;
@ -196,8 +200,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Returns the nearest phantom node. If this phantom node is not from a big component
// a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate)
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate)
{
bool has_small_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
// a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate,
const int bearing,
const int bearing_range)
const util::Coordinate input_coordinate, const int bearing, const int bearing_range)
{
bool has_small_component = false;
bool has_big_component = false;
@ -276,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
// a second phantom node is return that is the nearest coordinate in a big component.
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate input_coordinate,
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range)
@ -322,7 +324,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
private:
std::vector<PhantomNodeWithDistance>
MakePhantomNodes(const util::FixedPointCoordinate input_coordinate,
MakePhantomNodes(const util::Coordinate input_coordinate,
const std::vector<EdgeData> &results) const
{
std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size());
@ -334,10 +336,10 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return distance_and_phantoms;
}
PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate input_coordinate,
PhantomNodeWithDistance MakePhantomNode(const util::Coordinate input_coordinate,
const EdgeData &data) const
{
util::FixedPointCoordinate point_on_segment;
util::Coordinate point_on_segment;
double ratio;
const auto current_perpendicular_distance =
util::coordinate_calculation::perpendicularDistance(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,10 +28,10 @@ class BasePlugin
datafacade::BaseDataFacade &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),
[](const util::FixedPointCoordinate &coordinate)
[](const util::Coordinate coordinate)
{
return !coordinate.IsValid();
});
@ -150,9 +150,11 @@ class BasePlugin
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_bearings = !parameters.bearings.empty();
@ -176,32 +178,28 @@ class BasePlugin
{
if (use_radiuses && parameters.radiuses[i])
{
phantom_nodes[i] =
facade.NearestPhantomNodes(
phantom_nodes[i] = facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results, *parameters.radiuses[i],
parameters.bearings[i]->bearing, parameters.bearings[i]->range);
}
else
{
phantom_nodes[i] =
facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results, parameters.bearings[i]->bearing,
parameters.bearings[i]->range);
phantom_nodes[i] = facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results,
parameters.bearings[i]->bearing, parameters.bearings[i]->range);
}
}
else
{
if (use_radiuses && parameters.radiuses[i])
{
phantom_nodes[i] =
facade.NearestPhantomNodes(
phantom_nodes[i] = facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results, *parameters.radiuses[i]);
}
else
{
phantom_nodes[i] =
facade.NearestPhantomNodes(
parameters.coordinates[i], number_of_results);
facade.NearestPhantomNodes(parameters.coordinates[i], number_of_results);
}
}

View File

@ -1,7 +1,7 @@
#ifndef POLYLINECOMPRESSOR_H_
#define POLYLINECOMPRESSOR_H_
#include "osrm/coordinate.hpp"
#include "util/coordinate.hpp"
#include <string>
#include <vector>
@ -12,19 +12,19 @@ namespace engine
{
namespace detail
{
constexpr double POLYLINE_PECISION = 1e5;
constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION;
constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION;
constexpr double POLYLINE_PECISION = 1e5;
constexpr double COORDINATE_TO_POLYLINE = POLYLINE_PECISION / COORDINATE_PRECISION;
constexpr double POLYLINE_TO_COORDINATE = COORDINATE_PRECISION / POLYLINE_PECISION;
}
using CoordVectorForwardIter = std::vector<FixedPointCoordinate>::const_iterator;
using CoordVectorForwardIter = std::vector<util::Coordinate>::const_iterator;
// Encodes geometry into polyline format.
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end);
// Decodes geometry from polyline format
// See: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
std::vector<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
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<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)
{
std::reverse(id_vector.begin(), id_vector.end());
end_index =
id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
}
if (start_index > end_index)
@ -365,8 +364,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
BOOST_ASSERT(i < id_vector.size());
BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0);
unpacked_path.emplace_back(
PathData{id_vector[i], phantom_node_pair.target_phantom.name_id,
0, extractor::TurnInstruction::NoTurn,
PathData{id_vector[i], phantom_node_pair.target_phantom.name_id, 0,
extractor::TurnInstruction::NoTurn,
target_traversed_in_reverse
? phantom_node_pair.target_phantom.backward_travel_mode
: phantom_node_pair.target_phantom.forward_travel_mode});
@ -385,7 +384,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// looks like a trivially true check but tests for underflow
BOOST_ASSERT(last_index > second_to_last_index);
if (unpacked_path[last_index].turn_via_node == unpacked_path[second_to_last_index].turn_via_node)
if (unpacked_path[last_index].turn_via_node ==
unpacked_path[second_to_last_index].turn_via_node)
{
unpacked_path.pop_back();
}
@ -743,8 +743,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
nodes.target_phantom = target_phantom;
UnpackPath(packed_path.begin(), packed_path.end(), nodes, unpacked_path);
util::FixedPointCoordinate previous_coordinate = source_phantom.location;
util::FixedPointCoordinate current_coordinate;
util::Coordinate previous_coordinate = source_phantom.location;
util::Coordinate current_coordinate;
double distance = 0;
for (const auto &p : unpacked_path)
{

View File

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

View File

@ -12,8 +12,12 @@ namespace extractor
struct ExternalMemoryNode : QueryNode
{
ExternalMemoryNode(int lat, int lon, OSMNodeID node_id, bool barrier, bool traffic_lights)
: QueryNode(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights)
ExternalMemoryNode(const util::FixedLongitude lon_,
const util::FixedLatitude lat_,
OSMNodeID node_id_,
bool barrier_,
bool traffic_lights_)
: QueryNode(lon_, lat_, node_id_), barrier(barrier_), traffic_lights(traffic_lights_)
{
}
@ -21,12 +25,14 @@ struct ExternalMemoryNode : QueryNode
static ExternalMemoryNode min_value()
{
return ExternalMemoryNode(0, 0, MIN_OSM_NODEID, false, false);
return ExternalMemoryNode(util::FixedLongitude(0), util::FixedLatitude(0), MIN_OSM_NODEID,
false, false);
}
static ExternalMemoryNode max_value()
{
return ExternalMemoryNode(std::numeric_limits<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);
}

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ template <typename ParameterT,
typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0>
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();
return parseParameters<ParameterT>(first, last);
}

View File

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

View File

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

View File

@ -22,7 +22,7 @@ class MatchService final : public BaseService
public:
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,
util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class NearestService final : public BaseService
public:
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,
util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class RouteService final : public BaseService
public:
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,
util::json::Object &result) final override;

View File

@ -22,7 +22,7 @@ class TableService final : public BaseService
public:
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,
util::json::Object &result) final override;

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ namespace util
{
// Computes a 64 bit value that corresponds to the hilbert space filling curve
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate);
std::uint64_t hilbertCode(const Coordinate coordinate);
}
}

View File

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

View File

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

View File

@ -37,7 +37,7 @@ namespace util
// Static RTree for serving nearest neighbour queries
template <class EdgeDataT,
class CoordinateListT = std::vector<FixedPointCoordinate>,
class CoordinateListT = std::vector<Coordinate>,
bool UseSharedMemory = false,
std::uint32_t BRANCHING_FACTOR = 64,
std::uint32_t LEAF_NODE_SIZE = 1024>
@ -122,8 +122,8 @@ class StaticRTree
// generate auxiliary vector of hilbert-values
tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, m_element_count),
[&input_data_vector, &input_wrapper_vector, &coordinate_list](
const tbb::blocked_range<uint64_t> &range)
[&input_data_vector, &input_wrapper_vector,
&coordinate_list](const tbb::blocked_range<uint64_t> &range)
{
for (uint64_t element_counter = range.begin(), end = range.end();
element_counter != end; ++element_counter)
@ -137,14 +137,14 @@ class StaticRTree
BOOST_ASSERT(current_element.u < coordinate_list.size());
BOOST_ASSERT(current_element.v < coordinate_list.size());
FixedPointCoordinate current_centroid = EdgeDataT::Centroid(
FixedPointCoordinate(coordinate_list[current_element.u].lat,
coordinate_list[current_element.u].lon),
FixedPointCoordinate(coordinate_list[current_element.v].lat,
coordinate_list[current_element.v].lon));
current_centroid.lat =
COORDINATE_PRECISION * coordinate_calculation::mercator::latToY(
current_centroid.lat / COORDINATE_PRECISION);
Coordinate current_centroid =
EdgeDataT::Centroid(Coordinate(coordinate_list[current_element.u].lon,
coordinate_list[current_element.u].lat),
Coordinate(coordinate_list[current_element.v].lon,
coordinate_list[current_element.v].lat));
current_centroid.lat = FixedLatitude(
COORDINATE_PRECISION *
coordinate_calculation::mercator::latToY(toFloating(current_centroid.lat)));
current_wrapper.m_hilbert_value = hilbertCode(current_centroid);
}
@ -377,8 +377,7 @@ class StaticRTree
}
// Override filter and terminator for the desired behaviour.
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
const std::size_t max_results)
std::vector<EdgeDataT> Nearest(const Coordinate input_coordinate, const std::size_t max_results)
{
return Nearest(input_coordinate,
[](const EdgeDataT &)
@ -393,14 +392,13 @@ class StaticRTree
// Override filter and terminator for the desired behaviour.
template <typename FilterT, typename TerminationT>
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
const FilterT filter,
const TerminationT terminate)
std::vector<EdgeDataT>
Nearest(const Coordinate input_coordinate, const FilterT filter, const TerminationT terminate)
{
std::vector<EdgeDataT> results;
std::pair<double, double> projected_coordinate = {
coordinate_calculation::mercator::latToY(input_coordinate.lat / COORDINATE_PRECISION),
input_coordinate.lon / COORDINATE_PRECISION};
static_cast<double>(toFloating(input_coordinate.lon)),
coordinate_calculation::mercator::latToY(toFloating(input_coordinate.lat))};
// initialize queue with root element
std::priority_queue<QueryCandidate> traversal_queue;
@ -462,7 +460,7 @@ class StaticRTree
private:
template <typename QueueT>
void ExploreLeafNode(const std::uint32_t leaf_id,
const FixedPointCoordinate input_coordinate,
const Coordinate input_coordinate,
const std::pair<double, double> &projected_coordinate,
QueueT &traversal_queue)
{
@ -487,7 +485,7 @@ class StaticRTree
template <class QueueT>
void ExploreTreeNode(const TreeNode &parent,
const FixedPointCoordinate input_coordinate,
const Coordinate input_coordinate,
QueueT &traversal_queue)
{
for (std::uint32_t i = 0; i < parent.child_count; ++i)
@ -542,10 +540,10 @@ class StaticRTree
std::max(rectangle.max_lat, std::max(coordinate_list[objects[i].u].lat,
coordinate_list[objects[i].v].lat));
}
BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.max_lat != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.max_lon != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.min_lon != FixedLongitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(rectangle.min_lat != FixedLatitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(rectangle.max_lon != FixedLongitude(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>(), ""); \
From x; \
friend std::ostream& operator<<(std::ostream& stream, const To& inst); \
friend std::ostream &operator<<(std::ostream &stream, const To &inst); \
\
public: \
To() = default; \
explicit To(const From x_) : x(x_) {} \
explicit operator From &() { return x; } \
explicit operator const From &() const { return x; } \
bool operator<(const To &z_) const { return x < static_cast<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_); } \
explicit operator From() const { return x; } \
To operator+(const To rhs_) const { return To(x + static_cast<const From>(rhs_)); } \
To operator-(const To rhs_) const { return To(x - static_cast<const From>(rhs_)); } \
To operator*(const To rhs_) const { return To(x * static_cast<const From>(rhs_)); } \
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_); } \
}; \
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 \
{ \
template <> struct hash<To> \
@ -42,9 +51,6 @@ namespace osrm
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
#define UTIL_TILES_HPP
#include "util/coordinate.hpp"
#include <boost/assert.hpp>
#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);
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);
return Tile{x, y, detail::MAX_ZOOM};
}
inline Tile getBBMaxZoomTile(const double min_lon,
const double min_lat,
const double max_lon,
const double max_lat)
inline Tile getBBMaxZoomTile(const FloatLongitude min_lon,
const FloatLatitude min_lat,
const FloatLongitude max_lon,
const FloatLatitude max_lat)
{
const auto top_left = pointToTile(min_lon, min_lat);
const auto bottom_left = pointToTile(max_lon, max_lat);

View File

@ -8,7 +8,10 @@
// OpenStreetMap node ids are higher than 2^32
OSRM_STRONG_TYPEDEF(uint64_t, OSMNodeID)
OSRM_STRONG_TYPEDEF_HASHABLE(uint64_t, OSMNodeID)
OSRM_STRONG_TYPEDEF(uint32_t, OSMWayID)
OSRM_STRONG_TYPEDEF_HASHABLE(uint32_t, OSMWayID)
static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_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 "util/timing_util.hpp"
#include "mocks/mock_datafacade.hpp"
#include "osrm/coordinate.hpp"
#include "util/coordinate.hpp"
#include <iostream>
#include <random>
@ -25,23 +24,23 @@ constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
using RTreeLeaf = extractor::EdgeBasedNode;
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<util::FixedPointCoordinate>>;
using CoordinateListPtr = std::shared_ptr<std::vector<util::Coordinate>>;
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>;
FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file)
CoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file)
{
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
extractor::QueryNode current_node;
unsigned coordinate_count = 0;
nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned));
auto coords = std::make_shared<std::vector<FixedPointCoordinate>>(coordinate_count);
auto coords = std::make_shared<std::vector<Coordinate>>(coordinate_count);
for (unsigned i = 0; i < coordinate_count; ++i)
{
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).lon) >> 30) == 0);
}
@ -49,7 +48,7 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes
}
template <typename QueryT>
void benchmarkQuery(const std::vector<FixedPointCoordinate> &queries,
void benchmarkQuery(const std::vector<util::Coordinate> &queries,
const std::string &name,
QueryT query)
{
@ -75,38 +74,35 @@ void benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer
std::mt19937 mt_rand(RANDOM_SEED);
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
std::vector<FixedPointCoordinate> queries;
std::vector<util::Coordinate> queries;
for (unsigned i = 0; i < num_queries; i++)
{
queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand));
}
benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q)
benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const util::Coordinate &q)
{
return rtree.Nearest(q, 1);
});
benchmarkQuery(queries, "raw RTree queries (10 results)",
[&rtree](const FixedPointCoordinate &q)
benchmarkQuery(queries, "raw RTree queries (10 results)", [&rtree](const util::Coordinate &q)
{
return rtree.Nearest(q, 10);
});
benchmarkQuery(queries, "big component alternative queries",
[&geo_query](const FixedPointCoordinate &q)
[&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodeWithAlternativeFromBigComponent(q);
});
benchmarkQuery(queries, "max distance 1000", [&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "max distance 1000", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodesInRange(q, 1000);
});
benchmarkQuery(queries, "PhantomNode query (1 result)",
[&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "PhantomNode query (1 result)", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodes(q, 1);
});
benchmarkQuery(queries, "PhantomNode query (10 result)",
[&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "PhantomNode query (10 result)", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodes(q, 10);
});
@ -130,7 +126,8 @@ int main(int argc, char **argv)
auto coords = osrm::benchmarks::loadCoordinates(nodes_path);
osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords);
std::unique_ptr<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::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
{
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;
std::size_t max_edge_id = LoadEdgeExpandedGraph(
config.edge_based_graph_path, edge_based_edge_list,
config.edge_segment_lookup_path, config.edge_penalty_path,
config.segment_speed_lookup_path, config.node_based_graph_path,
config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path,
config.edge_penalty_path, config.segment_speed_lookup_path, config.node_based_graph_path,
config.geometry_path, config.rtree_leaf_path);
// Contracting the edge-expanded graph
@ -195,7 +194,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (!nodes_input_stream)
{
throw util::exception("Failed to open "+nodes_filename);
throw util::exception("Failed to open " + nodes_filename);
}
unsigned number_of_nodes = 0;
@ -203,7 +202,8 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
internal_to_external_node_map.resize(number_of_nodes);
// Load all the query nodes into a vector
nodes_input_stream.read(reinterpret_cast<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;
@ -213,7 +213,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ifstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream)
{
throw util::exception("Failed to open "+geometry_filename);
throw util::exception("Failed to open " + geometry_filename);
}
unsigned number_of_indices = 0;
unsigned number_of_compressed_geometries = 0;
@ -234,8 +234,10 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (number_of_compressed_geometries > 0)
{
geometry_stream.read((char *)&(m_geometry_list[0]),
number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
geometry_stream.read(
(char *)&(m_geometry_list[0]),
number_of_compressed_geometries *
sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
}
}
@ -249,7 +251,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in);
if (!leaf_node_file)
{
throw util::exception("Failed to open "+rtree_leaf_filename);
throw util::exception("Failed to open " + rtree_leaf_filename);
}
uint64_t m_element_count;
leaf_node_file.read((char *)&m_element_count, sizeof(uint64_t));
@ -259,71 +261,93 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
{
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 *v;
if (leaf_object.forward_packed_geometry_id != SPECIAL_EDGEID)
{
const unsigned forward_begin = m_geometry_indices.at(leaf_object.forward_packed_geometry_id);
const unsigned forward_begin =
m_geometry_indices.at(leaf_object.forward_packed_geometry_id);
if (leaf_object.fwd_segment_position == 0)
{
u = &(internal_to_external_node_map[leaf_object.u]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin]
.node_id]);
}
else
{
u = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position - 1].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position].node_id]);
u = &(internal_to_external_node_map
[m_geometry_list[forward_begin +
leaf_object.fwd_segment_position - 1]
.node_id]);
v = &(internal_to_external_node_map
[m_geometry_list[forward_begin +
leaf_object.fwd_segment_position]
.node_id]);
}
const double segment_length =
util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon);
util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat});
auto forward_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
auto forward_speed_iter =
segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
if (forward_speed_iter != segment_speed_lookup.end())
{
int new_segment_weight =
std::max(1, static_cast<int>(std::floor(
(segment_length * 10.) / (forward_speed_iter->second / 3.6) + .5)));
m_geometry_list[forward_begin + leaf_object.fwd_segment_position].weight = new_segment_weight;
int new_segment_weight = std::max(
1, static_cast<int>(std::floor(
(segment_length * 10.) / (forward_speed_iter->second / 3.6) +
.5)));
m_geometry_list[forward_begin + leaf_object.fwd_segment_position]
.weight = new_segment_weight;
}
}
if (leaf_object.reverse_packed_geometry_id != SPECIAL_EDGEID)
{
const unsigned reverse_begin = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id);
const unsigned reverse_end = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1);
const unsigned reverse_begin =
m_geometry_indices.at(leaf_object.reverse_packed_geometry_id);
const unsigned reverse_end =
m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1);
int rev_segment_position = (reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1;
int rev_segment_position =
(reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1;
if (rev_segment_position == 0)
{
u = &(internal_to_external_node_map[leaf_object.v]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin]
.node_id]);
}
else
{
u = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position - 1].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position].node_id]);
u = &(internal_to_external_node_map
[m_geometry_list[reverse_begin + rev_segment_position - 1]
.node_id]);
v = &(
internal_to_external_node_map[m_geometry_list[reverse_begin +
rev_segment_position]
.node_id]);
}
const double segment_length =
util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon);
util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat});
auto reverse_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
auto reverse_speed_iter =
segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
if (reverse_speed_iter != segment_speed_lookup.end())
{
int new_segment_weight =
std::max(1, static_cast<int>(std::floor(
(segment_length * 10.) / (reverse_speed_iter->second / 3.6) + .5)));
m_geometry_list[reverse_begin + rev_segment_position].weight = new_segment_weight;
int new_segment_weight = std::max(
1, static_cast<int>(std::floor(
(segment_length * 10.) / (reverse_speed_iter->second / 3.6) +
.5)));
m_geometry_list[reverse_begin + rev_segment_position].weight =
new_segment_weight;
}
}
}
m_element_count -= current_node.object_count;
}
}
@ -332,17 +356,20 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ofstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream)
{
throw util::exception("Failed to open "+geometry_filename+" for writing");
throw util::exception("Failed to open " + geometry_filename + " for writing");
}
const unsigned number_of_indices = m_geometry_indices.size();
const unsigned number_of_compressed_geometries = m_geometry_list.size();
geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices), sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])), 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));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices),
sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])),
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

View File

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

View File

@ -24,21 +24,21 @@ namespace
struct CoordinatePairCalculator
{
CoordinatePairCalculator() = delete;
CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a,
const util::FixedPointCoordinate coordinate_b)
CoordinatePairCalculator(const util::Coordinate coordinate_a,
const util::Coordinate coordinate_b)
{
// initialize distance calculator with two fixed coordinates a, b
first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD;
first_lon = (coordinate_a.lon / COORDINATE_PRECISION) * util::RAD;
second_lat = (coordinate_b.lat / COORDINATE_PRECISION) * util::RAD;
second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD;
first_lon = static_cast<double>(toFloating(coordinate_a.lon)) * util::RAD;
first_lat = static_cast<double>(toFloating(coordinate_a.lat)) * util::RAD;
second_lon = static_cast<double>(toFloating(coordinate_b.lon)) * 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
const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD;
const float float_lon1 = (other.lon / COORDINATE_PRECISION) * util::RAD;
const float float_lon1 = static_cast<double>(toFloating(other.lon)) * util::RAD;
const float float_lat1 = static_cast<double>(toFloating(other.lat)) * util::RAD;
// compute distance (a,c)
const float x_value_1 = (first_lon - float_lon1) * cos((float_lat1 + first_lat) / 2.f);
@ -61,9 +61,8 @@ struct CoordinatePairCalculator
};
}
std::vector<util::FixedPointCoordinate>
douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
std::vector<util::FixedPointCoordinate>::const_iterator end,
std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::const_iterator begin,
std::vector<util::Coordinate>::const_iterator end,
const unsigned zoom_level)
{
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;
recursion_stack.emplace(0UL, size-1);
recursion_stack.emplace(0UL, size - 1);
// mark locations as 'necessary' by divide-and-conquer
while (!recursion_stack.empty())
@ -131,7 +130,7 @@ douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
}
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);
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)
{
int min_lon = std::numeric_limits<int>::max();
int min_lat = std::numeric_limits<int>::max();
int max_lon = -std::numeric_limits<int>::max();
int max_lat = -std::numeric_limits<int>::max();
util::FixedLongitude min_lon{std::numeric_limits<int>::max()};
util::FixedLongitude max_lon{-std::numeric_limits<int>::max()};
util::FixedLatitude min_lat{std::numeric_limits<int>::max()};
util::FixedLatitude max_lat{-std::numeric_limits<int>::max()};
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;
for (const auto geometry : leg_geometries)
{
@ -59,8 +62,8 @@ std::vector<util::FixedPointCoordinate> simplifyGeometry(const std::vector<LegGe
}
}
std::vector<util::FixedPointCoordinate>
assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_simplification)
std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
const bool 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();
}) -
leg_geometries.size() + 1;
std::vector<util::FixedPointCoordinate> overview_geometry;
std::vector<util::Coordinate> overview_geometry;
overview_geometry.reserve(overview_size);
auto leg_index = 0UL;

View File

@ -26,7 +26,7 @@ namespace plugins
{
// 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)
{
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
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end)
{
auto size = std::distance(begin, end);
@ -69,20 +68,22 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
std::vector<int> delta_numbers;
BOOST_ASSERT(size > 0);
delta_numbers.reserve((size - 1) * 2);
util::FixedPointCoordinate previous_coordinate = {0, 0};
std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const FixedPointCoordinate loc)
util::Coordinate previous_coordinate{util::FixedLongitude(0), util::FixedLatitude(0)};
std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const util::Coordinate loc)
{
const int lat_diff = (loc.lat - previous_coordinate.lat) * detail::COORDINATE_TO_POLYLINE;
const int lon_diff = (loc.lon - previous_coordinate.lon) * detail::COORDINATE_TO_POLYLINE;
const int lat_diff = static_cast<int>(loc.lat - previous_coordinate.lat) *
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(lon_diff);
previous_coordinate = loc;
});
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 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));
lng += dlng;
util::FixedPointCoordinate p;
p.lat = lat * detail::POLYLINE_TO_COORDINATE;
p.lon = lng * detail::POLYLINE_TO_COORDINATE;
util::Coordinate p;
p.lat = util::FixedLatitude(lat * detail::POLYLINE_TO_COORDINATE);
p.lon = util::FixedLongitude(lng * detail::POLYLINE_TO_COORDINATE);
new_coordinates.push_back(p);
}

View File

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

View File

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

View File

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

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, "");
}
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
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("id", &osmium::Way::id),
luabind::class_<InternalExtractorEdge>("EdgeSource")
.property("source_coordinate", &InternalExtractorEdge::source_coordinate)
.property("weight_data", &InternalExtractorEdge::weight_data),
.def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate)
.def_readwrite("weight_data", &InternalExtractorEdge::weight_data),
luabind::class_<InternalExtractorEdge::WeightData>("WeightData")
.def_readwrite("speed", &InternalExtractorEdge::WeightData::speed),
luabind::class_<ExternalMemoryNode>("EdgeTarget")
.property("lat", &ExternalMemoryNode::lat)
.property("lon", &ExternalMemoryNode::lon),
luabind::class_<util::FixedPointCoordinate>("Coordinate")
.property("lat", &util::FixedPointCoordinate::lat)
.property("lon", &util::FixedPointCoordinate::lon),
.property("lon", &lonToDouble<ExternalMemoryNode>)
.property("lat", &latToDouble<ExternalMemoryNode>),
luabind::class_<util::Coordinate>("Coordinate")
.property("lon", &lonToDouble<util::Coordinate>)
.property("lat", &latToDouble<util::Coordinate>),
luabind::class_<RasterDatum>("RasterDatum")
.property("datum", &RasterDatum::datum)
.def_readonly("datum", &RasterDatum::datum)
.def("invalid_data", &RasterDatum::get_invalid)];
if (0 != luaL_dofile(lua_state, file_name.c_str()))

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)
{
parsed_url.coordinates.emplace_back(
util::FixedPointCoordinate(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION,
boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION));
parsed_url.coordinates.emplace_back(util::Coordinate(
util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION),
util::FixedLatitude(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION)));
};
const auto polyline_to_coordinates = [this](const std::string &polyline)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,8 +17,7 @@
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
#include "osrm/coordinate.hpp"
#include "util/coordinate.hpp"
#ifdef __linux__
#include <sys/mman.h>
@ -38,11 +37,9 @@ namespace osrm
namespace storage
{
using RTreeLeaf =
typename engine::datafacade::BaseDataFacade::RTreeLeaf;
using RTreeNode = util::StaticRTree<RTreeLeaf,
util::ShM<util::FixedPointCoordinate, true>::vector,
true>::TreeNode;
using RTreeLeaf = typename engine::datafacade::BaseDataFacade::RTreeLeaf;
using RTreeNode =
util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>::TreeNode;
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;
// 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);
unsigned coordinate_list_size = 0;
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);
// load geometries sizes
@ -438,15 +435,14 @@ int Storage::Run()
}
// Loading list of coordinates
util::FixedPointCoordinate *coordinates_ptr =
shared_layout_ptr->GetBlockPtr<util::FixedPointCoordinate, true>(
util::Coordinate *coordinates_ptr = shared_layout_ptr->GetBlockPtr<util::Coordinate, true>(
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
extractor::QueryNode current_node;
for (unsigned i = 0; i < coordinate_list_size; ++i)
{
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();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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