Skip to content

Commit 12238eb

Browse files
karenzsheaMoritz Kobitzsch
authored andcommitted
handle empty names in summaries
1 parent b033ac9 commit 12238eb

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

features/support/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module.exports = function () {
132132

133133
this.summary = (instructions) => {
134134
if (instructions) {
135-
return instructions.legs.map(l => l.summary).join(',');
135+
return instructions.legs.map(l => l.summary).join(';');
136136
}
137137
};
138138

features/testbot/summaries.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@routing @basic @testbot
2+
Feature: Basic Routing
3+
4+
Background:
5+
Given the profile "testbot"
6+
Given a grid size of 500 meters
7+
8+
@smallest
9+
Scenario: Summaries when routing on a simple network
10+
Given the node map
11+
| b | | | f |
12+
| | | | |
13+
| c | d | | g |
14+
| | | | |
15+
| a | | e | |
16+
17+
And the ways
18+
| nodes | name |
19+
| acb | road |
20+
| de | 1 st |
21+
| cd | |
22+
| dg | blvd |
23+
| df | street |
24+
25+
When I route I should get
26+
| waypoints | route | summary |
27+
| a,e | road,,1 st,1 st | road, 1 st |
28+
| a,d,f | road,,,street,street | road;street |
29+
| a,e,f | road,,1 st,1 st,1 st,street,street | road, 1 st;1 st, street |

include/engine/guidance/assemble_leg.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "engine/guidance/route_leg.hpp"
77
#include "engine/guidance/route_step.hpp"
88
#include "engine/internal_route_result.hpp"
9+
#include <boost/algorithm/string/join.hpp>
910

1011
#include <cstddef>
1112
#include <cstdint>
@@ -177,16 +178,16 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
177178

178179
BOOST_ASSERT(detail::MAX_USED_SEGMENTS > 0);
179180
BOOST_ASSERT(summary_array.begin() != summary_array.end());
180-
summary = std::accumulate(std::next(summary_array.begin()),
181-
summary_array.end(),
182-
facade.GetNameForID(summary_array.front()),
183-
[&facade](std::string previous, const std::uint32_t name_id) {
184-
if (name_id != 0)
185-
{
186-
previous += ", " + facade.GetNameForID(name_id);
187-
}
188-
return previous;
189-
});
181+
std::vector<std::string> summary_names;
182+
for (auto nameIt = summary_array.begin(), end = summary_array.end(); nameIt != end; ++nameIt)
183+
{
184+
auto name = facade.GetNameForID(* nameIt);
185+
name = name.empty() ? facade.GetRefForID(* nameIt) : name;
186+
if (!name.empty())
187+
summary_names.push_back(name);
188+
}
189+
BOOST_ASSERT(summary_names.size() =< MAX_USED_SEGMENTS);
190+
summary = boost::algorithm::join(summary_names, ", ");
190191
}
191192

192193
return RouteLeg{duration, distance, summary, {}};

0 commit comments

Comments
 (0)