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