diff --git a/include/engine/plugins/match.hpp b/include/engine/plugins/match.hpp index 713245376..0de44148a 100644 --- a/include/engine/plugins/match.hpp +++ b/include/engine/plugins/match.hpp @@ -10,7 +10,7 @@ #include "engine/guidance/segment_list.hpp" #include "engine/api_response_generator.hpp" #include "engine/routing_algorithms/map_matching.hpp" -#include "util/compute_angle.hpp" +#include "util/coordinate_calculation.hpp" #include "util/integer_range.hpp" #include "util/json_logger.hpp" #include "util/json_util.hpp" @@ -108,9 +108,9 @@ template class MapMatchingPlugin : public BasePlugin if (input_coords.size() - 1 > current_coordinate && 0 < current_coordinate) { - double turn_angle = util::ComputeAngle(input_coords[current_coordinate - 1], - input_coords[current_coordinate], - input_coords[current_coordinate + 1]); + double turn_angle = util::coordinate_calculation::computeAngle( + input_coords[current_coordinate - 1], input_coords[current_coordinate], + input_coords[current_coordinate + 1]); // sharp turns indicate a possible uturn if (turn_angle <= 90.0 || turn_angle >= 270.0) diff --git a/include/util/compute_angle.hpp b/include/util/compute_angle.hpp deleted file mode 100644 index b34f7bed9..000000000 --- a/include/util/compute_angle.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef COMPUTE_ANGLE_HPP -#define COMPUTE_ANGLE_HPP - -#include "osrm/coordinate.hpp" -#include "util/trigonometry_table.hpp" -#include "util/mercator.hpp" - -namespace osrm -{ -namespace util -{ - -// Get angle of line segment (A,C)->(C,B) -inline double ComputeAngle(const FixedPointCoordinate first, - const FixedPointCoordinate second, - const FixedPointCoordinate third) noexcept -{ - 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); - - double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI; - - while (angle < 0.) - { - angle += 360.; - } - - return angle; -} -} -} - -#endif // COMPUTE_ANGLE_HPP diff --git a/include/util/coordinate_calculation.hpp b/include/util/coordinate_calculation.hpp index 7e15b8ba0..decef8d64 100644 --- a/include/util/coordinate_calculation.hpp +++ b/include/util/coordinate_calculation.hpp @@ -57,6 +57,11 @@ double radToDeg(const double radian); 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); } } } diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index a6585b0f9..cc615c905 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -2,7 +2,6 @@ #include "extractor/edge_based_graph_factory.hpp" #include "util/coordinate_calculation.hpp" #include "util/percent.hpp" -#include "util/compute_angle.hpp" #include "util/integer_range.hpp" #include "util/lua_util.hpp" #include "util/simple_logger.hpp" @@ -336,7 +335,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() } BOOST_ASSERT(m_edge_based_node_list.size() == m_edge_based_node_is_startpoint.size()); - BOOST_ASSERT(m_max_edge_id+1 == m_edge_based_node_weights.size()); + BOOST_ASSERT(m_max_edge_id + 1 == m_edge_based_node_weights.size()); util::SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " nodes in edge-expanded graph"; @@ -498,7 +497,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( ? m_compressed_edge_container.GetFirstEdgeTargetID(e2) : node_w)]; - const double turn_angle = util::ComputeAngle( + const double turn_angle = util::coordinate_calculation::computeAngle( first_coordinate, m_node_info_list[node_v], third_coordinate); const int turn_penalty = GetTurnPenalty(turn_angle, lua_state); diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 4f1386310..f2d99ed4f 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -2,6 +2,7 @@ #include "util/mercator.hpp" #include "util/string_util.hpp" +#include "util/trigonometry_table.hpp" #include @@ -218,6 +219,27 @@ double bearing(const FixedPointCoordinate &first_coordinate, } return result; } + +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) - + 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); + + double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI; + + while (angle < 0.) + { + angle += 360.; + } + + return angle; +} } } }