remove bad algo from keep_types

This commit is contained in:
supermerill 2018-11-29 16:43:41 +01:00
parent 8b9ea5fe1c
commit 5d1e01839c
2 changed files with 18 additions and 7 deletions

View File

@ -1641,7 +1641,7 @@ PrintObject::_discover_neighbor_horizontal_shells(LayerRegion* layerm, const siz
// assign top and bottom surfaces to layer
SurfaceCollection tmp_coll;
for (const auto& s : neighbor_fill_surfaces.surfaces)
if (s.surface_type == stTop || s.is_bottom())
if (s.is_top() || s.is_bottom())
tmp_coll.append(s);
for (auto s : tmp_coll.group()) {

View File

@ -200,12 +200,23 @@ SurfaceCollection::keep_type(const SurfaceType type)
void
SurfaceCollection::keep_types(const SurfaceType *types, size_t ntypes)
{
size_t n {0};
for (size_t i = 0; i < ntypes; ++i)
n |= types[i]; // form bitmask.
// Use stl remove_if to remove
auto ptr = std::remove_if(surfaces.begin(), surfaces.end(),[n] (const Surface& s) { return (s.surface_type & n) != s.surface_type; });
surfaces.erase(ptr, surfaces.cend());
size_t j = 0;
for (size_t i = 0; i < surfaces.size(); ++ i) {
bool keep = false;
for (int k = 0; k < ntypes; ++ k) {
if (surfaces[i].surface_type == types[k]) {
keep = true;
break;
}
}
if (keep) {
if (j < i)
std::swap(surfaces[i], surfaces[j]);
++ j;
}
}
if (j < surfaces.size())
surfaces.erase(surfaces.begin() + j, surfaces.end());
}
void