24 if (x.size() != y.size()) {
25 throw std::invalid_argument(
"LinearSpline: x and y must be the same size");
28 throw std::invalid_argument(
"LinearSpline: need at least 2 points");
30 for (
size_t i = 1; i < x.size(); ++i) {
31 if (x[i] <= x[i - 1]) {
32 throw std::invalid_argument(
"LinearSpline: x must be strictly increasing");
40 if (intervalCache <
x_.size() - 1 && x >=
x_[intervalCache] && x <
x_[intervalCache + 1]) {
44 const auto it = std::ranges::lower_bound(
x_, x);
45 intervalCache = it ==
x_.begin() ? 0 : std::distance(
x_.begin(), it) - 1;
virtual void init(const std::vector< double > &x, const std::vector< double > &y)
Initialize from tabulated data (natural spline).
size_t findInterval(double x, size_t &intervalCache) const
Return the interval index for the given x-coordinate, using the supplied cached value if possible.