From ed1cab483e49e29396178a33dea51773aa770855 Mon Sep 17 00:00:00 2001 From: bonmas14 Date: Mon, 4 Aug 2025 13:33:47 +0000 Subject: Math, not tested --- src/un_math.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/un_math.c (limited to 'src/un_math.c') diff --git a/src/un_math.c b/src/un_math.c new file mode 100644 index 0000000..772ef70 --- /dev/null +++ b/src/un_math.c @@ -0,0 +1,99 @@ +/* reals */ + +real un_m_lerpr(real a, real b, real t) { + return (1.0 - t) * a + b * t; +} + +real un_m_ease_isiner(real t) { +#if defined(UN_DOUBLE_PRECISION) + return 1.0 - cos((t * PI) / 2.0); +#else + return 1.0 - cosf((t * PI) / 2.0); +#endif +} + +real un_m_ease_iosiner(real t) { +#if defined(UN_DOUBLE_PRECISION) + return sin((t * PI) / 2.0f); +#else + return sinf((t * PI) / 2.0f); +#endif +} + +real un_m_ease_osiner(real t) { +#if defined(UN_DOUBLE_PRECISION) + return -(cos(t * PI) - 1.0) / 2.0; +#else + return -(cosf(t * PI) - 1.0) / 2.0; +#endif +} + +real un_m_ease_iquadr(real t) { + return t * t; +} + +real un_m_ease_ioquadr(real t) { + return 1.0 - (1.0 - t) * (1.0 - t); +} + +real un_m_ease_oquadr(real t) { + return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0; +} + +/* floats */ +f32 un_m_lerpf(f32 a, f32 b, f32 t) { + return (1.0 - t) * a + b * t; +} + +f32 un_m_ease_isinef(f32 t) { + return 1.0 - cosf((t * PI) / 2.0); +} + +f32 un_m_ease_iosinef(f32 t) { + return sinf((t * PI) / 2.0f); +} + +f32 un_m_ease_osinef(f32 t) { + return -(cosf(t * PI) - 1.0) / 2.0; +} + +f32 un_m_ease_iquadf(f32 t) { + return t * t; +} + +f32 un_m_ease_ioquadf(f32 t) { + return 1.0 - (1.0 - t) * (1.0 - t); +} + +f32 un_m_ease_oquadf(f32 t) { + return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0; +} + +/* doubles */ +f64 un_m_lerpd(f64 a, f64 b, f64 t) { + return (1.0 - t) * a + b * t; +} + +f64 un_m_ease_isined(f64 t) { + return 1.0 - cos((t * PI) / 2.0); +} + +f64 un_m_ease_iosined(f64 t) { + return sin((t * PI) / 2.0f); +} + +f64 un_m_ease_osined(f64 t) { + return -(cos(t * PI) - 1.0) / 2.0; +} + +f64 un_m_ease_iquadd(f64 t) { + return t * t; +} + +f64 un_m_ease_ioquadd(f64 t) { + return 1.0 - (1.0 - t) * (1.0 - t); +} + +f64 un_m_ease_oquadd(f64 t) { + return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0; +} -- cgit v1.2.3-70-g09d2