|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Geo::JSON::Utils;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.007';  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
5
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
58073
 | 
 use strict;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
264
 | 
    | 
| 
6
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
31
 | 
 use warnings;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
188
 | 
    | 
| 
7
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
26
 | 
 use Carp;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
474
 | 
    | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
30
 | 
 use base 'Exporter';  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2125
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @EXPORT_OK = qw/ compare_positions compute_bbox /;  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # TODO improve - need to ensure floating points are the same  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub compare_positions {  | 
| 
15
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
  
1
  
 | 
1691
 | 
     my ( $pos1, $pos2 ) = @_;  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Assume positions have same number of dimensions  | 
| 
18
 | 
35
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
98
 | 
     my $dimensions = defined $pos1->[2] ? 2 : 1;  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
87
 | 
     foreach my $dim ( 0 .. $dimensions ) {  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         # TODO fix stringification problems...?  | 
| 
23
 | 
72
 | 
  
100
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
828
 | 
         return 0  | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             if ( defined $pos1->[$dim] && !defined $pos2->[$dim] )  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             || ( !defined $pos1->[$dim] && defined $pos2->[$dim] )  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             || ( $pos1->[$dim] != $pos2->[$dim] );  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
123
 | 
     return 1;  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub compute_bbox {  | 
| 
33
 | 
15
 | 
 
 | 
 
 | 
  
15
  
 | 
  
1
  
 | 
2975
 | 
     my $positions = shift;    # arrayref of positions  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
61
 | 
     croak "Need an array of at least 2 positions"  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless ref $positions  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         && ref $positions eq 'ARRAY'  | 
| 
38
 | 
15
 | 
  
 50
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
122
 | 
         && @{$positions} > 1;  | 
| 
 
 | 
 
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Assumes all have same number of dimensions  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
     my $dimensions = scalar @{ $positions->[0] } - 1;  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
42
 | 
    | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     my @min = my @max = @{ $positions->[0] };  | 
| 
 
 | 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
42
 | 
    | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     foreach my $position ( @{$positions} ) {  | 
| 
 
 | 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
    | 
| 
47
 | 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
90
 | 
         foreach my $d ( 0 .. $dimensions ) {  | 
| 
48
 | 
167
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
250
 | 
             $min[$d] = $position->[$d] if $position->[$d] < $min[$d];  | 
| 
49
 | 
167
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
353
 | 
             $max[$d] = $position->[$d] if $position->[$d] > $max[$d];  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
     return [ @min, @max ];  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |