Last change
on this file since 2740 was 2733, checked in by Takeshi Nakazato, 12 years ago |
New Development: No
JIRA Issue: Yes CAS-4770
Ready for Test: Yes
Interface Changes: Yes/No
What Interface Changed: Please list interface changes
Test Programs: List test programs
Put in Release Notes: Yes/No
Module(s): Module Names change impacts.
Description: Describe your changes here...
Redefined Interpolator1D and derived classes as template class.
|
File size:
971 bytes
|
Rev | Line | |
---|
[2733] | 1 | //
|
---|
| 2 | // C++ Implementation: LinearInterpolator1D
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | //
|
---|
| 7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
|
---|
| 8 | //
|
---|
| 9 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | #include <assert.h>
|
---|
| 13 |
|
---|
| 14 | #include "LinearInterpolator1D.h"
|
---|
| 15 |
|
---|
| 16 | namespace asap {
|
---|
| 17 |
|
---|
| 18 | template <class T, class U>
|
---|
| 19 | LinearInterpolator1D<T, U>::LinearInterpolator1D()
|
---|
| 20 | : Interpolator1D<T, U>()
|
---|
| 21 | {}
|
---|
| 22 |
|
---|
| 23 | template <class T, class U>
|
---|
| 24 | LinearInterpolator1D<T, U>::~LinearInterpolator1D()
|
---|
| 25 | {}
|
---|
| 26 |
|
---|
| 27 | template <class T, class U> U LinearInterpolator1D<T, U>::interpolate(T x)
|
---|
| 28 | {
|
---|
| 29 | assert(this->isready());
|
---|
| 30 | if (this->n_ == 1)
|
---|
| 31 | return this->y_[0];
|
---|
| 32 |
|
---|
| 33 | unsigned int i = this->locator_->locate(x);
|
---|
| 34 |
|
---|
| 35 | // do not perform extrapolation
|
---|
| 36 | if (i == 0) {
|
---|
| 37 | return this->y_[i];
|
---|
| 38 | }
|
---|
| 39 | else if (i == this->n_) {
|
---|
| 40 | return this->y_[i-1];
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | // linear interpolation
|
---|
| 44 | U y = this->y_[i-1] + (this->y_[i] - this->y_[i-1]) * (x - this->x_[i-1])
|
---|
| 45 | / (this->x_[i] - this->x_[i-1]);
|
---|
| 46 | return y;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.