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

« back to all changes in this revision

Viewing changes to t/thin.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 tests => 13;
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
BEGIN {
 
6
    use FindBin;
 
7
    use lib "$FindBin::Bin/../lib";
 
8
}
 
9
 
 
10
use Slic3r;
 
11
use List::Util qw(first);
 
12
use Slic3r::Geometry qw(epsilon scale unscale scaled_epsilon Y);
 
13
use Slic3r::Test;
 
14
 
 
15
# Disable this until a more robust implementation is provided. It currently
 
16
# fails on Linux 32bit because some spurious extrudates are generated.
 
17
if (0) {
 
18
    my $config = Slic3r::Config->new_from_defaults;
 
19
    $config->set('layer_height', 0.2);
 
20
    $config->set('first_layer_height', '100%');
 
21
    $config->set('extrusion_width', 0.5);
 
22
    $config->set('first_layer_extrusion_width', '200%'); # check this one too
 
23
    $config->set('skirts', 0);
 
24
    $config->set('thin_walls', 1);
 
25
    
 
26
    my $print = Slic3r::Test::init_print('gt2_teeth', config => $config);
 
27
    
 
28
    my %extrusion_paths = ();  # Z => count of continuous extrusions
 
29
    my $extruding = 0;
 
30
    Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
 
31
        my ($self, $cmd, $args, $info) = @_;
 
32
        
 
33
        if ($cmd eq 'G1') {
 
34
            if ($info->{extruding} && $info->{dist_XY}) {
 
35
                if (!$extruding) {
 
36
                    $extrusion_paths{$self->Z} //= 0;
 
37
                    $extrusion_paths{$self->Z}++;
 
38
                }
 
39
                $extruding = 1;
 
40
            } else {
 
41
                $extruding = 0;
 
42
            }
 
43
        }
 
44
    });
 
45
    
 
46
    ok !(first { $_ != 3 } values %extrusion_paths),
 
47
        'no superfluous thin walls are generated for toothed profile';
 
48
}
 
49
 
 
50
{
 
51
    my $square = Slic3r::Polygon->new_scale(  # ccw
 
52
        [100, 100],
 
53
        [200, 100],
 
54
        [200, 200],
 
55
        [100, 200],
 
56
    );
 
57
    my $hole_in_square = Slic3r::Polygon->new_scale(  # cw
 
58
        [140, 140],
 
59
        [140, 160],
 
60
        [160, 160],
 
61
        [160, 140],
 
62
    );
 
63
    my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
 
64
    my $res = $expolygon->medial_axis(scale 1, scale 0.5);
 
65
    is scalar(@$res), 1, 'medial axis of a square shape is a single path';
 
66
    isa_ok $res->[0], 'Slic3r::Polyline', 'medial axis result is a polyline';
 
67
    ok $res->[0]->first_point->coincides_with($res->[0]->last_point), 'polyline forms a closed loop';
 
68
    ok $res->[0]->length > $hole_in_square->length && $res->[0]->length < $square->length,
 
69
        'medial axis loop has reasonable length';
 
70
}
 
71
 
 
72
{
 
73
    my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
 
74
        [100, 100],
 
75
        [120, 100],
 
76
        [120, 200],
 
77
        [100, 200],
 
78
    ));
 
79
    my $res = $expolygon->medial_axis(scale 1, scale 0.5);
 
80
    is scalar(@$res), 1, 'medial axis of a narrow rectangle is a single line';
 
81
    ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
 
82
    
 
83
    $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
 
84
        [100, 100],
 
85
        [120, 100],
 
86
        [120, 200],
 
87
        [105, 200],  # extra point in the short side
 
88
        [100, 200],
 
89
    ));
 
90
    my $res2 = $expolygon->medial_axis(scale 1, scale 0.5);
 
91
    is scalar(@$res), 1, 'medial axis of a narrow rectangle with an extra vertex is still a single line';
 
92
    ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has still a reasonable length';
 
93
    ok !(grep { abs($_ - scale 150) < scaled_epsilon } map $_->[Y], map @$_, @$res2), "extra vertices don't influence medial axis";
 
94
    
 
95
}
 
96
 
 
97
{
 
98
    my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
 
99
        [100, 100],
 
100
        [120, 100],
 
101
        [112, 200],
 
102
        [108, 200],
 
103
    ));
 
104
    my $res = $expolygon->medial_axis(scale 1, scale 0.5);
 
105
    is scalar(@$res), 1, 'medial axis of a narrow trapezoid is a single line';
 
106
    ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
 
107
}
 
108
 
 
109
{
 
110
    my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
 
111
        [100, 100],
 
112
        [120, 100],
 
113
        [120, 180],
 
114
        [200, 180],
 
115
        [200, 200],
 
116
        [100, 200],
 
117
    ));
 
118
    my $res = $expolygon->medial_axis(scale 1, scale 0.5);
 
119
    is scalar(@$res), 1, 'medial axis of a L shape is a single polyline';
 
120
    my $len = unscale($res->[0]->length) + 20;  # 20 is the thickness of the expolygon, which is subtracted from the ends
 
121
    ok $len > 80*2 && $len < 100*2, 'medial axis has reasonable length';
 
122
}
 
123
 
 
124
__END__