PrusaSlicer-NonPlainar/xs/t/09_polyline.t

46 lines
1.0 KiB
Perl
Raw Normal View History

2013-07-15 21:23:35 +00:00
#!/usr/bin/perl
use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 7;
2013-07-15 21:23:35 +00:00
my $points = [
[100, 100],
[200, 100],
[200, 200],
];
my $polyline = Slic3r::Polyline->new(@$points);
2013-07-15 21:23:35 +00:00
is_deeply $polyline->pp, $points, 'polyline roundtrip';
is ref($polyline->arrayref), 'ARRAY', 'polyline arrayref is unblessed';
isa_ok $polyline->[0], 'Slic3r::Point::Ref', 'polyline point is blessed';
2013-07-15 21:23:35 +00:00
my $lines = $polyline->lines;
is_deeply [ map $_->pp, @$lines ], [
[ [100, 100], [200, 100] ],
[ [200, 100], [200, 200] ],
], 'polyline lines';
$polyline->append_polyline($polyline->clone);
is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
{
my $len = $polyline->length;
$polyline->clip_end($len/3);
ok abs($polyline->length - ($len-($len/3))) < 1, 'clip_end';
}
{
my $polyline = Slic3r::Polyline->new(
[0,0], [50,50], [100,0], [125,-25], [150,50],
);
$polyline->simplify(25);
is_deeply $polyline->pp, [ [0, 0], [50, 50], [125, -25], [150, 50] ], 'Douglas-Peucker';
}
2013-07-15 21:23:35 +00:00
__END__