tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
lerp.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_LERP_HPP
4#define TETL_CMATH_LERP_HPP
5
7
8namespace etl {
9
14template <floating_point Float>
15[[nodiscard]] constexpr auto lerp(Float a, Float b, Float t) noexcept -> Float
16{
17 if ((a <= 0 && b >= 0) || (a >= 0 && b <= 0)) {
18 return t * b + (1 - t) * a;
19 }
20
21 if (t == 1) {
22 return b;
23 }
24
25 auto const x = a + t * (b - a);
26 if ((t > 1) == (b > a)) {
27 return b < x ? x : b;
28 }
29 return x < b ? x : b;
30}
31
32} // namespace etl
33
34#endif // TETL_CMATH_LERP_HPP
constexpr auto lerp(Float a, Float b, Float t) noexcept -> Float
Computes a+t(b−a), i.e. the linear interpolation between a and b for the parameter t (or extrapolatio...
Definition lerp.hpp:15
Definition adjacent_find.hpp:8