Many places where I used unsigned array indices but meant size_t

This commit is contained in:
Eric Fischer 2016-03-25 12:20:32 -07:00
parent eee596d5f5
commit c2231318bd
4 changed files with 73 additions and 88 deletions

View File

@ -196,7 +196,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
uint32_t count = geom >> 3; uint32_t count = geom >> 3;
if (op == VT_MOVETO || op == VT_LINETO) { if (op == VT_MOVETO || op == VT_LINETO) {
for (unsigned k = 0; k < count; k++) { for (size_t k = 0; k < count; k++) {
px += dezig(feat.geometry(g + 1)); px += dezig(feat.geometry(g + 1));
py += dezig(feat.geometry(g + 2)); py += dezig(feat.geometry(g + 2));
g += 2; g += 2;
@ -220,7 +220,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
printf("\"type\": \"Point\", \"coordinates\": [ %f, %f ]", ops[0].lon, ops[0].lat); printf("\"type\": \"Point\", \"coordinates\": [ %f, %f ]", ops[0].lon, ops[0].lat);
} else { } else {
printf("\"type\": \"MultiPoint\", \"coordinates\": [ "); printf("\"type\": \"MultiPoint\", \"coordinates\": [ ");
for (unsigned i = 0; i < ops.size(); i++) { for (size_t i = 0; i < ops.size(); i++) {
if (i != 0) { if (i != 0) {
printf(", "); printf(", ");
} }
@ -230,7 +230,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
} }
} else if (feat.type() == VT_LINE) { } else if (feat.type() == VT_LINE) {
int movetos = 0; int movetos = 0;
for (unsigned i = 0; i < ops.size(); i++) { for (size_t i = 0; i < ops.size(); i++) {
if (ops[i].op == VT_MOVETO) { if (ops[i].op == VT_MOVETO) {
movetos++; movetos++;
} }
@ -238,7 +238,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
if (movetos < 2) { if (movetos < 2) {
printf("\"type\": \"LineString\", \"coordinates\": [ "); printf("\"type\": \"LineString\", \"coordinates\": [ ");
for (unsigned i = 0; i < ops.size(); i++) { for (size_t i = 0; i < ops.size(); i++) {
if (i != 0) { if (i != 0) {
printf(", "); printf(", ");
} }
@ -248,7 +248,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
} else { } else {
printf("\"type\": \"MultiLineString\", \"coordinates\": [ [ "); printf("\"type\": \"MultiLineString\", \"coordinates\": [ [ ");
int state = 0; int state = 0;
for (unsigned i = 0; i < ops.size(); i++) { for (size_t i = 0; i < ops.size(); i++) {
if (ops[i].op == VT_MOVETO) { if (ops[i].op == VT_MOVETO) {
if (state == 0) { if (state == 0) {
printf("[ %f, %f ]", ops[i].lon, ops[i].lat); printf("[ %f, %f ]", ops[i].lon, ops[i].lat);
@ -268,7 +268,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
std::vector<std::vector<draw> > rings; std::vector<std::vector<draw> > rings;
std::vector<double> areas; std::vector<double> areas;
for (unsigned i = 0; i < ops.size(); i++) { for (size_t i = 0; i < ops.size(); i++) {
if (ops[i].op == VT_MOVETO) { if (ops[i].op == VT_MOVETO) {
rings.push_back(std::vector<draw>()); rings.push_back(std::vector<draw>());
areas.push_back(0); areas.push_back(0);
@ -282,9 +282,9 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
int outer = 0; int outer = 0;
for (unsigned i = 0; i < rings.size(); i++) { for (size_t i = 0; i < rings.size(); i++) {
double area = 0; double area = 0;
for (unsigned k = 0; k < rings[i].size(); k++) { for (size_t k = 0; k < rings[i].size(); k++) {
if (rings[i][k].op != VT_CLOSEPATH) { if (rings[i][k].op != VT_CLOSEPATH) {
area += rings[i][k].lon * rings[i][(k + 1) % rings[i].size()].lat; area += rings[i][k].lon * rings[i][(k + 1) % rings[i].size()].lat;
area -= rings[i][k].lat * rings[i][(k + 1) % rings[i].size()].lon; area -= rings[i][k].lat * rings[i][(k + 1) % rings[i].size()].lon;
@ -306,7 +306,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
} }
int state = 0; int state = 0;
for (unsigned i = 0; i < rings.size(); i++) { for (size_t i = 0; i < rings.size(); i++) {
if (areas[i] <= 0) { if (areas[i] <= 0) {
if (state != 0) { if (state != 0) {
// new multipolygon // new multipolygon
@ -320,7 +320,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
printf(" ], [ "); printf(" ], [ ");
} }
for (unsigned j = 0; j < rings[i].size(); j++) { for (size_t j = 0; j < rings[i].size(); j++) {
if (rings[i][j].op != VT_CLOSEPATH) { if (rings[i][j].op != VT_CLOSEPATH) {
if (j != 0) { if (j != 0) {
printf(", "); printf(", ");

View File

@ -77,9 +77,7 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail
} }
void to_tile_scale(drawvec &geom, int z, int detail) { void to_tile_scale(drawvec &geom, int z, int detail) {
unsigned i; for (size_t i = 0; i < geom.size(); i++) {
for (i = 0; i < geom.size(); i++) {
geom[i].x >>= (32 - detail - z); geom[i].x >>= (32 - detail - z);
geom[i].y >>= (32 - detail - z); geom[i].y >>= (32 - detail - z);
} }
@ -90,9 +88,8 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
long long x = 0, y = 0; long long x = 0, y = 0;
drawvec out; drawvec out;
unsigned i;
for (i = 0; i < geom.size(); i++) { 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 && (geom[i].x >> shift) == x && (geom[i].y >> shift) == y) {
continue; continue;
} }
@ -112,7 +109,7 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
geom = out; geom = out;
out.resize(0); out.resize(0);
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
if (i + 1 >= geom.size()) { if (i + 1 >= geom.size()) {
continue; continue;
@ -139,7 +136,7 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
geom = out; geom = out;
out.resize(0); out.resize(0);
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { 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 && (geom[i - 1].x >> shift) == (geom[i].x >> shift) && (geom[i - 1].y >> shift) == (geom[i].y >> shift)) {
continue; continue;
@ -159,10 +156,9 @@ drawvec shrink_lines(drawvec &geom, int z, int detail, int basezoom, long long *
long long res = 200LL << (32 - 8 - z); long long res = 200LL << (32 - 8 - z);
long long portion = res / exp(log(sqrt(droprate)) * (basezoom - z)); long long portion = res / exp(log(sqrt(droprate)) * (basezoom - z));
unsigned i;
drawvec out; drawvec out;
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (i > 0 && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO) && geom[i].op == VT_LINETO) { if (i > 0 && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO) && geom[i].op == VT_LINETO) {
double dx = (geom[i].x - geom[i - 1].x); double dx = (geom[i].x - geom[i - 1].x);
double dy = (geom[i].y - geom[i - 1].y); double dy = (geom[i].y - geom[i - 1].y);
@ -214,7 +210,7 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) {
// to do any outer-ring children of those children as a new top level. // to do any outer-ring children of those children as a new top level.
ClipperLib::Path p = t->Contour; ClipperLib::Path p = t->Contour;
for (unsigned i = 0; i < p.size(); i++) { for (size_t i = 0; i < p.size(); i++) {
out.push_back(draw((i == 0) ? VT_MOVETO : VT_LINETO, p[i].X, p[i].Y)); out.push_back(draw((i == 0) ? VT_MOVETO : VT_LINETO, p[i].X, p[i].Y));
} }
if (p.size() > 0) { if (p.size() > 0) {
@ -223,7 +219,7 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) {
for (int n = 0; n < t->ChildCount(); n++) { for (int n = 0; n < t->ChildCount(); n++) {
ClipperLib::Path p = t->Childs[n]->Contour; ClipperLib::Path p = t->Childs[n]->Contour;
for (unsigned i = 0; i < p.size(); i++) { for (size_t i = 0; i < p.size(); i++) {
out.push_back(draw((i == 0) ? VT_MOVETO : VT_LINETO, p[i].X, p[i].Y)); out.push_back(draw((i == 0) ? VT_MOVETO : VT_LINETO, p[i].X, p[i].Y));
} }
if (p.size() > 0) { if (p.size() > 0) {
@ -243,9 +239,9 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
bool has_area = false; bool has_area = false;
for (unsigned i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -253,7 +249,7 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
} }
double area = 0; double area = 0;
for (unsigned k = i; k < j; k++) { for (size_t k = i; k < j; k++) {
area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y; area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y;
area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x; area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x;
} }
@ -265,14 +261,14 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
ClipperLib::Path path; ClipperLib::Path path;
drawvec tmp; drawvec tmp;
for (unsigned k = i; k < j; k++) { for (size_t k = i; k < j; k++) {
path.push_back(ClipperLib::IntPoint(geom[k].x, geom[k].y)); path.push_back(ClipperLib::IntPoint(geom[k].x, geom[k].y));
} }
if (!clipper.AddPath(path, ClipperLib::ptSubject, true)) { if (!clipper.AddPath(path, ClipperLib::ptSubject, true)) {
#if 0 #if 0
fprintf(stderr, "Couldn't add polygon for clipping:"); fprintf(stderr, "Couldn't add polygon for clipping:");
for (unsigned k = i; k < j; k++) { for (size_t k = i; k < j; k++) {
fprintf(stderr, " %lld,%lld", geom[k].x, geom[k].y); fprintf(stderr, " %lld,%lld", geom[k].x, geom[k].y);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -331,9 +327,9 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
drawvec close_poly(drawvec &geom) { drawvec close_poly(drawvec &geom) {
drawvec out; drawvec out;
for (unsigned i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -346,7 +342,7 @@ drawvec close_poly(drawvec &geom) {
} }
} }
for (unsigned n = i; n < j - 1; n++) { for (size_t n = i; n < j - 1; n++) {
out.push_back(geom[n]); out.push_back(geom[n]);
} }
out.push_back(draw(VT_CLOSEPATH, 0, 0)); out.push_back(draw(VT_CLOSEPATH, 0, 0));
@ -425,7 +421,7 @@ static drawvec clip_poly1(drawvec &geom, long long minx, long long miny, long lo
draw S = in[in.size() - 1]; draw S = in[in.size() - 1];
for (unsigned e = 0; e < in.size(); e++) { for (size_t e = 0; e < in.size(); e++) {
draw E = in[e]; draw E = in[e];
if (inside(E, edge, minx, miny, maxx, maxy)) { if (inside(E, edge, minx, miny, maxx, maxy)) {
@ -459,7 +455,7 @@ static drawvec clip_poly1(drawvec &geom, long long minx, long long miny, long lo
} }
out[0].op = VT_MOVETO; out[0].op = VT_MOVETO;
for (unsigned i = 1; i < out.size(); i++) { for (size_t i = 1; i < out.size(); i++) {
out[i].op = VT_LINETO; out[i].op = VT_LINETO;
} }
} }
@ -470,9 +466,9 @@ static drawvec clip_poly1(drawvec &geom, long long minx, long long miny, long lo
drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) { drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
drawvec out; drawvec out;
for (unsigned i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -480,7 +476,7 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
} }
drawvec tmp; drawvec tmp;
for (unsigned k = i; k < j; k++) { for (size_t k = i; k < j; k++) {
tmp.push_back(geom[k]); tmp.push_back(geom[k]);
} }
tmp = clip_poly1(tmp, minx, miny, maxx, maxy); tmp = clip_poly1(tmp, minx, miny, maxx, maxy);
@ -490,7 +486,7 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
for (unsigned k = 0; k < tmp.size(); k++) { for (size_t k = 0; k < tmp.size(); k++) {
out.push_back(tmp[k]); out.push_back(tmp[k]);
} }
@ -522,9 +518,9 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
*reduced = true; *reduced = true;
bool included_last_outer = false; bool included_last_outer = false;
for (unsigned i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -532,7 +528,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
} }
double area = 0; double area = 0;
for (unsigned k = i; k < j; k++) { for (size_t k = i; k < j; k++) {
area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y; area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y;
area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x; area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x;
} }
@ -571,7 +567,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
} 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 (size_t k = i; k <= j && k < geom.size(); k++) {
out.push_back(geom[k]); out.push_back(geom[k]);
} }
@ -587,7 +583,7 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
} else { } else {
fprintf(stderr, "how did we get here with %d in %d?\n", geom[i].op, (int) geom.size()); fprintf(stderr, "how did we get here with %d in %d?\n", geom[i].op, (int) geom.size());
for (unsigned n = 0; n < geom.size(); n++) { for (size_t n = 0; n < geom.size(); n++) {
fprintf(stderr, "%d/%lld/%lld ", geom[n].op, geom[n].x, geom[n].y); fprintf(stderr, "%d/%lld/%lld ", geom[n].op, geom[n].x, geom[n].y);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -601,7 +597,6 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
drawvec clip_point(drawvec &geom, int z, int detail, long long buffer) { drawvec clip_point(drawvec &geom, int z, int detail, long long buffer) {
drawvec out; drawvec out;
unsigned i;
long long min = 0; long long min = 0;
long long area = 0xFFFFFFFF; long long area = 0xFFFFFFFF;
@ -612,7 +607,7 @@ drawvec clip_point(drawvec &geom, int z, int detail, long long buffer) {
area += buffer * area / 256; area += buffer * area / 256;
} }
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].x >= min && geom[i].y >= min && geom[i].x <= area && geom[i].y <= area) { if (geom[i].x >= min && geom[i].y >= min && geom[i].x <= area && geom[i].y <= area) {
out.push_back(geom[i]); out.push_back(geom[i]);
} }
@ -650,7 +645,6 @@ int quick_check(long long *bbox, int z, int detail, long long buffer) {
drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer) { drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer) {
drawvec out; drawvec out;
unsigned i;
long long min = 0; long long min = 0;
long long area = 0xFFFFFFFF; long long area = 0xFFFFFFFF;
@ -661,7 +655,7 @@ drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer) {
area += buffer * area / 256; area += buffer * area / 256;
} }
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (i > 0 && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO) && geom[i].op == VT_LINETO) { if (i > 0 && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO) && geom[i].op == VT_LINETO) {
double x1 = geom[i - 1].x; double x1 = geom[i - 1].x;
double y1 = geom[i - 1].y; double y1 = geom[i - 1].y;
@ -773,7 +767,7 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e) {
drawvec impose_tile_boundaries(drawvec &geom, long long extent) { drawvec impose_tile_boundaries(drawvec &geom, long long extent) {
drawvec out; drawvec out;
for (unsigned i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (i > 0 && geom[i].op == VT_LINETO && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO)) { if (i > 0 && geom[i].op == VT_LINETO && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO)) {
double x1 = geom[i - 1].x; double x1 = geom[i - 1].x;
double y1 = geom[i - 1].y; double y1 = geom[i - 1].y;
@ -808,8 +802,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail) {
area = 1LL << (32 - z); area = 1LL << (32 - z);
} }
unsigned i; for (size_t i = 0; i < geom.size(); i++) {
for (i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
geom[i].necessary = 1; geom[i].necessary = 1;
} else if (geom[i].op == VT_LINETO) { } else if (geom[i].op == VT_LINETO) {
@ -821,9 +814,9 @@ drawvec simplify_lines(drawvec &geom, int z, int detail) {
geom = impose_tile_boundaries(geom, area); geom = impose_tile_boundaries(geom, area);
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -839,7 +832,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail) {
} }
drawvec out; drawvec out;
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].necessary) { if (geom[i].necessary) {
out.push_back(geom[i]); out.push_back(geom[i]);
} }
@ -855,8 +848,7 @@ drawvec reorder_lines(drawvec &geom) {
return geom; return geom;
} }
unsigned i; for (size_t i = 0; i < geom.size(); i++) {
for (i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
if (i != 0) { if (i != 0) {
return geom; return geom;
@ -879,7 +871,7 @@ drawvec reorder_lines(drawvec &geom) {
if (l1 > l2) { if (l1 > l2) {
drawvec out; drawvec out;
for (i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
out.push_back(geom[geom.size() - 1 - i]); out.push_back(geom[geom.size() - 1 - i]);
} }
out[0].op = VT_MOVETO; out[0].op = VT_MOVETO;
@ -894,14 +886,13 @@ drawvec fix_polygon(drawvec &geom) {
int outer = 1; int outer = 1;
drawvec out; drawvec out;
unsigned i; for (size_t i = 0; i < geom.size(); i++) {
for (i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_CLOSEPATH) { if (geom[i].op == VT_CLOSEPATH) {
outer = 1; outer = 1;
} else if (geom[i].op == VT_MOVETO) { } else if (geom[i].op == VT_MOVETO) {
// Find the end of the ring // Find the end of the ring
unsigned j; size_t j;
for (j = i + 1; j < geom.size(); j++) { for (j = i + 1; j < geom.size(); j++) {
if (geom[j].op != VT_LINETO) { if (geom[j].op != VT_LINETO) {
break; break;
@ -912,7 +903,7 @@ drawvec fix_polygon(drawvec &geom) {
// Close it if it isn't closed. // Close it if it isn't closed.
drawvec ring; drawvec ring;
for (unsigned a = i; a < j; a++) { for (size_t a = i; a < j; a++) {
ring.push_back(geom[a]); ring.push_back(geom[a]);
} }
if (j - i != 0 && (ring[0].x != ring[j - i - 1].x || ring[0].y != ring[j - i - 1].y)) { if (j - i != 0 && (ring[0].x != ring[j - i - 1].x || ring[0].y != ring[j - i - 1].y)) {
@ -923,7 +914,7 @@ drawvec fix_polygon(drawvec &geom) {
// inner/outer expectation // inner/outer expectation
double area = 0; double area = 0;
for (unsigned k = 0; k < ring.size(); k++) { for (size_t k = 0; k < ring.size(); k++) {
area += (long double) ring[k].x * (long double) ring[(k + 1) % ring.size()].y; area += (long double) ring[k].x * (long double) ring[(k + 1) % ring.size()].y;
area -= (long double) ring[k].y * (long double) ring[(k + 1) % ring.size()].x; area -= (long double) ring[k].y * (long double) ring[(k + 1) % ring.size()].x;
} }
@ -939,7 +930,7 @@ drawvec fix_polygon(drawvec &geom) {
// Copy ring into output, fixing the moveto/lineto ops if necessary because of // Copy ring into output, fixing the moveto/lineto ops if necessary because of
// reversal or closing // reversal or closing
for (unsigned a = 0; a < ring.size(); a++) { for (size_t a = 0; a < ring.size(); a++) {
if (a == 0) { if (a == 0) {
out.push_back(draw(VT_MOVETO, ring[a].x, ring[a].y)); out.push_back(draw(VT_MOVETO, ring[a].x, ring[a].y));
} else { } else {
@ -966,12 +957,12 @@ std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms) {
bool again = false; bool again = false;
std::vector<drawvec> out; std::vector<drawvec> out;
for (unsigned i = 0; i < geoms.size(); i++) { for (size_t i = 0; i < geoms.size(); i++) {
if (geoms[i].size() > 700) { if (geoms[i].size() > 700) {
long long midx = 0, midy = 0, count = 0; long long midx = 0, midy = 0, count = 0;
long long maxx = LONG_LONG_MIN, maxy = LONG_LONG_MIN, minx = LONG_LONG_MAX, miny = LONG_LONG_MAX; long long maxx = LONG_LONG_MIN, maxy = LONG_LONG_MIN, minx = LONG_LONG_MAX, miny = LONG_LONG_MAX;
for (unsigned j = 0; j < geoms[i].size(); j++) { for (size_t j = 0; j < geoms[i].size(); j++) {
if (geoms[i][j].op == VT_MOVETO || geoms[i][j].op == VT_LINETO) { if (geoms[i][j].op == VT_MOVETO || geoms[i][j].op == VT_LINETO) {
midx += geoms[i][j].x; midx += geoms[i][j].x;
midy += geoms[i][j].y; midy += geoms[i][j].y;

View File

@ -247,7 +247,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
std::vector<std::string> fields = ii->second; std::vector<std::string> fields = ii->second;
matched = 1; matched = 1;
for (unsigned i = 1; i < fields.size(); i++) { for (size_t i = 1; i < fields.size(); i++) {
std::string joinkey = header[i]; std::string joinkey = header[i];
std::string joinval = fields[i]; std::string joinval = fields[i];
int type = VT_STRING; int type = VT_STRING;
@ -311,11 +311,11 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
mapnik::vector::tile_feature *outfeature = outlayer->add_features(); mapnik::vector::tile_feature *outfeature = outlayer->add_features();
outfeature->set_type(feat.type()); outfeature->set_type(feat.type());
for (int g = 0; g < feat.geometry_size(); g++) { for (size_t g = 0; g < feat.geometry_size(); g++) {
outfeature->add_geometry(feat.geometry(g)); outfeature->add_geometry(feat.geometry(g));
} }
for (unsigned i = 0; i < feature_tags.size(); i++) { for (size_t i = 0; i < feature_tags.size(); i++) {
outfeature->add_tags(feature_tags[i]); outfeature->add_tags(feature_tags[i]);
} }
@ -485,8 +485,7 @@ std::vector<std::string> split(char *s) {
std::string dequote(std::string s) { std::string dequote(std::string s) {
std::string out; std::string out;
unsigned i; for (size_t i = 0; i < s.size(); i++) {
for (i = 0; i < s.size(); i++) {
if (s[i] == '"') { if (s[i] == '"') {
if (i + 1 < s.size() && s[i + 1] == '"') { if (i + 1 < s.size() && s[i + 1] == '"') {
out.push_back('"'); out.push_back('"');
@ -509,7 +508,7 @@ void readcsv(char *fn, std::vector<std::string> &header, std::map<std::string, s
if (fgets(s, MAXLINE, f)) { if (fgets(s, MAXLINE, f)) {
header = split(s); header = split(s);
for (unsigned i = 0; i < header.size(); i++) { for (size_t i = 0; i < header.size(); i++) {
header[i] = dequote(header[i]); header[i] = dequote(header[i]);
} }
} }
@ -519,7 +518,7 @@ void readcsv(char *fn, std::vector<std::string> &header, std::map<std::string, s
line[0] = dequote(line[0]); line[0] = dequote(line[0]);
} }
for (unsigned i = 0; i < line.size() && i < header.size(); i++) { for (size_t i = 0; i < line.size() && i < header.size(); i++) {
// printf("putting %s\n", line[0].c_str()); // printf("putting %s\n", line[0].c_str());
mapping.insert(std::pair<std::string, std::vector<std::string> >(line[0], line)); mapping.insert(std::pair<std::string, std::vector<std::string> >(line[0], line));
} }

35
tile.cc
View File

@ -165,8 +165,7 @@ int coalcmp(const void *v1, const void *v2) {
return cmp; return cmp;
} }
unsigned i; for (size_t i = 0; i < c1->meta.size() && i < c2->meta.size(); i++) {
for (i = 0; i < c1->meta.size() && i < c2->meta.size(); i++) {
cmp = c1->meta[i] - c2->meta[i]; cmp = c1->meta[i] - c2->meta[i];
if (cmp != 0) { if (cmp != 0) {
@ -293,8 +292,7 @@ mapnik::vector::tile create_tile(char **layernames, int line_detail, std::vector
layer->set_version(1); layer->set_version(1);
layer->set_extent(1 << line_detail); layer->set_extent(1 << line_detail);
unsigned x; for (size_t x = 0; x < features[i].size(); x++) {
for (x = 0; x < features[i].size(); x++) {
if (features[i][x].type == VT_LINE || features[i][x].type == VT_POLYGON) { if (features[i][x].type == VT_LINE || features[i][x].type == VT_POLYGON) {
features[i][x].geom = remove_noop(features[i][x].geom, features[i][x].type, 0); features[i][x].geom = remove_noop(features[i][x].geom, features[i][x].type, 0);
} }
@ -314,8 +312,7 @@ mapnik::vector::tile create_tile(char **layernames, int line_detail, std::vector
to_feature(features[i][x].geom, feature); to_feature(features[i][x].geom, feature);
*count += features[i][x].geom.size(); *count += features[i][x].geom.size();
unsigned y; for (size_t y = 0; y < features[i][x].meta.size(); y++) {
for (y = 0; y < features[i][x].meta.size(); y++) {
feature->add_tags(features[i][x].meta[y]); feature->add_tags(features[i][x].meta[y]);
} }
} }
@ -452,7 +449,7 @@ void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, u
serialize_long_long(geomfile[j], metastart, &geompos[j], fname); serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
long long wx = initial_x[segment], wy = initial_y[segment]; long long wx = initial_x[segment], wy = initial_y[segment];
for (unsigned u = 0; u < geom.size(); u++) { for (size_t u = 0; u < geom.size(); u++) {
serialize_byte(geomfile[j], geom[u].op, &geompos[j], fname); serialize_byte(geomfile[j], geom[u].op, &geompos[j], fname);
if (geom[u].op != VT_CLOSEPATH) { if (geom[u].op != VT_CLOSEPATH) {
@ -498,7 +495,7 @@ void *partial_feature_worker(void *v) {
struct partial_arg *a = (struct partial_arg *) v; struct partial_arg *a = (struct partial_arg *) v;
std::vector<struct partial> *partials = a->partials; std::vector<struct partial> *partials = a->partials;
for (unsigned i = a->task; i < (*partials).size(); i += a->tasks) { for (size_t i = a->task; i < (*partials).size(); i += a->tasks) {
drawvec geom = (*partials)[i].geoms[0]; // XXX assumption of a single geometry at the beginning drawvec geom = (*partials)[i].geoms[0]; // XXX assumption of a single geometry at the beginning
(*partials)[i].geoms.clear(); // avoid keeping two copies in memory (*partials)[i].geoms.clear(); // avoid keeping two copies in memory
signed char t = (*partials)[i].t; signed char t = (*partials)[i].t;
@ -540,7 +537,7 @@ void *partial_feature_worker(void *v) {
if (t == VT_POLYGON) { if (t == VT_POLYGON) {
// Scaling may have made the polygon degenerate. // Scaling may have made the polygon degenerate.
// Give Clipper a chance to try to fix it. // Give Clipper a chance to try to fix it.
for (unsigned i = 0; i < geoms.size(); i++) { for (size_t i = 0; i < geoms.size(); i++) {
geoms[i] = clean_or_clip_poly(geoms[i], 0, 0, 0, false); geoms[i] = clean_or_clip_poly(geoms[i], 0, 0, 0, false);
geoms[i] = close_poly(geoms[i]); geoms[i] = close_poly(geoms[i]);
} }
@ -733,16 +730,16 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
// If the geometry extends off the edge of the world, concatenate on another copy // If the geometry extends off the edge of the world, concatenate on another copy
// shifted by 360 degrees, and then make sure both copies get clipped down to size. // shifted by 360 degrees, and then make sure both copies get clipped down to size.
unsigned n = geom.size(); size_t n = geom.size();
if (bbox[0] < 0) { if (bbox[0] < 0) {
for (unsigned i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
geom.push_back(draw(geom[i].op, geom[i].x + (1LL << 32), geom[i].y)); geom.push_back(draw(geom[i].op, geom[i].x + (1LL << 32), geom[i].y));
} }
} }
if (bbox[2] > 1LL << 32) { if (bbox[2] > 1LL << 32) {
for (unsigned i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
geom.push_back(draw(geom[i].op, geom[i].x - (1LL << 32), geom[i].y)); geom.push_back(draw(geom[i].op, geom[i].x - (1LL << 32), geom[i].y));
} }
} }
@ -873,7 +870,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
// This is serial because decode_meta() unifies duplicates // This is serial because decode_meta() unifies duplicates
for (unsigned i = 0; i < partials.size(); i++) { for (size_t i = 0; i < partials.size(); i++) {
std::vector<drawvec> geoms = partials[i].geoms; std::vector<drawvec> geoms = partials[i].geoms;
partials[i].geoms.clear(); // avoid keeping two copies in memory partials[i].geoms.clear(); // avoid keeping two copies in memory
long long layer = partials[i].layer; long long layer = partials[i].layer;
@ -883,7 +880,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
// A complex polygon may have been split up into multiple geometries. // A complex polygon may have been split up into multiple geometries.
// Break them out into multiple features if necessary. // Break them out into multiple features if necessary.
for (unsigned j = 0; j < geoms.size(); j++) { for (size_t j = 0; j < geoms.size(); j++) {
if (t == VT_POINT || to_feature(geoms[j], NULL)) { if (t == VT_POINT || to_feature(geoms[j], NULL)) {
struct coalesce c; struct coalesce c;
char *meta = partials[i].meta; char *meta = partials[i].meta;
@ -915,9 +912,8 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
std::vector<coalesce> out; std::vector<coalesce> out;
unsigned x; for (size_t x = 0; x < features[j].size(); x++) {
for (x = 0; x < features[j].size(); x++) { size_t y = out.size() - 1;
unsigned y = out.size() - 1;
#if 0 #if 0
if (out.size() > 0 && coalcmp(&features[j][x], &out[y]) < 0) { if (out.size() > 0 && coalcmp(&features[j][x], &out[y]) < 0) {
@ -926,8 +922,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
#endif #endif
if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 700 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) { if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 700 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
unsigned z; for (size_t z = 0; z < features[j][x].geom.size(); z++) {
for (z = 0; z < features[j][x].geom.size(); z++) {
out[y].geom.push_back(features[j][x].geom[z]); out[y].geom.push_back(features[j][x].geom[z]);
} }
out[y].coalesced = true; out[y].coalesced = true;
@ -939,7 +934,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
features[j] = out; features[j] = out;
out.clear(); out.clear();
for (x = 0; x < features[j].size(); x++) { for (size_t x = 0; x < features[j].size(); x++) {
if (features[j][x].coalesced && features[j][x].type == VT_LINE) { if (features[j][x].coalesced && features[j][x].type == VT_LINE) {
features[j][x].geom = remove_noop(features[j][x].geom, features[j][x].type, 0); features[j][x].geom = remove_noop(features[j][x].geom, features[j][x].type, 0);
features[j][x].geom = simplify_lines(features[j][x].geom, 32, 0); features[j][x].geom = simplify_lines(features[j][x].geom, 32, 0);