mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25: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:
+10
-10
@@ -87,8 +87,8 @@ drawvec decode_geometry(FILE *meta, std::atomic<long long> *geompos, int z, unsi
|
||||
|
||||
void to_tile_scale(drawvec &geom, int z, int detail) {
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
geom[i].x >>= (32 - detail - z);
|
||||
geom[i].y >>= (32 - detail - z);
|
||||
geom[i].x = std::round((double) geom[i].x / (1LL << (32 - detail - z)));
|
||||
geom[i].y = std::round((double) geom[i].y / (1LL << (32 - detail - z)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ drawvec from_tile_scale(drawvec const &geom, int z, int detail) {
|
||||
drawvec out;
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
draw d = geom[i];
|
||||
d.x <<= (32 - detail - z);
|
||||
d.y <<= (32 - detail - z);
|
||||
d.x *= (1LL << (32 - detail - z));
|
||||
d.y *= (1LL << (32 - detail - z));
|
||||
out.push_back(d);
|
||||
}
|
||||
return out;
|
||||
@@ -110,7 +110,7 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
drawvec out;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_LINETO && (geom[i].x >> shift) == x && (geom[i].y >> shift) == y) {
|
||||
if (geom[i].op == VT_LINETO && std::round((double) geom[i].x / (1LL << shift)) == x && std::round((double) geom[i].y / (1LL << shift)) == y) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
out.push_back(geom[i]);
|
||||
} else { /* moveto or lineto */
|
||||
out.push_back(geom[i]);
|
||||
x = geom[i].x >> shift;
|
||||
y = geom[i].y >> shift;
|
||||
x = std::round((double) geom[i].x / (1LL << shift));
|
||||
y = std::round((double) geom[i].y / (1LL << shift));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
if (i > 0 && geom[i - 1].op == VT_LINETO && (geom[i - 1].x >> shift) == (geom[i].x >> shift) && (geom[i - 1].y >> shift) == (geom[i].y >> shift)) {
|
||||
if (i > 0 && geom[i - 1].op == VT_LINETO && std::round((double) geom[i - 1].x / (1LL << shift)) == std::round((double) geom[i].x / (1LL << shift)) && std::round((double) geom[i - 1].y / (1LL << shift)) == std::round((double) geom[i].y / (1LL << shift))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1323,8 +1323,8 @@ drawvec stairstep(drawvec &geom, int z, int detail) {
|
||||
double scale = 1 << (32 - detail - z);
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
geom[i].x = std::floor(geom[i].x / scale);
|
||||
geom[i].y = std::floor(geom[i].y / scale);
|
||||
geom[i].x = std::round(geom[i].x / scale);
|
||||
geom[i].y = std::round(geom[i].y / scale);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user