Improve performance of map matching via getPathDistance optimization
This commit is contained in:
parent
dec039bd53
commit
1877e52a5c
@ -353,49 +353,21 @@ double getPathDistance(const DataFacade<Algorithm> &facade,
|
|||||||
const PhantomNode &source_phantom,
|
const PhantomNode &source_phantom,
|
||||||
const PhantomNode &target_phantom)
|
const PhantomNode &target_phantom)
|
||||||
{
|
{
|
||||||
using util::coordinate_calculation::detail::DEGREE_TO_RAD;
|
double distance = 0.0;
|
||||||
using util::coordinate_calculation::detail::EARTH_RADIUS;
|
auto prev_coordinate = source_phantom.location;
|
||||||
|
|
||||||
double distance = 0;
|
|
||||||
double prev_lat =
|
|
||||||
static_cast<double>(util::toFloating(source_phantom.location.lat)) * DEGREE_TO_RAD;
|
|
||||||
double prev_lon =
|
|
||||||
static_cast<double>(util::toFloating(source_phantom.location.lon)) * DEGREE_TO_RAD;
|
|
||||||
double prev_cos = std::cos(prev_lat);
|
|
||||||
for (const auto &p : unpacked_path)
|
for (const auto &p : unpacked_path)
|
||||||
{
|
{
|
||||||
const auto current_coordinate = facade.GetCoordinateOfNode(p.turn_via_node);
|
const auto current_coordinate = facade.GetCoordinateOfNode(p.turn_via_node);
|
||||||
|
|
||||||
const double current_lat =
|
distance +=
|
||||||
static_cast<double>(util::toFloating(current_coordinate.lat)) * DEGREE_TO_RAD;
|
util::coordinate_calculation::greatCircleDistance(prev_coordinate, current_coordinate);
|
||||||
const double current_lon =
|
|
||||||
static_cast<double>(util::toFloating(current_coordinate.lon)) * DEGREE_TO_RAD;
|
|
||||||
const double current_cos = std::cos(current_lat);
|
|
||||||
|
|
||||||
const double sin_dlon = std::sin((prev_lon - current_lon) / 2.0);
|
prev_coordinate = current_coordinate;
|
||||||
const double sin_dlat = std::sin((prev_lat - current_lat) / 2.0);
|
|
||||||
|
|
||||||
const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
|
|
||||||
const double charv = 2. * std::atan2(std::sqrt(aharv), std::sqrt(1.0 - aharv));
|
|
||||||
distance += EARTH_RADIUS * charv;
|
|
||||||
|
|
||||||
prev_lat = current_lat;
|
|
||||||
prev_lon = current_lon;
|
|
||||||
prev_cos = current_cos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const double current_lat =
|
distance +=
|
||||||
static_cast<double>(util::toFloating(target_phantom.location.lat)) * DEGREE_TO_RAD;
|
util::coordinate_calculation::greatCircleDistance(prev_coordinate, target_phantom.location);
|
||||||
const double current_lon =
|
|
||||||
static_cast<double>(util::toFloating(target_phantom.location.lon)) * DEGREE_TO_RAD;
|
|
||||||
const double current_cos = std::cos(current_lat);
|
|
||||||
|
|
||||||
const double sin_dlon = std::sin((prev_lon - current_lon) / 2.0);
|
|
||||||
const double sin_dlat = std::sin((prev_lat - current_lat) / 2.0);
|
|
||||||
|
|
||||||
const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
|
|
||||||
const double charv = 2. * std::atan2(std::sqrt(aharv), std::sqrt(1.0 - aharv));
|
|
||||||
distance += EARTH_RADIUS * charv;
|
|
||||||
|
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user