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

44 lines
994 B
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';
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
push @lines, Slic3r::Line->new(points => [$self->points->[-1], $self->points->[0]]);
return @lines;
}
# superclass doesn't check whether last line of our closed polyline
# is parallel to first one, so let's do it here
sub merge_continuous_lines {
my $self = shift;
$self->SUPER::merge_continuous_lines(@_);
2011-09-01 19:06:28 +00:00
my @lines = $self->lines;
if ($lines[-1]->parallel_to($lines[0])) {
shift @{$self->points};
}
}
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
}
2011-09-02 19:10:20 +00:00
sub mgp_polygon {
my $self = shift;
my $p = Math::Geometry::Planar->new;
$p->points($self->points);
2011-09-02 19:10:20 +00:00
return $p;
}
2011-09-01 19:06:28 +00:00
1;