line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Compass::Bearing; |
2
|
2
|
|
|
2
|
|
66756
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
76
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
10
|
use base qw{Package::New}; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
2298
|
|
5
|
2
|
|
|
2
|
|
3222
|
use Geo::Functions qw{deg_rad round}; |
|
2
|
|
|
|
|
4740
|
|
|
2
|
|
|
|
|
1289
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION='0.07'; |
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
|
48
|
my $self = shift; |
38
|
2
|
|
50
|
|
|
12
|
my $param = shift || 3; |
39
|
2
|
|
|
|
|
11
|
$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
|
87931
|
my $self = shift; |
52
|
171
|
|
100
|
|
|
512
|
my $angle = shift || 0; #degrees |
53
|
171
|
|
|
|
|
406
|
$angle+=360 while ($angle < 0); |
54
|
171
|
|
|
|
|
307
|
my @data = $self->data; |
55
|
171
|
|
|
|
|
780
|
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
|
7499
|
my $self=shift; |
68
|
15
|
|
100
|
|
|
81
|
my $angle=deg_rad(shift()||0); #degrees |
69
|
15
|
|
|
|
|
175
|
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
|
1708
|
my $self=shift; |
85
|
177
|
|
|
|
|
177
|
my $param=shift; |
86
|
177
|
100
|
|
|
|
363
|
if (defined $param) { |
87
|
5
|
|
|
|
|
16
|
my %data=$self->_dataraw; |
88
|
5
|
|
|
|
|
39
|
my @keys=sort keys %data; |
89
|
5
|
50
|
|
|
|
16
|
if (exists $data{$param}) { |
90
|
5
|
|
|
|
|
29
|
$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
|
|
|
|
|
426
|
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
|
187
|
my $self=shift; |
108
|
171
|
|
|
|
|
288
|
my $data=$self->_dataraw; |
109
|
171
|
|
|
|
|
373
|
my $return=$data->{$self->set}; |
110
|
171
|
50
|
|
|
|
300
|
return wantarray ? @{$return} : $return; |
|
171
|
|
|
|
|
1073
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _dataraw { |
114
|
176
|
|
|
176
|
|
1325
|
my %data=(1=>[qw{N E S W}], |
115
|
|
|
|
|
|
|
2=>[qw{N NE E SE S SW W NW}], |
116
|
|
|
|
|
|
|
3=>[qw{N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW}]); |
117
|
176
|
100
|
|
|
|
536
|
return wantarray ? %data : \%data; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 BUGS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Please send to the geo-perl email list. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Michael R. Davis qw/perl michaelrdavis com/ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Copyright (c) 2012 Michael R. Davis (mrdvt92) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |