diff --git a/clip.cpp b/clip.cpp index d1af5deb..8df69bc7 100644 --- a/clip.cpp +++ b/clip.cpp @@ -184,21 +184,19 @@ int clip(long long *x0, long long *y0, long long *x1, long long *y1, long long x // XXX truncating division - long long shift = 1LL << (GLOBAL_DETAIL - 32); - // 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) / shift) * ((ymax - *y0) / shift) / (*y1 - *y0) * shift * shift; + x = *x0 + (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0); y = ymax; } else if (outcodeOut & BOTTOM) { // point is below the clip rectangle - x = *x0 + ((*x1 - *x0) / shift) * ((ymin - *y0) / shift) / (*y1 - *y0) * shift * shift; + x = *x0 + (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0); y = ymin; } else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle - y = *y0 + ((*y1 - *y0) / shift) * ((xmax - *x0) / shift) / (*x1 - *x0) * shift * shift; + y = *y0 + (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0); x = xmax; } else if (outcodeOut & LEFT) { // point is to the left of clip rectangle - y = *y0 + ((*y1 - *y0) / shift) * ((xmin - *x0) / shift) / (*x1 - *x0) * shift * shift; + y = *y0 + (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0); x = xmin; } diff --git a/geometry.cpp b/geometry.cpp index 3d155628..e25e58e6 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -307,14 +307,11 @@ double distance_from_line(long long point_x, long long point_y, long long segA_x // These calculations must be made in integers instead of floating point // to make them consistent between x86 and arm floating point implementations. // - // In a 32-bit world, coordinates may be up to 34 bits, so their product is up to 68 bits, + // Coordinates may be up to 34 bits, so their product is up to 68 bits, // making their sum up to 69 bits. Downshift before multiplying to keep them in range. - // - // If the world is bigger than 32 bits, scale down to 32 bits. - long long shift = 1LL << (GLOBAL_DETAIL - 32); - double something = ((p2x / 4 / shift) * (p2x / 8 / shift) + (p2y / 4 / shift) * (p2y / 8 / shift)) * 32.0 * shift * shift; + double something = ((p2x / 4) * (p2x / 8) + (p2y / 4) * (p2y / 8)) * 32.0; // likewise - double u = (0 == something) ? 0 : ((point_x - segA_x) / 4 / shift * (p2x / 8 / shift) + (point_y - segA_y) / 4 / shift * (p2y / 8 / shift)) * 32.0 * shift * shift / (something); + double u = (0 == something) ? 0 : ((point_x - segA_x) / 4 * (p2x / 8) + (point_y - segA_y) / 4 * (p2y / 8)) * 32.0 / (something); if (u >= 1) { u = 1; @@ -685,15 +682,13 @@ drawvec fix_polygon(const drawvec &geom) { xtotal /= count; ytotal /= count; - long long shift = 1LL << (GLOBAL_DETAIL - 32); - // figure out which point is furthest from the centroid long long dist2 = 0; long long furthest = 0; for (size_t a = 0; a + 1 < ring.size(); a++) { // division by 16 because these are z0 coordinates and we need to avoid overflow - long long xd = (ring[a].x - xtotal) / 16 / shift; - long long yd = (ring[a].y - ytotal) / 16 / shift; + long long xd = (ring[a].x - xtotal) / 16; + long long yd = (ring[a].y - ytotal) / 16; long long d2 = xd * xd + yd * yd; if (d2 > dist2 || (d2 == dist2 && ring[a] < ring[furthest])) { dist2 = d2; @@ -708,8 +703,8 @@ drawvec fix_polygon(const drawvec &geom) { long long furthestb = 0; for (size_t a = 0; a + 1 < ring.size(); a++) { // division by 16 because these are z0 coordinates and we need to avoid overflow - long long xd = (ring[a].x - ring[furthest].x) / 16 / shift; - long long yd = (ring[a].y - ring[furthest].y) / 16 / shift; + long long xd = (ring[a].x - ring[furthest].x) / 16; + long long yd = (ring[a].y - ring[furthest].y) / 16; long long d2 = xd * xd + yd * yd; if (d2 > dist2b || (d2 == dist2b && ring[a] < ring[furthestb])) { dist2b = d2; diff --git a/plugin.cpp b/plugin.cpp index 670d79c9..c7ca0e59 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -385,8 +385,8 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: for (size_t i = 0; i < dv.size(); i++) { unsigned sx = 0, sy = 0; if (z != 0) { - sx = (long long) x << (GLOBAL_DETAIL - z); - sy = (long long) y << (GLOBAL_DETAIL - z); + sx = x << (GLOBAL_DETAIL - z); + sy = 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 6c80dbec..af829b5b 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1265,8 +1265,8 @@ void *run_prefilter(void *v) { // Offset from tile coordinates back to world coordinates unsigned sx = 0, sy = 0; if (rpa->z != 0) { - sx = (long long) rpa->tx << (GLOBAL_DETAIL - rpa->z); - sy = (long long) rpa->ty << (GLOBAL_DETAIL - rpa->z); + sx = rpa->tx << (GLOBAL_DETAIL - rpa->z); + sy = rpa->ty << (GLOBAL_DETAIL - rpa->z); } for (size_t i = 0; i < tmp_feature.geometry.size(); i++) { tmp_feature.geometry[i].x += sx;