mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 01:45:41 +02:00
Next step of index widening; tests still pass
This commit is contained in:
+1
-1
@@ -1299,7 +1299,7 @@ drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigne
|
|||||||
drawvec out;
|
drawvec out;
|
||||||
|
|
||||||
// anchor point in world coordinates
|
// anchor point in world coordinates
|
||||||
unsigned wx, wy;
|
unsigned long long wx, wy;
|
||||||
decode_index(label_point, &wx, &wy);
|
decode_index(label_point, &wx, &wy);
|
||||||
|
|
||||||
long long wwx = decoded_to_coordinate(wx);
|
long long wwx = decoded_to_coordinate(wx);
|
||||||
|
|||||||
@@ -2508,7 +2508,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
|||||||
|
|
||||||
long long ip;
|
long long ip;
|
||||||
for (ip = 0; ip < indices; ip++) {
|
for (ip = 0; ip < indices; ip++) {
|
||||||
unsigned xx, yy;
|
unsigned long long xx, yy;
|
||||||
decode_index(map[ip].ix, &xx, &yy);
|
decode_index(map[ip].ix, &xx, &yy);
|
||||||
|
|
||||||
long long gxx = decoded_to_coordinate(xx);
|
long long gxx = decoded_to_coordinate(xx);
|
||||||
|
|||||||
+17
-17
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#define UINT_BITS 32
|
#define UINT_BITS 32
|
||||||
|
|
||||||
index_t (*encode_index)(unsigned int wx, unsigned int wy) = NULL;
|
index_t (*encode_index)(unsigned long long wx, unsigned long long wy) = NULL;
|
||||||
void (*decode_index)(index_t index, unsigned *wx, unsigned *wy) = NULL;
|
void (*decode_index)(index_t index, unsigned long long *wx, unsigned long long *wy) = NULL;
|
||||||
|
|
||||||
struct projection projections[] = {
|
struct projection projections[] = {
|
||||||
{"EPSG:4326", lonlat2tile, tile2lonlat, "urn:ogc:def:crs:OGC:1.3:CRS84"},
|
{"EPSG:4326", lonlat2tile, tile2lonlat, "urn:ogc:def:crs:OGC:1.3:CRS84"},
|
||||||
@@ -107,7 +107,7 @@ void tiletoepsg3857(long long ix, long long iy, int zoom, double *ox, double *oy
|
|||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Hilbert_curve
|
// https://en.wikipedia.org/wiki/Hilbert_curve
|
||||||
|
|
||||||
void hilbert_rot(unsigned long long n, unsigned *x, unsigned *y, unsigned long long rx, unsigned long long ry) {
|
void hilbert_rot(unsigned long long n, unsigned long long *x, unsigned long long *y, unsigned long long rx, unsigned long long ry) {
|
||||||
if (ry == 0) {
|
if (ry == 0) {
|
||||||
if (rx == 1) {
|
if (rx == 1) {
|
||||||
*x = n - 1 - *x;
|
*x = n - 1 - *x;
|
||||||
@@ -120,11 +120,11 @@ void hilbert_rot(unsigned long long n, unsigned *x, unsigned *y, unsigned long l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long hilbert_xy2d(unsigned long long n, unsigned x, unsigned y) {
|
index_t hilbert_xy2d(unsigned long long n, unsigned long long x, unsigned long long y) {
|
||||||
unsigned long long d = 0;
|
index_t d = 0;
|
||||||
unsigned long long rx, ry;
|
unsigned long long rx, ry;
|
||||||
|
|
||||||
for (unsigned long long s = n / 2; s > 0; s /= 2) {
|
for (index_t s = n / 2; s > 0; s /= 2) {
|
||||||
rx = (x & s) != 0;
|
rx = (x & s) != 0;
|
||||||
ry = (y & s) != 0;
|
ry = (y & s) != 0;
|
||||||
|
|
||||||
@@ -135,12 +135,12 @@ unsigned long long hilbert_xy2d(unsigned long long n, unsigned x, unsigned y) {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hilbert_d2xy(unsigned long long n, unsigned long long d, unsigned *x, unsigned *y) {
|
void hilbert_d2xy(index_t n, index_t d, unsigned long long *x, unsigned long long *y) {
|
||||||
unsigned long long rx, ry;
|
unsigned long long rx, ry;
|
||||||
unsigned long long t = d;
|
index_t t = d;
|
||||||
|
|
||||||
*x = *y = 0;
|
*x = *y = 0;
|
||||||
for (unsigned long long s = 1; s < n; s *= 2) {
|
for (index_t s = 1; s < n; s *= 2) {
|
||||||
rx = 1 & (t / 2);
|
rx = 1 & (t / 2);
|
||||||
ry = 1 & (t ^ rx);
|
ry = 1 & (t ^ rx);
|
||||||
hilbert_rot(s, x, y, rx, ry);
|
hilbert_rot(s, x, y, rx, ry);
|
||||||
@@ -150,20 +150,20 @@ void hilbert_d2xy(unsigned long long n, unsigned long long d, unsigned *x, unsig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
index_t encode_hilbert(unsigned int wx, unsigned int wy) {
|
index_t encode_hilbert(unsigned long long wx, unsigned long long wy) {
|
||||||
return hilbert_xy2d(1LL << UINT_BITS, wx, wy);
|
return hilbert_xy2d(1LL << UINT_BITS, wx, wy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode_hilbert(index_t index, unsigned *wx, unsigned *wy) {
|
void decode_hilbert(index_t index, unsigned long long *wx, unsigned long long *wy) {
|
||||||
hilbert_d2xy(1LL << UINT_BITS, index, wx, wy);
|
hilbert_d2xy(1LL << UINT_BITS, index, wx, wy);
|
||||||
}
|
}
|
||||||
|
|
||||||
index_t encode_quadkey(unsigned int wx, unsigned int wy) {
|
index_t encode_quadkey(unsigned long long wx, unsigned long long wy) {
|
||||||
unsigned long long out = 0;
|
index_t out = 0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < UINT_BITS; i++) {
|
for (i = 0; i < UINT_BITS; i++) {
|
||||||
unsigned long long v = ((wx >> (UINT_BITS - (i + 1))) & 1) << 1;
|
index_t v = ((wx >> (UINT_BITS - (i + 1))) & 1) << 1;
|
||||||
v |= (wy >> (UINT_BITS - (i + 1))) & 1;
|
v |= (wy >> (UINT_BITS - (i + 1))) & 1;
|
||||||
v = v << (64 - 2 * (i + 1));
|
v = v << (64 - 2 * (i + 1));
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ index_t encode_quadkey(unsigned int wx, unsigned int wy) {
|
|||||||
static std::atomic<unsigned char> decodex[256];
|
static std::atomic<unsigned char> decodex[256];
|
||||||
static std::atomic<unsigned char> decodey[256];
|
static std::atomic<unsigned char> decodey[256];
|
||||||
|
|
||||||
void decode_quadkey(index_t index, unsigned *wx, unsigned *wy) {
|
void decode_quadkey(index_t index, unsigned long long *wx, unsigned long long *wy) {
|
||||||
static std::atomic<int> initialized(0);
|
static std::atomic<int> initialized(0);
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
for (size_t ix = 0; ix < 256; ix++) {
|
for (size_t ix = 0; ix < 256; ix++) {
|
||||||
@@ -197,8 +197,8 @@ void decode_quadkey(index_t index, unsigned *wx, unsigned *wy) {
|
|||||||
*wx = *wy = 0;
|
*wx = *wy = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < 8; i++) {
|
for (size_t i = 0; i < 8; i++) {
|
||||||
*wx |= ((unsigned) decodex[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
*wx |= ((unsigned long long) decodex[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
||||||
*wy |= ((unsigned) decodey[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
*wy |= ((unsigned long long) decodey[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -20,14 +20,14 @@ struct projection {
|
|||||||
extern struct projection *projection;
|
extern struct projection *projection;
|
||||||
extern struct projection projections[];
|
extern struct projection projections[];
|
||||||
|
|
||||||
extern index_t (*encode_index)(unsigned int wx, unsigned int wy);
|
extern index_t (*encode_index)(unsigned long long wx, unsigned long long wy);
|
||||||
extern void (*decode_index)(index_t index, unsigned *wx, unsigned *wy);
|
extern void (*decode_index)(index_t index, unsigned long long *wx, unsigned long long *wy);
|
||||||
|
|
||||||
index_t encode_quadkey(unsigned int wx, unsigned int wy);
|
index_t encode_quadkey(unsigned long long wx, unsigned long long wy);
|
||||||
void decode_quadkey(index_t index, unsigned *wx, unsigned *wy);
|
void decode_quadkey(index_t index, unsigned long long *wx, unsigned long long *wy);
|
||||||
|
|
||||||
index_t encode_hilbert(unsigned int wx, unsigned int wy);
|
index_t encode_hilbert(unsigned long long wx, unsigned long long wy);
|
||||||
void decode_hilbert(index_t index, unsigned *wx, unsigned *wy);
|
void decode_hilbert(index_t index, unsigned long long *wx, unsigned long long *wy);
|
||||||
|
|
||||||
unsigned coordinate_to_encodable(long long coord);
|
unsigned coordinate_to_encodable(long long coord);
|
||||||
long long decoded_to_coordinate(unsigned coord);
|
long long decoded_to_coordinate(unsigned coord);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ TEST_CASE("Quadkey index", "quadkey index") {
|
|||||||
unsigned x = (unsigned) 1234567890;
|
unsigned x = (unsigned) 1234567890;
|
||||||
unsigned y = (unsigned) 3210987654;
|
unsigned y = (unsigned) 3210987654;
|
||||||
index_t encoded;
|
index_t encoded;
|
||||||
unsigned nx, ny;
|
unsigned long long nx, ny;
|
||||||
|
|
||||||
encoded = encode_quadkey(x, y);
|
encoded = encode_quadkey(x, y);
|
||||||
REQUIRE((unsigned long long) encoded == 7338499239188161052);
|
REQUIRE((unsigned long long) encoded == 7338499239188161052);
|
||||||
|
|||||||
Reference in New Issue
Block a user