Refactoring: new method in Flow for calculating spacing between extrusions having different width

master
Alessandro Ranellucci 2014-06-12 09:15:40 +02:00
parent 8ee11b3239
commit 6194cbf530
4 changed files with 26 additions and 10 deletions

View File

@ -41,18 +41,18 @@ sub flow {
sub make_perimeters {
my $self = shift;
# external perimeters
my $ext_perimeter_flow = $self->flow(FLOW_ROLE_EXTERNAL_PERIMETER);
my $ext_mm3_per_mm = $ext_perimeter_flow->mm3_per_mm;
my $ext_pwidth = $ext_perimeter_flow->scaled_width;
my $ext_pspacing = $ext_perimeter_flow->scaled_spacing;
# other perimeters
my $perimeter_flow = $self->flow(FLOW_ROLE_PERIMETER);
my $mm3_per_mm = $perimeter_flow->mm3_per_mm;
my $pwidth = $perimeter_flow->scaled_width;
my $pspacing = $perimeter_flow->scaled_spacing;
# external perimeters
my $ext_perimeter_flow = $self->flow(FLOW_ROLE_EXTERNAL_PERIMETER);
my $ext_mm3_per_mm = $ext_perimeter_flow->mm3_per_mm;
my $ext_pwidth = $ext_perimeter_flow->scaled_width;
my $ext_pspacing = scale($ext_perimeter_flow->spacing_to($perimeter_flow));
# overhang perimeters
my $overhang_flow = $self->region->flow(FLOW_ROLE_PERIMETER, -1, 1, 0, undef, $self->layer->object);
my $mm3_per_mm_overhang = $overhang_flow->mm3_per_mm;
@ -109,9 +109,7 @@ sub make_perimeters {
push @thin_walls, @$diff;
}
} else {
my $distance = ($i == 2)
? (0.5*$ext_pspacing + 0.5*$pspacing)
: (1.0*$pspacing);
my $distance = ($i == 2) ? $ext_pspacing : $pspacing;
@offsets = @{offset2(
\@last,

View File

@ -40,7 +40,7 @@ Flow::new_from_spacing(float spacing, float nozzle_diameter, float height, bool
float
Flow::spacing() const {
if (this->bridge) {
return width + BRIDGE_EXTRA_SPACING;
return this->width + BRIDGE_EXTRA_SPACING;
}
float min_flow_spacing;
@ -54,6 +54,21 @@ Flow::spacing() const {
return this->width - OVERLAP_FACTOR * (this->width - min_flow_spacing);
}
/* This method returns the centerline spacing between an extrusion using this
flow and another one using another flow.
this->spacing(other) shall return the same value as other.spacing(*this) */
float
Flow::spacing(const Flow &other) const {
assert(this->height == other.height);
assert(this->bridge == other.bridge);
if (this->bridge) {
return this->width/2 + other.width/2 + BRIDGE_EXTRA_SPACING;
}
return this->spacing()/2 + other.spacing()/2;
}
/* This method returns extrusion volume per head move unit. */
double
Flow::mm3_per_mm() const {

View File

@ -29,6 +29,7 @@ class Flow
Flow(float _w, float _h, float _nd, bool _bridge = false)
: width(_w), height(_h), nozzle_diameter(_nd), bridge(_bridge) {};
float spacing() const;
float spacing(const Flow &other) const;
double mm3_per_mm() const;
coord_t scaled_width() const {
return scale_(this->width);

View File

@ -24,6 +24,8 @@
bool bridge()
%code{% RETVAL = THIS->bridge; %};
float spacing();
float spacing_to(Flow* other)
%code{% RETVAL = THIS->spacing(*other); %};
long scaled_width();
long scaled_spacing();
double mm3_per_mm();