Fixed wrong usage of thickPolyline, added description of what it should actually contain

This commit is contained in:
PavelMikus 2023-04-19 13:32:24 +02:00 committed by Pavel Mikuš
parent 9d3a7f9f2a
commit 4409743ea4
3 changed files with 20 additions and 7 deletions

View file

@ -168,7 +168,7 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
polygon_sections[section_idx].end());
}
double squared_distance_limit_reconnection = 4 * scaled_spacing * scaled_spacing;
double squared_distance_limit_reconnection = 4 * double(scaled_spacing) * double(scaled_spacing);
Polygons reconstructed_area{};
// reconstruct polygon from polygon sections
@ -185,7 +185,9 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
for (TracedPoly &traced_poly : current_traced_polys) {
auto maybe_first_overlap = std::upper_bound(polygon_slice.begin(), polygon_slice.end(), traced_poly.lows.back(),
[](const Point &low, const Line &seg) { return seg.b.y() < low.y(); });
if (maybe_first_overlap != polygon_slice.begin()) {
maybe_first_overlap--;
}
if (maybe_first_overlap != polygon_slice.end() && // segment exists
segments_overlap(traced_poly.lows.back().y(), traced_poly.highs.back().y(), maybe_first_overlap->a.y(),
maybe_first_overlap->b.y())) // segment is overlapping
@ -252,22 +254,27 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
for (ThickPolyline &traced_path : current_traced_paths) {
auto maybe_overlap = std::upper_bound(polygon_slice.begin(), polygon_slice.end(), traced_path.last_point(),
[](const Point &low, const Line &seg) { return seg.a.y() < low.y(); });
bool segment_added = false;
if (maybe_overlap != polygon_slice.begin())
if (maybe_overlap != polygon_slice.begin()) {
maybe_overlap--;
}
bool segment_added = false;
while (!segment_added && maybe_overlap != polygon_slice.end()) {
if ((traced_path.last_point() - maybe_overlap->a).cast<double>().squaredNorm() <
squared_distance_limit_reconnection) {
traced_path.width.push_back(scaled_spacing);
traced_path.points.push_back(maybe_overlap->a);
traced_path.width.push_back(scaled_spacing);
traced_path.width.push_back(scaled_spacing);
traced_path.points.push_back(maybe_overlap->b);
traced_path.width.push_back(scaled_spacing);
used_segments.insert(&(*maybe_overlap));
segment_added = true;
} else if ((traced_path.last_point() - maybe_overlap->b).cast<double>().squaredNorm() <
squared_distance_limit_reconnection) {
traced_path.width.push_back(scaled_spacing);
traced_path.points.push_back(maybe_overlap->b);
traced_path.width.push_back(scaled_spacing);
traced_path.width.push_back(scaled_spacing);
traced_path.points.push_back(maybe_overlap->a);
traced_path.width.push_back(scaled_spacing);
used_segments.insert(&(*maybe_overlap));
@ -287,13 +294,14 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
[](const ThickPolyline &tp) { return tp.empty(); }),
current_traced_paths.end());
for (const auto &segment : polygon_slice) {
for (const Line &segment : polygon_slice) {
if (used_segments.find(&segment) == used_segments.end()) {
ThickPolyline &new_path = current_traced_paths.emplace_back();
new_path.points.push_back(segment.a);
new_path.width.push_back(scaled_spacing);
new_path.points.push_back(segment.b);
new_path.width.push_back(scaled_spacing);
new_path.endpoints = {true,true};
}
}
}

View file

@ -206,6 +206,9 @@ struct ThickPolyline {
void start_at_index(int index);
Points points;
// vector of startpoint width and endpoint width of each line segment. The size should be always (points.size()-1) * 2
// e.g. let four be points a,b,c,d. that are three lines ab, bc, cd. for each line, there should be start width, so the width vector is:
// w(a), w(b), w(b), w(c), w(c), w(d)
std::vector<coordf_t> width;
std::pair<bool,bool> endpoints { false, false };
};

View file

@ -2122,8 +2122,10 @@ void PrintObject::bridge_over_infill()
std::unordered_set<const Line *> used_segments;
for (TracedPoly &traced_poly : current_traced_polys) {
auto maybe_first_overlap = std::upper_bound(polygon_slice.begin(), polygon_slice.end(), traced_poly.lows.back(),
[](const Point &low, const Line &seg) { return seg.b.y() > low.y(); });
[](const Point &low, const Line &seg) { return seg.b.y() < low.y(); });
if (maybe_first_overlap != polygon_slice.begin()) {
maybe_first_overlap--;
}
if (maybe_first_overlap != polygon_slice.end() && // segment exists
segments_overlap(traced_poly.lows.back().y(), traced_poly.highs.back().y(), maybe_first_overlap->a.y(),
maybe_first_overlap->b.y())) // segment is overlapping