osrm-backend/include/engine/guidance/assemble_leg.hpp

81 lines
2.7 KiB
C++
Raw Normal View History

2016-01-28 10:28:44 -05:00
#ifndef ENGINE_GUIDANCE_ASSEMBLE_LEG_HPP_
#define ENGINE_GUIDANCE_ASSEMBLE_LEG_HPP_
2016-04-06 03:47:17 -04:00
#include "engine/guidance/leg_geometry.hpp"
2016-01-28 10:28:44 -05:00
#include "engine/guidance/route_leg.hpp"
#include "engine/guidance/route_step.hpp"
#include "engine/internal_route_result.hpp"
#include <cstddef>
#include <cstdint>
2016-04-06 03:47:17 -04:00
#include <algorithm>
2016-01-28 10:28:44 -05:00
#include <array>
2016-04-06 03:47:17 -04:00
#include <numeric>
#include <string>
#include <utility>
2016-04-06 03:47:17 -04:00
#include <vector>
2016-01-28 10:28:44 -05:00
namespace osrm
{
namespace engine
{
namespace guidance
{
2016-04-06 03:47:17 -04:00
inline RouteLeg assembleLeg(const std::vector<PathData> &route_data,
const LegGeometry &leg_geometry,
const PhantomNode &source_node,
const PhantomNode &target_node,
const bool target_traversed_in_reverse)
2016-01-28 10:28:44 -05:00
{
const auto target_duration =
2016-04-01 12:15:11 -04:00
(target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight) /
2016-01-28 10:28:44 -05:00
10.;
auto distance = std::accumulate(leg_geometry.segment_distances.begin(),
leg_geometry.segment_distances.end(), 0.);
auto duration = std::accumulate(route_data.begin(), route_data.end(), 0.,
2016-04-06 03:47:17 -04:00
[](const double sum, const PathData &data) {
2016-01-28 10:28:44 -05:00
return sum + data.duration_until_turn;
}) /
10.;
// s
// |
2016-03-30 07:14:48 -04:00
// Given a route a---b---c where there is a right turn at c.
2016-01-28 10:28:44 -05:00
// |
// d
// |--t
// e
// (a, b, c) gets compressed to (a,c)
// (c, d, e) gets compressed to (c,e)
// The duration of the turn (a,c) -> (c,e) will be the duration of (a,c) (e.g. the duration
// of (a,b,c)).
// The phantom node of s will contain:
// `forward_weight`: duration of (a,s)
// `forward_offset`: 0 (its the first segment)
// The phantom node of t will contain:
// `forward_weight`: duration of (d,t)
// `forward_offset`: duration of (c, d)
2016-03-18 11:14:48 -04:00
// path_data will have entries for (s,b), (b, c), (c, d) but (d, t) is only
// caputed by the phantom node. So we need to add the target duration here.
2016-04-01 12:15:11 -04:00
// On local segments, the target duration is already part of the duration, however.
2016-03-18 11:14:48 -04:00
duration = duration + target_duration;
2016-04-01 12:15:11 -04:00
if (route_data.empty())
{
2016-04-05 04:53:21 -04:00
duration -= (target_traversed_in_reverse ? source_node.reverse_weight
: source_node.forward_weight) /
2016-04-06 10:47:16 -04:00
10.0;
2016-04-01 12:15:11 -04:00
}
2016-01-28 10:28:44 -05:00
2016-04-05 04:53:21 -04:00
return RouteLeg{duration, distance, {}};
2016-01-28 10:28:44 -05:00
}
} // namespace guidance
} // namespace engine
} // namespace osrm
#endif // ENGINE_GUIDANCE_SEGMENT_LIST_HPP_