From e20ae3c149928ee597f26d13dc5101dd3493abbb Mon Sep 17 00:00:00 2001 From: whytro Date: Fri, 28 Apr 2023 02:46:32 +0900 Subject: [PATCH] Add support for radius requirement for bearings --- CHANGELOG.md | 2 ++ docs/http.md | 2 +- include/nodejs/node_osrm_support.hpp | 6 ++++++ src/engine/plugins/match.cpp | 6 ++++++ src/engine/plugins/nearest.cpp | 6 ++++++ src/engine/plugins/table.cpp | 6 ++++++ src/engine/plugins/viaroute.cpp | 6 ++++++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83e1fab4e..332238a02 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: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575) - Build: diff --git a/docs/http.md b/docs/http.md index 07acc968a..2b6d094f6 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 5296dc4ed..5f0bdf92c 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -536,6 +536,12 @@ 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 90517df18..81f6b551e 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -131,6 +131,12 @@ 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 671dbe3f2..aafcbaa1e 100644 --- a/src/engine/plugins/nearest.cpp +++ b/src/engine/plugins/nearest.cpp @@ -43,6 +43,12 @@ 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 451811305..89254a08f 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -44,6 +44,12 @@ 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 fe0727936..4757a7dbc 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -82,6 +82,12 @@ 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())