From abff3b1a60fb2fc47409444f42312847b5e31436 Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Shardiwal Date: Sat, 14 Jun 2014 09:13:13 +0530 Subject: [PATCH 1/2] POD Coverage - CPAN Fail report fixes --- lib/Math/Function/Interpolator.pm | 4 +-- lib/Math/Function/Interpolator/Cubic.pm | 8 +++++- lib/Math/Function/Interpolator/Linear.pm | 8 +++++- lib/Math/Function/Interpolator/Quadratic.pm | 29 ++++++++++++++------- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/Math/Function/Interpolator.pm b/lib/Math/Function/Interpolator.pm index 7d87b84..c74d85b 100644 --- a/lib/Math/Function/Interpolator.pm +++ b/lib/Math/Function/Interpolator.pm @@ -21,7 +21,7 @@ Math::Function::Interpolator - Interpolation made easy =head1 VERSION -Version 0.03 +Version 0.04 =head1 SYNOPSIS @@ -49,7 +49,7 @@ HashRef of points for interpolations =cut -our $VERSION = '0.03'; +our $VERSION = '0.04'; # Automatically load all interpolate methods has 'interpolate_classes' => ( diff --git a/lib/Math/Function/Interpolator/Cubic.pm b/lib/Math/Function/Interpolator/Cubic.pm index dbab2fd..1cc03dd 100644 --- a/lib/Math/Function/Interpolator/Cubic.pm +++ b/lib/Math/Function/Interpolator/Cubic.pm @@ -4,7 +4,7 @@ use 5.006; use strict; use warnings FATAL => 'all'; -our $VERSION = '0.01'; +our $VERSION = '0.02'; use Moo::Role; @@ -32,6 +32,12 @@ Math::Function::Interpolator::Cubic Math::Function::Interpolator::Cubic helps you to do the interpolation calculation with cubic method. It solves the interpolated_y given point_x and a minimum of 5 data points. +=head1 FIELDS + +=head2 interpolate (REQUIRED) + +Interpolations class object + =cut has 'interpolate' => ( diff --git a/lib/Math/Function/Interpolator/Linear.pm b/lib/Math/Function/Interpolator/Linear.pm index 4e80cbc..0391486 100644 --- a/lib/Math/Function/Interpolator/Linear.pm +++ b/lib/Math/Function/Interpolator/Linear.pm @@ -4,7 +4,7 @@ use 5.006; use strict; use warnings FATAL => 'all'; -our $VERSION = '0.01'; +our $VERSION = '0.02'; use Moo::Role; use Carp qw(confess); @@ -30,6 +30,12 @@ Math::Function::Interpolator::Linear - Interpolation made easy Math::Function::Interpolator::Linear helps you to do the interpolation calculation with linear method. It solves for point_y linearly given point_x and an array of points. +=head1 FIELDS + +=head2 interpolate (REQUIRED) + +Interpolations class object + =cut has 'interpolate' => ( diff --git a/lib/Math/Function/Interpolator/Quadratic.pm b/lib/Math/Function/Interpolator/Quadratic.pm index 3d12126..6965837 100644 --- a/lib/Math/Function/Interpolator/Quadratic.pm +++ b/lib/Math/Function/Interpolator/Quadratic.pm @@ -4,7 +4,7 @@ use 5.006; use strict; use warnings FATAL => 'all'; -our $VERSION = '0.01'; +our $VERSION = '0.02'; use Moo::Role; @@ -17,15 +17,6 @@ use POSIX; use Scalar::Util qw(looks_like_number); use Try::Tiny; -has 'interpolate' => ( - is => 'ro', - isa => sub { - die "Must be Interpolate class" - unless ref $_[0] eq 'Math::Function::Interpolator'; - }, - required => 1 -); - =head1 NAME Math::Function::Interpolator::Quadratic @@ -45,6 +36,24 @@ Math::Function::Interpolator::Quadratic Math::Function::Interpolator::Quadratic helps you to do the interpolation calculation with quadratic method. It solves the interpolated_y given point_x and a minimum of 5 data points. +=head1 FIELDS + +=head2 interpolate (REQUIRED) + +Interpolations class object + +=cut + +has 'interpolate' => ( + is => 'ro', + isa => sub { + die "Must be Interpolate class" + unless ref $_[0] eq 'Math::Function::Interpolator'; + }, + required => 1 +); + + =head1 METHODS =head2 do_calculation From 898efcd1e6f4577ead1687f49d447dc632c2b8a1 Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Shardiwal Date: Sun, 15 Jun 2014 10:39:45 +0530 Subject: [PATCH 2/2] method closest_three_points made availabe to call from interpolate class, could be usefull for the Mathematician --- Changes | 5 ++++ lib/Math/Function/Interpolator.pm | 32 +++++++++++++++++++-- lib/Math/Function/Interpolator/Quadratic.pm | 29 ++----------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index f030581..86051eb 100644 --- a/Changes +++ b/Changes @@ -9,4 +9,9 @@ Revision history for Math-Function-Interpolator 0.03 12/06/2014 Big fix, unwanted typo +0.04 14/06/2014 + CPAN fail test improved + +0.05 15/06/2014 + method closest_three_points exported, could be usefull for the Mathmatician diff --git a/lib/Math/Function/Interpolator.pm b/lib/Math/Function/Interpolator.pm index c74d85b..0de48fa 100644 --- a/lib/Math/Function/Interpolator.pm +++ b/lib/Math/Function/Interpolator.pm @@ -9,6 +9,11 @@ with qw(MooX::Traits); use Carp qw(confess); use Scalar::Util qw(looks_like_number); + +use Number::Closest::XS qw(find_closest_numbers_around); +use List::MoreUtils qw(pairwise indexes); +use List::Util qw(min max); + use Module::Runtime; use Module::Pluggable sub_name => 'interpolate_methods', @@ -21,7 +26,7 @@ Math::Function::Interpolator - Interpolation made easy =head1 VERSION -Version 0.04 +Version 0.05 =head1 SYNOPSIS @@ -49,7 +54,7 @@ HashRef of points for interpolations =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; # Automatically load all interpolate methods has 'interpolate_classes' => ( @@ -141,6 +146,29 @@ sub cubic { ->do_calculation($x); } +=head2 closest_three_points + + Returns the the closest three points to the sought point. + The third point is chosen based on the point which is closer to mid point + +=cut + +sub closest_three_points { + my ( $self, $sought, $all_points ) = @_; + + my @ap = sort { $a <=> $b } @{$all_points}; + my $length = scalar @ap; + + my ( $first, $second ) = + @{ find_closest_numbers_around( $sought, $all_points, 2 ) }; + my @indexes = indexes { $first == $_ or $second == $_ } @ap; + my $third_index = + ( max(@indexes) < $length - 2 ) ? max(@indexes) + 1 : min(@indexes) - 1; + my @sorted = sort { $a <=> $b } ( $first, $second, $ap[$third_index] ); + + return @sorted; +} + =head1 AUTHOR Binary.com, C<< >> diff --git a/lib/Math/Function/Interpolator/Quadratic.pm b/lib/Math/Function/Interpolator/Quadratic.pm index 6965837..d65ade4 100644 --- a/lib/Math/Function/Interpolator/Quadratic.pm +++ b/lib/Math/Function/Interpolator/Quadratic.pm @@ -4,16 +4,12 @@ use 5.006; use strict; use warnings FATAL => 'all'; -our $VERSION = '0.02'; +our $VERSION = '0.03'; use Moo::Role; use Carp qw(confess); -use List::MoreUtils qw(pairwise indexes); -use List::Util qw(min max); use Math::Cephes::Matrix qw(mat); -use Number::Closest::XS qw(find_closest_numbers_around); -use POSIX; use Scalar::Util qw(looks_like_number); use Try::Tiny; @@ -74,7 +70,7 @@ sub do_calculation { confess "cannot interpolate with fewer than 3 data points" if scalar @Xs < 3; - my @points = $self->_get_closest_three_points( $x, \@Xs ); + my @points = $self->interpolate->closest_three_points( $x, \@Xs ); # Three cofficient my $abc = mat( [ map { [ $_**2, $_, 1 ] } @points ] ); @@ -89,27 +85,6 @@ sub do_calculation { return ( $a * ( $x**2 ) + $b * $x + $c ); } - -# Returns the the closest three points to the sought point. -# The third point is chosen based on the point which is closer to mid point -# $interpolator->_get_closest_three_points(2.4,[1,2,3,4,9]) #returns (2,3,4) - -sub _get_closest_three_points { - my ( $self, $sought, $all_points ) = @_; - - my @ap = sort { $a <=> $b } @{$all_points}; - my $length = scalar @ap; - - my ( $first, $second ) = - @{ find_closest_numbers_around( $sought, $all_points, 2 ) }; - my @indexes = indexes { $first == $_ or $second == $_ } @ap; - my $third_index = - ( max(@indexes) < $length - 2 ) ? max(@indexes) + 1 : min(@indexes) - 1; - my @sorted = sort { $a <=> $b } ( $first, $second, $ap[$third_index] ); - - return @sorted; -} - =head1 AUTHOR Binary.com, C<< >>