Module: Moon::Interpolation::CatmullRom

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


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/moon/packages/std/animation/interpolation.rb', line 68

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

  if v[0] == v[m]
    if k < 0
      i = (f = m * (1 + k)).floor
    end
    catmull_rom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i)
  else
    if k < 0
      v[0] - (catmull_rom(v[0], v[0], v[1], v[1], -f) - v[0])
    elsif k > 1
      v[m] - (catmull_rom(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m])
    else
      catmull_rom(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i)
    end
  end
end