Sha256: e00bf7b0ebca47996fd76209fbb9b4496c62635183db620b2d5382b22a8f8369

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

# Implements the zip_curve_tuples method
module Tracksperanto::ZipTuples
  # Zip arrays of "value at" tuples into an array of "values at" tuples. 
  # The first value of each tuple will be the frame number
  # and keyframes which are not present in all arrays will be discarded. For example:
  #
  #    zip_curve_tuples( [[0, 12], [1, 23]], [[1, 12]]) #=> [[1, 23, 12]]
  #
  def zip_curve_tuples(*curves)
    tuples = []
    
    curves.each do | curve |
      curve.each do | keyframe |
        frame, value = keyframe
        tuples[frame] ? tuples[frame].push(value) : (tuples[frame] = [frame, value])
      end
    end

    tuples.compact.reject{|e| e.length < (curves.length + 1) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tracksperanto-1.6.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.6.3 lib/tracksperanto/zip_tuples.rb