JSON/Utils.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 10 / 10 Conditioncond 50.0% 9 / 18 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 80.5% 62 / 77 CC 15 SCAR 20.2
CC
15
Cov
85%
compare_positions
10.4
compute_bbox
8.0
BEGIN
1.0
CRAP 7.6
↑ Summary JSON/CRS.pm »
1 package Geo::JSON::Utils;
2  
3 7 our $VERSION = '0.007';
4  
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 our @EXPORT_OK = qw/ compare_positions compute_bbox /;
12  
13 # TODO improve - need to ensure floating points are the same
14 35 ▶sub compare_positions {
Subroutine compare_positions: called CC=8 SCAR=23.4
Pod documented
15 35 my ( $pos1, $pos2 ) = @_;
16  
17 # Assume positions have same number of dimensions
18 35 ▶ my $dimensions = defined $pos1->[2] ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $pos1->[2] ? : 3 32 35
19  
20 35 foreach my $dim ( 0 .. $dimensions ) {
21  
22 # TODO fix stringification problems...?
23 72 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if defined $pos1->[$dim] and not defined $pos2->[$dim] or not defined $pos1->[$dim] and defined $pos2->[$dim] or $pos1->[$dim] != $pos2->[$dim] 2 70 72
Condition41%5/12
defined $pos1->[$dim] and not defined $pos2->[$dim] or not defined $pos1->[$dim] and defined $pos2->[$dim] or $pos1->[$dim] != $pos2->[$dim]
l!l&&r!l&&!r
0270
defined $pos1->[$dim] and not defined $pos2->[$dim] or not defined $pos1->[$dim] and defined $pos2->[$dim]
l!l&&r!l&&!r
0072
defined $pos1->[$dim] and not defined $pos2->[$dim]
!ll&&!rl&&r
0720
not defined $pos1->[$dim] and defined $pos2->[$dim]
!ll&&!rl&&r
7200
MC/DC20%1/5
defined $pos1->[$dim] and not defined $pos2->[$dim] or not defined $pos1->[$dim] and defined $pos2->[$dim] or $pos1->[$dim] != $pos2->[$dim]
defined $pos1->[$dim] not defined $pos2->[$dim] not defined $pos1->[$dim] defined $pos2->[$dim] $pos1->[$dim] != $pos2->[$dim]
Truth table18%2/11
A and not(B) or not(C) and D or E
A= defined $pos1->[$dim]B= not defined $pos2->[$dim]C= not defined $pos1->[$dim]D= defined $pos2->[$dim]E= $pos1->[$dim] != $pos2->[$dim]
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
24 if ( defined $pos1->[$dim] && !defined $pos2->[$dim] )
25 || ( !defined $pos1->[$dim] && defined $pos2->[$dim] )
26 || ( $pos1->[$dim] != $pos2->[$dim] );
27 }
28  
29 33 return 1;
30 }
31  
32 15 ▶sub compute_bbox {
Subroutine compute_bbox: called CC=8 SCAR=20.8
Pod documented
33 15 my $positions = shift; # arrayref of positions
34  
35 croak "Need an array of at least 2 positions"
36 unless ref $positions
37 && ref $positions eq 'ARRAY'
38 15 ▶ && @{$positions} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $positions and ref $positions eq "ARRAY" and @{$positions;} > 1 1 14 15
Condition66%4/6
ref $positions and ref $positions eq "ARRAY" and @{$positions;} > 1
!ll&&!rl&&r
1014
ref $positions and ref $positions eq "ARRAY"
!ll&&!rl&&r
1014
MC/DC33%1/3
ref $positions and ref $positions eq "ARRAY" and @{$positions;} > 1
ref $positions ref $positions eq "ARRAY" @{$positions;} > 1
Truth table50%2/4
A and B and C
A= ref $positionsB= ref $positions eq "ARRAY"C= @{$positions;} > 1
ABCresult
0XX0
10X0
1100
1111
39  
40 # Assumes all have same number of dimensions
41  
42 14 my $dimensions = scalar @{ $positions->[0] } - 1;
43  
44 13 my @min = my @max = @{ $positions->[0] };
45  
46 13 foreach my $position ( @{$positions} ) {
47 71 foreach my $d ( 0 .. $dimensions ) {
48 167 ▶ $min[$d] = $position->[$d] if $position->[$d] < $min[$d];
Branch: 1 branch
BranchTrueFalseTotal
if $position->[$d] < $min[$d] 13 154 167
49 167 ▶ $max[$d] = $position->[$d] if $position->[$d] > $max[$d];
Branch: 1 branch
BranchTrueFalseTotal
if $position->[$d] > $max[$d] 48 119 167
50 }
51 }
52  
53 13 return [ @min, @max ];
54 }
55  
56 7 1;
57  
58 __END__
↑ Summary JSON/CRS.pm »