Make ComputeAngle a free standing function
This commit is contained in:
parent
f65dd63210
commit
f68247673a
@ -107,8 +107,8 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin
|
|||||||
|
|
||||||
if (input_coords.size() - 1 > current_coordinate && 0 < current_coordinate)
|
if (input_coords.size() - 1 > current_coordinate && 0 < current_coordinate)
|
||||||
{
|
{
|
||||||
double turn_angle = util::ComputeAngle::OfThreeFixedPointCoordinates(
|
double turn_angle = util::ComputeAngle(input_coords[current_coordinate - 1],
|
||||||
input_coords[current_coordinate - 1], input_coords[current_coordinate],
|
input_coords[current_coordinate],
|
||||||
input_coords[current_coordinate + 1]);
|
input_coords[current_coordinate + 1]);
|
||||||
|
|
||||||
// sharp turns indicate a possible uturn
|
// sharp turns indicate a possible uturn
|
||||||
|
@ -1,21 +1,36 @@
|
|||||||
#ifndef COMPUTE_ANGLE_HPP
|
#ifndef COMPUTE_ANGLE_HPP
|
||||||
#define COMPUTE_ANGLE_HPP
|
#define COMPUTE_ANGLE_HPP
|
||||||
|
|
||||||
|
#include "osrm/coordinate.hpp"
|
||||||
|
#include "util/trigonometry_table.hpp"
|
||||||
|
#include "util/mercator.hpp"
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
|
||||||
struct FixedPointCoordinate;
|
// Get angle of line segment (A,C)->(C,B)
|
||||||
|
inline double ComputeAngle(const FixedPointCoordinate first,
|
||||||
struct ComputeAngle
|
const FixedPointCoordinate second,
|
||||||
|
const FixedPointCoordinate third) noexcept
|
||||||
{
|
{
|
||||||
// Get angle of line segment (A,C)->(C,B)
|
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
|
||||||
// atan2 magic, formerly cosine theorem
|
const double v1y = mercator::lat2y(first.lat / COORDINATE_PRECISION) -
|
||||||
static double OfThreeFixedPointCoordinates(const FixedPointCoordinate &first,
|
mercator::lat2y(second.lat / COORDINATE_PRECISION);
|
||||||
const FixedPointCoordinate &second,
|
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION;
|
||||||
const FixedPointCoordinate &third) noexcept;
|
const double v2y = mercator::lat2y(third.lat / COORDINATE_PRECISION) -
|
||||||
};
|
mercator::lat2y(second.lat / COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
|
||||||
|
|
||||||
|
while (angle < 0.)
|
||||||
|
{
|
||||||
|
angle += 360.;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
|||||||
? m_compressed_edge_container.GetFirstEdgeTargetID(e2)
|
? m_compressed_edge_container.GetFirstEdgeTargetID(e2)
|
||||||
: node_w)];
|
: node_w)];
|
||||||
|
|
||||||
const double turn_angle = util::ComputeAngle::OfThreeFixedPointCoordinates(
|
const double turn_angle = util::ComputeAngle(
|
||||||
first_coordinate, m_node_info_list[node_v], third_coordinate);
|
first_coordinate, m_node_info_list[node_v], third_coordinate);
|
||||||
|
|
||||||
const int turn_penalty = GetTurnPenalty(turn_angle, lua_state);
|
const int turn_penalty = GetTurnPenalty(turn_angle, lua_state);
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
#include "util/compute_angle.hpp"
|
|
||||||
|
|
||||||
#include "util/trigonometry_table.hpp"
|
|
||||||
#include "util/mercator.hpp"
|
|
||||||
|
|
||||||
#include "osrm/coordinate.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace osrm
|
|
||||||
{
|
|
||||||
namespace util
|
|
||||||
{
|
|
||||||
|
|
||||||
double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &first,
|
|
||||||
const FixedPointCoordinate &second,
|
|
||||||
const FixedPointCoordinate &third) noexcept
|
|
||||||
{
|
|
||||||
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
|
|
||||||
const double v1y = mercator::lat2y(first.lat / COORDINATE_PRECISION) -
|
|
||||||
mercator::lat2y(second.lat / COORDINATE_PRECISION);
|
|
||||||
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION;
|
|
||||||
const double v2y = mercator::lat2y(third.lat / COORDINATE_PRECISION) -
|
|
||||||
mercator::lat2y(second.lat / COORDINATE_PRECISION);
|
|
||||||
|
|
||||||
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
|
|
||||||
while (angle < 0.)
|
|
||||||
{
|
|
||||||
angle += 360.;
|
|
||||||
}
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user