Make polygon scaling its own function

This commit is contained in:
Erica Fischer
2023-11-14 18:00:03 -08:00
parent 9e46ac8c0e
commit 33052aa60b
3 changed files with 14 additions and 34 deletions
+10 -7
View File
@@ -40,7 +40,12 @@ struct point {
typedef std::pair<point, point> segment;
bool visible(segment const &seg, long long extent) {
bool spindle_visible(segment const &seg, long long extent) {
if (extent == 0) {
// extent of 0 means no spindle revival
return false;
}
long long minx = std::min(seg.first.x, seg.second.x);
long long miny = std::min(seg.first.y, seg.second.y);
long long maxx = std::max(seg.first.x, seg.second.x);
@@ -77,7 +82,7 @@ bool fix_opposites(std::vector<segment> &segs, std::set<segment> &affected, long
long long dx = segs[i].second.x - segs[i].first.x;
long long dy = segs[i].second.y - segs[i].first.y;
long long dsq = dx * dx + dy * dy;
if (visible(segs[i], extent) && dsq >= 5 * 5) {
if (spindle_visible(segs[i], extent) && dsq >= 5 * 5) {
// alter the segment instead to keep it from collapsing away
double ang = atan2(dy, dx) - M_PI / 2;
@@ -694,7 +699,7 @@ double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t
return area;
}
drawvec scale_poly(drawvec const &geom, int z, int detail) {
drawvec scale_polygon(drawvec const &geom, int z, int detail) {
double scale = 1LL << (32 - detail - z);
drawvec out;
@@ -762,9 +767,7 @@ drawvec scale_poly(drawvec const &geom, int z, int detail) {
return out;
}
drawvec clean_polygon(drawvec geom, int z, int detail) {
geom = scale_poly(geom, z, detail);
drawvec clean_polygon(drawvec geom, long long extent) {
// decompose polygon rings into segments
std::vector<std::pair<point, point>> segments;
@@ -796,7 +799,7 @@ drawvec clean_polygon(drawvec geom, int z, int detail) {
// snap-round intersecting segments
snap_round(segments, 1LL << detail);
snap_round(segments, extent);
// reassemble segments into rings
+2 -1
View File
@@ -1 +1,2 @@
drawvec clean_polygon(drawvec geom, int z, int detail);
drawvec clean_polygon(drawvec geom, long long extent);
drawvec scale_polygon(drawvec const &geom, int z, int detail);
+2 -26
View File
@@ -615,36 +615,12 @@ void *partial_feature_worker(void *v) {
drawvec geom = (*partials)[i].geoms[0];
if (t == VT_POLYGON) {
geom = clean_polygon(geom, z, out_detail);
// (*partials)[i].t = t = VT_LINE;
geom = scale_polygon(geom, z, out_detail);
geom = clean_polygon(geom, 1LL << out_detail);
} else {
to_tile_scale(geom, z, out_detail);
}
#if 0
if (t == VT_POLYGON) {
// Scaling may have made the polygon degenerate.
// Give Clipper a chance to try to fix it.
{
drawvec before = geom;
// we can try scaling up because this is now tile scale
geom = clean_or_clip_poly(geom, 0, 0, false, true);
if (additional[A_DEBUG_POLYGON]) {
check_polygon(geom);
}
if (geom.size() < 3) {
if (area > 0) {
// area is in world coordinates, calculated before scaling down
geom = revive_polygon(before, area, z, out_detail);
} else {
geom.clear();
}
}
}
}
#endif
if (t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) {
t = (*partials)[i].t = VT_POINT;
geom = checkerboard_anchors(from_tile_scale(geom, z, out_detail), (*partials)[i].tx, (*partials)[i].ty, z, (*partials)[i].label_point);