File Coverage

blib/lib/CXC/Astro/Regions/CFITSIO.pm
Criterion Covered Total %
statement 42 42 100.0
branch n/a
condition 1 3 33.3
subroutine 13 13 100.0
pod 1 1 100.0
total 57 59 96.6


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