From 68e1edab80df32afbdb8ed07aa8c5e5853f22efe Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 5 Nov 2012 00:17:46 +0100 Subject: [PATCH] Require Math::Clipper 1.14 and increase scale factor for offset(). #720 --- Build.PL | 2 +- lib/Slic3r/Geometry/Clipper.pm | 10 +++++----- lib/Slic3r/Layer/Region.pm | 5 ++--- lib/Slic3r/Polygon.pm | 2 +- lib/Slic3r/Polyline.pm | 1 - lib/Slic3r/Print.pm | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Build.PL b/Build.PL index e34a56d0f..2863c6adf 100644 --- a/Build.PL +++ b/Build.PL @@ -11,7 +11,7 @@ my $build = Module::Build->new( 'File::Basename' => '0', 'File::Spec' => '0', 'Getopt::Long' => '0', - 'Math::Clipper' => '1.09', + 'Math::Clipper' => '1.14', 'Math::ConvexHull::MonotoneChain' => '0.01', 'Math::Geometry::Voronoi' => '1.3', 'Math::PlanePath' => '53', diff --git a/lib/Slic3r/Geometry/Clipper.pm b/lib/Slic3r/Geometry/Clipper.pm index 4739f15dc..0c1857a8a 100644 --- a/lib/Slic3r/Geometry/Clipper.pm +++ b/lib/Slic3r/Geometry/Clipper.pm @@ -8,20 +8,20 @@ our @EXPORT_OK = qw(safety_offset offset offset_ex diff_ex diff union_ex intersection_ex xor_ex PFT_EVENODD JT_MITER JT_ROUND JT_SQUARE is_counter_clockwise); -use Math::Clipper 1.09 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockwise area); +use Math::Clipper 1.14 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockwise area); use Slic3r::Geometry qw(scale); our $clipper = Math::Clipper->new; sub safety_offset { my ($polygons, $factor) = @_; - return Math::Clipper::offset($polygons, $factor || (scale 1e-05), 1, JT_MITER, 2); + return Math::Clipper::offset($polygons, $factor || (scale 1e-05), 100000, JT_MITER, 2); } sub offset { my ($polygons, $distance, $scale, $joinType, $miterLimit) = @_; - $scale ||= 1; - $joinType = JT_MITER if !defined $joinType; - $miterLimit ||= 2; + $scale ||= 100000; + $joinType //= JT_MITER; + $miterLimit //= 2; my $offsets = Math::Clipper::offset($polygons, $distance, $scale, $joinType, $miterLimit); return @$offsets; diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 3438ec79e..9701d7a12 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -1,7 +1,6 @@ package Slic3r::Layer::Region; use Moo; -use Math::Clipper ':all'; use Slic3r::ExtrusionPath ':roles'; use Slic3r::Geometry qw(scale shortest_path); use Slic3r::Geometry::Clipper qw(safety_offset union_ex diff_ex intersection_ex); @@ -109,7 +108,7 @@ sub make_surfaces { # now detect thin walls by re-outgrowing offsetted surfaces and subtracting # them from the original slices - my $outgrown = Math::Clipper::offset([ map $_->p, @{$self->slices} ], $distance); + my $outgrown = [ Slic3r::Geometry::Clipper::offset([ map $_->p, @{$self->slices} ], $distance) ]; my $diff = diff_ex( [ map $_->p, @surfaces ], $outgrown, @@ -410,7 +409,7 @@ sub prepare_fill_surfaces { # offset inwards my @offsets = $surface->expolygon->offset_ex(-$distance); - @offsets = @{union_ex(Math::Clipper::offset([ map @$_, @offsets ], $distance, 1, JT_MITER))}; + @offsets = @{union_ex([ Slic3r::Geometry::Clipper::offset([ map @$_, @offsets ], $distance)] )}; # isn't the union_ex useless? map Slic3r::Surface->new( expolygon => $_, surface_type => $surface->surface_type, diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index 3210e7896..96288f73d 100644 --- a/lib/Slic3r/Polygon.pm +++ b/lib/Slic3r/Polygon.pm @@ -21,7 +21,7 @@ sub boost_linestring { sub is_counter_clockwise { my $self = shift; - return Math::Clipper::is_counter_clockwise($self); + return Slic3r::Geometry::Clipper::is_counter_clockwise($self); } sub make_counter_clockwise { diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 8d7f6a434..8cdecf39f 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -2,7 +2,6 @@ package Slic3r::Polyline; use strict; use warnings; -use Math::Clipper qw(); use Scalar::Util qw(reftype); use Slic3r::Geometry qw(A B X Y X1 X2 Y1 Y2 polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices polyline_lines move_points same_point); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 2793da940..6ae8bc537 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -579,7 +579,7 @@ sub make_skirt { my $distance = scale $Slic3r::Config->skirt_distance; for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) { $distance += scale $spacing; - my $loop = Math::Clipper::offset([$convex_hull], $distance, &Slic3r::SCALING_FACTOR * 100, JT_ROUND)->[0]; + my ($loop) = Slic3r::Geometry::Clipper::offset([$convex_hull], $distance, 0.0001, JT_ROUND); push @{$self->skirt}, Slic3r::ExtrusionLoop->pack( polygon => Slic3r::Polygon->new(@$loop), role => EXTR_ROLE_SKIRT, @@ -634,7 +634,7 @@ sub make_brim { polygon => Slic3r::Polygon->new($_), role => EXTR_ROLE_SKIRT, flow_spacing => $Slic3r::first_layer_flow->spacing, - ) for @{Math::Clipper::offset(\@islands, $i * $Slic3r::first_layer_flow->scaled_spacing, 100, JT_SQUARE)}; + ) for Slic3r::Geometry::Clipper::offset(\@islands, $i * $Slic3r::first_layer_flow->scaled_spacing, undef, JT_SQUARE); # TODO: we need the offset inwards/offset outwards logic to avoid overlapping extrusions } }