Method: Music::Performance::PiecewiseFunction#eval

Defined in:
lib/music-performance/util/piecewise_function.rb

#eval(x) ⇒ Object

Evaluate the piecewise function by finding a function piece whose domain includes the given independent value.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/music-performance/util/piecewise_function.rb', line 105

def eval x
  y = nil
  
  @pieces.each do |domain, func|
    if domain.include? x
      y = func.call x
      break
    end
  end
  
  if y.nil?
    raise ArgumentError, "The input #{x} is not in the domain."
  end
  
  return y
end