2013-07-15 21:23:35 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2022-05-05 15:57:48 +00:00
|
|
|
use Test::More tests => 15;
|
2013-07-15 21:23:35 +00:00
|
|
|
|
|
|
|
my $points = [
|
|
|
|
[100, 100],
|
|
|
|
[200, 100],
|
|
|
|
[200, 200],
|
|
|
|
];
|
|
|
|
|
|
|
|
my $polyline = Slic3r::Polyline->new(@$points);
|
2013-09-03 17:26:58 +00:00
|
|
|
|
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';
|
|
|
|
|
2013-08-28 23:36:42 +00:00
|
|
|
$polyline->append_polyline($polyline->clone);
|
|
|
|
is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
|
|
|
|
|
2013-10-27 21:57:25 +00:00
|
|
|
{
|
|
|
|
my $len = $polyline->length;
|
|
|
|
$polyline->clip_end($len/3);
|
|
|
|
ok abs($polyline->length - ($len-($len/3))) < 1, 'clip_end';
|
|
|
|
}
|
|
|
|
|
2015-01-03 14:03:53 +00:00
|
|
|
{
|
|
|
|
my $polyline = Slic3r::Polyline->new(
|
|
|
|
[0,0], [20,0], [50,0], [80,0], [100,0],
|
|
|
|
);
|
|
|
|
$polyline->simplify(2);
|
|
|
|
is_deeply $polyline->pp, [ [0,0], [100,0] ], 'Douglas-Peucker';
|
|
|
|
}
|
|
|
|
|
2013-11-22 15:01:50 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2015-01-03 14:03:53 +00:00
|
|
|
{
|
|
|
|
my $polyline = Slic3r::Polyline->new(
|
|
|
|
[0,0], [100,0], [50,10],
|
|
|
|
);
|
|
|
|
$polyline->simplify(25);
|
|
|
|
is_deeply $polyline->pp, [ [0,0], [100,0], [50,10] ], 'Douglas-Peucker uses shortest distance instead of perpendicular distance';
|
|
|
|
}
|
|
|
|
|
2014-03-15 15:53:20 +00:00
|
|
|
{
|
|
|
|
my $polyline = Slic3r::Polyline->new(@$points);
|
|
|
|
is $polyline->length, 100*2, 'length';
|
|
|
|
$polyline->extend_end(50);
|
|
|
|
is $polyline->length, 100*2 + 50, 'extend_end';
|
|
|
|
$polyline->extend_start(50);
|
|
|
|
is $polyline->length, 100*2 + 50 + 50, 'extend_start';
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:28:12 +00:00
|
|
|
{
|
|
|
|
my $polyline = Slic3r::Polyline->new(@$points);
|
|
|
|
my $p1 = Slic3r::Polyline->new;
|
|
|
|
my $p2 = Slic3r::Polyline->new;
|
|
|
|
my $point = Slic3r::Point->new(150, 100);
|
|
|
|
$polyline->split_at($point, $p1, $p2);
|
|
|
|
is scalar(@$p1), 2, 'split_at';
|
|
|
|
is scalar(@$p2), 3, 'split_at';
|
|
|
|
ok $p1->last_point->coincides_with($point), 'split_at';
|
|
|
|
ok $p2->first_point->coincides_with($point), 'split_at';
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:51:57 +00:00
|
|
|
{
|
|
|
|
my $polyline = Slic3r::Polyline->new(@$points[0,1,2,0]);
|
|
|
|
my $p1 = Slic3r::Polyline->new;
|
|
|
|
my $p2 = Slic3r::Polyline->new;
|
|
|
|
$polyline->split_at($polyline->first_point, $p1, $p2);
|
|
|
|
is scalar(@$p1), 1, 'split_at';
|
|
|
|
is scalar(@$p2), 4, 'split_at';
|
|
|
|
}
|
|
|
|
|
2013-07-15 21:23:35 +00:00
|
|
|
__END__
|