lib/Astro/Montenbruck/CoCo.pm

filter: Statementstmt 100% 57 / 57 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 97.5% 80 / 82 CC 5 SCAR 6.1
CC
5
Cov
97%
_equecl
4.1
_equhor
2.0
BEGIN
1.0
CRAP 1.8
« lib/Astro/Montenbruck/SolEqu.pm ↑ Summary lib/Astro/Montenbruck/Ephemeris/Planet/Moon.pm »
1 package Astro::Montenbruck::CoCo;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use POSIX qw /tan atan2 asin acos/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Astro::Montenbruck::MathUtils qw/reduce_rad/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Math::Trig qw/:pi deg2rad rad2deg/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 Readonly::Scalar our $ECL => 1;
12 4 Readonly::Scalar our $EQU => 2;
13  
14 4 our %EXPORT_TAGS = (
15 all => [ qw/ecl2equ equ2ecl equ2hor hor2equ ecl2equ_rect equ2ecl_rect/ ],
16 );
17  
18 4 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }, qw/$ECL $EQU/ );
19  
20 4 our $VERSION = 0.01;
21  
22 # Common routine for coordinate conversion
23 # $target = $ECL (1) for equator -> ecliptic
24 # $target = $EQU (2) for ecliptic -> equator
25 676 ▶sub _equecl {
Subroutine _equecl: called CC=4 SCAR=14.0
26 676 my ( $x, $y, $e, $target ) = @_;
27 676 ▶ my $k = $target == $ECL ? 1
Branch: 2 branches
BranchTrueFalseTotal
$target == $Astro::Montenbruck::CoCo::ECL ? : 1 675 676
$target == $Astro::Montenbruck::CoCo::EQU ? : 675 0 675
28 : $target == $EQU ? -1 : 0;
29 676 ▶ die "Unknown target: '$target'! \n" until $k;
Branch: 1 branch
BranchTrueFalseTotal
$k or do { die "Unknown target: '${target}'! \n" } 676 0 676
30  
31 676 my $sin_a = sin($x);
32 676 my $cos_e = cos($e);
33 676 my $sin_e = sin($e);
34 676 reduce_rad(atan2( $sin_a * $cos_e + $k * ( tan($y) * $sin_e ), cos($x) )),
35 asin( sin($y) * $cos_e - $k * ( cos($y) * $sin_e * $sin_a ) );
36 }
37  
38  
39 1 ▶sub equ2ecl {
Subroutine equ2ecl: called CC=1 SCAR=0.0
Pod documented
40 1 map { rad2deg $_ } _equecl( ( map { deg2rad $_ } @_ ), $ECL );
41 }
42  
43 675 ▶sub ecl2equ {
Subroutine ecl2equ: called CC=1 SCAR=0.0
Pod documented
44 675 map { rad2deg $_ } _equecl( ( map { deg2rad $_ } @_ ), $EQU );
45 }
46  
47  
48 # Converts between azimuth/altitude and hour-angle/declination.
49 # The equations are symmetrical in the two pairs of coordinates so that exactly
50 # the same code may be used to convert in either direction, there is no need
51 # to specify direction with a swich.
52 2 ▶sub _equhor {
Subroutine _equhor: called CC=2 SCAR=6.9
53 2 my ($x, $y, $phi) = @_;
54 2 my ($sx, $sy, $sphi) = map{ sin } ($x, $y, $phi);
55 2 my ($cx, $cy, $cphi) = map{ cos } ($x, $y, $phi);
56  
57 2 my $sq = ($sy * $sphi) + ($cy * $cphi * $cx);
58 2 my $q = asin($sq);
59 2 my $cp = ($sy - ($sphi * $sq)) / ($cphi * cos($q));
60 2 my $p = acos($cp);
61 2 ▶ if ($sx > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sx > 0) 1 1 2
62 1 $p = pi2 - $p;
63 }
64 2 ($p, $q)
65 }
66  
67 2 ▶sub equ2hor {
Subroutine equ2hor: called CC=1 SCAR=0.0
Pod documented
68 2 map {rad2deg $_} _equhor( map { deg2rad $_ } @_ )
69 }
70  
71 1 ▶sub hor2equ {
Subroutine hor2equ: called CC=1 SCAR=0.0
Pod documented
72 1 equ2hor(@_)
73 }
74  
75  
76  
77 4 1;
78  
79 __END__
« lib/Astro/Montenbruck/SolEqu.pm ↑ Summary lib/Astro/Montenbruck/Ephemeris/Planet/Moon.pm »