mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-03 00:45:41 +02:00
Switch mean over to internal accumulation state
This commit is contained in:
+6
-12
@@ -120,19 +120,13 @@ static void preserve_attribute1(attribute_op const &op, std::string const &key,
|
||||
}
|
||||
|
||||
case op_mean: {
|
||||
auto state = attribute_accum_state.find(key);
|
||||
if (state == attribute_accum_state.end()) {
|
||||
accum_state s;
|
||||
s.sum = full_values[i].to_double() + val.to_double();
|
||||
s.count = 2;
|
||||
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
|
||||
|
||||
full_values[i] = (s.sum / s.count);
|
||||
size_t count = full_values[i].get_count();
|
||||
if (count <= 1) {
|
||||
full_values[i].set_double_count((full_values[i].to_double() + val.to_double()) / 2, 2);
|
||||
} else {
|
||||
state->second.sum += val.to_double();
|
||||
state->second.count += 1;
|
||||
|
||||
full_values[i] = (state->second.sum / state->second.count);
|
||||
double sum = full_values[i].to_double() * count + val.to_double();
|
||||
count++;
|
||||
full_values[i].set_double_count(sum / count, count);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ struct mvt_value {
|
||||
this->count = 0;
|
||||
}
|
||||
|
||||
void set_double_accum(double v, size_t c) {
|
||||
void set_double_count(double v, size_t c) {
|
||||
this->type = mvt_double;
|
||||
this->numeric_value.double_value = v;
|
||||
this->count = c;
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ struct serial_val {
|
||||
}
|
||||
}
|
||||
|
||||
void set_double_accum(double v, size_t c) {
|
||||
void set_double_count(double v, size_t c) {
|
||||
type = mvt_double;
|
||||
s = milo::dtoa_milo(v) + '\0' + std::to_string(c);
|
||||
}
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
@@ -2370,6 +2370,11 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
if (p.need_tilestats.size() > 0) {
|
||||
for (size_t j = 0; j < p.full_keys.size(); j++) {
|
||||
if (p.need_tilestats.count(*p.full_keys[j]) > 0) {
|
||||
// remove accumulation state
|
||||
size_t found = p.full_values[j].s.find('\0');
|
||||
if (found != std::string::npos) {
|
||||
p.full_values[j].s = p.full_values[j].s.substr(0, found);
|
||||
}
|
||||
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, *p.full_keys[j], p.full_values[j]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user