forked from bambulab/BambuStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_surface.t
76 lines (62 loc) · 2.43 KB
/
05_surface.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 15;
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->new($square, $hole_in_square);
my $surface = Slic3r::Surface->new(
expolygon => $expolygon,
surface_type => Slic3r::Surface::S_TYPE_INTERNAL,
);
$surface = $surface->clone;
isa_ok $surface->expolygon, 'Slic3r::ExPolygon::Ref', 'expolygon';
is_deeply [ @{$surface->expolygon->pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
is scalar(@{$surface->polygons}), 2, 'polygons roundtrip';
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';
{
my $surface2 = $surface->clone;
$surface2->expolygon->scale(2);
isnt $surface2->expolygon->area, $expolygon->area, 'expolygon is returned by reference';
}
{
my $collection = Slic3r::Surface::Collection->new;
$collection->append($_) for $surface, $surface->clone;
is scalar(@$collection), 2, 'collection has the right number of items';
is_deeply $collection->[0]->expolygon->pp, [$square, $hole_in_square],
'collection returns a correct surface expolygon';
$collection->clear;
is scalar(@$collection), 0, 'clear collection';
$collection->append($surface);
is scalar(@$collection), 1, 'append to collection';
my $item = $collection->[0];
isa_ok $item, 'Slic3r::Surface::Ref';
$item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL);
is $item->surface_type, $collection->[0]->surface_type, 'collection returns items by reference';
}
{
my $collection = Slic3r::Surface::Collection->new;
$collection->append($_) for
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_TOP);
is scalar(@{$collection->group}), 2, 'group() returns correct number of groups';
}
__END__