Add test for polyline lines
This commit is contained in:
parent
439255ca46
commit
77c479c127
3 changed files with 34 additions and 19 deletions
|
@ -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
|
||||
|
|
27
xs/t/09_polyline.t
Normal file
27
xs/t/09_polyline.t
Normal file
|
@ -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__
|
|
@ -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());
|
||||
}
|
Loading…
Add table
Reference in a new issue