Refactored ExtrusionEntityCollection::flatten()

This commit is contained in:
bubnikv 2019-09-16 16:35:08 +02:00
parent c38e537adc
commit 83b6b82188
2 changed files with 13 additions and 14 deletions

View File

@ -175,20 +175,20 @@ size_t ExtrusionEntityCollection::items_count() const
}
// Returns a single vector of pointers to all non-collection items contained in this one.
void ExtrusionEntityCollection::flatten(ExtrusionEntityCollection* retval) const
{
for (const ExtrusionEntity *entity : this->entities)
if (entity->is_collection())
retval->append(static_cast<const ExtrusionEntityCollection*>(entity)->flatten().entities);
else
retval->append(*entity);
}
ExtrusionEntityCollection ExtrusionEntityCollection::flatten() const
{
ExtrusionEntityCollection coll;
this->flatten(&coll);
return coll;
struct Flatten {
ExtrusionEntityCollection out;
void recursive_do(const ExtrusionEntityCollection &collection) {
for (const ExtrusionEntity* entity : collection.entities)
if (entity->is_collection())
this->recursive_do(*static_cast<const ExtrusionEntityCollection*>(entity));
else
out.append(*entity);
}
} flatten;
flatten.recursive_do(*this);
return flatten.out;
}
double ExtrusionEntityCollection::min_mm3_per_mm() const

View File

@ -85,7 +85,6 @@ public:
Polygons polygons_covered_by_spacing(const float scaled_epsilon = 0.f) const
{ Polygons out; this->polygons_covered_by_spacing(out, scaled_epsilon); return out; }
size_t items_count() const;
void flatten(ExtrusionEntityCollection* retval) const;
ExtrusionEntityCollection flatten() const;
double min_mm3_per_mm() const;
double total_volume() const override { double volume=0.; for (const auto& ent : entities) volume+=ent->total_volume(); return volume; }