mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-16 15:35:51 +08:00
Fix unsafe section for monotonic
supermerill/SuperSlicer#1889 supermerill/SuperSlicer#1893
This commit is contained in:
parent
c680aff561
commit
69dec1531d
@ -1253,7 +1253,7 @@ static void connect_segment_intersections_by_contours(
|
|||||||
SegmentIntersection& it2 = il.intersections[it.left_vertical()];
|
SegmentIntersection& it2 = il.intersections[it.left_vertical()];
|
||||||
assert(it2.left_vertical() == i_intersection);
|
assert(it2.left_vertical() == i_intersection);
|
||||||
it2.prev_on_contour_quality = SegmentIntersection::LinkQuality::Invalid;
|
it2.prev_on_contour_quality = SegmentIntersection::LinkQuality::Invalid;
|
||||||
}
|
}
|
||||||
if (it.has_right_vertical() && it.next_on_contour_quality == SegmentIntersection::LinkQuality::Invalid) {
|
if (it.has_right_vertical() && it.next_on_contour_quality == SegmentIntersection::LinkQuality::Invalid) {
|
||||||
SegmentIntersection& it2 = il.intersections[it.right_vertical()];
|
SegmentIntersection& it2 = il.intersections[it.right_vertical()];
|
||||||
assert(it2.right_vertical() == i_intersection);
|
assert(it2.right_vertical() == i_intersection);
|
||||||
@ -1263,7 +1263,7 @@ static void connect_segment_intersections_by_contours(
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(validate_segment_intersection_connectivity(segs));
|
assert(validate_segment_intersection_connectivity(segs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pinch_contours_insert_phony_outer_intersections(std::vector<SegmentedIntersectionLine> &segs)
|
static void pinch_contours_insert_phony_outer_intersections(std::vector<SegmentedIntersectionLine> &segs)
|
||||||
{
|
{
|
||||||
@ -1277,41 +1277,49 @@ 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);
|
||||||
// INNER_HIGH followed by INNER_LOW. The outer contour may have squeezed the inner contour into two separate loops.
|
size_t lo2idx = ++idx;
|
||||||
// In that case one shall insert a phony OUTER_HIGH / OUTER_LOW pair.
|
if (lo2idx < il.intersections.size()) {
|
||||||
int up = hi->vertical_up();
|
const SegmentIntersection& lo2 = il.intersections[lo2idx];
|
||||||
int dn = lo2->vertical_down();
|
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.
|
||||||
|
// In that case one shall insert a phony OUTER_HIGH / OUTER_LOW pair.
|
||||||
|
int up = hi.vertical_up();
|
||||||
|
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);
|
||||||
assert((up == -1 && dn == -1) || (dn + 1 == up));
|
assert((up == -1 && dn == -1) || (dn + 1 == up));
|
||||||
#endif // _NDEBUG
|
#endif // _NDEBUG
|
||||||
bool pinched = dn + 1 != up;
|
bool pinched = dn + 1 != up;
|
||||||
if (pinched) {
|
if (pinched) {
|
||||||
// hi is not connected with its inner contour to lo2.
|
// hi is not connected with its inner contour to lo2.
|
||||||
// Insert a phony OUTER_HIGH / OUTER_LOW pair.
|
// Insert a phony OUTER_HIGH / OUTER_LOW pair.
|
||||||
#if 0
|
#if 0
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user