Skip to content

Commit

Permalink
fixed to ruby doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tallakt committed Aug 24, 2012
1 parent 041ed25 commit a6c1132
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
20 changes: 12 additions & 8 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@ Quick Start
require 'spliner'

# Initialize a spline interpolation with x range 0.0..2.0
my_spline = Spliner::Spliner.new({0.0 => 0.0, 1.0 => 1.0, 2.0 => 0.5})
my_spline = Spliner::Spliner.new [0.0, 1.0, 2.0], [0.0, 1.0, 2.0]

# Perform interpolation on 31 values ranging from 0..2.0
x_values = (0..30).map {|x| x / 30.0 * 2.0 }
y_values = x_values.map {|x| my_spline[x] }
# Interpolate for a single value
y1 = my_spline[0.5]

# Perform interpolation on 11 values ranging from 0..2.0
y_values = my_spline[(0.0..2.0).step(0.1)]

# You may prefer to use the shortcut class method
y2 = Spliner::Spliner[[0.0, 1.0, 2.0], [0.0, 1.0, 0.5], 0.5]

# perform extrapolation outside key points using linear Y = aX + b
ex_spline = Spliner::Spliner.new({0.0 => 0.0, 1.0 => 1.0, 2.0 => 0.5}, :extrapolate => '10%')
ex_spline = Spliner::Spliner.new [0.0, 1.0, 2.0], [0.0, 1.0, 2.0], :extrapolate => '10%'
xx = ex_spline[2.1] # returns 0.4124999999999999

# perform extrapolation outside key points using linear Y = aX + b
ex_spline = Spliner::Spliner.new({0.0 => 0.0, 1.0 => 1.0, 2.0 => 0.5}, :extrapolate => '10%', :emethod => :hold)
ex_spline = Spliner::Spliner.new [0.0, 1.0, 2.0], [0.0, 1.0, 2.0], :extrapolate => '10%', :emethod => :hold)
xx = ex_spline[2.1] # returns 0.5

# Alternative intialization using X and Y arrays
ar_spline = Spliner::Spliner.new [1.0, 2.0, 3.0], [0.0, 3.0, 1.0]
# Alternative intialization using Hash
ar_spline = Spliner::Spliner.new({1.0 => 0.0, 2.0 => 3.0, 3.0 => 1.0})

# When duplicate X values are encountered, two or more discontinuous curves are used
two_spline = Spliner::Spliner.new [1.0, 2.0, 2.0, 3.0], [0.0, 3.0, 0.0, 1.0]
Expand Down
14 changes: 7 additions & 7 deletions lib/spliner/spliner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def initialize(*param)
# Spliner::Spliner#initialize
#
# @overload interpolate(points, x, options)
# @param points [Hash{Float => Float}] keys are X values in increasing order, values Y
# @param x [Float,Vector,Enumerable(Float)] X value(s) to interpolate on
# @param options [Hash]
# @param points [Hash{Float => Float}] keys are X values in increasing order, values Y
# @param x [Float,Vector,Enumerable(Float)] X value(s) to interpolate on
# @param options [Hash]
#
# @overload interpolate(key_x, key_y, x, options)
# @param key_x [Array(Float),Vector] the X values of the key points
# @param_key_y [Array(Float),Vector] the Y values of the key points
# @param x [Float,Vector,Enumerable(Float)] X value(s) to interpolate on
# @param options [Hash]
# @param key_x [Array(Float),Vector] the X values of the key points
# @param_key_y [Array(Float),Vector] the Y values of the key points
# @param x [Float,Vector,Enumerable(Float)] X value(s) to interpolate on
# @param options [Hash]
#
def self.interpolate(*args)
if (args.first.class == Hash)
Expand Down

0 comments on commit a6c1132

Please sign in to comment.