| 1 | package CXC::Astro::Regions::CFITSIO; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: CFITSIO Compatible Regions | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use v5.20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use experimental 'signatures', 'postderef', 'lexical_subs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | use CXC::Astro::Regions::CFITSIO::Types qw( | |||||||||||||||||||||||||||
| 12 | Angle | ||||||||||||||||||||||||||||
| 13 | ColumnName | ||||||||||||||||||||||||||||
| 14 | Tuple | ||||||||||||||||||||||||||||
| 15 | Length | ||||||||||||||||||||||||||||
| 16 | NonEmptyStr | ||||||||||||||||||||||||||||
| 17 | Vertex | ||||||||||||||||||||||||||||
| 18 | ArrayRef | ||||||||||||||||||||||||||||
| 19 | XPosition | ||||||||||||||||||||||||||||
| 20 | YPosition | ||||||||||||||||||||||||||||
| 21 | 2 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use CXC::Astro::Regions::CFITSIO::Variant; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | package CXC::Astro::Regions::CFITSIO::Role::Region { | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use constant RegionRole => __PACKAGE__ . '::Role::Region'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use parent 'Exporter::Tiny'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ▶ | my sub pkgpath ( @paths ) { | |||||||||||||||||||||||||||
|
Subroutine
pkgpath: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 23 | join q{::}, __PACKAGE__, map { ucfirst } @paths; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | ▶ | my sub args ( @args ) { | |||||||||||||||||||||||||||
|
Subroutine
args: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 40 | 66 | ▶ | return @args == 1 ? ( name => $args[0] ) : @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 8 | ▶ | my sub ANGLE { { name => 'angle', isa => Angle, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
ANGLE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | my sub ANGLEPAIR { { name => 'angles', isa => Tuple [ Angle, Angle ], args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
ANGLEPAIR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 10 | ▶ | my sub LENGTH { { name => 'length', isa => Length, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
LENGTH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 8 | ▶ | my sub LENGTHPAIR { { name => undef, isa => Tuple [ Length, Length ], args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
LENGTHPAIR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my sub STRING { { name => undef, isa => NonEmptyStr, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
STRING: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 20 | ▶ | my sub VERTEX { { name => undef, isa => Vertex, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
VERTEX: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | my sub VERTICES { { name => 'vertices', isa => ArrayRef [Vertex], args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
VERTICES: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | my sub XPOS { { name => undef, isa => XPosition, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
XPOS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | my sub YPOS { { name => undef, isa => YPosition, args( @_ ) } } | ||||||||||||||||||||||||||
|
Subroutine
YPOS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | my sub COLUMNPAIR { | ||||||||||||||||||||||||||||
| 53 | 6 | ▶ | { name => 'columns', isa => Tuple [ ColumnName, ColumnName ], required => 0, args( @_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
COLUMNPAIR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | our @EXPORT_OK = ( 'mkregion' ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # my sub REGION ( $name, $params ) { $Region{$name} = $params } | ||||||||||||||||||||||||||||
| 60 | 2 | my $stash = Package::Stash->new( __PACKAGE__ ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | ▶ | my sub REGION ( $region, %spec ) { | |||||||||||||||||||||||||||
|
Subroutine
REGION: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 22 | ▶ | $spec{with} //= [RegionRole]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$spec{"with"} //= ["CXC::Astro::Regions::CFITSIO::Role::Region"]
MC/DC0%0/1
$spec{"with"} //= ["CXC::Astro::Regions::CFITSIO::Role::Region"]
$spec{"with"}
Truth table50%1/2
A
A= $spec{"with"}
| |||||||||||||||||||||||||||||
| 65 | 22 | my $package = pkgpath( $region ); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 22 | ▶ | if ( exists $spec{name} && $spec{name} ne $region ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $spec{"name"} and $spec{"name"} ne $region
MC/DC0%0/2
exists $spec{"name"} and $spec{"name"} ne $region
exists $spec{"name"}
$spec{"name"} ne $region
Truth table66%2/3
A and B
A= exists $spec{"name"}B= $spec{"name"} ne $region
| |||||||||||||||||||||||||||||
| 68 | 0 | my $parent = pkgpath( $spec{name} ); | |||||||||||||||||||||||||||
| 69 | 0 | Moo->import::into( $parent ); | |||||||||||||||||||||||||||
| 70 | 0 | $spec{extends} = [$parent]; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 22 | my $variant = Variant( $region, %spec ); | |||||||||||||||||||||||||||
| 74 | 22 | Package::Stash->new( $variant )->add_symbol( q{@CARP_NOT}, [__PACKAGE__] ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 22 | ▶ | $stash->add_symbol( q{&} . $region, sub { $package->new( @_ ) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 22 | push @EXPORT_OK, $region; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Annulus ( Xc, Yc, Rin, Rout ) | ||||||||||||||||||||||||||||
| 91 | 2 | REGION annulus => ( | |||||||||||||||||||||||||||
| 92 | name => 'annulus', | ||||||||||||||||||||||||||||
| 93 | params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ) ], | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # Box ( Xc, Yc, Wdth, Hght, A ) | ||||||||||||||||||||||||||||
| 116 | # Box ( Xc, Yc, Wdth, Hght, A, Xcolumn, Ycolumn ) | ||||||||||||||||||||||||||||
| 117 | 2 | REGION box => ( | |||||||||||||||||||||||||||
| 118 | name => 'box', | ||||||||||||||||||||||||||||
| 119 | params => | ||||||||||||||||||||||||||||
| 120 | [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE( default => 0 ), COLUMNPAIR, ], | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # Circle ( Xc, Yc, R ) | ||||||||||||||||||||||||||||
| 136 | # Circle ( Xc, Yc, R, Xcolumn, Ycolumn ) | ||||||||||||||||||||||||||||
| 137 | 2 | REGION circle => ( params => [ VERTEX( 'center' ), LENGTH( 'radius' ), COLUMNPAIR ], ); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Diamond ( Xc, Yc, Wdth, Hght, A ) | ||||||||||||||||||||||||||||
| 147 | 2 | REGION diamond => | |||||||||||||||||||||||||||
| 148 | ( params => [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE( default => 0 ) ], | ||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # Ellipse ( Xc, Yc, Rx, Ry, A ) | ||||||||||||||||||||||||||||
| 171 | # Ellipse ( Xc, Yc, Rx, Ry, A, Xcolumn, Ycolumn ) | ||||||||||||||||||||||||||||
| 172 | 2 | REGION ellipse => | |||||||||||||||||||||||||||
| 173 | ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ), ANGLE( default => 0 ), COLUMNPAIR, ], ); | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # Elliptannulus ( Xc, Yc, Rinx, Riny, Routx, Routy, Ain, Aout ) | ||||||||||||||||||||||||||||
| 187 | 2 | REGION elliptannulus => | |||||||||||||||||||||||||||
| 188 | ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'inner' ), LENGTHPAIR( 'outer' ), ANGLEPAIR ], ); | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # Line ( X1, Y1, X2, Y2 ) | ||||||||||||||||||||||||||||
| 198 | 2 | REGION line => ( params => [ VERTEX( 'v1' ), VERTEX( 'v2' ) ], ); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # Point ( X1, Y1 ) | ||||||||||||||||||||||||||||
| 209 | 2 | REGION point => ( params => [ VERTEX( 'center' ) ], ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | # Polygon ( X1, Y1, X2, Y2, ... ) | ||||||||||||||||||||||||||||
| 220 | 2 | REGION polygon => ( params => [VERTICES], ); | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | # Rectangle ( X1, Y1, X2, Y2, A ) | ||||||||||||||||||||||||||||
| 233 | 2 | REGION rectangle => ( | |||||||||||||||||||||||||||
| 234 | params => [ XPOS( 'xmin' ), YPOS( 'ymin' ), XPOS( 'xmax' ), YPOS( 'ymax' ), ANGLE( default => 0 ) ], | ||||||||||||||||||||||||||||
| 235 | ); | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # Sector ( Xc, Yc, Amin, Amax ) | ||||||||||||||||||||||||||||
| 247 | 2 | REGION sector => ( params => [ VERTEX( 'center' ), ANGLEPAIR, ], ); | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | # No longer need this; clean it up. | ||||||||||||||||||||||||||||
| 250 | 2 | undef $stash; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | ▶ | sub mkregion ( $shape, @args ) { | |||||||||||||||||||||||||||
|
Subroutine
mkregion: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | 1 | my $class = pkgpath( $shape ); | |||||||||||||||||||||||||||
| 263 | 1 | ▶ | my $new = $class->can( 'new' ) // croak( "unknown region: $shape" ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class->can("new") // croak("unknown region: $shape")
MC/DC0%0/2
$class->can("new") // croak("unknown region: $shape")
$class->can("new")
croak("unknown region: $shape")
Truth table33%1/3
A // B
A= $class->can("new")B= croak("unknown region: $shape")
| |||||||||||||||||||||||||||||
| 264 | 1 | $class->$new( @args ); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 2 | 1; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | # | ||||||||||||||||||||||||||||
| 270 | # This file is part of CXC-Astro-Regions | ||||||||||||||||||||||||||||
| 271 | # | ||||||||||||||||||||||||||||
| 272 | # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||
| 274 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 275 | # | ||||||||||||||||||||||||||||
| 276 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 277 | # | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | __END__ | ||||||||||||||||||||||||||||