From 77c479c127f82918e3bba12bce0f9c20dab22f41 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci <aar@cpan.org> Date: Mon, 15 Jul 2013 23:23:35 +0200 Subject: [PATCH] Add test for polyline lines --- xs/src/Line.hpp | 13 ------------- xs/t/09_polyline.t | 27 +++++++++++++++++++++++++++ xs/xsp/my.map | 13 +++++++------ 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 xs/t/09_polyline.t diff --git a/xs/src/Line.hpp b/xs/src/Line.hpp index 466f5efae..f383e0a51 100644 --- a/xs/src/Line.hpp +++ b/xs/src/Line.hpp @@ -110,19 +110,6 @@ Line::to_SV_pureperl() { return newRV_noinc((SV*)av); } -SV* -lines2perl(pTHX_ Lines& lines) -{ - AV* av = newAV(); - av_extend(av, lines.size()-1); - int i = 0; - for (Lines::iterator it = lines.begin(); it != lines.end(); ++it) { - SV* sv = (*it).to_SV_ref(); - av_store(av, i++, sv); - } - return (SV*)newRV_noinc((SV*)av); -} - } #endif diff --git a/xs/t/09_polyline.t b/xs/t/09_polyline.t new file mode 100644 index 000000000..6fd81fa9c --- /dev/null +++ b/xs/t/09_polyline.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Slic3r::XS; +use Test::More tests => 4; + +my $points = [ + [100, 100], + [200, 100], + [200, 200], +]; + +my $polyline = Slic3r::Polyline->new(@$points); +is_deeply $polyline->pp, $points, 'polyline roundtrip'; + +is ref($polyline->arrayref), 'ARRAY', 'polyline arrayref is unblessed'; +isa_ok $polyline->[0], 'Slic3r::Point', 'polyline point is blessed'; + +my $lines = $polyline->lines; +is_deeply [ map $_->pp, @$lines ], [ + [ [100, 100], [200, 100] ], + [ [200, 100], [200, 200] ], +], 'polyline lines'; + +__END__ diff --git a/xs/xsp/my.map b/xs/xsp/my.map index c6c55c3d6..9245b2160 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -15,15 +15,16 @@ ExtrusionRole T_UV SurfaceType T_UV Lines T_LINES -Lines* T_LINES_PTR INPUT OUTPUT T_LINES - $arg = lines2perl(aTHX_ $var); - -T_LINES_PTR - $arg = lines2perl(aTHX_ *$var); - delete $var; + AV* av = newAV(); + $arg = newRV_noinc((SV*)av); + const unsigned int len = $var.size(); + av_extend(av, len-1); + for (unsigned int i = 0; i < len; i++) { + av_store(av, i, ${var}[i].to_SV_ref()); + } \ No newline at end of file