interpolate function

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

interpolate two arrays based on value

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;
  checkMinElements('inputRange', inputRange);
  checkMinElements('outputRange', outputRange);
  checkNonDecreasing('inputRange', inputRange);
  invariant(inputRange.length == outputRange.length,
      ['inputRange and outputRange must be the same length.']);

  var left = extrapolateLeft ?? extrapolate;
  var right = extrapolateRight ?? extrapolate;
  double? 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;
}