Module: Moon::Interpolation::Linear

Extended by:
Helper
Defined in:
lib/moon/packages/std/animation/interpolation.rb

Class Method Summary collapse

Methods included from Helper

bernstein, catmull_rom, factorial, linear

Class Method Details

.call(v, k) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/moon/packages/std/animation/interpolation.rb', line 38

def self.call(v, k)
  m = v.length - 1
  f = m * k
  i = f.floor

  if k < 0
    linear(v[0], v[1], f)
  elsif k > 1
    linear(v[m], v[m - 1], m - f)
  end
  linear(v[i], v[i + 1 > m ? m : i + 1], f - i)
end