mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
AK: Add mix
This commit is contained in:
parent
10efbfb09e
commit
8da0925d6d
2 changed files with 21 additions and 0 deletions
|
@ -91,6 +91,12 @@ constexpr T clamp(const T& value, const IdentityType<T>& min, const IdentityType
|
|||
return value;
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr T mix(T const& v1, T const& v2, U const& interpolation)
|
||||
{
|
||||
return v1 + (v2 - v1) * interpolation;
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr T ceil_div(T a, U b)
|
||||
{
|
||||
|
@ -167,6 +173,7 @@ using AK::exchange;
|
|||
using AK::is_constant_evaluated;
|
||||
using AK::max;
|
||||
using AK::min;
|
||||
using AK::mix;
|
||||
using AK::RawPtr;
|
||||
using AK::swap;
|
||||
using AK::to_underlying;
|
||||
|
|
|
@ -12,6 +12,20 @@
|
|||
#include <AK/Variant.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(mix)
|
||||
{
|
||||
double a = 1.0;
|
||||
double b = 3.0;
|
||||
|
||||
EXPECT_APPROXIMATE(mix(a, b, 0.0), 1.0);
|
||||
EXPECT_APPROXIMATE(mix(a, b, 0.5), 2.0);
|
||||
EXPECT_APPROXIMATE(mix(a, b, 1.0), 3.0);
|
||||
|
||||
EXPECT_APPROXIMATE(mix(b, a, 0.0), 3.0);
|
||||
EXPECT_APPROXIMATE(mix(b, a, 0.5), 2.0);
|
||||
EXPECT_APPROXIMATE(mix(b, a, 1.0), 1.0);
|
||||
}
|
||||
|
||||
TEST_CASE(swap)
|
||||
{
|
||||
int i = 4;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue