line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2004-2018 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution Math::Polygon. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Math::Polygon::Surface; |
10
|
1
|
|
|
1
|
|
57398
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
56
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.10'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
334
|
use Math::Polygon; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
16
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
546
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new(@) |
20
|
2
|
|
|
2
|
1
|
434
|
{ my $thing = shift; |
21
|
2
|
|
33
|
|
|
10
|
my $class = ref $thing || $thing; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
5
|
my @poly; |
24
|
|
|
|
|
|
|
my %options; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
5
|
while(@_) |
27
|
4
|
50
|
|
|
|
12
|
{ if(!ref $_[0]) { my $k = shift; $options{$k} = shift } |
|
0
|
50
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
28
|
4
|
|
|
|
|
7
|
elsif(ref $_[0] eq 'ARRAY') {push @poly, shift} |
29
|
0
|
|
|
|
|
0
|
elsif($_[0]->isa('Math::Polygon')) {push @poly, shift} |
30
|
0
|
|
|
|
|
0
|
else { die "Illegal argument $_[0]" } |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
6
|
$options{_poly} = \@poly if @poly; |
34
|
2
|
|
|
|
|
6
|
(bless {}, $class)->init(\%options); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init($$) |
38
|
2
|
|
|
2
|
0
|
5
|
{ my ($self, $args) = @_; |
39
|
2
|
|
|
|
|
3
|
my ($outer, @inner); |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
5
|
if($args->{_poly}) |
42
|
2
|
|
|
|
|
2
|
{ ($outer, @inner) = @{$args->{_poly}}; |
|
2
|
|
|
|
|
5
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else |
45
|
|
|
|
|
|
|
{ $outer = $args->{outer} |
46
|
0
|
0
|
|
|
|
0
|
or die "ERROR: surface requires outer polygon\n"; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
@inner = @{$args->{inner}} if defined $args->{inner}; |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
4
|
foreach ($outer, @inner) |
52
|
4
|
50
|
|
|
|
9
|
{ next unless ref $_ eq 'ARRAY'; |
53
|
4
|
|
|
|
|
25
|
$_ = Math::Polygon->new(points => $_); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
6
|
$self->{MS_outer} = $outer; |
57
|
2
|
|
|
|
|
3
|
$self->{MS_inner} = \@inner; |
58
|
2
|
|
|
|
|
5
|
$self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#------------ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
2
|
1
|
1171
|
sub outer() { shift->{MS_outer} } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
1
|
4
|
sub inner() { @{shift->{MS_inner}} } |
|
2
|
|
|
|
|
6
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#------------ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
1
|
|
sub bbox() { shift->outer->bbox } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub area() |
76
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
77
|
0
|
|
|
|
|
|
my $area = $self->outer->area; |
78
|
0
|
|
|
|
|
|
$area -= $_->area for $self->inner; |
79
|
0
|
|
|
|
|
|
$area; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub perimeter() |
84
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
85
|
0
|
|
|
|
|
|
my $per = $self->outer->perimeter; |
86
|
0
|
|
|
|
|
|
$per += $_->perimeter for $self->inner; |
87
|
0
|
|
|
|
|
|
$per; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#------------ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub lineClip($$$$) |
94
|
0
|
|
|
0
|
1
|
|
{ my ($self, @bbox) = @_; |
95
|
0
|
|
|
|
|
|
map { $_->lineClip(@bbox) } $self->outer, $self->inner; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub fillClip1($$$$) |
100
|
0
|
|
|
0
|
1
|
|
{ my ($self, @bbox) = @_; |
101
|
0
|
|
|
|
|
|
my $outer = $self->outer->fillClip1(@bbox); |
102
|
0
|
0
|
|
|
|
|
return () unless defined $outer; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$self->new |
105
|
|
|
|
|
|
|
( outer => $outer |
106
|
0
|
|
|
|
|
|
, inner => [ map {$_->fillClip1(@bbox)} $self->inner ] |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub string() |
112
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
113
|
|
|
|
|
|
|
"[" |
114
|
|
|
|
|
|
|
. join( "]\n-[" |
115
|
|
|
|
|
|
|
, $self->outer->string |
116
|
0
|
|
|
|
|
|
, map {$_->string } $self->inner) |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
. "]"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |