mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Consistent indent style with clang-format
This commit is contained in:
@@ -17,6 +17,7 @@ vector_tile.pb.cc vector_tile.pb.h: vector_tile.proto
|
|||||||
PG=
|
PG=
|
||||||
|
|
||||||
H = $(shell find . '(' -name '*.h' -o -name '*.hh' ')')
|
H = $(shell find . '(' -name '*.h' -o -name '*.hh' ')')
|
||||||
|
C = $(shell find . '(' -name '*.c' -o -name '*.cc' ')')
|
||||||
|
|
||||||
INCLUDES = -I/usr/local/include
|
INCLUDES = -I/usr/local/include
|
||||||
LIBS = -L/usr/local/lib
|
LIBS = -L/usr/local/lib
|
||||||
@@ -42,3 +43,6 @@ libjsonpull.a: jsonpull.o
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm tippecanoe *.o
|
rm tippecanoe *.o
|
||||||
|
|
||||||
|
indent:
|
||||||
|
for i in $(C) $(H); do clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false}" $$i; done
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymi
|
|||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!(outcode0 | outcode1)) { // Bitwise OR is 0. Trivially accept and get out of loop
|
if (!(outcode0 | outcode1)) { // Bitwise OR is 0. Trivially accept and get out of loop
|
||||||
accept = 1;
|
accept = 1;
|
||||||
break;
|
break;
|
||||||
} else if (outcode0 & outcode1) { // Bitwise AND is not 0. Trivially reject and get out of loop
|
} else if (outcode0 & outcode1) { // Bitwise AND is not 0. Trivially reject and get out of loop
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// failed both tests, so calculate the line segment to clip
|
// failed both tests, so calculate the line segment to clip
|
||||||
@@ -46,16 +46,16 @@ int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymi
|
|||||||
|
|
||||||
// Now find the intersection point;
|
// Now find the intersection point;
|
||||||
// use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0)
|
// use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0)
|
||||||
if (outcodeOut & TOP) { // point is above the clip rectangle
|
if (outcodeOut & TOP) { // point is above the clip rectangle
|
||||||
x = *x0 + (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0);
|
x = *x0 + (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0);
|
||||||
y = ymax;
|
y = ymax;
|
||||||
} else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
|
} else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
|
||||||
x = *x0 + (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0);
|
x = *x0 + (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0);
|
||||||
y = ymin;
|
y = ymin;
|
||||||
} else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle
|
} else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle
|
||||||
y = *y0 + (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0);
|
y = *y0 + (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0);
|
||||||
x = xmax;
|
x = xmax;
|
||||||
} else if (outcodeOut & LEFT) { // point is to the left of clip rectangle
|
} else if (outcodeOut & LEFT) { // point is to the left of clip rectangle
|
||||||
y = *y0 + (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0);
|
y = *y0 + (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0);
|
||||||
x = xmin;
|
x = xmin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,16 @@
|
|||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
||||||
inline bool is_compressed(std::string const& data) {
|
inline bool is_compressed(std::string const &data) {
|
||||||
return data.size() > 2 &&
|
return data.size() > 2 && (((uint8_t) data[0] == 0x78 && (uint8_t) data[1] == 0x9C) || ((uint8_t) data[0] == 0x1F && (uint8_t) data[1] == 0x8B));
|
||||||
(((uint8_t)data[0] == 0x78 && (uint8_t)data[1] == 0x9C) ||
|
|
||||||
((uint8_t)data[0] == 0x1F && (uint8_t)data[1] == 0x8B));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
||||||
inline int decompress(std::string const& input, std::string & output) {
|
inline int decompress(std::string const &input, std::string &output) {
|
||||||
z_stream inflate_s;
|
z_stream inflate_s;
|
||||||
inflate_s.zalloc = Z_NULL;
|
inflate_s.zalloc = Z_NULL;
|
||||||
inflate_s.zfree = Z_NULL;
|
inflate_s.zfree = Z_NULL;
|
||||||
@@ -29,13 +27,13 @@ inline int decompress(std::string const& input, std::string & output) {
|
|||||||
if (inflateInit2(&inflate_s, 32 + 15) != Z_OK) {
|
if (inflateInit2(&inflate_s, 32 + 15) != Z_OK) {
|
||||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||||
}
|
}
|
||||||
inflate_s.next_in = (Bytef *)input.data();
|
inflate_s.next_in = (Bytef *) input.data();
|
||||||
inflate_s.avail_in = input.size();
|
inflate_s.avail_in = input.size();
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
do {
|
do {
|
||||||
output.resize(length + 2 * input.size());
|
output.resize(length + 2 * input.size());
|
||||||
inflate_s.avail_out = 2 * input.size();
|
inflate_s.avail_out = 2 * input.size();
|
||||||
inflate_s.next_out = (Bytef *)(output.data() + length);
|
inflate_s.next_out = (Bytef *) (output.data() + length);
|
||||||
int ret = inflate(&inflate_s, Z_FINISH);
|
int ret = inflate(&inflate_s, Z_FINISH);
|
||||||
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
||||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||||
@@ -61,7 +59,7 @@ void handle(std::string message, int z, unsigned x, unsigned y) {
|
|||||||
|
|
||||||
if (is_compressed(message)) {
|
if (is_compressed(message)) {
|
||||||
std::string uncompressed;
|
std::string uncompressed;
|
||||||
decompress(message,uncompressed);
|
decompress(message, uncompressed);
|
||||||
if (!tile.ParseFromString(uncompressed)) {
|
if (!tile.ParseFromString(uncompressed)) {
|
||||||
fprintf(stderr, "Couldn't decompress tile %d/%u/%u\n", z, x, y);
|
fprintf(stderr, "Couldn't decompress tile %d/%u/%u\n", z, x, y);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -114,7 +112,7 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
unsigned ox = x, oy = y;
|
unsigned ox = x, oy = y;
|
||||||
|
|
||||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,10 +148,10 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
y /= 2;
|
y /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlite3_close(db) != SQLITE_OK) {
|
if (sqlite3_close(db) != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
|
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(char **argv) {
|
void usage(char **argv) {
|
||||||
|
|||||||
+6
-6
@@ -7,7 +7,7 @@ void enumerate(char *fname) {
|
|||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
|
|
||||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,10 +30,10 @@ void enumerate(char *fname) {
|
|||||||
|
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
if (sqlite3_close(db) != SQLITE_OK) {
|
if (sqlite3_close(db) != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
|
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(char **argv) {
|
void usage(char **argv) {
|
||||||
@@ -43,7 +43,7 @@ void usage(char **argv) {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
extern int optind;
|
extern int optind;
|
||||||
//extern char *optarg;
|
// extern char *optarg;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while ((i = getopt(argc, argv, "")) != -1) {
|
while ((i = getopt(argc, argv, "")) != -1) {
|
||||||
|
|||||||
@@ -25,39 +25,29 @@ int low_detail = 10;
|
|||||||
int full_detail = -1;
|
int full_detail = -1;
|
||||||
int min_detail = 7;
|
int min_detail = 7;
|
||||||
|
|
||||||
#define GEOM_POINT 0 /* array of positions */
|
#define GEOM_POINT 0 /* array of positions */
|
||||||
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
||||||
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
||||||
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
||||||
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
||||||
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
||||||
#define GEOM_TYPES 6
|
#define GEOM_TYPES 6
|
||||||
|
|
||||||
const char *geometry_names[GEOM_TYPES] = {
|
const char *geometry_names[GEOM_TYPES] = {
|
||||||
"Point",
|
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
||||||
"MultiPoint",
|
|
||||||
"LineString",
|
|
||||||
"MultiLineString",
|
|
||||||
"Polygon",
|
|
||||||
"MultiPolygon",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int geometry_within[GEOM_TYPES] = {
|
int geometry_within[GEOM_TYPES] = {
|
||||||
-1, /* point */
|
-1, /* point */
|
||||||
GEOM_POINT, /* multipoint */
|
GEOM_POINT, /* multipoint */
|
||||||
GEOM_POINT, /* linestring */
|
GEOM_POINT, /* linestring */
|
||||||
GEOM_LINESTRING, /* multilinestring */
|
GEOM_LINESTRING, /* multilinestring */
|
||||||
GEOM_LINESTRING, /* polygon */
|
GEOM_LINESTRING, /* polygon */
|
||||||
GEOM_POLYGON, /* multipolygon */
|
GEOM_POLYGON, /* multipolygon */
|
||||||
};
|
};
|
||||||
|
|
||||||
int mb_geometry[GEOM_TYPES] = {
|
int mb_geometry[GEOM_TYPES] = {
|
||||||
VT_POINT,
|
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
|
||||||
VT_POINT,
|
|
||||||
VT_LINE,
|
|
||||||
VT_LINE,
|
|
||||||
VT_POLYGON,
|
|
||||||
VT_POLYGON,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname) {
|
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname) {
|
||||||
@@ -208,7 +198,7 @@ int traverse_zooms(int geomfd[4], off_t geom_size[4], char *metabase, unsigned *
|
|||||||
char geomname[strlen(tmpdir) + strlen("/geom2.XXXXXXXX") + 1];
|
char geomname[strlen(tmpdir) + strlen("/geom2.XXXXXXXX") + 1];
|
||||||
sprintf(geomname, "%s/geom%d.XXXXXXXX", tmpdir, j);
|
sprintf(geomname, "%s/geom%d.XXXXXXXX", tmpdir, j);
|
||||||
subfd[j] = mkstemp(geomname);
|
subfd[j] = mkstemp(geomname);
|
||||||
//printf("%s\n", geomname);
|
// printf("%s\n", geomname);
|
||||||
if (subfd[j] < 0) {
|
if (subfd[j] < 0) {
|
||||||
perror(geomname);
|
perror(geomname);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -413,7 +403,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
|||||||
unlink(geomname);
|
unlink(geomname);
|
||||||
unlink(indexname);
|
unlink(indexname);
|
||||||
|
|
||||||
unsigned file_bbox[] = { UINT_MAX, UINT_MAX, 0, 0 };
|
unsigned file_bbox[] = {UINT_MAX, UINT_MAX, 0, 0};
|
||||||
unsigned midx = 0, midy = 0;
|
unsigned midx = 0, midy = 0;
|
||||||
long long seq = 0;
|
long long seq = 0;
|
||||||
|
|
||||||
@@ -523,7 +513,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned bbox[] = { UINT_MAX, UINT_MAX, 0, 0 };
|
unsigned bbox[] = {UINT_MAX, UINT_MAX, 0, 0};
|
||||||
|
|
||||||
int nprop = 0;
|
int nprop = 0;
|
||||||
if (properties->type == JSON_HASH) {
|
if (properties->type == JSON_HASH) {
|
||||||
@@ -601,8 +591,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
|||||||
for (minzoom = 0; minzoom < 31; minzoom++) {
|
for (minzoom = 0; minzoom < 31; minzoom++) {
|
||||||
unsigned mask = 1 << (32 - (minzoom + 1));
|
unsigned mask = 1 << (32 - (minzoom + 1));
|
||||||
|
|
||||||
if (((bbox[0] & mask) != (bbox[2] & mask)) ||
|
if (((bbox[0] & mask) != (bbox[2] & mask)) || ((bbox[1] & mask) != (bbox[3] & mask))) {
|
||||||
((bbox[1] & mask) != (bbox[3] & mask))) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,7 +600,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
|||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
r = .00000001;
|
r = .00000001;
|
||||||
}
|
}
|
||||||
minzoom = maxzoom - floor(log(r) / - log(droprate));
|
minzoom = maxzoom - floor(log(r) / -log(droprate));
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize_byte(geomfile, minzoom, &geompos, fname);
|
serialize_byte(geomfile, minzoom, &geompos, fname);
|
||||||
@@ -940,7 +929,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
|||||||
midlon = maxlon;
|
midlon = maxlon;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbtiles_write_metadata(outdb, fname, layernames, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, file_keys, nlayers); // XXX layers
|
mbtiles_write_metadata(outdb, fname, layernames, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, file_keys, nlayers); // XXX layers
|
||||||
|
|
||||||
for (i = 0; i < nlayers; i++) {
|
for (i = 0; i < nlayers; i++) {
|
||||||
pool_free_strings(&file_keys1[i]);
|
pool_free_strings(&file_keys1[i]);
|
||||||
@@ -1042,14 +1031,12 @@ int main(int argc, char **argv) {
|
|||||||
gamma = atof(optarg);
|
gamma = atof(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p': {
|
||||||
{
|
char *cp;
|
||||||
char *cp;
|
for (cp = optarg; *cp != '\0'; cp++) {
|
||||||
for (cp = optarg; *cp != '\0'; cp++) {
|
prevent[*cp & 0xFF] = 1;
|
||||||
prevent[*cp & 0xFF] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
fprintf(stderr, VERSION);
|
fprintf(stderr, VERSION);
|
||||||
|
|||||||
+32
-34
@@ -12,9 +12,9 @@
|
|||||||
#include "geometry.hh"
|
#include "geometry.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "clip.h"
|
#include "clip.h"
|
||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail, long long *bbox) {
|
drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail, long long *bbox) {
|
||||||
@@ -115,7 +115,7 @@ drawvec remove_noop(drawvec geom, int type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (geom[i + 1].op == VT_CLOSEPATH) {
|
if (geom[i + 1].op == VT_CLOSEPATH) {
|
||||||
i++; // also remove unused closepath
|
i++; // also remove unused closepath
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,17 +202,17 @@ static bool inside(draw d, int edge, long long area, long long buffer) {
|
|||||||
long long clip_buffer = buffer * area / 256;
|
long long clip_buffer = buffer * area / 256;
|
||||||
|
|
||||||
switch (edge) {
|
switch (edge) {
|
||||||
case 0: // top
|
case 0: // top
|
||||||
return d.y > -clip_buffer;
|
return d.y > -clip_buffer;
|
||||||
|
|
||||||
case 1: // right
|
case 1: // right
|
||||||
return d.x < area + clip_buffer;
|
return d.x < area + clip_buffer;
|
||||||
|
|
||||||
case 2: // bottom
|
case 2: // bottom
|
||||||
return d.y < area + clip_buffer;
|
return d.y < area + clip_buffer;
|
||||||
|
|
||||||
case 3: // left
|
case 3: // left
|
||||||
return d.x > -clip_buffer;
|
return d.x > -clip_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "internal error inside\n");
|
fprintf(stderr, "internal error inside\n");
|
||||||
@@ -227,8 +227,8 @@ static draw get_line_intersection(draw p0, draw p1, draw p2, draw p3) {
|
|||||||
double s2_y = p3.y - p2.y;
|
double s2_y = p3.y - p2.y;
|
||||||
|
|
||||||
double t;
|
double t;
|
||||||
//s = (-s1_y * (p0.x - p2.x) + s1_x * (p0.y - p2.y)) / (-s2_x * s1_y + s1_x * s2_y);
|
// s = (-s1_y * (p0.x - p2.x) + s1_x * (p0.y - p2.y)) / (-s2_x * s1_y + s1_x * s2_y);
|
||||||
t = ( s2_x * (p0.y - p2.y) - s2_y * (p0.x - p2.x)) / (-s2_x * s1_y + s1_x * s2_y);
|
t = (s2_x * (p0.y - p2.y) - s2_y * (p0.x - p2.x)) / (-s2_x * s1_y + s1_x * s2_y);
|
||||||
|
|
||||||
return draw(VT_LINETO, p0.x + (t * s1_x), p0.y + (t * s1_y));
|
return draw(VT_LINETO, p0.x + (t * s1_x), p0.y + (t * s1_y));
|
||||||
}
|
}
|
||||||
@@ -237,21 +237,21 @@ static draw intersect(draw a, draw b, int edge, long long area, long long buffer
|
|||||||
long long clip_buffer = buffer * area / 256;
|
long long clip_buffer = buffer * area / 256;
|
||||||
|
|
||||||
switch (edge) {
|
switch (edge) {
|
||||||
case 0: // top
|
case 0: // top
|
||||||
return get_line_intersection(a, b, draw(VT_MOVETO, -clip_buffer, -clip_buffer), draw(VT_MOVETO, area + clip_buffer, -clip_buffer));
|
return get_line_intersection(a, b, draw(VT_MOVETO, -clip_buffer, -clip_buffer), draw(VT_MOVETO, area + clip_buffer, -clip_buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // right
|
case 1: // right
|
||||||
return get_line_intersection(a, b, draw(VT_MOVETO, area + clip_buffer, -clip_buffer), draw(VT_MOVETO, area + clip_buffer, area + clip_buffer));
|
return get_line_intersection(a, b, draw(VT_MOVETO, area + clip_buffer, -clip_buffer), draw(VT_MOVETO, area + clip_buffer, area + clip_buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // bottom
|
case 2: // bottom
|
||||||
return get_line_intersection(a, b, draw(VT_MOVETO, area + clip_buffer, area + clip_buffer), draw(VT_MOVETO, -clip_buffer, area + clip_buffer));
|
return get_line_intersection(a, b, draw(VT_MOVETO, area + clip_buffer, area + clip_buffer), draw(VT_MOVETO, -clip_buffer, area + clip_buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // left
|
case 3: // left
|
||||||
return get_line_intersection(a, b, draw(VT_MOVETO, -clip_buffer, area + clip_buffer), draw(VT_MOVETO, -clip_buffer, -clip_buffer));
|
return get_line_intersection(a, b, draw(VT_MOVETO, -clip_buffer, area + clip_buffer), draw(VT_MOVETO, -clip_buffer, -clip_buffer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "internal error intersecting\n");
|
fprintf(stderr, "internal error intersecting\n");
|
||||||
@@ -369,7 +369,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
|
|||||||
area = fabs(area / 2);
|
area = fabs(area / 2);
|
||||||
|
|
||||||
if (area <= pixel * pixel) {
|
if (area <= pixel * pixel) {
|
||||||
//printf("area is only %f vs %lld so using square\n", area, pixel * pixel);
|
// printf("area is only %f vs %lld so using square\n", area, pixel * pixel);
|
||||||
|
|
||||||
*accum_area += area;
|
*accum_area += area;
|
||||||
if (*accum_area > pixel * pixel) {
|
if (*accum_area > pixel * pixel) {
|
||||||
@@ -384,7 +384,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
|
|||||||
*accum_area -= pixel * pixel;
|
*accum_area -= pixel * pixel;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//printf("area is %f so keeping instead of %lld\n", area, pixel * pixel);
|
// printf("area is %f so keeping instead of %lld\n", area, pixel * pixel);
|
||||||
|
|
||||||
for (unsigned k = i; k <= j && k < geom.size(); k++) {
|
for (unsigned k = i; k <= j && k < geom.size(); k++) {
|
||||||
out.push_back(geom[k]);
|
out.push_back(geom[k]);
|
||||||
@@ -481,13 +481,13 @@ drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer) {
|
|||||||
|
|
||||||
int c = clip(&x1, &y1, &x2, &y2, min, min, area, area);
|
int c = clip(&x1, &y1, &x2, &y2, min, min, area, area);
|
||||||
|
|
||||||
if (c > 1) { // clipped
|
if (c > 1) { // clipped
|
||||||
out.push_back(draw(VT_MOVETO, x1, y1));
|
out.push_back(draw(VT_MOVETO, x1, y1));
|
||||||
out.push_back(draw(VT_LINETO, x2, y2));
|
out.push_back(draw(VT_LINETO, x2, y2));
|
||||||
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
||||||
} else if (c == 1) { // unchanged
|
} else if (c == 1) { // unchanged
|
||||||
out.push_back(geom[i]);
|
out.push_back(geom[i]);
|
||||||
} else { // clipped away entirely
|
} else { // clipped away entirely
|
||||||
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -551,9 +551,7 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e) {
|
|||||||
// find index idx of element with max_distance
|
// find index idx of element with max_distance
|
||||||
int i;
|
int i;
|
||||||
for (i = first + 1; i < second; i++) {
|
for (i = first + 1; i < second; i++) {
|
||||||
double temp_dist = square_distance_from_line(geom[start + i].x, geom[start + i].y,
|
double temp_dist = square_distance_from_line(geom[start + i].x, geom[start + i].y, geom[start + first].x, geom[start + first].y, geom[start + second].x, geom[start + second].y);
|
||||||
geom[start + first].x, geom[start + first].y,
|
|
||||||
geom[start + second].x, geom[start + second].y);
|
|
||||||
|
|
||||||
double distance = fabs(temp_dist);
|
double distance = fabs(temp_dist);
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,8 @@ struct draw {
|
|||||||
this->y = y;
|
this->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() { }
|
draw() {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<draw> drawvec;
|
typedef std::vector<draw> drawvec;
|
||||||
|
|||||||
+2
-2
@@ -254,7 +254,7 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (j->container->expect != JSON_COMMA) {
|
if (j->container->expect != JSON_COMMA) {
|
||||||
if (! (j->container->expect == JSON_ITEM && j->container->length == 0)) {
|
if (!(j->container->expect == JSON_ITEM && j->container->length == 0)) {
|
||||||
j->error = "Found ] without final element";
|
j->error = "Found ] without final element";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (j->container->expect != JSON_COMMA) {
|
if (j->container->expect != JSON_COMMA) {
|
||||||
if (! (j->container->expect == JSON_KEY && j->container->length == 0)) {
|
if (!(j->container->expect == JSON_KEY && j->container->length == 0)) {
|
||||||
j->error = "Found } without final element";
|
j->error = "Found } without final element";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-3
@@ -1,12 +1,21 @@
|
|||||||
typedef enum json_type {
|
typedef enum json_type {
|
||||||
// These types can be returned by json_read()
|
// These types can be returned by json_read()
|
||||||
JSON_HASH, JSON_ARRAY, JSON_NUMBER, JSON_STRING, JSON_TRUE, JSON_FALSE, JSON_NULL,
|
JSON_HASH,
|
||||||
|
JSON_ARRAY,
|
||||||
|
JSON_NUMBER,
|
||||||
|
JSON_STRING,
|
||||||
|
JSON_TRUE,
|
||||||
|
JSON_FALSE,
|
||||||
|
JSON_NULL,
|
||||||
|
|
||||||
// These and JSON_HASH and JSON_ARRAY can be called back by json_read_with_separators()
|
// These and JSON_HASH and JSON_ARRAY can be called back by json_read_with_separators()
|
||||||
JSON_COMMA, JSON_COLON,
|
JSON_COMMA,
|
||||||
|
JSON_COLON,
|
||||||
|
|
||||||
// These are only used internally as expectations of what comes next
|
// These are only used internally as expectations of what comes next
|
||||||
JSON_ITEM, JSON_KEY, JSON_VALUE,
|
JSON_ITEM,
|
||||||
|
JSON_KEY,
|
||||||
|
JSON_VALUE,
|
||||||
} json_type;
|
} json_type;
|
||||||
|
|
||||||
typedef struct json_object {
|
typedef struct json_object {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ sqlite3 *mbtiles_open(char *dbname, char **argv) {
|
|||||||
sqlite3 *outdb;
|
sqlite3 *outdb;
|
||||||
|
|
||||||
if (sqlite3_open(dbname, &outdb) != SQLITE_OK) {
|
if (sqlite3_open(dbname, &outdb) != SQLITE_OK) {
|
||||||
fprintf(stderr, "%s: %s: %s\n", argv[0], dbname, sqlite3_errmsg(outdb));
|
fprintf(stderr, "%s: %s: %s\n", argv[0], dbname, sqlite3_errmsg(outdb));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ int is_pooled(struct pool *p, char *s, int type) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct pool_val *pool(struct pool *p, char *s, int type) {
|
struct pool_val *pool(struct pool *p, char *s, int type) {
|
||||||
return pool1(p, s, type, strcmp);
|
return pool1(p, s, type, strcmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ struct pool {
|
|||||||
int n;
|
int n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct pool_val *pool(struct pool *p, char *s, int type);
|
struct pool_val *pool(struct pool *p, char *s, int type);
|
||||||
void pool_free(struct pool *p);
|
void pool_free(struct pool *p);
|
||||||
void pool_free_strings(struct pool *p);
|
void pool_free_strings(struct pool *p);
|
||||||
|
|||||||
+1
-2
@@ -7,7 +7,7 @@ void latlon2tile(double lat, double lon, int zoom, unsigned int *x, unsigned int
|
|||||||
unsigned long long n = 1LL << zoom;
|
unsigned long long n = 1LL << zoom;
|
||||||
|
|
||||||
long long llx = n * ((lon + 180) / 360);
|
long long llx = n * ((lon + 180) / 360);
|
||||||
long long lly = n * (1 - (log(tan(lat_rad) + 1/cos(lat_rad)) / M_PI)) / 2;
|
long long lly = n * (1 - (log(tan(lat_rad) + 1 / cos(lat_rad)) / M_PI)) / 2;
|
||||||
|
|
||||||
if (lat >= 85.0511) {
|
if (lat >= 85.0511) {
|
||||||
lly = 0;
|
lly = 0;
|
||||||
@@ -53,7 +53,6 @@ unsigned long long encode(unsigned int wx, unsigned int wy) {
|
|||||||
out |= v;
|
out |= v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,17 +17,17 @@
|
|||||||
#include "geometry.hh"
|
#include "geometry.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "clip.h"
|
#include "clip.h"
|
||||||
#include "mbtiles.h"
|
#include "mbtiles.h"
|
||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMD_BITS 3
|
#define CMD_BITS 3
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
||||||
static inline int compress(std::string const& input, std::string& output) {
|
static inline int compress(std::string const &input, std::string &output) {
|
||||||
z_stream deflate_s;
|
z_stream deflate_s;
|
||||||
deflate_s.zalloc = Z_NULL;
|
deflate_s.zalloc = Z_NULL;
|
||||||
deflate_s.zfree = Z_NULL;
|
deflate_s.zfree = Z_NULL;
|
||||||
@@ -35,14 +35,14 @@ static inline int compress(std::string const& input, std::string& output) {
|
|||||||
deflate_s.avail_in = 0;
|
deflate_s.avail_in = 0;
|
||||||
deflate_s.next_in = Z_NULL;
|
deflate_s.next_in = Z_NULL;
|
||||||
deflateInit2(&deflate_s, Z_BEST_COMPRESSION, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY);
|
deflateInit2(&deflate_s, Z_BEST_COMPRESSION, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY);
|
||||||
deflate_s.next_in = (Bytef *)input.data();
|
deflate_s.next_in = (Bytef *) input.data();
|
||||||
deflate_s.avail_in = input.size();
|
deflate_s.avail_in = input.size();
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
do {
|
do {
|
||||||
size_t increase = input.size() / 2 + 1024;
|
size_t increase = input.size() / 2 + 1024;
|
||||||
output.resize(length + increase);
|
output.resize(length + increase);
|
||||||
deflate_s.avail_out = increase;
|
deflate_s.avail_out = increase;
|
||||||
deflate_s.next_out = (Bytef *)(output.data() + length);
|
deflate_s.next_out = (Bytef *) (output.data() + length);
|
||||||
int ret = deflate(&deflate_s, Z_FINISH);
|
int ret = deflate(&deflate_s, Z_FINISH);
|
||||||
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -129,7 +129,7 @@ struct coalesce {
|
|||||||
char *metasrc;
|
char *metasrc;
|
||||||
bool coalesced;
|
bool coalesced;
|
||||||
|
|
||||||
bool operator< (const coalesce &o) const {
|
bool operator<(const coalesce &o) const {
|
||||||
int cmp = coalindexcmp(this, &o);
|
int cmp = coalindexcmp(this, &o);
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
return true;
|
return true;
|
||||||
@@ -275,7 +275,7 @@ struct sll {
|
|||||||
char *name;
|
char *name;
|
||||||
long long val;
|
long long val;
|
||||||
|
|
||||||
bool operator< (const sll &o) const {
|
bool operator<(const sll &o) const {
|
||||||
if (this->val < o.val) {
|
if (this->val < o.val) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -372,7 +372,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
long long count = 0;
|
long long count = 0;
|
||||||
//long long along = 0;
|
// long long along = 0;
|
||||||
double accum_area = 0;
|
double accum_area = 0;
|
||||||
|
|
||||||
double interval = 0;
|
double interval = 0;
|
||||||
@@ -392,8 +392,8 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
features.push_back(std::vector<coalesce>());
|
features.push_back(std::vector<coalesce>());
|
||||||
}
|
}
|
||||||
|
|
||||||
int within[4] = { 0 };
|
int within[4] = {0};
|
||||||
long long geompos[4] = { 0 };
|
long long geompos[4] = {0};
|
||||||
|
|
||||||
*geoms = og;
|
*geoms = og;
|
||||||
|
|
||||||
@@ -483,7 +483,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
sy = ty << (32 - z);
|
sy = ty << (32 - z);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("type %d, meta %lld\n", t, metastart);
|
// printf("type %d, meta %lld\n", t, metastart);
|
||||||
serialize_byte(geomfile[j], t, &geompos[j], fname);
|
serialize_byte(geomfile[j], t, &geompos[j], fname);
|
||||||
serialize_byte(geomfile[j], layer, &geompos[j], fname);
|
serialize_byte(geomfile[j], layer, &geompos[j], fname);
|
||||||
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
|
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
|
||||||
@@ -528,7 +528,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
unsigned long long index = encode(bbox[0] / 2 + bbox[2] / 2, bbox[1] / 2 + bbox[3] / 2);
|
unsigned long long index = encode(bbox[0] / 2 + bbox[2] / 2, bbox[1] / 2 + bbox[3] / 2);
|
||||||
if (gap > 0) {
|
if (gap > 0) {
|
||||||
if (index == previndex) {
|
if (index == previndex) {
|
||||||
continue; // Exact duplicate: can't fulfil the gap requirement
|
continue; // Exact duplicate: can't fulfil the gap requirement
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp(log((index - previndex) / scale) * gamma) >= gap) {
|
if (exp(log((index - previndex) / scale) * gamma) >= gap) {
|
||||||
@@ -542,11 +542,11 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
gap = (index - previndex) / scale;
|
gap = (index - previndex) / scale;
|
||||||
|
|
||||||
if (gap == 0) {
|
if (gap == 0) {
|
||||||
continue; // Exact duplicate: skip
|
continue; // Exact duplicate: skip
|
||||||
} else if (gap < 1) {
|
} else if (gap < 1) {
|
||||||
continue; // Narrow dot spacing: need to stretch out
|
continue; // Narrow dot spacing: need to stretch out
|
||||||
} else {
|
} else {
|
||||||
gap = 0; // Wider spacing than minimum: so pass through unchanged
|
gap = 0; // Wider spacing than minimum: so pass through unchanged
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,7 +696,7 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
|
|
||||||
fraction = fraction * 500000 / compressed.size() * 0.95;
|
fraction = fraction * 500000 / compressed.size() * 0.95;
|
||||||
fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100);
|
fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100);
|
||||||
line_detail++; // to keep it the same when the loop decrements it
|
line_detail++; // to keep it the same when the loop decrements it
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
|
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
|
||||||
@@ -710,4 +710,3 @@ long long write_tile(char **geoms, char *metabase, unsigned *file_bbox, int z, u
|
|||||||
fprintf(stderr, "could not make tile %d/%u/%u small enough\n", z, tx, ty);
|
fprintf(stderr, "could not make tile %d/%u/%u small enough\n", z, tx, ty);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user