Skip to content

Commit 16fecc1

Browse files
Correctly set has_highway, has_ferry and has_toll attributes when directions_type is set to none (valhalla#4706)
1 parent 9888d8e commit 16fecc1

File tree

8 files changed

+117
-18
lines changed

8 files changed

+117
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* FIXED: Fix segfault in OSRM serializer with bannerInstructions when destination is on roundabout [#4480](https://github.com/valhalla/valhalla/pull/4481)
5050
* FIXED: Fix segfault in costmatrix (date_time and time zone always added). [#4530](https://github.com/valhalla/valhalla/pull/4530)
5151
* FIXED: Fixed roundoff issue in Tiles Row and Col methods [#4585](https://github.com/valhalla/valhalla/pull/4585)
52+
* FIXED: Fix for assigning attributes has_(highway, ferry, toll) if directions_type is none [#4465](https://github.com/valhalla/valhalla/issues/4465)
5253
* **Enhancement**
5354
* UPDATED: French translations, thanks to @xlqian [#4159](https://github.com/valhalla/valhalla/pull/4159)
5455
* CHANGED: -j flag for multithreaded executables to override mjolnir.concurrency [#4168](https://github.com/valhalla/valhalla/pull/4168)

proto/common.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,13 @@ enum TransitType {
391391
kGondola = 6;
392392
kFunicular = 7;
393393
}
394+
395+
message Summary {
396+
float length = 1; // kilometers or miles based on units
397+
double time = 2; // seconds
398+
BoundingBox bbox = 3; // Bounding box of the shape
399+
bool has_time_restrictions = 4; // Does the route contain any time restrictions?
400+
bool has_toll = 5;
401+
bool has_ferry = 6;
402+
bool has_highway = 7;
403+
}

proto/directions.proto

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import public "sign.proto";
66

77
message DirectionsLeg {
88

9-
message Summary {
10-
float length = 1; // kilometers or miles based on units
11-
double time = 2; // seconds
12-
BoundingBox bbox = 3; // Bounding box of the shape
13-
bool has_time_restrictions = 4; // Does the route contain any time restrictions?
14-
bool has_toll = 5;
15-
bool has_ferry = 6;
16-
bool has_highway = 7;
17-
}
189

1910
message GuidanceView {
2011
enum Type{

proto/trip.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ message TripLeg {
286286
repeated Incident incidents = 11;
287287
repeated string algorithms = 12;
288288
repeated Closure closures = 13;
289+
Summary summary = 14;
289290
}
290291

291292
message TripRoute {

src/odin/directionsbuilder.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ void DirectionsBuilder::PopulateDirectionsLeg(const Options& options,
9595
EnhancedTripLeg* etp,
9696
std::list<Maneuver>& maneuvers,
9797
DirectionsLeg& trip_directions) {
98-
bool has_toll = false;
99-
bool has_highway = false;
100-
bool has_ferry = false;
10198
// Populate trip and leg IDs
10299
trip_directions.set_trip_id(etp->trip_id());
103100
trip_directions.set_leg_id(etp->leg_id());
@@ -147,15 +144,12 @@ void DirectionsBuilder::PopulateDirectionsLeg(const Options& options,
147144
trip_maneuver->set_end_shape_index(maneuver.end_shape_index());
148145
if (maneuver.portions_toll()) {
149146
trip_maneuver->set_portions_toll(maneuver.portions_toll());
150-
has_toll = true;
151147
}
152148
if (maneuver.portions_highway()) {
153149
trip_maneuver->set_portions_highway(maneuver.portions_highway());
154-
has_highway = true;
155150
}
156151
if (maneuver.ferry()) {
157152
trip_maneuver->set_portions_ferry(maneuver.ferry());
158-
has_ferry = true;
159153
}
160154

161155
trip_maneuver->set_has_time_restrictions(maneuver.has_time_restrictions());
@@ -439,9 +433,9 @@ void DirectionsBuilder::PopulateDirectionsLeg(const Options& options,
439433
trip_directions.mutable_summary()->set_has_time_restrictions(has_time_restrictions);
440434

441435
// Populate toll, highway, ferry tags
442-
trip_directions.mutable_summary()->set_has_toll(has_toll);
443-
trip_directions.mutable_summary()->set_has_highway(has_highway);
444-
trip_directions.mutable_summary()->set_has_ferry(has_ferry);
436+
trip_directions.mutable_summary()->set_has_toll(etp->summary().has_toll());
437+
trip_directions.mutable_summary()->set_has_highway(etp->summary().has_highway());
438+
trip_directions.mutable_summary()->set_has_ferry(etp->summary().has_ferry());
445439
}
446440

447441
} // namespace odin

src/thor/triplegbuilder.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,9 @@ void TripLegBuilder::Build(
17541754
// from the edge index that we assigned to them earlier in route_action
17551755
auto intermediate_itr = trip_path.mutable_location()->begin() + 1;
17561756
double total_distance = 0;
1757+
bool has_toll = false;
1758+
bool has_ferry = false;
1759+
bool has_highway = false;
17571760

17581761
// loop over the edges to build the trip leg
17591762
for (auto edge_itr = path_begin; edge_itr != path_end; ++edge_itr, ++edge_index) {
@@ -1767,6 +1770,16 @@ void TripLegBuilder::Build(
17671770
const uint8_t travel_type = travel_types[static_cast<uint32_t>(mode)];
17681771
const auto& costing = mode_costing[static_cast<uint32_t>(mode)];
17691772

1773+
if (directededge->toll()) {
1774+
has_toll = true;
1775+
}
1776+
if (directededge->use() == Use::kFerry) {
1777+
has_ferry = true;
1778+
}
1779+
if (directededge->classification() == baldr::RoadClass::kMotorway) {
1780+
has_highway = true;
1781+
}
1782+
17701783
// Set node attributes - only set if they are true since they are optional
17711784
graph_tile_ptr start_tile = graphtile;
17721785
graphreader.GetGraphTile(startnode, start_tile);
@@ -2077,6 +2090,11 @@ void TripLegBuilder::Build(
20772090
trip_path.set_osm_changeset(osmchangeset);
20782091
}
20792092

2093+
Summary* summary = trip_path.mutable_summary();
2094+
summary->set_has_toll(has_toll);
2095+
summary->set_has_ferry(has_ferry);
2096+
summary->set_has_highway(has_highway);
2097+
20802098
// Add that extra costing information if requested
20812099
AccumulateRecostingInfoForward(options, start_pct, end_pct, forward_time_info, invariant,
20822100
graphreader, trip_path);

test/gurka/test_route_summary.cc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,83 @@ TEST(TestRouteSummary, DupSummaryFix) {
205205

206206
std::filesystem::remove_all(workdir);
207207
}
208+
209+
TEST(Standalone, TripLegSummary) {
210+
const std::string ascii_map = R"(
211+
A---B---C---D
212+
)";
213+
214+
const gurka::ways ways = {{"AB", {{"highway", "motorway"}}},
215+
{"BC", {{"highway", "motorway"}, {"toll", "yes"}}},
216+
{"CD", {{"route", "ferry"}}}};
217+
const double gridsize = 100;
218+
const auto layout = gurka::detail::map_to_coordinates(ascii_map, gridsize);
219+
const std::string workdir = "test/data/gurka_test_route_summary";
220+
221+
std::string result_json;
222+
rapidjson::Document result;
223+
224+
valhalla::gurka::map map = gurka::buildtiles(layout, ways, {}, {}, workdir);
225+
226+
valhalla::Api result0 = gurka::do_action(valhalla::Options::route, map, {"A", "B"}, "auto",
227+
{{"/directions_type", "none"}}, {}, &result_json);
228+
EXPECT_TRUE(result0.trip().routes(0).legs(0).summary().has_highway());
229+
EXPECT_FALSE(result0.trip().routes(0).legs(0).summary().has_toll());
230+
EXPECT_FALSE(result0.trip().routes(0).legs(0).summary().has_ferry());
231+
232+
result.Parse(result_json.c_str());
233+
auto trip = result["trip"].GetObject();
234+
auto summary = trip["summary"].GetObject();
235+
236+
EXPECT_TRUE(summary["has_highway"].GetBool());
237+
EXPECT_FALSE(summary["has_toll"].GetBool());
238+
EXPECT_FALSE(summary["has_ferry"].GetBool());
239+
result_json.erase();
240+
241+
valhalla::Api result1 = gurka::do_action(valhalla::Options::route, map, {"B", "C"}, "auto",
242+
{{"/directions_type", "none"}});
243+
EXPECT_TRUE(result1.trip().routes(0).legs(0).summary().has_highway());
244+
EXPECT_TRUE(result1.trip().routes(0).legs(0).summary().has_toll());
245+
EXPECT_FALSE(result1.trip().routes(0).legs(0).summary().has_ferry());
246+
247+
valhalla::Api result2 = gurka::do_action(valhalla::Options::route, map, {"C", "D"}, "auto",
248+
{{"/directions_type", "none"}});
249+
EXPECT_FALSE(result2.trip().routes(0).legs(0).summary().has_highway());
250+
EXPECT_FALSE(result2.trip().routes(0).legs(0).summary().has_toll());
251+
EXPECT_TRUE(result2.trip().routes(0).legs(0).summary().has_ferry());
252+
253+
// Validate that the presence of highway, toll, and ferry tags in route summaries is consistent
254+
// and does not depend on the `directions_type` value
255+
256+
valhalla::Api result3 = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, "auto",
257+
{{"/directions_type", "none"}}, {}, &result_json);
258+
259+
EXPECT_TRUE(result3.trip().routes(0).legs(0).summary().has_highway());
260+
EXPECT_TRUE(result3.trip().routes(0).legs(0).summary().has_toll());
261+
EXPECT_TRUE(result3.trip().routes(0).legs(0).summary().has_ferry());
262+
263+
result.Parse(result_json.c_str());
264+
trip = result["trip"].GetObject();
265+
summary = trip["summary"].GetObject();
266+
267+
EXPECT_TRUE(summary["has_highway"].GetBool());
268+
EXPECT_TRUE(summary["has_toll"].GetBool());
269+
EXPECT_TRUE(summary["has_ferry"].GetBool());
270+
result_json.erase();
271+
272+
valhalla::Api result4 = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, "auto",
273+
{{"/directions_type", "maneuvers"}}, {}, &result_json);
274+
EXPECT_TRUE(result4.trip().routes(0).legs(0).summary().has_highway());
275+
EXPECT_TRUE(result4.trip().routes(0).legs(0).summary().has_toll());
276+
EXPECT_TRUE(result4.trip().routes(0).legs(0).summary().has_ferry());
277+
278+
result.Parse(result_json.c_str());
279+
trip = result["trip"].GetObject();
280+
summary = trip["summary"].GetObject();
281+
282+
EXPECT_TRUE(summary["has_highway"].GetBool());
283+
EXPECT_TRUE(summary["has_toll"].GetBool());
284+
EXPECT_TRUE(summary["has_ferry"].GetBool());
285+
286+
std::filesystem::remove_all(workdir);
287+
}

valhalla/odin/enhancedtrippath.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class EnhancedTripLeg {
8888
return trip_path_.bbox();
8989
}
9090

91+
const ::valhalla::Summary& summary() const {
92+
return trip_path_.summary();
93+
}
94+
9195
std::unique_ptr<EnhancedTripLeg_Node> GetEnhancedNode(const int node_index);
9296

9397
std::unique_ptr<EnhancedTripLeg_Edge> GetPrevEdge(const int node_index, int delta = 1);

0 commit comments

Comments
 (0)