mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Trying to cover too-small triangles with bigger triangles
This commit is contained in:
+14
-26
@@ -74,47 +74,35 @@ drawvec fix_by_triangulation(drawvec const &dv, int z, int detail) {
|
|||||||
|
|
||||||
std::vector<N> indices = mapbox::earcut<N>(polygon);
|
std::vector<N> indices = mapbox::earcut<N>(polygon);
|
||||||
|
|
||||||
|
drawvec out2;
|
||||||
bool again = true;
|
bool again = true;
|
||||||
while (again) {
|
while (again) {
|
||||||
again = false;
|
again = false;
|
||||||
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
||||||
long long cx = 0, cy = 0;
|
|
||||||
for (size_t j = 0; j < 3; j++) {
|
|
||||||
cx += out[indices[i + j]].x;
|
|
||||||
cy += out[indices[i + j]].y;
|
|
||||||
}
|
|
||||||
cx /= 3;
|
|
||||||
cy /= 3;
|
|
||||||
|
|
||||||
for (size_t j = 0; j < 3; j++) {
|
for (size_t j = 0; j < 3; j++) {
|
||||||
size_t v1 = i + j;
|
size_t v1 = i + j;
|
||||||
size_t v2 = i + ((j + 1) % 3);
|
size_t v2 = i + ((j + 1) % 3);
|
||||||
|
size_t v3 = i + ((j + 2) % 3);
|
||||||
|
|
||||||
if (std::llround(out[indices[v1]].x / scale) == std::llround(out[indices[v2]].x / scale) &&
|
if (std::llabs(std::llround(out[indices[v1]].x / scale) - std::llround(out[indices[v2]].x / scale)) < 2 &&
|
||||||
std::llround(out[indices[v1]].y / scale) == std::llround(out[indices[v2]].y / scale)) {
|
std::llabs(std::llround(out[indices[v1]].y / scale) - std::llround(out[indices[v2]].y / scale)) < 2) {
|
||||||
double ang = atan2(out[indices[v1]].y - cy, out[indices[v1]].x - cx);
|
double ang = atan2(out[indices[v2]].y - out[indices[v1]].y, out[indices[v2]].x - out[indices[v1]].x);
|
||||||
double dx = scale * cos(ang) * sqrt(2) * 20;
|
|
||||||
double dy = scale * sin(ang) * sqrt(2) * 20;
|
|
||||||
if (can_adjust(out, indices, v1, &dx, &dy)) {
|
|
||||||
out[indices[v1]].x += dx;
|
|
||||||
out[indices[v1]].y += dy;
|
|
||||||
again = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ang = atan2(out[indices[v2]].y - cy, out[indices[v2]].x - cx);
|
drawvec tri;
|
||||||
dx = scale * cos(ang) * sqrt(2) * 20;
|
tri.emplace_back(VT_MOVETO, (long long) out[indices[v3]].x, (long long) out[indices[v3]].y);
|
||||||
dy = scale * sin(ang) * sqrt(2) * 20;
|
tri.emplace_back(VT_LINETO, out[indices[v1]].x - scale * cos(ang) * sqrt(2) * 2, out[indices[v1]].y - scale * sin(ang) * sqrt(2) * 2);
|
||||||
if (can_adjust(out, indices, v2, &dx, &dy)) {
|
tri.emplace_back(VT_LINETO, out[indices[v2]].x + scale * cos(ang) * sqrt(2) * 2, out[indices[v2]].y + scale * sin(ang) * sqrt(2) * 2);
|
||||||
out[indices[v2]].x += dx;
|
tri.emplace_back(VT_LINETO, (long long) out[indices[v3]].x, (long long) out[indices[v3]].y);
|
||||||
out[indices[v2]].y += dy;
|
printf("%f\n", get_area(tri, 0, tri.size()));
|
||||||
again = true;
|
|
||||||
|
for (auto const &d : tri) {
|
||||||
|
out2.push_back(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawvec out2;
|
|
||||||
for (size_t i = 0; i < out.size(); i++) {
|
for (size_t i = 0; i < out.size(); i++) {
|
||||||
if (out[i].op == VT_MOVETO) {
|
if (out[i].op == VT_MOVETO) {
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|||||||
@@ -613,6 +613,12 @@ void *partial_feature_worker(void *v) {
|
|||||||
|
|
||||||
drawvec geom = (*partials)[i].geoms[0];
|
drawvec geom = (*partials)[i].geoms[0];
|
||||||
|
|
||||||
|
if (t == VT_POLYGON) {
|
||||||
|
geom = clean_or_clip_poly(geom, 0, 0, false, false);
|
||||||
|
geom = fix_by_triangulation(geom, z, out_detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (t == VT_POLYGON) {
|
if (t == VT_POLYGON) {
|
||||||
drawvec cleaned = clean_or_clip_poly(geom, 0, 0, false, false);
|
drawvec cleaned = clean_or_clip_poly(geom, 0, 0, false, false);
|
||||||
drawvec fixed = fix_by_triangulation(geom, z, out_detail);
|
drawvec fixed = fix_by_triangulation(geom, z, out_detail);
|
||||||
@@ -620,6 +626,7 @@ void *partial_feature_worker(void *v) {
|
|||||||
geom = fixed;
|
geom = fixed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
to_tile_scale(geom, z, out_detail);
|
to_tile_scale(geom, z, out_detail);
|
||||||
|
|
||||||
@@ -634,7 +641,7 @@ void *partial_feature_worker(void *v) {
|
|||||||
check_polygon(geom);
|
check_polygon(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geom.size() < 3) {
|
if (geom.size() < 4) {
|
||||||
if (area > 0) {
|
if (area > 0) {
|
||||||
// area is in world coordinates, calculated before scaling down
|
// area is in world coordinates, calculated before scaling down
|
||||||
geom = revive_polygon(before, area, z, out_detail);
|
geom = revive_polygon(before, area, z, out_detail);
|
||||||
|
|||||||
Reference in New Issue
Block a user