OGS
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 a, NUMERIC_TYPE b, 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
#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