Method: Music::Performance::PiecewiseFunction#initialize
- Defined in:
- lib/music-performance/util/piecewise_function.rb
#initialize(points = []) ⇒ PiecewiseFunction
Take an array of points (each point is a two-element array pair) and create a piecewise function to calculate values in-between.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/music-performance/util/piecewise_function.rb', line 12 def initialize points = [] @pieces = { } points = points.sort_by {|p| p[0]} if points.count > 1 if points.is_a?(Hash) points = points.to_a end for i in 1...points.count add_points points[i-1], points[i] end end end |