| 1 | package Zodiac::Angle; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use List::MoreUtils qw(none); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Unicode::UTF8 qw(decode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | Readonly::Array our @SIGN_TYPES => qw(sign ascii); | |||||||||||||||||||||||||||
| 13 | 5 | Readonly::Hash our %ZODIAC => ( | |||||||||||||||||||||||||||
| 14 | 1 => { | ||||||||||||||||||||||||||||
| 15 | 'sign' => decode_utf8('♈'), # Aries/Beran | ||||||||||||||||||||||||||||
| 16 | 'ascii' => 'ar', | ||||||||||||||||||||||||||||
| 17 | }, | ||||||||||||||||||||||||||||
| 18 | 2 => { | ||||||||||||||||||||||||||||
| 19 | 'sign' => decode_utf8('♉'), # Taurus/Býk | ||||||||||||||||||||||||||||
| 20 | 'ascii' => 'ta', | ||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||
| 22 | 3 => { | ||||||||||||||||||||||||||||
| 23 | 'sign' => decode_utf8('♊'), # Gemini/Blíženci | ||||||||||||||||||||||||||||
| 24 | 'ascii' => 'ge', | ||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | 4 => { | ||||||||||||||||||||||||||||
| 27 | 'sign' => decode_utf8('♋'), # Cancer/Rak | ||||||||||||||||||||||||||||
| 28 | 'ascii' => 'cn', | ||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||
| 30 | 5 => { | ||||||||||||||||||||||||||||
| 31 | 'sign' => decode_utf8('♌'), # Leo/Lev | ||||||||||||||||||||||||||||
| 32 | 'ascii' => 'le', | ||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | 6 => { | ||||||||||||||||||||||||||||
| 35 | 'sign' => decode_utf8('♍'), # Virgo/Panna | ||||||||||||||||||||||||||||
| 36 | 'ascii' => 'vi', | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | 7 => { | ||||||||||||||||||||||||||||
| 39 | 'sign' => decode_utf8('♎'), # Libra/Váhy | ||||||||||||||||||||||||||||
| 40 | 'ascii' => 'li', | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | 8 => { | ||||||||||||||||||||||||||||
| 43 | 'sign' => decode_utf8('♏'), # Scorpio/Štír | ||||||||||||||||||||||||||||
| 44 | 'ascii' => 'sc', | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | 9 => { | ||||||||||||||||||||||||||||
| 47 | 'sign' => decode_utf8('♐'), # Sagittarius/Střelec | ||||||||||||||||||||||||||||
| 48 | 'ascii' => 'sa', | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | 10 => { | ||||||||||||||||||||||||||||
| 51 | 'sign' => decode_utf8('♑'), # Capricorn/Kozoroh | ||||||||||||||||||||||||||||
| 52 | 'ascii' => 'cp', | ||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | 11 => { | ||||||||||||||||||||||||||||
| 55 | 'sign' => decode_utf8('♒'), # Aquarius/Vodnář | ||||||||||||||||||||||||||||
| 56 | 'ascii' => 'aq', | ||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||
| 58 | 12 => { | ||||||||||||||||||||||||||||
| 59 | 'sign' => decode_utf8('♓'), # Pisces/Ryby | ||||||||||||||||||||||||||||
| 60 | 'ascii' => 'pi', | ||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 5 | Readonly::Scalar our $SPACE => ' '; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | our $VERSION = 0.05; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Constructor. | ||||||||||||||||||||||||||||
| 68 | sub new { | ||||||||||||||||||||||||||||
| 69 | 2 | ▶ | my ($class, @params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Create object. | ||||||||||||||||||||||||||||
| 72 | 2 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # Process parameters. | ||||||||||||||||||||||||||||
| 75 | 2 | set_params($self, @params); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | return $self; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub angle2zodiac { | ||||||||||||||||||||||||||||
| 81 | 17 | ▶ | my ($self, $angle, $opts_hr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
angle2zodiac: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # Options. | ||||||||||||||||||||||||||||
| 84 | 17 | ▶ | if (! defined $opts_hr || ! exists $opts_hr->{'minute'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opts_hr and exists $opts_hr->{"minute"}
MC/DC100%2/2
defined $opts_hr and exists $opts_hr->{"minute"}
defined $opts_hr
exists $opts_hr->{"minute"}
Truth table100%3/3
A and B
A= defined $opts_hrB= exists $opts_hr->{"minute"}
| |||||||||||||||||||||||||||||
| 85 | 13 | $opts_hr->{'minute'} = 1; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 17 | ▶ | if (! exists $opts_hr->{'second'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 15 | $opts_hr->{'second'} = 0; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 17 | ▶ | if (! exists $opts_hr->{'second_round'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 17 | $opts_hr->{'second_round'} = 4; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 17 | ▶ | if (! exists $opts_hr->{'sign_type'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 15 | $opts_hr->{'sign_type'} = 'sign'; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 17 | ▶ | if (none { $opts_hr->{'sign_type'} eq $_ } @SIGN_TYPES) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 1 | err "Parameter 'sign_type' is bad. Possible values are 'sign' and 'ascii'."; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 16 | my $ret = {}; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Full angle degree. | ||||||||||||||||||||||||||||
| 103 | 16 | my $full_angle_degree = int($angle); | |||||||||||||||||||||||||||
| 104 | 16 | $angle -= $full_angle_degree; | |||||||||||||||||||||||||||
| 105 | 16 | $angle *= 60; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Angle minute. | ||||||||||||||||||||||||||||
| 108 | 16 | ▶ | if ($opts_hr->{'minute'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 15 | $ret->{'angle_minute'} = int($angle); | |||||||||||||||||||||||||||
| 110 | 15 | $angle -= $ret->{'angle_minute'}; | |||||||||||||||||||||||||||
| 111 | 15 | $angle *= 60; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Angle second. | ||||||||||||||||||||||||||||
| 115 | 16 | ▶ | if ($opts_hr->{'second'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 2 | my $print_format = '%0.'.$opts_hr->{'second_round'}.'f'; | |||||||||||||||||||||||||||
| 117 | 2 | $ret->{'angle_second'} = sprintf($print_format, $angle); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # Angle sign. | ||||||||||||||||||||||||||||
| 121 | 16 | $ret->{'sign'} = int($full_angle_degree / 30); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Angle degree in sign. | ||||||||||||||||||||||||||||
| 124 | 16 | $ret->{'angle_degree'} = $full_angle_degree - ($ret->{'sign'} * 30); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # Output. | ||||||||||||||||||||||||||||
| 127 | 16 | my $zodiac_angle; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Output with sign (UTF-8). | ||||||||||||||||||||||||||||
| 130 | 16 | ▶ | if ($opts_hr->{'sign_type'} eq 'sign') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | $zodiac_angle = $ret->{'angle_degree'}.decode_utf8('°'). | ||||||||||||||||||||||||||||
| 132 | 15 | $ZODIAC{$ret->{'sign'} + 1}->{'sign'}; | |||||||||||||||||||||||||||
| 133 | 15 | ▶ | if ($opts_hr->{'minute'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 14 | $zodiac_angle .= $ret->{'angle_minute'}.decode_utf8("′"); | |||||||||||||||||||||||||||
| 135 | 14 | ▶ | if ($opts_hr->{'second'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | $zodiac_angle .= $ret->{'angle_second'}.decode_utf8("′′"); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # Output with ascii. | ||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||
| 142 | $zodiac_angle = $ret->{'angle_degree'}.$SPACE. | ||||||||||||||||||||||||||||
| 143 | 1 | $ZODIAC{$ret->{'sign'} + 1}->{'ascii'}; | |||||||||||||||||||||||||||
| 144 | 1 | ▶ | if ($opts_hr->{'minute'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 1 | $zodiac_angle .= $SPACE.$ret->{'angle_minute'}."'"; | |||||||||||||||||||||||||||
| 146 | 1 | ▶ | if ($opts_hr->{'second'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 1 | $zodiac_angle .= $ret->{'angle_second'}."''"; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 16 | return $zodiac_angle; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub zodiac2angle { | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my ($self, $zodiac_angle) = @_; | ||||||||||||||||||||||||||
|
Subroutine
zodiac2angle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # TODO | ||||||||||||||||||||||||||||
| 159 | 0 | my $angle; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | return $angle; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 5 | 1; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||