Refactoring: moved direction-specific methods to new role class Slic3r::Fill::WithDirection

This commit is contained in:
Alessandro Ranellucci 2014-07-26 16:28:38 +02:00
parent c4d70bcb85
commit d508be5ae8
4 changed files with 20 additions and 13 deletions

View File

@ -1,12 +1,27 @@
package Slic3r::Fill::Base; package Slic3r::Fill::Base;
use Moo; use Moo;
use Slic3r::Geometry qw(PI rad2deg);
has 'layer_id' => (is => 'rw'); has 'layer_id' => (is => 'rw');
has 'angle' => (is => 'rw'); # in radians, ccw, 0 = East has 'angle' => (is => 'rw'); # in radians, ccw, 0 = East
has 'bounding_box' => (is => 'ro', required => 0); # Slic3r::Geometry::BoundingBox object 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 angles () { [0, PI/2] }
sub infill_direction { sub infill_direction {
@ -67,15 +82,4 @@ sub rotate_points_back {
$_->rotate(@$rotate) for @$paths; $_->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; 1;

View File

@ -2,6 +2,7 @@ package Slic3r::Fill::Honeycomb;
use Moo; use Moo;
extends 'Slic3r::Fill::Base'; extends 'Slic3r::Fill::Base';
with qw(Slic3r::Fill::WithDirection);
has 'cache' => (is => 'rw', default => sub {{}}); has 'cache' => (is => 'rw', default => sub {{}});

View File

@ -2,6 +2,7 @@ package Slic3r::Fill::PlanePath;
use Moo; use Moo;
extends 'Slic3r::Fill::Base'; extends 'Slic3r::Fill::Base';
with qw(Slic3r::Fill::WithDirection);
use Slic3r::Geometry qw(scale X1 Y1 X2 Y2); use Slic3r::Geometry qw(scale X1 Y1 X2 Y2);
use Slic3r::Geometry::Clipper qw(intersection_pl); use Slic3r::Geometry::Clipper qw(intersection_pl);

View File

@ -2,6 +2,7 @@ package Slic3r::Fill::Rectilinear;
use Moo; use Moo;
extends 'Slic3r::Fill::Base'; extends 'Slic3r::Fill::Base';
with qw(Slic3r::Fill::WithDirection);
has 'cache' => (is => 'rw', default => sub {{}}); has 'cache' => (is => 'rw', default => sub {{}});