File Coverage

blib/lib/Math/Polygon/Surface.pm
Criterion Covered Total %
statement 37 63 58.7
branch 5 18 27.7
condition 1 6 16.6
subroutine 9 15 60.0
pod 9 10 90.0
total 61 112 54.4


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Math-Polygon version 2.00.
2             # The POD got stripped from this file by OODoc version 3.03.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2004-2025 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11             #oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION ***
12             #oodist: This file contains OODoc-style documentation which will get stripped
13             #oodist: during its release in the distribution. You can use this file for
14             #oodist: testing, however the code of this development version may be broken!
15              
16             package Math::Polygon::Surface;{
17             our $VERSION = '2.00';
18             }
19              
20              
21 1     1   98288 use strict;
  1         2  
  1         38  
22 1     1   11 use warnings;
  1         2  
  1         63  
23              
24 1     1   414 use Log::Report 'math-polygon';
  1         101068  
  1         5  
25 1     1   399 use Scalar::Util qw/blessed/;
  1         5  
  1         71  
26              
27 1     1   939 use Math::Polygon ();
  1         5  
  1         766  
28              
29             #--------------------
30              
31             sub new(@)
32 2     2 1 205989 { my $thing = shift;
33 2   33     18 my $class = ref $thing || $thing;
34 2         6 my (@poly, %options);
35              
36 2         10 while(@_)
37 4 50 0     19 { if(!ref $_[0]) { my $k = shift; $options{$k} = shift }
  0 50       0  
  0 0       0  
38 4         12 elsif(ref $_[0] eq 'ARRAY') { push @poly, shift }
39 0         0 elsif(blessed $_[0] && $_[0]->isa('Math::Polygon')) { push @poly, shift }
40 0         0 else { panic "illegal argument $_[0]" }
41             }
42              
43 2 50       13 $options{_poly} = \@poly if @poly;
44 2         16 (bless {}, $class)->init(\%options);
45             }
46              
47             sub init($$)
48 2     2 0 8 { my ($self, $args) = @_;
49 2         5 my ($outer, @inner);
50              
51 2 50       9 if($args->{_poly})
52 2         4 { ($outer, @inner) = @{$args->{_poly}};
  2         9  
53             }
54             else
55 0 0       0 { $outer = $args->{outer} or error __"surface requires outer polygon";
56 0 0       0 @inner = @{$args->{inner}} if defined $args->{inner};
  0         0  
57             }
58              
59 2         7 foreach ($outer, @inner)
60 4 50       14 { next unless ref $_ eq 'ARRAY';
61 4         23 $_ = Math::Polygon->new(points => $_);
62             }
63              
64 2         9 $self->{MS_outer} = $outer;
65 2         7 $self->{MS_inner} = \@inner;
66 2         8 $self;
67             }
68              
69             #--------------------
70              
71 2     2 1 2032 sub outer() { $_[0]->{MS_outer} }
72              
73              
74 2     2 1 6 sub inner() { @{$_[0]->{MS_inner}} }
  2         13  
75              
76             #--------------------
77              
78 0     0 1   sub bbox() { $_[0]->outer->bbox }
79              
80              
81             sub area()
82 0     0 1   { my $self = shift;
83 0           my $area = $self->outer->area;
84 0           $area -= $_->area for $self->inner;
85 0           $area;
86             }
87              
88              
89             sub perimeter()
90 0     0 1   { my $self = shift;
91 0           my $per = $self->outer->perimeter;
92 0           $per += $_->perimeter for $self->inner;
93 0           $per;
94             }
95              
96             #--------------------
97              
98             sub lineClip($$$$)
99 0     0 1   { my ($self, @bbox) = @_;
100 0           map { $_->lineClip(@bbox) } $self->outer, $self->inner;
  0            
101             }
102              
103              
104             sub fillClip1($$$$)
105 0     0 1   { my ($self, @bbox) = @_;
106 0           my $outer = $self->outer->fillClip1(@bbox);
107 0 0         return () unless defined $outer;
108              
109             $self->new(
110             outer => $outer,
111 0           inner => [ map {$_->fillClip1(@bbox)} $self->inner ],
  0            
112             );
113             }
114              
115              
116             sub string()
117 0     0 1   { my $self = shift;
118 0           "["
119             . join( "]\n-[",
120             $self->outer->string,
121             map $_->string, $self->inner)
122             . "]";
123             }
124              
125             1;