Further Perl unit test porting to C++ and Perl interface reduction:
Ported cooling, gap fill, thin walls and polyline unit tests.
This commit is contained in:
parent
5a67d0e183
commit
d4b8d4d0f3
46 changed files with 1080 additions and 1113 deletions
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include "test_data.hpp" // get access to init_print, etc
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/GCodeReader.hpp"
|
||||
#include "libslic3r/Flow.hpp"
|
||||
|
@ -16,61 +14,118 @@ using namespace Slic3r::Test;
|
|||
using namespace Slic3r;
|
||||
|
||||
SCENARIO("Extrusion width specifics", "[Flow]") {
|
||||
GIVEN("A config with a skirt, brim, some fill density, 3 perimeters, and 1 bottom solid layer and a 20mm cube mesh") {
|
||||
// this is a sharedptr
|
||||
DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "brim_width", 2 },
|
||||
{ "skirts", 1 },
|
||||
{ "perimeters", 3 },
|
||||
{ "fill_density", "40%" },
|
||||
{ "first_layer_height", 0.3 }
|
||||
});
|
||||
|
||||
WHEN("first layer width set to 2mm") {
|
||||
Slic3r::Model model;
|
||||
config.set("first_layer_extrusion_width", 2);
|
||||
Slic3r::Print print;
|
||||
Slic3r::Test::init_print({TestMesh::cube_20x20x20}, print, model, config);
|
||||
|
||||
std::vector<double> E_per_mm_bottom;
|
||||
std::string gcode = Test::gcode(print);
|
||||
Slic3r::GCodeReader parser;
|
||||
const double layer_height = config.opt_float("layer_height");
|
||||
parser.parse_buffer(gcode, [&E_per_mm_bottom, layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
|
||||
{
|
||||
if (self.z() == Approx(layer_height).margin(0.01)) { // only consider first layer
|
||||
if (line.extruding(self) && line.dist_XY(self) > 0) {
|
||||
E_per_mm_bottom.emplace_back(line.dist_E(self) / line.dist_XY(self));
|
||||
}
|
||||
}
|
||||
});
|
||||
THEN(" First layer width applies to everything on first layer.") {
|
||||
bool pass = false;
|
||||
double avg_E = std::accumulate(E_per_mm_bottom.cbegin(), E_per_mm_bottom.cend(), 0.0) / static_cast<double>(E_per_mm_bottom.size());
|
||||
|
||||
pass = (std::count_if(E_per_mm_bottom.cbegin(), E_per_mm_bottom.cend(), [avg_E] (const double& v) { return v == Approx(avg_E); }) == 0);
|
||||
REQUIRE(pass == true);
|
||||
REQUIRE(E_per_mm_bottom.size() > 0); // make sure it actually passed because of extrusion
|
||||
}
|
||||
THEN(" First layer width does not apply to upper layer.") {
|
||||
auto test = [](const DynamicPrintConfig &config) {
|
||||
Slic3r::GCodeReader parser;
|
||||
const double layer_height = config.opt_float("layer_height");
|
||||
std::vector<double> E_per_mm_bottom;
|
||||
parser.parse_buffer(Slic3r::Test::slice({ Slic3r::Test::TestMesh::cube_20x20x20 }, config),
|
||||
[&E_per_mm_bottom, layer_height] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
|
||||
{
|
||||
if (self.z() == Approx(layer_height).margin(0.01)) { // only consider first layer
|
||||
if (line.extruding(self) && line.dist_XY(self) > 0)
|
||||
E_per_mm_bottom.emplace_back(line.dist_E(self) / line.dist_XY(self));
|
||||
}
|
||||
});
|
||||
THEN("First layer width applies to everything on first layer.") {
|
||||
REQUIRE(E_per_mm_bottom.size() > 0);
|
||||
const double E_per_mm_avg = std::accumulate(E_per_mm_bottom.cbegin(), E_per_mm_bottom.cend(), 0.0) / static_cast<double>(E_per_mm_bottom.size());
|
||||
bool pass = (std::count_if(E_per_mm_bottom.cbegin(), E_per_mm_bottom.cend(), [E_per_mm_avg] (const double& v) { return v == Approx(E_per_mm_avg); }) == 0);
|
||||
REQUIRE(pass);
|
||||
}
|
||||
THEN("First layer width does not apply to upper layer.") {
|
||||
}
|
||||
};
|
||||
GIVEN("A config with a skirt, brim, some fill density, 3 perimeters, and 1 bottom solid layer") {
|
||||
auto config = Slic3r::DynamicPrintConfig::full_print_config_with({
|
||||
{ "skirts", 1 },
|
||||
{ "brim_width", 2 },
|
||||
{ "perimeters", 3 },
|
||||
{ "fill_density", "40%" },
|
||||
{ "first_layer_height", 0.3 },
|
||||
{ "first_layer_extrusion_width", "2" },
|
||||
});
|
||||
WHEN("Slicing a 20mm cube") {
|
||||
test(config);
|
||||
}
|
||||
}
|
||||
GIVEN("A config with more options and a 20mm cube ") {
|
||||
auto config = Slic3r::DynamicPrintConfig::full_print_config_with({
|
||||
{ "skirts", 1 },
|
||||
{ "brim_width", 2 },
|
||||
{ "perimeters", 3 },
|
||||
{ "fill_density", "40%" },
|
||||
{ "layer_height", "0.35" },
|
||||
{ "first_layer_height", "0.35" },
|
||||
{ "bottom_solid_layers", 1 },
|
||||
{ "first_layer_extrusion_width", "2" },
|
||||
{ "filament_diameter", "3" },
|
||||
{ "nozzle_diameter", "0.5" }
|
||||
});
|
||||
WHEN("Slicing a 20mm cube") {
|
||||
test(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
// needs gcode export
|
||||
|
||||
SCENARIO(" Bridge flow specifics.", "[Flow]") {
|
||||
auto config = DynamicPrintConfig::full_print_config_with({
|
||||
{ "bridge_speed", 99 },
|
||||
{ "bridge_flow_ratio", 1 },
|
||||
// to prevent speeds from being altered
|
||||
{ "cooling", "0" },
|
||||
// to prevent speeds from being altered
|
||||
{ "first_layer_speed", "100%" }
|
||||
});
|
||||
|
||||
auto test = [](const DynamicPrintConfig &config) {
|
||||
GCodeReader parser;
|
||||
const double bridge_speed = config.opt_float("bridge_speed") * 60.;
|
||||
std::vector<double> E_per_mm;
|
||||
parser.parse_buffer(Slic3r::Test::slice({ Slic3r::Test::TestMesh::overhang }, config),
|
||||
[&E_per_mm, bridge_speed](Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line) {
|
||||
if (line.extruding(self) && line.dist_XY(self) > 0) {
|
||||
if (is_approx<double>(line.new_F(self), bridge_speed))
|
||||
E_per_mm.emplace_back(line.dist_E(self) / line.dist_XY(self));
|
||||
}
|
||||
});
|
||||
const double nozzle_dmr = config.opt<ConfigOptionFloats>("nozzle_diameter")->get_at(0);
|
||||
const double filament_dmr = config.opt<ConfigOptionFloats>("filament_diameter")->get_at(0);
|
||||
const double bridge_mm_per_mm = sqr(nozzle_dmr / filament_dmr) * config.opt_float("bridge_flow_ratio");
|
||||
size_t num_errors = std::count_if(E_per_mm.begin(), E_per_mm.end(),
|
||||
[bridge_mm_per_mm](double v){ return std::abs(v - bridge_mm_per_mm) > 0.01; });
|
||||
return num_errors == 0;
|
||||
};
|
||||
|
||||
GIVEN("A default config with no cooling and a fixed bridge speed, flow ratio and an overhang mesh.") {
|
||||
WHEN("bridge_flow_ratio is set to 1.0") {
|
||||
WHEN("bridge_flow_ratio is set to 0.5 and extrusion width to default") {
|
||||
config.set_deserialize_strict({ { "bridge_flow_ratio", 0.5}, { "extrusion_width", "0" } });
|
||||
THEN("Output flow is as expected.") {
|
||||
REQUIRE(test(config));
|
||||
}
|
||||
}
|
||||
WHEN("bridge_flow_ratio is set to 0.5") {
|
||||
WHEN("bridge_flow_ratio is set to 2.0 and extrusion width to default") {
|
||||
config.set_deserialize_strict({ { "bridge_flow_ratio", 2.0}, { "extrusion_width", "0" } });
|
||||
THEN("Output flow is as expected.") {
|
||||
REQUIRE(test(config));
|
||||
}
|
||||
}
|
||||
WHEN("bridge_flow_ratio is set to 2.0") {
|
||||
WHEN("bridge_flow_ratio is set to 0.5 and extrusion_width to 0.4") {
|
||||
config.set_deserialize_strict({ { "bridge_flow_ratio", 0.5}, { "extrusion_width", 0.4 } });
|
||||
THEN("Output flow is as expected.") {
|
||||
REQUIRE(test(config));
|
||||
}
|
||||
}
|
||||
WHEN("bridge_flow_ratio is set to 1.0 and extrusion_width to 0.4") {
|
||||
config.set_deserialize_strict({ { "bridge_flow_ratio", 1.0}, { "extrusion_width", 0.4 } });
|
||||
THEN("Output flow is as expected.") {
|
||||
REQUIRE(test(config));
|
||||
}
|
||||
}
|
||||
WHEN("bridge_flow_ratio is set to 2 and extrusion_width to 0.4") {
|
||||
config.set_deserialize_strict({ { "bridge_flow_ratio", 2.}, { "extrusion_width", 0.4 } });
|
||||
THEN("Output flow is as expected.") {
|
||||
REQUIRE(test(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue