PrusaSlicer-NonPlainar/lib/Slic3r/Polyline/Closed.pm

50 lines
1.2 KiB
Perl
Raw Normal View History

2011-09-01 19:06:28 +00:00
package Slic3r::Polyline::Closed;
use Moo;
2011-09-01 19:06:28 +00:00
extends 'Slic3r::Polyline';
use Math::Clipper qw(JT_MITER);
use Slic3r::Geometry qw(scale);
sub lines {
my $self = shift;
my @lines = $self->SUPER::lines(@_);
2011-09-01 19:06:28 +00:00
# since this is a closed polyline, we just add a line at the end,
# connecting the last and the first point
2011-10-12 14:27:40 +00:00
push @lines, Slic3r::Line->new($self->points->[-1], $self->points->[0]);
return @lines;
}
2011-09-01 19:06:28 +00:00
sub encloses_point {
my $self = shift;
my ($point) = @_;
return Slic3r::Geometry::point_in_polygon($point->p, $self->p);
2011-09-01 19:06:28 +00:00
}
# returns false if the polyline is too tight to be printed
sub is_printable {
my $self = shift;
# try to get an inwards offset
# for a distance equal to half of the extrusion width;
# if no offset is possible, then polyline is not printable
my $p = $self->p;
@$p = reverse @$p if !Math::Clipper::is_counter_clockwise($p);
my $offsets = Math::Clipper::offset([$p], -(scale $Slic3r::flow_spacing / 2), $Slic3r::resolution * 100000, JT_MITER, 2);
return @$offsets ? 1 : 0;
}
2011-10-10 15:27:00 +00:00
sub is_valid {
my $self = shift;
return @{$self->points} >= 3;
}
sub polygon {
my $self = shift;
return Slic3r::Polygon->new($self->points);
}
2011-09-01 19:06:28 +00:00
1;