Commit b6cdc5b6 authored by Damien L-G's avatar Damien L-G

Drop the interpolation type and the policy from the key and only parse new keys

parent 07ef20ea
......@@ -78,32 +78,16 @@ void check_valid_number_of_options(std::vector<std::string> const &options,
template <typename Spline>
Spline *Map<Spline>::get_spline(std::string const &which) {
auto const options = parse_options(which);
check_valid_number_of_options(options, 5);
std::vector<std::string> const filenames(options.begin(),
options.begin() + 3);
auto const interpolation_type = options[3];
check_option_is_valid(interpolation_type, "interpolation type",
{"bicubic", "bilinear"});
if (interpolation_type == "bilinear") {
throw std::runtime_error("'bilinear' interpolation type is not implemented "
"at this time\nplease use 'bicubic' instead");
}
auto const out_of_domain_policy = options[4];
check_option_is_valid(out_of_domain_policy, "out-of-domain policy",
{"error"});
std::string key;
for (auto const &f : filenames) {
check_file_exists(f);
key += f;
}
key += interpolation_type;
key += out_of_domain_policy;
// Check if the spline object already exists. If it doesn't, create the
// object.
auto it = _splines.find(key);
auto it = _splines.find(which);
if (it == _splines.end()) {
auto const options = parse_options(which);
check_valid_number_of_options(options, 3);
std::vector<std::string> const filenames(options.begin(),
options.begin() + 3);
for (auto const &f : filenames) {
check_file_exists(f);
}
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
......@@ -114,7 +98,7 @@ Spline *Map<Spline>::get_spline(std::string const &which) {
auto const z = extract_from(filenames[2], parse_z);
auto const tz = transpose_z(x.size(), y.size(), z);
std::tie(it, std::ignore) =
_splines.insert({key, std::make_unique<Spline>(x, y, tz)});
_splines.insert({which, std::make_unique<Spline>(x, y, tz)});
}
return (it->second).get();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment