blib/lib/Geo/Horizon.pm

filter: Statementstmt 100% 40 / 40 Branchbran 66.6% 4 / 6 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 80.0% 4 / 5 totaltotal 90.1% 64 / 71 CC 7 SCAR 7.3
CC
7
Cov
92%
distance
3.0
distance_great_circle
3.0
new
2.0
CRAP 2.1
↑ Summary
1 package Geo::Horizon;
2 1 ▶use Math::Trig qw{acos};
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Geo::Horizon - Calculate distance to the visual horizon
7  
8 =head1 SYNOPSIS
9  
10 use Geo::Horizon;
11 my $gh = Geo::Horizon->new("WGS84");
12 my $lat=39;
13 my $alt=1.7;
14 my $distance_to_horizon=$gh->distance($alt,$lat);
15 print "Input Lat: $lat1\n";
16 print "Output Distance: $dist\n";
17  
18 =head1 DESCRIPTION
19  
20 A perl object for calculating the distance to the visual horizon on an ellipsoid.
21  
22 =cut
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 $VERSION = sprintf("%d.%02d", q{Revision: 0.02} =~ /(\d+)\.(\d+)/);
27  
28 =head1 CONSTRUCTOR
29  
30 =head2 new
31  
32 my $gh = Geo::Horizon->new(); #default WGS84
33  
34 =cut
35  
36 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
37 3 my $this = shift();
38 3 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
39 3 my $self = {};
40 3 bless $self, $class;
41 3 $self->initialize(@_);
42 3 return $self;
43 }
44  
45 =head1 METHODS
46  
47 =cut
48  
49 3 ▶sub initialize {
Subroutine initialize: called CC=1 SCAR=0.0
Pod undocumented
50 3 my $self = shift();
51 3 $self->ellipsoid(shift);
52 }
53  
54 =head2 ellipsoid
55  
56 Method to set or retrieve the current ellipsoid object. The ellipsoid is a L<Geo::Ellipsoids> object.
57  
58 my $ellipsoid=$gh->ellipsoid; #Default is WGS84
59  
60 $gh->ellipsoid('Clarke 1866'); #Built in ellipsoids from Geo::Ellipsoids
61 $gh->ellipsoid({a=>1}); #Custom Sphere 1 unit radius
62  
63 =cut
64  
65 719 ▶sub ellipsoid {
Subroutine ellipsoid: called CC=2 SCAR=6.9
Pod documented
66 719 my $self = shift();
67 719 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 716 719
68 3 my $param=shift();
69 1 ▶ use Geo::Ellipsoids;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 3 my $obj=Geo::Ellipsoids->new($param);
71 3 $self->{'ellipsoid'}=$obj;
72 }
73 719 return $self->{'ellipsoid'};
74 }
75  
76 =head2 distance
77  
78 The straight-line of sight distance to the horizon: This formula does not take in account radio or optical refraction which will be further the longer the wavelength.
79  
80 my $dist=$obj->distance($alt, $lat); #alt in meters (ellipsoid units)
81 #lat in signed decimal degrees
82 my $dist=$obj->distance($alt); #default lat => 0 (equator)
83 my $dist=$obj->distance; #default alt => 1.7
84  
85 Formula from http://newton.ex.ac.uk/research/qsystems/people/sque/physics/horizon/
86  
87 Ds = sqrt(h(2R + h))
88  
89 =cut
90  
91 202 ▶sub distance {
Subroutine distance: called CC=3 SCAR=11.0
Pod documented
92 202 my $self=shift();
93 202 my $alt=shift(); #usually meters but actaully ellipsoid units
94 202 ▶ $alt=1.7 unless defined $alt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alt 0 202 202
95 202 ▶ my $lat=shift() || 0; #degrees
Condition100%2/2
shift() || 0
l!l
90112
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
96 #Geometric Mean (http://mentorsoftwareinc.com/CC/gistips/TIPS0899.HTM)
97 202 my $R=sqrt($self->ellipsoid->n($lat) * $self->ellipsoid->rho($lat));
98 202 return sqrt($alt * (2 * $R + $alt));
99 }
100  
101 =head2 distance_great_circle
102  
103 The curved distance along the ellipsoid to the horizon: This is the great circle distance from the track point snapped to the ellipsoid to the visual horizon of the observer.
104  
105 my $dist=$obj->distance_great_circle($alt, $lat);
106 my $dist=$obj->distance_great_circle($alt); #default lat => 0
107 my $dist=$obj->distance_great_circle(); #default alt => 1.7
108  
109 Formula from http://newton.ex.ac.uk/research/qsystems/people/sque/physics/horizon/
110  
111 Dc = R acos(R / (R + h))
112  
113 =cut
114  
115 102 ▶sub distance_great_circle {
Subroutine distance_great_circle: called CC=3 SCAR=11.0
Pod documented
116 102 my $self=shift();
117 102 my $alt=shift(); #usually meters but actaully ellipsoid units
118 102 ▶ $alt=1.7 unless defined $alt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alt 0 102 102
119 102 ▶ my $lat=shift() || 0; #degrees
Condition100%2/2
shift() || 0
l!l
9012
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
120 102 my $R=sqrt($self->ellipsoid->n($lat) * $self->ellipsoid->rho($lat));
121 102 return $R * acos($R / ($R + $alt));
122 }
123  
124 1 1;
125  
126 __END__
↑ Summary