blib/lib/GIS/Distance/ALT.pm

filter: Statementstmt 100% 56 / 56 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 97.0% 65 / 67 SCAR 11.0
CC
3
Cov
97%
_distance
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« blib/lib/GIS/Distance/Vincenty.pm ↑ Summary Build »
1 package GIS::Distance::ALT;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = '0.18';
5  
6 1 ▶use parent 'GIS::Distance::Formula';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Math::Trig qw( deg2rad acos pi );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use GIS::Distance::Constants qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my $DEG_RADS = pi / 180;
13  
14 # Sphere with equal meridian length
15 1 my $RM = 6367449.14582342;
16  
17 # WGS 84 Ellipsoid
18 1 my $A = 6378137;
19 1 my $B = 6356752.314245;
20 1 my $F = 1 / 298.257223563;
21  
22 sub _distance {
23 5 ▶ my ($lat1, $lon1, $lat2, $lon2) = @_;
Subroutine _distance: called CC=3 SCAR=11.0
24  
25 5 my $f = 0.5 * ($lat2 + $lat1) * $DEG_RADS;
26 5 my $g = 0.5 * ($lat2 - $lat1) * $DEG_RADS;
27 5 my $l = 0.5 * ($lon2 - $lon1) * $DEG_RADS;
28  
29 5 my $sf = sin($f); my $sg = sin($g); my $sl = sin($l);
30 5 my $s2f = $sf * $sf; my $s2g = $sg * $sg; my $s2l = $sl * $sl;
31 5 my $c2f = 1.0 - $s2f; my $c2g = 1.0 - $s2g; my $c2l = 1.0 - $s2l;
32  
33 5 my $s2 = $s2g * $c2l + $c2f * $s2l;
34 5 my $c2 = $c2g * $c2l + $s2f * $s2l;
35  
36 5 my ($s, $c, $omega, $rr, $aa, $bb, $pp, $qq, $d2, $qp, $eps1, $eps2);
37  
38 5 ▶ return 0 if $s2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s2 == 0 0 5 5
39 5 ▶ return pi * $RM * 0.001 if $c2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $c2 == 0 0 5 5
40  
41 5 $s = sqrt($s2); $c = sqrt($c2);
42 5 $omega = atan2($s, $c);
43 5 $rr = $s * $c;
44 5 $aa = $s2g * $c2f / $s2 + $s2f * $c2g / $c2;
45 5 $bb = $s2g * $c2f / $s2 - $s2f * $c2g / $c2;
46 5 $pp = $rr / $omega;
47 5 $qq = $omega / $rr;
48 5 $d2 = $s2 - $c2;
49 5 $qp = $qq + 6 * $pp;
50 5 $eps1 = 0.5 * $F * (-$aa - 3 * $bb * $pp);
51 5 $eps2 = 0.25 * $F * $F * ((-$qp * $bb + (-3.75 + $d2 * ($qq + 3.75 * $pp)) *
52 $aa + 4. - $d2 * $qq) * $aa - (7.5 * $d2 * $bb * $pp - $qp) * $bb);
53  
54 5 my $d = 2 * $omega * $A * (1 + $eps1 + $eps2);
55 5 return $d * 0.001;
56 }
57  
58 1 1;
59 __END__
« blib/lib/GIS/Distance/Vincenty.pm ↑ Summary Build »