Fix unsafe section for monotonic

supermerill/SuperSlicer#1889
supermerill/SuperSlicer#1893
This commit is contained in:
supermerill 2021-11-16 20:17:23 +01:00
parent c680aff561
commit 69dec1531d

View File

@ -1277,27 +1277,34 @@ static void pinch_contours_insert_phony_outer_intersections(std::vector<Segmente
for (size_t i_vline = 1; i_vline < segs.size(); ++ i_vline) { for (size_t i_vline = 1; i_vline < segs.size(); ++ i_vline) {
SegmentedIntersectionLine &il = segs[i_vline]; SegmentedIntersectionLine &il = segs[i_vline];
assert(il.intersections.empty() || il.intersections.size() >= 2); assert(il.intersections.empty() || il.intersections.size() >= 2);
if (! il.intersections.empty()) { if (il.intersections.size() > 2) {
//these can trigger....(2 segments, high then low) but less if I check for il.intersections.size() > 2 instead of !empty()
assert(il.intersections.front().type == SegmentIntersection::OUTER_LOW); assert(il.intersections.front().type == SegmentIntersection::OUTER_LOW);
assert(il.intersections.back().type == SegmentIntersection::OUTER_HIGH); assert(il.intersections.back().type == SegmentIntersection::OUTER_HIGH);
auto end = il.intersections.end() - 1; auto end = il.intersections.end() - 1;
insert_after.clear(); insert_after.clear();
for (auto it = il.intersections.begin() + 1; it != end;) { size_t idx = 1;
if (it->type == SegmentIntersection::OUTER_HIGH) { while(idx < il.intersections.size()) {
++ it; if (il.intersections[idx].type == SegmentIntersection::OUTER_HIGH) {
assert(it->type == SegmentIntersection::OUTER_LOW); if (idx + 1 < il.intersections.size()) {
++ it; assert(il.intersections[idx + 1].type == SegmentIntersection::OUTER_LOW);
}
idx += 2;
} else { } else {
auto lo = it; size_t loidx = idx;
assert(lo->type == SegmentIntersection::INNER_LOW); const SegmentIntersection& lo = il.intersections[loidx];
auto hi = ++ it; assert(lo.type == SegmentIntersection::INNER_LOW);
assert(hi->type == SegmentIntersection::INNER_HIGH); size_t hiidx = ++idx;
auto lo2 = ++ it; const SegmentIntersection& hi = il.intersections[hiidx];
if (lo2->type == SegmentIntersection::INNER_LOW) { assert(hi.type == SegmentIntersection::INNER_HIGH);
size_t lo2idx = ++idx;
if (lo2idx < il.intersections.size()) {
const SegmentIntersection& lo2 = il.intersections[lo2idx];
if (lo2.type == SegmentIntersection::INNER_LOW) {
// INNER_HIGH followed by INNER_LOW. The outer contour may have squeezed the inner contour into two separate loops. // INNER_HIGH followed by INNER_LOW. The outer contour may have squeezed the inner contour into two separate loops.
// In that case one shall insert a phony OUTER_HIGH / OUTER_LOW pair. // In that case one shall insert a phony OUTER_HIGH / OUTER_LOW pair.
int up = hi->vertical_up(); int up = hi.vertical_up();
int dn = lo2->vertical_down(); int dn = lo2.vertical_down();
#ifndef _NDEBUG #ifndef _NDEBUG
assert(up == -1 || up > 0); assert(up == -1 || up > 0);
assert(dn == -1 || dn >= 0); assert(dn == -1 || dn >= 0);
@ -1311,7 +1318,8 @@ static void pinch_contours_insert_phony_outer_intersections(std::vector<Segmente
static int pinch_idx = 0; static int pinch_idx = 0;
printf("Pinched %d\n", pinch_idx++); printf("Pinched %d\n", pinch_idx++);
#endif #endif
insert_after.emplace_back(hi - il.intersections.begin()); insert_after.emplace_back(hiidx);
}
} }
} }
} }