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

« back to all changes in this revision

Viewing changes to t/combineinfill.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
use Test::More;
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
BEGIN {
 
6
    use FindBin;
 
7
    use lib "$FindBin::Bin/../lib";
 
8
}
 
9
 
 
10
use List::Util qw(first);
 
11
use Slic3r;
 
12
use Slic3r::Test;
 
13
 
 
14
plan tests => 2;
 
15
 
 
16
{
 
17
    my $config = Slic3r::Config->new_from_defaults;
 
18
    $config->set('layer_height', 0.2);
 
19
    $config->set('first_layer_height', 0.2);
 
20
    $config->set('nozzle_diameter', [0.5]);
 
21
    $config->set('infill_every_layers', 2);
 
22
    $config->set('infill_extruder', 2);
 
23
    $config->set('top_solid_layers', 0);
 
24
    $config->set('bottom_solid_layers', 0);
 
25
    my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
 
26
    ok my $gcode = Slic3r::Test::gcode($print), "infill_every_layers does not crash";
 
27
    
 
28
    my $tool = undef;
 
29
    my %layer_infill = ();  # layer_z => has_infill
 
30
    Slic3r::GCode::Reader->new->parse($gcode, sub {
 
31
        my ($self, $cmd, $args, $info) = @_;
 
32
        
 
33
        if ($cmd =~ /^T(\d+)/) {
 
34
            $tool = $1;
 
35
        } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
 
36
            $layer_infill{$self->Z} //= 0;
 
37
            if ($tool == $config->infill_extruder-1) {
 
38
                $layer_infill{$self->Z} = 1;
 
39
            }
 
40
        }
 
41
    });
 
42
    my $layers_with_infill = grep $_,  values %layer_infill;
 
43
    $layers_with_infill--; # first layer is never combined
 
44
    is $layers_with_infill, scalar(keys %layer_infill)/2, 'infill is only present in correct number of layers';
 
45
}
 
46
 
 
47
# the following needs to be adapted to the new API
 
48
if (0) {
 
49
    my $config = Slic3r::Config->new_from_defaults;
 
50
    $config->set('skirts', 0);
 
51
    $config->set('solid_layers', 0);
 
52
    $config->set('bottom_solid_layers', 0);
 
53
    $config->set('top_solid_layers', 0);
 
54
    $config->set('infill_every_layers', 6);
 
55
    $config->set('layer_height', 0.06);
 
56
    $config->set('perimeters', 1);
 
57
    
 
58
    my $test = sub {
 
59
        my ($shift) = @_;
 
60
        
 
61
        my $self = Slic3r::Test::init_print('20mm_cube', config => $config);
 
62
        
 
63
        $shift /= &Slic3r::SCALING_FACTOR;
 
64
        my $scale = 4; # make room for fat infill lines with low layer height
 
65
 
 
66
        # Put a slope on the box's sides by shifting x and y coords by $tilt * (z / boxheight).
 
67
        # The test here is to put such a slight slope on the walls that it should
 
68
        # not trigger any extra fill on fill layers that should be empty when 
 
69
        # combine infill is enabled.
 
70
        $_->[0] += $shift * ($_->[2] / (20 / &Slic3r::SCALING_FACTOR)) for @{$self->objects->[0]->meshes->[0]->vertices};
 
71
        $_->[1] += $shift * ($_->[2] / (20 / &Slic3r::SCALING_FACTOR)) for @{$self->objects->[0]->meshes->[0]->vertices};
 
72
        $_ = [$_->[0]*$scale, $_->[1]*$scale, $_->[2]] for @{$self->objects->[0]->meshes->[0]->vertices};
 
73
                
 
74
        # copy of Print::export_gcode() up to the point 
 
75
        # after fill surfaces are combined
 
76
        $self->init_extruders;
 
77
        $_->slice for @{$self->objects};
 
78
        $_->make_perimeters for @{$self->objects};
 
79
        $_->detect_surfaces_type for @{$self->objects};
 
80
        $_->prepare_fill_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
 
81
        $_->process_external_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
 
82
        $_->discover_horizontal_shells for @{$self->objects};
 
83
        $_->combine_infill for @{$self->objects};
 
84
 
 
85
        # Only layers with id % 6 == 0 should have fill.
 
86
        my $spurious_infill = 0;
 
87
        foreach my $layer (map @{$_->layers}, @{$self->objects}) {
 
88
            ++$spurious_infill if ($layer->id % 6 && grep @{$_->fill_surfaces} > 0, @{$layer->regions});
 
89
        }
 
90
 
 
91
        $spurious_infill -= scalar(@{$self->objects->[0]->layers} - 1) % 6;
 
92
        
 
93
        fail "spurious fill surfaces found on layers that should have none (walls " . sprintf("%.4f", Slic3r::Geometry::rad2deg(atan2($shift, 20/&Slic3r::SCALING_FACTOR))) . " degrees off vertical)"
 
94
            unless $spurious_infill == 0;
 
95
        1;
 
96
    };
 
97
    
 
98
    # Test with mm skew offsets for the top of the 20mm-high box
 
99
    for my $shift (0, 0.0001, 1) {
 
100
        ok $test->($shift), "no spurious fill surfaces with box walls " . sprintf("%.4f",Slic3r::Geometry::rad2deg(atan2($shift, 20))) . " degrees off of vertical";
 
101
    }
 
102
}
 
103
 
 
104
__END__