From 36bb57c6a865d733f1bbc37598a15a9695f53e8d Mon Sep 17 00:00:00 2001 From: supermerill Date: Tue, 29 Oct 2019 18:10:11 +0100 Subject: [PATCH] tests from mainline some cleaning in Medial axis. --- src/libslic3r/MedialAxis.cpp | 5 +-- src/libslic3r/Print.cpp | 20 ++++++++-- src/libslic3r/Print.hpp | 4 +- src/test/libslic3r/test_gcodewriter.cpp | 27 +++++++++++++ src/test/libslic3r/test_model.cpp | 1 + src/test/libslic3r/test_print.cpp | 51 ++++++++++++++++++++++++- src/test/libslic3r/test_printgcode.cpp | 44 +++++++++++++++++++++ 7 files changed, 143 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/MedialAxis.cpp b/src/libslic3r/MedialAxis.cpp index 1f822f82d..b5d207012 100644 --- a/src/libslic3r/MedialAxis.cpp +++ b/src/libslic3r/MedialAxis.cpp @@ -112,6 +112,7 @@ MedialAxis::polyline_from_voronoi(const Lines& voronoi_edges, ThickPolylines* po assert(polyline.width.size() == polyline.points.size()); // if loop, set endpoints to false + // prevent loop endpoints from being extended if (polyline.first_point().coincides_with(polyline.last_point())) { polyline.endpoints.first = false; polyline.endpoints.second = false; @@ -511,8 +512,6 @@ MedialAxis::fusion_curve(ThickPolylines &pp) } } sum_dot = abs(sum_dot); - //std::cout << " with mindot= " << min_dot << "< 0.5" << " ; with sum_dot= " << sum_dot << "< 0.2" << " ; with crosspoint.size= " << crosspoint.size() << " ; with coeff_contour_angle= " << coeff_contour_angle << " 0.2> " << (1 - (coeff_contour_angle / (PI / 2))) - //<< " ; length= " << unscaled(polyline.length())<<" >? 1.42*width= "<< polyline.width.front()<<"->"<< polyline.width.back() << "\n"; //only consider very shallow angle for contour if (mindot > 0.15 && @@ -640,7 +639,7 @@ MedialAxis::fusion_corners(ThickPolylines &pp) void MedialAxis::extends_line_both_side(ThickPolylines& pp) { - const ExPolygons anchors = offset2_ex(diff_ex(*this->bounds, this->expolygon), double(-SCALED_RESOLUTION), double(SCALED_RESOLUTION)); + const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(*this->bounds, this->expolygon)), double(-SCALED_RESOLUTION), double(SCALED_RESOLUTION)); for (size_t i = 0; i < pp.size(); ++i) { ThickPolyline& polyline = pp[i]; this->extends_line(polyline, anchors, this->min_width); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 59e696502..019f8d541 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -227,8 +227,9 @@ bool Print::invalidate_state_by_config_options(const std::vectorinvalidate_all_steps(); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index c93f5219a..004cabae1 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -374,6 +374,8 @@ public: // Accessed by SupportMaterial const PrintRegion* get_region(size_t idx) const { return m_regions[idx]; } + //put this in public to be accessible for tests, it was in private before. + bool invalidate_state_by_config_options(const std::vector &opt_keys); protected: // methods for handling regions PrintRegion* get_region(size_t idx) { return m_regions[idx]; } @@ -391,8 +393,6 @@ private: DynamicPrintConfig &placeholder_parser_overrides, DynamicPrintConfig &filament_overrides) const; - bool invalidate_state_by_config_options(const std::vector &opt_keys); - void _make_skirt(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out); ExPolygons _make_brim(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out); ExPolygons _make_brim_ears(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out); diff --git a/src/test/libslic3r/test_gcodewriter.cpp b/src/test/libslic3r/test_gcodewriter.cpp index 3b0c3d815..c3cd56982 100644 --- a/src/test/libslic3r/test_gcodewriter.cpp +++ b/src/test/libslic3r/test_gcodewriter.cpp @@ -111,3 +111,30 @@ SCENARIO("lift() is not ignored after unlift() at normal values of Z") { } } } + +SCENARIO("set_speed emits values with fixed-point output.") { + + GIVEN("GCodeWriter instance") { + GCodeWriter writer; + WHEN("set_speed is called to set speed to 1.09321e+06") { + THEN("Output string is G1 F1093210.000") { + REQUIRE_THAT(writer.set_speed(1.09321e+06), Catch::Equals("G1 F1093210.000\n")); + } + } + WHEN("set_speed is called to set speed to 1") { + THEN("Output string is G1 F1.000") { + REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1.000\n")); + } + } + WHEN("set_speed is called to set speed to 203.200022") { + THEN("Output string is G1 F203.200") { + REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.200\n")); + } + } + WHEN("set_speed is called to set speed to 203.200522") { + THEN("Output string is G1 F203.200") { + REQUIRE_THAT(writer.set_speed(203.200522), Catch::Equals("G1 F203.201\n")); + } + } + } +} diff --git a/src/test/libslic3r/test_model.cpp b/src/test/libslic3r/test_model.cpp index 305b32d5c..8fdff8bd6 100644 --- a/src/test/libslic3r/test_model.cpp +++ b/src/test/libslic3r/test_model.cpp @@ -70,6 +70,7 @@ SCENARIO("xy compensations"){ Point{ 200, 200 }, Point{ 100, 200 }} }; THEN("elephant and xy can compensate each other"){ +//TODO } THEN("hole and xy can compensate each othere"){ } diff --git a/src/test/libslic3r/test_print.cpp b/src/test/libslic3r/test_print.cpp index 27f1fb199..3951cf14f 100644 --- a/src/test/libslic3r/test_print.cpp +++ b/src/test/libslic3r/test_print.cpp @@ -68,10 +68,59 @@ SCENARIO("Print: Skirt generation") { } } +void test_is_solid_infill(Print &p, size_t obj_id, size_t layer_id ) { + const PrintObject& obj { *(p.objects().at(obj_id)) }; + const Layer& layer { *(obj.get_layer(layer_id)) }; + + // iterate over all of the regions in the layer + for (const LayerRegion* reg : layer.regions()) { + // for each region, iterate over the fill surfaces + for (const Surface& s : reg->fill_surfaces.surfaces) { + CHECK(s.has_fill_solid()); + } + } +} + +SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces to become internal.") { + GIVEN("sliced 20mm cube and config with top_solid_surfaces = 2 and bottom_solid_surfaces = 1") { + DynamicPrintConfig *config = Slic3r::DynamicPrintConfig::new_from_defaults(); + TestMesh m { TestMesh::cube_20x20x20 }; + config->set_key_value("top_solid_layers", new ConfigOptionInt(2)); + config->set_key_value("bottom_solid_layers", new ConfigOptionInt(1)); + config->set_key_value("layer_height", new ConfigOptionFloat(0.5)); // get a known number of layers + config->set_key_value("first_layer_height", new ConfigOptionFloat(0.5)); + Slic3r::Model model; + auto event_counter {0U}; + std::string stage; + Print print{}; + Slic3r::Test::init_print(print, { m }, model, config); + print.process(); + // Precondition: Ensure that the model has 2 solid top layers (39, 38) + // and one solid bottom layer (0). + test_is_solid_infill(print, 0, 0); // should be solid + test_is_solid_infill(print, 0, 39); // should be solid + test_is_solid_infill(print, 0, 38); // should be solid + WHEN("Model is re-sliced with top_solid_layers == 3") { + ((ConfigOptionInt&)(print.regions()[0]->config().top_solid_layers)).value = 3; + print.invalidate_state_by_config_options(std::vector{ "posPrepareInfill" }); + print.process(); + THEN("Print object does not have 0 solid bottom layers.") { + test_is_solid_infill(print, 0, 0); + } + AND_THEN("Print object has 3 top solid layers") { + test_is_solid_infill(print, 0, 39); + test_is_solid_infill(print, 0, 38); + test_is_solid_infill(print, 0, 37); + } + } + } + +} + SCENARIO("Print: Brim generation") { GIVEN("20mm cube and default config, 1mm first layer width") { DynamicPrintConfig *config = Slic3r::DynamicPrintConfig::new_from_defaults(); - TestMesh m = TestMesh::cube_20x20x20; + TestMesh m{ TestMesh::cube_20x20x20 }; Slic3r::Model model{}; config->set_key_value("first_layer_extrusion_width", new ConfigOptionFloatOrPercent(1, false)); WHEN("Brim is set to 3mm") { diff --git a/src/test/libslic3r/test_printgcode.cpp b/src/test/libslic3r/test_printgcode.cpp index 67577875b..873aa0da3 100644 --- a/src/test/libslic3r/test_printgcode.cpp +++ b/src/test/libslic3r/test_printgcode.cpp @@ -224,6 +224,50 @@ SCENARIO( "PrintGCode basic functionality") { REQUIRE(exported.find("; Layer_z 20") != std::string::npos); } } + WHEN("current_extruder exists in start_gcode") { + config->set("start_gcode", "; Extruder [current_extruder]"); + { + Slic3r::Model model; + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)}; + Slic3r::Test::gcode(gcode, print); + auto exported {gcode.str()}; + THEN("current_extruder is processed in the start gcode and set for first extruder") { + REQUIRE(exported.find("; Extruder 0") != std::string::npos); + } + } + config->set("solid_infill_extruder", 2); + config->set("support_material_extruder", 2); + config->set("infill_extruder", 2); + config->set("perimeter_extruder", 2); + { + Slic3r::Model model; + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)}; + Slic3r::Test::gcode(gcode, print); + auto exported {gcode.str()}; + THEN("current_extruder is processed in the start gcode and set for second extruder") { + REQUIRE(exported.find("; Extruder 1") != std::string::npos); + } + } + } + + WHEN("layer_num represents the layer's index from z=0") { + config->set("layer_gcode", ";Layer:[layer_num] ([layer_z] mm)"); + config->set("layer_height", 1.0); + config->set("first_layer_height", 1.0); + + Slic3r::Model model; + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20,TestMesh::cube_20x20x20}, model, config)}; + Slic3r::Test::gcode(gcode, print); + + auto exported {gcode.str()}; + int count = 2; + for(int pos = 0; pos != std::string::npos; count--) + pos = exported.find(";Layer:38 (20 mm)", pos+1); + + THEN("layer_num and layer_z are processed in the end gcode") {\ + REQUIRE(count == -1); + } + } gcode.clear(); }