Be kind to the optimizer, pass coordinates by value (just two ints)

This commit is contained in:
Daniel J. Hofmann 2016-01-21 13:07:24 +01:00 committed by Patrick Niklaus
parent 46fc6f8da4
commit d391df52ba
17 changed files with 165 additions and 162 deletions

View File

@ -74,19 +74,19 @@ template <class EdgeDataT> class BaseDataFacade
virtual extractor::TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
const float max_distance,
const int bearing = 0,
const int bearing_range = 180) = 0;
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
const unsigned max_results,
const int bearing = 0,
const int bearing_range = 180) = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate &input_coordinate,
const util::FixedPointCoordinate input_coordinate,
const int bearing = 0,
const int bearing_range = 180) = 0;

View File

@ -343,7 +343,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
const float max_distance,
const int bearing = 0,
const int bearing_range = 180) override final
@ -359,7 +359,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
const unsigned max_results,
const int bearing = 0,
const int bearing_range = 180) override final
@ -375,7 +375,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate &input_coordinate,
const util::FixedPointCoordinate input_coordinate,
const int bearing = 0,
const int bearing_range = 180) override final
{

View File

@ -79,8 +79,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
void LoadChecksum()
{
m_check_sum =
*data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::HSGR_CHECKSUM);
m_check_sum = *data_layout->GetBlockPtr<unsigned>(shared_memory,
storage::SharedDataLayout::HSGR_CHECKSUM);
util::SimpleLogger().Write() << "set checksum: " << m_check_sum;
}
@ -98,8 +98,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
{
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
RTreeNode *tree_ptr =
data_layout->GetBlockPtr<RTreeNode>(shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
RTreeNode *tree_ptr = data_layout->GetBlockPtr<RTreeNode>(
shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
m_static_rtree.reset(new TimeStampedRTreePair(
CURRENT_TIMESTAMP,
util::make_unique<SharedRTree>(
@ -111,11 +111,11 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
void LoadGraph()
{
GraphNode *graph_nodes_ptr =
data_layout->GetBlockPtr<GraphNode>(shared_memory, storage::SharedDataLayout::GRAPH_NODE_LIST);
GraphNode *graph_nodes_ptr = data_layout->GetBlockPtr<GraphNode>(
shared_memory, storage::SharedDataLayout::GRAPH_NODE_LIST);
GraphEdge *graph_edges_ptr =
data_layout->GetBlockPtr<GraphEdge>(shared_memory, storage::SharedDataLayout::GRAPH_EDGE_LIST);
GraphEdge *graph_edges_ptr = data_layout->GetBlockPtr<GraphEdge>(
shared_memory, storage::SharedDataLayout::GRAPH_EDGE_LIST);
typename util::ShM<GraphNode, true>::vector node_list(
graph_nodes_ptr, data_layout->num_entries[storage::SharedDataLayout::GRAPH_NODE_LIST]);
@ -128,10 +128,11 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
{
util::FixedPointCoordinate *coordinate_list_ptr =
data_layout->GetBlockPtr<util::FixedPointCoordinate>(shared_memory,
storage::SharedDataLayout::COORDINATE_LIST);
data_layout->GetBlockPtr<util::FixedPointCoordinate>(
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
m_coordinate_list = util::make_unique<util::ShM<util::FixedPointCoordinate, true>::vector>(
coordinate_list_ptr, data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
coordinate_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
extractor::TravelMode *travel_mode_list_ptr =
data_layout->GetBlockPtr<extractor::TravelMode>(shared_memory,
@ -148,8 +149,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]);
m_turn_instruction_list.swap(turn_instruction_list);
unsigned *name_id_list_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::NAME_ID_LIST);
unsigned *name_id_list_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, storage::SharedDataLayout::NAME_ID_LIST);
typename util::ShM<unsigned, true>::vector name_id_list(
name_id_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_ID_LIST]);
m_name_ID_list.swap(name_id_list);
@ -157,8 +158,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
void LoadViaNodeList()
{
NodeID *via_node_list_ptr =
data_layout->GetBlockPtr<NodeID>(shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
NodeID *via_node_list_ptr = data_layout->GetBlockPtr<NodeID>(
shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
typename util::ShM<NodeID, true>::vector via_node_list(
via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
m_via_node_list.swap(via_node_list);
@ -166,17 +167,17 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
void LoadNames()
{
unsigned *offsets_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::NAME_OFFSETS);
NameIndexBlock *blocks_ptr =
data_layout->GetBlockPtr<NameIndexBlock>(shared_memory, storage::SharedDataLayout::NAME_BLOCKS);
unsigned *offsets_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, storage::SharedDataLayout::NAME_OFFSETS);
NameIndexBlock *blocks_ptr = data_layout->GetBlockPtr<NameIndexBlock>(
shared_memory, storage::SharedDataLayout::NAME_BLOCKS);
typename util::ShM<unsigned, true>::vector name_offsets(
offsets_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_OFFSETS]);
typename util::ShM<NameIndexBlock, true>::vector name_blocks(
blocks_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_BLOCKS]);
char *names_list_ptr =
data_layout->GetBlockPtr<char>(shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST);
char *names_list_ptr = data_layout->GetBlockPtr<char>(
shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST);
typename util::ShM<char, true>::vector names_char_list(
names_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_CHAR_LIST]);
m_name_table = util::make_unique<util::RangeTable<16, true>>(
@ -192,8 +193,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return;
}
unsigned *core_marker_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::CORE_MARKER);
unsigned *core_marker_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, storage::SharedDataLayout::CORE_MARKER);
typename util::ShM<bool, true>::vector is_core_node(
core_marker_ptr, data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER]);
m_is_core_node.swap(is_core_node);
@ -208,16 +209,18 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDICATORS]);
m_edge_is_compressed.swap(edge_is_compressed);
unsigned *geometries_index_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX);
unsigned *geometries_index_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX);
typename util::ShM<unsigned, true>::vector geometry_begin_indices(
geometries_index_ptr, data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]);
geometries_index_ptr,
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]);
m_geometry_indices.swap(geometry_begin_indices);
unsigned *geometries_list_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
unsigned *geometries_list_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
typename util::ShM<unsigned, true>::vector geometry_list(
geometries_list_ptr, data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
geometries_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
m_geometry_list.swap(geometry_list);
}
@ -230,12 +233,12 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
{
if (!storage::SharedMemory::RegionExists(storage::CURRENT_REGIONS))
{
throw util::exception("No shared memory blocks found, have you forgotten to run osrm-datastore?");
throw util::exception(
"No shared memory blocks found, have you forgotten to run osrm-datastore?");
}
data_timestamp_ptr = static_cast<storage::SharedDataTimestamp *>(
storage::makeSharedMemory(storage::CURRENT_REGIONS,
sizeof(storage::SharedDataTimestamp), false, false)
->Ptr());
sizeof(storage::SharedDataTimestamp), false, false)->Ptr());
CURRENT_LAYOUT = storage::LAYOUT_NONE;
CURRENT_DATA = storage::DATA_NONE;
CURRENT_TIMESTAMP = 0;
@ -265,12 +268,13 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
CURRENT_DATA = data_timestamp_ptr->data;
CURRENT_TIMESTAMP = 0; // Force trigger a reload
util::SimpleLogger().Write(logDEBUG) << "Current layout was different to new layout, swapping";
util::SimpleLogger().Write(logDEBUG)
<< "Current layout was different to new layout, swapping";
}
else
{
util::SimpleLogger().Write(logDEBUG) << "Current layout was same to new layout, not swapping";
util::SimpleLogger().Write(logDEBUG)
<< "Current layout was same to new layout, not swapping";
}
if (CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp)
@ -280,15 +284,16 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
util::SimpleLogger().Write(logDEBUG) << "Performing data reload";
m_layout_memory.reset(storage::makeSharedMemory(CURRENT_LAYOUT));
data_layout = (storage::SharedDataLayout *) (m_layout_memory->Ptr());
data_layout = (storage::SharedDataLayout *)(m_layout_memory->Ptr());
m_large_memory.reset(storage::makeSharedMemory(CURRENT_DATA));
shared_memory = (char *) (m_large_memory->Ptr());
shared_memory = (char *)(m_large_memory->Ptr());
const char *file_index_ptr =
data_layout->GetBlockPtr<char>(shared_memory, storage::SharedDataLayout::FILE_INDEX_PATH);
const char *file_index_ptr = data_layout->GetBlockPtr<char>(
shared_memory, storage::SharedDataLayout::FILE_INDEX_PATH);
file_index_path = boost::filesystem::path(file_index_ptr);
if (!boost::filesystem::exists(file_index_path)) {
if (!boost::filesystem::exists(file_index_path))
{
util::SimpleLogger().Write(logDEBUG) << "Leaf file name "
<< file_index_path.string();
throw util::exception("Could not load leaf index file. "
@ -304,7 +309,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
LoadNames();
LoadCoreInformation();
util::SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size();
util::SimpleLogger().Write()
<< "number of geometries: " << m_coordinate_list->size();
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
{
if (!GetCoordinateOfNode(i).IsValid())
@ -398,7 +404,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodesInRange(const util::FixedPointCoordinate input_coordinate,
const float max_distance,
const int bearing = 0,
const int bearing_range = 180) override final
@ -414,7 +420,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const util::FixedPointCoordinate &input_coordinate,
NearestPhantomNodes(const util::FixedPointCoordinate input_coordinate,
const unsigned max_results,
const int bearing = 0,
const int bearing_range = 180) override final
@ -430,7 +436,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::FixedPointCoordinate &input_coordinate,
const util::FixedPointCoordinate input_coordinate,
const int bearing = 0,
const int bearing_range = 180) override final
{

View File

@ -35,7 +35,7 @@ template <typename RTreeT> 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::FixedPointCoordinate input_coordinate,
const double max_distance,
const int bearing = 0,
const int bearing_range = 180)
@ -57,7 +57,7 @@ template <typename RTreeT> 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::FixedPointCoordinate input_coordinate,
const unsigned max_results,
const int bearing = 0,
const int bearing_range = 180)
@ -78,7 +78,7 @@ template <typename RTreeT> 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 util::FixedPointCoordinate input_coordinate,
const int bearing = 0,
const int bearing_range = 180)
{
@ -86,8 +86,8 @@ template <typename RTreeT> class GeospatialQuery
bool has_big_component = false;
auto results = rtree.Nearest(
input_coordinate,
[this, bearing, bearing_range, &has_big_component,
&has_small_component](const EdgeData &data)
[this, bearing, bearing_range, &has_big_component, &has_small_component](
const EdgeData &data)
{
auto use_segment =
(!has_small_component || (!has_big_component && !data.component.is_tiny));
@ -122,7 +122,7 @@ template <typename RTreeT> class GeospatialQuery
private:
std::vector<PhantomNodeWithDistance>
MakePhantomNodes(const util::FixedPointCoordinate &input_coordinate,
MakePhantomNodes(const util::FixedPointCoordinate input_coordinate,
const std::vector<EdgeData> &results) const
{
std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size());
@ -134,7 +134,7 @@ template <typename RTreeT> class GeospatialQuery
return distance_and_phantoms;
}
PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate &input_coordinate,
PhantomNodeWithDistance MakePhantomNode(const util::FixedPointCoordinate input_coordinate,
const EdgeData &data) const
{
util::FixedPointCoordinate point_on_segment;

View File

@ -51,7 +51,7 @@ template <typename DataFacadeT> class SegmentList
const bool is_via_leg,
const DataFacade *facade);
void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &path_point);
void AppendSegment(const FixedPointCoordinate coordinate, const PathData &path_point);
void Finalize(const bool extract_alternative,
const InternalRouteResult &raw_route,
const unsigned zoom_level,
@ -192,7 +192,7 @@ std::vector<SegmentInformation> const &SegmentList<DataFacadeT>::Get() const
}
template <typename DataFacadeT>
void SegmentList<DataFacadeT>::AppendSegment(const FixedPointCoordinate &coordinate,
void SegmentList<DataFacadeT>::AppendSegment(const FixedPointCoordinate coordinate,
const PathData &path_point)
{
// if the start location is on top of a node, the first movement might be zero-length,

View File

@ -27,7 +27,7 @@ struct PhantomNode
unsigned packed_geometry_id,
bool is_tiny_component,
unsigned component_id,
util::FixedPointCoordinate &location,
util::FixedPointCoordinate location,
unsigned short fwd_segment_position,
extractor::TravelMode forward_travel_mode,
extractor::TravelMode backward_travel_mode)
@ -35,7 +35,7 @@ struct PhantomNode
forward_weight(forward_weight), reverse_weight(reverse_weight),
forward_offset(forward_offset), reverse_offset(reverse_offset),
packed_geometry_id(packed_geometry_id), component{component_id, is_tiny_component},
location(location), fwd_segment_position(fwd_segment_position),
location(std::move(location)), fwd_segment_position(fwd_segment_position),
forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode)
{
}
@ -89,7 +89,7 @@ struct PhantomNode
bool operator==(const PhantomNode &other) const { return location == other.location; }
template <class OtherT>
PhantomNode(const OtherT &other, const util::FixedPointCoordinate &foot_point)
PhantomNode(const OtherT &other, const util::FixedPointCoordinate foot_point)
{
forward_node_id = other.forward_edge_based_node_id;
reverse_node_id = other.reverse_edge_based_node_id;

View File

@ -50,7 +50,7 @@ class HelloWorldPlugin final : public BasePlugin
util::json::Array json_locations;
unsigned counter = 0;
for (const util::FixedPointCoordinate &coordinate : routeParameters.coordinates)
for (const auto coordinate : routeParameters.coordinates)
{
util::json::Object json_location;
util::json::Array json_coordinates;

View File

@ -38,7 +38,7 @@ class BasePlugin
const unsigned min = 2) const final
{
if (min > coordinates.size() || std::any_of(std::begin(coordinates), std::end(coordinates),
[](const util::FixedPointCoordinate &coordinate)
[](const util::FixedPointCoordinate coordinate)
{
return !coordinate.IsValid();
}))

View File

@ -58,8 +58,8 @@ struct EdgeBasedNode
(reverse_edge_based_node_id != SPECIAL_NODEID));
}
static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate &a,
const util::FixedPointCoordinate &b)
static inline util::FixedPointCoordinate Centroid(const util::FixedPointCoordinate a,
const util::FixedPointCoordinate b)
{
util::FixedPointCoordinate centroid;
// The coordinates of the midpoint are given by:

View File

@ -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);
}
}
}

View File

@ -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();
}
}

View File

@ -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 &current_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;
};
}
}

View File

@ -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);

View File

@ -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)

View File

@ -20,8 +20,8 @@ namespace
struct CoordinatePairCalculator
{
CoordinatePairCalculator() = delete;
CoordinatePairCalculator(const util::FixedPointCoordinate &coordinate_a,
const util::FixedPointCoordinate &coordinate_b)
CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a,
const util::FixedPointCoordinate coordinate_b)
{
// initialize distance calculator with two fixed coordinates a, b
first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD;
@ -30,7 +30,7 @@ struct CoordinatePairCalculator
second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD;
}
int operator()(util::FixedPointCoordinate &other) const
int operator()(const util::FixedPointCoordinate other) const
{
// set third coordinate c
const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD;

View File

@ -6,8 +6,6 @@
#include <boost/assert.hpp>
#include "osrm/coordinate.hpp"
#include <cmath>
#include <limits>
@ -44,15 +42,15 @@ double haversineDistance(const int lat1, const int lon1, const int lat2, const i
return EARTH_RADIUS * charv;
}
double haversineDistance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2)
double haversineDistance(const FixedPointCoordinate coordinate_1,
const FixedPointCoordinate coordinate_2)
{
return haversineDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_2.lon);
}
double greatCircleDistance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2)
double greatCircleDistance(const FixedPointCoordinate coordinate_1,
const FixedPointCoordinate coordinate_2)
{
return greatCircleDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_2.lon);
@ -75,9 +73,9 @@ double greatCircleDistance(const int lat1, const int lon1, const int lat2, const
return std::hypot(x_value, y_value) * EARTH_RADIUS;
}
double perpendicularDistance(const FixedPointCoordinate &source_coordinate,
const FixedPointCoordinate &target_coordinate,
const FixedPointCoordinate &query_location)
double perpendicularDistance(const FixedPointCoordinate source_coordinate,
const FixedPointCoordinate target_coordinate,
const FixedPointCoordinate query_location)
{
double ratio;
FixedPointCoordinate nearest_location;
@ -86,9 +84,9 @@ double perpendicularDistance(const FixedPointCoordinate &source_coordinate,
nearest_location, ratio);
}
double perpendicularDistance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
double perpendicularDistance(const FixedPointCoordinate segment_source,
const FixedPointCoordinate segment_target,
const FixedPointCoordinate query_location,
FixedPointCoordinate &nearest_location,
double &ratio)
{
@ -100,10 +98,10 @@ double perpendicularDistance(const FixedPointCoordinate &segment_source,
}
double
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &source_coordinate,
const FixedPointCoordinate &target_coordinate,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate)
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate source_coordinate,
const FixedPointCoordinate target_coordinate,
const FixedPointCoordinate query_location,
const std::pair<double, double> projected_coordinate)
{
double ratio;
FixedPointCoordinate nearest_location;
@ -114,10 +112,10 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &source_
}
double
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<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)
{
@ -196,8 +194,8 @@ double degToRad(const double degree) { return degree * (static_cast<double>(M_PI
double radToDeg(const double radian) { return radian * (180.0 * static_cast<double>(M_1_PI)); }
double bearing(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate)
double bearing(const FixedPointCoordinate first_coordinate,
const FixedPointCoordinate second_coordinate)
{
const double lon_diff =
second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION;
@ -220,9 +218,9 @@ double bearing(const FixedPointCoordinate &first_coordinate,
return result;
}
double computeAngle(const FixedPointCoordinate &first,
const FixedPointCoordinate &second,
const FixedPointCoordinate &third)
double computeAngle(const FixedPointCoordinate first,
const FixedPointCoordinate second,
const FixedPointCoordinate third)
{
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) -

View File

@ -1,13 +1,11 @@
#include "util/hilbert_value.hpp"
#include "osrm/coordinate.hpp"
namespace osrm
{
namespace util
{
uint64_t HilbertCode::operator()(const FixedPointCoordinate &current_coordinate) const
std::uint64_t HilbertCode::operator()(const FixedPointCoordinate current_coordinate) const
{
unsigned location[2];
location[0] = current_coordinate.lat + static_cast<int>(90 * COORDINATE_PRECISION);
@ -17,10 +15,11 @@ uint64_t HilbertCode::operator()(const FixedPointCoordinate &current_coordinate)
return BitInterleaving(location[0], location[1]);
}
uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t longitude) const
std::uint64_t HilbertCode::BitInterleaving(const std::uint32_t latitude,
const std::uint32_t longitude) const
{
uint64_t result = 0;
for (int8_t index = 31; index >= 0; --index)
std::uint64_t result = 0;
for (std::int8_t index = 31; index >= 0; --index)
{
result |= (latitude >> index) & 1;
result <<= 1;
@ -33,9 +32,9 @@ uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t lo
return result;
}
void HilbertCode::TransposeCoordinate(uint32_t *X) const
void HilbertCode::TransposeCoordinate(std::uint32_t *x) const
{
uint32_t M = 1u << (32 - 1), P, Q, t;
std::uint32_t M = 1u << (32 - 1), P, Q, t;
int i;
// Inverse undo
for (Q = M; Q > 1; Q >>= 1)
@ -44,28 +43,28 @@ void HilbertCode::TransposeCoordinate(uint32_t *X) const
for (i = 0; i < 2; ++i)
{
const bool condition = (X[i] & Q);
const bool condition = (x[i] & Q);
if (condition)
{
X[0] ^= P; // invert
x[0] ^= P; // invert
}
else
{
t = (X[0] ^ X[i]) & P;
X[0] ^= t;
X[i] ^= t;
t = (x[0] ^ x[i]) & P;
x[0] ^= t;
x[i] ^= t;
}
} // exchange
}
// Gray encode
for (i = 1; i < 2; ++i)
{
X[i] ^= X[i - 1];
x[i] ^= x[i - 1];
}
t = 0;
for (Q = M; Q > 1; Q >>= 1)
{
const bool condition = (X[2 - 1] & Q);
const bool condition = (x[2 - 1] & Q);
if (condition)
{
t ^= Q - 1;
@ -73,7 +72,7 @@ void HilbertCode::TransposeCoordinate(uint32_t *X) const
} // check if this for loop is wrong
for (i = 0; i < 2; ++i)
{
X[i] ^= t;
x[i] ^= t;
}
}
}