]> git.bts.cx Git - benzene.git/blob - src/bz/math/math.c
Initial version
[benzene.git] / src / bz / math / math.c
1 #include <bz/math/math.h>
2
3 #include <math.h>
4
5 float bzSine(float a) {
6 return sinf(bzLerp(0.0f, 2.0f * M_PI, fmodf(a, 1.0f)));
7 }
8
9 float bzCosine(float a) {
10 return cosf(bzLerp(0.0f, 2.0f * M_PI, fmodf(a, 1.0f)));
11 }
12
13 extern float bzInverseSine(float a) {
14 return bzUnlerp(0.0f, 2.0f * M_PI, fmodf(asinf(a), 2.0f * M_PI));
15 }
16
17 extern float bzInverseCosine(float a) {
18 return bzUnlerp(0.0f, 2.0f * M_PI, fmodf(acosf(a), 2.0f * M_PI));
19 }
20
21 float bzSqrt(float a) {
22 return sqrtf(a);
23 }
24
25 float bzAtan2(float x, float y) {
26 float a = atan2f(y, x);
27 float ca = bzUnlerp(0.0f, 2.0f * M_PI, a);
28 return ca;
29 }
30
31 float bzAngleDelta(float from, float to) {
32 float delta = fmodf(((to - from) + 2), 1);
33 if (delta >= 0.5f) {
34 delta = -(1.0f - delta);
35 }
36 return delta;
37 }
38
39 float bzDistance(float x1, float y1, float x2, float y2) {
40 return sqrtf(bzDistanceSquared(x1, y1, x2, y2));
41 }
42
43 float bzDistanceSquared(float x1, float y1, float x2, float y2) {
44 float dx = x2 - x1;
45 float dy = y2 - y1;
46 return dx * dx + dy * dy;
47 }
48
49 bool bzDistanceCheck(float x1, float y1, float x2, float y2, float distance) {
50 return bzDistanceSquared(x1, y1, x2, y2) <= distance * distance;
51 }