2013-07-16 18:09:53 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2013-07-16 18:29:15 +00:00
|
|
|
use Test::More tests => 3;
|
2013-07-16 18:09:53 +00:00
|
|
|
|
|
|
|
my $square = [ # ccw
|
|
|
|
[200, 100],
|
|
|
|
[200, 200],
|
|
|
|
[100, 200],
|
2013-07-16 18:29:15 +00:00
|
|
|
[100, 100],
|
2013-07-16 18:09:53 +00:00
|
|
|
];
|
|
|
|
my $hole_in_square = [ # cw
|
2013-07-16 18:29:15 +00:00
|
|
|
[160, 140],
|
2013-07-16 18:09:53 +00:00
|
|
|
[140, 140],
|
|
|
|
[140, 160],
|
|
|
|
[160, 160],
|
|
|
|
];
|
|
|
|
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
|
|
|
|
|
|
|
{
|
2013-07-16 18:29:15 +00:00
|
|
|
my $result = Slic3r::Geometry::Clipper::offset_ex([ @$expolygon ], 5);
|
2013-07-16 18:09:53 +00:00
|
|
|
is_deeply $result->[0]->pp, [ [
|
|
|
|
[205, 95],
|
|
|
|
[205, 205],
|
|
|
|
[95, 205],
|
|
|
|
[95, 95],
|
|
|
|
], [
|
|
|
|
[145, 145],
|
|
|
|
[145, 155],
|
|
|
|
[155, 155],
|
|
|
|
[155, 145],
|
|
|
|
] ], 'offset_ex';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2013-07-16 18:29:15 +00:00
|
|
|
my $result = Slic3r::Geometry::Clipper::offset2_ex([ @$expolygon ], 5, -2);
|
2013-07-16 18:09:53 +00:00
|
|
|
is_deeply $result->[0]->pp, [ [
|
|
|
|
[203, 97],
|
|
|
|
[203, 203],
|
|
|
|
[97, 203],
|
|
|
|
[97, 97],
|
|
|
|
], [
|
|
|
|
[143, 143],
|
|
|
|
[143, 157],
|
|
|
|
[157, 157],
|
|
|
|
[157, 143],
|
|
|
|
] ], 'offset_ex';
|
|
|
|
}
|
|
|
|
|
2013-07-16 18:29:15 +00:00
|
|
|
{
|
|
|
|
my $polygon1 = Slic3r::Polygon->new(@$square);
|
|
|
|
my $polygon2 = Slic3r::Polygon->new(reverse @$hole_in_square);
|
|
|
|
my $result = Slic3r::Geometry::Clipper::diff_ex([$polygon1], [$polygon2]);
|
|
|
|
is_deeply $result->[0]->pp, $expolygon->pp, 'diff_ex';
|
|
|
|
}
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
__END__
|