blib/lib/Math/Polygon/Tree.pm

filter: Statementstmt 98.0% 256 / 261 Branchbran 84.1% 106 / 126 Conditioncond 82.2% 134 / 163 MC/DCmcdc 57.6% 49 / 85 Subroutinesub 96.1% 25 / 26 Podpod 100% 11 / 11 totaltotal 86.4% 581 / 672 CC 128 SCAR 30.4
CC
128
Cov
90%
new
40.0
contains_bbox_rough
26.1
polygon_contains_point
23.4
CRAP 20.9
↑ Summary
1 package Math::Polygon::Tree;
2 6 $Math::Polygon::Tree::VERSION = '0.08';
3 # ABSTRACT: fast check if point is inside polygon
4  
5 # $Id$
6  
7  
8 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use base qw{ Exporter };
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use List::Util qw{ reduce first sum min max };
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use List::MoreUtils qw{ all any };
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use POSIX qw/ floor ceil /;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # todo: remove gpc and use simple bbox clip
21 6 our $CLIPPER_CLASS;
22 6 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.2
23 6 my @clippers = qw/
24 Math::Geometry::Planar::GPC::PolygonXS
25 Math::Geometry::Planar::GPC::Polygon
26 /;
27  
28 6 for my $class ( @clippers ) {
29 6 ▶ eval "require $class" or next;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class" or next 6 0 6
30 6 $CLIPPER_CLASS = $class;
31 6 last;
32 }
33  
34 6 ▶ croak "No clipper class available" if !$CLIPPER_CLASS;
Branch: 1 branch
BranchTrueFalseTotal
if not $Math::Polygon::Tree::CLIPPER_CLASS 0 6 6
35 }
36
37  
38  
39 6 our @EXPORT_OK = qw{
40 polygon_bbox
41 polygon_centroid
42 polygon_contains_point
43 };
44  
45 6 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
46  
47  
48 # tree options
49 6 our $MAX_LEAF_POINTS = 16;
50 6 our $SLICE_FIELD = 0.0001;
51 6 our $SLICE_NUM_COEF = 2;
52 6 our $SLICE_NUM_SPEED_COEF = 1;
53  
54 # floating-point comparsion accuracy
55 6 our $POLYGON_BORDER_WIDTH = 1e-9;
56  
57  
58  
59 8417 ▶sub new {
Subroutine new: called CC=40 SCAR=36.9
Pod documented
60 8417 my ($class, @in_contours) = @_;
61 8417 ▶ my %opt = ref $in_contours[-1] eq 'HASH' ? %{pop @in_contours} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $in_contours[-1] eq 'HASH' ? : 153 8264 8417
62 8417 my $self = bless {}, $class;
63  
64 ## load and close polys, calc bbox
65 8417 my @contours;
66 8417 ▶ while ( @in_contours ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@in_contours) 8975 8417 17392
67 8975 my $contour = shift @in_contours;
68  
69 8975 ▶ if ( ref $contour ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $contour ne "ARRAY") 2 8973 8975
70 2 unshift @in_contours, read_poly_file($contour);
71 2 next;
72 }
73  
74 8973 my @points = @$contour;
75 8973 ▶ push @points, $points[0] if !( $points[0]->[0] == $points[-1]->[0] && $points[0]->[1] == $points[-1]->[1] );
Branch: 1 branch
BranchTrueFalseTotal
unless $points[0][0] == $points[-1][0] and $points[0][1] == $points[-1][1] 8971 2 8973
Condition100%3/3
$points[0][0] == $points[-1][0] and $points[0][1] == $points[-1][1]
!ll&&!rl&&r
266563062
MC/DC100%2/2
$points[0][0] == $points[-1][0] and $points[0][1] == $points[-1][1]
$points[0][0] == $points[-1][0] $points[0][1] == $points[-1][1]
Truth table100%3/3
A and B
A= $points[0][0] == $points[-1][0]B= $points[0][1] == $points[-1][1]
ABresult
0X0
100
111
76  
77 8973 push @contours, \@points;
78  
79 8973 my $bbox = polygon_bbox(\@points);
80 8973 $self->{bbox} = bbox_union($bbox, $self->{bbox});
81 }
82  
83 8417 ▶ croak "No contours" if !@contours;
Branch: 1 branch
BranchTrueFalseTotal
unless @contours 0 8417 8417
84  
85 8417 my $nrpoints = sum map { scalar @$_ } @contours;
86  
87 # small polygon - no need to slice
88 8417 ▶ if ( $nrpoints <= $MAX_LEAF_POINTS ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nrpoints <= $Math::Polygon::Tree::MAX_LEAF_POINTS) 7185 1232 8417
89 7185 $self->{poly} = \@contours;
90  
91 # find some filled bboxes for rough checks
92 7185 ▶ if ( $opt{prepare_rough} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"prepare_rough"}) 131 7054 7185
93 131 my ($x0, $y0, $x1, $y1) = @{ $self->{bbox} };
94 131 for my $c ( @contours ) {
95 137 for my $i ( 0 .. $#$c-1 ) {
96 894 ▶ my ($h, $j, $k) = ( ($i>0 ? $i-1 : -2), ($i+1) % $#$c , ($i+2) % $#$c );
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 757 137 894
97  
98 894 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$h][1] == $c->[$i][1] and $c->[$k][1] == $c->[$j][1] and $c->[$i][1] == $y0 || $c->[$i][1] == $y1 and $c->[$j][1] == $y0 || $c->[$j][1] == $y1) 79 815 894
Condition100%15/15
$c->[$h][1] == $c->[$i][1] and $c->[$k][1] == $c->[$j][1] and $c->[$i][1] == $y0 || $c->[$i][1] == $y1 and $c->[$j][1] == $y0 || $c->[$j][1] == $y1
!ll&&!rl&&r
814179
$c->[$h][1] == $c->[$i][1] and $c->[$k][1] == $c->[$j][1] and $c->[$i][1] == $y0 || $c->[$i][1] == $y1
!ll&&!rl&&r
812280
$c->[$h][1] == $c->[$i][1] and $c->[$k][1] == $c->[$j][1]
!ll&&!rl&&r
71110182
$c->[$i][1] == $y0 or $c->[$i][1] == $y1
l!l&&r!l&&!r
46342
$c->[$j][1] == $y0 or $c->[$j][1] == $y1
l!l&&r!l&&!r
34451
MC/DC83%5/6
$c->[$h][1] == $c->[$i][1] and $c->[$k][1] == $c->[$j][1] and $c->[$i][1] == $y0 || $c->[$i][1] == $y1 and $c->[$j][1] == $y0 || $c->[$j][1] == $y1
$c->[$h][1] == $c->[$i][1] $c->[$k][1] == $c->[$j][1] $c->[$i][1] == $y0 $c->[$i][1] == $y1 $c->[$j][1] == $y0 $c->[$j][1] == $y1
Truth table66%6/9
A and B and C or D and E or F
A= $c->[$h][1] == $c->[$i][1]B= $c->[$k][1] == $c->[$j][1]C= $c->[$i][1] == $y0D= $c->[$i][1] == $y1E= $c->[$j][1] == $y0F= $c->[$j][1] == $y1
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X000
1101000
111X1X1
111X011
11011X1
1101011
99 $c->[$h]->[1] == $c->[$i]->[1]
100 && $c->[$k]->[1] == $c->[$j]->[1]
101 && ($c->[$i]->[1] == $y0 || $c->[$i]->[1] == $y1)
102 && ($c->[$j]->[1] == $y0 || $c->[$j]->[1] == $y1)
103 ) {
104 # left edge
105 79 ▶ if ( $c->[$i]->[0] == $x0 && $c->[$j]->[0] == $x0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i][0] == $x0 and $c->[$j][0] == $x0) 46 33 79
Condition66%2/3
$c->[$i][0] == $x0 and $c->[$j][0] == $x0
!ll&&!rl&&r
33046
MC/DC50%1/2
$c->[$i][0] == $x0 and $c->[$j][0] == $x0
$c->[$i][0] == $x0 $c->[$j][0] == $x0
Truth table66%2/3
A and B
A= $c->[$i][0] == $x0B= $c->[$j][0] == $x0
ABresult
0X0
100
111
106 46 my $x = min grep {$_ > $x0} map {$_->[0]} @$c;
107 46 push @{ $self->{filled_bboxes} }, [$x0, $y0, $x, $y1];
108 }
109 # right edge
110 79 ▶ if ( $c->[$i]->[0] == $x1 && $c->[$j]->[0] == $x1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i][0] == $x1 and $c->[$j][0] == $x1) 33 46 79
Condition66%2/3
$c->[$i][0] == $x1 and $c->[$j][0] == $x1
!ll&&!rl&&r
46033
MC/DC50%1/2
$c->[$i][0] == $x1 and $c->[$j][0] == $x1
$c->[$i][0] == $x1 $c->[$j][0] == $x1
Truth table66%2/3
A and B
A= $c->[$i][0] == $x1B= $c->[$j][0] == $x1
ABresult
0X0
100
111
111 33 my $x = max grep {$_ < $x1} map {$_->[0]} @$c;
112 33 push @{ $self->{filled_bboxes} }, [$x, $y0, $x1, $y1];
113 }
114 }
115  
116 894 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$h][0] == $c->[$i][0] and $c->[$k][0] == $c->[$j][0] and $c->[$i][0] == $x0 || $c->[$i][0] == $x1 and $c->[$j][0] == $x0 || $c->[$j][0] == $x1) 124 770 894
Condition100%15/15
$c->[$h][0] == $c->[$i][0] and $c->[$k][0] == $c->[$j][0] and $c->[$i][0] == $x0 || $c->[$i][0] == $x1 and $c->[$j][0] == $x0 || $c->[$j][0] == $x1
!ll&&!rl&&r
7691124
$c->[$h][0] == $c->[$i][0] and $c->[$k][0] == $c->[$j][0] and $c->[$i][0] == $x0 || $c->[$i][0] == $x1
!ll&&!rl&&r
7672125
$c->[$h][0] == $c->[$i][0] and $c->[$k][0] == $c->[$j][0]
!ll&&!rl&&r
66899127
$c->[$i][0] == $x0 or $c->[$i][0] == $x1
l!l&&r!l&&!r
61642
$c->[$j][0] == $x0 or $c->[$j][0] == $x1
l!l&&r!l&&!r
64601
MC/DC83%5/6
$c->[$h][0] == $c->[$i][0] and $c->[$k][0] == $c->[$j][0] and $c->[$i][0] == $x0 || $c->[$i][0] == $x1 and $c->[$j][0] == $x0 || $c->[$j][0] == $x1
$c->[$h][0] == $c->[$i][0] $c->[$k][0] == $c->[$j][0] $c->[$i][0] == $x0 $c->[$i][0] == $x1 $c->[$j][0] == $x0 $c->[$j][0] == $x1
Truth table66%6/9
A and B and C or D and E or F
A= $c->[$h][0] == $c->[$i][0]B= $c->[$k][0] == $c->[$j][0]C= $c->[$i][0] == $x0D= $c->[$i][0] == $x1E= $c->[$j][0] == $x0F= $c->[$j][0] == $x1
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X000
1101000
111X1X1
111X011
11011X1
1101011
117 $c->[$h]->[0] == $c->[$i]->[0]
118 && $c->[$k]->[0] == $c->[$j]->[0]
119 && ($c->[$i]->[0] == $x0 || $c->[$i]->[0] == $x1)
120 && ($c->[$j]->[0] == $x0 || $c->[$j]->[0] == $x1)
121 ) {
122 # lower edge
123 124 ▶ if ( $c->[$i]->[1] == $y0 && $c->[$j]->[1] == $y0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i][1] == $y0 and $c->[$j][1] == $y0) 59 65 124
Condition100%3/3
$c->[$i][1] == $y0 and $c->[$j][1] == $y0
!ll&&!rl&&r
62359
MC/DC100%2/2
$c->[$i][1] == $y0 and $c->[$j][1] == $y0
$c->[$i][1] == $y0 $c->[$j][1] == $y0
Truth table100%3/3
A and B
A= $c->[$i][1] == $y0B= $c->[$j][1] == $y0
ABresult
0X0
100
111
124 59 my $y = min grep {$_ > $y0} map {$_->[1]} @$c;
125 59 push @{ $self->{filled_bboxes} }, [$x0, $y0, $x1, $y];
126 }
127 # upper edge
128 124 ▶ if ( $c->[$i]->[1] == $y1 && $c->[$j]->[1] == $y1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i][1] == $y1 and $c->[$j][1] == $y1) 46 78 124
Condition100%3/3
$c->[$i][1] == $y1 and $c->[$j][1] == $y1
!ll&&!rl&&r
70846
MC/DC100%2/2
$c->[$i][1] == $y1 and $c->[$j][1] == $y1
$c->[$i][1] == $y1 $c->[$j][1] == $y1
Truth table100%3/3
A and B
A= $c->[$i][1] == $y1B= $c->[$j][1] == $y1
ABresult
0X0
100
111
129 46 my $y = max grep {$_ < $y1} map {$_->[1]} @$c;
130 46 push @{ $self->{filled_bboxes} }, [$x0, $y, $x1, $y1];
131 }
132 }
133 }
134 }
135 }
136  
137 7185 return $self;
138 }
139  
140  
141 # calc number of pieces (need to tune!)
142 1232 my ($xmin, $ymin, $xmax, $ymax) = @{$self->{bbox}};
143 1232 my $xy_ratio = ($xmax-$xmin) / ($ymax-$ymin);
144 1232 my $nparts = $SLICE_NUM_COEF * log( exp(1) * ($nrpoints/$MAX_LEAF_POINTS)**$SLICE_NUM_SPEED_COEF );
145  
146 1232 my $x_parts = $self->{x_parts} = ceil( sqrt($nparts * $xy_ratio) );
147 1232 my $y_parts = $self->{y_parts} = ceil( sqrt($nparts / $xy_ratio) );
148 1232 my $x_size = $self->{x_size} = ($xmax-$xmin) / $x_parts;
149 1232 my $y_size = $self->{y_size} = ($ymax-$ymin) / $y_parts;
150  
151  
152 # slice
153 1232 my $subparts = $self->{subparts} = [];
154
155 1232 my $gpc_poly = $CLIPPER_CLASS->new_gpc();
156 1232 $gpc_poly->add_polygon( $_, 0 ) for @contours;
157
158 1232 for my $j ( 0 .. $y_parts-1 ) {
159 2750 for my $i ( 0 .. $x_parts ) {
160  
161 9416 my $x0 = $xmin + ($i -$SLICE_FIELD)*$x_size;
162 9416 my $y0 = $ymin + ($j -$SLICE_FIELD)*$y_size;
163 9416 my $x1 = $xmin + ($i+1+$SLICE_FIELD)*$x_size;
164 9416 my $y1 = $ymin + ($j+1+$SLICE_FIELD)*$y_size;
165  
166 9416 my $gpc_slice = $CLIPPER_CLASS->new_gpc();
167 9416 $gpc_slice->add_polygon([ [$x0,$y0], [$x0,$y1], [$x1,$y1], [$x1,$y0], [$x0,$y0] ], 0);
168  
169 9416 my @slice_parts = $gpc_poly->clip_to($gpc_slice, 'INTERSECT')->get_polygons();
170  
171 # empty part
172 9416 ▶ if ( !@slice_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@slice_parts) 906 8510 9416
173 906 $subparts->[$i]->[$j] = 0;
174 906 next;
175 }
176  
177 # filled part
178 8510 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (@slice_parts == 1 and @{$slice_parts[0];} == 4 and &all(sub { $_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1; } , @{$slice_parts[0];})) 101 8409 8510
Condition100%6/6
@slice_parts == 1 and @{$slice_parts[0];} == 4 and &all(sub { $_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1; } , @{$slice_parts[0];})
!ll&&!rl&&r
44373972101
@slice_parts == 1 and @{$slice_parts[0];} == 4
!ll&&!rl&&r
49139464073
MC/DC100%3/3
@slice_parts == 1 and @{$slice_parts[0];} == 4 and &all(sub { $_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1; } , @{$slice_parts[0];})
@slice_parts == 1 @{$slice_parts[0];} == 4 &all(sub { $_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1; } , @{$slice_parts[0];})
Truth table100%4/4
A and B and C
A= @slice_parts == 1B= @{$slice_parts[0];} == 4C= &all(sub { $_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1; } , @{$slice_parts[0];})
ABCresult
0XX0
10X0
1100
1111
179 8019 @slice_parts == 1 && @{$slice_parts[0]} == 4
180 4073 ▶ && all { ($_->[0]==$x0 || $_->[0]==$x1) && ($_->[1]==$y0 || $_->[1]==$y1) } @{$slice_parts[0]}
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] == $x0 || $_->[0] == $x1 and $_->[1] == $y0 || $_->[1] == $y1 1945 3234 5179
Condition100%9/9
($_->[0] == $x0 || $_->[0] == $x1) && ($_->[1] == $y0 || $_->[1] == $y1)
!ll&&!rl&&r
32347381207
$_->[0] == $x0 or $_->[0] == $x1
l!l&&r!l&&!r
49014553234
$_->[1] == $y0 or $_->[1] == $y1
l!l&&r!l&&!r
1005202738
MC/DC100%4/4
($_->[0] == $x0 || $_->[0] == $x1) && ($_->[1] == $y0 || $_->[1] == $y1)
$_->[0] == $x0 $_->[0] == $x1 $_->[1] == $y0 $_->[1] == $y1
Truth table100%7/7
A or B && C or D
A= $_->[0] == $x0B= $_->[0] == $x1C= $_->[1] == $y0D= $_->[1] == $y1
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
181 ) {
182 101 $subparts->[$i]->[$j] = 1;
183 101 next;
184 }
185  
186 # complex subpart
187 8409 ▶ $subparts->[$i]->[$j] = Math::Polygon::Tree->new( @slice_parts, (%opt ? \%opt : ()) );
Branch: 1 branch
BranchTrueFalseTotal
%opt ? : 150 8259 8409
188 }
189 }
190  
191 1232 return $self;
192 }
193  
194  
195  
196  
197 2 ▶sub read_poly_file {
Subroutine read_poly_file: called CC=13 SCAR=27.7
Pod documented
198 2 my ($file) = @_;
199  
200 2 ▶ my $need_to_open = !ref $file || ref $file eq 'SCALAR';
Condition33%1/3
!ref($file) || ref $file eq 'SCALAR'
l!l&&r!l&&!r
002
MC/DC0%0/2
!ref($file) || ref $file eq 'SCALAR'
!ref($file) ref $file eq 'SCALAR'
Truth table33%1/3
not(A) || B
A= !ref($file)B= ref $file eq 'SCALAR'
ABresult
1X1
011
000
201 my $fh = $need_to_open
202 0 ▶ ? do { open my $in, '<', $file or croak "Couldn't open $file: $@"; $in }
Branch: 2 branches
BranchTrueFalseTotal
$need_to_open ? : 0 2 2
open my $in, "<", $file or croak("Couldn't open ${file}: $@") 0 0 0
203 : $file;
204  
205 2 my @contours;
206 my $pid;
207 2 my @cur_points;
208 2 ▶ while ( my $line = readline $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 15064 2 15066
209 # new contour
210 15064 ▶ if ( $line =~ /^([\-\!]?) (\d+)/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([\-\!]?) (\d+)/x) 2 15062 15064
211 2 ▶ $pid = $1 ? -$2 : $2;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 2 2
212 2 next;
213 }
214  
215 # point
216 15062 ▶ if ( $line =~ /^\s+([0-9.Ee+-]+)\s+([0-9.Ee+-]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s+([0-9.Ee+-]+)\s+([0-9.Ee+-]+)/) 15052 10 15062
217 15052 push @cur_points, [ $1+0, $2+0 ];
218 15052 next;
219 }
220  
221 # !!! inner contour - skipping
222 10 ▶ if ( $line =~ /^END/ && $pid < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^END/ and $pid < 0) 0 10 10
Condition66%2/3
$line =~ /^END/ and $pid < 0
!ll&&!rl&&r
640
MC/DC0%0/2
$line =~ /^END/ and $pid < 0
$line =~ /^END/ $pid < 0
Truth table66%2/3
A and B
A= $line =~ /^END/B= $pid < 0
ABresult
0X0
100
111
223 0 @cur_points = ();
224 0 next;
225 }
226  
227 # outer contour
228 10 ▶ if ( $line =~ /^END/ && @cur_points ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^END/ and @cur_points) 2 8 10
Condition100%3/3
$line =~ /^END/ and @cur_points
!ll&&!rl&&r
622
MC/DC100%2/2
$line =~ /^END/ and @cur_points
$line =~ /^END/ @cur_points
Truth table100%3/3
A and B
A= $line =~ /^END/B= @cur_points
ABresult
0X0
100
111
229 2 push @contours, [ @cur_points ];
230 2 @cur_points = ();
231 2 next;
232 }
233 }
234  
235 2 ▶ close $fh if $need_to_open;
Branch: 1 branch
BranchTrueFalseTotal
if $need_to_open 0 2 2
236 2 return @contours;
237 }
238  
239  
240  
241 52 ▶sub contains {
Subroutine contains: called CC=9 SCAR=22.0
Pod documented
242 52 my ($self, $point) = @_;
243  
244 52 ▶ croak "Point should be a reference" if ref $point ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $point ne "ARRAY" 0 52 52
245  
246 # check bbox
247 52 my ($px, $py) = @$point;
248 52 my ($xmin, $ymin, $xmax, $ymax) = @{ $self->{bbox} };
249 52 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py > $ymax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH 8 44 52
Condition77%7/9
$px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py > $ymax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
l!l&&r!l&&!r
8044
$px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
l!l&&r!l&&!r
8044
$px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
l!l&&r!l&&!r
1744
MC/DC50%2/4
$px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $py > $ymax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
$px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTH $py > $ymax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
Truth table60%3/5
A or B or C or D
A= $px < $xmin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTHB= $px > $xmax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTHC= $py < $ymin - $Math::Polygon::Tree::POLYGON_BORDER_WIDTHD= $py > $ymax + $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
ABCDresult
1XXX1
01XX1
001X1
00011
00000
250 if $px < $xmin-$POLYGON_BORDER_WIDTH
251 || $px > $xmax+$POLYGON_BORDER_WIDTH
252 || $py < $ymin-$POLYGON_BORDER_WIDTH
253 || $py > $ymax+$POLYGON_BORDER_WIDTH;
254  
255 # leaf
256 44 ▶ if ( exists $self->{poly} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"poly"}) 24 20 44
257 24 ▶ my $result = first {$_} map {polygon_contains_point($point, $_)} @{$self->{poly}};
Subroutine __ANON__: called CC=1 SCAR=0.0
258 24 ▶ return $result // 0;
Condition100%2/2
$result // 0
l!l
222
MC/DC100%1/1
$result // 0
$result
Truth table100%2/2
A
A= $result
Aresult
11
00
259 }
260  
261 # branch
262 20 my $i = min( floor( ($px-$xmin) / $self->{x_size} ), $self->{x_parts}-1 );
263 20 my $j = min( floor( ($py-$ymin) / $self->{y_size} ), $self->{y_parts}-1 );
264  
265 20 my $subpart = $self->{subparts}->[$i]->[$j];
266 20 ▶ return $subpart if !ref $subpart;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subpart 1 19 20
267 19 return $subpart->contains($point);
268 }
269  
270  
271  
272 6 ▶sub contains_points {
Subroutine contains_points: called CC=6 SCAR=18.2
Pod documented
273 6 my ($self, @points) = @_;
274  
275 6 ▶ my $iter_list = @points==1 && ref $points[0]->[0] ? $points[0] : \@points;
Branch: 1 branch
BranchTrueFalseTotal
@points == 1 && ref $points[0][0] ? : 6 0 6
Condition33%1/3
@points == 1 and ref $points[0][0]
!ll&&!rl&&r
006
MC/DC0%0/2
@points == 1 and ref $points[0][0]
@points == 1 ref $points[0][0]
Truth table33%1/3
A and B
A= @points == 1B= ref $points[0][0]
ABresult
0X0
100
111
276  
277 6 my $result;
278 6 for my $point ( @$iter_list ) {
279 11 my $point_result = 0 + !!$self->contains($point);
280 11 ▶ return undef if defined $result && $point_result != $result;
Branch: 1 branch
BranchTrueFalseTotal
if defined $result and $point_result != $result 1 10 11
Condition100%3/3
defined $result and $point_result != $result
!ll&&!rl&&r
641
MC/DC100%2/2
defined $result and $point_result != $result
defined $result $point_result != $result
Truth table100%3/3
A and B
A= defined $resultB= $point_result != $result
ABresult
0X0
100
111
281 10 $result = $point_result;
282 }
283  
284 5 return $result;
285 }
286  
287  
288  
289 10 ▶sub contains_bbox_rough {
Subroutine contains_bbox_rough: called CC=23 SCAR=32.6
Pod documented
290 10 my ($self, @bbox) = @_;
291 10 ▶ my %opt = ref $bbox[-1] eq 'HASH' ? %{pop @bbox} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $bbox[-1] eq 'HASH' ? : 1 9 10
292 10 ▶ my $bbox = ref $bbox[0] ? $bbox[0] : \@bbox;
Branch: 1 branch
BranchTrueFalseTotal
ref $bbox[0] ? : 10 0 10
293  
294 10 ▶ croak "Box should be 4 values array: xmin, ymin, xmax, ymax" if @$bbox != 4;
Branch: 1 branch
BranchTrueFalseTotal
if @$bbox != 4 0 10 10
295  
296 10 my ($x0, $y0, $x1, $y1) = @$bbox;
297 10 my ($xmin, $ymin, $xmax, $ymax) = @{$self->{bbox}};
298  
299 # completely outside bbox
300 10 ▶ return 0 if $x1 < $xmin || $x0 > $xmax || $y1 < $ymin || $y0 > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $x1 < $xmin or $x0 > $xmax or $y1 < $ymin or $y0 > $ymax 1 9 10
Condition66%6/9
$x1 < $xmin or $x0 > $xmax or $y1 < $ymin or $y0 > $ymax
l!l&&r!l&&!r
109
$x1 < $xmin or $x0 > $xmax or $y1 < $ymin
l!l&&r!l&&!r
109
$x1 < $xmin or $x0 > $xmax
l!l&&r!l&&!r
019
MC/DC25%1/4
$x1 < $xmin or $x0 > $xmax or $y1 < $ymin or $y0 > $ymax
$x1 < $xmin $x0 > $xmax $y1 < $ymin $y0 > $ymax
Truth table40%2/5
A or B or C or D
A= $x1 < $xminB= $x0 > $xmaxC= $y1 < $yminD= $y0 > $ymax
ABCDresult
1XXX1
01XX1
001X1
00011
00000
301  
302 # partly inside
303 9 ▶ return undef if !( $x0 >= $xmin && $x1 <= $xmax && $y0 >= $ymin && $y1 <= $ymax );
Branch: 1 branch
BranchTrueFalseTotal
unless $x0 >= $xmin and $x1 <= $xmax and $y0 >= $ymin and $y1 <= $ymax 1 8 9
Condition44%4/9
$x0 >= $xmin and $x1 <= $xmax and $y0 >= $ymin and $y1 <= $ymax
!ll&&!rl&&r
018
$x0 >= $xmin and $x1 <= $xmax and $y0 >= $ymin
!ll&&!rl&&r
009
$x0 >= $xmin and $x1 <= $xmax
!ll&&!rl&&r
009
MC/DC25%1/4
$x0 >= $xmin and $x1 <= $xmax and $y0 >= $ymin and $y1 <= $ymax
$x0 >= $xmin $x1 <= $xmax $y0 >= $ymin $y1 <= $ymax
Truth table40%2/5
A and B and C and D
A= $x0 >= $xminB= $x1 <= $xmaxC= $y0 >= $yminD= $y1 <= $ymax
ABCDresult
0XXX0
10XX0
110X0
11100
11111
304  
305 8 ▶ if ( !$self->{subparts} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"subparts"}) 6 2 8
306 6 ▶ for my $fbbox ( @{ $self->{filled_bboxes} || [] } ) {
Condition50%1/2
$self->{'filled_bboxes'} || []
l!l
60
MC/DC0%0/1
$self->{'filled_bboxes'} || []
$self->{'filled_bboxes'}
Truth table50%1/2
A
A= $self->{'filled_bboxes'}
Aresult
11
00
307 8 my ($fx0, $fy0, $fx1, $fy1) = @$fbbox;
308 8 ▶ return 1 if $x0>=$fx0 && $y0>=$fy0 && $x1<=$fx1 && $y1<=$fy1;
Branch: 1 branch
BranchTrueFalseTotal
if $x0 >= $fx0 and $y0 >= $fy0 and $x1 <= $fx1 and $y1 <= $fy1 3 5 8
Condition88%8/9
$x0 >= $fx0 and $y0 >= $fy0 and $x1 <= $fx1 and $y1 <= $fy1
!ll&&!rl&&r
323
$x0 >= $fx0 and $y0 >= $fy0 and $x1 <= $fx1
!ll&&!rl&&r
125
$x0 >= $fx0 and $y0 >= $fy0
!ll&&!rl&&r
017
MC/DC75%3/4
$x0 >= $fx0 and $y0 >= $fy0 and $x1 <= $fx1 and $y1 <= $fy1
$x0 >= $fx0 $y0 >= $fy0 $x1 <= $fx1 $y1 <= $fy1
Truth table80%4/5
A and B and C and D
A= $x0 >= $fx0B= $y0 >= $fy0C= $x1 <= $fx1D= $y1 <= $fy1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
309 }
310  
311 3 ▶ return undef if !$opt{inaccurate};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"inaccurate"} 2 1 3
312  
313 1 my @points = ( [$x0,$y0], [$x0,$y1], [$x1,$y0], [$x1,$y1] );
314 my $result =
315 1 ▶ any { my $p = $_; all { polygon_contains_point($_, $p) } @points }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
316 1 @{ $self->{poly} };
317 1 return 0 + $result;
318 }
319  
320 # lays in defferent subparts
321 2 my $i0 = min( floor( ($x0-$xmin) / $self->{x_size} ), $self->{x_parts}-1 );
322 2 my $i1 = min( floor( ($x1-$xmin) / $self->{x_size} ), $self->{x_parts}-1 );
323 2 ▶ return undef if $i0 != $i1;
Branch: 1 branch
BranchTrueFalseTotal
if $i0 != $i1 0 2 2
324
325 2 my $j0 = min( floor( ($y0-$ymin) / $self->{y_size} ), $self->{y_parts}-1 );
326 2 my $j1 = min( floor( ($y1-$ymin) / $self->{y_size} ), $self->{y_parts}-1 );
327 2 ▶ return undef if $j0 != $j1;
Branch: 1 branch
BranchTrueFalseTotal
if $j0 != $j1 0 2 2
328  
329 2 my $subpart = $self->{subparts}->[$i0]->[$j0];
330 2 ▶ return $subpart if !ref $subpart;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subpart 0 2 2
331 2 return $subpart->contains_bbox_rough($bbox);
332 }
333  
334  
335  
336 8 ▶sub contains_polygon_rough {
Subroutine contains_polygon_rough: called CC=3 SCAR=11.1
Pod documented
337 8 my ($self, $poly, %opt) = @_;
338 8 ▶ croak "Polygon should be a reference to array of points" if ref $poly ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $poly ne "ARRAY" 0 8 8
339  
340 8 ▶ return $self->contains_bbox_rough( polygon_bbox($poly), (%opt ? \%opt : ()) );
Branch: 1 branch
BranchTrueFalseTotal
%opt ? : 1 7 8
341 }
342  
343  
344  
345 0 ▶sub bbox {
Subroutine bbox: not called CC=1 SCAR=6.9
Pod documented
346 0 return shift()->{bbox};
347 }
348  
349  
350  
351  
352 8984 ▶sub polygon_bbox {
Subroutine polygon_bbox: called CC=2 SCAR=6.9
Pod documented
353 8984 my ($contour) = @_;
354  
355 8984 ▶ return bbox_union(@$contour) if @$contour <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$contour <= 2 7 8977 8984
356 8977 ▶ return reduce { bbox_union($a, $b) } @$contour;
Subroutine __ANON__: called CC=1 SCAR=0.0
357 }
358  
359  
360  
361 138914 ▶sub bbox_union {
Subroutine bbox_union: called CC=6 SCAR=19.0
Pod documented
362 138914 my ($bbox1, $bbox2) = @_;
363  
364 138914 ▶ $bbox2 //= $bbox1;
Condition66%2/3
$bbox2 //= $bbox1
l!l&&r!l&&!r
13049484200
MC/DC0%0/2
$bbox2 //= $bbox1
$bbox2 $bbox1
Truth table66%2/3
A //= B
A= $bbox2B= $bbox1
ABresult
1X1
011
000
365  
366 138914 ▶ my @bbox = (
Condition66%8/12
$bbox1->[2] // $bbox1->[0]
l!l&&r!l&&!r
12992889860
$bbox2->[2] // $bbox2->[0]
l!l&&r!l&&!r
89751299390
$bbox1->[3] // $bbox1->[1]
l!l&&r!l&&!r
12992889860
$bbox2->[3] // $bbox2->[1]
l!l&&r!l&&!r
89751299390
MC/DC0%0/2
$bbox1->[2] // $bbox1->[0]
$bbox1->[2] $bbox1->[0]
MC/DC0%0/2
$bbox2->[2] // $bbox2->[0]
$bbox2->[2] $bbox2->[0]
MC/DC0%0/2
$bbox1->[3] // $bbox1->[1]
$bbox1->[3] $bbox1->[1]
MC/DC0%0/2
$bbox2->[3] // $bbox2->[1]
$bbox2->[3] $bbox2->[1]
Truth table66%2/3
A // B
A= $bbox1->[2]B= $bbox1->[0]
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $bbox2->[2]B= $bbox2->[0]
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $bbox1->[3]B= $bbox1->[1]
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $bbox2->[3]B= $bbox2->[1]
ABresult
1X1
011
000
367 min( $bbox1->[0], $bbox2->[0] ),
368 min( $bbox1->[1], $bbox2->[1] ),
369 max( $bbox1->[2] // $bbox1->[0], $bbox2->[2] // $bbox2->[0] ),
370 max( $bbox1->[3] // $bbox1->[1], $bbox2->[3] // $bbox2->[1] ),
371 );
372  
373 138914 return \@bbox;
374 }
375  
376  
377  
378 5 ▶sub polygon_centroid {
Subroutine polygon_centroid: called CC=6 SCAR=17.9
Pod documented
379 5 my (@poly) = @_;
380 5 ▶ my $contour = ref $poly[0]->[0] ? $poly[0] : \@poly;
Branch: 1 branch
BranchTrueFalseTotal
ref $poly[0][0] ? : 5 0 5
381  
382 5 ▶ return $contour->[0] if @$contour < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$contour < 2 1 4 5
383  
384 4 my $sx = 0;
385 4 my $sy = 0;
386 4 my $sq = 0;
387  
388 4 my $p0 = $contour->[0];
389 4 for my $i ( 1 .. $#$contour-1 ) {
390 5 my $p = $contour->[$i];
391 5 my $p1 = $contour->[$i+1];
392  
393 5 my $tsq = ( ( $p->[0] - $p0->[0] ) * ( $p1->[1] - $p0->[1] )
394 - ( $p1->[0] - $p0->[0] ) * ( $p->[1] - $p0->[1] ) );
395 5 ▶ next if $tsq == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $tsq == 0 1 4 5
396
397 4 my $tx = ( $p0->[0] + $p->[0] + $p1->[0] ) / 3;
398 4 my $ty = ( $p0->[1] + $p->[1] + $p1->[1] ) / 3;
399  
400 4 $sx += $tx * $tsq;
401 4 $sy += $ty * $tsq;
402 4 $sq += $tsq;
403 }
404  
405 4 ▶ if ( $sq == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sq == 0) 1 3 4
406 1 my $bbox = polygon_bbox($contour);
407 1 return [ ($bbox->[0]+$bbox->[2])/2, ($bbox->[1]+$bbox->[3])/2 ];
408 }
409  
410 3 return [$sx/$sq, $sy/$sq];
411 }
412  
413  
414  
415 30 ▶sub polygon_contains_point {
Subroutine polygon_contains_point: called CC=23 SCAR=31.5
Pod documented
416 30 my ($point, @poly) = @_;
417 30 ▶ my $contour = ref $poly[0]->[0] ? $poly[0] : \@poly;
Branch: 1 branch
BranchTrueFalseTotal
ref $poly[0][0] ? : 30 0 30
418  
419 30 my ($x, $y) = @$point;
420 30 my ($px, $py) = @{ $contour->[0] };
421 30 my ($nx, $ny);
422  
423 30 my $inside = 0;
424  
425 30 for my $i ( 1 .. scalar @$contour ) {
426 120 ($nx, $ny) = @{ $contour->[ $i % scalar @$contour ] };
427  
428 120 ▶ return -1 if abs($y-$py) < $POLYGON_BORDER_WIDTH && abs($x-$px) < $POLYGON_BORDER_WIDTH;
Branch: 1 branch
BranchTrueFalseTotal
if abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $x - $px < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH 2 118 120
Condition100%3/3
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $x - $px < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
!ll&&!rl&&r
11442
MC/DC100%2/2
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $x - $px < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH abs $x - $px < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
Truth table100%3/3
A and B
A= abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTHB= abs $x - $px < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
ABresult
0X0
100
111
429  
430 118 ▶ return -1
Branch: 1 branch
BranchTrueFalseTotal
if abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and $x >= $px || $x >= $nx and $x <= $px || $x <= $nx 3 115 118
Condition73%11/15
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and $x >= $px || $x >= $nx and $x <= $px || $x <= $nx
!ll&&!rl&&r
11503
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and $x >= $px || $x >= $nx
!ll&&!rl&&r
11503
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH
!ll&&!rl&&r
11413
$x >= $px or $x >= $nx
l!l&&r!l&&!r
210
$x <= $px or $x <= $nx
l!l&&r!l&&!r
120
MC/DC33%2/6
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH and $x >= $px || $x >= $nx and $x <= $px || $x <= $nx
abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH $x >= $px $x >= $nx $x <= $px $x <= $nx
Truth table44%4/9
A and B and C or D and E or F
A= abs $y - $py < $Math::Polygon::Tree::POLYGON_BORDER_WIDTHB= abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTHC= $x >= $pxD= $x >= $nxE= $x <= $pxF= $x <= $nx
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X000
1101000
111X1X1
111X011
11011X1
1101011
431 if abs($y-$py) < $POLYGON_BORDER_WIDTH && abs($py-$ny) < $POLYGON_BORDER_WIDTH
432 && ( $x >= $px || $x >= $nx )
433 && ( $x <= $px || $x <= $nx );
434  
435 115 ▶ next if abs($py-$ny) < $POLYGON_BORDER_WIDTH;
Branch: 1 branch
BranchTrueFalseTotal
if abs $py - $ny < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH 42 73 115
436 73 ▶ next if $y < $py && $y < $ny;
Branch: 1 branch
BranchTrueFalseTotal
if $y < $py and $y < $ny 21 52 73
Condition100%3/3
$y < $py and $y < $ny
!ll&&!rl&&r
361621
MC/DC100%2/2
$y < $py and $y < $ny
$y < $py $y < $ny
Truth table100%3/3
A and B
A= $y < $pyB= $y < $ny
ABresult
0X0
100
111
437 52 ▶ next if $y > $py && $y > $ny;
Branch: 1 branch
BranchTrueFalseTotal
if $y > $py and $y > $ny 14 38 52
Condition100%3/3
$y > $py and $y > $ny
!ll&&!rl&&r
172114
MC/DC100%2/2
$y > $py and $y > $ny
$y > $py $y > $ny
Truth table100%3/3
A and B
A= $y > $pyB= $y > $ny
ABresult
0X0
100
111
438 38 ▶ next if $x > $px && $x > $nx;
Branch: 1 branch
BranchTrueFalseTotal
if $x > $px and $x > $nx 14 24 38
Condition100%3/3
$x > $px and $x > $nx
!ll&&!rl&&r
21314
MC/DC100%2/2
$x > $px and $x > $nx
$x > $px $x > $nx
Truth table100%3/3
A and B
A= $x > $pxB= $x > $nx
ABresult
0X0
100
111
439  
440 24 my $xx = ($y-$py)*($nx-$px)/($ny-$py)+$px;
441 24 ▶ return -1 if abs($x-$xx) < $POLYGON_BORDER_WIDTH;
Branch: 1 branch
BranchTrueFalseTotal
if abs $x - $xx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH 9 15 24
442  
443 15 ▶ next if $y <= $py && $y <= $ny;
Branch: 1 branch
BranchTrueFalseTotal
if $y <= $py and $y <= $ny 0 15 15
Condition66%2/3
$y <= $py and $y <= $ny
!ll&&!rl&&r
1320
MC/DC0%0/2
$y <= $py and $y <= $ny
$y <= $py $y <= $ny
Truth table66%2/3
A and B
A= $y <= $pyB= $y <= $ny
ABresult
0X0
100
111
444  
445 15 ▶ $inside = 1 - $inside
Branch: 1 branch
BranchTrueFalseTotal
if abs $px - $nx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $x < $xx 14 1 15
Condition100%3/3
abs $px - $nx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $x < $xx
l!l&&r!l&&!r
681
MC/DC100%2/2
abs $px - $nx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH or $x < $xx
abs $px - $nx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTH $x < $xx
Truth table100%3/3
A or B
A= abs $px - $nx < $Math::Polygon::Tree::POLYGON_BORDER_WIDTHB= $x < $xx
ABresult
1X1
011
000
446 if abs($px-$nx)<$POLYGON_BORDER_WIDTH || $x < $xx;
447 }
448 106 continue { ($px, $py) = ($nx, $ny); }
449  
450 16 return $inside;
451 }
452  
453  
454 6 1;
455  
456 __END__
↑ Summary