From d508be5ae81322bde41f6f2645d69702817237cf Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 26 Jul 2014 16:28:38 +0200 Subject: [PATCH] Refactoring: moved direction-specific methods to new role class Slic3r::Fill::WithDirection --- lib/Slic3r/Fill/Base.pm | 30 +++++++++++++++++------------- lib/Slic3r/Fill/Honeycomb.pm | 1 + lib/Slic3r/Fill/PlanePath.pm | 1 + lib/Slic3r/Fill/Rectilinear.pm | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/Slic3r/Fill/Base.pm b/lib/Slic3r/Fill/Base.pm index f71367215..21a802058 100644 --- a/lib/Slic3r/Fill/Base.pm +++ b/lib/Slic3r/Fill/Base.pm @@ -1,12 +1,27 @@ package Slic3r::Fill::Base; use Moo; -use Slic3r::Geometry qw(PI rad2deg); - has 'layer_id' => (is => 'rw'); has 'angle' => (is => 'rw'); # in radians, ccw, 0 = East has 'bounding_box' => (is => 'ro', required => 0); # Slic3r::Geometry::BoundingBox object +sub adjust_solid_spacing { + my $self = shift; + my %params = @_; + + my $number_of_lines = int($params{width} / $params{distance}) + 1; + return $params{distance} if $number_of_lines <= 1; + + my $extra_space = $params{width} % $params{distance}; + return $params{distance} + $extra_space / ($number_of_lines - 1); +} + + +package Slic3r::Fill::WithDirection; +use Moo::Role; + +use Slic3r::Geometry qw(PI rad2deg); + sub angles () { [0, PI/2] } sub infill_direction { @@ -67,15 +82,4 @@ sub rotate_points_back { $_->rotate(@$rotate) for @$paths; } -sub adjust_solid_spacing { - my $self = shift; - my %params = @_; - - my $number_of_lines = int($params{width} / $params{distance}) + 1; - return $params{distance} if $number_of_lines <= 1; - - my $extra_space = $params{width} % $params{distance}; - return $params{distance} + $extra_space / ($number_of_lines - 1); -} - 1; diff --git a/lib/Slic3r/Fill/Honeycomb.pm b/lib/Slic3r/Fill/Honeycomb.pm index 6e665a70b..08c0b0710 100644 --- a/lib/Slic3r/Fill/Honeycomb.pm +++ b/lib/Slic3r/Fill/Honeycomb.pm @@ -2,6 +2,7 @@ package Slic3r::Fill::Honeycomb; use Moo; extends 'Slic3r::Fill::Base'; +with qw(Slic3r::Fill::WithDirection); has 'cache' => (is => 'rw', default => sub {{}}); diff --git a/lib/Slic3r/Fill/PlanePath.pm b/lib/Slic3r/Fill/PlanePath.pm index 4c2d0e387..dd942aba9 100644 --- a/lib/Slic3r/Fill/PlanePath.pm +++ b/lib/Slic3r/Fill/PlanePath.pm @@ -2,6 +2,7 @@ package Slic3r::Fill::PlanePath; use Moo; extends 'Slic3r::Fill::Base'; +with qw(Slic3r::Fill::WithDirection); use Slic3r::Geometry qw(scale X1 Y1 X2 Y2); use Slic3r::Geometry::Clipper qw(intersection_pl); diff --git a/lib/Slic3r/Fill/Rectilinear.pm b/lib/Slic3r/Fill/Rectilinear.pm index 15b936131..8e3eee3a8 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -2,6 +2,7 @@ package Slic3r::Fill::Rectilinear; use Moo; extends 'Slic3r::Fill::Base'; +with qw(Slic3r::Fill::WithDirection); has 'cache' => (is => 'rw', default => sub {{}});