|
| 1 | +export module CppUtils.Math.Easing; |
| 2 | + |
| 3 | +import std; |
| 4 | + |
| 5 | +export namespace CppUtils::Math::Easing |
| 6 | +{ |
| 7 | + [[nodiscard]] constexpr auto inQuad(std::floating_point auto value) noexcept -> auto |
| 8 | + { |
| 9 | + return value * value; |
| 10 | + } |
| 11 | + |
| 12 | + [[nodiscard]] constexpr auto outQuad(std::floating_point auto value) noexcept -> auto |
| 13 | + { |
| 14 | + return value * (2 - value); |
| 15 | + } |
| 16 | + |
| 17 | + [[nodiscard]] constexpr auto inOutQuad(std::floating_point auto value) noexcept -> auto |
| 18 | + { |
| 19 | + return value < 0.5 ? 2 * value * value : -1 + (4 - 2 * value) * value; |
| 20 | + } |
| 21 | + |
| 22 | + [[nodiscard]] constexpr auto inCubic(std::floating_point auto value) noexcept -> auto |
| 23 | + { |
| 24 | + return value * value * value; |
| 25 | + } |
| 26 | + |
| 27 | + [[nodiscard]] constexpr auto outCubic(std::floating_point auto value) noexcept -> auto |
| 28 | + { |
| 29 | + auto temp = value - 1; |
| 30 | + return temp * temp * temp + 1; |
| 31 | + } |
| 32 | + |
| 33 | + [[nodiscard]] constexpr auto inOutCubic(std::floating_point auto value) noexcept -> auto |
| 34 | + { |
| 35 | + if (value < 0.5) |
| 36 | + return 4 * value * value * value; |
| 37 | + |
| 38 | + auto temp = -2 * value + 2; |
| 39 | + return 1 - (temp * temp * temp) / 2; |
| 40 | + } |
| 41 | + |
| 42 | + [[nodiscard]] constexpr auto inQuart(std::floating_point auto value) noexcept -> auto |
| 43 | + { |
| 44 | + return value * value * value * value; |
| 45 | + } |
| 46 | + |
| 47 | + [[nodiscard]] constexpr auto outQuart(std::floating_point auto value) noexcept -> auto |
| 48 | + { |
| 49 | + auto temp = value - 1; |
| 50 | + return 1 - temp * temp * temp * temp; |
| 51 | + } |
| 52 | + |
| 53 | + [[nodiscard]] constexpr auto inOutQuart(std::floating_point auto value) noexcept -> auto |
| 54 | + { |
| 55 | + if (value < 0.5) |
| 56 | + return 8 * value * value * value * value; |
| 57 | + |
| 58 | + auto temp = -2 * value + 2; |
| 59 | + return 1 - (temp * temp * temp * temp) / 2; |
| 60 | + } |
| 61 | + |
| 62 | + [[nodiscard]] constexpr auto inQuint(std::floating_point auto value) noexcept -> auto |
| 63 | + { |
| 64 | + return value * value * value * value * value; |
| 65 | + } |
| 66 | + |
| 67 | + [[nodiscard]] constexpr auto outQuint(std::floating_point auto value) noexcept -> auto |
| 68 | + { |
| 69 | + auto temp = value - 1; |
| 70 | + return 1 + temp * temp * temp * temp * temp; |
| 71 | + } |
| 72 | + |
| 73 | + [[nodiscard]] constexpr auto inOutQuint(std::floating_point auto value) noexcept -> auto |
| 74 | + { |
| 75 | + if (value < 0.5) |
| 76 | + return 16 * value * value * value * value * value; |
| 77 | + |
| 78 | + auto temp = -2 * value + 2; |
| 79 | + return 1 - (temp * temp * temp * temp * temp) / 2; |
| 80 | + } |
| 81 | + |
| 82 | + [[nodiscard]] constexpr auto inSine(std::floating_point auto value) noexcept -> auto |
| 83 | + { |
| 84 | + return 1 - std::cos((value * std::numbers::pi_v<decltype(value)>) / 2); |
| 85 | + } |
| 86 | + |
| 87 | + [[nodiscard]] constexpr auto outSine(std::floating_point auto value) noexcept -> auto |
| 88 | + { |
| 89 | + return std::sin((value * std::numbers::pi_v<decltype(value)>) / 2); |
| 90 | + } |
| 91 | + |
| 92 | + [[nodiscard]] constexpr auto inOutSine(std::floating_point auto value) noexcept -> auto |
| 93 | + { |
| 94 | + return -(std::cos(std::numbers::pi_v<decltype(value)> * value) - 1) / 2; |
| 95 | + } |
| 96 | + |
| 97 | + [[nodiscard]] constexpr auto inCirc(std::floating_point auto value) noexcept -> auto |
| 98 | + { |
| 99 | + return 1 - std::sqrt(1 - std::pow(value, 2)); |
| 100 | + } |
| 101 | + |
| 102 | + [[nodiscard]] constexpr auto outCirc(std::floating_point auto value) noexcept -> auto |
| 103 | + { |
| 104 | + return std::sqrt(1 - (value - 1) * (value - 1)); |
| 105 | + } |
| 106 | + |
| 107 | + [[nodiscard]] constexpr auto inOutCirc(std::floating_point auto value) noexcept -> auto |
| 108 | + { |
| 109 | + if (value < 0.5) |
| 110 | + return (1 - std::sqrt(1 - 4 * value * value)) / 2; |
| 111 | + |
| 112 | + auto temp = -2 * value + 2; |
| 113 | + return (std::sqrt(1 - temp * temp) + 1) / 2; |
| 114 | + } |
| 115 | +} |
0 commit comments