From 686ab56c4ad1ecb48cb0a6fac2d4288f55d910ad Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 18 Mar 2024 12:33:26 -0700 Subject: [PATCH] Bringing back reverted overflow changes, one at a time --- clip.cpp | 10 +++++----- main.cpp | 2 +- plugin.cpp | 6 +++--- tile.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clip.cpp b/clip.cpp index 8df69bc7..1157f514 100644 --- a/clip.cpp +++ b/clip.cpp @@ -177,7 +177,7 @@ int clip(long long *x0, long long *y0, long long *x1, long long *y1, long long x } else { // failed both tests, so calculate the line segment to clip // from an outside point to an intersection with clip edge - long long x = *x0, y = *y0; + __int128 x = *x0, y = *y0; // At least one endpoint is outside the clip rectangle; pick it. int outcodeOut = outcode0 ? outcode0 : outcode1; @@ -187,16 +187,16 @@ int clip(long long *x0, long long *y0, long long *x1, long long *y1, long long x // Now find the intersection point; // use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0) if (outcodeOut & TOP) { // point is above the clip rectangle - x = *x0 + (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0); + x = *x0 + (__int128) (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0); y = ymax; } else if (outcodeOut & BOTTOM) { // point is below the clip rectangle - x = *x0 + (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0); + x = *x0 + (__int128) (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0); y = ymin; } else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle - y = *y0 + (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0); + y = *y0 + (__int128) (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0); x = xmax; } else if (outcodeOut & LEFT) { // point is to the left of clip rectangle - y = *y0 + (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0); + y = *y0 + (__int128) (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0); x = xmin; } diff --git a/main.cpp b/main.cpp index 147ed9c7..bf31232b 100644 --- a/main.cpp +++ b/main.cpp @@ -2431,7 +2431,7 @@ std::pair read_input(std::vector &sources, char *fname, i double total_tile_count = 0; for (int i = 1; i <= maxzoom; i++) { - double tile_count = ceil(area_sum / ((1LL << (GLOBAL_DETAIL - i)) * (1LL << (GLOBAL_DETAIL - i)))); + double tile_count = ceil(area_sum / ((__int128) (1LL << (GLOBAL_DETAIL - i)) * (__int128) (1LL << (GLOBAL_DETAIL - i)))); total_tile_count += tile_count; // 2M tiles is an arbitrary limit, chosen to make tiling jobs diff --git a/plugin.cpp b/plugin.cpp index c7ca0e59..d613bd28 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -383,10 +383,10 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: // Scale and offset geometry from global to tile double scale = 1LL << geometry_scale; for (size_t i = 0; i < dv.size(); i++) { - unsigned sx = 0, sy = 0; + long long sx = 0, sy = 0; if (z != 0) { - sx = x << (GLOBAL_DETAIL - z); - sy = y << (GLOBAL_DETAIL - z); + sx = (long long) x << (GLOBAL_DETAIL - z); + sy = (long long) y << (GLOBAL_DETAIL - z); } dv[i].x = std::round(dv[i].x / scale) * scale - sx; dv[i].y = std::round(dv[i].y / scale) * scale - sy; diff --git a/tile.cpp b/tile.cpp index af829b5b..2a6b6a52 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1263,10 +1263,10 @@ void *run_prefilter(void *v) { tmp_feature.dropped = sf.dropped; // Offset from tile coordinates back to world coordinates - unsigned sx = 0, sy = 0; + long long sx = 0, sy = 0; if (rpa->z != 0) { - sx = rpa->tx << (GLOBAL_DETAIL - rpa->z); - sy = rpa->ty << (GLOBAL_DETAIL - rpa->z); + sx = (long long) rpa->tx << (GLOBAL_DETAIL - rpa->z); + sy = (long long) rpa->ty << (GLOBAL_DETAIL - rpa->z); } for (size_t i = 0; i < tmp_feature.geometry.size(); i++) { tmp_feature.geometry[i].x += sx;