Sha256: a483745777868f0faa79878b402ec8652921d4ccd785dc19a727e1c2ff19c919

Contents?: true

Size: 693 Bytes

Versions: 20

Compression:

Stored size: 693 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

20 entries across 20 versions & 1 rubygems

Version Path
tracksperanto-1.6.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.6.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.6.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.7 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.6 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.5 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.3 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.5.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.4.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.6 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.3.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.3.0 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.4 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.3 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.2 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.1 lib/tracksperanto/zip_tuples.rb
tracksperanto-1.2.0 lib/tracksperanto/zip_tuples.rb