Skip to content

Commit c9a5c76

Browse files
committed
Require a radius parameter when using bearings
1 parent 82b73ed commit c9a5c76

File tree

8 files changed

+44
-55
lines changed

8 files changed

+44
-55
lines changed

docs/http.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ To pass parameters to each location some options support an array-like encoding:
3131

3232
| Option | Values | Description |
3333
|----------------|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
34-
|bearings |`{bearing};{bearing}[;{bearing} ...]` |Limits the search to segments with given bearing in degrees towards true north in a clockwise direction. |
34+
|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. |
3535
|radiuses |`{radius};{radius}[;{radius} ...]` |Limits the search to given radius in meters. |
3636
|generate\_hints |`true` (default), `false` |Adds a Hint to the response which can be used in subsequent requests, see `hints` parameter. |
3737
|hints |`{hint};{hint}[;{hint} ...]` |Hint from previous request to derive position in street network. |

include/engine/api/base_parameters.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct BaseParameters
106106
bool IsValid() const
107107
{
108108
return (hints.empty() || hints.size() == coordinates.size()) &&
109-
(bearings.empty() || bearings.size() == coordinates.size()) &&
109+
(bearings.empty() || bearings.size() == radiuses.size()) &&
110110
(radiuses.empty() || radiuses.size() == coordinates.size()) &&
111111
(approaches.empty() || approaches.size() == coordinates.size()) &&
112112
std::all_of(bearings.begin(),

include/server/service/utils.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ namespace osrm::server::service
44
{
55

66
const constexpr char PARAMETER_SIZE_MISMATCH_MSG[] =
7-
"Number of elements in %1% size %2% does not match coordinate size %3%";
7+
"Number of elements in %1% size %2% does not match %3% size %4%";
88

99
template <typename ParamT>
1010
bool constrainParamSize(const char *msg_template,
11-
const char *name,
11+
const char *param_name,
1212
const ParamT &param,
13+
const char *target_name,
1314
const std::size_t target_size,
1415
std::string &help)
1516
{
1617
if (param.size() > 0 && param.size() != target_size)
1718
{
18-
help = (boost::format(msg_template) % name % param.size() % target_size).str();
19+
help = (boost::format(msg_template) % param_name % param.size() % target_name % target_size).str();
1920
return true;
2021
}
2122
return false;

src/server/service/match_service.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#include "server/service/match_service.hpp"
2+
#include "server/service/utils.hpp"
23

34
#include "server/api/parameters_parser.hpp"
4-
#include "server/service/utils.hpp"
55
#include "engine/api/match_parameters.hpp"
66

77
#include "util/json_container.hpp"
88

9-
#include <boost/format.hpp>
10-
119
namespace osrm::server::service
1210
{
1311
namespace
@@ -17,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters &parameters)
1715
std::string help;
1816

1917
const auto coord_size = parameters.coordinates.size();
18+
const auto bearings_size = parameters.bearings.size();
2019

2120
const bool param_size_mismatch =
2221
constrainParamSize(
23-
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
22+
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
23+
constrainParamSize(
24+
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
2425
constrainParamSize(
25-
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
26+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
2627
constrainParamSize(
27-
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
28+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
2829
constrainParamSize(
29-
PARAMETER_SIZE_MISMATCH_MSG, "timestamps", parameters.timestamps, coord_size, help);
30+
PARAMETER_SIZE_MISMATCH_MSG, "timestamps", parameters.timestamps, "coordinates", coord_size, help);
3031

3132
if (!param_size_mismatch && parameters.coordinates.size() < 2)
3233
{

src/server/service/nearest_service.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66

77
#include "util/json_container.hpp"
88

9-
#include <boost/format.hpp>
10-
119
namespace osrm::server::service
1210
{
13-
1411
namespace
1512
{
1613
std::string getWrongOptionHelp(const engine::api::NearestParameters &parameters)
1714
{
1815
std::string help;
1916

2017
const auto coord_size = parameters.coordinates.size();
18+
const auto bearings_size = parameters.bearings.size();
2119

22-
constrainParamSize(PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help);
2320
constrainParamSize(
24-
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help);
21+
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help);
22+
constrainParamSize(
23+
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help);
24+
constrainParamSize(
25+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help);
2526
constrainParamSize(
26-
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help);
27+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help);
2728
constrainParamSize(
28-
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
29+
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
2930

3031
return help;
3132
}

src/server/service/route_service.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters &parameters)
1515
std::string help;
1616

1717
const auto coord_size = parameters.coordinates.size();
18+
const auto bearings_size = parameters.bearings.size();
1819

1920
const bool param_size_mismatch =
2021
constrainParamSize(
21-
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
22+
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
2223
constrainParamSize(
23-
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
24+
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
2425
constrainParamSize(
25-
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
26+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
2627
constrainParamSize(
27-
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
28+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
29+
constrainParamSize(
30+
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
2831

2932
if (!param_size_mismatch && parameters.coordinates.size() < 2)
3033
{

src/server/service/table_service.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,33 @@
11
#include "server/service/table_service.hpp"
2+
#include "server/service/utils.hpp"
23

34
#include "server/api/parameters_parser.hpp"
45
#include "engine/api/table_parameters.hpp"
56

67
#include "util/json_container.hpp"
78

8-
#include <boost/format.hpp>
9-
109
namespace osrm::server::service
1110
{
12-
1311
namespace
1412
{
15-
16-
const constexpr char PARAMETER_SIZE_MISMATCH_MSG[] =
17-
"Number of elements in %1% size %2% does not match coordinate size %3%";
18-
19-
template <typename ParamT>
20-
bool constrainParamSize(const char *msg_template,
21-
const char *name,
22-
const ParamT &param,
23-
const std::size_t target_size,
24-
std::string &help)
25-
{
26-
if (param.size() > 0 && param.size() != target_size)
27-
{
28-
help = (boost::format(msg_template) % name % param.size() % target_size).str();
29-
return true;
30-
}
31-
return false;
32-
}
33-
3413
std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
3514
{
3615
std::string help;
3716

3817
const auto coord_size = parameters.coordinates.size();
18+
const auto bearings_size = parameters.bearings.size();
3919

4020
const bool param_size_mismatch =
4121
constrainParamSize(
42-
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
22+
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
23+
constrainParamSize(
24+
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
4325
constrainParamSize(
44-
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
26+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
4527
constrainParamSize(
46-
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
28+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
4729
constrainParamSize(
48-
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
30+
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
4931

5032
if (!param_size_mismatch && parameters.coordinates.size() < 2)
5133
{

src/server/service/trip_service.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include "util/json_container.hpp"
88

9-
#include <boost/format.hpp>
10-
119
namespace osrm::server::service
1210
{
1311
namespace
@@ -17,16 +15,19 @@ std::string getWrongOptionHelp(const engine::api::TripParameters &parameters)
1715
std::string help;
1816

1917
const auto coord_size = parameters.coordinates.size();
18+
const auto bearings_size = parameters.bearings.size();
2019

2120
const bool param_size_mismatch =
2221
constrainParamSize(
23-
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, coord_size, help) ||
22+
PARAMETER_SIZE_MISMATCH_MSG, "hints", parameters.hints, "coordinates", coord_size, help) ||
23+
constrainParamSize(
24+
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, "coordinates", coord_size, help) ||
2425
constrainParamSize(
25-
PARAMETER_SIZE_MISMATCH_MSG, "bearings", parameters.bearings, coord_size, help) ||
26+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "bearings", bearings_size, help) ||
2627
constrainParamSize(
27-
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, coord_size, help) ||
28+
PARAMETER_SIZE_MISMATCH_MSG, "radiuses", parameters.radiuses, "coordinates", coord_size, help) ||
2829
constrainParamSize(
29-
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, coord_size, help);
30+
PARAMETER_SIZE_MISMATCH_MSG, "approaches", parameters.approaches, "coordinates", coord_size, help);
3031

3132
if (!param_size_mismatch && parameters.coordinates.size() < 2)
3233
{

0 commit comments

Comments
 (0)