diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb545ffe..fdbe7a402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased - Changes from 5.27.1 + - API: + - CHANGED: Require a `radius` parameter when using `bearings`. [#6572](https://github.com/Project-OSRM/osrm-backend/pull/6572) - Features - ADDED: Route pedestrians over highway=platform [#6993](https://github.com/Project-OSRM/osrm-backend/pull/6993) - REMOVED: Remove all core-CH left-overs [#6920](https://github.com/Project-OSRM/osrm-backend/pull/6920) diff --git a/docs/http.md b/docs/http.md index 9e6649d73..c54e9e39d 100644 --- a/docs/http.md +++ b/docs/http.md @@ -31,7 +31,7 @@ To pass parameters to each location some options support an array-like encoding: | Option | Values | Description | |----------------|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -|bearings |`{bearing};{bearing}[;{bearing} ...]` |Limits the search to segments with given bearing in degrees towards true north in a clockwise direction. | +|bearings |`{bearing};{bearing}[;{bearing} ...]` |Limits the search to segments with given bearing in degrees towards true north in a clockwise direction. Requires a corresponding radius or set default_radius flag. | |radiuses |`{radius};{radius}[;{radius} ...]` |Limits the search to given radius in meters. | |generate\_hints |`true` (default), `false` |Adds a Hint to the response which can be used in subsequent requests, see `hints` parameter. | |hints |`{hint};{hint}[;{hint} ...]` |Hint from previous request to derive position in street network. | diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index f428308e5..5a185ce87 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -591,6 +591,14 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args, return false; } + if (!obj.Has("radiuses") && default_radius.IsUndefined()) + { + ThrowError( + args.Env(), + "Bearings must be accompanied with radiuses or a default_radius must be set."); + return false; + } + auto bearings_array = bearings.As(); if (bearings_array.Length() != params->coordinates.size()) diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 6fe8f6699..fb780ef27 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -132,6 +132,13 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, return Error("InvalidValue", "Invalid coordinate value.", result); } + if (!parameters.bearings.empty() && !default_radius.has_value() && + parameters.radiuses.size() != parameters.bearings.size()) + { + return Error( + "InvalidOptions", "Number of radiuses does not match number of bearings", result); + } + if (max_radius_map_matching > 0 && std::any_of(parameters.radiuses.begin(), parameters.radiuses.end(), [&](const auto &radius) diff --git a/src/engine/plugins/nearest.cpp b/src/engine/plugins/nearest.cpp index b8d43a5a6..93c3086db 100644 --- a/src/engine/plugins/nearest.cpp +++ b/src/engine/plugins/nearest.cpp @@ -43,6 +43,13 @@ Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms return Error("InvalidOptions", "Only one input coordinate is supported", result); } + if (!params.bearings.empty() && !default_radius.has_value() && + params.radiuses.size() != params.bearings.size()) + { + return Error( + "InvalidOptions", "Number of radiuses does not match number of bearings", result); + } + auto phantom_nodes = GetPhantomNodes(facade, params, params.number_of_results); if (phantom_nodes.front().size() == 0) diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 5fd214c1a..199e4a999 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -44,6 +44,13 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, "InvalidOptions", "Number of bearings does not match number of coordinates", result); } + if (!params.bearings.empty() && !default_radius.has_value() && + params.radiuses.size() != params.bearings.size()) + { + return Error( + "InvalidOptions", "Number of radiuses does not match number of bearings", result); + } + // Empty sources or destinations means the user wants all of them included, respectively // The ManyToMany routing algorithm we dispatch to below already handles this perfectly. const auto num_sources = diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index a59a2c467..00f4fbb13 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -82,6 +82,13 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm if (!CheckAlgorithms(route_parameters, algorithms, result)) return Status::Error; + if (!route_parameters.bearings.empty() && !default_radius.has_value() && + route_parameters.radiuses.size() != route_parameters.bearings.size()) + { + return Error( + "InvalidOptions", "Number of radiuses does not match number of bearings", result); + } + const auto &facade = algorithms.GetFacade(); auto phantom_node_pairs = GetPhantomNodes(facade, route_parameters); if (phantom_node_pairs.size() != route_parameters.coordinates.size())