30 lines
666 B
C++
30 lines
666 B
C++
#pragma once
|
|
|
|
#include "./numerics/interpolation1d/interpolation1d_base.h"
|
|
|
|
|
|
namespace numerics{
|
|
|
|
template <typename T>
|
|
struct interp_linear : Base_interp<T> {
|
|
using Base = Base_interp<T>;
|
|
// bring base data members into scope (or use this->xx / this->yy below)
|
|
using Base::xx;
|
|
using Base::yy;
|
|
|
|
|
|
interp_linear(const utils::Vector<T> &xv, const utils::Vector<T> &yv): Base_interp<T>(xv, &yv[0], 2){}
|
|
|
|
T rawinterp(int64_t j, T x) override{
|
|
if (xx[j]==xx[j+1]){
|
|
return yy[j]; // Table is defective, but we can recover.
|
|
}else {
|
|
return (yy[j] + ((x-xx[j])/(xx[j+1]-xx[j]))*(yy[j+1]-yy[j]));
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace numerics
|
|
|