fixed center-finding algorithm
This commit is contained in:
parent
e78221409a
commit
5d6bf3261e
@ -5,6 +5,7 @@
|
|||||||
#include "libslic3r/BoundingBox.hpp"
|
#include "libslic3r/BoundingBox.hpp"
|
||||||
#include "libslic3r/EdgeGrid.hpp"
|
#include "libslic3r/EdgeGrid.hpp"
|
||||||
#include "libslic3r/ClipperUtils.hpp"
|
#include "libslic3r/ClipperUtils.hpp"
|
||||||
|
#include "libslic3r/SVG.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -413,24 +414,27 @@ static std::vector<size_t> find_enforcer_centers(const Polygon& polygon,
|
|||||||
};
|
};
|
||||||
|
|
||||||
int last_enforcer_start_idx = enforcers_idxs.front();
|
int last_enforcer_start_idx = enforcers_idxs.front();
|
||||||
|
bool first_pt_in_list = enforcers_idxs.front() != 0;
|
||||||
bool last_pt_in_list = enforcers_idxs.back() == polygon.points.size() - 1;
|
bool last_pt_in_list = enforcers_idxs.back() == polygon.points.size() - 1;
|
||||||
|
bool wrap_around = last_pt_in_list && first_pt_in_list;
|
||||||
|
|
||||||
for (size_t i=0; i<enforcers_idxs.size()-1; ++i) {
|
for (size_t i=0; i<enforcers_idxs.size(); ++i) {
|
||||||
if ((i == enforcers_idxs.size() - 1)
|
if (i != enforcers_idxs.size() - 1) {
|
||||||
|| enforcers_idxs[i+1] != enforcers_idxs[i] + 1) {
|
if (enforcers_idxs[i+1] != enforcers_idxs[i] + 1) {
|
||||||
// i is last point of current enforcer
|
// i is last point of current enforcer
|
||||||
out.push_back(get_center_idx(last_enforcer_start_idx, enforcers_idxs[i]));
|
out.push_back(get_center_idx(last_enforcer_start_idx, enforcers_idxs[i]));
|
||||||
last_enforcer_start_idx = enforcers_idxs[i+1];
|
last_enforcer_start_idx = enforcers_idxs[i+1];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (! wrap_around) {
|
||||||
|
// we can safely use the last enforcer point.
|
||||||
|
out.push_back(get_center_idx(last_enforcer_start_idx, enforcers_idxs[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_pt_in_list) {
|
if (wrap_around) {
|
||||||
// last point is an enforcer - not yet accounted for.
|
// Update first center already found.
|
||||||
if (enforcers_idxs.front() != 0) {
|
|
||||||
size_t center_idx = get_center_idx(last_enforcer_start_idx, enforcers_idxs.back());
|
|
||||||
out.push_back(center_idx);
|
|
||||||
} else {
|
|
||||||
// Wrap-around. Update first center already found.
|
|
||||||
if (out.empty()) {
|
if (out.empty()) {
|
||||||
// Probably an enforcer around the whole contour. Return nothing.
|
// Probably an enforcer around the whole contour. Return nothing.
|
||||||
return out;
|
return out;
|
||||||
@ -452,7 +456,6 @@ static std::vector<size_t> find_enforcer_centers(const Polygon& polygon,
|
|||||||
--out[0];
|
--out[0];
|
||||||
assert(out[0] < lengths.size() - 1);
|
assert(out[0] < lengths.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user