From 8e27e355c2bb8450459d6f031cddab968bd67a3f Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 8 Mar 2021 14:29:23 +0100 Subject: [PATCH] Fixing unit tests. --- t/support.t | 1 - tests/fff_print/test_flow.cpp | 51 ++++--------------- .../test_elephant_foot_compensation.cpp | 22 ++++---- xs/lib/Slic3r/XS.pm | 3 +- xs/xsp/Flow.xsp | 21 +++----- xs/xsp/Layer.xsp | 4 +- xs/xsp/Print.xsp | 3 -- 7 files changed, 30 insertions(+), 75 deletions(-) diff --git a/t/support.t b/t/support.t index a0cac1470..0283df22b 100644 --- a/t/support.t +++ b/t/support.t @@ -31,7 +31,6 @@ use Slic3r::Test; role => FLOW_ROLE_SUPPORT_MATERIAL, nozzle_diameter => $print->config->nozzle_diameter->[$object_config->support_material_extruder-1] // $print->config->nozzle_diameter->[0], layer_height => $object_config->layer_height, - bridge_flow_ratio => 0, ); my $support = Slic3r::Print::SupportMaterial->new( object_config => $print->print->objects->[0]->config, diff --git a/tests/fff_print/test_flow.cpp b/tests/fff_print/test_flow.cpp index 63b62a4d7..b679a07e3 100644 --- a/tests/fff_print/test_flow.cpp +++ b/tests/fff_print/test_flow.cpp @@ -96,43 +96,41 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") { GIVEN("Nozzle Diameter of 0.4, a desired width of 1mm and layer height of 0.5") { ConfigOptionFloatOrPercent width(1.0, false); float nozzle_diameter = 0.4f; - float bridge_flow = 0.f; float layer_height = 0.5f; // Spacing for non-bridges is has some overlap THEN("External perimeter flow has spacing fixed to 1.125 * nozzle_diameter") { - auto flow = Flow::new_from_config_width(frExternalPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height, bridge_flow); + auto flow = Flow::new_from_config_width(frExternalPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height); REQUIRE(flow.spacing() == Approx(1.125 * nozzle_diameter - layer_height * (1.0 - PI / 4.0))); } THEN("Internal perimeter flow has spacing fixed to 1.125 * nozzle_diameter") { - auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height, bridge_flow); + auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height); REQUIRE(flow.spacing() == Approx(1.125 *nozzle_diameter - layer_height * (1.0 - PI / 4.0))); } THEN("Spacing for supplied width is 0.8927f") { - auto flow = Flow::new_from_config_width(frExternalPerimeter, width, nozzle_diameter, layer_height, bridge_flow); + auto flow = Flow::new_from_config_width(frExternalPerimeter, width, nozzle_diameter, layer_height); REQUIRE(flow.spacing() == Approx(width.value - layer_height * (1.0 - PI / 4.0))); - flow = Flow::new_from_config_width(frPerimeter, width, nozzle_diameter, layer_height, bridge_flow); + flow = Flow::new_from_config_width(frPerimeter, width, nozzle_diameter, layer_height); REQUIRE(flow.spacing() == Approx(width.value - layer_height * (1.0 - PI / 4.0))); } } /// Check the min/max GIVEN("Nozzle Diameter of 0.25") { float nozzle_diameter = 0.25f; - float bridge_flow = 0.f; float layer_height = 0.5f; WHEN("layer height is set to 0.2") { layer_height = 0.15f; THEN("Max width is set.") { - auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height, bridge_flow); - REQUIRE(flow.width == Approx(1.125 * nozzle_diameter)); + auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height); + REQUIRE(flow.width() == Approx(1.125 * 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, bridge_flow); - REQUIRE(flow.width == Approx(1.125 * nozzle_diameter)); + auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height); + REQUIRE(flow.width() == Approx(1.125 * nozzle_diameter)); } } } @@ -158,41 +156,12 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") { /// Spacing, width calculation for bridge extrusions SCENARIO("Flow: Flow math for bridges", "[Flow]") { GIVEN("Nozzle Diameter of 0.4, a desired width of 1mm and layer height of 0.5") { - auto width = ConfigOptionFloatOrPercent(1.0, false); float nozzle_diameter = 0.4f; float bridge_flow = 1.0f; - float layer_height = 0.5f; WHEN("Flow role is frExternalPerimeter") { - auto flow = Flow::new_from_config_width(frExternalPerimeter, width, nozzle_diameter, layer_height, bridge_flow); + auto flow = Flow::bridging_flow(nozzle_diameter * sqrt(bridge_flow), nozzle_diameter); THEN("Bridge width is same as nozzle diameter") { - REQUIRE(flow.width == Approx(nozzle_diameter)); - } - THEN("Bridge spacing is same as nozzle diameter + BRIDGE_EXTRA_SPACING") { - REQUIRE(flow.spacing() == Approx(nozzle_diameter + BRIDGE_EXTRA_SPACING)); - } - } - WHEN("Flow role is frInfill") { - auto flow = Flow::new_from_config_width(frInfill, width, nozzle_diameter, layer_height, bridge_flow); - THEN("Bridge width is same as nozzle diameter") { - REQUIRE(flow.width == Approx(nozzle_diameter)); - } - THEN("Bridge spacing is same as nozzle diameter + BRIDGE_EXTRA_SPACING") { - REQUIRE(flow.spacing() == Approx(nozzle_diameter + BRIDGE_EXTRA_SPACING)); - } - } - WHEN("Flow role is frPerimeter") { - auto flow = Flow::new_from_config_width(frPerimeter, width, nozzle_diameter, layer_height, bridge_flow); - THEN("Bridge width is same as nozzle diameter") { - REQUIRE(flow.width == Approx(nozzle_diameter)); - } - THEN("Bridge spacing is same as nozzle diameter + BRIDGE_EXTRA_SPACING") { - REQUIRE(flow.spacing() == Approx(nozzle_diameter + BRIDGE_EXTRA_SPACING)); - } - } - WHEN("Flow role is frSupportMaterial") { - auto flow = Flow::new_from_config_width(frSupportMaterial, width, nozzle_diameter, layer_height, bridge_flow); - THEN("Bridge width is same as nozzle diameter") { - REQUIRE(flow.width == Approx(nozzle_diameter)); + REQUIRE(flow.width() == Approx(nozzle_diameter)); } THEN("Bridge spacing is same as nozzle diameter + BRIDGE_EXTRA_SPACING") { REQUIRE(flow.spacing() == Approx(nozzle_diameter + BRIDGE_EXTRA_SPACING)); diff --git a/tests/libslic3r/test_elephant_foot_compensation.cpp b/tests/libslic3r/test_elephant_foot_compensation.cpp index 180f678c5..4e340c37a 100644 --- a/tests/libslic3r/test_elephant_foot_compensation.cpp +++ b/tests/libslic3r/test_elephant_foot_compensation.cpp @@ -434,7 +434,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { ExPolygon expoly = contour_with_hole(); WHEN("Compensated") { // Elephant foot compensation shall not pinch off bits from this contour. - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.2f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.2f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_with_hole.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -449,7 +449,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { GIVEN("Tiny contour") { ExPolygon expoly({ { 133382606, 94912473 }, { 134232493, 95001115 }, { 133783926, 95159440 }, { 133441897, 95180666 }, { 133408242, 95191984 }, { 133339012, 95166830 }, { 132991642, 95011087 }, { 133206549, 94908304 } }); WHEN("Compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.2f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.2f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_tiny.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -464,7 +464,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { GIVEN("Large box") { ExPolygon expoly( { {50000000, 50000000 }, { 0, 50000000 }, { 0, 0 }, { 50000000, 0 } } ); WHEN("Compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.21f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.21f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_large_box.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -479,7 +479,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { GIVEN("Thin ring (GH issue #2085)") { ExPolygon expoly = thin_ring(); WHEN("Compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.25f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.25f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_thin_ring.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -532,7 +532,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { expoly = union_ex({ expoly, expoly2 }).front(); WHEN("Partially compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f, false), 0.25f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f), 0.25f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_0.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -543,7 +543,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { } } WHEN("Fully compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.35f, 0.2f, 0.4f, false), 0.17f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.35f, 0.2f, 0.4f), 0.17f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_1.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -558,7 +558,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { GIVEN("Box with hole close to wall (GH issue #2998)") { ExPolygon expoly = box_with_hole_close_to_wall(); WHEN("Compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.25f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.25f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_2.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -575,7 +575,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { ExPolygon expoly = spirograph_gear_1mm(); WHEN("Partially compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f, false), 0.25f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f), 0.25f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_2.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -586,7 +586,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { } } WHEN("Fully compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.35f, 0.2f, 0.4f, false), 0.17f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.35f, 0.2f, 0.4f), 0.17f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_3.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -597,7 +597,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { } } WHEN("Brutally compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f, false), 0.6f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.45f, 0.2f, 0.4f), 0.6f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_4.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, @@ -612,7 +612,7 @@ SCENARIO("Elephant foot compensation", "[ElephantFoot]") { GIVEN("Vase with fins") { ExPolygon expoly = vase_with_fins(); WHEN("Compensated") { - ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f, false), 0.41f); + ExPolygon expoly_compensated = elephant_foot_compensation(expoly, Flow(0.419999987f, 0.2f, 0.4f), 0.41f); #ifdef TESTS_EXPORT_SVGS SVG::export_expolygons(debug_out_path("elephant_foot_compensation_vase_with_fins.svg").c_str(), { { { expoly }, { "gray", "black", "blue", coord_t(scale_(0.02)), 0.5f, "black", coord_t(scale_(0.05)) } }, diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index fa4dde43a..6d3bf35cf 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -158,7 +158,6 @@ sub new { my $self = $class->_new( @args{qw(width height nozzle_diameter)}, ); - $self->set_bridge($args{bridge} // 0); return $self; } @@ -166,7 +165,7 @@ sub new_from_width { my ($class, %args) = @_; return $class->_new_from_width( - @args{qw(role width nozzle_diameter layer_height bridge_flow_ratio)}, + @args{qw(role width nozzle_diameter layer_height)}, ); } diff --git a/xs/xsp/Flow.xsp b/xs/xsp/Flow.xsp index b57df5e37..6962085d5 100644 --- a/xs/xsp/Flow.xsp +++ b/xs/xsp/Flow.xsp @@ -8,21 +8,13 @@ %name{Slic3r::Flow} class Flow { ~Flow(); %name{_new} Flow(float width, float height, float nozzle_diameter); - void set_height(float height) - %code{% THIS->height = height; %}; - void set_bridge(bool bridge) - %code{% THIS->bridge = bridge; %}; Clone clone() %code{% RETVAL = THIS; %}; - float width() - %code{% RETVAL = THIS->width; %}; - float height() - %code{% RETVAL = THIS->height; %}; - float nozzle_diameter() - %code{% RETVAL = THIS->nozzle_diameter; %}; - bool bridge() - %code{% RETVAL = THIS->bridge; %}; + float width(); + float height(); + float nozzle_diameter(); + bool bridge(); float spacing(); float spacing_to(Flow* other) %code{% RETVAL = THIS->spacing(*other); %}; @@ -32,17 +24,16 @@ %{ Flow* -_new_from_width(CLASS, role, width, nozzle_diameter, height, bridge_flow_ratio) +_new_from_width(CLASS, role, width, nozzle_diameter, height) char* CLASS; FlowRole role; std::string width; float nozzle_diameter; float height; - float bridge_flow_ratio; CODE: ConfigOptionFloatOrPercent optwidth; optwidth.deserialize(width); - RETVAL = new Flow(Flow::new_from_config_width(role, optwidth, nozzle_diameter, height, bridge_flow_ratio)); + RETVAL = new Flow(Flow::new_from_config_width(role, optwidth, nozzle_diameter, height)); OUTPUT: RETVAL diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index 5d006e676..50ddfd9a1 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -23,8 +23,8 @@ Ref fills() %code%{ RETVAL = &THIS->fills; %}; - Clone flow(FlowRole role, bool bridge = false, double width = -1) - %code%{ RETVAL = THIS->flow(role, bridge, width); %}; + Clone flow(FlowRole role) + %code%{ RETVAL = THIS->flow(role); %}; void prepare_fill_surfaces(); void make_perimeters(SurfaceCollection* slices, SurfaceCollection* fill_surfaces) %code%{ THIS->make_perimeters(*slices, fill_surfaces); %}; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index cc3dac224..9e632bd53 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -33,9 +33,6 @@ _constant() Ref config() %code%{ RETVAL = &THIS->config(); %}; Ref print(); - - Clone flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object) - %code%{ RETVAL = THIS->flow(role, layer_height, bridge, first_layer, width, *object); %}; }; %name{Slic3r::Print::Object} class PrintObject {