Class: Castaway::Interpolation::Linear
- Inherits:
-
Object
- Object
- Castaway::Interpolation::Linear
- Defined in:
- lib/castaway/interpolation/linear.rb
Overview
A linear interpolation between two values
Instance Attribute Summary collapse
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #[](t) ⇒ Object
-
#initialize(start, finish) ⇒ Linear
constructor
A new instance of Linear.
Constructor Details
#initialize(start, finish) ⇒ Linear
Returns a new instance of Linear.
8 9 10 11 12 |
# File 'lib/castaway/interpolation/linear.rb', line 8 def initialize(start, finish) @start = start @finish = finish @delta = finish - start end |
Instance Attribute Details
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
6 7 8 |
# File 'lib/castaway/interpolation/linear.rb', line 6 def finish @finish end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
6 7 8 |
# File 'lib/castaway/interpolation/linear.rb', line 6 def start @start end |
Instance Method Details
#[](t) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/castaway/interpolation/linear.rb', line 14 def [](t) if t < 0 @start elsif t > 1 @finish else @delta * t + @start end end |