2013-07-06 14:33:49 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2013-07-13 22:38:01 +00:00
|
|
|
use Test::More tests => 11;
|
2013-07-11 16:55:51 +00:00
|
|
|
|
|
|
|
use constant PI => 4 * atan2(1, 1);
|
2013-07-06 14:33:49 +00:00
|
|
|
|
|
|
|
my $square = [ # ccw
|
|
|
|
[100, 100],
|
|
|
|
[200, 100],
|
|
|
|
[200, 200],
|
|
|
|
[100, 200],
|
|
|
|
];
|
|
|
|
my $hole_in_square = [ # cw
|
|
|
|
[140, 140],
|
|
|
|
[140, 160],
|
|
|
|
[160, 160],
|
|
|
|
[160, 140],
|
|
|
|
];
|
|
|
|
|
|
|
|
my $expolygon = Slic3r::ExPolygon::XS->new($square, $hole_in_square);
|
|
|
|
is_deeply [ @$expolygon ], [$square, $hole_in_square], 'expolygon roundtrip';
|
|
|
|
|
2013-07-07 11:34:55 +00:00
|
|
|
isa_ok $expolygon->arrayref, 'Slic3r::ExPolygon', 'Perl expolygon is blessed';
|
|
|
|
isa_ok $expolygon->[0], 'Slic3r::Polygon', 'Perl polygons are blessed';
|
|
|
|
isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
|
|
|
|
2013-07-11 16:55:51 +00:00
|
|
|
{
|
|
|
|
my $clone = $expolygon->clone;
|
|
|
|
is_deeply [ @$clone ], [$square, $hole_in_square], 'clone';
|
|
|
|
# The following tests implicitely check that modifying clones
|
|
|
|
# does not modify the original one.
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $expolygon2 = $expolygon->clone;
|
|
|
|
$expolygon2->scale(2.5);
|
|
|
|
is_deeply [ @$expolygon2 ], [
|
|
|
|
[map [ 2.5*$_->[0], 2.5*$_->[1] ], @$square],
|
|
|
|
[map [ 2.5*$_->[0], 2.5*$_->[1] ], @$hole_in_square]
|
|
|
|
], 'scale';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $expolygon2 = $expolygon->clone;
|
|
|
|
$expolygon2->translate(10, -5);
|
|
|
|
is_deeply [ @$expolygon2 ], [
|
|
|
|
[map [ $_->[0]+10, $_->[1]-5 ], @$square],
|
|
|
|
[map [ $_->[0]+10, $_->[1]-5 ], @$hole_in_square]
|
|
|
|
], 'translate';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $expolygon2 = $expolygon->clone;
|
|
|
|
$expolygon2->rotate(PI/2, Slic3r::Point::XS->new(150,150));
|
|
|
|
is_deeply [ @$expolygon2 ], [
|
|
|
|
[ @$square[1,2,3,0] ],
|
|
|
|
[ @$hole_in_square[3,0,1,2] ]
|
|
|
|
], 'rotate around Point::XS';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $expolygon2 = $expolygon->clone;
|
|
|
|
$expolygon2->rotate(PI/2, [150,150]);
|
|
|
|
is_deeply [ @$expolygon2 ], [
|
|
|
|
[ @$square[1,2,3,0] ],
|
|
|
|
[ @$hole_in_square[3,0,1,2] ]
|
|
|
|
], 'rotate around pure-Perl Point';
|
|
|
|
}
|
2013-07-11 12:13:30 +00:00
|
|
|
|
2013-07-13 22:38:01 +00:00
|
|
|
{
|
|
|
|
my $expolygon2 = $expolygon->clone;
|
|
|
|
$expolygon2->scale(2);
|
|
|
|
my $collection = Slic3r::ExPolygon::Collection->new($expolygon->arrayref, $expolygon2->arrayref);
|
|
|
|
is_deeply [ @$collection ], [ $expolygon->arrayref, $expolygon2->arrayref ],
|
|
|
|
'expolygon collection';
|
|
|
|
my $collection2 = Slic3r::ExPolygon::Collection->new($expolygon, $expolygon2);
|
|
|
|
is_deeply [ @$collection ], [ @$collection2 ],
|
|
|
|
'expolygon collection with XS expolygons';
|
|
|
|
}
|
|
|
|
|
2013-07-06 14:33:49 +00:00
|
|
|
__END__
|