Add support for radius requirement for bearings

This commit is contained in:
whytro 2023-04-28 02:46:32 +09:00
parent ba23f5b587
commit e20ae3c149
7 changed files with 33 additions and 1 deletions

View File

@ -1,5 +1,7 @@
# Unreleased # Unreleased
- Changes from 5.27.1 - 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 - Features
- ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575) - ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575)
- Build: - Build:

View File

@ -31,7 +31,7 @@ To pass parameters to each location some options support an array-like encoding:
| Option | Values | Description | | 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. | |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. | |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. | |hints |`{hint};{hint}[;{hint} ...]` |Hint from previous request to derive position in street network. |

View File

@ -536,6 +536,12 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args,
return false; 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<Napi::Array>(); auto bearings_array = bearings.As<Napi::Array>();
if (bearings_array.Length() != params->coordinates.size()) if (bearings_array.Length() != params->coordinates.size())

View File

@ -131,6 +131,12 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Error("InvalidValue", "Invalid coordinate value.", result); 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(), if (max_radius_map_matching > 0 && std::any_of(parameters.radiuses.begin(),
parameters.radiuses.end(), parameters.radiuses.end(),
[&](const auto &radius) { [&](const auto &radius) {

View File

@ -43,6 +43,12 @@ Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms
return Error("InvalidOptions", "Only one input coordinate is supported", result); 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); auto phantom_nodes = GetPhantomNodes(facade, params, params.number_of_results);
if (phantom_nodes.front().size() == 0) if (phantom_nodes.front().size() == 0)

View File

@ -44,6 +44,12 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
"InvalidOptions", "Number of bearings does not match number of coordinates", result); "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 // 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. // The ManyToMany routing algorithm we dispatch to below already handles this perfectly.
const auto num_sources = const auto num_sources =

View File

@ -82,6 +82,12 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
if (!CheckAlgorithms(route_parameters, algorithms, result)) if (!CheckAlgorithms(route_parameters, algorithms, result))
return Status::Error; 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(); const auto &facade = algorithms.GetFacade();
auto phantom_node_pairs = GetPhantomNodes(facade, route_parameters); auto phantom_node_pairs = GetPhantomNodes(facade, route_parameters);
if (phantom_node_pairs.size() != route_parameters.coordinates.size()) if (phantom_node_pairs.size() != route_parameters.coordinates.size())