interpolate function

double interpolate(
  1. double value,
  2. InterpolateConfig config
)

interpolate two arrays based on value can be used as a animation helper

Implementation

double interpolate(double value, InterpolateConfig config) {
  var inputRange = config.inputRange;
  var outputRange = config.outputRange;
  var extrapolate = config.extrapolate;
  var extrapolateLeft = config.extrapolateLeft;
  var extrapolateRight = config.extrapolateRight;

  var left = extrapolateLeft ?? extrapolate;
  var right = extrapolateRight ?? extrapolate;
  var output = interpolateInternal(value, inputRange, outputRange);

  if (left == Extrapolate.EXTEND) {
  } else if (left == Extrapolate.CLAMP) {
    if (value < inputRange[0]) {
      output = outputRange[0];
    }
  } else if (left == Extrapolate.IDENTITY) {
    if (value < inputRange[0]) {
      output = value;
    }
  }

  if (right == Extrapolate.EXTEND) {
  } else if (right == Extrapolate.CLAMP) {
    if (value > inputRange[inputRange.length - 1]) {
      output = outputRange[outputRange.length - 1];
    }
  } else if (right == Extrapolate.IDENTITY) {
    if (value > inputRange[inputRange.length - 1]) {
      output = value;
    }
  }

  return output;
}