diff --git a/features/guidance/turn-angles.feature b/features/guidance/turn-angles.feature index d2fd342f2..0934472d0 100644 --- a/features/guidance/turn-angles.feature +++ b/features/guidance/turn-angles.feature @@ -1149,3 +1149,22 @@ Feature: Simple Turns When I route I should get | waypoints | route | turns | | a,m | gato,hain,hain | depart,turn left,arrive | + + Scenario: Segfaulting Regression + Given the node map + """ + a - - - - - - - - - - - - - - b c + | + | + | + d--------------e + """ + + And the ways + | nodes | lanes:forward | + | ab | | + | bcde | 6 | + + When I route I should get + | waypoints | route | + | a,e | ab,bcde,bcde | diff --git a/src/extractor/guidance/coordinate_extractor.cpp b/src/extractor/guidance/coordinate_extractor.cpp index 98869da52..34bdbcb93 100644 --- a/src/extractor/guidance/coordinate_extractor.cpp +++ b/src/extractor/guidance/coordinate_extractor.cpp @@ -273,9 +273,10 @@ CoordinateExtractor::GetCoordinateAlongRoad(const NodeID intersection_node, { // skip over the first coordinates, in specific the assumed lane count. We add a small // safety factor, to not overshoot on the regression - const auto trimmed_coordinates = TrimCoordinatesByLengthFront( - coordinates, 0.8 * (considered_lanes * ASSUMED_LANE_WIDTH)); - if (trimmed_coordinates.size() >= 2) + const auto trimming_length = 0.8 * (considered_lanes * ASSUMED_LANE_WIDTH); + const auto trimmed_coordinates = + TrimCoordinatesByLengthFront(coordinates, 0.8 * trimming_length); + if (trimmed_coordinates.size() >= 2 && (total_distance >= trimming_length + 2)) { // get the regression line const auto regression_line_trimmed = RegressionLine(trimmed_coordinates); @@ -803,6 +804,10 @@ CoordinateExtractor::RegressionLine(const std::vector &coordin // (less dependent on modelling of the data in OSM) const auto sampled_coordinates = SampleCoordinates(coordinates, FAR_LOOKAHEAD_DISTANCE, 1); + BOOST_ASSERT(!coordinates.empty()); + if (sampled_coordinates.size() < 2) // less than 1 meter in length + return {coordinates.front(), coordinates.back()}; + // compute the regression vector based on the sum of least squares const auto regression_line = leastSquareRegression(sampled_coordinates); const auto coord_between_front =