Skip to content

Commit

Permalink
Fix count accumulation in overzoom
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Sep 24, 2024
1 parent c5f2f0d commit b6ba448
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ void preserve_attribute(attribute_op const &op, std::string const &key, serial_v
s.count = 2;
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));

full_values[i].type = mvt_double;
full_values[i].s = std::to_string(s.count);
} else { // already present, incrementing
state->second.count += 1;
full_values[i].type = mvt_double;
full_values[i].s = std::to_string(state->second.count);
}
return;
Expand Down
43 changes: 35 additions & 8 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,13 +1186,18 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /
// it is the wrong one.

std::string outkey = key;
bool starting_from_accumulation;

if (starts_with(outkey, accumulate_numeric + ":")) {
std::string prefix = accumulate_numeric + ":" + op.first + ":";
if (starts_with(outkey, prefix)) {
outkey = outkey.substr(prefix.size());
starting_from_accumulation = true; // from a subaccumulation
} else {
continue; // to next operation
}
} else {
starting_from_accumulation = false; // from a plain value
}
// and then put it back on for the output field
std::string prefixed = accumulate_numeric + ":" + op.first + ":" + outkey;
Expand All @@ -1208,32 +1213,54 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /
// not present at all, so copy our value to the prefixed output
numeric_out_field.emplace(prefixed, full_keys.size());
full_keys.push_back(prefixed);

if (op.second == op_count) {
serial_val sv;
sv.type = mvt_double;
sv.s = "1";
full_values.push_back(sv);
if (starting_from_accumulation) {
// copy our count
full_values.push_back(mvt_value_to_serial_val(val));
} else {
// new count of 1
serial_val sv;
sv.type = mvt_double;
sv.s = "1";
full_values.push_back(sv);
}
} else {
full_values.push_back(mvt_value_to_serial_val(val));
}
} else {
// exists unprefixed, so copy it, and then accumulate on our value
numeric_out_field.emplace(prefixed, full_keys.size());
full_keys.push_back(prefixed);

if (op.second == op_count) {
serial_val sv;
sv.type = mvt_double;
sv.s = "1";
if (starting_from_accumulation) {
// sum our count onto the existing 1
sv.s = std::to_string(1 + mvt_value_to_long_long(val));
} else {
// sum our 1 onto the existing 1
sv.s = "2";
}
full_values.push_back(sv);
} else {
full_values.push_back(full_values[out_attr->second]);
preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
}

preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
}
} else {
// exists, so accumulate on our value
preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
if (op.second == op_count) {
if (starting_from_accumulation) {
// sum our count onto the existing count
full_values[prefixed_attr->second].s = std::to_string(atoll(full_values[prefixed_attr->second].s.c_str()) + mvt_value_to_long_long(val));
} else {
full_values[prefixed_attr->second].s = std::to_string(atoll(full_values[prefixed_attr->second].s.c_str()) + 1);
}
} else {
preserve_attribute(op.second, prefixed, mvt_value_to_serial_val(val), full_keys, full_values, attribute_accum_state);
}
}
}
}
Expand Down

0 comments on commit b6ba448

Please sign in to comment.