diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index c37b86074..1fa75bb99 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -10,21 +10,11 @@ use Math::Geometry::Voronoi; use Slic3r::Geometry qw(X Y A B point_in_polygon same_line epsilon); use Slic3r::Geometry::Clipper qw(union_ex JT_MITER); -sub contour { - my $self = shift; - return $self->[0]; -} - -sub holes { - my $self = shift; - return @$self[1..$#$self]; -} - sub is_valid { my $self = shift; return (!first { !$_->is_valid } @$self) && $self->contour->is_counter_clockwise - && (!first { $_->is_counter_clockwise } $self->holes); + && (!first { $_->is_counter_clockwise } @{$self->holes}); } # returns false if the expolygon is too tight to be printed diff --git a/lib/Slic3r/GCode/MotionPlanner.pm b/lib/Slic3r/GCode/MotionPlanner.pm index a51e1bcbe..ec3a63b1c 100644 --- a/lib/Slic3r/GCode/MotionPlanner.pm +++ b/lib/Slic3r/GCode/MotionPlanner.pm @@ -150,7 +150,7 @@ sub BUILD { points => [ values %{$self->_pointmap} ], no_arrows => 1, expolygons => $self->islands, - #red_polygons => [ map $_->holes, map @$_, @{$self->_inner} ], + #red_polygons => [ map @{$_->holes}, map @$_, @{$self->_inner} ], #white_polygons => [ map @$_, @{$self->_outer} ], ); printf "%d islands\n", scalar @{$self->islands}; @@ -195,7 +195,7 @@ sub find_node { # if we're inside a hole, move to a point on hole; { - my $polygon = first { $_->encloses_point($point) } (map $_->holes, map @$_, @{$self->_inner}); + my $polygon = first { $_->encloses_point($point) } (map @{$_->holes}, map @$_, @{$self->_inner}); return nearest_point($point, $polygon) if $polygon; } diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 2c896bc07..30a6c342c 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -159,7 +159,7 @@ sub _merge_loops { $slices = offset2_ex($slices, +$safety_offset, -$safety_offset); Slic3r::debugf " %d surface(s) having %d holes detected from %d polylines\n", - scalar(@$slices), scalar(map $_->holes, @$slices), scalar(@$loops) if $Slic3r::debug; + scalar(@$slices), scalar(map @{$_->holes}, @$slices), scalar(@$loops) if $Slic3r::debug; return map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL), @$slices; } @@ -198,7 +198,7 @@ sub make_perimeters { my @offsets = @{offset2_ex(\@last, -1.5*$spacing, +0.5*$spacing)}; my @contours_offsets = map $_->contour, @offsets; - my @holes_offsets = map $_->holes, @offsets; + my @holes_offsets = map @{$_->holes}, @offsets; @offsets = (@contours_offsets, @holes_offsets); # turn @offsets from ExPolygons to Polygons # where offset2() collapses the expolygon, then there's no room for an inner loop diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index e40b1eb84..0eb04092a 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -531,7 +531,7 @@ EOF my $expolygon = $slice->clone; $expolygon->translate(@$copy); $print_polygon->($expolygon->contour, 'contour'); - $print_polygon->($_, 'hole') for $expolygon->holes; + $print_polygon->($_, 'hole') for @{$expolygon->holes}; push @current_layer_slices, $expolygon; } } diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index fe44179f8..b5c0d2eec 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -245,7 +245,7 @@ sub slice { ]); my $diff = diff_ex( [ map @$_, @$union ], - [ map $_->expolygon->holes, @upper_surfaces, @lower_surfaces, ], + [ map @{$_->expolygon->holes}, @upper_surfaces, @lower_surfaces, ], ); $layerm->slices->clear; diff --git a/xs/t/04_expolygon.t b/xs/t/04_expolygon.t index aa87bc74b..8e14e589c 100644 --- a/xs/t/04_expolygon.t +++ b/xs/t/04_expolygon.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 18; +use Test::More tests => 20; use constant PI => 4 * atan2(1, 1); @@ -28,6 +28,8 @@ is_deeply $expolygon->pp, [$square, $hole_in_square], 'expolygon roundtrip'; is ref($expolygon->arrayref), 'ARRAY', 'expolygon arrayref is unblessed'; isa_ok $expolygon->[0], 'Slic3r::Polygon', 'expolygon polygon is blessed'; +isa_ok $expolygon->contour, 'Slic3r::Polygon', 'expolygon contour is blessed'; +isa_ok $expolygon->holes->[0], 'Slic3r::Polygon', 'expolygon hole is blessed'; isa_ok $expolygon->[0][0], 'Slic3r::Point', 'expolygon point is blessed'; { diff --git a/xs/xsp/ExPolygon.xsp b/xs/xsp/ExPolygon.xsp index 49582642a..ed64ba8c1 100644 --- a/xs/xsp/ExPolygon.xsp +++ b/xs/xsp/ExPolygon.xsp @@ -13,6 +13,10 @@ %code{% RETVAL = THIS->to_SV(); %}; SV* pp() %code{% RETVAL = THIS->to_SV_pureperl(); %}; + Polygon* contour() + %code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(THIS->contour); %}; + Polygons holes() + %code{% RETVAL = THIS->holes; %}; void scale(double factor); void translate(double x, double y); double area();