This commit is contained in:
SoftFever 2022-11-09 22:04:03 +08:00
parent e551fe57b7
commit d3326f9f0c

View file

@ -612,13 +612,18 @@ void PerimeterGenerator::process()
} }
// nest loops: holes first // nest loops: holes first
for (int d = 0; d <= loop_number; ++ d) { int idx;
PerimeterGeneratorLoops &holes_d = holes[d]; for (int d = -1; d < loop_number; ++ d) {
idx = d;
if (idx == -1)
idx = loop_number;
PerimeterGeneratorLoops &holes_d = holes[idx];
// loop through all holes having depth == d // loop through all holes having depth == d
for (int i = 0; i < (int)holes_d.size(); ++ i) { for (int i = 0; i < (int)holes_d.size(); ++ i) {
const PerimeterGeneratorLoop &loop = holes_d[i]; const PerimeterGeneratorLoop &loop = holes_d[i];
// find the hole loop that contains this one, if any // find the hole loop that contains this one, if any
for (int t = d + 1; t <= loop_number; ++ t) { for (int t = idx + 1; t <= loop_number; ++ t) {
for (int j = 0; j < (int)holes[t].size(); ++ j) { for (int j = 0; j < (int)holes[t].size(); ++ j) {
PerimeterGeneratorLoop &candidate_parent = holes[t][j]; PerimeterGeneratorLoop &candidate_parent = holes[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) { if (candidate_parent.polygon.contains(loop.polygon.first_point())) {
@ -645,13 +650,16 @@ void PerimeterGenerator::process()
} }
} }
// nest contour loops // nest contour loops
for (int d = loop_number; d >= 1; -- d) { for (int d = loop_number-1; d >= 0; -- d) {
PerimeterGeneratorLoops &contours_d = contours[d]; idx = d;
if (idx == 0)
idx = loop_number;
PerimeterGeneratorLoops &contours_d = contours[idx];
// loop through all contours having depth == d // loop through all contours having depth == d
for (int i = 0; i < (int)contours_d.size(); ++ i) { for (int i = 0; i < (int)contours_d.size(); ++ i) {
const PerimeterGeneratorLoop &loop = contours_d[i]; const PerimeterGeneratorLoop &loop = contours_d[i];
// find the contour loop that contains it // find the contour loop that contains it
for (int t = d - 1; t >= 0; -- t) { for (int t = idx - 1; t >= 0; -- t) {
for (size_t j = 0; j < contours[t].size(); ++ j) { for (size_t j = 0; j < contours[t].size(); ++ j) {
PerimeterGeneratorLoop &candidate_parent = contours[t][j]; PerimeterGeneratorLoop &candidate_parent = contours[t][j];
if (candidate_parent.polygon.contains(loop.polygon.first_point())) { if (candidate_parent.polygon.contains(loop.polygon.first_point())) {