nextInterpolation function

UnaryFunction<double> nextInterpolation({
  1. required Vector<double> xs,
  2. required Vector<double> ys,
  3. double right = double.nan,
})

A function providing the next value of a discrete monotonically increasing set of sample points xs and ys. Returns right if there is no next sample point.

Implementation

UnaryFunction<double> nextInterpolation({
  required Vector<double> xs,
  required Vector<double> ys,
  double right = double.nan,
}) {
  checkPoints(DataType.float,
      xs: xs, ys: ys, min: 1, ordered: true, unique: true);
  return (double x) {
    if (x < xs.getUnchecked(0)) {
      return ys.getUnchecked(0);
    } else if (xs.getUnchecked(xs.count - 1) < x) {
      return right;
    } else {
      return ys.getUnchecked(DataType.float.comparator
          .binarySearchLeft(xs, x)
          .clamp(0, xs.count - 1));
    }
  };
}