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
6
#include <
etl/_concepts/floating_point.hpp
>
7
8
namespace
etl
{
9
14
template
<
float
ing_po
int
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
floating_point.hpp
etl::lerp
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
etl
Definition
adjacent_find.hpp:8
include
etl
_cmath
lerp.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0