Optimizations to regular_points(), clip_end(), clip_start()

This commit is contained in:
Alessandro Ranellucci 2013-10-27 13:51:59 +01:00
parent 28e9682d0e
commit 06e7a1ae68

View File

@ -91,17 +91,17 @@ sub clip_end {
my ($distance) = @_; my ($distance) = @_;
while ($distance > 0) { while ($distance > 0) {
my $last_point = $self->[-1]; my $last_point = $self->last_point->clone;
$self->pop_back; $self->pop_back;
last if @$self == 0; last if @$self == 0;
my $last_segment_length = $last_point->distance_to($self->[-1]); my $last_segment_length = $last_point->distance_to($self->last_point);
if ($last_segment_length <= $distance) { if ($last_segment_length <= $distance) {
$distance -= $last_segment_length; $distance -= $last_segment_length;
next; next;
} }
my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->[-1], $distance); my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->last_point, $distance);
$self->append($new_point); $self->append($new_point);
$distance = 0; $distance = 0;
} }
@ -112,19 +112,19 @@ sub clip_start {
my $self = shift; my $self = shift;
my ($distance) = @_; my ($distance) = @_;
my @points = @$self; my @my_points = @$self;
my $points = [ $self->[0] ]; my $points = [ $my_points[0] ];
for (my $i = 1; $distance > 0 && $i <= $#points; $i++) { for (my $i = 1; $distance > 0 && $i <= $#my_points; $i++) {
my $point = $points[$i]; my $point = $my_points[$i];
my $segment_length = $point->distance_to($points[$i-1]); my $segment_length = $point->distance_to($my_points[$i-1]);
if ($segment_length <= $distance) { if ($segment_length <= $distance) {
$distance -= $segment_length; $distance -= $segment_length;
push @$points, $point; push @$points, $point;
next; next;
} }
my $new_point = Slic3r::Geometry::point_along_segment($points[$i-1], $point, $distance); my $new_point = Slic3r::Geometry::point_along_segment($my_points[$i-1], $point, $distance);
push @$points, Slic3r::Point->new(@$new_point); push @$points, Slic3r::Point->new(@$new_point);
$distance = 0; $distance = 0;
} }
@ -139,12 +139,13 @@ sub regular_points {
my $self = shift; my $self = shift;
my ($distance) = @_; my ($distance) = @_;
my @points = ($self->[0]); my @my_points = @$self;
my @points = ($my_points[0]);
my $len = 0; my $len = 0;
for (my $i = 1; $i <= $#$self; $i++) { for (my $i = 1; $i <= $#my_points; $i++) {
my $point = $self->[$i]; my $point = $my_points[$i];
my $segment_length = $point->distance_to($self->[$i-1]); my $segment_length = $point->distance_to($my_points[$i-1]);
$len += $segment_length; $len += $segment_length;
next if $len < $distance; next if $len < $distance;
@ -155,8 +156,8 @@ sub regular_points {
} }
my $take = $segment_length - ($len - $distance); # how much we take of this segment my $take = $segment_length - ($len - $distance); # how much we take of this segment
my $new_point = Slic3r::Geometry::point_along_segment($self->[$i-1], $point, $take); my $new_point = Slic3r::Geometry::point_along_segment($my_points[$i-1], $point, $take);
push @points, Slic3r::Point->new($new_point); push @points, Slic3r::Point->new(@$new_point);
$i--; $i--;
$len = -$take; $len = -$take;
} }