line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Compass::Bearing; |
2
|
2
|
|
|
2
|
|
135448
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
57
|
|
3
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
10
|
use base qw{Package::New}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1015
|
|
5
|
2
|
|
|
2
|
|
1361
|
use Geo::Functions qw{deg_rad round}; |
|
2
|
|
|
|
|
3371
|
|
|
2
|
|
|
|
|
899
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Compass::Bearing - Convert angle to text bearing (aka heading) |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Compass::Bearing; |
16
|
|
|
|
|
|
|
my $cb = Compass::Bearing->new(3); |
17
|
|
|
|
|
|
|
my $angle = 12; |
18
|
|
|
|
|
|
|
printf "Bearing: %s deg => %s\n", $angle, $cb->bearing($angle); #prints NNE |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Convert angle to text bearing (aka heading) |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
The new() constructor may be called with any parameter that is appropriate to the set method. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $obj = Compass::Bearing->new(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub initialize { |
37
|
2
|
|
|
2
|
1
|
204
|
my $self = shift; |
38
|
2
|
|
50
|
|
|
14
|
my $param = shift || 3; |
39
|
2
|
|
|
|
|
8
|
$self->set($param); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 bearing |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Method returns a text string based on bearing |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $bearing=$obj->bearing($degrees_from_north); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub bearing { |
51
|
171
|
|
|
171
|
1
|
95952
|
my $self = shift; |
52
|
171
|
|
100
|
|
|
435
|
my $angle = shift || 0; #degrees |
53
|
171
|
|
|
|
|
434
|
$angle += 360 while ($angle < 0); |
54
|
171
|
|
|
|
|
324
|
my @data = $self->data; |
55
|
171
|
|
|
|
|
641
|
return $data[round($angle/360 * @data) % @data]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 bearing_rad |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Method returns a text string based on bearing |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $bearing=$obj->bearing_rad($radians_from_north); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub bearing_rad { |
67
|
15
|
|
|
15
|
1
|
7511
|
my $self = shift; |
68
|
15
|
|
100
|
|
|
75
|
my $angle = deg_rad(shift()||0); #degrees |
69
|
15
|
|
|
|
|
185
|
return $self->bearing($angle); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 set |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Method sets and returns key for the bearing text data structure. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $key = $self->set; |
77
|
|
|
|
|
|
|
my $key = $self->set(1); |
78
|
|
|
|
|
|
|
my $key = $self->set(2); |
79
|
|
|
|
|
|
|
my $key = $self->set(3); #default value |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub set { |
84
|
177
|
|
|
177
|
1
|
1859
|
my $self = shift; |
85
|
177
|
|
|
|
|
277
|
my $param = shift; |
86
|
177
|
100
|
|
|
|
370
|
if (defined $param) { |
87
|
5
|
|
|
|
|
13
|
my %data = $self->_dataraw; |
88
|
5
|
|
|
|
|
28
|
my @keys = sort keys %data; |
89
|
5
|
50
|
|
|
|
15
|
if (exists $data{$param}) { |
90
|
5
|
|
|
|
|
28
|
$self->{'set'} = $param; |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
0
|
die(qq{Error: "$param" is not a valid parameter to the set method. Try }. join(", ", map {qq{"$_"}} @keys). ".\n") |
|
0
|
|
|
|
|
0
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
177
|
|
|
|
|
423
|
return $self->{'set'}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 data |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Method returns an array of text values. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $data=$self->data; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub data { |
107
|
171
|
|
|
171
|
1
|
268
|
my $self = shift; |
108
|
171
|
|
|
|
|
303
|
my $data = $self->_dataraw; |
109
|
171
|
|
|
|
|
382
|
my $return = $data->{$self->set}; |
110
|
171
|
50
|
|
|
|
324
|
return wantarray ? @{$return} : $return; |
|
171
|
|
|
|
|
754
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _dataraw { |
114
|
176
|
|
|
176
|
|
1077
|
my %data=( |
115
|
|
|
|
|
|
|
1 => [qw{N E S W}], |
116
|
|
|
|
|
|
|
2 => [qw{N NE E SE S SW W NW}], |
117
|
|
|
|
|
|
|
3 => [qw{N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW}] |
118
|
|
|
|
|
|
|
); |
119
|
176
|
100
|
|
|
|
475
|
return wantarray ? %data : \%data; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 BUGS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Please log on GitHub |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Michael R. Davis |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
MIT License |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Copyright (c) 2022 Michael R. Davis |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SEE ALSO |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L compass method |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |