Bearing calculation on matching short segments fix.

This commit is contained in:
Lev Dragunov 2018-02-28 15:36:45 +03:00 committed by Patrick Niklaus
parent e34f2db4db
commit 7922a6172a
2 changed files with 10 additions and 5 deletions

View File

@ -25,7 +25,7 @@ std::pair<short, short> getDepartBearings(const LegGeometry &leg_geometry,
const auto turn_coordinate = leg_geometry.locations.front();
const auto post_turn_coordinate = *(leg_geometry.locations.begin() + 1);
if (turn_coordinate == post_turn_coordinate)
if (util::coordinate_calculation::haversineDistance(turn_coordinate, post_turn_coordinate) <= 1)
{
return std::make_pair<short, short>(0, source_node.GetBearing(traversed_in_reverse));
}
@ -41,7 +41,7 @@ std::pair<short, short> getArriveBearings(const LegGeometry &leg_geometry,
BOOST_ASSERT(leg_geometry.locations.size() >= 2);
const auto turn_coordinate = leg_geometry.locations.back();
const auto pre_turn_coordinate = *(leg_geometry.locations.end() - 2);
if (turn_coordinate == pre_turn_coordinate)
if (util::coordinate_calculation::haversineDistance(turn_coordinate, pre_turn_coordinate) <= 1)
{
return std::make_pair<short, short>(target_node.GetBearing(traversed_in_reverse), 0);
}

View File

@ -283,6 +283,7 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
geometry.osm_node_ids.begin() + offset);
}
auto const first_bearing = steps.front().maneuver.bearing_after;
// We have to adjust the first step both for its name and the bearings
if (zero_length_step)
{
@ -339,10 +340,14 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
});
auto &first_step = steps.front();
auto bearing = first_bearing;
// we changed the geometry, we need to recalculate the bearing
auto bearing = std::round(util::coordinate_calculation::bearing(
geometry.locations[first_step.geometry_begin],
geometry.locations[first_step.geometry_begin + 1]));
if (geometry.locations[first_step.geometry_begin] != geometry.locations[first_step.geometry_begin + 1])
{
bearing = std::round(util::coordinate_calculation::bearing(
geometry.locations[first_step.geometry_begin],
geometry.locations[first_step.geometry_begin + 1]));
}
first_step.maneuver.bearing_after = bearing;
first_step.intersections.front().bearings.front() = bearing;
}