From 28695c719c80c2c3bc78f88d240bc3bce37749bd Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 3 Jun 2014 23:59:03 +0200 Subject: [PATCH] Fixed regression causing bridge flow to be incorrect when a manual default extrusion width was specified. Includes several regression tests. #2027 --- t/flow.t | 42 ++++++++++++++++++++++++++++++++++++++++-- xs/src/Flow.cpp | 3 ++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/t/flow.t b/t/flow.t index 0d436f5a..80fc12c5 100644 --- a/t/flow.t +++ b/t/flow.t @@ -1,4 +1,4 @@ -use Test::More tests => 1; +use Test::More tests => 6; use strict; use warnings; @@ -9,7 +9,7 @@ BEGIN { use List::Util qw(first sum); use Slic3r; -use Slic3r::Geometry qw(scale); +use Slic3r::Geometry qw(scale PI); use Slic3r::Test; { @@ -38,4 +38,42 @@ use Slic3r::Test; 'first_layer_extrusion_width applies to everything on first layer'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('bridge_speed', 99); + $config->set('bridge_flow_ratio', 1); + $config->set('cooling', 0); # to prevent speeds from being altered + $config->set('first_layer_speed', '100%'); # to prevent speeds from being altered + + my $test = sub { + my $print = Slic3r::Test::init_print('overhang', config => $config); + my @E_per_mm = (); + Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($info->{extruding} && $info->{dist_XY} > 0) { + if (($args->{F} // $self->F) == $config->bridge_speed*60) { + push @E_per_mm, $info->{dist_E} / $info->{dist_XY}; + } + } + }); + my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio; + my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI); + ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm), + 'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio; + }; + + $config->set('bridge_flow_ratio', 0.5); + $test->(); + $config->set('bridge_flow_ratio', 2); + $test->(); + $config->set('extrusion_width', 0.4); + $config->set('bridge_flow_ratio', 1); + $test->(); + $config->set('bridge_flow_ratio', 0.5); + $test->(); + $config->set('bridge_flow_ratio', 2); + $test->(); +} + __END__ diff --git a/xs/src/Flow.cpp b/xs/src/Flow.cpp index 19aa807d..6f66f70d 100644 --- a/xs/src/Flow.cpp +++ b/xs/src/Flow.cpp @@ -9,7 +9,8 @@ Flow::new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &wid if (height <= 0 && bridge_flow_ratio == 0) CONFESS("Invalid flow height supplied to new_from_config_width()"); float w; - if (!width.percent && width.value == 0) { + // use automatic extrusion width if user left 0 or we need a bridge flow + if ((!width.percent && width.value == 0) || bridge_flow_ratio > 0) { w = Flow::_width(role, nozzle_diameter, height, bridge_flow_ratio); } else { w = width.get_abs_value(height);