// // C++ Implementation: LinearInterpolator1D // // Description: // // // Author: Takeshi Nakazato , (C) 2012 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include #include "LinearInterpolator1D.h" namespace asap { template LinearInterpolator1D::LinearInterpolator1D() : Interpolator1D() {} template LinearInterpolator1D::~LinearInterpolator1D() {} template U LinearInterpolator1D::interpolate(T x) { //assert(this->isready()); assert_(this->isready(),"object is not ready to process."); if (this->n_ == 1) return this->y_[0]; unsigned int i = this->locator_->locate(x); // do not perform extrapolation if (i == 0) { return this->y_[i]; } else if (i == this->n_) { return this->y_[i-1]; } // linear interpolation U y = this->y_[i-1] + (this->y_[i] - this->y_[i-1]) * (x - this->x_[i-1]) / (this->x_[i] - this->x_[i-1]); return y; } }