diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index fb2649192..318cf7c7f 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -32,6 +32,11 @@ use overload '@{}' => sub { $_[0]->arrayref }, 'fallback' => 1; +package Slic3r::Polyline::Ref; +our @ISA = 'Slic3r::Polyline'; + +sub DESTROY {} + package Slic3r::Polyline::Collection; use overload '@{}' => sub { $_[0]->arrayref }, @@ -42,6 +47,11 @@ use overload '@{}' => sub { $_[0]->arrayref }, 'fallback' => 1; +package Slic3r::Polygon::Ref; +our @ISA = 'Slic3r::Polygon'; + +sub DESTROY {} + package Slic3r::ExPolygon::Collection; use overload '@{}' => sub { $_[0]->arrayref }, diff --git a/xs/t/07_extrusionpath.t b/xs/t/07_extrusionpath.t index 835f25a21..78e084ccd 100644 --- a/xs/t/07_extrusionpath.t +++ b/xs/t/07_extrusionpath.t @@ -16,7 +16,7 @@ my $path = Slic3r::ExtrusionPath->new( polyline => Slic3r::Polyline->new(@$points), role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, ); -isa_ok $path->polyline, 'Slic3r::Polyline', 'path polyline'; +isa_ok $path->polyline, 'Slic3r::Polyline::Ref', 'path polyline'; is_deeply $path->polyline->pp, $points, 'path points roundtrip'; $path->reverse; diff --git a/xs/t/08_extrusionloop.t b/xs/t/08_extrusionloop.t index a218825f1..bd729361f 100644 --- a/xs/t/08_extrusionloop.t +++ b/xs/t/08_extrusionloop.t @@ -17,7 +17,7 @@ my $loop = Slic3r::ExtrusionLoop->new( polygon => Slic3r::Polygon->new(@$square), role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, ); -isa_ok $loop->polygon, 'Slic3r::Polygon', 'loop polygon'; +isa_ok $loop->polygon, 'Slic3r::Polygon::Ref', 'loop polygon'; is_deeply $loop->polygon->pp, $square, 'polygon points roundtrip'; $loop = $loop->clone; diff --git a/xs/t/12_extrusionpathcollection.t b/xs/t/12_extrusionpathcollection.t index 176eac5c6..5d1704f0a 100644 --- a/xs/t/12_extrusionpathcollection.t +++ b/xs/t/12_extrusionpathcollection.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 12; +use Test::More tests => 13; my $points = [ [100, 100], @@ -35,12 +35,18 @@ is scalar(@$collection), 3, 'append ExtrusionPath'; $collection->append($loop); is scalar(@$collection), 4, 'append ExtrusionLoop'; -isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection', 'correct object returned for collection'; -isa_ok $collection->[2], 'Slic3r::ExtrusionPath', 'correct object returned for path'; -isa_ok $collection->[3], 'Slic3r::ExtrusionLoop', 'correct object returned for loop'; +isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection::Ref', 'correct object returned for collection'; +isa_ok $collection->[2], 'Slic3r::ExtrusionPath::Ref', 'correct object returned for path'; +isa_ok $collection->[3], 'Slic3r::ExtrusionLoop::Ref', 'correct object returned for loop'; is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated'; +{ + my $collection_loop = $collection->[3]; + $collection_loop->polygon->scale(2); + is_deeply $collection->[3]->polygon->pp, $collection_loop->polygon->pp, 'items are returned by reference'; +} + { my $collection = Slic3r::ExtrusionPath::Collection->new( map Slic3r::ExtrusionPath->new(polyline => $_, role => 0), diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index ecc117ef1..9c9249bf2 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -39,12 +39,12 @@ _new(CLASS, polygon_sv, role, height, flow_spacing) Polygon* ExtrusionLoop::polygon(...) PREINIT: - const char* CLASS = "Slic3r::Polygon"; + const char* CLASS = "Slic3r::Polygon::Ref"; CODE: if (items > 1) { THIS->polygon.from_SV_check( ST(1) ); } - RETVAL = new Polygon(THIS->polygon); + RETVAL = &(THIS->polygon); OUTPUT: RETVAL diff --git a/xs/xsp/ExtrusionPath.xsp b/xs/xsp/ExtrusionPath.xsp index 7e52ac00c..9978e952e 100644 --- a/xs/xsp/ExtrusionPath.xsp +++ b/xs/xsp/ExtrusionPath.xsp @@ -41,12 +41,12 @@ _new(CLASS, polyline_sv, role, height, flow_spacing) Polyline* ExtrusionPath::polyline(...) PREINIT: - const char* CLASS = "Slic3r::Polyline"; + const char* CLASS = "Slic3r::Polyline::Ref"; CODE: if (items > 1) { THIS->polyline.from_SV_check( ST(1) ); } - RETVAL = new Polyline(THIS->polyline); + RETVAL = &(THIS->polyline); OUTPUT: RETVAL