Sha256: 31c65ecf5e0d2f47e3ca59c0534e83fca9675bf46ed1540b26968309165ba397

Contents?: true

Size: 887 Bytes

Versions: 37

Compression:

Stored size: 887 Bytes

Contents

# -*- encoding : utf-8 -*-
# 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

37 entries across 37 versions & 1 rubygems

Version Path
tracksperanto-3.5.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.5.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.5.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.5.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.4.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.4.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.13 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.12 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.11 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.10 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.9 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.8 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.7 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.6 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.3.0.pre lib/tracksperanto/zip_tuples.rb
tracksperanto-3.2.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.2.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.2.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.1.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-3.0.1 lib/tracksperanto/zip_tuples.rb