From 7475762a275aeb859486bd7fd89fea7ead360779 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 21 Nov 2013 18:47:25 +0100 Subject: [PATCH] Remove residual uses of Boost for line clipping --- lib/Slic3r/ExPolygon.pm | 4 ++-- lib/Slic3r/Print/SupportMaterial.pm | 22 +++++++++++----------- lib/Slic3r/Test/SectionCut.pm | 12 ++++++------ utils/gcode_sectioncut.pl | 6 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 80252d78..a1d7cca4 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -110,8 +110,8 @@ sub _medial_axis_clip { push @$covered, map $grow->($_, $width*1.1), @$clipped; # if the first remaining segment is connected to the last polyline, append it - # to that -- NOTE: this assumes that multi_linestring_multi_polygon_difference() - # preserved the orientation of the input linestring + # to that -- FIXME: this assumes that diff_pl() + # preserved the orientation of the input linestring but this is not generally true if (@polylines && @$clipped && $clipped->[0]->first_point->distance_to($polylines[-1]->last_point) <= $width/10) { $polylines[-1]->append_polyline(shift @$clipped); } diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 4a8dd3dc..9cc19a64 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -4,7 +4,8 @@ use Moo; use List::Util qw(sum min max); use Slic3r::ExtrusionPath ':roles'; use Slic3r::Geometry qw(scale scaled_epsilon PI rad2deg deg2rad); -use Slic3r::Geometry::Clipper qw(offset diff union union_ex intersection offset_ex offset2); +use Slic3r::Geometry::Clipper qw(offset diff union union_ex intersection offset_ex offset2 + intersection_pl); use Slic3r::Surface ':types'; has 'config' => (is => 'rw', required => 1); @@ -442,12 +443,12 @@ sub generate_toolpaths { # only consider the loops facing the overhang { - my $overhang_with_margin = offset_ex($overhang, +$flow->scaled_width/2); + my $overhang_with_margin = offset($overhang, +$flow->scaled_width/2); @external_loops = grep { - @{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection( - [ map $_->pp, @$overhang_with_margin ], - [ $_->split_at_first_point->pp ], - ) } + @{intersection_pl( + [ $_->split_at_first_point ], + $overhang_with_margin, + )} } @external_loops; } @@ -467,11 +468,10 @@ sub generate_toolpaths { } # clip such loops to the side oriented towards the object - @loops = map Slic3r::Polyline->new(@$_), - @{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection( - [ map $_->pp, @{offset_ex($overhang, +scale MARGIN)} ], - [ map $_->split_at_first_point->pp, @loops ], - ) }; + @loops = @{intersection_pl( + [ map $_->split_at_first_point, @loops ], + offset($overhang, +scale MARGIN), + )}; # add the contact infill area to the interface area # note that growing loops by $circle_radius ensures no tiny diff --git a/lib/Slic3r/Test/SectionCut.pm b/lib/Slic3r/Test/SectionCut.pm index 6f506722..596d0c1d 100644 --- a/lib/Slic3r/Test/SectionCut.pm +++ b/lib/Slic3r/Test/SectionCut.pm @@ -3,7 +3,7 @@ use Moo; use List::Util qw(first max); use Slic3r::Geometry qw(X Y A B X1 Y1 X2 Y2 unscale); -use Slic3r::Geometry::Clipper qw(union_ex); +use Slic3r::Geometry::Clipper qw(union_ex intersection_pl); use SVG; has 'scale' => (is => 'ro', default => sub {30}); @@ -17,7 +17,7 @@ sub _build_line { my $bb = $self->print->bounding_box; my $y = $bb->size->[Y] * $self->y_percent; - return [ [ $bb->x_min, $y ], [ $bb->x_max, $y ] ] + return Slic3r::Line->new([ $bb->x_min, $y ], [ $bb->x_max, $y ]); } sub export_svg { @@ -91,10 +91,10 @@ sub _plot { foreach my $path (@paths) { foreach my $line (@{$path->lines}) { - my @intersections = @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection( - Slic3r::ExPolygon->new(@{$line->grow(Slic3r::Geometry::scale $path->flow_spacing/2)})->pp, - [ $self->line ], - ) }; + my @intersections = @{intersection_pl( + [ $self->line->as_polyline ], + $line->grow(Slic3r::Geometry::scale $path->flow_spacing/2), + )}; die "Intersection has more than two points!\n" if first { @$_ > 2 } @intersections; if ($path->is_bridge) { diff --git a/utils/gcode_sectioncut.pl b/utils/gcode_sectioncut.pl index 733208a3..4d9619e4 100644 --- a/utils/gcode_sectioncut.pl +++ b/utils/gcode_sectioncut.pl @@ -80,10 +80,10 @@ my %opt = ( # draw paths foreach my $z (sort keys %paths) { foreach my $line (@{ $paths{$z} }) { - my @intersections = @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection( - Slic3r::ExPolygon->new(_grow($line, $opt{extrusion_width}/2)), + my @intersections = @{intersection_pl( [ $section_line ], - ) }; + [ _grow($line, $opt{extrusion_width}/2) ], + )}; $g->rectangle( 'x' => $opt{scale} * ($_->[A][X] - $bounding_box->x_min),