File: loops.t

package info (click to toggle)
slic3r 1.3.0%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,572 kB
  • sloc: cpp: 63,126; perl: 21,512; ansic: 6,312; sh: 591; xml: 201; makefile: 37; python: 11
file content (51 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (3)
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
use Test::More;
use strict;
use warnings;

plan tests => 4;

BEGIN {
    use FindBin;
    use lib "$FindBin::Bin/../lib";
    use local::lib "$FindBin::Bin/../local-lib";
}

use Slic3r;
use Slic3r::Geometry qw(Z epsilon scale);
use Slic3r::Test;

{
    # We want to check what happens when three concentric loops happen
    # to be at the same height, the two external ones being ccw and the other being
    # a hole, thus cw. So we create three cubes, centered around origin, the internal
    # one having reversed normals.
    my $mesh1 = Slic3r::Test::mesh('20mm_cube');
    
    # center around origin
    my $bb = $mesh1->bounding_box;
    $mesh1->translate(
        -($bb->x_min + $bb->size->x/2),
        -($bb->y_min + $bb->size->y/2),  #//
        -($bb->z_min + $bb->size->z/2),
    );
    
    my $mesh2 = $mesh1->clone;
    $mesh2->scale(1.2);
    
    my $mesh3 = $mesh2->clone;
    $mesh3->scale(1.2);
    
    $mesh1->reverse_normals;
    ok $mesh1->volume < 0, 'reverse_normals';
    
    my $all_meshes = Slic3r::TriangleMesh->new;
    $all_meshes->merge($_) for $mesh1, $mesh2, $mesh3;
    
    my $loops = $all_meshes->slice_at(Z, 0);
    is scalar(@$loops), 1, 'one expolygon returned';
    is scalar(@{$loops->[0]->holes}), 1, 'expolygon has one hole';
    ok abs(-$loops->[0]->holes->[0]->area - scale($bb->size->x)*scale($bb->size->y)) < epsilon, #))
        'hole has expected size';
}

__END__