mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
A little glitchy, but close
This commit is contained in:
+19
-41
@@ -75,54 +75,33 @@ drawvec fix_by_triangulation(drawvec const &dv, int z, int detail) {
|
||||
std::vector<N> indices = mapbox::earcut<N>(polygon);
|
||||
|
||||
drawvec out2;
|
||||
bool again = true;
|
||||
while (again) {
|
||||
again = false;
|
||||
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
||||
std::vector<double> lengths;
|
||||
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
||||
std::vector<double> lengths;
|
||||
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
size_t v1 = i + j;
|
||||
size_t v2 = i + ((j + 1) % 3);
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
size_t v1 = i + j;
|
||||
size_t v2 = i + ((j + 1) % 3);
|
||||
size_t v3 = i + ((j + 2) % 3);
|
||||
|
||||
double dx = out[indices[v1]].x - out[indices[v2]].x;
|
||||
double dy = out[indices[v1]].y - out[indices[v2]].y;
|
||||
double d = sqrt(dx * dx + dy * dy);
|
||||
long long px, py;
|
||||
|
||||
lengths.push_back(d);
|
||||
}
|
||||
if (distance_from_line(out[indices[v1]].x, out[indices[v1]].y, // the point
|
||||
out[indices[v2]].x, out[indices[v2]].y, // start of opposite side
|
||||
out[indices[v3]].x, out[indices[v3]].y, // end of opposite side
|
||||
&px, &py) < scale) {
|
||||
// make a new triangle that is not so flat
|
||||
out2.push_back(draw(VT_MOVETO, out[indices[v2]].x, out[indices[v2]].y));
|
||||
out2.push_back(draw(VT_LINETO, out[indices[v3]].x, out[indices[v3]].y));
|
||||
|
||||
std::sort(lengths.begin(), lengths.end());
|
||||
printf("%f %f\n", lengths[2], lengths[0]);
|
||||
|
||||
if (lengths[2] > 5 * lengths[0]) {
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
size_t v1 = i + j;
|
||||
size_t v2 = i + ((j + 1) % 3);
|
||||
size_t v3 = i + ((j + 2) % 3);
|
||||
|
||||
if (std::llabs(std::llround(out[indices[v1]].x / scale) - std::llround(out[indices[v2]].x / scale)) < 2 &&
|
||||
std::llabs(std::llround(out[indices[v1]].y / scale) - std::llround(out[indices[v2]].y / scale)) < 2) {
|
||||
double ang = atan2(out[indices[v2]].y - out[indices[v1]].y, out[indices[v2]].x - out[indices[v1]].x);
|
||||
|
||||
double stretch = 1.5;
|
||||
|
||||
drawvec tri;
|
||||
tri.emplace_back(VT_MOVETO, (long long) out[indices[v3]].x, (long long) out[indices[v3]].y);
|
||||
tri.emplace_back(VT_LINETO, out[indices[v1]].x - scale * cos(ang) * stretch, out[indices[v1]].y - scale * sin(ang) * stretch);
|
||||
tri.emplace_back(VT_LINETO, out[indices[v2]].x + scale * cos(ang) * stretch, out[indices[v2]].y + scale * sin(ang) * stretch);
|
||||
tri.emplace_back(VT_LINETO, (long long) out[indices[v3]].x, (long long) out[indices[v3]].y);
|
||||
printf("%f\n", get_area(tri, 0, tri.size()));
|
||||
|
||||
for (auto const &d : tri) {
|
||||
out2.push_back(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
double ang = atan2(out[indices[v1]].y - py, out[indices[v1]].x - px);
|
||||
out2.push_back(draw(VT_LINETO, out[indices[v1]].x + scale * cos(ang), out[indices[v1]].y + scale * sin(ang)));
|
||||
out2.push_back(draw(VT_LINETO, out[indices[v2]].x, out[indices[v2]].y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// re-close the rings from which we removed the last points earlier
|
||||
|
||||
for (size_t i = 0; i < out.size(); i++) {
|
||||
if (out[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
@@ -136,7 +115,6 @@ drawvec fix_by_triangulation(drawvec const &dv, int z, int detail) {
|
||||
out2.push_back(out[k]);
|
||||
}
|
||||
|
||||
// re-close the ring
|
||||
out2.push_back(draw(VT_LINETO, out[i].x, out[i].y));
|
||||
i = j - 1;
|
||||
}
|
||||
|
||||
+11
-4
@@ -334,7 +334,7 @@ bool point_within_tile(long long x, long long y, int z) {
|
||||
return x >= 0 && y >= 0 && x < area && y < area;
|
||||
}
|
||||
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y) {
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, long long *px, long long *py) {
|
||||
long long p2x = segB_x - segA_x;
|
||||
long long p2y = segB_y - segA_y;
|
||||
double something = p2x * p2x + p2y * p2y;
|
||||
@@ -349,6 +349,13 @@ double distance_from_line(long long point_x, long long point_y, long long segA_x
|
||||
double x = segA_x + u * p2x;
|
||||
double y = segA_y + u * p2y;
|
||||
|
||||
if (px != NULL) {
|
||||
*px = std::round(x);
|
||||
}
|
||||
if (py != NULL) {
|
||||
*py = std::round(y);
|
||||
}
|
||||
|
||||
double dx = x - point_x;
|
||||
double dy = y - point_y;
|
||||
|
||||
@@ -400,7 +407,7 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
|
||||
if (geom[start + first] < geom[start + second]) {
|
||||
farthest_element_index = first;
|
||||
for (i = first + 1; i < second; i++) {
|
||||
double temp_dist = 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);
|
||||
double temp_dist = 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, NULL, NULL);
|
||||
|
||||
double distance = std::fabs(temp_dist);
|
||||
|
||||
@@ -412,7 +419,7 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
|
||||
} else {
|
||||
farthest_element_index = second;
|
||||
for (i = second - 1; i > first; i--) {
|
||||
double temp_dist = distance_from_line(geom[start + i].x, geom[start + i].y, geom[start + second].x, geom[start + second].y, geom[start + first].x, geom[start + first].y);
|
||||
double temp_dist = distance_from_line(geom[start + i].x, geom[start + i].y, geom[start + second].x, geom[start + second].y, geom[start + first].x, geom[start + first].y, NULL, NULL);
|
||||
|
||||
double distance = std::fabs(temp_dist);
|
||||
|
||||
@@ -1046,7 +1053,7 @@ double label_goodness(const drawvec &dv, long long x, long long y) {
|
||||
}
|
||||
|
||||
if (i > 0 && dv[i].op == VT_LINETO) {
|
||||
dist = distance_from_line(x, y, dv[i - 1].x, dv[i - 1].y, dv[i].x, dv[i].y);
|
||||
dist = distance_from_line(x, y, dv[i - 1].x, dv[i - 1].y, dv[i].x, dv[i].y, NULL, NULL);
|
||||
if (dist < closest) {
|
||||
closest = dist;
|
||||
}
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long
|
||||
drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
||||
void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t retain);
|
||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y, long long *px, long long *py);
|
||||
|
||||
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress);
|
||||
|
||||
+1
-1
@@ -586,7 +586,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
|
||||
for (size_t k = i + 1; k < j - 1; k++) {
|
||||
double d = distance_from_line(scaled_geometry[k].x, scaled_geometry[k].y,
|
||||
scaled_geometry[i].x, scaled_geometry[i].y,
|
||||
scaled_geometry[which].x, scaled_geometry[which].y);
|
||||
scaled_geometry[which].x, scaled_geometry[which].y, NULL, NULL);
|
||||
if ((d > far) ||
|
||||
((d == far) && (scaled_geometry[k] < scaled_geometry[which2]))) {
|
||||
far = d;
|
||||
|
||||
Reference in New Issue
Block a user