mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Committing to integer coordinates to fix more accidental mirror segs
This commit is contained in:
+43
-3
@@ -44,6 +44,7 @@ bool fix_opposites(std::vector<segment> &segs) {
|
|||||||
opposites.emplace(opposite, i);
|
opposites.emplace(opposite, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t found = 0;
|
||||||
for (size_t i = 0; i < segs.size(); i++) {
|
for (size_t i = 0; i < segs.size(); i++) {
|
||||||
if (segs[i] == erased) {
|
if (segs[i] == erased) {
|
||||||
continue;
|
continue;
|
||||||
@@ -55,6 +56,8 @@ bool fix_opposites(std::vector<segment> &segs) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found++;
|
||||||
|
|
||||||
double dx = std::round(segs[i].second.x) - std::round(segs[i].first.x);
|
double dx = std::round(segs[i].second.x) - std::round(segs[i].first.x);
|
||||||
double dy = std::round(segs[i].second.y) - std::round(segs[i].first.y);
|
double dy = std::round(segs[i].second.y) - std::round(segs[i].first.y);
|
||||||
double dsq = dx * dx + dy * dy;
|
double dsq = dx * dx + dy * dy;
|
||||||
@@ -82,6 +85,11 @@ bool fix_opposites(std::vector<segment> &segs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("found %zu\n", found);
|
||||||
|
if (found > 0) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
size_t out = 0;
|
size_t out = 0;
|
||||||
for (size_t i = 0; i < segs.size(); i++) {
|
for (size_t i = 0; i < segs.size(); i++) {
|
||||||
if (segs[i] != erased) {
|
if (segs[i] != erased) {
|
||||||
@@ -321,7 +329,6 @@ void snap_round(std::vector<segment> &segs) {
|
|||||||
|
|
||||||
if (fix_opposites(segs)) {
|
if (fix_opposites(segs)) {
|
||||||
again = true;
|
again = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up for a scanline traversal of the segments
|
// set up for a scanline traversal of the segments
|
||||||
@@ -442,6 +449,39 @@ drawvec reassemble(std::vector<segment> const &segs) {
|
|||||||
// lead around either the largest outer ring or
|
// lead around either the largest outer ring or
|
||||||
// the smallest inner ring that includes this point.
|
// the smallest inner ring that includes this point.
|
||||||
|
|
||||||
|
auto best = options.first;
|
||||||
|
double bestang = -500;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
for (; options.first != options.second; ++options.first) {
|
||||||
|
double ang1 = atan2(here.second.y - here.first.y, here.second.x - here.first.x);
|
||||||
|
// the vector for ang2 is backwards, so a complete reversal would be a difference of 0
|
||||||
|
double ang2 = atan2(options.first->second.first.y - options.first->second.second.y,
|
||||||
|
options.first->second.first.x - options.first->second.second.x);
|
||||||
|
double diff = ang1 - ang2;
|
||||||
|
if (diff < 0) {
|
||||||
|
diff += 2 * M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%f,%f to %f,%f to %f,%f, %f,%f: %f\n",
|
||||||
|
here.first.x, here.first.y,
|
||||||
|
here.second.x, here.second.y,
|
||||||
|
options.first->second.first.x, options.first->second.first.y,
|
||||||
|
options.first->second.second.x, options.first->second.second.y,
|
||||||
|
diff * 180 / M_PI);
|
||||||
|
|
||||||
|
if (diff > bestang) {
|
||||||
|
bestang = diff;
|
||||||
|
best = options.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
here = best->second;
|
||||||
|
examined.emplace(here.first, here);
|
||||||
|
examining.erase(best);
|
||||||
|
#endif
|
||||||
|
|
||||||
// XXX just arbitrarily choosing the first for the moment
|
// XXX just arbitrarily choosing the first for the moment
|
||||||
|
|
||||||
here = options.first->second;
|
here = options.first->second;
|
||||||
@@ -525,8 +565,8 @@ drawvec clean_polygon(drawvec const &geom, int z, int detail) {
|
|||||||
|
|
||||||
for (size_t k = i; k + 1 < j; k++) {
|
for (size_t k = i; k + 1 < j; k++) {
|
||||||
std::pair<point, point> seg = std::make_pair(
|
std::pair<point, point> seg = std::make_pair(
|
||||||
point(geom[k].x / scale, geom[k].y / scale),
|
point(std::round(geom[k].x / scale), std::round(geom[k].y / scale)),
|
||||||
point(geom[k + 1].x / scale, geom[k + 1].y / scale));
|
point(std::round(geom[k + 1].x / scale), std::round(geom[k + 1].y / scale)));
|
||||||
|
|
||||||
if (std::round(seg.first.x) != std::round(seg.second.x) ||
|
if (std::round(seg.first.x) != std::round(seg.second.x) ||
|
||||||
std::round(seg.first.y) != std::round(seg.second.y)) {
|
std::round(seg.first.y) != std::round(seg.second.y)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user