linter
This commit is contained in:
@@ -11,10 +11,10 @@
|
||||
* - InOut: Aceleración + Desaceleración (slow -> fast -> slow)
|
||||
*/
|
||||
|
||||
#ifndef EASING_FUNCTIONS_HPP
|
||||
#define EASING_FUNCTIONS_HPP
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
@@ -22,252 +22,230 @@
|
||||
|
||||
namespace Easing {
|
||||
|
||||
// ============================================================================
|
||||
// LINEAR
|
||||
// ============================================================================
|
||||
|
||||
inline float linear(float t) {
|
||||
inline auto linear(float t) -> float {
|
||||
return t;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QUAD (Cuadrática: t^2)
|
||||
// ============================================================================
|
||||
|
||||
inline float quadIn(float t) {
|
||||
inline auto quadIn(float t) -> float {
|
||||
return t * t;
|
||||
}
|
||||
|
||||
inline float quadOut(float t) {
|
||||
inline auto quadOut(float t) -> float {
|
||||
return t * (2.0F - t);
|
||||
}
|
||||
|
||||
inline float quadInOut(float t) {
|
||||
inline auto quadInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 2.0F * t * t;
|
||||
}
|
||||
return -1.0F + (4.0F - 2.0F * t) * t;
|
||||
return -1.0F + ((4.0F - 2.0F * t) * t);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// CUBIC (Cúbica: t^3)
|
||||
// ============================================================================
|
||||
|
||||
inline float cubicIn(float t) {
|
||||
inline auto cubicIn(float t) -> float {
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
inline float cubicOut(float t) {
|
||||
const float f = t - 1.0F;
|
||||
return f * f * f + 1.0F;
|
||||
inline auto cubicOut(float t) -> float {
|
||||
const float F = t - 1.0F;
|
||||
return (F * F * F) + 1.0F;
|
||||
}
|
||||
|
||||
inline float cubicInOut(float t) {
|
||||
inline auto cubicInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 4.0F * t * t * t;
|
||||
}
|
||||
const float f = (2.0F * t - 2.0F);
|
||||
return 0.5F * f * f * f + 1.0F;
|
||||
const float F = ((2.0F * t) - 2.0F);
|
||||
return (0.5F * F * F * F) + 1.0F;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QUART (Cuártica: t^4)
|
||||
// ============================================================================
|
||||
|
||||
inline float quartIn(float t) {
|
||||
inline auto quartIn(float t) -> float {
|
||||
return t * t * t * t;
|
||||
}
|
||||
|
||||
inline float quartOut(float t) {
|
||||
const float f = t - 1.0F;
|
||||
return 1.0F - f * f * f * f;
|
||||
inline auto quartOut(float t) -> float {
|
||||
const float F = t - 1.0F;
|
||||
return 1.0F - (F * F * F * F);
|
||||
}
|
||||
|
||||
inline float quartInOut(float t) {
|
||||
inline auto quartInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 8.0F * t * t * t * t;
|
||||
}
|
||||
const float f = t - 1.0F;
|
||||
return 1.0F - 8.0F * f * f * f * f;
|
||||
const float F = t - 1.0F;
|
||||
return 1.0F - (8.0F * F * F * F * F);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QUINT (Quíntica: t^5)
|
||||
// ============================================================================
|
||||
|
||||
inline float quintIn(float t) {
|
||||
inline auto quintIn(float t) -> float {
|
||||
return t * t * t * t * t;
|
||||
}
|
||||
|
||||
inline float quintOut(float t) {
|
||||
const float f = t - 1.0F;
|
||||
return f * f * f * f * f + 1.0F;
|
||||
inline auto quintOut(float t) -> float {
|
||||
const float F = t - 1.0F;
|
||||
return (F * F * F * F * F) + 1.0F;
|
||||
}
|
||||
|
||||
inline float quintInOut(float t) {
|
||||
inline auto quintInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 16.0F * t * t * t * t * t;
|
||||
}
|
||||
const float f = (2.0F * t - 2.0F);
|
||||
return 0.5F * f * f * f * f * f + 1.0F;
|
||||
const float F = ((2.0F * t) - 2.0F);
|
||||
return (0.5F * F * F * F * F * F) + 1.0F;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// SINE (Sinusoidal)
|
||||
// ============================================================================
|
||||
|
||||
inline float sineIn(float t) {
|
||||
return 1.0F - std::cos(t * static_cast<float>(M_PI) * 0.5F);
|
||||
inline auto sineIn(float t) -> float {
|
||||
return 1.0F - std::cos(t * std::numbers::pi_v<float> * 0.5F);
|
||||
}
|
||||
|
||||
inline float sineOut(float t) {
|
||||
return std::sin(t * static_cast<float>(M_PI) * 0.5F);
|
||||
inline auto sineOut(float t) -> float {
|
||||
return std::sin(t * std::numbers::pi_v<float> * 0.5F);
|
||||
}
|
||||
|
||||
inline float sineInOut(float t) {
|
||||
return 0.5F * (1.0F - std::cos(static_cast<float>(M_PI) * t));
|
||||
inline auto sineInOut(float t) -> float {
|
||||
return 0.5F * (1.0F - std::cos(std::numbers::pi_v<float> * t));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// EXPO (Exponencial)
|
||||
// ============================================================================
|
||||
|
||||
inline float expoIn(float t) {
|
||||
if (t == 0.0F) return 0.0F;
|
||||
inline auto expoIn(float t) -> float {
|
||||
if (t == 0.0F) {
|
||||
return 0.0F;
|
||||
}
|
||||
return std::pow(2.0F, 10.0F * (t - 1.0F));
|
||||
}
|
||||
|
||||
inline float expoOut(float t) {
|
||||
if (t == 1.0F) return 1.0F;
|
||||
inline auto expoOut(float t) -> float {
|
||||
if (t == 1.0F) {
|
||||
return 1.0F;
|
||||
}
|
||||
return 1.0F - std::pow(2.0F, -10.0F * t);
|
||||
}
|
||||
|
||||
inline float expoInOut(float t) {
|
||||
if (t == 0.0F || t == 1.0F) return t;
|
||||
inline auto expoInOut(float t) -> float {
|
||||
if (t == 0.0F || t == 1.0F) {
|
||||
return t;
|
||||
}
|
||||
|
||||
if (t < 0.5F) {
|
||||
return 0.5F * std::pow(2.0F, (20.0F * t) - 10.0F);
|
||||
}
|
||||
return 0.5F * (2.0F - std::pow(2.0F, -20.0F * t + 10.0F));
|
||||
return 0.5F * (2.0F - std::pow(2.0F, (-20.0F * t) + 10.0F));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// CIRC (Circular)
|
||||
// ============================================================================
|
||||
|
||||
inline float circIn(float t) {
|
||||
return 1.0F - std::sqrt(1.0F - t * t);
|
||||
inline auto circIn(float t) -> float {
|
||||
return 1.0F - std::sqrt(1.0F - (t * t));
|
||||
}
|
||||
|
||||
inline float circOut(float t) {
|
||||
const float f = t - 1.0F;
|
||||
return std::sqrt(1.0F - f * f);
|
||||
inline auto circOut(float t) -> float {
|
||||
const float F = t - 1.0F;
|
||||
return std::sqrt(1.0F - (F * F));
|
||||
}
|
||||
|
||||
inline float circInOut(float t) {
|
||||
inline auto circInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 0.5F * (1.0F - std::sqrt(1.0F - 4.0F * t * t));
|
||||
return 0.5F * (1.0F - std::sqrt(1.0F - (4.0F * t * t)));
|
||||
}
|
||||
const float f = 2.0F * t - 2.0F;
|
||||
return 0.5F * (std::sqrt(1.0F - f * f) + 1.0F);
|
||||
const float F = (2.0F * t) - 2.0F;
|
||||
return 0.5F * (std::sqrt(1.0F - (F * F)) + 1.0F);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// BACK (Overshoot - retrocede antes de avanzar)
|
||||
// ============================================================================
|
||||
|
||||
inline float backIn(float t, float overshoot = 1.70158F) {
|
||||
inline auto backIn(float t, float overshoot = 1.70158F) -> float {
|
||||
return t * t * ((overshoot + 1.0F) * t - overshoot);
|
||||
}
|
||||
|
||||
inline float backOut(float t, float overshoot = 1.70158F) {
|
||||
const float f = t - 1.0F;
|
||||
return f * f * ((overshoot + 1.0F) * f + overshoot) + 1.0F;
|
||||
inline auto backOut(float t, float overshoot = 1.70158F) -> float {
|
||||
const float F = t - 1.0F;
|
||||
return (F * F * ((overshoot + 1.0F) * F + overshoot)) + 1.0F;
|
||||
}
|
||||
|
||||
inline float backInOut(float t, float overshoot = 1.70158F) {
|
||||
const float s = overshoot * 1.525F;
|
||||
inline auto backInOut(float t, float overshoot = 1.70158F) -> float {
|
||||
const float S = overshoot * 1.525F;
|
||||
|
||||
if (t < 0.5F) {
|
||||
const float f = 2.0F * t;
|
||||
return 0.5F * (f * f * ((s + 1.0F) * f - s));
|
||||
const float F = 2.0F * t;
|
||||
return 0.5F * (F * F * ((S + 1.0F) * F - S));
|
||||
}
|
||||
|
||||
const float f = 2.0F * t - 2.0F;
|
||||
return 0.5F * (f * f * ((s + 1.0F) * f + s) + 2.0F);
|
||||
const float F = (2.0F * t) - 2.0F;
|
||||
return 0.5F * (F * F * ((S + 1.0F) * F + S) + 2.0F);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ELASTIC (Oscilación elástica - efecto de resorte)
|
||||
// ============================================================================
|
||||
inline auto elasticIn(float t, float amplitude = 1.0F, float period = 0.3F) -> float {
|
||||
if (t == 0.0F || t == 1.0F) {
|
||||
return t;
|
||||
}
|
||||
|
||||
inline float elasticIn(float t, float amplitude = 1.0F, float period = 0.3F) {
|
||||
if (t == 0.0F || t == 1.0F) return t;
|
||||
|
||||
const float s = period / (2.0F * static_cast<float>(M_PI)) * std::asin(1.0F / amplitude);
|
||||
const float f = t - 1.0F;
|
||||
return -(amplitude * std::pow(2.0F, 10.0F * f) *
|
||||
std::sin((f - s) * (2.0F * static_cast<float>(M_PI)) / period));
|
||||
const float S = period / (2.0F * std::numbers::pi_v<float>)*std::asin(1.0F / amplitude);
|
||||
const float F = t - 1.0F;
|
||||
return -(amplitude * std::pow(2.0F, 10.0F * F) *
|
||||
std::sin((F - S) * (2.0F * std::numbers::pi_v<float>) / period));
|
||||
}
|
||||
|
||||
inline float elasticOut(float t, float amplitude = 1.0F, float period = 0.3F) {
|
||||
if (t == 0.0F || t == 1.0F) return t;
|
||||
inline auto elasticOut(float t, float amplitude = 1.0F, float period = 0.3F) -> float {
|
||||
if (t == 0.0F || t == 1.0F) {
|
||||
return t;
|
||||
}
|
||||
|
||||
const float s = period / (2.0F * static_cast<float>(M_PI)) * std::asin(1.0F / amplitude);
|
||||
return amplitude * std::pow(2.0F, -10.0F * t) *
|
||||
std::sin((t - s) * (2.0F * static_cast<float>(M_PI)) / period) + 1.0F;
|
||||
const float S = period / (2.0F * std::numbers::pi_v<float>)*std::asin(1.0F / amplitude);
|
||||
return (amplitude * std::pow(2.0F, -10.0F * t) *
|
||||
std::sin((t - S) * (2.0F * std::numbers::pi_v<float>) / period)) +
|
||||
1.0F;
|
||||
}
|
||||
|
||||
inline float elasticInOut(float t, float amplitude = 1.0F, float period = 0.3F) {
|
||||
if (t == 0.0F || t == 1.0F) return t;
|
||||
inline auto elasticInOut(float t, float amplitude = 1.0F, float period = 0.3F) -> float {
|
||||
if (t == 0.0F || t == 1.0F) {
|
||||
return t;
|
||||
}
|
||||
|
||||
const float s = period / (2.0F * static_cast<float>(M_PI)) * std::asin(1.0F / amplitude);
|
||||
const float S = period / (2.0F * std::numbers::pi_v<float>)*std::asin(1.0F / amplitude);
|
||||
|
||||
if (t < 0.5F) {
|
||||
const float f = 2.0F * t - 1.0F;
|
||||
return -0.5F * (amplitude * std::pow(2.0F, 10.0F * f) *
|
||||
std::sin((f - s) * (2.0F * static_cast<float>(M_PI)) / period));
|
||||
const float F = (2.0F * t) - 1.0F;
|
||||
return -0.5F * (amplitude * std::pow(2.0F, 10.0F * F) * std::sin((F - S) * (2.0F * std::numbers::pi_v<float>) / period));
|
||||
}
|
||||
|
||||
const float f = 2.0F * t - 1.0F;
|
||||
return 0.5F * amplitude * std::pow(2.0F, -10.0F * f) *
|
||||
std::sin((f - s) * (2.0F * static_cast<float>(M_PI)) / period) + 1.0F;
|
||||
const float F = (2.0F * t) - 1.0F;
|
||||
return (0.5F * amplitude * std::pow(2.0F, -10.0F * F) *
|
||||
std::sin((F - S) * (2.0F * std::numbers::pi_v<float>) / period)) +
|
||||
1.0F;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// BOUNCE (Rebote - simula física de rebote)
|
||||
// ============================================================================
|
||||
inline auto bounceOut(float t) -> float {
|
||||
const float N1 = 7.5625F;
|
||||
const float D1 = 2.75F;
|
||||
|
||||
inline float bounceOut(float t) {
|
||||
const float n1 = 7.5625F;
|
||||
const float d1 = 2.75F;
|
||||
|
||||
if (t < 1.0F / d1) {
|
||||
return n1 * t * t;
|
||||
if (t < 1.0F / D1) {
|
||||
return N1 * t * t;
|
||||
}
|
||||
if (t < 2.0F / d1) {
|
||||
const float f = t - 1.5F / d1;
|
||||
return n1 * f * f + 0.75F;
|
||||
if (t < 2.0F / D1) {
|
||||
const float F = t - (1.5F / D1);
|
||||
return (N1 * F * F) + 0.75F;
|
||||
}
|
||||
if (t < 2.5F / d1) {
|
||||
const float f = t - 2.25F / d1;
|
||||
return n1 * f * f + 0.9375F;
|
||||
if (t < 2.5F / D1) {
|
||||
const float F = t - (2.25F / D1);
|
||||
return (N1 * F * F) + 0.9375F;
|
||||
}
|
||||
const float f = t - 2.625F / d1;
|
||||
return n1 * f * f + 0.984375F;
|
||||
const float F = t - (2.625F / D1);
|
||||
return (N1 * F * F) + 0.984375F;
|
||||
}
|
||||
|
||||
inline float bounceIn(float t) {
|
||||
inline auto bounceIn(float t) -> float {
|
||||
return 1.0F - bounceOut(1.0F - t);
|
||||
}
|
||||
|
||||
inline float bounceInOut(float t) {
|
||||
inline auto bounceInOut(float t) -> float {
|
||||
if (t < 0.5F) {
|
||||
return 0.5F * bounceIn(2.0F * t);
|
||||
}
|
||||
return 0.5F * bounceOut(2.0F * t - 1.0F) + 0.5F;
|
||||
return (0.5F * bounceOut((2.0F * t) - 1.0F)) + 0.5F;
|
||||
}
|
||||
|
||||
} // namespace Easing
|
||||
|
||||
#endif // EASING_FUNCTIONS_HPP
|
||||
|
||||
Reference in New Issue
Block a user