spliner 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spliner.rb +1 -1
- data/lib/spliner/spliner.rb +8 -6
- data/spec/spliner_spec.rb +6 -1
- metadata +1 -1
data/lib/spliner.rb
CHANGED
data/lib/spliner/spliner.rb
CHANGED
@@ -70,12 +70,14 @@ module Spliner
|
|
70
70
|
options ||= {}
|
71
71
|
|
72
72
|
if options[:fix_invalid_x]
|
73
|
-
|
74
|
-
|
75
|
-
pp
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
begin
|
74
|
+
size_at_start = x.size
|
75
|
+
pp = Hash[x.zip y]
|
76
|
+
to_delete = pp.keys.each_cons(2).select {|a,b| b < a}.map(&:last)
|
77
|
+
to_delete.each {|k| pp.delete k }
|
78
|
+
x = pp.keys
|
79
|
+
y = pp.values
|
80
|
+
end while x.size < size_at_start
|
79
81
|
end
|
80
82
|
|
81
83
|
@sections = split_at_duplicates(x).map {|slice| SplinerSection.new x[slice], y[slice] }
|
data/spec/spliner_spec.rb
CHANGED
@@ -135,9 +135,14 @@ describe Spliner::Spliner do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'has the option :fix_invalid_x to delete invalid x values (not increasing)' do
|
138
|
-
s = Spliner::Spliner.new [0.0, -1.0, 1.0], [0.0, 1.0, 1.0], :extrapolate => '100%', :fix_invalid_x => true
|
138
|
+
s = Spliner::Spliner.new [0.0, -1.0, -1.1, 0.5, 0.4, 1.0], [0.0, 1.0, 1.0, 0.5, 1.0, 1.0], :extrapolate => '100%', :fix_invalid_x => true
|
139
139
|
expect(s[0.5]).to be_within(0.001).of(0.5)
|
140
140
|
expect(s[-0.5]).to be_within(0.001).of(-0.5)
|
141
|
+
|
142
|
+
# not sure why this one is more difficult
|
143
|
+
x = [ -0.2006675899028778, -0.15321242064237595, -0.1328744888305664, -0.09355448558926582, -0.055590344592928886, -0.01355862058699131, 0.0, -0.008135172538459301, 0.0, -0.005423448514193296 ]
|
144
|
+
y = [ -60.06944274902344, -53.81944274902344, -51.46846008300781, -46.78096008300781, -41.30497741699219, -35.9664306640625, -33.99884033203125, -32.79803466796875, -31.980606079101562, -31.163192749023438 ]
|
145
|
+
s2 = Spliner::Spliner.new x, y, :fix_invalid_x => true
|
141
146
|
end
|
142
147
|
|
143
148
|
end
|