Astro-Coords
view release on metacpan or search on metacpan
lib/Astro/Coords/Angle.pm view on Meta::CPAN
angles in any desired format.
=cut
use 5.006;
use strict;
use warnings;
use warnings::register;
use Carp;
use Scalar::Util qw/ looks_like_number /;
use Astro::PAL;
# Overloading
use overload
'""' => "stringify",
'0+' => "numify",
fallback => 1;
# Package Global variables
our $VERSION = '0.23';
=head1 METHODS
=head2 Constructor
=over 4
=item B<new>
Construct a new C<Angle> object. Must be called with an angle as first
argument. Optional hash arguments can be supplied to specify, for example,
the units of the supplied angle.
$ang = new Astro::Coords::Angle( $angle,
units => "degrees" );
Supported options are:
units - units of the supplied string or number
range - restricted range of the angle
Supported units are:
sexagesimal - A string of format either dd:mm:ss or "dd mm ss"
"dms" separators are also supported.
degrees - decimal degrees
radians - radians
arcsec - arc seconds (abbreviated form is 'as')
arcmin - arc minutes (abbreviated form is 'am')
The units can be abbreviated to the first 3 characters.
If the units are not supplied the default is to assume "sexagesimal"
if the supplied string contains spaces or colons or the characters
"d", "m" or "s", "degrees" if the supplied number is greater than 2*PI
(6.28), and "radians" for all other values. Negative angles are supported.
The options for range are documented in the C<range> method.
If the angle can not be decoded (if a string), the constructor will fail.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
croak "Constructor for object of class $class must be called with an argument" unless @_;
# first argument is the angle
my $input_ang = shift;
# optional hash, only read it if we have an even number of
# remaining arguments
my %args;
if (@_) {
if (scalar(@_) % 2 == 0) {
%args = @_;
} else {
warnings::warnif("An odd number of Optional arguments were supplied to constructor");
}
}
# Now need to convert this to radians (the internal representation)
# Allow for inheritance
my $rad = $class->_cvt_torad($input_ang, $args{units});
croak "Unable to decode supplied angle (".
(defined $input_ang ? "'$input_ang'" : "<undef>").")"
unless defined $rad;
# Create the object
my $ang = bless {
ANGLE => $rad,
RANGE => 'NONE',
NDP => undef, # number of decimal places
DELIM => undef, # string delimiter
}, $class;
# If a range was specified, normalise the angle
$ang->range( $args{range} ) if exists $args{range};
# And return the object
return $ang;
}
=back
=head2 Accessor Methods
=over 4
=item B<radians>
Return the angle in radians.
$rad = $ang->radians;
=cut
( run in 1.101 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )