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-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
|
|
|
|
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
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
my @lines = $self->lines;
|
|
|
|
if ($lines[-1]->parallel_to($lines[0])) {
|
|
|
|
shift @{$self->points};
|
|
|
|
}
|
2011-09-06 09:50:43 +00:00
|
|
|
}
|
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-09-02 19:10:20 +00:00
|
|
|
sub mgp_polygon {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $p = Math::Geometry::Planar->new;
|
2011-09-18 17:28:12 +00:00
|
|
|
$p->points($self->points);
|
2011-09-02 19:10:20 +00:00
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|