Allow -1.0 as unlimited for default_radius value (#6599)
This commit is contained in:
@@ -13,13 +13,15 @@ bool EngineConfig::IsValid() const
|
||||
return v == -1 || v > limit;
|
||||
};
|
||||
|
||||
const bool limits_valid = unlimited_or_more_than(max_locations_distance_table, 2) &&
|
||||
unlimited_or_more_than(max_locations_map_matching, 2) &&
|
||||
unlimited_or_more_than(max_radius_map_matching, 0) &&
|
||||
unlimited_or_more_than(max_locations_trip, 2) &&
|
||||
unlimited_or_more_than(max_locations_viaroute, 2) &&
|
||||
unlimited_or_more_than(max_results_nearest, 0) &&
|
||||
max_alternatives >= 0;
|
||||
const bool limits_valid =
|
||||
unlimited_or_more_than(max_locations_distance_table, 2) &&
|
||||
unlimited_or_more_than(max_locations_map_matching, 2) &&
|
||||
unlimited_or_more_than(max_radius_map_matching, 0) &&
|
||||
unlimited_or_more_than(max_locations_trip, 2) &&
|
||||
unlimited_or_more_than(max_locations_viaroute, 2) &&
|
||||
unlimited_or_more_than(max_results_nearest, 0) &&
|
||||
(!default_radius.has_value() || unlimited_or_more_than(*default_radius, 0)) &&
|
||||
max_alternatives >= 0;
|
||||
|
||||
return ((use_shared_memory && all_path_are_empty) || (use_mmap && storage_config.IsValid()) ||
|
||||
storage_config.IsValid()) &&
|
||||
|
||||
@@ -181,7 +181,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
if (tidied.parameters.radiuses.empty())
|
||||
{
|
||||
search_radiuses.resize(tidied.parameters.coordinates.size(),
|
||||
default_radius.has_value()
|
||||
default_radius.has_value() && *default_radius != -1.0
|
||||
? *default_radius
|
||||
: routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||
}
|
||||
else
|
||||
{
|
||||
return default_radius.has_value()
|
||||
return default_radius.has_value() && *default_radius != -1.0
|
||||
? *default_radius
|
||||
: routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER;
|
||||
}
|
||||
|
||||
+29
-1
@@ -12,6 +12,7 @@
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/optional/optional_io.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -70,6 +71,33 @@ std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm)
|
||||
}
|
||||
} // namespace osrm::engine
|
||||
|
||||
// overload validate for the double type to allow "unlimited" as an input
|
||||
namespace boost
|
||||
{
|
||||
void validate(boost::any &v, const std::vector<std::string> &values, double *, double)
|
||||
{
|
||||
boost::program_options::validators::check_first_occurrence(v);
|
||||
const std::string &s = boost::program_options::validators::get_single_string(values);
|
||||
|
||||
if (s == "unlimited")
|
||||
{
|
||||
v = -1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
v = std::stod(s);
|
||||
}
|
||||
catch (const std::invalid_argument &)
|
||||
{
|
||||
throw boost::program_options::validation_error(
|
||||
boost::program_options::validation_error::invalid_option_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned generateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
@@ -149,7 +177,7 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
value<double>(&config.max_radius_map_matching)->default_value(-1.0),
|
||||
"Max. radius size supported in map matching query. Default: unlimited.") //
|
||||
("default-radius",
|
||||
value<boost::optional<double>>(&config.default_radius),
|
||||
value<boost::optional<double>>(&config.default_radius)->default_value(-1.0),
|
||||
"Default radius size for queries. Default: unlimited.");
|
||||
|
||||
// hidden options, will be allowed on command line, but will not be shown to the user
|
||||
|
||||
Reference in New Issue
Block a user