Allow -1.0 as unlimited for default_radius value (#6599)
This commit is contained in:
@@ -83,7 +83,7 @@ struct EngineConfig final
|
||||
int max_locations_map_matching = -1;
|
||||
double max_radius_map_matching = -1.0;
|
||||
int max_results_nearest = -1;
|
||||
boost::optional<double> default_radius;
|
||||
boost::optional<double> default_radius = -1.0;
|
||||
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
|
||||
bool use_shared_memory = true;
|
||||
boost::filesystem::path memory_file;
|
||||
|
||||
@@ -72,7 +72,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
[this, &max_distance, &max_results, input_coordinate](const std::size_t num_results,
|
||||
const CandidateSegment &segment) {
|
||||
return (max_results && num_results >= *max_results) ||
|
||||
(max_distance &&
|
||||
(max_distance && max_distance != -1.0 &&
|
||||
CheckSegmentDistance(input_coordinate, segment, *max_distance));
|
||||
});
|
||||
|
||||
@@ -163,7 +163,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
auto distance = GetSegmentDistance(input_coordinate, segment);
|
||||
auto further_than_big_component = distance > big_component_distance;
|
||||
auto no_more_candidates = has_big_component && further_than_big_component;
|
||||
auto too_far_away = max_distance && distance > *max_distance;
|
||||
auto too_far_away =
|
||||
max_distance && max_distance != -1.0 && distance > *max_distance;
|
||||
|
||||
// Time to terminate the search when:
|
||||
// 1. We've found a node from a big component and the next candidate is further away
|
||||
|
||||
@@ -317,9 +317,16 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
||||
ThrowError(args.Env(), "max_alternatives must be an integral number");
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -337,10 +344,17 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
||||
engine_config->max_results_nearest = max_results_nearest.ToNumber().Int32Value();
|
||||
if (max_alternatives.IsNumber())
|
||||
engine_config->max_alternatives = max_alternatives.ToNumber().Int32Value();
|
||||
|
||||
if (max_radius_map_matching.IsNumber())
|
||||
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())
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user