New coverage detection for bridges. Includes implementation of ExPolygon::get_trapezoids()

This commit is contained in:
Alessandro Ranellucci 2014-04-24 13:43:24 +02:00
parent d458a7c4d2
commit 6201aacf88
21 changed files with 358 additions and 27 deletions

View file

@ -3,8 +3,9 @@
use strict;
use warnings;
use List::Util qw(first);
use Slic3r::XS;
use Test::More tests => 21;
use Test::More tests => 31;
use constant PI => 4 * atan2(1, 1);
@ -104,4 +105,32 @@ is $expolygon->area, 100*100-20*20, 'area';
is_deeply $collection->[0]->clone->pp, $collection->[0]->pp, 'clone collection item';
}
{
my $expolygon = Slic3r::ExPolygon->new($square);
my $polygons = $expolygon->get_trapezoids(PI/2);
is scalar(@$polygons), 1, 'correct number of trapezoids returned';
is scalar(@{$polygons->[0]}), 4, 'trapezoid has 4 points';
is $polygons->[0]->area, $expolygon->area, 'trapezoid has correct area';
}
{
my $polygons = $expolygon->get_trapezoids(PI/2);
is scalar(@$polygons), 4, 'correct number of trapezoids returned';
# trapezoid polygons might have more than 4 points in case of collinear segments
$polygons = [ map @{$_->simplify(1)}, @$polygons ];
ok !defined(first { @$_ != 4 } @$polygons), 'all trapezoids have 4 points';
is scalar(grep { $_->area == 40*100 } @$polygons), 2, 'trapezoids have expected area';
is scalar(grep { $_->area == 20*40 } @$polygons), 2, 'trapezoids have expected area';
}
{
my $expolygon = Slic3r::ExPolygon->new([ [0,100],[100,0],[200,0],[300,100],[200,200],[100,200] ]);
my $polygons = $expolygon->get_trapezoids(PI/2);
is scalar(@$polygons), 3, 'correct number of trapezoids returned';
is scalar(grep { $_->area == 100*200/2 } @$polygons), 2, 'trapezoids have expected area';
is scalar(grep { $_->area == 100*200 } @$polygons), 1, 'trapezoids have expected area';
}
__END__