Class: Musicality::Function::Linear

Inherits:
Musicality::Function show all
Defined in:
lib/musicality/notation/util/function.rb

Instance Attribute Summary collapse

Attributes inherited from Musicality::Function

#domain

Instance Method Summary collapse

Methods inherited from Musicality::Function

#at, #sample, transform_domains

Constructor Details

#initialize(p1, p2) ⇒ Linear

Returns a new instance of Linear.



61
62
63
64
65
66
# File 'lib/musicality/notation/util/function.rb', line 61

def initialize p1,p2
  @slope = (p2[1] - p1[1])/(p2[0] - p1[0]).to_f
  @intercept = p1[1] - @slope * p1[0]

  super() {|x| x * @slope + @intercept }
end

Instance Attribute Details

#interceptObject (readonly)

Returns the value of attribute intercept.



59
60
61
# File 'lib/musicality/notation/util/function.rb', line 59

def intercept
  @intercept
end

#slopeObject (readonly)

Returns the value of attribute slope.



59
60
61
# File 'lib/musicality/notation/util/function.rb', line 59

def slope
  @slope
end

Instance Method Details

#==(other) ⇒ Object



68
69
70
# File 'lib/musicality/notation/util/function.rb', line 68

def ==(other)
  super(other) && @slope == other.slope && @intercept == other.intercept
end