Module: Interpolate

Defined in:
lib/interpolate/base.rb,
lib/interpolate/version.rb

Overview

Interpolate is a library for generic linear interpolation objects. Useful for such things as calculating linear motion between locations (or arrays of locations), multi-channel color gradients, piecewise functions, or even just placing values within intervals.

Interpolation generators can be created with the Interpolate::Points class, given a set of interpolation “key points” and associated key values. By default, the key values should be able to calculate their own blending function (by defining an interpolate instance method). Alternatively, the Interpolate::Points object can be passed a block that takes three arguments: the lower value, the higher value, and the balance ratio between the two.

For the balance ratio, 0.0 means 100% of the lower value and a balance ratio of 1.0 means 100% of the higher value. A balance ratio of 0.5 means that the Interpolate::Points object has determined that the interpolated value should be a 50%/50% mixture of the lower and higher values. It is up to the blending function to determine how to calculate the interpolated value.

A Interpolate::Points objects is constructed with a Hash object, wherein each key is a Numeric and each value is an object (which itself may respond to interpolate). If any of the value objects do not respond to interpolate, a blending function (blend_with) must be used to determine the interpolated values.

The default blending function, Interpolate::Points::DEFAULT_BLEND, simply calls the interpolate method on the lower key value with the arguments of 1) the higher key value and 2) the balance ratio.

Author

Adam Collins

License

Licensed under the MIT license.

Defined Under Namespace

Classes: Points

Constant Summary collapse

VERSION_MAJOR =
0
VERSION_MINOR =
3
VERSION_BUILD =
0
VERSION =
[VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD].join('.')