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

Use the constant for clipper offset scale #4997

Open
wants to merge 2 commits 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
12 changes: 6 additions & 6 deletions src/test/libslic3r/test_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,25 @@ SCENARIO("Print: Brim generation") {
config->set("brim_width", 3);
auto print {Slic3r::Test::init_print({m}, model, config)};
print->make_brim();
THEN("Brim Extrusion collection has 3 loops in it") {
REQUIRE(print->brim.items_count() == 3);
THEN("Brim Extrusion collection has 4 loops in it") {
REQUIRE(print->brim.items_count() == 4);
}
}
WHEN("Brim is set to 6mm") {
config->set("brim_width", 6);
auto print {Slic3r::Test::init_print({m}, model, config)};
print->make_brim();
THEN("Brim Extrusion collection has 6 loops in it") {
REQUIRE(print->brim.items_count() == 6);
THEN("Brim Extrusion collection has 7 loops in it") {
REQUIRE(print->brim.items_count() == 7);
}
}
WHEN("Brim is set to 6mm, extrusion width 0.5mm") {
config->set("brim_width", 6);
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);
THEN("Brim Extrusion collection has 13 loops in it") {
REQUIRE(print->brim.items_count() == 13);
}
}
}
Expand Down
42 changes: 38 additions & 4 deletions src/test/libslic3r/test_skirt_brim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
Slic3r::Model model;
auto gcode {std::stringstream("")};
gcode.clear();
const double used_layer_height = 0.01;
GIVEN("A default configuration") {
auto config {Config::new_from_defaults()};
config->set("support_material_speed", 99);
config->set("first_layer_height", 0.3);
config->set("first_layer_height", used_layer_height);
config->set("gcode_comments", true);

// avoid altering speeds unexpectedly
config->set("cooling", false);
config->set("first_layer_speed", "100%");
Expand All @@ -88,21 +88,55 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
config->set("perimeters", 0);
config->set("skirts", 0);
config->set("brim_width", 5);
config->set("interior_brim_width", 0);
config->set("brim_connections_width", 0);
config->set("first_layer_extrusion_width", 0.10);
config->set("extrusion_width", 0.10);
config->set("nozzle_diameter", "0.05");
THEN("Configuration is sane.") {
REQUIRE(config->get<ConfigOptionFloatOrPercent>("first_layer_extrusion_width").get_abs_value(used_layer_height) > 0.05);
REQUIRE(used_layer_height < 0.05);
}
THEN("Brim is generated") {
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)};
Slic3r::Test::gcode(gcode, print);
bool brim_generated = false;
auto support_speed = config->get<ConfigOptionFloat>("support_material_speed") * MM_PER_MIN;
parser.parse_stream(gcode, [&brim_generated, support_speed] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
parser.parse_stream(gcode, [&brim_generated, support_speed, used_layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
{
if (self.Z == Approx(0.3) || line.new_Z() == Approx(0.3)) {
if (self.Z == Approx(used_layer_height) || line.new_Z() == Approx(used_layer_height)) {
if (line.extruding() && self.F == Approx(support_speed)) {
brim_generated = true;
}
}
});
REQUIRE(brim_generated);
}
THEN("Brim width is 5mm around the object.") {
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config, false, Slic3r::Pointf(0, 0))};
Slic3r::Test::gcode(gcode, print);
double max_x = 0, min_x = 0, max_y = 0, min_y = 0;
auto support_speed = config->get<ConfigOptionFloat>("support_material_speed") * MM_PER_MIN;
auto line_width = config->get<ConfigOptionFloatOrPercent>("first_layer_extrusion_width").get_abs_value(used_layer_height);
auto brim = config->get<ConfigOptionFloat>("brim_width");
parser.parse_stream(gcode, [&max_x, &max_y, &min_x, &min_y, line_width, support_speed, used_layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
{
if (self.Z == Approx(used_layer_height) || line.new_Z() == Approx(used_layer_height)) {
if (line.extruding() && self.F == Approx(support_speed)) {
max_x = std::max(double(self.X), max_x);
min_x = std::min(double(self.X), min_x);
max_y = std::max(double(self.Y), max_y);
min_y = std::min(double(self.Y), min_y);
}
}
});
// match the centerline of our extrusion min/max, should be very close to +/-15mm
REQUIRE(max_x == Approx(15.0-(line_width / 2.0)).epsilon(line_width * 0.01));
REQUIRE(max_y == Approx(15.0-(line_width / 2.0)).epsilon(line_width * 0.01));
REQUIRE(min_x == Approx(-15.0+(line_width / 2.0)).epsilon(line_width * 0.01));
REQUIRE(min_y == Approx(-15.0+(line_width / 2.0)).epsilon(line_width * 0.01));
}

}

WHEN("Skirt area is smaller than the brim") {
Expand Down
8 changes: 4 additions & 4 deletions src/test/test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ TriangleMesh mesh(TestMesh m) {
}


shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& model, config_ptr _config, bool comments) {
shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& model, config_ptr _config, bool comments, Slic3r::Pointf center) {
auto config {Slic3r::Config::new_from_defaults()};
config->apply(_config);

Expand All @@ -224,7 +224,7 @@ shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& m
}

model.arrange_objects(print->config.min_object_distance());
model.center_instances_around_point(Slic3r::Pointf(100,100));
model.center_instances_around_point(center);
for (auto* mo : model.objects) {
print->auto_assign_extruders(mo);
print->add_model_object(mo);
Expand All @@ -234,7 +234,7 @@ shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& m

return print;
}
shared_Print init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Model& model, config_ptr _config, bool comments) {
shared_Print init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Model& model, config_ptr _config, bool comments, Slic3r::Pointf center) {
auto config {Slic3r::Config::new_from_defaults()};
config->apply(_config);

Expand All @@ -257,7 +257,7 @@ shared_Print init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Mode
}

model.arrange_objects(print->config.min_object_distance());
model.center_instances_around_point(Slic3r::Pointf(100,100));
model.center_instances_around_point(center);
for (auto* mo : model.objects) {
print->auto_assign_extruders(mo);
print->add_model_object(mo);
Expand Down
4 changes: 2 additions & 2 deletions src/test/test_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ bool _equiv(const T& a, const T& b, double epsilon) { return abs(a - b) < epsilo

Slic3r::Model model(const std::string& model_name, TriangleMesh&& _mesh);

shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false);
shared_Print init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false);
shared_Print init_print(std::initializer_list<TestMesh> meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false, Slic3r::Pointf center = Slic3r::Pointf(100,100));
shared_Print init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Model& model, config_ptr _config = Slic3r::Config::new_from_defaults(), bool comments = false, Slic3r::Pointf center = Slic3r::Pointf(100,100));

void gcode(std::stringstream& gcode, shared_Print print);

Expand Down
4 changes: 2 additions & 2 deletions xs/src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ Print::_make_brim()

Polygons loops;
const int num_loops = floor(this->config.brim_width / flow.width + 0.5);
for (int i = num_loops; i >= 1; --i) {
for (int i = num_loops+1; i >= 1; --i) {
// JT_SQUARE ensures no vertex is outside the given offset distance
// -0.5 because islands are not represented by their centerlines
// (first offset more, then step back - reverse order than the one used for
Expand All @@ -1127,7 +1127,7 @@ Print::_make_brim()
islands,
flow.scaled_width() + flow.scaled_spacing() * (i - 1.5 + 0.5),
flow.scaled_spacing() * -0.525, // WORKAROUND for brim placement, original 0.5 leaves too much of a gap.
100000,
CLIPPER_OFFSET_SCALE,
ClipperLib::jtSquare
));
}
Expand Down