From 2f046799f26fdf923ab25d38f536758437a76316 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 26 Mar 2013 14:03:24 +0100 Subject: [PATCH] Removed offset() method from Slic3r::Polygon because it only works with ccw polygons --- lib/Slic3r/GCode/MotionPlanner.pm | 5 +++-- lib/Slic3r/GUI/Plater.pm | 6 +++--- lib/Slic3r/Polygon.pm | 7 +------ lib/Slic3r/Polyline.pm | 5 ++++- lib/Slic3r/Print.pm | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/Slic3r/GCode/MotionPlanner.pm b/lib/Slic3r/GCode/MotionPlanner.pm index 114f6a2be..0cde4e1af 100644 --- a/lib/Slic3r/GCode/MotionPlanner.pm +++ b/lib/Slic3r/GCode/MotionPlanner.pm @@ -13,7 +13,7 @@ has '_crossing_edges' => (is => 'rw', default => sub { {} }); # edge_idx => boo use List::Util qw(first); use Slic3r::Geometry qw(A B scale epsilon nearest_point); -use Slic3r::Geometry::Clipper qw(diff_ex JT_MITER); +use Slic3r::Geometry::Clipper qw(diff_ex offset JT_MITER); # clearance (in mm) from the perimeters has '_inner_margin' => (is => 'ro', default => sub { scale 0.5 }); @@ -68,7 +68,8 @@ sub BUILD { : [ $self->islands->[$i]->offset_ex(-$self->_inner_margin) ]; # offset the island outwards to make the boundaries for external movements - $self->_outer->[$i] = [ $self->islands->[$i]->contour->offset($self->_outer_margin) ]; + $self->_outer->[$i] = [ offset([ $self->islands->[$i]->contour], $self->_outer_margin) ]; + bless $_, 'Slic3r::Polygon' for @{ $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 diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index c0e300120..ba527324a 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -7,7 +7,7 @@ use File::Basename qw(basename dirname); use List::Util qw(max sum first); use Math::ConvexHull::MonotoneChain qw(convex_hull); use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX); -use Slic3r::Geometry::Clipper qw(JT_ROUND); +use Slic3r::Geometry::Clipper qw(offset JT_ROUND); use threads::shared qw(shared_clone); use Wx qw(:bitmap :brush :button :cursor :dialog :filedialog :font :keycode :icon :id :listctrl :misc :panel :pen :sizer :toolbar :window); use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL EVT_CHOICE); @@ -881,7 +881,7 @@ sub repaint { # if sequential printing is enabled and we have more than one object if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) { my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, @{$parent->{object_previews}->[-1][2]->expolygons} ])); - my $clearance = +($convex_hull->offset($parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND))[0]; + my ($clearance) = offset([$convex_hull], $parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND); $dc->SetPen($parent->{clearance_pen}); $dc->SetBrush($parent->{transparent_brush}); $dc->DrawPolygon($parent->_y($clearance), 0, 0); @@ -892,7 +892,7 @@ sub repaint { # draw skirt if (@{$parent->{object_previews}} && $parent->{config}->skirts) { my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, map @{$_->[2]->expolygons}, @{$parent->{object_previews}} ])); - $convex_hull = +($convex_hull->offset($parent->{config}->skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND))[0]; + ($convex_hull) = offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND); $dc->SetPen($parent->{skirt_pen}); $dc->SetBrush($parent->{transparent_brush}); $dc->DrawPolygon($parent->_y($convex_hull), 0, 0) if $convex_hull; diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index 07f36d4f1..a89cc0791 100644 --- a/lib/Slic3r/Polygon.pm +++ b/lib/Slic3r/Polygon.pm @@ -95,11 +95,6 @@ sub area { return Slic3r::Geometry::Clipper::area($self); } -sub offset { - my $self = shift; - return map Slic3r::Polygon->new($_), Slic3r::Geometry::Clipper::offset([$self], @_); -} - sub grow { my $self = shift; return $self->split_at_first_point->grow(@_); @@ -147,7 +142,7 @@ sub is_printable { # detect them and we would be discarding them. my $p = $self->clone; $p->make_counter_clockwise; - return $p->offset(-$width / 2) ? 1 : 0; + return Slic3r::Geometry::Clipper::offset([$p], -$width / 2) ? 1 : 0; } sub is_valid { diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 2578e505d..4d7fbe90e 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -86,7 +86,10 @@ sub length { sub grow { my $self = shift; - return Slic3r::Polygon->new(@$self, CORE::reverse @$self[1..($#$self-1)])->offset(@_); + return Slic3r::Geometry::Clipper::offset( + [ Slic3r::Polygon->new(@$self, CORE::reverse @$self[1..($#$self-1)]) ], + @_, + ); } sub nearest_point_to { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 4332fbc6c..6df75f2fe 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -151,7 +151,7 @@ sub validate { { my @points = map [ @$_[X,Y] ], map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes}; my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points)); - $clearance = +($convex_hull->offset(scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND))[0]; + ($clearance) = offset([$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND); } for my $copy (@{$self->objects->[$obj_idx]->copies}) { my $copy_clearance = $clearance->clone;