From 6194cbf530e427da4aa884d17469de2c3b13ff63 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 Jun 2014 09:15:40 +0200 Subject: [PATCH] Refactoring: new method in Flow for calculating spacing between extrusions having different width --- lib/Slic3r/Layer/Region.pm | 16 +++++++--------- xs/src/Flow.cpp | 17 ++++++++++++++++- xs/src/Flow.hpp | 1 + xs/xsp/Flow.xsp | 2 ++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index bf6e639e..976b049f 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -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, diff --git a/xs/src/Flow.cpp b/xs/src/Flow.cpp index ba828aff..00c6cdc9 100644 --- a/xs/src/Flow.cpp +++ b/xs/src/Flow.cpp @@ -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 { diff --git a/xs/src/Flow.hpp b/xs/src/Flow.hpp index aeb87183..88cae247 100644 --- a/xs/src/Flow.hpp +++ b/xs/src/Flow.hpp @@ -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); diff --git a/xs/xsp/Flow.xsp b/xs/xsp/Flow.xsp index 7c494314..09c6fd57 100644 --- a/xs/xsp/Flow.xsp +++ b/xs/xsp/Flow.xsp @@ -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();