Skip to content

Commit

Permalink
Make ComputeAngle a free standing function
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Jan 8, 2016
1 parent f6af73a commit 0144446
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
6 changes: 3 additions & 3 deletions include/engine/plugins/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin

if (input_coords.size() - 1 > current_coordinate && 0 < current_coordinate)
{
double turn_angle = util::ComputeAngle::OfThreeFixedPointCoordinates(
input_coords[current_coordinate - 1], input_coords[current_coordinate],
input_coords[current_coordinate + 1]);
double turn_angle = util::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)
Expand Down
33 changes: 24 additions & 9 deletions include/util/compute_angle.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
#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
{

struct FixedPointCoordinate;

struct ComputeAngle
// Get angle of line segment (A,C)->(C,B)
inline double ComputeAngle(const FixedPointCoordinate first,
const FixedPointCoordinate second,
const FixedPointCoordinate third) noexcept
{
// Get angle of line segment (A,C)->(C,B)
// atan2 magic, formerly cosine theorem
static double 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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
? m_compressed_edge_container.GetFirstEdgeTargetID(e2)
: 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);

const int turn_penalty = GetTurnPenalty(turn_angle, lua_state);
Expand Down
34 changes: 0 additions & 34 deletions src/util/compute_angle.cpp

This file was deleted.

0 comments on commit 0144446

Please sign in to comment.