Return ExtrusionPath->polyline and ExtrusionLoop->polygon by reference
This commit is contained in:
parent
d2e4bba074
commit
dd70f6be2f
@ -32,6 +32,11 @@ use overload
|
|||||||
'@{}' => sub { $_[0]->arrayref },
|
'@{}' => sub { $_[0]->arrayref },
|
||||||
'fallback' => 1;
|
'fallback' => 1;
|
||||||
|
|
||||||
|
package Slic3r::Polyline::Ref;
|
||||||
|
our @ISA = 'Slic3r::Polyline';
|
||||||
|
|
||||||
|
sub DESTROY {}
|
||||||
|
|
||||||
package Slic3r::Polyline::Collection;
|
package Slic3r::Polyline::Collection;
|
||||||
use overload
|
use overload
|
||||||
'@{}' => sub { $_[0]->arrayref },
|
'@{}' => sub { $_[0]->arrayref },
|
||||||
@ -42,6 +47,11 @@ use overload
|
|||||||
'@{}' => sub { $_[0]->arrayref },
|
'@{}' => sub { $_[0]->arrayref },
|
||||||
'fallback' => 1;
|
'fallback' => 1;
|
||||||
|
|
||||||
|
package Slic3r::Polygon::Ref;
|
||||||
|
our @ISA = 'Slic3r::Polygon';
|
||||||
|
|
||||||
|
sub DESTROY {}
|
||||||
|
|
||||||
package Slic3r::ExPolygon::Collection;
|
package Slic3r::ExPolygon::Collection;
|
||||||
use overload
|
use overload
|
||||||
'@{}' => sub { $_[0]->arrayref },
|
'@{}' => sub { $_[0]->arrayref },
|
||||||
|
@ -16,7 +16,7 @@ my $path = Slic3r::ExtrusionPath->new(
|
|||||||
polyline => Slic3r::Polyline->new(@$points),
|
polyline => Slic3r::Polyline->new(@$points),
|
||||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
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';
|
is_deeply $path->polyline->pp, $points, 'path points roundtrip';
|
||||||
|
|
||||||
$path->reverse;
|
$path->reverse;
|
||||||
|
@ -17,7 +17,7 @@ my $loop = Slic3r::ExtrusionLoop->new(
|
|||||||
polygon => Slic3r::Polygon->new(@$square),
|
polygon => Slic3r::Polygon->new(@$square),
|
||||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
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';
|
is_deeply $loop->polygon->pp, $square, 'polygon points roundtrip';
|
||||||
|
|
||||||
$loop = $loop->clone;
|
$loop = $loop->clone;
|
||||||
|
@ -4,7 +4,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 12;
|
use Test::More tests => 13;
|
||||||
|
|
||||||
my $points = [
|
my $points = [
|
||||||
[100, 100],
|
[100, 100],
|
||||||
@ -35,12 +35,18 @@ is scalar(@$collection), 3, 'append ExtrusionPath';
|
|||||||
$collection->append($loop);
|
$collection->append($loop);
|
||||||
is scalar(@$collection), 4, 'append ExtrusionLoop';
|
is scalar(@$collection), 4, 'append ExtrusionLoop';
|
||||||
|
|
||||||
isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection', 'correct object returned for collection';
|
isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection::Ref', 'correct object returned for collection';
|
||||||
isa_ok $collection->[2], 'Slic3r::ExtrusionPath', 'correct object returned for path';
|
isa_ok $collection->[2], 'Slic3r::ExtrusionPath::Ref', 'correct object returned for path';
|
||||||
isa_ok $collection->[3], 'Slic3r::ExtrusionLoop', 'correct object returned for loop';
|
isa_ok $collection->[3], 'Slic3r::ExtrusionLoop::Ref', 'correct object returned for loop';
|
||||||
|
|
||||||
is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated';
|
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(
|
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
||||||
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0),
|
map Slic3r::ExtrusionPath->new(polyline => $_, role => 0),
|
||||||
|
@ -39,12 +39,12 @@ _new(CLASS, polygon_sv, role, height, flow_spacing)
|
|||||||
Polygon*
|
Polygon*
|
||||||
ExtrusionLoop::polygon(...)
|
ExtrusionLoop::polygon(...)
|
||||||
PREINIT:
|
PREINIT:
|
||||||
const char* CLASS = "Slic3r::Polygon";
|
const char* CLASS = "Slic3r::Polygon::Ref";
|
||||||
CODE:
|
CODE:
|
||||||
if (items > 1) {
|
if (items > 1) {
|
||||||
THIS->polygon.from_SV_check( ST(1) );
|
THIS->polygon.from_SV_check( ST(1) );
|
||||||
}
|
}
|
||||||
RETVAL = new Polygon(THIS->polygon);
|
RETVAL = &(THIS->polygon);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ _new(CLASS, polyline_sv, role, height, flow_spacing)
|
|||||||
Polyline*
|
Polyline*
|
||||||
ExtrusionPath::polyline(...)
|
ExtrusionPath::polyline(...)
|
||||||
PREINIT:
|
PREINIT:
|
||||||
const char* CLASS = "Slic3r::Polyline";
|
const char* CLASS = "Slic3r::Polyline::Ref";
|
||||||
CODE:
|
CODE:
|
||||||
if (items > 1) {
|
if (items > 1) {
|
||||||
THIS->polyline.from_SV_check( ST(1) );
|
THIS->polyline.from_SV_check( ST(1) );
|
||||||
}
|
}
|
||||||
RETVAL = new Polyline(THIS->polyline);
|
RETVAL = &(THIS->polyline);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user