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.22';
lib/Astro/Coords/Angle.pm view on Meta::CPAN
sub _guess_units {
my $self = shift;
my $input = shift;
return undef if !defined $input;
# Now if we have a space, colon or alphabetic character
# then we have a real string and assume sexagesimal.
# Use pre-defined character classes
my $units;
# if it does not look like a number choose sexagesimal
if (!looks_like_number($input)) {
$units = "sexagesimal";
} elsif ($input > Astro::PAL::D2PI) {
$units = "degrees";
} else {
$units = "radians";
}
return $units;
}
#!perl
use strict;
use Test::More tests => 105;
use Test::Number::Delta within => 1e-9;
use Scalar::Util qw/ looks_like_number /;
require_ok('Astro::Coords');
require_ok('Astro::Telescope');
use Time::Piece ':override';
# Force stringification to use colons
Astro::Coords::Angle->DELIM(':');
Astro::Coords::Angle::Hour->DELIM(':');
Astro::Coords::Angle::Hour->NDP(2);
exit;
sub test_array_elem {
my $ansref = shift; # The answer you got
my $testref = shift; # The answer you should have got
# Compare sizes
is($#$ansref, $#$testref, "Compare number of elements in array");
for my $i (0..$#$testref) {
if (defined $ansref->[$i] && looks_like_number($ansref->[$i])) {
delta_ok($ansref->[$i], $testref->[$i], "Compare array element $i");
} else {
is($ansref->[$i], $testref->[$i], "Compare array element $i");
}
}
}
sub _gmstrptime {
# parse ISO date as UT
#!perl
use strict;
use Test::More tests => 44;
use Test::Number::Delta;
use Scalar::Util qw/ looks_like_number /;
require_ok("Astro::Coords");
require_ok("Astro::Telescope");
require_ok("Astro::Coords::Offset");
require_ok('Astro::Coords::Angle');
my $off = Astro::Coords::Offset->new( 55, 22, system => "GALACTIC" );
isa_ok($off, "Astro::Coords::Offset");
is( $off->system, "GAL", "Check system conversion");
$off = Astro::Coords::Offset->new(0, 0);
my $coordsoff = $coords->apply_offset($off);
# Ensure that the basic position is the same for the new
# (0,0) offset
my @refpos = $coords->array();
my @newpos = $coordsoff->array();
is (scalar(@refpos), scalar(@newpos), "array() returns same number of items");
for my $i (0..$#refpos) {
if (defined $refpos[$i] && defined $newpos[$i] &&
looks_like_number($refpos[$i])) {
delta_ok( $newpos[$i], $refpos[$i], "Compare element $i");
} else {
is( $newpos[$i], $refpos[$i], "Compare element $i");
}
}
is_deeply( $coordsoff->datetime, $coords->datetime, "Check date time object");
is_deeply( $coordsoff->telescope, $coords->telescope, "Check telescop");
$off = new Astro::Coords::Offset(
new Astro::Coords::Angle(0.001, unit => 'radians'),
( run in 0.401 second using v1.01-cache-2.11-cpan-64827b87656 )