Bless arrayref representation into Slic3r classes

This commit is contained in:
Alessandro Ranellucci 2013-07-07 13:34:55 +02:00
parent 53e4532f9c
commit 989e48ede0
5 changed files with 11 additions and 5 deletions

View File

@ -46,7 +46,7 @@ polygon2perl(Polygon& poly) {
for (unsigned int i = 0; i < num_points; i++) { for (unsigned int i = 0; i < num_points; i++) {
av_store(av, i, point2perl(poly[i])); av_store(av, i, point2perl(poly[i]));
} }
return (SV*)newRV_noinc((SV*)av); return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Polygon", GV_ADD));
} }
#endif #endif

View File

@ -21,7 +21,7 @@ point2perl(Point& point) {
AV* av = newAV(); AV* av = newAV();
av_fill(av, 1); av_fill(av, 1);
av_store_point_xy(av, point.x, point.y); av_store_point_xy(av, point.x, point.y);
return (SV*)newRV_noinc((SV*)av); return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Point", GV_ADD));
} }
#endif #endif

View File

@ -4,9 +4,11 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 1; use Test::More tests => 2;
my $point = Slic3r::Point::XS->new(10, 15); my $point = Slic3r::Point::XS->new(10, 15);
is_deeply [ @$point ], [10, 15], 'point roundtrip'; is_deeply [ @$point ], [10, 15], 'point roundtrip';
isa_ok $point->arrayref, 'Slic3r::Point', 'Perl point is blessed';
__END__ __END__

View File

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 1; use Test::More tests => 4;
my $square = [ # ccw my $square = [ # ccw
[100, 100], [100, 100],
@ -22,4 +22,8 @@ my $hole_in_square = [ # cw
my $expolygon = Slic3r::ExPolygon::XS->new($square, $hole_in_square); my $expolygon = Slic3r::ExPolygon::XS->new($square, $hole_in_square);
is_deeply [ @$expolygon ], [$square, $hole_in_square], 'expolygon roundtrip'; is_deeply [ @$expolygon ], [$square, $hole_in_square], 'expolygon roundtrip';
isa_ok $expolygon->arrayref, 'Slic3r::ExPolygon', 'Perl expolygon is blessed';
isa_ok $expolygon->[0], 'Slic3r::Polygon', 'Perl polygons are blessed';
isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
__END__ __END__

View File

@ -30,7 +30,7 @@ ExPolygon::arrayref()
for (unsigned int i = 0; i < num_holes; i++) { for (unsigned int i = 0; i < num_holes; i++) {
av_store(av, i+1, polygon2perl(THIS->holes[i])); av_store(av, i+1, polygon2perl(THIS->holes[i]));
} }
RETVAL = (SV*)newRV_noinc((SV*)av); RETVAL = sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::ExPolygon", GV_ADD));
OUTPUT: OUTPUT:
RETVAL RETVAL