diff --git a/docs/http.md b/docs/http.md index 3c12f9fcc..230913644 100644 --- a/docs/http.md +++ b/docs/http.md @@ -235,10 +235,10 @@ In addition to the [general options](#general-options) the following options are |------------|--------------------------------------------------|---------------------------------------------| |sources |`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as source. | |destinations|`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as destination.| -|annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned. | -|fallback_speed|`double > 0`|If no route found between a source/destination pair, calculate the as-the-crow-flies distance, then use this speed to estimate duration.| +|annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. | +|fallback_speed|`double > 0`| If no route found between a source/destination pair, calculate the as-the-crow-flies distance, then use this speed to estimate duration.| |fallback_coordinate|`input` (default), or `snapped`| When using a `fallback_speed`, use the user-supplied coordinate (`input`), or the snapped location (`snapped`) for calculating distances.| -|scale_factor|`double > 0`| Multiply the table `duration` values by this number. Default is 1.0.| +|scale_factor|`double`| Multiplies the table `duration` values by this number.| Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal** to number of input locations; diff --git a/features/testbot/duration_matrix.feature b/features/testbot/duration_matrix.feature index 929fc9037..8d5f47123 100644 --- a/features/testbot/duration_matrix.feature +++ b/features/testbot/duration_matrix.feature @@ -624,4 +624,22 @@ Feature: Basic Duration Matrix When I request a travel time matrix I should get | | a | b | | a | 0 | 20 | - | b | 20 | 0 | \ No newline at end of file + | b | 20 | 0 | + + Scenario: Testbot - Travel time matrix of minimal network with overflow factor + Given the query options + | scale_factor | 2147483647 | + + Given the node map + """ + a b + """ + + And the ways + | nodes | + | ab | + + When I request a travel time matrix I should get + | | a | b | + | a | 0 | 20 | + | b | 20 | 0 | diff --git a/include/engine/api/table_parameters.hpp b/include/engine/api/table_parameters.hpp index 1b4e924a1..c6afa0875 100644 --- a/include/engine/api/table_parameters.hpp +++ b/include/engine/api/table_parameters.hpp @@ -140,9 +140,6 @@ struct TableParameters : public BaseParameters if (fallback_speed < 0) return false; - if (scale_factor < 1) - return false; - return true; } }; diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 11179fc99..ab0b143a6 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -1238,11 +1238,6 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo &args, Nan::ThrowError("scale_factor must be a number"); return table_parameters_ptr(); } - else if (scale_factor->NumberValue() < 1) - { - Nan::ThrowError("scale_factor must be > 1"); - return table_parameters_ptr(); - } params->scale_factor = static_cast(scale_factor->NumberValue()); } diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 2e5e9f095..6babf1e53 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -96,7 +96,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, } // Scan table for null results - if any exist, replace with distance estimates - if (params.fallback_speed > 0 || params.scale_factor > 1.0) + if (params.fallback_speed > 0 || params.scale_factor != 1.0) { for (std::size_t row = 0; row < num_sources; row++) { @@ -128,11 +128,15 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, result_tables_pair.second[table_index] = distance_estimate; } } - if (params.scale_factor > 1.0 && + if (params.scale_factor != 1.0 && result_tables_pair.first[table_index] != MAXIMAL_EDGE_DURATION) { - result_tables_pair.first[table_index] = std::lround( - result_tables_pair.first[table_index] * (double)params.scale_factor); + double result = std::lround(result_tables_pair.first[table_index] * params.scale_factor); + if (result > MAXIMAL_EDGE_DURATION) { + result_tables_pair.first[table_index] = MAXIMAL_EDGE_DURATION - 1; + } else { + result_tables_pair.first[table_index] = result; + } } } } diff --git a/src/server/service/table_service.cpp b/src/server/service/table_service.cpp index 4694aaf6f..374ea2202 100644 --- a/src/server/service/table_service.cpp +++ b/src/server/service/table_service.cpp @@ -61,11 +61,6 @@ std::string getWrongOptionHelp(const engine::api::TableParameters ¶meters) help = "fallback_speed must be > 0"; } - if (parameters.scale_factor < 1) - { - help = "scale_factor must be > 1"; - } - return help; } } // anon. ns diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 4667486a7..0d13703dc 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -565,6 +565,15 @@ BOOST_AUTO_TEST_CASE(valid_table_urls) BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true); CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources); CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations); + + auto result_8 = parseParameters("1,2;3,4?sources=all&destinations=all&annotations=duration&fallback_speed=1&fallback_coordinate=snapped&scale_factor=2"); + BOOST_CHECK(result_8); + CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources); + CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations); + CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates); } BOOST_AUTO_TEST_CASE(valid_match_urls)