From 0b63afb370c079f30726a986c23769a2de1d6130 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 2 Nov 2013 14:44:30 +0100 Subject: [PATCH] Fix complete_objects after XS port. Includes regression test. #1511 --- lib/Slic3r/Print.pm | 8 +++----- lib/Slic3r/Test.pm | 7 +++++-- t/gcode.t | 10 +++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 557237db1..f1c645cd5 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -7,7 +7,7 @@ use List::Util qw(min 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 MAX PI scale unscale move_points chained_path); -use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex offset +use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex intersection offset offset2 traverse_pt JT_ROUND JT_SQUARE); use Time::HiRes qw(gettimeofday tv_interval); @@ -170,9 +170,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) = map Slic3r::Polygon->new(@$_), - @{Slic3r::Geometry::Clipper::offset( - [$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND)}; + ($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; @@ -180,7 +178,7 @@ sub validate { if (@{ intersection(\@a, [$copy_clearance]) }) { die "Some objects are too close; your extruder will collide with them.\n"; } - @a = map @$_, @{union_ex([ @a, $copy_clearance ])}; + @a = map $_->clone, map @$_, @{union_ex([ @a, $copy_clearance ])}; } } } diff --git a/lib/Slic3r/Test.pm b/lib/Slic3r/Test.pm index 811d14a2b..6f2b5d403 100644 --- a/lib/Slic3r/Test.pm +++ b/lib/Slic3r/Test.pm @@ -90,7 +90,7 @@ sub model { my $object = $model->add_object; $object->add_volume(mesh => $mesh); $object->add_instance( - offset => [0,0], + offset => Slic3r::Point->new(0,0), rotation => $params{rotation} // 0, ); return $model; @@ -106,7 +106,10 @@ sub init_print { my $print = Slic3r::Print->new(config => $config); $model_name = [$model_name] if ref($model_name) ne 'ARRAY'; - $print->add_model(model($_, %params)) for @$model_name; + for my $model (map model($_, %params), @$model_name) { + $model->arrange_objects($config); + $print->add_model($model); + } $print->validate; return $print; diff --git a/t/gcode.t b/t/gcode.t index 04ff13f5d..bb51698d4 100644 --- a/t/gcode.t +++ b/t/gcode.t @@ -1,4 +1,4 @@ -use Test::More tests => 3; +use Test::More tests => 4; use strict; use warnings; @@ -42,4 +42,12 @@ use Slic3r::Test; ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('complete_objects', 1); + $config->set('duplicate', 2); + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + ok Slic3r::Test::gcode($print), "complete_objects"; +} + __END__