aboutsummaryrefslogtreecommitdiff
path: root/src/un_math.c
blob: 42a1c4bfea9b55f32587bb37b22e80d10b2d5d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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_D) / 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_D) / 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_D) - 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;
}