Skip to content

Commit df3c39c

Browse files
author
Moritz Kobitzsch
committed
clean-up guidance code/code in general
removes duplicated includes removes unused includes eliminates dedicated toolkits that resulted in circular dependencies moves functionality close to data, where possible
1 parent a28a20a commit df3c39c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+607
-692
lines changed

include/engine/guidance/assemble_geometry.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "engine/datafacade/datafacade_base.hpp"
77
#include "engine/guidance/leg_geometry.hpp"
88
#include "engine/guidance/route_step.hpp"
9-
#include "engine/guidance/toolkit.hpp"
109
#include "engine/internal_route_result.hpp"
1110
#include "engine/phantom_node.hpp"
1211
#include "util/coordinate.hpp"

include/engine/guidance/assemble_steps.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
#include "engine/guidance/leg_geometry.hpp"
99
#include "engine/guidance/route_step.hpp"
1010
#include "engine/guidance/step_maneuver.hpp"
11-
#include "engine/guidance/toolkit.hpp"
1211
#include "engine/internal_route_result.hpp"
1312
#include "engine/phantom_node.hpp"
1413
#include "util/bearing.hpp"
1514
#include "util/coordinate.hpp"
1615
#include "util/coordinate_calculation.hpp"
1716
#include "util/guidance/entry_class.hpp"
18-
#include "util/guidance/toolkit.hpp"
1917
#include "util/guidance/turn_lanes.hpp"
2018
#include "util/typedefs.hpp"
2119

@@ -156,7 +154,7 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
156154
intersection.entry.push_back(entry_class.allowsEntry(idx));
157155
}
158156
std::int16_t bearing_in_driving_direction =
159-
util::bearing::reverseBearing(std::round(bearings.first));
157+
util::reverseBearing(std::round(bearings.first));
160158
maneuver = {intersection.location,
161159
bearing_in_driving_direction,
162160
bearings.second,
@@ -216,14 +214,13 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
216214
BOOST_ASSERT(segment_index == number_of_segments - 1);
217215
bearings = detail::getArriveBearings(leg_geometry);
218216

219-
intersection = {
220-
target_node.location,
221-
std::vector<short>({static_cast<short>(util::bearing::reverseBearing(bearings.first))}),
222-
std::vector<bool>({true}),
223-
0,
224-
Intersection::NO_INDEX,
225-
util::guidance::LaneTuple(),
226-
{}};
217+
intersection = {target_node.location,
218+
std::vector<short>({static_cast<short>(util::reverseBearing(bearings.first))}),
219+
std::vector<bool>({true}),
220+
0,
221+
Intersection::NO_INDEX,
222+
util::guidance::LaneTuple(),
223+
{}};
227224

228225
// This step has length zero, the only reason we need it is the target location
229226
maneuver = {intersection.location,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef OSRM_ENGINE_GUIDANCE_POSTPROCESSING_TOOLKIT_HPP_
2+
#define OSRM_ENGINE_GUIDANCE_POSTPROCESSING_TOOLKIT_HPP_
3+
4+
#include "extractor/guidance/turn_instruction.hpp"
5+
#include "engine/guidance/route_step.hpp"
6+
7+
#include <iterator>
8+
#include <utility>
9+
10+
namespace osrm
11+
{
12+
namespace engine
13+
{
14+
namespace guidance
15+
{
16+
17+
// Runs fn on RouteStep sub-ranges determined to be roundabouts.
18+
// The function fn is getting called with a roundabout range as in: [enter, .., leave].
19+
//
20+
// The following situations are taken care for (i.e. we discard them):
21+
// - partial roundabout: enter without exit or exit without enter
22+
// - data issues: no roundabout, exit before enter
23+
template <typename Iter, typename Fn> inline Fn forEachRoundabout(Iter first, Iter last, Fn fn)
24+
{
25+
while (first != last)
26+
{
27+
const auto enter = std::find_if(first, last, [](const RouteStep &step) {
28+
return entersRoundabout(step.maneuver.instruction);
29+
});
30+
31+
// enter has to come before leave, otherwise: faulty data / partial roundabout, skip those
32+
const auto leave = std::find_if(enter, last, [](const RouteStep &step) {
33+
return leavesRoundabout(step.maneuver.instruction);
34+
});
35+
36+
// No roundabouts, or partial one (like start / end inside a roundabout)
37+
if (enter == last || leave == last)
38+
break;
39+
40+
(void)fn(std::make_pair(enter, leave));
41+
42+
// Skip to first step after the currently handled enter / leave pair
43+
first = std::next(leave);
44+
}
45+
46+
return fn;
47+
}
48+
49+
} // namespace guidance
50+
} // namespace engine
51+
} // namespace osrm
52+
53+
#endif /* OSRM_ENGINE_GUIDANCE_POSTPROCESSING_TOOLKIT_HPP_ */

include/engine/guidance/route_step.hpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#include "util/guidance/turn_lanes.hpp"
1212

1313
#include <cstddef>
14-
1514
#include <string>
1615
#include <vector>
1716

17+
#include <boost/range/iterator_range.hpp>
18+
1819
namespace osrm
1920
{
2021
namespace engine
@@ -71,6 +72,33 @@ struct RouteStep
7172
std::size_t geometry_begin;
7273
std::size_t geometry_end;
7374
std::vector<Intersection> intersections;
75+
76+
LaneID numLanesToTheRight() const
77+
{
78+
return intersections.front().lanes.first_lane_from_the_right;
79+
}
80+
81+
LaneID numLanesToTheLeft() const
82+
{
83+
LaneID const total = intersections.front().lane_description.size();
84+
return total - (intersections.front().lanes.lanes_in_turn +
85+
intersections.front().lanes.first_lane_from_the_right);
86+
}
87+
88+
auto lanesToTheLeft() const
89+
{
90+
const auto &description = intersections.front().lane_description;
91+
LaneID num_lanes_left = numLanesToTheLeft();
92+
return boost::make_iterator_range(description.begin(),
93+
description.begin() + num_lanes_left);
94+
}
95+
96+
auto lanesToTheRight() const
97+
{
98+
const auto &description = intersections.front().lane_description;
99+
LaneID num_lanes_right = numLanesToTheRight();
100+
return boost::make_iterator_range(description.end() - num_lanes_right, description.end());
101+
}
74102
};
75103

76104
inline RouteStep getInvalidRouteStep()

include/engine/guidance/toolkit.hpp

Lines changed: 0 additions & 108 deletions
This file was deleted.

include/engine/trip/trip_farthest_insertion.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "util/dist_table_wrapper.hpp"
55
#include "util/typedefs.hpp"
6-
#include "util/typedefs.hpp"
76

87
#include "osrm/json_container.hpp"
98
#include <boost/assert.hpp>

include/extractor/edge_based_graph_factory.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <memory>
3030
#include <queue>
3131
#include <string>
32-
#include <string>
3332
#include <unordered_map>
3433
#include <unordered_set>
3534
#include <vector>

include/extractor/extraction_helper_functions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <limits>
1313
#include <string>
1414

15-
#include "extractor/guidance/toolkit.hpp"
15+
#include "extractor/guidance/parsing_toolkit.hpp"
1616

1717
namespace osrm
1818
{
@@ -109,13 +109,13 @@ inline unsigned parseDuration(const std::string &s)
109109
inline std::string
110110
trimLaneString(std::string lane_string, std::int32_t count_left, std::int32_t count_right)
111111
{
112-
return extractor::guidance::trimLaneString(std::move(lane_string), count_left, count_right);
112+
return guidance::trimLaneString(std::move(lane_string), count_left, count_right);
113113
}
114114

115115
inline std::string applyAccessTokens(const std::string &lane_string,
116116
const std::string &access_tokens)
117117
{
118-
return extractor::guidance::applyAccessTokens(lane_string, access_tokens);
118+
return guidance::applyAccessTokens(lane_string, access_tokens);
119119
}
120120

121121
// Takes a string representing a list separated by delim and canonicalizes containing spaces.

include/extractor/geojson_debug_policies.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "extractor/guidance/coordinate_extractor.hpp"
1313
#include "extractor/guidance/intersection.hpp"
14-
#include "extractor/guidance/toolkit.hpp"
14+
15+
#include <boost/optional.hpp>
1516

1617
namespace osrm
1718
{

include/extractor/guidance/coordinate_extractor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "util/attributes.hpp"
1111
#include "util/coordinate.hpp"
12-
#include "util/coordinate_calculation.hpp"
1312
#include "util/node_based_graph.hpp"
1413

1514
namespace osrm

0 commit comments

Comments
 (0)