| 1 | package Geo::Functions; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw(@ISA @EXPORT_OK); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | require Exporter; | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Geo::Constants qw{RAD DEG KNOTS}; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||
| 9 | 1 | @EXPORT_OK = (qw{deg_rad rad_deg deg_dms rad_dms dms_deg dm_deg round mps_knots knots_mps}); | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | Geo::Functions - Package for standard Geo:: functions. | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | use Geo::Functions qw{deg_rad deg_dms rad_deg}; #import into namespace | ||||||||||||||||||||||||||||||
| 19 | print "Degrees: ", deg_rad(3.14/4), "\n"; | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | use Geo::Functions; | ||||||||||||||||||||||||||||||
| 22 | my $obj = Geo::Functions->new; | ||||||||||||||||||||||||||||||
| 23 | print "Degrees: ", $obj->deg_rad(3.14/2), "\n"; | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | Package for standard Geo:: functions. | ||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | =head1 CONVENTIONS | ||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | Function naming convention is "format of the return" underscore "format of the parameters." For example, you can read the deg_rad function as "degrees given radians" or "degrees from radians". | ||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | =head2 new | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | The new() constructor | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | my $obj = Geo::Functions->new(); | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 44 | 1 | my $this = shift(); | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||
| 46 | 1 | my $self = {}; | |||||||||||||||||||||||||||||
| 47 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||
| 48 | 1 | $self->initialize(@_); | |||||||||||||||||||||||||||||
| 49 | 1 | return $self; | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | =head2 initialize | ||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub initialize { | ||||||||||||||||||||||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 59 | 1 | my $self = shift(); | |||||||||||||||||||||||||||||
| 60 | 1 | %$self = @_; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | =head2 deg_dms | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | Degrees given degrees minutes seconds. | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | my $deg = deg_dms(39, 29, 17.134); | ||||||||||||||||||||||||||||||
| 68 | my $deg = deg_dms(39, 29, 17.134, 'N'); | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 615 | ▶ | sub deg_dms { | ||||||||||||||||||||||||||||
|
Subroutine
deg_dms: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 73 | 615 | my $self = shift(); | |||||||||||||||||||||||||||||
| 74 | 615 | ▶ | my $d = ref($self) ? shift()||0 : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() or 0
MC/DC0%0/1
shift() or 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 75 | 615 | ▶ | my $m = shift()||0; | ||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 76 | 615 | ▶ | my $s = shift()||0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 77 | 615 | ▶ | my $nsew = shift()||'N'; | ||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 'N'
MC/DC100%1/1
shift() || 'N'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 78 | 615 | ▶ | my $sign = ($nsew=~m/[SW-]/i) ? -1 : 1; #matches "-" to support -1 | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 79 | 615 | return $sign * ($d + ($m + $s/60)/60); | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | =head2 deg_rad | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | Degrees given radians. | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | my $deg = deg_rad(3.14); | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | sub deg_rad { | ||||||||||||||||||||||||||||
|
Subroutine
deg_rad: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 91 | 2 | my $self = shift(); | |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | my $rad = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | 2 | return $rad*DEG(); | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | =head2 rad_deg | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | Radians given degrees. | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | my $rad = rad_deg(90); | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 9 | ▶ | sub rad_deg { | ||||||||||||||||||||||||||||
|
Subroutine
rad_deg: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 105 | 9 | my $self = shift(); | |||||||||||||||||||||||||||||
| 106 | 9 | ▶ | my $deg = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | 9 | return $deg*RAD(); | |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | =head2 rad_dms | ||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | Radians given degrees minutes seconds. | ||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | my $rad = rad_dms(45 30 20.0); | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub rad_dms { | ||||||||||||||||||||||||||||
|
Subroutine
rad_dms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 119 | 2 | return rad_deg(deg_dms(@_)); | |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||
| 122 | =head2 round | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | Round to the nearest integer. This formula rounds toward +/- infinity. | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | my $int = round(42.2); | ||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 8 | ▶ | sub round { | ||||||||||||||||||||||||||||
|
Subroutine
round: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 131 | 8 | my $self = shift(); | |||||||||||||||||||||||||||||
| 132 | 8 | ▶ | my $number = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 133 | 8 | return int($number + 0.5 * ($number <=> 0)); | |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | =head2 dms_deg | ||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | Degrees minutes seconds given degrees. | ||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | my ($d, $m, $s, $sign) = dms_deg($degrees, qw{N S}); | ||||||||||||||||||||||||||||||
| 141 | my ($d, $m, $s, $sign) = dms_deg($degrees, qw{E W}); | ||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | 400 | ▶ | sub dms_deg { | ||||||||||||||||||||||||||||
|
Subroutine
dms_deg: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 146 | 400 | my $self = shift(); | |||||||||||||||||||||||||||||
| 147 | 400 | ▶ | my $number = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 148 | 400 | my @sign = @_; | |||||||||||||||||||||||||||||
| 149 | 400 | ▶ | my $sign = $number >= 0 ? $sign[0]||1 : $sign[1]||-1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$sign[0] or 1
$sign[1] or -1
MC/DC0%0/1
$sign[0] or 1
$sign[0]
MC/DC0%0/1
$sign[1] or -1
$sign[1]
Truth table50%1/2
A
A= $sign[0]
Truth table50%1/2
A
A= $sign[1]
| |||||||||||||||||||||||||||||||
| 150 | 400 | $number = abs($number); | |||||||||||||||||||||||||||||
| 151 | 400 | my $d = int($number); | |||||||||||||||||||||||||||||
| 152 | 400 | my $m = int(($number-$d) * 60); | |||||||||||||||||||||||||||||
| 153 | 400 | my $s = ((($number-$d) * 60) - $m) * 60; | |||||||||||||||||||||||||||||
| 154 | 400 | my @dms = ($d, $m, $s, $sign); | |||||||||||||||||||||||||||||
| 155 | 400 | ▶ | return wantarray ? @dms : join(' ', @dms); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | =head2 dm_deg | ||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | Degrees minutes given degrees. | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | my ($d, $m, $sign) = dm_deg($degrees, qw{N S}); | ||||||||||||||||||||||||||||||
| 163 | my ($d, $m, $sign) = dm_deg($degrees, qw{E W}); | ||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 200 | ▶ | sub dm_deg { | ||||||||||||||||||||||||||||
|
Subroutine
dm_deg: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 168 | 200 | my $self = shift(); | |||||||||||||||||||||||||||||
| 169 | 200 | ▶ | my $number = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 170 | 200 | my @sign = @_; | |||||||||||||||||||||||||||||
| 171 | 200 | ▶ | my $sign = $number >= 0 ? $sign[0]||1 : $sign[1]||-1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$sign[0] or 1
$sign[1] or -1
MC/DC0%0/1
$sign[0] or 1
$sign[0]
MC/DC0%0/1
$sign[1] or -1
$sign[1]
Truth table50%1/2
A
A= $sign[0]
Truth table50%1/2
A
A= $sign[1]
| |||||||||||||||||||||||||||||||
| 172 | 200 | $number = abs($number); | |||||||||||||||||||||||||||||
| 173 | 200 | my $d = int($number); | |||||||||||||||||||||||||||||
| 174 | 200 | my $m = ($number-$d) * 60; | |||||||||||||||||||||||||||||
| 175 | 200 | my @dm = ($d, $m, $sign); | |||||||||||||||||||||||||||||
| 176 | 200 | ▶ | return wantarray ? @dm : join(' ', @dm); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | =head2 mps_knots | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | meters per second given knots | ||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | my $mps = mps_knots(50.0); | ||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | 8 | ▶ | sub mps_knots { | ||||||||||||||||||||||||||||
|
Subroutine
mps_knots: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 188 | 8 | my $self = shift(); | |||||||||||||||||||||||||||||
| 189 | 8 | ▶ | my $number = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 190 | 8 | return $number * KNOTS(); | |||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | =head2 knots_mps | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | knots given meters per second | ||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | my $knots = knots_mps(25.0); | ||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | 8 | ▶ | sub knots_mps { | ||||||||||||||||||||||||||||
|
Subroutine
knots_mps: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 202 | 8 | my $self = shift(); | |||||||||||||||||||||||||||||
| 203 | 8 | ▶ | my $number = ref($self) ? shift() : $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 204 | 8 | return $number / KNOTS(); | |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | =head1 BUGS | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | Please log on GitHub | ||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | =head1 AUTHOR | ||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||
| 213 | Michael R. Davis | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | =head1 LICENSE | ||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||
| 217 | MIT License | ||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | Copyright (c) 2022 Michael R. Davis | ||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||
| 221 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | L<Geo::Constants>, L<Geo::Ellipsoids> | ||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||
| 225 | =cut | ||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||
| 227 | 1 | 1; | |||||||||||||||||||||||||||||