From a880f44a918312feba76eab275dadc79aaf27897 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 23 Mar 2015 14:44:21 -0700 Subject: [PATCH] Clean up the gamma semantics a little. 0 (default) means unchanged: maxzoom contains all the dots. Positive number, even very small, means that it still checks the gap size and thins out dots if they are close together. Negative number means no gamma, and the old random instead of uniform dropping at low zooms. --- README.md | 2 +- geojson.c | 2 +- tile.cc | 52 +++++++++++++++++++++++++++------------------------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index bb592d7..8f6f949 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Options * -f: Delete the mbtiles file if it already exists instead of giving an error * -r rate: Rate at which dots are dropped at lower zoom levels (default 2.5) * -b pixels: Buffer size where features are duplicated from adjacent tiles (default 5) - * -g gamma: Rate at which especially dense dots are dropped (default 1, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number. + * -g gamma: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number. Example ------- diff --git a/geojson.c b/geojson.c index e17912a..cb21d17 100644 --- a/geojson.c +++ b/geojson.c @@ -901,7 +901,7 @@ int main(int argc, char **argv) { int minzoom = 0; int force = 0; double droprate = 2.5; - double gamma = 1; + double gamma = 0; int buffer = 5; const char *tmpdir = "/tmp"; diff --git a/tile.cc b/tile.cc index 48abeca..fb9ec65 100644 --- a/tile.cc +++ b/tile.cc @@ -489,11 +489,11 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u continue; } - if (t == VT_POINT && z < feature_minzoom && gamma == 0) { + if (t == VT_POINT && z < feature_minzoom && gamma < 0) { continue; } - if (t == VT_POINT && gamma != 0) { + if (t == VT_POINT && gamma >= 0) { seq++; if (seq >= 0) { seq -= interval; @@ -501,32 +501,34 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u continue; } - unsigned long long index = encode(bbox[0] / 2 + bbox[2] / 2, bbox[1] / 2 + bbox[3] / 2); - if (gap > 0) { - if (index == previndex) { - continue; // Exact duplicate: can't fulfil the gap requirement + if (gamma > 0) { + unsigned long long index = encode(bbox[0] / 2 + bbox[2] / 2, bbox[1] / 2 + bbox[3] / 2); + if (gap > 0) { + if (index == previndex) { + continue; // Exact duplicate: can't fulfil the gap requirement + } + + if (exp(log((index - previndex) / scale) * gamma) >= gap) { + // Dot is further from the previous than the nth root of the gap, + // so produce it, and choose a new gap at the next point. + gap = 0; + } else { + continue; + } + } else { + gap = (index - previndex) / scale; + + if (gap == 0) { + continue; // Exact duplicate: skip + } else if (gap < 1) { + continue; // Narrow dot spacing: need to stretch out + } else { + gap = 0; // Wider spacing than minimum: so pass through unchanged + } } - if (exp(log((index - previndex) / scale) * gamma) >= gap) { - // Dot is further from the previous than the nth root of the gap, - // so produce it, and choose a new gap at the next point. - gap = 0; - } else { - continue; - } - } else { - gap = (index - previndex) / scale; - - if (gap == 0) { - continue; // Exact duplicate: skip - } else if (gap < 1) { - continue; // Narrow dot spacing: need to stretch out - } else { - gap = 0; // Wider spacing than minimum: so pass through unchanged - } + previndex = index; } - - previndex = index; } bool reduced = false;