2011-09-25 21:15:45 +00:00
|
|
|
package Slic3r::ExtrusionLoop;
|
|
|
|
use Moo;
|
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
# the underlying Slic3r::Polygon objects holds the geometry
|
|
|
|
has 'polygon' => (
|
2012-05-19 15:57:38 +00:00
|
|
|
is => 'rw',
|
2011-12-30 18:59:51 +00:00
|
|
|
required => 1,
|
2012-06-09 13:53:14 +00:00
|
|
|
handles => [qw(is_printable nearest_point_to reverse)],
|
2011-12-30 18:59:51 +00:00
|
|
|
);
|
2011-09-25 21:15:45 +00:00
|
|
|
|
2012-07-01 16:12:21 +00:00
|
|
|
has 'flow_spacing' => (is => 'rw');
|
|
|
|
|
2012-05-19 13:40:11 +00:00
|
|
|
# see EXTR_ROLE_* constants in ExtrusionPath.pm
|
2011-12-05 11:15:52 +00:00
|
|
|
has 'role' => (is => 'rw', required => 1);
|
2011-11-28 17:37:53 +00:00
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
sub BUILD {
|
|
|
|
my $self = shift;
|
|
|
|
bless $self->polygon, 'Slic3r::Polygon';
|
2012-05-19 15:57:38 +00:00
|
|
|
$self->polygon($self->polygon->serialize);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub deserialize {
|
|
|
|
my $self = shift;
|
|
|
|
$self->polygon($self->polygon->deserialize);
|
2011-12-30 18:59:51 +00:00
|
|
|
}
|
|
|
|
|
2012-06-30 15:23:55 +00:00
|
|
|
sub shortest_path {
|
|
|
|
my $self = shift;
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
sub split_at {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
|
2011-10-12 12:54:49 +00:00
|
|
|
$point = Slic3r::Point->new($point);
|
2011-09-25 21:15:45 +00:00
|
|
|
|
2012-06-07 17:53:27 +00:00
|
|
|
$self->deserialize;
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
# find index of point
|
|
|
|
my $i = -1;
|
2012-01-12 21:05:35 +00:00
|
|
|
for (my $n = 0; $n <= $#{$self->polygon}; $n++) {
|
2011-12-30 18:59:51 +00:00
|
|
|
if ($point->id eq $self->polygon->[$n]->id) {
|
2011-09-25 21:15:45 +00:00
|
|
|
$i = $n;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die "Point not found" if $i == -1;
|
|
|
|
|
|
|
|
my @new_points = ();
|
2011-12-30 18:59:51 +00:00
|
|
|
push @new_points, @{$self->polygon}[$i .. $#{$self->polygon}];
|
|
|
|
push @new_points, @{$self->polygon}[0 .. $i];
|
2011-09-25 21:15:45 +00:00
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
return Slic3r::ExtrusionPath->new(
|
|
|
|
polyline => Slic3r::Polyline->new(\@new_points),
|
|
|
|
role => $self->role,
|
2012-07-01 16:12:21 +00:00
|
|
|
flow_spacing => $self->flow_spacing,
|
2011-12-30 18:59:51 +00:00
|
|
|
);
|
2011-09-25 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 11:03:36 +00:00
|
|
|
sub split_at_first_point {
|
|
|
|
my $self = shift;
|
2012-07-02 15:57:29 +00:00
|
|
|
$self->deserialize;
|
2012-02-19 11:03:36 +00:00
|
|
|
return $self->split_at($self->polygon->[0]);
|
|
|
|
}
|
|
|
|
|
2012-06-07 10:21:33 +00:00
|
|
|
# although a loop doesn't have endpoints, this method is provided to allow
|
|
|
|
# ExtrusionLoop objects to be added to an ExtrusionPath::Collection and
|
|
|
|
# sorted by the ->shortest_path() method
|
|
|
|
sub endpoints {
|
|
|
|
my $self = shift;
|
|
|
|
return ($self->polygon->[0], $self->polygon->[-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
# provided for ExtrusionPath::Collection->shortest_path()
|
|
|
|
sub points {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->polygon;
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
1;
|