Get rid of the ExtrusionLoop objects in concentric filler

This commit is contained in:
Alessandro Ranellucci 2012-10-30 15:29:13 +01:00
parent 20e73face2
commit cec7bf815c
5 changed files with 60 additions and 53 deletions

View file

@ -37,36 +37,22 @@ sub pack {
sub split_at_index { sub split_at_index {
my $self = shift; my $self = shift;
my ($index) = @_;
my @new_points = ();
push @new_points, @{$self->polygon}[$index .. $#{$self->polygon}];
push @new_points, @{$self->polygon}[0 .. $index];
return Slic3r::ExtrusionPath->new( return Slic3r::ExtrusionPath->new(
polyline => Slic3r::Polyline->new(\@new_points), polyline => $self->polygon->split_at_index(@_),
role => $self->role, role => $self->role,
flow_spacing => $self->flow_spacing, flow_spacing => $self->flow_spacing,
); );
} }
sub split_at { sub split_at {
my $self = shift; my $self = shift;
my ($point) = @_;
$point = Slic3r::Point->new($point); return Slic3r::ExtrusionPath->new(
polyline => $self->polygon->split_at(@_),
# find index of point role => $self->role,
my $i = -1; flow_spacing => $self->flow_spacing,
for (my $n = 0; $n <= $#{$self->polygon}; $n++) { );
if (same_point($point, $self->polygon->[$n])) {
$i = $n;
last;
}
}
die "Point not found" if $i == -1;
return $self->split_at_index($i);
} }
sub split_at_first_point { sub split_at_first_point {
@ -82,12 +68,6 @@ sub endpoints {
return ($self->polygon->[0], $self->polygon->[-1]); return ($self->polygon->[0], $self->polygon->[-1]);
} }
# provided for ExtrusionPath::Collection->shortest_path()
sub points {
my $self = shift;
return $self->polygon;
}
package Slic3r::ExtrusionLoop::Packed; package Slic3r::ExtrusionLoop::Packed;
sub unpack { sub unpack {
my $self = shift; my $self = shift;

View file

@ -15,7 +15,7 @@ use Slic3r::Geometry qw(PI X Y epsilon deg2rad rotate_points);
has 'polyline' => ( has 'polyline' => (
is => 'rw', is => 'rw',
required => 1, required => 1,
handles => [qw(merge_continuous_lines lines length reverse)], handles => [qw(merge_continuous_lines lines length reverse clip_end)],
); );
# height is the vertical thickness of the extrusion expressed in mm # height is the vertical thickness of the extrusion expressed in mm
@ -58,26 +58,6 @@ sub pack {
# no-op, this allows to use both packed and non-packed objects in Collections # no-op, this allows to use both packed and non-packed objects in Collections
sub unpack { $_[0] } sub unpack { $_[0] }
sub clip_end {
my $self = shift;
my ($distance) = @_;
while ($distance > 0) {
my $last_point = pop @{$self->points};
last if !@{$self->points};
my $last_segment_length = $last_point->distance_to($self->points->[-1]);
if ($last_segment_length <= $distance) {
$distance -= $last_segment_length;
next;
}
my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->points->[-1], $distance);
push @{$self->points}, Slic3r::Point->new($new_point);
$distance = 0;
}
}
sub clip_with_polygon { sub clip_with_polygon {
my $self = shift; my $self = shift;
my ($polygon) = @_; my ($polygon) = @_;

View file

@ -51,13 +51,13 @@ sub fill_surface {
($bounding_box->[X1] + $bounding_box->[X2]) / 2, ($bounding_box->[X1] + $bounding_box->[X2]) / 2,
($bounding_box->[Y1] + $bounding_box->[Y2]) / 2, ($bounding_box->[Y1] + $bounding_box->[Y2]) / 2,
); );
foreach my $loop (map Slic3r::ExtrusionLoop->new(polygon => $_, role => EXTR_ROLE_FILL), @loops) { foreach my $loop (@loops) {
# extrude all loops ccw # extrude all loops ccw
$loop->polygon->make_counter_clockwise; $loop->make_counter_clockwise;
# find the point of the loop that is closest to the current extruder position # find the point of the loop that is closest to the current extruder position
my $index = $loop->nearest_point_index_to($cur_pos); my $index = $loop->nearest_point_index_to($cur_pos);
$cur_pos = $loop->polygon->[0]; $cur_pos = $loop->[0];
# split the loop at the starting point and make a path # split the loop at the starting point and make a path
my $path = $loop->split_at_index($index); my $path = $loop->split_at_index($index);
@ -65,7 +65,7 @@ sub fill_surface {
# clip the path to avoid the extruder to get exactly on the first point of the loop # clip the path to avoid the extruder to get exactly on the first point of the loop
$path->clip_end(scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING); $path->clip_end(scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING);
push @paths, $path->points if @{$path->points}; push @paths, $path if @$path;
} }
return { flow_spacing => $flow_spacing }, @paths; return { flow_spacing => $flow_spacing }, @paths;

View file

@ -119,4 +119,31 @@ sub is_valid {
return @$self >= 3; return @$self >= 3;
} }
sub split_at_index {
my $self = shift;
my ($index) = @_;
return (ref $self)->new(
@$self[$index .. $#$self],
@$self[0 .. $index],
);
}
sub split_at {
my $self = shift;
my ($point) = @_;
# find index of point
my $i = -1;
for (my $n = 0; $n <= $#$self; $n++) {
if (Slic3r::Geometry::same_point($point, $self->[$n])) {
$i = $n;
last;
}
}
die "Point not found" if $i == -1;
return $self->split_at_index($i);
}
1; 1;

View file

@ -181,6 +181,26 @@ sub scale {
return $self; return $self;
} }
sub clip_end {
my $self = shift;
my ($distance) = @_;
while ($distance > 0) {
my $last_point = pop @$self;
last if !@$self;
my $last_segment_length = $last_point->distance_to($self->[-1]);
if ($last_segment_length <= $distance) {
$distance -= $last_segment_length;
next;
}
my $new_point = Slic3r::Geometry::point_along_segment($last_point, $self->[-1], $distance);
push @$self, Slic3r::Point->new($new_point);
$distance = 0;
}
}
package Slic3r::Polyline::Collection; package Slic3r::Polyline::Collection;
use Moo; use Moo;