// // C++ Implementation: Interpolator1D // // Description: // // // Author: Takeshi Nakazato , (C) 2012 // // Copyright: See COPYING file that comes with this distribution // // #include #include #include #include #include "Interpolator1D.h" #include "Locator.h" #include "BisectionLocator.h" #include "HuntLocator.h" namespace asap { template Interpolator1D::Interpolator1D() : order_(1), n_(0), x_(0), y_(0), locator_(0) { } template Interpolator1D::~Interpolator1D() { if (locator_) delete locator_; } template void Interpolator1D::setData(T *x, U *y, unsigned int n) { x_ = x; y_ = y; n_ = n; createLocator(); locator_->set(x, n); } template void Interpolator1D::setX(T *x, unsigned int n) { //assert(n_ == 0 || n_ == n); casacore::assert_(n_ == 0 || n_ == n, "length mismatch in data."); x_ = x; n_ = n; createLocator(); locator_->set(x, n); } template void Interpolator1D::setY(U *y, unsigned int n) { //assert(n_ == 0 || n_ == n); casacore::assert_(n_ == 0 || n_ == n, "length mismatch in data."); y_ = y; n_ = n; } template void Interpolator1D::reset() { n_ = 0; x_ = 0; y_ = 0; if (locator_) { delete locator_; locator_ = 0; } } template bool Interpolator1D::isready() { return (n_ > 0 && x_ != 0 && y_ != 0); } template unsigned int Interpolator1D::locate(T x) { return locator_->locate(x); } template void Interpolator1D::createLocator() { if (!locator_) { if (n_ > 1000) locator_ = new HuntLocator(); else locator_ = new BisectionLocator(); } } }