2011-09-26 08:52:58 +00:00
|
|
|
package Slic3r::ExtrusionPath::Collection;
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
|
|
has 'paths' => (
|
|
|
|
is => 'rw',
|
|
|
|
#isa => 'ArrayRef[Slic3r::ExtrusionPath]',
|
|
|
|
default => sub { [] },
|
|
|
|
);
|
|
|
|
|
|
|
|
sub add {
|
|
|
|
my $self = shift;
|
|
|
|
my ($path) = @_;
|
|
|
|
|
|
|
|
push @{$self->paths}, $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub endpoints {
|
|
|
|
my $self = shift;
|
2011-12-04 15:24:46 +00:00
|
|
|
return [ map $_->endpoints, @{$self->paths} ];
|
2011-09-26 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub shortest_path {
|
|
|
|
my $self = shift;
|
|
|
|
my ($start_near) = @_;
|
|
|
|
|
2012-02-19 09:48:58 +00:00
|
|
|
my @my_paths = @{$self->paths};
|
2011-09-26 08:52:58 +00:00
|
|
|
my @paths = ();
|
|
|
|
my $start_at;
|
2012-02-19 09:48:58 +00:00
|
|
|
CYCLE: while (@my_paths) {
|
2011-09-26 08:52:58 +00:00
|
|
|
# find nearest point
|
2012-02-19 09:48:58 +00:00
|
|
|
my $endpoints = [ map $_->endpoints, @my_paths ];
|
2011-11-07 14:40:09 +00:00
|
|
|
$start_at = $start_near
|
2012-02-19 09:48:58 +00:00
|
|
|
? Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, $endpoints))
|
2011-11-07 14:40:09 +00:00
|
|
|
: $self->endpoints->[0];
|
2011-09-26 08:52:58 +00:00
|
|
|
|
|
|
|
# loop through paths to find the one that starts or ends at the point found
|
2012-02-19 09:48:58 +00:00
|
|
|
PATH: for (my $i = 0; $i <= $#my_paths; $i++) {
|
|
|
|
if ($start_at->id eq $my_paths[$i]->points->[0]->id) {
|
|
|
|
push @paths, splice @my_paths, $i, 1;
|
|
|
|
} elsif ($start_at->id eq $my_paths[$i]->points->[-1]->id) {
|
|
|
|
$my_paths[$i]->reverse;
|
|
|
|
push @paths, splice @my_paths, $i, 1;
|
2011-09-26 08:52:58 +00:00
|
|
|
} else {
|
|
|
|
next PATH;
|
|
|
|
}
|
2011-10-12 12:54:49 +00:00
|
|
|
$start_near = $paths[-1]->points->[-1];
|
2011-09-26 08:52:58 +00:00
|
|
|
next CYCLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return @paths;
|
|
|
|
}
|
|
|
|
|
2011-10-01 12:26:54 +00:00
|
|
|
sub cleanup {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# split paths at angles that are too acute to be printed as they will cause blobs
|
|
|
|
@{$self->paths} = map $_->split_at_acute_angles, @{$self->paths};
|
|
|
|
}
|
|
|
|
|
2011-10-20 16:11:59 +00:00
|
|
|
sub detect_arcs {
|
|
|
|
my $self = shift;
|
2011-11-07 13:12:07 +00:00
|
|
|
@{$self->paths} = map $_->detect_arcs(@_), @{$self->paths};
|
2011-10-20 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 08:52:58 +00:00
|
|
|
1;
|