Qhull
view release on metacpan or search on metacpan
lib/Qhull/PP.pm view on Meta::CPAN
package Qhull::PP;
# ABSTRACT: Pure Perl interface to Qhull
use v5.26;
use strict;
use warnings;
use experimental 'signatures', 'lexical_subs', 'declared_refs';
our $VERSION = '0.08';
use Exporter::Shiny 'qhull';
use Scalar::Util 'blessed';
use Ref::Util 'is_arrayref';
use List::Util 'any';
use Log::Any '$log';
use Eval::Closure 'eval_closure';
use Ref::Util 'is_hashref', 'is_plain_arrayref';
use File::Spec;
use Qhull::Util 'parse_output';
use Qhull::Util::Options 'CAT_OUTPUT_FORMAT';
use Qhull::Options;
use System::Command;
use Feature::Compat::Defer;
use Alien::Qhull;
my sub croak {
require Carp;
our @CARP_NOT = qw( Qhull );
goto \&Carp::croak;
}
use constant qhull_exe => do {
my $exe;
if ( my @bin_dirs = Alien::Qhull->bin_dir ) {
for my $dir ( @bin_dirs ) {
$exe = File::Spec->catfile( $dir, 'qhull' );
last if -x $exe;
undef $exe;
}
}
_croak( q{Qhull executable 'qhull' was not found} )
if !defined $exe;
$exe;
};
my sub build_feed_qhull {
my @args = @_;
# individual coordinate elements
if ( @args == 1 && blessed $args[0] && $args[0]->isa( 'PDL' ) ) {
croak( 'a single NDArray argument must have dimensions == 2: got ' . $args[0]->ndims )
if $args[0]->ndims != 2;
@args = $args[0]->dog;
}
# these are captured in the constructed feed_qhull() sub; $nelem
# is determined after scanning the input
my $nelem;
my $ndims = @args;
croak( 'number of dimensions must be > 1' )
if @args < 2;
my @qsub;
my @extents;
my $icoord = 0;
for my $coord ( @args ) {
if ( is_plain_arrayref( $coord ) ) {
push @extents, 0+ @$coord;
push @qsub, sprintf( q|$coord[%d][$_]|, $icoord );
}
elsif ( blessed $coord && $coord->isa( 'PDL' ) ) {
croak( "coord[$icoord]: NDArray coordinate argument must be 1D" )
if $coord->ndims != 1;
push @extents, $coord->nelem;
( run in 3.121 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )