fix gapfill bits on outer edge of curves

medial_axis fusion_corners fix
using supermerill/SuperSlicer#1583 project to reproduce
This commit is contained in:
supermerill 2021-09-26 23:37:30 +02:00
parent 3f796cdf78
commit f138405bba

View File

@ -644,7 +644,6 @@ MedialAxis::fusion_corners(ThickPolylines &pp)
//if (polyline.points.size() != 2) continue; // maybe we should have something to merge X-point to 2-point if it's near enough. //if (polyline.points.size() != 2) continue; // maybe we should have something to merge X-point to 2-point if it's near enough.
if (polyline.endpoints.first) polyline.reverse(); if (polyline.endpoints.first) polyline.reverse();
else if (!polyline.endpoints.second) continue; else if (!polyline.endpoints.second) continue;
if (polyline.width.back() > 0) continue;
//check my length is small //check my length is small
coord_t length = (coord_t)polyline.length(); coord_t length = (coord_t)polyline.length();
@ -676,28 +675,30 @@ MedialAxis::fusion_corners(ThickPolylines &pp)
if (pp[crosspoint[0]].endpoints.second && length > pp[crosspoint[0]].length()) continue; if (pp[crosspoint[0]].endpoints.second && length > pp[crosspoint[0]].length()) continue;
if (pp[crosspoint[1]].endpoints.second && length > pp[crosspoint[1]].length()) continue; if (pp[crosspoint[1]].endpoints.second && length > pp[crosspoint[1]].length()) continue;
//FIXME: also pull (a bit less) points that are near to this one. if (polyline.width.back() > 0) {
// if true, pull it a bit, depends on my size, the dot?, and the coeff at my 0-end (~14% for a square, almost 0 for a gentle curve) //FIXME: also pull (a bit less) points that are near to this one.
coord_t length_pull = (coord_t)polyline.length(); // if true, pull it a bit, depends on my size, the dot?, and the coeff at my 0-end (~14% for a square, almost 0 for a gentle curve)
length_pull *= (coord_t)( 0.144 * get_coeff_from_angle_countour( coord_t length_pull = (coord_t)polyline.length();
polyline.points.back(), length_pull *= (coord_t)(0.144 * get_coeff_from_angle_countour(
this->expolygon, polyline.points.back(),
std::min(min_width, (coord_t)(polyline.length() / 2)))); this->expolygon,
std::min(min_width, (coord_t)(polyline.length() / 2))));
//compute dir //compute dir
Vec2d pull_direction(polyline.points[1].x() - polyline.points[0].x(), polyline.points[1].y() - polyline.points[0].y()); Vec2d pull_direction(polyline.points[1].x() - polyline.points[0].x(), polyline.points[1].y() - polyline.points[0].y());
pull_direction.normalize(); pull_direction.normalize();
pull_direction.x() *= length_pull; pull_direction.x() *= length_pull;
pull_direction.y() *= length_pull; pull_direction.y() *= length_pull;
//pull the points //pull the points
Point &p1 = pp[crosspoint[0]].points[0]; Point& p1 = pp[crosspoint[0]].points[0];
p1.x() = p1.x() + (coord_t)pull_direction.x(); p1.x() = p1.x() + (coord_t)pull_direction.x();
p1.y() = p1.y() + (coord_t)pull_direction.y(); p1.y() = p1.y() + (coord_t)pull_direction.y();
Point &p2 = pp[crosspoint[1]].points[0]; Point& p2 = pp[crosspoint[1]].points[0];
p2.x() = p2.x() + (coord_t)pull_direction.x(); p2.x() = p2.x() + (coord_t)pull_direction.x();
p2.y() = p2.y() + (coord_t)pull_direction.y(); p2.y() = p2.y() + (coord_t)pull_direction.y();
}
//delete the now unused polyline //delete the now unused polyline
pp.erase(pp.begin() + i); pp.erase(pp.begin() + i);