mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-20 00:08:55 +00:00
AK: Add mix
This commit is contained in:
parent
10efbfb09e
commit
8da0925d6d
Notes:
sideshowbarker
2024-07-17 21:41:15 +09:00
Author: https://github.com/gmta
Commit: 8da0925d6d
Pull-request: https://github.com/SerenityOS/serenity/pull/11612
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;
|
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>
|
template<typename T, typename U>
|
||||||
constexpr T ceil_div(T a, U b)
|
constexpr T ceil_div(T a, U b)
|
||||||
{
|
{
|
||||||
|
@ -167,6 +173,7 @@ using AK::exchange;
|
||||||
using AK::is_constant_evaluated;
|
using AK::is_constant_evaluated;
|
||||||
using AK::max;
|
using AK::max;
|
||||||
using AK::min;
|
using AK::min;
|
||||||
|
using AK::mix;
|
||||||
using AK::RawPtr;
|
using AK::RawPtr;
|
||||||
using AK::swap;
|
using AK::swap;
|
||||||
using AK::to_underlying;
|
using AK::to_underlying;
|
||||||
|
|
|
@ -12,6 +12,20 @@
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
#include <AK/Vector.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)
|
TEST_CASE(swap)
|
||||||
{
|
{
|
||||||
int i = 4;
|
int i = 4;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue