blib/lib/Geo/GoogleMaps/MobileTool.pm

filter: Statementstmt 85.5% 65 / 76 Branchbran 70.0% 14 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 83.6% 97 / 116 CC 13 SCAR 14.6
CC
13
Cov
82%
import
8.1
lnglat2pixel
4.3
pixel2lnglat
4.3
CRAP 4.3
↑ Summary
1 package Geo::GoogleMaps::MobileTool;
2  
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use version; our $VERSION = qv('0.0.1');
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 our @EXPORT = qw(
13 lnglat2pixel
14 pixel2lnglat
15 deltapixel2lnglat
16 deltalnglat_perpixel
17 );
18  
19 6 my $zmbase = 128;
20 6 my @zmmax;
21 my $offproj;
22  
23 6 ▶sub import {
Subroutine import: called CC=7 SCAR=21.0
24 6 my ( $class, $opt ) = @_;
25  
26 6 ▶ $offproj = ( $opt && $opt eq 'unableProj' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opt && $opt eq 'unableProj' ? : 2 4 6
Condition66%2/3
$opt and $opt eq "unableProj"
!ll&&!rl&&r
402
MC/DC50%1/2
$opt and $opt eq "unableProj"
$opt $opt eq "unableProj"
Truth table66%2/3
A and B
A= $optB= $opt eq "unableProj"
ABresult
0X0
100
111
27 6 ▶ unless ( $offproj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offproj) 4 2 6
28 4 eval { require Geo::Proj };
29 4 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 4 0 4
30 4 $offproj = 1;
31 } else {
32 0 Geo::Proj->import();
33 }
34 }
35  
36 6 foreach my $zm (0..20) {
37 126 $zmmax[$zm] = $zmbase * 2 ** $zm;
38 126 ▶ unless ( $offproj ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offproj) 0 126 126
39 0 my $name = "gmapzm$zm";
40 0 my $r = $zmmax[$zm] / pi;
41 0 my $proj = "+proj=merc +a=$r +b=$r +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=\@null +no
42 _defs";
43 0 Geo::Proj->new(
44 nick => $name,
45 proj4 => $proj,
46 );
47 }
48 }
49  
50 6 local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
51  
52 6 $class->SUPER::import();
53 }
54  
55 12 ▶sub lnglat2pixel {
Subroutine lnglat2pixel: called CC=4 SCAR=14.6
Pod documented
56 12 my ( $lng, $lat, $zm, $intoff ) = @_;
57  
58 12 my ( $x, $y );
59  
60 12 ▶ if ( $offproj ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offproj) { } 12 0 12
61 12 $x = $lng / 180.0 * $zmmax[$zm];
62 12 $y = log( tan( pi * ( 0.25 + $lat / 360.0 ) ) ) / pi * $zmmax[$zm];
63 } else {
64 0 my $pt = Geo::Proj->to( 'wgs84', "gmapzm$zm", [ $lng, $lat ] );
65 0 ( $x, $y ) = @{ $pt };
66 }
67  
68 12 $x += $zmmax[$zm];
69 12 $y = -1.0 * ( $y - $zmmax[$zm] );
70  
71 12 ▶ ( $x, $y ) = map { int( $_ ) } ( $x, $y ) unless ( $intoff );
Branch: 1 branch
BranchTrueFalseTotal
unless $intoff 4 8 12
72  
73 12 ▶ return wantarray ? ( $x, $y ) : [ $x, $y ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
74 }
75  
76 12 ▶sub pixel2lnglat {
Subroutine pixel2lnglat: called CC=4 SCAR=14.6
Pod documented
77 12 my ( $x, $y, $zm, $intoff ) = @_;
78  
79 12 ▶ ( $x, $y ) = map { $_ + 0.5 } ( $x, $y ) unless ( $intoff );
Branch: 1 branch
BranchTrueFalseTotal
unless $intoff 4 8 12
80  
81 12 $x -= $zmmax[$zm];
82 12 $y = -1.0 * $y + $zmmax[$zm];
83  
84 12 my ( $lng, $lat );
85  
86 12 ▶ if ( $offproj ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offproj) { } 12 0 12
87 12 $lng = $x / $zmmax[$zm] * 180.0;
88 12 $lat = atan( sinh( $y / $zmmax[$zm] * pi ) ) / pi *180.0;
89 } else {
90 0 my $pt = Geo::Proj->to( "gmapzm$zm", 'wgs84', [ $x, $y ] );
91 0 ( $lng, $lat ) = @{$pt};
92 }
93
94 12 ▶ return wantarray ? ( $lng, $lat ) : [ $lng, $lat ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 0 12
95 }
96  
97 8 ▶sub deltapixel2lnglat {
Subroutine deltapixel2lnglat: called CC=1 SCAR=0.0
Pod documented
98 8 my ( $lng, $lat, $dpxx, $dpxy, $zm ) = @_;
99  
100 8 my ( $fx, $fy ) = lnglat2pixel( $lng, $lat, $zm, 1 );
101  
102 8 $fx += $dpxx;
103  
104 8 $fy += $dpxy;
105  
106 8 return pixel2lnglat( $fx, $fy, $zm, 1 );
107 }
108  
109 4 ▶sub deltalnglat_perpixel {
Subroutine deltalnglat_perpixel: called CC=1 SCAR=0.0
Pod documented
110 4 my ( $lng, $lat, $zm ) = @_;
111  
112 4 my $dpx_plng = $zmmax[$zm] / 180.0;
113 4 my $dpy_plat = sec( $lat / 180.0 * pi ) * $zmmax[$zm] / 180.0;
114  
115 4 return map { 1.0 / $_ } ( $dpx_plng, $dpy_plat );
116 }
117  
118 6 1; # Magic true value required at end of module
119 __END__
↑ Summary