OGS
LinearIntervalInterpolation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include "BaseLib/Error.h"
7
8namespace MathLib {
9
20template <typename NUMERIC_TYPE>
22public:
32 LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d);
39 inline NUMERIC_TYPE operator() (NUMERIC_TYPE x) const;
40
41private:
45 NUMERIC_TYPE m_;
49 NUMERIC_TYPE n_;
50};
51
52template <typename NUMERIC_TYPE>
54 NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d)
55 : m_(d - c), n_(0.0)
56{
57 if (b == a) {
58 OGS_FATAL("LinearIntervalInterpolation::LinearIntervalInterpolation: a == b, empty interval");
59 }
60 m_ /= (b - a);
61 n_ = c - m_ * a;
62}
63
64template <typename NUMERIC_TYPE>
65inline NUMERIC_TYPE LinearIntervalInterpolation<NUMERIC_TYPE>::operator() (NUMERIC_TYPE x) const
66{
67 return m_ * x + n_;
68}
69
70} // end namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:19
LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, NUMERIC_TYPE d)
NUMERIC_TYPE operator()(NUMERIC_TYPE x) const