Fix overflow on zero duration segments, fixes #4283.
As a form of smoothing we use the previous speed value instead. This makes sense because the zero duration segments have to be very short, potentially also zero length.
This commit is contained in:
parent
72a23645a8
commit
6eb4247484
@ -59,3 +59,27 @@ Feature: Annotations
|
|||||||
| from | to | route | a:datasources | a:speed |
|
| from | to | route | a:datasources | a:speed |
|
||||||
| a | i | abcdefghi,abcdefghi | 1:0:1:0:1:0:0:0 | 50:10:50:10:50:10:10:10 |
|
| a | i | abcdefghi,abcdefghi | 1:0:1:0:1:0:0:0 | 50:10:50:10:50:10:10:10 |
|
||||||
| i | a | abcdefghi,abcdefghi | 0:1:0:0:0:0:0:1 | 10:50:10:10:10:10:10:50 |
|
| i | a | abcdefghi,abcdefghi | 0:1:0:0:0:0:0:1 | 10:50:10:10:10:10:10:50 |
|
||||||
|
|
||||||
|
Scenario: Speed annotations should handle zero segments
|
||||||
|
Given the profile "testbot"
|
||||||
|
|
||||||
|
Given the node map
|
||||||
|
"""
|
||||||
|
a -- b --- c
|
||||||
|
|
|
||||||
|
d
|
||||||
|
"""
|
||||||
|
|
||||||
|
And the ways
|
||||||
|
| nodes |
|
||||||
|
| abc |
|
||||||
|
| cd |
|
||||||
|
|
||||||
|
# This test relies on the snapping to the EBN cd to introduce a zero segment after the turn
|
||||||
|
And the query options
|
||||||
|
| annotations | speed,distance,duration,nodes |
|
||||||
|
| bearings | 90,5;180,5 |
|
||||||
|
|
||||||
|
When I route I should get
|
||||||
|
| from | to | route | a:speed | a:distance | a:duration | a:nodes |
|
||||||
|
| a | c | abc,abc | 10:10:10 | 249.998641:299.931643:0 | 25:30:0 | 1:2:3 |
|
||||||
|
@ -88,11 +88,12 @@ class RouteAPI : public BaseAPI
|
|||||||
{
|
{
|
||||||
util::json::Array annotations_store;
|
util::json::Array annotations_store;
|
||||||
annotations_store.values.reserve(leg.annotations.size());
|
annotations_store.values.reserve(leg.annotations.size());
|
||||||
std::for_each(leg.annotations.begin(),
|
|
||||||
leg.annotations.end(),
|
for (const auto& step : leg.annotations)
|
||||||
[Get, &annotations_store](const auto &step) {
|
{
|
||||||
annotations_store.values.push_back(Get(step));
|
annotations_store.values.push_back(Get(step));
|
||||||
});
|
}
|
||||||
|
|
||||||
return annotations_store;
|
return annotations_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,10 +256,19 @@ class RouteAPI : public BaseAPI
|
|||||||
// AnnotationsType uses bit flags, & operator checks if a property is set
|
// AnnotationsType uses bit flags, & operator checks if a property is set
|
||||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
|
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
|
||||||
{
|
{
|
||||||
|
double prev_speed = 0;
|
||||||
annotation.values["speed"] = GetAnnotations(
|
annotation.values["speed"] = GetAnnotations(
|
||||||
leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
leg_geometry, [&prev_speed](const guidance::LegGeometry::Annotation &anno) {
|
||||||
auto val = std::round(anno.distance / anno.duration * 10.) / 10.;
|
if (anno.duration < std::numeric_limits<double>::min())
|
||||||
return util::json::clamp_float(val);
|
{
|
||||||
|
return prev_speed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
|
||||||
|
prev_speed = speed;
|
||||||
|
return util::json::clamp_float(speed);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,11 +303,10 @@ class RouteAPI : public BaseAPI
|
|||||||
{
|
{
|
||||||
util::json::Array nodes;
|
util::json::Array nodes;
|
||||||
nodes.values.reserve(leg_geometry.osm_node_ids.size());
|
nodes.values.reserve(leg_geometry.osm_node_ids.size());
|
||||||
std::for_each(leg_geometry.osm_node_ids.begin(),
|
for (const auto node_id : leg_geometry.osm_node_ids)
|
||||||
leg_geometry.osm_node_ids.end(),
|
{
|
||||||
[this, &nodes](const OSMNodeID &node_id) {
|
nodes.values.push_back(static_cast<std::uint64_t>(node_id));
|
||||||
nodes.values.push_back(static_cast<std::uint64_t>(node_id));
|
}
|
||||||
});
|
|
||||||
annotation.values["nodes"] = std::move(nodes);
|
annotation.values["nodes"] = std::move(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user