diff --git a/lib/Slic3r/ExtrusionPath.pm b/lib/Slic3r/ExtrusionPath.pm index 56e2c349e..7aaf88b5c 100644 --- a/lib/Slic3r/ExtrusionPath.pm +++ b/lib/Slic3r/ExtrusionPath.pm @@ -148,6 +148,7 @@ sub detect_arcs { my $self = shift; my ($max_angle, $len_epsilon) = @_; + $self->deserialize; $max_angle = deg2rad($max_angle || 15); $len_epsilon ||= 10 / $Slic3r::scaling_factor; diff --git a/t/arcs.t b/t/arcs.t index b63c2660e..44535e946 100644 --- a/t/arcs.t +++ b/t/arcs.t @@ -11,7 +11,7 @@ BEGIN { use Slic3r; use Slic3r::ExtrusionPath ':roles'; -use Slic3r::Geometry qw(epsilon); +use Slic3r::Geometry qw(epsilon scale X Y); { my $path = Slic3r::ExtrusionPath->new(polyline => Slic3r::Polyline->new( @@ -32,23 +32,27 @@ use Slic3r::Geometry qw(epsilon); #========================================================== { - my $path1 = Slic3r::ExtrusionPath->new(polyline => Slic3r::Polyline->new( + my @points = map [ scale $_->[0], scale $_->[1] ], ( [10,20], [10.7845909572784,19.9691733373313], [11.5643446504023,19.8768834059514], [12.3344536385591,19.7236992039768], [13.0901699437495,19.5105651629515], [13.8268343236509,19.2387953251129], [14.5399049973955,18.9100652418837], [15.2249856471595,18.5264016435409], [15.8778525229247,18.0901699437495], - [16.4944804833018,17.6040596560003], - ), role => EXTR_ROLE_FILL); + [16.4944804833018,17.6040596560003] + ); + my $path1 = Slic3r::ExtrusionPath->new( + polyline => Slic3r::Polyline->new(@points), + role => EXTR_ROLE_FILL, + ); my $path2 = Slic3r::ExtrusionPath->new( - polyline => Slic3r::Polyline->new(reverse @{$path1->points}), + polyline => Slic3r::Polyline->new(reverse @points), role => EXTR_ROLE_FILL, ); my $collection1 = Slic3r::ExtrusionPath::Collection->new(paths => [$path1]); my $collection2 = Slic3r::ExtrusionPath::Collection->new(paths => [$path2]); - $collection1->detect_arcs(10, 1); - $collection2->detect_arcs(10, 1); + $collection1->detect_arcs(10, scale 1); + $collection2->detect_arcs(10, scale 1); is scalar(@{$collection1->paths}), 1, 'path collection now contains one path'; is scalar(@{$collection2->paths}), 1, 'path collection now contains one path'; @@ -56,18 +60,19 @@ use Slic3r::Geometry qw(epsilon); isa_ok $collection1->paths->[0], 'Slic3r::ExtrusionPath::Arc', 'path'; isa_ok $collection2->paths->[0], 'Slic3r::ExtrusionPath::Arc', 'path'; - my $expected_length = 7.06858347057701; - ok abs($collection1->paths->[0]->length - $expected_length) < epsilon, 'cw oriented arc has correct length'; - ok abs($collection2->paths->[0]->length - $expected_length) < epsilon, 'ccw oriented arc has correct length'; + $_->deserialize for $collection1->paths->[0], $collection2->paths->[0]; + my $expected_length = scale 7.06858347057701; + ok abs($collection1->paths->[0]->length - $expected_length) < scale epsilon, 'cw oriented arc has correct length'; + ok abs($collection2->paths->[0]->length - $expected_length) < scale epsilon, 'ccw oriented arc has correct length'; is $collection1->paths->[0]->orientation, 'cw', 'cw orientation was correctly detected'; is $collection2->paths->[0]->orientation, 'ccw', 'ccw orientation was correctly detected'; my $center1 = [ map sprintf('%.0f', $_), @{ $collection1->paths->[0]->center } ]; - is_deeply $center1, [10,10], 'center was correctly detected'; + ok abs($center1->[X] - scale 10) < scale epsilon && abs($center1->[Y] - scale 10) < scale epsilon, 'center was correctly detected'; my $center2 = [ map sprintf('%.0f', $_), @{ $collection2->paths->[0]->center } ]; - is_deeply $center2, [10,10], 'center was correctly detected'; + ok abs($center2->[X] - scale 10) < scale epsilon && abs($center1->[Y] - scale 10) < scale epsilon, 'center was correctly detected'; } #==========================================================