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