interpolator 0.12 → 0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/interpolator.rb +22 -4
- metadata +2 -2
data/interpolator.rb
CHANGED
@@ -20,8 +20,8 @@
|
|
20
20
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
21
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
# OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
24
|
-
|
23
|
+
#
|
24
|
+
#
|
25
25
|
module Interpolator
|
26
26
|
|
27
27
|
# Table holds a series of independent and dependent values that can be interpolated or extrapolated.
|
@@ -56,6 +56,9 @@ module Interpolator
|
|
56
56
|
# t = Table.new [1.0,2.0],[3.0,4.0]
|
57
57
|
# and is equivalent to
|
58
58
|
# t = Table.new(1.0=>3.0,2.0=>4.0)
|
59
|
+
#
|
60
|
+
# set attributes inline
|
61
|
+
# t = Table.new([1.0,2.0],[3.0,4.0]) do |tab| tab.extrapolate=false end
|
59
62
|
#
|
60
63
|
# * bivariant table
|
61
64
|
#
|
@@ -76,6 +79,15 @@ module Interpolator
|
|
76
79
|
# 1=>Table.new([1.0,2.0,3.0],[4.0,5.0,6.0]),
|
77
80
|
# 5=>Table.new([11.0,12.0,13.0],[-14.0,-15.0,-16.0]))
|
78
81
|
# )
|
82
|
+
#
|
83
|
+
#
|
84
|
+
# As a convienance the constructor accepts a block and will pass back the
|
85
|
+
# Table instance. This makes it easy to set the style and extrapolation inline.
|
86
|
+
# For example,
|
87
|
+
#
|
88
|
+
# tabfoo = Table.new [1,2,3],[4,5.5,6] do |t| t.extrapolate=false end
|
89
|
+
#
|
90
|
+
#
|
79
91
|
def initialize (*args)
|
80
92
|
if (args.size==2) then
|
81
93
|
raise "duel argument table constructor must be 2 Arrays" unless args[0].kind_of? Array
|
@@ -100,6 +112,9 @@ module Interpolator
|
|
100
112
|
end
|
101
113
|
@extrapolate = true
|
102
114
|
@style = LINEAR
|
115
|
+
if block_given?
|
116
|
+
yield self # makes it easy for users to set Table attributes inline
|
117
|
+
end
|
103
118
|
end
|
104
119
|
# Interpolate or extrapolate the Table. Pass as many arguments as there are independent dimensions to the table (univariant a
|
105
120
|
# single argument, bivariant 2 arguments, etc.)
|
@@ -392,13 +407,16 @@ require 'test/unit'
|
|
392
407
|
t.read(1)
|
393
408
|
}
|
394
409
|
end
|
410
|
+
def test_block
|
411
|
+
t = Table.new [1.0,2.0,3.0],[3.0,4.0,5.0] do |tab| tab.extrapolate=false;tab.style=Table::LAGRANGE2 end
|
412
|
+
assert_equal(t.read(4.0),5.0)
|
413
|
+
end
|
395
414
|
|
396
415
|
end
|
416
|
+
|
397
417
|
|
398
418
|
end
|
399
419
|
|
400
420
|
|
401
421
|
end
|
402
422
|
|
403
|
-
|
404
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interpolator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.13"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric T Meyers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-08 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|