Sha256: 7f5acb8750e447e281d5cc8f135b50fbb2a012de08fc6dc92ac9fc4fbdc007cc

Contents?: true

Size: 859 Bytes

Versions: 20

Compression:

Stored size: 859 Bytes

Contents

# Implements the zip_curve_tuples method
module Tracksperanto::ZipTuples
  # Zip arrays of "value at" tuples into an array of "values at" tuples
  # (note the plural). 
  # 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]]
  #
  # We make use of the fact that setting an offset index in an array fills it with nils up to
  # the index inserted
  def zip_curve_tuples(*curves)
    tuples = curves.inject([]) do | tuples, curve_of_at_and_value |
      curve_of_at_and_value.each do | frame, value |
       tuples[frame] = tuples[frame] ? (tuples[frame] << value) : [frame, value]
      end
      tuples
    end
    
    tuples.reject{|e| e.nil? || (e.length < (curves.length + 1)) }
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
tracksperanto-2.8.6 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.8.5 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.8.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.8.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.8.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.8.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.7.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.6.3 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.6.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.6.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.6.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.5.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.4.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.3.3 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.3.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.3.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.3.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.2.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.2.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-2.2.0 lib/tracksperanto/zip_tuples.rb