File: 004filltype.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 (49 lines) | stat: -rw-r--r-- 1,422 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
use Math::Clipper ':all';
use Test::More tests=>4;

my $ai = [ #area = 16
[0,0],
[4,0],
[4,4],
[0,4]
];
my $bi = [#area = 4, is inside $ai
[1,1],
[3,1],
[3,3],
[1,3]
];
my $bir = [#area = 4 (negative if PFT_NONZERO), is inside $ai
[1,3],
[3,3],
[3,1],
[1,1]
];


my $clipper = Math::Clipper->new;
$clipper->use_full_coordinate_range(1);
$clipper->add_subject_polygon($ai);
$clipper->add_subject_polygon($bi);
my $result = $clipper->execute(CT_DIFFERENCE,PFT_EVENODD,PFT_EVENODD); # PFT_EVENODD is default, just being explicit here
ok(scalar(@{$result}) == 2,'EVENODD begets hole');
$clipper->clear();

$clipper->add_subject_polygon($ai);
$clipper->add_subject_polygon($bir);
$result = $clipper->execute(CT_DIFFERENCE,PFT_EVENODD,PFT_EVENODD); # PFT_EVENODD is default, just being explicit here
ok(scalar(@{$result}) == 2,'EVENODD still begets hole despite reversed inner polygon winding');
$clipper->clear();

$clipper->add_subject_polygon($ai);
$clipper->add_subject_polygon($bir);
$result = $clipper->execute(CT_DIFFERENCE,PFT_NONZERO,PFT_NONZERO);
ok(scalar(@{$result}) == 2,'NONZERO begets hole with inner polygon wound opposite to outer');
$clipper->clear();

$clipper->add_subject_polygon($ai);
$clipper->add_subject_polygon($bi);
$result = $clipper->execute(CT_DIFFERENCE,PFT_NONZERO,PFT_NONZERO);
ok(scalar(@{$result}) == 1,'NONZERO begets one polygon, when inner poly wound same as outside');
$clipper->clear();