From 6e216e2fd947d96782253da0d44a4ce20899e679 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 May 2013 09:24:48 +0200 Subject: [PATCH] New traverse_pt() --- lib/Slic3r/Geometry/Clipper.pm | 19 ++++++++++++++++++- lib/Slic3r/Print.pm | 33 +++++++-------------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/Slic3r/Geometry/Clipper.pm b/lib/Slic3r/Geometry/Clipper.pm index 801f26463..b6d0eb523 100644 --- a/lib/Slic3r/Geometry/Clipper.pm +++ b/lib/Slic3r/Geometry/Clipper.pm @@ -6,7 +6,7 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(safety_offset safety_offset_ex offset offset_ex collapse_ex diff_ex diff union_ex intersection_ex xor_ex PFT_EVENODD JT_MITER JT_ROUND - JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex); + JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt); use Math::Clipper 1.21 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockwise area); use Slic3r::Geometry qw(scale); @@ -145,4 +145,21 @@ sub simplify_polygons { return @{ Math::Clipper::simplify_polygons($polygons, $pft // PFT_NONZERO) }; } +sub traverse_pt { + my ($polynodes) = @_; + + # use a nearest neighbor search to order these children + # TODO: supply second argument to chained_path_items() too? + my @nodes = @{Slic3r::Geometry::chained_path_items( + [ map [ ($_->{outer} ? $_->{outer}[0] : $_->{hole}[0]), $_ ], @$polynodes ], + )}; + + my @polygons = (); + foreach my $polynode (@$polynodes) { + push @polygons, traverse_pt($polynode->{children}); + push @polygons, $polynode->{outer} // [ reverse @{$polynode->{hole}} ] + } + return @polygons; +} + 1; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d5589227a..9841e4fd7 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -6,9 +6,9 @@ use File::Spec; use List::Util qw(max first); use Math::ConvexHull::MonotoneChain qw(convex_hull); use Slic3r::ExtrusionPath ':roles'; -use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN PI scale unscale move_points nearest_point chained_path_items); +use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN PI scale unscale move_points nearest_point); use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex offset - offset2 JT_ROUND JT_SQUARE PFT_EVENODD); + offset2 traverse_pt JT_ROUND JT_SQUARE PFT_EVENODD); use Time::HiRes qw(gettimeofday tv_interval); has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1); @@ -683,30 +683,11 @@ sub make_brim { push @loops, offset2(\@islands, ($i - 2) * $flow->scaled_spacing, ($i + 1.5) * $flow->scaled_spacing, undef, JT_SQUARE); } - # prepare a subroutine to traverse the tree and return inner perimeters first - my $traverse; - $traverse = sub { - my ($loops) = @_; - - # use a nearest neighbor search to order these children - # TODO: supply second argument to chained_path_items() too? - @$loops = @{chained_path_items( - [ map [ ($_->{outer} ? $_->{outer}[0] : $_->{hole}[0]), $_ ], @$loops ], - )}; - - my @polygons = (); - foreach my $loop (@$loops) { - push @polygons, $traverse->($loop->{children}); - push @polygons, Slic3r::ExtrusionLoop->pack( - polygon => Slic3r::Polygon->new($loop->{outer} // [ reverse @{$loop->{hole}} ]), - role => EXTR_ROLE_SKIRT, - flow_spacing => $flow->spacing, - ); - } - return @polygons; - }; - - @{$self->brim} = reverse $traverse->( union_pt(\@loops, PFT_EVENODD) ); + @{$self->brim} = map Slic3r::ExtrusionLoop->pack( + polygon => Slic3r::Polygon->new($_), + role => EXTR_ROLE_SKIRT, + flow_spacing => $flow->spacing, + ), reverse traverse_pt( union_pt(\@loops, PFT_EVENODD) ); } sub write_gcode {