File: 005offset.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 (77 lines) | stat: -rw-r--r-- 2,716 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use Math::Clipper ':all';
use Test::More tests => 19;

my $ccw = [
[0,0],
[4,0],
[4,4],
[0,4]
];
my $cw = [
[0,0],
[0,4],
[4,4],
[4,0]
];


my $offpolys1 = Math::Clipper::offset([$ccw], 1.0, 1);
#diag("\ncnt:\n",scalar(@{$offpolys1}),"\n\n");
ok(scalar(@{$offpolys1})==1,'positive offset, on ccw');
is(Math::Clipper::area($offpolys1->[0]),(16 + 20),'area check for positive ccw off');
#diag("\ngoing in wind1:".Math::Clipper::is_counter_clockwise($ccw) . " vs " .Math::Clipper::is_counter_clockwise($offpolys1->[0]));
my $offpolys2 = Math::Clipper::offset([$offpolys1->[0] , $cw], 1.0, 1); # $cw works as a hole inside $offpolys1->[0]
ok(scalar(@{$offpolys2})==2,'positive offset, on cw');
my $asum=0;
map {
	#diag("\n".Math::Clipper::area($_));
	$asum+=Math::Clipper::area($_)
	} @{$offpolys2};
is($asum,((16 + 20) + (28) - (16 - 12)),'area check for positive cw off');

my $offpolys3 = Math::Clipper::offset([$ccw], -1.0, 1);
#diag("\ngoing in wind2:".Math::Clipper::is_counter_clockwise($ccw) . " vs " .Math::Clipper::is_counter_clockwise($offpolys3->[0]));
ok(scalar(@{$offpolys3})==1,'negative offset, on ccw');
is(Math::Clipper::area($offpolys3->[0]),(16 - 12),'area check for negative ccw off');

my $offpolys4 = Math::Clipper::offset([$offpolys2->[0],$offpolys2->[1]], -1.0, 1);
ok(scalar(@{$offpolys4})==2,'negative offset, on cw');
$asum=0;
map {
	#diag("\n".Math::Clipper::area($_));
	$asum+=Math::Clipper::area($_)
	} @{$offpolys4};
is($asum,((16 + 20) - 16),'area check for negative cw off');

{
    my $res = Math::Clipper::int_offset([$ccw], 1.0, 1, JT_MITER, 2);
    ok @$res == 1, 'positive int_offset, on ccw';
    is Math::Clipper::area($res->[0]), (16 + 20), 'area check for positive ccw int_offset';
}

{
    my $res = Math::Clipper::int_offset([$ccw], -1.0, 1, JT_MITER, 2);
    ok @$res == 1, 'negative int_offset, on ccw';
    is Math::Clipper::area($res->[0]), 2*2, 'area check for negative ccw int_offset';
}

{
    my $res = Math::Clipper::int_offset2([$ccw], 1.0, -1.0, 1, JT_MITER, 2);
    ok @$res == 1, 'int_offset2 returned one item';
    is Math::Clipper::area($ccw), Math::Clipper::area($res->[0]), 'int_offset2 performed double offset';
}

{
    my $res = Math::Clipper::ex_int_offset([$ccw, $cw], 1.0, 1, JT_MITER, 2);
    ok @$res == 1, 'ex_int_offset returned one item';
    isa_ok $res->[0], 'HASH', 'ex_int_offset returned one ExPolygon';
}

{
    my $res = Math::Clipper::ex_int_offset2([$ccw], 1.0, -1.0, 1, JT_MITER, 2);
    ok @$res == 1, 'ex_int_offset2 returned one item';
    isa_ok $res->[0], 'HASH', 'ex_int_offset2 returned one ExPolygon';
    is Math::Clipper::area($ccw), Math::Clipper::area($res->[0]{outer}), 'ex_int_offset2 performed double offset';
}

__END__