~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/t/12_extrusionpathcollection.t

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Slic3r::XS;
 
7
use Test::More tests => 16;
 
8
 
 
9
my $points = [
 
10
    [100, 100],
 
11
    [200, 100],
 
12
    [200, 200],
 
13
];
 
14
 
 
15
my $path = Slic3r::ExtrusionPath->new(
 
16
    polyline => Slic3r::Polyline->new(@$points),
 
17
    role     => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
 
18
    mm3_per_mm => 1,
 
19
);
 
20
 
 
21
my $loop = Slic3r::ExtrusionLoop->new_from_paths(
 
22
    Slic3r::ExtrusionPath->new(
 
23
        polyline => Slic3r::Polygon->new(@$points)->split_at_first_point,
 
24
        role     => Slic3r::ExtrusionPath::EXTR_ROLE_FILL,
 
25
        mm3_per_mm => 1,
 
26
    ),
 
27
);
 
28
 
 
29
my $collection = Slic3r::ExtrusionPath::Collection->new($path);
 
30
isa_ok $collection, 'Slic3r::ExtrusionPath::Collection', 'collection object with items in constructor';
 
31
ok !$collection->no_sort, 'no_sort is false by default';
 
32
 
 
33
$collection->append($collection);
 
34
is scalar(@$collection), 2, 'append ExtrusionPath::Collection';
 
35
 
 
36
$collection->append($path);
 
37
is scalar(@$collection), 3, 'append ExtrusionPath';
 
38
 
 
39
$collection->append($loop);
 
40
is scalar(@$collection), 4, 'append ExtrusionLoop';
 
41
 
 
42
isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection::Ref', 'correct object returned for collection';
 
43
isa_ok $collection->[2], 'Slic3r::ExtrusionPath::Ref', 'correct object returned for path';
 
44
isa_ok $collection->[3], 'Slic3r::ExtrusionLoop::Ref', 'correct object returned for loop';
 
45
is ref($collection->[2]->clone), 'Slic3r::ExtrusionPath', 'correct object returned for cloned path';
 
46
is ref($collection->[3]->clone), 'Slic3r::ExtrusionLoop', 'correct object returned for cloned loop';
 
47
 
 
48
is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated';
 
49
 
 
50
{
 
51
    my $collection_loop = $collection->[3];
 
52
    $collection_loop->polygon->scale(2);
 
53
    is_deeply $collection->[3]->polygon->pp, $collection_loop->polygon->pp, 'items are returned by reference';
 
54
}
 
55
 
 
56
{
 
57
    my $collection = Slic3r::ExtrusionPath::Collection->new(
 
58
        map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
 
59
            Slic3r::Polyline->new([0,15], [0,18], [0,20]),
 
60
            Slic3r::Polyline->new([0,10], [0,8], [0,5]),
 
61
    );
 
62
    is_deeply
 
63
        [ map $_->y, map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
 
64
        [20, 18, 15, 10, 8, 5],
 
65
        'chained_path_from';
 
66
    is_deeply
 
67
        [ map $_->y, map @{$_->polyline}, @{$collection->chained_path(0)} ],
 
68
        [15, 18, 20, 10, 8, 5],
 
69
        'chained_path';
 
70
}
 
71
 
 
72
{
 
73
    my $collection = Slic3r::ExtrusionPath::Collection->new(
 
74
        map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
 
75
            Slic3r::Polyline->new([15,0], [10,0], [4,0]),
 
76
            Slic3r::Polyline->new([10,5], [15,5], [20,5]),
 
77
    );
 
78
    is_deeply
 
79
        [ map $_->x, map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
 
80
        [reverse 4, 10, 15, 10, 15, 20],
 
81
        'chained_path_from';
 
82
    
 
83
    $collection->no_sort(1);
 
84
    my @foo = @{$collection->chained_path(0)};
 
85
    pass 'chained_path with no_sort';
 
86
}
 
87
 
 
88
__END__