From 83b6b82188941744fe7b1a0ad04f5888b7900bb0 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 16 Sep 2019 16:35:08 +0200 Subject: [PATCH 1/2] Refactored ExtrusionEntityCollection::flatten() --- src/libslic3r/ExtrusionEntityCollection.cpp | 26 ++++++++++----------- src/libslic3r/ExtrusionEntityCollection.hpp | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/ExtrusionEntityCollection.cpp b/src/libslic3r/ExtrusionEntityCollection.cpp index 9ae116c47..70c2348af 100644 --- a/src/libslic3r/ExtrusionEntityCollection.cpp +++ b/src/libslic3r/ExtrusionEntityCollection.cpp @@ -11,7 +11,7 @@ ExtrusionEntityCollection::ExtrusionEntityCollection(const ExtrusionPaths &paths this->append(paths); } -ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const ExtrusionEntityCollection &other) +ExtrusionEntityCollection& ExtrusionEntityCollection::operator=(const ExtrusionEntityCollection &other) { this->entities = other.entities; for (size_t i = 0; i < this->entities.size(); ++i) @@ -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(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(entity)); + else + out.append(*entity); + } + } flatten; + flatten.recursive_do(*this); + return flatten.out; } double ExtrusionEntityCollection::min_mm3_per_mm() const diff --git a/src/libslic3r/ExtrusionEntityCollection.hpp b/src/libslic3r/ExtrusionEntityCollection.hpp index 4fe964ee1..221afc453 100644 --- a/src/libslic3r/ExtrusionEntityCollection.hpp +++ b/src/libslic3r/ExtrusionEntityCollection.hpp @@ -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; } From 94212fa2a92b5d01be5da8235f02423249dd7b2a Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 19 Sep 2019 08:56:47 +0200 Subject: [PATCH 2/2] Another fix of admesh on big endian architectures, fixes #2879 --- src/admesh/stl_io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admesh/stl_io.cpp b/src/admesh/stl_io.cpp index af9bb4f98..ddf377c78 100644 --- a/src/admesh/stl_io.cpp +++ b/src/admesh/stl_io.cpp @@ -151,8 +151,8 @@ bool stl_write_binary(stl_file *stl, const char *file, const char *label) memcpy(buffer, &stl->stats.number_of_facets, 4); stl_internal_reverse_quads(buffer, 4); fwrite(buffer, 4, 1, fp); - for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) { - memcpy(buffer, stl->facet_start + i, 50); + for (const stl_facet &facet : stl->facet_start) { + memcpy(buffer, &facet, 50); // Convert to little endian. stl_internal_reverse_quads(buffer, 48); fwrite(buffer, SIZEOF_STL_FACET, 1, fp);