Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some more tests #4876

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 94 additions & 3 deletions src/test/libslic3r/test_extrusion_entity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <catch.hpp>
#include "test_data.hpp" // get access to init_print, etc
#include "Config.hpp"
#include "ExtrusionEntityCollection.hpp"
#include "ExtrusionEntity.hpp"
#include "GCodeReader.hpp"
#include "Point.hpp"
#include <cstdlib>

Expand All @@ -27,12 +30,13 @@ ExtrusionPaths random_paths(size_t count=10, size_t length=20, float LO=-50, flo
}

using namespace Slic3r;
using namespace Slic3r::Test;

SCENARIO("ExtrusionEntityCollection: Polygon flattening") {
srand(0xDEADBEEF); // consistent seed for test reproducibility.

// Generate one specific random path set and save it for later comparison
ExtrusionPaths nosort_path_set {random_paths()};
ExtrusionPaths nosort_path_set{ random_paths() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this the result of an automatic code formatter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably


ExtrusionEntityCollection sub_nosort;
sub_nosort.append(nosort_path_set);
Expand All @@ -53,13 +57,13 @@ SCENARIO("ExtrusionEntityCollection: Polygon flattening") {
WHEN("The EEC is flattened with default options (preserve_order=false)") {
sample.flatten(&output);
THEN("The output EEC contains no Extrusion Entity Collections") {
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection();}) == 0);
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection(); }) == 0);
}
}
WHEN("The EEC is flattened with preservation (preserve_order=true)") {
sample.flatten(&output, true);
THEN("The output EECs contains one EEC.") {
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection();}) == 1);
CHECK(std::count_if(output.entities.cbegin(), output.entities.cend(), [=](const ExtrusionEntity* e) {return e->is_collection(); }) == 1);
}
AND_THEN("The ordered EEC contains the same order of elements than the original") {
// find the entity in the collection
Expand All @@ -77,3 +81,90 @@ SCENARIO("ExtrusionEntityCollection: Polygon flattening") {
}
}
}

SCENARIO("ExtrusionEntityCollection: no sort") {
auto config{ Config::new_from_defaults() };
config->set("gcode_comments", true);
config->set("skirts", "0");

Slic3r::Model model;
shared_Print print{ Slic3r::Test::init_print({ TestMesh::cube_20x20x20 }, model, config) };

std::map<double, bool> layers_with_skirt;
std::map<double, bool> layers_with_brim;

print->process();
//replace extrusion from sliceing by manual ones
print->objects[0]->clear_layers();
Layer* customL_layer = print->objects[0]->add_layer(0, 0.2, 0.2, 0.1);
LayerRegion* custom_region = customL_layer->add_region(print->regions[0]);

ExtrusionPath path_peri(ExtrusionRole::erPerimeter);
path_peri.polyline.append(Point{ 0,0 });
path_peri.polyline.append(Point{ scale_(1),scale_(0) });
ExtrusionPath path_fill1(ExtrusionRole::erInternalInfill);
path_fill1.polyline.append(Point{ scale_(1),scale_(0) });
path_fill1.polyline.append(Point{ scale_(2),scale_(0) });
ExtrusionPath path_fill2(ExtrusionRole::erInternalInfill);
path_fill2.polyline.append(Point{ scale_(2),scale_(0) });
path_fill2.polyline.append(Point{ scale_(3),scale_(0) });
ExtrusionEntityCollection coll_fill;
coll_fill.append(path_fill2);
coll_fill.append(path_fill1);
ExtrusionEntityCollection coll_peri;
coll_peri.append(path_peri);


WHEN("sort") {
custom_region->fills.append(coll_fill);
custom_region->perimeters.append(coll_peri);
coll_fill.no_sort = false;
std::stringstream gcode;
Slic3r::Test::gcode(gcode, print);
auto parser{ Slic3r::GCodeReader() };
std::vector<float> extrude_x;
parser.parse_stream(gcode, [](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
{
line.extruding();
if (self.Z == Approx(0.3) || line.new_Z() == Approx(0.3)) {
if (line.extruding() && self.F == Approx(12)) {
}
}
});
parser.parse_stream(gcode, [&extrude_x, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
{
line.extruding();
std::cout << "line.comment='" << line.comment << "'\n";
if (line.comment == " infill" || line.comment == " perimeter" || line.comment == " move to first infill point") {
extrude_x.push_back(line.new_X());
}
});
REQUIRE(extrude_x.size()==3);
REQUIRE(extrude_x[0] == 91);
REQUIRE(extrude_x[1] == 92);
REQUIRE(extrude_x[2] == 93);
}


WHEN("no sort") {
coll_fill.no_sort = true;
custom_region->fills.append(coll_fill);
custom_region->perimeters.append(coll_peri);
std::stringstream gcode;
Slic3r::Test::gcode(gcode, print);
auto parser{ Slic3r::GCodeReader() };
std::vector<float> extrude_x;
parser.parse_stream(gcode, [&extrude_x, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
{
if (line.comment == " infill" || line.comment == " perimeter" || line.comment == " move to first infill point") {
extrude_x.push_back(line.new_X());
}
});
REQUIRE(extrude_x.size() == 5);
REQUIRE(extrude_x[0] == 91);
REQUIRE(extrude_x[1] == 92);
REQUIRE(extrude_x[2] == 93);
REQUIRE(extrude_x[3] == 91);
REQUIRE(extrude_x[4] == 92);
}
}
8 changes: 8 additions & 0 deletions src/test/libslic3r/test_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ SCENARIO("Flow: Flow math for non-bridges", "[!mayfail]") {
auto flow {Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height, 0.0f)};
REQUIRE(flow.width == Approx(1.4*nozzle_diameter));
}
THEN("Min width is respected") {
auto flow{ Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent{0, false}, nozzle_diameter, layer_height, 0.0f) };
REQUIRE(flow.width >= Approx(1.05*nozzle_diameter));
}
}
WHEN("Layer height is set to 0.2") {
layer_height = 0.3f;
THEN("Min width is set.") {
auto flow {Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height, 0.0f)};
REQUIRE(flow.width == Approx(1.05*nozzle_diameter));
}
THEN("Min width is respected.") {
auto flow{ Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent{0, false}, nozzle_diameter, layer_height, 0.0f) };
REQUIRE(flow.width >= Approx(1.05*nozzle_diameter));
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/test/libslic3r/test_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,18 @@ SCENARIO("Print: Brim generation") {
config->set("first_layer_extrusion_width", 0.5);
auto print {Slic3r::Test::init_print({m}, model, config)};
print->make_brim();
THEN("Brim Extrusion collection has 12 loops in it") {
REQUIRE(print->brim.items_count() == 12);
double nbLoops = 6.0 / print->brim_flow().spacing();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here for the extrusion collection?

Copy link
Collaborator Author

@supermerill supermerill Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it that way because I wanted it to check if it makes the correct number of loop and not checking if the spacing is exactly what we tough about it (the layer heigh isn't set, btw)
I should had changes other tests also, i think that only this one bother me at the time because it is so large, a little difference in spacing can change the loop count.

THEN("Brim Extrusion collection has " + std::to_string(nbLoops) + " loops in it (flow="+ std::to_string(print->brim_flow().spacing())+")") {
REQUIRE(print->brim.items_count() == floor(nbLoops));
}
}
WHEN("Brim ears activated, 3mm") {
config->set("brim_width", 3);
config->set("brim_ears", true);
shared_Print print{ Slic3r::Test::init_print({m}, model, config) };
print->process();
THEN("Brim ears Extrusion collection has 4 extrusions in it") {
REQUIRE(print->brim.items_count() == 4);
}
}
}
Expand Down