PrusaSlicer-NonPlainar/t/clipper.t

69 lines
1.6 KiB
Perl
Raw Normal View History

use Test::More;
2011-10-10 09:00:19 +00:00
use strict;
use warnings;
2012-12-27 13:16:50 +00:00
plan tests => 3;
2013-08-26 23:26:44 +00:00
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
2013-08-26 23:26:44 +00:00
use Slic3r;
use Slic3r::Geometry::Clipper qw(intersection_ex union_ex diff_ex);
2012-12-27 13:16:50 +00:00
{
my $square = [ # ccw
[10, 10],
[20, 10],
[20, 20],
[10, 20],
];
my $hole_in_square = [ # cw
[14, 14],
[14, 16],
[16, 16],
[16, 14],
];
my $square2 = [ # ccw
[5, 12],
[25, 12],
[25, 18],
[5, 18],
];
2013-08-26 23:26:44 +00:00
my $intersection = intersection_ex([ $square, $hole_in_square ], [ $square2 ]);
2013-08-26 23:26:44 +00:00
is_deeply [ map $_->pp, @$intersection ], [[
[
[20, 12],
[20, 18],
[10, 18],
[10, 12],
],
[
[14, 14],
[14, 16],
[16, 16],
[16, 14],
],
]], 'hole is preserved after intersection';
2012-12-27 13:16:50 +00:00
}
2012-12-27 13:16:50 +00:00
#==========================================================
2012-12-27 13:16:50 +00:00
{
my $contour1 = [ [0,0], [40,0], [40,40], [0,40] ]; # ccw
my $contour2 = [ [10,10], [30,10], [30,30], [10,30] ]; # ccw
my $hole = [ [15,15], [15,25], [25,25], [25,15] ]; # cw
2013-08-26 23:26:44 +00:00
my $union = union_ex([ $contour1, $contour2, $hole ]);
2013-08-26 23:26:44 +00:00
is_deeply [ map $_->pp, @$union ], [[ [ [40,0], [40,40], [0,40], [0,0] ] ]],
2012-12-27 13:16:50 +00:00
'union of two ccw and one cw is a contour with no holes';
2013-08-26 23:26:44 +00:00
my $diff = diff_ex([ $contour1, $contour2 ], [ $hole ]);
is_deeply [ map $_->pp, @$diff ], [[ [ [40,0], [40,40], [0,40], [0,0] ], [ [15,15], [15,25], [25,25], [25,15] ] ]],
2012-12-27 13:16:50 +00:00
'difference of a cw from two ccw is a contour with one hole';
}