| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Math::Interpolator::Linear - lazy linear interpolation |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Math::Interpolator::Linear; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$ipl = Math::Interpolator::Linear->new(@points); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$y = $ipl->y($x); |
|
12
|
|
|
|
|
|
|
$x = $ipl->x($y); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This is a subclass of the lazy interpolator class C. |
|
17
|
|
|
|
|
|
|
This class implements linear interpolation. See L |
|
18
|
|
|
|
|
|
|
for the interface. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This code is neutral as to numeric type. The coordinate values used |
|
21
|
|
|
|
|
|
|
in interpolation may be native Perl numbers, C objects, |
|
22
|
|
|
|
|
|
|
or possibly other types. Mixing types within a single interpolation is |
|
23
|
|
|
|
|
|
|
not recommended. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package Math::Interpolator::Linear; |
|
28
|
|
|
|
|
|
|
|
|
29
|
7
|
|
|
7
|
|
173389
|
{ use 5.006; } |
|
|
7
|
|
|
|
|
26
|
|
|
|
7
|
|
|
|
|
316
|
|
|
30
|
7
|
|
|
7
|
|
46
|
use warnings; |
|
|
7
|
|
|
|
|
23
|
|
|
|
7
|
|
|
|
|
246
|
|
|
31
|
7
|
|
|
7
|
|
40
|
use strict; |
|
|
7
|
|
|
|
|
24
|
|
|
|
7
|
|
|
|
|
345
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = "0.005"; |
|
34
|
|
|
|
|
|
|
|
|
35
|
7
|
|
|
7
|
|
6173
|
use parent "Math::Interpolator"; |
|
|
7
|
|
|
|
|
2926
|
|
|
|
7
|
|
|
|
|
36
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item $ipl->y(X) |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item $ipl->x(Y) |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
These methods are part of the standard C interface. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _conv { |
|
50
|
60
|
|
|
60
|
|
118
|
my($self, $x_method, $y_method, $x) = @_; |
|
51
|
60
|
|
|
|
|
105
|
my $nhood_method = "nhood_$x_method"; |
|
52
|
60
|
|
|
|
|
261
|
my($a, $b) = $self->$nhood_method($x, 1); |
|
53
|
50
|
|
|
|
|
149
|
my $xa = $a->$x_method; |
|
54
|
50
|
|
|
|
|
686
|
my $xb = $b->$x_method; |
|
55
|
50
|
|
|
|
|
122
|
my $ya = $a->$y_method; |
|
56
|
50
|
|
|
|
|
119
|
my $yb = $b->$y_method; |
|
57
|
50
|
|
|
|
|
307
|
return $ya + ($x - $xa) * (($yb - $ya) / ($xb - $xa)); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub y { |
|
61
|
51
|
|
|
51
|
1
|
11634
|
my($self, $x) = @_; |
|
62
|
51
|
|
|
|
|
134
|
return $self->_conv("x", "y", $x); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub x { |
|
66
|
9
|
|
|
9
|
1
|
1025
|
my($self, $y) = @_; |
|
67
|
9
|
|
|
|
|
20
|
return $self->_conv("y", "x", $y); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=back |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Andrew Main (Zefram) |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copyright (C) 2006, 2007, 2009, 2010, 2012 |
|
83
|
|
|
|
|
|
|
Andrew Main (Zefram) |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 LICENSE |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
|
88
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |