2013-07-15 10:14:22 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2013-08-26 20:39:35 +00:00
|
|
|
use Test::More tests => 11;
|
2013-07-15 10:14:22 +00:00
|
|
|
|
|
|
|
my $square = [ # ccw
|
|
|
|
[100, 100],
|
|
|
|
[200, 100],
|
|
|
|
[200, 200],
|
|
|
|
[100, 200],
|
|
|
|
];
|
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
my $polygon = Slic3r::Polygon->new(@$square);
|
2013-07-15 21:12:13 +00:00
|
|
|
is_deeply $polygon->pp, $square, 'polygon roundtrip';
|
2013-07-15 10:14:22 +00:00
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
is ref($polygon->arrayref), 'ARRAY', 'polygon arrayref is unblessed';
|
|
|
|
isa_ok $polygon->[0], 'Slic3r::Point', 'polygon point is blessed';
|
2013-07-15 10:14:22 +00:00
|
|
|
|
2013-07-15 21:28:23 +00:00
|
|
|
my $lines = $polygon->lines;
|
|
|
|
is_deeply [ map $_->pp, @$lines ], [
|
|
|
|
[ [100, 100], [200, 100] ],
|
|
|
|
[ [200, 100], [200, 200] ],
|
|
|
|
[ [200, 200], [100, 200] ],
|
|
|
|
[ [100, 200], [100, 100] ],
|
|
|
|
], 'polygon lines';
|
|
|
|
|
2013-07-16 15:13:01 +00:00
|
|
|
is_deeply $polygon->split_at_first_point->pp, [ @$square[0,1,2,3,0] ], 'split_at_first_point';
|
|
|
|
is_deeply $polygon->split_at_index(2)->pp, [ @$square[2,3,0,1,2] ], 'split_at_index';
|
2013-08-26 20:39:35 +00:00
|
|
|
is_deeply $polygon->split_at(Slic3r::Point->new(@{$square->[2]}))->pp, [ @$square[2,3,0,1,2] ], 'split_at';
|
2013-07-15 21:38:06 +00:00
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
ok $polygon->is_counter_clockwise, 'is_counter_clockwise';
|
|
|
|
{
|
|
|
|
my $clone = $polygon->clone;
|
|
|
|
$clone->reverse;
|
|
|
|
ok !$clone->is_counter_clockwise, 'is_counter_clockwise';
|
2013-07-16 19:09:29 +00:00
|
|
|
$clone->make_counter_clockwise;
|
|
|
|
ok $clone->is_counter_clockwise, 'make_counter_clockwise';
|
|
|
|
$clone->make_counter_clockwise;
|
|
|
|
ok $clone->is_counter_clockwise, 'make_counter_clockwise';
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 10:14:22 +00:00
|
|
|
__END__
|