| 1 | package Qhull::PP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Pure Perl interface to Qhull | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use experimental 'signatures', 'lexical_subs', 'declared_refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Exporter::Shiny 'qhull'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Ref::Util 'is_arrayref'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use List::Util 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Log::Any '$log'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Eval::Closure 'eval_closure'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Ref::Util 'is_hashref', 'is_plain_arrayref'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Qhull::Util 'parse_output'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Qhull::Util::Options 'CAT_OUTPUT_FORMAT'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use Qhull::Options; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use System::Command; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Feature::Compat::Defer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use Alien::Qhull; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my sub croak { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | our @CARP_NOT = qw( Qhull ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | goto \&Carp::croak; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | use constant qhull_exe => do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $exe; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | if ( my @bin_dirs = Alien::Qhull->bin_dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | for my $dir ( @bin_dirs ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | $exe = File::Spec->catfile( $dir, 'qhull' ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | last if -x $exe; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | undef $exe; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | _croak( q{Qhull executable 'qhull' was not found} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | if !defined $exe; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | $exe; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my sub build_feed_qhull { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_feed_qhull: called CC=13 SCAR=34.9
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # individual coordinate elements | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( @args == 1 && blessed $args[0] && $args[0]->isa( 'PDL' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@args == 1 and builtin::blessed($args[0]) and $args[0]->isa("PDL")
@args == 1 and builtin::blessed($args[0])
MC/DC0%0/3
@args == 1 and builtin::blessed($args[0]) and $args[0]->isa("PDL")
@args == 1
builtin::blessed($args[0])
$args[0]->isa("PDL")
Truth table25%1/4
A and B and C
A= @args == 1B= builtin::blessed($args[0])C= $args[0]->isa("PDL")
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | croak( 'a single NDArray argument must have dimensions == 2: got ' . $args[0]->ndims ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | if $args[0]->ndims != 2; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | @args = $args[0]->dog; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # these are captured in the constructed feed_qhull() sub; $nelem | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # is determined after scanning the input | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my $nelem; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $ndims = @args; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | croak( 'number of dimensions must be > 1' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | if @args < 2; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my @qsub; | |||||||||||||||||||||||||||||||||||||||||
| 71 | my @extents; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $icoord = 0; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | for my $coord ( @args ) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | if ( is_plain_arrayref( $coord ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | push @extents, 0+ @$coord; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | push @qsub, sprintf( q|$coord[%d][$_]|, $icoord ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | elsif ( blessed $coord && $coord->isa( 'PDL' ) ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
builtin::blessed($coord) and $coord->isa("PDL")
MC/DC0%0/2
builtin::blessed($coord) and $coord->isa("PDL")
builtin::blessed($coord)
$coord->isa("PDL")
Truth table0%0/3
A and B
A= builtin::blessed($coord)B= $coord->isa("PDL")
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | croak( "coord[$icoord]: NDArray coordinate argument must be 1D" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | if $coord->ndims != 1; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | push @extents, $coord->nelem; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | push @qsub, sprintf( q|$coord[%d]->at($_)|, $icoord ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | croak( "coord[$icoord] is neither a Perl arrayref or an NDArray" ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | continue { $icoord++ } | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # initialize value for capture. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | $nelem = $extents[0]; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | croak( 'coordinate arrays must have the same extent: ' . join( ', ', @extents ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | if any { $_ != $nelem } @extents; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # actually the following is not quite true. depending upon what | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # the caller is asking to be computed, the minimum number of | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # points may be larger. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | croak( 'number of points must be > 1' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | if $nelem < 2; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $source = join( "\n", | |||||||||||||||||||||||||||||||||||||||||
| 103 | q| use experimental 'signatures'; |, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | q| sub ($fh) { |, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | q| $fh->say( $ndims ); |, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | q| $fh->say( $nelem ); |, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | q| $fh->say( join( "\t", |, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | join( ', ', @qsub ), | ||||||||||||||||||||||||||||||||||||||||||
| 109 | qq|) ) for (0..$nelem-1)|, q|}|, ); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | eval_closure( | |||||||||||||||||||||||||||||||||||||||||
| 113 | source => $source, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | environment => { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | '@coord' => \@args, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | '$ndims' => \$ndims, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | '$nelem' => \$nelem, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 120 | $source, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | ## no critic( Subroutines::ProhibitExcessComplexity ) | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 9 | ▶ | sub qhull ( @coords ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qhull: called CC=22 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | my %option = ( | ||||||||||||||||||||||||||||||||||||||||||
| 166 | raw => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | passthrough => [], | ||||||||||||||||||||||||||||||||||||||||||
| 168 | trace => !!0, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | qh_opts => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | save_input => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | ▶ | is_hashref( $coords[-1] ) ? %{ pop @coords } : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | my $raw = delete $option{raw}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 9 | my $trace = delete $option{trace}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 9 | ▶ | my $qh_opts = delete( $option{qh_opts} ) // []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $option{"qh_opts"} // []
MC/DC100%1/1
delete $option{"qh_opts"} // []
delete $option{"qh_opts"}
Truth table100%2/2
A
A= delete $option{"qh_opts"}
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 9 | my $save_input = delete $option{save_input}; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | my $passthrough = delete $option{passthrough}; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 9 | ▶ | if ( is_arrayref( $qh_opts ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | $qh_opts = Qhull::Options->new_from_options( $qh_opts ); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ▶ | elsif ( !blessed( $qh_opts ) || !$qh_opts->isa( 'Qhull::Options' ) ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($qh_opts) && $qh_opts->isa('Qhull::Options')
MC/DC0%0/2
builtin::blessed($qh_opts) && $qh_opts->isa('Qhull::Options')
builtin::blessed($qh_opts)
$qh_opts->isa('Qhull::Options')
Truth table33%1/3
A && B
A= builtin::blessed($qh_opts)B= $qh_opts->isa('Qhull::Options')
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | croak( 'qh_opts must be a Qhull::Options object or an arrayref' ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 9 | $qh_opts = $qh_opts->filter_args( passthrough => $passthrough ); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # default mode is convex hull, return orderd list of indices (extrema), (format => 'Fx') | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 9 | ▶ | $qh_opts = $qh_opts->clone_with_options( ['Fx'] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$qh_opts->has_compute or $qh_opts->has_output_format
MC/DC50%1/2
$qh_opts->has_compute or $qh_opts->has_output_format
$qh_opts->has_compute
$qh_opts->has_output_format
Truth table66%2/3
A or B
A= $qh_opts->has_computeB= $qh_opts->has_output_format
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | if !$qh_opts->has_compute && !$qh_opts->has_output_format; | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | ▶ | croak( 'unknown options passed to qhull: ' . join( ', ', keys %option ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | if %option; | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | ▶ | croak( 'specify coordinates either via "TI" or as an argument to qhull(), but not both' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@coords and defined $qh_opts->input
MC/DC0%0/2
@coords and defined $qh_opts->input
@coords
defined $qh_opts->input
Truth table66%2/3
A and B
A= @coordsB= defined $qh_opts->input
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | if @coords && defined $qh_opts->input; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 9 | ▶ | croak( 'no coordinates specified' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $qh_opts->input or @coords
MC/DC0%0/2
defined $qh_opts->input or @coords
defined $qh_opts->input
@coords
Truth table66%2/3
A or B
A= defined $qh_opts->inputB= @coords
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | if !defined $qh_opts->input && !@coords; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | # if there are errors in creating the feed routine, die before starting up | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # qhull | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | ▶ | my ( $feed, $feed_source ) = @coords ? build_feed_qhull( @coords ) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | ▶ | $log->is_debug | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | && $log->debug( 'executing qhull: ', $qh_opts->qhull_opts ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | my @cmd = ( qhull_exe, $qh_opts->qhull_opts->@* ); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my $cmd = System::Command->new( @cmd ); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | ▶ | if ( $feed ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # Log::Any says don't use newlines; ignore that advice here. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $log->trace( $feed_source ); | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | ▶ | if ( defined $save_input ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | open my $fh, '>', $save_input | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | or croak( "unable to create $save_input" ); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $feed->( $fh ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $fh->close or croak( "error closing $save_input" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # ensure that the sub-process' sstdin is closed, regardless of | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # how this block is exited. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | defer { $cmd->stdin->close }; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | $feed->( $cmd->stdin ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | my $stderr = do { | |||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 9 | readline( $cmd->stderr ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 9 | ▶ | croak( 'error running ' . join( q{ }, @cmd ) . ': ' . $stderr ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | if length $stderr; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | my $output = defined( $qh_opts->output ) | ||||||||||||||||||||||||||||||||||||||||||
| 238 | ? do { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $cmd->close; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | require File::Slurper; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | File::Slurper::read_binary( $qh_opts->output ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 9 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | readline( $cmd->stdout ); | |||||||||||||||||||||||||||||||||||||||||
| 246 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 9 | ▶ | return $output if $raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | my @output = parse_output( | ||||||||||||||||||||||||||||||||||||||||||
| 251 | { trace => $trace }, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | $output, map { $_->[1]{name} } $qh_opts->by_category->{ +CAT_OUTPUT_FORMAT }{by_position}->@*, | |||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | return @output; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # This file is part of Qhull | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | __END__ | ||||||||||||||||||||||||||||||||||||||||||