File Coverage

blib/lib/Astro/Coord/ECI/VSOP87D/_Superior.pm
Criterion Covered Total %
statement 77 89 86.5
branch 21 28 75.0
condition 1 2 50.0
subroutine 17 20 85.0
pod 5 5 100.0
total 121 144 84.0


line stmt bran cond sub pod time code
1             package Astro::Coord::ECI::VSOP87D::_Superior;
2              
3 7     7   1060 use 5.008;
  7         24  
4              
5 7     7   37 use strict;
  7         16  
  7         135  
6 7     7   33 use warnings;
  7         24  
  7         268  
7              
8 7     7   51 use base qw{ Astro::Coord::ECI };
  7         27  
  7         942  
9              
10 7         452 use Astro::Coord::ECI::Mixin qw{
11             almanac almanac_hash
12             next_quarter_hash
13 7     7   2687 };
  7         5958  
14 7     7   52 use Astro::Coord::ECI::Utils qw{ PI PIOVER2 find_first_true mod2pi };
  7         31  
  7         397  
15 7     7   3025 use Astro::Coord::ECI::VSOP87D qw{ :mixin };
  7         22  
  7         1244  
16 7     7   58 use Carp;
  7         15  
  7         7256  
17              
18             our $VERSION = '0.005_01';
19              
20             sub new {
21 10     10 1 3910 my ( $class, %arg ) = @_;
22 10         84 $class->__default( \%arg );
23 10         103 return $class->SUPER::new( %arg );
24             }
25              
26             sub __almanac_event_type_iterator {
27 0     0   0 my ( $self, $station ) = @_;
28              
29 0         0 my $inx = 0;
30              
31 0         0 my $horizon = $station->__get_almanac_horizon();
32              
33 0         0 my @events = (
34             [ $station, next_elevation => [ $self, $horizon, 1 ],
35             horizon => '__horizon_name' ],
36             [ $station, next_meridian => [ $self ],
37             transit => '__transit_name' ],
38             [ $self, next_quarter => [], 'quarter', '__quarter_name' ],
39             );
40              
41             return sub {
42             $inx < @events
43 0 0   0   0 and return @{ $events[$inx++] };
  0         0  
44 0         0 return;
45 0         0 };
46             }
47              
48             {
49             my $get = sub {
50             my ( $self, $name ) = @_;
51             return $self->__get_attr()->{$name};
52             };
53              
54             my %accessor = (
55             model_cutoff => $get,
56             nutation_cutoff => $get,
57             );
58              
59             sub attribute {
60 0     0 1 0 my ( $self, $name ) = @_;
61 0 0       0 exists $accessor{$name}
62             and return __PACKAGE__;
63 0         0 return $self->SUPER::attribute( $name );
64             }
65              
66             sub get {
67 4777     4777 1 115725 my ( $self, @arg ) = @_;
68 4777         7796 my @rslt;
69 4777         9305 foreach my $name ( @arg ) {
70 4777 100       12489 if ( my $code = $accessor{$name} ) {
71 2279         5362 push @rslt, $code->( $self, $name );
72             } else {
73 2498         9451 push @rslt, $self->SUPER::get( $name );
74             }
75             wantarray
76 4777 100       62024 or return $rslt[0];
77             }
78 40         693 return @rslt;
79             }
80             }
81              
82             # NOTE that the %opt arguments are UNSUPPORTED and can be changed or
83             # removed without notice. Caveat coder.
84             sub next_quarter {
85 25     25 1 3052 my ( $self, $quarter, %opt ) = @_;
86              
87 25         105 my $time = $self->universal();
88              
89 25         417 my $increment = $self->synodic_period() / 16;
90              
91             my @checker = (
92             sub { # 0 = conjunction
93 165     165   2309 my ( $time ) = @_;
94 165 100       555 return $self->__longitude_from_sun( $time ) < 0 ? 4 : 0;
95             },
96             sub { # 1 = west quadrature
97 165     165   2278 my ( $time ) = @_;
98 165 100       532 return $self->__longitude_from_sun( $time, - PIOVER2 ) < 0 ? 1 : 0;
99             },
100             sub { # 2 = opposition
101 327     327   4567 my ( $time ) = @_;
102 327 100       1034 return $self->__longitude_from_sun( $time, PI ) < 0 ? 2 : 0;
103             },
104             sub { # 3 = east quadrature
105 157     157   2188 my ( $time ) = @_;
106 157 100       469 return $self->__longitude_from_sun( $time, PIOVER2 ) < 0 ? 3 : 0;
107             },
108 25         693 );
109              
110 25 50       137 if ( defined $opt{checker_result} ) {
111 0         0 return $checker[$opt{checker_result}]->( $time );
112             }
113              
114 25         54 my $test;
115 25 100       97 if ( defined $quarter ) {
116 5         22 $test = $checker[$quarter];
117 5         27 while ( $test->( $time ) ) {
118 13         153 $time += $increment;
119             }
120 5         73 while ( ! $test->( $time ) ) {
121 37         384 $time += $increment;
122             }
123             } else {
124 20 50       68 my @chk = grep { ! $_->( $time ) } @checker
  80         661  
125             or confess 'Programming error - no false checks';
126 20         221 my $rslt;
127 20         66 while ( ! $rslt ) {
128 80         618 $time += $increment;
129 80         490 foreach my $c ( @chk ) {
130 145 100       864 $rslt = $c->( $time )
131             and last;
132             }
133             }
134 20         219 $quarter = $rslt % 4;
135 20         403 $test = $checker[$quarter];
136             }
137              
138 25         182 my $rslt = find_first_true( $time - $increment, $time, $test );
139              
140 25         709 $self->universal( $rslt );
141              
142             wantarray
143 25 50       452 or return $rslt;
144 25         213 return( $rslt, $quarter, $self->__quarter_name( $quarter ) );
145             }
146              
147             sub __quarter_name {
148 25     25   90 my ( $self, $event, $name ) = @_;
149 25   50     201 $name ||= [
150             '%s conjunction',
151             '%s west quadrature',
152             '%s opposition',
153             '%s east quadrature',
154             ];
155 25         108 return sprintf $name->[$event], $self->get( 'name' );
156             }
157              
158             {
159             my %mutator = (
160             model_cutoff => \&__mutate_model_cutoff,
161             nutation_cutoff => \&__mutate_nutation_cutoff,
162             );
163              
164             sub set {
165 20     20 1 397 my ( $self, @arg ) = @_;
166 20         65 while ( @arg ) {
167 65         1168 my ( $name, $value ) = splice @arg, 0, 2;
168 65 100       191 if ( my $code = $mutator{$name} ) {
169 20         67 $code->( $self, $name, $value );
170             } else {
171 45         140 $self->SUPER::set( $name, $value );
172             }
173             }
174 20         637 return $self;
175             }
176             }
177              
178             1;
179              
180             __END__