OGS
LinearIntervalInterpolation.h
Go to the documentation of this file.
1
15#pragma once
16
17#include "BaseLib/Error.h"
18
19namespace MathLib {
20
31template <typename NUMERIC_TYPE>
33public:
43 LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d);
50 inline NUMERIC_TYPE operator() (NUMERIC_TYPE x) const;
51
52private:
56 NUMERIC_TYPE m_;
60 NUMERIC_TYPE n_;
61};
62
63template <typename NUMERIC_TYPE>
65 NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d)
66 : m_(d - c), n_(0.0)
67{
68 if (b == a) {
69 OGS_FATAL("LinearIntervalInterpolation::LinearIntervalInterpolation: a == b, empty interval");
70 }
71 m_ /= (b - a);
72 n_ = c - m_ * a;
73}
74
75template <typename NUMERIC_TYPE>
76inline NUMERIC_TYPE LinearIntervalInterpolation<NUMERIC_TYPE>::operator() (NUMERIC_TYPE x) const
77{
78 return m_ * x + n_;
79}
80
81} // end namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:26
Class (template) LinearIntervalInterpolation is a functional object performing an interval mapping .
LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d)
NUMERIC_TYPE operator()(NUMERIC_TYPE x) const