Code optimization

This commit is contained in:
Alessandro Ranellucci 2012-02-25 22:15:34 +01:00
parent 170d29a789
commit c98f6734c7
5 changed files with 13 additions and 20 deletions

View file

@ -121,8 +121,7 @@ sub bounding_box_polygon {
sub clip_line {
my $self = shift;
my ($line) = @_;
$line = Slic3r::Line->new($line) if ref $line eq 'ARRAY';
my ($line) = @_; # line must be a Slic3r::Line object
my @intersections = grep $_, map $_->intersection($line, 1), map $_->lines, @$self;
my @dir = (

View file

@ -38,7 +38,7 @@ sub fill_surface {
my $x = $bounding_box->[X1];
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
for (my $i = 0; $x <= $bounding_box->[X2] + scale epsilon; $i++) {
my $vertical_line = [ [$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]] ];
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]]);
if ($is_line_pattern && $i % 2) {
$vertical_line->[A][X] -= $line_oscillation;
$vertical_line->[B][X] += $line_oscillation;

View file

@ -7,15 +7,7 @@ use Slic3r::Geometry qw(A B X Y);
sub new {
my $class = shift;
my $self;
if (@_ == 2) {
$self = [ @_ ];
} elsif (ref $_[0] eq 'ARRAY') {
$self = [ $_[0][0], $_[0][1] ];
} elsif ($_[0]->isa(__PACKAGE__)) {
return $_[0];
} else {
die "Invalid argument for $class->new";
}
$self = [ @_ ];
bless $self, $class;
bless $_, 'Slic3r::Point' for @$self;
return $self;

View file

@ -32,7 +32,9 @@ sub clone {
sub lines {
my $self = shift;
return map Slic3r::Line->new($_), polygon_lines($self);
my @lines = polygon_lines($self);
bless $_, 'Slic3r::Line' for @lines;
return @lines;
}
sub cleanup {