2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Polyline::Closed;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
|
|
|
extends 'Slic3r::Polyline';
|
|
|
|
|
2011-10-07 17:07:57 +00:00
|
|
|
use Math::Clipper qw(JT_MITER);
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
sub lines {
|
|
|
|
my $self = shift;
|
|
|
|
my @lines = $self->SUPER::lines(@_);
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2011-09-18 17:28:12 +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]);
|
2011-09-18 17:28:12 +00:00
|
|
|
return @lines;
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
sub encloses_point {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point) = @_;
|
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
return Slic3r::Geometry::point_in_polygon($point->p, $self->p);
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 17:07:57 +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], -($Slic3r::flow_width / 2 / $Slic3r::resolution), $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;
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|