File indexing completed on 2026-08-06 09:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EXSAMPLE_linear_interpolator_h_included
0012 #define EXSAMPLE_linear_interpolator_h_included
0013
0014 #include "utility.h"
0015
0016 namespace exsample {
0017
0018
0019
0020 struct inversion_has_no_solution { };
0021
0022
0023
0024 struct constant_interpolation {
0025
0026
0027 constant_interpolation(double xlow,
0028 double xhigh,
0029 double h)
0030 : range(xlow,xhigh), value(h) {}
0031
0032
0033 std::pair<double,double> range;
0034
0035
0036 double value;
0037
0038 };
0039
0040
0041
0042 class linear_interpolator {
0043
0044 public:
0045
0046
0047 linear_interpolator();
0048
0049
0050
0051 explicit linear_interpolator(const std::map<double,double>& points);
0052
0053 public:
0054
0055
0056 double operator()(double x) const;
0057
0058
0059 std::pair<double,double> range() const { return range_; }
0060
0061 public:
0062
0063
0064
0065 bool invertible(double f) const {
0066 return (range_.first <= f &&
0067 range_.second >= f);
0068 }
0069
0070
0071
0072 double unique_inverse(double f) const;
0073
0074
0075 std::map<double,double>& interpolation() {
0076 return interpolation_;
0077 }
0078
0079
0080 void set_interpolation(double point, double value);
0081
0082
0083 void reset();
0084
0085 public:
0086
0087
0088 template<class OStream>
0089 void put(OStream& os) const;
0090
0091
0092 template<class IStream>
0093 void get(IStream& is);
0094
0095 private:
0096
0097
0098 std::map<double, double> interpolation_;
0099
0100
0101 std::pair<double,double> range_;
0102
0103 };
0104
0105
0106 template<class OStream>
0107 inline OStream& operator<<(OStream& os, const linear_interpolator& ip) {
0108 ip.put(os);
0109 return os;
0110 }
0111
0112
0113 template<class IStream>
0114 inline IStream& operator>>(IStream& is, linear_interpolator& ip) {
0115 ip.get(is);
0116 return is;
0117 }
0118
0119 }
0120
0121 #include "linear_interpolator.icc"
0122
0123 #endif