diff --git a/lib/Math/Function/Interpolator.pm b/lib/Math/Function/Interpolator.pm index a5a1cf5..af38feb 100644 --- a/lib/Math/Function/Interpolator.pm +++ b/lib/Math/Function/Interpolator.pm @@ -15,6 +15,42 @@ use Module::Pluggable search_path => ['Math::Function::Interpolator'], ; +=head1 NAME + +Math::Function::Interpolator - Interpolation made easy + +=head1 VERSION + +Version 0.01 + +=head1 SYNOPSIS + + use Math::Function::Interpolator; + + my $interpolator = Math::Function::Interpolator->new( + points => {1=>2,2=>3,3=>4} + ); + + $interpolator->linear(2.5); + + $interpolator->quadratic(2.5); + + $interpolator->cubic(2.5); + +=head1 DESCRIPTION + +Math::Function::Interpolator helps you to do the interpolation calculation with linear, quadratic and cubic methods. + +=head1 FIELDS + +=head2 points (REQUIRED) + +HashRef of points for interpolations + +=cut + +our $VERSION = '0.01'; + # Automatically load all interpolate methods has 'interpolate_classes' => ( is => 'ro', @@ -37,9 +73,10 @@ has points => ( required => 1, ); -=head1 SUBROUTINES/METHODS +=head1 METHODS + +=head2 BUILDARGS -=head2 buildargs BUILDARGS =cut @@ -59,45 +96,8 @@ sub BUILDARGS { ## no critic (Subroutines::RequireArgUnpacking) return \%args; } -=head1 NAME - -Math::Function::Interpolator - Interpolation made easy - -=head1 VERSION - -Version 0.01 - -=cut - -our $VERSION = '0.01'; - -=head1 SYNOPSIS - - use Math::Function::Interpolator; - - my $interpolator = Math::Function::Interpolator->new( - points => {1=>2,2=>3,3=>4} - ); - - $interpolator->linear(2.5); - - $interpolator->quadratic(2.5); - - $interpolator->cubic(2.5); - -=head1 DESCRIPTION - -Math::Function::Interpolator helps you to do the interpolation calculation with linear, quadratic and cubic methods. - -=head1 EXPORT - =head2 linear -=head2 quadratic -=head2 cubic -=head1 SUBROUTINES/METHODS - -=head2 linear This method do the linear interpolation. It solves for point_y linearly given point_x and an array of points. =cut @@ -112,6 +112,7 @@ sub linear { } =head2 quadratic + This method do the quadratic interpolation. It solves the interpolated_y value given point_x with 3 data points. =cut @@ -126,6 +127,7 @@ sub quadratic { } =head2 cubic + This method do the cubic interpolation. It solves the interpolated_y given point_x and a minimum of 5 data points. =cut diff --git a/lib/Math/Function/Interpolator/Cubic.pm b/lib/Math/Function/Interpolator/Cubic.pm index 83829bb..dbab2fd 100644 --- a/lib/Math/Function/Interpolator/Cubic.pm +++ b/lib/Math/Function/Interpolator/Cubic.pm @@ -13,6 +13,27 @@ use List::MoreUtils qw(pairwise indexes); use Number::Closest::XS qw(find_closest_numbers_around); use Scalar::Util qw(looks_like_number); +=head1 NAME + +Math::Function::Interpolator::Cubic + +=head1 SYNOPSIS + + use Math::Function::Interpolator; + + my $interpolator = Math::Function::Interpolator->new( + points => {1=>2,2=>3,3=>4} + ); + + $interpolator->cubic(2.5); + +=head1 DESCRIPTION + +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. + +=cut + has 'interpolate' => ( is => 'ro', isa => sub { @@ -92,9 +113,10 @@ sub _extrapolate_spline { return $first->{y} - ( $first->{x} - $x ) * $derivative1; } -=head1 SUBROUTINES/METHODS +=head1 METHODS + +=head2 do_calculation -=head2 cubic do_calculation =cut @@ -154,20 +176,6 @@ sub do_calculation { return $y; } -=head1 SYNOPSIS - - use Math::Function::Interpolator; - - my $interpolator = Math::Function::Interpolator->new( - points => {1=>2,2=>3,3=>4} - ); - - $interpolator->cubic(2.5); - -=head1 DESCRIPTION - -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 AUTHOR diff --git a/lib/Math/Function/Interpolator/Linear.pm b/lib/Math/Function/Interpolator/Linear.pm index fab8822..4e80cbc 100644 --- a/lib/Math/Function/Interpolator/Linear.pm +++ b/lib/Math/Function/Interpolator/Linear.pm @@ -12,7 +12,24 @@ use Number::Closest::XS qw(find_closest_numbers_around); use Scalar::Util qw(looks_like_number); =head1 NAME + Math::Function::Interpolator::Linear - Interpolation made easy + +=head1 SYNOPSIS + + use Math::Function::Interpolator; + + my $interpolator = Math::Function::Interpolator->new( + points => {1=>2,2=>3,3=>4} + ); + + $interpolator->linear(2.5); + +=head1 DESCRIPTION + +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. + =cut has 'interpolate' => ( @@ -24,9 +41,10 @@ has 'interpolate' => ( required => 1 ); -=head1 SUBROUTINES/METHODS +=head1 METHODS + +=head2 do_calculation -=head2 linear do_calculation =cut @@ -55,22 +73,6 @@ sub do_calculation { return $m * $x + $c; } -=head1 SYNOPSIS - - use Math::Function::Interpolator; - - my $interpolator = Math::Function::Interpolator->new( - points => {1=>2,2=>3,3=>4} - ); - - $interpolator->linear(2.5); - -=head1 DESCRIPTION - -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 AUTHOR Binary.com, C<< >> diff --git a/lib/Math/Function/Interpolator/Quadratic.pm b/lib/Math/Function/Interpolator/Quadratic.pm index 9a05981..3d12126 100644 --- a/lib/Math/Function/Interpolator/Quadratic.pm +++ b/lib/Math/Function/Interpolator/Quadratic.pm @@ -26,9 +26,29 @@ has 'interpolate' => ( required => 1 ); -=head1 SUBROUTINES/METHODS +=head1 NAME + +Math::Function::Interpolator::Quadratic + +=head1 SYNOPSIS + + use Math::Function::Interpolator; + + my $interpolator = Math::Function::Interpolator->new( + points => {1=>2,2=>3,3=>4,4=>5,5=>6} + ); + + $interpolator->quadratic(2.5); + +=head1 DESCRIPTION + +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 METHODS + +=head2 do_calculation -=head2 quadratic do_calculation =cut @@ -81,21 +101,6 @@ sub _get_closest_three_points { return @sorted; } -=head1 SYNOPSIS - - use Math::Function::Interpolator; - - my $interpolator = Math::Function::Interpolator->new( - points => {1=>2,2=>3,3=>4,4=>5,5=>6} - ); - - $interpolator->quadratic(2.5); - -=head1 DESCRIPTION - -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 AUTHOR Binary.com, C<< >> @@ -106,9 +111,6 @@ Please report any bugs or feature requests to C. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. - - - =head1 SUPPORT You can find documentation for this module with the perldoc command.