FixMath
FixMathMapper.h
1 #ifndef FIXMATH_MAPPER_H
2 #define FIXMATH_MAPPER_H
3 
4 #include "FixMath.h"
5 
10 template<typename in_type, typename out_type>
12 {
13 
14  public:
27  FixMathMapperFull(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max) {
28  setBounds(_in_min,_in_max,_out_min,_out_max);
29  }
30 
31 
41  void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
42  {
43  in_min = _in_min;
44  in_max = _in_max;
45  out_min = _out_min;
46  out_max = _out_max;
47  compute_coef();
48  }
49 
50 
55  out_type map(in_type in) const
56  {
57  return ((in - in_min) * coef) + out_min;
58  }
59 
60 
61  private:
62  decltype((out_type(1)-out_type(0)) * (in_type(1)-in_type(0)).invFull()) coef=0;
63  in_type in_min, in_max;
64  out_type out_min, out_max;
65 
66  void compute_coef()
67  {
68  coef = (out_max-out_min)*(in_max-in_min).invFull();
69  }
70 };
71 
72 
73 
74 
75 
76 
77 
82 template<typename in_type, typename out_type>
84 {
85 
86  public:
99  FixMathMapperAccurate(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max) {
100  setBounds(_in_min,_in_max,_out_min,_out_max);
101  }
102 
103 
113  void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
114  {
115  in_min = _in_min;
116  in_max = _in_max;
117  out_min = _out_min;
118  out_max = _out_max;
119  compute_coef();
120  }
121 
122 
127  out_type map(in_type in) const
128  {
129  return ((in - in_min) * coef) + out_min;
130  }
131 
132 
133  private:
134  decltype((out_type(1)-out_type(0)) * (in_type(1)-in_type(0)).invFull()) coef=0;
135  in_type in_min, in_max;
136  out_type out_min, out_max;
137 
138  void compute_coef()
139  {
140  coef = (out_max-out_min)*(in_max-in_min).invAccurate();
141  }
142 };
143 
144 
145 
146 
147 
148 
149 
150 
155 template<typename in_type, typename out_type>
157 {
158 
159  public:
172  FixMathMapperFast(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max) {
173  setBounds(_in_min,_in_max,_out_min,_out_max);
174  }
175 
176 
186  void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
187  {
188  in_min = _in_min;
189  in_max = _in_max;
190  out_min = _out_min;
191  out_max = _out_max;
192  compute_coef();
193  }
194 
195 
200  out_type map(in_type in) const
201  {
202  return ((in - in_min) * coef) + out_min;
203  }
204 
205 
206  private:
207  decltype((out_type(1)-out_type(0)) * (in_type(1)-in_type(0)).invFull()) coef=0;
208  in_type in_min, in_max;
209  out_type out_min, out_max;
210 
211  void compute_coef()
212  {
213  coef = (out_max-out_min)*(in_max-in_min).invFast();
214  }
215 };
216 
217 
218 
219 #endif
Definition: FixMathMapper.h:84
out_type map(in_type in) const
Definition: FixMathMapper.h:127
FixMathMapperAccurate()
Definition: FixMathMapper.h:89
void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:113
FixMathMapperAccurate(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:99
Definition: FixMathMapper.h:157
FixMathMapperFast()
Definition: FixMathMapper.h:162
FixMathMapperFast(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:172
void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:186
out_type map(in_type in) const
Definition: FixMathMapper.h:200
Definition: FixMathMapper.h:12
FixMathMapperFull()
Definition: FixMathMapper.h:17
FixMathMapperFull(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:27
out_type map(in_type in) const
Definition: FixMathMapper.h:55
void setBounds(in_type _in_min, in_type _in_max, out_type _out_min, out_type _out_max)
Definition: FixMathMapper.h:41