Class: Musicality::Function::Linear
- Inherits:
-
Musicality::Function
- Object
- Musicality::Function
- Musicality::Function::Linear
- Defined in:
- lib/musicality/notation/util/function.rb
Instance Attribute Summary collapse
-
#intercept ⇒ Object
readonly
Returns the value of attribute intercept.
-
#slope ⇒ Object
readonly
Returns the value of attribute slope.
Attributes inherited from Musicality::Function
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(p1, p2) ⇒ Linear
constructor
A new instance of Linear.
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
#intercept ⇒ Object (readonly)
Returns the value of attribute intercept.
59 60 61 |
# File 'lib/musicality/notation/util/function.rb', line 59 def intercept @intercept end |
#slope ⇒ Object (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 |