26 #ifndef MLN_FUN_V2V_LINEAR_HH
27 # define MLN_FUN_V2V_LINEAR_HH
33 # include <mln/core/concept/function.hh>
34 # include <mln/convert/to.hh>
54 template <
typename V,
typename T = V,
typename R = T>
59 R operator()(
const V& v)
const;
62 R operator()(
const U& u)
const;
69 template <
typename V,
typename T = V,
typename R = T>
70 struct linear_sat :
public Function_v2v< linear_sat<V,T,R> >
74 R operator()(
const V& v)
const;
77 R operator()(
const U& u)
const;
84 # ifndef MLN_INCLUDE_ONLY
89 template <
typename V,
typename T,
typename R>
91 linear<V,T,R>::linear(T a, T b)
97 template <
typename V,
typename T,
typename R>
100 linear<V,T,R>::operator()(
const V& v)
const
102 return mln::convert::to<R>(a *
static_cast<T
>(v) + b);
105 template <
typename V,
typename T,
typename R>
106 template <
typename U>
109 linear<V,T,R>::operator()(
const U& u)
const
111 return this->operator()(static_cast<V>(u));
117 template <
typename V,
typename T,
typename R>
119 linear_sat<V,T,R>::linear_sat(T a, T b)
125 template <
typename V,
typename T,
typename R>
128 linear_sat<V,T,R>::operator()(
const V& v)
const
130 T res = a *
static_cast<T
>(v) + b;
131 if (res > mln_max(R))
133 else if (res < mln_min(R))
135 return mln::convert::to<R>(res);
138 template <
typename V,
typename T,
typename R>
139 template <
typename U>
142 linear_sat<V,T,R>::operator()(
const U& u)
const
144 mlc_converts_to(U, V)::check();
145 return this->operator()(static_cast<V>(u));
149 # endif // ! MLN_INCLUDE_ONLY
158 #endif // ! MLN_FUN_V2V_LINEAR_HH