From 36e1ea0caa653a2dbd286b0b2ef891ee3331276a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 21 Nov 2011 16:35:10 +0100 Subject: [PATCH] Make sure bridges don't overlap. #58 --- lib/Slic3r/Layer.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 5d5b1f821..ff59de281 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -297,6 +297,7 @@ sub make_surfaces { $self->cleanup_lines; eval { $detect->(); }; + warn $@ if $@; if (@discarded_lines) { print " Warning: even slow detection algorithm throwed errors. Review the output before printing.\n"; @@ -441,6 +442,36 @@ sub process_bridges { ), @$intersection; } } + + # now we need to merge bridges to avoid overlapping + { + # build a list of unique bridge types + my $unique_type = sub { $_[0]->surface_type . "_" . ($_[0]->bridge_angle || '') }; + my @unique_types = (); + foreach my $bridge (@{$self->bridges}) { + push @unique_types, $unique_type->($bridge); + } + + # merge bridges of the same type, removing any of the bridges already merged; + # the order of @unique_types determines the priority between bridges having + # different surface_type or bridge_angle + my @bridges = (); + foreach my $type (@unique_types) { + my @surfaces = grep { $unique_type->($_) eq $type } @{$self->bridges}; + my $union = union_ex([ map $_->p, @surfaces ]); + my $diff = diff_ex( + [ map @$_, @$union ], + [ map $_->p, @bridges ], + ); + + push @bridges, map Slic3r::Surface::Bridge->cast_from_expolygon($_, + surface_type => $surfaces[0]->surface_type, + bridge_angle => $surfaces[0]->bridge_angle, + ), @$union; + } + + @{$self->bridges} = @bridges; + } } # generates a set of surfaces that will be used to make perimeters