Be kind to the optimizer, pass coordinates by value (just two ints)
This commit is contained in:
committed by
Patrick Niklaus
parent
46fc6f8da4
commit
d391df52ba
@@ -1,6 +1,8 @@
|
||||
#ifndef COORDINATE_CALCULATION
|
||||
#define COORDINATE_CALCULATION
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -14,54 +16,52 @@ const constexpr long double RAD = 0.017453292519943295769236907684886;
|
||||
// The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
|
||||
const constexpr long double EARTH_RADIUS = 6372797.560856;
|
||||
|
||||
struct FixedPointCoordinate;
|
||||
|
||||
namespace coordinate_calculation
|
||||
{
|
||||
double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
double haversineDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
double haversineDistance(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
|
||||
double greatCircleDistance(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
double greatCircleDistance(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
|
||||
double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
double perpendicularDistance(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location);
|
||||
double perpendicularDistance(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location);
|
||||
|
||||
double perpendicularDistance(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location,
|
||||
double perpendicularDistance(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location,
|
||||
FixedPointCoordinate &nearest_location,
|
||||
double &ratio);
|
||||
|
||||
double
|
||||
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location,
|
||||
const std::pair<double, double> &projected_coordinate);
|
||||
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location,
|
||||
const std::pair<double, double> projected_coordinate);
|
||||
|
||||
double
|
||||
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source,
|
||||
const FixedPointCoordinate &segment_target,
|
||||
const FixedPointCoordinate &query_location,
|
||||
const std::pair<double, double> &projected_coordinate,
|
||||
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location,
|
||||
const std::pair<double, double> projected_coordinate,
|
||||
FixedPointCoordinate &nearest_location,
|
||||
double &ratio);
|
||||
|
||||
double degToRad(const double degree);
|
||||
double radToDeg(const double radian);
|
||||
|
||||
double bearing(const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate &second_coordinate);
|
||||
double bearing(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
|
||||
// Get angle of line segment (A,C)->(C,B)
|
||||
double computeAngle(const FixedPointCoordinate &first,
|
||||
const FixedPointCoordinate &second,
|
||||
const FixedPointCoordinate &third);
|
||||
double computeAngle(const FixedPointCoordinate first,
|
||||
const FixedPointCoordinate second,
|
||||
const FixedPointCoordinate third);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "contractor/contractor_config.hpp"
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
#ifndef DEBUG_GEOMETRY
|
||||
|
||||
@@ -23,7 +24,7 @@ inline void DEBUG_GEOMETRY_STOP() {}
|
||||
inline void DEBUG_TURNS_START(const std::string & /* debug_turns_filename */) {}
|
||||
inline void DEBUG_TURN(const NodeID /* node */,
|
||||
const std::vector<extractor::QueryNode> & /* m_node_info_list */,
|
||||
const FixedPointCoordinate & /* first_coordinate */,
|
||||
const FixedPointCoordinate /* first_coordinate */,
|
||||
const int /* turn_angle */,
|
||||
const int /* turn_penalty */)
|
||||
{
|
||||
@@ -95,11 +96,9 @@ inline void DEBUG_GEOMETRY_EDGE(int new_segment_weight,
|
||||
if (!dg_first_debug_geometry)
|
||||
debug_geometry_file << "," << std::endl;
|
||||
debug_geometry_file << "{ \"type\":\"Feature\",\"properties\":{\"original\":false, "
|
||||
"\"weight\":"
|
||||
<< new_segment_weight / 10.0 << ",\"speed\":"
|
||||
<< static_cast<int>(
|
||||
std::floor((segment_length / new_segment_weight) * 10. * 3.6))
|
||||
<< ",";
|
||||
"\"weight\":" << new_segment_weight / 10.0 << ",\"speed\":"
|
||||
<< static_cast<int>(std::floor((segment_length / new_segment_weight) *
|
||||
10. * 3.6)) << ",";
|
||||
debug_geometry_file << "\"from_node\": " << previous_osm_node_id
|
||||
<< ", \"to_node\": " << this_osm_node_id << ",";
|
||||
debug_geometry_file << "\"timestamp\": \"" << dg_time_buffer << "\"},";
|
||||
@@ -114,7 +113,8 @@ inline void DEBUG_GEOMETRY_STOP()
|
||||
{
|
||||
if (dg_output_debug_geometry)
|
||||
{
|
||||
debug_geometry_file << std::endl << "]}" << std::endl;
|
||||
debug_geometry_file << std::endl
|
||||
<< "]}" << std::endl;
|
||||
debug_geometry_file.close();
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ inline void DEBUG_UTURN(const NodeID node,
|
||||
|
||||
inline void DEBUG_TURN(const NodeID node,
|
||||
const std::vector<extractor::QueryNode> &m_node_info_list,
|
||||
const FixedPointCoordinate &first_coordinate,
|
||||
const FixedPointCoordinate first_coordinate,
|
||||
const int turn_angle,
|
||||
const int turn_penalty)
|
||||
{
|
||||
@@ -201,7 +201,8 @@ inline void DEBUG_TURNS_STOP()
|
||||
{
|
||||
if (dg_output_turn_debug)
|
||||
{
|
||||
dg_debug_turns_file << std::endl << "]}" << std::endl;
|
||||
dg_debug_turns_file << std::endl
|
||||
<< "]}" << std::endl;
|
||||
dg_debug_turns_file.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef HILBERT_VALUE_HPP
|
||||
#define HILBERT_VALUE_HPP
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace osrm
|
||||
@@ -9,19 +11,16 @@ namespace util
|
||||
{
|
||||
|
||||
// computes a 64 bit value that corresponds to the hilbert space filling curve
|
||||
|
||||
struct FixedPointCoordinate;
|
||||
|
||||
class HilbertCode
|
||||
{
|
||||
public:
|
||||
uint64_t operator()(const FixedPointCoordinate ¤t_coordinate) const;
|
||||
std::uint64_t operator()(const FixedPointCoordinate current_coordinate) const;
|
||||
HilbertCode() {}
|
||||
HilbertCode(const HilbertCode &) = delete;
|
||||
|
||||
private:
|
||||
inline uint64_t BitInterleaving(const uint32_t a, const uint32_t b) const;
|
||||
inline void TransposeCoordinate(uint32_t *X) const;
|
||||
inline std::uint64_t BitInterleaving(const std::uint32_t a, const std::uint32_t b) const;
|
||||
inline void TransposeCoordinate(std::uint32_t *x) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ struct RectangleInt2D
|
||||
Contains(lower_left));
|
||||
}
|
||||
|
||||
double GetMinDist(const FixedPointCoordinate &location) const
|
||||
double GetMinDist(const FixedPointCoordinate location) const
|
||||
{
|
||||
const bool is_contained = Contains(location);
|
||||
if (is_contained)
|
||||
@@ -139,7 +139,7 @@ struct RectangleInt2D
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
double GetMinMaxDist(const FixedPointCoordinate &location) const
|
||||
double GetMinMaxDist(const FixedPointCoordinate location) const
|
||||
{
|
||||
double min_max_dist = std::numeric_limits<double>::max();
|
||||
// Get minmax distance to each of the four sides
|
||||
@@ -170,7 +170,7 @@ struct RectangleInt2D
|
||||
return min_max_dist;
|
||||
}
|
||||
|
||||
bool Contains(const FixedPointCoordinate &location) const
|
||||
bool Contains(const FixedPointCoordinate location) const
|
||||
{
|
||||
const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat);
|
||||
const bool lons_contained = (location.lon >= min_lon) && (location.lon <= max_lon);
|
||||
|
||||
@@ -124,8 +124,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, &get_hilbert_number,
|
||||
&coordinate_list](const tbb::blocked_range<uint64_t> &range)
|
||||
[&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list](
|
||||
const tbb::blocked_range<uint64_t> &range)
|
||||
{
|
||||
for (uint64_t element_counter = range.begin(), end = range.end();
|
||||
element_counter != end; ++element_counter)
|
||||
@@ -322,7 +322,7 @@ class StaticRTree
|
||||
}
|
||||
|
||||
// Override filter and terminator for the desired behaviour.
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
|
||||
const std::size_t max_results)
|
||||
{
|
||||
return Nearest(input_coordinate,
|
||||
@@ -338,7 +338,7 @@ class StaticRTree
|
||||
|
||||
// Override filter and terminator for the desired behaviour.
|
||||
template <typename FilterT, typename TerminationT>
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate &input_coordinate,
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
|
||||
const FilterT filter,
|
||||
const TerminationT terminate)
|
||||
{
|
||||
@@ -407,7 +407,7 @@ class StaticRTree
|
||||
private:
|
||||
template <typename QueueT>
|
||||
void ExploreLeafNode(const std::uint32_t leaf_id,
|
||||
const FixedPointCoordinate &input_coordinate,
|
||||
const FixedPointCoordinate input_coordinate,
|
||||
const std::pair<double, double> &projected_coordinate,
|
||||
QueueT &traversal_queue)
|
||||
{
|
||||
@@ -432,7 +432,7 @@ class StaticRTree
|
||||
|
||||
template <class QueueT>
|
||||
void ExploreTreeNode(const TreeNode &parent,
|
||||
const FixedPointCoordinate &input_coordinate,
|
||||
const FixedPointCoordinate input_coordinate,
|
||||
QueueT &traversal_queue)
|
||||
{
|
||||
for (uint32_t i = 0; i < parent.child_count; ++i)
|
||||
|
||||
Reference in New Issue
Block a user