2013-07-14 11:05:55 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2014-02-10 12:19:44 +00:00
|
|
|
use Test::More tests => 15;
|
2013-07-14 11:05:55 +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],
|
|
|
|
];
|
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
2013-07-14 11:05:55 +00:00
|
|
|
my $surface = Slic3r::Surface->new(
|
|
|
|
expolygon => $expolygon,
|
|
|
|
surface_type => Slic3r::Surface::S_TYPE_INTERNAL,
|
|
|
|
);
|
|
|
|
|
|
|
|
$surface = $surface->clone;
|
|
|
|
|
2013-08-30 22:28:24 +00:00
|
|
|
isa_ok $surface->expolygon, 'Slic3r::ExPolygon::Ref', 'expolygon';
|
2013-07-15 20:57:22 +00:00
|
|
|
is_deeply [ @{$surface->expolygon->pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
|
2013-08-26 21:03:00 +00:00
|
|
|
is scalar(@{$surface->polygons}), 2, 'polygons roundtrip';
|
2013-07-14 11:05:55 +00:00
|
|
|
|
|
|
|
is $surface->surface_type, Slic3r::Surface::S_TYPE_INTERNAL, 'surface_type';
|
|
|
|
$surface->surface_type(Slic3r::Surface::S_TYPE_BOTTOM);
|
|
|
|
is $surface->surface_type, Slic3r::Surface::S_TYPE_BOTTOM, 'modify surface_type';
|
|
|
|
|
|
|
|
$surface->bridge_angle(30);
|
|
|
|
is $surface->bridge_angle, 30, 'bridge_angle';
|
|
|
|
|
|
|
|
$surface->extra_perimeters(2);
|
|
|
|
is $surface->extra_perimeters, 2, 'extra_perimeters';
|
|
|
|
|
2013-08-30 22:28:24 +00:00
|
|
|
{
|
|
|
|
my $surface2 = $surface->clone;
|
|
|
|
$surface2->expolygon->scale(2);
|
|
|
|
isnt $surface2->expolygon->area, $expolygon->area, 'expolygon is returned by reference';
|
|
|
|
}
|
|
|
|
|
2013-07-14 12:56:43 +00:00
|
|
|
{
|
2014-11-09 15:23:50 +00:00
|
|
|
my $collection = Slic3r::Surface::Collection->new;
|
|
|
|
$collection->append($_) for $surface, $surface->clone;
|
2013-07-14 12:56:43 +00:00
|
|
|
is scalar(@$collection), 2, 'collection has the right number of items';
|
2013-07-15 20:57:22 +00:00
|
|
|
is_deeply $collection->[0]->expolygon->pp, [$square, $hole_in_square],
|
2013-07-14 12:56:43 +00:00
|
|
|
'collection returns a correct surface expolygon';
|
|
|
|
$collection->clear;
|
|
|
|
is scalar(@$collection), 0, 'clear collection';
|
|
|
|
$collection->append($surface);
|
|
|
|
is scalar(@$collection), 1, 'append to collection';
|
2013-07-15 10:14:22 +00:00
|
|
|
|
|
|
|
my $item = $collection->[0];
|
2013-09-06 16:36:38 +00:00
|
|
|
isa_ok $item, 'Slic3r::Surface::Ref';
|
2013-07-15 10:14:22 +00:00
|
|
|
$item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL);
|
2013-09-06 16:36:38 +00:00
|
|
|
is $item->surface_type, $collection->[0]->surface_type, 'collection returns items by reference';
|
2013-07-14 12:56:43 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 17:15:59 +00:00
|
|
|
{
|
2014-11-09 15:23:50 +00:00
|
|
|
my $collection = Slic3r::Surface::Collection->new;
|
|
|
|
$collection->append($_) for
|
2013-11-23 17:15:59 +00:00
|
|
|
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
|
|
|
|
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
|
2014-11-09 15:23:50 +00:00
|
|
|
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_TOP);
|
2013-11-23 17:15:59 +00:00
|
|
|
is scalar(@{$collection->group}), 2, 'group() returns correct number of groups';
|
|
|
|
}
|
|
|
|
|
2013-07-14 11:05:55 +00:00
|
|
|
__END__
|