File: 012_polytree.t

package info (click to toggle)
libmath-clipper-perl 1.23-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 484 kB
  • ctags: 1,094
  • sloc: cpp: 3,448; perl: 131; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,592 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
52
53
54
55
56
use Math::Clipper ':all';
use Test::More tests => 9;

{
    my $square1 = [
        [0,0],
        [10,0],
        [10,10],
        [0,10],
    ];
    my $hole1 = [
        [2,2],
        [2,8],
        [8,8],
        [8,2],
    ];
    my $square2 = [
        [4,4],
        [6,4],
        [6,6],
        [4,6],
    ];
    
    my $clipper = Math::Clipper->new;
    $clipper->add_subject_polygons([ $square1, $hole1, $square2 ]);
    my $polytree = $clipper->pt_execute(CT_UNION);
    is scalar(@$polytree), 1, 'only one top-level polygon';
    ok exists $polytree->[0]{outer}, 'top-level polygon has outer type';
    is area($polytree->[0]{outer}), area($square1), 'top-level polygon has expected area';
    is scalar(@{ $polytree->[0]{children} }), 1, 'top-level polygon has one child';
    ok exists $polytree->[0]{children}[0]{hole}, 'top-level polygon child is hole';
    is scalar(@{ $polytree->[0]{children}[0]{children} }), 1, 'hole has one child';
    ok exists $polytree->[0]{children}[0]{children}[0]{outer}, 'hole child has outer type';
    is area($polytree->[0]{children}[0]{children}[0]{outer}), area($square2), 'hole child has expected area';
}

{
    my $square1 = [
        [0,0],
        [10,0],
        [10,10],
        [0,10],
    ];
    my $square2 = [
        [20,20],
        [30,20],
        [30,30],
        [20,30],
    ];
    my $clipper = Math::Clipper->new;
    $clipper->add_subject_polygons([ $square1, $square2 ]);
    my $polytree = $clipper->pt_execute(CT_INTERSECTION);
    is scalar(@$polytree), 0, 'null intersection returned empty arrayref';
}

__END__