Allow 'unlimited' as value for certain flags
This commit is contained in:
parent
ce6525d3da
commit
54ebd35ad1
@ -10,6 +10,7 @@
|
|||||||
- NodeJS:
|
- NodeJS:
|
||||||
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
|
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
|
||||||
- Misc:
|
- Misc:
|
||||||
|
- ADDED: Add support for "unlimited" to be passed as a value for the default-radius and max-matching-radius flags. [#6599](https://github.com/Project-OSRM/osrm-backend/pull/6599)
|
||||||
- CHANGED: Allow -1.0 as unlimited for default_radius value. [#6599](https://github.com/Project-OSRM/osrm-backend/pull/6599)
|
- CHANGED: Allow -1.0 as unlimited for default_radius value. [#6599](https://github.com/Project-OSRM/osrm-backend/pull/6599)
|
||||||
- CHANGED: Move vector in CSVFilesParser instead copying it. [#6470](https://github.com/Project-OSRM/osrm-backend/pull/6470)
|
- CHANGED: Move vector in CSVFilesParser instead copying it. [#6470](https://github.com/Project-OSRM/osrm-backend/pull/6470)
|
||||||
- REMOVED: Get rid of unused functions in util/json_util.hpp. [#6446](https://github.com/Project-OSRM/osrm-backend/pull/6446)
|
- REMOVED: Get rid of unused functions in util/json_util.hpp. [#6446](https://github.com/Project-OSRM/osrm-backend/pull/6446)
|
||||||
|
|||||||
@ -317,9 +317,16 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
|||||||
ThrowError(args.Env(), "max_alternatives must be an integral number");
|
ThrowError(args.Env(), "max_alternatives must be an integral number");
|
||||||
return engine_config_ptr();
|
return engine_config_ptr();
|
||||||
}
|
}
|
||||||
if (!default_radius.IsUndefined() && !default_radius.IsNumber())
|
if (!max_radius_map_matching.IsUndefined() && max_radius_map_matching.IsString() &&
|
||||||
|
max_radius_map_matching.ToString().Utf8Value() != "unlimited")
|
||||||
{
|
{
|
||||||
ThrowError(args.Env(), "default_radius must be an integral number");
|
ThrowError(args.Env(), "max_radius_map_matching must be unlimited or an integral number");
|
||||||
|
return engine_config_ptr();
|
||||||
|
}
|
||||||
|
if (!default_radius.IsUndefined() && default_radius.IsString() &&
|
||||||
|
default_radius.ToString().Utf8Value() != "unlimited")
|
||||||
|
{
|
||||||
|
ThrowError(args.Env(), "default_radius must be unlimited or an integral number");
|
||||||
return engine_config_ptr();
|
return engine_config_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,10 +344,17 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
|||||||
engine_config->max_results_nearest = max_results_nearest.ToNumber().Int32Value();
|
engine_config->max_results_nearest = max_results_nearest.ToNumber().Int32Value();
|
||||||
if (max_alternatives.IsNumber())
|
if (max_alternatives.IsNumber())
|
||||||
engine_config->max_alternatives = max_alternatives.ToNumber().Int32Value();
|
engine_config->max_alternatives = max_alternatives.ToNumber().Int32Value();
|
||||||
|
|
||||||
if (max_radius_map_matching.IsNumber())
|
if (max_radius_map_matching.IsNumber())
|
||||||
engine_config->max_radius_map_matching = max_radius_map_matching.ToNumber().DoubleValue();
|
engine_config->max_radius_map_matching = max_radius_map_matching.ToNumber().DoubleValue();
|
||||||
|
else if (max_radius_map_matching.IsString() &&
|
||||||
|
max_radius_map_matching.ToString().Utf8Value() == "unlimited")
|
||||||
|
engine_config->max_radius_map_matching = -1.0;
|
||||||
|
|
||||||
if (default_radius.IsNumber())
|
if (default_radius.IsNumber())
|
||||||
engine_config->default_radius = default_radius.ToNumber().DoubleValue();
|
engine_config->default_radius = default_radius.ToNumber().DoubleValue();
|
||||||
|
else if (default_radius.IsString() && default_radius.ToString().Utf8Value() == "unlimited")
|
||||||
|
engine_config->default_radius = -1.0;
|
||||||
|
|
||||||
return engine_config;
|
return engine_config;
|
||||||
}
|
}
|
||||||
@ -1703,4 +1717,4 @@ inline match_parameters_ptr argumentsToMatchParameter(const Napi::CallbackInfo &
|
|||||||
|
|
||||||
} // namespace node_osrm
|
} // namespace node_osrm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -71,6 +71,33 @@ std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm)
|
|||||||
}
|
}
|
||||||
} // namespace osrm::engine
|
} // 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
|
// generate boost::program_options object for the routing part
|
||||||
inline unsigned generateServerProgramOptions(const int argc,
|
inline unsigned generateServerProgramOptions(const int argc,
|
||||||
const char *argv[],
|
const char *argv[],
|
||||||
|
|||||||
@ -118,6 +118,12 @@ test('constructor: takes a default_radius argument', function(assert) {
|
|||||||
assert.ok(osrm);
|
assert.ok(osrm);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('constructor: takes a default_radius unlimited argument', function(assert) {
|
||||||
|
assert.plan(1);
|
||||||
|
var osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'unlimited'});
|
||||||
|
assert.ok(osrm);
|
||||||
|
});
|
||||||
|
|
||||||
test('constructor: throws if default_radius is not a number', function(assert) {
|
test('constructor: throws if default_radius is not a number', function(assert) {
|
||||||
assert.plan(2);
|
assert.plan(2);
|
||||||
assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'abc'}); }, /default_radius must be an integral number/, 'Does not accept string');
|
assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'abc'}); }, /default_radius must be an integral number/, 'Does not accept string');
|
||||||
@ -135,6 +141,7 @@ test('constructor: parses custom limits', function(assert) {
|
|||||||
max_locations_map_matching: 1,
|
max_locations_map_matching: 1,
|
||||||
max_results_nearest: 1,
|
max_results_nearest: 1,
|
||||||
max_alternatives: 1,
|
max_alternatives: 1,
|
||||||
|
default_radius: 1
|
||||||
});
|
});
|
||||||
assert.ok(osrm);
|
assert.ok(osrm);
|
||||||
});
|
});
|
||||||
@ -150,7 +157,8 @@ test('constructor: throws on invalid custom limits', function(assert) {
|
|||||||
max_locations_distance_table: false,
|
max_locations_distance_table: false,
|
||||||
max_locations_map_matching: 'a lot',
|
max_locations_map_matching: 'a lot',
|
||||||
max_results_nearest: null,
|
max_results_nearest: null,
|
||||||
max_alternatives: '10'
|
max_alternatives: '10',
|
||||||
|
default_radius: '10'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user