mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
Round coordinates instead of truncating them (#60)
* Round coordinates instead of truncating them * Update all the tests for coordinate rounding changes * Curses, integer division still truncates * Fix tests * Also round instead of shifting when looking for no-op linetos * Should I worry that the same change for moveto doesn't change any tests? * Also round instead of shifting when scaling down to maxzoom resolution * Replace another explicit shift, for origin point * Round instead of shift when writing clipped geometries to the next zoom * Fix low-zoom gridding and smaller-than-a-pixel checks * Don't guess an excessively large maxzoom when there is only one feature * Add a test for guessing the maxzoom of a single point * Explicitly sort by index if no other order distinguishes features * Another affected test
This commit is contained in:
@@ -51,7 +51,7 @@ extern "C" {
|
||||
|
||||
// Offset coordinates to keep them positive
|
||||
#define COORD_OFFSET (4LL << 32)
|
||||
#define SHIFT_RIGHT(a) ((((a) + COORD_OFFSET) >> geometry_scale) - (COORD_OFFSET >> geometry_scale))
|
||||
#define SHIFT_RIGHT(a) ((long long) std::round((double)(a) / (1LL << geometry_scale)))
|
||||
|
||||
#define XSTRINGIFY(s) STRINGIFY(s)
|
||||
#define STRINGIFY(s) #s
|
||||
@@ -320,6 +320,10 @@ struct ordercmp {
|
||||
}
|
||||
}
|
||||
|
||||
if (a.index < b.index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // greater than or equal
|
||||
}
|
||||
} ordercmp;
|
||||
@@ -1814,12 +1818,12 @@ static bool line_is_too_small(drawvec const &geometry, int z, int detail) {
|
||||
return true;
|
||||
}
|
||||
|
||||
long long x = geometry[0].x >> (32 - detail - z);
|
||||
long long y = geometry[0].y >> (32 - detail - z);
|
||||
long long x = std::round((double) geometry[0].x / (1LL << (32 - detail - z)));
|
||||
long long y = std::round((double) geometry[0].y / (1LL << (32 - detail - z)));
|
||||
|
||||
for (auto &g : geometry) {
|
||||
long long xx = g.x >> (32 - detail - z);
|
||||
long long yy = g.y >> (32 - detail - z);
|
||||
long long xx = std::round((double) g.x / (1LL << (32 - detail - z)));
|
||||
long long yy = std::round((double) g.y / (1LL << (32 - detail - z)));
|
||||
|
||||
if (xx != x || yy != y) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user