Require a radius parameter when using bearings
This commit is contained in:
parent
82b73ed9ab
commit
c9a5c76ed4
@ -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. |
|
||||
|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. |
|
||||
|
@ -106,7 +106,7 @@ struct BaseParameters
|
||||
bool IsValid() const
|
||||
{
|
||||
return (hints.empty() || hints.size() == coordinates.size()) &&
|
||||
(bearings.empty() || bearings.size() == coordinates.size()) &&
|
||||
(bearings.empty() || bearings.size() == radiuses.size()) &&
|
||||
(radiuses.empty() || radiuses.size() == coordinates.size()) &&
|
||||
(approaches.empty() || approaches.size() == coordinates.size()) &&
|
||||
std::all_of(bearings.begin(),
|
||||
|
@ -4,18 +4,19 @@ namespace osrm::server::service
|
||||
{
|
||||
|
||||
const constexpr char PARAMETER_SIZE_MISMATCH_MSG[] =
|
||||
"Number of elements in %1% size %2% does not match coordinate size %3%";
|
||||
"Number of elements in %1% size %2% does not match %3% size %4%";
|
||||
|
||||
template <typename ParamT>
|
||||
bool constrainParamSize(const char *msg_template,
|
||||
const char *name,
|
||||
const char *param_name,
|
||||
const ParamT ¶m,
|
||||
const char *target_name,
|
||||
const std::size_t target_size,
|
||||
std::string &help)
|
||||
{
|
||||
if (param.size() > 0 && param.size() != target_size)
|
||||
{
|
||||
help = (boost::format(msg_template) % name % param.size() % target_size).str();
|
||||
help = (boost::format(msg_template) % param_name % param.size() % target_name % target_size).str();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1,13 +1,11 @@
|
||||
#include "server/service/match_service.hpp"
|
||||
#include "server/service/utils.hpp"
|
||||
|
||||
#include "server/api/parameters_parser.hpp"
|
||||
#include "server/service/utils.hpp"
|
||||
#include "engine/api/match_parameters.hpp"
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace osrm::server::service
|
||||
{
|
||||
namespace
|
||||
@ -17,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters ¶meters)
|
||||
std::string help;
|
||||
|
||||
const auto coord_size = parameters.coordinates.size();
|
||||
const auto bearings_size = parameters.bearings.size();
|
||||
|
||||
const bool param_size_mismatch =
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "timestamps", parameters.timestamps, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "timestamps", parameters.timestamps, "coordinates", coord_size, help);
|
||||
|
||||
if (!param_size_mismatch && parameters.coordinates.size() < 2)
|
||||
{
|
||||
|
@ -6,11 +6,8 @@
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace osrm::server::service
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string getWrongOptionHelp(const engine::api::NearestParameters ¶meters)
|
||||
@ -18,14 +15,18 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters ¶meters)
|
||||
std::string help;
|
||||
|
||||
const auto coord_size = parameters.coordinates.size();
|
||||
const auto bearings_size = parameters.bearings.size();
|
||||
|
||||
constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help);
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help);
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help);
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help);
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help);
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
|
||||
|
||||
return help;
|
||||
}
|
||||
|
@ -15,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters ¶meters)
|
||||
std::string help;
|
||||
|
||||
const auto coord_size = parameters.coordinates.size();
|
||||
const auto bearings_size = parameters.bearings.size();
|
||||
|
||||
const bool param_size_mismatch =
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
|
||||
|
||||
if (!param_size_mismatch && parameters.coordinates.size() < 2)
|
||||
{
|
||||
|
@ -1,51 +1,33 @@
|
||||
#include "server/service/table_service.hpp"
|
||||
#include "server/service/utils.hpp"
|
||||
|
||||
#include "server/api/parameters_parser.hpp"
|
||||
#include "engine/api/table_parameters.hpp"
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace osrm::server::service
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
const constexpr char PARAMETER_SIZE_MISMATCH_MSG[] =
|
||||
"Number of elements in %1% size %2% does not match coordinate size %3%";
|
||||
|
||||
template <typename ParamT>
|
||||
bool constrainParamSize(const char *msg_template,
|
||||
const char *name,
|
||||
const ParamT ¶m,
|
||||
const std::size_t target_size,
|
||||
std::string &help)
|
||||
{
|
||||
if (param.size() > 0 && param.size() != target_size)
|
||||
{
|
||||
help = (boost::format(msg_template) % name % param.size() % target_size).str();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string getWrongOptionHelp(const engine::api::TableParameters ¶meters)
|
||||
{
|
||||
std::string help;
|
||||
|
||||
const auto coord_size = parameters.coordinates.size();
|
||||
const auto bearings_size = parameters.bearings.size();
|
||||
|
||||
const bool param_size_mismatch =
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
|
||||
|
||||
if (!param_size_mismatch && parameters.coordinates.size() < 2)
|
||||
{
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace osrm::server::service
|
||||
{
|
||||
namespace
|
||||
@ -17,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::TripParameters ¶meters)
|
||||
std::string help;
|
||||
|
||||
const auto coord_size = parameters.coordinates.size();
|
||||
const auto bearings_size = parameters.bearings.size();
|
||||
|
||||
const bool param_size_mismatch =
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
|
||||
constrainParamSize(
|
||||
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
|
||||
|
||||
if (!param_size_mismatch && parameters.coordinates.size() < 2)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user