PrusaSlicer-NonPlainar/lib/Slic3r/ExtrusionLoop.pm

57 lines
1.3 KiB
Perl
Raw Normal View History

package Slic3r::ExtrusionLoop;
use Moo;
# the underlying Slic3r::Polygon objects holds the geometry
has 'polygon' => (
is => 'rw',
required => 1,
handles => [qw(is_printable nearest_point_to)],
);
# see EXTR_ROLE_* constants in ExtrusionPath.pm
has 'role' => (is => 'rw', required => 1);
2011-11-28 17:37:53 +00:00
sub BUILD {
my $self = shift;
bless $self->polygon, 'Slic3r::Polygon';
$self->polygon($self->polygon->serialize);
}
sub deserialize {
my $self = shift;
$self->polygon($self->polygon->deserialize);
}
sub split_at {
my $self = shift;
my ($point) = @_;
$point = Slic3r::Point->new($point);
# find index of point
my $i = -1;
2012-01-12 21:05:35 +00:00
for (my $n = 0; $n <= $#{$self->polygon}; $n++) {
if ($point->id eq $self->polygon->[$n]->id) {
$i = $n;
last;
}
}
die "Point not found" if $i == -1;
my @new_points = ();
push @new_points, @{$self->polygon}[$i .. $#{$self->polygon}];
push @new_points, @{$self->polygon}[0 .. $i];
return Slic3r::ExtrusionPath->new(
polyline => Slic3r::Polyline->new(\@new_points),
role => $self->role,
);
}
2012-02-19 11:03:36 +00:00
sub split_at_first_point {
my $self = shift;
return $self->split_at($self->polygon->[0]);
}
1;