spliner 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  require 'spliner/spliner'
2
2
 
3
3
  module Spliner
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  end
@@ -42,15 +42,17 @@ module Spliner
42
42
  # @overload initialize(key_points, options)
43
43
  # @param key_points [Hash{Float => Float}] keys are X values in increasing order, values Y
44
44
  # @param options [Hash]
45
- # @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%'
45
+ # @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%', or float 0.1
46
46
  # @option options [Symbol] :emethod (:linear) extrapolation method
47
+ # @option options [Symbol] :fix_invalid_x (false) delete data points not in increasing order
47
48
  #
48
49
  # @overload initialize(x, y, options)
49
50
  # @param x [Array(Float),Vector] the X values of the key points
50
51
  # @param y [Array(Float),Vector] the Y values of the key points
51
52
  # @param options [Hash]
52
- # @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%'
53
+ # @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%', or float 0.1
53
54
  # @option options [Symbol] :emethod (:linear) extrapolation method
55
+ # @option options [Symbol] :fix_invalid_x (false) delete data points not in increasing order
54
56
  #
55
57
  def initialize(*param)
56
58
  # sort parameters from two alternative initializer signatures
@@ -67,6 +69,15 @@ module Spliner
67
69
  end
68
70
  options ||= {}
69
71
 
72
+ if options[:fix_invalid_x]
73
+ pp = Hash[x.zip y]
74
+ pp.keys.each_cons(2) do |a,b|
75
+ pp.delete b if b < a
76
+ end
77
+ x = pp.keys
78
+ y = pp.values
79
+ end
80
+
70
81
  @sections = split_at_duplicates(x).map {|slice| SplinerSection.new x[slice], y[slice] }
71
82
 
72
83
  # Handle extrapolation option parameter
@@ -79,6 +90,10 @@ module Spliner
79
90
  @range = (x.first - extra)..(x.last + extra)
80
91
  when Range
81
92
  @range = ex
93
+ when Float
94
+ span = x.last - x.first
95
+ extra = span * ex
96
+ @range = (x.first - extra)..(x.last + extra)
82
97
  when nil
83
98
  @range = x.first..x.last
84
99
  else
@@ -99,6 +99,10 @@ describe Spliner::Spliner do
99
99
  s3 = Spliner::Spliner.new KEYS_0_100, :extrapolate => '10 %'
100
100
  expect(s3.range.first).to be_within(0.0001).of(-10.0)
101
101
  expect(s3.range.last).to be_within(0.0001).of(110.0)
102
+
103
+ s4 = Spliner::Spliner.new KEYS_0_100, :extrapolate => 0.1
104
+ expect(s3.range.first).to be_within(0.0001).of(-10.0)
105
+ expect(s3.range.last).to be_within(0.0001).of(110.0)
102
106
  end
103
107
 
104
108
  it 'splits data points with duplicate X values into separate sections' do
@@ -130,4 +134,10 @@ describe Spliner::Spliner do
130
134
  expect(Spliner::Spliner::interpolate(DATASET, 0..2, :extrapolate => '5%')).to eq(DATASET.values)
131
135
  end
132
136
 
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
139
+ expect(s[0.5]).to be_within(0.001).of(0.5)
140
+ expect(s[-0.5]).to be_within(0.001).of(-0.5)
141
+ end
142
+
133
143
  end
metadata CHANGED
@@ -1,85 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spliner
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
4
5
  prerelease:
5
- version: 1.0.3
6
6
  platform: ruby
7
- authors:
8
- - Tallak Tveide
7
+ authors:
8
+ - Tallak Tveide
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-08-24 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rspec
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "2.11"
24
- type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rake
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "0.9"
35
- type: :development
36
- version_requirements: *id002
37
- description: Simple library to perform cubic spline interpolation based on key X,Y values
38
- email:
39
- - tallak@tveide.net
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.9'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ description: Simple library to perform cubic spline interpolation based on key X,Y
47
+ values
48
+ email:
49
+ - tallak@tveide.net
40
50
  executables: []
41
-
42
51
  extensions: []
43
-
44
52
  extra_rdoc_files: []
45
-
46
- files:
47
- - .gitignore
48
- - .travis.yml
49
- - Gemfile
50
- - README.markdown
51
- - Rakefile
52
- - lib/spliner.rb
53
- - lib/spliner/spliner.rb
54
- - lib/spliner/spliner_section.rb
55
- - spec/spliner_spec.rb
56
- - spliner.gemspec
53
+ files:
54
+ - .gitignore
55
+ - .travis.yml
56
+ - Gemfile
57
+ - README.markdown
58
+ - Rakefile
59
+ - lib/spliner.rb
60
+ - lib/spliner/spliner.rb
61
+ - lib/spliner/spliner_section.rb
62
+ - spec/spliner_spec.rb
63
+ - spliner.gemspec
57
64
  homepage: http://www.github.com/tallakt/spliner
58
65
  licenses: []
59
-
60
66
  post_install_message:
61
67
  rdoc_options: []
62
-
63
- require_paths:
64
- - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
66
71
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 1.9.1
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.1
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
77
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
77
82
  requirements: []
78
-
79
83
  rubyforge_project: spliner
80
84
  rubygems_version: 1.8.24
81
85
  signing_key:
82
86
  specification_version: 3
83
87
  summary: Cubic spline interpolation library
84
88
  test_files: []
85
-
89
+ has_rdoc: