diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 717fc1d53..70e3f4f97 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -6,7 +6,7 @@ use warnings; use Boost::Geometry::Utils; use Math::Geometry::Voronoi; -use Slic3r::Geometry qw(X Y A B point_in_polygon same_line); +use Slic3r::Geometry qw(X Y A B point_in_polygon same_line scale epsilon); use Slic3r::Geometry::Clipper qw(union_ex JT_MITER); # the constructor accepts an array of polygons @@ -113,7 +113,7 @@ sub encloses_line { my ($line) = @_; my $clip = $self->clip_line($line); - return @$clip == 1 && same_line($clip->[0], $line); + return @$clip == 1 && abs($line->length - Slic3r::Geometry::line_length($clip->[0])) < scale epsilon; } sub point_on_segment { diff --git a/lib/Slic3r/GCode/MotionPlanner.pm b/lib/Slic3r/GCode/MotionPlanner.pm index cf0d97a2d..b95a38ec6 100644 --- a/lib/Slic3r/GCode/MotionPlanner.pm +++ b/lib/Slic3r/GCode/MotionPlanner.pm @@ -38,6 +38,7 @@ sub BUILD { my $crossing_edges = $self->_crossing_edges; my $tolerance = scale epsilon; + # given an expolygon, this subroutine connects all its visible points my $add_expolygon = sub { my ($expolygon, $crosses_perimeter) = @_; my @points = map @$_, @$expolygon; @@ -55,13 +56,25 @@ sub BUILD { } }; + # process individual islands for my $i (0 .. $#{$self->islands}) { + # simplify the island's contours $self->islands->[$i]->simplify($self->_inner_margin); + + # offset the island inwards to make the boundaries for internal movements + # so that no motion along external perimeters happens $self->_inner->[$i] = [ $self->islands->[$i]->offset_ex(-$self->_inner_margin) ] if !$self->no_internal; + + # offset the island outwards to make the boundaries for external movements $self->_outer->[$i] = [ $self->islands->[$i]->contour->offset($self->_outer_margin) ]; + + # further simplification (isn't this a duplication of the one above?) $_->simplify($self->_inner_margin) for @{$self->_inner->[$i]}, @{$self->_outer->[$i]}; + # if internal motion is enabled, build a set of utility expolygons representing + # the outer boundaries (as contours) and the inner boundaries (as holes). whenever + # we jump from a hole to a contour or viceversa, we know we're crossing a perimeter if (!$self->no_internal) { $self->_contours_ex->[$i] = diff_ex( $self->_outer->[$i], @@ -81,7 +94,7 @@ sub BUILD { my ($polygon, $line) = @_; @{Boost::Geometry::Utils::polygon_linestring_intersection( $polygon->boost_polygon, - Boost::Geometry::Utils::linestring($line), + $line->boost_linestring, )} > 0; }; @@ -148,10 +161,11 @@ sub BUILD { require "Slic3r/SVG.pm"; Slic3r::SVG::output(undef, "space.svg", lines => \@lines, + points => [ values %{$self->_pointmap} ], no_arrows => 1, - polygons => [ map @$_, @{$self->islands} ], - red_polygons => [ map $_->holes, map @$_, @{$self->_inner} ], - white_polygons => [ map @$_, @{$self->_outer} ], + #polygons => [ map @$_, @{$self->islands} ], + #red_polygons => [ map $_->holes, map @$_, @{$self->_inner} ], + #white_polygons => [ map @$_, @{$self->_outer} ], ); printf "%d islands\n", scalar @{$self->islands}; } diff --git a/lib/Slic3r/SVG.pm b/lib/Slic3r/SVG.pm index 1bfa839f6..9b00001e0 100644 --- a/lib/Slic3r/SVG.pm +++ b/lib/Slic3r/SVG.pm @@ -13,7 +13,6 @@ sub factor { sub svg { my ($print) = @_; - $print ||= Slic3r::Print->new(x_length => 200 / &Slic3r::SCALING_FACTOR, y_length => 200 / &Slic3r::SCALING_FACTOR); my $svg = SVG->new(width => 200 * 10, height => 200 * 10); my $marker_end = $svg->marker(